blob: 71bebdc7ce747c5e884106b81c4efc643dba89ec [file] [log] [blame]
[email protected]810a52ef2010-01-08 01:22:151// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
8#include <string>
9#include <vector>
10
[email protected]a92b8642009-05-05 23:38:5611#include "app/l10n_util.h"
[email protected]37126212009-05-06 02:23:3112#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1113#include "app/resource_bundle.h"
[email protected]2041cf342010-02-19 03:15:5914#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2915#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5016#include "base/compiler_specific.h"
[email protected]4646f292009-05-20 03:49:0517#include "base/field_trial.h"
[email protected]30507922010-01-15 16:48:2318#include "base/histogram.h"
[email protected]8380c092009-06-25 17:45:5119#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5320#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/string_piece.h"
22#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2323#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5724#include "build/build_config.h"
[email protected]81e63782009-02-27 19:35:0925#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5526#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2927#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1728#include "chrome/common/chrome_constants.h"
[email protected]d146b832009-12-23 02:45:4829#include "chrome/common/extensions/extension_constants.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1731#include "chrome/common/page_zoom.h"
[email protected]e09ba552009-02-05 03:26:2932#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2633#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2934#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5935#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2537#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1138#include "chrome/renderer/devtools_agent.h"
39#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3540#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3241#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3542#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3743#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2844#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5646#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1147#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5648#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1249#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3050#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5051#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2552#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2853#include "chrome/renderer/render_thread.h"
[email protected]bd92c3a2010-01-13 05:02:3454#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4655#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3556#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2957#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2958#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2959#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4260#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5661#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1562#include "gfx/color_utils.h"
63#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5764#include "gfx/native_widget_types.h"
[email protected]34ac8f32009-02-22 23:03:2765#include "grit/generated_resources.h"
66#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3467#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2968#include "net/base/escape.h"
69#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0070#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1071#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3072#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]58c321d2010-02-19 12:11:2873#include "third_party/WebKit/WebKit/chromium/public/GeolocationServiceBridgeChromium.h"
[email protected]418ed5ab2009-11-12 01:14:4974#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
75#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0776#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4977#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
78#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3279#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4980#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3581#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]418ed5ab2009-11-12 01:14:4982#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
83#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
84#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:4185#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]95056b582010-02-18 01:29:2486#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4987#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3288#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0789#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:4990#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
91#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4992#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
93#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
95#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
96#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
98#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:3499#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49100#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
102#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
103#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
104#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
105#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]80f584d92010-01-21 03:59:04106#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29107#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29108#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24109#include "webkit/glue/form_field.h"
110#include "webkit/glue/form_field_values.h"
111#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34112#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17113#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51114#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29115#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29116#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30117#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23118#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30119#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]8400e032010-02-26 18:50:11120#include "webkit/glue/media/video_renderer_impl.h"
initial.commit09911bf2008-07-26 23:55:29121#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29122#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17123#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29124
[email protected]6c8afae52009-01-22 02:24:57125#if defined(OS_WIN)
126// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57127// * theming
[email protected]cd818412010-03-19 03:23:15128#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03129#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46130#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]6c8afae52009-01-22 02:24:57131#endif
132
[email protected]80f584d92010-01-21 03:59:04133using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26134using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33135using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45136using webkit_glue::AltErrorPageResourceFetcher;
[email protected]95056b582010-02-18 01:29:24137using webkit_glue::FormField;
[email protected]51bd36612009-10-20 22:49:47138using webkit_glue::FormFieldValues;
[email protected]b0950a72009-09-29 23:16:17139using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56140using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10141using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15142using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08143using WebKit::WebAccessibilityObject;
[email protected]1c83eb42009-09-11 21:08:41144using WebKit::WebColor;
145using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59146using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44147using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51148using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07149using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55150using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28151using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29152using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00153using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58154using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25155using WebKit::WebDragOperation;
156using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51157using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47158using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49159using WebKit::WebFindOptions;
[email protected]979c28b2009-11-07 01:30:48160using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45161using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17162using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41163using WebKit::WebImage;
[email protected]95056b582010-02-18 01:29:24164using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17165using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28166using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17167using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28168using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28169using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51170using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07171using WebKit::WebPageSerializer;
172using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17173using WebKit::WebPlugin;
174using WebKit::WebPluginParams;
[email protected]24a7f3c2010-03-25 08:26:49175using WebKit::WebPluginDocument;
[email protected]48c9cf2d2009-09-16 16:47:52176using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59177using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51178using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52179using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40180using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35181using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29182using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59183using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42184using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02185using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34186using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28187using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51188using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52189using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28190using WebKit::WebURL;
191using WebKit::WebURLError;
192using WebKit::WebURLRequest;
193using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28194using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03195using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28196using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43197using WebKit::WebWorker;
198using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33199
initial.commit09911bf2008-07-26 23:55:29200//-----------------------------------------------------------------------------
201
202// define to write the time necessary for thumbnail/DOM text retrieval,
203// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29204// #define TIME_TEXT_RETRIEVAL
205
206// maximum number of characters in the document to index, any text beyond this
207// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57208static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29209
210// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37211static const int kThumbnailWidth = 212;
212static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29213
214// Delay in milliseconds that we'll wait before capturing the page contents
215// and thumbnail.
216static const int kDelayForCaptureMs = 500;
217
218// Typically, we capture the page data once the page is loaded.
219// Sometimes, the page never finishes to load, preventing the page capture
220// To workaround this problem, we always perform a capture after the following
221// delay.
222static const int kDelayForForcedCaptureMs = 6000;
223
[email protected]882daa92009-11-05 16:31:31224// Time, in seconds, we delay before sending content state changes (such as form
225// state and scroll position) to the browser. We delay sending changes to avoid
226// spamming the browser.
227// To avoid having tab/session restore require sending a message to get the
228// current content state during tab closing we use a shorter timeout for the
229// foreground renderer. This means there is a small window of time from which
230// content state is modified and not sent to session restore, but this is
231// better than having to wake up all renderers during shutdown.
232static const int kDelaySecondsForContentStateSyncHidden = 5;
233static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29234
[email protected]0aa55312008-10-17 21:53:08235// The maximum number of popups that can be spawned from one page.
236static const int kMaximumNumberOfUnacknowledgedPopups = 25;
237
initial.commit09911bf2008-07-26 23:55:29238static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16239 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29240
[email protected]50b691c2008-10-31 19:08:35241static const char* const kBackForwardNavigationScheme = "history";
242
[email protected]8c4cdd42010-01-12 21:31:13243// The string returned in DetectLanguage if we failed to detect the language.
[email protected]8dc5a2052010-01-19 21:32:42244static const char* const kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13245
[email protected]726985e22009-06-18 21:09:28246static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
247 WebVector<WebURL> urls;
248 ds->redirectChain(urls);
249 result->reserve(urls.size());
250 for (size_t i = 0; i < urls.size(); ++i)
251 result->push_back(urls[i]);
252}
253
[email protected]61f5a7b2009-12-22 22:21:20254static bool UrlMatchesPermissions(
255 const GURL& url, const std::vector<URLPattern>& host_permissions) {
256 for (size_t i = 0; i < host_permissions.size(); ++i) {
257 if (host_permissions[i].MatchesUrl(url))
258 return true;
259 }
260
261 return false;
262}
263
[email protected]30507922010-01-15 16:48:23264static bool PaintViewIntoCanvas(WebView* view,
265 skia::PlatformCanvas& canvas) {
266 view->layout();
267 const WebSize& size = view->size();
268
269 if (!canvas.initialize(size.width, size.height, true))
270 return false;
271
272 view->paint(webkit_glue::ToWebCanvas(&canvas),
273 WebRect(0, 0, size.width, size.height));
274 // TODO: Add a way to snapshot the whole page, not just the currently
275 // visible part.
276
277 return true;
278}
279
280// Calculates how "boring" a thumbnail is. The boring score is the
281// 0,1 ranged percentage of pixels that are the most common
282// luma. Higher boring scores indicate that a higher percentage of a
283// bitmap are all the same brightness.
284static double CalculateBoringScore(SkBitmap* bitmap) {
285 int histogram[256] = {0};
286 color_utils::BuildLumaHistogram(bitmap, histogram);
287
288 int color_count = *std::max_element(histogram, histogram + 256);
289 int pixel_count = bitmap->width() * bitmap->height();
290 return static_cast<double>(color_count) / pixel_count;
291}
292
initial.commit09911bf2008-07-26 23:55:29293///////////////////////////////////////////////////////////////////////////////
294
[email protected]60c42a8c72009-10-09 04:08:59295int32 RenderView::next_page_id_ = 1;
296
[email protected]cdaf8d02010-03-30 19:52:47297struct RenderView::PendingFileChooser {
298 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
299 WebFileChooserCompletion* c)
300 : params(p),
301 completion(c) {
302 }
303 ViewHostMsg_RunFileChooser_Params params;
304 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
305};
306
[email protected]2fab253a2009-08-17 23:00:59307RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34308 const WebPreferences& webkit_preferences,
309 int64 session_storage_namespace_id)
[email protected]81a34412009-01-05 19:17:24310 : RenderWidget(render_thread, true),
[email protected]81e63782009-02-27 19:35:09311 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21312 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24313 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21314 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24315 page_id_(-1),
316 last_page_id_sent_to_browser_(-1),
317 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24318 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46319 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50320 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11321 devtools_agent_(NULL),
322 devtools_client_(NULL),
[email protected]3cc72b12010-03-18 23:03:00323 history_list_offset_(-1),
324 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24325 has_unload_listener_(false),
326 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a12009-10-16 03:53:39327 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24328 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26329 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31330 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25331 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26332 ALLOW_THIS_IN_INITIALIZER_LIST(
333 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53334 view_type_(ViewType::INVALID),
335 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55336 last_top_level_navigation_page_id_(-1),
337#if defined(OS_MACOSX)
338 has_document_tag_(false),
339#endif
[email protected]98324892009-09-09 21:16:05340 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32341 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34342 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]b921cfd22010-02-25 16:57:51343 ALLOW_THIS_IN_INITIALIZER_LIST(text_translator_(this)),
[email protected]ab9eabac2010-03-16 16:54:10344 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
345 cross_origin_access_count_(0),
346 same_origin_access_count_(0) {
[email protected]71b0d5d2010-02-15 05:43:07347 ClearBlockedContentSettings();
[email protected]7e0831b2010-02-01 08:45:15348 page_translator_.reset(new PageTranslator(&text_translator_, this));
initial.commit09911bf2008-07-26 23:55:29349}
350
351RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08352 if (decrement_shared_popup_at_destruction_)
353 shared_popup_counter_->data--;
354
[email protected]b0950a72009-09-29 23:16:17355 // Dispose of un-disposed image fetchers.
356 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
357 i != image_fetchers_.end(); ++i) {
358 delete *i;
359 }
360
[email protected]a1128322009-10-06 18:38:46361 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47362 while (!file_chooser_completions_.empty()) {
363 if (file_chooser_completions_.front()->completion) {
364 file_chooser_completions_.front()->completion->didChooseFile(
365 WebVector<WebString>());
366 }
367 file_chooser_completions_.pop_front();
368 }
[email protected]a1128322009-10-06 18:38:46369
[email protected]83dde542009-09-11 20:59:55370#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05371 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55372 if (has_document_tag_)
373 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
374#endif
[email protected]98324892009-09-09 21:16:05375
[email protected]5fb88962009-04-16 19:03:25376 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59377
378#ifndef NDEBUG
379 // Make sure we are no longer referenced by the ViewMap.
380 ViewMap* views = Singleton<ViewMap>::get();
381 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
382 DCHECK_NE(this, it->second) << "Failed to call Close?";
383#endif
384}
385
386/*static*/
387void RenderView::ForEach(RenderViewVisitor* visitor) {
388 ViewMap* views = Singleton<ViewMap>::get();
389 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
390 if (!visitor->Visit(it->second))
391 return;
392 }
393}
394
395/*static*/
396RenderView* RenderView::FromWebView(WebView* webview) {
397 ViewMap* views = Singleton<ViewMap>::get();
398 ViewMap::iterator it = views->find(webview);
399 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29400}
401
402/*static*/
[email protected]0aa55312008-10-17 21:53:08403RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24404 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15405 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08406 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51407 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08408 const WebPreferences& webkit_prefs,
409 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34410 int32 routing_id,
411 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29412 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34413 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
414 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29415 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29416 opener_id,
[email protected]80d96fa2009-06-10 22:34:51417 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08418 counter,
initial.commit09911bf2008-07-26 23:55:29419 routing_id); // adds reference
420 return view;
421}
422
423/*static*/
424void RenderView::SetNextPageID(int32 next_page_id) {
425 // This method should only be called during process startup, and the given
426 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05427 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29428 DCHECK(next_page_id >= next_page_id_);
429 next_page_id_ = next_page_id;
430}
431
[email protected]afe3a1672009-11-17 19:04:12432void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56433 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
434}
435
[email protected]a3a8fb6d2009-10-22 20:12:51436void RenderView::PluginCrashed(const FilePath& plugin_path) {
437 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29438}
439
[email protected]d8fd6fa2010-02-01 15:54:26440#if defined(OS_MACOSX)
441void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
442 plugin_delegates_.insert(delegate);
443}
444
445void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
446 plugin_delegates_.erase(delegate);
447}
448#endif
449
[email protected]18bcc3c2009-01-27 21:39:15450void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29451 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51452 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08453 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29454 int32 routing_id) {
455 DCHECK(!webview());
456
457 if (opener_id != MSG_ROUTING_NONE)
458 opener_id_ = opener_id;
459
[email protected]0aa55312008-10-17 21:53:08460 if (counter) {
461 shared_popup_counter_ = counter;
462 shared_popup_counter_->data++;
463 decrement_shared_popup_at_destruction_ = true;
464 } else {
465 shared_popup_counter_ = new SharedRenderViewCounter(0);
466 decrement_shared_popup_at_destruction_ = false;
467 }
468
[email protected]58bfc6b2009-06-24 09:45:02469 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04470
[email protected]50ae00ef2009-10-19 05:11:03471 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59472 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59473 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27474 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29475 webview()->setDevToolsAgent(
476 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29477
[email protected]d3ba77272009-09-03 00:06:09478 OnSetRendererPrefs(renderer_prefs);
479
initial.commit09911bf2008-07-26 23:55:29480 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24481 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29482 // Take a reference on behalf of the RenderThread. This will be balanced
483 // when we receive ViewMsg_Close.
484 AddRef();
485
486 // If this is a popup, we must wait for the CreatingNew_ACK message before
487 // completing initialization. Otherwise, we can finish it now.
488 if (opener_id == MSG_ROUTING_NONE) {
489 did_show_ = true;
490 CompleteInit(parent_hwnd);
491 }
492
493 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29494
[email protected]58bfc6b2009-06-24 09:45:02495 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09496 if (command_line.HasSwitch(switches::kDomAutomationController))
497 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29498
[email protected]5fb88962009-04-16 19:03:25499 audio_message_filter_ = new AudioMessageFilter(routing_id_);
500 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29501}
502
503void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27504 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27505 if (main_frame)
506 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26507
[email protected]b2abac72009-02-26 12:39:28508 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11509 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28510 return;
[email protected]b4b967e2009-04-22 11:33:05511 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
512 return;
[email protected]b6849bda2009-10-14 23:59:26513 if (notification_provider_->OnMessageReceived(message))
514 return;
[email protected]58c321d2010-02-19 12:11:28515 if (geolocation_dispatcher_.get() &&
516 geolocation_dispatcher_->OnMessageReceived(message)) {
517 return;
518 }
[email protected]b2abac72009-02-26 12:39:28519
initial.commit09911bf2008-07-26 23:55:29520 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29521 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23522 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29523 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01524 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29525 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
526 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56527 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29528 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
initial.commit09911bf2008-07-26 23:55:29529 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
530 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
531 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
532 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27533#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35534 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27535#endif
initial.commit09911bf2008-07-26 23:55:29536 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
537 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05538 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
539 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
540 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04541 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29542 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
543 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
544 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15545 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29546 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49547 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
548 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17549 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]f85f0702010-01-30 09:31:01550 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost,
551 OnSetContentSettingsForLoadingHost)
[email protected]40bd6582009-12-04 23:49:51552 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
553 OnSetZoomLevelForLoadingHost)
initial.commit09911bf2008-07-26 23:55:29554 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18555 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
556 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28557 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33558 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29559 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48560 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29561 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29562 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29563 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
564 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
565 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
566 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
567 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45568 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29569 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50570 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
571 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29572 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
573 OnDragSourceSystemDragEnded)
574 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29575 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
576 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
577 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
578 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
579 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
580 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29581 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
582 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04583 IPC_MESSAGE_HANDLER(
584 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
585 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29586 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50587 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
588 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
589 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29590 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
591 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
592 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45593 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
594 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08595 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
596 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24597 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
598 OnAutoFillSuggestionsReturned)
599 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
600 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48601 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
602 OnAutoFillFormDataFilled)
[email protected]2c4410d2009-05-06 23:46:22603 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
604 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00605 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27606 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37607 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
608 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16609 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14610 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25611 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
612 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10613 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
614 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51615 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53616 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
617 OnUpdateBrowserWindowId)
618 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
619 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56620 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34621 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14622#if defined(OS_MACOSX)
623 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13624 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14625#endif
[email protected]446705872009-09-10 07:22:48626 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33627 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35628 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
629 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33630 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
631 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42632 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]0bedb8a2010-01-14 19:36:32633 IPC_MESSAGE_HANDLER(ViewMsg_TranslateTextReponse, OnTranslateTextResponse)
[email protected]634a6f92008-12-01 21:39:31634
initial.commit09911bf2008-07-26 23:55:29635 // Have the super handle all other messages.
636 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
637 IPC_END_MESSAGE_MAP()
638}
639
initial.commit09911bf2008-07-26 23:55:29640void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27641 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29642 if (!main_frame)
643 return;
644
645 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45646 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29647 if (url.is_empty())
648 return;
649
650 if (size_.IsEmpty())
651 return; // Don't create an empty thumbnail!
652
653 ThumbnailScore score;
654 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02655 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15656 &thumbnail, &score))
657 return;
658
initial.commit09911bf2008-07-26 23:55:29659 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46660 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29661}
662
[email protected]30507922010-01-15 16:48:23663void RenderView::SendSnapshot() {
664 SkBitmap snapshot;
665 bool error = false;
666
667 WebFrame* main_frame = webview()->mainFrame();
668 if (!main_frame)
669 error = true;
670
671 if (!error && !CaptureSnapshot(webview(), &snapshot))
672 error = true;
673
674 DCHECK(error == snapshot.empty()) <<
675 "Snapshot should be empty on error, non-empty otherwise.";
676
677 // Send the snapshot to the browser process.
678 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
679}
680
[email protected]068637222009-01-29 16:58:07681void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29682 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58683 if (webview()) {
684 // If the user has selected text in the currently focused frame we print
685 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27686 if (webview()->focusedFrame()->hasSelection())
687 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58688 else
[email protected]26aa0482009-09-30 16:55:27689 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58690 }
initial.commit09911bf2008-07-26 23:55:29691}
692
[email protected]82270452009-06-19 15:58:01693void RenderView::OnPrintingDone(int document_cookie, bool success) {
694 // Ignoring document cookie here since only one print job can be outstanding
695 // per renderer and document_cookie is 0 when printing is successful.
696 DCHECK(print_helper_.get());
697 if (print_helper_.get() != NULL) {
698 print_helper_->DidFinishPrinting(success);
699 }
700}
701
initial.commit09911bf2008-07-26 23:55:29702void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
703 if (load_id != page_id_)
704 return; // this capture call is no longer relevant due to navigation
705 if (load_id == last_indexed_page_id_)
706 return; // we already indexed this page
707
708 if (!webview())
709 return;
710
[email protected]26aa0482009-09-30 16:55:27711 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29712 if (!main_frame)
713 return;
714
715 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45716 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29717 return;
718
719 // Don't index/capture pages that failed to load. This only checks the top
720 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45721 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28722 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29723 return;
724
725 if (!preliminary_capture)
726 last_indexed_page_id_ = load_id;
727
[email protected]a8a81292010-01-21 00:32:45728 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45729 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29730 if (url.is_empty())
731 return;
732
[email protected]a8a81292010-01-21 00:32:45733 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29734 std::wstring contents;
735 CaptureText(main_frame, &contents);
736 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45737 base::TimeTicks begin_time = base::TimeTicks::Now();
738 std::string language = DetermineTextLanguage(contents);
739 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
740 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52741
[email protected]a8a81292010-01-21 00:32:45742 // Send the text to the browser for indexing (the browser might decide not
743 // to index, if the URL is HTTPS for instance) and language discovery.
744 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
745 language));
[email protected]5c4266922009-07-10 16:41:27746 }
747
initial.commit09911bf2008-07-26 23:55:29748 // thumbnail
749 SendThumbnail();
750}
751
752void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
753 contents->clear();
754 if (!frame)
755 return;
756
757#ifdef TIME_TEXT_RETRIEVAL
758 double begin = time_util::GetHighResolutionTimeNow();
759#endif
760
761 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45762 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29763
764#ifdef TIME_TEXT_RETRIEVAL
765 double end = time_util::GetHighResolutionTimeNow();
766 char buf[128];
767 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
768 contents.size(), (end - begin)*1000);
769 OutputDebugStringA(buf);
770#endif
771
772 // When the contents are clipped to the maximum, we don't want to have a
773 // partial word indexed at the end that might have been clipped. Therefore,
774 // terminate the string at the last space to ensure no words are clipped.
775 if (contents->size() == kMaxIndexChars) {
776 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
777 if (last_space_index == std::wstring::npos)
778 return; // don't index if we got a huge block of text with no spaces
779 contents->resize(last_space_index);
780 }
781}
782
[email protected]8649fb32009-06-26 17:51:02783bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29784 int w,
785 int h,
786 SkBitmap* thumbnail,
787 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23788 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15789
[email protected]8649fb32009-06-26 17:51:02790 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23791
792 // Paint |view| into |canvas|.
793 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02794 return false;
[email protected]8649fb32009-06-26 17:51:02795
796 skia::BitmapPlatformDevice& device =
797 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
798
799 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29800
[email protected]cab34d6a2009-09-24 01:14:52801 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29802 float dest_aspect = dest_rect.width() / dest_rect.height();
803
804 // Get the src rect so that we can preserve the aspect ratio while filling
805 // the destination.
806 SkIRect src_rect;
807 if (src_bmp.width() < dest_rect.width() ||
808 src_bmp.height() < dest_rect.height()) {
809 // Source image is smaller: we clip the part of source image within the
810 // dest rect, and then stretch it to fill the dest rect. We don't respect
811 // the aspect ratio in this case.
812 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
813 static_cast<S16CPU>(dest_rect.height()));
814 score->good_clipping = false;
815 } else {
816 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
817 if (src_aspect > dest_aspect) {
818 // Wider than tall, clip horizontally: we center the smaller thumbnail in
819 // the wider screen.
820 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
821 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
822 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
823 score->good_clipping = false;
824 } else {
825 src_rect.set(0, 0, src_bmp.width(),
826 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
827 score->good_clipping = true;
828 }
829 }
830
[email protected]26aa0482009-09-30 16:55:27831 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29832
833 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02834 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29835
836 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14837 *thumbnail = skia::ImageOperations::Resize(
838 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29839
840 score->boring_score = CalculateBoringScore(thumbnail);
841
[email protected]30507922010-01-15 16:48:23842 HISTOGRAM_TIMES("Renderer4.Thumbnail",
843 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15844 return true;
initial.commit09911bf2008-07-26 23:55:29845}
846
[email protected]30507922010-01-15 16:48:23847bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
848 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29849
[email protected]30507922010-01-15 16:48:23850 skia::PlatformCanvas canvas;
851 if (!PaintViewIntoCanvas(view, canvas))
852 return false;
853
854 skia::BitmapPlatformDevice& device =
855 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
856
857 const SkBitmap& bitmap = device.accessBitmap(false);
858 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
859 return false;
860
861 HISTOGRAM_TIMES("Renderer4.Snapshot",
862 base::TimeTicks::Now() - beginning_time);
863 return true;
initial.commit09911bf2008-07-26 23:55:29864}
865
866void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
867 if (!webview())
868 return;
869
[email protected]3cc72b12010-03-18 23:03:00870 history_list_offset_ = params.current_history_list_offset;
871 history_list_length_ = params.current_history_list_length;
872
[email protected]8c785c62009-07-13 14:20:15873 if (devtools_agent_.get())
874 devtools_agent_->OnNavigate();
875
[email protected]422197532010-01-25 17:38:23876 if (notification_provider_.get())
877 notification_provider_->OnNavigate();
878
[email protected]a9f607e2009-10-23 19:59:27879 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26880
initial.commit09911bf2008-07-26 23:55:29881 AboutHandler::MaybeHandle(params.url);
882
[email protected]ecbf10d2010-02-18 13:03:29883 bool is_reload =
884 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
885 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29886
[email protected]26aa0482009-09-30 16:55:27887 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45888 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29889 // We cannot reload if we do not have any history state. This happens, for
890 // example, when recovering from a crash. Our workaround here is a bit of
891 // a hack since it means that reload after a crashed tab does not cause an
892 // end-to-end cache validation.
893 is_reload = false;
894 }
895
[email protected]77f17a82009-05-21 04:42:54896 // A navigation resulting from loading a javascript URL should not be treated
897 // as a browser initiated event. Instead, we want it to look as if the page
898 // initiated any load resulting from JS execution.
899 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30900 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00901 params.page_id,
902 params.pending_history_list_offset,
903 params.transition,
904 params.request_time);
[email protected]5e369672009-11-03 23:48:30905 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
906 // We're doing a load of a page that was restored from the last session.
907 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
908 // which can result in stale data for pages that are set to expire. We
909 // explicitly override that by setting the policy here so that as
910 // necessary we load from the network.
911 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
912 }
913 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54914 }
initial.commit09911bf2008-07-26 23:55:29915
[email protected]a7ccc4d2010-01-27 08:14:48916 NavigationState* navigation_state = pending_navigation_state_.get();
917
[email protected]04d3c6e2009-05-22 17:00:13918 // If we are reloading, then WebKit will use the history state of the current
919 // page, so we should just ignore any given history state. Otherwise, if we
920 // have history state, then we need to navigate to it, which corresponds to a
921 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55922 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48923 if (navigation_state)
924 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29925 bool ignore_cache = (params.navigation_type ==
926 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
927 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55928 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13929 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58930 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48931 if (navigation_state)
932 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45933 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17934 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13935 } else {
936 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28937 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29938
[email protected]e6f546c32009-07-01 17:12:55939 // A session history navigation should have been accompanied by state.
940 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13941
[email protected]dd7daa82009-08-10 05:46:45942 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55943 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13944
[email protected]726985e22009-06-18 21:09:28945 if (params.referrer.is_valid()) {
946 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
947 WebString::fromUTF8(params.referrer.spec()));
948 }
[email protected]04d3c6e2009-05-22 17:00:13949
[email protected]a7ccc4d2010-01-27 08:14:48950 if (navigation_state)
951 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45952 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50953 }
954
[email protected]77f17a82009-05-21 04:42:54955 // In case LoadRequest failed before DidCreateDataSource was called.
956 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29957}
958
959// Stop loading the current page
960void RenderView::OnStop() {
961 if (webview())
[email protected]b4bb2502009-10-01 22:35:27962 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29963}
964
[email protected]ecbf10d2010-02-18 13:03:29965// Reload current focused frame.
966// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56967void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29968 if (webview() && webview()->focusedFrame()) {
969 // We always obey the cache (ignore_cache=false) here.
970 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
971 // a cache-ignoring reload of the frame.
972 webview()->focusedFrame()->reload(false);
973 }
[email protected]1dda4022010-01-28 18:24:56974}
975
[email protected]e6f546c32009-07-01 17:12:55976void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29977 bool new_navigation,
978 const GURL& display_url,
979 const std::string& security_info) {
980 if (!webview())
981 return;
982
[email protected]e6f546c32009-07-01 17:12:55983 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00984 new_navigation ? -1 : page_id_,
985 history_list_offset_,
986 PageTransition::LINK,
987 Time::Now()));
[email protected]e6f546c32009-07-01 17:12:55988 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29989
[email protected]26aa0482009-09-30 16:55:27990 webview()->mainFrame()->loadHTMLString(
991 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55992
993 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29994}
995
996void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27997 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29998}
999
[email protected]68b1e922009-06-23 16:00:251000void RenderView::OnExecuteEditCommand(const std::string& name,
1001 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271002 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251003 return;
1004
[email protected]26aa0482009-09-30 16:55:271005 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451006 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251007}
1008
[email protected]b2abac72009-02-26 12:39:281009void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111010 DCHECK(!devtools_client_.get());
1011 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281012}
1013
initial.commit09911bf2008-07-26 23:55:291014void RenderView::OnUpdateTargetURLAck() {
1015 // Check if there is a targeturl waiting to be sent.
1016 if (target_url_status_ == TARGET_PENDING) {
1017 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1018 pending_target_url_));
1019 }
1020
1021 target_url_status_ = TARGET_NONE;
1022}
1023
1024void RenderView::OnUndo() {
1025 if (!webview())
1026 return;
1027
[email protected]26aa0482009-09-30 16:55:271028 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121029 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291030}
1031
1032void RenderView::OnRedo() {
1033 if (!webview())
1034 return;
1035
[email protected]26aa0482009-09-30 16:55:271036 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121037 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291038}
1039
1040void RenderView::OnCut() {
1041 if (!webview())
1042 return;
1043
[email protected]26aa0482009-09-30 16:55:271044 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121045 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291046}
1047
1048void RenderView::OnCopy() {
1049 if (!webview())
1050 return;
1051
[email protected]26aa0482009-09-30 16:55:271052 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121053 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291054}
1055
[email protected]c0cc3092009-09-12 08:27:271056#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351057void RenderView::OnCopyToFindPboard() {
1058 if (!webview())
1059 return;
1060
1061 // Since the find pasteboard supports only plain text, this can be simpler
1062 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271063 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351064 if (frame->hasSelection()) {
1065 string16 selection = frame->selectionAsText();
1066 RenderThread::current()->Send(
1067 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1068 }
1069
[email protected]afe3a1672009-11-17 19:04:121070 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351071}
[email protected]c0cc3092009-09-12 08:27:271072#endif
[email protected]a954bf72009-09-12 07:30:351073
initial.commit09911bf2008-07-26 23:55:291074void RenderView::OnPaste() {
1075 if (!webview())
1076 return;
1077
[email protected]26aa0482009-09-30 16:55:271078 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121079 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291080}
1081
[email protected]2a3a7762009-10-19 19:17:321082void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291083 if (!webview())
1084 return;
1085
[email protected]1ff7a032010-02-03 02:46:031086 WebFrame* frame = webview()->focusedFrame();
1087 if (!frame->hasSelection())
1088 frame->selectWordAroundCaret();
1089 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291090}
1091
[email protected]98324892009-09-09 21:16:051092void RenderView::OnAdvanceToNextMisspelling() {
1093 if (!webview())
1094 return;
[email protected]26aa0482009-09-30 16:55:271095 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051096 WebString::fromUTF8("AdvanceToNextMisspelling"));
1097}
1098
1099void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1100 if (!webview())
1101 return;
1102 // We need to tell the webView whether the spelling panel is visible or not so
1103 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261104 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271105 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051106 WebString::fromUTF8("ToggleSpellPanel"));
1107}
1108
[email protected]bbbd545c2008-12-15 20:18:041109void RenderView::OnToggleSpellCheck() {
1110 if (!webview())
1111 return;
1112
[email protected]26aa0482009-09-30 16:55:271113 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451114 frame->enableContinuousSpellChecking(
1115 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041116}
1117
initial.commit09911bf2008-07-26 23:55:291118void RenderView::OnDelete() {
1119 if (!webview())
1120 return;
1121
[email protected]26aa0482009-09-30 16:55:271122 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121123 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291124}
1125
1126void RenderView::OnSelectAll() {
1127 if (!webview())
1128 return;
1129
[email protected]26aa0482009-09-30 16:55:271130 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221131 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121132 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291133}
1134
1135void RenderView::OnSetInitialFocus(bool reverse) {
1136 if (!webview())
1137 return;
[email protected]26aa0482009-09-30 16:55:271138 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291139}
1140
1141///////////////////////////////////////////////////////////////////////////////
1142
[email protected]433819d2010-01-30 20:20:011143void RenderView::SetContentSettings(const ContentSettings& settings) {
1144 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011145}
1146
initial.commit09911bf2008-07-26 23:55:291147// Tell the embedding application that the URL of the active page has changed
1148void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451149 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291150 DCHECK(ds);
1151
[email protected]726985e22009-06-18 21:09:281152 const WebURLRequest& request = ds->request();
1153 const WebURLRequest& original_request = ds->originalRequest();
1154 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291155
[email protected]daa8c58e2009-06-15 17:21:101156 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1157 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291158
1159 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281160 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291161 params.is_post = false;
1162 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281163 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551164 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291165 // SSL state specified in the request takes precedence over the one in the
1166 // response.
1167 // So far this is only intended for error pages that are not expected to be
1168 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281169 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551170 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291171 } else {
[email protected]726985e22009-06-18 21:09:281172 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291173 }
1174
1175 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281176 if (ds->hasUnreachableURL()) {
1177 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291178 } else {
[email protected]726985e22009-06-18 21:09:281179 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291180 }
1181
[email protected]726985e22009-06-18 21:09:281182 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241183 params.should_update_history = !ds->hasUnreachableURL() &&
1184 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291185
[email protected]ce0e250d2009-10-23 21:00:351186 params.searchable_form_url = navigation_state->searchable_form_url();
1187 params.searchable_form_encoding =
1188 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291189
1190 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101191 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291192 if (password_form_data)
1193 params.password_form = *password_form_data;
1194
1195 params.gesture = navigation_gesture_;
1196 navigation_gesture_ = NavigationGestureUnknown;
1197
[email protected]dd7daa82009-08-10 05:46:451198 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291199 // Top-level navigation.
1200
[email protected]71b0d5d2010-02-15 05:43:071201 // Clear "block" flags for the new page. This needs to happen before any of
1202 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1203 // so that these functions can correctly detect that a piece of content
1204 // flipped from "not blocked" to "blocked".
1205 ClearBlockedContentSettings();
1206
[email protected]f85f0702010-01-30 09:31:011207 // Set content settings.
1208 HostContentSettings::iterator host_content_settings =
1209 host_content_settings_.find(GURL(request.url()).host());
1210 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011211 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011212
1213 // These content settings were merely recorded transiently for this load.
1214 // We can erase them now. If at some point we reload this page, the
1215 // browser will send us new, up-to-date content settings.
1216 host_content_settings_.erase(host_content_settings);
1217 }
1218
[email protected]40bd6582009-12-04 23:49:511219 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011220 HostZoomLevels::iterator host_zoom =
[email protected]40bd6582009-12-04 23:49:511221 host_zoom_levels_.find(GURL(request.url()).host());
[email protected]f85f0702010-01-30 09:31:011222 if (host_zoom != host_zoom_levels_.end()) {
1223 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511224 // This zoom level was merely recorded transiently for this load. We can
1225 // erase it now. If at some point we reload this page, the browser will
1226 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011227 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511228 }
1229
initial.commit09911bf2008-07-26 23:55:291230 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551231 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291232
[email protected]daa8c58e2009-06-15 17:21:101233 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291234 if (!PageTransition::IsMainFrame(params.transition)) {
1235 // If the main frame does a load, it should not be reported as a subframe
1236 // navigation. This can occur in the following case:
1237 // 1. You're on a site with frames.
1238 // 2. You do a subframe navigation. This is stored with transition type
1239 // MANUAL_SUBFRAME.
1240 // 3. You navigate to some non-frame site, say, google.com.
1241 // 4. You navigate back to the page from step 2. Since it was initially
1242 // MANUAL_SUBFRAME, it will be that same transition type here.
1243 // We don't want that, because any navigation that changes the toplevel
1244 // frame should be tracked as a toplevel navigation (this allows us to
1245 // update the URL bar, etc).
1246 params.transition = PageTransition::LINK;
1247 }
1248
initial.commit09911bf2008-07-26 23:55:291249 // If we have a valid consumed client redirect source,
1250 // the page contained a client redirect (meta refresh, document.loc...),
1251 // so we set the referrer and transition to match.
1252 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041253 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291254 params.referrer = completed_client_redirect_src_;
1255 params.transition = static_cast<PageTransition::Type>(
1256 params.transition | PageTransition::CLIENT_REDIRECT);
1257 } else {
1258 // Bug 654101: the referrer will be empty on https->http transitions. It
1259 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281260 params.referrer = GURL(
1261 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291262 }
1263
[email protected]726985e22009-06-18 21:09:281264 string16 method = request.httpMethod();
1265 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291266 params.is_post = true;
1267
[email protected]c2a797d2009-09-21 16:46:321268 // Save some histogram data so we can compute the average memory used per
1269 // page load of the glyphs.
1270 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1271 webkit_glue::GetGlyphPageCount());
1272
[email protected]15cf526b2010-02-12 06:33:491273 // This message needs to be sent before any of allowScripts(),
1274 // allowImages(), allowPlugins() is called for the new page, so that when
1275 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1276 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291277 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1278 } else {
1279 // Subframe navigation: the type depends on whether this navigation
1280 // generated a new session history entry. When they do generate a session
1281 // history entry, it means the user initiated the navigation and we should
1282 // mark it as such. This test checks if this is the first time UpdateURL
1283 // has been called since WillNavigateToURL was called to initiate the load.
1284 if (page_id_ > last_page_id_sent_to_browser_)
1285 params.transition = PageTransition::MANUAL_SUBFRAME;
1286 else
1287 params.transition = PageTransition::AUTO_SUBFRAME;
1288
initial.commit09911bf2008-07-26 23:55:291289 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1290 }
1291
1292 last_page_id_sent_to_browser_ =
1293 std::max(last_page_id_sent_to_browser_, page_id_);
1294
1295 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101296 // we don't want the transition type to persist. Just clear it.
1297 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501298
[email protected]6c8afae52009-01-22 02:24:571299#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151300 if (accessibility_.get()) {
[email protected]17455962010-02-24 01:39:351301 // Remove accessibility info cache.
1302 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501303 }
[email protected]6c8afae52009-01-22 02:24:571304#else
[email protected]7d926f92009-03-03 14:26:541305 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571306#endif
initial.commit09911bf2008-07-26 23:55:291307}
1308
1309// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171310void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291311 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171312 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171313 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171314 routing_id_,
1315 page_id_,
1316 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1317 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171318 }
initial.commit09911bf2008-07-26 23:55:291319}
1320
1321void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401322 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291323 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271324 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291325 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301326 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291327 last_encoding_name_ = encoding_name;
1328
[email protected]e38f40152008-09-12 23:08:301329 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291330 }
1331}
1332
[email protected]f4d34b52008-11-24 23:05:011333// Sends the previous session history state to the browser so it will be saved
1334// before we navigate to a new page. This must be called *before* the page ID
1335// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291336void RenderView::UpdateSessionHistory(WebFrame* frame) {
1337 // If we have a valid page ID at this point, then it corresponds to the page
1338 // we are navigating away from. Otherwise, this is the first navigation, so
1339 // there is no past session history to record.
1340 if (page_id_ == -1)
1341 return;
1342
[email protected]ca948a22009-06-25 19:36:171343 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271344 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171345 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291346 return;
[email protected]ca948a22009-06-25 19:36:171347
1348 Send(new ViewHostMsg_UpdateState(
1349 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291350}
1351
[email protected]3d9689372009-09-10 04:29:171352void RenderView::OpenURL(
1353 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1354 Send(new ViewHostMsg_OpenURL(
1355 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1356}
1357
[email protected]79dbc662009-09-04 05:42:511358// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291359
initial.commit09911bf2008-07-26 23:55:291360void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281361 const WebURLRequest& failed_request,
1362 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291363 const std::string& html,
1364 bool replace) {
[email protected]726985e22009-06-18 21:09:281365 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291366
1367 std::string alt_html;
1368 if (html.empty()) {
1369 // Use a local error page.
1370 int resource_id;
1371 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281372 if (error.reason == net::ERR_CACHE_MISS &&
1373 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291374 GetFormRepostErrorValues(failed_url, &error_strings);
1375 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1376 } else {
1377 GetLocalizedErrorValues(error, &error_strings);
1378 resource_id = IDR_NET_ERROR_HTML;
1379 }
initial.commit09911bf2008-07-26 23:55:291380
1381 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1382 } else {
1383 alt_html = html;
1384 }
1385
[email protected]dd7daa82009-08-10 05:46:451386 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551387 GURL(kUnreachableWebDataURL),
1388 failed_url,
1389 replace);
initial.commit09911bf2008-07-26 23:55:291390}
1391
[email protected]7ccddb8c2009-08-04 17:36:551392void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291393 dom_automation_controller_.set_message_sender(this);
1394 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551395 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291396 L"domAutomationController");
1397}
1398
initial.commit09911bf2008-07-26 23:55:291399bool RenderView::RunJavaScriptMessage(int type,
1400 const std::wstring& message,
1401 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071402 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291403 std::wstring* result) {
1404 bool success = false;
1405 std::wstring result_temp;
1406 if (!result)
1407 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291408
[email protected]12636df2009-09-28 22:32:211409 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1410 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291411 return success;
1412}
1413
[email protected]c1f50aa2010-02-18 03:46:571414bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1415 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1416 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1417 // it is particularly important that we do not call willEnterModalLoop as
1418 // that would defer resource loads for the dialog itself.
1419 if (RenderThread::current()) // Will be NULL during unit tests.
1420 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1421
1422 message->EnableMessagePumping(); // Runs a nested message loop.
1423 return Send(message);
1424}
1425
initial.commit09911bf2008-07-26 23:55:291426void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1427 if (!osd_url.is_empty())
1428 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1429 autodetected));
1430}
1431
[email protected]95056b582010-02-18 01:29:241432void RenderView::OnAutoFillSuggestionsReturned(
1433 int query_id,
1434 const std::vector<string16>& names,
1435 const std::vector<string16>& labels,
1436 int default_suggestion_index) {
1437 if (webview() && query_id == autofill_query_id_) {
1438 webview()->applyAutoFillSuggestions(
1439 autofill_query_node_, names, labels, default_suggestion_index);
1440 }
1441 autofill_query_node_.reset();
1442}
1443
1444void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a12009-10-16 03:53:391445 int query_id,
1446 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031447 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181448 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081449 webview()->applyAutocompleteSuggestions(
[email protected]acca2a12009-10-16 03:53:391450 autofill_query_node_, suggestions, default_suggestion_index);
1451 }
1452 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031453}
1454
[email protected]45c6e532010-03-15 23:51:241455void RenderView::OnAutoFillFormDataFilled(int query_id,
1456 const webkit_glue::FormData& form) {
[email protected]c83641732010-02-20 01:04:481457 if (query_id != autofill_query_id_)
1458 return;
1459
1460 form_manager_.FillForm(form);
1461}
1462
[email protected]2c4410d2009-05-06 23:46:221463void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311464 popup_notification_visible_ = visible;
1465}
1466
initial.commit09911bf2008-07-26 23:55:291467uint32 RenderView::GetCPBrowsingContext() {
1468 uint32 context = 0;
1469 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1470 return context;
1471}
1472
initial.commit09911bf2008-07-26 23:55:291473void RenderView::AddSearchProvider(const std::string& url) {
1474 AddGURLSearchProvider(GURL(url),
1475 false); // not autodetected
1476}
1477
[email protected]f103ab72009-09-02 17:10:591478void RenderView::OnMissingPluginStatus(
1479 WebPluginDelegateProxy* delegate,
1480 int status) {
[email protected]6c8afae52009-01-22 02:24:571481#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591482 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291483 // Show the InfoBar for the first available plugin.
1484 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591485 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291486 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1487 }
1488 } else {
1489 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1490 // to start the download/install.
1491 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1492 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1493 }
1494 }
[email protected]6c8afae52009-01-22 02:24:571495#else
1496 // TODO(port): plugins current not supported
1497 NOTIMPLEMENTED();
1498#endif
initial.commit09911bf2008-07-26 23:55:291499}
1500
[email protected]48c9cf2d2009-09-16 16:47:521501// WebKit::WebViewClient ------------------------------------------------------
1502
1503WebView* RenderView::createView(WebFrame* creator) {
1504 // Check to make sure we aren't overloading on popups.
1505 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1506 return NULL;
1507
1508 // This window can't be closed from a window.close() call until we receive a
1509 // message from the Browser process explicitly allowing it.
1510 popup_notification_visible_ = true;
1511
1512 int32 routing_id = MSG_ROUTING_NONE;
1513 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461514 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341515 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521516
[email protected]48c9cf2d2009-09-16 16:47:521517 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341518 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1519 session_storage_namespace_id_,
1520 &routing_id,
1521 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211522 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521523 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521524
[email protected]48c9cf2d2009-09-16 16:47:521525 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421526 0,
[email protected]12636df2009-09-28 22:32:211527 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521528 renderer_preferences_,
1529 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211530 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341531 routing_id,
1532 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521533 view->opened_by_user_gesture_ = user_gesture;
1534
[email protected]007a848b2009-10-26 15:55:461535 // Record whether the creator frame is trying to suppress the opener field.
1536 view->opener_suppressed_ = opener_suppressed;
1537
[email protected]48c9cf2d2009-09-16 16:47:521538 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091539 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521540 if (!creator_url.is_valid() || !creator_url.IsStandard())
1541 creator_url = GURL();
1542 view->creator_url_ = creator_url;
1543
1544 // Copy over the alternate error page URL so we can have alt error pages in
1545 // the new render view (we don't need the browser to send the URL back down).
1546 view->alternate_error_page_url_ = alternate_error_page_url_;
1547
1548 return view->webview();
1549}
1550
1551WebWidget* RenderView::createPopupMenu(bool activatable) {
1552 RenderWidget* widget = RenderWidget::Create(routing_id_,
1553 render_thread_,
1554 activatable);
1555 return widget->webwidget();
1556}
1557
1558WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1559 RenderWidget* widget = RenderWidget::Create(routing_id_,
1560 render_thread_,
1561 true);
1562 widget->ConfigureAsExternalPopupMenu(info);
1563 return widget->webwidget();
1564}
1565
[email protected]bd92c3a2010-01-13 05:02:341566WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1567 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1568 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291569 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1570 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1571 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341572}
1573
[email protected]48c9cf2d2009-09-16 16:47:521574void RenderView::didAddMessageToConsole(
1575 const WebConsoleMessage& message, const WebString& source_name,
1576 unsigned source_line) {
1577 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1578 UTF16ToWideHack(message.text),
1579 static_cast<int32>(source_line),
1580 UTF16ToWideHack(source_name)));
1581}
1582
1583void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581584 DCHECK(frame);
1585 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521586}
1587
1588void RenderView::didStartLoading() {
1589 if (is_loading_) {
1590 DLOG(WARNING) << "didStartLoading called while loading";
1591 return;
1592 }
1593
1594 is_loading_ = true;
1595 // Clear the pointer so that we can assign it only when there is an unknown
1596 // plugin on a page.
1597 first_default_plugin_.reset();
1598
1599 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1600}
1601
1602void RenderView::didStopLoading() {
1603 if (!is_loading_) {
1604 DLOG(WARNING) << "DidStopLoading called while not loading";
1605 return;
1606 }
1607
1608 is_loading_ = false;
1609
1610 // NOTE: For now we're doing the safest thing, and sending out notification
1611 // when done loading. This currently isn't an issue as the favicon is only
1612 // displayed when done loading. Ideally we would send notification when
1613 // finished parsing the head, but webkit doesn't support that yet.
1614 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271615 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521616 if (!favicon_url.is_empty())
1617 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1618
[email protected]26aa0482009-09-30 16:55:271619 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521620 true); // autodetected
1621
1622 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1623
[email protected]f9f4841b2010-03-20 05:41:421624 MessageLoop::current()->PostDelayedTask(
1625 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521626 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1627 false),
1628 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521629}
1630
[email protected]f55039a2010-02-17 14:12:061631bool RenderView::isSmartInsertDeleteEnabled() {
1632#if defined(OS_MACOSX)
1633 return true;
1634#else
1635 return false;
1636#endif
1637}
1638
[email protected]04fc9482009-09-18 22:13:031639bool RenderView::isSelectTrailingWhitespaceEnabled() {
1640#if defined(OS_WIN)
1641 return true;
1642#else
1643 return false;
1644#endif
1645}
1646
1647void RenderView::setInputMethodEnabled(bool enabled) {
1648 // Save the updated IME status and mark the input focus has been updated.
1649 // The IME status is to be sent to a browser process next time when
1650 // the input caret is rendered.
1651 if (!ime_control_busy_) {
1652 ime_control_updated_ = true;
1653 ime_control_new_state_ = enabled;
1654 }
1655}
1656
1657void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031658#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031659 if (!handling_input_event_)
1660 return;
1661 // TODO(estade): investigate incremental updates to the selection so that we
1662 // don't send the entire selection over IPC every time.
1663 if (!is_empty_selection) {
1664 // Sometimes we get repeated didChangeSelection calls from webkit when
1665 // the selection hasn't actually changed. We don't want to report these
1666 // because it will cause us to continually claim the X clipboard.
1667 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271668 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031669 if (this_selection == last_selection_)
1670 return;
1671
1672 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1673 this_selection));
1674 last_selection_ = this_selection;
1675 } else {
1676 last_selection_.clear();
1677 }
1678#endif
1679}
1680
1681void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121682 const std::string& name = UTF16ToUTF8(command_name);
1683 if (StartsWithASCII(name, "Move", true) ||
1684 StartsWithASCII(name, "Insert", true) ||
1685 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031686 return;
1687 UserMetricsRecordAction(name);
1688}
1689
[email protected]b2528b72009-09-24 06:57:101690bool RenderView::handleCurrentKeyboardEvent() {
1691 if (edit_commands_.empty())
1692 return false;
1693
[email protected]26aa0482009-09-30 16:55:271694 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101695 if (!frame)
1696 return false;
1697
1698 EditCommands::iterator it = edit_commands_.begin();
1699 EditCommands::iterator end = edit_commands_.end();
1700
[email protected]507b33ea2009-09-29 03:56:511701 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101702 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331703 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1704 // key (but it's the exception). Once one edit command is not executed, it
1705 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101706 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1707 WebString::fromUTF8(it->value)))
1708 break;
[email protected]507b33ea2009-09-29 03:56:511709 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101710 }
1711
[email protected]507b33ea2009-09-29 03:56:511712 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101713}
1714
[email protected]2a3a7762009-10-19 19:17:321715void RenderView::spellCheck(const WebString& text,
1716 int& misspelled_offset,
1717 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561718 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461719
[email protected]85c55dc2009-11-06 03:05:461720 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171721 RenderThread* thread = RenderThread::current();
1722 // Will be NULL during unit tests.
1723 if (thread) {
[email protected]c27324b2009-11-19 22:44:291724 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171725 word.c_str(), word.size(), document_tag_,
1726 &misspelled_offset, &misspelled_length, NULL);
1727 }
[email protected]1dbafaf72009-09-23 19:43:561728}
1729
1730WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321731 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561732 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261733 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561734 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171735 RenderThread* thread = RenderThread::current();
1736 // Will be NULL during unit tests.
1737 if (thread) {
1738 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291739 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171740 word, document_tag_);
1741 }
[email protected]1dbafaf72009-09-23 19:43:561742 }
[email protected]2a3a7762009-10-19 19:17:321743 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561744}
1745
[email protected]c49085c72009-10-02 16:28:561746void RenderView::showSpellingUI(bool show) {
1747 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1748}
1749
[email protected]8922e1f2009-10-03 05:01:261750bool RenderView::isShowingSpellingUI() {
1751 return spelling_panel_visible_;
1752}
1753
[email protected]1dbafaf72009-09-23 19:43:561754void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321755 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1756 word));
[email protected]1dbafaf72009-09-23 19:43:561757}
1758
[email protected]a1128322009-10-06 18:38:461759bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351760 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471761 WebFileChooserCompletion* chooser_completion) {
1762 ViewHostMsg_RunFileChooser_Params ipc_params;
1763 ipc_params.mode = params.multiSelect ?
1764 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1765 ViewHostMsg_RunFileChooser_Params::Open;
1766 ipc_params.title = params.title;
1767 ipc_params.default_file_name =
1768 webkit_glue::WebStringToFilePath(params.initialValue);
1769
1770 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461771}
1772
[email protected]48c9cf2d2009-09-16 16:47:521773void RenderView::runModalAlertDialog(
1774 WebFrame* frame, const WebString& message) {
1775 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1776 UTF16ToWideHack(message),
1777 std::wstring(),
1778 frame->url(),
1779 NULL);
1780}
1781
1782bool RenderView::runModalConfirmDialog(
1783 WebFrame* frame, const WebString& message) {
1784 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1785 UTF16ToWideHack(message),
1786 std::wstring(),
1787 frame->url(),
1788 NULL);
1789}
1790
1791bool RenderView::runModalPromptDialog(
1792 WebFrame* frame, const WebString& message, const WebString& default_value,
1793 WebString* actual_value) {
1794 std::wstring result;
1795 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1796 UTF16ToWideHack(message),
1797 UTF16ToWideHack(default_value),
1798 frame->url(),
1799 &result);
1800 if (ok)
1801 actual_value->assign(WideToUTF16Hack(result));
1802 return ok;
1803}
1804
1805bool RenderView::runModalBeforeUnloadDialog(
1806 WebFrame* frame, const WebString& message) {
1807 bool success = false;
1808 // This is an ignored return value, but is included so we can accept the same
1809 // response as RunJavaScriptMessage.
1810 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211811 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521812 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211813 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521814 return success;
1815}
1816
[email protected]79e37442009-10-09 18:17:441817void RenderView::showContextMenu(
1818 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291819 ContextMenuParams params = ContextMenuParams(data);
1820 if (!params.misspelled_word.empty() && RenderThread::current()) {
1821 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041822 bool spelled_right = RenderThread::current()->spellchecker()->
1823 SpellCheckWord(
1824 params.misspelled_word.c_str(), params.misspelled_word.size(),
1825 document_tag_,
1826 &misspelled_offset, &misspelled_length,
1827 &params.dictionary_suggestions);
1828 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291829 params.misspelled_word.clear();
1830 }
1831
1832 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441833}
1834
[email protected]48c9cf2d2009-09-16 16:47:521835void RenderView::setStatusText(const WebString& text) {
1836}
1837
[email protected]163f8242009-10-30 20:19:551838void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1839 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521840 if (latest_url == target_url_)
1841 return;
[email protected]163f8242009-10-30 20:19:551842
[email protected]48c9cf2d2009-09-16 16:47:521843 // Tell the browser to display a destination link.
1844 if (target_url_status_ == TARGET_INFLIGHT ||
1845 target_url_status_ == TARGET_PENDING) {
1846 // If we have a request in-flight, save the URL to be sent when we
1847 // receive an ACK to the in-flight request. We can happily overwrite
1848 // any existing pending sends.
1849 pending_target_url_ = latest_url;
1850 target_url_status_ = TARGET_PENDING;
1851 } else {
1852 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1853 target_url_ = latest_url;
1854 target_url_status_ = TARGET_INFLIGHT;
1855 }
1856}
1857
[email protected]882daa92009-11-05 16:31:311858void RenderView::StartNavStateSyncTimerIfNecessary() {
1859 int delay;
1860 if (send_content_state_immediately_)
1861 delay = 0;
1862 else if (is_hidden())
1863 delay = kDelaySecondsForContentStateSyncHidden;
1864 else
1865 delay = kDelaySecondsForContentStateSync;
1866
1867 if (nav_state_sync_timer_.IsRunning()) {
1868 // The timer is already running. If the delay of the timer maches the amount
1869 // we want to delay by, then return. Otherwise stop the timer so that it
1870 // gets started with the right delay.
1871 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1872 return;
1873 nav_state_sync_timer_.Stop();
1874 }
1875
1876 nav_state_sync_timer_.Start(
1877 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1878}
1879
[email protected]163f8242009-10-30 20:19:551880void RenderView::setMouseOverURL(const WebURL& url) {
1881 mouse_over_url_ = GURL(url);
1882 UpdateTargetURL(mouse_over_url_, focus_url_);
1883}
1884
1885void RenderView::setKeyboardFocusURL(const WebURL& url) {
1886 focus_url_ = GURL(url);
1887 UpdateTargetURL(focus_url_, mouse_over_url_);
1888}
1889
[email protected]48c9cf2d2009-09-16 16:47:521890void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1891 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1892 hint));
1893}
1894
[email protected]49fd9da2010-03-17 21:00:471895void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1896 WebDragOperationsMask allowed_ops) {
[email protected]c27ae592010-03-18 15:24:411897 startDragging(data, allowed_ops, WebImage(), WebPoint());
1898}
1899
1900void RenderView::startDragging(const WebDragData& data,
1901 WebDragOperationsMask mask,
1902 const WebImage& image,
1903 const WebPoint& imageOffset) {
1904#if WEBKIT_USING_SKIA
1905 SkBitmap bitmap(image.getSkBitmap());
1906#elif WEBKIT_USING_CG
1907 // Needs implementing: http://crbug.com/11457
1908 SkBitmap bitmap;
1909#endif
1910
[email protected]48c9cf2d2009-09-16 16:47:521911 Send(new ViewHostMsg_StartDragging(routing_id_,
1912 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411913 mask,
1914 bitmap,
1915 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521916}
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) {
[email protected]48c9cf2d2009-09-16 16:47:521931 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1932}
1933
1934int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001935 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521936}
1937
1938int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001939 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521940}
1941
[email protected]8922e1f2009-10-03 05:01:261942void RenderView::didUpdateInspectorSettings() {
1943 Send(new ViewHostMsg_UpdateInspectorSettings(
1944 routing_id_, webview()->inspectorSettings().utf8()));
1945}
1946
[email protected]acca2a12009-10-16 03:53:391947void RenderView::queryAutofillSuggestions(const WebNode& node,
1948 const WebString& name,
1949 const WebString& value) {
1950 static int query_counter = 0;
1951 autofill_query_id_ = query_counter++;
1952 autofill_query_node_ = node;
[email protected]95056b582010-02-18 01:29:241953 const WebKit::WebInputElement input_element =
1954 node.toConstElement<WebInputElement>();
[email protected]acca2a12009-10-16 03:53:391955 Send(new ViewHostMsg_QueryFormFieldAutofill(
[email protected]95056b582010-02-18 01:29:241956 routing_id_, autofill_query_id_, FormField(input_element)));
[email protected]acca2a12009-10-16 03:53:391957}
1958
1959void RenderView::removeAutofillSuggestions(const WebString& name,
1960 const WebString& value) {
1961 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1962}
1963
[email protected]c83641732010-02-20 01:04:481964void RenderView::didAcceptAutoFillSuggestion(
1965 const WebKit::WebNode& node,
1966 const WebKit::WebString& name,
1967 const WebKit::WebString& label) {
1968 static int query_counter = 0;
1969 autofill_query_id_ = query_counter++;
1970
[email protected]45c6e532010-03-15 23:51:241971 webkit_glue::FormData form;
[email protected]c83641732010-02-20 01:04:481972 const WebInputElement element = node.toConstElement<WebInputElement>();
1973 if (!form_manager_.FindForm(element, &form))
1974 return;
1975
1976 Send(new ViewHostMsg_FillAutoFillFormData(
1977 routing_id_, autofill_query_id_, form, name, label));
1978}
1979
[email protected]79dbc662009-09-04 05:42:511980// WebKit::WebWidgetClient ----------------------------------------------------
1981
initial.commit09911bf2008-07-26 23:55:291982// We are supposed to get a single call to Show for a newly created RenderView
1983// that was created via RenderView::CreateWebView. So, we wait until this
1984// point to dispatch the ShowView message.
1985//
1986// This method provides us with the information about how to display the newly
1987// created RenderView (i.e., as a constrained popup or as a new tab).
1988//
[email protected]4873c7d2009-07-16 06:36:281989void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291990 DCHECK(!did_show_) << "received extraneous Show call";
1991 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1992
1993 if (did_show_)
1994 return;
1995 did_show_ = true;
1996
[email protected]28295ec2009-10-16 05:34:331997 // Force new windows to a popup if they were not opened with a user gesture.
1998 if (!opened_by_user_gesture_) {
1999 // We exempt background tabs for compat with older versions of Chrome.
2000 // TODO(darin): This seems bogus. These should have a user gesture, so
2001 // we probably don't need this check.
2002 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2003 policy = WebKit::WebNavigationPolicyNewPopup;
2004 }
2005
initial.commit09911bf2008-07-26 23:55:292006 // NOTE: initial_pos_ may still have its default values at this point, but
2007 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2008 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282009 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2010 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292011 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242012 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292013}
2014
[email protected]4873c7d2009-07-16 06:36:282015void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222016 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282017 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312018}
2019
[email protected]4873c7d2009-07-16 06:36:282020void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292021 DCHECK(did_show_) << "should already have shown the view";
2022
[email protected]c1f50aa2010-02-18 03:46:572023 // We must keep WebKit's shared timer running in this case in order to allow
2024 // showModalDialog to function properly.
2025 //
2026 // TODO(darin): WebKit should really be smarter about suppressing events and
2027 // timers so that we do not need to manage the shared timer in such a heavy
2028 // handed manner.
2029 //
2030 if (RenderThread::current()) // Will be NULL during unit tests.
2031 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2032
[email protected]12636df2009-09-28 22:32:212033 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292034}
2035
[email protected]3d9689372009-09-10 04:29:172036// WebKit::WebFrameClient -----------------------------------------------------
2037
2038WebPlugin* RenderView::createPlugin(
2039 WebFrame* frame, const WebPluginParams& params) {
2040 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2041}
2042
2043WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2044 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
2045}
2046
[email protected]9c00f002009-11-05 22:37:422047WebSharedWorker* RenderView::createSharedWorker(
2048 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372049 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422050
[email protected]30447b62009-11-13 01:13:372051 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512052 bool exists = false;
[email protected]30447b62009-11-13 01:13:372053 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512054 ViewHostMsg_CreateWorker_Params params;
2055 params.url = url;
2056 params.is_shared = true;
2057 params.name = name;
2058 params.document_id = document_id;
2059 params.render_view_route_id = routing_id_;
2060 params.route_id = MSG_ROUTING_NONE;
[email protected]30447b62009-11-13 01:13:372061 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512062 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372063 if (url_mismatch) {
2064 return NULL;
2065 } else {
2066 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492067 document_id,
[email protected]6de0bcf2010-02-17 22:00:512068 exists,
[email protected]30447b62009-11-13 01:13:372069 route_id,
2070 routing_id_);
2071 }
[email protected]9c00f002009-11-05 22:37:422072}
2073
[email protected]3d9689372009-09-10 04:29:172074WebMediaPlayer* RenderView::createMediaPlayer(
2075 WebFrame* frame, WebMediaPlayerClient* client) {
2076 scoped_refptr<media::FilterFactoryCollection> factory =
2077 new media::FilterFactoryCollection();
2078 // Add in any custom filter factories first.
2079 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2080 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2081 // Add the chrome specific audio renderer.
2082 factory->AddFactory(
2083 AudioRendererImpl::CreateFactory(audio_message_filter()));
2084 }
2085
[email protected]80f584d92010-01-21 03:59:042086 WebApplicationCacheHostImpl* appcache_host =
2087 WebApplicationCacheHostImpl::FromFrame(frame);
2088
[email protected]3d9689372009-09-10 04:29:172089 // TODO(hclam): obtain the following parameters from |client|.
2090 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2091 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152092 GURL(), // referrer
2093 "null", // frame origin
2094 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172095 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042096 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172097 routing_id());
2098
[email protected]0436b9a2009-10-23 00:23:052099 // A simple data source that keeps all data in memory.
2100 media::FilterFactory* simple_data_source_factory =
2101 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2102 bridge_factory);
2103 // A sophisticated data source that does memory caching.
2104 media::FilterFactory* buffered_data_source_factory =
2105 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2106 bridge_factory);
2107 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2108 factory->AddFactory(simple_data_source_factory);
2109 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172110 } else {
[email protected]0436b9a2009-10-23 00:23:052111 factory->AddFactory(buffered_data_source_factory);
2112 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172113 }
[email protected]8400e032010-02-26 18:50:112114
2115 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2116 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2117 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2118 } else {
[email protected]b57509eb2010-03-30 01:26:282119 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2120 factory_factory =
2121 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112122 }
2123
2124 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172125}
2126
[email protected]b921cfd22010-02-25 16:57:512127WebCookieJar* RenderView::cookieJar() {
2128 return &cookie_jar_;
2129}
2130
[email protected]3d9689372009-09-10 04:29:172131void RenderView::willClose(WebFrame* frame) {
2132 if (!frame->parent()) {
2133 const GURL& url = frame->url();
2134 if (url.SchemeIs("http") || url.SchemeIs("https"))
2135 DumpLoadHistograms();
2136 }
[email protected]fa7b6b542009-11-03 05:02:302137
2138 WebDataSource* ds = frame->dataSource();
2139 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2140 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172141}
2142
[email protected]684e4a42010-01-30 06:44:112143bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002144 if (!enabled_per_settings)
2145 return false;
[email protected]c21f1d52010-03-04 03:19:432146 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112147}
2148
2149bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002150 if (!enabled_per_settings)
2151 return false;
2152 if (!AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) {
2153 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2154 return false;
2155 }
2156 return true;
[email protected]684e4a42010-01-30 06:44:112157}
2158
[email protected]3d9689372009-09-10 04:29:172159void RenderView::loadURLExternally(
2160 WebFrame* frame, const WebURLRequest& request,
2161 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592162 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2163 if (policy == WebKit::WebNavigationPolicyDownload) {
2164 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2165 } else {
2166 OpenURL(request.url(), referrer, policy);
2167 }
[email protected]3d9689372009-09-10 04:29:172168}
2169
2170WebNavigationPolicy RenderView::decidePolicyForNavigation(
2171 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222172 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172173 // Webkit is asking whether to navigate to a new URL.
2174 // This is fine normally, except if we're showing UI from one security
2175 // context and they're trying to navigate to a different context.
2176 const GURL& url = request.url();
2177
2178 // If the browser is interested, then give it a chance to look at top level
2179 // navigations
2180 if (renderer_preferences_.browser_handles_top_level_requests &&
2181 // Only send once.
2182 last_top_level_navigation_page_id_ != page_id_ &&
2183 // Not interested in reloads.
2184 type != WebKit::WebNavigationTypeReload &&
2185 type != WebKit::WebNavigationTypeFormSubmitted &&
2186 // Must be a top level frame.
2187 frame->parent() == NULL) {
2188 // Skip if navigation is on the same page (using '#').
2189 GURL frame_origin = GURL(frame->url()).GetOrigin();
2190 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
2191 last_top_level_navigation_page_id_ = page_id_;
[email protected]b36a9f92009-10-19 17:34:572192 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2193 OpenURL(url, referrer, default_policy);
[email protected]3d9689372009-09-10 04:29:172194 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2195 }
2196 }
2197
2198 // A content initiated navigation may have originated from a link-click,
2199 // script, drag-n-drop operation, etc.
2200 bool is_content_initiated =
2201 NavigationState::FromDataSource(frame->provisionalDataSource())->
2202 is_content_initiated();
2203
2204 // We only care about navigations that are within the current tab (as opposed
2205 // to, for example, opening a new window).
2206 // But we sometimes navigate to about:blank to clear a tab, and we want to
2207 // still allow that.
2208 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2209 is_content_initiated && frame->parent() == NULL &&
2210 !url.SchemeIs(chrome::kAboutScheme)) {
2211 // When we received such unsolicited navigations, we sometimes want to
2212 // punt them up to the browser to handle.
2213 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2214 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2215 frame->isViewSourceModeEnabled() ||
2216 url.SchemeIs(chrome::kViewSourceScheme) ||
2217 url.SchemeIs(chrome::kPrintScheme)) {
2218 OpenURL(url, GURL(), default_policy);
2219 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2220 }
2221 }
2222
2223 // Detect when a page is "forking" a new tab that can be safely rendered in
2224 // its own process. This is done by sites like Gmail that try to open links
2225 // in new windows without script connections back to the original page. We
2226 // treat such cases as browser navigations (in which we will create a new
2227 // renderer for a cross-site navigation), rather than WebKit navigations.
2228 //
2229 // We use the following heuristic to decide whether to fork a new page in its
2230 // own process:
2231 // The parent page must open a new tab to about:blank, set the new tab's
2232 // window.opener to null, and then redirect the tab to a cross-site URL using
2233 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462234 //
2235 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2236 // (see below).
[email protected]3d9689372009-09-10 04:29:172237 bool is_fork =
2238 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252239 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172240 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522241 historyBackListCount() < 1 &&
2242 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172243 // The parent page must have set the child's window.opener to null before
2244 // redirecting to the desired URL.
2245 frame->opener() == NULL &&
2246 // Must be a top-level frame.
2247 frame->parent() == NULL &&
2248 // Must not have issued the request from this page.
2249 is_content_initiated &&
2250 // Must be targeted at the current tab.
2251 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2252 // Must be a JavaScript navigation, which appears as "other".
2253 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462254
2255 // Recognize if this navigation is from a link with rel=noreferrer and
2256 // target=_blank attributes, in which case the opener will be suppressed. If
2257 // so, it is safe to load cross-site pages in a separate process, so we
2258 // should let the browser handle it.
2259 bool is_noreferrer_and_blank_target =
2260 // Frame should be top level and not yet navigated.
2261 frame->parent() == NULL &&
2262 frame->url().isEmpty() &&
2263 historyBackListCount() < 1 &&
2264 historyForwardListCount() < 1 &&
2265 // Links with rel=noreferrer will have no Referer field, and their
2266 // resulting frame will have its window.opener suppressed.
2267 // TODO(creis): should add a request.httpReferrer() method to help avoid
2268 // typos on the unusual spelling of Referer.
2269 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2270 opener_suppressed_ &&
2271 frame->opener() == NULL &&
2272 // Links with target=_blank will have no name.
2273 frame->name().isNull() &&
2274 // Another frame (with a non-empty creator) should have initiated the
2275 // request, targeted at this frame.
2276 !creator_url_.is_empty() &&
2277 is_content_initiated &&
2278 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2279 type == WebKit::WebNavigationTypeOther;
2280
2281 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172282 // Open the URL via the browser, not via WebKit.
2283 OpenURL(url, GURL(), default_policy);
2284 return WebKit::WebNavigationPolicyIgnore;
2285 }
2286
2287 return default_policy;
2288}
2289
[email protected]6069da8c2009-10-20 20:33:492290bool RenderView::canHandleRequest(
2291 WebFrame* frame, const WebURLRequest& request) {
2292 // We allow WebKit to think that everything can be handled even though
2293 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342294 return true;
2295}
2296
[email protected]6069da8c2009-10-20 20:33:492297WebURLError RenderView::cannotHandleRequestError(
2298 WebFrame* frame, const WebURLRequest& request) {
2299 NOTREACHED(); // Since we said we can handle all requests.
2300 return WebURLError();
2301}
2302
2303WebURLError RenderView::cancelledError(
2304 WebFrame* frame, const WebURLRequest& request) {
2305 WebURLError error;
2306 error.domain = WebString::fromUTF8(net::kErrorDomain);
2307 error.reason = net::ERR_ABORTED;
2308 error.unreachableURL = request.url();
2309 return error;
[email protected]7b7a7dc2009-10-19 02:23:342310}
2311
2312void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492313 WebFrame*, const WebURLError&) {
2314 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342315}
2316
[email protected]979c28b2009-11-07 01:30:482317void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172318 NavigationState* navigation_state =
2319 NavigationState::FromDataSource(frame->provisionalDataSource());
2320
2321 if (navigation_state->transition_type() == PageTransition::LINK)
2322 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2323
2324 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352325 WebSearchableFormData web_searchable_form_data(form);
2326 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2327 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212328 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172329 navigation_state->set_password_form_data(
2330 PasswordFormDomManager::CreatePasswordForm(form));
2331
[email protected]979c28b2009-11-07 01:30:482332 if (form.autoComplete()) {
[email protected]c54d269e2009-10-21 18:07:382333 scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form));
2334 if (form_values.get())
[email protected]51bd36612009-10-20 22:49:472335 Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_,
[email protected]c54d269e2009-10-21 18:07:382336 *form_values));
[email protected]3d9689372009-09-10 04:29:172337 }
2338}
2339
2340void RenderView::willPerformClientRedirect(
2341 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2342 double fire_time) {
2343 // Ignore
2344}
2345
2346void RenderView::didCancelClientRedirect(WebFrame* frame) {
2347 // Ignore
2348}
2349
2350void RenderView::didCompleteClientRedirect(
2351 WebFrame* frame, const WebURL& from) {
2352 if (!frame->parent())
2353 completed_client_redirect_src_ = from;
2354}
2355
2356void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2357 // The rest of RenderView assumes that a WebDataSource will always have a
2358 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482359 bool content_initiated = !pending_navigation_state_.get();
2360 NavigationState* state = content_initiated ?
2361 NavigationState::CreateContentInitiated() :
2362 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182363 if (content_initiated) {
2364 switch (ds->request().cachePolicy()) {
2365 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2366 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2367 break;
2368 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2369 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2370 break;
2371 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2372 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2373 break;
2374 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2375 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2376 break;
2377 }
2378 }
[email protected]fa7b6b542009-11-03 05:02:302379
2380 state->set_user_script_idle_scheduler(
2381 new UserScriptIdleScheduler(this, frame));
2382 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172383}
2384
2385void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2386 WebDataSource* ds = frame->provisionalDataSource();
2387 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2388
2389 navigation_state->set_start_load_time(Time::Now());
2390
2391 // Update the request time if WebKit has better knowledge of it.
2392 if (navigation_state->request_time().is_null()) {
2393 double event_time = ds->triggeringEventTime();
2394 if (event_time != 0.0)
2395 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2396 }
2397
2398 bool is_top_most = !frame->parent();
2399 if (is_top_most) {
2400 navigation_gesture_ = frame->isProcessingUserGesture() ?
2401 NavigationGestureUnknown : NavigationGestureAuto;
2402
2403 // Make sure redirect tracking state is clear for the new load.
2404 completed_client_redirect_src_ = GURL();
2405 } else if (frame->parent()->isLoading()) {
2406 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002407 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172408 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2409 }
2410
2411 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2412 routing_id_, is_top_most, ds->request().url()));
2413}
2414
2415void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2416 if (frame->parent())
2417 return;
2418 // Received a redirect on the main frame.
2419 WebDataSource* data_source = frame->provisionalDataSource();
2420 if (!data_source) {
2421 // Should only be invoked when we have a data source.
2422 NOTREACHED();
2423 return;
2424 }
2425 std::vector<GURL> redirects;
2426 GetRedirectChain(data_source, &redirects);
2427 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512428 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2429 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172430 }
2431}
2432
[email protected]40bd6582009-12-04 23:49:512433void RenderView::didFailProvisionalLoad(WebFrame* frame,
2434 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172435 // Notify the browser that we failed a provisional load with an error.
2436 //
2437 // Note: It is important this notification occur before DidStopLoading so the
2438 // SSL manager can react to the provisional load failure before being
2439 // notified the load stopped.
2440 //
2441 WebDataSource* ds = frame->provisionalDataSource();
2442 DCHECK(ds);
2443
2444 const WebURLRequest& failed_request = ds->request();
2445
2446 bool show_repost_interstitial =
2447 (error.reason == net::ERR_CACHE_MISS &&
2448 EqualsASCII(failed_request.httpMethod(), "POST"));
2449 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2450 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2451 show_repost_interstitial));
2452
2453 // Don't display an error page if this is simply a cancelled load. Aside
2454 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2455 if (error.reason == net::ERR_ABORTED)
2456 return;
2457
2458 // Make sure we never show errors in view source mode.
2459 frame->enableViewSourceMode(false);
2460
2461 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2462
2463 // If this is a failed back/forward/reload navigation, then we need to do a
2464 // 'replace' load. This is necessary to avoid messing up session history.
2465 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2466 // as session history is concerned.
2467 //
2468 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2469 // the page id.
2470 //
2471 bool replace =
2472 navigation_state->pending_page_id() != -1 ||
2473 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2474
2475 // If we failed on a browser initiated request, then make sure that our error
2476 // page load is regarded as the same browser initiated request.
2477 if (!navigation_state->is_content_initiated()) {
2478 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2479 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002480 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172481 navigation_state->transition_type(),
2482 navigation_state->request_time()));
2483 }
2484
2485 // Provide the user with a more helpful error page?
2486 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2487 return;
2488
2489 // Fallback to a local error page.
2490 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2491 replace);
2492}
2493
2494void RenderView::didReceiveDocumentData(
2495 WebFrame* frame, const char* data, size_t data_len,
2496 bool& prevent_default) {
2497 NavigationState* navigation_state =
2498 NavigationState::FromDataSource(frame->dataSource());
2499 if (!navigation_state->postpone_loading_data())
2500 return;
2501
2502 // We're going to call commitDocumentData ourselves...
2503 prevent_default = true;
2504
2505 // Continue buffering the response data for the original 404 page. If it
2506 // grows too large, then we'll just let it through.
2507 navigation_state->append_postponed_data(data, data_len);
2508 if (navigation_state->postponed_data().size() >= 512) {
2509 navigation_state->set_postpone_loading_data(false);
2510 frame->commitDocumentData(navigation_state->postponed_data().data(),
2511 navigation_state->postponed_data().size());
2512 navigation_state->clear_postponed_data();
2513 }
2514}
2515
[email protected]40bd6582009-12-04 23:49:512516void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2517 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172518 NavigationState* navigation_state =
2519 NavigationState::FromDataSource(frame->dataSource());
2520
[email protected]9e84a872010-02-09 18:23:422521 if (!frame->parent()) { // Main frame case.
2522 // Let the page translator know that the page has changed so it can clear
2523 // its states.
2524 page_translator_->MainFrameNavigated();
2525 }
2526
[email protected]3d9689372009-09-10 04:29:172527 navigation_state->set_commit_load_time(Time::Now());
2528 if (is_new_navigation) {
2529 // When we perform a new navigation, we need to update the previous session
2530 // history entry with state for the page we are leaving.
2531 UpdateSessionHistory(frame);
2532
2533 // We bump our Page ID to correspond with the new session history entry.
2534 page_id_ = next_page_id_++;
2535
[email protected]3cc72b12010-03-18 23:03:002536 // Advance our offset in session history, applying the length limit. There
2537 // is now no forward history.
2538 history_list_offset_++;
2539 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2540 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2541 history_list_length_ = history_list_offset_ + 1;
2542
[email protected]f9f4841b2010-03-20 05:41:422543 MessageLoop::current()->PostDelayedTask(
2544 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172545 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2546 page_id_, true),
2547 kDelayForForcedCaptureMs);
2548 } else {
2549 // Inspect the navigation_state on this frame to see if the navigation
2550 // corresponds to a session history navigation... Note: |frame| may or
2551 // may not be the toplevel frame, but for the case of capturing session
2552 // history, the first committed frame suffices. We keep track of whether
2553 // we've seen this commit before so that only capture session history once
2554 // per navigation.
2555 //
2556 // Note that we need to check if the page ID changed. In the case of a
2557 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2558 // previous URL and the current page ID, which would be wrong.
2559 if (navigation_state->pending_page_id() != -1 &&
2560 navigation_state->pending_page_id() != page_id_ &&
2561 !navigation_state->request_committed()) {
2562 // This is a successful session history navigation!
2563 UpdateSessionHistory(frame);
2564 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002565
2566 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172567 }
2568 }
2569
2570 // Remember that we've already processed this request, so we don't update
2571 // the session history again. We do this regardless of whether this is
2572 // a session history navigation, because if we attempted a session history
2573 // navigation without valid HistoryItem state, WebCore will think it is a
2574 // new navigation.
2575 navigation_state->set_request_committed(true);
2576
2577 UpdateURL(frame);
2578
2579 // If this committed load was initiated by a client redirect, we're
2580 // at the last stop now, so clear it.
2581 completed_client_redirect_src_ = GURL();
2582
2583 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272584 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172585}
2586
2587void RenderView::didClearWindowObject(WebFrame* frame) {
2588 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2589 BindDOMAutomationController(frame);
2590 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2591 dom_ui_bindings_.set_message_sender(this);
2592 dom_ui_bindings_.set_routing_id(routing_id_);
2593 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2594 }
2595 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2596 external_host_bindings_.set_message_sender(this);
2597 external_host_bindings_.set_routing_id(routing_id_);
2598 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2599 }
2600}
2601
2602void RenderView::didCreateDocumentElement(WebFrame* frame) {
2603 if (RenderThread::current()) { // Will be NULL during unit tests.
2604 RenderThread::current()->user_script_slave()->InjectScripts(
2605 frame, UserScript::DOCUMENT_START);
2606 }
[email protected]078b34612009-09-19 19:31:512607 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2608 view_type_ == ViewType::EXTENSION_MOLE) {
2609 InjectToolstripCSS();
2610 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2611 }
[email protected]3d9689372009-09-10 04:29:172612
2613 // Notify the browser about non-blank documents loading in the top frame.
2614 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252615 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272616 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172617 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2618 }
2619}
2620
2621void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2622 UpdateTitle(frame, title);
2623
2624 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272625 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172626}
2627
2628void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2629 WebDataSource* ds = frame->dataSource();
2630 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2631 DCHECK(navigation_state);
2632 navigation_state->set_finish_document_load_time(Time::Now());
2633
2634 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2635
[email protected]e9e07992010-02-17 21:04:362636 // The document has now been fully loaded. Scan for forms to be sent up to
2637 // the browser.
2638 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482639 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362640 SendForms(frame);
[email protected]3d9689372009-09-10 04:29:172641 SendPasswordForms(frame);
2642
2643 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272644 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172645
2646 if (RenderThread::current()) { // Will be NULL during unit tests.
2647 RenderThread::current()->user_script_slave()->InjectScripts(
2648 frame, UserScript::DOCUMENT_END);
2649 }
[email protected]fa7b6b542009-11-03 05:02:302650
2651 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
[email protected]9e84a872010-02-09 18:23:422652
2653 if (page_translator_->IsPageTranslated())
2654 page_translator_->TranslateFrame(frame);
[email protected]fa7b6b542009-11-03 05:02:302655}
2656
2657void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2658 if (RenderThread::current()) { // Will be NULL during unit tests.
2659 RenderThread::current()->user_script_slave()->InjectScripts(
2660 frame, UserScript::DOCUMENT_IDLE);
2661 }
2662
2663 WebFrame* main_frame = webview()->mainFrame();
2664 if (frame == main_frame) {
2665 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202666 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302667 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202668 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302669 pending_code_execution_queue_.pop();
2670 }
2671 }
[email protected]3d9689372009-09-10 04:29:172672}
2673
2674void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2675 // Ignore
2676}
2677
2678void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2679 // Ignore
2680}
2681
2682void RenderView::didFinishLoad(WebFrame* frame) {
2683 WebDataSource* ds = frame->dataSource();
2684 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2685 DCHECK(navigation_state);
2686 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302687 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172688}
2689
[email protected]ccbe04e2010-03-17 17:58:432690void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172691 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062692
2693 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2694 // since a new one gets created by didCreateDataSource.
2695 NavigationState* state =
2696 NavigationState::FromDataSource(frame->dataSource());
2697 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2698
[email protected]3d9689372009-09-10 04:29:172699 // If this was a reference fragment navigation that we initiated, then we
2700 // could end up having a non-null pending navigation state. We just need to
2701 // update the ExtraData on the datasource so that others who read the
2702 // ExtraData will get the new NavigationState. Similarly, if we did not
2703 // initiate this navigation, then we need to take care to reset any pre-
2704 // existing navigation state to a content-initiated navigation state.
2705 // DidCreateDataSource conveniently takes care of this for us.
2706 didCreateDataSource(frame, frame->dataSource());
2707
[email protected]f6c2459d2010-02-24 22:34:062708 if (idle_scheduler_ran) {
2709 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2710 NavigationState* new_state =
2711 NavigationState::FromDataSource(frame->dataSource());
2712 new_state->user_script_idle_scheduler()->set_has_run(true);
2713 }
2714
[email protected]3d9689372009-09-10 04:29:172715 didCommitProvisionalLoad(frame, is_new_navigation);
2716
[email protected]26aa0482009-09-30 16:55:272717 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172718}
2719
[email protected]476b6f82009-09-10 21:00:592720void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312721 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592722}
2723
[email protected]3d9689372009-09-10 04:29:172724void RenderView::assignIdentifierToRequest(
2725 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2726 // Ignore
2727}
2728
[email protected]fa0a3432010-03-30 16:53:492729// Used in logMimeTypeForCrossOriginRequest(), remove when that function
2730// is removed
2731typedef base::hash_map<unsigned, WebURLRequest::TargetType> TargetTypeMap;
2732static TargetTypeMap target_type_map_;
2733typedef base::hash_map<std::string, int> MimeTypeMap;
2734static MimeTypeMap mime_type_map_;
2735
2736// Copied from net/base/mime_util.cc, supported_non_image_types[]
2737static const char* const cross_origin_mime_types_to_log[] = {
2738 "text/cache-manifest",
2739 "text/html",
2740 "text/xml",
2741 "text/xsl",
2742 "text/plain",
2743 "text/vnd.chromium.ftp-dir",
2744 "text/",
2745 "text/css",
2746 "image/svg+xml",
2747 "application/xml",
2748 "application/xhtml+xml",
2749 "application/rss+xml",
2750 "application/atom+xml",
2751 "application/json",
2752 "application/x-x509-user-cert",
2753 "multipart/x-mixed-replace"
2754};
2755
2756static void initMimeTypeMapIfNeeded() {
2757 if (!mime_type_map_.size()) {
2758 for (size_t i = 0; i < arraysize(cross_origin_mime_types_to_log); ++i)
2759 mime_type_map_[cross_origin_mime_types_to_log[i]] = i;
2760 }
2761}
2762
2763static void logMimeTypeForCrossOriginRequest(
2764 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
2765 initMimeTypeMapIfNeeded();
2766
2767 // Metrics to check the feasability of blocking cross-site requests
2768 // a renderer shouldn't be making (in case we try to move cross-site frames
2769 // into their own process someday). We're erring on the side of counting more
2770 // mime-types then we strictly need (we'd only consider blocking cross-site
2771 // requests with types similar to HTML, XML, or JSON).
2772 // TODO(japhet): Make these more granular. We're ignoring all miscellaneous
2773 // subresource requests, not just the XHRs that might be allowed.
2774 // Also, we should make these metrics be based on something more accurate
2775 // than the mime type header, such as parsing or content sniffing.
2776 TargetTypeMap::iterator iter = target_type_map_.find(identifier);
2777 if (iter != target_type_map_.end()) {
2778 WebURLRequest::TargetType target_type = iter->second;
2779 target_type_map_.erase(iter);
2780 if (target_type != WebURLRequest::TargetIsMainFrame
2781 && target_type != WebURLRequest::TargetIsSubFrame
2782 && target_type != WebURLRequest::TargetIsSubResource
2783 && target_type != WebURLRequest::TargetIsObject
2784 && !frame->securityOrigin().canAccess(
2785 WebSecurityOrigin::create(response.url()))) {
2786 std::string mime_type = response.mimeType().utf8();
2787 MimeTypeMap::iterator mime_type_iter = mime_type_map_.find(mime_type);
2788 if (mime_type_iter != mime_type_map_.end()) {
2789 UMA_HISTOGRAM_ENUMERATION(
2790 "SiteIsolation.CrossSiteNonFrameResponse_MIME_Type",
2791 mime_type_iter->second, arraysize(cross_origin_mime_types_to_log));
2792 }
2793 }
2794 }
2795}
2796
[email protected]3d9689372009-09-10 04:29:172797void RenderView::willSendRequest(
2798 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2799 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302800 WebFrame* top_frame = frame->top();
2801 if (!top_frame)
2802 top_frame = frame;
2803 WebDataSource* data_source = top_frame->provisionalDataSource();
2804 if (!data_source)
2805 data_source = top_frame->dataSource();
2806 if (data_source) {
2807 NavigationState* state = NavigationState::FromDataSource(data_source);
2808 if (state && state->is_cache_policy_override_set())
2809 request.setCachePolicy(state->cache_policy_override());
2810 }
[email protected]3d9689372009-09-10 04:29:172811 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502812 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132813 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492814
2815 target_type_map_[identifier] = request.targetType();
[email protected]3d9689372009-09-10 04:29:172816}
2817
2818void RenderView::didReceiveResponse(
2819 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492820
2821 logMimeTypeForCrossOriginRequest(frame, identifier, response);
2822
[email protected]3d9689372009-09-10 04:29:172823 // Only do this for responses that correspond to a provisional data source
2824 // of the top-most frame. If we have a provisional data source, then we
2825 // can't have any sub-resources yet, so we know that this response must
2826 // correspond to a frame load.
2827 if (!frame->provisionalDataSource() || frame->parent())
2828 return;
2829
2830 // If we are in view source mode, then just let the user see the source of
2831 // the server's 404 error page.
2832 if (frame->isViewSourceModeEnabled())
2833 return;
2834
[email protected]f48013be2010-01-14 22:07:452835 // Record that this was a page loaded over SPDY.
2836 if (response.wasFetchedViaSPDY()) {
2837 NavigationState* navigation_state =
2838 NavigationState::FromDataSource(frame->provisionalDataSource());
2839 navigation_state->set_was_fetched_via_spdy(true);
2840 }
2841
2842 // Consider loading an alternate error page for 404 responses.
2843 if (response.httpStatusCode() != 404)
2844 return;
2845
[email protected]3d9689372009-09-10 04:29:172846 // Can we even load an alternate error page for this URL?
2847 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2848 return;
2849
2850 NavigationState* navigation_state =
2851 NavigationState::FromDataSource(frame->provisionalDataSource());
2852 navigation_state->set_postpone_loading_data(true);
2853 navigation_state->clear_postponed_data();
2854}
2855
2856void RenderView::didFinishResourceLoad(
2857 WebFrame* frame, unsigned identifier) {
2858 NavigationState* navigation_state =
2859 NavigationState::FromDataSource(frame->dataSource());
2860 if (!navigation_state->postpone_loading_data())
2861 return;
2862
2863 // The server returned a 404 and the content was < 512 bytes (which we
2864 // suppressed). Go ahead and fetch the alternate page content.
2865
2866 const GURL& frame_url = frame->url();
2867
2868 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2869 DCHECK(error_page_url.is_valid());
2870
2871 WebURLError original_error;
2872 original_error.unreachableURL = frame_url;
2873
2874 navigation_state->set_alt_error_page_fetcher(
2875 new AltErrorPageResourceFetcher(
2876 error_page_url, frame, original_error,
2877 NewCallback(this, &RenderView::AltErrorPageFinished)));
2878}
2879
2880void RenderView::didFailResourceLoad(
2881 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2882 // Ignore
2883}
2884
2885void RenderView::didLoadResourceFromMemoryCache(
2886 WebFrame* frame, const WebURLRequest& request,
2887 const WebURLResponse& response) {
2888 // Let the browser know we loaded a resource from the memory cache. This
2889 // message is needed to display the correct SSL indicators.
2890 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2891 routing_id_,
2892 request.url(),
[email protected]91733b62009-09-18 06:21:092893 frame->securityOrigin().toString().utf8(),
2894 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172895 response.securityInfo()));
2896}
2897
[email protected]6069da8c2009-10-20 20:33:492898void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292899 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2900}
2901
2902void RenderView::didRunInsecureContent(
2903 WebFrame* frame, const WebSecurityOrigin& origin) {
2904 Send(new ViewHostMsg_DidRunInsecureContent(
2905 routing_id_,
2906 origin.toString().utf8()));
2907}
2908
[email protected]7ea093ba2009-11-03 05:54:592909bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002910 if (enabled_per_settings)
2911 return AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
[email protected]7ea093ba2009-11-03 05:54:592912
2913 WebSecurityOrigin origin = frame->securityOrigin();
2914 if (origin.isEmpty())
2915 return false; // Uninitialized document?
2916
2917 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2918 return true; // Browser UI elements should still work.
2919
2920 // If the scheme is ftp: or file:, an empty file name indicates a directory
2921 // listing, which requires JavaScript to function properly.
2922 GURL frame_url = frame->url();
2923 const char* kDirProtocols[] = { "ftp", "file" };
2924 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2925 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2926 return frame_url.SchemeIs(kDirProtocols[i]) &&
2927 frame_url.ExtractFileName().empty();
2928 }
2929 }
2930
2931 return false; // Other protocols fall through here.
2932}
2933
[email protected]8934a3b2010-02-25 00:34:002934void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
2935 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
2936}
2937
[email protected]c21f1d52010-03-04 03:19:432938void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
2939 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
2940}
2941
[email protected]3d9689372009-09-10 04:29:172942void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2943 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2944}
2945
[email protected]0c882b282009-10-07 17:01:282946void RenderView::didCreateScriptContext(WebFrame* frame) {
2947 EventBindings::HandleContextCreated(frame, false);
2948}
2949
2950void RenderView::didDestroyScriptContext(WebFrame* frame) {
2951 EventBindings::HandleContextDestroyed(frame);
2952}
2953
2954void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2955 EventBindings::HandleContextCreated(frame, true);
2956}
2957
[email protected]fc86daa2010-03-30 23:52:532958void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
2959 WebFrame* target,
2960 bool cross_origin,
2961 const WebString& property_name,
2962 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:102963 // TODO(johnnyg): track the individual properties and repeat event_ids.
2964 if (cross_origin)
2965 cross_origin_access_count_++;
2966 else
2967 same_origin_access_count_++;
2968}
2969
[email protected]3d9689372009-09-10 04:29:172970void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142971 CheckPreferredSize();
2972}
2973
2974void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172975 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252976 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172977 // message.
[email protected]ab32b16c2009-10-16 14:57:252978 if (send_preferred_size_changes_) {
[email protected]dfca5acf2010-03-22 03:28:432979 if (!webview())
2980 return;
2981
[email protected]3d9689372009-09-10 04:29:172982 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:252983 // cache the width and height and only send the IPC message when we're sure
2984 // they're different.
[email protected]26aa0482009-09-30 16:55:272985 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:392986 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:292987
[email protected]ab32b16c2009-10-16 14:57:252988 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:392989 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:252990 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:392991 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:252992
[email protected]ab32b16c2009-10-16 14:57:252993 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2994 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172995 }
2996 }
2997}
2998
[email protected]143dcd592009-11-06 21:33:492999void RenderView::didChangeScrollOffset(WebFrame* frame) {
3000 StartNavStateSyncTimerIfNecessary();
3001}
3002
[email protected]8922e1f2009-10-03 05:01:263003void RenderView::reportFindInPageMatchCount(int request_id, int count,
3004 bool final_update) {
3005 // If we have a message that has been queued up, then we should just replace
3006 // it. The ACK from the browser will make sure it gets sent when the browser
3007 // wants it.
3008 if (queued_find_reply_message_.get()) {
3009 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3010 routing_id_,
3011 request_id,
3012 count,
3013 gfx::Rect(),
3014 -1, // Don't update active match ordinal.
3015 final_update);
3016 queued_find_reply_message_.reset(msg);
3017 } else {
3018 // Send the search result over to the browser process.
3019 Send(new ViewHostMsg_Find_Reply(
3020 routing_id_,
3021 request_id,
3022 count,
3023 gfx::Rect(),
3024 -1, // // Don't update active match ordinal.
3025 final_update));
3026 }
3027}
3028
3029void RenderView::reportFindInPageSelection(int request_id,
3030 int active_match_ordinal,
3031 const WebRect& selection_rect) {
3032 // Send the search result over to the browser process.
3033 Send(new ViewHostMsg_Find_Reply(routing_id_,
3034 request_id,
3035 -1,
3036 selection_rect,
3037 active_match_ordinal,
3038 false));
3039}
3040
[email protected]24a7f3c2010-03-25 08:26:493041void RenderView::ReportNoFindInPageResults(int request_id) {
3042 Send(new ViewHostMsg_Find_Reply(routing_id_,
3043 request_id,
3044 0,
3045 gfx::Rect(),
3046 0,
3047 true));
3048}
3049
[email protected]79dbc662009-09-04 05:42:513050// webkit_glue::WebPluginPageDelegate -----------------------------------------
3051
[email protected]f103ab72009-09-02 17:10:593052webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
3053 const GURL& url,
3054 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:593055 std::string* actual_mime_type) {
3056 if (!PluginChannelHost::IsListening())
3057 return NULL;
3058
3059 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:273060 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:593061 if (main_frame)
3062 policy_url = main_frame->url();
3063
3064 FilePath path;
[email protected]610c0892009-09-08 19:46:183065 render_thread_->Send(new ViewHostMsg_GetPluginPath(
3066 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:593067 if (path.value().empty())
3068 return NULL;
3069
3070 const std::string* mime_type_to_use;
3071 if (!actual_mime_type->empty())
3072 mime_type_to_use = actual_mime_type;
3073 else
3074 mime_type_to_use = &mime_type;
3075
[email protected]d2139662009-12-10 03:21:143076 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283077 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143078 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163079 const char kPepperPrefix[] = "pepper-";
3080 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143081 if (CommandLine::ForCurrentProcess()->
3082 HasSwitch(switches::kInternalPepper)) {
3083 in_process_plugin = true;
3084 use_pepper_host = true;
3085 } else {
3086 // In process Pepper plugins must be explicitly enabled.
3087 return NULL;
3088 }
[email protected]d7ce4272010-03-27 01:06:013089 } else if (CommandLine::ForCurrentProcess()->
3090 HasSwitch(switches::kInternalPDF) &&
3091 StartsWithASCII(*mime_type_to_use, "application/pdf", true)) {
3092 in_process_plugin = true;
3093 use_pepper_host = true;
[email protected]26e8d5e2009-10-13 02:47:163094 }
[email protected]d2139662009-12-10 03:21:143095 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463096 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3097 if (mime_type == "application/x-nacl-srpc") {
3098 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143099 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463100 }
3101 }
3102 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143103 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283104 WebPluginDelegatePepper* pepper_plugin =
3105 WebPluginDelegatePepper::Create(path, *mime_type_to_use,
3106 AsWeakPtr());
3107 current_pepper_plugins_.insert(pepper_plugin);
3108 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143109 } else {
[email protected]6876dff2010-01-15 19:38:093110#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143111 return WebPluginDelegateImpl::Create(
3112 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093113#else
[email protected]596b2c42010-01-14 20:40:433114 NOTIMPLEMENTED();
3115 return NULL;
[email protected]7b6616f2010-01-14 18:07:553116#endif
[email protected]6876dff2010-01-15 19:38:093117 }
[email protected]f103ab72009-09-02 17:10:593118 }
3119
[email protected]610c0892009-09-08 19:46:183120 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593121}
3122
3123void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033124#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593125 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3126 routing_id(), window));
3127#endif
3128}
3129
3130void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033131#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593132 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3133 routing_id(), window));
3134#endif
3135 CleanupWindowInPluginMoves(window);
3136}
3137
3138void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3139 SchedulePluginMove(move);
3140}
3141
3142void RenderView::DidStartLoadingForPlugin() {
3143 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523144 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593145}
3146
3147void RenderView::DidStopLoadingForPlugin() {
3148 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523149 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593150}
3151
3152void RenderView::ShowModalHTMLDialogForPlugin(
3153 const GURL& url,
3154 const gfx::Size& size,
3155 const std::string& json_arguments,
3156 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213157 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593158 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213159 json_retval));
[email protected]f103ab72009-09-02 17:10:593160}
3161
[email protected]b921cfd22010-02-25 16:57:513162WebCookieJar* RenderView::GetCookieJar() {
3163 return &cookie_jar_;
3164}
3165
3166void RenderView::PageTranslated(int page_id,
3167 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:163168 const std::string& target_lang,
3169 TranslateErrors::Type error_type) {
[email protected]b921cfd22010-02-25 16:57:513170 Send(new ViewHostMsg_PageTranslated(routing_id_, page_id_,
[email protected]152b8ba32010-03-29 19:40:163171 original_lang, target_lang,
3172 error_type));
[email protected]b921cfd22010-02-25 16:57:513173}
3174
initial.commit09911bf2008-07-26 23:55:293175void RenderView::SyncNavigationState() {
3176 if (!webview())
3177 return;
3178
[email protected]26aa0482009-09-30 16:55:273179 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173180 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293181 return;
[email protected]ca948a22009-06-25 19:36:173182
3183 Send(new ViewHostMsg_UpdateState(
3184 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293185}
3186
[email protected]b0950a72009-09-29 23:16:173187bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3188 // Make sure webview was not shut down.
3189 if (!webview())
3190 return false;
3191 // Create an image resource fetcher and assign it with a call back object.
3192 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273193 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173194 NewCallback(this, &RenderView::DidDownloadImage)));
3195 return true;
3196}
3197
3198void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293199 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173200 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473201 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3202 fetcher->id(),
3203 fetcher->image_url(),
3204 image.isNull(),
3205 image));
[email protected]b0950a72009-09-29 23:16:173206 // Dispose of the image fetcher.
3207 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3208 image_fetchers_.erase(fetcher);
3209 // We're in the callback from the ImageResourceFetcher, best to delay
3210 // deletion.
3211 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293212}
3213
[email protected]bf5c2ff392009-07-08 16:24:333214void RenderView::OnDownloadFavIcon(int id,
3215 const GURL& image_url,
3216 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343217 bool data_image_failed = false;
3218 if (image_url.SchemeIs("data")) {
3219 SkBitmap data_image = ImageFromDataUrl(image_url);
3220 data_image_failed = data_image.empty();
3221 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333222 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3223 data_image));
[email protected]f11ca0732009-04-11 00:09:343224 }
3225 }
3226
[email protected]bf5c2ff392009-07-08 16:24:333227 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173228 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333229 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3230 SkBitmap()));
3231 }
initial.commit09911bf2008-07-26 23:55:293232}
3233
[email protected]f11ca0732009-04-11 00:09:343234SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3235 std::string mime_type, char_set, data;
3236 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3237 // Decode the favicon using WebKit's image decoder.
3238 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3239 const unsigned char* src_data =
3240 reinterpret_cast<const unsigned char*>(&data[0]);
3241
3242 return decoder.Decode(src_data, data.size());
3243 }
3244 return SkBitmap();
3245}
3246
initial.commit09911bf2008-07-26 23:55:293247void RenderView::OnGetApplicationInfo(int page_id) {
3248 webkit_glue::WebApplicationInfo app_info;
3249 if (page_id == page_id_)
3250 webkit_glue::GetApplicationInfo(webview(), &app_info);
3251
3252 // Prune out any data URLs in the set of icons. The browser process expects
3253 // any icon with a data URL to have originated from a favicon. We don't want
3254 // to decode arbitrary data URLs in the browser process. See
3255 // http://b/issue?id=1162972
3256 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593257 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293258 app_info.icons.erase(app_info.icons.begin() + i);
3259 --i;
3260 }
3261 }
3262
3263 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3264}
3265
[email protected]7ccddb8c2009-08-04 17:36:553266GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293267 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553268 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293269 // If the URL that failed was secure, then the embedding web page was not
3270 // expecting a network attacker to be able to manipulate its contents. As
3271 // we fetch alternate error pages over HTTP, we would be allowing a network
3272 // attacker to manipulate the contents of the response if we tried to use
3273 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153274 return GURL();
initial.commit09911bf2008-07-26 23:55:293275 }
3276
3277 // Grab the base URL from the browser process.
3278 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153279 return GURL();
initial.commit09911bf2008-07-26 23:55:293280
3281 // Strip query params from the failed URL.
3282 GURL::Replacements remove_params;
3283 remove_params.ClearUsername();
3284 remove_params.ClearPassword();
3285 remove_params.ClearQuery();
3286 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553287 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503288 std::string spec_to_send = url_to_send.spec();
3289 // Notify link doctor of the url truncation by sending of "?" at the end.
3290 if (failed_url.has_query())
3291 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293292
3293 // Construct the query params to send to link doctor.
3294 std::string params(alternate_error_page_url_.query());
3295 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503296 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293297 params.append("&sourceid=chrome");
3298 params.append("&error=");
3299 switch (error_type) {
3300 case DNS_ERROR:
3301 params.append("dnserror");
3302 break;
3303
3304 case HTTP_404:
3305 params.append("http404");
3306 break;
3307
[email protected]5df266ac2008-10-15 19:50:133308 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333309 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133310 break;
3311
initial.commit09911bf2008-07-26 23:55:293312 default:
3313 NOTREACHED() << "unknown ErrorPageType";
3314 }
3315
3316 // OK, build the final url to return.
3317 GURL::Replacements link_doctor_params;
3318 link_doctor_params.SetQueryStr(params);
3319 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3320 return url;
3321}
3322
[email protected]24a7f3c2010-03-25 08:26:493323webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() {
3324 WebPlugin* plugin = webview()->mainFrame()->document().
3325 toElement<WebPluginDocument>().plugin();
3326 return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate();
3327}
3328
[email protected]6069da8c2009-10-20 20:33:493329void RenderView::OnFind(int request_id, const string16& search_text,
3330 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273331 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493332
3333 if (main_frame->document().isPluginDocument()) {
3334 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3335 if (options.findNext) {
3336 // Just navigate back/forward.
3337 delegate->SelectFindResult(options.forward);
3338 } else {
3339 if (delegate->SupportsFind()) {
3340 delegate->StartFind(UTF16ToUTF8(search_text),
3341 options.matchCase,
3342 request_id);
3343 } else {
3344 ReportNoFindInPageResults(request_id);
3345 }
3346 }
3347 return;
3348 }
3349
[email protected]b4bb2502009-10-01 22:35:273350 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273351 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293352 WebFrame* search_frame = focused_frame; // start searching focused frame.
3353
3354 bool multi_frame = (frame_after_main != main_frame);
3355
3356 // If we have multiple frames, we don't want to wrap the search within the
3357 // frame, so we check here if we only have main_frame in the chain.
3358 bool wrap_within_frame = !multi_frame;
3359
[email protected]b3f2b912009-04-09 16:18:523360 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293361 bool result = false;
3362
[email protected]7830da3e2009-11-06 16:27:263363 // If something is selected when we start searching it means we cannot just
3364 // increment the current match ordinal; we need to re-generate it.
3365 WebRange current_selection = focused_frame->selectionRange();
3366
initial.commit09911bf2008-07-26 23:55:293367 do {
[email protected]dd7daa82009-08-10 05:46:453368 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593369 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293370
3371 if (!result) {
3372 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223373 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293374
3375 // Find the next frame, but skip the invisible ones.
3376 do {
3377 // What is the next frame to search? (we might be going backwards). Note
3378 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593379 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273380 search_frame->traverseNext(true) :
3381 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453382 } while (!search_frame->hasVisibleContent() &&
3383 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293384
[email protected]884db412008-11-24 23:46:503385 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223386 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293387
3388 // If we have multiple frames and we have wrapped back around to the
3389 // focused frame, we need to search it once more allowing wrap within
3390 // the frame, otherwise it will report 'no match' if the focused frame has
3391 // reported matches, but no frames after the focused_frame contain a
3392 // match for the search word(s).
3393 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453394 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593395 request_id, search_text, options, true, // Force wrapping.
3396 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293397 }
3398 }
3399
[email protected]26aa0482009-09-30 16:55:273400 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293401 } while (!result && search_frame != focused_frame);
3402
[email protected]7830da3e2009-11-06 16:27:263403 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293404 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453405 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293406 } else {
3407 // If nothing is found, set result to "0 of 0", otherwise, set it to
3408 // "-1 of 1" to indicate that we found at least one item, but we don't know
3409 // yet what is active.
3410 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3411 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293412
[email protected]4f3dc372009-02-24 00:10:293413 // If we find no matches then this will be our last status update.
3414 // Otherwise the scoping effort will send more results.
3415 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293416
[email protected]4f3dc372009-02-24 00:10:293417 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403418 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593419 request_id,
[email protected]4f3dc372009-02-24 00:10:293420 match_count,
3421 selection_rect,
3422 ordinal,
3423 final_status_update));
initial.commit09911bf2008-07-26 23:55:293424
initial.commit09911bf2008-07-26 23:55:293425 // Scoping effort begins, starting with the mainframe.
3426 search_frame = main_frame;
3427
[email protected]dd7daa82009-08-10 05:46:453428 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293429
3430 do {
3431 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453432 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293433
3434 // We don't start another scoping effort unless at least one match has
3435 // been found.
3436 if (result) {
3437 // Start new scoping request. If the scoping function determines that it
3438 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453439 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593440 search_text,
3441 options,
initial.commit09911bf2008-07-26 23:55:293442 true); // reset the tickmarks
3443 }
3444
3445 // Iterate to the next frame. The frame will not necessarily scope, for
3446 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273447 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293448 } while (search_frame != main_frame);
3449 }
3450}
3451
[email protected]24a7f3c2010-03-25 08:26:493452void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3453 WebView* view = webview();
3454 if (!view)
3455 return;
3456
3457 WebDocument doc = view->mainFrame()->document();
3458 if (doc.isPluginDocument()) {
3459 GetDelegateForPluginDocument()->StopFind();
3460 return;
3461 }
3462
3463 bool clear_selection =
3464 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3465 if (clear_selection)
3466 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3467
3468 WebFrame* frame = view->mainFrame();
3469 while (frame) {
3470 frame->stopFinding(clear_selection);
3471 frame = frame->traverseNext(false);
3472 }
3473
3474 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3475 WebFrame* focused_frame = view->focusedFrame();
3476 if (focused_frame) {
3477 WebDocument doc = focused_frame->document();
3478 if (!doc.isNull()) {
3479 WebNode node = doc.focusedNode();
3480 if (!node.isNull())
3481 node.simulateClick();
3482 }
3483 }
3484 }
3485}
3486
3487void RenderView::OnFindReplyAck() {
3488 // Check if there is any queued up request waiting to be sent.
3489 if (queued_find_reply_message_.get()) {
3490 // Send the search result over to the browser process.
3491 Send(queued_find_reply_message_.get());
3492 queued_find_reply_message_.release();
3493 }
3494}
3495
[email protected]8c4cdd42010-01-12 21:31:133496// static
3497std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403498 // Text with less than 100 bytes will probably not provide good results.
3499 // Report it as unknown language.
3500 if (text.length() < 100)
3501 return kUnknownLanguageCode;
3502
[email protected]8c4cdd42010-01-12 21:31:133503 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133504 int num_languages = 0;
3505 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423506 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133507 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423508 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133509 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403510 if (is_reliable && cld_language != NUM_LANGUAGES &&
3511 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483512 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3513 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263514 // language code for tradtional Chinese among others.
3515 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3516 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3517 // for Simplified Chinese.
3518 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133519 }
[email protected]8c4cdd42010-01-12 21:31:133520 return language;
[email protected]7893a982010-01-07 23:25:523521}
3522
[email protected]8934a3b2010-02-25 00:34:003523bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353524 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003525 return current_content_settings_.settings[settings_type] !=
3526 CONTENT_SETTING_BLOCK;
3527}
3528
3529void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3530 if (!content_blocked_[settings_type]) {
3531 content_blocked_[settings_type] = true;
3532 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353533 }
[email protected]0de80162010-02-03 04:52:353534}
3535
[email protected]71b0d5d2010-02-15 05:43:073536void RenderView::ClearBlockedContentSettings() {
3537 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3538 content_blocked_[i] = false;
3539}
3540
initial.commit09911bf2008-07-26 23:55:293541void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3542 Send(new ViewHostMsg_DnsPrefetch(host_names));
3543}
3544
[email protected]40bd6582009-12-04 23:49:513545void RenderView::OnZoom(PageZoom::Function function) {
3546 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3547 return;
3548
[email protected]b03794d2010-03-26 19:57:523549 // Should we be saving zoom levels for plugins? It's not clear, so for now
3550 // don't.
3551 if (webview()->mainFrame()->document().isPluginDocument()) {
3552 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3553 int zoom;
3554 if (function == PageZoom::RESET) {
3555 zoom = 0;
3556 } else if (function == PageZoom::ZOOM_OUT) {
3557 zoom = -1;
3558 } else if (function == PageZoom::ZOOM_IN) {
3559 zoom = 1;
3560 } else {
3561 NOTREACHED();
[email protected]754bb3b2010-03-26 20:12:113562 return;
[email protected]b03794d2010-03-26 19:57:523563 }
3564 delegate->Zoom(zoom);
3565 return;
3566 }
3567
[email protected]40bd6582009-12-04 23:49:513568 int zoom_level = webview()->zoomLevel();
3569 int new_zoom_level = webview()->setZoomLevel(false,
3570 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3571
3572 // Tell the browser which host got zoomed so it can update the saved values.
3573 // Pages like the safe browsing interstitial can have empty hosts; don't
3574 // record those.
3575 std::string host(GURL(webview()->mainFrame()->url()).host());
3576 if (!host.empty())
3577 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3578}
3579
[email protected]f85f0702010-01-30 09:31:013580void RenderView::OnSetContentSettingsForLoadingHost(
3581 std::string host,
3582 const ContentSettings& content_settings) {
3583 host_content_settings_[host] = content_settings;
3584}
3585
[email protected]40bd6582009-12-04 23:49:513586void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3587 int zoom_level) {
3588 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293589}
3590
[email protected]41fc0322009-09-04 22:23:403591void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273592 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293593}
3594
[email protected]a697f4c2009-09-14 22:30:183595void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273596 WebString no_encoding;
3597 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183598}
3599
[email protected]20ad2692009-11-20 18:27:203600bool RenderView::GetAllChildFrames(
3601 WebFrame* parent_frame,
3602 std::vector<WebFrame*>* frames_vector) const {
3603 if (!parent_frame)
3604 return false;
3605 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3606 child_frame = child_frame->nextSibling()) {
3607 frames_vector->push_back(child_frame);
3608 GetAllChildFrames(child_frame, frames_vector);
3609 }
3610 return true;
3611}
3612
[email protected]dd7daa82009-08-10 05:46:453613WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3614 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273615 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453616
3617 // xpath string can represent a frame deep down the tree (across multiple
3618 // frame DOMs).
3619 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3620 // should break into 2 xpaths
3621 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3622
[email protected]26aa0482009-09-30 16:55:273623 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453624
3625 std::wstring xpath_remaining = xpath;
3626 while (!xpath_remaining.empty()) {
3627 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3628 std::wstring xpath_child;
3629 if (delim_pos != std::wstring::npos) {
3630 xpath_child = xpath_remaining.substr(0, delim_pos);
3631 xpath_remaining.erase(0, delim_pos + 1);
3632 } else {
3633 xpath_remaining.swap(xpath_child);
3634 }
3635 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293636 }
3637
[email protected]dd7daa82009-08-10 05:46:453638 return frame;
initial.commit09911bf2008-07-26 23:55:293639}
3640
[email protected]f29acf52008-11-03 20:08:333641void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3642 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293643 WebFrame* web_frame = GetChildFrame(frame_xpath);
3644 if (!web_frame)
3645 return;
3646
[email protected]dd7daa82009-08-10 05:46:453647 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293648}
3649
[email protected]1810e132009-03-24 23:35:483650void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083651 const std::string& css,
3652 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483653 WebFrame* web_frame = GetChildFrame(frame_xpath);
3654 if (!web_frame)
3655 return;
3656
[email protected]ffaef0c2009-09-15 17:08:083657 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483658}
3659
[email protected]00c39612010-03-06 02:53:283660void RenderView::OnPepperPluginDestroy(
3661 WebPluginDelegatePepper* pepper_plugin) {
3662 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
3663 current_pepper_plugins_.find(pepper_plugin);
3664 if (found_pepper == current_pepper_plugins_.end()) {
3665 NOTREACHED();
3666 return;
3667 }
3668 current_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473669
3670 // The plugin could have been destroyed while it was waiting for a file
3671 // choose callback, so check all pending completion callbacks and NULL them.
3672 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3673 file_chooser_completions_.begin();
3674 i != file_chooser_completions_.end(); /* nothing */) {
3675 if ((*i)->completion == pepper_plugin) {
3676 // We NULL the first one instead of deleting it because the plugin might
3677 // be the one waiting for a file choose callback. If the callback later
3678 // comes, we don't want to send the result to the next callback in line.
3679 if (i == file_chooser_completions_.begin())
3680 (*i)->completion = NULL;
3681 else
3682 i = file_chooser_completions_.erase(i);
3683 } else {
3684 ++i;
3685 }
3686 }
[email protected]00c39612010-03-06 02:53:283687}
3688
initial.commit09911bf2008-07-26 23:55:293689void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3690 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333691 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293692}
3693
[email protected]1810e132009-03-24 23:35:483694void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083695 const std::string& css,
3696 const std::string& id) {
3697 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413698
3699 // Notify RenderViewHost that css has been inserted into the frame.
3700 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483701}
3702
[email protected]7ea066a2009-04-06 20:21:593703void RenderView::OnAddMessageToConsole(
3704 const string16& frame_xpath,
3705 const string16& message,
3706 const WebConsoleMessage::Level& level) {
3707 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593708 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453709 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293710}
3711
[email protected]81e63782009-02-27 19:35:093712void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3713 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293714}
3715
3716void RenderView::OnSetDOMUIProperty(const std::string& name,
3717 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093718 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293719 dom_ui_bindings_.SetProperty(name, value);
3720}
3721
3722void RenderView::OnReservePageIDRange(int size_of_range) {
3723 next_page_id_ += size_of_range + 1;
3724}
3725
[email protected]e80c73b2009-04-07 23:24:583726void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3727 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253728 bool ended,
3729 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033730 if (ended) {
[email protected]26aa0482009-09-30 16:55:273731 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033732 }
initial.commit09911bf2008-07-26 23:55:293733}
3734
3735void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273736 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293737}
3738
initial.commit09911bf2008-07-26 23:55:293739void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103740 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293741 webkit_glue::FillPasswordForm(this->webview(), form_data);
3742}
3743
3744void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583745 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253746 const gfx::Point& screen_point,
3747 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273748 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583749 drop_data.ToDragData(),
3750 drop_data.identity,
3751 client_point,
[email protected]1d9f4132009-09-08 17:29:253752 screen_point,
3753 ops);
initial.commit09911bf2008-07-26 23:55:293754
[email protected]1d9f4132009-09-08 17:29:253755 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293756}
3757
[email protected]e80c73b2009-04-07 23:24:583758void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253759 const gfx::Point& screen_point,
3760 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273761 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253762 client_point,
3763 screen_point,
3764 ops);
initial.commit09911bf2008-07-26 23:55:293765
[email protected]1d9f4132009-09-08 17:29:253766 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293767}
3768
3769void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273770 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293771}
3772
[email protected]e80c73b2009-04-07 23:24:583773void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3774 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273775 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293776}
3777
3778void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593779 webkit_preferences_ = prefs;
3780 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293781}
3782
3783void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3784 alternate_error_page_url_ = url;
3785}
3786
[email protected]a0c7153e2009-12-09 14:36:333787void RenderView::OnCustomContextMenuAction(unsigned action) {
3788 webview()->performCustomContextMenuAction(action);
3789}
3790
[email protected]d4a00a72010-01-29 01:44:423791void RenderView::OnTranslatePage(int page_id,
3792 const std::string& source_lang,
3793 const std::string& target_lang) {
3794 if (page_id != page_id_)
3795 return; // Not the page we expected, nothing to do.
3796
3797 WebFrame* main_frame = webview()->mainFrame();
3798 if (!main_frame)
3799 return;
[email protected]9e84a872010-02-09 18:23:423800
3801 page_translator_->TranslatePage(page_id, main_frame,
3802 source_lang, target_lang);
[email protected]d4a00a72010-01-29 01:44:423803}
3804
[email protected]0bedb8a2010-01-14 19:36:323805void RenderView::OnTranslateTextResponse(
3806 int work_id, int error_id, const std::vector<string16>& text_chunks) {
[email protected]d4a00a72010-01-29 01:44:423807 text_translator_.OnTranslationResponse(work_id, error_id, text_chunks);
[email protected]0bedb8a2010-01-14 19:36:323808}
3809
initial.commit09911bf2008-07-26 23:55:293810void RenderView::OnInstallMissingPlugin() {
3811 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593812 if (first_default_plugin_)
3813 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293814}
3815
[email protected]cdaf8d02010-03-30 19:52:473816void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363817 // This could happen if we navigated to a different page before the user
3818 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473819 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363820 return;
3821
[email protected]cdaf8d02010-03-30 19:52:473822 WebVector<WebString> ws_file_names(paths.size());
3823 for (size_t i = 0; i < paths.size(); ++i)
3824 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463825
[email protected]cdaf8d02010-03-30 19:52:473826 if (file_chooser_completions_.front()->completion)
3827 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3828 file_chooser_completions_.pop_front();
3829
3830 // If there are more pending file chooser requests, schedule one now.
3831 if (!file_chooser_completions_.empty()) {
3832 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3833 file_chooser_completions_.front()->params));
3834 }
initial.commit09911bf2008-07-26 23:55:293835}
3836
3837void RenderView::OnEnableViewSourceMode() {
3838 if (!webview())
3839 return;
[email protected]26aa0482009-09-30 16:55:273840 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293841 if (!main_frame)
3842 return;
3843
[email protected]dd7daa82009-08-10 05:46:453844 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293845}
3846
[email protected]ab32b16c2009-10-16 14:57:253847void RenderView::OnEnablePreferredSizeChangedMode() {
3848 send_preferred_size_changes_ = true;
[email protected]e8014aa52010-03-03 14:30:063849
3850 if (ViewType::ShouldAutoResize(view_type_))
[email protected]d8a179c2010-01-31 00:58:143851 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3852 &RenderView::CheckPreferredSize);
[email protected]0666aef2009-05-13 19:48:083853}
3854
[email protected]cda45c02010-02-25 19:28:103855void RenderView::OnDisableScrollbarsForSmallWindows(
3856 const gfx::Size& disable_scrollbar_size_limit) {
3857 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3858}
3859
[email protected]80d96fa2009-06-10 22:34:513860void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3861 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373862 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:033863#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:413864 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3865 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463866 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323867
[email protected]644d77e2010-01-27 01:03:103868 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323869 webview()->setScrollbarColors(
3870 renderer_prefs.thumb_inactive_color,
3871 renderer_prefs.thumb_active_color,
3872 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103873 webview()->setSelectionColors(
3874 renderer_prefs.active_selection_bg_color,
3875 renderer_prefs.active_selection_fg_color,
3876 renderer_prefs.inactive_selection_bg_color,
3877 renderer_prefs.inactive_selection_fg_color);
3878 }
[email protected]7a74e102009-09-03 00:16:563879#endif
[email protected]80d96fa2009-06-10 22:34:513880}
3881
[email protected]952cb702009-10-07 05:50:283882void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3883 const WebMediaPlayerAction& action) {
3884 if (webview())
3885 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563886}
3887
[email protected]7b291f92009-08-14 05:43:533888void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513889 // When this is first set, the bindings aren't fully loaded. We only need
3890 // to call through this API after the page has already been loaded. It's
3891 // also called in didCreateDocumentElement to bootstrap.
3892 if (view_type_ != ViewType::INVALID) {
3893 if (type == ViewType::EXTENSION_MOLE ||
3894 type == ViewType::EXTENSION_TOOLSTRIP) {
3895 ExtensionProcessBindings::SetViewType(webview(), type);
3896 }
3897 }
[email protected]7b291f92009-08-14 05:43:533898 view_type_ = type;
3899}
3900
3901void RenderView::OnUpdateBrowserWindowId(int window_id) {
3902 browser_window_id_ = window_id;
3903}
3904
[email protected]266eb6f2008-09-30 23:56:503905void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253906 const webkit_glue::WebAccessibility::InParams& in_params,
3907 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573908#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153909 if (!accessibility_.get()) {
3910 // TODO(dglazkov): Once implemented for all ports, remove lazy
3911 // instantiation of accessibility_.
3912 accessibility_.reset(WebAccessibilityCache::create());
3913 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253914 }
[email protected]266eb6f2008-09-30 23:56:503915
[email protected]17455962010-02-24 01:39:353916 out_params->return_code =
3917 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3918 in_params,
3919 out_params);
[email protected]c7287a92009-11-04 20:06:153920
[email protected]6c8afae52009-01-22 02:24:573921#else // defined(OS_WIN)
3922 // TODO(port): accessibility not yet implemented
3923 NOTIMPLEMENTED();
3924#endif
[email protected]266eb6f2008-09-30 23:56:503925}
3926
[email protected]6a983b42009-03-20 20:12:253927void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573928#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153929 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503930 // If accessibility is not activated, ignore clearing message.
3931 return;
3932 }
[email protected]e846d0d2009-05-20 00:53:063933
[email protected]c7287a92009-11-04 20:06:153934 if (clear_all) {
3935 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503936 return;
[email protected]c7287a92009-11-04 20:06:153937 }
3938
3939 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063940
[email protected]6c8afae52009-01-22 02:24:573941#else // defined(OS_WIN)
3942 // TODO(port): accessibility not yet implemented
3943 NOTIMPLEMENTED();
3944#endif
[email protected]266eb6f2008-09-30 23:56:503945}
3946
initial.commit09911bf2008-07-26 23:55:293947void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3948 const GURL& page_url) {
3949 // Prepare list to storage all savable resource links.
3950 std::vector<GURL> resources_list;
3951 std::vector<GURL> referrers_list;
3952 std::vector<GURL> frames_list;
3953 webkit_glue::SavableResourcesResult result(&resources_list,
3954 &referrers_list,
3955 &frames_list);
3956
[email protected]dbeb3952009-10-13 18:01:183957 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3958 webview(),
3959 page_url,
3960 &result,
3961 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293962 // If something is wrong when collecting all savable resource links,
3963 // send empty list to embedder(browser) to tell it failed.
3964 referrers_list.clear();
3965 resources_list.clear();
3966 frames_list.clear();
3967 }
3968
3969 // Send result of all savable resource links to embedder.
3970 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3971 resources_list,
3972 referrers_list,
3973 frames_list));
3974}
3975
3976void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323977 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313978 const std::vector<FilePath>& local_paths,
3979 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073980
3981 // Convert std::vector of GURLs to WebVector<WebURL>
3982 WebVector<WebURL> weburl_links(links);
3983
3984 // Convert std::vector of std::strings to WebVector<WebString>
3985 WebVector<WebString> webstring_paths(local_paths.size());
3986 for (size_t i = 0; i < local_paths.size(); i++)
3987 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3988
3989 WebPageSerializer::serialize(webview()->mainFrame(),
3990 true, this, weburl_links, webstring_paths,
3991 webkit_glue::FilePathToWebString(
3992 local_directory_name));
initial.commit09911bf2008-07-26 23:55:293993}
3994
[email protected]d9ec5c0f2009-12-23 11:55:073995void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
3996 const WebCString& data,
3997 WebPageSerializerClient::PageSerializationStatus status) {
3998 Send(new ViewHostMsg_SendSerializedHtmlData(
3999 routing_id_,
4000 frame_url,
4001 data.data(),
4002 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294003}
4004
[email protected]04b4a6c2008-08-02 00:44:474005void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:274006 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474007 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294008}
4009
[email protected]eb6b87a2009-07-24 15:57:394010void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294011 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4012 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4013 // in the onunload handler from appearing. For now, we're bypassing that and
4014 // calling the FrameLoader's CloseURL method directly. This should be
4015 // revisited to avoid having two ways to close a page. Having a single way
4016 // to close that can run onunload is also useful for fixing
4017 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274018 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294019 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454020 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174021 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294022 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4023 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454024 if (url.SchemeIs(chrome::kHttpScheme) ||
4025 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294026 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294027 }
[email protected]26aa0482009-09-30 16:55:274028 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294029
[email protected]ab9eabac2010-03-16 16:54:104030 // Reset stats
4031 cross_origin_access_count_ = 0;
4032 same_origin_access_count_ = 0;
4033
[email protected]eb6b87a2009-07-24 15:57:394034 // Just echo back the params in the ACK.
4035 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294036}
4037
4038void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574039#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294040 gfx::NativeTheme::instance()->CloseHandles();
4041 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:284042 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:574043#else // defined(OS_WIN)
4044 // TODO(port): we don't support theming on non-Windows platforms yet
4045 NOTIMPLEMENTED();
4046#endif
initial.commit09911bf2008-07-26 23:55:294047}
4048
[email protected]28790922009-03-09 19:48:374049void RenderView::OnMessageFromExternalHost(const std::string& message,
4050 const std::string& origin,
4051 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154052 if (message.empty())
4053 return;
4054
[email protected]28790922009-03-09 19:48:374055 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4056 target);
[email protected]3ac14a052008-08-15 21:22:154057}
4058
[email protected]0aa55312008-10-17 21:53:084059void RenderView::OnDisassociateFromPopupCount() {
4060 if (decrement_shared_popup_at_destruction_)
4061 shared_popup_counter_->data--;
4062 shared_popup_counter_ = new SharedRenderViewCounter(0);
4063 decrement_shared_popup_at_destruction_ = false;
4064}
4065
[email protected]15d79e12009-08-02 19:23:454066bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4067 const WebURLError& error,
4068 bool replace) {
4069 // We only show alternate error pages in the main frame. They are
4070 // intended to assist the user when navigating, so there is not much
4071 // value in showing them for failed subframes. Ideally, we would be
4072 // able to use the TYPED transition type for this, but that flag is
4073 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454074 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454075 return false;
4076
4077 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374078 // connection failure.
[email protected]15d79e12009-08-02 19:23:454079 int ec = error.reason;
4080 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4081 ec != net::ERR_CONNECTION_FAILED &&
4082 ec != net::ERR_CONNECTION_REFUSED &&
4083 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374084 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454085 return false;
4086
4087 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554088 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454089 if (!error_page_url.is_valid())
4090 return false;
4091
4092 // Load an empty page first so there is an immediate response to the error,
4093 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454094 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454095 GURL(kUnreachableWebDataURL),
4096 error.unreachableURL,
4097 replace);
4098
4099 // Now, create a fetcher for the error page and associate it with the data
4100 // source we just created via the LoadHTMLString call. That way if another
4101 // navigation occurs, the fetcher will get destroyed.
4102 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454103 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454104 navigation_state->set_alt_error_page_fetcher(
4105 new AltErrorPageResourceFetcher(
4106 error_page_url, frame, error,
4107 NewCallback(this, &RenderView::AltErrorPageFinished)));
4108 return true;
4109}
4110
initial.commit09911bf2008-07-26 23:55:294111std::string RenderView::GetAltHTMLForTemplate(
4112 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394113 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294114 ResourceBundle::GetSharedInstance().GetRawDataResource(
4115 template_resource_id));
4116
4117 if (template_html.empty()) {
4118 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4119 return "";
4120 }
[email protected]7cd22a52009-07-14 00:40:254121
initial.commit09911bf2008-07-26 23:55:294122 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254123 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294124 template_html, &error_strings, "t");
4125}
[email protected]0e79b9e2009-02-13 04:20:484126
[email protected]15d79e12009-08-02 19:23:454127void RenderView::AltErrorPageFinished(WebFrame* frame,
4128 const WebURLError& original_error,
4129 const std::string& html) {
4130 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554131
4132 // If we failed to download the alternate error page, fall back to the
4133 // original error page if present. Otherwise, LoadNavigationErrorPage
4134 // will simply display a default error page.
4135 const std::string* html_to_load = &html;
4136 if (html.empty()) {
4137 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454138 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554139 html_to_load = &navigation_state->postponed_data();
4140 }
4141 LoadNavigationErrorPage(
4142 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454143}
4144
[email protected]30f75e62009-02-25 22:01:004145void RenderView::OnMoveOrResizeStarted() {
4146 if (webview())
[email protected]4605325d2010-02-08 23:46:044147 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:004148}
4149
[email protected]30f75e62009-02-25 22:01:004150void RenderView::OnResize(const gfx::Size& new_size,
4151 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104152 if (webview()) {
[email protected]4605325d2010-02-08 23:46:044153 webview()->hideSuggestionsPopup();
[email protected]cda45c02010-02-25 19:28:104154
4155 if (send_preferred_size_changes_) {
4156 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4157 // either width or height, allow scroll bars.
4158 bool allow_scrollbars = (
4159 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244160 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104161 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4162 }
4163 }
4164
[email protected]30f75e62009-02-25 22:01:004165 RenderWidget::OnResize(new_size, resizer_rect);
4166}
[email protected]0aa477bd2009-03-23 22:21:434167
[email protected]00c39612010-03-06 02:53:284168void RenderView::DidInitiatePaint() {
4169 // Notify any pepper plugins that we started painting. The plugin "should"
4170 // never notified that we started painting, this is used for internal
4171 // bookkeeping only, so we know that the set can not change under us.
4172 for (std::set<WebPluginDelegatePepper*>::iterator i =
4173 current_pepper_plugins_.begin();
4174 i != current_pepper_plugins_.end(); ++i)
4175 (*i)->RenderViewInitiatedPaint();
4176}
4177
4178void RenderView::DidFlushPaint() {
4179 // Notify any pepper plugins that we painted. This will call into the plugin,
4180 // and we it may ask to close itself as a result. This will, in turn, modify
4181 // our set, possibly invalidating the iterator. So we iterate on a copy that
4182 // won't change out from under us.
4183 std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_;
4184 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4185 i != plugins.end(); ++i) {
4186 // The copy above makes sure our iterator is never invalid if some plugins
4187 // are destroyed. But some plugin may decide to close all of its views in
4188 // response to a paint in one of them, so we need to make sure each one is
4189 // still "current" before using it.
4190 if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end())
4191 (*i)->RenderViewFlushedPaint();
4192 }
4193
4194 WebFrame* main_frame = webview()->mainFrame();
4195
4196 // If we have a provisional frame we are between the start and commit stages
4197 // of loading and we don't want to save stats.
4198 if (!main_frame->provisionalDataSource()) {
4199 WebDataSource* ds = main_frame->dataSource();
4200 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4201 DCHECK(navigation_state);
4202
4203 Time now = Time::Now();
4204 if (navigation_state->first_paint_time().is_null()) {
4205 navigation_state->set_first_paint_time(now);
4206 }
4207 if (navigation_state->first_paint_after_load_time().is_null() &&
4208 !navigation_state->finish_load_time().is_null()) {
4209 navigation_state->set_first_paint_after_load_time(now);
4210 }
4211 }
4212}
4213
4214
[email protected]05d478752009-04-08 23:38:164215void RenderView::OnClearFocusedNode() {
4216 if (webview())
[email protected]26aa0482009-09-30 16:55:274217 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164218}
4219
[email protected]699ab0d2009-04-23 23:19:144220void RenderView::OnSetBackground(const SkBitmap& background) {
4221 if (webview())
[email protected]b4bb2502009-10-01 22:35:274222 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144223
4224 SetBackground(background);
4225}
4226
[email protected]8c66c5a2009-07-22 17:26:344227void RenderView::OnSetActive(bool active) {
4228 if (webview())
[email protected]b4bb2502009-10-01 22:35:274229 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264230
4231#if defined(OS_MACOSX)
4232 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4233 for (plugin_it = plugin_delegates_.begin();
4234 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4235 (*plugin_it)->SetWindowFocus(active);
4236 }
4237#endif
[email protected]8c66c5a2009-07-22 17:26:344238}
4239
[email protected]6ce7abc52010-02-02 18:40:144240#if defined(OS_MACOSX)
4241void RenderView::OnSetWindowVisibility(bool visible) {
4242 // Inform plugins that their container has changed visibility.
4243 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4244 for (plugin_it = plugin_delegates_.begin();
4245 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4246 (*plugin_it)->SetContainerVisibility(visible);
4247 }
4248}
[email protected]1e6e3c992010-02-08 15:52:134249
4250void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4251 gfx::Rect view_frame) {
4252 // Inform plugins that their window's frame has changed.
4253 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4254 for (plugin_it = plugin_delegates_.begin();
4255 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4256 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4257 }
4258}
[email protected]6ce7abc52010-02-02 18:40:144259#endif // OS_MACOSX
4260
[email protected]309d7a282009-03-24 09:18:274261void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584262 const ListValue& args,
[email protected]c6619182009-05-12 14:59:324263 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474264 bool has_callback) {
[email protected]c6619182009-05-12 14:59:324265 Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id,
[email protected]2f25d7b92009-06-10 00:06:474266 has_callback));
[email protected]309d7a282009-03-24 09:18:274267}
4268
[email protected]c6619182009-05-12 14:59:324269void RenderView::OnExtensionResponse(int request_id,
4270 bool success,
4271 const std::string& response,
4272 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354273 ExtensionProcessBindings::HandleResponse(
4274 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274275}
[email protected]c20210e62009-04-03 21:39:264276
[email protected]078b34612009-09-19 19:31:514277void RenderView::InjectToolstripCSS() {
4278 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4279 return;
4280
4281 static const base::StringPiece toolstrip_css(
4282 ResourceBundle::GetSharedInstance().GetRawDataResource(
4283 IDR_EXTENSION_TOOLSTRIP_CSS));
4284 std::string css = toolstrip_css.as_string();
4285 InsertCSS(L"", css, "ToolstripDefaultCSS");
4286}
4287
[email protected]7120f132009-07-20 21:05:374288void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494289 const ListValue& args,
4290 bool requires_incognito_access) {
4291 RendererExtensionBindings::Invoke(
4292 function_name, args, this, requires_incognito_access);
[email protected]7120f132009-07-20 21:05:374293}
4294
[email protected]e7e4f3c2009-04-21 15:24:084295// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264296//
[email protected]7a9b51f2009-06-29 21:28:294297// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:264298// The time points we keep are
4299// request: time document was requested by user
4300// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254301// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294302// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264303// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294304// first_paint: first paint performed
4305// first_paint_after_load: first paint performed after load is finished
4306// begin: request if it was user requested, start otherwise
4307//
[email protected]c20210e62009-04-03 21:39:264308// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:254309// request->start,
[email protected]7a9b51f2009-06-29 21:28:294310// start->commit,
4311// commit->finish_document,
4312// finish_document->finish,
4313// begin->commit,
4314// begin->finishDoc,
4315// begin->finish,
4316// begin->first_paint,
4317// begin->first_paint_after_load
4318// commit->finishDoc,
4319// commit->first_paint,
4320// commit->first_paint_after_load,
4321// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264322//
[email protected]e7e4f3c2009-04-21 15:24:084323// It's possible for the request time not to be set, if a client
4324// redirect had been done (the user never requested the page)
4325// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294326// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264327void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274328 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564329 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454330 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294331 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564332
[email protected]f9f4841b2010-03-20 05:41:424333 // If we've already dumped, do nothing.
4334 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294335 return;
[email protected]ed3fb032009-06-16 19:50:564336
[email protected]f9f4841b2010-03-20 05:41:424337 // Handle case where user hits "stop" or "back" before loading completely.
4338 bool abandoned_page = finish.is_null();
4339 if (abandoned_page) {
4340 finish = Time::Now();
4341 navigation_state->set_finish_load_time(finish);
4342 }
4343 UMA_HISTOGRAM_ENUMERATION("Renderer4.Abandoned", abandoned_page ? 1 : 0, 2);
4344
[email protected]f8999642009-10-27 21:39:424345 LogNavigationState(navigation_state, main_frame->dataSource());
4346
[email protected]a7ccc4d2010-01-27 08:14:484347 NavigationState::LoadType load_type = navigation_state->load_type();
4348 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184349 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484350
[email protected]ab9eabac2010-03-16 16:54:104351 // Site isolation metrics.
4352 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4353 cross_origin_access_count_);
4354 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4355 same_origin_access_count_);
4356
[email protected]7a9b51f2009-06-29 21:28:294357 Time request = navigation_state->request_time();
4358 Time start = navigation_state->start_load_time();
4359 Time commit = navigation_state->commit_load_time();
4360 Time finish_doc = navigation_state->finish_document_load_time();
4361 Time first_paint = navigation_state->first_paint_time();
4362 Time first_paint_after_load =
4363 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:264364
[email protected]7a9b51f2009-06-29 21:28:294365 Time begin;
4366 // Client side redirects will have no request time.
4367 if (request.is_null()) {
4368 begin = start;
4369 } else {
4370 begin = request;
4371 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084372 }
[email protected]7a9b51f2009-06-29 21:28:294373 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4374 UMA_HISTOGRAM_MEDIUM_TIMES(
4375 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4376 UMA_HISTOGRAM_MEDIUM_TIMES(
4377 "Renderer4.FinishDocToFinish", finish - finish_doc);
4378
4379 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484380
4381 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4382 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4383 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484384 TimeDelta begin_to_finish_doc = finish_doc - begin;
4385 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184386
4387 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4388 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4389 static const size_t kBeginToFinishBucketCount(100);
4390 TimeDelta begin_to_finish = finish_doc - begin;
4391 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4392 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4393
[email protected]a7ccc4d2010-01-27 08:14:484394 switch (load_type) {
4395 case NavigationState::UNDEFINED_LOAD:
4396 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4397 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4398 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184399 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4400 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4401 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484402 break;
4403 case NavigationState::RELOAD:
4404 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4405 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4406 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184407 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4408 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4409 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484410 break;
4411 case NavigationState::HISTORY_LOAD:
4412 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4413 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4414 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184415 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4416 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4417 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484418 break;
4419 case NavigationState::NORMAL_LOAD:
4420 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4421 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4422 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184423 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4424 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4425 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484426 break;
[email protected]4c1b6f0b2010-02-07 16:38:184427 case NavigationState::LINK_LOAD_NORMAL:
4428 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484429 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4430 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184431 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4432 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4433 kBeginToFinishBucketCount);
4434 break;
4435 case NavigationState::LINK_LOAD_RELOAD:
4436 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4437 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4438 kBeginToFinishDocBucketCount);
4439 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4440 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4441 kBeginToFinishBucketCount);
4442 break;
4443 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4444 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4445 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4446 kBeginToFinishDocBucketCount);
4447 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4448 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4449 kBeginToFinishBucketCount);
4450 break;
4451 case NavigationState::LINK_LOAD_CACHE_ONLY:
4452 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4453 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4454 kBeginToFinishDocBucketCount);
4455 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4456 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4457 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484458 break;
4459 default:
4460 break;
4461 }
4462
4463 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4464 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4465 if (use_dns_histogram) {
[email protected]f9f4841b2010-03-20 05:41:424466 UMA_HISTOGRAM_ENUMERATION(
4467 FieldTrial::MakeName("Renderer4.Abandoned", "DnsImpact"),
4468 abandoned_page ? 1 : 0, 2);
4469 UMA_HISTOGRAM_ENUMERATION(
4470 FieldTrial::MakeName("Renderer4.LoadType", "DnsImpact"),
[email protected]fd11f1752010-02-23 22:35:484471 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484472 switch (load_type) {
4473 case NavigationState::NORMAL_LOAD:
4474 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184475 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4476 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4477 kBeginToFinishBucketCount);
4478 break;
4479 case NavigationState::LINK_LOAD_NORMAL:
4480 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184481 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4482 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4483 kBeginToFinishBucketCount);
4484 break;
4485 case NavigationState::LINK_LOAD_RELOAD:
4486 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184487 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4488 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4489 kBeginToFinishBucketCount);
4490 break;
4491 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4492 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184493 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4494 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4495 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484496 break;
4497 default:
4498 break;
4499 }
4500 }
4501
[email protected]f9f4841b2010-03-20 05:41:424502 static bool use_packet_split_histogram(FieldTrialList::Find("PacketSplit") &&
4503 !FieldTrialList::Find("PacketSplit")->group_name().empty());
4504 if (use_packet_split_histogram) {
4505 UMA_HISTOGRAM_ENUMERATION(
4506 FieldTrial::MakeName("Renderer4.Abandoned", "PacketSplit"),
4507 abandoned_page ? 1 : 0, 2);
4508 UMA_HISTOGRAM_ENUMERATION(
4509 FieldTrial::MakeName("Renderer4.LoadType", "PacketSplit"),
4510 load_type, NavigationState::kLoadTypeMax);
4511 switch (load_type) {
4512 case NavigationState::NORMAL_LOAD:
4513 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4514 "Renderer4.BeginToFinish_NormalLoad", "PacketSplit"),
4515 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4516 kBeginToFinishBucketCount);
4517 break;
4518 case NavigationState::LINK_LOAD_NORMAL:
4519 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4520 "Renderer4.BeginToFinish_LinkLoadNormal", "PacketSplit"),
4521 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4522 kBeginToFinishBucketCount);
4523 break;
4524 case NavigationState::LINK_LOAD_RELOAD:
4525 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4526 "Renderer4.BeginToFinish_LinkLoadReload", "PacketSplit"),
4527 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4528 kBeginToFinishBucketCount);
4529 break;
4530 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4531 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4532 "Renderer4.BeginToFinish_LinkLoadStaleOk", "PacketSplit"),
4533 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4534 kBeginToFinishBucketCount);
4535 break;
4536 default:
4537 break;
4538 }
4539 }
4540
[email protected]a7ccc4d2010-01-27 08:14:484541 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4542 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4543 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484544 UMA_HISTOGRAM_ENUMERATION(
4545 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4546 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484547 switch (load_type) {
4548 case NavigationState::NORMAL_LOAD:
4549 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484550 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4551 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4552 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484553 break;
[email protected]4c1b6f0b2010-02-07 16:38:184554 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484555 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484556 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4557 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4558 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184559 break;
4560 case NavigationState::LINK_LOAD_RELOAD:
4561 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484562 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4563 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4564 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184565 break;
4566 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4567 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484568 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4569 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4570 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184571 break;
4572 case NavigationState::LINK_LOAD_CACHE_ONLY:
4573 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484574 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4575 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4576 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484577 break;
4578 default:
4579 break;
4580 }
4581 }
4582
4583 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4584 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184585 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4586 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484587 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4588 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4589 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4590 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544591
[email protected]0a32257a2009-07-09 18:10:414592 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4593 finish - start, kBeginToFinishMin,
4594 kBeginToFinishMax, kBeginToFinishBucketCount);
4595 if (!request.is_null())
4596 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4597 finish - request, kBeginToFinishMin,
4598 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544599
[email protected]7a9b51f2009-06-29 21:28:294600 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4601
4602 if (!first_paint.is_null()) {
4603 UMA_HISTOGRAM_MEDIUM_TIMES(
4604 "Renderer4.BeginToFirstPaint", first_paint - begin);
4605 UMA_HISTOGRAM_MEDIUM_TIMES(
4606 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264607 }
[email protected]7a9b51f2009-06-29 21:28:294608
4609 if (!first_paint_after_load.is_null()) {
4610 UMA_HISTOGRAM_MEDIUM_TIMES(
4611 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4612 UMA_HISTOGRAM_MEDIUM_TIMES(
4613 "Renderer4.CommitToFirstPaintAfterLoad",
4614 first_paint_after_load - commit);
4615 UMA_HISTOGRAM_MEDIUM_TIMES(
4616 "Renderer4.FinishToFirstPaintAfterLoad",
4617 first_paint_after_load - finish);
4618 }
4619
4620 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414621
4622 // Since there are currently no guarantees that renderer histograms will be
4623 // sent to the browser, we initiate a PostTask here to be sure that we send
4624 // the histograms we generated. Without this call, pages that don't have an
4625 // on-close-handler might generate data that is lost when the renderer is
4626 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484627 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4628 // should post when the onload is complete, so that it doesn't interfere with
4629 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414630 if (RenderThread::current()) {
4631 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134632 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414633 }
[email protected]c20210e62009-04-03 21:39:264634}
[email protected]e846d0d2009-05-20 00:53:064635
[email protected]f8999642009-10-27 21:39:424636void RenderView::LogNavigationState(const NavigationState* state,
4637 const WebDataSource* ds) const {
4638 // Because this function gets called on every page load,
4639 // take extra care to optimize it away if logging is turned off.
4640 if (logging::LOG_INFO < logging::GetMinLogLevel())
4641 return;
4642
4643 DCHECK(state);
4644 DCHECK(ds);
4645 GURL url(ds->request().url());
4646 Time start = state->start_load_time();
4647 Time finish = state->finish_load_time();
4648 // TODO(mbelshe): should we log more stats?
4649 LOG(INFO) << "PLT: "
4650 << (finish - start).InMilliseconds()
4651 << "ms "
4652 << url.spec();
4653}
4654
[email protected]cc0445f2009-10-13 16:09:084655void RenderView::focusAccessibilityObject(
4656 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064657#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154658 // TODO(dglazkov): Current logic implies that focus change can only be made
4659 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4660 // where accessibility is initialized. We should determine whether that's
4661 // right.
4662 if (!accessibility_.get())
4663 return;
[email protected]e846d0d2009-05-20 00:53:064664
4665 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154666 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064667
4668 // If id is valid, alert the browser side that an accessibility focus change
4669 // occurred.
4670 if (acc_obj_id >= 0)
4671 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4672
4673#else // defined(OS_WIN)
4674 // TODO(port): accessibility not yet implemented
4675 NOTIMPLEMENTED();
4676#endif
4677}
[email protected]daa8c58e2009-06-15 17:21:104678
[email protected]e9e07992010-02-17 21:04:364679void RenderView::SendForms(WebFrame* frame) {
4680 WebVector<WebFormElement> web_forms;
4681 frame->forms(web_forms);
4682
4683 std::vector<FormFieldValues> forms;
4684 for (size_t i = 0; i < web_forms.size(); ++i) {
4685 const WebFormElement& web_form = web_forms[i];
4686
4687 if (web_form.autoComplete()) {
4688 scoped_ptr<FormFieldValues> form(FormFieldValues::Create(web_form));
4689 if (form.get())
4690 forms.push_back(*form);
4691 }
4692 }
4693
4694 if (!forms.empty())
4695 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
4696}
4697
[email protected]a3018be2010-03-09 04:28:484698void RenderView::didChangeAccessibilityObjectState(
4699 const WebKit::WebAccessibilityObject& acc_obj) {
4700#if defined(OS_WIN)
4701 // TODO(dglazkov): Current logic implies that a state change can only be made
4702 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4703 // where accessibility is initialized. We should determine whether that's
4704 // right.
4705 if (!accessibility_.get())
4706 return;
4707
4708 // Retrieve the accessibility object id of the AccessibilityObject.
4709 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4710
4711 // If id is valid, alert the browser side that an accessibility object state
4712 // change occurred.
4713 if (acc_obj_id >= 0)
4714 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4715 acc_obj_id));
4716
4717#else // defined(OS_WIN)
4718 // TODO(port): accessibility not yet implemented
4719 NOTIMPLEMENTED();
4720#endif
4721}
4722
[email protected]daa8c58e2009-06-15 17:21:104723void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:484724 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454725 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104726
4727 std::vector<PasswordForm> password_forms;
4728 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484729 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104730
4731 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:484732 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:104733 scoped_ptr<PasswordForm> password_form(
4734 PasswordFormDomManager::CreatePasswordForm(form));
4735 if (password_form.get())
4736 password_forms.push_back(*password_form);
4737 }
4738 }
4739
4740 if (!password_forms.empty())
4741 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4742}
[email protected]0fda7272009-06-26 15:49:334743
4744void RenderView::Print(WebFrame* frame, bool script_initiated) {
4745 DCHECK(frame);
4746 if (print_helper_.get() == NULL) {
4747 print_helper_.reset(new PrintWebViewHelper(this));
4748 }
4749 print_helper_->Print(frame, script_initiated);
4750}
[email protected]446705872009-09-10 07:22:484751
4752void RenderView::OnSetEditCommandsForNextKeyEvent(
4753 const EditCommands& edit_commands) {
4754 edit_commands_ = edit_commands;
4755}
4756
[email protected]61f5a7b2009-12-22 22:21:204757void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274758 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354759 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204760 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4761 false));
[email protected]912256b32009-09-18 09:47:354762 return;
4763 }
4764
[email protected]fa7b6b542009-11-03 05:02:304765 WebDataSource* ds = main_frame->dataSource();
4766 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4767 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204768 pending_code_execution_queue_.push(
4769 linked_ptr<ViewMsg_ExecuteCode_Params>(
4770 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304771 return;
4772 }
4773
[email protected]61f5a7b2009-12-22 22:21:204774 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304775}
4776
4777void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204778 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484779 // Don't execute scripts in gallery pages.
4780 GURL frame_url = GURL(frame->url());
4781 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4782 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4783 return;
4784 }
4785
[email protected]20ad2692009-11-20 18:27:204786 std::vector<WebFrame*> frame_vector;
4787 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204788 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204789 GetAllChildFrames(frame, &frame_vector);
4790
4791 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4792 frame_it != frame_vector.end(); ++frame_it) {
4793 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204794 if (params.is_javascript) {
4795 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4796 continue;
4797
[email protected]20ad2692009-11-20 18:27:204798 std::vector<WebScriptSource> sources;
4799 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204800 WebScriptSource(WebString::fromUTF8(params.code)));
4801 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204802 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204803 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204804 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4805 } else {
[email protected]61f5a7b2009-12-22 22:21:204806 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204807 }
[email protected]912256b32009-09-18 09:47:354808 }
4809
[email protected]61f5a7b2009-12-22 22:21:204810 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354811}
4812
[email protected]60c42a8c72009-10-09 04:08:594813void RenderView::Close() {
4814 // We need to grab a pointer to the doomed WebView before we destroy it.
4815 WebView* doomed = webview();
4816 RenderWidget::Close();
4817 Singleton<ViewMap>::get()->erase(doomed);
4818}
4819
[email protected]446705872009-09-10 07:22:484820void RenderView::DidHandleKeyEvent() {
4821 edit_commands_.clear();
4822}
4823
[email protected]941e4552010-02-01 21:23:434824#if defined(OS_MACOSX)
4825void RenderView::OnWasHidden() {
4826 RenderWidget::OnWasHidden();
4827
4828 // Inform plugins that their container is no longer visible.
4829 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4830 for (plugin_it = plugin_delegates_.begin();
4831 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4832 (*plugin_it)->SetContainerVisibility(false);
4833 }
4834}
4835
4836void RenderView::OnWasRestored(bool needs_repainting) {
4837 RenderWidget::OnWasRestored(needs_repainting);
4838
4839 // Inform plugins that their container is now visible.
4840 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4841 for (plugin_it = plugin_delegates_.begin();
4842 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4843 (*plugin_it)->SetContainerVisibility(true);
4844 }
4845}
[email protected]1e6e3c992010-02-08 15:52:134846
4847void RenderView::OnSetFocus(bool enable) {
4848 RenderWidget::OnSetFocus(enable);
4849
4850 // RenderWidget's call to setFocus can cause the underlying webview's
4851 // activation state to change just like a call to setIsActive.
4852 if (enable && webview() && webview()->isActive()) {
4853 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4854 for (plugin_it = plugin_delegates_.begin();
4855 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4856 (*plugin_it)->SetWindowFocus(true);
4857 }
4858 }
4859}
[email protected]941e4552010-02-01 21:23:434860#endif // OS_MACOSX
4861
[email protected]83dde542009-09-11 20:59:554862void RenderView::EnsureDocumentTag() {
4863 // TODO(darin): There's actually no reason for this to be here. We should
4864 // have the browser side manage the document tag.
4865#if defined(OS_MACOSX)
4866 if (!has_document_tag_) {
4867 // Make the call to get the tag.
4868 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4869 has_document_tag_ = true;
4870 }
4871#endif
4872}
[email protected]12636df2009-09-28 22:32:214873
[email protected]43f28f832010-02-03 02:28:484874#if defined(OS_MACOSX)
4875gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle() {
4876 gfx::PluginWindowHandle window = NULL;
4877 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
4878 routing_id(), &window));
4879 return window;
4880}
4881
4882void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4883 if (window)
4884 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4885}
4886
[email protected]44ce0b12010-03-12 16:45:334887void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4888 int32 width,
4889 int32 height,
4890 uint64 io_surface_identifier) {
4891 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484892 routing_id(), window, width, height, io_surface_identifier));
4893}
4894
[email protected]44ce0b12010-03-12 16:45:334895void RenderView::AcceleratedSurfaceSetTransportDIB(
4896 gfx::PluginWindowHandle window,
4897 int32 width,
4898 int32 height,
4899 TransportDIB::Handle transport_dib) {
4900 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074901 routing_id(), window, width, height, transport_dib));
4902}
4903
[email protected]44ce0b12010-03-12 16:45:334904TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4905 size_t size) {
[email protected]1aef98132010-02-23 18:00:074906 TransportDIB::Handle dib_handle;
4907 // Assume this is a synchronous RPC.
4908 if (Send(new ViewHostMsg_AllocTransportDIB(size, &dib_handle)))
4909 return dib_handle;
4910 // Return an invalid handle if Send() fails.
4911 return TransportDIB::DefaultHandleValue();
4912}
4913
[email protected]44ce0b12010-03-12 16:45:334914void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074915 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4916}
4917
[email protected]44ce0b12010-03-12 16:45:334918void RenderView::AcceleratedSurfaceBuffersSwapped(
4919 gfx::PluginWindowHandle window) {
4920 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:484921}
4922#endif
[email protected]58c321d2010-02-19 12:11:284923
[email protected]cdaf8d02010-03-30 19:52:474924bool RenderView::ScheduleFileChooser(
4925 const ViewHostMsg_RunFileChooser_Params& params,
4926 WebFileChooserCompletion* completion) {
4927 static const size_t kMaximumPendingFileChooseRequests = 4;
4928 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4929 // This sanity check prevents too many file choose requests from getting
4930 // queued which could DoS the user. Getting these is most likely a
4931 // programming error (there are many ways to DoS the user so it's not
4932 // considered a "real" security check), either in JS requesting many file
4933 // choosers to pop up, or in a plugin.
4934 //
4935 // TODO(brettw) we might possibly want to require a user gesture to open
4936 // a file picker, which will address this issue in a better way.
4937 return false;
4938 }
4939
4940 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4941 new PendingFileChooser(params, completion)));
4942 if (file_chooser_completions_.size() == 1) {
4943 // Actually show the browse dialog when this is the first request.
4944 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4945 }
4946 return true;
4947}
4948
[email protected]58c321d2010-02-19 12:11:284949WebKit::WebGeolocationServiceInterface* RenderView::getGeolocationService() {
4950 if (!geolocation_dispatcher_.get())
4951 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
4952 return geolocation_dispatcher_.get();
4953}