blob: f9f875d72777efdfb5b9a84b78d89e32fba2e257 [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]8380c092009-06-25 17:45:5119#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5320#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/string_piece.h"
22#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2323#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5724#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0925#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5526#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2927#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1728#include "chrome/common/chrome_constants.h"
[email protected]d146b832009-12-23 02:45:4829#include "chrome/common/extensions/extension_constants.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1731#include "chrome/common/page_zoom.h"
[email protected]e09ba552009-02-05 03:26:2932#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2633#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5935#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2537#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1138#include "chrome/renderer/devtools_agent.h"
39#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3540#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3241#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3542#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3743#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2844#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5646#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1147#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5648#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1249#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3050#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5051#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2552#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2853#include "chrome/renderer/render_thread.h"
[email protected]bd92c3a2010-01-13 05:02:3454#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4655#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3556#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2957#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2958#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2959#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4260#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5661#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1562#include "gfx/color_utils.h"
63#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5764#include "gfx/native_widget_types.h"
[email protected]34ac8f32009-02-22 23:03:2765#include "grit/generated_resources.h"
66#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3467#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2968#include "net/base/escape.h"
69#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0070#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1071#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3072#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]58c321d2010-02-19 12:11:2873#include "third_party/WebKit/WebKit/chromium/public/GeolocationServiceBridgeChromium.h"
[email protected]418ed5ab2009-11-12 01:14:4974#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
75#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0776#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4977#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
78#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3279#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4980#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3581#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]418ed5ab2009-11-12 01:14:4982#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
83#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
84#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:4185#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]95056b582010-02-18 01:29:2486#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4987#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3288#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0789#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:4990#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4992#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
93#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
95#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
96#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
98#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:3499#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49100#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
102#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
103#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
104#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
105#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]80f584d92010-01-21 03:59:04106#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29107#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29108#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24109#include "webkit/glue/form_field.h"
110#include "webkit/glue/form_field_values.h"
111#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34112#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17113#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51114#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29115#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29116#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:23117#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]8400e032010-02-26 18:50:11118#include "webkit/glue/media/video_renderer_impl.h"
initial.commit09911bf2008-07-26 23:55:29119#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29120#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17121#include "webkit/glue/webmediaplayer_impl.h"
[email protected]24a7f3c2010-03-25 08:26:49122#include "webkit/glue/webplugin_delegate.h"
[email protected]f103ab72009-09-02 17:10:59123#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29124
[email protected]6c8afae52009-01-22 02:24:57125#if defined(OS_WIN)
126// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57127// * theming
[email protected]cd818412010-03-19 03:23:15128#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03129#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46130#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]6c8afae52009-01-22 02:24:57131#endif
132
[email protected]80f584d92010-01-21 03:59:04133using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26134using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33135using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45136using webkit_glue::AltErrorPageResourceFetcher;
[email protected]95056b582010-02-18 01:29:24137using webkit_glue::FormField;
[email protected]51bd36612009-10-20 22:49:47138using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17139using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56140using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10141using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15142using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08143using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41144using WebKit::WebColor;
145using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59146using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44147using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51148using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07149using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55150using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28151using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29152using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00153using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58154using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25155using WebKit::WebDragOperation;
156using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51157using WebKit::WebEditingAction;
[email protected]6069da8c2009-10-20 20:33:49158using WebKit::WebFindOptions;
[email protected]979c28b2009-11-07 01:30:48159using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45160using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17161using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41162using WebKit::WebImage;
[email protected]95056b582010-02-18 01:29:24163using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17164using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28165using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17166using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28167using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28168using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51169using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07170using WebKit::WebPageSerializer;
171using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17172using WebKit::WebPlugin;
173using WebKit::WebPluginParams;
[email protected]24a7f3c2010-03-25 08:26:49174using WebKit::WebPluginDocument;
[email protected]48c9cf2d2009-09-16 16:47:52175using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59176using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51177using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52178using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40179using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35180using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29181using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59182using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42183using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02184using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34185using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28186using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51187using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52188using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28189using WebKit::WebURL;
190using WebKit::WebURLError;
191using WebKit::WebURLRequest;
192using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28193using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03194using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28195using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43196using WebKit::WebWorker;
197using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33198
initial.commit09911bf2008-07-26 23:55:29199//-----------------------------------------------------------------------------
200
201// define to write the time necessary for thumbnail/DOM text retrieval,
202// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29203// #define TIME_TEXT_RETRIEVAL
204
205// maximum number of characters in the document to index, any text beyond this
206// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57207static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29208
209// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37210static const int kThumbnailWidth = 212;
211static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29212
213// Delay in milliseconds that we'll wait before capturing the page contents
214// and thumbnail.
215static const int kDelayForCaptureMs = 500;
216
217// Typically, we capture the page data once the page is loaded.
218// Sometimes, the page never finishes to load, preventing the page capture
219// To workaround this problem, we always perform a capture after the following
220// delay.
221static const int kDelayForForcedCaptureMs = 6000;
222
[email protected]882daa92009-11-05 16:31:31223// Time, in seconds, we delay before sending content state changes (such as form
224// state and scroll position) to the browser. We delay sending changes to avoid
225// spamming the browser.
226// To avoid having tab/session restore require sending a message to get the
227// current content state during tab closing we use a shorter timeout for the
228// foreground renderer. This means there is a small window of time from which
229// content state is modified and not sent to session restore, but this is
230// better than having to wake up all renderers during shutdown.
231static const int kDelaySecondsForContentStateSyncHidden = 5;
232static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29233
[email protected]0aa55312008-10-17 21:53:08234// The maximum number of popups that can be spawned from one page.
235static const int kMaximumNumberOfUnacknowledgedPopups = 25;
236
initial.commit09911bf2008-07-26 23:55:29237static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16238 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29239
[email protected]50b691c2008-10-31 19:08:35240static const char* const kBackForwardNavigationScheme = "history";
241
[email protected]8c4cdd42010-01-12 21:31:13242// The string returned in DetectLanguage if we failed to detect the language.
[email protected]8dc5a2052010-01-19 21:32:42243static const char* const kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13244
[email protected]726985e22009-06-18 21:09:28245static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
246 WebVector<WebURL> urls;
247 ds->redirectChain(urls);
248 result->reserve(urls.size());
249 for (size_t i = 0; i < urls.size(); ++i)
250 result->push_back(urls[i]);
251}
252
[email protected]61f5a7b2009-12-22 22:21:20253static bool UrlMatchesPermissions(
254 const GURL& url, const std::vector<URLPattern>& host_permissions) {
255 for (size_t i = 0; i < host_permissions.size(); ++i) {
256 if (host_permissions[i].MatchesUrl(url))
257 return true;
258 }
259
260 return false;
261}
262
[email protected]30507922010-01-15 16:48:23263static bool PaintViewIntoCanvas(WebView* view,
264 skia::PlatformCanvas& canvas) {
265 view->layout();
266 const WebSize& size = view->size();
267
268 if (!canvas.initialize(size.width, size.height, true))
269 return false;
270
271 view->paint(webkit_glue::ToWebCanvas(&canvas),
272 WebRect(0, 0, size.width, size.height));
273 // TODO: Add a way to snapshot the whole page, not just the currently
274 // visible part.
275
276 return true;
277}
278
279// Calculates how "boring" a thumbnail is. The boring score is the
280// 0,1 ranged percentage of pixels that are the most common
281// luma. Higher boring scores indicate that a higher percentage of a
282// bitmap are all the same brightness.
283static double CalculateBoringScore(SkBitmap* bitmap) {
284 int histogram[256] = {0};
285 color_utils::BuildLumaHistogram(bitmap, histogram);
286
287 int color_count = *std::max_element(histogram, histogram + 256);
288 int pixel_count = bitmap->width() * bitmap->height();
289 return static_cast<double>(color_count) / pixel_count;
290}
291
initial.commit09911bf2008-07-26 23:55:29292///////////////////////////////////////////////////////////////////////////////
293
[email protected]60c42a8c72009-10-09 04:08:59294int32 RenderView::next_page_id_ = 1;
295
[email protected]2fab253a2009-08-17 23:00:59296RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34297 const WebPreferences& webkit_preferences,
298 int64 session_storage_namespace_id)
[email protected]81a34412009-01-05 19:17:24299 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09300 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21301 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24302 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21303 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24304 page_id_(-1),
305 last_page_id_sent_to_browser_(-1),
306 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24307 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46308 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50309 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11310 devtools_agent_(NULL),
311 devtools_client_(NULL),
[email protected]a1128322009-10-06 18:38:46312 file_chooser_completion_(NULL),
[email protected]3cc72b12010-03-18 23:03:00313 history_list_offset_(-1),
314 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24315 has_unload_listener_(false),
316 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39317 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24318 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26319 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31320 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25321 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26322 ALLOW_THIS_IN_INITIALIZER_LIST(
323 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53324 view_type_(ViewType::INVALID),
325 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55326 last_top_level_navigation_page_id_(-1),
327#if defined(OS_MACOSX)
328 has_document_tag_(false),
329#endif
[email protected]98324892009-09-09 21:16:05330 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32331 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34332 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]b921cfd22010-02-25 16:57:51333 ALLOW_THIS_IN_INITIALIZER_LIST(text_translator_(this)),
[email protected]ab9eabac2010-03-16 16:54:10334 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
335 cross_origin_access_count_(0),
336 same_origin_access_count_(0) {
[email protected]71b0d5d2010-02-15 05:43:07337 ClearBlockedContentSettings();
[email protected]7e0831b2010-02-01 08:45:15338 page_translator_.reset(new PageTranslator(&text_translator_, this));
initial.commit09911bf2008-07-26 23:55:29339}
340
341RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08342 if (decrement_shared_popup_at_destruction_)
343 shared_popup_counter_->data--;
344
[email protected]b0950a72009-09-29 23:16:17345 // Dispose of un-disposed image fetchers.
346 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
347 i != image_fetchers_.end(); ++i) {
348 delete *i;
349 }
350
[email protected]a1128322009-10-06 18:38:46351 // If file chooser is still waiting for answer, dispatch empty answer.
352 if (file_chooser_completion_)
353 file_chooser_completion_->didChooseFile(WebVector<WebString>());
354
[email protected]83dde542009-09-11 20:59:55355#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05356 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55357 if (has_document_tag_)
358 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
359#endif
[email protected]98324892009-09-09 21:16:05360
[email protected]5fb88962009-04-16 19:03:25361 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59362
363#ifndef NDEBUG
364 // Make sure we are no longer referenced by the ViewMap.
365 ViewMap* views = Singleton<ViewMap>::get();
366 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
367 DCHECK_NE(this, it->second) << "Failed to call Close?";
368#endif
369}
370
371/*static*/
372void RenderView::ForEach(RenderViewVisitor* visitor) {
373 ViewMap* views = Singleton<ViewMap>::get();
374 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
375 if (!visitor->Visit(it->second))
376 return;
377 }
378}
379
380/*static*/
381RenderView* RenderView::FromWebView(WebView* webview) {
382 ViewMap* views = Singleton<ViewMap>::get();
383 ViewMap::iterator it = views->find(webview);
384 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29385}
386
387/*static*/
[email protected]0aa55312008-10-17 21:53:08388RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24389 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15390 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08391 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51392 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08393 const WebPreferences& webkit_prefs,
394 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34395 int32 routing_id,
396 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29397 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34398 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
399 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29400 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29401 opener_id,
[email protected]80d96fa2009-06-10 22:34:51402 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08403 counter,
initial.commit09911bf2008-07-26 23:55:29404 routing_id); // adds reference
405 return view;
406}
407
408/*static*/
409void RenderView::SetNextPageID(int32 next_page_id) {
410 // This method should only be called during process startup, and the given
411 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05412 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29413 DCHECK(next_page_id >= next_page_id_);
414 next_page_id_ = next_page_id;
415}
416
[email protected]afe3a1672009-11-17 19:04:12417void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56418 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
419}
420
[email protected]a3a8fb6d2009-10-22 20:12:51421void RenderView::PluginCrashed(const FilePath& plugin_path) {
422 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29423}
424
[email protected]d8fd6fa2010-02-01 15:54:26425#if defined(OS_MACOSX)
426void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
427 plugin_delegates_.insert(delegate);
428}
429
430void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
431 plugin_delegates_.erase(delegate);
432}
433#endif
434
[email protected]18bcc3c2009-01-27 21:39:15435void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29436 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51437 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08438 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29439 int32 routing_id) {
440 DCHECK(!webview());
441
442 if (opener_id != MSG_ROUTING_NONE)
443 opener_id_ = opener_id;
444
[email protected]0aa55312008-10-17 21:53:08445 if (counter) {
446 shared_popup_counter_ = counter;
447 shared_popup_counter_->data++;
448 decrement_shared_popup_at_destruction_ = true;
449 } else {
450 shared_popup_counter_ = new SharedRenderViewCounter(0);
451 decrement_shared_popup_at_destruction_ = false;
452 }
453
[email protected]58bfc6b2009-06-24 09:45:02454 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04455
[email protected]50ae00ef2009-10-19 05:11:03456 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59457 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59458 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27459 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29460 webview()->setDevToolsAgent(
461 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29462
[email protected]d3ba77272009-09-03 00:06:09463 OnSetRendererPrefs(renderer_prefs);
464
initial.commit09911bf2008-07-26 23:55:29465 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24466 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29467 // Take a reference on behalf of the RenderThread. This will be balanced
468 // when we receive ViewMsg_Close.
469 AddRef();
470
471 // If this is a popup, we must wait for the CreatingNew_ACK message before
472 // completing initialization. Otherwise, we can finish it now.
473 if (opener_id == MSG_ROUTING_NONE) {
474 did_show_ = true;
475 CompleteInit(parent_hwnd);
476 }
477
478 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29479
[email protected]58bfc6b2009-06-24 09:45:02480 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09481 if (command_line.HasSwitch(switches::kDomAutomationController))
482 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29483
[email protected]5fb88962009-04-16 19:03:25484 audio_message_filter_ = new AudioMessageFilter(routing_id_);
485 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29486}
487
488void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27489 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27490 if (main_frame)
491 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26492
[email protected]b2abac72009-02-26 12:39:28493 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11494 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28495 return;
[email protected]b4b967e2009-04-22 11:33:05496 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
497 return;
[email protected]b6849bda2009-10-14 23:59:26498 if (notification_provider_->OnMessageReceived(message))
499 return;
[email protected]58c321d2010-02-19 12:11:28500 if (geolocation_dispatcher_.get() &&
501 geolocation_dispatcher_->OnMessageReceived(message)) {
502 return;
503 }
[email protected]b2abac72009-02-26 12:39:28504
initial.commit09911bf2008-07-26 23:55:29505 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29506 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23507 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29508 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01509 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29510 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
511 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56512 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29513 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
initial.commit09911bf2008-07-26 23:55:29514 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
515 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
516 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
517 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27518#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35519 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27520#endif
initial.commit09911bf2008-07-26 23:55:29521 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
522 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05523 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
524 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
525 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04526 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29527 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
528 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
529 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15530 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29531 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49532 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
533 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17534 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]f85f0702010-01-30 09:31:01535 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost,
536 OnSetContentSettingsForLoadingHost)
[email protected]40bd6582009-12-04 23:49:51537 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
538 OnSetZoomLevelForLoadingHost)
initial.commit09911bf2008-07-26 23:55:29539 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18540 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
541 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28542 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33543 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29544 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48545 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29546 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29547 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29548 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
549 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
550 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
551 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
552 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45553 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29554 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50555 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
556 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29557 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
558 OnDragSourceSystemDragEnded)
559 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29560 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
561 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
562 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
563 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
564 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
565 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29566 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
567 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04568 IPC_MESSAGE_HANDLER(
569 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
570 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29571 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50572 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
573 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
574 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29575 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
576 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
577 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45578 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
579 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08580 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
581 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24582 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
583 OnAutoFillSuggestionsReturned)
584 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
585 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48586 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
587 OnAutoFillFormDataFilled)
[email protected]2c4410d2009-05-06 23:46:22588 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
589 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00590 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27591 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37592 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
593 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16594 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14595 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25596 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
597 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10598 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
599 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51600 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53601 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
602 OnUpdateBrowserWindowId)
603 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
604 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56605 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34606 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14607#if defined(OS_MACOSX)
608 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13609 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14610#endif
[email protected]446705872009-09-10 07:22:48611 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33612 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35613 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
614 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33615 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
616 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42617 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]0bedb8a2010-01-14 19:36:32618 IPC_MESSAGE_HANDLER(ViewMsg_TranslateTextReponse, OnTranslateTextResponse)
[email protected]634a6f92008-12-01 21:39:31619
initial.commit09911bf2008-07-26 23:55:29620 // Have the super handle all other messages.
621 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
622 IPC_END_MESSAGE_MAP()
623}
624
initial.commit09911bf2008-07-26 23:55:29625void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27626 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29627 if (!main_frame)
628 return;
629
630 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45631 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29632 if (url.is_empty())
633 return;
634
635 if (size_.IsEmpty())
636 return; // Don't create an empty thumbnail!
637
638 ThumbnailScore score;
639 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02640 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15641 &thumbnail, &score))
642 return;
643
initial.commit09911bf2008-07-26 23:55:29644 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46645 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29646}
647
[email protected]30507922010-01-15 16:48:23648void RenderView::SendSnapshot() {
649 SkBitmap snapshot;
650 bool error = false;
651
652 WebFrame* main_frame = webview()->mainFrame();
653 if (!main_frame)
654 error = true;
655
656 if (!error && !CaptureSnapshot(webview(), &snapshot))
657 error = true;
658
659 DCHECK(error == snapshot.empty()) <<
660 "Snapshot should be empty on error, non-empty otherwise.";
661
662 // Send the snapshot to the browser process.
663 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
664}
665
[email protected]068637222009-01-29 16:58:07666void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29667 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58668 if (webview()) {
669 // If the user has selected text in the currently focused frame we print
670 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27671 if (webview()->focusedFrame()->hasSelection())
672 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58673 else
[email protected]26aa0482009-09-30 16:55:27674 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58675 }
initial.commit09911bf2008-07-26 23:55:29676}
677
[email protected]82270452009-06-19 15:58:01678void RenderView::OnPrintingDone(int document_cookie, bool success) {
679 // Ignoring document cookie here since only one print job can be outstanding
680 // per renderer and document_cookie is 0 when printing is successful.
681 DCHECK(print_helper_.get());
682 if (print_helper_.get() != NULL) {
683 print_helper_->DidFinishPrinting(success);
684 }
685}
686
initial.commit09911bf2008-07-26 23:55:29687void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
688 if (load_id != page_id_)
689 return; // this capture call is no longer relevant due to navigation
690 if (load_id == last_indexed_page_id_)
691 return; // we already indexed this page
692
693 if (!webview())
694 return;
695
[email protected]26aa0482009-09-30 16:55:27696 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29697 if (!main_frame)
698 return;
699
700 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45701 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29702 return;
703
704 // Don't index/capture pages that failed to load. This only checks the top
705 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45706 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28707 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29708 return;
709
710 if (!preliminary_capture)
711 last_indexed_page_id_ = load_id;
712
[email protected]a8a81292010-01-21 00:32:45713 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45714 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29715 if (url.is_empty())
716 return;
717
[email protected]a8a81292010-01-21 00:32:45718 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29719 std::wstring contents;
720 CaptureText(main_frame, &contents);
721 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45722 base::TimeTicks begin_time = base::TimeTicks::Now();
723 std::string language = DetermineTextLanguage(contents);
724 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
725 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52726
[email protected]a8a81292010-01-21 00:32:45727 // Send the text to the browser for indexing (the browser might decide not
728 // to index, if the URL is HTTPS for instance) and language discovery.
729 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
730 language));
[email protected]5c4266922009-07-10 16:41:27731 }
732
initial.commit09911bf2008-07-26 23:55:29733 // thumbnail
734 SendThumbnail();
735}
736
737void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
738 contents->clear();
739 if (!frame)
740 return;
741
742#ifdef TIME_TEXT_RETRIEVAL
743 double begin = time_util::GetHighResolutionTimeNow();
744#endif
745
746 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45747 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29748
749#ifdef TIME_TEXT_RETRIEVAL
750 double end = time_util::GetHighResolutionTimeNow();
751 char buf[128];
752 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
753 contents.size(), (end - begin)*1000);
754 OutputDebugStringA(buf);
755#endif
756
757 // When the contents are clipped to the maximum, we don't want to have a
758 // partial word indexed at the end that might have been clipped. Therefore,
759 // terminate the string at the last space to ensure no words are clipped.
760 if (contents->size() == kMaxIndexChars) {
761 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
762 if (last_space_index == std::wstring::npos)
763 return; // don't index if we got a huge block of text with no spaces
764 contents->resize(last_space_index);
765 }
766}
767
[email protected]8649fb32009-06-26 17:51:02768bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29769 int w,
770 int h,
771 SkBitmap* thumbnail,
772 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23773 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15774
[email protected]8649fb32009-06-26 17:51:02775 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23776
777 // Paint |view| into |canvas|.
778 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02779 return false;
[email protected]8649fb32009-06-26 17:51:02780
781 skia::BitmapPlatformDevice& device =
782 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
783
784 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29785
[email protected]cab34d6a2009-09-24 01:14:52786 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29787 float dest_aspect = dest_rect.width() / dest_rect.height();
788
789 // Get the src rect so that we can preserve the aspect ratio while filling
790 // the destination.
791 SkIRect src_rect;
792 if (src_bmp.width() < dest_rect.width() ||
793 src_bmp.height() < dest_rect.height()) {
794 // Source image is smaller: we clip the part of source image within the
795 // dest rect, and then stretch it to fill the dest rect. We don't respect
796 // the aspect ratio in this case.
797 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
798 static_cast<S16CPU>(dest_rect.height()));
799 score->good_clipping = false;
800 } else {
801 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
802 if (src_aspect > dest_aspect) {
803 // Wider than tall, clip horizontally: we center the smaller thumbnail in
804 // the wider screen.
805 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
806 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
807 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
808 score->good_clipping = false;
809 } else {
810 src_rect.set(0, 0, src_bmp.width(),
811 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
812 score->good_clipping = true;
813 }
814 }
815
[email protected]26aa0482009-09-30 16:55:27816 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29817
818 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02819 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29820
821 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14822 *thumbnail = skia::ImageOperations::Resize(
823 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29824
825 score->boring_score = CalculateBoringScore(thumbnail);
826
[email protected]30507922010-01-15 16:48:23827 HISTOGRAM_TIMES("Renderer4.Thumbnail",
828 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15829 return true;
initial.commit09911bf2008-07-26 23:55:29830}
831
[email protected]30507922010-01-15 16:48:23832bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
833 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29834
[email protected]30507922010-01-15 16:48:23835 skia::PlatformCanvas canvas;
836 if (!PaintViewIntoCanvas(view, canvas))
837 return false;
838
839 skia::BitmapPlatformDevice& device =
840 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
841
842 const SkBitmap& bitmap = device.accessBitmap(false);
843 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
844 return false;
845
846 HISTOGRAM_TIMES("Renderer4.Snapshot",
847 base::TimeTicks::Now() - beginning_time);
848 return true;
initial.commit09911bf2008-07-26 23:55:29849}
850
851void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
852 if (!webview())
853 return;
854
[email protected]3cc72b12010-03-18 23:03:00855 history_list_offset_ = params.current_history_list_offset;
856 history_list_length_ = params.current_history_list_length;
857
[email protected]8c785c62009-07-13 14:20:15858 if (devtools_agent_.get())
859 devtools_agent_->OnNavigate();
860
[email protected]422197532010-01-25 17:38:23861 if (notification_provider_.get())
862 notification_provider_->OnNavigate();
863
[email protected]a9f607e2009-10-23 19:59:27864 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26865
initial.commit09911bf2008-07-26 23:55:29866 AboutHandler::MaybeHandle(params.url);
867
[email protected]ecbf10d2010-02-18 13:03:29868 bool is_reload =
869 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
870 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29871
[email protected]26aa0482009-09-30 16:55:27872 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45873 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29874 // We cannot reload if we do not have any history state. This happens, for
875 // example, when recovering from a crash. Our workaround here is a bit of
876 // a hack since it means that reload after a crashed tab does not cause an
877 // end-to-end cache validation.
878 is_reload = false;
879 }
880
[email protected]77f17a82009-05-21 04:42:54881 // A navigation resulting from loading a javascript URL should not be treated
882 // as a browser initiated event. Instead, we want it to look as if the page
883 // initiated any load resulting from JS execution.
884 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30885 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00886 params.page_id,
887 params.pending_history_list_offset,
888 params.transition,
889 params.request_time);
[email protected]5e369672009-11-03 23:48:30890 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
891 // We're doing a load of a page that was restored from the last session.
892 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
893 // which can result in stale data for pages that are set to expire. We
894 // explicitly override that by setting the policy here so that as
895 // necessary we load from the network.
896 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
897 }
898 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54899 }
initial.commit09911bf2008-07-26 23:55:29900
[email protected]a7ccc4d2010-01-27 08:14:48901 NavigationState* navigation_state = pending_navigation_state_.get();
902
[email protected]04d3c6e2009-05-22 17:00:13903 // If we are reloading, then WebKit will use the history state of the current
904 // page, so we should just ignore any given history state. Otherwise, if we
905 // have history state, then we need to navigate to it, which corresponds to a
906 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55907 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48908 if (navigation_state)
909 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29910 bool ignore_cache = (params.navigation_type ==
911 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
912 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55913 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13914 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58915 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48916 if (navigation_state)
917 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45918 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17919 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13920 } else {
921 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28922 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29923
[email protected]e6f546c32009-07-01 17:12:55924 // A session history navigation should have been accompanied by state.
925 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13926
[email protected]dd7daa82009-08-10 05:46:45927 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55928 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13929
[email protected]726985e22009-06-18 21:09:28930 if (params.referrer.is_valid()) {
931 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
932 WebString::fromUTF8(params.referrer.spec()));
933 }
[email protected]04d3c6e2009-05-22 17:00:13934
[email protected]a7ccc4d2010-01-27 08:14:48935 if (navigation_state)
936 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45937 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50938 }
939
[email protected]77f17a82009-05-21 04:42:54940 // In case LoadRequest failed before DidCreateDataSource was called.
941 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29942}
943
944// Stop loading the current page
945void RenderView::OnStop() {
946 if (webview())
[email protected]b4bb2502009-10-01 22:35:27947 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29948}
949
[email protected]ecbf10d2010-02-18 13:03:29950// Reload current focused frame.
951// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56952void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29953 if (webview() && webview()->focusedFrame()) {
954 // We always obey the cache (ignore_cache=false) here.
955 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
956 // a cache-ignoring reload of the frame.
957 webview()->focusedFrame()->reload(false);
958 }
[email protected]1dda4022010-01-28 18:24:56959}
960
[email protected]e6f546c32009-07-01 17:12:55961void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29962 bool new_navigation,
963 const GURL& display_url,
964 const std::string& security_info) {
965 if (!webview())
966 return;
967
[email protected]e6f546c32009-07-01 17:12:55968 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00969 new_navigation ? -1 : page_id_,
970 history_list_offset_,
971 PageTransition::LINK,
972 Time::Now()));
[email protected]e6f546c32009-07-01 17:12:55973 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29974
[email protected]26aa0482009-09-30 16:55:27975 webview()->mainFrame()->loadHTMLString(
976 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55977
978 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29979}
980
981void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27982 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29983}
984
[email protected]68b1e922009-06-23 16:00:25985void RenderView::OnExecuteEditCommand(const std::string& name,
986 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27987 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25988 return;
989
[email protected]26aa0482009-09-30 16:55:27990 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45991 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25992}
993
[email protected]b2abac72009-02-26 12:39:28994void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11995 DCHECK(!devtools_client_.get());
996 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28997}
998
initial.commit09911bf2008-07-26 23:55:29999void RenderView::OnUpdateTargetURLAck() {
1000 // Check if there is a targeturl waiting to be sent.
1001 if (target_url_status_ == TARGET_PENDING) {
1002 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1003 pending_target_url_));
1004 }
1005
1006 target_url_status_ = TARGET_NONE;
1007}
1008
1009void RenderView::OnUndo() {
1010 if (!webview())
1011 return;
1012
[email protected]26aa0482009-09-30 16:55:271013 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121014 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291015}
1016
1017void RenderView::OnRedo() {
1018 if (!webview())
1019 return;
1020
[email protected]26aa0482009-09-30 16:55:271021 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121022 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291023}
1024
1025void RenderView::OnCut() {
1026 if (!webview())
1027 return;
1028
[email protected]26aa0482009-09-30 16:55:271029 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121030 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291031}
1032
1033void RenderView::OnCopy() {
1034 if (!webview())
1035 return;
1036
[email protected]26aa0482009-09-30 16:55:271037 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121038 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291039}
1040
[email protected]c0cc3092009-09-12 08:27:271041#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351042void RenderView::OnCopyToFindPboard() {
1043 if (!webview())
1044 return;
1045
1046 // Since the find pasteboard supports only plain text, this can be simpler
1047 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271048 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351049 if (frame->hasSelection()) {
1050 string16 selection = frame->selectionAsText();
1051 RenderThread::current()->Send(
1052 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1053 }
1054
[email protected]afe3a1672009-11-17 19:04:121055 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351056}
[email protected]c0cc3092009-09-12 08:27:271057#endif
[email protected]a954bf72009-09-12 07:30:351058
initial.commit09911bf2008-07-26 23:55:291059void RenderView::OnPaste() {
1060 if (!webview())
1061 return;
1062
[email protected]26aa0482009-09-30 16:55:271063 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121064 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291065}
1066
[email protected]2a3a7762009-10-19 19:17:321067void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291068 if (!webview())
1069 return;
1070
[email protected]1ff7a032010-02-03 02:46:031071 WebFrame* frame = webview()->focusedFrame();
1072 if (!frame->hasSelection())
1073 frame->selectWordAroundCaret();
1074 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291075}
1076
[email protected]98324892009-09-09 21:16:051077void RenderView::OnAdvanceToNextMisspelling() {
1078 if (!webview())
1079 return;
[email protected]26aa0482009-09-30 16:55:271080 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051081 WebString::fromUTF8("AdvanceToNextMisspelling"));
1082}
1083
1084void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1085 if (!webview())
1086 return;
1087 // We need to tell the webView whether the spelling panel is visible or not so
1088 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261089 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271090 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051091 WebString::fromUTF8("ToggleSpellPanel"));
1092}
1093
[email protected]bbbd545c2008-12-15 20:18:041094void RenderView::OnToggleSpellCheck() {
1095 if (!webview())
1096 return;
1097
[email protected]26aa0482009-09-30 16:55:271098 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451099 frame->enableContinuousSpellChecking(
1100 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041101}
1102
initial.commit09911bf2008-07-26 23:55:291103void RenderView::OnDelete() {
1104 if (!webview())
1105 return;
1106
[email protected]26aa0482009-09-30 16:55:271107 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121108 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291109}
1110
1111void RenderView::OnSelectAll() {
1112 if (!webview())
1113 return;
1114
[email protected]26aa0482009-09-30 16:55:271115 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221116 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121117 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291118}
1119
1120void RenderView::OnSetInitialFocus(bool reverse) {
1121 if (!webview())
1122 return;
[email protected]26aa0482009-09-30 16:55:271123 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291124}
1125
1126///////////////////////////////////////////////////////////////////////////////
1127
[email protected]433819d2010-01-30 20:20:011128void RenderView::SetContentSettings(const ContentSettings& settings) {
1129 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011130}
1131
initial.commit09911bf2008-07-26 23:55:291132// Tell the embedding application that the URL of the active page has changed
1133void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451134 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291135 DCHECK(ds);
1136
[email protected]726985e22009-06-18 21:09:281137 const WebURLRequest& request = ds->request();
1138 const WebURLRequest& original_request = ds->originalRequest();
1139 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291140
[email protected]daa8c58e2009-06-15 17:21:101141 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1142 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291143
1144 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281145 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291146 params.is_post = false;
1147 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281148 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551149 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291150 // SSL state specified in the request takes precedence over the one in the
1151 // response.
1152 // So far this is only intended for error pages that are not expected to be
1153 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281154 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551155 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291156 } else {
[email protected]726985e22009-06-18 21:09:281157 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291158 }
1159
1160 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281161 if (ds->hasUnreachableURL()) {
1162 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291163 } else {
[email protected]726985e22009-06-18 21:09:281164 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291165 }
1166
[email protected]726985e22009-06-18 21:09:281167 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241168 params.should_update_history = !ds->hasUnreachableURL() &&
1169 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291170
[email protected]ce0e250d2009-10-23 21:00:351171 params.searchable_form_url = navigation_state->searchable_form_url();
1172 params.searchable_form_encoding =
1173 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291174
1175 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101176 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291177 if (password_form_data)
1178 params.password_form = *password_form_data;
1179
1180 params.gesture = navigation_gesture_;
1181 navigation_gesture_ = NavigationGestureUnknown;
1182
[email protected]dd7daa82009-08-10 05:46:451183 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291184 // Top-level navigation.
1185
[email protected]71b0d5d2010-02-15 05:43:071186 // Clear "block" flags for the new page. This needs to happen before any of
1187 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1188 // so that these functions can correctly detect that a piece of content
1189 // flipped from "not blocked" to "blocked".
1190 ClearBlockedContentSettings();
1191
[email protected]f85f0702010-01-30 09:31:011192 // Set content settings.
1193 HostContentSettings::iterator host_content_settings =
1194 host_content_settings_.find(GURL(request.url()).host());
1195 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011196 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011197
1198 // These content settings were merely recorded transiently for this load.
1199 // We can erase them now. If at some point we reload this page, the
1200 // browser will send us new, up-to-date content settings.
1201 host_content_settings_.erase(host_content_settings);
1202 }
1203
[email protected]40bd6582009-12-04 23:49:511204 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011205 HostZoomLevels::iterator host_zoom =
[email protected]40bd6582009-12-04 23:49:511206 host_zoom_levels_.find(GURL(request.url()).host());
[email protected]f85f0702010-01-30 09:31:011207 if (host_zoom != host_zoom_levels_.end()) {
1208 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511209 // This zoom level was merely recorded transiently for this load. We can
1210 // erase it now. If at some point we reload this page, the browser will
1211 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011212 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511213 }
1214
initial.commit09911bf2008-07-26 23:55:291215 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551216 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291217
[email protected]daa8c58e2009-06-15 17:21:101218 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291219 if (!PageTransition::IsMainFrame(params.transition)) {
1220 // If the main frame does a load, it should not be reported as a subframe
1221 // navigation. This can occur in the following case:
1222 // 1. You're on a site with frames.
1223 // 2. You do a subframe navigation. This is stored with transition type
1224 // MANUAL_SUBFRAME.
1225 // 3. You navigate to some non-frame site, say, google.com.
1226 // 4. You navigate back to the page from step 2. Since it was initially
1227 // MANUAL_SUBFRAME, it will be that same transition type here.
1228 // We don't want that, because any navigation that changes the toplevel
1229 // frame should be tracked as a toplevel navigation (this allows us to
1230 // update the URL bar, etc).
1231 params.transition = PageTransition::LINK;
1232 }
1233
initial.commit09911bf2008-07-26 23:55:291234 // If we have a valid consumed client redirect source,
1235 // the page contained a client redirect (meta refresh, document.loc...),
1236 // so we set the referrer and transition to match.
1237 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041238 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291239 params.referrer = completed_client_redirect_src_;
1240 params.transition = static_cast<PageTransition::Type>(
1241 params.transition | PageTransition::CLIENT_REDIRECT);
1242 } else {
1243 // Bug 654101: the referrer will be empty on https->http transitions. It
1244 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281245 params.referrer = GURL(
1246 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291247 }
1248
[email protected]726985e22009-06-18 21:09:281249 string16 method = request.httpMethod();
1250 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291251 params.is_post = true;
1252
[email protected]c2a797d2009-09-21 16:46:321253 // Save some histogram data so we can compute the average memory used per
1254 // page load of the glyphs.
1255 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1256 webkit_glue::GetGlyphPageCount());
1257
[email protected]15cf526b2010-02-12 06:33:491258 // This message needs to be sent before any of allowScripts(),
1259 // allowImages(), allowPlugins() is called for the new page, so that when
1260 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1261 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291262 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1263 } else {
1264 // Subframe navigation: the type depends on whether this navigation
1265 // generated a new session history entry. When they do generate a session
1266 // history entry, it means the user initiated the navigation and we should
1267 // mark it as such. This test checks if this is the first time UpdateURL
1268 // has been called since WillNavigateToURL was called to initiate the load.
1269 if (page_id_ > last_page_id_sent_to_browser_)
1270 params.transition = PageTransition::MANUAL_SUBFRAME;
1271 else
1272 params.transition = PageTransition::AUTO_SUBFRAME;
1273
initial.commit09911bf2008-07-26 23:55:291274 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1275 }
1276
1277 last_page_id_sent_to_browser_ =
1278 std::max(last_page_id_sent_to_browser_, page_id_);
1279
1280 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101281 // we don't want the transition type to persist. Just clear it.
1282 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501283
[email protected]6c8afae52009-01-22 02:24:571284#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151285 if (accessibility_.get()) {
[email protected]17455962010-02-24 01:39:351286 // Remove accessibility info cache.
1287 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501288 }
[email protected]6c8afae52009-01-22 02:24:571289#else
[email protected]7d926f92009-03-03 14:26:541290 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571291#endif
initial.commit09911bf2008-07-26 23:55:291292}
1293
1294// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171295void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291296 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171297 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171298 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171299 routing_id_,
1300 page_id_,
1301 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1302 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171303 }
initial.commit09911bf2008-07-26 23:55:291304}
1305
1306void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401307 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291308 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271309 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291310 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301311 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291312 last_encoding_name_ = encoding_name;
1313
[email protected]e38f40152008-09-12 23:08:301314 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291315 }
1316}
1317
[email protected]f4d34b52008-11-24 23:05:011318// Sends the previous session history state to the browser so it will be saved
1319// before we navigate to a new page. This must be called *before* the page ID
1320// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291321void RenderView::UpdateSessionHistory(WebFrame* frame) {
1322 // If we have a valid page ID at this point, then it corresponds to the page
1323 // we are navigating away from. Otherwise, this is the first navigation, so
1324 // there is no past session history to record.
1325 if (page_id_ == -1)
1326 return;
1327
[email protected]ca948a22009-06-25 19:36:171328 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271329 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171330 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291331 return;
[email protected]ca948a22009-06-25 19:36:171332
1333 Send(new ViewHostMsg_UpdateState(
1334 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291335}
1336
[email protected]3d9689372009-09-10 04:29:171337void RenderView::OpenURL(
1338 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1339 Send(new ViewHostMsg_OpenURL(
1340 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1341}
1342
[email protected]79dbc662009-09-04 05:42:511343// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291344
initial.commit09911bf2008-07-26 23:55:291345void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281346 const WebURLRequest& failed_request,
1347 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291348 const std::string& html,
1349 bool replace) {
[email protected]726985e22009-06-18 21:09:281350 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291351
1352 std::string alt_html;
1353 if (html.empty()) {
1354 // Use a local error page.
1355 int resource_id;
1356 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281357 if (error.reason == net::ERR_CACHE_MISS &&
1358 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291359 GetFormRepostErrorValues(failed_url, &error_strings);
1360 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1361 } else {
1362 GetLocalizedErrorValues(error, &error_strings);
1363 resource_id = IDR_NET_ERROR_HTML;
1364 }
initial.commit09911bf2008-07-26 23:55:291365
1366 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1367 } else {
1368 alt_html = html;
1369 }
1370
[email protected]dd7daa82009-08-10 05:46:451371 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551372 GURL(kUnreachableWebDataURL),
1373 failed_url,
1374 replace);
initial.commit09911bf2008-07-26 23:55:291375}
1376
[email protected]7ccddb8c2009-08-04 17:36:551377void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291378 dom_automation_controller_.set_message_sender(this);
1379 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551380 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291381 L"domAutomationController");
1382}
1383
initial.commit09911bf2008-07-26 23:55:291384bool RenderView::RunJavaScriptMessage(int type,
1385 const std::wstring& message,
1386 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071387 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291388 std::wstring* result) {
1389 bool success = false;
1390 std::wstring result_temp;
1391 if (!result)
1392 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291393
[email protected]12636df2009-09-28 22:32:211394 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1395 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291396 return success;
1397}
1398
[email protected]c1f50aa2010-02-18 03:46:571399bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1400 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1401 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1402 // it is particularly important that we do not call willEnterModalLoop as
1403 // that would defer resource loads for the dialog itself.
1404 if (RenderThread::current()) // Will be NULL during unit tests.
1405 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1406
1407 message->EnableMessagePumping(); // Runs a nested message loop.
1408 return Send(message);
1409}
1410
initial.commit09911bf2008-07-26 23:55:291411void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1412 if (!osd_url.is_empty())
1413 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1414 autodetected));
1415}
1416
[email protected]95056b582010-02-18 01:29:241417void RenderView::OnAutoFillSuggestionsReturned(
1418 int query_id,
1419 const std::vector<string16>& names,
1420 const std::vector<string16>& labels,
1421 int default_suggestion_index) {
1422 if (webview() && query_id == autofill_query_id_) {
1423 webview()->applyAutoFillSuggestions(
1424 autofill_query_node_, names, labels, default_suggestion_index);
1425 }
1426 autofill_query_node_.reset();
1427}
1428
1429void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a1f2009-10-16 03:53:391430 int query_id,
1431 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031432 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181433 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081434 webview()->applyAutocompleteSuggestions(
[email protected]acca2a1f2009-10-16 03:53:391435 autofill_query_node_, suggestions, default_suggestion_index);
1436 }
1437 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031438}
1439
[email protected]45c6e532010-03-15 23:51:241440void RenderView::OnAutoFillFormDataFilled(int query_id,
1441 const webkit_glue::FormData& form) {
[email protected]c83641732010-02-20 01:04:481442 if (query_id != autofill_query_id_)
1443 return;
1444
1445 form_manager_.FillForm(form);
1446}
1447
[email protected]2c4410d2009-05-06 23:46:221448void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311449 popup_notification_visible_ = visible;
1450}
1451
initial.commit09911bf2008-07-26 23:55:291452uint32 RenderView::GetCPBrowsingContext() {
1453 uint32 context = 0;
1454 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1455 return context;
1456}
1457
initial.commit09911bf2008-07-26 23:55:291458void RenderView::AddSearchProvider(const std::string& url) {
1459 AddGURLSearchProvider(GURL(url),
1460 false); // not autodetected
1461}
1462
[email protected]f103ab72009-09-02 17:10:591463void RenderView::OnMissingPluginStatus(
1464 WebPluginDelegateProxy* delegate,
1465 int status) {
[email protected]6c8afae52009-01-22 02:24:571466#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591467 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291468 // Show the InfoBar for the first available plugin.
1469 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591470 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291471 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1472 }
1473 } else {
1474 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1475 // to start the download/install.
1476 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1477 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1478 }
1479 }
[email protected]6c8afae52009-01-22 02:24:571480#else
1481 // TODO(port): plugins current not supported
1482 NOTIMPLEMENTED();
1483#endif
initial.commit09911bf2008-07-26 23:55:291484}
1485
[email protected]48c9cf2d2009-09-16 16:47:521486// WebKit::WebViewClient ------------------------------------------------------
1487
1488WebView* RenderView::createView(WebFrame* creator) {
1489 // Check to make sure we aren't overloading on popups.
1490 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1491 return NULL;
1492
1493 // This window can't be closed from a window.close() call until we receive a
1494 // message from the Browser process explicitly allowing it.
1495 popup_notification_visible_ = true;
1496
1497 int32 routing_id = MSG_ROUTING_NONE;
1498 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461499 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341500 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521501
[email protected]48c9cf2d2009-09-16 16:47:521502 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341503 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1504 session_storage_namespace_id_,
1505 &routing_id,
1506 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211507 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521508 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521509
[email protected]48c9cf2d2009-09-16 16:47:521510 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421511 0,
[email protected]12636df2009-09-28 22:32:211512 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521513 renderer_preferences_,
1514 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211515 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341516 routing_id,
1517 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521518 view->opened_by_user_gesture_ = user_gesture;
1519
[email protected]007a848b2009-10-26 15:55:461520 // Record whether the creator frame is trying to suppress the opener field.
1521 view->opener_suppressed_ = opener_suppressed;
1522
[email protected]48c9cf2d2009-09-16 16:47:521523 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091524 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521525 if (!creator_url.is_valid() || !creator_url.IsStandard())
1526 creator_url = GURL();
1527 view->creator_url_ = creator_url;
1528
1529 // Copy over the alternate error page URL so we can have alt error pages in
1530 // the new render view (we don't need the browser to send the URL back down).
1531 view->alternate_error_page_url_ = alternate_error_page_url_;
1532
1533 return view->webview();
1534}
1535
1536WebWidget* RenderView::createPopupMenu(bool activatable) {
1537 RenderWidget* widget = RenderWidget::Create(routing_id_,
1538 render_thread_,
1539 activatable);
1540 return widget->webwidget();
1541}
1542
1543WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1544 RenderWidget* widget = RenderWidget::Create(routing_id_,
1545 render_thread_,
1546 true);
1547 widget->ConfigureAsExternalPopupMenu(info);
1548 return widget->webwidget();
1549}
1550
[email protected]bd92c3a2010-01-13 05:02:341551WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1552 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1553 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291554 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1555 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1556 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341557}
1558
[email protected]48c9cf2d2009-09-16 16:47:521559void RenderView::didAddMessageToConsole(
1560 const WebConsoleMessage& message, const WebString& source_name,
1561 unsigned source_line) {
1562 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1563 UTF16ToWideHack(message.text),
1564 static_cast<int32>(source_line),
1565 UTF16ToWideHack(source_name)));
1566}
1567
1568void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581569 DCHECK(frame);
1570 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521571}
1572
1573void RenderView::didStartLoading() {
1574 if (is_loading_) {
1575 DLOG(WARNING) << "didStartLoading called while loading";
1576 return;
1577 }
1578
1579 is_loading_ = true;
1580 // Clear the pointer so that we can assign it only when there is an unknown
1581 // plugin on a page.
1582 first_default_plugin_.reset();
1583
1584 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1585}
1586
1587void RenderView::didStopLoading() {
1588 if (!is_loading_) {
1589 DLOG(WARNING) << "DidStopLoading called while not loading";
1590 return;
1591 }
1592
1593 is_loading_ = false;
1594
1595 // NOTE: For now we're doing the safest thing, and sending out notification
1596 // when done loading. This currently isn't an issue as the favicon is only
1597 // displayed when done loading. Ideally we would send notification when
1598 // finished parsing the head, but webkit doesn't support that yet.
1599 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271600 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521601 if (!favicon_url.is_empty())
1602 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1603
[email protected]26aa0482009-09-30 16:55:271604 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521605 true); // autodetected
1606
1607 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1608
[email protected]f9f4841b2010-03-20 05:41:421609 MessageLoop::current()->PostDelayedTask(
1610 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521611 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1612 false),
1613 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521614}
1615
[email protected]f55039a2010-02-17 14:12:061616bool RenderView::isSmartInsertDeleteEnabled() {
1617#if defined(OS_MACOSX)
1618 return true;
1619#else
1620 return false;
1621#endif
1622}
1623
[email protected]04fc9482009-09-18 22:13:031624bool RenderView::isSelectTrailingWhitespaceEnabled() {
1625#if defined(OS_WIN)
1626 return true;
1627#else
1628 return false;
1629#endif
1630}
1631
1632void RenderView::setInputMethodEnabled(bool enabled) {
1633 // Save the updated IME status and mark the input focus has been updated.
1634 // The IME status is to be sent to a browser process next time when
1635 // the input caret is rendered.
1636 if (!ime_control_busy_) {
1637 ime_control_updated_ = true;
1638 ime_control_new_state_ = enabled;
1639 }
1640}
1641
1642void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031643#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031644 if (!handling_input_event_)
1645 return;
1646 // TODO(estade): investigate incremental updates to the selection so that we
1647 // don't send the entire selection over IPC every time.
1648 if (!is_empty_selection) {
1649 // Sometimes we get repeated didChangeSelection calls from webkit when
1650 // the selection hasn't actually changed. We don't want to report these
1651 // because it will cause us to continually claim the X clipboard.
1652 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271653 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031654 if (this_selection == last_selection_)
1655 return;
1656
1657 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1658 this_selection));
1659 last_selection_ = this_selection;
1660 } else {
1661 last_selection_.clear();
1662 }
1663#endif
1664}
1665
1666void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121667 const std::string& name = UTF16ToUTF8(command_name);
1668 if (StartsWithASCII(name, "Move", true) ||
1669 StartsWithASCII(name, "Insert", true) ||
1670 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031671 return;
1672 UserMetricsRecordAction(name);
1673}
1674
[email protected]b2528b72009-09-24 06:57:101675bool RenderView::handleCurrentKeyboardEvent() {
1676 if (edit_commands_.empty())
1677 return false;
1678
[email protected]26aa0482009-09-30 16:55:271679 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101680 if (!frame)
1681 return false;
1682
1683 EditCommands::iterator it = edit_commands_.begin();
1684 EditCommands::iterator end = edit_commands_.end();
1685
[email protected]507b33ea2009-09-29 03:56:511686 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101687 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331688 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1689 // key (but it's the exception). Once one edit command is not executed, it
1690 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101691 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1692 WebString::fromUTF8(it->value)))
1693 break;
[email protected]507b33ea2009-09-29 03:56:511694 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101695 }
1696
[email protected]507b33ea2009-09-29 03:56:511697 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101698}
1699
[email protected]2a3a7762009-10-19 19:17:321700void RenderView::spellCheck(const WebString& text,
1701 int& misspelled_offset,
1702 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561703 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461704
[email protected]85c55dc2009-11-06 03:05:461705 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171706 RenderThread* thread = RenderThread::current();
1707 // Will be NULL during unit tests.
1708 if (thread) {
[email protected]c27324b2009-11-19 22:44:291709 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171710 word.c_str(), word.size(), document_tag_,
1711 &misspelled_offset, &misspelled_length, NULL);
1712 }
[email protected]1dbafaf72009-09-23 19:43:561713}
1714
1715WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321716 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561717 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261718 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561719 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171720 RenderThread* thread = RenderThread::current();
1721 // Will be NULL during unit tests.
1722 if (thread) {
1723 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291724 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171725 word, document_tag_);
1726 }
[email protected]1dbafaf72009-09-23 19:43:561727 }
[email protected]2a3a7762009-10-19 19:17:321728 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561729}
1730
[email protected]c49085c72009-10-02 16:28:561731void RenderView::showSpellingUI(bool show) {
1732 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1733}
1734
[email protected]8922e1f2009-10-03 05:01:261735bool RenderView::isShowingSpellingUI() {
1736 return spelling_panel_visible_;
1737}
1738
[email protected]1dbafaf72009-09-23 19:43:561739void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321740 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1741 word));
[email protected]1dbafaf72009-09-23 19:43:561742}
1743
[email protected]a1128322009-10-06 18:38:461744bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351745 const WebKit::WebFileChooserParams& params,
[email protected]a1128322009-10-06 18:38:461746 WebKit::WebFileChooserCompletion* chooser_completion) {
1747 if (file_chooser_completion_) {
1748 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1749 // with the fact that web pages can programatically trigger this. With the
1750 // asnychronous messages, we can get an additional call when one is pending,
1751 // which this test is for. For now, we just ignore the additional file
1752 // chooser request. WebKit doesn't do anything to expect the callback, so
1753 // we can just ignore calling it.
1754 return false;
1755 }
1756 file_chooser_completion_ = chooser_completion;
1757 Send(new ViewHostMsg_RunFileChooser(
[email protected]01178b52010-01-15 06:59:351758 routing_id_, params.multiSelect, params.title,
1759 webkit_glue::WebStringToFilePath(params.initialValue)));
[email protected]a1128322009-10-06 18:38:461760 return true;
1761}
1762
[email protected]48c9cf2d2009-09-16 16:47:521763void RenderView::runModalAlertDialog(
1764 WebFrame* frame, const WebString& message) {
1765 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1766 UTF16ToWideHack(message),
1767 std::wstring(),
1768 frame->url(),
1769 NULL);
1770}
1771
1772bool RenderView::runModalConfirmDialog(
1773 WebFrame* frame, const WebString& message) {
1774 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1775 UTF16ToWideHack(message),
1776 std::wstring(),
1777 frame->url(),
1778 NULL);
1779}
1780
1781bool RenderView::runModalPromptDialog(
1782 WebFrame* frame, const WebString& message, const WebString& default_value,
1783 WebString* actual_value) {
1784 std::wstring result;
1785 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1786 UTF16ToWideHack(message),
1787 UTF16ToWideHack(default_value),
1788 frame->url(),
1789 &result);
1790 if (ok)
1791 actual_value->assign(WideToUTF16Hack(result));
1792 return ok;
1793}
1794
1795bool RenderView::runModalBeforeUnloadDialog(
1796 WebFrame* frame, const WebString& message) {
1797 bool success = false;
1798 // This is an ignored return value, but is included so we can accept the same
1799 // response as RunJavaScriptMessage.
1800 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211801 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521802 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211803 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521804 return success;
1805}
1806
[email protected]79e37442009-10-09 18:17:441807void RenderView::showContextMenu(
1808 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291809 ContextMenuParams params = ContextMenuParams(data);
1810 if (!params.misspelled_word.empty() && RenderThread::current()) {
1811 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041812 bool spelled_right = RenderThread::current()->spellchecker()->
1813 SpellCheckWord(
1814 params.misspelled_word.c_str(), params.misspelled_word.size(),
1815 document_tag_,
1816 &misspelled_offset, &misspelled_length,
1817 &params.dictionary_suggestions);
1818 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291819 params.misspelled_word.clear();
1820 }
1821
1822 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441823}
1824
[email protected]48c9cf2d2009-09-16 16:47:521825void RenderView::setStatusText(const WebString& text) {
1826}
1827
[email protected]163f8242009-10-30 20:19:551828void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1829 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521830 if (latest_url == target_url_)
1831 return;
[email protected]163f8242009-10-30 20:19:551832
[email protected]48c9cf2d2009-09-16 16:47:521833 // Tell the browser to display a destination link.
1834 if (target_url_status_ == TARGET_INFLIGHT ||
1835 target_url_status_ == TARGET_PENDING) {
1836 // If we have a request in-flight, save the URL to be sent when we
1837 // receive an ACK to the in-flight request. We can happily overwrite
1838 // any existing pending sends.
1839 pending_target_url_ = latest_url;
1840 target_url_status_ = TARGET_PENDING;
1841 } else {
1842 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1843 target_url_ = latest_url;
1844 target_url_status_ = TARGET_INFLIGHT;
1845 }
1846}
1847
[email protected]882daa92009-11-05 16:31:311848void RenderView::StartNavStateSyncTimerIfNecessary() {
1849 int delay;
1850 if (send_content_state_immediately_)
1851 delay = 0;
1852 else if (is_hidden())
1853 delay = kDelaySecondsForContentStateSyncHidden;
1854 else
1855 delay = kDelaySecondsForContentStateSync;
1856
1857 if (nav_state_sync_timer_.IsRunning()) {
1858 // The timer is already running. If the delay of the timer maches the amount
1859 // we want to delay by, then return. Otherwise stop the timer so that it
1860 // gets started with the right delay.
1861 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1862 return;
1863 nav_state_sync_timer_.Stop();
1864 }
1865
1866 nav_state_sync_timer_.Start(
1867 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1868}
1869
[email protected]163f8242009-10-30 20:19:551870void RenderView::setMouseOverURL(const WebURL& url) {
1871 mouse_over_url_ = GURL(url);
1872 UpdateTargetURL(mouse_over_url_, focus_url_);
1873}
1874
1875void RenderView::setKeyboardFocusURL(const WebURL& url) {
1876 focus_url_ = GURL(url);
1877 UpdateTargetURL(focus_url_, mouse_over_url_);
1878}
1879
[email protected]48c9cf2d2009-09-16 16:47:521880void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1881 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1882 hint));
1883}
1884
[email protected]49fd9da2010-03-17 21:00:471885void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1886 WebDragOperationsMask allowed_ops) {
[email protected]c27ae592010-03-18 15:24:411887 startDragging(data, allowed_ops, WebImage(), WebPoint());
1888}
1889
1890void RenderView::startDragging(const WebDragData& data,
1891 WebDragOperationsMask mask,
1892 const WebImage& image,
1893 const WebPoint& imageOffset) {
1894#if WEBKIT_USING_SKIA
1895 SkBitmap bitmap(image.getSkBitmap());
1896#elif WEBKIT_USING_CG
1897 // Needs implementing: http://crbug.com/11457
1898 SkBitmap bitmap;
1899#endif
1900
[email protected]48c9cf2d2009-09-16 16:47:521901 Send(new ViewHostMsg_StartDragging(routing_id_,
1902 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411903 mask,
1904 bitmap,
1905 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521906}
1907
[email protected]28b92df2009-09-25 17:35:451908bool RenderView::acceptsLoadDrops() {
1909 return renderer_preferences_.can_accept_load_drops;
1910}
1911
[email protected]48c9cf2d2009-09-16 16:47:521912void RenderView::focusNext() {
1913 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1914}
1915
1916void RenderView::focusPrevious() {
1917 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1918}
1919
1920void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521921 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1922}
1923
1924int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001925 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521926}
1927
1928int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001929 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521930}
1931
[email protected]8922e1f2009-10-03 05:01:261932void RenderView::didUpdateInspectorSettings() {
1933 Send(new ViewHostMsg_UpdateInspectorSettings(
1934 routing_id_, webview()->inspectorSettings().utf8()));
1935}
1936
[email protected]acca2a1f2009-10-16 03:53:391937void RenderView::queryAutofillSuggestions(const WebNode& node,
1938 const WebString& name,
1939 const WebString& value) {
1940 static int query_counter = 0;
1941 autofill_query_id_ = query_counter++;
1942 autofill_query_node_ = node;
[email protected]95056b582010-02-18 01:29:241943 const WebKit::WebInputElement input_element =
1944 node.toConstElement<WebInputElement>();
[email protected]acca2a1f2009-10-16 03:53:391945 Send(new ViewHostMsg_QueryFormFieldAutofill(
[email protected]95056b582010-02-18 01:29:241946 routing_id_, autofill_query_id_, FormField(input_element)));
[email protected]acca2a1f2009-10-16 03:53:391947}
1948
1949void RenderView::removeAutofillSuggestions(const WebString& name,
1950 const WebString& value) {
1951 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1952}
1953
[email protected]c83641732010-02-20 01:04:481954void RenderView::didAcceptAutoFillSuggestion(
1955 const WebKit::WebNode& node,
1956 const WebKit::WebString& name,
1957 const WebKit::WebString& label) {
1958 static int query_counter = 0;
1959 autofill_query_id_ = query_counter++;
1960
[email protected]45c6e532010-03-15 23:51:241961 webkit_glue::FormData form;
[email protected]c83641732010-02-20 01:04:481962 const WebInputElement element = node.toConstElement<WebInputElement>();
1963 if (!form_manager_.FindForm(element, &form))
1964 return;
1965
1966 Send(new ViewHostMsg_FillAutoFillFormData(
1967 routing_id_, autofill_query_id_, form, name, label));
1968}
1969
[email protected]79dbc662009-09-04 05:42:511970// WebKit::WebWidgetClient ----------------------------------------------------
1971
initial.commit09911bf2008-07-26 23:55:291972// We are supposed to get a single call to Show for a newly created RenderView
1973// that was created via RenderView::CreateWebView. So, we wait until this
1974// point to dispatch the ShowView message.
1975//
1976// This method provides us with the information about how to display the newly
1977// created RenderView (i.e., as a constrained popup or as a new tab).
1978//
[email protected]4873c7d2009-07-16 06:36:281979void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291980 DCHECK(!did_show_) << "received extraneous Show call";
1981 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1982
1983 if (did_show_)
1984 return;
1985 did_show_ = true;
1986
[email protected]28295ec2009-10-16 05:34:331987 // Force new windows to a popup if they were not opened with a user gesture.
1988 if (!opened_by_user_gesture_) {
1989 // We exempt background tabs for compat with older versions of Chrome.
1990 // TODO(darin): This seems bogus. These should have a user gesture, so
1991 // we probably don't need this check.
1992 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1993 policy = WebKit::WebNavigationPolicyNewPopup;
1994 }
1995
initial.commit09911bf2008-07-26 23:55:291996 // NOTE: initial_pos_ may still have its default values at this point, but
1997 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1998 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281999 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2000 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292001 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242002 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292003}
2004
[email protected]4873c7d2009-07-16 06:36:282005void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222006 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282007 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312008}
2009
[email protected]4873c7d2009-07-16 06:36:282010void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292011 DCHECK(did_show_) << "should already have shown the view";
2012
[email protected]c1f50aa2010-02-18 03:46:572013 // We must keep WebKit's shared timer running in this case in order to allow
2014 // showModalDialog to function properly.
2015 //
2016 // TODO(darin): WebKit should really be smarter about suppressing events and
2017 // timers so that we do not need to manage the shared timer in such a heavy
2018 // handed manner.
2019 //
2020 if (RenderThread::current()) // Will be NULL during unit tests.
2021 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2022
[email protected]12636df2009-09-28 22:32:212023 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292024}
2025
[email protected]3d9689372009-09-10 04:29:172026// WebKit::WebFrameClient -----------------------------------------------------
2027
2028WebPlugin* RenderView::createPlugin(
2029 WebFrame* frame, const WebPluginParams& params) {
2030 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2031}
2032
2033WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2034 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
2035}
2036
[email protected]9c00f002009-11-05 22:37:422037WebSharedWorker* RenderView::createSharedWorker(
2038 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372039 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422040
[email protected]30447b62009-11-13 01:13:372041 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512042 bool exists = false;
[email protected]30447b62009-11-13 01:13:372043 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512044 ViewHostMsg_CreateWorker_Params params;
2045 params.url = url;
2046 params.is_shared = true;
2047 params.name = name;
2048 params.document_id = document_id;
2049 params.render_view_route_id = routing_id_;
2050 params.route_id = MSG_ROUTING_NONE;
[email protected]30447b62009-11-13 01:13:372051 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512052 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372053 if (url_mismatch) {
2054 return NULL;
2055 } else {
2056 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492057 document_id,
[email protected]6de0bcf2010-02-17 22:00:512058 exists,
[email protected]30447b62009-11-13 01:13:372059 route_id,
2060 routing_id_);
2061 }
[email protected]9c00f002009-11-05 22:37:422062}
2063
[email protected]3d9689372009-09-10 04:29:172064WebMediaPlayer* RenderView::createMediaPlayer(
2065 WebFrame* frame, WebMediaPlayerClient* client) {
2066 scoped_refptr<media::FilterFactoryCollection> factory =
2067 new media::FilterFactoryCollection();
2068 // Add in any custom filter factories first.
2069 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2070 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2071 // Add the chrome specific audio renderer.
2072 factory->AddFactory(
2073 AudioRendererImpl::CreateFactory(audio_message_filter()));
2074 }
2075
[email protected]80f584d92010-01-21 03:59:042076 WebApplicationCacheHostImpl* appcache_host =
2077 WebApplicationCacheHostImpl::FromFrame(frame);
2078
[email protected]3d9689372009-09-10 04:29:172079 // TODO(hclam): obtain the following parameters from |client|.
2080 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2081 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152082 GURL(), // referrer
2083 "null", // frame origin
2084 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172085 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042086 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172087 routing_id());
2088
[email protected]0436b9a2009-10-23 00:23:052089 // A simple data source that keeps all data in memory.
2090 media::FilterFactory* simple_data_source_factory =
2091 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2092 bridge_factory);
2093 // A sophisticated data source that does memory caching.
2094 media::FilterFactory* buffered_data_source_factory =
2095 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2096 bridge_factory);
2097 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2098 factory->AddFactory(simple_data_source_factory);
2099 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172100 } else {
[email protected]0436b9a2009-10-23 00:23:052101 factory->AddFactory(buffered_data_source_factory);
2102 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172103 }
[email protected]8400e032010-02-26 18:50:112104
2105 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2106 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2107 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2108 } else {
2109 factory_factory = new webkit_glue::VideoRendererImpl::FactoryFactory();
2110 }
2111
2112 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172113}
2114
[email protected]b921cfd22010-02-25 16:57:512115WebCookieJar* RenderView::cookieJar() {
2116 return &cookie_jar_;
2117}
2118
[email protected]3d9689372009-09-10 04:29:172119void RenderView::willClose(WebFrame* frame) {
2120 if (!frame->parent()) {
2121 const GURL& url = frame->url();
2122 if (url.SchemeIs("http") || url.SchemeIs("https"))
2123 DumpLoadHistograms();
2124 }
[email protected]fa7b6b542009-11-03 05:02:302125
2126 WebDataSource* ds = frame->dataSource();
2127 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2128 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172129}
2130
[email protected]684e4a42010-01-30 06:44:112131bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002132 if (!enabled_per_settings)
2133 return false;
[email protected]c21f1d52010-03-04 03:19:432134 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112135}
2136
2137bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002138 if (!enabled_per_settings)
2139 return false;
2140 if (!AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) {
2141 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2142 return false;
2143 }
2144 return true;
[email protected]684e4a42010-01-30 06:44:112145}
2146
[email protected]3d9689372009-09-10 04:29:172147void RenderView::loadURLExternally(
2148 WebFrame* frame, const WebURLRequest& request,
2149 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592150 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2151 if (policy == WebKit::WebNavigationPolicyDownload) {
2152 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2153 } else {
2154 OpenURL(request.url(), referrer, policy);
2155 }
[email protected]3d9689372009-09-10 04:29:172156}
2157
2158WebNavigationPolicy RenderView::decidePolicyForNavigation(
2159 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222160 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172161 // Webkit is asking whether to navigate to a new URL.
2162 // This is fine normally, except if we're showing UI from one security
2163 // context and they're trying to navigate to a different context.
2164 const GURL& url = request.url();
2165
2166 // If the browser is interested, then give it a chance to look at top level
2167 // navigations
2168 if (renderer_preferences_.browser_handles_top_level_requests &&
2169 // Only send once.
2170 last_top_level_navigation_page_id_ != page_id_ &&
2171 // Not interested in reloads.
2172 type != WebKit::WebNavigationTypeReload &&
2173 type != WebKit::WebNavigationTypeFormSubmitted &&
2174 // Must be a top level frame.
2175 frame->parent() == NULL) {
2176 // Skip if navigation is on the same page (using '#').
2177 GURL frame_origin = GURL(frame->url()).GetOrigin();
2178 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
2179 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:572180 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2181 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:172182 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2183 }
2184 }
2185
2186 // A content initiated navigation may have originated from a link-click,
2187 // script, drag-n-drop operation, etc.
2188 bool is_content_initiated =
2189 NavigationState::FromDataSource(frame->provisionalDataSource())->
2190 is_content_initiated();
2191
2192 // We only care about navigations that are within the current tab (as opposed
2193 // to, for example, opening a new window).
2194 // But we sometimes navigate to about:blank to clear a tab, and we want to
2195 // still allow that.
2196 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2197 is_content_initiated && frame->parent() == NULL &&
2198 !url.SchemeIs(chrome::kAboutScheme)) {
2199 // When we received such unsolicited navigations, we sometimes want to
2200 // punt them up to the browser to handle.
2201 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2202 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2203 frame->isViewSourceModeEnabled() ||
2204 url.SchemeIs(chrome::kViewSourceScheme) ||
2205 url.SchemeIs(chrome::kPrintScheme)) {
2206 OpenURL(url, GURL(), default_policy);
2207 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2208 }
2209 }
2210
2211 // Detect when a page is "forking" a new tab that can be safely rendered in
2212 // its own process. This is done by sites like Gmail that try to open links
2213 // in new windows without script connections back to the original page. We
2214 // treat such cases as browser navigations (in which we will create a new
2215 // renderer for a cross-site navigation), rather than WebKit navigations.
2216 //
2217 // We use the following heuristic to decide whether to fork a new page in its
2218 // own process:
2219 // The parent page must open a new tab to about:blank, set the new tab's
2220 // window.opener to null, and then redirect the tab to a cross-site URL using
2221 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462222 //
2223 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2224 // (see below).
[email protected]3d9689372009-09-10 04:29:172225 bool is_fork =
2226 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252227 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172228 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522229 historyBackListCount() < 1 &&
2230 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172231 // The parent page must have set the child's window.opener to null before
2232 // redirecting to the desired URL.
2233 frame->opener() == NULL &&
2234 // Must be a top-level frame.
2235 frame->parent() == NULL &&
2236 // Must not have issued the request from this page.
2237 is_content_initiated &&
2238 // Must be targeted at the current tab.
2239 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2240 // Must be a JavaScript navigation, which appears as "other".
2241 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462242
2243 // Recognize if this navigation is from a link with rel=noreferrer and
2244 // target=_blank attributes, in which case the opener will be suppressed. If
2245 // so, it is safe to load cross-site pages in a separate process, so we
2246 // should let the browser handle it.
2247 bool is_noreferrer_and_blank_target =
2248 // Frame should be top level and not yet navigated.
2249 frame->parent() == NULL &&
2250 frame->url().isEmpty() &&
2251 historyBackListCount() < 1 &&
2252 historyForwardListCount() < 1 &&
2253 // Links with rel=noreferrer will have no Referer field, and their
2254 // resulting frame will have its window.opener suppressed.
2255 // TODO(creis): should add a request.httpReferrer() method to help avoid
2256 // typos on the unusual spelling of Referer.
2257 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2258 opener_suppressed_ &&
2259 frame->opener() == NULL &&
2260 // Links with target=_blank will have no name.
2261 frame->name().isNull() &&
2262 // Another frame (with a non-empty creator) should have initiated the
2263 // request, targeted at this frame.
2264 !creator_url_.is_empty() &&
2265 is_content_initiated &&
2266 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2267 type == WebKit::WebNavigationTypeOther;
2268
2269 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172270 // Open the URL via the browser, not via WebKit.
2271 OpenURL(url, GURL(), default_policy);
2272 return WebKit::WebNavigationPolicyIgnore;
2273 }
2274
2275 return default_policy;
2276}
2277
[email protected]6069da8c2009-10-20 20:33:492278bool RenderView::canHandleRequest(
2279 WebFrame* frame, const WebURLRequest& request) {
2280 // We allow WebKit to think that everything can be handled even though
2281 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342282 return true;
2283}
2284
[email protected]6069da8c2009-10-20 20:33:492285WebURLError RenderView::cannotHandleRequestError(
2286 WebFrame* frame, const WebURLRequest& request) {
2287 NOTREACHED(); // Since we said we can handle all requests.
2288 return WebURLError();
2289}
2290
2291WebURLError RenderView::cancelledError(
2292 WebFrame* frame, const WebURLRequest& request) {
2293 WebURLError error;
2294 error.domain = WebString::fromUTF8(net::kErrorDomain);
2295 error.reason = net::ERR_ABORTED;
2296 error.unreachableURL = request.url();
2297 return error;
[email protected]7b7a7dc2009-10-19 02:23:342298}
2299
2300void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492301 WebFrame*, const WebURLError&) {
2302 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342303}
2304
[email protected]979c28b2009-11-07 01:30:482305void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172306 NavigationState* navigation_state =
2307 NavigationState::FromDataSource(frame->provisionalDataSource());
2308
2309 if (navigation_state->transition_type() == PageTransition::LINK)
2310 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2311
2312 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352313 WebSearchableFormData web_searchable_form_data(form);
2314 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2315 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212316 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172317 navigation_state->set_password_form_data(
2318 PasswordFormDomManager::CreatePasswordForm(form));
2319
[email protected]979c28b2009-11-07 01:30:482320 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382321 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2322 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472323 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382324 *form_values));
[email protected]3d9689372009-09-10 04:29:172325 }
2326}
2327
2328void RenderView::willPerformClientRedirect(
2329 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2330 double fire_time) {
2331 // Ignore
2332}
2333
2334void RenderView::didCancelClientRedirect(WebFrame* frame) {
2335 // Ignore
2336}
2337
2338void RenderView::didCompleteClientRedirect(
2339 WebFrame* frame, const WebURL& from) {
2340 if (!frame->parent())
2341 completed_client_redirect_src_ = from;
2342}
2343
2344void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2345 // The rest of RenderView assumes that a WebDataSource will always have a
2346 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482347 bool content_initiated = !pending_navigation_state_.get();
2348 NavigationState* state = content_initiated ?
2349 NavigationState::CreateContentInitiated() :
2350 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182351 if (content_initiated) {
2352 switch (ds->request().cachePolicy()) {
2353 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2354 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2355 break;
2356 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2357 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2358 break;
2359 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2360 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2361 break;
2362 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2363 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2364 break;
2365 }
2366 }
[email protected]fa7b6b542009-11-03 05:02:302367
2368 state->set_user_script_idle_scheduler(
2369 new UserScriptIdleScheduler(this, frame));
2370 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172371}
2372
2373void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2374 WebDataSource* ds = frame->provisionalDataSource();
2375 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2376
2377 navigation_state->set_start_load_time(Time::Now());
2378
2379 // Update the request time if WebKit has better knowledge of it.
2380 if (navigation_state->request_time().is_null()) {
2381 double event_time = ds->triggeringEventTime();
2382 if (event_time != 0.0)
2383 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2384 }
2385
2386 bool is_top_most = !frame->parent();
2387 if (is_top_most) {
2388 navigation_gesture_ = frame->isProcessingUserGesture() ?
2389 NavigationGestureUnknown : NavigationGestureAuto;
2390
2391 // Make sure redirect tracking state is clear for the new load.
2392 completed_client_redirect_src_ = GURL();
2393 } else if (frame->parent()->isLoading()) {
2394 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002395 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172396 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2397 }
2398
2399 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2400 routing_id_, is_top_most, ds->request().url()));
2401}
2402
2403void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2404 if (frame->parent())
2405 return;
2406 // Received a redirect on the main frame.
2407 WebDataSource* data_source = frame->provisionalDataSource();
2408 if (!data_source) {
2409 // Should only be invoked when we have a data source.
2410 NOTREACHED();
2411 return;
2412 }
2413 std::vector<GURL> redirects;
2414 GetRedirectChain(data_source, &redirects);
2415 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512416 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2417 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172418 }
2419}
2420
[email protected]40bd6582009-12-04 23:49:512421void RenderView::didFailProvisionalLoad(WebFrame* frame,
2422 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172423 // Notify the browser that we failed a provisional load with an error.
2424 //
2425 // Note: It is important this notification occur before DidStopLoading so the
2426 // SSL manager can react to the provisional load failure before being
2427 // notified the load stopped.
2428 //
2429 WebDataSource* ds = frame->provisionalDataSource();
2430 DCHECK(ds);
2431
2432 const WebURLRequest& failed_request = ds->request();
2433
2434 bool show_repost_interstitial =
2435 (error.reason == net::ERR_CACHE_MISS &&
2436 EqualsASCII(failed_request.httpMethod(), "POST"));
2437 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2438 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2439 show_repost_interstitial));
2440
2441 // Don't display an error page if this is simply a cancelled load. Aside
2442 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2443 if (error.reason == net::ERR_ABORTED)
2444 return;
2445
2446 // Make sure we never show errors in view source mode.
2447 frame->enableViewSourceMode(false);
2448
2449 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2450
2451 // If this is a failed back/forward/reload navigation, then we need to do a
2452 // 'replace' load. This is necessary to avoid messing up session history.
2453 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2454 // as session history is concerned.
2455 //
2456 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2457 // the page id.
2458 //
2459 bool replace =
2460 navigation_state->pending_page_id() != -1 ||
2461 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2462
2463 // If we failed on a browser initiated request, then make sure that our error
2464 // page load is regarded as the same browser initiated request.
2465 if (!navigation_state->is_content_initiated()) {
2466 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2467 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002468 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172469 navigation_state->transition_type(),
2470 navigation_state->request_time()));
2471 }
2472
2473 // Provide the user with a more helpful error page?
2474 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2475 return;
2476
2477 // Fallback to a local error page.
2478 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2479 replace);
2480}
2481
2482void RenderView::didReceiveDocumentData(
2483 WebFrame* frame, const char* data, size_t data_len,
2484 bool& prevent_default) {
2485 NavigationState* navigation_state =
2486 NavigationState::FromDataSource(frame->dataSource());
2487 if (!navigation_state->postpone_loading_data())
2488 return;
2489
2490 // We're going to call commitDocumentData ourselves...
2491 prevent_default = true;
2492
2493 // Continue buffering the response data for the original 404 page. If it
2494 // grows too large, then we'll just let it through.
2495 navigation_state->append_postponed_data(data, data_len);
2496 if (navigation_state->postponed_data().size() >= 512) {
2497 navigation_state->set_postpone_loading_data(false);
2498 frame->commitDocumentData(navigation_state->postponed_data().data(),
2499 navigation_state->postponed_data().size());
2500 navigation_state->clear_postponed_data();
2501 }
2502}
2503
[email protected]40bd6582009-12-04 23:49:512504void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2505 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172506 NavigationState* navigation_state =
2507 NavigationState::FromDataSource(frame->dataSource());
2508
[email protected]9e84a872010-02-09 18:23:422509 if (!frame->parent()) { // Main frame case.
2510 // Let the page translator know that the page has changed so it can clear
2511 // its states.
2512 page_translator_->MainFrameNavigated();
2513 }
2514
[email protected]3d9689372009-09-10 04:29:172515 navigation_state->set_commit_load_time(Time::Now());
2516 if (is_new_navigation) {
2517 // When we perform a new navigation, we need to update the previous session
2518 // history entry with state for the page we are leaving.
2519 UpdateSessionHistory(frame);
2520
2521 // We bump our Page ID to correspond with the new session history entry.
2522 page_id_ = next_page_id_++;
2523
[email protected]3cc72b12010-03-18 23:03:002524 // Advance our offset in session history, applying the length limit. There
2525 // is now no forward history.
2526 history_list_offset_++;
2527 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2528 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2529 history_list_length_ = history_list_offset_ + 1;
2530
[email protected]f9f4841b2010-03-20 05:41:422531 MessageLoop::current()->PostDelayedTask(
2532 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172533 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2534 page_id_, true),
2535 kDelayForForcedCaptureMs);
2536 } else {
2537 // Inspect the navigation_state on this frame to see if the navigation
2538 // corresponds to a session history navigation... Note: |frame| may or
2539 // may not be the toplevel frame, but for the case of capturing session
2540 // history, the first committed frame suffices. We keep track of whether
2541 // we've seen this commit before so that only capture session history once
2542 // per navigation.
2543 //
2544 // Note that we need to check if the page ID changed. In the case of a
2545 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2546 // previous URL and the current page ID, which would be wrong.
2547 if (navigation_state->pending_page_id() != -1 &&
2548 navigation_state->pending_page_id() != page_id_ &&
2549 !navigation_state->request_committed()) {
2550 // This is a successful session history navigation!
2551 UpdateSessionHistory(frame);
2552 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002553
2554 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172555 }
2556 }
2557
2558 // Remember that we've already processed this request, so we don't update
2559 // the session history again. We do this regardless of whether this is
2560 // a session history navigation, because if we attempted a session history
2561 // navigation without valid HistoryItem state, WebCore will think it is a
2562 // new navigation.
2563 navigation_state->set_request_committed(true);
2564
2565 UpdateURL(frame);
2566
2567 // If this committed load was initiated by a client redirect, we're
2568 // at the last stop now, so clear it.
2569 completed_client_redirect_src_ = GURL();
2570
2571 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272572 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172573}
2574
2575void RenderView::didClearWindowObject(WebFrame* frame) {
2576 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2577 BindDOMAutomationController(frame);
2578 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2579 dom_ui_bindings_.set_message_sender(this);
2580 dom_ui_bindings_.set_routing_id(routing_id_);
2581 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2582 }
2583 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2584 external_host_bindings_.set_message_sender(this);
2585 external_host_bindings_.set_routing_id(routing_id_);
2586 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2587 }
2588}
2589
2590void RenderView::didCreateDocumentElement(WebFrame* frame) {
2591 if (RenderThread::current()) { // Will be NULL during unit tests.
2592 RenderThread::current()->user_script_slave()->InjectScripts(
2593 frame, UserScript::DOCUMENT_START);
2594 }
[email protected]078b34612009-09-19 19:31:512595 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2596 view_type_ == ViewType::EXTENSION_MOLE) {
2597 InjectToolstripCSS();
2598 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2599 }
[email protected]3d9689372009-09-10 04:29:172600
2601 // Notify the browser about non-blank documents loading in the top frame.
2602 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252603 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272604 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172605 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2606 }
2607}
2608
2609void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2610 UpdateTitle(frame, title);
2611
2612 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272613 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172614}
2615
2616void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2617 WebDataSource* ds = frame->dataSource();
2618 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2619 DCHECK(navigation_state);
2620 navigation_state->set_finish_document_load_time(Time::Now());
2621
2622 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2623
[email protected]e9e07992010-02-17 21:04:362624 // The document has now been fully loaded. Scan for forms to be sent up to
2625 // the browser.
2626 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482627 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362628 SendForms(frame);
[email protected]3d9689372009-09-10 04:29:172629 SendPasswordForms(frame);
2630
2631 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272632 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172633
2634 if (RenderThread::current()) { // Will be NULL during unit tests.
2635 RenderThread::current()->user_script_slave()->InjectScripts(
2636 frame, UserScript::DOCUMENT_END);
2637 }
[email protected]fa7b6b542009-11-03 05:02:302638
2639 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
[email protected]9e84a872010-02-09 18:23:422640
2641 if (page_translator_->IsPageTranslated())
2642 page_translator_->TranslateFrame(frame);
[email protected]fa7b6b542009-11-03 05:02:302643}
2644
2645void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2646 if (RenderThread::current()) { // Will be NULL during unit tests.
2647 RenderThread::current()->user_script_slave()->InjectScripts(
2648 frame, UserScript::DOCUMENT_IDLE);
2649 }
2650
2651 WebFrame* main_frame = webview()->mainFrame();
2652 if (frame == main_frame) {
2653 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202654 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302655 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202656 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302657 pending_code_execution_queue_.pop();
2658 }
2659 }
[email protected]3d9689372009-09-10 04:29:172660}
2661
2662void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2663 // Ignore
2664}
2665
2666void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2667 // Ignore
2668}
2669
2670void RenderView::didFinishLoad(WebFrame* frame) {
2671 WebDataSource* ds = frame->dataSource();
2672 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2673 DCHECK(navigation_state);
2674 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302675 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172676}
2677
[email protected]ccbe04e2010-03-17 17:58:432678void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172679 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062680
2681 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2682 // since a new one gets created by didCreateDataSource.
2683 NavigationState* state =
2684 NavigationState::FromDataSource(frame->dataSource());
2685 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2686
[email protected]3d9689372009-09-10 04:29:172687 // If this was a reference fragment navigation that we initiated, then we
2688 // could end up having a non-null pending navigation state. We just need to
2689 // update the ExtraData on the datasource so that others who read the
2690 // ExtraData will get the new NavigationState. Similarly, if we did not
2691 // initiate this navigation, then we need to take care to reset any pre-
2692 // existing navigation state to a content-initiated navigation state.
2693 // DidCreateDataSource conveniently takes care of this for us.
2694 didCreateDataSource(frame, frame->dataSource());
2695
[email protected]f6c2459d2010-02-24 22:34:062696 if (idle_scheduler_ran) {
2697 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2698 NavigationState* new_state =
2699 NavigationState::FromDataSource(frame->dataSource());
2700 new_state->user_script_idle_scheduler()->set_has_run(true);
2701 }
2702
[email protected]3d9689372009-09-10 04:29:172703 didCommitProvisionalLoad(frame, is_new_navigation);
2704
[email protected]26aa0482009-09-30 16:55:272705 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172706}
2707
[email protected]476b6f82009-09-10 21:00:592708void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312709 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592710}
2711
[email protected]3d9689372009-09-10 04:29:172712void RenderView::assignIdentifierToRequest(
2713 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2714 // Ignore
2715}
2716
2717void RenderView::willSendRequest(
2718 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2719 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302720 WebFrame* top_frame = frame->top();
2721 if (!top_frame)
2722 top_frame = frame;
2723 WebDataSource* data_source = top_frame->provisionalDataSource();
2724 if (!data_source)
2725 data_source = top_frame->dataSource();
2726 if (data_source) {
2727 NavigationState* state = NavigationState::FromDataSource(data_source);
2728 if (state && state->is_cache_policy_override_set())
2729 request.setCachePolicy(state->cache_policy_override());
2730 }
[email protected]3d9689372009-09-10 04:29:172731 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502732 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132733 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172734}
2735
2736void RenderView::didReceiveResponse(
2737 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]3d9689372009-09-10 04:29:172738 // Only do this for responses that correspond to a provisional data source
2739 // of the top-most frame. If we have a provisional data source, then we
2740 // can't have any sub-resources yet, so we know that this response must
2741 // correspond to a frame load.
2742 if (!frame->provisionalDataSource() || frame->parent())
2743 return;
2744
2745 // If we are in view source mode, then just let the user see the source of
2746 // the server's 404 error page.
2747 if (frame->isViewSourceModeEnabled())
2748 return;
2749
[email protected]f48013be2010-01-14 22:07:452750 // Record that this was a page loaded over SPDY.
2751 if (response.wasFetchedViaSPDY()) {
2752 NavigationState* navigation_state =
2753 NavigationState::FromDataSource(frame->provisionalDataSource());
2754 navigation_state->set_was_fetched_via_spdy(true);
2755 }
2756
2757 // Consider loading an alternate error page for 404 responses.
2758 if (response.httpStatusCode() != 404)
2759 return;
2760
[email protected]3d9689372009-09-10 04:29:172761 // Can we even load an alternate error page for this URL?
2762 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2763 return;
2764
2765 NavigationState* navigation_state =
2766 NavigationState::FromDataSource(frame->provisionalDataSource());
2767 navigation_state->set_postpone_loading_data(true);
2768 navigation_state->clear_postponed_data();
2769}
2770
2771void RenderView::didFinishResourceLoad(
2772 WebFrame* frame, unsigned identifier) {
2773 NavigationState* navigation_state =
2774 NavigationState::FromDataSource(frame->dataSource());
2775 if (!navigation_state->postpone_loading_data())
2776 return;
2777
2778 // The server returned a 404 and the content was < 512 bytes (which we
2779 // suppressed). Go ahead and fetch the alternate page content.
2780
2781 const GURL& frame_url = frame->url();
2782
2783 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2784 DCHECK(error_page_url.is_valid());
2785
2786 WebURLError original_error;
2787 original_error.unreachableURL = frame_url;
2788
2789 navigation_state->set_alt_error_page_fetcher(
2790 new AltErrorPageResourceFetcher(
2791 error_page_url, frame, original_error,
2792 NewCallback(this, &RenderView::AltErrorPageFinished)));
2793}
2794
2795void RenderView::didFailResourceLoad(
2796 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2797 // Ignore
2798}
2799
2800void RenderView::didLoadResourceFromMemoryCache(
2801 WebFrame* frame, const WebURLRequest& request,
2802 const WebURLResponse& response) {
2803 // Let the browser know we loaded a resource from the memory cache. This
2804 // message is needed to display the correct SSL indicators.
2805 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2806 routing_id_,
2807 request.url(),
[email protected]91733b62009-09-18 06:21:092808 frame->securityOrigin().toString().utf8(),
2809 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172810 response.securityInfo()));
2811}
2812
[email protected]6069da8c2009-10-20 20:33:492813void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292814 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2815}
2816
2817void RenderView::didRunInsecureContent(
2818 WebFrame* frame, const WebSecurityOrigin& origin) {
2819 Send(new ViewHostMsg_DidRunInsecureContent(
2820 routing_id_,
2821 origin.toString().utf8()));
2822}
2823
[email protected]7ea093ba2009-11-03 05:54:592824bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002825 if (enabled_per_settings)
2826 return AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
[email protected]7ea093ba2009-11-03 05:54:592827
2828 WebSecurityOrigin origin = frame->securityOrigin();
2829 if (origin.isEmpty())
2830 return false; // Uninitialized document?
2831
2832 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2833 return true; // Browser UI elements should still work.
2834
2835 // If the scheme is ftp: or file:, an empty file name indicates a directory
2836 // listing, which requires JavaScript to function properly.
2837 GURL frame_url = frame->url();
2838 const char* kDirProtocols[] = { "ftp", "file" };
2839 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2840 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2841 return frame_url.SchemeIs(kDirProtocols[i]) &&
2842 frame_url.ExtractFileName().empty();
2843 }
2844 }
2845
2846 return false; // Other protocols fall through here.
2847}
2848
[email protected]8934a3b2010-02-25 00:34:002849void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
2850 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
2851}
2852
[email protected]c21f1d52010-03-04 03:19:432853void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
2854 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
2855}
2856
[email protected]3d9689372009-09-10 04:29:172857void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2858 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2859}
2860
[email protected]0c882b282009-10-07 17:01:282861void RenderView::didCreateScriptContext(WebFrame* frame) {
2862 EventBindings::HandleContextCreated(frame, false);
2863}
2864
2865void RenderView::didDestroyScriptContext(WebFrame* frame) {
2866 EventBindings::HandleContextDestroyed(frame);
2867}
2868
2869void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2870 EventBindings::HandleContextCreated(frame, true);
2871}
2872
[email protected]ab9eabac2010-03-16 16:54:102873void RenderView::didMakeCrossFrameAccess(WebFrame* frame,
2874 bool cross_origin,
2875 const WebString& property,
2876 unsigned long long event_id) {
2877 // TODO(johnnyg): track the individual properties and repeat event_ids.
2878 if (cross_origin)
2879 cross_origin_access_count_++;
2880 else
2881 same_origin_access_count_++;
2882}
2883
[email protected]3d9689372009-09-10 04:29:172884void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142885 CheckPreferredSize();
2886}
2887
2888void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172889 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252890 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172891 // message.
[email protected]ab32b16c2009-10-16 14:57:252892 if (send_preferred_size_changes_) {
[email protected]dfca5acf2010-03-22 03:28:432893 if (!webview())
2894 return;
2895
[email protected]3d9689372009-09-10 04:29:172896 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252897 // cache the width and height and only send the IPC message when we're sure
2898 // they're different.
[email protected]26aa0482009-09-30 16:55:272899 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:392900 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:292901
[email protected]ab32b16c2009-10-16 14:57:252902 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:392903 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:252904 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:392905 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:252906
[email protected]ab32b16c2009-10-16 14:57:252907 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2908 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172909 }
2910 }
2911}
2912
[email protected]143dcd592009-11-06 21:33:492913void RenderView::didChangeScrollOffset(WebFrame* frame) {
2914 StartNavStateSyncTimerIfNecessary();
2915}
2916
[email protected]8922e1f2009-10-03 05:01:262917void RenderView::reportFindInPageMatchCount(int request_id, int count,
2918 bool final_update) {
2919 // If we have a message that has been queued up, then we should just replace
2920 // it. The ACK from the browser will make sure it gets sent when the browser
2921 // wants it.
2922 if (queued_find_reply_message_.get()) {
2923 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2924 routing_id_,
2925 request_id,
2926 count,
2927 gfx::Rect(),
2928 -1, // Don't update active match ordinal.
2929 final_update);
2930 queued_find_reply_message_.reset(msg);
2931 } else {
2932 // Send the search result over to the browser process.
2933 Send(new ViewHostMsg_Find_Reply(
2934 routing_id_,
2935 request_id,
2936 count,
2937 gfx::Rect(),
2938 -1, // // Don't update active match ordinal.
2939 final_update));
2940 }
2941}
2942
2943void RenderView::reportFindInPageSelection(int request_id,
2944 int active_match_ordinal,
2945 const WebRect& selection_rect) {
2946 // Send the search result over to the browser process.
2947 Send(new ViewHostMsg_Find_Reply(routing_id_,
2948 request_id,
2949 -1,
2950 selection_rect,
2951 active_match_ordinal,
2952 false));
2953}
2954
[email protected]24a7f3c2010-03-25 08:26:492955void RenderView::ReportNoFindInPageResults(int request_id) {
2956 Send(new ViewHostMsg_Find_Reply(routing_id_,
2957 request_id,
2958 0,
2959 gfx::Rect(),
2960 0,
2961 true));
2962}
2963
[email protected]79dbc662009-09-04 05:42:512964// webkit_glue::WebPluginPageDelegate -----------------------------------------
2965
[email protected]f103ab72009-09-02 17:10:592966webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2967 const GURL& url,
2968 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592969 std::string* actual_mime_type) {
2970 if (!PluginChannelHost::IsListening())
2971 return NULL;
2972
2973 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272974 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592975 if (main_frame)
2976 policy_url = main_frame->url();
2977
2978 FilePath path;
[email protected]610c0892009-09-08 19:46:182979 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2980 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592981 if (path.value().empty())
2982 return NULL;
2983
2984 const std::string* mime_type_to_use;
2985 if (!actual_mime_type->empty())
2986 mime_type_to_use = actual_mime_type;
2987 else
2988 mime_type_to_use = &mime_type;
2989
[email protected]d2139662009-12-10 03:21:142990 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:282991 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:142992 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:162993 const char kPepperPrefix[] = "pepper-";
2994 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:142995 if (CommandLine::ForCurrentProcess()->
2996 HasSwitch(switches::kInternalPepper)) {
2997 in_process_plugin = true;
2998 use_pepper_host = true;
2999 } else {
3000 // In process Pepper plugins must be explicitly enabled.
3001 return NULL;
3002 }
[email protected]26e8d5e2009-10-13 02:47:163003 }
[email protected]d2139662009-12-10 03:21:143004 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463005 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3006 if (mime_type == "application/x-nacl-srpc") {
3007 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143008 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463009 }
3010 }
3011 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143012 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283013 WebPluginDelegatePepper* pepper_plugin =
3014 WebPluginDelegatePepper::Create(path, *mime_type_to_use,
3015 AsWeakPtr());
3016 current_pepper_plugins_.insert(pepper_plugin);
3017 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143018 } else {
[email protected]6876dff2010-01-15 19:38:093019#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143020 return WebPluginDelegateImpl::Create(
3021 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093022#else
[email protected]596b2c42010-01-14 20:40:433023 NOTIMPLEMENTED();
3024 return NULL;
[email protected]7b6616f2010-01-14 18:07:553025#endif
[email protected]6876dff2010-01-15 19:38:093026 }
[email protected]f103ab72009-09-02 17:10:593027 }
3028
[email protected]610c0892009-09-08 19:46:183029 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593030}
3031
3032void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033033#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593034 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3035 routing_id(), window));
3036#endif
3037}
3038
3039void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033040#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593041 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3042 routing_id(), window));
3043#endif
3044 CleanupWindowInPluginMoves(window);
3045}
3046
3047void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3048 SchedulePluginMove(move);
3049}
3050
3051void RenderView::DidStartLoadingForPlugin() {
3052 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523053 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593054}
3055
3056void RenderView::DidStopLoadingForPlugin() {
3057 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523058 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593059}
3060
3061void RenderView::ShowModalHTMLDialogForPlugin(
3062 const GURL& url,
3063 const gfx::Size& size,
3064 const std::string& json_arguments,
3065 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213066 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593067 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213068 json_retval));
[email protected]f103ab72009-09-02 17:10:593069}
3070
[email protected]b921cfd22010-02-25 16:57:513071WebCookieJar* RenderView::GetCookieJar() {
3072 return &cookie_jar_;
3073}
3074
3075void RenderView::PageTranslated(int page_id,
3076 const std::string& original_lang,
3077 const std::string& target_lang) {
3078 Send(new ViewHostMsg_PageTranslated(routing_id_, page_id_,
3079 original_lang, target_lang));
3080}
3081
initial.commit09911bf2008-07-26 23:55:293082void RenderView::SyncNavigationState() {
3083 if (!webview())
3084 return;
3085
[email protected]26aa0482009-09-30 16:55:273086 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173087 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293088 return;
[email protected]ca948a22009-06-25 19:36:173089
3090 Send(new ViewHostMsg_UpdateState(
3091 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293092}
3093
[email protected]b0950a72009-09-29 23:16:173094bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3095 // Make sure webview was not shut down.
3096 if (!webview())
3097 return false;
3098 // Create an image resource fetcher and assign it with a call back object.
3099 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273100 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173101 NewCallback(this, &RenderView::DidDownloadImage)));
3102 return true;
3103}
3104
3105void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293106 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173107 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473108 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3109 fetcher->id(),
3110 fetcher->image_url(),
3111 image.isNull(),
3112 image));
[email protected]b0950a72009-09-29 23:16:173113 // Dispose of the image fetcher.
3114 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3115 image_fetchers_.erase(fetcher);
3116 // We're in the callback from the ImageResourceFetcher, best to delay
3117 // deletion.
3118 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293119}
3120
[email protected]bf5c2ff392009-07-08 16:24:333121void RenderView::OnDownloadFavIcon(int id,
3122 const GURL& image_url,
3123 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343124 bool data_image_failed = false;
3125 if (image_url.SchemeIs("data")) {
3126 SkBitmap data_image = ImageFromDataUrl(image_url);
3127 data_image_failed = data_image.empty();
3128 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333129 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3130 data_image));
[email protected]f11ca0732009-04-11 00:09:343131 }
3132 }
3133
[email protected]bf5c2ff392009-07-08 16:24:333134 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173135 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333136 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3137 SkBitmap()));
3138 }
initial.commit09911bf2008-07-26 23:55:293139}
3140
[email protected]f11ca0732009-04-11 00:09:343141SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3142 std::string mime_type, char_set, data;
3143 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3144 // Decode the favicon using WebKit's image decoder.
3145 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3146 const unsigned char* src_data =
3147 reinterpret_cast<const unsigned char*>(&data[0]);
3148
3149 return decoder.Decode(src_data, data.size());
3150 }
3151 return SkBitmap();
3152}
3153
initial.commit09911bf2008-07-26 23:55:293154void RenderView::OnGetApplicationInfo(int page_id) {
3155 webkit_glue::WebApplicationInfo app_info;
3156 if (page_id == page_id_)
3157 webkit_glue::GetApplicationInfo(webview(), &app_info);
3158
3159 // Prune out any data URLs in the set of icons. The browser process expects
3160 // any icon with a data URL to have originated from a favicon. We don't want
3161 // to decode arbitrary data URLs in the browser process. See
3162 // http://b/issue?id=1162972
3163 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593164 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293165 app_info.icons.erase(app_info.icons.begin() + i);
3166 --i;
3167 }
3168 }
3169
3170 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3171}
3172
[email protected]7ccddb8c2009-08-04 17:36:553173GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293174 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553175 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293176 // If the URL that failed was secure, then the embedding web page was not
3177 // expecting a network attacker to be able to manipulate its contents. As
3178 // we fetch alternate error pages over HTTP, we would be allowing a network
3179 // attacker to manipulate the contents of the response if we tried to use
3180 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153181 return GURL();
initial.commit09911bf2008-07-26 23:55:293182 }
3183
3184 // Grab the base URL from the browser process.
3185 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153186 return GURL();
initial.commit09911bf2008-07-26 23:55:293187
3188 // Strip query params from the failed URL.
3189 GURL::Replacements remove_params;
3190 remove_params.ClearUsername();
3191 remove_params.ClearPassword();
3192 remove_params.ClearQuery();
3193 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553194 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503195 std::string spec_to_send = url_to_send.spec();
3196 // Notify link doctor of the url truncation by sending of "?" at the end.
3197 if (failed_url.has_query())
3198 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293199
3200 // Construct the query params to send to link doctor.
3201 std::string params(alternate_error_page_url_.query());
3202 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503203 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293204 params.append("&sourceid=chrome");
3205 params.append("&error=");
3206 switch (error_type) {
3207 case DNS_ERROR:
3208 params.append("dnserror");
3209 break;
3210
3211 case HTTP_404:
3212 params.append("http404");
3213 break;
3214
[email protected]5df266ac2008-10-15 19:50:133215 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333216 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133217 break;
3218
initial.commit09911bf2008-07-26 23:55:293219 default:
3220 NOTREACHED() << "unknown ErrorPageType";
3221 }
3222
3223 // OK, build the final url to return.
3224 GURL::Replacements link_doctor_params;
3225 link_doctor_params.SetQueryStr(params);
3226 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3227 return url;
3228}
3229
[email protected]24a7f3c2010-03-25 08:26:493230webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() {
3231 WebPlugin* plugin = webview()->mainFrame()->document().
3232 toElement<WebPluginDocument>().plugin();
3233 return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate();
3234}
3235
[email protected]6069da8c2009-10-20 20:33:493236void RenderView::OnFind(int request_id, const string16& search_text,
3237 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273238 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493239
3240 if (main_frame->document().isPluginDocument()) {
3241 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3242 if (options.findNext) {
3243 // Just navigate back/forward.
3244 delegate->SelectFindResult(options.forward);
3245 } else {
3246 if (delegate->SupportsFind()) {
3247 delegate->StartFind(UTF16ToUTF8(search_text),
3248 options.matchCase,
3249 request_id);
3250 } else {
3251 ReportNoFindInPageResults(request_id);
3252 }
3253 }
3254 return;
3255 }
3256
[email protected]b4bb2502009-10-01 22:35:273257 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273258 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293259 WebFrame* search_frame = focused_frame; // start searching focused frame.
3260
3261 bool multi_frame = (frame_after_main != main_frame);
3262
3263 // If we have multiple frames, we don't want to wrap the search within the
3264 // frame, so we check here if we only have main_frame in the chain.
3265 bool wrap_within_frame = !multi_frame;
3266
[email protected]b3f2b912009-04-09 16:18:523267 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293268 bool result = false;
3269
[email protected]7830da3e2009-11-06 16:27:263270 // If something is selected when we start searching it means we cannot just
3271 // increment the current match ordinal; we need to re-generate it.
3272 WebRange current_selection = focused_frame->selectionRange();
3273
initial.commit09911bf2008-07-26 23:55:293274 do {
[email protected]dd7daa82009-08-10 05:46:453275 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593276 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293277
3278 if (!result) {
3279 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223280 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293281
3282 // Find the next frame, but skip the invisible ones.
3283 do {
3284 // What is the next frame to search? (we might be going backwards). Note
3285 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593286 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273287 search_frame->traverseNext(true) :
3288 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453289 } while (!search_frame->hasVisibleContent() &&
3290 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293291
[email protected]884db412008-11-24 23:46:503292 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223293 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293294
3295 // If we have multiple frames and we have wrapped back around to the
3296 // focused frame, we need to search it once more allowing wrap within
3297 // the frame, otherwise it will report 'no match' if the focused frame has
3298 // reported matches, but no frames after the focused_frame contain a
3299 // match for the search word(s).
3300 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453301 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593302 request_id, search_text, options, true, // Force wrapping.
3303 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293304 }
3305 }
3306
[email protected]26aa0482009-09-30 16:55:273307 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293308 } while (!result && search_frame != focused_frame);
3309
[email protected]7830da3e2009-11-06 16:27:263310 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293311 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453312 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293313 } else {
3314 // If nothing is found, set result to "0 of 0", otherwise, set it to
3315 // "-1 of 1" to indicate that we found at least one item, but we don't know
3316 // yet what is active.
3317 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3318 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293319
[email protected]4f3dc372009-02-24 00:10:293320 // If we find no matches then this will be our last status update.
3321 // Otherwise the scoping effort will send more results.
3322 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293323
[email protected]4f3dc372009-02-24 00:10:293324 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403325 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593326 request_id,
[email protected]4f3dc372009-02-24 00:10:293327 match_count,
3328 selection_rect,
3329 ordinal,
3330 final_status_update));
initial.commit09911bf2008-07-26 23:55:293331
initial.commit09911bf2008-07-26 23:55:293332 // Scoping effort begins, starting with the mainframe.
3333 search_frame = main_frame;
3334
[email protected]dd7daa82009-08-10 05:46:453335 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293336
3337 do {
3338 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453339 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293340
3341 // We don't start another scoping effort unless at least one match has
3342 // been found.
3343 if (result) {
3344 // Start new scoping request. If the scoping function determines that it
3345 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453346 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593347 search_text,
3348 options,
initial.commit09911bf2008-07-26 23:55:293349 true); // reset the tickmarks
3350 }
3351
3352 // Iterate to the next frame. The frame will not necessarily scope, for
3353 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273354 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293355 } while (search_frame != main_frame);
3356 }
3357}
3358
[email protected]24a7f3c2010-03-25 08:26:493359void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3360 WebView* view = webview();
3361 if (!view)
3362 return;
3363
3364 WebDocument doc = view->mainFrame()->document();
3365 if (doc.isPluginDocument()) {
3366 GetDelegateForPluginDocument()->StopFind();
3367 return;
3368 }
3369
3370 bool clear_selection =
3371 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3372 if (clear_selection)
3373 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3374
3375 WebFrame* frame = view->mainFrame();
3376 while (frame) {
3377 frame->stopFinding(clear_selection);
3378 frame = frame->traverseNext(false);
3379 }
3380
3381 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3382 WebFrame* focused_frame = view->focusedFrame();
3383 if (focused_frame) {
3384 WebDocument doc = focused_frame->document();
3385 if (!doc.isNull()) {
3386 WebNode node = doc.focusedNode();
3387 if (!node.isNull())
3388 node.simulateClick();
3389 }
3390 }
3391 }
3392}
3393
3394void RenderView::OnFindReplyAck() {
3395 // Check if there is any queued up request waiting to be sent.
3396 if (queued_find_reply_message_.get()) {
3397 // Send the search result over to the browser process.
3398 Send(queued_find_reply_message_.get());
3399 queued_find_reply_message_.release();
3400 }
3401}
3402
[email protected]8c4cdd42010-01-12 21:31:133403// static
3404std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403405 // Text with less than 100 bytes will probably not provide good results.
3406 // Report it as unknown language.
3407 if (text.length() < 100)
3408 return kUnknownLanguageCode;
3409
[email protected]8c4cdd42010-01-12 21:31:133410 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133411 int num_languages = 0;
3412 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423413 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133414 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423415 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133416 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403417 if (is_reliable && cld_language != NUM_LANGUAGES &&
3418 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483419 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3420 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263421 // language code for tradtional Chinese among others.
3422 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3423 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3424 // for Simplified Chinese.
3425 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133426 }
[email protected]8c4cdd42010-01-12 21:31:133427 return language;
[email protected]7893a982010-01-07 23:25:523428}
3429
[email protected]8934a3b2010-02-25 00:34:003430bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353431 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003432 return current_content_settings_.settings[settings_type] !=
3433 CONTENT_SETTING_BLOCK;
3434}
3435
3436void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3437 if (!content_blocked_[settings_type]) {
3438 content_blocked_[settings_type] = true;
3439 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353440 }
[email protected]0de80162010-02-03 04:52:353441}
3442
[email protected]71b0d5d2010-02-15 05:43:073443void RenderView::ClearBlockedContentSettings() {
3444 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3445 content_blocked_[i] = false;
3446}
3447
initial.commit09911bf2008-07-26 23:55:293448void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3449 Send(new ViewHostMsg_DnsPrefetch(host_names));
3450}
3451
[email protected]40bd6582009-12-04 23:49:513452void RenderView::OnZoom(PageZoom::Function function) {
3453 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3454 return;
3455
3456 int zoom_level = webview()->zoomLevel();
3457 int new_zoom_level = webview()->setZoomLevel(false,
3458 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3459
3460 // Tell the browser which host got zoomed so it can update the saved values.
3461 // Pages like the safe browsing interstitial can have empty hosts; don't
3462 // record those.
3463 std::string host(GURL(webview()->mainFrame()->url()).host());
3464 if (!host.empty())
3465 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3466}
3467
[email protected]f85f0702010-01-30 09:31:013468void RenderView::OnSetContentSettingsForLoadingHost(
3469 std::string host,
3470 const ContentSettings& content_settings) {
3471 host_content_settings_[host] = content_settings;
3472}
3473
[email protected]40bd6582009-12-04 23:49:513474void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3475 int zoom_level) {
3476 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293477}
3478
[email protected]41fc0322009-09-04 22:23:403479void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273480 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293481}
3482
[email protected]a697f4c2009-09-14 22:30:183483void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273484 WebString no_encoding;
3485 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183486}
3487
[email protected]20ad2692009-11-20 18:27:203488bool RenderView::GetAllChildFrames(
3489 WebFrame* parent_frame,
3490 std::vector<WebFrame*>* frames_vector) const {
3491 if (!parent_frame)
3492 return false;
3493 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3494 child_frame = child_frame->nextSibling()) {
3495 frames_vector->push_back(child_frame);
3496 GetAllChildFrames(child_frame, frames_vector);
3497 }
3498 return true;
3499}
3500
[email protected]dd7daa82009-08-10 05:46:453501WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3502 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273503 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453504
3505 // xpath string can represent a frame deep down the tree (across multiple
3506 // frame DOMs).
3507 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3508 // should break into 2 xpaths
3509 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3510
[email protected]26aa0482009-09-30 16:55:273511 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453512
3513 std::wstring xpath_remaining = xpath;
3514 while (!xpath_remaining.empty()) {
3515 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3516 std::wstring xpath_child;
3517 if (delim_pos != std::wstring::npos) {
3518 xpath_child = xpath_remaining.substr(0, delim_pos);
3519 xpath_remaining.erase(0, delim_pos + 1);
3520 } else {
3521 xpath_remaining.swap(xpath_child);
3522 }
3523 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293524 }
3525
[email protected]dd7daa82009-08-10 05:46:453526 return frame;
initial.commit09911bf2008-07-26 23:55:293527}
3528
[email protected]f29acf52008-11-03 20:08:333529void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3530 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293531 WebFrame* web_frame = GetChildFrame(frame_xpath);
3532 if (!web_frame)
3533 return;
3534
[email protected]dd7daa82009-08-10 05:46:453535 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293536}
3537
[email protected]1810e132009-03-24 23:35:483538void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083539 const std::string& css,
3540 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483541 WebFrame* web_frame = GetChildFrame(frame_xpath);
3542 if (!web_frame)
3543 return;
3544
[email protected]ffaef0c2009-09-15 17:08:083545 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483546}
3547
[email protected]00c39612010-03-06 02:53:283548void RenderView::OnPepperPluginDestroy(
3549 WebPluginDelegatePepper* pepper_plugin) {
3550 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
3551 current_pepper_plugins_.find(pepper_plugin);
3552 if (found_pepper == current_pepper_plugins_.end()) {
3553 NOTREACHED();
3554 return;
3555 }
3556 current_pepper_plugins_.erase(found_pepper);
3557}
3558
initial.commit09911bf2008-07-26 23:55:293559void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3560 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333561 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293562}
3563
[email protected]1810e132009-03-24 23:35:483564void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083565 const std::string& css,
3566 const std::string& id) {
3567 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413568
3569 // Notify RenderViewHost that css has been inserted into the frame.
3570 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483571}
3572
[email protected]7ea066a2009-04-06 20:21:593573void RenderView::OnAddMessageToConsole(
3574 const string16& frame_xpath,
3575 const string16& message,
3576 const WebConsoleMessage::Level& level) {
3577 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593578 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453579 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293580}
3581
[email protected]81e63782009-02-27 19:35:093582void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3583 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293584}
3585
3586void RenderView::OnSetDOMUIProperty(const std::string& name,
3587 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093588 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293589 dom_ui_bindings_.SetProperty(name, value);
3590}
3591
3592void RenderView::OnReservePageIDRange(int size_of_range) {
3593 next_page_id_ += size_of_range + 1;
3594}
3595
[email protected]e80c73b2009-04-07 23:24:583596void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3597 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253598 bool ended,
3599 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033600 if (ended) {
[email protected]26aa0482009-09-30 16:55:273601 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033602 }
initial.commit09911bf2008-07-26 23:55:293603}
3604
3605void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273606 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293607}
3608
initial.commit09911bf2008-07-26 23:55:293609void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103610 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293611 webkit_glue::FillPasswordForm(this->webview(), form_data);
3612}
3613
3614void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583615 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253616 const gfx::Point& screen_point,
3617 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273618 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583619 drop_data.ToDragData(),
3620 drop_data.identity,
3621 client_point,
[email protected]1d9f4132009-09-08 17:29:253622 screen_point,
3623 ops);
initial.commit09911bf2008-07-26 23:55:293624
[email protected]1d9f4132009-09-08 17:29:253625 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293626}
3627
[email protected]e80c73b2009-04-07 23:24:583628void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253629 const gfx::Point& screen_point,
3630 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273631 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253632 client_point,
3633 screen_point,
3634 ops);
initial.commit09911bf2008-07-26 23:55:293635
[email protected]1d9f4132009-09-08 17:29:253636 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293637}
3638
3639void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273640 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293641}
3642
[email protected]e80c73b2009-04-07 23:24:583643void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3644 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273645 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293646}
3647
3648void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593649 webkit_preferences_ = prefs;
3650 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293651}
3652
3653void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3654 alternate_error_page_url_ = url;
3655}
3656
[email protected]a0c7153e2009-12-09 14:36:333657void RenderView::OnCustomContextMenuAction(unsigned action) {
3658 webview()->performCustomContextMenuAction(action);
3659}
3660
[email protected]d4a00a72010-01-29 01:44:423661void RenderView::OnTranslatePage(int page_id,
3662 const std::string& source_lang,
3663 const std::string& target_lang) {
3664 if (page_id != page_id_)
3665 return; // Not the page we expected, nothing to do.
3666
3667 WebFrame* main_frame = webview()->mainFrame();
3668 if (!main_frame)
3669 return;
[email protected]9e84a872010-02-09 18:23:423670
3671 page_translator_->TranslatePage(page_id, main_frame,
3672 source_lang, target_lang);
[email protected]d4a00a72010-01-29 01:44:423673}
3674
[email protected]0bedb8a2010-01-14 19:36:323675void RenderView::OnTranslateTextResponse(
3676 int work_id, int error_id, const std::vector<string16>& text_chunks) {
[email protected]d4a00a72010-01-29 01:44:423677 text_translator_.OnTranslationResponse(work_id, error_id, text_chunks);
[email protected]0bedb8a2010-01-14 19:36:323678}
3679
initial.commit09911bf2008-07-26 23:55:293680void RenderView::OnInstallMissingPlugin() {
3681 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593682 if (first_default_plugin_)
3683 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293684}
3685
[email protected]b62d1a8c2009-01-13 23:54:573686void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:343687 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363688 // This could happen if we navigated to a different page before the user
3689 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463690 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363691 return;
3692
[email protected]6069da8c2009-10-20 20:33:493693 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463694 for (size_t i = 0; i < file_names.size(); ++i) {
3695 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3696 }
3697
3698 file_chooser_completion_->didChooseFile(ws_file_names);
3699 // Reset the chooser pointer
3700 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293701}
3702
3703void RenderView::OnEnableViewSourceMode() {
3704 if (!webview())
3705 return;
[email protected]26aa0482009-09-30 16:55:273706 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293707 if (!main_frame)
3708 return;
3709
[email protected]dd7daa82009-08-10 05:46:453710 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293711}
3712
[email protected]ab32b16c2009-10-16 14:57:253713void RenderView::OnEnablePreferredSizeChangedMode() {
3714 send_preferred_size_changes_ = true;
[email protected]e8014aa52010-03-03 14:30:063715
3716 if (ViewType::ShouldAutoResize(view_type_))
[email protected]d8a179c2010-01-31 00:58:143717 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3718 &RenderView::CheckPreferredSize);
[email protected]0666aef2009-05-13 19:48:083719}
3720
[email protected]cda45c02010-02-25 19:28:103721void RenderView::OnDisableScrollbarsForSmallWindows(
3722 const gfx::Size& disable_scrollbar_size_limit) {
3723 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3724}
3725
[email protected]80d96fa2009-06-10 22:34:513726void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3727 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373728 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:033729#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:413730 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3731 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463732 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323733
[email protected]644d77e2010-01-27 01:03:103734 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323735 webview()->setScrollbarColors(
3736 renderer_prefs.thumb_inactive_color,
3737 renderer_prefs.thumb_active_color,
3738 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103739 webview()->setSelectionColors(
3740 renderer_prefs.active_selection_bg_color,
3741 renderer_prefs.active_selection_fg_color,
3742 renderer_prefs.inactive_selection_bg_color,
3743 renderer_prefs.inactive_selection_fg_color);
3744 }
[email protected]7a74e102009-09-03 00:16:563745#endif
[email protected]80d96fa2009-06-10 22:34:513746}
3747
[email protected]952cb702009-10-07 05:50:283748void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3749 const WebMediaPlayerAction& action) {
3750 if (webview())
3751 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563752}
3753
[email protected]7b291f92009-08-14 05:43:533754void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513755 // When this is first set, the bindings aren't fully loaded. We only need
3756 // to call through this API after the page has already been loaded. It's
3757 // also called in didCreateDocumentElement to bootstrap.
3758 if (view_type_ != ViewType::INVALID) {
3759 if (type == ViewType::EXTENSION_MOLE ||
3760 type == ViewType::EXTENSION_TOOLSTRIP) {
3761 ExtensionProcessBindings::SetViewType(webview(), type);
3762 }
3763 }
[email protected]7b291f92009-08-14 05:43:533764 view_type_ = type;
3765}
3766
3767void RenderView::OnUpdateBrowserWindowId(int window_id) {
3768 browser_window_id_ = window_id;
3769}
3770
[email protected]266eb6f2008-09-30 23:56:503771void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253772 const webkit_glue::WebAccessibility::InParams& in_params,
3773 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573774#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153775 if (!accessibility_.get()) {
3776 // TODO(dglazkov): Once implemented for all ports, remove lazy
3777 // instantiation of accessibility_.
3778 accessibility_.reset(WebAccessibilityCache::create());
3779 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253780 }
[email protected]266eb6f2008-09-30 23:56:503781
[email protected]17455962010-02-24 01:39:353782 out_params->return_code =
3783 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3784 in_params,
3785 out_params);
[email protected]c7287a92009-11-04 20:06:153786
[email protected]6c8afae52009-01-22 02:24:573787#else // defined(OS_WIN)
3788 // TODO(port): accessibility not yet implemented
3789 NOTIMPLEMENTED();
3790#endif
[email protected]266eb6f2008-09-30 23:56:503791}
3792
[email protected]6a983b42009-03-20 20:12:253793void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573794#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153795 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503796 // If accessibility is not activated, ignore clearing message.
3797 return;
3798 }
[email protected]e846d0d2009-05-20 00:53:063799
[email protected]c7287a92009-11-04 20:06:153800 if (clear_all) {
3801 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503802 return;
[email protected]c7287a92009-11-04 20:06:153803 }
3804
3805 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063806
[email protected]6c8afae52009-01-22 02:24:573807#else // defined(OS_WIN)
3808 // TODO(port): accessibility not yet implemented
3809 NOTIMPLEMENTED();
3810#endif
[email protected]266eb6f2008-09-30 23:56:503811}
3812
initial.commit09911bf2008-07-26 23:55:293813void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3814 const GURL& page_url) {
3815 // Prepare list to storage all savable resource links.
3816 std::vector<GURL> resources_list;
3817 std::vector<GURL> referrers_list;
3818 std::vector<GURL> frames_list;
3819 webkit_glue::SavableResourcesResult result(&resources_list,
3820 &referrers_list,
3821 &frames_list);
3822
[email protected]dbeb3952009-10-13 18:01:183823 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3824 webview(),
3825 page_url,
3826 &result,
3827 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293828 // If something is wrong when collecting all savable resource links,
3829 // send empty list to embedder(browser) to tell it failed.
3830 referrers_list.clear();
3831 resources_list.clear();
3832 frames_list.clear();
3833 }
3834
3835 // Send result of all savable resource links to embedder.
3836 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3837 resources_list,
3838 referrers_list,
3839 frames_list));
3840}
3841
3842void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323843 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313844 const std::vector<FilePath>& local_paths,
3845 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073846
3847 // Convert std::vector of GURLs to WebVector<WebURL>
3848 WebVector<WebURL> weburl_links(links);
3849
3850 // Convert std::vector of std::strings to WebVector<WebString>
3851 WebVector<WebString> webstring_paths(local_paths.size());
3852 for (size_t i = 0; i < local_paths.size(); i++)
3853 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3854
3855 WebPageSerializer::serialize(webview()->mainFrame(),
3856 true, this, weburl_links, webstring_paths,
3857 webkit_glue::FilePathToWebString(
3858 local_directory_name));
initial.commit09911bf2008-07-26 23:55:293859}
3860
[email protected]d9ec5c0f2009-12-23 11:55:073861void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
3862 const WebCString& data,
3863 WebPageSerializerClient::PageSerializationStatus status) {
3864 Send(new ViewHostMsg_SendSerializedHtmlData(
3865 routing_id_,
3866 frame_url,
3867 data.data(),
3868 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:293869}
3870
[email protected]04b4a6c2008-08-02 00:44:473871void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273872 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473873 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293874}
3875
[email protected]eb6b87a2009-07-24 15:57:393876void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293877 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3878 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3879 // in the onunload handler from appearing. For now, we're bypassing that and
3880 // calling the FrameLoader's CloseURL method directly. This should be
3881 // revisited to avoid having two ways to close a page. Having a single way
3882 // to close that can run onunload is also useful for fixing
3883 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273884 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293885 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453886 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173887 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293888 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3889 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453890 if (url.SchemeIs(chrome::kHttpScheme) ||
3891 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293892 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293893 }
[email protected]26aa0482009-09-30 16:55:273894 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293895
[email protected]ab9eabac2010-03-16 16:54:103896 // Reset stats
3897 cross_origin_access_count_ = 0;
3898 same_origin_access_count_ = 0;
3899
[email protected]eb6b87a2009-07-24 15:57:393900 // Just echo back the params in the ACK.
3901 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293902}
3903
3904void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573905#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293906 gfx::NativeTheme::instance()->CloseHandles();
3907 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283908 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573909#else // defined(OS_WIN)
3910 // TODO(port): we don't support theming on non-Windows platforms yet
3911 NOTIMPLEMENTED();
3912#endif
initial.commit09911bf2008-07-26 23:55:293913}
3914
[email protected]28790922009-03-09 19:48:373915void RenderView::OnMessageFromExternalHost(const std::string& message,
3916 const std::string& origin,
3917 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153918 if (message.empty())
3919 return;
3920
[email protected]28790922009-03-09 19:48:373921 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3922 target);
[email protected]3ac14a052008-08-15 21:22:153923}
3924
[email protected]0aa55312008-10-17 21:53:083925void RenderView::OnDisassociateFromPopupCount() {
3926 if (decrement_shared_popup_at_destruction_)
3927 shared_popup_counter_->data--;
3928 shared_popup_counter_ = new SharedRenderViewCounter(0);
3929 decrement_shared_popup_at_destruction_ = false;
3930}
3931
[email protected]15d79e12009-08-02 19:23:453932bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3933 const WebURLError& error,
3934 bool replace) {
3935 // We only show alternate error pages in the main frame. They are
3936 // intended to assist the user when navigating, so there is not much
3937 // value in showing them for failed subframes. Ideally, we would be
3938 // able to use the TYPED transition type for this, but that flag is
3939 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453940 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453941 return false;
3942
3943 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373944 // connection failure.
[email protected]15d79e12009-08-02 19:23:453945 int ec = error.reason;
3946 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3947 ec != net::ERR_CONNECTION_FAILED &&
3948 ec != net::ERR_CONNECTION_REFUSED &&
3949 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373950 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453951 return false;
3952
3953 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553954 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453955 if (!error_page_url.is_valid())
3956 return false;
3957
3958 // Load an empty page first so there is an immediate response to the error,
3959 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453960 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453961 GURL(kUnreachableWebDataURL),
3962 error.unreachableURL,
3963 replace);
3964
3965 // Now, create a fetcher for the error page and associate it with the data
3966 // source we just created via the LoadHTMLString call. That way if another
3967 // navigation occurs, the fetcher will get destroyed.
3968 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453969 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453970 navigation_state->set_alt_error_page_fetcher(
3971 new AltErrorPageResourceFetcher(
3972 error_page_url, frame, error,
3973 NewCallback(this, &RenderView::AltErrorPageFinished)));
3974 return true;
3975}
3976
initial.commit09911bf2008-07-26 23:55:293977std::string RenderView::GetAltHTMLForTemplate(
3978 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393979 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293980 ResourceBundle::GetSharedInstance().GetRawDataResource(
3981 template_resource_id));
3982
3983 if (template_html.empty()) {
3984 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3985 return "";
3986 }
[email protected]7cd22a52009-07-14 00:40:253987
initial.commit09911bf2008-07-26 23:55:293988 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253989 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293990 template_html, &error_strings, "t");
3991}
[email protected]0e79b9e2009-02-13 04:20:483992
[email protected]15d79e12009-08-02 19:23:453993void RenderView::AltErrorPageFinished(WebFrame* frame,
3994 const WebURLError& original_error,
3995 const std::string& html) {
3996 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553997
3998 // If we failed to download the alternate error page, fall back to the
3999 // original error page if present. Otherwise, LoadNavigationErrorPage
4000 // will simply display a default error page.
4001 const std::string* html_to_load = &html;
4002 if (html.empty()) {
4003 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454004 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554005 html_to_load = &navigation_state->postponed_data();
4006 }
4007 LoadNavigationErrorPage(
4008 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454009}
4010
[email protected]30f75e62009-02-25 22:01:004011void RenderView::OnMoveOrResizeStarted() {
4012 if (webview())
[email protected]4605325d2010-02-08 23:46:044013 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:004014}
4015
[email protected]30f75e62009-02-25 22:01:004016void RenderView::OnResize(const gfx::Size& new_size,
4017 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104018 if (webview()) {
[email protected]4605325d2010-02-08 23:46:044019 webview()->hideSuggestionsPopup();
[email protected]cda45c02010-02-25 19:28:104020
4021 if (send_preferred_size_changes_) {
4022 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4023 // either width or height, allow scroll bars.
4024 bool allow_scrollbars = (
4025 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244026 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104027 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4028 }
4029 }
4030
[email protected]30f75e62009-02-25 22:01:004031 RenderWidget::OnResize(new_size, resizer_rect);
4032}
[email protected]0aa477bd2009-03-23 22:21:434033
[email protected]00c39612010-03-06 02:53:284034void RenderView::DidInitiatePaint() {
4035 // Notify any pepper plugins that we started painting. The plugin "should"
4036 // never notified that we started painting, this is used for internal
4037 // bookkeeping only, so we know that the set can not change under us.
4038 for (std::set<WebPluginDelegatePepper*>::iterator i =
4039 current_pepper_plugins_.begin();
4040 i != current_pepper_plugins_.end(); ++i)
4041 (*i)->RenderViewInitiatedPaint();
4042}
4043
4044void RenderView::DidFlushPaint() {
4045 // Notify any pepper plugins that we painted. This will call into the plugin,
4046 // and we it may ask to close itself as a result. This will, in turn, modify
4047 // our set, possibly invalidating the iterator. So we iterate on a copy that
4048 // won't change out from under us.
4049 std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_;
4050 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4051 i != plugins.end(); ++i) {
4052 // The copy above makes sure our iterator is never invalid if some plugins
4053 // are destroyed. But some plugin may decide to close all of its views in
4054 // response to a paint in one of them, so we need to make sure each one is
4055 // still "current" before using it.
4056 if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end())
4057 (*i)->RenderViewFlushedPaint();
4058 }
4059
4060 WebFrame* main_frame = webview()->mainFrame();
4061
4062 // If we have a provisional frame we are between the start and commit stages
4063 // of loading and we don't want to save stats.
4064 if (!main_frame->provisionalDataSource()) {
4065 WebDataSource* ds = main_frame->dataSource();
4066 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4067 DCHECK(navigation_state);
4068
4069 Time now = Time::Now();
4070 if (navigation_state->first_paint_time().is_null()) {
4071 navigation_state->set_first_paint_time(now);
4072 }
4073 if (navigation_state->first_paint_after_load_time().is_null() &&
4074 !navigation_state->finish_load_time().is_null()) {
4075 navigation_state->set_first_paint_after_load_time(now);
4076 }
4077 }
4078}
4079
4080
[email protected]05d478752009-04-08 23:38:164081void RenderView::OnClearFocusedNode() {
4082 if (webview())
[email protected]26aa0482009-09-30 16:55:274083 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164084}
4085
[email protected]699ab0d2009-04-23 23:19:144086void RenderView::OnSetBackground(const SkBitmap& background) {
4087 if (webview())
[email protected]b4bb2502009-10-01 22:35:274088 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144089
4090 SetBackground(background);
4091}
4092
[email protected]8c66c5a2009-07-22 17:26:344093void RenderView::OnSetActive(bool active) {
4094 if (webview())
[email protected]b4bb2502009-10-01 22:35:274095 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264096
4097#if defined(OS_MACOSX)
4098 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4099 for (plugin_it = plugin_delegates_.begin();
4100 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4101 (*plugin_it)->SetWindowFocus(active);
4102 }
4103#endif
[email protected]8c66c5a2009-07-22 17:26:344104}
4105
[email protected]6ce7abc52010-02-02 18:40:144106#if defined(OS_MACOSX)
4107void RenderView::OnSetWindowVisibility(bool visible) {
4108 // Inform plugins that their container has changed visibility.
4109 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4110 for (plugin_it = plugin_delegates_.begin();
4111 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4112 (*plugin_it)->SetContainerVisibility(visible);
4113 }
4114}
[email protected]1e6e3c992010-02-08 15:52:134115
4116void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4117 gfx::Rect view_frame) {
4118 // Inform plugins that their window's frame has changed.
4119 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4120 for (plugin_it = plugin_delegates_.begin();
4121 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4122 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4123 }
4124}
[email protected]6ce7abc52010-02-02 18:40:144125#endif // OS_MACOSX
4126
[email protected]309d7a282009-03-24 09:18:274127void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584128 const ListValue& args,
[email protected]c6619182009-05-12 14:59:324129 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474130 bool has_callback) {
[email protected]c6619182009-05-12 14:59:324131 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:474132 has_callback));
[email protected]309d7a282009-03-24 09:18:274133}
4134
[email protected]c6619182009-05-12 14:59:324135void RenderView::OnExtensionResponse(int request_id,
4136 bool success,
4137 const std::string& response,
4138 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354139 ExtensionProcessBindings::HandleResponse(
4140 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274141}
[email protected]c20210e62009-04-03 21:39:264142
[email protected]078b34612009-09-19 19:31:514143void RenderView::InjectToolstripCSS() {
4144 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4145 return;
4146
4147 static const base::StringPiece toolstrip_css(
4148 ResourceBundle::GetSharedInstance().GetRawDataResource(
4149 IDR_EXTENSION_TOOLSTRIP_CSS));
4150 std::string css = toolstrip_css.as_string();
4151 InsertCSS(L"", css, "ToolstripDefaultCSS");
4152}
4153
[email protected]7120f132009-07-20 21:05:374154void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494155 const ListValue& args,
4156 bool requires_incognito_access) {
4157 RendererExtensionBindings::Invoke(
4158 function_name, args, this, requires_incognito_access);
[email protected]7120f132009-07-20 21:05:374159}
4160
[email protected]e7e4f3c2009-04-21 15:24:084161// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264162//
[email protected]7a9b51f2009-06-29 21:28:294163// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:264164// The time points we keep are
4165// request: time document was requested by user
4166// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254167// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294168// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264169// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294170// first_paint: first paint performed
4171// first_paint_after_load: first paint performed after load is finished
4172// begin: request if it was user requested, start otherwise
4173//
[email protected]c20210e62009-04-03 21:39:264174// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:254175// request->start,
[email protected]7a9b51f2009-06-29 21:28:294176// start->commit,
4177// commit->finish_document,
4178// finish_document->finish,
4179// begin->commit,
4180// begin->finishDoc,
4181// begin->finish,
4182// begin->first_paint,
4183// begin->first_paint_after_load
4184// commit->finishDoc,
4185// commit->first_paint,
4186// commit->first_paint_after_load,
4187// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264188//
[email protected]e7e4f3c2009-04-21 15:24:084189// It's possible for the request time not to be set, if a client
4190// redirect had been done (the user never requested the page)
4191// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294192// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264193void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274194 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564195 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454196 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294197 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564198
[email protected]f9f4841b2010-03-20 05:41:424199 // If we've already dumped, do nothing.
4200 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294201 return;
[email protected]ed3fb032009-06-16 19:50:564202
[email protected]f9f4841b2010-03-20 05:41:424203 // Handle case where user hits "stop" or "back" before loading completely.
4204 bool abandoned_page = finish.is_null();
4205 if (abandoned_page) {
4206 finish = Time::Now();
4207 navigation_state->set_finish_load_time(finish);
4208 }
4209 UMA_HISTOGRAM_ENUMERATION("Renderer4.Abandoned", abandoned_page ? 1 : 0, 2);
4210
[email protected]f8999642009-10-27 21:39:424211 LogNavigationState(navigation_state, main_frame->dataSource());
4212
[email protected]a7ccc4d2010-01-27 08:14:484213 NavigationState::LoadType load_type = navigation_state->load_type();
4214 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184215 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484216
[email protected]ab9eabac2010-03-16 16:54:104217 // Site isolation metrics.
4218 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4219 cross_origin_access_count_);
4220 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4221 same_origin_access_count_);
4222
[email protected]7a9b51f2009-06-29 21:28:294223 Time request = navigation_state->request_time();
4224 Time start = navigation_state->start_load_time();
4225 Time commit = navigation_state->commit_load_time();
4226 Time finish_doc = navigation_state->finish_document_load_time();
4227 Time first_paint = navigation_state->first_paint_time();
4228 Time first_paint_after_load =
4229 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:264230
[email protected]7a9b51f2009-06-29 21:28:294231 Time begin;
4232 // Client side redirects will have no request time.
4233 if (request.is_null()) {
4234 begin = start;
4235 } else {
4236 begin = request;
4237 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084238 }
[email protected]7a9b51f2009-06-29 21:28:294239 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4240 UMA_HISTOGRAM_MEDIUM_TIMES(
4241 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4242 UMA_HISTOGRAM_MEDIUM_TIMES(
4243 "Renderer4.FinishDocToFinish", finish - finish_doc);
4244
4245 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484246
4247 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4248 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4249 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484250 TimeDelta begin_to_finish_doc = finish_doc - begin;
4251 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184252
4253 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4254 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4255 static const size_t kBeginToFinishBucketCount(100);
4256 TimeDelta begin_to_finish = finish_doc - begin;
4257 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4258 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4259
[email protected]a7ccc4d2010-01-27 08:14:484260 switch (load_type) {
4261 case NavigationState::UNDEFINED_LOAD:
4262 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4263 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4264 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184265 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4266 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4267 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484268 break;
4269 case NavigationState::RELOAD:
4270 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4271 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4272 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184273 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4274 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4275 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484276 break;
4277 case NavigationState::HISTORY_LOAD:
4278 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4279 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4280 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184281 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4282 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4283 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484284 break;
4285 case NavigationState::NORMAL_LOAD:
4286 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4287 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4288 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184289 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4290 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4291 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484292 break;
[email protected]4c1b6f0b2010-02-07 16:38:184293 case NavigationState::LINK_LOAD_NORMAL:
4294 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484295 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4296 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184297 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4298 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4299 kBeginToFinishBucketCount);
4300 break;
4301 case NavigationState::LINK_LOAD_RELOAD:
4302 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4303 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4304 kBeginToFinishDocBucketCount);
4305 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4306 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4307 kBeginToFinishBucketCount);
4308 break;
4309 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4310 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4311 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4312 kBeginToFinishDocBucketCount);
4313 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4314 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4315 kBeginToFinishBucketCount);
4316 break;
4317 case NavigationState::LINK_LOAD_CACHE_ONLY:
4318 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4319 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4320 kBeginToFinishDocBucketCount);
4321 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4322 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4323 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484324 break;
4325 default:
4326 break;
4327 }
4328
4329 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4330 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4331 if (use_dns_histogram) {
[email protected]f9f4841b2010-03-20 05:41:424332 UMA_HISTOGRAM_ENUMERATION(
4333 FieldTrial::MakeName("Renderer4.Abandoned", "DnsImpact"),
4334 abandoned_page ? 1 : 0, 2);
4335 UMA_HISTOGRAM_ENUMERATION(
4336 FieldTrial::MakeName("Renderer4.LoadType", "DnsImpact"),
[email protected]fd11f1752010-02-23 22:35:484337 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484338 switch (load_type) {
4339 case NavigationState::NORMAL_LOAD:
4340 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184341 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4342 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4343 kBeginToFinishBucketCount);
4344 break;
4345 case NavigationState::LINK_LOAD_NORMAL:
4346 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184347 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4348 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4349 kBeginToFinishBucketCount);
4350 break;
4351 case NavigationState::LINK_LOAD_RELOAD:
4352 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184353 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4354 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4355 kBeginToFinishBucketCount);
4356 break;
4357 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4358 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184359 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4360 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4361 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484362 break;
4363 default:
4364 break;
4365 }
4366 }
4367
[email protected]f9f4841b2010-03-20 05:41:424368 static bool use_packet_split_histogram(FieldTrialList::Find("PacketSplit") &&
4369 !FieldTrialList::Find("PacketSplit")->group_name().empty());
4370 if (use_packet_split_histogram) {
4371 UMA_HISTOGRAM_ENUMERATION(
4372 FieldTrial::MakeName("Renderer4.Abandoned", "PacketSplit"),
4373 abandoned_page ? 1 : 0, 2);
4374 UMA_HISTOGRAM_ENUMERATION(
4375 FieldTrial::MakeName("Renderer4.LoadType", "PacketSplit"),
4376 load_type, NavigationState::kLoadTypeMax);
4377 switch (load_type) {
4378 case NavigationState::NORMAL_LOAD:
4379 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4380 "Renderer4.BeginToFinish_NormalLoad", "PacketSplit"),
4381 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4382 kBeginToFinishBucketCount);
4383 break;
4384 case NavigationState::LINK_LOAD_NORMAL:
4385 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4386 "Renderer4.BeginToFinish_LinkLoadNormal", "PacketSplit"),
4387 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4388 kBeginToFinishBucketCount);
4389 break;
4390 case NavigationState::LINK_LOAD_RELOAD:
4391 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4392 "Renderer4.BeginToFinish_LinkLoadReload", "PacketSplit"),
4393 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4394 kBeginToFinishBucketCount);
4395 break;
4396 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4397 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4398 "Renderer4.BeginToFinish_LinkLoadStaleOk", "PacketSplit"),
4399 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4400 kBeginToFinishBucketCount);
4401 break;
4402 default:
4403 break;
4404 }
4405 }
4406
[email protected]a7ccc4d2010-01-27 08:14:484407 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4408 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4409 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484410 UMA_HISTOGRAM_ENUMERATION(
4411 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4412 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484413 switch (load_type) {
4414 case NavigationState::NORMAL_LOAD:
4415 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484416 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4417 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4418 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484419 break;
[email protected]4c1b6f0b2010-02-07 16:38:184420 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484421 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484422 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4423 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4424 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184425 break;
4426 case NavigationState::LINK_LOAD_RELOAD:
4427 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484428 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4429 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4430 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184431 break;
4432 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4433 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484434 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4435 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4436 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184437 break;
4438 case NavigationState::LINK_LOAD_CACHE_ONLY:
4439 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484440 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4441 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4442 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484443 break;
4444 default:
4445 break;
4446 }
4447 }
4448
4449 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4450 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184451 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4452 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484453 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4454 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4455 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4456 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544457
[email protected]0a32257a2009-07-09 18:10:414458 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4459 finish - start, kBeginToFinishMin,
4460 kBeginToFinishMax, kBeginToFinishBucketCount);
4461 if (!request.is_null())
4462 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4463 finish - request, kBeginToFinishMin,
4464 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544465
[email protected]7a9b51f2009-06-29 21:28:294466 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4467
4468 if (!first_paint.is_null()) {
4469 UMA_HISTOGRAM_MEDIUM_TIMES(
4470 "Renderer4.BeginToFirstPaint", first_paint - begin);
4471 UMA_HISTOGRAM_MEDIUM_TIMES(
4472 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264473 }
[email protected]7a9b51f2009-06-29 21:28:294474
4475 if (!first_paint_after_load.is_null()) {
4476 UMA_HISTOGRAM_MEDIUM_TIMES(
4477 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4478 UMA_HISTOGRAM_MEDIUM_TIMES(
4479 "Renderer4.CommitToFirstPaintAfterLoad",
4480 first_paint_after_load - commit);
4481 UMA_HISTOGRAM_MEDIUM_TIMES(
4482 "Renderer4.FinishToFirstPaintAfterLoad",
4483 first_paint_after_load - finish);
4484 }
4485
4486 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414487
4488 // Since there are currently no guarantees that renderer histograms will be
4489 // sent to the browser, we initiate a PostTask here to be sure that we send
4490 // the histograms we generated. Without this call, pages that don't have an
4491 // on-close-handler might generate data that is lost when the renderer is
4492 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484493 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4494 // should post when the onload is complete, so that it doesn't interfere with
4495 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414496 if (RenderThread::current()) {
4497 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134498 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414499 }
[email protected]c20210e62009-04-03 21:39:264500}
[email protected]e846d0d2009-05-20 00:53:064501
[email protected]f8999642009-10-27 21:39:424502void RenderView::LogNavigationState(const NavigationState* state,
4503 const WebDataSource* ds) const {
4504 // Because this function gets called on every page load,
4505 // take extra care to optimize it away if logging is turned off.
4506 if (logging::LOG_INFO < logging::GetMinLogLevel())
4507 return;
4508
4509 DCHECK(state);
4510 DCHECK(ds);
4511 GURL url(ds->request().url());
4512 Time start = state->start_load_time();
4513 Time finish = state->finish_load_time();
4514 // TODO(mbelshe): should we log more stats?
4515 LOG(INFO) << "PLT: "
4516 << (finish - start).InMilliseconds()
4517 << "ms "
4518 << url.spec();
4519}
4520
[email protected]cc0445f2009-10-13 16:09:084521void RenderView::focusAccessibilityObject(
4522 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064523#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154524 // TODO(dglazkov): Current logic implies that focus change can only be made
4525 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4526 // where accessibility is initialized. We should determine whether that's
4527 // right.
4528 if (!accessibility_.get())
4529 return;
[email protected]e846d0d2009-05-20 00:53:064530
4531 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154532 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064533
4534 // If id is valid, alert the browser side that an accessibility focus change
4535 // occurred.
4536 if (acc_obj_id >= 0)
4537 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4538
4539#else // defined(OS_WIN)
4540 // TODO(port): accessibility not yet implemented
4541 NOTIMPLEMENTED();
4542#endif
4543}
[email protected]daa8c58e2009-06-15 17:21:104544
[email protected]e9e07992010-02-17 21:04:364545void RenderView::SendForms(WebFrame* frame) {
4546 WebVector<WebFormElement> web_forms;
4547 frame->forms(web_forms);
4548
4549 std::vector<FormFieldValues> forms;
4550 for (size_t i = 0; i < web_forms.size(); ++i) {
4551 const WebFormElement& web_form = web_forms[i];
4552
4553 if (web_form.autoComplete()) {
4554 scoped_ptr<FormFieldValues> form(FormFieldValues::Create(web_form));
4555 if (form.get())
4556 forms.push_back(*form);
4557 }
4558 }
4559
4560 if (!forms.empty())
4561 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
4562}
4563
[email protected]a3018be2010-03-09 04:28:484564void RenderView::didChangeAccessibilityObjectState(
4565 const WebKit::WebAccessibilityObject& acc_obj) {
4566#if defined(OS_WIN)
4567 // TODO(dglazkov): Current logic implies that a state change can only be made
4568 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4569 // where accessibility is initialized. We should determine whether that's
4570 // right.
4571 if (!accessibility_.get())
4572 return;
4573
4574 // Retrieve the accessibility object id of the AccessibilityObject.
4575 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4576
4577 // If id is valid, alert the browser side that an accessibility object state
4578 // change occurred.
4579 if (acc_obj_id >= 0)
4580 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4581 acc_obj_id));
4582
4583#else // defined(OS_WIN)
4584 // TODO(port): accessibility not yet implemented
4585 NOTIMPLEMENTED();
4586#endif
4587}
4588
[email protected]daa8c58e2009-06-15 17:21:104589void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:484590 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454591 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104592
4593 std::vector<PasswordForm> password_forms;
4594 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484595 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104596
4597 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:484598 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:104599 scoped_ptr<PasswordForm> password_form(
4600 PasswordFormDomManager::CreatePasswordForm(form));
4601 if (password_form.get())
4602 password_forms.push_back(*password_form);
4603 }
4604 }
4605
4606 if (!password_forms.empty())
4607 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4608}
[email protected]0fda7272009-06-26 15:49:334609
4610void RenderView::Print(WebFrame* frame, bool script_initiated) {
4611 DCHECK(frame);
4612 if (print_helper_.get() == NULL) {
4613 print_helper_.reset(new PrintWebViewHelper(this));
4614 }
4615 print_helper_->Print(frame, script_initiated);
4616}
[email protected]446705872009-09-10 07:22:484617
4618void RenderView::OnSetEditCommandsForNextKeyEvent(
4619 const EditCommands& edit_commands) {
4620 edit_commands_ = edit_commands;
4621}
4622
[email protected]61f5a7b2009-12-22 22:21:204623void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274624 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354625 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204626 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4627 false));
[email protected]912256b32009-09-18 09:47:354628 return;
4629 }
4630
[email protected]fa7b6b542009-11-03 05:02:304631 WebDataSource* ds = main_frame->dataSource();
4632 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4633 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204634 pending_code_execution_queue_.push(
4635 linked_ptr<ViewMsg_ExecuteCode_Params>(
4636 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304637 return;
4638 }
4639
[email protected]61f5a7b2009-12-22 22:21:204640 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304641}
4642
4643void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204644 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484645 // Don't execute scripts in gallery pages.
4646 GURL frame_url = GURL(frame->url());
4647 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4648 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4649 return;
4650 }
4651
[email protected]20ad2692009-11-20 18:27:204652 std::vector<WebFrame*> frame_vector;
4653 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204654 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204655 GetAllChildFrames(frame, &frame_vector);
4656
4657 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4658 frame_it != frame_vector.end(); ++frame_it) {
4659 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204660 if (params.is_javascript) {
4661 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4662 continue;
4663
[email protected]20ad2692009-11-20 18:27:204664 std::vector<WebScriptSource> sources;
4665 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204666 WebScriptSource(WebString::fromUTF8(params.code)));
4667 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204668 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204669 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204670 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4671 } else {
[email protected]61f5a7b2009-12-22 22:21:204672 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204673 }
[email protected]912256b32009-09-18 09:47:354674 }
4675
[email protected]61f5a7b2009-12-22 22:21:204676 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354677}
4678
[email protected]60c42a8c72009-10-09 04:08:594679void RenderView::Close() {
4680 // We need to grab a pointer to the doomed WebView before we destroy it.
4681 WebView* doomed = webview();
4682 RenderWidget::Close();
4683 Singleton<ViewMap>::get()->erase(doomed);
4684}
4685
[email protected]446705872009-09-10 07:22:484686void RenderView::DidHandleKeyEvent() {
4687 edit_commands_.clear();
4688}
4689
[email protected]941e4552010-02-01 21:23:434690#if defined(OS_MACOSX)
4691void RenderView::OnWasHidden() {
4692 RenderWidget::OnWasHidden();
4693
4694 // Inform plugins that their container is no longer visible.
4695 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4696 for (plugin_it = plugin_delegates_.begin();
4697 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4698 (*plugin_it)->SetContainerVisibility(false);
4699 }
4700}
4701
4702void RenderView::OnWasRestored(bool needs_repainting) {
4703 RenderWidget::OnWasRestored(needs_repainting);
4704
4705 // Inform plugins that their container is now visible.
4706 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4707 for (plugin_it = plugin_delegates_.begin();
4708 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4709 (*plugin_it)->SetContainerVisibility(true);
4710 }
4711}
[email protected]1e6e3c992010-02-08 15:52:134712
4713void RenderView::OnSetFocus(bool enable) {
4714 RenderWidget::OnSetFocus(enable);
4715
4716 // RenderWidget's call to setFocus can cause the underlying webview's
4717 // activation state to change just like a call to setIsActive.
4718 if (enable && webview() && webview()->isActive()) {
4719 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4720 for (plugin_it = plugin_delegates_.begin();
4721 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4722 (*plugin_it)->SetWindowFocus(true);
4723 }
4724 }
4725}
[email protected]941e4552010-02-01 21:23:434726#endif // OS_MACOSX
4727
[email protected]83dde542009-09-11 20:59:554728void RenderView::EnsureDocumentTag() {
4729 // TODO(darin): There's actually no reason for this to be here. We should
4730 // have the browser side manage the document tag.
4731#if defined(OS_MACOSX)
4732 if (!has_document_tag_) {
4733 // Make the call to get the tag.
4734 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4735 has_document_tag_ = true;
4736 }
4737#endif
4738}
[email protected]12636df2009-09-28 22:32:214739
[email protected]43f28f832010-02-03 02:28:484740#if defined(OS_MACOSX)
4741gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle() {
4742 gfx::PluginWindowHandle window = NULL;
4743 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
4744 routing_id(), &window));
4745 return window;
4746}
4747
4748void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4749 if (window)
4750 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4751}
4752
[email protected]44ce0b12010-03-12 16:45:334753void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4754 int32 width,
4755 int32 height,
4756 uint64 io_surface_identifier) {
4757 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484758 routing_id(), window, width, height, io_surface_identifier));
4759}
4760
[email protected]44ce0b12010-03-12 16:45:334761void RenderView::AcceleratedSurfaceSetTransportDIB(
4762 gfx::PluginWindowHandle window,
4763 int32 width,
4764 int32 height,
4765 TransportDIB::Handle transport_dib) {
4766 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074767 routing_id(), window, width, height, transport_dib));
4768}
4769
[email protected]44ce0b12010-03-12 16:45:334770TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4771 size_t size) {
[email protected]1aef98132010-02-23 18:00:074772 TransportDIB::Handle dib_handle;
4773 // Assume this is a synchronous RPC.
4774 if (Send(new ViewHostMsg_AllocTransportDIB(size, &dib_handle)))
4775 return dib_handle;
4776 // Return an invalid handle if Send() fails.
4777 return TransportDIB::DefaultHandleValue();
4778}
4779
[email protected]44ce0b12010-03-12 16:45:334780void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074781 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4782}
4783
[email protected]44ce0b12010-03-12 16:45:334784void RenderView::AcceleratedSurfaceBuffersSwapped(
4785 gfx::PluginWindowHandle window) {
4786 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:484787}
4788#endif
[email protected]58c321d2010-02-19 12:11:284789
4790WebKit::WebGeolocationServiceInterface* RenderView::getGeolocationService() {
4791 if (!geolocation_dispatcher_.get())
4792 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
4793 return geolocation_dispatcher_.get();
4794}