blob: 6985c289379385f10a10e1e60d5bea412647f1fb [file] [log] [blame]
[email protected]810a52ef2010-01-08 01:22:151// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
8#include <string>
9#include <vector>
10
[email protected]91e81ae2009-05-08 22:14:3811#include "app/gfx/color_utils.h"
[email protected]37126212009-05-06 02:23:3112#include "app/gfx/favicon_size.h"
[email protected]010ea08a2009-10-11 20:21:3213#include "app/gfx/native_widget_types.h"
[email protected]a92b8642009-05-05 23:38:5614#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3115#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1116#include "app/resource_bundle.h"
[email protected]2041cf342010-02-19 03:15:5917#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2918#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5019#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0520#include "base/field_trial.h"
[email protected]30507922010-01-15 16:48:2321#include "base/histogram.h"
[email protected]8380c092009-06-25 17:45:5122#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5323#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2924#include "base/string_piece.h"
25#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2326#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5727#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0928#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5529#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1731#include "chrome/common/chrome_constants.h"
[email protected]1f4fc8e8c2010-01-02 00:46:4132#include "chrome/common/histogram_synchronizer.h"
[email protected]d146b832009-12-23 02:45:4833#include "chrome/common/extensions/extension_constants.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1735#include "chrome/common/page_zoom.h"
[email protected]e09ba552009-02-05 03:26:2936#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2637#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5939#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2940#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2541#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1142#include "chrome/renderer/devtools_agent.h"
43#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3544#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3245#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3546#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3747#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2848#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5650#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ed3fb032009-06-16 19:50:5651#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1252#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3053#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5054#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2555#include "chrome/renderer/render_process.h"
[email protected]bd92c3a2010-01-13 05:02:3456#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4657#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3558#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2960#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2961#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4262#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5663#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:2764#include "grit/generated_resources.h"
65#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3466#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2967#include "net/base/escape.h"
68#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0069#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1070#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3071#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]58c321d2010-02-19 12:11:2872#include "third_party/WebKit/WebKit/chromium/public/GeolocationServiceBridgeChromium.h"
[email protected]418ed5ab2009-11-12 01:14:4973#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
74#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0775#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4976#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
77#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3278#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4979#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3580#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]418ed5ab2009-11-12 01:14:4981#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
82#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
83#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]95056b582010-02-18 01:29:2484#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4985#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3286#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0787#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]418ed5ab2009-11-12 01:14:4988#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
89#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
90#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
92#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
93#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:3495#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:4996#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
98#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
99#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
100#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]80f584d92010-01-21 03:59:04102#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29103#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29104#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24105#include "webkit/glue/form_field.h"
106#include "webkit/glue/form_field_values.h"
107#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34108#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17109#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51110#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29111#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29112#include "webkit/glue/plugins/plugin_list.h"
[email protected]8a3b7962009-09-04 05:53:23113#include "webkit/glue/plugins/webplugin_delegate_impl.h"
initial.commit09911bf2008-07-26 23:55:29114#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29115#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17116#include "webkit/glue/webmediaplayer_impl.h"
[email protected]f103ab72009-09-02 17:10:59117#include "webkit/glue/webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29118
[email protected]6c8afae52009-01-22 02:24:57119#if defined(OS_WIN)
120// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57121// * theming
[email protected]86281ad2009-10-07 20:07:17122#include "app/gfx/native_theme_win.h"
[email protected]39cd64ed2010-02-05 02:18:46123#elif defined(OS_LINUX)
124#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]6c8afae52009-01-22 02:24:57125#endif
126
[email protected]80f584d92010-01-21 03:59:04127using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26128using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33129using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45130using webkit_glue::AltErrorPageResourceFetcher;
[email protected]95056b582010-02-18 01:29:24131using webkit_glue::FormField;
[email protected]51bd36612009-10-20 22:49:47132using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17133using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56134using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10135using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15136using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08137using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41138using WebKit::WebColor;
139using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59140using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44141using WebKit::WebContextMenuData;
[email protected]d9ec5c0f2009-12-23 11:55:07142using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55143using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28144using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29145using WebKit::WebDevToolsAgent;
[email protected]e80c73b2009-04-07 23:24:58146using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25147using WebKit::WebDragOperation;
148using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51149using WebKit::WebEditingAction;
[email protected]6069da8c2009-10-20 20:33:49150using WebKit::WebFindOptions;
[email protected]979c28b2009-11-07 01:30:48151using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45152using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17153using WebKit::WebHistoryItem;
[email protected]95056b582010-02-18 01:29:24154using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17155using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28156using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17157using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28158using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28159using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51160using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07161using WebKit::WebPageSerializer;
162using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17163using WebKit::WebPlugin;
164using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52165using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59166using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51167using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52168using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40169using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35170using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29171using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59172using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42173using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02174using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34175using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28176using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51177using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52178using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28179using WebKit::WebURL;
180using WebKit::WebURLError;
181using WebKit::WebURLRequest;
182using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28183using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03184using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28185using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43186using WebKit::WebWorker;
187using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33188
initial.commit09911bf2008-07-26 23:55:29189//-----------------------------------------------------------------------------
190
191// define to write the time necessary for thumbnail/DOM text retrieval,
192// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29193// #define TIME_TEXT_RETRIEVAL
194
195// maximum number of characters in the document to index, any text beyond this
196// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57197static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29198
199// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37200static const int kThumbnailWidth = 212;
201static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29202
203// Delay in milliseconds that we'll wait before capturing the page contents
204// and thumbnail.
205static const int kDelayForCaptureMs = 500;
206
207// Typically, we capture the page data once the page is loaded.
208// Sometimes, the page never finishes to load, preventing the page capture
209// To workaround this problem, we always perform a capture after the following
210// delay.
211static const int kDelayForForcedCaptureMs = 6000;
212
[email protected]882daa92009-11-05 16:31:31213// Time, in seconds, we delay before sending content state changes (such as form
214// state and scroll position) to the browser. We delay sending changes to avoid
215// spamming the browser.
216// To avoid having tab/session restore require sending a message to get the
217// current content state during tab closing we use a shorter timeout for the
218// foreground renderer. This means there is a small window of time from which
219// content state is modified and not sent to session restore, but this is
220// better than having to wake up all renderers during shutdown.
221static const int kDelaySecondsForContentStateSyncHidden = 5;
222static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29223
[email protected]0aa55312008-10-17 21:53:08224// The maximum number of popups that can be spawned from one page.
225static const int kMaximumNumberOfUnacknowledgedPopups = 25;
226
initial.commit09911bf2008-07-26 23:55:29227static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16228 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29229
[email protected]50b691c2008-10-31 19:08:35230static const char* const kBackForwardNavigationScheme = "history";
231
[email protected]8c4cdd42010-01-12 21:31:13232// The string returned in DetectLanguage if we failed to detect the language.
[email protected]8dc5a2052010-01-19 21:32:42233static const char* const kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13234
[email protected]726985e22009-06-18 21:09:28235static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
236 WebVector<WebURL> urls;
237 ds->redirectChain(urls);
238 result->reserve(urls.size());
239 for (size_t i = 0; i < urls.size(); ++i)
240 result->push_back(urls[i]);
241}
242
[email protected]61f5a7b2009-12-22 22:21:20243static bool UrlMatchesPermissions(
244 const GURL& url, const std::vector<URLPattern>& host_permissions) {
245 for (size_t i = 0; i < host_permissions.size(); ++i) {
246 if (host_permissions[i].MatchesUrl(url))
247 return true;
248 }
249
250 return false;
251}
252
[email protected]30507922010-01-15 16:48:23253static bool PaintViewIntoCanvas(WebView* view,
254 skia::PlatformCanvas& canvas) {
255 view->layout();
256 const WebSize& size = view->size();
257
258 if (!canvas.initialize(size.width, size.height, true))
259 return false;
260
261 view->paint(webkit_glue::ToWebCanvas(&canvas),
262 WebRect(0, 0, size.width, size.height));
263 // TODO: Add a way to snapshot the whole page, not just the currently
264 // visible part.
265
266 return true;
267}
268
269// Calculates how "boring" a thumbnail is. The boring score is the
270// 0,1 ranged percentage of pixels that are the most common
271// luma. Higher boring scores indicate that a higher percentage of a
272// bitmap are all the same brightness.
273static double CalculateBoringScore(SkBitmap* bitmap) {
274 int histogram[256] = {0};
275 color_utils::BuildLumaHistogram(bitmap, histogram);
276
277 int color_count = *std::max_element(histogram, histogram + 256);
278 int pixel_count = bitmap->width() * bitmap->height();
279 return static_cast<double>(color_count) / pixel_count;
280}
281
initial.commit09911bf2008-07-26 23:55:29282///////////////////////////////////////////////////////////////////////////////
283
[email protected]60c42a8c72009-10-09 04:08:59284int32 RenderView::next_page_id_ = 1;
285
[email protected]2fab253a2009-08-17 23:00:59286RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34287 const WebPreferences& webkit_preferences,
288 int64 session_storage_namespace_id)
[email protected]81a34412009-01-05 19:17:24289 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09290 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21291 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24292 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21293 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24294 page_id_(-1),
295 last_page_id_sent_to_browser_(-1),
296 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24297 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46298 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50299 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11300 devtools_agent_(NULL),
301 devtools_client_(NULL),
[email protected]a1128322009-10-06 18:38:46302 file_chooser_completion_(NULL),
[email protected]81a34412009-01-05 19:17:24303 history_back_list_count_(0),
304 history_forward_list_count_(0),
[email protected]81a34412009-01-05 19:17:24305 has_unload_listener_(false),
306 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39307 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24308 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26309 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31310 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25311 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26312 ALLOW_THIS_IN_INITIALIZER_LIST(
313 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53314 view_type_(ViewType::INVALID),
315 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55316 last_top_level_navigation_page_id_(-1),
317#if defined(OS_MACOSX)
318 has_document_tag_(false),
319#endif
[email protected]98324892009-09-09 21:16:05320 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32321 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34322 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]0bedb8a2010-01-14 19:36:32323 ALLOW_THIS_IN_INITIALIZER_LIST(text_translator_(this)) {
[email protected]71b0d5d2010-02-15 05:43:07324 ClearBlockedContentSettings();
[email protected]7e0831b2010-02-01 08:45:15325 page_translator_.reset(new PageTranslator(&text_translator_, this));
initial.commit09911bf2008-07-26 23:55:29326}
327
328RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08329 if (decrement_shared_popup_at_destruction_)
330 shared_popup_counter_->data--;
331
[email protected]b0950a72009-09-29 23:16:17332 // Dispose of un-disposed image fetchers.
333 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
334 i != image_fetchers_.end(); ++i) {
335 delete *i;
336 }
337
[email protected]a1128322009-10-06 18:38:46338 // If file chooser is still waiting for answer, dispatch empty answer.
339 if (file_chooser_completion_)
340 file_chooser_completion_->didChooseFile(WebVector<WebString>());
341
[email protected]83dde542009-09-11 20:59:55342#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05343 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55344 if (has_document_tag_)
345 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
346#endif
[email protected]98324892009-09-09 21:16:05347
[email protected]5fb88962009-04-16 19:03:25348 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59349
350#ifndef NDEBUG
351 // Make sure we are no longer referenced by the ViewMap.
352 ViewMap* views = Singleton<ViewMap>::get();
353 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
354 DCHECK_NE(this, it->second) << "Failed to call Close?";
355#endif
356}
357
358/*static*/
359void RenderView::ForEach(RenderViewVisitor* visitor) {
360 ViewMap* views = Singleton<ViewMap>::get();
361 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
362 if (!visitor->Visit(it->second))
363 return;
364 }
365}
366
367/*static*/
368RenderView* RenderView::FromWebView(WebView* webview) {
369 ViewMap* views = Singleton<ViewMap>::get();
370 ViewMap::iterator it = views->find(webview);
371 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29372}
373
374/*static*/
[email protected]0aa55312008-10-17 21:53:08375RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24376 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15377 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08378 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51379 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08380 const WebPreferences& webkit_prefs,
381 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34382 int32 routing_id,
383 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29384 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34385 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
386 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29387 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29388 opener_id,
[email protected]80d96fa2009-06-10 22:34:51389 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08390 counter,
initial.commit09911bf2008-07-26 23:55:29391 routing_id); // adds reference
392 return view;
393}
394
395/*static*/
396void RenderView::SetNextPageID(int32 next_page_id) {
397 // This method should only be called during process startup, and the given
398 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05399 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29400 DCHECK(next_page_id >= next_page_id_);
401 next_page_id_ = next_page_id;
402}
403
[email protected]afe3a1672009-11-17 19:04:12404void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56405 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
406}
407
[email protected]a3a8fb6d2009-10-22 20:12:51408void RenderView::PluginCrashed(const FilePath& plugin_path) {
409 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29410}
411
[email protected]d8fd6fa2010-02-01 15:54:26412#if defined(OS_MACOSX)
413void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
414 plugin_delegates_.insert(delegate);
415}
416
417void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
418 plugin_delegates_.erase(delegate);
419}
420#endif
421
[email protected]18bcc3c2009-01-27 21:39:15422void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29423 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51424 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08425 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29426 int32 routing_id) {
427 DCHECK(!webview());
428
429 if (opener_id != MSG_ROUTING_NONE)
430 opener_id_ = opener_id;
431
[email protected]0aa55312008-10-17 21:53:08432 if (counter) {
433 shared_popup_counter_ = counter;
434 shared_popup_counter_->data++;
435 decrement_shared_popup_at_destruction_ = true;
436 } else {
437 shared_popup_counter_ = new SharedRenderViewCounter(0);
438 decrement_shared_popup_at_destruction_ = false;
439 }
440
[email protected]58bfc6b2009-06-24 09:45:02441 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04442
[email protected]50ae00ef2009-10-19 05:11:03443 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59444 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59445 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27446 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29447 webview()->setDevToolsAgent(
448 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29449
[email protected]d3ba77272009-09-03 00:06:09450 OnSetRendererPrefs(renderer_prefs);
451
initial.commit09911bf2008-07-26 23:55:29452 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24453 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29454 // Take a reference on behalf of the RenderThread. This will be balanced
455 // when we receive ViewMsg_Close.
456 AddRef();
457
458 // If this is a popup, we must wait for the CreatingNew_ACK message before
459 // completing initialization. Otherwise, we can finish it now.
460 if (opener_id == MSG_ROUTING_NONE) {
461 did_show_ = true;
462 CompleteInit(parent_hwnd);
463 }
464
465 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29466
[email protected]58bfc6b2009-06-24 09:45:02467 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09468 if (command_line.HasSwitch(switches::kDomAutomationController))
469 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29470
[email protected]5fb88962009-04-16 19:03:25471 audio_message_filter_ = new AudioMessageFilter(routing_id_);
472 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29473}
474
475void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27476 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27477 if (main_frame)
478 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26479
[email protected]b2abac72009-02-26 12:39:28480 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11481 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28482 return;
[email protected]b4b967e2009-04-22 11:33:05483 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
484 return;
[email protected]b6849bda2009-10-14 23:59:26485 if (notification_provider_->OnMessageReceived(message))
486 return;
[email protected]58c321d2010-02-19 12:11:28487 if (geolocation_dispatcher_.get() &&
488 geolocation_dispatcher_->OnMessageReceived(message)) {
489 return;
490 }
[email protected]b2abac72009-02-26 12:39:28491
initial.commit09911bf2008-07-26 23:55:29492 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29493 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23494 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29495 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01496 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29497 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
498 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56499 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29500 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
501 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
502 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
503 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
504 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
505 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27506#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35507 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27508#endif
initial.commit09911bf2008-07-26 23:55:29509 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
510 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05511 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
512 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
513 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04514 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29515 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
516 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
517 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15518 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29519 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]630e26b2008-10-14 22:55:17520 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]f85f0702010-01-30 09:31:01521 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost,
522 OnSetContentSettingsForLoadingHost)
[email protected]40bd6582009-12-04 23:49:51523 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
524 OnSetZoomLevelForLoadingHost)
initial.commit09911bf2008-07-26 23:55:29525 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18526 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
527 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28528 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33529 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29530 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48531 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29532 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29533 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29534 IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill)
535 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
536 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
537 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
538 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
539 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45540 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29541 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50542 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
543 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29544 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
545 OnDragSourceSystemDragEnded)
546 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
547 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
548 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
549 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
550 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
551 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
552 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
553 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
554 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount,
555 OnUpdateBackForwardListCount)
556 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
557 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04558 IPC_MESSAGE_HANDLER(
559 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
560 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29561 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50562 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
563 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
564 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29565 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
566 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
567 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45568 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
569 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08570 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
571 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24572 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
573 OnAutoFillSuggestionsReturned)
574 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
575 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48576 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
577 OnAutoFillFormDataFilled)
[email protected]2c4410d2009-05-06 23:46:22578 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
579 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00580 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27581 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37582 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
583 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16584 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14585 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25586 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
587 OnEnablePreferredSizeChangedMode)
[email protected]80d96fa2009-06-10 22:34:51588 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53589 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
590 OnUpdateBrowserWindowId)
591 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
592 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56593 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34594 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14595#if defined(OS_MACOSX)
596 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13597 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14598#endif
[email protected]446705872009-09-10 07:22:48599 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33600 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35601 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
602 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33603 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
604 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42605 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]0bedb8a2010-01-14 19:36:32606 IPC_MESSAGE_HANDLER(ViewMsg_TranslateTextReponse, OnTranslateTextResponse)
[email protected]634a6f92008-12-01 21:39:31607
initial.commit09911bf2008-07-26 23:55:29608 // Have the super handle all other messages.
609 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
610 IPC_END_MESSAGE_MAP()
611}
612
initial.commit09911bf2008-07-26 23:55:29613void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27614 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29615 if (!main_frame)
616 return;
617
618 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45619 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29620 if (url.is_empty())
621 return;
622
623 if (size_.IsEmpty())
624 return; // Don't create an empty thumbnail!
625
626 ThumbnailScore score;
627 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02628 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15629 &thumbnail, &score))
630 return;
631
initial.commit09911bf2008-07-26 23:55:29632 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46633 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29634}
635
[email protected]30507922010-01-15 16:48:23636void RenderView::SendSnapshot() {
637 SkBitmap snapshot;
638 bool error = false;
639
640 WebFrame* main_frame = webview()->mainFrame();
641 if (!main_frame)
642 error = true;
643
644 if (!error && !CaptureSnapshot(webview(), &snapshot))
645 error = true;
646
647 DCHECK(error == snapshot.empty()) <<
648 "Snapshot should be empty on error, non-empty otherwise.";
649
650 // Send the snapshot to the browser process.
651 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
652}
653
[email protected]068637222009-01-29 16:58:07654void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29655 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58656 if (webview()) {
657 // If the user has selected text in the currently focused frame we print
658 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27659 if (webview()->focusedFrame()->hasSelection())
660 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58661 else
[email protected]26aa0482009-09-30 16:55:27662 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58663 }
initial.commit09911bf2008-07-26 23:55:29664}
665
[email protected]82270452009-06-19 15:58:01666void RenderView::OnPrintingDone(int document_cookie, bool success) {
667 // Ignoring document cookie here since only one print job can be outstanding
668 // per renderer and document_cookie is 0 when printing is successful.
669 DCHECK(print_helper_.get());
670 if (print_helper_.get() != NULL) {
671 print_helper_->DidFinishPrinting(success);
672 }
673}
674
initial.commit09911bf2008-07-26 23:55:29675void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
676 if (load_id != page_id_)
677 return; // this capture call is no longer relevant due to navigation
678 if (load_id == last_indexed_page_id_)
679 return; // we already indexed this page
680
681 if (!webview())
682 return;
683
[email protected]26aa0482009-09-30 16:55:27684 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29685 if (!main_frame)
686 return;
687
688 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45689 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29690 return;
691
692 // Don't index/capture pages that failed to load. This only checks the top
693 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45694 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28695 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29696 return;
697
698 if (!preliminary_capture)
699 last_indexed_page_id_ = load_id;
700
[email protected]a8a81292010-01-21 00:32:45701 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45702 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29703 if (url.is_empty())
704 return;
705
[email protected]a8a81292010-01-21 00:32:45706 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29707 std::wstring contents;
708 CaptureText(main_frame, &contents);
709 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45710 base::TimeTicks begin_time = base::TimeTicks::Now();
711 std::string language = DetermineTextLanguage(contents);
712 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
713 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52714
[email protected]a8a81292010-01-21 00:32:45715 // Send the text to the browser for indexing (the browser might decide not
716 // to index, if the URL is HTTPS for instance) and language discovery.
717 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
718 language));
[email protected]5c4266922009-07-10 16:41:27719 }
720
initial.commit09911bf2008-07-26 23:55:29721 // thumbnail
722 SendThumbnail();
723}
724
725void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
726 contents->clear();
727 if (!frame)
728 return;
729
730#ifdef TIME_TEXT_RETRIEVAL
731 double begin = time_util::GetHighResolutionTimeNow();
732#endif
733
734 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45735 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29736
737#ifdef TIME_TEXT_RETRIEVAL
738 double end = time_util::GetHighResolutionTimeNow();
739 char buf[128];
740 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
741 contents.size(), (end - begin)*1000);
742 OutputDebugStringA(buf);
743#endif
744
745 // When the contents are clipped to the maximum, we don't want to have a
746 // partial word indexed at the end that might have been clipped. Therefore,
747 // terminate the string at the last space to ensure no words are clipped.
748 if (contents->size() == kMaxIndexChars) {
749 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
750 if (last_space_index == std::wstring::npos)
751 return; // don't index if we got a huge block of text with no spaces
752 contents->resize(last_space_index);
753 }
754}
755
[email protected]8649fb32009-06-26 17:51:02756bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29757 int w,
758 int h,
759 SkBitmap* thumbnail,
760 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23761 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15762
[email protected]8649fb32009-06-26 17:51:02763 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23764
765 // Paint |view| into |canvas|.
766 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02767 return false;
[email protected]8649fb32009-06-26 17:51:02768
769 skia::BitmapPlatformDevice& device =
770 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
771
772 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29773
[email protected]cab34d6a2009-09-24 01:14:52774 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29775 float dest_aspect = dest_rect.width() / dest_rect.height();
776
777 // Get the src rect so that we can preserve the aspect ratio while filling
778 // the destination.
779 SkIRect src_rect;
780 if (src_bmp.width() < dest_rect.width() ||
781 src_bmp.height() < dest_rect.height()) {
782 // Source image is smaller: we clip the part of source image within the
783 // dest rect, and then stretch it to fill the dest rect. We don't respect
784 // the aspect ratio in this case.
785 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
786 static_cast<S16CPU>(dest_rect.height()));
787 score->good_clipping = false;
788 } else {
789 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
790 if (src_aspect > dest_aspect) {
791 // Wider than tall, clip horizontally: we center the smaller thumbnail in
792 // the wider screen.
793 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
794 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
795 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
796 score->good_clipping = false;
797 } else {
798 src_rect.set(0, 0, src_bmp.width(),
799 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
800 score->good_clipping = true;
801 }
802 }
803
[email protected]26aa0482009-09-30 16:55:27804 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29805
806 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02807 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29808
809 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14810 *thumbnail = skia::ImageOperations::Resize(
811 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29812
813 score->boring_score = CalculateBoringScore(thumbnail);
814
[email protected]30507922010-01-15 16:48:23815 HISTOGRAM_TIMES("Renderer4.Thumbnail",
816 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15817 return true;
initial.commit09911bf2008-07-26 23:55:29818}
819
[email protected]30507922010-01-15 16:48:23820bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
821 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29822
[email protected]30507922010-01-15 16:48:23823 skia::PlatformCanvas canvas;
824 if (!PaintViewIntoCanvas(view, canvas))
825 return false;
826
827 skia::BitmapPlatformDevice& device =
828 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
829
830 const SkBitmap& bitmap = device.accessBitmap(false);
831 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
832 return false;
833
834 HISTOGRAM_TIMES("Renderer4.Snapshot",
835 base::TimeTicks::Now() - beginning_time);
836 return true;
initial.commit09911bf2008-07-26 23:55:29837}
838
839void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
840 if (!webview())
841 return;
842
[email protected]8c785c62009-07-13 14:20:15843 if (devtools_agent_.get())
844 devtools_agent_->OnNavigate();
845
[email protected]422197532010-01-25 17:38:23846 if (notification_provider_.get())
847 notification_provider_->OnNavigate();
848
[email protected]a9f607e2009-10-23 19:59:27849 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26850
initial.commit09911bf2008-07-26 23:55:29851 AboutHandler::MaybeHandle(params.url);
852
[email protected]ecbf10d2010-02-18 13:03:29853 bool is_reload =
854 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
855 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29856
[email protected]26aa0482009-09-30 16:55:27857 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45858 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29859 // We cannot reload if we do not have any history state. This happens, for
860 // example, when recovering from a crash. Our workaround here is a bit of
861 // a hack since it means that reload after a crashed tab does not cause an
862 // end-to-end cache validation.
863 is_reload = false;
864 }
865
[email protected]77f17a82009-05-21 04:42:54866 // A navigation resulting from loading a javascript URL should not be treated
867 // as a browser initiated event. Instead, we want it to look as if the page
868 // initiated any load resulting from JS execution.
869 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30870 NavigationState* state = NavigationState::CreateBrowserInitiated(
871 params.page_id, params.transition, params.request_time);
872 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
873 // We're doing a load of a page that was restored from the last session.
874 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
875 // which can result in stale data for pages that are set to expire. We
876 // explicitly override that by setting the policy here so that as
877 // necessary we load from the network.
878 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
879 }
880 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54881 }
initial.commit09911bf2008-07-26 23:55:29882
[email protected]a7ccc4d2010-01-27 08:14:48883 NavigationState* navigation_state = pending_navigation_state_.get();
884
[email protected]04d3c6e2009-05-22 17:00:13885 // If we are reloading, then WebKit will use the history state of the current
886 // page, so we should just ignore any given history state. Otherwise, if we
887 // have history state, then we need to navigate to it, which corresponds to a
888 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55889 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48890 if (navigation_state)
891 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29892 bool ignore_cache = (params.navigation_type ==
893 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
894 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55895 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13896 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58897 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48898 if (navigation_state)
899 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45900 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17901 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13902 } else {
903 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28904 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29905
[email protected]e6f546c32009-07-01 17:12:55906 // A session history navigation should have been accompanied by state.
907 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13908
[email protected]dd7daa82009-08-10 05:46:45909 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55910 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13911
[email protected]726985e22009-06-18 21:09:28912 if (params.referrer.is_valid()) {
913 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
914 WebString::fromUTF8(params.referrer.spec()));
915 }
[email protected]04d3c6e2009-05-22 17:00:13916
[email protected]a7ccc4d2010-01-27 08:14:48917 if (navigation_state)
918 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45919 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50920 }
921
[email protected]77f17a82009-05-21 04:42:54922 // In case LoadRequest failed before DidCreateDataSource was called.
923 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29924}
925
926// Stop loading the current page
927void RenderView::OnStop() {
928 if (webview())
[email protected]b4bb2502009-10-01 22:35:27929 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29930}
931
[email protected]ecbf10d2010-02-18 13:03:29932// Reload current focused frame.
933// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56934void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29935 if (webview() && webview()->focusedFrame()) {
936 // We always obey the cache (ignore_cache=false) here.
937 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
938 // a cache-ignoring reload of the frame.
939 webview()->focusedFrame()->reload(false);
940 }
[email protected]1dda4022010-01-28 18:24:56941}
942
[email protected]e6f546c32009-07-01 17:12:55943void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29944 bool new_navigation,
945 const GURL& display_url,
946 const std::string& security_info) {
947 if (!webview())
948 return;
949
[email protected]e6f546c32009-07-01 17:12:55950 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
951 new_navigation ? -1 : page_id_, PageTransition::LINK, Time::Now()));
952 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29953
[email protected]26aa0482009-09-30 16:55:27954 webview()->mainFrame()->loadHTMLString(
955 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55956
957 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29958}
959
960void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27961 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29962}
963
[email protected]68b1e922009-06-23 16:00:25964void RenderView::OnExecuteEditCommand(const std::string& name,
965 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27966 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25967 return;
968
[email protected]26aa0482009-09-30 16:55:27969 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45970 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25971}
972
[email protected]b2abac72009-02-26 12:39:28973void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:11974 DCHECK(!devtools_client_.get());
975 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:28976}
977
initial.commit09911bf2008-07-26 23:55:29978void RenderView::OnStopFinding(bool clear_selection) {
979 WebView* view = webview();
980 if (!view)
981 return;
982
983 if (clear_selection)
[email protected]26aa0482009-09-30 16:55:27984 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:29985
[email protected]26aa0482009-09-30 16:55:27986 WebFrame* frame = view->mainFrame();
initial.commit09911bf2008-07-26 23:55:29987 while (frame) {
[email protected]dd7daa82009-08-10 05:46:45988 frame->stopFinding(clear_selection);
[email protected]b4bb2502009-10-01 22:35:27989 frame = frame->traverseNext(false);
initial.commit09911bf2008-07-26 23:55:29990 }
991}
992
993void RenderView::OnFindReplyAck() {
994 // Check if there is any queued up request waiting to be sent.
995 if (queued_find_reply_message_.get()) {
996 // Send the search result over to the browser process.
997 Send(queued_find_reply_message_.get());
998 queued_find_reply_message_.release();
999 }
1000}
1001
1002void RenderView::OnUpdateTargetURLAck() {
1003 // Check if there is a targeturl waiting to be sent.
1004 if (target_url_status_ == TARGET_PENDING) {
1005 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1006 pending_target_url_));
1007 }
1008
1009 target_url_status_ = TARGET_NONE;
1010}
1011
1012void RenderView::OnUndo() {
1013 if (!webview())
1014 return;
1015
[email protected]26aa0482009-09-30 16:55:271016 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121017 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291018}
1019
1020void RenderView::OnRedo() {
1021 if (!webview())
1022 return;
1023
[email protected]26aa0482009-09-30 16:55:271024 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121025 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291026}
1027
1028void RenderView::OnCut() {
1029 if (!webview())
1030 return;
1031
[email protected]26aa0482009-09-30 16:55:271032 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121033 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291034}
1035
1036void RenderView::OnCopy() {
1037 if (!webview())
1038 return;
1039
[email protected]26aa0482009-09-30 16:55:271040 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121041 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291042}
1043
[email protected]c0cc3092009-09-12 08:27:271044#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351045void RenderView::OnCopyToFindPboard() {
1046 if (!webview())
1047 return;
1048
1049 // Since the find pasteboard supports only plain text, this can be simpler
1050 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271051 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351052 if (frame->hasSelection()) {
1053 string16 selection = frame->selectionAsText();
1054 RenderThread::current()->Send(
1055 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1056 }
1057
[email protected]afe3a1672009-11-17 19:04:121058 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351059}
[email protected]c0cc3092009-09-12 08:27:271060#endif
[email protected]a954bf72009-09-12 07:30:351061
initial.commit09911bf2008-07-26 23:55:291062void RenderView::OnPaste() {
1063 if (!webview())
1064 return;
1065
[email protected]26aa0482009-09-30 16:55:271066 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121067 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291068}
1069
[email protected]2a3a7762009-10-19 19:17:321070void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291071 if (!webview())
1072 return;
1073
[email protected]1ff7a032010-02-03 02:46:031074 WebFrame* frame = webview()->focusedFrame();
1075 if (!frame->hasSelection())
1076 frame->selectWordAroundCaret();
1077 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291078}
1079
[email protected]98324892009-09-09 21:16:051080void RenderView::OnAdvanceToNextMisspelling() {
1081 if (!webview())
1082 return;
[email protected]26aa0482009-09-30 16:55:271083 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051084 WebString::fromUTF8("AdvanceToNextMisspelling"));
1085}
1086
1087void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1088 if (!webview())
1089 return;
1090 // We need to tell the webView whether the spelling panel is visible or not so
1091 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261092 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271093 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051094 WebString::fromUTF8("ToggleSpellPanel"));
1095}
1096
[email protected]bbbd545c2008-12-15 20:18:041097void RenderView::OnToggleSpellCheck() {
1098 if (!webview())
1099 return;
1100
[email protected]26aa0482009-09-30 16:55:271101 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451102 frame->enableContinuousSpellChecking(
1103 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041104}
1105
initial.commit09911bf2008-07-26 23:55:291106void RenderView::OnDelete() {
1107 if (!webview())
1108 return;
1109
[email protected]26aa0482009-09-30 16:55:271110 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121111 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291112}
1113
1114void RenderView::OnSelectAll() {
1115 if (!webview())
1116 return;
1117
[email protected]26aa0482009-09-30 16:55:271118 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221119 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121120 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291121}
1122
1123void RenderView::OnSetInitialFocus(bool reverse) {
1124 if (!webview())
1125 return;
[email protected]26aa0482009-09-30 16:55:271126 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291127}
1128
1129///////////////////////////////////////////////////////////////////////////////
1130
[email protected]433819d2010-01-30 20:20:011131void RenderView::SetContentSettings(const ContentSettings& settings) {
1132 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011133}
1134
initial.commit09911bf2008-07-26 23:55:291135// Tell the embedding application that the URL of the active page has changed
1136void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451137 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291138 DCHECK(ds);
1139
[email protected]726985e22009-06-18 21:09:281140 const WebURLRequest& request = ds->request();
1141 const WebURLRequest& original_request = ds->originalRequest();
1142 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291143
[email protected]daa8c58e2009-06-15 17:21:101144 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1145 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291146
1147 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281148 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291149 params.is_post = false;
1150 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281151 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551152 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291153 // SSL state specified in the request takes precedence over the one in the
1154 // response.
1155 // So far this is only intended for error pages that are not expected to be
1156 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281157 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551158 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291159 } else {
[email protected]726985e22009-06-18 21:09:281160 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291161 }
1162
1163 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281164 if (ds->hasUnreachableURL()) {
1165 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291166 } else {
[email protected]726985e22009-06-18 21:09:281167 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291168 }
1169
[email protected]726985e22009-06-18 21:09:281170 GetRedirectChain(ds, &params.redirects);
1171 params.should_update_history = !ds->hasUnreachableURL();
initial.commit09911bf2008-07-26 23:55:291172
[email protected]ce0e250d2009-10-23 21:00:351173 params.searchable_form_url = navigation_state->searchable_form_url();
1174 params.searchable_form_encoding =
1175 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291176
1177 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101178 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291179 if (password_form_data)
1180 params.password_form = *password_form_data;
1181
1182 params.gesture = navigation_gesture_;
1183 navigation_gesture_ = NavigationGestureUnknown;
1184
[email protected]dd7daa82009-08-10 05:46:451185 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291186 // Top-level navigation.
1187
[email protected]71b0d5d2010-02-15 05:43:071188 // Clear "block" flags for the new page. This needs to happen before any of
1189 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1190 // so that these functions can correctly detect that a piece of content
1191 // flipped from "not blocked" to "blocked".
1192 ClearBlockedContentSettings();
1193
[email protected]f85f0702010-01-30 09:31:011194 // Set content settings.
1195 HostContentSettings::iterator host_content_settings =
1196 host_content_settings_.find(GURL(request.url()).host());
1197 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011198 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011199
1200 // These content settings were merely recorded transiently for this load.
1201 // We can erase them now. If at some point we reload this page, the
1202 // browser will send us new, up-to-date content settings.
1203 host_content_settings_.erase(host_content_settings);
1204 }
1205
[email protected]40bd6582009-12-04 23:49:511206 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011207 HostZoomLevels::iterator host_zoom =
[email protected]40bd6582009-12-04 23:49:511208 host_zoom_levels_.find(GURL(request.url()).host());
[email protected]f85f0702010-01-30 09:31:011209 if (host_zoom != host_zoom_levels_.end()) {
1210 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511211 // This zoom level was merely recorded transiently for this load. We can
1212 // erase it now. If at some point we reload this page, the browser will
1213 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011214 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511215 }
1216
initial.commit09911bf2008-07-26 23:55:291217 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551218 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291219
[email protected]daa8c58e2009-06-15 17:21:101220 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291221 if (!PageTransition::IsMainFrame(params.transition)) {
1222 // If the main frame does a load, it should not be reported as a subframe
1223 // navigation. This can occur in the following case:
1224 // 1. You're on a site with frames.
1225 // 2. You do a subframe navigation. This is stored with transition type
1226 // MANUAL_SUBFRAME.
1227 // 3. You navigate to some non-frame site, say, google.com.
1228 // 4. You navigate back to the page from step 2. Since it was initially
1229 // MANUAL_SUBFRAME, it will be that same transition type here.
1230 // We don't want that, because any navigation that changes the toplevel
1231 // frame should be tracked as a toplevel navigation (this allows us to
1232 // update the URL bar, etc).
1233 params.transition = PageTransition::LINK;
1234 }
1235
initial.commit09911bf2008-07-26 23:55:291236 // If we have a valid consumed client redirect source,
1237 // the page contained a client redirect (meta refresh, document.loc...),
1238 // so we set the referrer and transition to match.
1239 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041240 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291241 params.referrer = completed_client_redirect_src_;
1242 params.transition = static_cast<PageTransition::Type>(
1243 params.transition | PageTransition::CLIENT_REDIRECT);
1244 } else {
1245 // Bug 654101: the referrer will be empty on https->http transitions. It
1246 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281247 params.referrer = GURL(
1248 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291249 }
1250
[email protected]726985e22009-06-18 21:09:281251 string16 method = request.httpMethod();
1252 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291253 params.is_post = true;
1254
[email protected]c2a797d2009-09-21 16:46:321255 // Save some histogram data so we can compute the average memory used per
1256 // page load of the glyphs.
1257 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1258 webkit_glue::GetGlyphPageCount());
1259
[email protected]15cf526b2010-02-12 06:33:491260 // This message needs to be sent before any of allowScripts(),
1261 // allowImages(), allowPlugins() is called for the new page, so that when
1262 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1263 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291264 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1265 } else {
1266 // Subframe navigation: the type depends on whether this navigation
1267 // generated a new session history entry. When they do generate a session
1268 // history entry, it means the user initiated the navigation and we should
1269 // mark it as such. This test checks if this is the first time UpdateURL
1270 // has been called since WillNavigateToURL was called to initiate the load.
1271 if (page_id_ > last_page_id_sent_to_browser_)
1272 params.transition = PageTransition::MANUAL_SUBFRAME;
1273 else
1274 params.transition = PageTransition::AUTO_SUBFRAME;
1275
initial.commit09911bf2008-07-26 23:55:291276 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1277 }
1278
1279 last_page_id_sent_to_browser_ =
1280 std::max(last_page_id_sent_to_browser_, page_id_);
1281
1282 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101283 // we don't want the transition type to persist. Just clear it.
1284 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501285
[email protected]6c8afae52009-01-22 02:24:571286#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151287 if (accessibility_.get()) {
[email protected]be645db2009-02-06 20:36:331288 // Clear accessibility info cache.
[email protected]c7287a92009-11-04 20:06:151289 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:501290 }
[email protected]6c8afae52009-01-22 02:24:571291#else
[email protected]7d926f92009-03-03 14:26:541292 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571293#endif
initial.commit09911bf2008-07-26 23:55:291294}
1295
1296// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171297void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291298 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171299 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171300 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171301 routing_id_,
1302 page_id_,
1303 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1304 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171305 }
initial.commit09911bf2008-07-26 23:55:291306}
1307
1308void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401309 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291310 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271311 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291312 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301313 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291314 last_encoding_name_ = encoding_name;
1315
[email protected]e38f40152008-09-12 23:08:301316 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291317 }
1318}
1319
[email protected]f4d34b52008-11-24 23:05:011320// Sends the previous session history state to the browser so it will be saved
1321// before we navigate to a new page. This must be called *before* the page ID
1322// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291323void RenderView::UpdateSessionHistory(WebFrame* frame) {
1324 // If we have a valid page ID at this point, then it corresponds to the page
1325 // we are navigating away from. Otherwise, this is the first navigation, so
1326 // there is no past session history to record.
1327 if (page_id_ == -1)
1328 return;
1329
[email protected]ca948a22009-06-25 19:36:171330 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271331 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171332 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291333 return;
[email protected]ca948a22009-06-25 19:36:171334
1335 Send(new ViewHostMsg_UpdateState(
1336 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291337}
1338
[email protected]3d9689372009-09-10 04:29:171339void RenderView::OpenURL(
1340 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1341 Send(new ViewHostMsg_OpenURL(
1342 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1343}
1344
[email protected]79dbc662009-09-04 05:42:511345// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291346
[email protected]a2f6bc112009-06-27 16:27:251347void RenderView::DidPaint() {
[email protected]26aa0482009-09-30 16:55:271348 WebFrame* main_frame = webview()->mainFrame();
[email protected]a2f6bc112009-06-27 16:27:251349
[email protected]dd7daa82009-08-10 05:46:451350 if (main_frame->provisionalDataSource()) {
[email protected]a2f6bc112009-06-27 16:27:251351 // If we have a provisional frame we are between the start
1352 // and commit stages of loading...ignore this paint.
1353 return;
1354 }
1355
[email protected]dd7daa82009-08-10 05:46:451356 WebDataSource* ds = main_frame->dataSource();
[email protected]a2f6bc112009-06-27 16:27:251357 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]78a3a6f2009-07-02 16:15:011358 DCHECK(navigation_state);
1359
1360 Time now = Time::Now();
1361 if (navigation_state->first_paint_time().is_null()) {
1362 navigation_state->set_first_paint_time(now);
1363 }
1364 if (navigation_state->first_paint_after_load_time().is_null() &&
1365 !navigation_state->finish_load_time().is_null()) {
1366 navigation_state->set_first_paint_after_load_time(now);
[email protected]a2f6bc112009-06-27 16:27:251367 }
1368}
1369
initial.commit09911bf2008-07-26 23:55:291370void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281371 const WebURLRequest& failed_request,
1372 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291373 const std::string& html,
1374 bool replace) {
[email protected]726985e22009-06-18 21:09:281375 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291376
1377 std::string alt_html;
1378 if (html.empty()) {
1379 // Use a local error page.
1380 int resource_id;
1381 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281382 if (error.reason == net::ERR_CACHE_MISS &&
1383 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291384 GetFormRepostErrorValues(failed_url, &error_strings);
1385 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1386 } else {
1387 GetLocalizedErrorValues(error, &error_strings);
1388 resource_id = IDR_NET_ERROR_HTML;
1389 }
[email protected]8e50b602009-03-03 22:59:431390 error_strings.SetString(L"textdirection",
1391 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
1392 L"rtl" : L"ltr");
initial.commit09911bf2008-07-26 23:55:291393
1394 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1395 } else {
1396 alt_html = html;
1397 }
1398
[email protected]dd7daa82009-08-10 05:46:451399 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551400 GURL(kUnreachableWebDataURL),
1401 failed_url,
1402 replace);
initial.commit09911bf2008-07-26 23:55:291403}
1404
[email protected]7ccddb8c2009-08-04 17:36:551405void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291406 dom_automation_controller_.set_message_sender(this);
1407 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551408 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291409 L"domAutomationController");
1410}
1411
initial.commit09911bf2008-07-26 23:55:291412bool RenderView::RunJavaScriptMessage(int type,
1413 const std::wstring& message,
1414 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071415 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291416 std::wstring* result) {
1417 bool success = false;
1418 std::wstring result_temp;
1419 if (!result)
1420 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291421
[email protected]12636df2009-09-28 22:32:211422 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1423 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291424 return success;
1425}
1426
[email protected]c1f50aa2010-02-18 03:46:571427bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1428 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1429 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1430 // it is particularly important that we do not call willEnterModalLoop as
1431 // that would defer resource loads for the dialog itself.
1432 if (RenderThread::current()) // Will be NULL during unit tests.
1433 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1434
1435 message->EnableMessagePumping(); // Runs a nested message loop.
1436 return Send(message);
1437}
1438
initial.commit09911bf2008-07-26 23:55:291439void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1440 if (!osd_url.is_empty())
1441 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1442 autodetected));
1443}
1444
[email protected]95056b582010-02-18 01:29:241445void RenderView::OnAutoFillSuggestionsReturned(
1446 int query_id,
1447 const std::vector<string16>& names,
1448 const std::vector<string16>& labels,
1449 int default_suggestion_index) {
1450 if (webview() && query_id == autofill_query_id_) {
1451 webview()->applyAutoFillSuggestions(
1452 autofill_query_node_, names, labels, default_suggestion_index);
1453 }
1454 autofill_query_node_.reset();
1455}
1456
1457void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a1f2009-10-16 03:53:391458 int query_id,
1459 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031460 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181461 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081462 webview()->applyAutocompleteSuggestions(
[email protected]acca2a1f2009-10-16 03:53:391463 autofill_query_node_, suggestions, default_suggestion_index);
1464 }
1465 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031466}
1467
[email protected]c83641732010-02-20 01:04:481468void RenderView::OnAutoFillFormDataFilled(int query_id, const FormData& form) {
1469 if (query_id != autofill_query_id_)
1470 return;
1471
1472 form_manager_.FillForm(form);
1473}
1474
[email protected]2c4410d2009-05-06 23:46:221475void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311476 popup_notification_visible_ = visible;
1477}
1478
initial.commit09911bf2008-07-26 23:55:291479uint32 RenderView::GetCPBrowsingContext() {
1480 uint32 context = 0;
1481 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1482 return context;
1483}
1484
initial.commit09911bf2008-07-26 23:55:291485void RenderView::AddSearchProvider(const std::string& url) {
1486 AddGURLSearchProvider(GURL(url),
1487 false); // not autodetected
1488}
1489
[email protected]f103ab72009-09-02 17:10:591490void RenderView::OnMissingPluginStatus(
1491 WebPluginDelegateProxy* delegate,
1492 int status) {
[email protected]6c8afae52009-01-22 02:24:571493#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591494 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291495 // Show the InfoBar for the first available plugin.
1496 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591497 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291498 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1499 }
1500 } else {
1501 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1502 // to start the download/install.
1503 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1504 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1505 }
1506 }
[email protected]6c8afae52009-01-22 02:24:571507#else
1508 // TODO(port): plugins current not supported
1509 NOTIMPLEMENTED();
1510#endif
initial.commit09911bf2008-07-26 23:55:291511}
1512
[email protected]48c9cf2d2009-09-16 16:47:521513// WebKit::WebViewClient ------------------------------------------------------
1514
1515WebView* RenderView::createView(WebFrame* creator) {
1516 // Check to make sure we aren't overloading on popups.
1517 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1518 return NULL;
1519
1520 // This window can't be closed from a window.close() call until we receive a
1521 // message from the Browser process explicitly allowing it.
1522 popup_notification_visible_ = true;
1523
1524 int32 routing_id = MSG_ROUTING_NONE;
1525 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461526 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341527 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521528
[email protected]48c9cf2d2009-09-16 16:47:521529 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341530 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1531 session_storage_namespace_id_,
1532 &routing_id,
1533 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211534 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521535 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521536
[email protected]48c9cf2d2009-09-16 16:47:521537 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421538 0,
[email protected]12636df2009-09-28 22:32:211539 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521540 renderer_preferences_,
1541 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211542 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341543 routing_id,
1544 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521545 view->opened_by_user_gesture_ = user_gesture;
1546
[email protected]007a848b2009-10-26 15:55:461547 // Record whether the creator frame is trying to suppress the opener field.
1548 view->opener_suppressed_ = opener_suppressed;
1549
[email protected]48c9cf2d2009-09-16 16:47:521550 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091551 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521552 if (!creator_url.is_valid() || !creator_url.IsStandard())
1553 creator_url = GURL();
1554 view->creator_url_ = creator_url;
1555
1556 // Copy over the alternate error page URL so we can have alt error pages in
1557 // the new render view (we don't need the browser to send the URL back down).
1558 view->alternate_error_page_url_ = alternate_error_page_url_;
1559
1560 return view->webview();
1561}
1562
1563WebWidget* RenderView::createPopupMenu(bool activatable) {
1564 RenderWidget* widget = RenderWidget::Create(routing_id_,
1565 render_thread_,
1566 activatable);
1567 return widget->webwidget();
1568}
1569
1570WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1571 RenderWidget* widget = RenderWidget::Create(routing_id_,
1572 render_thread_,
1573 true);
1574 widget->ConfigureAsExternalPopupMenu(info);
1575 return widget->webwidget();
1576}
1577
[email protected]bd92c3a2010-01-13 05:02:341578WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1579 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1580 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291581 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1582 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1583 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341584}
1585
[email protected]48c9cf2d2009-09-16 16:47:521586void RenderView::didAddMessageToConsole(
1587 const WebConsoleMessage& message, const WebString& source_name,
1588 unsigned source_line) {
1589 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1590 UTF16ToWideHack(message.text),
1591 static_cast<int32>(source_line),
1592 UTF16ToWideHack(source_name)));
1593}
1594
1595void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581596 DCHECK(frame);
1597 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521598}
1599
1600void RenderView::didStartLoading() {
1601 if (is_loading_) {
1602 DLOG(WARNING) << "didStartLoading called while loading";
1603 return;
1604 }
1605
1606 is_loading_ = true;
1607 // Clear the pointer so that we can assign it only when there is an unknown
1608 // plugin on a page.
1609 first_default_plugin_.reset();
1610
1611 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1612}
1613
1614void RenderView::didStopLoading() {
1615 if (!is_loading_) {
1616 DLOG(WARNING) << "DidStopLoading called while not loading";
1617 return;
1618 }
1619
1620 is_loading_ = false;
1621
1622 // NOTE: For now we're doing the safest thing, and sending out notification
1623 // when done loading. This currently isn't an issue as the favicon is only
1624 // displayed when done loading. Ideally we would send notification when
1625 // finished parsing the head, but webkit doesn't support that yet.
1626 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271627 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521628 if (!favicon_url.is_empty())
1629 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1630
[email protected]26aa0482009-09-30 16:55:271631 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521632 true); // autodetected
1633
1634 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1635
1636 MessageLoop::current()->PostDelayedTask(FROM_HERE,
1637 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1638 false),
1639 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521640}
1641
[email protected]f55039a2010-02-17 14:12:061642bool RenderView::isSmartInsertDeleteEnabled() {
1643#if defined(OS_MACOSX)
1644 return true;
1645#else
1646 return false;
1647#endif
1648}
1649
[email protected]04fc9482009-09-18 22:13:031650bool RenderView::isSelectTrailingWhitespaceEnabled() {
1651#if defined(OS_WIN)
1652 return true;
1653#else
1654 return false;
1655#endif
1656}
1657
1658void RenderView::setInputMethodEnabled(bool enabled) {
1659 // Save the updated IME status and mark the input focus has been updated.
1660 // The IME status is to be sent to a browser process next time when
1661 // the input caret is rendered.
1662 if (!ime_control_busy_) {
1663 ime_control_updated_ = true;
1664 ime_control_new_state_ = enabled;
1665 }
1666}
1667
1668void RenderView::didChangeSelection(bool is_empty_selection) {
1669#if defined(OS_LINUX)
1670 if (!handling_input_event_)
1671 return;
1672 // TODO(estade): investigate incremental updates to the selection so that we
1673 // don't send the entire selection over IPC every time.
1674 if (!is_empty_selection) {
1675 // Sometimes we get repeated didChangeSelection calls from webkit when
1676 // the selection hasn't actually changed. We don't want to report these
1677 // because it will cause us to continually claim the X clipboard.
1678 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271679 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031680 if (this_selection == last_selection_)
1681 return;
1682
1683 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1684 this_selection));
1685 last_selection_ = this_selection;
1686 } else {
1687 last_selection_.clear();
1688 }
1689#endif
1690}
1691
1692void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121693 const std::string& name = UTF16ToUTF8(command_name);
1694 if (StartsWithASCII(name, "Move", true) ||
1695 StartsWithASCII(name, "Insert", true) ||
1696 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031697 return;
1698 UserMetricsRecordAction(name);
1699}
1700
[email protected]b2528b72009-09-24 06:57:101701bool RenderView::handleCurrentKeyboardEvent() {
1702 if (edit_commands_.empty())
1703 return false;
1704
[email protected]26aa0482009-09-30 16:55:271705 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101706 if (!frame)
1707 return false;
1708
1709 EditCommands::iterator it = edit_commands_.begin();
1710 EditCommands::iterator end = edit_commands_.end();
1711
[email protected]507b33ea2009-09-29 03:56:511712 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101713 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331714 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1715 // key (but it's the exception). Once one edit command is not executed, it
1716 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101717 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1718 WebString::fromUTF8(it->value)))
1719 break;
[email protected]507b33ea2009-09-29 03:56:511720 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101721 }
1722
[email protected]507b33ea2009-09-29 03:56:511723 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101724}
1725
[email protected]2a3a7762009-10-19 19:17:321726void RenderView::spellCheck(const WebString& text,
1727 int& misspelled_offset,
1728 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561729 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461730
[email protected]85c55dc2009-11-06 03:05:461731 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171732 RenderThread* thread = RenderThread::current();
1733 // Will be NULL during unit tests.
1734 if (thread) {
[email protected]c27324b2009-11-19 22:44:291735 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171736 word.c_str(), word.size(), document_tag_,
1737 &misspelled_offset, &misspelled_length, NULL);
1738 }
[email protected]1dbafaf72009-09-23 19:43:561739}
1740
1741WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321742 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561743 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261744 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561745 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171746 RenderThread* thread = RenderThread::current();
1747 // Will be NULL during unit tests.
1748 if (thread) {
1749 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291750 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171751 word, document_tag_);
1752 }
[email protected]1dbafaf72009-09-23 19:43:561753 }
[email protected]2a3a7762009-10-19 19:17:321754 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561755}
1756
[email protected]c49085c72009-10-02 16:28:561757void RenderView::showSpellingUI(bool show) {
1758 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1759}
1760
[email protected]8922e1f2009-10-03 05:01:261761bool RenderView::isShowingSpellingUI() {
1762 return spelling_panel_visible_;
1763}
1764
[email protected]1dbafaf72009-09-23 19:43:561765void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321766 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1767 word));
[email protected]1dbafaf72009-09-23 19:43:561768}
1769
[email protected]a1128322009-10-06 18:38:461770bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351771 const WebKit::WebFileChooserParams& params,
[email protected]a1128322009-10-06 18:38:461772 WebKit::WebFileChooserCompletion* chooser_completion) {
1773 if (file_chooser_completion_) {
1774 // TODO(brettw): bug 1235154: This should be a synchronous message to deal
1775 // with the fact that web pages can programatically trigger this. With the
1776 // asnychronous messages, we can get an additional call when one is pending,
1777 // which this test is for. For now, we just ignore the additional file
1778 // chooser request. WebKit doesn't do anything to expect the callback, so
1779 // we can just ignore calling it.
1780 return false;
1781 }
1782 file_chooser_completion_ = chooser_completion;
1783 Send(new ViewHostMsg_RunFileChooser(
[email protected]01178b52010-01-15 06:59:351784 routing_id_, params.multiSelect, params.title,
1785 webkit_glue::WebStringToFilePath(params.initialValue)));
[email protected]a1128322009-10-06 18:38:461786 return true;
1787}
1788
[email protected]48c9cf2d2009-09-16 16:47:521789void RenderView::runModalAlertDialog(
1790 WebFrame* frame, const WebString& message) {
1791 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1792 UTF16ToWideHack(message),
1793 std::wstring(),
1794 frame->url(),
1795 NULL);
1796}
1797
1798bool RenderView::runModalConfirmDialog(
1799 WebFrame* frame, const WebString& message) {
1800 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1801 UTF16ToWideHack(message),
1802 std::wstring(),
1803 frame->url(),
1804 NULL);
1805}
1806
1807bool RenderView::runModalPromptDialog(
1808 WebFrame* frame, const WebString& message, const WebString& default_value,
1809 WebString* actual_value) {
1810 std::wstring result;
1811 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1812 UTF16ToWideHack(message),
1813 UTF16ToWideHack(default_value),
1814 frame->url(),
1815 &result);
1816 if (ok)
1817 actual_value->assign(WideToUTF16Hack(result));
1818 return ok;
1819}
1820
1821bool RenderView::runModalBeforeUnloadDialog(
1822 WebFrame* frame, const WebString& message) {
1823 bool success = false;
1824 // This is an ignored return value, but is included so we can accept the same
1825 // response as RunJavaScriptMessage.
1826 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211827 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521828 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211829 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521830 return success;
1831}
1832
[email protected]79e37442009-10-09 18:17:441833void RenderView::showContextMenu(
1834 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291835 ContextMenuParams params = ContextMenuParams(data);
1836 if (!params.misspelled_word.empty() && RenderThread::current()) {
1837 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041838 bool spelled_right = RenderThread::current()->spellchecker()->
1839 SpellCheckWord(
1840 params.misspelled_word.c_str(), params.misspelled_word.size(),
1841 document_tag_,
1842 &misspelled_offset, &misspelled_length,
1843 &params.dictionary_suggestions);
1844 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291845 params.misspelled_word.clear();
1846 }
1847
1848 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441849}
1850
[email protected]48c9cf2d2009-09-16 16:47:521851void RenderView::setStatusText(const WebString& text) {
1852}
1853
[email protected]163f8242009-10-30 20:19:551854void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1855 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521856 if (latest_url == target_url_)
1857 return;
[email protected]163f8242009-10-30 20:19:551858
[email protected]48c9cf2d2009-09-16 16:47:521859 // Tell the browser to display a destination link.
1860 if (target_url_status_ == TARGET_INFLIGHT ||
1861 target_url_status_ == TARGET_PENDING) {
1862 // If we have a request in-flight, save the URL to be sent when we
1863 // receive an ACK to the in-flight request. We can happily overwrite
1864 // any existing pending sends.
1865 pending_target_url_ = latest_url;
1866 target_url_status_ = TARGET_PENDING;
1867 } else {
1868 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1869 target_url_ = latest_url;
1870 target_url_status_ = TARGET_INFLIGHT;
1871 }
1872}
1873
[email protected]882daa92009-11-05 16:31:311874void RenderView::StartNavStateSyncTimerIfNecessary() {
1875 int delay;
1876 if (send_content_state_immediately_)
1877 delay = 0;
1878 else if (is_hidden())
1879 delay = kDelaySecondsForContentStateSyncHidden;
1880 else
1881 delay = kDelaySecondsForContentStateSync;
1882
1883 if (nav_state_sync_timer_.IsRunning()) {
1884 // The timer is already running. If the delay of the timer maches the amount
1885 // we want to delay by, then return. Otherwise stop the timer so that it
1886 // gets started with the right delay.
1887 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1888 return;
1889 nav_state_sync_timer_.Stop();
1890 }
1891
1892 nav_state_sync_timer_.Start(
1893 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1894}
1895
[email protected]163f8242009-10-30 20:19:551896void RenderView::setMouseOverURL(const WebURL& url) {
1897 mouse_over_url_ = GURL(url);
1898 UpdateTargetURL(mouse_over_url_, focus_url_);
1899}
1900
1901void RenderView::setKeyboardFocusURL(const WebURL& url) {
1902 focus_url_ = GURL(url);
1903 UpdateTargetURL(focus_url_, mouse_over_url_);
1904}
1905
[email protected]48c9cf2d2009-09-16 16:47:521906void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1907 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1908 hint));
1909}
1910
1911void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1912 WebDragOperationsMask allowed_ops) {
1913 Send(new ViewHostMsg_StartDragging(routing_id_,
1914 WebDropData(data),
1915 allowed_ops));
1916}
1917
[email protected]28b92df2009-09-25 17:35:451918bool RenderView::acceptsLoadDrops() {
1919 return renderer_preferences_.can_accept_load_drops;
1920}
1921
[email protected]48c9cf2d2009-09-16 16:47:521922void RenderView::focusNext() {
1923 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1924}
1925
1926void RenderView::focusPrevious() {
1927 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1928}
1929
1930void RenderView::navigateBackForwardSoon(int offset) {
1931 history_back_list_count_ += offset;
1932 history_forward_list_count_ -= offset;
1933
1934 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1935}
1936
1937int RenderView::historyBackListCount() {
1938 return history_back_list_count_;
1939}
1940
1941int RenderView::historyForwardListCount() {
1942 return history_forward_list_count_;
1943}
1944
1945void RenderView::didAddHistoryItem() {
1946 // We don't want to update the history length for the start page
1947 // navigation.
[email protected]26aa0482009-09-30 16:55:271948 WebFrame* main_frame = webview()->mainFrame();
[email protected]48c9cf2d2009-09-16 16:47:521949 DCHECK(main_frame != NULL);
1950
1951 WebDataSource* ds = main_frame->dataSource();
1952 DCHECK(ds != NULL);
1953
1954 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1955 DCHECK(navigation_state);
1956 if (navigation_state->transition_type() == PageTransition::START_PAGE)
1957 return;
1958
1959 history_back_list_count_++;
1960 history_forward_list_count_ = 0;
1961}
1962
[email protected]8922e1f2009-10-03 05:01:261963void RenderView::didUpdateInspectorSettings() {
1964 Send(new ViewHostMsg_UpdateInspectorSettings(
1965 routing_id_, webview()->inspectorSettings().utf8()));
1966}
1967
[email protected]acca2a1f2009-10-16 03:53:391968void RenderView::queryAutofillSuggestions(const WebNode& node,
1969 const WebString& name,
1970 const WebString& value) {
1971 static int query_counter = 0;
1972 autofill_query_id_ = query_counter++;
1973 autofill_query_node_ = node;
[email protected]95056b582010-02-18 01:29:241974 const WebKit::WebInputElement input_element =
1975 node.toConstElement<WebInputElement>();
[email protected]acca2a1f2009-10-16 03:53:391976 Send(new ViewHostMsg_QueryFormFieldAutofill(
[email protected]95056b582010-02-18 01:29:241977 routing_id_, autofill_query_id_, FormField(input_element)));
[email protected]acca2a1f2009-10-16 03:53:391978}
1979
1980void RenderView::removeAutofillSuggestions(const WebString& name,
1981 const WebString& value) {
1982 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1983}
1984
[email protected]c83641732010-02-20 01:04:481985void RenderView::didAcceptAutoFillSuggestion(
1986 const WebKit::WebNode& node,
1987 const WebKit::WebString& name,
1988 const WebKit::WebString& label) {
1989 static int query_counter = 0;
1990 autofill_query_id_ = query_counter++;
1991
1992 FormData form;
1993 const WebInputElement element = node.toConstElement<WebInputElement>();
1994 if (!form_manager_.FindForm(element, &form))
1995 return;
1996
1997 Send(new ViewHostMsg_FillAutoFillFormData(
1998 routing_id_, autofill_query_id_, form, name, label));
1999}
2000
[email protected]79dbc662009-09-04 05:42:512001// WebKit::WebWidgetClient ----------------------------------------------------
2002
initial.commit09911bf2008-07-26 23:55:292003// We are supposed to get a single call to Show for a newly created RenderView
2004// that was created via RenderView::CreateWebView. So, we wait until this
2005// point to dispatch the ShowView message.
2006//
2007// This method provides us with the information about how to display the newly
2008// created RenderView (i.e., as a constrained popup or as a new tab).
2009//
[email protected]4873c7d2009-07-16 06:36:282010void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292011 DCHECK(!did_show_) << "received extraneous Show call";
2012 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2013
2014 if (did_show_)
2015 return;
2016 did_show_ = true;
2017
[email protected]28295ec2009-10-16 05:34:332018 // Force new windows to a popup if they were not opened with a user gesture.
2019 if (!opened_by_user_gesture_) {
2020 // We exempt background tabs for compat with older versions of Chrome.
2021 // TODO(darin): This seems bogus. These should have a user gesture, so
2022 // we probably don't need this check.
2023 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2024 policy = WebKit::WebNavigationPolicyNewPopup;
2025 }
2026
initial.commit09911bf2008-07-26 23:55:292027 // NOTE: initial_pos_ may still have its default values at this point, but
2028 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2029 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282030 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2031 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292032 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242033 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292034}
2035
[email protected]4873c7d2009-07-16 06:36:282036void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222037 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282038 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312039}
2040
[email protected]4873c7d2009-07-16 06:36:282041void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292042 DCHECK(did_show_) << "should already have shown the view";
2043
[email protected]c1f50aa2010-02-18 03:46:572044 // We must keep WebKit's shared timer running in this case in order to allow
2045 // showModalDialog to function properly.
2046 //
2047 // TODO(darin): WebKit should really be smarter about suppressing events and
2048 // timers so that we do not need to manage the shared timer in such a heavy
2049 // handed manner.
2050 //
2051 if (RenderThread::current()) // Will be NULL during unit tests.
2052 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2053
[email protected]12636df2009-09-28 22:32:212054 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292055}
2056
[email protected]3d9689372009-09-10 04:29:172057// WebKit::WebFrameClient -----------------------------------------------------
2058
2059WebPlugin* RenderView::createPlugin(
2060 WebFrame* frame, const WebPluginParams& params) {
2061 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2062}
2063
2064WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2065 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
2066}
2067
[email protected]9c00f002009-11-05 22:37:422068WebSharedWorker* RenderView::createSharedWorker(
2069 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372070 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422071
[email protected]30447b62009-11-13 01:13:372072 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512073 bool exists = false;
[email protected]30447b62009-11-13 01:13:372074 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512075 ViewHostMsg_CreateWorker_Params params;
2076 params.url = url;
2077 params.is_shared = true;
2078 params.name = name;
2079 params.document_id = document_id;
2080 params.render_view_route_id = routing_id_;
2081 params.route_id = MSG_ROUTING_NONE;
[email protected]30447b62009-11-13 01:13:372082 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512083 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372084 if (url_mismatch) {
2085 return NULL;
2086 } else {
2087 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492088 document_id,
[email protected]6de0bcf2010-02-17 22:00:512089 exists,
[email protected]30447b62009-11-13 01:13:372090 route_id,
2091 routing_id_);
2092 }
[email protected]9c00f002009-11-05 22:37:422093}
2094
[email protected]3d9689372009-09-10 04:29:172095WebMediaPlayer* RenderView::createMediaPlayer(
2096 WebFrame* frame, WebMediaPlayerClient* client) {
2097 scoped_refptr<media::FilterFactoryCollection> factory =
2098 new media::FilterFactoryCollection();
2099 // Add in any custom filter factories first.
2100 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2101 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2102 // Add the chrome specific audio renderer.
2103 factory->AddFactory(
2104 AudioRendererImpl::CreateFactory(audio_message_filter()));
2105 }
2106
[email protected]80f584d92010-01-21 03:59:042107 WebApplicationCacheHostImpl* appcache_host =
2108 WebApplicationCacheHostImpl::FromFrame(frame);
2109
[email protected]3d9689372009-09-10 04:29:172110 // TODO(hclam): obtain the following parameters from |client|.
2111 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2112 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152113 GURL(), // referrer
2114 "null", // frame origin
2115 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172116 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042117 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172118 routing_id());
2119
[email protected]0436b9a2009-10-23 00:23:052120 // A simple data source that keeps all data in memory.
2121 media::FilterFactory* simple_data_source_factory =
2122 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2123 bridge_factory);
2124 // A sophisticated data source that does memory caching.
2125 media::FilterFactory* buffered_data_source_factory =
2126 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2127 bridge_factory);
2128 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2129 factory->AddFactory(simple_data_source_factory);
2130 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172131 } else {
[email protected]0436b9a2009-10-23 00:23:052132 factory->AddFactory(buffered_data_source_factory);
2133 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172134 }
2135 return new webkit_glue::WebMediaPlayerImpl(client, factory);
2136}
2137
2138void RenderView::willClose(WebFrame* frame) {
2139 if (!frame->parent()) {
2140 const GURL& url = frame->url();
2141 if (url.SchemeIs("http") || url.SchemeIs("https"))
2142 DumpLoadHistograms();
2143 }
[email protected]fa7b6b542009-11-03 05:02:302144
2145 WebDataSource* ds = frame->dataSource();
2146 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2147 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172148}
2149
[email protected]684e4a42010-01-30 06:44:112150bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]2d30a7a2010-02-04 01:57:502151 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS, enabled_per_settings);
[email protected]684e4a42010-01-30 06:44:112152}
2153
2154bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]2d30a7a2010-02-04 01:57:502155 return AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES, enabled_per_settings);
[email protected]684e4a42010-01-30 06:44:112156}
2157
[email protected]3d9689372009-09-10 04:29:172158void RenderView::loadURLExternally(
2159 WebFrame* frame, const WebURLRequest& request,
2160 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592161 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2162 if (policy == WebKit::WebNavigationPolicyDownload) {
2163 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2164 } else {
2165 OpenURL(request.url(), referrer, policy);
2166 }
[email protected]3d9689372009-09-10 04:29:172167}
2168
2169WebNavigationPolicy RenderView::decidePolicyForNavigation(
2170 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222171 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172172 // Webkit is asking whether to navigate to a new URL.
2173 // This is fine normally, except if we're showing UI from one security
2174 // context and they're trying to navigate to a different context.
2175 const GURL& url = request.url();
2176
2177 // If the browser is interested, then give it a chance to look at top level
2178 // navigations
2179 if (renderer_preferences_.browser_handles_top_level_requests &&
2180 // Only send once.
2181 last_top_level_navigation_page_id_ != page_id_ &&
2182 // Not interested in reloads.
2183 type != WebKit::WebNavigationTypeReload &&
2184 type != WebKit::WebNavigationTypeFormSubmitted &&
2185 // Must be a top level frame.
2186 frame->parent() == NULL) {
2187 // Skip if navigation is on the same page (using '#').
2188 GURL frame_origin = GURL(frame->url()).GetOrigin();
2189 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
2190 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:572191 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2192 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:172193 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2194 }
2195 }
2196
2197 // A content initiated navigation may have originated from a link-click,
2198 // script, drag-n-drop operation, etc.
2199 bool is_content_initiated =
2200 NavigationState::FromDataSource(frame->provisionalDataSource())->
2201 is_content_initiated();
2202
2203 // We only care about navigations that are within the current tab (as opposed
2204 // to, for example, opening a new window).
2205 // But we sometimes navigate to about:blank to clear a tab, and we want to
2206 // still allow that.
2207 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2208 is_content_initiated && frame->parent() == NULL &&
2209 !url.SchemeIs(chrome::kAboutScheme)) {
2210 // When we received such unsolicited navigations, we sometimes want to
2211 // punt them up to the browser to handle.
2212 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2213 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2214 frame->isViewSourceModeEnabled() ||
2215 url.SchemeIs(chrome::kViewSourceScheme) ||
2216 url.SchemeIs(chrome::kPrintScheme)) {
2217 OpenURL(url, GURL(), default_policy);
2218 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2219 }
2220 }
2221
2222 // Detect when a page is "forking" a new tab that can be safely rendered in
2223 // its own process. This is done by sites like Gmail that try to open links
2224 // in new windows without script connections back to the original page. We
2225 // treat such cases as browser navigations (in which we will create a new
2226 // renderer for a cross-site navigation), rather than WebKit navigations.
2227 //
2228 // We use the following heuristic to decide whether to fork a new page in its
2229 // own process:
2230 // The parent page must open a new tab to about:blank, set the new tab's
2231 // window.opener to null, and then redirect the tab to a cross-site URL using
2232 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462233 //
2234 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2235 // (see below).
[email protected]3d9689372009-09-10 04:29:172236 bool is_fork =
2237 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252238 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172239 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522240 historyBackListCount() < 1 &&
2241 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172242 // The parent page must have set the child's window.opener to null before
2243 // redirecting to the desired URL.
2244 frame->opener() == NULL &&
2245 // Must be a top-level frame.
2246 frame->parent() == NULL &&
2247 // Must not have issued the request from this page.
2248 is_content_initiated &&
2249 // Must be targeted at the current tab.
2250 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2251 // Must be a JavaScript navigation, which appears as "other".
2252 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462253
2254 // Recognize if this navigation is from a link with rel=noreferrer and
2255 // target=_blank attributes, in which case the opener will be suppressed. If
2256 // so, it is safe to load cross-site pages in a separate process, so we
2257 // should let the browser handle it.
2258 bool is_noreferrer_and_blank_target =
2259 // Frame should be top level and not yet navigated.
2260 frame->parent() == NULL &&
2261 frame->url().isEmpty() &&
2262 historyBackListCount() < 1 &&
2263 historyForwardListCount() < 1 &&
2264 // Links with rel=noreferrer will have no Referer field, and their
2265 // resulting frame will have its window.opener suppressed.
2266 // TODO(creis): should add a request.httpReferrer() method to help avoid
2267 // typos on the unusual spelling of Referer.
2268 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2269 opener_suppressed_ &&
2270 frame->opener() == NULL &&
2271 // Links with target=_blank will have no name.
2272 frame->name().isNull() &&
2273 // Another frame (with a non-empty creator) should have initiated the
2274 // request, targeted at this frame.
2275 !creator_url_.is_empty() &&
2276 is_content_initiated &&
2277 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2278 type == WebKit::WebNavigationTypeOther;
2279
2280 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172281 // Open the URL via the browser, not via WebKit.
2282 OpenURL(url, GURL(), default_policy);
2283 return WebKit::WebNavigationPolicyIgnore;
2284 }
2285
2286 return default_policy;
2287}
2288
[email protected]6069da8c2009-10-20 20:33:492289bool RenderView::canHandleRequest(
2290 WebFrame* frame, const WebURLRequest& request) {
2291 // We allow WebKit to think that everything can be handled even though
2292 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342293 return true;
2294}
2295
[email protected]6069da8c2009-10-20 20:33:492296WebURLError RenderView::cannotHandleRequestError(
2297 WebFrame* frame, const WebURLRequest& request) {
2298 NOTREACHED(); // Since we said we can handle all requests.
2299 return WebURLError();
2300}
2301
2302WebURLError RenderView::cancelledError(
2303 WebFrame* frame, const WebURLRequest& request) {
2304 WebURLError error;
2305 error.domain = WebString::fromUTF8(net::kErrorDomain);
2306 error.reason = net::ERR_ABORTED;
2307 error.unreachableURL = request.url();
2308 return error;
[email protected]7b7a7dc2009-10-19 02:23:342309}
2310
2311void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492312 WebFrame*, const WebURLError&) {
2313 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342314}
2315
[email protected]979c28b2009-11-07 01:30:482316void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172317 NavigationState* navigation_state =
2318 NavigationState::FromDataSource(frame->provisionalDataSource());
2319
2320 if (navigation_state->transition_type() == PageTransition::LINK)
2321 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2322
2323 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352324 WebSearchableFormData web_searchable_form_data(form);
2325 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2326 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212327 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172328 navigation_state->set_password_form_data(
2329 PasswordFormDomManager::CreatePasswordForm(form));
2330
[email protected]979c28b2009-11-07 01:30:482331 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382332 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2333 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472334 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382335 *form_values));
[email protected]3d9689372009-09-10 04:29:172336 }
2337}
2338
2339void RenderView::willPerformClientRedirect(
2340 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2341 double fire_time) {
2342 // Ignore
2343}
2344
2345void RenderView::didCancelClientRedirect(WebFrame* frame) {
2346 // Ignore
2347}
2348
2349void RenderView::didCompleteClientRedirect(
2350 WebFrame* frame, const WebURL& from) {
2351 if (!frame->parent())
2352 completed_client_redirect_src_ = from;
2353}
2354
2355void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2356 // The rest of RenderView assumes that a WebDataSource will always have a
2357 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482358 bool content_initiated = !pending_navigation_state_.get();
2359 NavigationState* state = content_initiated ?
2360 NavigationState::CreateContentInitiated() :
2361 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182362 if (content_initiated) {
2363 switch (ds->request().cachePolicy()) {
2364 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2365 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2366 break;
2367 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2368 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2369 break;
2370 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2371 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2372 break;
2373 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2374 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2375 break;
2376 }
2377 }
[email protected]fa7b6b542009-11-03 05:02:302378
2379 state->set_user_script_idle_scheduler(
2380 new UserScriptIdleScheduler(this, frame));
2381 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172382}
2383
2384void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2385 WebDataSource* ds = frame->provisionalDataSource();
2386 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2387
2388 navigation_state->set_start_load_time(Time::Now());
2389
2390 // Update the request time if WebKit has better knowledge of it.
2391 if (navigation_state->request_time().is_null()) {
2392 double event_time = ds->triggeringEventTime();
2393 if (event_time != 0.0)
2394 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2395 }
2396
2397 bool is_top_most = !frame->parent();
2398 if (is_top_most) {
2399 navigation_gesture_ = frame->isProcessingUserGesture() ?
2400 NavigationGestureUnknown : NavigationGestureAuto;
2401
2402 // Make sure redirect tracking state is clear for the new load.
2403 completed_client_redirect_src_ = GURL();
2404 } else if (frame->parent()->isLoading()) {
2405 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002406 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172407 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2408 }
2409
2410 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2411 routing_id_, is_top_most, ds->request().url()));
2412}
2413
2414void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2415 if (frame->parent())
2416 return;
2417 // Received a redirect on the main frame.
2418 WebDataSource* data_source = frame->provisionalDataSource();
2419 if (!data_source) {
2420 // Should only be invoked when we have a data source.
2421 NOTREACHED();
2422 return;
2423 }
2424 std::vector<GURL> redirects;
2425 GetRedirectChain(data_source, &redirects);
2426 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512427 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2428 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172429 }
2430}
2431
[email protected]40bd6582009-12-04 23:49:512432void RenderView::didFailProvisionalLoad(WebFrame* frame,
2433 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172434 // Notify the browser that we failed a provisional load with an error.
2435 //
2436 // Note: It is important this notification occur before DidStopLoading so the
2437 // SSL manager can react to the provisional load failure before being
2438 // notified the load stopped.
2439 //
2440 WebDataSource* ds = frame->provisionalDataSource();
2441 DCHECK(ds);
2442
2443 const WebURLRequest& failed_request = ds->request();
2444
2445 bool show_repost_interstitial =
2446 (error.reason == net::ERR_CACHE_MISS &&
2447 EqualsASCII(failed_request.httpMethod(), "POST"));
2448 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2449 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2450 show_repost_interstitial));
2451
2452 // Don't display an error page if this is simply a cancelled load. Aside
2453 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2454 if (error.reason == net::ERR_ABORTED)
2455 return;
2456
2457 // Make sure we never show errors in view source mode.
2458 frame->enableViewSourceMode(false);
2459
2460 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2461
2462 // If this is a failed back/forward/reload navigation, then we need to do a
2463 // 'replace' load. This is necessary to avoid messing up session history.
2464 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2465 // as session history is concerned.
2466 //
2467 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2468 // the page id.
2469 //
2470 bool replace =
2471 navigation_state->pending_page_id() != -1 ||
2472 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2473
2474 // If we failed on a browser initiated request, then make sure that our error
2475 // page load is regarded as the same browser initiated request.
2476 if (!navigation_state->is_content_initiated()) {
2477 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2478 navigation_state->pending_page_id(),
2479 navigation_state->transition_type(),
2480 navigation_state->request_time()));
2481 }
2482
2483 // Provide the user with a more helpful error page?
2484 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2485 return;
2486
2487 // Fallback to a local error page.
2488 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2489 replace);
2490}
2491
2492void RenderView::didReceiveDocumentData(
2493 WebFrame* frame, const char* data, size_t data_len,
2494 bool& prevent_default) {
2495 NavigationState* navigation_state =
2496 NavigationState::FromDataSource(frame->dataSource());
2497 if (!navigation_state->postpone_loading_data())
2498 return;
2499
2500 // We're going to call commitDocumentData ourselves...
2501 prevent_default = true;
2502
2503 // Continue buffering the response data for the original 404 page. If it
2504 // grows too large, then we'll just let it through.
2505 navigation_state->append_postponed_data(data, data_len);
2506 if (navigation_state->postponed_data().size() >= 512) {
2507 navigation_state->set_postpone_loading_data(false);
2508 frame->commitDocumentData(navigation_state->postponed_data().data(),
2509 navigation_state->postponed_data().size());
2510 navigation_state->clear_postponed_data();
2511 }
2512}
2513
[email protected]40bd6582009-12-04 23:49:512514void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2515 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172516 NavigationState* navigation_state =
2517 NavigationState::FromDataSource(frame->dataSource());
2518
[email protected]9e84a872010-02-09 18:23:422519 if (!frame->parent()) { // Main frame case.
2520 // Let the page translator know that the page has changed so it can clear
2521 // its states.
2522 page_translator_->MainFrameNavigated();
2523 }
2524
[email protected]3d9689372009-09-10 04:29:172525 navigation_state->set_commit_load_time(Time::Now());
2526 if (is_new_navigation) {
2527 // When we perform a new navigation, we need to update the previous session
2528 // history entry with state for the page we are leaving.
2529 UpdateSessionHistory(frame);
2530
2531 // We bump our Page ID to correspond with the new session history entry.
2532 page_id_ = next_page_id_++;
2533
2534 MessageLoop::current()->PostDelayedTask(FROM_HERE,
2535 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2536 page_id_, true),
2537 kDelayForForcedCaptureMs);
2538 } else {
2539 // Inspect the navigation_state on this frame to see if the navigation
2540 // corresponds to a session history navigation... Note: |frame| may or
2541 // may not be the toplevel frame, but for the case of capturing session
2542 // history, the first committed frame suffices. We keep track of whether
2543 // we've seen this commit before so that only capture session history once
2544 // per navigation.
2545 //
2546 // Note that we need to check if the page ID changed. In the case of a
2547 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2548 // previous URL and the current page ID, which would be wrong.
2549 if (navigation_state->pending_page_id() != -1 &&
2550 navigation_state->pending_page_id() != page_id_ &&
2551 !navigation_state->request_committed()) {
2552 // This is a successful session history navigation!
2553 UpdateSessionHistory(frame);
2554 page_id_ = navigation_state->pending_page_id();
2555 }
2556 }
2557
2558 // Remember that we've already processed this request, so we don't update
2559 // the session history again. We do this regardless of whether this is
2560 // a session history navigation, because if we attempted a session history
2561 // navigation without valid HistoryItem state, WebCore will think it is a
2562 // new navigation.
2563 navigation_state->set_request_committed(true);
2564
2565 UpdateURL(frame);
2566
2567 // If this committed load was initiated by a client redirect, we're
2568 // at the last stop now, so clear it.
2569 completed_client_redirect_src_ = GURL();
2570
2571 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272572 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172573}
2574
2575void RenderView::didClearWindowObject(WebFrame* frame) {
2576 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2577 BindDOMAutomationController(frame);
2578 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2579 dom_ui_bindings_.set_message_sender(this);
2580 dom_ui_bindings_.set_routing_id(routing_id_);
2581 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2582 }
2583 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2584 external_host_bindings_.set_message_sender(this);
2585 external_host_bindings_.set_routing_id(routing_id_);
2586 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2587 }
2588}
2589
2590void RenderView::didCreateDocumentElement(WebFrame* frame) {
2591 if (RenderThread::current()) { // Will be NULL during unit tests.
2592 RenderThread::current()->user_script_slave()->InjectScripts(
2593 frame, UserScript::DOCUMENT_START);
2594 }
[email protected]078b34612009-09-19 19:31:512595 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2596 view_type_ == ViewType::EXTENSION_MOLE) {
2597 InjectToolstripCSS();
2598 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2599 }
[email protected]3d9689372009-09-10 04:29:172600
2601 // Notify the browser about non-blank documents loading in the top frame.
2602 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252603 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272604 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172605 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2606 }
2607}
2608
2609void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2610 UpdateTitle(frame, title);
2611
2612 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272613 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172614}
2615
2616void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2617 WebDataSource* ds = frame->dataSource();
2618 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2619 DCHECK(navigation_state);
2620 navigation_state->set_finish_document_load_time(Time::Now());
2621
2622 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2623
[email protected]e9e07992010-02-17 21:04:362624 // The document has now been fully loaded. Scan for forms to be sent up to
2625 // the browser.
2626 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482627 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362628 SendForms(frame);
[email protected]3d9689372009-09-10 04:29:172629 SendPasswordForms(frame);
2630
2631 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272632 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172633
2634 if (RenderThread::current()) { // Will be NULL during unit tests.
2635 RenderThread::current()->user_script_slave()->InjectScripts(
2636 frame, UserScript::DOCUMENT_END);
2637 }
[email protected]fa7b6b542009-11-03 05:02:302638
2639 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
[email protected]9e84a872010-02-09 18:23:422640
2641 if (page_translator_->IsPageTranslated())
2642 page_translator_->TranslateFrame(frame);
[email protected]fa7b6b542009-11-03 05:02:302643}
2644
2645void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2646 if (RenderThread::current()) { // Will be NULL during unit tests.
2647 RenderThread::current()->user_script_slave()->InjectScripts(
2648 frame, UserScript::DOCUMENT_IDLE);
2649 }
2650
2651 WebFrame* main_frame = webview()->mainFrame();
2652 if (frame == main_frame) {
2653 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202654 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302655 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202656 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302657 pending_code_execution_queue_.pop();
2658 }
2659 }
[email protected]3d9689372009-09-10 04:29:172660}
2661
2662void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2663 // Ignore
2664}
2665
2666void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2667 // Ignore
2668}
2669
2670void RenderView::didFinishLoad(WebFrame* frame) {
2671 WebDataSource* ds = frame->dataSource();
2672 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2673 DCHECK(navigation_state);
2674 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302675 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172676}
2677
2678void RenderView::didChangeLocationWithinPage(
2679 WebFrame* frame, bool is_new_navigation) {
2680 // If this was a reference fragment navigation that we initiated, then we
2681 // could end up having a non-null pending navigation state. We just need to
2682 // update the ExtraData on the datasource so that others who read the
2683 // ExtraData will get the new NavigationState. Similarly, if we did not
2684 // initiate this navigation, then we need to take care to reset any pre-
2685 // existing navigation state to a content-initiated navigation state.
2686 // DidCreateDataSource conveniently takes care of this for us.
2687 didCreateDataSource(frame, frame->dataSource());
2688
2689 didCommitProvisionalLoad(frame, is_new_navigation);
2690
[email protected]26aa0482009-09-30 16:55:272691 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]b6ad7ba2010-02-08 18:44:552692
2693 NavigationState* navigation_state = NavigationState::FromDataSource(
2694 frame->dataSource());
2695 navigation_state->user_script_idle_scheduler()->DidChangeLocationWithinPage();
[email protected]3d9689372009-09-10 04:29:172696}
2697
[email protected]476b6f82009-09-10 21:00:592698void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312699 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592700}
2701
[email protected]3d9689372009-09-10 04:29:172702void RenderView::assignIdentifierToRequest(
2703 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2704 // Ignore
2705}
2706
2707void RenderView::willSendRequest(
2708 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2709 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302710 WebFrame* top_frame = frame->top();
2711 if (!top_frame)
2712 top_frame = frame;
2713 WebDataSource* data_source = top_frame->provisionalDataSource();
2714 if (!data_source)
2715 data_source = top_frame->dataSource();
2716 if (data_source) {
2717 NavigationState* state = NavigationState::FromDataSource(data_source);
2718 if (state && state->is_cache_policy_override_set())
2719 request.setCachePolicy(state->cache_policy_override());
2720 }
[email protected]3d9689372009-09-10 04:29:172721 request.setRequestorID(routing_id_);
2722}
2723
2724void RenderView::didReceiveResponse(
2725 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]3d9689372009-09-10 04:29:172726 // Only do this for responses that correspond to a provisional data source
2727 // of the top-most frame. If we have a provisional data source, then we
2728 // can't have any sub-resources yet, so we know that this response must
2729 // correspond to a frame load.
2730 if (!frame->provisionalDataSource() || frame->parent())
2731 return;
2732
2733 // If we are in view source mode, then just let the user see the source of
2734 // the server's 404 error page.
2735 if (frame->isViewSourceModeEnabled())
2736 return;
2737
[email protected]f48013be2010-01-14 22:07:452738 // Record that this was a page loaded over SPDY.
2739 if (response.wasFetchedViaSPDY()) {
2740 NavigationState* navigation_state =
2741 NavigationState::FromDataSource(frame->provisionalDataSource());
2742 navigation_state->set_was_fetched_via_spdy(true);
2743 }
2744
2745 // Consider loading an alternate error page for 404 responses.
2746 if (response.httpStatusCode() != 404)
2747 return;
2748
[email protected]3d9689372009-09-10 04:29:172749 // Can we even load an alternate error page for this URL?
2750 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2751 return;
2752
2753 NavigationState* navigation_state =
2754 NavigationState::FromDataSource(frame->provisionalDataSource());
2755 navigation_state->set_postpone_loading_data(true);
2756 navigation_state->clear_postponed_data();
2757}
2758
2759void RenderView::didFinishResourceLoad(
2760 WebFrame* frame, unsigned identifier) {
2761 NavigationState* navigation_state =
2762 NavigationState::FromDataSource(frame->dataSource());
2763 if (!navigation_state->postpone_loading_data())
2764 return;
2765
2766 // The server returned a 404 and the content was < 512 bytes (which we
2767 // suppressed). Go ahead and fetch the alternate page content.
2768
2769 const GURL& frame_url = frame->url();
2770
2771 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2772 DCHECK(error_page_url.is_valid());
2773
2774 WebURLError original_error;
2775 original_error.unreachableURL = frame_url;
2776
2777 navigation_state->set_alt_error_page_fetcher(
2778 new AltErrorPageResourceFetcher(
2779 error_page_url, frame, original_error,
2780 NewCallback(this, &RenderView::AltErrorPageFinished)));
2781}
2782
2783void RenderView::didFailResourceLoad(
2784 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2785 // Ignore
2786}
2787
2788void RenderView::didLoadResourceFromMemoryCache(
2789 WebFrame* frame, const WebURLRequest& request,
2790 const WebURLResponse& response) {
2791 // Let the browser know we loaded a resource from the memory cache. This
2792 // message is needed to display the correct SSL indicators.
2793 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2794 routing_id_,
2795 request.url(),
[email protected]91733b62009-09-18 06:21:092796 frame->securityOrigin().toString().utf8(),
2797 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172798 response.securityInfo()));
2799}
2800
[email protected]6069da8c2009-10-20 20:33:492801void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292802 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2803}
2804
2805void RenderView::didRunInsecureContent(
2806 WebFrame* frame, const WebSecurityOrigin& origin) {
2807 Send(new ViewHostMsg_DidRunInsecureContent(
2808 routing_id_,
2809 origin.toString().utf8()));
2810}
2811
[email protected]7ea093ba2009-11-03 05:54:592812bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]684e4a42010-01-30 06:44:112813 if (enabled_per_settings) {
[email protected]2d30a7a2010-02-04 01:57:502814 return AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0de80162010-02-03 04:52:352815 enabled_per_settings);
[email protected]684e4a42010-01-30 06:44:112816 }
[email protected]7ea093ba2009-11-03 05:54:592817
2818 WebSecurityOrigin origin = frame->securityOrigin();
2819 if (origin.isEmpty())
2820 return false; // Uninitialized document?
2821
2822 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2823 return true; // Browser UI elements should still work.
2824
2825 // If the scheme is ftp: or file:, an empty file name indicates a directory
2826 // listing, which requires JavaScript to function properly.
2827 GURL frame_url = frame->url();
2828 const char* kDirProtocols[] = { "ftp", "file" };
2829 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2830 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2831 return frame_url.SchemeIs(kDirProtocols[i]) &&
2832 frame_url.ExtractFileName().empty();
2833 }
2834 }
2835
2836 return false; // Other protocols fall through here.
2837}
2838
[email protected]3d9689372009-09-10 04:29:172839void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2840 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2841}
2842
[email protected]0c882b282009-10-07 17:01:282843void RenderView::didCreateScriptContext(WebFrame* frame) {
2844 EventBindings::HandleContextCreated(frame, false);
2845}
2846
2847void RenderView::didDestroyScriptContext(WebFrame* frame) {
2848 EventBindings::HandleContextDestroyed(frame);
2849}
2850
2851void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2852 EventBindings::HandleContextCreated(frame, true);
2853}
2854
[email protected]3d9689372009-09-10 04:29:172855void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142856 CheckPreferredSize();
2857}
2858
2859void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172860 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252861 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172862 // message.
[email protected]ab32b16c2009-10-16 14:57:252863 if (send_preferred_size_changes_) {
[email protected]3d9689372009-09-10 04:29:172864 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252865 // cache the width and height and only send the IPC message when we're sure
2866 // they're different.
[email protected]26aa0482009-09-30 16:55:272867 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:392868 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:292869
[email protected]ab32b16c2009-10-16 14:57:252870 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:392871 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:252872 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:392873 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:252874
[email protected]ab32b16c2009-10-16 14:57:252875 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2876 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172877 }
2878 }
2879}
2880
[email protected]143dcd592009-11-06 21:33:492881void RenderView::didChangeScrollOffset(WebFrame* frame) {
2882 StartNavStateSyncTimerIfNecessary();
2883}
2884
[email protected]8922e1f2009-10-03 05:01:262885void RenderView::reportFindInPageMatchCount(int request_id, int count,
2886 bool final_update) {
2887 // If we have a message that has been queued up, then we should just replace
2888 // it. The ACK from the browser will make sure it gets sent when the browser
2889 // wants it.
2890 if (queued_find_reply_message_.get()) {
2891 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2892 routing_id_,
2893 request_id,
2894 count,
2895 gfx::Rect(),
2896 -1, // Don't update active match ordinal.
2897 final_update);
2898 queued_find_reply_message_.reset(msg);
2899 } else {
2900 // Send the search result over to the browser process.
2901 Send(new ViewHostMsg_Find_Reply(
2902 routing_id_,
2903 request_id,
2904 count,
2905 gfx::Rect(),
2906 -1, // // Don't update active match ordinal.
2907 final_update));
2908 }
2909}
2910
2911void RenderView::reportFindInPageSelection(int request_id,
2912 int active_match_ordinal,
2913 const WebRect& selection_rect) {
2914 // Send the search result over to the browser process.
2915 Send(new ViewHostMsg_Find_Reply(routing_id_,
2916 request_id,
2917 -1,
2918 selection_rect,
2919 active_match_ordinal,
2920 false));
2921}
2922
[email protected]79dbc662009-09-04 05:42:512923// webkit_glue::WebPluginPageDelegate -----------------------------------------
2924
[email protected]f103ab72009-09-02 17:10:592925webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
2926 const GURL& url,
2927 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:592928 std::string* actual_mime_type) {
2929 if (!PluginChannelHost::IsListening())
2930 return NULL;
2931
2932 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:272933 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:592934 if (main_frame)
2935 policy_url = main_frame->url();
2936
2937 FilePath path;
[email protected]610c0892009-09-08 19:46:182938 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2939 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:592940 if (path.value().empty())
2941 return NULL;
2942
2943 const std::string* mime_type_to_use;
2944 if (!actual_mime_type->empty())
2945 mime_type_to_use = actual_mime_type;
2946 else
2947 mime_type_to_use = &mime_type;
2948
[email protected]d2139662009-12-10 03:21:142949 bool use_pepper_host = false;
2950 bool in_process_plugin = RenderProcess::current()->in_process_plugins();
2951 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:162952 const char kPepperPrefix[] = "pepper-";
2953 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:142954 if (CommandLine::ForCurrentProcess()->
2955 HasSwitch(switches::kInternalPepper)) {
2956 in_process_plugin = true;
2957 use_pepper_host = true;
2958 } else {
2959 // In process Pepper plugins must be explicitly enabled.
2960 return NULL;
2961 }
[email protected]26e8d5e2009-10-13 02:47:162962 }
[email protected]d2139662009-12-10 03:21:142963 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:462964 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
2965 if (mime_type == "application/x-nacl-srpc") {
2966 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:142967 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:462968 }
2969 }
2970 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:142971 if (use_pepper_host) {
2972 return WebPluginDelegatePepper::Create(
[email protected]7477ea6f2009-12-22 23:28:152973 path,
2974 *mime_type_to_use,
[email protected]6876dff2010-01-15 19:38:092975 AsWeakPtr());
[email protected]d2139662009-12-10 03:21:142976 } else {
[email protected]6876dff2010-01-15 19:38:092977#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:142978 return WebPluginDelegateImpl::Create(
2979 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092980#else
[email protected]596b2c42010-01-14 20:40:432981 NOTIMPLEMENTED();
2982 return NULL;
[email protected]7b6616f2010-01-14 18:07:552983#endif
[email protected]6876dff2010-01-15 19:38:092984 }
[email protected]f103ab72009-09-02 17:10:592985 }
2986
[email protected]610c0892009-09-08 19:46:182987 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592988}
2989
2990void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
2991#if defined(OS_LINUX)
2992 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2993 routing_id(), window));
2994#endif
2995}
2996
2997void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
2998#if defined(OS_LINUX)
2999 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3000 routing_id(), window));
3001#endif
3002 CleanupWindowInPluginMoves(window);
3003}
3004
3005void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3006 SchedulePluginMove(move);
3007}
3008
3009void RenderView::DidStartLoadingForPlugin() {
3010 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523011 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593012}
3013
3014void RenderView::DidStopLoadingForPlugin() {
3015 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523016 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593017}
3018
[email protected]7e0831b2010-02-01 08:45:153019void RenderView::PageTranslated(int page_id,
3020 const std::string& original_lang,
3021 const std::string& target_lang) {
3022 Send(new ViewHostMsg_PageTranslated(routing_id_, page_id_,
3023 original_lang, target_lang));
3024}
3025
[email protected]f103ab72009-09-02 17:10:593026void RenderView::ShowModalHTMLDialogForPlugin(
3027 const GURL& url,
3028 const gfx::Size& size,
3029 const std::string& json_arguments,
3030 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213031 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593032 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213033 json_retval));
[email protected]f103ab72009-09-02 17:10:593034}
3035
initial.commit09911bf2008-07-26 23:55:293036void RenderView::SyncNavigationState() {
3037 if (!webview())
3038 return;
3039
[email protected]26aa0482009-09-30 16:55:273040 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173041 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293042 return;
[email protected]ca948a22009-06-25 19:36:173043
3044 Send(new ViewHostMsg_UpdateState(
3045 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293046}
3047
[email protected]b0950a72009-09-29 23:16:173048bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3049 // Make sure webview was not shut down.
3050 if (!webview())
3051 return false;
3052 // Create an image resource fetcher and assign it with a call back object.
3053 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273054 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173055 NewCallback(this, &RenderView::DidDownloadImage)));
3056 return true;
3057}
3058
3059void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293060 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173061 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473062 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3063 fetcher->id(),
3064 fetcher->image_url(),
3065 image.isNull(),
3066 image));
[email protected]b0950a72009-09-29 23:16:173067 // Dispose of the image fetcher.
3068 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3069 image_fetchers_.erase(fetcher);
3070 // We're in the callback from the ImageResourceFetcher, best to delay
3071 // deletion.
3072 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293073}
3074
[email protected]bf5c2ff392009-07-08 16:24:333075void RenderView::OnDownloadFavIcon(int id,
3076 const GURL& image_url,
3077 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343078 bool data_image_failed = false;
3079 if (image_url.SchemeIs("data")) {
3080 SkBitmap data_image = ImageFromDataUrl(image_url);
3081 data_image_failed = data_image.empty();
3082 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333083 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3084 data_image));
[email protected]f11ca0732009-04-11 00:09:343085 }
3086 }
3087
[email protected]bf5c2ff392009-07-08 16:24:333088 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173089 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333090 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3091 SkBitmap()));
3092 }
initial.commit09911bf2008-07-26 23:55:293093}
3094
[email protected]f11ca0732009-04-11 00:09:343095SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3096 std::string mime_type, char_set, data;
3097 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3098 // Decode the favicon using WebKit's image decoder.
3099 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3100 const unsigned char* src_data =
3101 reinterpret_cast<const unsigned char*>(&data[0]);
3102
3103 return decoder.Decode(src_data, data.size());
3104 }
3105 return SkBitmap();
3106}
3107
initial.commit09911bf2008-07-26 23:55:293108void RenderView::OnGetApplicationInfo(int page_id) {
3109 webkit_glue::WebApplicationInfo app_info;
3110 if (page_id == page_id_)
3111 webkit_glue::GetApplicationInfo(webview(), &app_info);
3112
3113 // Prune out any data URLs in the set of icons. The browser process expects
3114 // any icon with a data URL to have originated from a favicon. We don't want
3115 // to decode arbitrary data URLs in the browser process. See
3116 // http://b/issue?id=1162972
3117 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593118 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293119 app_info.icons.erase(app_info.icons.begin() + i);
3120 --i;
3121 }
3122 }
3123
3124 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3125}
3126
[email protected]7ccddb8c2009-08-04 17:36:553127GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293128 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553129 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293130 // If the URL that failed was secure, then the embedding web page was not
3131 // expecting a network attacker to be able to manipulate its contents. As
3132 // we fetch alternate error pages over HTTP, we would be allowing a network
3133 // attacker to manipulate the contents of the response if we tried to use
3134 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153135 return GURL();
initial.commit09911bf2008-07-26 23:55:293136 }
3137
3138 // Grab the base URL from the browser process.
3139 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153140 return GURL();
initial.commit09911bf2008-07-26 23:55:293141
3142 // Strip query params from the failed URL.
3143 GURL::Replacements remove_params;
3144 remove_params.ClearUsername();
3145 remove_params.ClearPassword();
3146 remove_params.ClearQuery();
3147 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553148 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
initial.commit09911bf2008-07-26 23:55:293149
3150 // Construct the query params to send to link doctor.
3151 std::string params(alternate_error_page_url_.query());
3152 params.append("&url=");
[email protected]0d2e6a62010-01-15 20:09:193153 params.append(EscapeQueryParamValue(url_to_send.spec(), true));
initial.commit09911bf2008-07-26 23:55:293154 params.append("&sourceid=chrome");
3155 params.append("&error=");
3156 switch (error_type) {
3157 case DNS_ERROR:
3158 params.append("dnserror");
3159 break;
3160
3161 case HTTP_404:
3162 params.append("http404");
3163 break;
3164
[email protected]5df266ac2008-10-15 19:50:133165 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333166 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133167 break;
3168
initial.commit09911bf2008-07-26 23:55:293169 default:
3170 NOTREACHED() << "unknown ErrorPageType";
3171 }
3172
3173 // OK, build the final url to return.
3174 GURL::Replacements link_doctor_params;
3175 link_doctor_params.SetQueryStr(params);
3176 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3177 return url;
3178}
3179
[email protected]6069da8c2009-10-20 20:33:493180void RenderView::OnFind(int request_id, const string16& search_text,
3181 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273182 WebFrame* main_frame = webview()->mainFrame();
[email protected]b4bb2502009-10-01 22:35:273183 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273184 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293185 WebFrame* search_frame = focused_frame; // start searching focused frame.
3186
3187 bool multi_frame = (frame_after_main != main_frame);
3188
3189 // If we have multiple frames, we don't want to wrap the search within the
3190 // frame, so we check here if we only have main_frame in the chain.
3191 bool wrap_within_frame = !multi_frame;
3192
[email protected]b3f2b912009-04-09 16:18:523193 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293194 bool result = false;
3195
[email protected]7830da3e2009-11-06 16:27:263196 // If something is selected when we start searching it means we cannot just
3197 // increment the current match ordinal; we need to re-generate it.
3198 WebRange current_selection = focused_frame->selectionRange();
3199
initial.commit09911bf2008-07-26 23:55:293200 do {
[email protected]dd7daa82009-08-10 05:46:453201 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593202 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293203
3204 if (!result) {
3205 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223206 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293207
3208 // Find the next frame, but skip the invisible ones.
3209 do {
3210 // What is the next frame to search? (we might be going backwards). Note
3211 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593212 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273213 search_frame->traverseNext(true) :
3214 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453215 } while (!search_frame->hasVisibleContent() &&
3216 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293217
[email protected]884db412008-11-24 23:46:503218 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223219 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293220
3221 // If we have multiple frames and we have wrapped back around to the
3222 // focused frame, we need to search it once more allowing wrap within
3223 // the frame, otherwise it will report 'no match' if the focused frame has
3224 // reported matches, but no frames after the focused_frame contain a
3225 // match for the search word(s).
3226 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453227 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593228 request_id, search_text, options, true, // Force wrapping.
3229 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293230 }
3231 }
3232
[email protected]26aa0482009-09-30 16:55:273233 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293234 } while (!result && search_frame != focused_frame);
3235
[email protected]7830da3e2009-11-06 16:27:263236 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293237 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453238 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293239 } else {
3240 // If nothing is found, set result to "0 of 0", otherwise, set it to
3241 // "-1 of 1" to indicate that we found at least one item, but we don't know
3242 // yet what is active.
3243 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3244 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293245
[email protected]4f3dc372009-02-24 00:10:293246 // If we find no matches then this will be our last status update.
3247 // Otherwise the scoping effort will send more results.
3248 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293249
[email protected]4f3dc372009-02-24 00:10:293250 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403251 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593252 request_id,
[email protected]4f3dc372009-02-24 00:10:293253 match_count,
3254 selection_rect,
3255 ordinal,
3256 final_status_update));
initial.commit09911bf2008-07-26 23:55:293257
initial.commit09911bf2008-07-26 23:55:293258 // Scoping effort begins, starting with the mainframe.
3259 search_frame = main_frame;
3260
[email protected]dd7daa82009-08-10 05:46:453261 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293262
3263 do {
3264 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453265 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293266
3267 // We don't start another scoping effort unless at least one match has
3268 // been found.
3269 if (result) {
3270 // Start new scoping request. If the scoping function determines that it
3271 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453272 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593273 search_text,
3274 options,
initial.commit09911bf2008-07-26 23:55:293275 true); // reset the tickmarks
3276 }
3277
3278 // Iterate to the next frame. The frame will not necessarily scope, for
3279 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273280 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293281 } while (search_frame != main_frame);
3282 }
3283}
3284
[email protected]8c4cdd42010-01-12 21:31:133285// static
3286std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
3287 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133288 int num_languages = 0;
3289 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423290 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133291 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423292 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133293 &num_languages, NULL);
3294 if (cld_language != NUM_LANGUAGES && cld_language != UNKNOWN_LANGUAGE &&
3295 cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483296 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3297 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263298 // language code for tradtional Chinese among others.
3299 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3300 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3301 // for Simplified Chinese.
3302 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133303 }
[email protected]8c4cdd42010-01-12 21:31:133304 return language;
[email protected]7893a982010-01-07 23:25:523305}
3306
[email protected]2d30a7a2010-02-04 01:57:503307bool RenderView::AllowContentType(ContentSettingsType settings_type,
[email protected]0de80162010-02-03 04:52:353308 bool enabled_per_settings) {
3309 if (!enabled_per_settings)
3310 return false;
3311 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]4c1b6f0b2010-02-07 16:38:183312 if (current_content_settings_.settings[settings_type] ==
3313 CONTENT_SETTING_BLOCK) {
[email protected]71b0d5d2010-02-15 05:43:073314 if (!content_blocked_[settings_type]) {
3315 content_blocked_[settings_type] = true;
[email protected]2d30a7a2010-02-04 01:57:503316 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
3317 }
[email protected]0de80162010-02-03 04:52:353318 return false;
3319 }
3320 return true;
3321}
3322
[email protected]71b0d5d2010-02-15 05:43:073323void RenderView::ClearBlockedContentSettings() {
3324 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3325 content_blocked_[i] = false;
3326}
3327
initial.commit09911bf2008-07-26 23:55:293328void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3329 Send(new ViewHostMsg_DnsPrefetch(host_names));
3330}
3331
[email protected]40bd6582009-12-04 23:49:513332void RenderView::OnZoom(PageZoom::Function function) {
3333 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3334 return;
3335
3336 int zoom_level = webview()->zoomLevel();
3337 int new_zoom_level = webview()->setZoomLevel(false,
3338 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3339
3340 // Tell the browser which host got zoomed so it can update the saved values.
3341 // Pages like the safe browsing interstitial can have empty hosts; don't
3342 // record those.
3343 std::string host(GURL(webview()->mainFrame()->url()).host());
3344 if (!host.empty())
3345 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3346}
3347
[email protected]f85f0702010-01-30 09:31:013348void RenderView::OnSetContentSettingsForLoadingHost(
3349 std::string host,
3350 const ContentSettings& content_settings) {
3351 host_content_settings_[host] = content_settings;
3352}
3353
[email protected]40bd6582009-12-04 23:49:513354void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3355 int zoom_level) {
3356 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293357}
3358
[email protected]41fc0322009-09-04 22:23:403359void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273360 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293361}
3362
[email protected]a697f4c2009-09-14 22:30:183363void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273364 WebString no_encoding;
3365 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183366}
3367
[email protected]20ad2692009-11-20 18:27:203368bool RenderView::GetAllChildFrames(
3369 WebFrame* parent_frame,
3370 std::vector<WebFrame*>* frames_vector) const {
3371 if (!parent_frame)
3372 return false;
3373 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3374 child_frame = child_frame->nextSibling()) {
3375 frames_vector->push_back(child_frame);
3376 GetAllChildFrames(child_frame, frames_vector);
3377 }
3378 return true;
3379}
3380
[email protected]dd7daa82009-08-10 05:46:453381WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3382 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273383 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453384
3385 // xpath string can represent a frame deep down the tree (across multiple
3386 // frame DOMs).
3387 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3388 // should break into 2 xpaths
3389 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3390
[email protected]26aa0482009-09-30 16:55:273391 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453392
3393 std::wstring xpath_remaining = xpath;
3394 while (!xpath_remaining.empty()) {
3395 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3396 std::wstring xpath_child;
3397 if (delim_pos != std::wstring::npos) {
3398 xpath_child = xpath_remaining.substr(0, delim_pos);
3399 xpath_remaining.erase(0, delim_pos + 1);
3400 } else {
3401 xpath_remaining.swap(xpath_child);
3402 }
3403 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293404 }
3405
[email protected]dd7daa82009-08-10 05:46:453406 return frame;
initial.commit09911bf2008-07-26 23:55:293407}
3408
[email protected]f29acf52008-11-03 20:08:333409void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3410 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293411 WebFrame* web_frame = GetChildFrame(frame_xpath);
3412 if (!web_frame)
3413 return;
3414
[email protected]dd7daa82009-08-10 05:46:453415 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293416}
3417
[email protected]1810e132009-03-24 23:35:483418void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083419 const std::string& css,
3420 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483421 WebFrame* web_frame = GetChildFrame(frame_xpath);
3422 if (!web_frame)
3423 return;
3424
[email protected]ffaef0c2009-09-15 17:08:083425 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483426}
3427
initial.commit09911bf2008-07-26 23:55:293428void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3429 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333430 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293431}
3432
[email protected]1810e132009-03-24 23:35:483433void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083434 const std::string& css,
3435 const std::string& id) {
3436 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413437
3438 // Notify RenderViewHost that css has been inserted into the frame.
3439 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483440}
3441
[email protected]7ea066a2009-04-06 20:21:593442void RenderView::OnAddMessageToConsole(
3443 const string16& frame_xpath,
3444 const string16& message,
3445 const WebConsoleMessage::Level& level) {
3446 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593447 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453448 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293449}
3450
[email protected]81e63782009-02-27 19:35:093451void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3452 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293453}
3454
3455void RenderView::OnSetDOMUIProperty(const std::string& name,
3456 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093457 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293458 dom_ui_bindings_.SetProperty(name, value);
3459}
3460
3461void RenderView::OnReservePageIDRange(int size_of_range) {
3462 next_page_id_ += size_of_range + 1;
3463}
3464
[email protected]e80c73b2009-04-07 23:24:583465void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3466 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253467 bool ended,
3468 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033469 if (ended) {
[email protected]26aa0482009-09-30 16:55:273470 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033471 }
initial.commit09911bf2008-07-26 23:55:293472}
3473
3474void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273475 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293476}
3477
initial.commit09911bf2008-07-26 23:55:293478void RenderView::OnFormFill(const FormData& form) {
3479 webkit_glue::FillForm(this->webview(), form);
3480}
3481
3482void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103483 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293484 webkit_glue::FillPasswordForm(this->webview(), form_data);
3485}
3486
3487void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583488 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253489 const gfx::Point& screen_point,
3490 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273491 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583492 drop_data.ToDragData(),
3493 drop_data.identity,
3494 client_point,
[email protected]1d9f4132009-09-08 17:29:253495 screen_point,
3496 ops);
initial.commit09911bf2008-07-26 23:55:293497
[email protected]1d9f4132009-09-08 17:29:253498 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293499}
3500
[email protected]e80c73b2009-04-07 23:24:583501void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253502 const gfx::Point& screen_point,
3503 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273504 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253505 client_point,
3506 screen_point,
3507 ops);
initial.commit09911bf2008-07-26 23:55:293508
[email protected]1d9f4132009-09-08 17:29:253509 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293510}
3511
3512void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273513 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293514}
3515
[email protected]e80c73b2009-04-07 23:24:583516void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3517 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273518 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293519}
3520
3521void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593522 webkit_preferences_ = prefs;
3523 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293524}
3525
3526void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3527 alternate_error_page_url_ = url;
3528}
3529
[email protected]a0c7153e2009-12-09 14:36:333530void RenderView::OnCustomContextMenuAction(unsigned action) {
3531 webview()->performCustomContextMenuAction(action);
3532}
3533
[email protected]d4a00a72010-01-29 01:44:423534void RenderView::OnTranslatePage(int page_id,
3535 const std::string& source_lang,
3536 const std::string& target_lang) {
3537 if (page_id != page_id_)
3538 return; // Not the page we expected, nothing to do.
3539
3540 WebFrame* main_frame = webview()->mainFrame();
3541 if (!main_frame)
3542 return;
[email protected]9e84a872010-02-09 18:23:423543
3544 page_translator_->TranslatePage(page_id, main_frame,
3545 source_lang, target_lang);
[email protected]d4a00a72010-01-29 01:44:423546}
3547
[email protected]0bedb8a2010-01-14 19:36:323548void RenderView::OnTranslateTextResponse(
3549 int work_id, int error_id, const std::vector<string16>& text_chunks) {
[email protected]d4a00a72010-01-29 01:44:423550 text_translator_.OnTranslationResponse(work_id, error_id, text_chunks);
[email protected]0bedb8a2010-01-14 19:36:323551}
3552
initial.commit09911bf2008-07-26 23:55:293553void RenderView::OnInstallMissingPlugin() {
3554 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593555 if (first_default_plugin_)
3556 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293557}
3558
[email protected]b62d1a8c2009-01-13 23:54:573559void RenderView::OnFileChooserResponse(
[email protected]561abe62009-04-06 18:08:343560 const std::vector<FilePath>& file_names) {
[email protected]8029f5672009-03-20 22:33:363561 // This could happen if we navigated to a different page before the user
3562 // closed the chooser.
[email protected]a1128322009-10-06 18:38:463563 if (!file_chooser_completion_)
[email protected]8029f5672009-03-20 22:33:363564 return;
3565
[email protected]6069da8c2009-10-20 20:33:493566 WebVector<WebString> ws_file_names(file_names.size());
[email protected]a1128322009-10-06 18:38:463567 for (size_t i = 0; i < file_names.size(); ++i) {
3568 ws_file_names[i] = webkit_glue::FilePathToWebString(file_names[i]);
3569 }
3570
3571 file_chooser_completion_->didChooseFile(ws_file_names);
3572 // Reset the chooser pointer
3573 file_chooser_completion_ = NULL;
initial.commit09911bf2008-07-26 23:55:293574}
3575
3576void RenderView::OnEnableViewSourceMode() {
3577 if (!webview())
3578 return;
[email protected]26aa0482009-09-30 16:55:273579 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293580 if (!main_frame)
3581 return;
3582
[email protected]dd7daa82009-08-10 05:46:453583 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293584}
3585
[email protected]ab32b16c2009-10-16 14:57:253586void RenderView::OnEnablePreferredSizeChangedMode() {
3587 send_preferred_size_changes_ = true;
[email protected]d8a179c2010-01-31 00:58:143588 if (CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
3589 switches::kProcessType) == switches::kExtensionProcess) {
3590 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3591 &RenderView::CheckPreferredSize);
3592 }
[email protected]0666aef2009-05-13 19:48:083593}
3594
[email protected]80d96fa2009-06-10 22:34:513595void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3596 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373597 UpdateFontRenderingFromRendererPrefs();
[email protected]033970a2009-10-14 16:45:053598#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]1c83eb42009-09-11 21:08:413599 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3600 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463601 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323602
[email protected]644d77e2010-01-27 01:03:103603 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323604 webview()->setScrollbarColors(
3605 renderer_prefs.thumb_inactive_color,
3606 renderer_prefs.thumb_active_color,
3607 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103608 webview()->setSelectionColors(
3609 renderer_prefs.active_selection_bg_color,
3610 renderer_prefs.active_selection_fg_color,
3611 renderer_prefs.inactive_selection_bg_color,
3612 renderer_prefs.inactive_selection_fg_color);
3613 }
[email protected]7a74e102009-09-03 00:16:563614#endif
[email protected]80d96fa2009-06-10 22:34:513615}
3616
[email protected]952cb702009-10-07 05:50:283617void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3618 const WebMediaPlayerAction& action) {
3619 if (webview())
3620 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563621}
3622
[email protected]7b291f92009-08-14 05:43:533623void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513624 // When this is first set, the bindings aren't fully loaded. We only need
3625 // to call through this API after the page has already been loaded. It's
3626 // also called in didCreateDocumentElement to bootstrap.
3627 if (view_type_ != ViewType::INVALID) {
3628 if (type == ViewType::EXTENSION_MOLE ||
3629 type == ViewType::EXTENSION_TOOLSTRIP) {
3630 ExtensionProcessBindings::SetViewType(webview(), type);
3631 }
3632 }
[email protected]7b291f92009-08-14 05:43:533633 view_type_ = type;
3634}
3635
3636void RenderView::OnUpdateBrowserWindowId(int window_id) {
3637 browser_window_id_ = window_id;
3638}
3639
initial.commit09911bf2008-07-26 23:55:293640void RenderView::OnUpdateBackForwardListCount(int back_list_count,
3641 int forward_list_count) {
3642 history_back_list_count_ = back_list_count;
3643 history_forward_list_count_ = forward_list_count;
3644}
3645
[email protected]266eb6f2008-09-30 23:56:503646void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253647 const webkit_glue::WebAccessibility::InParams& in_params,
3648 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573649#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153650 if (!accessibility_.get()) {
3651 // TODO(dglazkov): Once implemented for all ports, remove lazy
3652 // instantiation of accessibility_.
3653 accessibility_.reset(WebAccessibilityCache::create());
3654 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253655 }
[email protected]266eb6f2008-09-30 23:56:503656
[email protected]c7287a92009-11-04 20:06:153657 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3658 in_params,
3659 out_params);
3660
[email protected]6c8afae52009-01-22 02:24:573661#else // defined(OS_WIN)
3662 // TODO(port): accessibility not yet implemented
3663 NOTIMPLEMENTED();
3664#endif
[email protected]266eb6f2008-09-30 23:56:503665}
3666
[email protected]6a983b42009-03-20 20:12:253667void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573668#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153669 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503670 // If accessibility is not activated, ignore clearing message.
3671 return;
3672 }
[email protected]e846d0d2009-05-20 00:53:063673
[email protected]c7287a92009-11-04 20:06:153674 if (clear_all) {
3675 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503676 return;
[email protected]c7287a92009-11-04 20:06:153677 }
3678
3679 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063680
[email protected]6c8afae52009-01-22 02:24:573681#else // defined(OS_WIN)
3682 // TODO(port): accessibility not yet implemented
3683 NOTIMPLEMENTED();
3684#endif
[email protected]266eb6f2008-09-30 23:56:503685}
3686
initial.commit09911bf2008-07-26 23:55:293687void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3688 const GURL& page_url) {
3689 // Prepare list to storage all savable resource links.
3690 std::vector<GURL> resources_list;
3691 std::vector<GURL> referrers_list;
3692 std::vector<GURL> frames_list;
3693 webkit_glue::SavableResourcesResult result(&resources_list,
3694 &referrers_list,
3695 &frames_list);
3696
[email protected]dbeb3952009-10-13 18:01:183697 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3698 webview(),
3699 page_url,
3700 &result,
3701 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293702 // If something is wrong when collecting all savable resource links,
3703 // send empty list to embedder(browser) to tell it failed.
3704 referrers_list.clear();
3705 resources_list.clear();
3706 frames_list.clear();
3707 }
3708
3709 // Send result of all savable resource links to embedder.
3710 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3711 resources_list,
3712 referrers_list,
3713 frames_list));
3714}
3715
3716void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323717 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313718 const std::vector<FilePath>& local_paths,
3719 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073720
3721 // Convert std::vector of GURLs to WebVector<WebURL>
3722 WebVector<WebURL> weburl_links(links);
3723
3724 // Convert std::vector of std::strings to WebVector<WebString>
3725 WebVector<WebString> webstring_paths(local_paths.size());
3726 for (size_t i = 0; i < local_paths.size(); i++)
3727 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3728
3729 WebPageSerializer::serialize(webview()->mainFrame(),
3730 true, this, weburl_links, webstring_paths,
3731 webkit_glue::FilePathToWebString(
3732 local_directory_name));
initial.commit09911bf2008-07-26 23:55:293733}
3734
[email protected]d9ec5c0f2009-12-23 11:55:073735void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
3736 const WebCString& data,
3737 WebPageSerializerClient::PageSerializationStatus status) {
3738 Send(new ViewHostMsg_SendSerializedHtmlData(
3739 routing_id_,
3740 frame_url,
3741 data.data(),
3742 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:293743}
3744
[email protected]04b4a6c2008-08-02 00:44:473745void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273746 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473747 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293748}
3749
[email protected]eb6b87a2009-07-24 15:57:393750void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293751 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3752 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3753 // in the onunload handler from appearing. For now, we're bypassing that and
3754 // calling the FrameLoader's CloseURL method directly. This should be
3755 // revisited to avoid having two ways to close a page. Having a single way
3756 // to close that can run onunload is also useful for fixing
3757 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273758 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293759 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453760 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173761 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293762 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3763 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:453764 if (url.SchemeIs(chrome::kHttpScheme) ||
3765 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:293766 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:293767 }
[email protected]26aa0482009-09-30 16:55:273768 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293769
[email protected]eb6b87a2009-07-24 15:57:393770 // Just echo back the params in the ACK.
3771 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:293772}
3773
3774void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573775#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:293776 gfx::NativeTheme::instance()->CloseHandles();
3777 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:283778 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:573779#else // defined(OS_WIN)
3780 // TODO(port): we don't support theming on non-Windows platforms yet
3781 NOTIMPLEMENTED();
3782#endif
initial.commit09911bf2008-07-26 23:55:293783}
3784
[email protected]28790922009-03-09 19:48:373785void RenderView::OnMessageFromExternalHost(const std::string& message,
3786 const std::string& origin,
3787 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:153788 if (message.empty())
3789 return;
3790
[email protected]28790922009-03-09 19:48:373791 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
3792 target);
[email protected]3ac14a052008-08-15 21:22:153793}
3794
[email protected]0aa55312008-10-17 21:53:083795void RenderView::OnDisassociateFromPopupCount() {
3796 if (decrement_shared_popup_at_destruction_)
3797 shared_popup_counter_->data--;
3798 shared_popup_counter_ = new SharedRenderViewCounter(0);
3799 decrement_shared_popup_at_destruction_ = false;
3800}
3801
[email protected]15d79e12009-08-02 19:23:453802bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3803 const WebURLError& error,
3804 bool replace) {
3805 // We only show alternate error pages in the main frame. They are
3806 // intended to assist the user when navigating, so there is not much
3807 // value in showing them for failed subframes. Ideally, we would be
3808 // able to use the TYPED transition type for this, but that flag is
3809 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453810 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453811 return false;
3812
3813 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373814 // connection failure.
[email protected]15d79e12009-08-02 19:23:453815 int ec = error.reason;
3816 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3817 ec != net::ERR_CONNECTION_FAILED &&
3818 ec != net::ERR_CONNECTION_REFUSED &&
3819 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373820 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453821 return false;
3822
3823 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553824 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453825 if (!error_page_url.is_valid())
3826 return false;
3827
3828 // Load an empty page first so there is an immediate response to the error,
3829 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453830 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:453831 GURL(kUnreachableWebDataURL),
3832 error.unreachableURL,
3833 replace);
3834
3835 // Now, create a fetcher for the error page and associate it with the data
3836 // source we just created via the LoadHTMLString call. That way if another
3837 // navigation occurs, the fetcher will get destroyed.
3838 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453839 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453840 navigation_state->set_alt_error_page_fetcher(
3841 new AltErrorPageResourceFetcher(
3842 error_page_url, frame, error,
3843 NewCallback(this, &RenderView::AltErrorPageFinished)));
3844 return true;
3845}
3846
initial.commit09911bf2008-07-26 23:55:293847std::string RenderView::GetAltHTMLForTemplate(
3848 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:393849 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:293850 ResourceBundle::GetSharedInstance().GetRawDataResource(
3851 template_resource_id));
3852
3853 if (template_html.empty()) {
3854 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
3855 return "";
3856 }
[email protected]7cd22a52009-07-14 00:40:253857
initial.commit09911bf2008-07-26 23:55:293858 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:253859 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:293860 template_html, &error_strings, "t");
3861}
[email protected]0e79b9e2009-02-13 04:20:483862
[email protected]15d79e12009-08-02 19:23:453863void RenderView::AltErrorPageFinished(WebFrame* frame,
3864 const WebURLError& original_error,
3865 const std::string& html) {
3866 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:553867
3868 // If we failed to download the alternate error page, fall back to the
3869 // original error page if present. Otherwise, LoadNavigationErrorPage
3870 // will simply display a default error page.
3871 const std::string* html_to_load = &html;
3872 if (html.empty()) {
3873 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453874 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:553875 html_to_load = &navigation_state->postponed_data();
3876 }
3877 LoadNavigationErrorPage(
3878 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:453879}
3880
[email protected]30f75e62009-02-25 22:01:003881void RenderView::OnMoveOrResizeStarted() {
3882 if (webview())
[email protected]4605325d2010-02-08 23:46:043883 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:003884}
3885
[email protected]30f75e62009-02-25 22:01:003886void RenderView::OnResize(const gfx::Size& new_size,
3887 const gfx::Rect& resizer_rect) {
3888 if (webview())
[email protected]4605325d2010-02-08 23:46:043889 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:003890 RenderWidget::OnResize(new_size, resizer_rect);
3891}
[email protected]0aa477bd2009-03-23 22:21:433892
[email protected]05d478752009-04-08 23:38:163893void RenderView::OnClearFocusedNode() {
3894 if (webview())
[email protected]26aa0482009-09-30 16:55:273895 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163896}
3897
[email protected]699ab0d2009-04-23 23:19:143898void RenderView::OnSetBackground(const SkBitmap& background) {
3899 if (webview())
[email protected]b4bb2502009-10-01 22:35:273900 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143901
3902 SetBackground(background);
3903}
3904
[email protected]8c66c5a2009-07-22 17:26:343905void RenderView::OnSetActive(bool active) {
3906 if (webview())
[email protected]b4bb2502009-10-01 22:35:273907 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263908
3909#if defined(OS_MACOSX)
3910 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3911 for (plugin_it = plugin_delegates_.begin();
3912 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3913 (*plugin_it)->SetWindowFocus(active);
3914 }
3915#endif
[email protected]8c66c5a2009-07-22 17:26:343916}
3917
[email protected]6ce7abc52010-02-02 18:40:143918#if defined(OS_MACOSX)
3919void RenderView::OnSetWindowVisibility(bool visible) {
3920 // Inform plugins that their container has changed visibility.
3921 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3922 for (plugin_it = plugin_delegates_.begin();
3923 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3924 (*plugin_it)->SetContainerVisibility(visible);
3925 }
3926}
[email protected]1e6e3c992010-02-08 15:52:133927
3928void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
3929 gfx::Rect view_frame) {
3930 // Inform plugins that their window's frame has changed.
3931 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3932 for (plugin_it = plugin_delegates_.begin();
3933 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3934 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3935 }
3936}
[email protected]6ce7abc52010-02-02 18:40:143937#endif // OS_MACOSX
3938
[email protected]309d7a282009-03-24 09:18:273939void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:583940 const ListValue& args,
[email protected]c6619182009-05-12 14:59:323941 int request_id,
[email protected]2f25d7b92009-06-10 00:06:473942 bool has_callback) {
[email protected]c6619182009-05-12 14:59:323943 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:473944 has_callback));
[email protected]309d7a282009-03-24 09:18:273945}
3946
[email protected]c6619182009-05-12 14:59:323947void RenderView::OnExtensionResponse(int request_id,
3948 bool success,
3949 const std::string& response,
3950 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:353951 ExtensionProcessBindings::HandleResponse(
3952 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:273953}
[email protected]c20210e62009-04-03 21:39:263954
[email protected]078b34612009-09-19 19:31:513955void RenderView::InjectToolstripCSS() {
3956 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
3957 return;
3958
3959 static const base::StringPiece toolstrip_css(
3960 ResourceBundle::GetSharedInstance().GetRawDataResource(
3961 IDR_EXTENSION_TOOLSTRIP_CSS));
3962 std::string css = toolstrip_css.as_string();
3963 InsertCSS(L"", css, "ToolstripDefaultCSS");
3964}
3965
[email protected]7120f132009-07-20 21:05:373966void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
3967 const ListValue& args) {
3968 RendererExtensionBindings::Invoke(function_name, args, this);
3969}
3970
[email protected]e7e4f3c2009-04-21 15:24:083971// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:263972//
[email protected]7a9b51f2009-06-29 21:28:293973// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:263974// The time points we keep are
3975// request: time document was requested by user
3976// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:253977// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:293978// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:263979// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:293980// first_paint: first paint performed
3981// first_paint_after_load: first paint performed after load is finished
3982// begin: request if it was user requested, start otherwise
3983//
[email protected]c20210e62009-04-03 21:39:263984// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:253985// request->start,
[email protected]7a9b51f2009-06-29 21:28:293986// start->commit,
3987// commit->finish_document,
3988// finish_document->finish,
3989// begin->commit,
3990// begin->finishDoc,
3991// begin->finish,
3992// begin->first_paint,
3993// begin->first_paint_after_load
3994// commit->finishDoc,
3995// commit->first_paint,
3996// commit->first_paint_after_load,
3997// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:263998//
[email protected]e7e4f3c2009-04-21 15:24:083999// It's possible for the request time not to be set, if a client
4000// redirect had been done (the user never requested the page)
4001// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294002// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264003void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274004 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564005 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454006 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294007 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564008
[email protected]7a9b51f2009-06-29 21:28:294009 // If we've already dumped or we haven't finished loading, do nothing.
4010 if (navigation_state->load_histograms_recorded() || finish.is_null())
4011 return;
[email protected]ed3fb032009-06-16 19:50:564012
[email protected]f8999642009-10-27 21:39:424013 LogNavigationState(navigation_state, main_frame->dataSource());
4014
[email protected]a7ccc4d2010-01-27 08:14:484015 NavigationState::LoadType load_type = navigation_state->load_type();
4016 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184017 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484018
[email protected]7a9b51f2009-06-29 21:28:294019 Time request = navigation_state->request_time();
4020 Time start = navigation_state->start_load_time();
4021 Time commit = navigation_state->commit_load_time();
4022 Time finish_doc = navigation_state->finish_document_load_time();
4023 Time first_paint = navigation_state->first_paint_time();
4024 Time first_paint_after_load =
4025 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:264026
[email protected]7a9b51f2009-06-29 21:28:294027 Time begin;
4028 // Client side redirects will have no request time.
4029 if (request.is_null()) {
4030 begin = start;
4031 } else {
4032 begin = request;
4033 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084034 }
[email protected]7a9b51f2009-06-29 21:28:294035 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4036 UMA_HISTOGRAM_MEDIUM_TIMES(
4037 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4038 UMA_HISTOGRAM_MEDIUM_TIMES(
4039 "Renderer4.FinishDocToFinish", finish - finish_doc);
4040
4041 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484042
4043 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4044 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4045 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484046 TimeDelta begin_to_finish_doc = finish_doc - begin;
4047 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184048
4049 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4050 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4051 static const size_t kBeginToFinishBucketCount(100);
4052 TimeDelta begin_to_finish = finish_doc - begin;
4053 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4054 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4055
[email protected]a7ccc4d2010-01-27 08:14:484056 switch (load_type) {
4057 case NavigationState::UNDEFINED_LOAD:
4058 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4059 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4060 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184061 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4062 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4063 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484064 break;
4065 case NavigationState::RELOAD:
4066 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4067 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4068 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184069 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4070 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4071 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484072 break;
4073 case NavigationState::HISTORY_LOAD:
4074 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4075 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4076 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184077 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4078 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4079 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484080 break;
4081 case NavigationState::NORMAL_LOAD:
4082 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4083 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4084 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184085 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4086 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4087 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484088 break;
[email protected]4c1b6f0b2010-02-07 16:38:184089 case NavigationState::LINK_LOAD_NORMAL:
4090 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484091 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4092 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184093 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4094 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4095 kBeginToFinishBucketCount);
4096 break;
4097 case NavigationState::LINK_LOAD_RELOAD:
4098 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4099 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4100 kBeginToFinishDocBucketCount);
4101 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4102 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4103 kBeginToFinishBucketCount);
4104 break;
4105 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4106 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4107 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4108 kBeginToFinishDocBucketCount);
4109 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4110 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4111 kBeginToFinishBucketCount);
4112 break;
4113 case NavigationState::LINK_LOAD_CACHE_ONLY:
4114 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4115 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4116 kBeginToFinishDocBucketCount);
4117 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4118 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4119 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484120 break;
4121 default:
4122 break;
4123 }
4124
4125 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4126 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4127 if (use_dns_histogram) {
4128 switch (load_type) {
4129 case NavigationState::NORMAL_LOAD:
4130 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4131 "Renderer4.BeginToFinishDoc_NormalLoad", "DnsImpact"),
4132 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4133 kBeginToFinishDocBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484134 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184135 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4136 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4137 kBeginToFinishBucketCount);
4138 break;
4139 case NavigationState::LINK_LOAD_NORMAL:
4140 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4141 "Renderer4.BeginToFinishDoc_LinkLoadNormal", "DnsImpact"),
[email protected]a7ccc4d2010-01-27 08:14:484142 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4143 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184144 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4145 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4146 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4147 kBeginToFinishBucketCount);
4148 break;
4149 case NavigationState::LINK_LOAD_RELOAD:
4150 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4151 "Renderer4.BeginToFinishDoc_LinkLoadReload", "DnsImpact"),
4152 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4153 kBeginToFinishDocBucketCount);
4154 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4155 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4156 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4157 kBeginToFinishBucketCount);
4158 break;
4159 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4160 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4161 "Renderer4.BeginToFinishDoc_LinkLoadStaleOk", "DnsImpact"),
4162 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4163 kBeginToFinishDocBucketCount);
4164 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4165 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4166 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4167 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484168 break;
4169 default:
4170 break;
4171 }
4172 }
4173
4174 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4175 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4176 if (use_sdch_histogram) {
4177 switch (load_type) {
4178 case NavigationState::NORMAL_LOAD:
4179 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4180 "Renderer4.BeginToFinishDoc_NormalLoad", "GlobalSdch"),
4181 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4182 kBeginToFinishDocBucketCount);
4183 break;
[email protected]4c1b6f0b2010-02-07 16:38:184184 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484185 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184186 "Renderer4.BeginToFinishDoc_LinkLoadNormal", "GlobalSdch"),
4187 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4188 kBeginToFinishDocBucketCount);
4189 break;
4190 case NavigationState::LINK_LOAD_RELOAD:
4191 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4192 "Renderer4.BeginToFinishDoc_LinkLoadReload", "GlobalSdch"),
4193 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4194 kBeginToFinishDocBucketCount);
4195 break;
4196 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4197 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4198 "Renderer4.BeginToFinishDoc_LinkLoadCacheStaleOk", "GlobalSdch"),
4199 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4200 kBeginToFinishDocBucketCount);
4201 break;
4202 case NavigationState::LINK_LOAD_CACHE_ONLY:
4203 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4204 "Renderer4.BeginToFinishDoc_LinkLoadCacheOnly", "GlobalSdch"),
[email protected]a7ccc4d2010-01-27 08:14:484205 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4206 kBeginToFinishDocBucketCount);
4207 break;
4208 default:
4209 break;
4210 }
4211 }
4212
4213 static bool use_socket_late_binding_histogram =
4214 FieldTrialList::Find("SocketLateBinding") &&
4215 !FieldTrialList::Find("SocketLateBinding")->group_name().empty();
4216 if (use_socket_late_binding_histogram) {
4217 switch (load_type) {
4218 case NavigationState::NORMAL_LOAD:
4219 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4220 "Renderer4.BeginToFinishDoc_NormalLoad", "SocketLateBinding"),
4221 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4222 kBeginToFinishDocBucketCount);
4223 break;
[email protected]4c1b6f0b2010-02-07 16:38:184224 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484225 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184226 "Renderer4.BeginToFinishDoc_LinkLoadNormal", "SocketLateBinding"),
4227 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4228 kBeginToFinishDocBucketCount);
4229 break;
4230 case NavigationState::LINK_LOAD_RELOAD:
4231 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4232 "Renderer4.BeginToFinishDoc_LinkLoadReload", "SocketLateBinding"),
[email protected]a7ccc4d2010-01-27 08:14:484233 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4234 kBeginToFinishDocBucketCount);
4235 break;
4236 default:
4237 break;
4238 }
4239 }
4240
4241 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4242 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184243 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4244 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484245 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4246 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4247 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4248 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544249
[email protected]0a32257a2009-07-09 18:10:414250 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4251 finish - start, kBeginToFinishMin,
4252 kBeginToFinishMax, kBeginToFinishBucketCount);
4253 if (!request.is_null())
4254 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4255 finish - request, kBeginToFinishMin,
4256 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544257
[email protected]7a9b51f2009-06-29 21:28:294258 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4259
4260 if (!first_paint.is_null()) {
4261 UMA_HISTOGRAM_MEDIUM_TIMES(
4262 "Renderer4.BeginToFirstPaint", first_paint - begin);
4263 UMA_HISTOGRAM_MEDIUM_TIMES(
4264 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264265 }
[email protected]7a9b51f2009-06-29 21:28:294266
4267 if (!first_paint_after_load.is_null()) {
4268 UMA_HISTOGRAM_MEDIUM_TIMES(
4269 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4270 UMA_HISTOGRAM_MEDIUM_TIMES(
4271 "Renderer4.CommitToFirstPaintAfterLoad",
4272 first_paint_after_load - commit);
4273 UMA_HISTOGRAM_MEDIUM_TIMES(
4274 "Renderer4.FinishToFirstPaintAfterLoad",
4275 first_paint_after_load - finish);
4276 }
4277
4278 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414279
4280 // Since there are currently no guarantees that renderer histograms will be
4281 // sent to the browser, we initiate a PostTask here to be sure that we send
4282 // the histograms we generated. Without this call, pages that don't have an
4283 // on-close-handler might generate data that is lost when the renderer is
4284 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484285 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4286 // should post when the onload is complete, so that it doesn't interfere with
4287 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414288 if (RenderThread::current()) {
4289 RenderThread::current()->SendHistograms(
4290 HistogramSynchronizer::kReservedSequenceNumber);
4291 }
[email protected]c20210e62009-04-03 21:39:264292}
[email protected]e846d0d2009-05-20 00:53:064293
[email protected]f8999642009-10-27 21:39:424294void RenderView::LogNavigationState(const NavigationState* state,
4295 const WebDataSource* ds) const {
4296 // Because this function gets called on every page load,
4297 // take extra care to optimize it away if logging is turned off.
4298 if (logging::LOG_INFO < logging::GetMinLogLevel())
4299 return;
4300
4301 DCHECK(state);
4302 DCHECK(ds);
4303 GURL url(ds->request().url());
4304 Time start = state->start_load_time();
4305 Time finish = state->finish_load_time();
4306 // TODO(mbelshe): should we log more stats?
4307 LOG(INFO) << "PLT: "
4308 << (finish - start).InMilliseconds()
4309 << "ms "
4310 << url.spec();
4311}
4312
[email protected]cc0445f2009-10-13 16:09:084313void RenderView::focusAccessibilityObject(
4314 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064315#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154316 // TODO(dglazkov): Current logic implies that focus change can only be made
4317 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4318 // where accessibility is initialized. We should determine whether that's
4319 // right.
4320 if (!accessibility_.get())
4321 return;
[email protected]e846d0d2009-05-20 00:53:064322
4323 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154324 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064325
4326 // If id is valid, alert the browser side that an accessibility focus change
4327 // occurred.
4328 if (acc_obj_id >= 0)
4329 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4330
4331#else // defined(OS_WIN)
4332 // TODO(port): accessibility not yet implemented
4333 NOTIMPLEMENTED();
4334#endif
4335}
[email protected]daa8c58e2009-06-15 17:21:104336
[email protected]e9e07992010-02-17 21:04:364337void RenderView::SendForms(WebFrame* frame) {
4338 WebVector<WebFormElement> web_forms;
4339 frame->forms(web_forms);
4340
4341 std::vector<FormFieldValues> forms;
4342 for (size_t i = 0; i < web_forms.size(); ++i) {
4343 const WebFormElement& web_form = web_forms[i];
4344
4345 if (web_form.autoComplete()) {
4346 scoped_ptr<FormFieldValues> form(FormFieldValues::Create(web_form));
4347 if (form.get())
4348 forms.push_back(*form);
4349 }
4350 }
4351
4352 if (!forms.empty())
4353 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
4354}
4355
[email protected]daa8c58e2009-06-15 17:21:104356void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:484357 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454358 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104359
4360 std::vector<PasswordForm> password_forms;
4361 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484362 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104363
4364 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:484365 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:104366 scoped_ptr<PasswordForm> password_form(
4367 PasswordFormDomManager::CreatePasswordForm(form));
4368 if (password_form.get())
4369 password_forms.push_back(*password_form);
4370 }
4371 }
4372
4373 if (!password_forms.empty())
4374 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4375}
[email protected]0fda7272009-06-26 15:49:334376
4377void RenderView::Print(WebFrame* frame, bool script_initiated) {
4378 DCHECK(frame);
4379 if (print_helper_.get() == NULL) {
4380 print_helper_.reset(new PrintWebViewHelper(this));
4381 }
4382 print_helper_->Print(frame, script_initiated);
4383}
[email protected]446705872009-09-10 07:22:484384
4385void RenderView::OnSetEditCommandsForNextKeyEvent(
4386 const EditCommands& edit_commands) {
4387 edit_commands_ = edit_commands;
4388}
4389
[email protected]61f5a7b2009-12-22 22:21:204390void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274391 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354392 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204393 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4394 false));
[email protected]912256b32009-09-18 09:47:354395 return;
4396 }
4397
[email protected]fa7b6b542009-11-03 05:02:304398 WebDataSource* ds = main_frame->dataSource();
4399 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4400 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204401 pending_code_execution_queue_.push(
4402 linked_ptr<ViewMsg_ExecuteCode_Params>(
4403 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304404 return;
4405 }
4406
[email protected]61f5a7b2009-12-22 22:21:204407 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304408}
4409
4410void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204411 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484412 // Don't execute scripts in gallery pages.
4413 GURL frame_url = GURL(frame->url());
4414 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4415 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4416 return;
4417 }
4418
[email protected]20ad2692009-11-20 18:27:204419 std::vector<WebFrame*> frame_vector;
4420 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204421 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204422 GetAllChildFrames(frame, &frame_vector);
4423
4424 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4425 frame_it != frame_vector.end(); ++frame_it) {
4426 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204427 if (params.is_javascript) {
4428 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4429 continue;
4430
[email protected]20ad2692009-11-20 18:27:204431 std::vector<WebScriptSource> sources;
4432 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204433 WebScriptSource(WebString::fromUTF8(params.code)));
4434 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204435 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204436 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204437 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4438 } else {
[email protected]61f5a7b2009-12-22 22:21:204439 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204440 }
[email protected]912256b32009-09-18 09:47:354441 }
4442
[email protected]61f5a7b2009-12-22 22:21:204443 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354444}
4445
[email protected]60c42a8c72009-10-09 04:08:594446void RenderView::Close() {
4447 // We need to grab a pointer to the doomed WebView before we destroy it.
4448 WebView* doomed = webview();
4449 RenderWidget::Close();
4450 Singleton<ViewMap>::get()->erase(doomed);
4451}
4452
[email protected]446705872009-09-10 07:22:484453void RenderView::DidHandleKeyEvent() {
4454 edit_commands_.clear();
4455}
4456
[email protected]941e4552010-02-01 21:23:434457#if defined(OS_MACOSX)
4458void RenderView::OnWasHidden() {
4459 RenderWidget::OnWasHidden();
4460
4461 // Inform plugins that their container is no longer visible.
4462 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4463 for (plugin_it = plugin_delegates_.begin();
4464 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4465 (*plugin_it)->SetContainerVisibility(false);
4466 }
4467}
4468
4469void RenderView::OnWasRestored(bool needs_repainting) {
4470 RenderWidget::OnWasRestored(needs_repainting);
4471
4472 // Inform plugins that their container is now visible.
4473 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4474 for (plugin_it = plugin_delegates_.begin();
4475 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4476 (*plugin_it)->SetContainerVisibility(true);
4477 }
4478}
[email protected]1e6e3c992010-02-08 15:52:134479
4480void RenderView::OnSetFocus(bool enable) {
4481 RenderWidget::OnSetFocus(enable);
4482
4483 // RenderWidget's call to setFocus can cause the underlying webview's
4484 // activation state to change just like a call to setIsActive.
4485 if (enable && webview() && webview()->isActive()) {
4486 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4487 for (plugin_it = plugin_delegates_.begin();
4488 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4489 (*plugin_it)->SetWindowFocus(true);
4490 }
4491 }
4492}
[email protected]941e4552010-02-01 21:23:434493#endif // OS_MACOSX
4494
[email protected]83dde542009-09-11 20:59:554495void RenderView::EnsureDocumentTag() {
4496 // TODO(darin): There's actually no reason for this to be here. We should
4497 // have the browser side manage the document tag.
4498#if defined(OS_MACOSX)
4499 if (!has_document_tag_) {
4500 // Make the call to get the tag.
4501 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4502 has_document_tag_ = true;
4503 }
4504#endif
4505}
[email protected]12636df2009-09-28 22:32:214506
[email protected]43f28f832010-02-03 02:28:484507#if defined(OS_MACOSX)
4508gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle() {
4509 gfx::PluginWindowHandle window = NULL;
4510 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
4511 routing_id(), &window));
4512 return window;
4513}
4514
4515void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4516 if (window)
4517 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4518}
4519
4520void RenderView::GPUPluginSetIOSurface(gfx::PluginWindowHandle window,
4521 int32 width,
4522 int32 height,
4523 uint64 io_surface_identifier) {
4524 Send(new ViewHostMsg_GPUPluginSetIOSurface(
4525 routing_id(), window, width, height, io_surface_identifier));
4526}
4527
4528void RenderView::GPUPluginBuffersSwapped(gfx::PluginWindowHandle window) {
4529 Send(new ViewHostMsg_GPUPluginBuffersSwapped(routing_id(), window));
4530}
4531#endif
[email protected]58c321d2010-02-19 12:11:284532
4533WebKit::WebGeolocationServiceInterface* RenderView::getGeolocationService() {
4534 if (!geolocation_dispatcher_.get())
4535 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
4536 return geolocation_dispatcher_.get();
4537}
4538