blob: c58b10b6243d0e23d21e1e449a7349866c7b473e [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]91e81ae2009-05-08 22:14:3811#include "app/gfx/color_utils.h"
[email protected]37126212009-05-06 02:23:3112#include "app/gfx/favicon_size.h"
[email protected]010ea08a2009-10-11 20:21:3213#include "app/gfx/native_widget_types.h"
[email protected]a92b8642009-05-05 23:38:5614#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3115#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1116#include "app/resource_bundle.h"
[email protected]2041cf342010-02-19 03:15:5917#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2918#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5019#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0520#include "base/field_trial.h"
[email protected]30507922010-01-15 16:48:2321#include "base/histogram.h"
[email protected]8380c092009-06-25 17:45:5122#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5323#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2924#include "base/string_piece.h"
25#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2326#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5727#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0928#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5529#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1731#include "chrome/common/chrome_constants.h"
[email protected]1f4fc8e8c2010-01-02 00:46:4132#include "chrome/common/histogram_synchronizer.h"
[email protected]d146b832009-12-23 02:45:4833#include "chrome/common/extensions/extension_constants.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1735#include "chrome/common/page_zoom.h"
[email protected]e09ba552009-02-05 03:26:2936#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2637#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5939#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2541#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1142#include "chrome/renderer/devtools_agent.h"
43#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3544#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3245#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3546#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3747#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2848#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5650#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5651#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1252#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3053#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5054#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2555#include "chrome/renderer/render_process.h"
[email protected]bd92c3a2010-01-13 05:02:3456#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4657#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3558#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2960#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2961#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4262#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5663#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2764#include "grit/generated_resources.h"
65#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3466#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2967#include "net/base/escape.h"
68#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0069#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1070#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3071#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]58c321d2010-02-19 12:11:2872#include "third_party/WebKit/WebKit/chromium/public/GeolocationServiceBridgeChromium.h"
[email protected]418ed5ab2009-11-12 01:14:4973#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
74#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0775#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4976#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
77#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3278#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4979#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3580#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]418ed5ab2009-11-12 01:14:4981#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
82#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
83#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]95056b582010-02-18 01:29:2484#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4985#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3286#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0787#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]418ed5ab2009-11-12 01:14:4988#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
89#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
90#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
92#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
93#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:3495#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:4996#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
98#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
99#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
100#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]80f584d92010-01-21 03:59:04102#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29103#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29104#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24105#include "webkit/glue/form_field.h"
106#include "webkit/glue/form_field_values.h"
107#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34108#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17109#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51110#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29111#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29112#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:23113#include "webkit/glue/plugins/webplugin_delegate_impl.h"
initial.commit09911bf2008-07-26 23:55:29114#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29115#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17116#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:59117#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29118
[email protected]6c8afae52009-01-22 02:24:57119#if defined(OS_WIN)
120// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57121// * theming
[email protected]86281ad2009-10-07 20:07:17122#include "app/gfx/native_theme_win.h"
[email protected]39cd64ed2010-02-05 02:18:46123#elif defined(OS_LINUX)
124#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]6c8afae52009-01-22 02:24:57125#endif
126
[email protected]80f584d92010-01-21 03:59:04127using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26128using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33129using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45130using webkit_glue::AltErrorPageResourceFetcher;
[email protected]95056b582010-02-18 01:29:24131using webkit_glue::FormField;
[email protected]51bd36612009-10-20 22:49:47132using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17133using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56134using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10135using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15136using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08137using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41138using WebKit::WebColor;
139using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59140using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44141using WebKit::WebContextMenuData;
[email protected]d9ec5c0f2009-12-23 11:55:07142using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55143using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28144using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29145using WebKit::WebDevToolsAgent;
[email protected]e80c73b2009-04-07 23:24:58146using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25147using WebKit::WebDragOperation;
148using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51149using WebKit::WebEditingAction;
[email protected]6069da8c2009-10-20 20:33:49150using WebKit::WebFindOptions;
[email protected]979c28b2009-11-07 01:30:48151using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45152using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17153using WebKit::WebHistoryItem;
[email protected]95056b582010-02-18 01:29:24154using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17155using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28156using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17157using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28158using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28159using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51160using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07161using WebKit::WebPageSerializer;
162using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17163using WebKit::WebPlugin;
164using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52165using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59166using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51167using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52168using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40169using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35170using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29171using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59172using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42173using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02174using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34175using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28176using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51177using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52178using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28179using WebKit::WebURL;
180using WebKit::WebURLError;
181using WebKit::WebURLRequest;
182using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28183using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03184using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28185using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43186using WebKit::WebWorker;
187using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33188
initial.commit09911bf2008-07-26 23:55:29189//-----------------------------------------------------------------------------
190
191// define to write the time necessary for thumbnail/DOM text retrieval,
192// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29193// #define TIME_TEXT_RETRIEVAL
194
195// maximum number of characters in the document to index, any text beyond this
196// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57197static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29198
199// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37200static const int kThumbnailWidth = 212;
201static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29202
203// Delay in milliseconds that we'll wait before capturing the page contents
204// and thumbnail.
205static const int kDelayForCaptureMs = 500;
206
207// Typically, we capture the page data once the page is loaded.
208// Sometimes, the page never finishes to load, preventing the page capture
209// To workaround this problem, we always perform a capture after the following
210// delay.
211static const int kDelayForForcedCaptureMs = 6000;
212
[email protected]882daa92009-11-05 16:31:31213// Time, in seconds, we delay before sending content state changes (such as form
214// state and scroll position) to the browser. We delay sending changes to avoid
215// spamming the browser.
216// To avoid having tab/session restore require sending a message to get the
217// current content state during tab closing we use a shorter timeout for the
218// foreground renderer. This means there is a small window of time from which
219// content state is modified and not sent to session restore, but this is
220// better than having to wake up all renderers during shutdown.
221static const int kDelaySecondsForContentStateSyncHidden = 5;
222static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29223
[email protected]0aa55312008-10-17 21:53:08224// The maximum number of popups that can be spawned from one page.
225static const int kMaximumNumberOfUnacknowledgedPopups = 25;
226
initial.commit09911bf2008-07-26 23:55:29227static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16228 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29229
[email protected]50b691c2008-10-31 19:08:35230static const char* const kBackForwardNavigationScheme = "history";
231
[email protected]8c4cdd42010-01-12 21:31:13232// The string returned in DetectLanguage if we failed to detect the language.
[email protected]8dc5a2052010-01-19 21:32:42233static const char* const kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13234
[email protected]726985e22009-06-18 21:09:28235static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
236 WebVector<WebURL> urls;
237 ds->redirectChain(urls);
238 result->reserve(urls.size());
239 for (size_t i = 0; i < urls.size(); ++i)
240 result->push_back(urls[i]);
241}
242
[email protected]61f5a7b2009-12-22 22:21:20243static bool UrlMatchesPermissions(
244 const GURL& url, const std::vector<URLPattern>& host_permissions) {
245 for (size_t i = 0; i < host_permissions.size(); ++i) {
246 if (host_permissions[i].MatchesUrl(url))
247 return true;
248 }
249
250 return false;
251}
252
[email protected]30507922010-01-15 16:48:23253static bool PaintViewIntoCanvas(WebView* view,
254 skia::PlatformCanvas& canvas) {
255 view->layout();
256 const WebSize& size = view->size();
257
258 if (!canvas.initialize(size.width, size.height, true))
259 return false;
260
261 view->paint(webkit_glue::ToWebCanvas(&canvas),
262 WebRect(0, 0, size.width, size.height));
263 // TODO: Add a way to snapshot the whole page, not just the currently
264 // visible part.
265
266 return true;
267}
268
269// Calculates how "boring" a thumbnail is. The boring score is the
270// 0,1 ranged percentage of pixels that are the most common
271// luma. Higher boring scores indicate that a higher percentage of a
272// bitmap are all the same brightness.
273static double CalculateBoringScore(SkBitmap* bitmap) {
274 int histogram[256] = {0};
275 color_utils::BuildLumaHistogram(bitmap, histogram);
276
277 int color_count = *std::max_element(histogram, histogram + 256);
278 int pixel_count = bitmap->width() * bitmap->height();
279 return static_cast<double>(color_count) / pixel_count;
280}
281
initial.commit09911bf2008-07-26 23:55:29282///////////////////////////////////////////////////////////////////////////////
283
[email protected]60c42a8c72009-10-09 04:08:59284int32 RenderView::next_page_id_ = 1;
285
[email protected]2fab253a2009-08-17 23:00:59286RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34287 const WebPreferences& webkit_preferences,
288 int64 session_storage_namespace_id)
[email protected]81a34412009-01-05 19:17:24289 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09290 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21291 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24292 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21293 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24294 page_id_(-1),
295 last_page_id_sent_to_browser_(-1),
296 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24297 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46298 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50299 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11300 devtools_agent_(NULL),
301 devtools_client_(NULL),
[email protected]a1128322009-10-06 18:38:46302 file_chooser_completion_(NULL),
[email protected]81a34412009-01-05 19:17:24303 history_back_list_count_(0),
304 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24305 has_unload_listener_(false),
306 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39307 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24308 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26309 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31310 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25311 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26312 ALLOW_THIS_IN_INITIALIZER_LIST(
313 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53314 view_type_(ViewType::INVALID),
315 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55316 last_top_level_navigation_page_id_(-1),
317#if defined(OS_MACOSX)
318 has_document_tag_(false),
319#endif
[email protected]98324892009-09-09 21:16:05320 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32321 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34322 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]0bedb8a2010-01-14 19:36:32323 ALLOW_THIS_IN_INITIALIZER_LIST(text_translator_(this)) {
[email protected]71b0d5d2010-02-15 05:43:07324 ClearBlockedContentSettings();
[email protected]7e0831b2010-02-01 08:45:15325 page_translator_.reset(new PageTranslator(&text_translator_, this));
initial.commit09911bf2008-07-26 23:55:29326}
327
328RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08329 if (decrement_shared_popup_at_destruction_)
330 shared_popup_counter_->data--;
331
[email protected]b0950a72009-09-29 23:16:17332 // Dispose of un-disposed image fetchers.
333 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
334 i != image_fetchers_.end(); ++i) {
335 delete *i;
336 }
337
[email protected]a1128322009-10-06 18:38:46338 // If file chooser is still waiting for answer, dispatch empty answer.
339 if (file_chooser_completion_)
340 file_chooser_completion_->didChooseFile(WebVector<WebString>());
341
[email protected]83dde542009-09-11 20:59:55342#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05343 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55344 if (has_document_tag_)
345 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
346#endif
[email protected]98324892009-09-09 21:16:05347
[email protected]5fb88962009-04-16 19:03:25348 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59349
350#ifndef NDEBUG
351 // Make sure we are no longer referenced by the ViewMap.
352 ViewMap* views = Singleton<ViewMap>::get();
353 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
354 DCHECK_NE(this, it->second) << "Failed to call Close?";
355#endif
356}
357
358/*static*/
359void RenderView::ForEach(RenderViewVisitor* visitor) {
360 ViewMap* views = Singleton<ViewMap>::get();
361 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
362 if (!visitor->Visit(it->second))
363 return;
364 }
365}
366
367/*static*/
368RenderView* RenderView::FromWebView(WebView* webview) {
369 ViewMap* views = Singleton<ViewMap>::get();
370 ViewMap::iterator it = views->find(webview);
371 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29372}
373
374/*static*/
[email protected]0aa55312008-10-17 21:53:08375RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24376 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15377 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08378 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51379 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08380 const WebPreferences& webkit_prefs,
381 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34382 int32 routing_id,
383 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29384 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34385 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
386 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29387 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29388 opener_id,
[email protected]80d96fa2009-06-10 22:34:51389 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08390 counter,
initial.commit09911bf2008-07-26 23:55:29391 routing_id); // adds reference
392 return view;
393}
394
395/*static*/
396void RenderView::SetNextPageID(int32 next_page_id) {
397 // This method should only be called during process startup, and the given
398 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05399 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29400 DCHECK(next_page_id >= next_page_id_);
401 next_page_id_ = next_page_id;
402}
403
[email protected]afe3a1672009-11-17 19:04:12404void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56405 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
406}
407
[email protected]a3a8fb6d2009-10-22 20:12:51408void RenderView::PluginCrashed(const FilePath& plugin_path) {
409 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29410}
411
[email protected]d8fd6fa2010-02-01 15:54:26412#if defined(OS_MACOSX)
413void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
414 plugin_delegates_.insert(delegate);
415}
416
417void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
418 plugin_delegates_.erase(delegate);
419}
420#endif
421
[email protected]18bcc3c2009-01-27 21:39:15422void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29423 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51424 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08425 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29426 int32 routing_id) {
427 DCHECK(!webview());
428
429 if (opener_id != MSG_ROUTING_NONE)
430 opener_id_ = opener_id;
431
[email protected]0aa55312008-10-17 21:53:08432 if (counter) {
433 shared_popup_counter_ = counter;
434 shared_popup_counter_->data++;
435 decrement_shared_popup_at_destruction_ = true;
436 } else {
437 shared_popup_counter_ = new SharedRenderViewCounter(0);
438 decrement_shared_popup_at_destruction_ = false;
439 }
440
[email protected]58bfc6b2009-06-24 09:45:02441 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04442
[email protected]50ae00ef2009-10-19 05:11:03443 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59444 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59445 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27446 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29447 webview()->setDevToolsAgent(
448 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29449
[email protected]d3ba77272009-09-03 00:06:09450 OnSetRendererPrefs(renderer_prefs);
451
initial.commit09911bf2008-07-26 23:55:29452 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24453 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29454 // Take a reference on behalf of the RenderThread. This will be balanced
455 // when we receive ViewMsg_Close.
456 AddRef();
457
458 // If this is a popup, we must wait for the CreatingNew_ACK message before
459 // completing initialization. Otherwise, we can finish it now.
460 if (opener_id == MSG_ROUTING_NONE) {
461 did_show_ = true;
462 CompleteInit(parent_hwnd);
463 }
464
465 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29466
[email protected]58bfc6b2009-06-24 09:45:02467 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09468 if (command_line.HasSwitch(switches::kDomAutomationController))
469 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29470
[email protected]5fb88962009-04-16 19:03:25471 audio_message_filter_ = new AudioMessageFilter(routing_id_);
472 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29473}
474
475void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27476 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27477 if (main_frame)
478 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26479
[email protected]b2abac72009-02-26 12:39:28480 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11481 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28482 return;
[email protected]b4b967e2009-04-22 11:33:05483 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
484 return;
[email protected]b6849bda2009-10-14 23:59:26485 if (notification_provider_->OnMessageReceived(message))
486 return;
[email protected]58c321d2010-02-19 12:11:28487 if (geolocation_dispatcher_.get() &&
488 geolocation_dispatcher_->OnMessageReceived(message)) {
489 return;
490 }
[email protected]b2abac72009-02-26 12:39:28491
initial.commit09911bf2008-07-26 23:55:29492 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29493 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23494 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29495 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01496 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29497 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
498 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56499 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29500 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
501 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
502 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
503 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
504 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
505 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27506#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35507 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27508#endif
initial.commit09911bf2008-07-26 23:55:29509 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
510 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05511 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
512 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
513 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04514 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29515 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
516 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
517 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15518 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29519 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]630e26b2008-10-14 22:55:17520 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]f85f0702010-01-30 09:31:01521 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost,
522 OnSetContentSettingsForLoadingHost)
[email protected]40bd6582009-12-04 23:49:51523 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
524 OnSetZoomLevelForLoadingHost)
initial.commit09911bf2008-07-26 23:55:29525 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18526 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
527 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28528 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33529 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29530 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48531 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29532 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29533 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29534 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
535 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
536 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
537 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
538 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
539 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45540 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29541 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50542 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
543 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29544 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
545 OnDragSourceSystemDragEnded)
546 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
547 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
548 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
549 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
550 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
551 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
552 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
553 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
554 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
555 OnUpdateBackForwardListCount)
556 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
557 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04558 IPC_MESSAGE_HANDLER(
559 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
560 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29561 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50562 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
563 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
564 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29565 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
566 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
567 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45568 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
569 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08570 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
571 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24572 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
573 OnAutoFillSuggestionsReturned)
574 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
575 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48576 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
577 OnAutoFillFormDataFilled)
[email protected]2c4410d2009-05-06 23:46:22578 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
579 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00580 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27581 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37582 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
583 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16584 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14585 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25586 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
587 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:51588 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53589 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
590 OnUpdateBrowserWindowId)
591 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
592 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56593 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34594 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14595#if defined(OS_MACOSX)
596 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13597 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14598#endif
[email protected]446705872009-09-10 07:22:48599 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33600 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35601 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
602 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33603 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
604 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42605 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]0bedb8a2010-01-14 19:36:32606 IPC_MESSAGE_HANDLER(ViewMsg_TranslateTextReponse, OnTranslateTextResponse)
[email protected]634a6f92008-12-01 21:39:31607
initial.commit09911bf2008-07-26 23:55:29608 // Have the super handle all other messages.
609 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
610 IPC_END_MESSAGE_MAP()
611}
612
initial.commit09911bf2008-07-26 23:55:29613void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27614 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29615 if (!main_frame)
616 return;
617
618 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45619 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29620 if (url.is_empty())
621 return;
622
623 if (size_.IsEmpty())
624 return; // Don't create an empty thumbnail!
625
626 ThumbnailScore score;
627 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02628 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15629 &thumbnail, &score))
630 return;
631
initial.commit09911bf2008-07-26 23:55:29632 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46633 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29634}
635
[email protected]30507922010-01-15 16:48:23636void RenderView::SendSnapshot() {
637 SkBitmap snapshot;
638 bool error = false;
639
640 WebFrame* main_frame = webview()->mainFrame();
641 if (!main_frame)
642 error = true;
643
644 if (!error && !CaptureSnapshot(webview(), &snapshot))
645 error = true;
646
647 DCHECK(error == snapshot.empty()) <<
648 "Snapshot should be empty on error, non-empty otherwise.";
649
650 // Send the snapshot to the browser process.
651 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
652}
653
[email protected]068637222009-01-29 16:58:07654void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29655 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58656 if (webview()) {
657 // If the user has selected text in the currently focused frame we print
658 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27659 if (webview()->focusedFrame()->hasSelection())
660 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58661 else
[email protected]26aa0482009-09-30 16:55:27662 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58663 }
initial.commit09911bf2008-07-26 23:55:29664}
665
[email protected]82270452009-06-19 15:58:01666void RenderView::OnPrintingDone(int document_cookie, bool success) {
667 // Ignoring document cookie here since only one print job can be outstanding
668 // per renderer and document_cookie is 0 when printing is successful.
669 DCHECK(print_helper_.get());
670 if (print_helper_.get() != NULL) {
671 print_helper_->DidFinishPrinting(success);
672 }
673}
674
initial.commit09911bf2008-07-26 23:55:29675void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
676 if (load_id != page_id_)
677 return; // this capture call is no longer relevant due to navigation
678 if (load_id == last_indexed_page_id_)
679 return; // we already indexed this page
680
681 if (!webview())
682 return;
683
[email protected]26aa0482009-09-30 16:55:27684 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29685 if (!main_frame)
686 return;
687
688 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45689 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29690 return;
691
692 // Don't index/capture pages that failed to load. This only checks the top
693 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45694 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28695 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29696 return;
697
698 if (!preliminary_capture)
699 last_indexed_page_id_ = load_id;
700
[email protected]a8a81292010-01-21 00:32:45701 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45702 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29703 if (url.is_empty())
704 return;
705
[email protected]a8a81292010-01-21 00:32:45706 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29707 std::wstring contents;
708 CaptureText(main_frame, &contents);
709 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45710 base::TimeTicks begin_time = base::TimeTicks::Now();
711 std::string language = DetermineTextLanguage(contents);
712 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
713 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52714
[email protected]a8a81292010-01-21 00:32:45715 // Send the text to the browser for indexing (the browser might decide not
716 // to index, if the URL is HTTPS for instance) and language discovery.
717 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
718 language));
[email protected]5c4266922009-07-10 16:41:27719 }
720
initial.commit09911bf2008-07-26 23:55:29721 // thumbnail
722 SendThumbnail();
723}
724
725void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
726 contents->clear();
727 if (!frame)
728 return;
729
730#ifdef TIME_TEXT_RETRIEVAL
731 double begin = time_util::GetHighResolutionTimeNow();
732#endif
733
734 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45735 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29736
737#ifdef TIME_TEXT_RETRIEVAL
738 double end = time_util::GetHighResolutionTimeNow();
739 char buf[128];
740 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
741 contents.size(), (end - begin)*1000);
742 OutputDebugStringA(buf);
743#endif
744
745 // When the contents are clipped to the maximum, we don't want to have a
746 // partial word indexed at the end that might have been clipped. Therefore,
747 // terminate the string at the last space to ensure no words are clipped.
748 if (contents->size() == kMaxIndexChars) {
749 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
750 if (last_space_index == std::wstring::npos)
751 return; // don't index if we got a huge block of text with no spaces
752 contents->resize(last_space_index);
753 }
754}
755
[email protected]8649fb32009-06-26 17:51:02756bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29757 int w,
758 int h,
759 SkBitmap* thumbnail,
760 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23761 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15762
[email protected]8649fb32009-06-26 17:51:02763 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23764
765 // Paint |view| into |canvas|.
766 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02767 return false;
[email protected]8649fb32009-06-26 17:51:02768
769 skia::BitmapPlatformDevice& device =
770 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
771
772 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29773
[email protected]cab34d6a2009-09-24 01:14:52774 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29775 float dest_aspect = dest_rect.width() / dest_rect.height();
776
777 // Get the src rect so that we can preserve the aspect ratio while filling
778 // the destination.
779 SkIRect src_rect;
780 if (src_bmp.width() < dest_rect.width() ||
781 src_bmp.height() < dest_rect.height()) {
782 // Source image is smaller: we clip the part of source image within the
783 // dest rect, and then stretch it to fill the dest rect. We don't respect
784 // the aspect ratio in this case.
785 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
786 static_cast<S16CPU>(dest_rect.height()));
787 score->good_clipping = false;
788 } else {
789 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
790 if (src_aspect > dest_aspect) {
791 // Wider than tall, clip horizontally: we center the smaller thumbnail in
792 // the wider screen.
793 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
794 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
795 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
796 score->good_clipping = false;
797 } else {
798 src_rect.set(0, 0, src_bmp.width(),
799 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
800 score->good_clipping = true;
801 }
802 }
803
[email protected]26aa0482009-09-30 16:55:27804 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29805
806 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02807 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29808
809 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14810 *thumbnail = skia::ImageOperations::Resize(
811 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29812
813 score->boring_score = CalculateBoringScore(thumbnail);
814
[email protected]30507922010-01-15 16:48:23815 HISTOGRAM_TIMES("Renderer4.Thumbnail",
816 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15817 return true;
initial.commit09911bf2008-07-26 23:55:29818}
819
[email protected]30507922010-01-15 16:48:23820bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
821 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29822
[email protected]30507922010-01-15 16:48:23823 skia::PlatformCanvas canvas;
824 if (!PaintViewIntoCanvas(view, canvas))
825 return false;
826
827 skia::BitmapPlatformDevice& device =
828 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
829
830 const SkBitmap& bitmap = device.accessBitmap(false);
831 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
832 return false;
833
834 HISTOGRAM_TIMES("Renderer4.Snapshot",
835 base::TimeTicks::Now() - beginning_time);
836 return true;
initial.commit09911bf2008-07-26 23:55:29837}
838
839void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
840 if (!webview())
841 return;
842
[email protected]8c785c62009-07-13 14:20:15843 if (devtools_agent_.get())
844 devtools_agent_->OnNavigate();
845
[email protected]422197532010-01-25 17:38:23846 if (notification_provider_.get())
847 notification_provider_->OnNavigate();
848
[email protected]a9f607e2009-10-23 19:59:27849 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26850
initial.commit09911bf2008-07-26 23:55:29851 AboutHandler::MaybeHandle(params.url);
852
[email protected]ecbf10d2010-02-18 13:03:29853 bool is_reload =
854 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
855 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29856
[email protected]26aa0482009-09-30 16:55:27857 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45858 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29859 // We cannot reload if we do not have any history state. This happens, for
860 // example, when recovering from a crash. Our workaround here is a bit of
861 // a hack since it means that reload after a crashed tab does not cause an
862 // end-to-end cache validation.
863 is_reload = false;
864 }
865
[email protected]77f17a82009-05-21 04:42:54866 // A navigation resulting from loading a javascript URL should not be treated
867 // as a browser initiated event. Instead, we want it to look as if the page
868 // initiated any load resulting from JS execution.
869 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30870 NavigationState* state = NavigationState::CreateBrowserInitiated(
871 params.page_id, params.transition, params.request_time);
872 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
873 // We're doing a load of a page that was restored from the last session.
874 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
875 // which can result in stale data for pages that are set to expire. We
876 // explicitly override that by setting the policy here so that as
877 // necessary we load from the network.
878 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
879 }
880 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54881 }
initial.commit09911bf2008-07-26 23:55:29882
[email protected]a7ccc4d2010-01-27 08:14:48883 NavigationState* navigation_state = pending_navigation_state_.get();
884
[email protected]04d3c6e2009-05-22 17:00:13885 // If we are reloading, then WebKit will use the history state of the current
886 // page, so we should just ignore any given history state. Otherwise, if we
887 // have history state, then we need to navigate to it, which corresponds to a
888 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55889 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48890 if (navigation_state)
891 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29892 bool ignore_cache = (params.navigation_type ==
893 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
894 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55895 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13896 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58897 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48898 if (navigation_state)
899 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45900 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17901 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13902 } else {
903 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28904 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29905
[email protected]e6f546c32009-07-01 17:12:55906 // A session history navigation should have been accompanied by state.
907 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13908
[email protected]dd7daa82009-08-10 05:46:45909 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55910 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13911
[email protected]726985e22009-06-18 21:09:28912 if (params.referrer.is_valid()) {
913 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
914 WebString::fromUTF8(params.referrer.spec()));
915 }
[email protected]04d3c6e2009-05-22 17:00:13916
[email protected]a7ccc4d2010-01-27 08:14:48917 if (navigation_state)
918 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45919 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50920 }
921
[email protected]77f17a82009-05-21 04:42:54922 // In case LoadRequest failed before DidCreateDataSource was called.
923 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29924}
925
926// Stop loading the current page
927void RenderView::OnStop() {
928 if (webview())
[email protected]b4bb2502009-10-01 22:35:27929 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29930}
931
[email protected]ecbf10d2010-02-18 13:03:29932// Reload current focused frame.
933// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56934void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29935 if (webview() && webview()->focusedFrame()) {
936 // We always obey the cache (ignore_cache=false) here.
937 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
938 // a cache-ignoring reload of the frame.
939 webview()->focusedFrame()->reload(false);
940 }
[email protected]1dda4022010-01-28 18:24:56941}
942
[email protected]e6f546c32009-07-01 17:12:55943void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29944 bool new_navigation,
945 const GURL& display_url,
946 const std::string& security_info) {
947 if (!webview())
948 return;
949
[email protected]e6f546c32009-07-01 17:12:55950 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
951 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
952 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29953
[email protected]26aa0482009-09-30 16:55:27954 webview()->mainFrame()->loadHTMLString(
955 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55956
957 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29958}
959
960void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27961 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29962}
963
[email protected]68b1e922009-06-23 16:00:25964void RenderView::OnExecuteEditCommand(const std::string& name,
965 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27966 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25967 return;
968
[email protected]26aa0482009-09-30 16:55:27969 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45970 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25971}
972
[email protected]b2abac72009-02-26 12:39:28973void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11974 DCHECK(!devtools_client_.get());
975 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28976}
977
initial.commit09911bf2008-07-26 23:55:29978void RenderView::OnStopFinding(bool clear_selection) {
979 WebView* view = webview();
980 if (!view)
981 return;
982
983 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27984 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29985
[email protected]26aa0482009-09-30 16:55:27986 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29987 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45988 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:27989 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:29990 }
991}
992
993void RenderView::OnFindReplyAck() {
994 // Check if there is any queued up request waiting to be sent.
995 if (queued_find_reply_message_.get()) {
996 // Send the search result over to the browser process.
997 Send(queued_find_reply_message_.get());
998 queued_find_reply_message_.release();
999 }
1000}
1001
1002void RenderView::OnUpdateTargetURLAck() {
1003 // Check if there is a targeturl waiting to be sent.
1004 if (target_url_status_ == TARGET_PENDING) {
1005 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1006 pending_target_url_));
1007 }
1008
1009 target_url_status_ = TARGET_NONE;
1010}
1011
1012void RenderView::OnUndo() {
1013 if (!webview())
1014 return;
1015
[email protected]26aa0482009-09-30 16:55:271016 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121017 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291018}
1019
1020void RenderView::OnRedo() {
1021 if (!webview())
1022 return;
1023
[email protected]26aa0482009-09-30 16:55:271024 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121025 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291026}
1027
1028void RenderView::OnCut() {
1029 if (!webview())
1030 return;
1031
[email protected]26aa0482009-09-30 16:55:271032 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121033 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291034}
1035
1036void RenderView::OnCopy() {
1037 if (!webview())
1038 return;
1039
[email protected]26aa0482009-09-30 16:55:271040 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121041 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291042}
1043
[email protected]c0cc3092009-09-12 08:27:271044#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351045void RenderView::OnCopyToFindPboard() {
1046 if (!webview())
1047 return;
1048
1049 // Since the find pasteboard supports only plain text, this can be simpler
1050 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271051 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351052 if (frame->hasSelection()) {
1053 string16 selection = frame->selectionAsText();
1054 RenderThread::current()->Send(
1055 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1056 }
1057
[email protected]afe3a1672009-11-17 19:04:121058 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351059}
[email protected]c0cc3092009-09-12 08:27:271060#endif
[email protected]a954bf72009-09-12 07:30:351061
initial.commit09911bf2008-07-26 23:55:291062void RenderView::OnPaste() {
1063 if (!webview())
1064 return;
1065
[email protected]26aa0482009-09-30 16:55:271066 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121067 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291068}
1069
[email protected]2a3a7762009-10-19 19:17:321070void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291071 if (!webview())
1072 return;
1073
[email protected]1ff7a032010-02-03 02:46:031074 WebFrame* frame = webview()->focusedFrame();
1075 if (!frame->hasSelection())
1076 frame->selectWordAroundCaret();
1077 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291078}
1079
[email protected]98324892009-09-09 21:16:051080void RenderView::OnAdvanceToNextMisspelling() {
1081 if (!webview())
1082 return;
[email protected]26aa0482009-09-30 16:55:271083 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051084 WebString::fromUTF8("AdvanceToNextMisspelling"));
1085}
1086
1087void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1088 if (!webview())
1089 return;
1090 // We need to tell the webView whether the spelling panel is visible or not so
1091 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261092 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271093 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051094 WebString::fromUTF8("ToggleSpellPanel"));
1095}
1096
[email protected]bbbd545c2008-12-15 20:18:041097void RenderView::OnToggleSpellCheck() {
1098 if (!webview())
1099 return;
1100
[email protected]26aa0482009-09-30 16:55:271101 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451102 frame->enableContinuousSpellChecking(
1103 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041104}
1105
initial.commit09911bf2008-07-26 23:55:291106void RenderView::OnDelete() {
1107 if (!webview())
1108 return;
1109
[email protected]26aa0482009-09-30 16:55:271110 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121111 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291112}
1113
1114void RenderView::OnSelectAll() {
1115 if (!webview())
1116 return;
1117
[email protected]26aa0482009-09-30 16:55:271118 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221119 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121120 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291121}
1122
1123void RenderView::OnSetInitialFocus(bool reverse) {
1124 if (!webview())
1125 return;
[email protected]26aa0482009-09-30 16:55:271126 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291127}
1128
1129///////////////////////////////////////////////////////////////////////////////
1130
[email protected]433819d2010-01-30 20:20:011131void RenderView::SetContentSettings(const ContentSettings& settings) {
1132 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011133}
1134
initial.commit09911bf2008-07-26 23:55:291135// Tell the embedding application that the URL of the active page has changed
1136void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451137 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291138 DCHECK(ds);
1139
[email protected]726985e22009-06-18 21:09:281140 const WebURLRequest& request = ds->request();
1141 const WebURLRequest& original_request = ds->originalRequest();
1142 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291143
[email protected]daa8c58e2009-06-15 17:21:101144 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1145 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291146
1147 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281148 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291149 params.is_post = false;
1150 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281151 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551152 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291153 // SSL state specified in the request takes precedence over the one in the
1154 // response.
1155 // So far this is only intended for error pages that are not expected to be
1156 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281157 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551158 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291159 } else {
[email protected]726985e22009-06-18 21:09:281160 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291161 }
1162
1163 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281164 if (ds->hasUnreachableURL()) {
1165 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291166 } else {
[email protected]726985e22009-06-18 21:09:281167 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291168 }
1169
[email protected]726985e22009-06-18 21:09:281170 GetRedirectChain(ds, &params.redirects);
1171 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:291172
[email protected]ce0e250d2009-10-23 21:00:351173 params.searchable_form_url = navigation_state->searchable_form_url();
1174 params.searchable_form_encoding =
1175 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291176
1177 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101178 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291179 if (password_form_data)
1180 params.password_form = *password_form_data;
1181
1182 params.gesture = navigation_gesture_;
1183 navigation_gesture_ = NavigationGestureUnknown;
1184
[email protected]dd7daa82009-08-10 05:46:451185 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291186 // Top-level navigation.
1187
[email protected]71b0d5d2010-02-15 05:43:071188 // Clear "block" flags for the new page. This needs to happen before any of
1189 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1190 // so that these functions can correctly detect that a piece of content
1191 // flipped from "not blocked" to "blocked".
1192 ClearBlockedContentSettings();
1193
[email protected]f85f0702010-01-30 09:31:011194 // Set content settings.
1195 HostContentSettings::iterator host_content_settings =
1196 host_content_settings_.find(GURL(request.url()).host());
1197 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011198 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011199
1200 // These content settings were merely recorded transiently for this load.
1201 // We can erase them now. If at some point we reload this page, the
1202 // browser will send us new, up-to-date content settings.
1203 host_content_settings_.erase(host_content_settings);
1204 }
1205
[email protected]40bd6582009-12-04 23:49:511206 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011207 HostZoomLevels::iterator host_zoom =
[email protected]40bd6582009-12-04 23:49:511208 host_zoom_levels_.find(GURL(request.url()).host());
[email protected]f85f0702010-01-30 09:31:011209 if (host_zoom != host_zoom_levels_.end()) {
1210 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511211 // This zoom level was merely recorded transiently for this load. We can
1212 // erase it now. If at some point we reload this page, the browser will
1213 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011214 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511215 }
1216
initial.commit09911bf2008-07-26 23:55:291217 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551218 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291219
[email protected]daa8c58e2009-06-15 17:21:101220 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291221 if (!PageTransition::IsMainFrame(params.transition)) {
1222 // If the main frame does a load, it should not be reported as a subframe
1223 // navigation. This can occur in the following case:
1224 // 1. You're on a site with frames.
1225 // 2. You do a subframe navigation. This is stored with transition type
1226 // MANUAL_SUBFRAME.
1227 // 3. You navigate to some non-frame site, say, google.com.
1228 // 4. You navigate back to the page from step 2. Since it was initially
1229 // MANUAL_SUBFRAME, it will be that same transition type here.
1230 // We don't want that, because any navigation that changes the toplevel
1231 // frame should be tracked as a toplevel navigation (this allows us to
1232 // update the URL bar, etc).
1233 params.transition = PageTransition::LINK;
1234 }
1235
initial.commit09911bf2008-07-26 23:55:291236 // If we have a valid consumed client redirect source,
1237 // the page contained a client redirect (meta refresh, document.loc...),
1238 // so we set the referrer and transition to match.
1239 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041240 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291241 params.referrer = completed_client_redirect_src_;
1242 params.transition = static_cast<PageTransition::Type>(
1243 params.transition | PageTransition::CLIENT_REDIRECT);
1244 } else {
1245 // Bug 654101: the referrer will be empty on https->http transitions. It
1246 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281247 params.referrer = GURL(
1248 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291249 }
1250
[email protected]726985e22009-06-18 21:09:281251 string16 method = request.httpMethod();
1252 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291253 params.is_post = true;
1254
[email protected]c2a797d2009-09-21 16:46:321255 // Save some histogram data so we can compute the average memory used per
1256 // page load of the glyphs.
1257 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1258 webkit_glue::GetGlyphPageCount());
1259
[email protected]15cf526b2010-02-12 06:33:491260 // This message needs to be sent before any of allowScripts(),
1261 // allowImages(), allowPlugins() is called for the new page, so that when
1262 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1263 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291264 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1265 } else {
1266 // Subframe navigation: the type depends on whether this navigation
1267 // generated a new session history entry. When they do generate a session
1268 // history entry, it means the user initiated the navigation and we should
1269 // mark it as such. This test checks if this is the first time UpdateURL
1270 // has been called since WillNavigateToURL was called to initiate the load.
1271 if (page_id_ > last_page_id_sent_to_browser_)
1272 params.transition = PageTransition::MANUAL_SUBFRAME;
1273 else
1274 params.transition = PageTransition::AUTO_SUBFRAME;
1275
initial.commit09911bf2008-07-26 23:55:291276 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1277 }
1278
1279 last_page_id_sent_to_browser_ =
1280 std::max(last_page_id_sent_to_browser_, page_id_);
1281
1282 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101283 // we don't want the transition type to persist. Just clear it.
1284 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501285
[email protected]6c8afae52009-01-22 02:24:571286#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151287 if (accessibility_.get()) {
[email protected]17455962010-02-24 01:39:351288 // Remove accessibility info cache.
1289 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501290 }
[email protected]6c8afae52009-01-22 02:24:571291#else
[email protected]7d926f92009-03-03 14:26:541292 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571293#endif
initial.commit09911bf2008-07-26 23:55:291294}
1295
1296// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171297void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291298 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171299 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171300 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171301 routing_id_,
1302 page_id_,
1303 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1304 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171305 }
initial.commit09911bf2008-07-26 23:55:291306}
1307
1308void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401309 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291310 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271311 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291312 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301313 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291314 last_encoding_name_ = encoding_name;
1315
[email protected]e38f40152008-09-12 23:08:301316 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291317 }
1318}
1319
[email protected]f4d34b52008-11-24 23:05:011320// Sends the previous session history state to the browser so it will be saved
1321// before we navigate to a new page. This must be called *before* the page ID
1322// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291323void RenderView::UpdateSessionHistory(WebFrame* frame) {
1324 // If we have a valid page ID at this point, then it corresponds to the page
1325 // we are navigating away from. Otherwise, this is the first navigation, so
1326 // there is no past session history to record.
1327 if (page_id_ == -1)
1328 return;
1329
[email protected]ca948a22009-06-25 19:36:171330 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271331 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171332 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291333 return;
[email protected]ca948a22009-06-25 19:36:171334
1335 Send(new ViewHostMsg_UpdateState(
1336 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291337}
1338
[email protected]3d9689372009-09-10 04:29:171339void RenderView::OpenURL(
1340 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1341 Send(new ViewHostMsg_OpenURL(
1342 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1343}
1344
[email protected]79dbc662009-09-04 05:42:511345// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291346
[email protected]a2f6bc112009-06-27 16:27:251347void RenderView::DidPaint() {
[email protected]26aa0482009-09-30 16:55:271348 WebFrame* main_frame = webview()->mainFrame();
[email protected]a2f6bc112009-06-27 16:27:251349
[email protected]dd7daa82009-08-10 05:46:451350 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251351 // If we have a provisional frame we are between the start
1352 // and commit stages of loading...ignore this paint.
1353 return;
1354 }
1355
[email protected]dd7daa82009-08-10 05:46:451356 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251357 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011358 DCHECK(navigation_state);
1359
1360 Time now = Time::Now();
1361 if (navigation_state->first_paint_time().is_null()) {
1362 navigation_state->set_first_paint_time(now);
1363 }
1364 if (navigation_state->first_paint_after_load_time().is_null() &&
1365 !navigation_state->finish_load_time().is_null()) {
1366 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251367 }
1368}
1369
initial.commit09911bf2008-07-26 23:55:291370void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281371 const WebURLRequest& failed_request,
1372 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291373 const std::string& html,
1374 bool replace) {
[email protected]726985e22009-06-18 21:09:281375 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291376
1377 std::string alt_html;
1378 if (html.empty()) {
1379 // Use a local error page.
1380 int resource_id;
1381 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281382 if (error.reason == net::ERR_CACHE_MISS &&
1383 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291384 GetFormRepostErrorValues(failed_url, &error_strings);
1385 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1386 } else {
1387 GetLocalizedErrorValues(error, &error_strings);
1388 resource_id = IDR_NET_ERROR_HTML;
1389 }
[email protected]8e50b602009-03-03 22:59:431390 error_strings.SetString(L"textdirection",
1391 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1392 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291393
1394 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1395 } else {
1396 alt_html = html;
1397 }
1398
[email protected]dd7daa82009-08-10 05:46:451399 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551400 GURL(kUnreachableWebDataURL),
1401 failed_url,
1402 replace);
initial.commit09911bf2008-07-26 23:55:291403}
1404
[email protected]7ccddb8c2009-08-04 17:36:551405void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291406 dom_automation_controller_.set_message_sender(this);
1407 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551408 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291409 L"domAutomationController");
1410}
1411
initial.commit09911bf2008-07-26 23:55:291412bool RenderView::RunJavaScriptMessage(int type,
1413 const std::wstring& message,
1414 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071415 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291416 std::wstring* result) {
1417 bool success = false;
1418 std::wstring result_temp;
1419 if (!result)
1420 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291421
[email protected]12636df2009-09-28 22:32:211422 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1423 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291424 return success;
1425}
1426
[email protected]c1f50aa2010-02-18 03:46:571427bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1428 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1429 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1430 // it is particularly important that we do not call willEnterModalLoop as
1431 // that would defer resource loads for the dialog itself.
1432 if (RenderThread::current()) // Will be NULL during unit tests.
1433 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1434
1435 message->EnableMessagePumping(); // Runs a nested message loop.
1436 return Send(message);
1437}
1438
initial.commit09911bf2008-07-26 23:55:291439void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1440 if (!osd_url.is_empty())
1441 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1442 autodetected));
1443}
1444
[email protected]95056b582010-02-18 01:29:241445void RenderView::OnAutoFillSuggestionsReturned(
1446 int query_id,
1447 const std::vector<string16>& names,
1448 const std::vector<string16>& labels,
1449 int default_suggestion_index) {
1450 if (webview() && query_id == autofill_query_id_) {
1451 webview()->applyAutoFillSuggestions(
1452 autofill_query_node_, names, labels, default_suggestion_index);
1453 }
1454 autofill_query_node_.reset();
1455}
1456
1457void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a1f2009-10-16 03:53:391458 int query_id,
1459 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031460 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181461 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081462 webview()->applyAutocompleteSuggestions(
[email protected]acca2a1f2009-10-16 03:53:391463 autofill_query_node_, suggestions, default_suggestion_index);
1464 }
1465 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031466}
1467
[email protected]c83641732010-02-20 01:04:481468void RenderView::OnAutoFillFormDataFilled(int query_id, const FormData& form) {
1469 if (query_id != autofill_query_id_)
1470 return;
1471
1472 form_manager_.FillForm(form);
1473}
1474
[email protected]2c4410d2009-05-06 23:46:221475void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311476 popup_notification_visible_ = visible;
1477}
1478
initial.commit09911bf2008-07-26 23:55:291479uint32 RenderView::GetCPBrowsingContext() {
1480 uint32 context = 0;
1481 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1482 return context;
1483}
1484
initial.commit09911bf2008-07-26 23:55:291485void RenderView::AddSearchProvider(const std::string& url) {
1486 AddGURLSearchProvider(GURL(url),
1487 false); // not autodetected
1488}
1489
[email protected]f103ab72009-09-02 17:10:591490void RenderView::OnMissingPluginStatus(
1491 WebPluginDelegateProxy* delegate,
1492 int status) {
[email protected]6c8afae52009-01-22 02:24:571493#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591494 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291495 // Show the InfoBar for the first available plugin.
1496 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591497 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291498 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1499 }
1500 } else {
1501 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1502 // to start the download/install.
1503 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1504 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1505 }
1506 }
[email protected]6c8afae52009-01-22 02:24:571507#else
1508 // TODO(port): plugins current not supported
1509 NOTIMPLEMENTED();
1510#endif
initial.commit09911bf2008-07-26 23:55:291511}
1512
[email protected]48c9cf2d2009-09-16 16:47:521513// WebKit::WebViewClient ------------------------------------------------------
1514
1515WebView* RenderView::createView(WebFrame* creator) {
1516 // Check to make sure we aren't overloading on popups.
1517 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1518 return NULL;
1519
1520 // This window can't be closed from a window.close() call until we receive a
1521 // message from the Browser process explicitly allowing it.
1522 popup_notification_visible_ = true;
1523
1524 int32 routing_id = MSG_ROUTING_NONE;
1525 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461526 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341527 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521528
[email protected]48c9cf2d2009-09-16 16:47:521529 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341530 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1531 session_storage_namespace_id_,
1532 &routing_id,
1533 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211534 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521535 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521536
[email protected]48c9cf2d2009-09-16 16:47:521537 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421538 0,
[email protected]12636df2009-09-28 22:32:211539 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521540 renderer_preferences_,
1541 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211542 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341543 routing_id,
1544 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521545 view->opened_by_user_gesture_ = user_gesture;
1546
[email protected]007a848b2009-10-26 15:55:461547 // Record whether the creator frame is trying to suppress the opener field.
1548 view->opener_suppressed_ = opener_suppressed;
1549
[email protected]48c9cf2d2009-09-16 16:47:521550 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091551 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521552 if (!creator_url.is_valid() || !creator_url.IsStandard())
1553 creator_url = GURL();
1554 view->creator_url_ = creator_url;
1555
1556 // Copy over the alternate error page URL so we can have alt error pages in
1557 // the new render view (we don't need the browser to send the URL back down).
1558 view->alternate_error_page_url_ = alternate_error_page_url_;
1559
1560 return view->webview();
1561}
1562
1563WebWidget* RenderView::createPopupMenu(bool activatable) {
1564 RenderWidget* widget = RenderWidget::Create(routing_id_,
1565 render_thread_,
1566 activatable);
[email protected]c4b220f52010-02-22 23:49:151567 showing_popup_menu_ = true;
1568 widget->SetPopupMenuOwnerWidget(this);
1569
[email protected]48c9cf2d2009-09-16 16:47:521570 return widget->webwidget();
1571}
1572
1573WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1574 RenderWidget* widget = RenderWidget::Create(routing_id_,
1575 render_thread_,
1576 true);
[email protected]c4b220f52010-02-22 23:49:151577 showing_popup_menu_ = true;
1578 widget->SetPopupMenuOwnerWidget(this);
1579
[email protected]48c9cf2d2009-09-16 16:47:521580 widget->ConfigureAsExternalPopupMenu(info);
1581 return widget->webwidget();
1582}
1583
[email protected]bd92c3a2010-01-13 05:02:341584WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1585 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1586 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291587 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1588 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1589 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341590}
1591
[email protected]48c9cf2d2009-09-16 16:47:521592void RenderView::didAddMessageToConsole(
1593 const WebConsoleMessage& message, const WebString& source_name,
1594 unsigned source_line) {
1595 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1596 UTF16ToWideHack(message.text),
1597 static_cast<int32>(source_line),
1598 UTF16ToWideHack(source_name)));
1599}
1600
1601void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581602 DCHECK(frame);
1603 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521604}
1605
1606void RenderView::didStartLoading() {
1607 if (is_loading_) {
1608 DLOG(WARNING) << "didStartLoading called while loading";
1609 return;
1610 }
1611
1612 is_loading_ = true;
1613 // Clear the pointer so that we can assign it only when there is an unknown
1614 // plugin on a page.
1615 first_default_plugin_.reset();
1616
1617 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1618}
1619
1620void RenderView::didStopLoading() {
1621 if (!is_loading_) {
1622 DLOG(WARNING) << "DidStopLoading called while not loading";
1623 return;
1624 }
1625
1626 is_loading_ = false;
1627
1628 // NOTE: For now we're doing the safest thing, and sending out notification
1629 // when done loading. This currently isn't an issue as the favicon is only
1630 // displayed when done loading. Ideally we would send notification when
1631 // finished parsing the head, but webkit doesn't support that yet.
1632 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271633 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521634 if (!favicon_url.is_empty())
1635 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1636
[email protected]26aa0482009-09-30 16:55:271637 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521638 true); // autodetected
1639
1640 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1641
1642 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1643 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1644 false),
1645 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521646}
1647
[email protected]f55039a2010-02-17 14:12:061648bool RenderView::isSmartInsertDeleteEnabled() {
1649#if defined(OS_MACOSX)
1650 return true;
1651#else
1652 return false;
1653#endif
1654}
1655
[email protected]04fc9482009-09-18 22:13:031656bool RenderView::isSelectTrailingWhitespaceEnabled() {
1657#if defined(OS_WIN)
1658 return true;
1659#else
1660 return false;
1661#endif
1662}
1663
1664void RenderView::setInputMethodEnabled(bool enabled) {
1665 // Save the updated IME status and mark the input focus has been updated.
1666 // The IME status is to be sent to a browser process next time when
1667 // the input caret is rendered.
1668 if (!ime_control_busy_) {
1669 ime_control_updated_ = true;
1670 ime_control_new_state_ = enabled;
1671 }
1672}
1673
1674void RenderView::didChangeSelection(bool is_empty_selection) {
1675#if defined(OS_LINUX)
1676 if (!handling_input_event_)
1677 return;
1678 // TODO(estade): investigate incremental updates to the selection so that we
1679 // don't send the entire selection over IPC every time.
1680 if (!is_empty_selection) {
1681 // Sometimes we get repeated didChangeSelection calls from webkit when
1682 // the selection hasn't actually changed. We don't want to report these
1683 // because it will cause us to continually claim the X clipboard.
1684 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271685 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031686 if (this_selection == last_selection_)
1687 return;
1688
1689 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1690 this_selection));
1691 last_selection_ = this_selection;
1692 } else {
1693 last_selection_.clear();
1694 }
1695#endif
1696}
1697
1698void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121699 const std::string& name = UTF16ToUTF8(command_name);
1700 if (StartsWithASCII(name, "Move", true) ||
1701 StartsWithASCII(name, "Insert", true) ||
1702 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031703 return;
1704 UserMetricsRecordAction(name);
1705}
1706
[email protected]b2528b72009-09-24 06:57:101707bool RenderView::handleCurrentKeyboardEvent() {
1708 if (edit_commands_.empty())
1709 return false;
1710
[email protected]26aa0482009-09-30 16:55:271711 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101712 if (!frame)
1713 return false;
1714
1715 EditCommands::iterator it = edit_commands_.begin();
1716 EditCommands::iterator end = edit_commands_.end();
1717
[email protected]507b33ea2009-09-29 03:56:511718 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101719 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331720 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1721 // key (but it's the exception). Once one edit command is not executed, it
1722 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101723 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1724 WebString::fromUTF8(it->value)))
1725 break;
[email protected]507b33ea2009-09-29 03:56:511726 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101727 }
1728
[email protected]507b33ea2009-09-29 03:56:511729 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101730}
1731
[email protected]2a3a7762009-10-19 19:17:321732void RenderView::spellCheck(const WebString& text,
1733 int& misspelled_offset,
1734 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561735 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461736
[email protected]85c55dc2009-11-06 03:05:461737 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171738 RenderThread* thread = RenderThread::current();
1739 // Will be NULL during unit tests.
1740 if (thread) {
[email protected]c27324b2009-11-19 22:44:291741 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171742 word.c_str(), word.size(), document_tag_,
1743 &misspelled_offset, &misspelled_length, NULL);
1744 }
[email protected]1dbafaf72009-09-23 19:43:561745}
1746
1747WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321748 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561749 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261750 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561751 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171752 RenderThread* thread = RenderThread::current();
1753 // Will be NULL during unit tests.
1754 if (thread) {
1755 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291756 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171757 word, document_tag_);
1758 }
[email protected]1dbafaf72009-09-23 19:43:561759 }
[email protected]2a3a7762009-10-19 19:17:321760 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561761}
1762
[email protected]c49085c72009-10-02 16:28:561763void RenderView::showSpellingUI(bool show) {
1764 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1765}
1766
[email protected]8922e1f2009-10-03 05:01:261767bool RenderView::isShowingSpellingUI() {
1768 return spelling_panel_visible_;
1769}
1770
[email protected]1dbafaf72009-09-23 19:43:561771void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321772 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1773 word));
[email protected]1dbafaf72009-09-23 19:43:561774}
1775
[email protected]a1128322009-10-06 18:38:461776bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351777 const WebKit::WebFileChooserParams& params,
[email protected]a1128322009-10-06 18:38:461778 WebKit::WebFileChooserCompletion* chooser_completion) {
1779 if (file_chooser_completion_) {
1780 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1781 // with the fact that web pages can programatically trigger this. With the
1782 // asnychronous messages, we can get an additional call when one is pending,
1783 // which this test is for. For now, we just ignore the additional file
1784 // chooser request. WebKit doesn't do anything to expect the callback, so
1785 // we can just ignore calling it.
1786 return false;
1787 }
1788 file_chooser_completion_ = chooser_completion;
1789 Send(new ViewHostMsg_RunFileChooser(
[email protected]01178b52010-01-15 06:59:351790 routing_id_, params.multiSelect, params.title,
1791 webkit_glue::WebStringToFilePath(params.initialValue)));
[email protected]a1128322009-10-06 18:38:461792 return true;
1793}
1794
[email protected]48c9cf2d2009-09-16 16:47:521795void RenderView::runModalAlertDialog(
1796 WebFrame* frame, const WebString& message) {
1797 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1798 UTF16ToWideHack(message),
1799 std::wstring(),
1800 frame->url(),
1801 NULL);
1802}
1803
1804bool RenderView::runModalConfirmDialog(
1805 WebFrame* frame, const WebString& message) {
1806 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1807 UTF16ToWideHack(message),
1808 std::wstring(),
1809 frame->url(),
1810 NULL);
1811}
1812
1813bool RenderView::runModalPromptDialog(
1814 WebFrame* frame, const WebString& message, const WebString& default_value,
1815 WebString* actual_value) {
1816 std::wstring result;
1817 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1818 UTF16ToWideHack(message),
1819 UTF16ToWideHack(default_value),
1820 frame->url(),
1821 &result);
1822 if (ok)
1823 actual_value->assign(WideToUTF16Hack(result));
1824 return ok;
1825}
1826
1827bool RenderView::runModalBeforeUnloadDialog(
1828 WebFrame* frame, const WebString& message) {
1829 bool success = false;
1830 // This is an ignored return value, but is included so we can accept the same
1831 // response as RunJavaScriptMessage.
1832 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211833 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521834 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211835 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521836 return success;
1837}
1838
[email protected]79e37442009-10-09 18:17:441839void RenderView::showContextMenu(
1840 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291841 ContextMenuParams params = ContextMenuParams(data);
1842 if (!params.misspelled_word.empty() && RenderThread::current()) {
1843 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041844 bool spelled_right = RenderThread::current()->spellchecker()->
1845 SpellCheckWord(
1846 params.misspelled_word.c_str(), params.misspelled_word.size(),
1847 document_tag_,
1848 &misspelled_offset, &misspelled_length,
1849 &params.dictionary_suggestions);
1850 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291851 params.misspelled_word.clear();
1852 }
1853
1854 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441855}
1856
[email protected]48c9cf2d2009-09-16 16:47:521857void RenderView::setStatusText(const WebString& text) {
1858}
1859
[email protected]163f8242009-10-30 20:19:551860void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1861 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521862 if (latest_url == target_url_)
1863 return;
[email protected]163f8242009-10-30 20:19:551864
[email protected]48c9cf2d2009-09-16 16:47:521865 // Tell the browser to display a destination link.
1866 if (target_url_status_ == TARGET_INFLIGHT ||
1867 target_url_status_ == TARGET_PENDING) {
1868 // If we have a request in-flight, save the URL to be sent when we
1869 // receive an ACK to the in-flight request. We can happily overwrite
1870 // any existing pending sends.
1871 pending_target_url_ = latest_url;
1872 target_url_status_ = TARGET_PENDING;
1873 } else {
1874 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1875 target_url_ = latest_url;
1876 target_url_status_ = TARGET_INFLIGHT;
1877 }
1878}
1879
[email protected]882daa92009-11-05 16:31:311880void RenderView::StartNavStateSyncTimerIfNecessary() {
1881 int delay;
1882 if (send_content_state_immediately_)
1883 delay = 0;
1884 else if (is_hidden())
1885 delay = kDelaySecondsForContentStateSyncHidden;
1886 else
1887 delay = kDelaySecondsForContentStateSync;
1888
1889 if (nav_state_sync_timer_.IsRunning()) {
1890 // The timer is already running. If the delay of the timer maches the amount
1891 // we want to delay by, then return. Otherwise stop the timer so that it
1892 // gets started with the right delay.
1893 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1894 return;
1895 nav_state_sync_timer_.Stop();
1896 }
1897
1898 nav_state_sync_timer_.Start(
1899 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1900}
1901
[email protected]163f8242009-10-30 20:19:551902void RenderView::setMouseOverURL(const WebURL& url) {
1903 mouse_over_url_ = GURL(url);
1904 UpdateTargetURL(mouse_over_url_, focus_url_);
1905}
1906
1907void RenderView::setKeyboardFocusURL(const WebURL& url) {
1908 focus_url_ = GURL(url);
1909 UpdateTargetURL(focus_url_, mouse_over_url_);
1910}
1911
[email protected]48c9cf2d2009-09-16 16:47:521912void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1913 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1914 hint));
1915}
1916
1917void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1918 WebDragOperationsMask allowed_ops) {
1919 Send(new ViewHostMsg_StartDragging(routing_id_,
1920 WebDropData(data),
1921 allowed_ops));
1922}
1923
[email protected]28b92df2009-09-25 17:35:451924bool RenderView::acceptsLoadDrops() {
1925 return renderer_preferences_.can_accept_load_drops;
1926}
1927
[email protected]48c9cf2d2009-09-16 16:47:521928void RenderView::focusNext() {
1929 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1930}
1931
1932void RenderView::focusPrevious() {
1933 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1934}
1935
1936void RenderView::navigateBackForwardSoon(int offset) {
1937 history_back_list_count_ += offset;
1938 history_forward_list_count_ -= offset;
1939
1940 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1941}
1942
1943int RenderView::historyBackListCount() {
1944 return history_back_list_count_;
1945}
1946
1947int RenderView::historyForwardListCount() {
1948 return history_forward_list_count_;
1949}
1950
1951void RenderView::didAddHistoryItem() {
1952 // We don't want to update the history length for the start page
1953 // navigation.
[email protected]26aa0482009-09-30 16:55:271954 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521955 DCHECK(main_frame != NULL);
1956
1957 WebDataSource* ds = main_frame->dataSource();
1958 DCHECK(ds != NULL);
1959
1960 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1961 DCHECK(navigation_state);
1962 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1963 return;
1964
1965 history_back_list_count_++;
1966 history_forward_list_count_ = 0;
1967}
1968
[email protected]8922e1f2009-10-03 05:01:261969void RenderView::didUpdateInspectorSettings() {
1970 Send(new ViewHostMsg_UpdateInspectorSettings(
1971 routing_id_, webview()->inspectorSettings().utf8()));
1972}
1973
[email protected]acca2a1f2009-10-16 03:53:391974void RenderView::queryAutofillSuggestions(const WebNode& node,
1975 const WebString& name,
1976 const WebString& value) {
1977 static int query_counter = 0;
1978 autofill_query_id_ = query_counter++;
1979 autofill_query_node_ = node;
[email protected]95056b582010-02-18 01:29:241980 const WebKit::WebInputElement input_element =
1981 node.toConstElement<WebInputElement>();
[email protected]acca2a1f2009-10-16 03:53:391982 Send(new ViewHostMsg_QueryFormFieldAutofill(
[email protected]95056b582010-02-18 01:29:241983 routing_id_, autofill_query_id_, FormField(input_element)));
[email protected]acca2a1f2009-10-16 03:53:391984}
1985
1986void RenderView::removeAutofillSuggestions(const WebString& name,
1987 const WebString& value) {
1988 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1989}
1990
[email protected]c83641732010-02-20 01:04:481991void RenderView::didAcceptAutoFillSuggestion(
1992 const WebKit::WebNode& node,
1993 const WebKit::WebString& name,
1994 const WebKit::WebString& label) {
1995 static int query_counter = 0;
1996 autofill_query_id_ = query_counter++;
1997
1998 FormData form;
1999 const WebInputElement element = node.toConstElement<WebInputElement>();
2000 if (!form_manager_.FindForm(element, &form))
2001 return;
2002
2003 Send(new ViewHostMsg_FillAutoFillFormData(
2004 routing_id_, autofill_query_id_, form, name, label));
2005}
2006
[email protected]79dbc662009-09-04 05:42:512007// WebKit::WebWidgetClient ----------------------------------------------------
2008
initial.commit09911bf2008-07-26 23:55:292009// We are supposed to get a single call to Show for a newly created RenderView
2010// that was created via RenderView::CreateWebView. So, we wait until this
2011// point to dispatch the ShowView message.
2012//
2013// This method provides us with the information about how to display the newly
2014// created RenderView (i.e., as a constrained popup or as a new tab).
2015//
[email protected]4873c7d2009-07-16 06:36:282016void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292017 DCHECK(!did_show_) << "received extraneous Show call";
2018 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2019
2020 if (did_show_)
2021 return;
2022 did_show_ = true;
2023
[email protected]28295ec2009-10-16 05:34:332024 // Force new windows to a popup if they were not opened with a user gesture.
2025 if (!opened_by_user_gesture_) {
2026 // We exempt background tabs for compat with older versions of Chrome.
2027 // TODO(darin): This seems bogus. These should have a user gesture, so
2028 // we probably don't need this check.
2029 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2030 policy = WebKit::WebNavigationPolicyNewPopup;
2031 }
2032
initial.commit09911bf2008-07-26 23:55:292033 // NOTE: initial_pos_ may still have its default values at this point, but
2034 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2035 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282036 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2037 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292038 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242039 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292040}
2041
[email protected]4873c7d2009-07-16 06:36:282042void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222043 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282044 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312045}
2046
[email protected]4873c7d2009-07-16 06:36:282047void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292048 DCHECK(did_show_) << "should already have shown the view";
2049
[email protected]c1f50aa2010-02-18 03:46:572050 // We must keep WebKit's shared timer running in this case in order to allow
2051 // showModalDialog to function properly.
2052 //
2053 // TODO(darin): WebKit should really be smarter about suppressing events and
2054 // timers so that we do not need to manage the shared timer in such a heavy
2055 // handed manner.
2056 //
2057 if (RenderThread::current()) // Will be NULL during unit tests.
2058 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2059
[email protected]12636df2009-09-28 22:32:212060 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292061}
2062
[email protected]3d9689372009-09-10 04:29:172063// WebKit::WebFrameClient -----------------------------------------------------
2064
2065WebPlugin* RenderView::createPlugin(
2066 WebFrame* frame, const WebPluginParams& params) {
2067 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2068}
2069
2070WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2071 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
2072}
2073
[email protected]9c00f002009-11-05 22:37:422074WebSharedWorker* RenderView::createSharedWorker(
2075 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372076 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422077
[email protected]30447b62009-11-13 01:13:372078 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512079 bool exists = false;
[email protected]30447b62009-11-13 01:13:372080 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512081 ViewHostMsg_CreateWorker_Params params;
2082 params.url = url;
2083 params.is_shared = true;
2084 params.name = name;
2085 params.document_id = document_id;
2086 params.render_view_route_id = routing_id_;
2087 params.route_id = MSG_ROUTING_NONE;
[email protected]30447b62009-11-13 01:13:372088 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512089 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372090 if (url_mismatch) {
2091 return NULL;
2092 } else {
2093 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492094 document_id,
[email protected]6de0bcf2010-02-17 22:00:512095 exists,
[email protected]30447b62009-11-13 01:13:372096 route_id,
2097 routing_id_);
2098 }
[email protected]9c00f002009-11-05 22:37:422099}
2100
[email protected]3d9689372009-09-10 04:29:172101WebMediaPlayer* RenderView::createMediaPlayer(
2102 WebFrame* frame, WebMediaPlayerClient* client) {
2103 scoped_refptr<media::FilterFactoryCollection> factory =
2104 new media::FilterFactoryCollection();
2105 // Add in any custom filter factories first.
2106 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2107 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2108 // Add the chrome specific audio renderer.
2109 factory->AddFactory(
2110 AudioRendererImpl::CreateFactory(audio_message_filter()));
2111 }
2112
[email protected]80f584d92010-01-21 03:59:042113 WebApplicationCacheHostImpl* appcache_host =
2114 WebApplicationCacheHostImpl::FromFrame(frame);
2115
[email protected]3d9689372009-09-10 04:29:172116 // TODO(hclam): obtain the following parameters from |client|.
2117 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2118 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152119 GURL(), // referrer
2120 "null", // frame origin
2121 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172122 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042123 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172124 routing_id());
2125
[email protected]0436b9a2009-10-23 00:23:052126 // A simple data source that keeps all data in memory.
2127 media::FilterFactory* simple_data_source_factory =
2128 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2129 bridge_factory);
2130 // A sophisticated data source that does memory caching.
2131 media::FilterFactory* buffered_data_source_factory =
2132 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2133 bridge_factory);
2134 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2135 factory->AddFactory(simple_data_source_factory);
2136 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172137 } else {
[email protected]0436b9a2009-10-23 00:23:052138 factory->AddFactory(buffered_data_source_factory);
2139 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172140 }
2141 return new webkit_glue::WebMediaPlayerImpl(client, factory);
2142}
2143
2144void RenderView::willClose(WebFrame* frame) {
2145 if (!frame->parent()) {
2146 const GURL& url = frame->url();
2147 if (url.SchemeIs("http") || url.SchemeIs("https"))
2148 DumpLoadHistograms();
2149 }
[email protected]fa7b6b542009-11-03 05:02:302150
2151 WebDataSource* ds = frame->dataSource();
2152 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2153 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172154}
2155
[email protected]684e4a42010-01-30 06:44:112156bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]2d30a7a2010-02-04 01:57:502157 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS, enabled_per_settings);
[email protected]684e4a42010-01-30 06:44:112158}
2159
2160bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]2d30a7a2010-02-04 01:57:502161 return AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES, enabled_per_settings);
[email protected]684e4a42010-01-30 06:44:112162}
2163
[email protected]3d9689372009-09-10 04:29:172164void RenderView::loadURLExternally(
2165 WebFrame* frame, const WebURLRequest& request,
2166 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592167 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2168 if (policy == WebKit::WebNavigationPolicyDownload) {
2169 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2170 } else {
2171 OpenURL(request.url(), referrer, policy);
2172 }
[email protected]3d9689372009-09-10 04:29:172173}
2174
2175WebNavigationPolicy RenderView::decidePolicyForNavigation(
2176 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222177 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172178 // Webkit is asking whether to navigate to a new URL.
2179 // This is fine normally, except if we're showing UI from one security
2180 // context and they're trying to navigate to a different context.
2181 const GURL& url = request.url();
2182
2183 // If the browser is interested, then give it a chance to look at top level
2184 // navigations
2185 if (renderer_preferences_.browser_handles_top_level_requests &&
2186 // Only send once.
2187 last_top_level_navigation_page_id_ != page_id_ &&
2188 // Not interested in reloads.
2189 type != WebKit::WebNavigationTypeReload &&
2190 type != WebKit::WebNavigationTypeFormSubmitted &&
2191 // Must be a top level frame.
2192 frame->parent() == NULL) {
2193 // Skip if navigation is on the same page (using '#').
2194 GURL frame_origin = GURL(frame->url()).GetOrigin();
2195 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
2196 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:572197 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2198 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:172199 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2200 }
2201 }
2202
2203 // A content initiated navigation may have originated from a link-click,
2204 // script, drag-n-drop operation, etc.
2205 bool is_content_initiated =
2206 NavigationState::FromDataSource(frame->provisionalDataSource())->
2207 is_content_initiated();
2208
2209 // We only care about navigations that are within the current tab (as opposed
2210 // to, for example, opening a new window).
2211 // But we sometimes navigate to about:blank to clear a tab, and we want to
2212 // still allow that.
2213 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2214 is_content_initiated && frame->parent() == NULL &&
2215 !url.SchemeIs(chrome::kAboutScheme)) {
2216 // When we received such unsolicited navigations, we sometimes want to
2217 // punt them up to the browser to handle.
2218 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2219 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2220 frame->isViewSourceModeEnabled() ||
2221 url.SchemeIs(chrome::kViewSourceScheme) ||
2222 url.SchemeIs(chrome::kPrintScheme)) {
2223 OpenURL(url, GURL(), default_policy);
2224 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2225 }
2226 }
2227
2228 // Detect when a page is "forking" a new tab that can be safely rendered in
2229 // its own process. This is done by sites like Gmail that try to open links
2230 // in new windows without script connections back to the original page. We
2231 // treat such cases as browser navigations (in which we will create a new
2232 // renderer for a cross-site navigation), rather than WebKit navigations.
2233 //
2234 // We use the following heuristic to decide whether to fork a new page in its
2235 // own process:
2236 // The parent page must open a new tab to about:blank, set the new tab's
2237 // window.opener to null, and then redirect the tab to a cross-site URL using
2238 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462239 //
2240 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2241 // (see below).
[email protected]3d9689372009-09-10 04:29:172242 bool is_fork =
2243 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252244 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172245 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522246 historyBackListCount() < 1 &&
2247 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172248 // The parent page must have set the child's window.opener to null before
2249 // redirecting to the desired URL.
2250 frame->opener() == NULL &&
2251 // Must be a top-level frame.
2252 frame->parent() == NULL &&
2253 // Must not have issued the request from this page.
2254 is_content_initiated &&
2255 // Must be targeted at the current tab.
2256 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2257 // Must be a JavaScript navigation, which appears as "other".
2258 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462259
2260 // Recognize if this navigation is from a link with rel=noreferrer and
2261 // target=_blank attributes, in which case the opener will be suppressed. If
2262 // so, it is safe to load cross-site pages in a separate process, so we
2263 // should let the browser handle it.
2264 bool is_noreferrer_and_blank_target =
2265 // Frame should be top level and not yet navigated.
2266 frame->parent() == NULL &&
2267 frame->url().isEmpty() &&
2268 historyBackListCount() < 1 &&
2269 historyForwardListCount() < 1 &&
2270 // Links with rel=noreferrer will have no Referer field, and their
2271 // resulting frame will have its window.opener suppressed.
2272 // TODO(creis): should add a request.httpReferrer() method to help avoid
2273 // typos on the unusual spelling of Referer.
2274 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2275 opener_suppressed_ &&
2276 frame->opener() == NULL &&
2277 // Links with target=_blank will have no name.
2278 frame->name().isNull() &&
2279 // Another frame (with a non-empty creator) should have initiated the
2280 // request, targeted at this frame.
2281 !creator_url_.is_empty() &&
2282 is_content_initiated &&
2283 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2284 type == WebKit::WebNavigationTypeOther;
2285
2286 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172287 // Open the URL via the browser, not via WebKit.
2288 OpenURL(url, GURL(), default_policy);
2289 return WebKit::WebNavigationPolicyIgnore;
2290 }
2291
2292 return default_policy;
2293}
2294
[email protected]6069da8c2009-10-20 20:33:492295bool RenderView::canHandleRequest(
2296 WebFrame* frame, const WebURLRequest& request) {
2297 // We allow WebKit to think that everything can be handled even though
2298 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342299 return true;
2300}
2301
[email protected]6069da8c2009-10-20 20:33:492302WebURLError RenderView::cannotHandleRequestError(
2303 WebFrame* frame, const WebURLRequest& request) {
2304 NOTREACHED(); // Since we said we can handle all requests.
2305 return WebURLError();
2306}
2307
2308WebURLError RenderView::cancelledError(
2309 WebFrame* frame, const WebURLRequest& request) {
2310 WebURLError error;
2311 error.domain = WebString::fromUTF8(net::kErrorDomain);
2312 error.reason = net::ERR_ABORTED;
2313 error.unreachableURL = request.url();
2314 return error;
[email protected]7b7a7dc2009-10-19 02:23:342315}
2316
2317void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492318 WebFrame*, const WebURLError&) {
2319 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342320}
2321
[email protected]979c28b2009-11-07 01:30:482322void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172323 NavigationState* navigation_state =
2324 NavigationState::FromDataSource(frame->provisionalDataSource());
2325
2326 if (navigation_state->transition_type() == PageTransition::LINK)
2327 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2328
2329 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352330 WebSearchableFormData web_searchable_form_data(form);
2331 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2332 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212333 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172334 navigation_state->set_password_form_data(
2335 PasswordFormDomManager::CreatePasswordForm(form));
2336
[email protected]979c28b2009-11-07 01:30:482337 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382338 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2339 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472340 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382341 *form_values));
[email protected]3d9689372009-09-10 04:29:172342 }
2343}
2344
2345void RenderView::willPerformClientRedirect(
2346 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2347 double fire_time) {
2348 // Ignore
2349}
2350
2351void RenderView::didCancelClientRedirect(WebFrame* frame) {
2352 // Ignore
2353}
2354
2355void RenderView::didCompleteClientRedirect(
2356 WebFrame* frame, const WebURL& from) {
2357 if (!frame->parent())
2358 completed_client_redirect_src_ = from;
2359}
2360
2361void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2362 // The rest of RenderView assumes that a WebDataSource will always have a
2363 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482364 bool content_initiated = !pending_navigation_state_.get();
2365 NavigationState* state = content_initiated ?
2366 NavigationState::CreateContentInitiated() :
2367 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182368 if (content_initiated) {
2369 switch (ds->request().cachePolicy()) {
2370 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2371 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2372 break;
2373 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2374 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2375 break;
2376 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2377 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2378 break;
2379 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2380 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2381 break;
2382 }
2383 }
[email protected]fa7b6b542009-11-03 05:02:302384
2385 state->set_user_script_idle_scheduler(
2386 new UserScriptIdleScheduler(this, frame));
2387 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172388}
2389
2390void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2391 WebDataSource* ds = frame->provisionalDataSource();
2392 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2393
2394 navigation_state->set_start_load_time(Time::Now());
2395
2396 // Update the request time if WebKit has better knowledge of it.
2397 if (navigation_state->request_time().is_null()) {
2398 double event_time = ds->triggeringEventTime();
2399 if (event_time != 0.0)
2400 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2401 }
2402
2403 bool is_top_most = !frame->parent();
2404 if (is_top_most) {
2405 navigation_gesture_ = frame->isProcessingUserGesture() ?
2406 NavigationGestureUnknown : NavigationGestureAuto;
2407
2408 // Make sure redirect tracking state is clear for the new load.
2409 completed_client_redirect_src_ = GURL();
2410 } else if (frame->parent()->isLoading()) {
2411 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002412 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172413 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2414 }
2415
2416 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2417 routing_id_, is_top_most, ds->request().url()));
2418}
2419
2420void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2421 if (frame->parent())
2422 return;
2423 // Received a redirect on the main frame.
2424 WebDataSource* data_source = frame->provisionalDataSource();
2425 if (!data_source) {
2426 // Should only be invoked when we have a data source.
2427 NOTREACHED();
2428 return;
2429 }
2430 std::vector<GURL> redirects;
2431 GetRedirectChain(data_source, &redirects);
2432 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512433 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2434 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172435 }
2436}
2437
[email protected]40bd6582009-12-04 23:49:512438void RenderView::didFailProvisionalLoad(WebFrame* frame,
2439 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172440 // Notify the browser that we failed a provisional load with an error.
2441 //
2442 // Note: It is important this notification occur before DidStopLoading so the
2443 // SSL manager can react to the provisional load failure before being
2444 // notified the load stopped.
2445 //
2446 WebDataSource* ds = frame->provisionalDataSource();
2447 DCHECK(ds);
2448
2449 const WebURLRequest& failed_request = ds->request();
2450
2451 bool show_repost_interstitial =
2452 (error.reason == net::ERR_CACHE_MISS &&
2453 EqualsASCII(failed_request.httpMethod(), "POST"));
2454 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2455 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2456 show_repost_interstitial));
2457
2458 // Don't display an error page if this is simply a cancelled load. Aside
2459 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2460 if (error.reason == net::ERR_ABORTED)
2461 return;
2462
2463 // Make sure we never show errors in view source mode.
2464 frame->enableViewSourceMode(false);
2465
2466 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2467
2468 // If this is a failed back/forward/reload navigation, then we need to do a
2469 // 'replace' load. This is necessary to avoid messing up session history.
2470 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2471 // as session history is concerned.
2472 //
2473 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2474 // the page id.
2475 //
2476 bool replace =
2477 navigation_state->pending_page_id() != -1 ||
2478 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2479
2480 // If we failed on a browser initiated request, then make sure that our error
2481 // page load is regarded as the same browser initiated request.
2482 if (!navigation_state->is_content_initiated()) {
2483 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2484 navigation_state->pending_page_id(),
2485 navigation_state->transition_type(),
2486 navigation_state->request_time()));
2487 }
2488
2489 // Provide the user with a more helpful error page?
2490 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2491 return;
2492
2493 // Fallback to a local error page.
2494 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2495 replace);
2496}
2497
2498void RenderView::didReceiveDocumentData(
2499 WebFrame* frame, const char* data, size_t data_len,
2500 bool& prevent_default) {
2501 NavigationState* navigation_state =
2502 NavigationState::FromDataSource(frame->dataSource());
2503 if (!navigation_state->postpone_loading_data())
2504 return;
2505
2506 // We're going to call commitDocumentData ourselves...
2507 prevent_default = true;
2508
2509 // Continue buffering the response data for the original 404 page. If it
2510 // grows too large, then we'll just let it through.
2511 navigation_state->append_postponed_data(data, data_len);
2512 if (navigation_state->postponed_data().size() >= 512) {
2513 navigation_state->set_postpone_loading_data(false);
2514 frame->commitDocumentData(navigation_state->postponed_data().data(),
2515 navigation_state->postponed_data().size());
2516 navigation_state->clear_postponed_data();
2517 }
2518}
2519
[email protected]40bd6582009-12-04 23:49:512520void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2521 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172522 NavigationState* navigation_state =
2523 NavigationState::FromDataSource(frame->dataSource());
2524
[email protected]9e84a872010-02-09 18:23:422525 if (!frame->parent()) { // Main frame case.
2526 // Let the page translator know that the page has changed so it can clear
2527 // its states.
2528 page_translator_->MainFrameNavigated();
2529 }
2530
[email protected]3d9689372009-09-10 04:29:172531 navigation_state->set_commit_load_time(Time::Now());
2532 if (is_new_navigation) {
2533 // When we perform a new navigation, we need to update the previous session
2534 // history entry with state for the page we are leaving.
2535 UpdateSessionHistory(frame);
2536
2537 // We bump our Page ID to correspond with the new session history entry.
2538 page_id_ = next_page_id_++;
2539
2540 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2541 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2542 page_id_, true),
2543 kDelayForForcedCaptureMs);
2544 } else {
2545 // Inspect the navigation_state on this frame to see if the navigation
2546 // corresponds to a session history navigation... Note: |frame| may or
2547 // may not be the toplevel frame, but for the case of capturing session
2548 // history, the first committed frame suffices. We keep track of whether
2549 // we've seen this commit before so that only capture session history once
2550 // per navigation.
2551 //
2552 // Note that we need to check if the page ID changed. In the case of a
2553 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2554 // previous URL and the current page ID, which would be wrong.
2555 if (navigation_state->pending_page_id() != -1 &&
2556 navigation_state->pending_page_id() != page_id_ &&
2557 !navigation_state->request_committed()) {
2558 // This is a successful session history navigation!
2559 UpdateSessionHistory(frame);
2560 page_id_ = navigation_state->pending_page_id();
2561 }
2562 }
2563
2564 // Remember that we've already processed this request, so we don't update
2565 // the session history again. We do this regardless of whether this is
2566 // a session history navigation, because if we attempted a session history
2567 // navigation without valid HistoryItem state, WebCore will think it is a
2568 // new navigation.
2569 navigation_state->set_request_committed(true);
2570
2571 UpdateURL(frame);
2572
2573 // If this committed load was initiated by a client redirect, we're
2574 // at the last stop now, so clear it.
2575 completed_client_redirect_src_ = GURL();
2576
2577 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272578 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172579}
2580
2581void RenderView::didClearWindowObject(WebFrame* frame) {
2582 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2583 BindDOMAutomationController(frame);
2584 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2585 dom_ui_bindings_.set_message_sender(this);
2586 dom_ui_bindings_.set_routing_id(routing_id_);
2587 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2588 }
2589 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2590 external_host_bindings_.set_message_sender(this);
2591 external_host_bindings_.set_routing_id(routing_id_);
2592 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2593 }
2594}
2595
2596void RenderView::didCreateDocumentElement(WebFrame* frame) {
2597 if (RenderThread::current()) { // Will be NULL during unit tests.
2598 RenderThread::current()->user_script_slave()->InjectScripts(
2599 frame, UserScript::DOCUMENT_START);
2600 }
[email protected]078b34612009-09-19 19:31:512601 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2602 view_type_ == ViewType::EXTENSION_MOLE) {
2603 InjectToolstripCSS();
2604 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2605 }
[email protected]3d9689372009-09-10 04:29:172606
2607 // Notify the browser about non-blank documents loading in the top frame.
2608 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252609 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272610 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172611 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2612 }
2613}
2614
2615void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2616 UpdateTitle(frame, title);
2617
2618 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272619 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172620}
2621
2622void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2623 WebDataSource* ds = frame->dataSource();
2624 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2625 DCHECK(navigation_state);
2626 navigation_state->set_finish_document_load_time(Time::Now());
2627
2628 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2629
[email protected]e9e07992010-02-17 21:04:362630 // The document has now been fully loaded. Scan for forms to be sent up to
2631 // the browser.
2632 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482633 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362634 SendForms(frame);
[email protected]3d9689372009-09-10 04:29:172635 SendPasswordForms(frame);
2636
2637 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272638 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172639
2640 if (RenderThread::current()) { // Will be NULL during unit tests.
2641 RenderThread::current()->user_script_slave()->InjectScripts(
2642 frame, UserScript::DOCUMENT_END);
2643 }
[email protected]fa7b6b542009-11-03 05:02:302644
2645 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
[email protected]9e84a872010-02-09 18:23:422646
2647 if (page_translator_->IsPageTranslated())
2648 page_translator_->TranslateFrame(frame);
[email protected]fa7b6b542009-11-03 05:02:302649}
2650
2651void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2652 if (RenderThread::current()) { // Will be NULL during unit tests.
2653 RenderThread::current()->user_script_slave()->InjectScripts(
2654 frame, UserScript::DOCUMENT_IDLE);
2655 }
2656
2657 WebFrame* main_frame = webview()->mainFrame();
2658 if (frame == main_frame) {
2659 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202660 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302661 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202662 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302663 pending_code_execution_queue_.pop();
2664 }
2665 }
[email protected]3d9689372009-09-10 04:29:172666}
2667
2668void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2669 // Ignore
2670}
2671
2672void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2673 // Ignore
2674}
2675
2676void RenderView::didFinishLoad(WebFrame* frame) {
2677 WebDataSource* ds = frame->dataSource();
2678 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2679 DCHECK(navigation_state);
2680 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302681 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172682}
2683
2684void RenderView::didChangeLocationWithinPage(
2685 WebFrame* frame, bool is_new_navigation) {
2686 // If this was a reference fragment navigation that we initiated, then we
2687 // could end up having a non-null pending navigation state. We just need to
2688 // update the ExtraData on the datasource so that others who read the
2689 // ExtraData will get the new NavigationState. Similarly, if we did not
2690 // initiate this navigation, then we need to take care to reset any pre-
2691 // existing navigation state to a content-initiated navigation state.
2692 // DidCreateDataSource conveniently takes care of this for us.
2693 didCreateDataSource(frame, frame->dataSource());
2694
2695 didCommitProvisionalLoad(frame, is_new_navigation);
2696
[email protected]26aa0482009-09-30 16:55:272697 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]b6ad7ba2010-02-08 18:44:552698
2699 NavigationState* navigation_state = NavigationState::FromDataSource(
2700 frame->dataSource());
2701 navigation_state->user_script_idle_scheduler()->DidChangeLocationWithinPage();
[email protected]3d9689372009-09-10 04:29:172702}
2703
[email protected]476b6f82009-09-10 21:00:592704void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312705 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592706}
2707
[email protected]3d9689372009-09-10 04:29:172708void RenderView::assignIdentifierToRequest(
2709 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2710 // Ignore
2711}
2712
2713void RenderView::willSendRequest(
2714 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2715 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302716 WebFrame* top_frame = frame->top();
2717 if (!top_frame)
2718 top_frame = frame;
2719 WebDataSource* data_source = top_frame->provisionalDataSource();
2720 if (!data_source)
2721 data_source = top_frame->dataSource();
2722 if (data_source) {
2723 NavigationState* state = NavigationState::FromDataSource(data_source);
2724 if (state && state->is_cache_policy_override_set())
2725 request.setCachePolicy(state->cache_policy_override());
2726 }
[email protected]3d9689372009-09-10 04:29:172727 request.setRequestorID(routing_id_);
2728}
2729
2730void RenderView::didReceiveResponse(
2731 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]3d9689372009-09-10 04:29:172732 // Only do this for responses that correspond to a provisional data source
2733 // of the top-most frame. If we have a provisional data source, then we
2734 // can't have any sub-resources yet, so we know that this response must
2735 // correspond to a frame load.
2736 if (!frame->provisionalDataSource() || frame->parent())
2737 return;
2738
2739 // If we are in view source mode, then just let the user see the source of
2740 // the server's 404 error page.
2741 if (frame->isViewSourceModeEnabled())
2742 return;
2743
[email protected]f48013be2010-01-14 22:07:452744 // Record that this was a page loaded over SPDY.
2745 if (response.wasFetchedViaSPDY()) {
2746 NavigationState* navigation_state =
2747 NavigationState::FromDataSource(frame->provisionalDataSource());
2748 navigation_state->set_was_fetched_via_spdy(true);
2749 }
2750
2751 // Consider loading an alternate error page for 404 responses.
2752 if (response.httpStatusCode() != 404)
2753 return;
2754
[email protected]3d9689372009-09-10 04:29:172755 // Can we even load an alternate error page for this URL?
2756 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2757 return;
2758
2759 NavigationState* navigation_state =
2760 NavigationState::FromDataSource(frame->provisionalDataSource());
2761 navigation_state->set_postpone_loading_data(true);
2762 navigation_state->clear_postponed_data();
2763}
2764
2765void RenderView::didFinishResourceLoad(
2766 WebFrame* frame, unsigned identifier) {
2767 NavigationState* navigation_state =
2768 NavigationState::FromDataSource(frame->dataSource());
2769 if (!navigation_state->postpone_loading_data())
2770 return;
2771
2772 // The server returned a 404 and the content was < 512 bytes (which we
2773 // suppressed). Go ahead and fetch the alternate page content.
2774
2775 const GURL& frame_url = frame->url();
2776
2777 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2778 DCHECK(error_page_url.is_valid());
2779
2780 WebURLError original_error;
2781 original_error.unreachableURL = frame_url;
2782
2783 navigation_state->set_alt_error_page_fetcher(
2784 new AltErrorPageResourceFetcher(
2785 error_page_url, frame, original_error,
2786 NewCallback(this, &RenderView::AltErrorPageFinished)));
2787}
2788
2789void RenderView::didFailResourceLoad(
2790 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2791 // Ignore
2792}
2793
2794void RenderView::didLoadResourceFromMemoryCache(
2795 WebFrame* frame, const WebURLRequest& request,
2796 const WebURLResponse& response) {
2797 // Let the browser know we loaded a resource from the memory cache. This
2798 // message is needed to display the correct SSL indicators.
2799 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2800 routing_id_,
2801 request.url(),
[email protected]91733b62009-09-18 06:21:092802 frame->securityOrigin().toString().utf8(),
2803 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172804 response.securityInfo()));
2805}
2806
[email protected]6069da8c2009-10-20 20:33:492807void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292808 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2809}
2810
2811void RenderView::didRunInsecureContent(
2812 WebFrame* frame, const WebSecurityOrigin& origin) {
2813 Send(new ViewHostMsg_DidRunInsecureContent(
2814 routing_id_,
2815 origin.toString().utf8()));
2816}
2817
[email protected]7ea093ba2009-11-03 05:54:592818bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]684e4a42010-01-30 06:44:112819 if (enabled_per_settings) {
[email protected]2d30a7a2010-02-04 01:57:502820 return AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0de80162010-02-03 04:52:352821 enabled_per_settings);
[email protected]684e4a42010-01-30 06:44:112822 }
[email protected]7ea093ba2009-11-03 05:54:592823
2824 WebSecurityOrigin origin = frame->securityOrigin();
2825 if (origin.isEmpty())
2826 return false; // Uninitialized document?
2827
2828 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2829 return true; // Browser UI elements should still work.
2830
2831 // If the scheme is ftp: or file:, an empty file name indicates a directory
2832 // listing, which requires JavaScript to function properly.
2833 GURL frame_url = frame->url();
2834 const char* kDirProtocols[] = { "ftp", "file" };
2835 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2836 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2837 return frame_url.SchemeIs(kDirProtocols[i]) &&
2838 frame_url.ExtractFileName().empty();
2839 }
2840 }
2841
2842 return false; // Other protocols fall through here.
2843}
2844
[email protected]3d9689372009-09-10 04:29:172845void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2846 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2847}
2848
[email protected]0c882b282009-10-07 17:01:282849void RenderView::didCreateScriptContext(WebFrame* frame) {
2850 EventBindings::HandleContextCreated(frame, false);
2851}
2852
2853void RenderView::didDestroyScriptContext(WebFrame* frame) {
2854 EventBindings::HandleContextDestroyed(frame);
2855}
2856
2857void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2858 EventBindings::HandleContextCreated(frame, true);
2859}
2860
[email protected]3d9689372009-09-10 04:29:172861void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142862 CheckPreferredSize();
2863}
2864
2865void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172866 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252867 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172868 // message.
[email protected]ab32b16c2009-10-16 14:57:252869 if (send_preferred_size_changes_) {
[email protected]3d9689372009-09-10 04:29:172870 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252871 // cache the width and height and only send the IPC message when we're sure
2872 // they're different.
[email protected]26aa0482009-09-30 16:55:272873 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:392874 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:292875
[email protected]ab32b16c2009-10-16 14:57:252876 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:392877 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:252878 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:392879 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:252880
[email protected]ab32b16c2009-10-16 14:57:252881 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2882 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172883 }
2884 }
2885}
2886
[email protected]143dcd592009-11-06 21:33:492887void RenderView::didChangeScrollOffset(WebFrame* frame) {
2888 StartNavStateSyncTimerIfNecessary();
2889}
2890
[email protected]8922e1f2009-10-03 05:01:262891void RenderView::reportFindInPageMatchCount(int request_id, int count,
2892 bool final_update) {
2893 // If we have a message that has been queued up, then we should just replace
2894 // it. The ACK from the browser will make sure it gets sent when the browser
2895 // wants it.
2896 if (queued_find_reply_message_.get()) {
2897 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2898 routing_id_,
2899 request_id,
2900 count,
2901 gfx::Rect(),
2902 -1, // Don't update active match ordinal.
2903 final_update);
2904 queued_find_reply_message_.reset(msg);
2905 } else {
2906 // Send the search result over to the browser process.
2907 Send(new ViewHostMsg_Find_Reply(
2908 routing_id_,
2909 request_id,
2910 count,
2911 gfx::Rect(),
2912 -1, // // Don't update active match ordinal.
2913 final_update));
2914 }
2915}
2916
2917void RenderView::reportFindInPageSelection(int request_id,
2918 int active_match_ordinal,
2919 const WebRect& selection_rect) {
2920 // Send the search result over to the browser process.
2921 Send(new ViewHostMsg_Find_Reply(routing_id_,
2922 request_id,
2923 -1,
2924 selection_rect,
2925 active_match_ordinal,
2926 false));
2927}
2928
[email protected]79dbc662009-09-04 05:42:512929// webkit_glue::WebPluginPageDelegate -----------------------------------------
2930
[email protected]f103ab72009-09-02 17:10:592931webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2932 const GURL& url,
2933 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592934 std::string* actual_mime_type) {
2935 if (!PluginChannelHost::IsListening())
2936 return NULL;
2937
2938 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272939 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592940 if (main_frame)
2941 policy_url = main_frame->url();
2942
2943 FilePath path;
[email protected]610c0892009-09-08 19:46:182944 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2945 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592946 if (path.value().empty())
2947 return NULL;
2948
2949 const std::string* mime_type_to_use;
2950 if (!actual_mime_type->empty())
2951 mime_type_to_use = actual_mime_type;
2952 else
2953 mime_type_to_use = &mime_type;
2954
[email protected]d2139662009-12-10 03:21:142955 bool use_pepper_host = false;
2956 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2957 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:162958 const char kPepperPrefix[] = "pepper-";
2959 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:142960 if (CommandLine::ForCurrentProcess()->
2961 HasSwitch(switches::kInternalPepper)) {
2962 in_process_plugin = true;
2963 use_pepper_host = true;
2964 } else {
2965 // In process Pepper plugins must be explicitly enabled.
2966 return NULL;
2967 }
[email protected]26e8d5e2009-10-13 02:47:162968 }
[email protected]d2139662009-12-10 03:21:142969 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:462970 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2971 if (mime_type == "application/x-nacl-srpc") {
2972 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:142973 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:462974 }
2975 }
2976 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:142977 if (use_pepper_host) {
2978 return WebPluginDelegatePepper::Create(
[email protected]7477ea6f2009-12-22 23:28:152979 path,
2980 *mime_type_to_use,
[email protected]6876dff2010-01-15 19:38:092981 AsWeakPtr());
[email protected]d2139662009-12-10 03:21:142982 } else {
[email protected]6876dff2010-01-15 19:38:092983#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:142984 return WebPluginDelegateImpl::Create(
2985 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092986#else
[email protected]596b2c42010-01-14 20:40:432987 NOTIMPLEMENTED();
2988 return NULL;
[email protected]7b6616f2010-01-14 18:07:552989#endif
[email protected]6876dff2010-01-15 19:38:092990 }
[email protected]f103ab72009-09-02 17:10:592991 }
2992
[email protected]610c0892009-09-08 19:46:182993 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592994}
2995
2996void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2997#if defined(OS_LINUX)
2998 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2999 routing_id(), window));
3000#endif
3001}
3002
3003void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
3004#if defined(OS_LINUX)
3005 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3006 routing_id(), window));
3007#endif
3008 CleanupWindowInPluginMoves(window);
3009}
3010
3011void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3012 SchedulePluginMove(move);
3013}
3014
3015void RenderView::DidStartLoadingForPlugin() {
3016 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523017 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593018}
3019
3020void RenderView::DidStopLoadingForPlugin() {
3021 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523022 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593023}
3024
[email protected]7e0831b2010-02-01 08:45:153025void RenderView::PageTranslated(int page_id,
3026 const std::string& original_lang,
3027 const std::string& target_lang) {
3028 Send(new ViewHostMsg_PageTranslated(routing_id_, page_id_,
3029 original_lang, target_lang));
3030}
3031
[email protected]f103ab72009-09-02 17:10:593032void RenderView::ShowModalHTMLDialogForPlugin(
3033 const GURL& url,
3034 const gfx::Size& size,
3035 const std::string& json_arguments,
3036 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213037 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593038 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213039 json_retval));
[email protected]f103ab72009-09-02 17:10:593040}
3041
initial.commit09911bf2008-07-26 23:55:293042void RenderView::SyncNavigationState() {
3043 if (!webview())
3044 return;
3045
[email protected]26aa0482009-09-30 16:55:273046 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173047 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293048 return;
[email protected]ca948a22009-06-25 19:36:173049
3050 Send(new ViewHostMsg_UpdateState(
3051 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293052}
3053
[email protected]b0950a72009-09-29 23:16:173054bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3055 // Make sure webview was not shut down.
3056 if (!webview())
3057 return false;
3058 // Create an image resource fetcher and assign it with a call back object.
3059 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273060 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173061 NewCallback(this, &RenderView::DidDownloadImage)));
3062 return true;
3063}
3064
3065void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293066 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173067 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473068 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3069 fetcher->id(),
3070 fetcher->image_url(),
3071 image.isNull(),
3072 image));
[email protected]b0950a72009-09-29 23:16:173073 // Dispose of the image fetcher.
3074 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3075 image_fetchers_.erase(fetcher);
3076 // We're in the callback from the ImageResourceFetcher, best to delay
3077 // deletion.
3078 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293079}
3080
[email protected]bf5c2ff392009-07-08 16:24:333081void RenderView::OnDownloadFavIcon(int id,
3082 const GURL& image_url,
3083 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343084 bool data_image_failed = false;
3085 if (image_url.SchemeIs("data")) {
3086 SkBitmap data_image = ImageFromDataUrl(image_url);
3087 data_image_failed = data_image.empty();
3088 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333089 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3090 data_image));
[email protected]f11ca0732009-04-11 00:09:343091 }
3092 }
3093
[email protected]bf5c2ff392009-07-08 16:24:333094 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173095 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333096 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3097 SkBitmap()));
3098 }
initial.commit09911bf2008-07-26 23:55:293099}
3100
[email protected]f11ca0732009-04-11 00:09:343101SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3102 std::string mime_type, char_set, data;
3103 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3104 // Decode the favicon using WebKit's image decoder.
3105 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3106 const unsigned char* src_data =
3107 reinterpret_cast<const unsigned char*>(&data[0]);
3108
3109 return decoder.Decode(src_data, data.size());
3110 }
3111 return SkBitmap();
3112}
3113
initial.commit09911bf2008-07-26 23:55:293114void RenderView::OnGetApplicationInfo(int page_id) {
3115 webkit_glue::WebApplicationInfo app_info;
3116 if (page_id == page_id_)
3117 webkit_glue::GetApplicationInfo(webview(), &app_info);
3118
3119 // Prune out any data URLs in the set of icons. The browser process expects
3120 // any icon with a data URL to have originated from a favicon. We don't want
3121 // to decode arbitrary data URLs in the browser process. See
3122 // http://b/issue?id=1162972
3123 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593124 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293125 app_info.icons.erase(app_info.icons.begin() + i);
3126 --i;
3127 }
3128 }
3129
3130 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3131}
3132
[email protected]7ccddb8c2009-08-04 17:36:553133GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293134 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553135 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293136 // If the URL that failed was secure, then the embedding web page was not
3137 // expecting a network attacker to be able to manipulate its contents. As
3138 // we fetch alternate error pages over HTTP, we would be allowing a network
3139 // attacker to manipulate the contents of the response if we tried to use
3140 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153141 return GURL();
initial.commit09911bf2008-07-26 23:55:293142 }
3143
3144 // Grab the base URL from the browser process.
3145 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153146 return GURL();
initial.commit09911bf2008-07-26 23:55:293147
3148 // Strip query params from the failed URL.
3149 GURL::Replacements remove_params;
3150 remove_params.ClearUsername();
3151 remove_params.ClearPassword();
3152 remove_params.ClearQuery();
3153 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553154 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:293155
3156 // Construct the query params to send to link doctor.
3157 std::string params(alternate_error_page_url_.query());
3158 params.append("&url=");
[email protected]0d2e6a62010-01-15 20:09:193159 params.append(EscapeQueryParamValue(url_to_send.spec(), true));
initial.commit09911bf2008-07-26 23:55:293160 params.append("&sourceid=chrome");
3161 params.append("&error=");
3162 switch (error_type) {
3163 case DNS_ERROR:
3164 params.append("dnserror");
3165 break;
3166
3167 case HTTP_404:
3168 params.append("http404");
3169 break;
3170
[email protected]5df266ac2008-10-15 19:50:133171 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333172 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133173 break;
3174
initial.commit09911bf2008-07-26 23:55:293175 default:
3176 NOTREACHED() << "unknown ErrorPageType";
3177 }
3178
3179 // OK, build the final url to return.
3180 GURL::Replacements link_doctor_params;
3181 link_doctor_params.SetQueryStr(params);
3182 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3183 return url;
3184}
3185
[email protected]6069da8c2009-10-20 20:33:493186void RenderView::OnFind(int request_id, const string16& search_text,
3187 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273188 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:273189 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273190 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293191 WebFrame* search_frame = focused_frame; // start searching focused frame.
3192
3193 bool multi_frame = (frame_after_main != main_frame);
3194
3195 // If we have multiple frames, we don't want to wrap the search within the
3196 // frame, so we check here if we only have main_frame in the chain.
3197 bool wrap_within_frame = !multi_frame;
3198
[email protected]b3f2b912009-04-09 16:18:523199 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293200 bool result = false;
3201
[email protected]7830da3e2009-11-06 16:27:263202 // If something is selected when we start searching it means we cannot just
3203 // increment the current match ordinal; we need to re-generate it.
3204 WebRange current_selection = focused_frame->selectionRange();
3205
initial.commit09911bf2008-07-26 23:55:293206 do {
[email protected]dd7daa82009-08-10 05:46:453207 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593208 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293209
3210 if (!result) {
3211 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223212 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293213
3214 // Find the next frame, but skip the invisible ones.
3215 do {
3216 // What is the next frame to search? (we might be going backwards). Note
3217 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593218 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273219 search_frame->traverseNext(true) :
3220 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453221 } while (!search_frame->hasVisibleContent() &&
3222 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293223
[email protected]884db412008-11-24 23:46:503224 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223225 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293226
3227 // If we have multiple frames and we have wrapped back around to the
3228 // focused frame, we need to search it once more allowing wrap within
3229 // the frame, otherwise it will report 'no match' if the focused frame has
3230 // reported matches, but no frames after the focused_frame contain a
3231 // match for the search word(s).
3232 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453233 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593234 request_id, search_text, options, true, // Force wrapping.
3235 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293236 }
3237 }
3238
[email protected]26aa0482009-09-30 16:55:273239 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293240 } while (!result && search_frame != focused_frame);
3241
[email protected]7830da3e2009-11-06 16:27:263242 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293243 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453244 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293245 } else {
3246 // If nothing is found, set result to "0 of 0", otherwise, set it to
3247 // "-1 of 1" to indicate that we found at least one item, but we don't know
3248 // yet what is active.
3249 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3250 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293251
[email protected]4f3dc372009-02-24 00:10:293252 // If we find no matches then this will be our last status update.
3253 // Otherwise the scoping effort will send more results.
3254 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293255
[email protected]4f3dc372009-02-24 00:10:293256 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403257 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593258 request_id,
[email protected]4f3dc372009-02-24 00:10:293259 match_count,
3260 selection_rect,
3261 ordinal,
3262 final_status_update));
initial.commit09911bf2008-07-26 23:55:293263
initial.commit09911bf2008-07-26 23:55:293264 // Scoping effort begins, starting with the mainframe.
3265 search_frame = main_frame;
3266
[email protected]dd7daa82009-08-10 05:46:453267 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293268
3269 do {
3270 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453271 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293272
3273 // We don't start another scoping effort unless at least one match has
3274 // been found.
3275 if (result) {
3276 // Start new scoping request. If the scoping function determines that it
3277 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453278 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593279 search_text,
3280 options,
initial.commit09911bf2008-07-26 23:55:293281 true); // reset the tickmarks
3282 }
3283
3284 // Iterate to the next frame. The frame will not necessarily scope, for
3285 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273286 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293287 } while (search_frame != main_frame);
3288 }
3289}
3290
[email protected]8c4cdd42010-01-12 21:31:133291// static
3292std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403293 // Text with less than 100 bytes will probably not provide good results.
3294 // Report it as unknown language.
3295 if (text.length() < 100)
3296 return kUnknownLanguageCode;
3297
[email protected]8c4cdd42010-01-12 21:31:133298 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133299 int num_languages = 0;
3300 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423301 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133302 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423303 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133304 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403305 if (is_reliable && cld_language != NUM_LANGUAGES &&
3306 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483307 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3308 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263309 // language code for tradtional Chinese among others.
3310 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3311 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3312 // for Simplified Chinese.
3313 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133314 }
[email protected]8c4cdd42010-01-12 21:31:133315 return language;
[email protected]7893a982010-01-07 23:25:523316}
3317
[email protected]2d30a7a2010-02-04 01:57:503318bool RenderView::AllowContentType(ContentSettingsType settings_type,
[email protected]0de80162010-02-03 04:52:353319 bool enabled_per_settings) {
3320 if (!enabled_per_settings)
3321 return false;
3322 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]4c1b6f0b2010-02-07 16:38:183323 if (current_content_settings_.settings[settings_type] ==
3324 CONTENT_SETTING_BLOCK) {
[email protected]71b0d5d2010-02-15 05:43:073325 if (!content_blocked_[settings_type]) {
3326 content_blocked_[settings_type] = true;
[email protected]2d30a7a2010-02-04 01:57:503327 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
3328 }
[email protected]0de80162010-02-03 04:52:353329 return false;
3330 }
3331 return true;
3332}
3333
[email protected]71b0d5d2010-02-15 05:43:073334void RenderView::ClearBlockedContentSettings() {
3335 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3336 content_blocked_[i] = false;
3337}
3338
initial.commit09911bf2008-07-26 23:55:293339void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3340 Send(new ViewHostMsg_DnsPrefetch(host_names));
3341}
3342
[email protected]40bd6582009-12-04 23:49:513343void RenderView::OnZoom(PageZoom::Function function) {
3344 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3345 return;
3346
3347 int zoom_level = webview()->zoomLevel();
3348 int new_zoom_level = webview()->setZoomLevel(false,
3349 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3350
3351 // Tell the browser which host got zoomed so it can update the saved values.
3352 // Pages like the safe browsing interstitial can have empty hosts; don't
3353 // record those.
3354 std::string host(GURL(webview()->mainFrame()->url()).host());
3355 if (!host.empty())
3356 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3357}
3358
[email protected]f85f0702010-01-30 09:31:013359void RenderView::OnSetContentSettingsForLoadingHost(
3360 std::string host,
3361 const ContentSettings& content_settings) {
3362 host_content_settings_[host] = content_settings;
3363}
3364
[email protected]40bd6582009-12-04 23:49:513365void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3366 int zoom_level) {
3367 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293368}
3369
[email protected]41fc0322009-09-04 22:23:403370void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273371 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293372}
3373
[email protected]a697f4c2009-09-14 22:30:183374void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273375 WebString no_encoding;
3376 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183377}
3378
[email protected]20ad2692009-11-20 18:27:203379bool RenderView::GetAllChildFrames(
3380 WebFrame* parent_frame,
3381 std::vector<WebFrame*>* frames_vector) const {
3382 if (!parent_frame)
3383 return false;
3384 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3385 child_frame = child_frame->nextSibling()) {
3386 frames_vector->push_back(child_frame);
3387 GetAllChildFrames(child_frame, frames_vector);
3388 }
3389 return true;
3390}
3391
[email protected]dd7daa82009-08-10 05:46:453392WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3393 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273394 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453395
3396 // xpath string can represent a frame deep down the tree (across multiple
3397 // frame DOMs).
3398 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3399 // should break into 2 xpaths
3400 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3401
[email protected]26aa0482009-09-30 16:55:273402 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453403
3404 std::wstring xpath_remaining = xpath;
3405 while (!xpath_remaining.empty()) {
3406 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3407 std::wstring xpath_child;
3408 if (delim_pos != std::wstring::npos) {
3409 xpath_child = xpath_remaining.substr(0, delim_pos);
3410 xpath_remaining.erase(0, delim_pos + 1);
3411 } else {
3412 xpath_remaining.swap(xpath_child);
3413 }
3414 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293415 }
3416
[email protected]dd7daa82009-08-10 05:46:453417 return frame;
initial.commit09911bf2008-07-26 23:55:293418}
3419
[email protected]f29acf52008-11-03 20:08:333420void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3421 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293422 WebFrame* web_frame = GetChildFrame(frame_xpath);
3423 if (!web_frame)
3424 return;
3425
[email protected]dd7daa82009-08-10 05:46:453426 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293427}
3428
[email protected]1810e132009-03-24 23:35:483429void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083430 const std::string& css,
3431 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483432 WebFrame* web_frame = GetChildFrame(frame_xpath);
3433 if (!web_frame)
3434 return;
3435
[email protected]ffaef0c2009-09-15 17:08:083436 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483437}
3438
initial.commit09911bf2008-07-26 23:55:293439void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3440 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333441 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293442}
3443
[email protected]1810e132009-03-24 23:35:483444void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083445 const std::string& css,
3446 const std::string& id) {
3447 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413448
3449 // Notify RenderViewHost that css has been inserted into the frame.
3450 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483451}
3452
[email protected]7ea066a2009-04-06 20:21:593453void RenderView::OnAddMessageToConsole(
3454 const string16& frame_xpath,
3455 const string16& message,
3456 const WebConsoleMessage::Level& level) {
3457 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593458 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453459 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293460}
3461
[email protected]81e63782009-02-27 19:35:093462void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3463 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293464}
3465
3466void RenderView::OnSetDOMUIProperty(const std::string& name,
3467 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093468 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293469 dom_ui_bindings_.SetProperty(name, value);
3470}
3471
3472void RenderView::OnReservePageIDRange(int size_of_range) {
3473 next_page_id_ += size_of_range + 1;
3474}
3475
[email protected]e80c73b2009-04-07 23:24:583476void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3477 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253478 bool ended,
3479 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033480 if (ended) {
[email protected]26aa0482009-09-30 16:55:273481 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033482 }
initial.commit09911bf2008-07-26 23:55:293483}
3484
3485void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273486 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293487}
3488
initial.commit09911bf2008-07-26 23:55:293489void RenderView::OnFormFill(const FormData& form) {
3490 webkit_glue::FillForm(this->webview(), form);
3491}
3492
3493void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103494 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293495 webkit_glue::FillPasswordForm(this->webview(), form_data);
3496}
3497
3498void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583499 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253500 const gfx::Point& screen_point,
3501 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273502 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583503 drop_data.ToDragData(),
3504 drop_data.identity,
3505 client_point,
[email protected]1d9f4132009-09-08 17:29:253506 screen_point,
3507 ops);
initial.commit09911bf2008-07-26 23:55:293508
[email protected]1d9f4132009-09-08 17:29:253509 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293510}
3511
[email protected]e80c73b2009-04-07 23:24:583512void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253513 const gfx::Point& screen_point,
3514 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273515 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253516 client_point,
3517 screen_point,
3518 ops);
initial.commit09911bf2008-07-26 23:55:293519
[email protected]1d9f4132009-09-08 17:29:253520 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293521}
3522
3523void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273524 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293525}
3526
[email protected]e80c73b2009-04-07 23:24:583527void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3528 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273529 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293530}
3531
3532void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593533 webkit_preferences_ = prefs;
3534 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293535}
3536
3537void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3538 alternate_error_page_url_ = url;
3539}
3540
[email protected]a0c7153e2009-12-09 14:36:333541void RenderView::OnCustomContextMenuAction(unsigned action) {
3542 webview()->performCustomContextMenuAction(action);
3543}
3544
[email protected]d4a00a72010-01-29 01:44:423545void RenderView::OnTranslatePage(int page_id,
3546 const std::string& source_lang,
3547 const std::string& target_lang) {
3548 if (page_id != page_id_)
3549 return; // Not the page we expected, nothing to do.
3550
3551 WebFrame* main_frame = webview()->mainFrame();
3552 if (!main_frame)
3553 return;
[email protected]9e84a872010-02-09 18:23:423554
3555 page_translator_->TranslatePage(page_id, main_frame,
3556 source_lang, target_lang);
[email protected]d4a00a72010-01-29 01:44:423557}
3558
[email protected]0bedb8a2010-01-14 19:36:323559void RenderView::OnTranslateTextResponse(
3560 int work_id, int error_id, const std::vector<string16>& text_chunks) {
[email protected]d4a00a72010-01-29 01:44:423561 text_translator_.OnTranslationResponse(work_id, error_id, text_chunks);
[email protected]0bedb8a2010-01-14 19:36:323562}
3563
initial.commit09911bf2008-07-26 23:55:293564void RenderView::OnInstallMissingPlugin() {
3565 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593566 if (first_default_plugin_)
3567 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293568}
3569
[email protected]b62d1a8c2009-01-13 23:54:573570void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:343571 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363572 // This could happen if we navigated to a different page before the user
3573 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463574 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363575 return;
3576
[email protected]6069da8c2009-10-20 20:33:493577 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463578 for (size_t i = 0; i < file_names.size(); ++i) {
3579 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3580 }
3581
3582 file_chooser_completion_->didChooseFile(ws_file_names);
3583 // Reset the chooser pointer
3584 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293585}
3586
3587void RenderView::OnEnableViewSourceMode() {
3588 if (!webview())
3589 return;
[email protected]26aa0482009-09-30 16:55:273590 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293591 if (!main_frame)
3592 return;
3593
[email protected]dd7daa82009-08-10 05:46:453594 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293595}
3596
[email protected]ab32b16c2009-10-16 14:57:253597void RenderView::OnEnablePreferredSizeChangedMode() {
3598 send_preferred_size_changes_ = true;
[email protected]d8a179c2010-01-31 00:58:143599 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3600 switches::kProcessType) == switches::kExtensionProcess) {
3601 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3602 &RenderView::CheckPreferredSize);
3603 }
[email protected]0666aef2009-05-13 19:48:083604}
3605
[email protected]80d96fa2009-06-10 22:34:513606void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3607 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373608 UpdateFontRenderingFromRendererPrefs();
[email protected]033970a2009-10-14 16:45:053609#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]1c83eb42009-09-11 21:08:413610 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3611 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463612 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323613
[email protected]644d77e2010-01-27 01:03:103614 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323615 webview()->setScrollbarColors(
3616 renderer_prefs.thumb_inactive_color,
3617 renderer_prefs.thumb_active_color,
3618 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103619 webview()->setSelectionColors(
3620 renderer_prefs.active_selection_bg_color,
3621 renderer_prefs.active_selection_fg_color,
3622 renderer_prefs.inactive_selection_bg_color,
3623 renderer_prefs.inactive_selection_fg_color);
3624 }
[email protected]7a74e102009-09-03 00:16:563625#endif
[email protected]80d96fa2009-06-10 22:34:513626}
3627
[email protected]952cb702009-10-07 05:50:283628void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3629 const WebMediaPlayerAction& action) {
3630 if (webview())
3631 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563632}
3633
[email protected]7b291f92009-08-14 05:43:533634void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513635 // When this is first set, the bindings aren't fully loaded. We only need
3636 // to call through this API after the page has already been loaded. It's
3637 // also called in didCreateDocumentElement to bootstrap.
3638 if (view_type_ != ViewType::INVALID) {
3639 if (type == ViewType::EXTENSION_MOLE ||
3640 type == ViewType::EXTENSION_TOOLSTRIP) {
3641 ExtensionProcessBindings::SetViewType(webview(), type);
3642 }
3643 }
[email protected]7b291f92009-08-14 05:43:533644 view_type_ = type;
3645}
3646
3647void RenderView::OnUpdateBrowserWindowId(int window_id) {
3648 browser_window_id_ = window_id;
3649}
3650
initial.commit09911bf2008-07-26 23:55:293651void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3652 int forward_list_count) {
3653 history_back_list_count_ = back_list_count;
3654 history_forward_list_count_ = forward_list_count;
3655}
3656
[email protected]266eb6f2008-09-30 23:56:503657void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253658 const webkit_glue::WebAccessibility::InParams& in_params,
3659 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573660#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153661 if (!accessibility_.get()) {
3662 // TODO(dglazkov): Once implemented for all ports, remove lazy
3663 // instantiation of accessibility_.
3664 accessibility_.reset(WebAccessibilityCache::create());
3665 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253666 }
[email protected]266eb6f2008-09-30 23:56:503667
[email protected]17455962010-02-24 01:39:353668 out_params->return_code =
3669 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3670 in_params,
3671 out_params);
[email protected]c7287a92009-11-04 20:06:153672
[email protected]6c8afae52009-01-22 02:24:573673#else // defined(OS_WIN)
3674 // TODO(port): accessibility not yet implemented
3675 NOTIMPLEMENTED();
3676#endif
[email protected]266eb6f2008-09-30 23:56:503677}
3678
[email protected]6a983b42009-03-20 20:12:253679void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573680#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153681 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503682 // If accessibility is not activated, ignore clearing message.
3683 return;
3684 }
[email protected]e846d0d2009-05-20 00:53:063685
[email protected]c7287a92009-11-04 20:06:153686 if (clear_all) {
3687 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503688 return;
[email protected]c7287a92009-11-04 20:06:153689 }
3690
3691 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063692
[email protected]6c8afae52009-01-22 02:24:573693#else // defined(OS_WIN)
3694 // TODO(port): accessibility not yet implemented
3695 NOTIMPLEMENTED();
3696#endif
[email protected]266eb6f2008-09-30 23:56:503697}
3698
initial.commit09911bf2008-07-26 23:55:293699void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3700 const GURL& page_url) {
3701 // Prepare list to storage all savable resource links.
3702 std::vector<GURL> resources_list;
3703 std::vector<GURL> referrers_list;
3704 std::vector<GURL> frames_list;
3705 webkit_glue::SavableResourcesResult result(&resources_list,
3706 &referrers_list,
3707 &frames_list);
3708
[email protected]dbeb3952009-10-13 18:01:183709 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3710 webview(),
3711 page_url,
3712 &result,
3713 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293714 // If something is wrong when collecting all savable resource links,
3715 // send empty list to embedder(browser) to tell it failed.
3716 referrers_list.clear();
3717 resources_list.clear();
3718 frames_list.clear();
3719 }
3720
3721 // Send result of all savable resource links to embedder.
3722 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3723 resources_list,
3724 referrers_list,
3725 frames_list));
3726}
3727
3728void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323729 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313730 const std::vector<FilePath>& local_paths,
3731 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073732
3733 // Convert std::vector of GURLs to WebVector<WebURL>
3734 WebVector<WebURL> weburl_links(links);
3735
3736 // Convert std::vector of std::strings to WebVector<WebString>
3737 WebVector<WebString> webstring_paths(local_paths.size());
3738 for (size_t i = 0; i < local_paths.size(); i++)
3739 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3740
3741 WebPageSerializer::serialize(webview()->mainFrame(),
3742 true, this, weburl_links, webstring_paths,
3743 webkit_glue::FilePathToWebString(
3744 local_directory_name));
initial.commit09911bf2008-07-26 23:55:293745}
3746
[email protected]d9ec5c0f2009-12-23 11:55:073747void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
3748 const WebCString& data,
3749 WebPageSerializerClient::PageSerializationStatus status) {
3750 Send(new ViewHostMsg_SendSerializedHtmlData(
3751 routing_id_,
3752 frame_url,
3753 data.data(),
3754 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:293755}
3756
[email protected]04b4a6c2008-08-02 00:44:473757void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273758 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473759 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293760}
3761
[email protected]eb6b87a2009-07-24 15:57:393762void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293763 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3764 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3765 // in the onunload handler from appearing. For now, we're bypassing that and
3766 // calling the FrameLoader's CloseURL method directly. This should be
3767 // revisited to avoid having two ways to close a page. Having a single way
3768 // to close that can run onunload is also useful for fixing
3769 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273770 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293771 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453772 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173773 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293774 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3775 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453776 if (url.SchemeIs(chrome::kHttpScheme) ||
3777 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293778 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293779 }
[email protected]26aa0482009-09-30 16:55:273780 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293781
[email protected]eb6b87a2009-07-24 15:57:393782 // Just echo back the params in the ACK.
3783 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293784}
3785
3786void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573787#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293788 gfx::NativeTheme::instance()->CloseHandles();
3789 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283790 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573791#else // defined(OS_WIN)
3792 // TODO(port): we don't support theming on non-Windows platforms yet
3793 NOTIMPLEMENTED();
3794#endif
initial.commit09911bf2008-07-26 23:55:293795}
3796
[email protected]28790922009-03-09 19:48:373797void RenderView::OnMessageFromExternalHost(const std::string& message,
3798 const std::string& origin,
3799 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153800 if (message.empty())
3801 return;
3802
[email protected]28790922009-03-09 19:48:373803 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3804 target);
[email protected]3ac14a052008-08-15 21:22:153805}
3806
[email protected]0aa55312008-10-17 21:53:083807void RenderView::OnDisassociateFromPopupCount() {
3808 if (decrement_shared_popup_at_destruction_)
3809 shared_popup_counter_->data--;
3810 shared_popup_counter_ = new SharedRenderViewCounter(0);
3811 decrement_shared_popup_at_destruction_ = false;
3812}
3813
[email protected]15d79e12009-08-02 19:23:453814bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3815 const WebURLError& error,
3816 bool replace) {
3817 // We only show alternate error pages in the main frame. They are
3818 // intended to assist the user when navigating, so there is not much
3819 // value in showing them for failed subframes. Ideally, we would be
3820 // able to use the TYPED transition type for this, but that flag is
3821 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453822 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453823 return false;
3824
3825 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373826 // connection failure.
[email protected]15d79e12009-08-02 19:23:453827 int ec = error.reason;
3828 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3829 ec != net::ERR_CONNECTION_FAILED &&
3830 ec != net::ERR_CONNECTION_REFUSED &&
3831 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373832 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453833 return false;
3834
3835 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553836 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453837 if (!error_page_url.is_valid())
3838 return false;
3839
3840 // Load an empty page first so there is an immediate response to the error,
3841 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453842 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453843 GURL(kUnreachableWebDataURL),
3844 error.unreachableURL,
3845 replace);
3846
3847 // Now, create a fetcher for the error page and associate it with the data
3848 // source we just created via the LoadHTMLString call. That way if another
3849 // navigation occurs, the fetcher will get destroyed.
3850 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453851 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453852 navigation_state->set_alt_error_page_fetcher(
3853 new AltErrorPageResourceFetcher(
3854 error_page_url, frame, error,
3855 NewCallback(this, &RenderView::AltErrorPageFinished)));
3856 return true;
3857}
3858
initial.commit09911bf2008-07-26 23:55:293859std::string RenderView::GetAltHTMLForTemplate(
3860 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393861 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293862 ResourceBundle::GetSharedInstance().GetRawDataResource(
3863 template_resource_id));
3864
3865 if (template_html.empty()) {
3866 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3867 return "";
3868 }
[email protected]7cd22a52009-07-14 00:40:253869
initial.commit09911bf2008-07-26 23:55:293870 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253871 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293872 template_html, &error_strings, "t");
3873}
[email protected]0e79b9e2009-02-13 04:20:483874
[email protected]15d79e12009-08-02 19:23:453875void RenderView::AltErrorPageFinished(WebFrame* frame,
3876 const WebURLError& original_error,
3877 const std::string& html) {
3878 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553879
3880 // If we failed to download the alternate error page, fall back to the
3881 // original error page if present. Otherwise, LoadNavigationErrorPage
3882 // will simply display a default error page.
3883 const std::string* html_to_load = &html;
3884 if (html.empty()) {
3885 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453886 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553887 html_to_load = &navigation_state->postponed_data();
3888 }
3889 LoadNavigationErrorPage(
3890 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453891}
3892
[email protected]30f75e62009-02-25 22:01:003893void RenderView::OnMoveOrResizeStarted() {
3894 if (webview())
[email protected]4605325d2010-02-08 23:46:043895 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:003896}
3897
[email protected]30f75e62009-02-25 22:01:003898void RenderView::OnResize(const gfx::Size& new_size,
3899 const gfx::Rect& resizer_rect) {
3900 if (webview())
[email protected]4605325d2010-02-08 23:46:043901 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:003902 RenderWidget::OnResize(new_size, resizer_rect);
3903}
[email protected]0aa477bd2009-03-23 22:21:433904
[email protected]05d478752009-04-08 23:38:163905void RenderView::OnClearFocusedNode() {
3906 if (webview())
[email protected]26aa0482009-09-30 16:55:273907 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163908}
3909
[email protected]699ab0d2009-04-23 23:19:143910void RenderView::OnSetBackground(const SkBitmap& background) {
3911 if (webview())
[email protected]b4bb2502009-10-01 22:35:273912 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143913
3914 SetBackground(background);
3915}
3916
[email protected]8c66c5a2009-07-22 17:26:343917void RenderView::OnSetActive(bool active) {
3918 if (webview())
[email protected]b4bb2502009-10-01 22:35:273919 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263920
3921#if defined(OS_MACOSX)
3922 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3923 for (plugin_it = plugin_delegates_.begin();
3924 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3925 (*plugin_it)->SetWindowFocus(active);
3926 }
3927#endif
[email protected]8c66c5a2009-07-22 17:26:343928}
3929
[email protected]6ce7abc52010-02-02 18:40:143930#if defined(OS_MACOSX)
3931void RenderView::OnSetWindowVisibility(bool visible) {
3932 // Inform plugins that their container has changed visibility.
3933 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3934 for (plugin_it = plugin_delegates_.begin();
3935 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3936 (*plugin_it)->SetContainerVisibility(visible);
3937 }
3938}
[email protected]1e6e3c992010-02-08 15:52:133939
3940void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
3941 gfx::Rect view_frame) {
3942 // Inform plugins that their window's frame has changed.
3943 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3944 for (plugin_it = plugin_delegates_.begin();
3945 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3946 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3947 }
3948}
[email protected]6ce7abc52010-02-02 18:40:143949#endif // OS_MACOSX
3950
[email protected]309d7a282009-03-24 09:18:273951void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:583952 const ListValue& args,
[email protected]c6619182009-05-12 14:59:323953 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473954 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323955 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473956 has_callback));
[email protected]309d7a282009-03-24 09:18:273957}
3958
[email protected]c6619182009-05-12 14:59:323959void RenderView::OnExtensionResponse(int request_id,
3960 bool success,
3961 const std::string& response,
3962 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353963 ExtensionProcessBindings::HandleResponse(
3964 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273965}
[email protected]c20210e62009-04-03 21:39:263966
[email protected]078b34612009-09-19 19:31:513967void RenderView::InjectToolstripCSS() {
3968 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3969 return;
3970
3971 static const base::StringPiece toolstrip_css(
3972 ResourceBundle::GetSharedInstance().GetRawDataResource(
3973 IDR_EXTENSION_TOOLSTRIP_CSS));
3974 std::string css = toolstrip_css.as_string();
3975 InsertCSS(L"", css, "ToolstripDefaultCSS");
3976}
3977
[email protected]7120f132009-07-20 21:05:373978void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3979 const ListValue& args) {
3980 RendererExtensionBindings::Invoke(function_name, args, this);
3981}
3982
[email protected]e7e4f3c2009-04-21 15:24:083983// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263984//
[email protected]7a9b51f2009-06-29 21:28:293985// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263986// The time points we keep are
3987// request: time document was requested by user
3988// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253989// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293990// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263991// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293992// first_paint: first paint performed
3993// first_paint_after_load: first paint performed after load is finished
3994// begin: request if it was user requested, start otherwise
3995//
[email protected]c20210e62009-04-03 21:39:263996// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253997// request->start,
[email protected]7a9b51f2009-06-29 21:28:293998// start->commit,
3999// commit->finish_document,
4000// finish_document->finish,
4001// begin->commit,
4002// begin->finishDoc,
4003// begin->finish,
4004// begin->first_paint,
4005// begin->first_paint_after_load
4006// commit->finishDoc,
4007// commit->first_paint,
4008// commit->first_paint_after_load,
4009// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264010//
[email protected]e7e4f3c2009-04-21 15:24:084011// It's possible for the request time not to be set, if a client
4012// redirect had been done (the user never requested the page)
4013// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294014// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264015void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274016 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564017 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454018 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294019 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564020
[email protected]7a9b51f2009-06-29 21:28:294021 // If we've already dumped or we haven't finished loading, do nothing.
4022 if (navigation_state->load_histograms_recorded() || finish.is_null())
4023 return;
[email protected]ed3fb032009-06-16 19:50:564024
[email protected]f8999642009-10-27 21:39:424025 LogNavigationState(navigation_state, main_frame->dataSource());
4026
[email protected]a7ccc4d2010-01-27 08:14:484027 NavigationState::LoadType load_type = navigation_state->load_type();
4028 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184029 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484030
[email protected]7a9b51f2009-06-29 21:28:294031 Time request = navigation_state->request_time();
4032 Time start = navigation_state->start_load_time();
4033 Time commit = navigation_state->commit_load_time();
4034 Time finish_doc = navigation_state->finish_document_load_time();
4035 Time first_paint = navigation_state->first_paint_time();
4036 Time first_paint_after_load =
4037 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:264038
[email protected]7a9b51f2009-06-29 21:28:294039 Time begin;
4040 // Client side redirects will have no request time.
4041 if (request.is_null()) {
4042 begin = start;
4043 } else {
4044 begin = request;
4045 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084046 }
[email protected]7a9b51f2009-06-29 21:28:294047 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4048 UMA_HISTOGRAM_MEDIUM_TIMES(
4049 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4050 UMA_HISTOGRAM_MEDIUM_TIMES(
4051 "Renderer4.FinishDocToFinish", finish - finish_doc);
4052
4053 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484054
4055 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4056 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4057 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484058 TimeDelta begin_to_finish_doc = finish_doc - begin;
4059 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184060
4061 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4062 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4063 static const size_t kBeginToFinishBucketCount(100);
4064 TimeDelta begin_to_finish = finish_doc - begin;
4065 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4066 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4067
[email protected]a7ccc4d2010-01-27 08:14:484068 switch (load_type) {
4069 case NavigationState::UNDEFINED_LOAD:
4070 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4071 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4072 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184073 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4074 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4075 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484076 break;
4077 case NavigationState::RELOAD:
4078 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4079 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4080 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184081 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4082 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4083 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484084 break;
4085 case NavigationState::HISTORY_LOAD:
4086 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4087 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4088 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184089 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4090 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4091 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484092 break;
4093 case NavigationState::NORMAL_LOAD:
4094 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4095 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4096 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184097 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4098 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4099 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484100 break;
[email protected]4c1b6f0b2010-02-07 16:38:184101 case NavigationState::LINK_LOAD_NORMAL:
4102 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484103 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4104 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184105 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4106 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4107 kBeginToFinishBucketCount);
4108 break;
4109 case NavigationState::LINK_LOAD_RELOAD:
4110 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4111 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4112 kBeginToFinishDocBucketCount);
4113 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4114 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4115 kBeginToFinishBucketCount);
4116 break;
4117 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4118 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4119 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4120 kBeginToFinishDocBucketCount);
4121 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4122 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4123 kBeginToFinishBucketCount);
4124 break;
4125 case NavigationState::LINK_LOAD_CACHE_ONLY:
4126 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4127 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4128 kBeginToFinishDocBucketCount);
4129 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4130 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4131 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484132 break;
4133 default:
4134 break;
4135 }
4136
4137 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4138 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4139 if (use_dns_histogram) {
[email protected]fd11f1752010-02-23 22:35:484140 UMA_HISTOGRAM_ENUMERATION(FieldTrial::MakeName(
4141 "Renderer4.LoadType", "DnsImpact"),
4142 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484143 switch (load_type) {
4144 case NavigationState::NORMAL_LOAD:
4145 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184146 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4147 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4148 kBeginToFinishBucketCount);
4149 break;
4150 case NavigationState::LINK_LOAD_NORMAL:
4151 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184152 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4153 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4154 kBeginToFinishBucketCount);
4155 break;
4156 case NavigationState::LINK_LOAD_RELOAD:
4157 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184158 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4159 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4160 kBeginToFinishBucketCount);
4161 break;
4162 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4163 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184164 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4165 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4166 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484167 break;
4168 default:
4169 break;
4170 }
4171 }
4172
4173 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4174 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4175 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484176 UMA_HISTOGRAM_ENUMERATION(
4177 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4178 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484179 switch (load_type) {
4180 case NavigationState::NORMAL_LOAD:
4181 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484182 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4183 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4184 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484185 break;
[email protected]4c1b6f0b2010-02-07 16:38:184186 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484187 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484188 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4189 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4190 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184191 break;
4192 case NavigationState::LINK_LOAD_RELOAD:
4193 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484194 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4195 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4196 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184197 break;
4198 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4199 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484200 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4201 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4202 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184203 break;
4204 case NavigationState::LINK_LOAD_CACHE_ONLY:
4205 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484206 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4207 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4208 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484209 break;
4210 default:
4211 break;
4212 }
4213 }
4214
4215 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4216 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184217 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4218 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484219 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4220 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4221 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4222 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544223
[email protected]0a32257a2009-07-09 18:10:414224 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4225 finish - start, kBeginToFinishMin,
4226 kBeginToFinishMax, kBeginToFinishBucketCount);
4227 if (!request.is_null())
4228 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4229 finish - request, kBeginToFinishMin,
4230 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544231
[email protected]7a9b51f2009-06-29 21:28:294232 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4233
4234 if (!first_paint.is_null()) {
4235 UMA_HISTOGRAM_MEDIUM_TIMES(
4236 "Renderer4.BeginToFirstPaint", first_paint - begin);
4237 UMA_HISTOGRAM_MEDIUM_TIMES(
4238 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264239 }
[email protected]7a9b51f2009-06-29 21:28:294240
4241 if (!first_paint_after_load.is_null()) {
4242 UMA_HISTOGRAM_MEDIUM_TIMES(
4243 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4244 UMA_HISTOGRAM_MEDIUM_TIMES(
4245 "Renderer4.CommitToFirstPaintAfterLoad",
4246 first_paint_after_load - commit);
4247 UMA_HISTOGRAM_MEDIUM_TIMES(
4248 "Renderer4.FinishToFirstPaintAfterLoad",
4249 first_paint_after_load - finish);
4250 }
4251
4252 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414253
4254 // Since there are currently no guarantees that renderer histograms will be
4255 // sent to the browser, we initiate a PostTask here to be sure that we send
4256 // the histograms we generated. Without this call, pages that don't have an
4257 // on-close-handler might generate data that is lost when the renderer is
4258 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484259 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4260 // should post when the onload is complete, so that it doesn't interfere with
4261 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414262 if (RenderThread::current()) {
4263 RenderThread::current()->SendHistograms(
4264 HistogramSynchronizer::kReservedSequenceNumber);
4265 }
[email protected]c20210e62009-04-03 21:39:264266}
[email protected]e846d0d2009-05-20 00:53:064267
[email protected]f8999642009-10-27 21:39:424268void RenderView::LogNavigationState(const NavigationState* state,
4269 const WebDataSource* ds) const {
4270 // Because this function gets called on every page load,
4271 // take extra care to optimize it away if logging is turned off.
4272 if (logging::LOG_INFO < logging::GetMinLogLevel())
4273 return;
4274
4275 DCHECK(state);
4276 DCHECK(ds);
4277 GURL url(ds->request().url());
4278 Time start = state->start_load_time();
4279 Time finish = state->finish_load_time();
4280 // TODO(mbelshe): should we log more stats?
4281 LOG(INFO) << "PLT: "
4282 << (finish - start).InMilliseconds()
4283 << "ms "
4284 << url.spec();
4285}
4286
[email protected]cc0445f2009-10-13 16:09:084287void RenderView::focusAccessibilityObject(
4288 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064289#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154290 // TODO(dglazkov): Current logic implies that focus change can only be made
4291 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4292 // where accessibility is initialized. We should determine whether that's
4293 // right.
4294 if (!accessibility_.get())
4295 return;
[email protected]e846d0d2009-05-20 00:53:064296
4297 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154298 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064299
4300 // If id is valid, alert the browser side that an accessibility focus change
4301 // occurred.
4302 if (acc_obj_id >= 0)
4303 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4304
4305#else // defined(OS_WIN)
4306 // TODO(port): accessibility not yet implemented
4307 NOTIMPLEMENTED();
4308#endif
4309}
[email protected]daa8c58e2009-06-15 17:21:104310
[email protected]e9e07992010-02-17 21:04:364311void RenderView::SendForms(WebFrame* frame) {
4312 WebVector<WebFormElement> web_forms;
4313 frame->forms(web_forms);
4314
4315 std::vector<FormFieldValues> forms;
4316 for (size_t i = 0; i < web_forms.size(); ++i) {
4317 const WebFormElement& web_form = web_forms[i];
4318
4319 if (web_form.autoComplete()) {
4320 scoped_ptr<FormFieldValues> form(FormFieldValues::Create(web_form));
4321 if (form.get())
4322 forms.push_back(*form);
4323 }
4324 }
4325
4326 if (!forms.empty())
4327 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
4328}
4329
[email protected]daa8c58e2009-06-15 17:21:104330void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:484331 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454332 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104333
4334 std::vector<PasswordForm> password_forms;
4335 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484336 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104337
4338 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:484339 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:104340 scoped_ptr<PasswordForm> password_form(
4341 PasswordFormDomManager::CreatePasswordForm(form));
4342 if (password_form.get())
4343 password_forms.push_back(*password_form);
4344 }
4345 }
4346
4347 if (!password_forms.empty())
4348 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4349}
[email protected]0fda7272009-06-26 15:49:334350
4351void RenderView::Print(WebFrame* frame, bool script_initiated) {
4352 DCHECK(frame);
4353 if (print_helper_.get() == NULL) {
4354 print_helper_.reset(new PrintWebViewHelper(this));
4355 }
4356 print_helper_->Print(frame, script_initiated);
4357}
[email protected]446705872009-09-10 07:22:484358
4359void RenderView::OnSetEditCommandsForNextKeyEvent(
4360 const EditCommands& edit_commands) {
4361 edit_commands_ = edit_commands;
4362}
4363
[email protected]61f5a7b2009-12-22 22:21:204364void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274365 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354366 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204367 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4368 false));
[email protected]912256b32009-09-18 09:47:354369 return;
4370 }
4371
[email protected]fa7b6b542009-11-03 05:02:304372 WebDataSource* ds = main_frame->dataSource();
4373 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4374 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204375 pending_code_execution_queue_.push(
4376 linked_ptr<ViewMsg_ExecuteCode_Params>(
4377 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304378 return;
4379 }
4380
[email protected]61f5a7b2009-12-22 22:21:204381 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304382}
4383
4384void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204385 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484386 // Don't execute scripts in gallery pages.
4387 GURL frame_url = GURL(frame->url());
4388 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4389 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4390 return;
4391 }
4392
[email protected]20ad2692009-11-20 18:27:204393 std::vector<WebFrame*> frame_vector;
4394 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204395 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204396 GetAllChildFrames(frame, &frame_vector);
4397
4398 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4399 frame_it != frame_vector.end(); ++frame_it) {
4400 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204401 if (params.is_javascript) {
4402 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4403 continue;
4404
[email protected]20ad2692009-11-20 18:27:204405 std::vector<WebScriptSource> sources;
4406 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204407 WebScriptSource(WebString::fromUTF8(params.code)));
4408 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204409 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204410 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204411 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4412 } else {
[email protected]61f5a7b2009-12-22 22:21:204413 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204414 }
[email protected]912256b32009-09-18 09:47:354415 }
4416
[email protected]61f5a7b2009-12-22 22:21:204417 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354418}
4419
[email protected]60c42a8c72009-10-09 04:08:594420void RenderView::Close() {
4421 // We need to grab a pointer to the doomed WebView before we destroy it.
4422 WebView* doomed = webview();
4423 RenderWidget::Close();
4424 Singleton<ViewMap>::get()->erase(doomed);
4425}
4426
[email protected]446705872009-09-10 07:22:484427void RenderView::DidHandleKeyEvent() {
4428 edit_commands_.clear();
4429}
4430
[email protected]941e4552010-02-01 21:23:434431#if defined(OS_MACOSX)
4432void RenderView::OnWasHidden() {
4433 RenderWidget::OnWasHidden();
4434
4435 // Inform plugins that their container is no longer visible.
4436 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4437 for (plugin_it = plugin_delegates_.begin();
4438 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4439 (*plugin_it)->SetContainerVisibility(false);
4440 }
4441}
4442
4443void RenderView::OnWasRestored(bool needs_repainting) {
4444 RenderWidget::OnWasRestored(needs_repainting);
4445
4446 // Inform plugins that their container is now visible.
4447 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4448 for (plugin_it = plugin_delegates_.begin();
4449 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4450 (*plugin_it)->SetContainerVisibility(true);
4451 }
4452}
[email protected]1e6e3c992010-02-08 15:52:134453
4454void RenderView::OnSetFocus(bool enable) {
4455 RenderWidget::OnSetFocus(enable);
4456
4457 // RenderWidget's call to setFocus can cause the underlying webview's
4458 // activation state to change just like a call to setIsActive.
4459 if (enable && webview() && webview()->isActive()) {
4460 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4461 for (plugin_it = plugin_delegates_.begin();
4462 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4463 (*plugin_it)->SetWindowFocus(true);
4464 }
4465 }
4466}
[email protected]941e4552010-02-01 21:23:434467#endif // OS_MACOSX
4468
[email protected]83dde542009-09-11 20:59:554469void RenderView::EnsureDocumentTag() {
4470 // TODO(darin): There's actually no reason for this to be here. We should
4471 // have the browser side manage the document tag.
4472#if defined(OS_MACOSX)
4473 if (!has_document_tag_) {
4474 // Make the call to get the tag.
4475 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4476 has_document_tag_ = true;
4477 }
4478#endif
4479}
[email protected]12636df2009-09-28 22:32:214480
[email protected]43f28f832010-02-03 02:28:484481#if defined(OS_MACOSX)
4482gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle() {
4483 gfx::PluginWindowHandle window = NULL;
4484 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
4485 routing_id(), &window));
4486 return window;
4487}
4488
4489void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4490 if (window)
4491 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4492}
4493
4494void RenderView::GPUPluginSetIOSurface(gfx::PluginWindowHandle window,
4495 int32 width,
4496 int32 height,
4497 uint64 io_surface_identifier) {
4498 Send(new ViewHostMsg_GPUPluginSetIOSurface(
4499 routing_id(), window, width, height, io_surface_identifier));
4500}
4501
[email protected]1aef98132010-02-23 18:00:074502void RenderView::GPUPluginSetTransportDIB(gfx::PluginWindowHandle window,
4503 int32 width,
4504 int32 height,
4505 TransportDIB::Handle transport_dib) {
4506 Send(new ViewHostMsg_GPUPluginSetTransportDIB(
4507 routing_id(), window, width, height, transport_dib));
4508}
4509
4510TransportDIB::Handle RenderView::GPUPluginAllocTransportDIB(size_t size) {
4511 TransportDIB::Handle dib_handle;
4512 // Assume this is a synchronous RPC.
4513 if (Send(new ViewHostMsg_AllocTransportDIB(size, &dib_handle)))
4514 return dib_handle;
4515 // Return an invalid handle if Send() fails.
4516 return TransportDIB::DefaultHandleValue();
4517}
4518
4519void RenderView::GPUPluginFreeTransportDIB(TransportDIB::Id dib_id) {
4520 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4521}
4522
[email protected]43f28f832010-02-03 02:28:484523void RenderView::GPUPluginBuffersSwapped(gfx::PluginWindowHandle window) {
4524 Send(new ViewHostMsg_GPUPluginBuffersSwapped(routing_id(), window));
4525}
4526#endif
[email protected]58c321d2010-02-19 12:11:284527
4528WebKit::WebGeolocationServiceInterface* RenderView::getGeolocationService() {
4529 if (!geolocation_dispatcher_.get())
4530 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
4531 return geolocation_dispatcher_.get();
4532}
4533