blob: ce5520bcc7e948d01b51901480e0519da36b73c5 [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"
initial.commit09911bf2008-07-26 23:55:2917#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5018#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0519#include "base/field_trial.h"
[email protected]30507922010-01-15 16:48:2320#include "base/histogram.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5322#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2923#include "base/string_piece.h"
24#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2325#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5726#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0927#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5528#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1730#include "chrome/common/chrome_constants.h"
[email protected]1f4fc8e8c2010-01-02 00:46:4131#include "chrome/common/histogram_synchronizer.h"
[email protected]d146b832009-12-23 02:45:4832#include "chrome/common/extensions/extension_constants.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1734#include "chrome/common/page_zoom.h"
[email protected]8beff0762009-09-29 02:18:3035#include "chrome/common/plugin_messages.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"
initial.commit09911bf2008-07-26 23:55:2948#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5649#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5650#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1251#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3052#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5053#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2554#include "chrome/renderer/render_process.h"
[email protected]bd92c3a2010-01-13 05:02:3455#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4656#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3557#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2958#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2959#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2960#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4261#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5662#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2763#include "grit/generated_resources.h"
64#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3465#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2966#include "net/base/escape.h"
67#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0068#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1069#include "skia/ext/image_operations.h"
[email protected]8c4cdd42010-01-12 21:31:1370#include "third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]418ed5ab2009-11-12 01:14:4971#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
72#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0773#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4974#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
75#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3276#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4977#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3578#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]418ed5ab2009-11-12 01:14:4979#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
80#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
81#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
82#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3283#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0784#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]418ed5ab2009-11-12 01:14:4985#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
86#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
87#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
88#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
89#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
90#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:3492#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:4993#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
95#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
96#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
98#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]80f584d92010-01-21 03:59:0499#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29100#include "webkit/default_plugin/default_plugin_shared.h"
[email protected]ca948a22009-06-25 19:36:17101#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29102#include "webkit/glue/dom_operations.h"
[email protected]f11ca0732009-04-11 00:09:34103#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17104#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51105#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29106#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29107#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:23108#include "webkit/glue/plugins/webplugin_delegate_impl.h"
initial.commit09911bf2008-07-26 23:55:29109#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29110#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17111#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:59112#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29113
[email protected]6c8afae52009-01-22 02:24:57114#if defined(OS_WIN)
115// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57116// * theming
[email protected]86281ad2009-10-07 20:07:17117#include "app/gfx/native_theme_win.h"
[email protected]6c8afae52009-01-22 02:24:57118#endif
119
[email protected]80f584d92010-01-21 03:59:04120using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26121using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33122using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45123using webkit_glue::AltErrorPageResourceFetcher;
[email protected]51bd36612009-10-20 22:49:47124using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17125using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56126using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10127using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15128using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08129using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41130using WebKit::WebColor;
131using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59132using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44133using WebKit::WebContextMenuData;
[email protected]d9ec5c0f2009-12-23 11:55:07134using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55135using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28136using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29137using WebKit::WebDevToolsAgent;
[email protected]e80c73b2009-04-07 23:24:58138using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25139using WebKit::WebDragOperation;
140using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51141using WebKit::WebEditingAction;
[email protected]6069da8c2009-10-20 20:33:49142using WebKit::WebFindOptions;
[email protected]979c28b2009-11-07 01:30:48143using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45144using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17145using WebKit::WebHistoryItem;
[email protected]3d9689372009-09-10 04:29:17146using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28147using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17148using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28149using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28150using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51151using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07152using WebKit::WebPageSerializer;
153using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17154using WebKit::WebPlugin;
155using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52156using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59157using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51158using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52159using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40160using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35161using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29162using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59163using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42164using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02165using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34166using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28167using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51168using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52169using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28170using WebKit::WebURL;
171using WebKit::WebURLError;
172using WebKit::WebURLRequest;
173using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28174using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03175using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28176using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43177using WebKit::WebWorker;
178using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33179
initial.commit09911bf2008-07-26 23:55:29180//-----------------------------------------------------------------------------
181
182// define to write the time necessary for thumbnail/DOM text retrieval,
183// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29184// #define TIME_TEXT_RETRIEVAL
185
186// maximum number of characters in the document to index, any text beyond this
187// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57188static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29189
190// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37191static const int kThumbnailWidth = 212;
192static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29193
194// Delay in milliseconds that we'll wait before capturing the page contents
195// and thumbnail.
196static const int kDelayForCaptureMs = 500;
197
198// Typically, we capture the page data once the page is loaded.
199// Sometimes, the page never finishes to load, preventing the page capture
200// To workaround this problem, we always perform a capture after the following
201// delay.
202static const int kDelayForForcedCaptureMs = 6000;
203
[email protected]882daa92009-11-05 16:31:31204// Time, in seconds, we delay before sending content state changes (such as form
205// state and scroll position) to the browser. We delay sending changes to avoid
206// spamming the browser.
207// To avoid having tab/session restore require sending a message to get the
208// current content state during tab closing we use a shorter timeout for the
209// foreground renderer. This means there is a small window of time from which
210// content state is modified and not sent to session restore, but this is
211// better than having to wake up all renderers during shutdown.
212static const int kDelaySecondsForContentStateSyncHidden = 5;
213static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29214
[email protected]0aa55312008-10-17 21:53:08215// The maximum number of popups that can be spawned from one page.
216static const int kMaximumNumberOfUnacknowledgedPopups = 25;
217
initial.commit09911bf2008-07-26 23:55:29218static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16219 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29220
[email protected]50b691c2008-10-31 19:08:35221static const char* const kBackForwardNavigationScheme = "history";
222
[email protected]8c4cdd42010-01-12 21:31:13223// The string returned in DetectLanguage if we failed to detect the language.
[email protected]8dc5a2052010-01-19 21:32:42224static const char* const kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13225
[email protected]726985e22009-06-18 21:09:28226static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
227 WebVector<WebURL> urls;
228 ds->redirectChain(urls);
229 result->reserve(urls.size());
230 for (size_t i = 0; i < urls.size(); ++i)
231 result->push_back(urls[i]);
232}
233
[email protected]61f5a7b2009-12-22 22:21:20234static bool UrlMatchesPermissions(
235 const GURL& url, const std::vector<URLPattern>& host_permissions) {
236 for (size_t i = 0; i < host_permissions.size(); ++i) {
237 if (host_permissions[i].MatchesUrl(url))
238 return true;
239 }
240
241 return false;
242}
243
[email protected]30507922010-01-15 16:48:23244static bool PaintViewIntoCanvas(WebView* view,
245 skia::PlatformCanvas& canvas) {
246 view->layout();
247 const WebSize& size = view->size();
248
249 if (!canvas.initialize(size.width, size.height, true))
250 return false;
251
252 view->paint(webkit_glue::ToWebCanvas(&canvas),
253 WebRect(0, 0, size.width, size.height));
254 // TODO: Add a way to snapshot the whole page, not just the currently
255 // visible part.
256
257 return true;
258}
259
260// Calculates how "boring" a thumbnail is. The boring score is the
261// 0,1 ranged percentage of pixels that are the most common
262// luma. Higher boring scores indicate that a higher percentage of a
263// bitmap are all the same brightness.
264static double CalculateBoringScore(SkBitmap* bitmap) {
265 int histogram[256] = {0};
266 color_utils::BuildLumaHistogram(bitmap, histogram);
267
268 int color_count = *std::max_element(histogram, histogram + 256);
269 int pixel_count = bitmap->width() * bitmap->height();
270 return static_cast<double>(color_count) / pixel_count;
271}
272
initial.commit09911bf2008-07-26 23:55:29273///////////////////////////////////////////////////////////////////////////////
274
[email protected]60c42a8c72009-10-09 04:08:59275int32 RenderView::next_page_id_ = 1;
276
[email protected]2fab253a2009-08-17 23:00:59277RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34278 const WebPreferences& webkit_preferences,
279 int64 session_storage_namespace_id)
[email protected]81a34412009-01-05 19:17:24280 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09281 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21282 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24283 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21284 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24285 page_id_(-1),
286 last_page_id_sent_to_browser_(-1),
287 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24288 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46289 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50290 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11291 devtools_agent_(NULL),
292 devtools_client_(NULL),
[email protected]a1128322009-10-06 18:38:46293 file_chooser_completion_(NULL),
[email protected]81a34412009-01-05 19:17:24294 history_back_list_count_(0),
295 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24296 has_unload_listener_(false),
297 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a12009-10-16 03:53:39298 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24299 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26300 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31301 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25302 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26303 ALLOW_THIS_IN_INITIALIZER_LIST(
304 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53305 view_type_(ViewType::INVALID),
306 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55307 last_top_level_navigation_page_id_(-1),
308#if defined(OS_MACOSX)
309 has_document_tag_(false),
310#endif
[email protected]98324892009-09-09 21:16:05311 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32312 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34313 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]0bedb8a2010-01-14 19:36:32314 ALLOW_THIS_IN_INITIALIZER_LIST(text_translator_(this)) {
315 page_translator_.reset(new PageTranslator(&text_translator_));
initial.commit09911bf2008-07-26 23:55:29316}
317
318RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08319 if (decrement_shared_popup_at_destruction_)
320 shared_popup_counter_->data--;
321
[email protected]b0950a72009-09-29 23:16:17322 // Dispose of un-disposed image fetchers.
323 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
324 i != image_fetchers_.end(); ++i) {
325 delete *i;
326 }
327
[email protected]a1128322009-10-06 18:38:46328 // If file chooser is still waiting for answer, dispatch empty answer.
329 if (file_chooser_completion_)
330 file_chooser_completion_->didChooseFile(WebVector<WebString>());
331
[email protected]83dde542009-09-11 20:59:55332#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05333 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55334 if (has_document_tag_)
335 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
336#endif
[email protected]98324892009-09-09 21:16:05337
[email protected]5fb88962009-04-16 19:03:25338 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59339
340#ifndef NDEBUG
341 // Make sure we are no longer referenced by the ViewMap.
342 ViewMap* views = Singleton<ViewMap>::get();
343 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
344 DCHECK_NE(this, it->second) << "Failed to call Close?";
345#endif
346}
347
348/*static*/
349void RenderView::ForEach(RenderViewVisitor* visitor) {
350 ViewMap* views = Singleton<ViewMap>::get();
351 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
352 if (!visitor->Visit(it->second))
353 return;
354 }
355}
356
357/*static*/
358RenderView* RenderView::FromWebView(WebView* webview) {
359 ViewMap* views = Singleton<ViewMap>::get();
360 ViewMap::iterator it = views->find(webview);
361 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29362}
363
364/*static*/
[email protected]0aa55312008-10-17 21:53:08365RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24366 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15367 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08368 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51369 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08370 const WebPreferences& webkit_prefs,
371 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34372 int32 routing_id,
373 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29374 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34375 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
376 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29377 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29378 opener_id,
[email protected]80d96fa2009-06-10 22:34:51379 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08380 counter,
initial.commit09911bf2008-07-26 23:55:29381 routing_id); // adds reference
382 return view;
383}
384
385/*static*/
386void RenderView::SetNextPageID(int32 next_page_id) {
387 // This method should only be called during process startup, and the given
388 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05389 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29390 DCHECK(next_page_id >= next_page_id_);
391 next_page_id_ = next_page_id;
392}
393
[email protected]afe3a1672009-11-17 19:04:12394void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56395 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
396}
397
[email protected]a3a8fb6d2009-10-22 20:12:51398void RenderView::PluginCrashed(const FilePath& plugin_path) {
399 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29400}
401
[email protected]18bcc3c2009-01-27 21:39:15402void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29403 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51404 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08405 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29406 int32 routing_id) {
407 DCHECK(!webview());
408
409 if (opener_id != MSG_ROUTING_NONE)
410 opener_id_ = opener_id;
411
[email protected]0aa55312008-10-17 21:53:08412 if (counter) {
413 shared_popup_counter_ = counter;
414 shared_popup_counter_->data++;
415 decrement_shared_popup_at_destruction_ = true;
416 } else {
417 shared_popup_counter_ = new SharedRenderViewCounter(0);
418 decrement_shared_popup_at_destruction_ = false;
419 }
420
[email protected]58bfc6b2009-06-24 09:45:02421 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04422
[email protected]50ae00ef2009-10-19 05:11:03423 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59424 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59425 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27426 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29427 webview()->setDevToolsAgent(
428 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29429
[email protected]d3ba77272009-09-03 00:06:09430 OnSetRendererPrefs(renderer_prefs);
431
initial.commit09911bf2008-07-26 23:55:29432 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24433 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29434 // Take a reference on behalf of the RenderThread. This will be balanced
435 // when we receive ViewMsg_Close.
436 AddRef();
437
438 // If this is a popup, we must wait for the CreatingNew_ACK message before
439 // completing initialization. Otherwise, we can finish it now.
440 if (opener_id == MSG_ROUTING_NONE) {
441 did_show_ = true;
442 CompleteInit(parent_hwnd);
443 }
444
445 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29446
[email protected]58bfc6b2009-06-24 09:45:02447 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09448 if (command_line.HasSwitch(switches::kDomAutomationController))
449 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29450
[email protected]5fb88962009-04-16 19:03:25451 audio_message_filter_ = new AudioMessageFilter(routing_id_);
452 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29453}
454
455void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27456 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27457 if (main_frame)
458 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26459
[email protected]b2abac72009-02-26 12:39:28460 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11461 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28462 return;
[email protected]b4b967e2009-04-22 11:33:05463 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
464 return;
[email protected]b6849bda2009-10-14 23:59:26465 if (notification_provider_->OnMessageReceived(message))
466 return;
[email protected]b2abac72009-02-26 12:39:28467
initial.commit09911bf2008-07-26 23:55:29468 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29469 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23470 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29471 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01472 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29473 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
474 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56475 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29476 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
477 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
478 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
479 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
480 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
481 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27482#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35483 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27484#endif
initial.commit09911bf2008-07-26 23:55:29485 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
486 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05487 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
488 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
489 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04490 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29491 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
492 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
493 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15494 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29495 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]630e26b2008-10-14 22:55:17496 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]40bd6582009-12-04 23:49:51497 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
498 OnSetZoomLevelForLoadingHost)
initial.commit09911bf2008-07-26 23:55:29499 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18500 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
501 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28502 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33503 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29504 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48505 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29506 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29507 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29508 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
509 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
510 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
511 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
512 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
513 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45514 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29515 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50516 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
517 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29518 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
519 OnDragSourceSystemDragEnded)
520 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
521 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
522 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
523 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
524 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
525 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
526 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
527 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
528 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
529 OnUpdateBackForwardListCount)
530 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
531 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04532 IPC_MESSAGE_HANDLER(
533 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
534 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29535 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50536 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
537 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
538 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29539 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
540 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
541 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45542 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
543 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08544 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
545 OnDisassociateFromPopupCount)
[email protected]842936a2009-10-14 06:00:36546 IPC_MESSAGE_HANDLER(ViewMsg_QueryFormFieldAutofill_ACK,
547 OnQueryFormFieldAutofillAck)
[email protected]2c4410d2009-05-06 23:46:22548 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
549 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00550 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27551 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37552 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
553 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16554 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14555 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25556 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
557 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:51558 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53559 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
560 OnUpdateBrowserWindowId)
561 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
562 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56563 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34564 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]446705872009-09-10 07:22:48565 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33566 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35567 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
568 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33569 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
570 OnCustomContextMenuAction)
[email protected]0bedb8a2010-01-14 19:36:32571 IPC_MESSAGE_HANDLER(ViewMsg_TranslateTextReponse, OnTranslateTextResponse)
[email protected]634a6f92008-12-01 21:39:31572
initial.commit09911bf2008-07-26 23:55:29573 // Have the super handle all other messages.
574 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
575 IPC_END_MESSAGE_MAP()
576}
577
initial.commit09911bf2008-07-26 23:55:29578void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27579 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29580 if (!main_frame)
581 return;
582
583 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45584 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29585 if (url.is_empty())
586 return;
587
588 if (size_.IsEmpty())
589 return; // Don't create an empty thumbnail!
590
591 ThumbnailScore score;
592 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02593 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15594 &thumbnail, &score))
595 return;
596
initial.commit09911bf2008-07-26 23:55:29597 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46598 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29599}
600
[email protected]30507922010-01-15 16:48:23601void RenderView::SendSnapshot() {
602 SkBitmap snapshot;
603 bool error = false;
604
605 WebFrame* main_frame = webview()->mainFrame();
606 if (!main_frame)
607 error = true;
608
609 if (!error && !CaptureSnapshot(webview(), &snapshot))
610 error = true;
611
612 DCHECK(error == snapshot.empty()) <<
613 "Snapshot should be empty on error, non-empty otherwise.";
614
615 // Send the snapshot to the browser process.
616 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
617}
618
[email protected]068637222009-01-29 16:58:07619void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29620 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58621 if (webview()) {
622 // If the user has selected text in the currently focused frame we print
623 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27624 if (webview()->focusedFrame()->hasSelection())
625 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58626 else
[email protected]26aa0482009-09-30 16:55:27627 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58628 }
initial.commit09911bf2008-07-26 23:55:29629}
630
[email protected]82270452009-06-19 15:58:01631void RenderView::OnPrintingDone(int document_cookie, bool success) {
632 // Ignoring document cookie here since only one print job can be outstanding
633 // per renderer and document_cookie is 0 when printing is successful.
634 DCHECK(print_helper_.get());
635 if (print_helper_.get() != NULL) {
636 print_helper_->DidFinishPrinting(success);
637 }
638}
639
initial.commit09911bf2008-07-26 23:55:29640void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
641 if (load_id != page_id_)
642 return; // this capture call is no longer relevant due to navigation
643 if (load_id == last_indexed_page_id_)
644 return; // we already indexed this page
645
646 if (!webview())
647 return;
648
[email protected]26aa0482009-09-30 16:55:27649 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29650 if (!main_frame)
651 return;
652
653 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45654 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29655 return;
656
657 // Don't index/capture pages that failed to load. This only checks the top
658 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45659 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28660 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29661 return;
662
663 if (!preliminary_capture)
664 last_indexed_page_id_ = load_id;
665
[email protected]a8a81292010-01-21 00:32:45666 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45667 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29668 if (url.is_empty())
669 return;
670
[email protected]a8a81292010-01-21 00:32:45671 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29672 std::wstring contents;
673 CaptureText(main_frame, &contents);
674 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45675 base::TimeTicks begin_time = base::TimeTicks::Now();
676 std::string language = DetermineTextLanguage(contents);
677 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
678 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52679
[email protected]a8a81292010-01-21 00:32:45680 // Send the text to the browser for indexing (the browser might decide not
681 // to index, if the URL is HTTPS for instance) and language discovery.
682 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
683 language));
[email protected]5c4266922009-07-10 16:41:27684 }
685
initial.commit09911bf2008-07-26 23:55:29686 // thumbnail
687 SendThumbnail();
688}
689
690void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
691 contents->clear();
692 if (!frame)
693 return;
694
695#ifdef TIME_TEXT_RETRIEVAL
696 double begin = time_util::GetHighResolutionTimeNow();
697#endif
698
699 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45700 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29701
702#ifdef TIME_TEXT_RETRIEVAL
703 double end = time_util::GetHighResolutionTimeNow();
704 char buf[128];
705 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
706 contents.size(), (end - begin)*1000);
707 OutputDebugStringA(buf);
708#endif
709
710 // When the contents are clipped to the maximum, we don't want to have a
711 // partial word indexed at the end that might have been clipped. Therefore,
712 // terminate the string at the last space to ensure no words are clipped.
713 if (contents->size() == kMaxIndexChars) {
714 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
715 if (last_space_index == std::wstring::npos)
716 return; // don't index if we got a huge block of text with no spaces
717 contents->resize(last_space_index);
718 }
719}
720
[email protected]8649fb32009-06-26 17:51:02721bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29722 int w,
723 int h,
724 SkBitmap* thumbnail,
725 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23726 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15727
[email protected]8649fb32009-06-26 17:51:02728 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23729
730 // Paint |view| into |canvas|.
731 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02732 return false;
[email protected]8649fb32009-06-26 17:51:02733
734 skia::BitmapPlatformDevice& device =
735 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
736
737 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29738
[email protected]cab34d6a2009-09-24 01:14:52739 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29740 float dest_aspect = dest_rect.width() / dest_rect.height();
741
742 // Get the src rect so that we can preserve the aspect ratio while filling
743 // the destination.
744 SkIRect src_rect;
745 if (src_bmp.width() < dest_rect.width() ||
746 src_bmp.height() < dest_rect.height()) {
747 // Source image is smaller: we clip the part of source image within the
748 // dest rect, and then stretch it to fill the dest rect. We don't respect
749 // the aspect ratio in this case.
750 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
751 static_cast<S16CPU>(dest_rect.height()));
752 score->good_clipping = false;
753 } else {
754 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
755 if (src_aspect > dest_aspect) {
756 // Wider than tall, clip horizontally: we center the smaller thumbnail in
757 // the wider screen.
758 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
759 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
760 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
761 score->good_clipping = false;
762 } else {
763 src_rect.set(0, 0, src_bmp.width(),
764 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
765 score->good_clipping = true;
766 }
767 }
768
[email protected]26aa0482009-09-30 16:55:27769 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29770
771 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02772 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29773
774 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14775 *thumbnail = skia::ImageOperations::Resize(
776 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29777
778 score->boring_score = CalculateBoringScore(thumbnail);
779
[email protected]30507922010-01-15 16:48:23780 HISTOGRAM_TIMES("Renderer4.Thumbnail",
781 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15782 return true;
initial.commit09911bf2008-07-26 23:55:29783}
784
[email protected]30507922010-01-15 16:48:23785bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
786 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29787
[email protected]30507922010-01-15 16:48:23788 skia::PlatformCanvas canvas;
789 if (!PaintViewIntoCanvas(view, canvas))
790 return false;
791
792 skia::BitmapPlatformDevice& device =
793 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
794
795 const SkBitmap& bitmap = device.accessBitmap(false);
796 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
797 return false;
798
799 HISTOGRAM_TIMES("Renderer4.Snapshot",
800 base::TimeTicks::Now() - beginning_time);
801 return true;
initial.commit09911bf2008-07-26 23:55:29802}
803
804void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
805 if (!webview())
806 return;
807
[email protected]8c785c62009-07-13 14:20:15808 if (devtools_agent_.get())
809 devtools_agent_->OnNavigate();
810
[email protected]422197532010-01-25 17:38:23811 if (notification_provider_.get())
812 notification_provider_->OnNavigate();
813
[email protected]a9f607e2009-10-23 19:59:27814 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26815
initial.commit09911bf2008-07-26 23:55:29816 AboutHandler::MaybeHandle(params.url);
817
[email protected]5e369672009-11-03 23:48:30818 bool is_reload = (params.navigation_type == ViewMsg_Navigate_Params::RELOAD);
initial.commit09911bf2008-07-26 23:55:29819
[email protected]26aa0482009-09-30 16:55:27820 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45821 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29822 // We cannot reload if we do not have any history state. This happens, for
823 // example, when recovering from a crash. Our workaround here is a bit of
824 // a hack since it means that reload after a crashed tab does not cause an
825 // end-to-end cache validation.
826 is_reload = false;
827 }
828
[email protected]77f17a82009-05-21 04:42:54829 // A navigation resulting from loading a javascript URL should not be treated
830 // as a browser initiated event. Instead, we want it to look as if the page
831 // initiated any load resulting from JS execution.
832 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30833 NavigationState* state = NavigationState::CreateBrowserInitiated(
834 params.page_id, params.transition, params.request_time);
835 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
836 // We're doing a load of a page that was restored from the last session.
837 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
838 // which can result in stale data for pages that are set to expire. We
839 // explicitly override that by setting the policy here so that as
840 // necessary we load from the network.
841 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
842 }
843 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54844 }
initial.commit09911bf2008-07-26 23:55:29845
[email protected]a7ccc4d2010-01-27 08:14:48846 NavigationState* navigation_state = pending_navigation_state_.get();
847
[email protected]04d3c6e2009-05-22 17:00:13848 // If we are reloading, then WebKit will use the history state of the current
849 // page, so we should just ignore any given history state. Otherwise, if we
850 // have history state, then we need to navigate to it, which corresponds to a
851 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55852 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48853 if (navigation_state)
854 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]dd7daa82009-08-10 05:46:45855 main_frame->reload();
[email protected]e6f546c32009-07-01 17:12:55856 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13857 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58858 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48859 if (navigation_state)
860 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45861 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17862 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13863 } else {
864 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28865 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29866
[email protected]e6f546c32009-07-01 17:12:55867 // A session history navigation should have been accompanied by state.
868 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13869
[email protected]dd7daa82009-08-10 05:46:45870 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55871 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13872
[email protected]726985e22009-06-18 21:09:28873 if (params.referrer.is_valid()) {
874 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
875 WebString::fromUTF8(params.referrer.spec()));
876 }
[email protected]04d3c6e2009-05-22 17:00:13877
[email protected]a7ccc4d2010-01-27 08:14:48878 if (navigation_state)
879 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45880 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50881 }
882
[email protected]77f17a82009-05-21 04:42:54883 // In case LoadRequest failed before DidCreateDataSource was called.
884 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29885}
886
887// Stop loading the current page
888void RenderView::OnStop() {
889 if (webview())
[email protected]b4bb2502009-10-01 22:35:27890 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29891}
892
[email protected]1dda4022010-01-28 18:24:56893// Reload current focused frame
894void RenderView::OnReloadFrame() {
895 if (webview() && webview()->focusedFrame())
896 webview()->focusedFrame()->reload();
897}
898
[email protected]e6f546c32009-07-01 17:12:55899void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29900 bool new_navigation,
901 const GURL& display_url,
902 const std::string& security_info) {
903 if (!webview())
904 return;
905
[email protected]e6f546c32009-07-01 17:12:55906 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
907 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
908 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29909
[email protected]26aa0482009-09-30 16:55:27910 webview()->mainFrame()->loadHTMLString(
911 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55912
913 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29914}
915
916void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27917 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29918}
919
[email protected]68b1e922009-06-23 16:00:25920void RenderView::OnExecuteEditCommand(const std::string& name,
921 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27922 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25923 return;
924
[email protected]26aa0482009-09-30 16:55:27925 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45926 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25927}
928
[email protected]b2abac72009-02-26 12:39:28929void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11930 DCHECK(!devtools_client_.get());
931 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28932}
933
initial.commit09911bf2008-07-26 23:55:29934void RenderView::OnStopFinding(bool clear_selection) {
935 WebView* view = webview();
936 if (!view)
937 return;
938
939 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27940 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29941
[email protected]26aa0482009-09-30 16:55:27942 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29943 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45944 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:27945 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:29946 }
947}
948
949void RenderView::OnFindReplyAck() {
950 // Check if there is any queued up request waiting to be sent.
951 if (queued_find_reply_message_.get()) {
952 // Send the search result over to the browser process.
953 Send(queued_find_reply_message_.get());
954 queued_find_reply_message_.release();
955 }
956}
957
958void RenderView::OnUpdateTargetURLAck() {
959 // Check if there is a targeturl waiting to be sent.
960 if (target_url_status_ == TARGET_PENDING) {
961 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
962 pending_target_url_));
963 }
964
965 target_url_status_ = TARGET_NONE;
966}
967
968void RenderView::OnUndo() {
969 if (!webview())
970 return;
971
[email protected]26aa0482009-09-30 16:55:27972 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:12973 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:29974}
975
976void RenderView::OnRedo() {
977 if (!webview())
978 return;
979
[email protected]26aa0482009-09-30 16:55:27980 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:12981 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:29982}
983
984void RenderView::OnCut() {
985 if (!webview())
986 return;
987
[email protected]26aa0482009-09-30 16:55:27988 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:12989 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:29990}
991
992void RenderView::OnCopy() {
993 if (!webview())
994 return;
995
[email protected]26aa0482009-09-30 16:55:27996 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:12997 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:29998}
999
[email protected]c0cc3092009-09-12 08:27:271000#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351001void RenderView::OnCopyToFindPboard() {
1002 if (!webview())
1003 return;
1004
1005 // Since the find pasteboard supports only plain text, this can be simpler
1006 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271007 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351008 if (frame->hasSelection()) {
1009 string16 selection = frame->selectionAsText();
1010 RenderThread::current()->Send(
1011 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1012 }
1013
[email protected]afe3a1672009-11-17 19:04:121014 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351015}
[email protected]c0cc3092009-09-12 08:27:271016#endif
[email protected]a954bf72009-09-12 07:30:351017
initial.commit09911bf2008-07-26 23:55:291018void RenderView::OnPaste() {
1019 if (!webview())
1020 return;
1021
[email protected]26aa0482009-09-30 16:55:271022 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121023 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291024}
1025
[email protected]2a3a7762009-10-19 19:17:321026void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291027 if (!webview())
1028 return;
1029
[email protected]2a3a7762009-10-19 19:17:321030 webview()->focusedFrame()->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291031}
1032
[email protected]98324892009-09-09 21:16:051033void RenderView::OnAdvanceToNextMisspelling() {
1034 if (!webview())
1035 return;
[email protected]26aa0482009-09-30 16:55:271036 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051037 WebString::fromUTF8("AdvanceToNextMisspelling"));
1038}
1039
1040void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1041 if (!webview())
1042 return;
1043 // We need to tell the webView whether the spelling panel is visible or not so
1044 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261045 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271046 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051047 WebString::fromUTF8("ToggleSpellPanel"));
1048}
1049
[email protected]bbbd545c2008-12-15 20:18:041050void RenderView::OnToggleSpellCheck() {
1051 if (!webview())
1052 return;
1053
[email protected]26aa0482009-09-30 16:55:271054 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451055 frame->enableContinuousSpellChecking(
1056 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041057}
1058
initial.commit09911bf2008-07-26 23:55:291059void RenderView::OnDelete() {
1060 if (!webview())
1061 return;
1062
[email protected]26aa0482009-09-30 16:55:271063 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121064 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291065}
1066
1067void RenderView::OnSelectAll() {
1068 if (!webview())
1069 return;
1070
[email protected]26aa0482009-09-30 16:55:271071 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221072 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121073 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291074}
1075
1076void RenderView::OnSetInitialFocus(bool reverse) {
1077 if (!webview())
1078 return;
[email protected]26aa0482009-09-30 16:55:271079 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291080}
1081
1082///////////////////////////////////////////////////////////////////////////////
1083
1084// Tell the embedding application that the URL of the active page has changed
1085void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451086 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291087 DCHECK(ds);
1088
[email protected]726985e22009-06-18 21:09:281089 const WebURLRequest& request = ds->request();
1090 const WebURLRequest& original_request = ds->originalRequest();
1091 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291092
[email protected]daa8c58e2009-06-15 17:21:101093 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1094 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291095
1096 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281097 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291098 params.is_post = false;
1099 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281100 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551101 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291102 // SSL state specified in the request takes precedence over the one in the
1103 // response.
1104 // So far this is only intended for error pages that are not expected to be
1105 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281106 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551107 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291108 } else {
[email protected]726985e22009-06-18 21:09:281109 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291110 }
1111
1112 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281113 if (ds->hasUnreachableURL()) {
1114 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291115 } else {
[email protected]726985e22009-06-18 21:09:281116 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291117 }
1118
[email protected]726985e22009-06-18 21:09:281119 GetRedirectChain(ds, &params.redirects);
1120 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:291121
[email protected]ce0e250d2009-10-23 21:00:351122 params.searchable_form_url = navigation_state->searchable_form_url();
1123 params.searchable_form_encoding =
1124 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291125
1126 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101127 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291128 if (password_form_data)
1129 params.password_form = *password_form_data;
1130
1131 params.gesture = navigation_gesture_;
1132 navigation_gesture_ = NavigationGestureUnknown;
1133
[email protected]dd7daa82009-08-10 05:46:451134 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291135 // Top-level navigation.
1136
[email protected]40bd6582009-12-04 23:49:511137 // Set zoom level.
1138 HostZoomLevels::iterator host =
1139 host_zoom_levels_.find(GURL(request.url()).host());
1140 if (host != host_zoom_levels_.end()) {
1141 webview()->setZoomLevel(false, host->second);
1142 // This zoom level was merely recorded transiently for this load. We can
1143 // erase it now. If at some point we reload this page, the browser will
1144 // send us a new, up-to-date zoom level.
1145 host_zoom_levels_.erase(host);
1146 }
1147
initial.commit09911bf2008-07-26 23:55:291148 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551149 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291150
[email protected]daa8c58e2009-06-15 17:21:101151 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291152 if (!PageTransition::IsMainFrame(params.transition)) {
1153 // If the main frame does a load, it should not be reported as a subframe
1154 // navigation. This can occur in the following case:
1155 // 1. You're on a site with frames.
1156 // 2. You do a subframe navigation. This is stored with transition type
1157 // MANUAL_SUBFRAME.
1158 // 3. You navigate to some non-frame site, say, google.com.
1159 // 4. You navigate back to the page from step 2. Since it was initially
1160 // MANUAL_SUBFRAME, it will be that same transition type here.
1161 // We don't want that, because any navigation that changes the toplevel
1162 // frame should be tracked as a toplevel navigation (this allows us to
1163 // update the URL bar, etc).
1164 params.transition = PageTransition::LINK;
1165 }
1166
initial.commit09911bf2008-07-26 23:55:291167 // If we have a valid consumed client redirect source,
1168 // the page contained a client redirect (meta refresh, document.loc...),
1169 // so we set the referrer and transition to match.
1170 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041171 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291172 params.referrer = completed_client_redirect_src_;
1173 params.transition = static_cast<PageTransition::Type>(
1174 params.transition | PageTransition::CLIENT_REDIRECT);
1175 } else {
1176 // Bug 654101: the referrer will be empty on https->http transitions. It
1177 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281178 params.referrer = GURL(
1179 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291180 }
1181
[email protected]726985e22009-06-18 21:09:281182 string16 method = request.httpMethod();
1183 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291184 params.is_post = true;
1185
[email protected]c2a797d2009-09-21 16:46:321186 // Save some histogram data so we can compute the average memory used per
1187 // page load of the glyphs.
1188 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1189 webkit_glue::GetGlyphPageCount());
1190
initial.commit09911bf2008-07-26 23:55:291191 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1192 } else {
1193 // Subframe navigation: the type depends on whether this navigation
1194 // generated a new session history entry. When they do generate a session
1195 // history entry, it means the user initiated the navigation and we should
1196 // mark it as such. This test checks if this is the first time UpdateURL
1197 // has been called since WillNavigateToURL was called to initiate the load.
1198 if (page_id_ > last_page_id_sent_to_browser_)
1199 params.transition = PageTransition::MANUAL_SUBFRAME;
1200 else
1201 params.transition = PageTransition::AUTO_SUBFRAME;
1202
initial.commit09911bf2008-07-26 23:55:291203 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1204 }
1205
1206 last_page_id_sent_to_browser_ =
1207 std::max(last_page_id_sent_to_browser_, page_id_);
1208
1209 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101210 // we don't want the transition type to persist. Just clear it.
1211 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501212
[email protected]6c8afae52009-01-22 02:24:571213#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151214 if (accessibility_.get()) {
[email protected]be645db2009-02-06 20:36:331215 // Clear accessibility info cache.
[email protected]c7287a92009-11-04 20:06:151216 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:501217 }
[email protected]6c8afae52009-01-22 02:24:571218#else
[email protected]7d926f92009-03-03 14:26:541219 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571220#endif
initial.commit09911bf2008-07-26 23:55:291221}
1222
1223// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171224void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291225 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171226 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171227 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171228 routing_id_,
1229 page_id_,
1230 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1231 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171232 }
initial.commit09911bf2008-07-26 23:55:291233}
1234
1235void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401236 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291237 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271238 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291239 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301240 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291241 last_encoding_name_ = encoding_name;
1242
[email protected]e38f40152008-09-12 23:08:301243 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291244 }
1245}
1246
[email protected]f4d34b52008-11-24 23:05:011247// Sends the previous session history state to the browser so it will be saved
1248// before we navigate to a new page. This must be called *before* the page ID
1249// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291250void RenderView::UpdateSessionHistory(WebFrame* frame) {
1251 // If we have a valid page ID at this point, then it corresponds to the page
1252 // we are navigating away from. Otherwise, this is the first navigation, so
1253 // there is no past session history to record.
1254 if (page_id_ == -1)
1255 return;
1256
[email protected]ca948a22009-06-25 19:36:171257 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271258 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171259 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291260 return;
[email protected]ca948a22009-06-25 19:36:171261
1262 Send(new ViewHostMsg_UpdateState(
1263 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291264}
1265
[email protected]3d9689372009-09-10 04:29:171266void RenderView::OpenURL(
1267 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1268 Send(new ViewHostMsg_OpenURL(
1269 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1270}
1271
[email protected]79dbc662009-09-04 05:42:511272// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291273
[email protected]a2f6bc112009-06-27 16:27:251274void RenderView::DidPaint() {
[email protected]26aa0482009-09-30 16:55:271275 WebFrame* main_frame = webview()->mainFrame();
[email protected]a2f6bc112009-06-27 16:27:251276
[email protected]dd7daa82009-08-10 05:46:451277 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251278 // If we have a provisional frame we are between the start
1279 // and commit stages of loading...ignore this paint.
1280 return;
1281 }
1282
[email protected]dd7daa82009-08-10 05:46:451283 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251284 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011285 DCHECK(navigation_state);
1286
1287 Time now = Time::Now();
1288 if (navigation_state->first_paint_time().is_null()) {
1289 navigation_state->set_first_paint_time(now);
1290 }
1291 if (navigation_state->first_paint_after_load_time().is_null() &&
1292 !navigation_state->finish_load_time().is_null()) {
1293 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251294 }
1295}
1296
initial.commit09911bf2008-07-26 23:55:291297void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281298 const WebURLRequest& failed_request,
1299 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291300 const std::string& html,
1301 bool replace) {
[email protected]726985e22009-06-18 21:09:281302 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291303
1304 std::string alt_html;
1305 if (html.empty()) {
1306 // Use a local error page.
1307 int resource_id;
1308 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281309 if (error.reason == net::ERR_CACHE_MISS &&
1310 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291311 GetFormRepostErrorValues(failed_url, &error_strings);
1312 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1313 } else {
1314 GetLocalizedErrorValues(error, &error_strings);
1315 resource_id = IDR_NET_ERROR_HTML;
1316 }
[email protected]8e50b602009-03-03 22:59:431317 error_strings.SetString(L"textdirection",
1318 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1319 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291320
1321 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1322 } else {
1323 alt_html = html;
1324 }
1325
[email protected]dd7daa82009-08-10 05:46:451326 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551327 GURL(kUnreachableWebDataURL),
1328 failed_url,
1329 replace);
initial.commit09911bf2008-07-26 23:55:291330}
1331
[email protected]7ccddb8c2009-08-04 17:36:551332void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291333 dom_automation_controller_.set_message_sender(this);
1334 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551335 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291336 L"domAutomationController");
1337}
1338
initial.commit09911bf2008-07-26 23:55:291339bool RenderView::RunJavaScriptMessage(int type,
1340 const std::wstring& message,
1341 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071342 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291343 std::wstring* result) {
1344 bool success = false;
1345 std::wstring result_temp;
1346 if (!result)
1347 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291348
[email protected]12636df2009-09-28 22:32:211349 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1350 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291351 return success;
1352}
1353
1354void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1355 if (!osd_url.is_empty())
1356 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1357 autodetected));
1358}
1359
[email protected]842936a2009-10-14 06:00:361360void RenderView::OnQueryFormFieldAutofillAck(
[email protected]acca2a12009-10-16 03:53:391361 int query_id,
1362 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031363 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181364 if (webview() && query_id == autofill_query_id_) {
[email protected]acca2a12009-10-16 03:53:391365 webview()->applyAutofillSuggestions(
1366 autofill_query_node_, suggestions, default_suggestion_index);
1367 }
1368 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031369}
1370
[email protected]2c4410d2009-05-06 23:46:221371void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311372 popup_notification_visible_ = visible;
1373}
1374
initial.commit09911bf2008-07-26 23:55:291375uint32 RenderView::GetCPBrowsingContext() {
1376 uint32 context = 0;
1377 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1378 return context;
1379}
1380
initial.commit09911bf2008-07-26 23:55:291381void RenderView::AddSearchProvider(const std::string& url) {
1382 AddGURLSearchProvider(GURL(url),
1383 false); // not autodetected
1384}
1385
[email protected]f103ab72009-09-02 17:10:591386void RenderView::OnMissingPluginStatus(
1387 WebPluginDelegateProxy* delegate,
1388 int status) {
[email protected]6c8afae52009-01-22 02:24:571389#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591390 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291391 // Show the InfoBar for the first available plugin.
1392 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591393 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291394 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1395 }
1396 } else {
1397 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1398 // to start the download/install.
1399 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1400 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1401 }
1402 }
[email protected]6c8afae52009-01-22 02:24:571403#else
1404 // TODO(port): plugins current not supported
1405 NOTIMPLEMENTED();
1406#endif
initial.commit09911bf2008-07-26 23:55:291407}
1408
[email protected]48c9cf2d2009-09-16 16:47:521409// WebKit::WebViewClient ------------------------------------------------------
1410
1411WebView* RenderView::createView(WebFrame* creator) {
1412 // Check to make sure we aren't overloading on popups.
1413 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1414 return NULL;
1415
1416 // This window can't be closed from a window.close() call until we receive a
1417 // message from the Browser process explicitly allowing it.
1418 popup_notification_visible_ = true;
1419
1420 int32 routing_id = MSG_ROUTING_NONE;
1421 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461422 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341423 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521424
[email protected]48c9cf2d2009-09-16 16:47:521425 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341426 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1427 session_storage_namespace_id_,
1428 &routing_id,
1429 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211430 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521431 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521432
[email protected]48c9cf2d2009-09-16 16:47:521433 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421434 0,
[email protected]12636df2009-09-28 22:32:211435 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521436 renderer_preferences_,
1437 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211438 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341439 routing_id,
1440 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521441 view->opened_by_user_gesture_ = user_gesture;
1442
[email protected]007a848b2009-10-26 15:55:461443 // Record whether the creator frame is trying to suppress the opener field.
1444 view->opener_suppressed_ = opener_suppressed;
1445
[email protected]48c9cf2d2009-09-16 16:47:521446 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091447 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521448 if (!creator_url.is_valid() || !creator_url.IsStandard())
1449 creator_url = GURL();
1450 view->creator_url_ = creator_url;
1451
1452 // Copy over the alternate error page URL so we can have alt error pages in
1453 // the new render view (we don't need the browser to send the URL back down).
1454 view->alternate_error_page_url_ = alternate_error_page_url_;
1455
1456 return view->webview();
1457}
1458
1459WebWidget* RenderView::createPopupMenu(bool activatable) {
1460 RenderWidget* widget = RenderWidget::Create(routing_id_,
1461 render_thread_,
1462 activatable);
1463 return widget->webwidget();
1464}
1465
1466WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1467 RenderWidget* widget = RenderWidget::Create(routing_id_,
1468 render_thread_,
1469 true);
1470 widget->ConfigureAsExternalPopupMenu(info);
1471 return widget->webwidget();
1472}
1473
[email protected]bd92c3a2010-01-13 05:02:341474WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1475 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1476 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291477 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1478 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1479 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341480}
1481
[email protected]48c9cf2d2009-09-16 16:47:521482void RenderView::didAddMessageToConsole(
1483 const WebConsoleMessage& message, const WebString& source_name,
1484 unsigned source_line) {
1485 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1486 UTF16ToWideHack(message.text),
1487 static_cast<int32>(source_line),
1488 UTF16ToWideHack(source_name)));
1489}
1490
1491void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581492 DCHECK(frame);
1493 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521494}
1495
1496void RenderView::didStartLoading() {
1497 if (is_loading_) {
1498 DLOG(WARNING) << "didStartLoading called while loading";
1499 return;
1500 }
1501
1502 is_loading_ = true;
1503 // Clear the pointer so that we can assign it only when there is an unknown
1504 // plugin on a page.
1505 first_default_plugin_.reset();
1506
1507 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1508}
1509
1510void RenderView::didStopLoading() {
1511 if (!is_loading_) {
1512 DLOG(WARNING) << "DidStopLoading called while not loading";
1513 return;
1514 }
1515
1516 is_loading_ = false;
1517
1518 // NOTE: For now we're doing the safest thing, and sending out notification
1519 // when done loading. This currently isn't an issue as the favicon is only
1520 // displayed when done loading. Ideally we would send notification when
1521 // finished parsing the head, but webkit doesn't support that yet.
1522 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271523 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521524 if (!favicon_url.is_empty())
1525 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1526
[email protected]26aa0482009-09-30 16:55:271527 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521528 true); // autodetected
1529
1530 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1531
1532 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1533 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1534 false),
1535 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521536}
1537
[email protected]04fc9482009-09-18 22:13:031538bool RenderView::isSelectTrailingWhitespaceEnabled() {
1539#if defined(OS_WIN)
1540 return true;
1541#else
1542 return false;
1543#endif
1544}
1545
1546void RenderView::setInputMethodEnabled(bool enabled) {
1547 // Save the updated IME status and mark the input focus has been updated.
1548 // The IME status is to be sent to a browser process next time when
1549 // the input caret is rendered.
1550 if (!ime_control_busy_) {
1551 ime_control_updated_ = true;
1552 ime_control_new_state_ = enabled;
1553 }
1554}
1555
1556void RenderView::didChangeSelection(bool is_empty_selection) {
1557#if defined(OS_LINUX)
1558 if (!handling_input_event_)
1559 return;
1560 // TODO(estade): investigate incremental updates to the selection so that we
1561 // don't send the entire selection over IPC every time.
1562 if (!is_empty_selection) {
1563 // Sometimes we get repeated didChangeSelection calls from webkit when
1564 // the selection hasn't actually changed. We don't want to report these
1565 // because it will cause us to continually claim the X clipboard.
1566 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271567 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031568 if (this_selection == last_selection_)
1569 return;
1570
1571 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1572 this_selection));
1573 last_selection_ = this_selection;
1574 } else {
1575 last_selection_.clear();
1576 }
1577#endif
1578}
1579
1580void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121581 const std::string& name = UTF16ToUTF8(command_name);
1582 if (StartsWithASCII(name, "Move", true) ||
1583 StartsWithASCII(name, "Insert", true) ||
1584 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031585 return;
1586 UserMetricsRecordAction(name);
1587}
1588
[email protected]b2528b72009-09-24 06:57:101589bool RenderView::handleCurrentKeyboardEvent() {
1590 if (edit_commands_.empty())
1591 return false;
1592
[email protected]26aa0482009-09-30 16:55:271593 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101594 if (!frame)
1595 return false;
1596
1597 EditCommands::iterator it = edit_commands_.begin();
1598 EditCommands::iterator end = edit_commands_.end();
1599
[email protected]507b33ea2009-09-29 03:56:511600 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101601 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331602 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1603 // key (but it's the exception). Once one edit command is not executed, it
1604 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101605 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1606 WebString::fromUTF8(it->value)))
1607 break;
[email protected]507b33ea2009-09-29 03:56:511608 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101609 }
1610
[email protected]507b33ea2009-09-29 03:56:511611 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101612}
1613
[email protected]2a3a7762009-10-19 19:17:321614void RenderView::spellCheck(const WebString& text,
1615 int& misspelled_offset,
1616 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561617 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461618
[email protected]85c55dc2009-11-06 03:05:461619 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171620 RenderThread* thread = RenderThread::current();
1621 // Will be NULL during unit tests.
1622 if (thread) {
[email protected]c27324b2009-11-19 22:44:291623 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171624 word.c_str(), word.size(), document_tag_,
1625 &misspelled_offset, &misspelled_length, NULL);
1626 }
[email protected]1dbafaf72009-09-23 19:43:561627}
1628
1629WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321630 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561631 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261632 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561633 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171634 RenderThread* thread = RenderThread::current();
1635 // Will be NULL during unit tests.
1636 if (thread) {
1637 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291638 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171639 word, document_tag_);
1640 }
[email protected]1dbafaf72009-09-23 19:43:561641 }
[email protected]2a3a7762009-10-19 19:17:321642 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561643}
1644
[email protected]c49085c72009-10-02 16:28:561645void RenderView::showSpellingUI(bool show) {
1646 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1647}
1648
[email protected]8922e1f2009-10-03 05:01:261649bool RenderView::isShowingSpellingUI() {
1650 return spelling_panel_visible_;
1651}
1652
[email protected]1dbafaf72009-09-23 19:43:561653void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321654 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1655 word));
[email protected]1dbafaf72009-09-23 19:43:561656}
1657
[email protected]a1128322009-10-06 18:38:461658bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351659 const WebKit::WebFileChooserParams& params,
[email protected]a1128322009-10-06 18:38:461660 WebKit::WebFileChooserCompletion* chooser_completion) {
1661 if (file_chooser_completion_) {
1662 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1663 // with the fact that web pages can programatically trigger this. With the
1664 // asnychronous messages, we can get an additional call when one is pending,
1665 // which this test is for. For now, we just ignore the additional file
1666 // chooser request. WebKit doesn't do anything to expect the callback, so
1667 // we can just ignore calling it.
1668 return false;
1669 }
1670 file_chooser_completion_ = chooser_completion;
1671 Send(new ViewHostMsg_RunFileChooser(
[email protected]01178b52010-01-15 06:59:351672 routing_id_, params.multiSelect, params.title,
1673 webkit_glue::WebStringToFilePath(params.initialValue)));
[email protected]a1128322009-10-06 18:38:461674 return true;
1675}
1676
[email protected]48c9cf2d2009-09-16 16:47:521677void RenderView::runModalAlertDialog(
1678 WebFrame* frame, const WebString& message) {
1679 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1680 UTF16ToWideHack(message),
1681 std::wstring(),
1682 frame->url(),
1683 NULL);
1684}
1685
1686bool RenderView::runModalConfirmDialog(
1687 WebFrame* frame, const WebString& message) {
1688 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1689 UTF16ToWideHack(message),
1690 std::wstring(),
1691 frame->url(),
1692 NULL);
1693}
1694
1695bool RenderView::runModalPromptDialog(
1696 WebFrame* frame, const WebString& message, const WebString& default_value,
1697 WebString* actual_value) {
1698 std::wstring result;
1699 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1700 UTF16ToWideHack(message),
1701 UTF16ToWideHack(default_value),
1702 frame->url(),
1703 &result);
1704 if (ok)
1705 actual_value->assign(WideToUTF16Hack(result));
1706 return ok;
1707}
1708
1709bool RenderView::runModalBeforeUnloadDialog(
1710 WebFrame* frame, const WebString& message) {
1711 bool success = false;
1712 // This is an ignored return value, but is included so we can accept the same
1713 // response as RunJavaScriptMessage.
1714 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211715 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521716 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211717 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521718 return success;
1719}
1720
[email protected]79e37442009-10-09 18:17:441721void RenderView::showContextMenu(
1722 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291723 ContextMenuParams params = ContextMenuParams(data);
1724 if (!params.misspelled_word.empty() && RenderThread::current()) {
1725 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041726 bool spelled_right = RenderThread::current()->spellchecker()->
1727 SpellCheckWord(
1728 params.misspelled_word.c_str(), params.misspelled_word.size(),
1729 document_tag_,
1730 &misspelled_offset, &misspelled_length,
1731 &params.dictionary_suggestions);
1732 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291733 params.misspelled_word.clear();
1734 }
1735
1736 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441737}
1738
[email protected]48c9cf2d2009-09-16 16:47:521739void RenderView::setStatusText(const WebString& text) {
1740}
1741
[email protected]163f8242009-10-30 20:19:551742void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1743 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521744 if (latest_url == target_url_)
1745 return;
[email protected]163f8242009-10-30 20:19:551746
[email protected]48c9cf2d2009-09-16 16:47:521747 // Tell the browser to display a destination link.
1748 if (target_url_status_ == TARGET_INFLIGHT ||
1749 target_url_status_ == TARGET_PENDING) {
1750 // If we have a request in-flight, save the URL to be sent when we
1751 // receive an ACK to the in-flight request. We can happily overwrite
1752 // any existing pending sends.
1753 pending_target_url_ = latest_url;
1754 target_url_status_ = TARGET_PENDING;
1755 } else {
1756 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1757 target_url_ = latest_url;
1758 target_url_status_ = TARGET_INFLIGHT;
1759 }
1760}
1761
[email protected]882daa92009-11-05 16:31:311762void RenderView::StartNavStateSyncTimerIfNecessary() {
1763 int delay;
1764 if (send_content_state_immediately_)
1765 delay = 0;
1766 else if (is_hidden())
1767 delay = kDelaySecondsForContentStateSyncHidden;
1768 else
1769 delay = kDelaySecondsForContentStateSync;
1770
1771 if (nav_state_sync_timer_.IsRunning()) {
1772 // The timer is already running. If the delay of the timer maches the amount
1773 // we want to delay by, then return. Otherwise stop the timer so that it
1774 // gets started with the right delay.
1775 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1776 return;
1777 nav_state_sync_timer_.Stop();
1778 }
1779
1780 nav_state_sync_timer_.Start(
1781 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1782}
1783
[email protected]163f8242009-10-30 20:19:551784void RenderView::setMouseOverURL(const WebURL& url) {
1785 mouse_over_url_ = GURL(url);
1786 UpdateTargetURL(mouse_over_url_, focus_url_);
1787}
1788
1789void RenderView::setKeyboardFocusURL(const WebURL& url) {
1790 focus_url_ = GURL(url);
1791 UpdateTargetURL(focus_url_, mouse_over_url_);
1792}
1793
[email protected]48c9cf2d2009-09-16 16:47:521794void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1795 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1796 hint));
1797}
1798
1799void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1800 WebDragOperationsMask allowed_ops) {
1801 Send(new ViewHostMsg_StartDragging(routing_id_,
1802 WebDropData(data),
1803 allowed_ops));
1804}
1805
[email protected]28b92df2009-09-25 17:35:451806bool RenderView::acceptsLoadDrops() {
1807 return renderer_preferences_.can_accept_load_drops;
1808}
1809
[email protected]48c9cf2d2009-09-16 16:47:521810void RenderView::focusNext() {
1811 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1812}
1813
1814void RenderView::focusPrevious() {
1815 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1816}
1817
1818void RenderView::navigateBackForwardSoon(int offset) {
1819 history_back_list_count_ += offset;
1820 history_forward_list_count_ -= offset;
1821
1822 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1823}
1824
1825int RenderView::historyBackListCount() {
1826 return history_back_list_count_;
1827}
1828
1829int RenderView::historyForwardListCount() {
1830 return history_forward_list_count_;
1831}
1832
1833void RenderView::didAddHistoryItem() {
1834 // We don't want to update the history length for the start page
1835 // navigation.
[email protected]26aa0482009-09-30 16:55:271836 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521837 DCHECK(main_frame != NULL);
1838
1839 WebDataSource* ds = main_frame->dataSource();
1840 DCHECK(ds != NULL);
1841
1842 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1843 DCHECK(navigation_state);
1844 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1845 return;
1846
1847 history_back_list_count_++;
1848 history_forward_list_count_ = 0;
1849}
1850
[email protected]8922e1f2009-10-03 05:01:261851void RenderView::didUpdateInspectorSettings() {
1852 Send(new ViewHostMsg_UpdateInspectorSettings(
1853 routing_id_, webview()->inspectorSettings().utf8()));
1854}
1855
[email protected]acca2a12009-10-16 03:53:391856void RenderView::queryAutofillSuggestions(const WebNode& node,
1857 const WebString& name,
1858 const WebString& value) {
1859 static int query_counter = 0;
1860 autofill_query_id_ = query_counter++;
1861 autofill_query_node_ = node;
1862 Send(new ViewHostMsg_QueryFormFieldAutofill(
1863 routing_id_, autofill_query_id_, name, value));
1864}
1865
1866void RenderView::removeAutofillSuggestions(const WebString& name,
1867 const WebString& value) {
1868 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1869}
1870
[email protected]79dbc662009-09-04 05:42:511871// WebKit::WebWidgetClient ----------------------------------------------------
1872
initial.commit09911bf2008-07-26 23:55:291873// We are supposed to get a single call to Show for a newly created RenderView
1874// that was created via RenderView::CreateWebView. So, we wait until this
1875// point to dispatch the ShowView message.
1876//
1877// This method provides us with the information about how to display the newly
1878// created RenderView (i.e., as a constrained popup or as a new tab).
1879//
[email protected]4873c7d2009-07-16 06:36:281880void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291881 DCHECK(!did_show_) << "received extraneous Show call";
1882 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1883
1884 if (did_show_)
1885 return;
1886 did_show_ = true;
1887
[email protected]28295ec2009-10-16 05:34:331888 // Force new windows to a popup if they were not opened with a user gesture.
1889 if (!opened_by_user_gesture_) {
1890 // We exempt background tabs for compat with older versions of Chrome.
1891 // TODO(darin): This seems bogus. These should have a user gesture, so
1892 // we probably don't need this check.
1893 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1894 policy = WebKit::WebNavigationPolicyNewPopup;
1895 }
1896
initial.commit09911bf2008-07-26 23:55:291897 // NOTE: initial_pos_ may still have its default values at this point, but
1898 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1899 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281900 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1901 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291902 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241903 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291904}
1905
[email protected]4873c7d2009-07-16 06:36:281906void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:221907 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:281908 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:311909}
1910
[email protected]4873c7d2009-07-16 06:36:281911void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291912 DCHECK(did_show_) << "should already have shown the view";
1913
[email protected]12636df2009-09-28 22:32:211914 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291915}
1916
[email protected]3d9689372009-09-10 04:29:171917// WebKit::WebFrameClient -----------------------------------------------------
1918
1919WebPlugin* RenderView::createPlugin(
1920 WebFrame* frame, const WebPluginParams& params) {
1921 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
1922}
1923
1924WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
1925 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
1926}
1927
[email protected]9c00f002009-11-05 22:37:421928WebSharedWorker* RenderView::createSharedWorker(
1929 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371930 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421931
[email protected]30447b62009-11-13 01:13:371932 int route_id = MSG_ROUTING_NONE;
1933 bool url_mismatch = false;
1934 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]0791d3a2010-01-28 01:28:491935 url, name, document_id, routing_id_, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371936 if (url_mismatch) {
1937 return NULL;
1938 } else {
1939 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:491940 document_id,
[email protected]30447b62009-11-13 01:13:371941 route_id,
1942 routing_id_);
1943 }
[email protected]9c00f002009-11-05 22:37:421944}
1945
[email protected]3d9689372009-09-10 04:29:171946WebMediaPlayer* RenderView::createMediaPlayer(
1947 WebFrame* frame, WebMediaPlayerClient* client) {
1948 scoped_refptr<media::FilterFactoryCollection> factory =
1949 new media::FilterFactoryCollection();
1950 // Add in any custom filter factories first.
1951 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1952 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1953 // Add the chrome specific audio renderer.
1954 factory->AddFactory(
1955 AudioRendererImpl::CreateFactory(audio_message_filter()));
1956 }
1957
[email protected]80f584d92010-01-21 03:59:041958 WebApplicationCacheHostImpl* appcache_host =
1959 WebApplicationCacheHostImpl::FromFrame(frame);
1960
[email protected]3d9689372009-09-10 04:29:171961 // TODO(hclam): obtain the following parameters from |client|.
1962 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
1963 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:151964 GURL(), // referrer
1965 "null", // frame origin
1966 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:171967 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:041968 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:171969 routing_id());
1970
[email protected]0436b9a2009-10-23 00:23:051971 // A simple data source that keeps all data in memory.
1972 media::FilterFactory* simple_data_source_factory =
1973 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
1974 bridge_factory);
1975 // A sophisticated data source that does memory caching.
1976 media::FilterFactory* buffered_data_source_factory =
1977 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
1978 bridge_factory);
1979 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
1980 factory->AddFactory(simple_data_source_factory);
1981 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:171982 } else {
[email protected]0436b9a2009-10-23 00:23:051983 factory->AddFactory(buffered_data_source_factory);
1984 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:171985 }
1986 return new webkit_glue::WebMediaPlayerImpl(client, factory);
1987}
1988
1989void RenderView::willClose(WebFrame* frame) {
1990 if (!frame->parent()) {
1991 const GURL& url = frame->url();
1992 if (url.SchemeIs("http") || url.SchemeIs("https"))
1993 DumpLoadHistograms();
1994 }
[email protected]fa7b6b542009-11-03 05:02:301995
1996 WebDataSource* ds = frame->dataSource();
1997 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1998 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:171999}
2000
2001void RenderView::loadURLExternally(
2002 WebFrame* frame, const WebURLRequest& request,
2003 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592004 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2005 if (policy == WebKit::WebNavigationPolicyDownload) {
2006 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2007 } else {
2008 OpenURL(request.url(), referrer, policy);
2009 }
[email protected]3d9689372009-09-10 04:29:172010}
2011
2012WebNavigationPolicy RenderView::decidePolicyForNavigation(
2013 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222014 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172015 // Webkit is asking whether to navigate to a new URL.
2016 // This is fine normally, except if we're showing UI from one security
2017 // context and they're trying to navigate to a different context.
2018 const GURL& url = request.url();
2019
2020 // If the browser is interested, then give it a chance to look at top level
2021 // navigations
2022 if (renderer_preferences_.browser_handles_top_level_requests &&
2023 // Only send once.
2024 last_top_level_navigation_page_id_ != page_id_ &&
2025 // Not interested in reloads.
2026 type != WebKit::WebNavigationTypeReload &&
2027 type != WebKit::WebNavigationTypeFormSubmitted &&
2028 // Must be a top level frame.
2029 frame->parent() == NULL) {
2030 // Skip if navigation is on the same page (using '#').
2031 GURL frame_origin = GURL(frame->url()).GetOrigin();
2032 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
2033 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:572034 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2035 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:172036 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2037 }
2038 }
2039
2040 // A content initiated navigation may have originated from a link-click,
2041 // script, drag-n-drop operation, etc.
2042 bool is_content_initiated =
2043 NavigationState::FromDataSource(frame->provisionalDataSource())->
2044 is_content_initiated();
2045
2046 // We only care about navigations that are within the current tab (as opposed
2047 // to, for example, opening a new window).
2048 // But we sometimes navigate to about:blank to clear a tab, and we want to
2049 // still allow that.
2050 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2051 is_content_initiated && frame->parent() == NULL &&
2052 !url.SchemeIs(chrome::kAboutScheme)) {
2053 // When we received such unsolicited navigations, we sometimes want to
2054 // punt them up to the browser to handle.
2055 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2056 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2057 frame->isViewSourceModeEnabled() ||
2058 url.SchemeIs(chrome::kViewSourceScheme) ||
2059 url.SchemeIs(chrome::kPrintScheme)) {
2060 OpenURL(url, GURL(), default_policy);
2061 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2062 }
2063 }
2064
2065 // Detect when a page is "forking" a new tab that can be safely rendered in
2066 // its own process. This is done by sites like Gmail that try to open links
2067 // in new windows without script connections back to the original page. We
2068 // treat such cases as browser navigations (in which we will create a new
2069 // renderer for a cross-site navigation), rather than WebKit navigations.
2070 //
2071 // We use the following heuristic to decide whether to fork a new page in its
2072 // own process:
2073 // The parent page must open a new tab to about:blank, set the new tab's
2074 // window.opener to null, and then redirect the tab to a cross-site URL using
2075 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462076 //
2077 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2078 // (see below).
[email protected]3d9689372009-09-10 04:29:172079 bool is_fork =
2080 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252081 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172082 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522083 historyBackListCount() < 1 &&
2084 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172085 // The parent page must have set the child's window.opener to null before
2086 // redirecting to the desired URL.
2087 frame->opener() == NULL &&
2088 // Must be a top-level frame.
2089 frame->parent() == NULL &&
2090 // Must not have issued the request from this page.
2091 is_content_initiated &&
2092 // Must be targeted at the current tab.
2093 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2094 // Must be a JavaScript navigation, which appears as "other".
2095 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462096
2097 // Recognize if this navigation is from a link with rel=noreferrer and
2098 // target=_blank attributes, in which case the opener will be suppressed. If
2099 // so, it is safe to load cross-site pages in a separate process, so we
2100 // should let the browser handle it.
2101 bool is_noreferrer_and_blank_target =
2102 // Frame should be top level and not yet navigated.
2103 frame->parent() == NULL &&
2104 frame->url().isEmpty() &&
2105 historyBackListCount() < 1 &&
2106 historyForwardListCount() < 1 &&
2107 // Links with rel=noreferrer will have no Referer field, and their
2108 // resulting frame will have its window.opener suppressed.
2109 // TODO(creis): should add a request.httpReferrer() method to help avoid
2110 // typos on the unusual spelling of Referer.
2111 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2112 opener_suppressed_ &&
2113 frame->opener() == NULL &&
2114 // Links with target=_blank will have no name.
2115 frame->name().isNull() &&
2116 // Another frame (with a non-empty creator) should have initiated the
2117 // request, targeted at this frame.
2118 !creator_url_.is_empty() &&
2119 is_content_initiated &&
2120 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2121 type == WebKit::WebNavigationTypeOther;
2122
2123 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172124 // Open the URL via the browser, not via WebKit.
2125 OpenURL(url, GURL(), default_policy);
2126 return WebKit::WebNavigationPolicyIgnore;
2127 }
2128
2129 return default_policy;
2130}
2131
[email protected]6069da8c2009-10-20 20:33:492132bool RenderView::canHandleRequest(
2133 WebFrame* frame, const WebURLRequest& request) {
2134 // We allow WebKit to think that everything can be handled even though
2135 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342136 return true;
2137}
2138
[email protected]6069da8c2009-10-20 20:33:492139WebURLError RenderView::cannotHandleRequestError(
2140 WebFrame* frame, const WebURLRequest& request) {
2141 NOTREACHED(); // Since we said we can handle all requests.
2142 return WebURLError();
2143}
2144
2145WebURLError RenderView::cancelledError(
2146 WebFrame* frame, const WebURLRequest& request) {
2147 WebURLError error;
2148 error.domain = WebString::fromUTF8(net::kErrorDomain);
2149 error.reason = net::ERR_ABORTED;
2150 error.unreachableURL = request.url();
2151 return error;
[email protected]7b7a7dc2009-10-19 02:23:342152}
2153
2154void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492155 WebFrame*, const WebURLError&) {
2156 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342157}
2158
[email protected]979c28b2009-11-07 01:30:482159void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172160 NavigationState* navigation_state =
2161 NavigationState::FromDataSource(frame->provisionalDataSource());
2162
2163 if (navigation_state->transition_type() == PageTransition::LINK)
2164 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2165
2166 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352167 WebSearchableFormData web_searchable_form_data(form);
2168 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2169 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212170 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172171 navigation_state->set_password_form_data(
2172 PasswordFormDomManager::CreatePasswordForm(form));
2173
[email protected]979c28b2009-11-07 01:30:482174 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382175 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2176 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472177 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382178 *form_values));
[email protected]3d9689372009-09-10 04:29:172179 }
2180}
2181
2182void RenderView::willPerformClientRedirect(
2183 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2184 double fire_time) {
2185 // Ignore
2186}
2187
2188void RenderView::didCancelClientRedirect(WebFrame* frame) {
2189 // Ignore
2190}
2191
2192void RenderView::didCompleteClientRedirect(
2193 WebFrame* frame, const WebURL& from) {
2194 if (!frame->parent())
2195 completed_client_redirect_src_ = from;
2196}
2197
2198void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2199 // The rest of RenderView assumes that a WebDataSource will always have a
2200 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482201 bool content_initiated = !pending_navigation_state_.get();
2202 NavigationState* state = content_initiated ?
2203 NavigationState::CreateContentInitiated() :
2204 pending_navigation_state_.release();
2205 // TODO(jar): We may need to split up LINK_LOAD into several categories, based
2206 // on cache policy (not that location.reload() forces cache to be avoided).
2207 // Without the distinction, the distribution may be significantly bimodal.
2208 if (content_initiated)
2209 state->set_load_type(NavigationState::LINK_LOAD);
[email protected]fa7b6b542009-11-03 05:02:302210
2211 state->set_user_script_idle_scheduler(
2212 new UserScriptIdleScheduler(this, frame));
2213 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172214}
2215
2216void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2217 WebDataSource* ds = frame->provisionalDataSource();
2218 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2219
2220 navigation_state->set_start_load_time(Time::Now());
2221
2222 // Update the request time if WebKit has better knowledge of it.
2223 if (navigation_state->request_time().is_null()) {
2224 double event_time = ds->triggeringEventTime();
2225 if (event_time != 0.0)
2226 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2227 }
2228
2229 bool is_top_most = !frame->parent();
2230 if (is_top_most) {
2231 navigation_gesture_ = frame->isProcessingUserGesture() ?
2232 NavigationGestureUnknown : NavigationGestureAuto;
2233
2234 // Make sure redirect tracking state is clear for the new load.
2235 completed_client_redirect_src_ = GURL();
2236 } else if (frame->parent()->isLoading()) {
2237 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002238 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172239 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2240 }
2241
2242 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2243 routing_id_, is_top_most, ds->request().url()));
2244}
2245
2246void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2247 if (frame->parent())
2248 return;
2249 // Received a redirect on the main frame.
2250 WebDataSource* data_source = frame->provisionalDataSource();
2251 if (!data_source) {
2252 // Should only be invoked when we have a data source.
2253 NOTREACHED();
2254 return;
2255 }
2256 std::vector<GURL> redirects;
2257 GetRedirectChain(data_source, &redirects);
2258 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512259 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2260 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172261 }
2262}
2263
[email protected]40bd6582009-12-04 23:49:512264void RenderView::didFailProvisionalLoad(WebFrame* frame,
2265 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172266 // Notify the browser that we failed a provisional load with an error.
2267 //
2268 // Note: It is important this notification occur before DidStopLoading so the
2269 // SSL manager can react to the provisional load failure before being
2270 // notified the load stopped.
2271 //
2272 WebDataSource* ds = frame->provisionalDataSource();
2273 DCHECK(ds);
2274
2275 const WebURLRequest& failed_request = ds->request();
2276
2277 bool show_repost_interstitial =
2278 (error.reason == net::ERR_CACHE_MISS &&
2279 EqualsASCII(failed_request.httpMethod(), "POST"));
2280 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2281 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2282 show_repost_interstitial));
2283
2284 // Don't display an error page if this is simply a cancelled load. Aside
2285 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2286 if (error.reason == net::ERR_ABORTED)
2287 return;
2288
2289 // Make sure we never show errors in view source mode.
2290 frame->enableViewSourceMode(false);
2291
2292 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2293
2294 // If this is a failed back/forward/reload navigation, then we need to do a
2295 // 'replace' load. This is necessary to avoid messing up session history.
2296 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2297 // as session history is concerned.
2298 //
2299 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2300 // the page id.
2301 //
2302 bool replace =
2303 navigation_state->pending_page_id() != -1 ||
2304 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2305
2306 // If we failed on a browser initiated request, then make sure that our error
2307 // page load is regarded as the same browser initiated request.
2308 if (!navigation_state->is_content_initiated()) {
2309 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2310 navigation_state->pending_page_id(),
2311 navigation_state->transition_type(),
2312 navigation_state->request_time()));
2313 }
2314
2315 // Provide the user with a more helpful error page?
2316 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2317 return;
2318
2319 // Fallback to a local error page.
2320 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2321 replace);
2322}
2323
2324void RenderView::didReceiveDocumentData(
2325 WebFrame* frame, const char* data, size_t data_len,
2326 bool& prevent_default) {
2327 NavigationState* navigation_state =
2328 NavigationState::FromDataSource(frame->dataSource());
2329 if (!navigation_state->postpone_loading_data())
2330 return;
2331
2332 // We're going to call commitDocumentData ourselves...
2333 prevent_default = true;
2334
2335 // Continue buffering the response data for the original 404 page. If it
2336 // grows too large, then we'll just let it through.
2337 navigation_state->append_postponed_data(data, data_len);
2338 if (navigation_state->postponed_data().size() >= 512) {
2339 navigation_state->set_postpone_loading_data(false);
2340 frame->commitDocumentData(navigation_state->postponed_data().data(),
2341 navigation_state->postponed_data().size());
2342 navigation_state->clear_postponed_data();
2343 }
2344}
2345
[email protected]40bd6582009-12-04 23:49:512346void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2347 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172348 NavigationState* navigation_state =
2349 NavigationState::FromDataSource(frame->dataSource());
2350
2351 navigation_state->set_commit_load_time(Time::Now());
2352 if (is_new_navigation) {
2353 // When we perform a new navigation, we need to update the previous session
2354 // history entry with state for the page we are leaving.
2355 UpdateSessionHistory(frame);
2356
2357 // We bump our Page ID to correspond with the new session history entry.
2358 page_id_ = next_page_id_++;
2359
2360 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2361 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2362 page_id_, true),
2363 kDelayForForcedCaptureMs);
2364 } else {
2365 // Inspect the navigation_state on this frame to see if the navigation
2366 // corresponds to a session history navigation... Note: |frame| may or
2367 // may not be the toplevel frame, but for the case of capturing session
2368 // history, the first committed frame suffices. We keep track of whether
2369 // we've seen this commit before so that only capture session history once
2370 // per navigation.
2371 //
2372 // Note that we need to check if the page ID changed. In the case of a
2373 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2374 // previous URL and the current page ID, which would be wrong.
2375 if (navigation_state->pending_page_id() != -1 &&
2376 navigation_state->pending_page_id() != page_id_ &&
2377 !navigation_state->request_committed()) {
2378 // This is a successful session history navigation!
2379 UpdateSessionHistory(frame);
2380 page_id_ = navigation_state->pending_page_id();
2381 }
2382 }
2383
2384 // Remember that we've already processed this request, so we don't update
2385 // the session history again. We do this regardless of whether this is
2386 // a session history navigation, because if we attempted a session history
2387 // navigation without valid HistoryItem state, WebCore will think it is a
2388 // new navigation.
2389 navigation_state->set_request_committed(true);
2390
2391 UpdateURL(frame);
2392
2393 // If this committed load was initiated by a client redirect, we're
2394 // at the last stop now, so clear it.
2395 completed_client_redirect_src_ = GURL();
2396
2397 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272398 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172399}
2400
2401void RenderView::didClearWindowObject(WebFrame* frame) {
2402 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2403 BindDOMAutomationController(frame);
2404 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2405 dom_ui_bindings_.set_message_sender(this);
2406 dom_ui_bindings_.set_routing_id(routing_id_);
2407 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2408 }
2409 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2410 external_host_bindings_.set_message_sender(this);
2411 external_host_bindings_.set_routing_id(routing_id_);
2412 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2413 }
2414}
2415
2416void RenderView::didCreateDocumentElement(WebFrame* frame) {
2417 if (RenderThread::current()) { // Will be NULL during unit tests.
2418 RenderThread::current()->user_script_slave()->InjectScripts(
2419 frame, UserScript::DOCUMENT_START);
2420 }
[email protected]078b34612009-09-19 19:31:512421 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2422 view_type_ == ViewType::EXTENSION_MOLE) {
2423 InjectToolstripCSS();
2424 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2425 }
[email protected]3d9689372009-09-10 04:29:172426
2427 // Notify the browser about non-blank documents loading in the top frame.
2428 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252429 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272430 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172431 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2432 }
2433}
2434
2435void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2436 UpdateTitle(frame, title);
2437
2438 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272439 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172440}
2441
2442void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2443 WebDataSource* ds = frame->dataSource();
2444 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2445 DCHECK(navigation_state);
2446 navigation_state->set_finish_document_load_time(Time::Now());
2447
2448 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2449
2450 // The document has now been fully loaded. Scan for password forms to be
2451 // sent up to the browser.
2452 SendPasswordForms(frame);
2453
2454 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272455 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172456
2457 if (RenderThread::current()) { // Will be NULL during unit tests.
2458 RenderThread::current()->user_script_slave()->InjectScripts(
2459 frame, UserScript::DOCUMENT_END);
2460 }
[email protected]fa7b6b542009-11-03 05:02:302461
2462 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2463}
2464
2465void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2466 if (RenderThread::current()) { // Will be NULL during unit tests.
2467 RenderThread::current()->user_script_slave()->InjectScripts(
2468 frame, UserScript::DOCUMENT_IDLE);
2469 }
2470
2471 WebFrame* main_frame = webview()->mainFrame();
2472 if (frame == main_frame) {
2473 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202474 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302475 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202476 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302477 pending_code_execution_queue_.pop();
2478 }
2479 }
[email protected]3d9689372009-09-10 04:29:172480}
2481
2482void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2483 // Ignore
2484}
2485
2486void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2487 // Ignore
2488}
2489
2490void RenderView::didFinishLoad(WebFrame* frame) {
2491 WebDataSource* ds = frame->dataSource();
2492 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2493 DCHECK(navigation_state);
2494 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302495 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172496}
2497
2498void RenderView::didChangeLocationWithinPage(
2499 WebFrame* frame, bool is_new_navigation) {
2500 // If this was a reference fragment navigation that we initiated, then we
2501 // could end up having a non-null pending navigation state. We just need to
2502 // update the ExtraData on the datasource so that others who read the
2503 // ExtraData will get the new NavigationState. Similarly, if we did not
2504 // initiate this navigation, then we need to take care to reset any pre-
2505 // existing navigation state to a content-initiated navigation state.
2506 // DidCreateDataSource conveniently takes care of this for us.
2507 didCreateDataSource(frame, frame->dataSource());
2508
2509 didCommitProvisionalLoad(frame, is_new_navigation);
2510
[email protected]26aa0482009-09-30 16:55:272511 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172512}
2513
[email protected]476b6f82009-09-10 21:00:592514void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312515 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592516}
2517
[email protected]3d9689372009-09-10 04:29:172518void RenderView::assignIdentifierToRequest(
2519 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2520 // Ignore
2521}
2522
2523void RenderView::willSendRequest(
2524 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2525 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302526 WebFrame* top_frame = frame->top();
2527 if (!top_frame)
2528 top_frame = frame;
2529 WebDataSource* data_source = top_frame->provisionalDataSource();
2530 if (!data_source)
2531 data_source = top_frame->dataSource();
2532 if (data_source) {
2533 NavigationState* state = NavigationState::FromDataSource(data_source);
2534 if (state && state->is_cache_policy_override_set())
2535 request.setCachePolicy(state->cache_policy_override());
2536 }
[email protected]3d9689372009-09-10 04:29:172537 request.setRequestorID(routing_id_);
2538}
2539
2540void RenderView::didReceiveResponse(
2541 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]3d9689372009-09-10 04:29:172542 // Only do this for responses that correspond to a provisional data source
2543 // of the top-most frame. If we have a provisional data source, then we
2544 // can't have any sub-resources yet, so we know that this response must
2545 // correspond to a frame load.
2546 if (!frame->provisionalDataSource() || frame->parent())
2547 return;
2548
2549 // If we are in view source mode, then just let the user see the source of
2550 // the server's 404 error page.
2551 if (frame->isViewSourceModeEnabled())
2552 return;
2553
[email protected]f48013be2010-01-14 22:07:452554 // Record that this was a page loaded over SPDY.
2555 if (response.wasFetchedViaSPDY()) {
2556 NavigationState* navigation_state =
2557 NavigationState::FromDataSource(frame->provisionalDataSource());
2558 navigation_state->set_was_fetched_via_spdy(true);
2559 }
2560
2561 // Consider loading an alternate error page for 404 responses.
2562 if (response.httpStatusCode() != 404)
2563 return;
2564
[email protected]3d9689372009-09-10 04:29:172565 // Can we even load an alternate error page for this URL?
2566 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2567 return;
2568
2569 NavigationState* navigation_state =
2570 NavigationState::FromDataSource(frame->provisionalDataSource());
2571 navigation_state->set_postpone_loading_data(true);
2572 navigation_state->clear_postponed_data();
2573}
2574
2575void RenderView::didFinishResourceLoad(
2576 WebFrame* frame, unsigned identifier) {
2577 NavigationState* navigation_state =
2578 NavigationState::FromDataSource(frame->dataSource());
2579 if (!navigation_state->postpone_loading_data())
2580 return;
2581
2582 // The server returned a 404 and the content was < 512 bytes (which we
2583 // suppressed). Go ahead and fetch the alternate page content.
2584
2585 const GURL& frame_url = frame->url();
2586
2587 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2588 DCHECK(error_page_url.is_valid());
2589
2590 WebURLError original_error;
2591 original_error.unreachableURL = frame_url;
2592
2593 navigation_state->set_alt_error_page_fetcher(
2594 new AltErrorPageResourceFetcher(
2595 error_page_url, frame, original_error,
2596 NewCallback(this, &RenderView::AltErrorPageFinished)));
2597}
2598
2599void RenderView::didFailResourceLoad(
2600 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2601 // Ignore
2602}
2603
2604void RenderView::didLoadResourceFromMemoryCache(
2605 WebFrame* frame, const WebURLRequest& request,
2606 const WebURLResponse& response) {
2607 // Let the browser know we loaded a resource from the memory cache. This
2608 // message is needed to display the correct SSL indicators.
2609 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2610 routing_id_,
2611 request.url(),
[email protected]91733b62009-09-18 06:21:092612 frame->securityOrigin().toString().utf8(),
2613 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172614 response.securityInfo()));
2615}
2616
[email protected]6069da8c2009-10-20 20:33:492617void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292618 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2619}
2620
2621void RenderView::didRunInsecureContent(
2622 WebFrame* frame, const WebSecurityOrigin& origin) {
2623 Send(new ViewHostMsg_DidRunInsecureContent(
2624 routing_id_,
2625 origin.toString().utf8()));
2626}
2627
[email protected]7ea093ba2009-11-03 05:54:592628bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
2629 if (enabled_per_settings)
2630 return true;
2631
2632 WebSecurityOrigin origin = frame->securityOrigin();
2633 if (origin.isEmpty())
2634 return false; // Uninitialized document?
2635
2636 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2637 return true; // Browser UI elements should still work.
2638
2639 // If the scheme is ftp: or file:, an empty file name indicates a directory
2640 // listing, which requires JavaScript to function properly.
2641 GURL frame_url = frame->url();
2642 const char* kDirProtocols[] = { "ftp", "file" };
2643 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2644 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2645 return frame_url.SchemeIs(kDirProtocols[i]) &&
2646 frame_url.ExtractFileName().empty();
2647 }
2648 }
2649
2650 return false; // Other protocols fall through here.
2651}
2652
[email protected]3d9689372009-09-10 04:29:172653void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2654 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2655}
2656
[email protected]0c882b282009-10-07 17:01:282657void RenderView::didCreateScriptContext(WebFrame* frame) {
2658 EventBindings::HandleContextCreated(frame, false);
2659}
2660
2661void RenderView::didDestroyScriptContext(WebFrame* frame) {
2662 EventBindings::HandleContextDestroyed(frame);
2663}
2664
2665void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2666 EventBindings::HandleContextCreated(frame, true);
2667}
2668
[email protected]3d9689372009-09-10 04:29:172669void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2670 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252671 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172672 // message.
[email protected]ab32b16c2009-10-16 14:57:252673 if (send_preferred_size_changes_) {
[email protected]3d9689372009-09-10 04:29:172674 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252675 // cache the width and height and only send the IPC message when we're sure
2676 // they're different.
[email protected]26aa0482009-09-30 16:55:272677 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:392678 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:292679
[email protected]ab32b16c2009-10-16 14:57:252680 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:392681 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:252682 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:392683 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:252684
[email protected]ab32b16c2009-10-16 14:57:252685 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2686 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172687 }
2688 }
2689}
2690
[email protected]143dcd592009-11-06 21:33:492691void RenderView::didChangeScrollOffset(WebFrame* frame) {
2692 StartNavStateSyncTimerIfNecessary();
2693}
2694
[email protected]8922e1f2009-10-03 05:01:262695void RenderView::reportFindInPageMatchCount(int request_id, int count,
2696 bool final_update) {
2697 // If we have a message that has been queued up, then we should just replace
2698 // it. The ACK from the browser will make sure it gets sent when the browser
2699 // wants it.
2700 if (queued_find_reply_message_.get()) {
2701 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2702 routing_id_,
2703 request_id,
2704 count,
2705 gfx::Rect(),
2706 -1, // Don't update active match ordinal.
2707 final_update);
2708 queued_find_reply_message_.reset(msg);
2709 } else {
2710 // Send the search result over to the browser process.
2711 Send(new ViewHostMsg_Find_Reply(
2712 routing_id_,
2713 request_id,
2714 count,
2715 gfx::Rect(),
2716 -1, // // Don't update active match ordinal.
2717 final_update));
2718 }
2719}
2720
2721void RenderView::reportFindInPageSelection(int request_id,
2722 int active_match_ordinal,
2723 const WebRect& selection_rect) {
2724 // Send the search result over to the browser process.
2725 Send(new ViewHostMsg_Find_Reply(routing_id_,
2726 request_id,
2727 -1,
2728 selection_rect,
2729 active_match_ordinal,
2730 false));
2731}
2732
[email protected]79dbc662009-09-04 05:42:512733// webkit_glue::WebPluginPageDelegate -----------------------------------------
2734
[email protected]f103ab72009-09-02 17:10:592735webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2736 const GURL& url,
2737 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592738 std::string* actual_mime_type) {
2739 if (!PluginChannelHost::IsListening())
2740 return NULL;
2741
2742 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272743 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592744 if (main_frame)
2745 policy_url = main_frame->url();
2746
2747 FilePath path;
[email protected]610c0892009-09-08 19:46:182748 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2749 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592750 if (path.value().empty())
2751 return NULL;
2752
2753 const std::string* mime_type_to_use;
2754 if (!actual_mime_type->empty())
2755 mime_type_to_use = actual_mime_type;
2756 else
2757 mime_type_to_use = &mime_type;
2758
[email protected]d2139662009-12-10 03:21:142759 bool use_pepper_host = false;
2760 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2761 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:162762 const char kPepperPrefix[] = "pepper-";
2763 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:142764 if (CommandLine::ForCurrentProcess()->
2765 HasSwitch(switches::kInternalPepper)) {
2766 in_process_plugin = true;
2767 use_pepper_host = true;
2768 } else {
2769 // In process Pepper plugins must be explicitly enabled.
2770 return NULL;
2771 }
[email protected]26e8d5e2009-10-13 02:47:162772 }
[email protected]d2139662009-12-10 03:21:142773 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:462774 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2775 if (mime_type == "application/x-nacl-srpc") {
2776 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:142777 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:462778 }
2779 }
2780 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:142781 if (use_pepper_host) {
2782 return WebPluginDelegatePepper::Create(
[email protected]7477ea6f2009-12-22 23:28:152783 path,
2784 *mime_type_to_use,
[email protected]6876dff2010-01-15 19:38:092785 AsWeakPtr());
[email protected]d2139662009-12-10 03:21:142786 } else {
[email protected]6876dff2010-01-15 19:38:092787#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:142788 return WebPluginDelegateImpl::Create(
2789 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092790#else
[email protected]596b2c42010-01-14 20:40:432791 NOTIMPLEMENTED();
2792 return NULL;
[email protected]7b6616f2010-01-14 18:07:552793#endif
[email protected]6876dff2010-01-15 19:38:092794 }
[email protected]f103ab72009-09-02 17:10:592795 }
2796
[email protected]610c0892009-09-08 19:46:182797 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592798}
2799
2800void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2801#if defined(OS_LINUX)
2802 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2803 routing_id(), window));
2804#endif
2805}
2806
2807void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2808#if defined(OS_LINUX)
2809 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2810 routing_id(), window));
2811#endif
2812 CleanupWindowInPluginMoves(window);
2813}
2814
2815void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
2816 SchedulePluginMove(move);
2817}
2818
2819void RenderView::DidStartLoadingForPlugin() {
2820 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522821 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592822}
2823
2824void RenderView::DidStopLoadingForPlugin() {
2825 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522826 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592827}
2828
2829void RenderView::ShowModalHTMLDialogForPlugin(
2830 const GURL& url,
2831 const gfx::Size& size,
2832 const std::string& json_arguments,
2833 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:212834 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:592835 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:212836 json_retval));
[email protected]f103ab72009-09-02 17:10:592837}
2838
initial.commit09911bf2008-07-26 23:55:292839void RenderView::SyncNavigationState() {
2840 if (!webview())
2841 return;
2842
[email protected]26aa0482009-09-30 16:55:272843 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172844 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292845 return;
[email protected]ca948a22009-06-25 19:36:172846
2847 Send(new ViewHostMsg_UpdateState(
2848 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292849}
2850
[email protected]b0950a72009-09-29 23:16:172851bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
2852 // Make sure webview was not shut down.
2853 if (!webview())
2854 return false;
2855 // Create an image resource fetcher and assign it with a call back object.
2856 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:272857 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:172858 NewCallback(this, &RenderView::DidDownloadImage)));
2859 return true;
2860}
2861
2862void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:292863 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:172864 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:472865 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
2866 fetcher->id(),
2867 fetcher->image_url(),
2868 image.isNull(),
2869 image));
[email protected]b0950a72009-09-29 23:16:172870 // Dispose of the image fetcher.
2871 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
2872 image_fetchers_.erase(fetcher);
2873 // We're in the callback from the ImageResourceFetcher, best to delay
2874 // deletion.
2875 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:292876}
2877
[email protected]bf5c2ff392009-07-08 16:24:332878void RenderView::OnDownloadFavIcon(int id,
2879 const GURL& image_url,
2880 int image_size) {
[email protected]f11ca0732009-04-11 00:09:342881 bool data_image_failed = false;
2882 if (image_url.SchemeIs("data")) {
2883 SkBitmap data_image = ImageFromDataUrl(image_url);
2884 data_image_failed = data_image.empty();
2885 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:332886 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
2887 data_image));
[email protected]f11ca0732009-04-11 00:09:342888 }
2889 }
2890
[email protected]bf5c2ff392009-07-08 16:24:332891 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:172892 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:332893 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
2894 SkBitmap()));
2895 }
initial.commit09911bf2008-07-26 23:55:292896}
2897
[email protected]f11ca0732009-04-11 00:09:342898SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
2899 std::string mime_type, char_set, data;
2900 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
2901 // Decode the favicon using WebKit's image decoder.
2902 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
2903 const unsigned char* src_data =
2904 reinterpret_cast<const unsigned char*>(&data[0]);
2905
2906 return decoder.Decode(src_data, data.size());
2907 }
2908 return SkBitmap();
2909}
2910
initial.commit09911bf2008-07-26 23:55:292911void RenderView::OnGetApplicationInfo(int page_id) {
2912 webkit_glue::WebApplicationInfo app_info;
2913 if (page_id == page_id_)
2914 webkit_glue::GetApplicationInfo(webview(), &app_info);
2915
2916 // Prune out any data URLs in the set of icons. The browser process expects
2917 // any icon with a data URL to have originated from a favicon. We don't want
2918 // to decode arbitrary data URLs in the browser process. See
2919 // http://b/issue?id=1162972
2920 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:592921 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:292922 app_info.icons.erase(app_info.icons.begin() + i);
2923 --i;
2924 }
2925 }
2926
2927 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
2928}
2929
[email protected]7ccddb8c2009-08-04 17:36:552930GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292931 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552932 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292933 // If the URL that failed was secure, then the embedding web page was not
2934 // expecting a network attacker to be able to manipulate its contents. As
2935 // we fetch alternate error pages over HTTP, we would be allowing a network
2936 // attacker to manipulate the contents of the response if we tried to use
2937 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:152938 return GURL();
initial.commit09911bf2008-07-26 23:55:292939 }
2940
2941 // Grab the base URL from the browser process.
2942 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:152943 return GURL();
initial.commit09911bf2008-07-26 23:55:292944
2945 // Strip query params from the failed URL.
2946 GURL::Replacements remove_params;
2947 remove_params.ClearUsername();
2948 remove_params.ClearPassword();
2949 remove_params.ClearQuery();
2950 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552951 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:292952
2953 // Construct the query params to send to link doctor.
2954 std::string params(alternate_error_page_url_.query());
2955 params.append("&url=");
[email protected]0d2e6a62010-01-15 20:09:192956 params.append(EscapeQueryParamValue(url_to_send.spec(), true));
initial.commit09911bf2008-07-26 23:55:292957 params.append("&sourceid=chrome");
2958 params.append("&error=");
2959 switch (error_type) {
2960 case DNS_ERROR:
2961 params.append("dnserror");
2962 break;
2963
2964 case HTTP_404:
2965 params.append("http404");
2966 break;
2967
[email protected]5df266ac2008-10-15 19:50:132968 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332969 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132970 break;
2971
initial.commit09911bf2008-07-26 23:55:292972 default:
2973 NOTREACHED() << "unknown ErrorPageType";
2974 }
2975
2976 // OK, build the final url to return.
2977 GURL::Replacements link_doctor_params;
2978 link_doctor_params.SetQueryStr(params);
2979 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2980 return url;
2981}
2982
[email protected]6069da8c2009-10-20 20:33:492983void RenderView::OnFind(int request_id, const string16& search_text,
2984 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272985 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:272986 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272987 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292988 WebFrame* search_frame = focused_frame; // start searching focused frame.
2989
2990 bool multi_frame = (frame_after_main != main_frame);
2991
2992 // If we have multiple frames, we don't want to wrap the search within the
2993 // frame, so we check here if we only have main_frame in the chain.
2994 bool wrap_within_frame = !multi_frame;
2995
[email protected]b3f2b912009-04-09 16:18:522996 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:292997 bool result = false;
2998
[email protected]7830da3e2009-11-06 16:27:262999 // If something is selected when we start searching it means we cannot just
3000 // increment the current match ordinal; we need to re-generate it.
3001 WebRange current_selection = focused_frame->selectionRange();
3002
initial.commit09911bf2008-07-26 23:55:293003 do {
[email protected]dd7daa82009-08-10 05:46:453004 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593005 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293006
3007 if (!result) {
3008 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223009 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293010
3011 // Find the next frame, but skip the invisible ones.
3012 do {
3013 // What is the next frame to search? (we might be going backwards). Note
3014 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593015 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273016 search_frame->traverseNext(true) :
3017 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453018 } while (!search_frame->hasVisibleContent() &&
3019 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293020
[email protected]884db412008-11-24 23:46:503021 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223022 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293023
3024 // If we have multiple frames and we have wrapped back around to the
3025 // focused frame, we need to search it once more allowing wrap within
3026 // the frame, otherwise it will report 'no match' if the focused frame has
3027 // reported matches, but no frames after the focused_frame contain a
3028 // match for the search word(s).
3029 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453030 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593031 request_id, search_text, options, true, // Force wrapping.
3032 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293033 }
3034 }
3035
[email protected]26aa0482009-09-30 16:55:273036 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293037 } while (!result && search_frame != focused_frame);
3038
[email protected]7830da3e2009-11-06 16:27:263039 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293040 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453041 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293042 } else {
3043 // If nothing is found, set result to "0 of 0", otherwise, set it to
3044 // "-1 of 1" to indicate that we found at least one item, but we don't know
3045 // yet what is active.
3046 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3047 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293048
[email protected]4f3dc372009-02-24 00:10:293049 // If we find no matches then this will be our last status update.
3050 // Otherwise the scoping effort will send more results.
3051 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293052
[email protected]4f3dc372009-02-24 00:10:293053 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403054 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593055 request_id,
[email protected]4f3dc372009-02-24 00:10:293056 match_count,
3057 selection_rect,
3058 ordinal,
3059 final_status_update));
initial.commit09911bf2008-07-26 23:55:293060
initial.commit09911bf2008-07-26 23:55:293061 // Scoping effort begins, starting with the mainframe.
3062 search_frame = main_frame;
3063
[email protected]dd7daa82009-08-10 05:46:453064 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293065
3066 do {
3067 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453068 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293069
3070 // We don't start another scoping effort unless at least one match has
3071 // been found.
3072 if (result) {
3073 // Start new scoping request. If the scoping function determines that it
3074 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453075 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593076 search_text,
3077 options,
initial.commit09911bf2008-07-26 23:55:293078 true); // reset the tickmarks
3079 }
3080
3081 // Iterate to the next frame. The frame will not necessarily scope, for
3082 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273083 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293084 } while (search_frame != main_frame);
3085 }
3086}
3087
[email protected]8c4cdd42010-01-12 21:31:133088std::string RenderView::DetectLanguage() {
3089 if (!webview() || is_loading_)
3090 return kUnknownLanguageCode;
3091
[email protected]8c4cdd42010-01-12 21:31:133092 WebFrame* main_frame = webview()->mainFrame();
3093 std::wstring contents;
3094 CaptureText(main_frame, &contents);
[email protected]8dc5a2052010-01-19 21:32:423095 return DetermineTextLanguage(contents);
[email protected]8c4cdd42010-01-12 21:31:133096}
3097
3098// static
3099std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
3100 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133101 int num_languages = 0;
3102 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423103 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133104 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423105 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133106 &num_languages, NULL);
3107 if (cld_language != NUM_LANGUAGES && cld_language != UNKNOWN_LANGUAGE &&
3108 cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483109 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3110 // the languages CLD can detect. As a result, it'll return the invalid
3111 // language code for tradtional Chinese among others. |LanguageCode| will go
3112 // through ISO 639-1, ISO-639-2 and 'other' tables to do the 'right' thing.
[email protected]8dc5a2052010-01-19 21:32:423113 language = LanguageCode(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133114 }
[email protected]8c4cdd42010-01-12 21:31:133115 return language;
[email protected]7893a982010-01-07 23:25:523116}
3117
initial.commit09911bf2008-07-26 23:55:293118void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3119 Send(new ViewHostMsg_DnsPrefetch(host_names));
3120}
3121
[email protected]40bd6582009-12-04 23:49:513122void RenderView::OnZoom(PageZoom::Function function) {
3123 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3124 return;
3125
3126 int zoom_level = webview()->zoomLevel();
3127 int new_zoom_level = webview()->setZoomLevel(false,
3128 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3129
3130 // Tell the browser which host got zoomed so it can update the saved values.
3131 // Pages like the safe browsing interstitial can have empty hosts; don't
3132 // record those.
3133 std::string host(GURL(webview()->mainFrame()->url()).host());
3134 if (!host.empty())
3135 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3136}
3137
3138void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3139 int zoom_level) {
3140 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293141}
3142
[email protected]41fc0322009-09-04 22:23:403143void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273144 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293145}
3146
[email protected]a697f4c2009-09-14 22:30:183147void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273148 WebString no_encoding;
3149 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183150}
3151
[email protected]20ad2692009-11-20 18:27:203152bool RenderView::GetAllChildFrames(
3153 WebFrame* parent_frame,
3154 std::vector<WebFrame*>* frames_vector) const {
3155 if (!parent_frame)
3156 return false;
3157 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3158 child_frame = child_frame->nextSibling()) {
3159 frames_vector->push_back(child_frame);
3160 GetAllChildFrames(child_frame, frames_vector);
3161 }
3162 return true;
3163}
3164
[email protected]dd7daa82009-08-10 05:46:453165WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3166 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273167 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453168
3169 // xpath string can represent a frame deep down the tree (across multiple
3170 // frame DOMs).
3171 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3172 // should break into 2 xpaths
3173 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3174
[email protected]26aa0482009-09-30 16:55:273175 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453176
3177 std::wstring xpath_remaining = xpath;
3178 while (!xpath_remaining.empty()) {
3179 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3180 std::wstring xpath_child;
3181 if (delim_pos != std::wstring::npos) {
3182 xpath_child = xpath_remaining.substr(0, delim_pos);
3183 xpath_remaining.erase(0, delim_pos + 1);
3184 } else {
3185 xpath_remaining.swap(xpath_child);
3186 }
3187 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293188 }
3189
[email protected]dd7daa82009-08-10 05:46:453190 return frame;
initial.commit09911bf2008-07-26 23:55:293191}
3192
[email protected]f29acf52008-11-03 20:08:333193void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3194 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293195 WebFrame* web_frame = GetChildFrame(frame_xpath);
3196 if (!web_frame)
3197 return;
3198
[email protected]dd7daa82009-08-10 05:46:453199 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293200}
3201
[email protected]1810e132009-03-24 23:35:483202void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083203 const std::string& css,
3204 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483205 WebFrame* web_frame = GetChildFrame(frame_xpath);
3206 if (!web_frame)
3207 return;
3208
[email protected]ffaef0c2009-09-15 17:08:083209 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483210}
3211
initial.commit09911bf2008-07-26 23:55:293212void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3213 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333214 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293215}
3216
[email protected]1810e132009-03-24 23:35:483217void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083218 const std::string& css,
3219 const std::string& id) {
3220 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413221
3222 // Notify RenderViewHost that css has been inserted into the frame.
3223 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483224}
3225
[email protected]7ea066a2009-04-06 20:21:593226void RenderView::OnAddMessageToConsole(
3227 const string16& frame_xpath,
3228 const string16& message,
3229 const WebConsoleMessage::Level& level) {
3230 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593231 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453232 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293233}
3234
[email protected]81e63782009-02-27 19:35:093235void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3236 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293237}
3238
3239void RenderView::OnSetDOMUIProperty(const std::string& name,
3240 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093241 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293242 dom_ui_bindings_.SetProperty(name, value);
3243}
3244
3245void RenderView::OnReservePageIDRange(int size_of_range) {
3246 next_page_id_ += size_of_range + 1;
3247}
3248
[email protected]e80c73b2009-04-07 23:24:583249void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3250 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253251 bool ended,
3252 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033253 if (ended) {
[email protected]26aa0482009-09-30 16:55:273254 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033255 }
initial.commit09911bf2008-07-26 23:55:293256}
3257
3258void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273259 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293260}
3261
initial.commit09911bf2008-07-26 23:55:293262void RenderView::OnFormFill(const FormData& form) {
3263 webkit_glue::FillForm(this->webview(), form);
3264}
3265
3266void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103267 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293268 webkit_glue::FillPasswordForm(this->webview(), form_data);
3269}
3270
3271void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583272 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253273 const gfx::Point& screen_point,
3274 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273275 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583276 drop_data.ToDragData(),
3277 drop_data.identity,
3278 client_point,
[email protected]1d9f4132009-09-08 17:29:253279 screen_point,
3280 ops);
initial.commit09911bf2008-07-26 23:55:293281
[email protected]1d9f4132009-09-08 17:29:253282 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293283}
3284
[email protected]e80c73b2009-04-07 23:24:583285void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253286 const gfx::Point& screen_point,
3287 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273288 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253289 client_point,
3290 screen_point,
3291 ops);
initial.commit09911bf2008-07-26 23:55:293292
[email protected]1d9f4132009-09-08 17:29:253293 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293294}
3295
3296void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273297 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293298}
3299
[email protected]e80c73b2009-04-07 23:24:583300void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3301 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273302 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293303}
3304
3305void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593306 webkit_preferences_ = prefs;
3307 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293308}
3309
3310void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3311 alternate_error_page_url_ = url;
3312}
3313
[email protected]a0c7153e2009-12-09 14:36:333314void RenderView::OnCustomContextMenuAction(unsigned action) {
3315 webview()->performCustomContextMenuAction(action);
3316}
3317
[email protected]0bedb8a2010-01-14 19:36:323318void RenderView::OnTranslateTextResponse(
3319 int work_id, int error_id, const std::vector<string16>& text_chunks) {
3320 if (error_id) {
3321 page_translator_->TranslationError(work_id, error_id);
3322 return;
3323 }
3324 page_translator_->TextTranslated(work_id, text_chunks);
3325}
3326
initial.commit09911bf2008-07-26 23:55:293327void RenderView::OnInstallMissingPlugin() {
3328 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593329 if (first_default_plugin_)
3330 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293331}
3332
[email protected]b62d1a8c2009-01-13 23:54:573333void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:343334 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363335 // This could happen if we navigated to a different page before the user
3336 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463337 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363338 return;
3339
[email protected]6069da8c2009-10-20 20:33:493340 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463341 for (size_t i = 0; i < file_names.size(); ++i) {
3342 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3343 }
3344
3345 file_chooser_completion_->didChooseFile(ws_file_names);
3346 // Reset the chooser pointer
3347 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293348}
3349
3350void RenderView::OnEnableViewSourceMode() {
3351 if (!webview())
3352 return;
[email protected]26aa0482009-09-30 16:55:273353 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293354 if (!main_frame)
3355 return;
3356
[email protected]dd7daa82009-08-10 05:46:453357 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293358}
3359
[email protected]ab32b16c2009-10-16 14:57:253360void RenderView::OnEnablePreferredSizeChangedMode() {
3361 send_preferred_size_changes_ = true;
[email protected]0666aef2009-05-13 19:48:083362}
3363
[email protected]80d96fa2009-06-10 22:34:513364void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3365 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373366 UpdateFontRenderingFromRendererPrefs();
[email protected]033970a2009-10-14 16:45:053367#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]1c83eb42009-09-11 21:08:413368 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3369 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]93623c5d2009-12-10 21:40:323370
[email protected]644d77e2010-01-27 01:03:103371 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323372 webview()->setScrollbarColors(
3373 renderer_prefs.thumb_inactive_color,
3374 renderer_prefs.thumb_active_color,
3375 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103376 webview()->setSelectionColors(
3377 renderer_prefs.active_selection_bg_color,
3378 renderer_prefs.active_selection_fg_color,
3379 renderer_prefs.inactive_selection_bg_color,
3380 renderer_prefs.inactive_selection_fg_color);
3381 }
[email protected]7a74e102009-09-03 00:16:563382#endif
[email protected]80d96fa2009-06-10 22:34:513383}
3384
[email protected]952cb702009-10-07 05:50:283385void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3386 const WebMediaPlayerAction& action) {
3387 if (webview())
3388 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563389}
3390
[email protected]7b291f92009-08-14 05:43:533391void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513392 // When this is first set, the bindings aren't fully loaded. We only need
3393 // to call through this API after the page has already been loaded. It's
3394 // also called in didCreateDocumentElement to bootstrap.
3395 if (view_type_ != ViewType::INVALID) {
3396 if (type == ViewType::EXTENSION_MOLE ||
3397 type == ViewType::EXTENSION_TOOLSTRIP) {
3398 ExtensionProcessBindings::SetViewType(webview(), type);
3399 }
3400 }
[email protected]7b291f92009-08-14 05:43:533401 view_type_ = type;
3402}
3403
3404void RenderView::OnUpdateBrowserWindowId(int window_id) {
3405 browser_window_id_ = window_id;
3406}
3407
initial.commit09911bf2008-07-26 23:55:293408void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3409 int forward_list_count) {
3410 history_back_list_count_ = back_list_count;
3411 history_forward_list_count_ = forward_list_count;
3412}
3413
[email protected]266eb6f2008-09-30 23:56:503414void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253415 const webkit_glue::WebAccessibility::InParams& in_params,
3416 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573417#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153418 if (!accessibility_.get()) {
3419 // TODO(dglazkov): Once implemented for all ports, remove lazy
3420 // instantiation of accessibility_.
3421 accessibility_.reset(WebAccessibilityCache::create());
3422 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253423 }
[email protected]266eb6f2008-09-30 23:56:503424
[email protected]c7287a92009-11-04 20:06:153425 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3426 in_params,
3427 out_params);
3428
[email protected]6c8afae52009-01-22 02:24:573429#else // defined(OS_WIN)
3430 // TODO(port): accessibility not yet implemented
3431 NOTIMPLEMENTED();
3432#endif
[email protected]266eb6f2008-09-30 23:56:503433}
3434
[email protected]6a983b42009-03-20 20:12:253435void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573436#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153437 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503438 // If accessibility is not activated, ignore clearing message.
3439 return;
3440 }
[email protected]e846d0d2009-05-20 00:53:063441
[email protected]c7287a92009-11-04 20:06:153442 if (clear_all) {
3443 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503444 return;
[email protected]c7287a92009-11-04 20:06:153445 }
3446
3447 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063448
[email protected]6c8afae52009-01-22 02:24:573449#else // defined(OS_WIN)
3450 // TODO(port): accessibility not yet implemented
3451 NOTIMPLEMENTED();
3452#endif
[email protected]266eb6f2008-09-30 23:56:503453}
3454
initial.commit09911bf2008-07-26 23:55:293455void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3456 const GURL& page_url) {
3457 // Prepare list to storage all savable resource links.
3458 std::vector<GURL> resources_list;
3459 std::vector<GURL> referrers_list;
3460 std::vector<GURL> frames_list;
3461 webkit_glue::SavableResourcesResult result(&resources_list,
3462 &referrers_list,
3463 &frames_list);
3464
[email protected]dbeb3952009-10-13 18:01:183465 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3466 webview(),
3467 page_url,
3468 &result,
3469 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293470 // If something is wrong when collecting all savable resource links,
3471 // send empty list to embedder(browser) to tell it failed.
3472 referrers_list.clear();
3473 resources_list.clear();
3474 frames_list.clear();
3475 }
3476
3477 // Send result of all savable resource links to embedder.
3478 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3479 resources_list,
3480 referrers_list,
3481 frames_list));
3482}
3483
3484void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323485 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313486 const std::vector<FilePath>& local_paths,
3487 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073488
3489 // Convert std::vector of GURLs to WebVector<WebURL>
3490 WebVector<WebURL> weburl_links(links);
3491
3492 // Convert std::vector of std::strings to WebVector<WebString>
3493 WebVector<WebString> webstring_paths(local_paths.size());
3494 for (size_t i = 0; i < local_paths.size(); i++)
3495 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3496
3497 WebPageSerializer::serialize(webview()->mainFrame(),
3498 true, this, weburl_links, webstring_paths,
3499 webkit_glue::FilePathToWebString(
3500 local_directory_name));
initial.commit09911bf2008-07-26 23:55:293501}
3502
[email protected]d9ec5c0f2009-12-23 11:55:073503void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
3504 const WebCString& data,
3505 WebPageSerializerClient::PageSerializationStatus status) {
3506 Send(new ViewHostMsg_SendSerializedHtmlData(
3507 routing_id_,
3508 frame_url,
3509 data.data(),
3510 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:293511}
3512
[email protected]04b4a6c2008-08-02 00:44:473513void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273514 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473515 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293516}
3517
[email protected]eb6b87a2009-07-24 15:57:393518void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293519 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3520 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3521 // in the onunload handler from appearing. For now, we're bypassing that and
3522 // calling the FrameLoader's CloseURL method directly. This should be
3523 // revisited to avoid having two ways to close a page. Having a single way
3524 // to close that can run onunload is also useful for fixing
3525 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273526 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293527 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453528 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173529 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293530 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3531 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453532 if (url.SchemeIs(chrome::kHttpScheme) ||
3533 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293534 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293535 }
[email protected]26aa0482009-09-30 16:55:273536 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293537
[email protected]eb6b87a2009-07-24 15:57:393538 // Just echo back the params in the ACK.
3539 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293540}
3541
3542void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573543#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293544 gfx::NativeTheme::instance()->CloseHandles();
3545 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283546 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573547#else // defined(OS_WIN)
3548 // TODO(port): we don't support theming on non-Windows platforms yet
3549 NOTIMPLEMENTED();
3550#endif
initial.commit09911bf2008-07-26 23:55:293551}
3552
[email protected]28790922009-03-09 19:48:373553void RenderView::OnMessageFromExternalHost(const std::string& message,
3554 const std::string& origin,
3555 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153556 if (message.empty())
3557 return;
3558
[email protected]28790922009-03-09 19:48:373559 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3560 target);
[email protected]3ac14a052008-08-15 21:22:153561}
3562
[email protected]0aa55312008-10-17 21:53:083563void RenderView::OnDisassociateFromPopupCount() {
3564 if (decrement_shared_popup_at_destruction_)
3565 shared_popup_counter_->data--;
3566 shared_popup_counter_ = new SharedRenderViewCounter(0);
3567 decrement_shared_popup_at_destruction_ = false;
3568}
3569
[email protected]15d79e12009-08-02 19:23:453570bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3571 const WebURLError& error,
3572 bool replace) {
3573 // We only show alternate error pages in the main frame. They are
3574 // intended to assist the user when navigating, so there is not much
3575 // value in showing them for failed subframes. Ideally, we would be
3576 // able to use the TYPED transition type for this, but that flag is
3577 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453578 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453579 return false;
3580
3581 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373582 // connection failure.
[email protected]15d79e12009-08-02 19:23:453583 int ec = error.reason;
3584 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3585 ec != net::ERR_CONNECTION_FAILED &&
3586 ec != net::ERR_CONNECTION_REFUSED &&
3587 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373588 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453589 return false;
3590
3591 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553592 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453593 if (!error_page_url.is_valid())
3594 return false;
3595
3596 // Load an empty page first so there is an immediate response to the error,
3597 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453598 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453599 GURL(kUnreachableWebDataURL),
3600 error.unreachableURL,
3601 replace);
3602
3603 // Now, create a fetcher for the error page and associate it with the data
3604 // source we just created via the LoadHTMLString call. That way if another
3605 // navigation occurs, the fetcher will get destroyed.
3606 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453607 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453608 navigation_state->set_alt_error_page_fetcher(
3609 new AltErrorPageResourceFetcher(
3610 error_page_url, frame, error,
3611 NewCallback(this, &RenderView::AltErrorPageFinished)));
3612 return true;
3613}
3614
initial.commit09911bf2008-07-26 23:55:293615std::string RenderView::GetAltHTMLForTemplate(
3616 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393617 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293618 ResourceBundle::GetSharedInstance().GetRawDataResource(
3619 template_resource_id));
3620
3621 if (template_html.empty()) {
3622 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3623 return "";
3624 }
[email protected]7cd22a52009-07-14 00:40:253625
initial.commit09911bf2008-07-26 23:55:293626 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253627 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293628 template_html, &error_strings, "t");
3629}
[email protected]0e79b9e2009-02-13 04:20:483630
[email protected]15d79e12009-08-02 19:23:453631void RenderView::AltErrorPageFinished(WebFrame* frame,
3632 const WebURLError& original_error,
3633 const std::string& html) {
3634 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553635
3636 // If we failed to download the alternate error page, fall back to the
3637 // original error page if present. Otherwise, LoadNavigationErrorPage
3638 // will simply display a default error page.
3639 const std::string* html_to_load = &html;
3640 if (html.empty()) {
3641 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453642 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553643 html_to_load = &navigation_state->postponed_data();
3644 }
3645 LoadNavigationErrorPage(
3646 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453647}
3648
[email protected]30f75e62009-02-25 22:01:003649void RenderView::OnMoveOrResizeStarted() {
3650 if (webview())
[email protected]acca2a12009-10-16 03:53:393651 webview()->hideAutofillPopup();
[email protected]30f75e62009-02-25 22:01:003652}
3653
[email protected]30f75e62009-02-25 22:01:003654void RenderView::OnResize(const gfx::Size& new_size,
3655 const gfx::Rect& resizer_rect) {
3656 if (webview())
[email protected]acca2a12009-10-16 03:53:393657 webview()->hideAutofillPopup();
[email protected]30f75e62009-02-25 22:01:003658 RenderWidget::OnResize(new_size, resizer_rect);
3659}
[email protected]0aa477bd2009-03-23 22:21:433660
[email protected]05d478752009-04-08 23:38:163661void RenderView::OnClearFocusedNode() {
3662 if (webview())
[email protected]26aa0482009-09-30 16:55:273663 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163664}
3665
[email protected]699ab0d2009-04-23 23:19:143666void RenderView::OnSetBackground(const SkBitmap& background) {
3667 if (webview())
[email protected]b4bb2502009-10-01 22:35:273668 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143669
3670 SetBackground(background);
3671}
3672
[email protected]8c66c5a2009-07-22 17:26:343673void RenderView::OnSetActive(bool active) {
3674 if (webview())
[email protected]b4bb2502009-10-01 22:35:273675 webview()->setIsActive(active);
[email protected]8c66c5a2009-07-22 17:26:343676}
3677
[email protected]309d7a282009-03-24 09:18:273678void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:583679 const ListValue& args,
[email protected]c6619182009-05-12 14:59:323680 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473681 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323682 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473683 has_callback));
[email protected]309d7a282009-03-24 09:18:273684}
3685
[email protected]c6619182009-05-12 14:59:323686void RenderView::OnExtensionResponse(int request_id,
3687 bool success,
3688 const std::string& response,
3689 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353690 ExtensionProcessBindings::HandleResponse(
3691 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273692}
[email protected]c20210e62009-04-03 21:39:263693
[email protected]078b34612009-09-19 19:31:513694void RenderView::InjectToolstripCSS() {
3695 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3696 return;
3697
3698 static const base::StringPiece toolstrip_css(
3699 ResourceBundle::GetSharedInstance().GetRawDataResource(
3700 IDR_EXTENSION_TOOLSTRIP_CSS));
3701 std::string css = toolstrip_css.as_string();
3702 InsertCSS(L"", css, "ToolstripDefaultCSS");
3703}
3704
[email protected]7120f132009-07-20 21:05:373705void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3706 const ListValue& args) {
3707 RendererExtensionBindings::Invoke(function_name, args, this);
3708}
3709
[email protected]e7e4f3c2009-04-21 15:24:083710// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263711//
[email protected]7a9b51f2009-06-29 21:28:293712// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263713// The time points we keep are
3714// request: time document was requested by user
3715// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253716// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293717// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263718// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293719// first_paint: first paint performed
3720// first_paint_after_load: first paint performed after load is finished
3721// begin: request if it was user requested, start otherwise
3722//
[email protected]c20210e62009-04-03 21:39:263723// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253724// request->start,
[email protected]7a9b51f2009-06-29 21:28:293725// start->commit,
3726// commit->finish_document,
3727// finish_document->finish,
3728// begin->commit,
3729// begin->finishDoc,
3730// begin->finish,
3731// begin->first_paint,
3732// begin->first_paint_after_load
3733// commit->finishDoc,
3734// commit->first_paint,
3735// commit->first_paint_after_load,
3736// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263737//
[email protected]e7e4f3c2009-04-21 15:24:083738// It's possible for the request time not to be set, if a client
3739// redirect had been done (the user never requested the page)
3740// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:293741// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:263742void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:273743 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:563744 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453745 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:293746 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:563747
[email protected]7a9b51f2009-06-29 21:28:293748 // If we've already dumped or we haven't finished loading, do nothing.
3749 if (navigation_state->load_histograms_recorded() || finish.is_null())
3750 return;
[email protected]ed3fb032009-06-16 19:50:563751
[email protected]f8999642009-10-27 21:39:423752 LogNavigationState(navigation_state, main_frame->dataSource());
3753
[email protected]a7ccc4d2010-01-27 08:14:483754 NavigationState::LoadType load_type = navigation_state->load_type();
3755 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
3756 NavigationState::LOAD_TYPE_MAX);
3757
[email protected]7a9b51f2009-06-29 21:28:293758 Time request = navigation_state->request_time();
3759 Time start = navigation_state->start_load_time();
3760 Time commit = navigation_state->commit_load_time();
3761 Time finish_doc = navigation_state->finish_document_load_time();
3762 Time first_paint = navigation_state->first_paint_time();
3763 Time first_paint_after_load =
3764 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:263765
[email protected]7a9b51f2009-06-29 21:28:293766 Time begin;
3767 // Client side redirects will have no request time.
3768 if (request.is_null()) {
3769 begin = start;
3770 } else {
3771 begin = request;
3772 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:083773 }
[email protected]7a9b51f2009-06-29 21:28:293774 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
3775 UMA_HISTOGRAM_MEDIUM_TIMES(
3776 "Renderer4.CommitToFinishDoc", finish_doc - commit);
3777 UMA_HISTOGRAM_MEDIUM_TIMES(
3778 "Renderer4.FinishDocToFinish", finish - finish_doc);
3779
3780 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:483781
3782 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
3783 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
3784 static const size_t kBeginToFinishDocBucketCount(100);
3785
3786 TimeDelta begin_to_finish_doc = finish_doc - begin;
3787 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
3788 switch (load_type) {
3789 case NavigationState::UNDEFINED_LOAD:
3790 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
3791 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3792 kBeginToFinishDocBucketCount);
3793 break;
3794 case NavigationState::RELOAD:
3795 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
3796 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3797 kBeginToFinishDocBucketCount);
3798 break;
3799 case NavigationState::HISTORY_LOAD:
3800 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
3801 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3802 kBeginToFinishDocBucketCount);
3803 break;
3804 case NavigationState::NORMAL_LOAD:
3805 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
3806 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3807 kBeginToFinishDocBucketCount);
3808 break;
3809 case NavigationState::LINK_LOAD:
3810 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoad",
3811 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3812 kBeginToFinishDocBucketCount);
3813 break;
3814 default:
3815 break;
3816 }
3817
3818 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
3819 !FieldTrialList::Find("DnsImpact")->group_name().empty());
3820 if (use_dns_histogram) {
3821 switch (load_type) {
3822 case NavigationState::NORMAL_LOAD:
3823 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
3824 "Renderer4.BeginToFinishDoc_NormalLoad", "DnsImpact"),
3825 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3826 kBeginToFinishDocBucketCount);
3827 break;
3828 case NavigationState::LINK_LOAD:
3829 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
3830 "Renderer4.BeginToFinishDoc_LinkLoad", "DnsImpact"),
3831 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3832 kBeginToFinishDocBucketCount);
3833 break;
3834 default:
3835 break;
3836 }
3837 }
3838
3839 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
3840 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
3841 if (use_sdch_histogram) {
3842 switch (load_type) {
3843 case NavigationState::NORMAL_LOAD:
3844 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
3845 "Renderer4.BeginToFinishDoc_NormalLoad", "GlobalSdch"),
3846 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3847 kBeginToFinishDocBucketCount);
3848 break;
3849 case NavigationState::LINK_LOAD:
3850 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
3851 "Renderer4.BeginToFinishDoc_LinkLoad", "GlobalSdch"),
3852 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3853 kBeginToFinishDocBucketCount);
3854 break;
3855 default:
3856 break;
3857 }
3858 }
3859
3860 static bool use_socket_late_binding_histogram =
3861 FieldTrialList::Find("SocketLateBinding") &&
3862 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
3863 if (use_socket_late_binding_histogram) {
3864 switch (load_type) {
3865 case NavigationState::NORMAL_LOAD:
3866 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
3867 "Renderer4.BeginToFinishDoc_NormalLoad", "SocketLateBinding"),
3868 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3869 kBeginToFinishDocBucketCount);
3870 break;
3871 case NavigationState::LINK_LOAD:
3872 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
3873 "Renderer4.BeginToFinishDoc_LinkLoad", "SocketLateBinding"),
3874 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3875 kBeginToFinishDocBucketCount);
3876 break;
3877 default:
3878 break;
3879 }
3880 }
3881
3882 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
3883 !FieldTrialList::Find("CacheSize")->group_name().empty());
3884 if (use_cache_histogram1 && NavigationState::LINK_LOAD == load_type)
3885 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
3886 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
3887 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
3888 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:543889
3890 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
3891 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
3892 static const size_t kBeginToFinishBucketCount(100);
3893
3894 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish",
3895 finish - begin, kBeginToFinishMin,
3896 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]0a32257a2009-07-09 18:10:413897 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
3898 finish - start, kBeginToFinishMin,
3899 kBeginToFinishMax, kBeginToFinishBucketCount);
3900 if (!request.is_null())
3901 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
3902 finish - request, kBeginToFinishMin,
3903 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:543904
[email protected]7a9b51f2009-06-29 21:28:293905 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
3906
3907 if (!first_paint.is_null()) {
3908 UMA_HISTOGRAM_MEDIUM_TIMES(
3909 "Renderer4.BeginToFirstPaint", first_paint - begin);
3910 UMA_HISTOGRAM_MEDIUM_TIMES(
3911 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:263912 }
[email protected]7a9b51f2009-06-29 21:28:293913
3914 if (!first_paint_after_load.is_null()) {
3915 UMA_HISTOGRAM_MEDIUM_TIMES(
3916 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
3917 UMA_HISTOGRAM_MEDIUM_TIMES(
3918 "Renderer4.CommitToFirstPaintAfterLoad",
3919 first_paint_after_load - commit);
3920 UMA_HISTOGRAM_MEDIUM_TIMES(
3921 "Renderer4.FinishToFirstPaintAfterLoad",
3922 first_paint_after_load - finish);
3923 }
3924
3925 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:413926
3927 // Since there are currently no guarantees that renderer histograms will be
3928 // sent to the browser, we initiate a PostTask here to be sure that we send
3929 // the histograms we generated. Without this call, pages that don't have an
3930 // on-close-handler might generate data that is lost when the renderer is
3931 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:483932 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
3933 // should post when the onload is complete, so that it doesn't interfere with
3934 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:413935 if (RenderThread::current()) {
3936 RenderThread::current()->SendHistograms(
3937 HistogramSynchronizer::kReservedSequenceNumber);
3938 }
[email protected]c20210e62009-04-03 21:39:263939}
[email protected]e846d0d2009-05-20 00:53:063940
[email protected]f8999642009-10-27 21:39:423941void RenderView::LogNavigationState(const NavigationState* state,
3942 const WebDataSource* ds) const {
3943 // Because this function gets called on every page load,
3944 // take extra care to optimize it away if logging is turned off.
3945 if (logging::LOG_INFO < logging::GetMinLogLevel())
3946 return;
3947
3948 DCHECK(state);
3949 DCHECK(ds);
3950 GURL url(ds->request().url());
3951 Time start = state->start_load_time();
3952 Time finish = state->finish_load_time();
3953 // TODO(mbelshe): should we log more stats?
3954 LOG(INFO) << "PLT: "
3955 << (finish - start).InMilliseconds()
3956 << "ms "
3957 << url.spec();
3958}
3959
[email protected]cc0445f2009-10-13 16:09:083960void RenderView::focusAccessibilityObject(
3961 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:063962#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153963 // TODO(dglazkov): Current logic implies that focus change can only be made
3964 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
3965 // where accessibility is initialized. We should determine whether that's
3966 // right.
3967 if (!accessibility_.get())
3968 return;
[email protected]e846d0d2009-05-20 00:53:063969
3970 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:153971 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:063972
3973 // If id is valid, alert the browser side that an accessibility focus change
3974 // occurred.
3975 if (acc_obj_id >= 0)
3976 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
3977
3978#else // defined(OS_WIN)
3979 // TODO(port): accessibility not yet implemented
3980 NOTIMPLEMENTED();
3981#endif
3982}
[email protected]daa8c58e2009-06-15 17:21:103983
3984void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:483985 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:453986 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:103987
3988 std::vector<PasswordForm> password_forms;
3989 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:483990 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:103991
3992 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:483993 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:103994 scoped_ptr<PasswordForm> password_form(
3995 PasswordFormDomManager::CreatePasswordForm(form));
3996 if (password_form.get())
3997 password_forms.push_back(*password_form);
3998 }
3999 }
4000
4001 if (!password_forms.empty())
4002 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4003}
[email protected]0fda7272009-06-26 15:49:334004
4005void RenderView::Print(WebFrame* frame, bool script_initiated) {
4006 DCHECK(frame);
4007 if (print_helper_.get() == NULL) {
4008 print_helper_.reset(new PrintWebViewHelper(this));
4009 }
4010 print_helper_->Print(frame, script_initiated);
4011}
[email protected]446705872009-09-10 07:22:484012
4013void RenderView::OnSetEditCommandsForNextKeyEvent(
4014 const EditCommands& edit_commands) {
4015 edit_commands_ = edit_commands;
4016}
4017
[email protected]61f5a7b2009-12-22 22:21:204018void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274019 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354020 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204021 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4022 false));
[email protected]912256b32009-09-18 09:47:354023 return;
4024 }
4025
[email protected]fa7b6b542009-11-03 05:02:304026 WebDataSource* ds = main_frame->dataSource();
4027 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4028 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204029 pending_code_execution_queue_.push(
4030 linked_ptr<ViewMsg_ExecuteCode_Params>(
4031 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304032 return;
4033 }
4034
[email protected]61f5a7b2009-12-22 22:21:204035 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304036}
4037
4038void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204039 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484040 // Don't execute scripts in gallery pages.
4041 GURL frame_url = GURL(frame->url());
4042 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4043 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4044 return;
4045 }
4046
[email protected]20ad2692009-11-20 18:27:204047 std::vector<WebFrame*> frame_vector;
4048 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204049 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204050 GetAllChildFrames(frame, &frame_vector);
4051
4052 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4053 frame_it != frame_vector.end(); ++frame_it) {
4054 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204055 if (params.is_javascript) {
4056 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4057 continue;
4058
[email protected]20ad2692009-11-20 18:27:204059 std::vector<WebScriptSource> sources;
4060 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204061 WebScriptSource(WebString::fromUTF8(params.code)));
4062 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204063 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204064 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204065 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4066 } else {
[email protected]61f5a7b2009-12-22 22:21:204067 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204068 }
[email protected]912256b32009-09-18 09:47:354069 }
4070
[email protected]61f5a7b2009-12-22 22:21:204071 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354072}
4073
[email protected]60c42a8c72009-10-09 04:08:594074void RenderView::Close() {
4075 // We need to grab a pointer to the doomed WebView before we destroy it.
4076 WebView* doomed = webview();
4077 RenderWidget::Close();
4078 Singleton<ViewMap>::get()->erase(doomed);
4079}
4080
[email protected]446705872009-09-10 07:22:484081void RenderView::DidHandleKeyEvent() {
4082 edit_commands_.clear();
4083}
4084
[email protected]83dde542009-09-11 20:59:554085void RenderView::EnsureDocumentTag() {
4086 // TODO(darin): There's actually no reason for this to be here. We should
4087 // have the browser side manage the document tag.
4088#if defined(OS_MACOSX)
4089 if (!has_document_tag_) {
4090 // Make the call to get the tag.
4091 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4092 has_document_tag_ = true;
4093 }
4094#endif
4095}
[email protected]12636df2009-09-28 22:32:214096
4097bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]8beff0762009-09-29 02:18:304098 PluginChannelHost::Broadcast(
4099 new PluginMsg_SignalModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:214100
4101 message->EnableMessagePumping(); // Runs a nested message loop.
4102 bool rv = Send(message);
4103
[email protected]8beff0762009-09-29 02:18:304104 PluginChannelHost::Broadcast(
4105 new PluginMsg_ResetModalDialogEvent(host_window_));
[email protected]12636df2009-09-28 22:32:214106
4107 return rv;
4108}