blob: 9a5cc84e9ec96c3943a31e9f7cd04a4ff445b0ff [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]035545f2010-04-09 13:10:2125#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0926#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5527#include "chrome/common/child_process_logging.h"
initial.commit09911bf2008-07-26 23:55:2928#include "chrome/common/chrome_switches.h"
[email protected]f0af6a72009-05-30 05:25:1729#include "chrome/common/chrome_constants.h"
[email protected]d146b832009-12-23 02:45:4830#include "chrome/common/extensions/extension_constants.h"
initial.commit09911bf2008-07-26 23:55:2931#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1732#include "chrome/common/page_zoom.h"
[email protected]e09ba552009-02-05 03:26:2933#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2634#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2935#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5936#include "chrome/common/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2937#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2538#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1139#include "chrome/renderer/devtools_agent.h"
40#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3541#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3242#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3543#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3744#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2845#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2946#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5647#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1148#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5649#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1250#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3051#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5052#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2553#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2854#include "chrome/renderer/render_thread.h"
[email protected]035545f2010-04-09 13:10:2155#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3456#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4657#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3558#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2959#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2960#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2961#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4262#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5663#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1564#include "gfx/color_utils.h"
65#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5766#include "gfx/native_widget_types.h"
[email protected]34ac8f32009-02-22 23:03:2767#include "grit/generated_resources.h"
68#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3469#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2970#include "net/base/escape.h"
71#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0072#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1073#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3074#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]418ed5ab2009-11-12 01:14:4975#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
76#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0777#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4978#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
79#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3280#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4981#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3582#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]b1438212010-04-03 00:30:5983#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:4984#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
85#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
86#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:4187#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:5088#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4989#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3290#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0791#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:4992#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
93#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4994#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
95#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
96#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
98#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
99#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
100#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34101#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49102#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
103#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
104#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
105#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
106#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
107#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]80f584d92010-01-21 03:59:04108#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29109#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29110#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59111#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24112#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24113#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34114#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17115#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51116#include "webkit/glue/media/simple_data_source.h"
initial.commit09911bf2008-07-26 23:55:29117#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29118#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30119#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23120#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30121#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]8400e032010-02-26 18:50:11122#include "webkit/glue/media/video_renderer_impl.h"
initial.commit09911bf2008-07-26 23:55:29123#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29124#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17125#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29126
[email protected]6c8afae52009-01-22 02:24:57127#if defined(OS_WIN)
128// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57129// * theming
[email protected]cd818412010-03-19 03:23:15130#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03131#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46132#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33133#elif defined(OS_MACOSX)
134#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57135#endif
136
[email protected]80f584d92010-01-21 03:59:04137using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26138using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33139using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45140using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59141using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24142using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17143using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56144using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10145using webkit_glue::PasswordFormDomManager;
[email protected]c7287a92009-11-04 20:06:15146using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08147using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21148using WebKit::WebApplicationCacheHost;
149using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41150using WebKit::WebColor;
151using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59152using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44153using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51154using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07155using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55156using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28157using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29158using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00159using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58160using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25161using WebKit::WebDragOperation;
162using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51163using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47164using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49165using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59166using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48167using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45168using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17169using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41170using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50171using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17172using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28173using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17174using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28175using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28176using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51177using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07178using WebKit::WebPageSerializer;
179using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17180using WebKit::WebPlugin;
181using WebKit::WebPluginParams;
[email protected]24a7f3c2010-03-25 08:26:49182using WebKit::WebPluginDocument;
[email protected]48c9cf2d2009-09-16 16:47:52183using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59184using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51185using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52186using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40187using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35188using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29189using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59190using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42191using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02192using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34193using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28194using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51195using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52196using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28197using WebKit::WebURL;
198using WebKit::WebURLError;
199using WebKit::WebURLRequest;
200using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28201using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03202using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28203using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43204using WebKit::WebWorker;
205using WebKit::WebWorkerClient;
[email protected]e1acf6f2008-10-27 20:43:33206
initial.commit09911bf2008-07-26 23:55:29207//-----------------------------------------------------------------------------
208
209// define to write the time necessary for thumbnail/DOM text retrieval,
210// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29211// #define TIME_TEXT_RETRIEVAL
212
213// maximum number of characters in the document to index, any text beyond this
214// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57215static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29216
217// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37218static const int kThumbnailWidth = 212;
219static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29220
221// Delay in milliseconds that we'll wait before capturing the page contents
222// and thumbnail.
223static const int kDelayForCaptureMs = 500;
224
225// Typically, we capture the page data once the page is loaded.
226// Sometimes, the page never finishes to load, preventing the page capture
227// To workaround this problem, we always perform a capture after the following
228// delay.
229static const int kDelayForForcedCaptureMs = 6000;
230
[email protected]882daa92009-11-05 16:31:31231// Time, in seconds, we delay before sending content state changes (such as form
232// state and scroll position) to the browser. We delay sending changes to avoid
233// spamming the browser.
234// To avoid having tab/session restore require sending a message to get the
235// current content state during tab closing we use a shorter timeout for the
236// foreground renderer. This means there is a small window of time from which
237// content state is modified and not sent to session restore, but this is
238// better than having to wake up all renderers during shutdown.
239static const int kDelaySecondsForContentStateSyncHidden = 5;
240static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29241
[email protected]0aa55312008-10-17 21:53:08242// The maximum number of popups that can be spawned from one page.
243static const int kMaximumNumberOfUnacknowledgedPopups = 25;
244
initial.commit09911bf2008-07-26 23:55:29245static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16246 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29247
[email protected]50b691c2008-10-31 19:08:35248static const char* const kBackForwardNavigationScheme = "history";
249
[email protected]8c4cdd42010-01-12 21:31:13250// The string returned in DetectLanguage if we failed to detect the language.
[email protected]8dc5a2052010-01-19 21:32:42251static const char* const kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13252
[email protected]726985e22009-06-18 21:09:28253static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
254 WebVector<WebURL> urls;
255 ds->redirectChain(urls);
256 result->reserve(urls.size());
257 for (size_t i = 0; i < urls.size(); ++i)
258 result->push_back(urls[i]);
259}
260
[email protected]61f5a7b2009-12-22 22:21:20261static bool UrlMatchesPermissions(
262 const GURL& url, const std::vector<URLPattern>& host_permissions) {
263 for (size_t i = 0; i < host_permissions.size(); ++i) {
264 if (host_permissions[i].MatchesUrl(url))
265 return true;
266 }
267
268 return false;
269}
270
[email protected]30507922010-01-15 16:48:23271static bool PaintViewIntoCanvas(WebView* view,
272 skia::PlatformCanvas& canvas) {
273 view->layout();
274 const WebSize& size = view->size();
275
276 if (!canvas.initialize(size.width, size.height, true))
277 return false;
278
279 view->paint(webkit_glue::ToWebCanvas(&canvas),
280 WebRect(0, 0, size.width, size.height));
281 // TODO: Add a way to snapshot the whole page, not just the currently
282 // visible part.
283
284 return true;
285}
286
287// Calculates how "boring" a thumbnail is. The boring score is the
288// 0,1 ranged percentage of pixels that are the most common
289// luma. Higher boring scores indicate that a higher percentage of a
290// bitmap are all the same brightness.
291static double CalculateBoringScore(SkBitmap* bitmap) {
292 int histogram[256] = {0};
293 color_utils::BuildLumaHistogram(bitmap, histogram);
294
295 int color_count = *std::max_element(histogram, histogram + 256);
296 int pixel_count = bitmap->width() * bitmap->height();
297 return static_cast<double>(color_count) / pixel_count;
298}
299
initial.commit09911bf2008-07-26 23:55:29300///////////////////////////////////////////////////////////////////////////////
301
[email protected]60c42a8c72009-10-09 04:08:59302int32 RenderView::next_page_id_ = 1;
303
[email protected]cdaf8d02010-03-30 19:52:47304struct RenderView::PendingFileChooser {
305 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
306 WebFileChooserCompletion* c)
307 : params(p),
308 completion(c) {
309 }
310 ViewHostMsg_RunFileChooser_Params params;
311 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
312};
313
[email protected]2fab253a2009-08-17 23:00:59314RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34315 const WebPreferences& webkit_preferences,
316 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12317 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]81e63782009-02-27 19:35:09318 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21319 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24320 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21321 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24322 page_id_(-1),
323 last_page_id_sent_to_browser_(-1),
324 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24325 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46326 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50327 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11328 devtools_agent_(NULL),
329 devtools_client_(NULL),
[email protected]3cc72b12010-03-18 23:03:00330 history_list_offset_(-1),
331 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24332 has_unload_listener_(false),
333 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39334 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24335 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26336 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31337 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25338 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26339 ALLOW_THIS_IN_INITIALIZER_LIST(
340 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53341 view_type_(ViewType::INVALID),
342 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55343 last_top_level_navigation_page_id_(-1),
344#if defined(OS_MACOSX)
345 has_document_tag_(false),
346#endif
[email protected]98324892009-09-09 21:16:05347 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32348 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34349 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ab9eabac2010-03-16 16:54:10350 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]85d252e2010-04-06 22:21:02351 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
[email protected]ab9eabac2010-03-16 16:54:10352 cross_origin_access_count_(0),
353 same_origin_access_count_(0) {
[email protected]71b0d5d2010-02-15 05:43:07354 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29355}
356
357RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08358 if (decrement_shared_popup_at_destruction_)
359 shared_popup_counter_->data--;
360
[email protected]b0950a72009-09-29 23:16:17361 // Dispose of un-disposed image fetchers.
362 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
363 i != image_fetchers_.end(); ++i) {
364 delete *i;
365 }
366
[email protected]a1128322009-10-06 18:38:46367 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47368 while (!file_chooser_completions_.empty()) {
369 if (file_chooser_completions_.front()->completion) {
370 file_chooser_completions_.front()->completion->didChooseFile(
371 WebVector<WebString>());
372 }
373 file_chooser_completions_.pop_front();
374 }
[email protected]a1128322009-10-06 18:38:46375
[email protected]83dde542009-09-11 20:59:55376#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05377 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55378 if (has_document_tag_)
379 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
380#endif
[email protected]98324892009-09-09 21:16:05381
[email protected]5fb88962009-04-16 19:03:25382 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59383
384#ifndef NDEBUG
385 // Make sure we are no longer referenced by the ViewMap.
386 ViewMap* views = Singleton<ViewMap>::get();
387 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
388 DCHECK_NE(this, it->second) << "Failed to call Close?";
389#endif
390}
391
392/*static*/
393void RenderView::ForEach(RenderViewVisitor* visitor) {
394 ViewMap* views = Singleton<ViewMap>::get();
395 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
396 if (!visitor->Visit(it->second))
397 return;
398 }
399}
400
401/*static*/
402RenderView* RenderView::FromWebView(WebView* webview) {
403 ViewMap* views = Singleton<ViewMap>::get();
404 ViewMap::iterator it = views->find(webview);
405 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29406}
407
408/*static*/
[email protected]0aa55312008-10-17 21:53:08409RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24410 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15411 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08412 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51413 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08414 const WebPreferences& webkit_prefs,
415 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34416 int32 routing_id,
417 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29418 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34419 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
420 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29421 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29422 opener_id,
[email protected]80d96fa2009-06-10 22:34:51423 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08424 counter,
initial.commit09911bf2008-07-26 23:55:29425 routing_id); // adds reference
426 return view;
427}
428
429/*static*/
430void RenderView::SetNextPageID(int32 next_page_id) {
431 // This method should only be called during process startup, and the given
432 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05433 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29434 DCHECK(next_page_id >= next_page_id_);
435 next_page_id_ = next_page_id;
436}
437
[email protected]afe3a1672009-11-17 19:04:12438void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56439 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
440}
441
[email protected]a3a8fb6d2009-10-22 20:12:51442void RenderView::PluginCrashed(const FilePath& plugin_path) {
443 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29444}
445
[email protected]d8fd6fa2010-02-01 15:54:26446#if defined(OS_MACOSX)
447void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
448 plugin_delegates_.insert(delegate);
449}
450
451void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
452 plugin_delegates_.erase(delegate);
453}
454#endif
455
[email protected]18bcc3c2009-01-27 21:39:15456void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29457 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51458 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08459 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29460 int32 routing_id) {
461 DCHECK(!webview());
462
463 if (opener_id != MSG_ROUTING_NONE)
464 opener_id_ = opener_id;
465
[email protected]0aa55312008-10-17 21:53:08466 if (counter) {
467 shared_popup_counter_ = counter;
468 shared_popup_counter_->data++;
469 decrement_shared_popup_at_destruction_ = true;
470 } else {
471 shared_popup_counter_ = new SharedRenderViewCounter(0);
472 decrement_shared_popup_at_destruction_ = false;
473 }
474
[email protected]58bfc6b2009-06-24 09:45:02475 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04476
[email protected]50ae00ef2009-10-19 05:11:03477 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59478 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59479 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27480 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29481 webview()->setDevToolsAgent(
482 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29483
[email protected]d3ba77272009-09-03 00:06:09484 OnSetRendererPrefs(renderer_prefs);
485
initial.commit09911bf2008-07-26 23:55:29486 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24487 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29488 // Take a reference on behalf of the RenderThread. This will be balanced
489 // when we receive ViewMsg_Close.
490 AddRef();
491
492 // If this is a popup, we must wait for the CreatingNew_ACK message before
493 // completing initialization. Otherwise, we can finish it now.
494 if (opener_id == MSG_ROUTING_NONE) {
495 did_show_ = true;
496 CompleteInit(parent_hwnd);
497 }
498
499 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29500
[email protected]58bfc6b2009-06-24 09:45:02501 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09502 if (command_line.HasSwitch(switches::kDomAutomationController))
503 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29504
[email protected]5fb88962009-04-16 19:03:25505 audio_message_filter_ = new AudioMessageFilter(routing_id_);
506 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29507}
508
509void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27510 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27511 if (main_frame)
512 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26513
[email protected]b2abac72009-02-26 12:39:28514 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11515 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28516 return;
[email protected]b4b967e2009-04-22 11:33:05517 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
518 return;
[email protected]b6849bda2009-10-14 23:59:26519 if (notification_provider_->OnMessageReceived(message))
520 return;
[email protected]58c321d2010-02-19 12:11:28521 if (geolocation_dispatcher_.get() &&
522 geolocation_dispatcher_->OnMessageReceived(message)) {
523 return;
524 }
[email protected]b2abac72009-02-26 12:39:28525
initial.commit09911bf2008-07-26 23:55:29526 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29527 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23528 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29529 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01530 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29531 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
532 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56533 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29534 IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText)
initial.commit09911bf2008-07-26 23:55:29535 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
536 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
537 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
538 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27539#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35540 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27541#endif
initial.commit09911bf2008-07-26 23:55:29542 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
543 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05544 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
545 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
546 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04547 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29548 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
549 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
550 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15551 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29552 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49553 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
554 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17555 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]f85f0702010-01-30 09:31:01556 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost,
557 OnSetContentSettingsForLoadingHost)
[email protected]40bd6582009-12-04 23:49:51558 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
559 OnSetZoomLevelForLoadingHost)
initial.commit09911bf2008-07-26 23:55:29560 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18561 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
562 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28563 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33564 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29565 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48566 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29567 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29568 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29569 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
570 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
571 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
572 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
573 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45574 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29575 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50576 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
577 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29578 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
579 OnDragSourceSystemDragEnded)
580 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29581 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
582 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
583 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
584 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
585 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
586 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29587 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
588 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04589 IPC_MESSAGE_HANDLER(
590 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
591 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29592 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50593 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
594 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
595 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29596 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
597 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
598 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45599 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
600 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08601 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
602 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24603 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
604 OnAutoFillSuggestionsReturned)
[email protected]cf28ec52010-04-09 22:56:34605 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillForms, OnAutoFillForms)
[email protected]95056b582010-02-18 01:29:24606 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
607 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48608 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
609 OnAutoFillFormDataFilled)
[email protected]2c4410d2009-05-06 23:46:22610 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
611 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00612 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27613 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37614 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
615 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16616 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14617 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25618 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
619 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10620 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
621 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51622 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53623 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
624 OnUpdateBrowserWindowId)
625 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
626 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56627 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34628 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14629#if defined(OS_MACOSX)
630 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13631 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14632#endif
[email protected]446705872009-09-10 07:22:48633 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33634 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35635 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
636 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33637 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
638 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42639 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02640 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]634a6f92008-12-01 21:39:31641
initial.commit09911bf2008-07-26 23:55:29642 // Have the super handle all other messages.
643 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
644 IPC_END_MESSAGE_MAP()
645}
646
initial.commit09911bf2008-07-26 23:55:29647void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27648 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29649 if (!main_frame)
650 return;
651
652 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45653 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29654 if (url.is_empty())
655 return;
656
657 if (size_.IsEmpty())
658 return; // Don't create an empty thumbnail!
659
660 ThumbnailScore score;
661 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02662 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15663 &thumbnail, &score))
664 return;
665
initial.commit09911bf2008-07-26 23:55:29666 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46667 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29668}
669
[email protected]30507922010-01-15 16:48:23670void RenderView::SendSnapshot() {
671 SkBitmap snapshot;
672 bool error = false;
673
674 WebFrame* main_frame = webview()->mainFrame();
675 if (!main_frame)
676 error = true;
677
678 if (!error && !CaptureSnapshot(webview(), &snapshot))
679 error = true;
680
681 DCHECK(error == snapshot.empty()) <<
682 "Snapshot should be empty on error, non-empty otherwise.";
683
684 // Send the snapshot to the browser process.
685 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
686}
687
[email protected]068637222009-01-29 16:58:07688void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29689 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58690 if (webview()) {
691 // If the user has selected text in the currently focused frame we print
692 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27693 if (webview()->focusedFrame()->hasSelection())
694 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58695 else
[email protected]26aa0482009-09-30 16:55:27696 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58697 }
initial.commit09911bf2008-07-26 23:55:29698}
699
[email protected]82270452009-06-19 15:58:01700void RenderView::OnPrintingDone(int document_cookie, bool success) {
701 // Ignoring document cookie here since only one print job can be outstanding
702 // per renderer and document_cookie is 0 when printing is successful.
703 DCHECK(print_helper_.get());
704 if (print_helper_.get() != NULL) {
705 print_helper_->DidFinishPrinting(success);
706 }
707}
708
initial.commit09911bf2008-07-26 23:55:29709void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
710 if (load_id != page_id_)
711 return; // this capture call is no longer relevant due to navigation
712 if (load_id == last_indexed_page_id_)
713 return; // we already indexed this page
714
715 if (!webview())
716 return;
717
[email protected]26aa0482009-09-30 16:55:27718 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29719 if (!main_frame)
720 return;
721
722 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45723 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29724 return;
725
726 // Don't index/capture pages that failed to load. This only checks the top
727 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45728 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28729 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29730 return;
731
732 if (!preliminary_capture)
733 last_indexed_page_id_ = load_id;
734
[email protected]a8a81292010-01-21 00:32:45735 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45736 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29737 if (url.is_empty())
738 return;
739
[email protected]a8a81292010-01-21 00:32:45740 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29741 std::wstring contents;
742 CaptureText(main_frame, &contents);
743 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45744 base::TimeTicks begin_time = base::TimeTicks::Now();
745 std::string language = DetermineTextLanguage(contents);
746 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
747 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52748
[email protected]a8a81292010-01-21 00:32:45749 // Send the text to the browser for indexing (the browser might decide not
750 // to index, if the URL is HTTPS for instance) and language discovery.
751 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
752 language));
[email protected]5c4266922009-07-10 16:41:27753 }
754
initial.commit09911bf2008-07-26 23:55:29755 // thumbnail
756 SendThumbnail();
757}
758
759void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
760 contents->clear();
761 if (!frame)
762 return;
763
764#ifdef TIME_TEXT_RETRIEVAL
765 double begin = time_util::GetHighResolutionTimeNow();
766#endif
767
768 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45769 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29770
771#ifdef TIME_TEXT_RETRIEVAL
772 double end = time_util::GetHighResolutionTimeNow();
773 char buf[128];
774 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
775 contents.size(), (end - begin)*1000);
776 OutputDebugStringA(buf);
777#endif
778
779 // When the contents are clipped to the maximum, we don't want to have a
780 // partial word indexed at the end that might have been clipped. Therefore,
781 // terminate the string at the last space to ensure no words are clipped.
782 if (contents->size() == kMaxIndexChars) {
783 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
784 if (last_space_index == std::wstring::npos)
785 return; // don't index if we got a huge block of text with no spaces
786 contents->resize(last_space_index);
787 }
788}
789
[email protected]8649fb32009-06-26 17:51:02790bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29791 int w,
792 int h,
793 SkBitmap* thumbnail,
794 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23795 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15796
[email protected]8649fb32009-06-26 17:51:02797 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23798
799 // Paint |view| into |canvas|.
800 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02801 return false;
[email protected]8649fb32009-06-26 17:51:02802
803 skia::BitmapPlatformDevice& device =
804 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
805
806 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29807
[email protected]cab34d6a2009-09-24 01:14:52808 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29809 float dest_aspect = dest_rect.width() / dest_rect.height();
810
811 // Get the src rect so that we can preserve the aspect ratio while filling
812 // the destination.
813 SkIRect src_rect;
814 if (src_bmp.width() < dest_rect.width() ||
815 src_bmp.height() < dest_rect.height()) {
816 // Source image is smaller: we clip the part of source image within the
817 // dest rect, and then stretch it to fill the dest rect. We don't respect
818 // the aspect ratio in this case.
819 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
820 static_cast<S16CPU>(dest_rect.height()));
821 score->good_clipping = false;
822 } else {
823 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
824 if (src_aspect > dest_aspect) {
825 // Wider than tall, clip horizontally: we center the smaller thumbnail in
826 // the wider screen.
827 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
828 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
829 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
830 score->good_clipping = false;
831 } else {
832 src_rect.set(0, 0, src_bmp.width(),
833 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
834 score->good_clipping = true;
835 }
836 }
837
[email protected]26aa0482009-09-30 16:55:27838 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29839
840 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02841 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29842
843 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14844 *thumbnail = skia::ImageOperations::Resize(
845 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29846
847 score->boring_score = CalculateBoringScore(thumbnail);
848
[email protected]30507922010-01-15 16:48:23849 HISTOGRAM_TIMES("Renderer4.Thumbnail",
850 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15851 return true;
initial.commit09911bf2008-07-26 23:55:29852}
853
[email protected]30507922010-01-15 16:48:23854bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
855 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29856
[email protected]30507922010-01-15 16:48:23857 skia::PlatformCanvas canvas;
858 if (!PaintViewIntoCanvas(view, canvas))
859 return false;
860
861 skia::BitmapPlatformDevice& device =
862 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
863
864 const SkBitmap& bitmap = device.accessBitmap(false);
865 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
866 return false;
867
868 HISTOGRAM_TIMES("Renderer4.Snapshot",
869 base::TimeTicks::Now() - beginning_time);
870 return true;
initial.commit09911bf2008-07-26 23:55:29871}
872
873void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
874 if (!webview())
875 return;
876
[email protected]3cc72b12010-03-18 23:03:00877 history_list_offset_ = params.current_history_list_offset;
878 history_list_length_ = params.current_history_list_length;
879
[email protected]8c785c62009-07-13 14:20:15880 if (devtools_agent_.get())
881 devtools_agent_->OnNavigate();
882
[email protected]422197532010-01-25 17:38:23883 if (notification_provider_.get())
884 notification_provider_->OnNavigate();
885
[email protected]a9f607e2009-10-23 19:59:27886 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26887
initial.commit09911bf2008-07-26 23:55:29888 AboutHandler::MaybeHandle(params.url);
889
[email protected]ecbf10d2010-02-18 13:03:29890 bool is_reload =
891 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
892 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29893
[email protected]26aa0482009-09-30 16:55:27894 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45895 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29896 // We cannot reload if we do not have any history state. This happens, for
897 // example, when recovering from a crash. Our workaround here is a bit of
898 // a hack since it means that reload after a crashed tab does not cause an
899 // end-to-end cache validation.
900 is_reload = false;
901 }
902
[email protected]77f17a82009-05-21 04:42:54903 // A navigation resulting from loading a javascript URL should not be treated
904 // as a browser initiated event. Instead, we want it to look as if the page
905 // initiated any load resulting from JS execution.
906 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30907 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00908 params.page_id,
909 params.pending_history_list_offset,
910 params.transition,
911 params.request_time);
[email protected]5e369672009-11-03 23:48:30912 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
913 // We're doing a load of a page that was restored from the last session.
914 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
915 // which can result in stale data for pages that are set to expire. We
916 // explicitly override that by setting the policy here so that as
917 // necessary we load from the network.
918 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
919 }
920 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54921 }
initial.commit09911bf2008-07-26 23:55:29922
[email protected]a7ccc4d2010-01-27 08:14:48923 NavigationState* navigation_state = pending_navigation_state_.get();
924
[email protected]04d3c6e2009-05-22 17:00:13925 // If we are reloading, then WebKit will use the history state of the current
926 // page, so we should just ignore any given history state. Otherwise, if we
927 // have history state, then we need to navigate to it, which corresponds to a
928 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55929 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48930 if (navigation_state)
931 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29932 bool ignore_cache = (params.navigation_type ==
933 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
934 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55935 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13936 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58937 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48938 if (navigation_state)
939 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45940 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17941 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13942 } else {
943 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28944 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29945
[email protected]e6f546c32009-07-01 17:12:55946 // A session history navigation should have been accompanied by state.
947 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13948
[email protected]dd7daa82009-08-10 05:46:45949 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55950 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13951
[email protected]726985e22009-06-18 21:09:28952 if (params.referrer.is_valid()) {
953 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
954 WebString::fromUTF8(params.referrer.spec()));
955 }
[email protected]04d3c6e2009-05-22 17:00:13956
[email protected]a7ccc4d2010-01-27 08:14:48957 if (navigation_state)
958 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45959 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50960 }
961
[email protected]77f17a82009-05-21 04:42:54962 // In case LoadRequest failed before DidCreateDataSource was called.
963 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29964}
965
966// Stop loading the current page
967void RenderView::OnStop() {
968 if (webview())
[email protected]b4bb2502009-10-01 22:35:27969 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29970}
971
[email protected]ecbf10d2010-02-18 13:03:29972// Reload current focused frame.
973// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56974void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29975 if (webview() && webview()->focusedFrame()) {
976 // We always obey the cache (ignore_cache=false) here.
977 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
978 // a cache-ignoring reload of the frame.
979 webview()->focusedFrame()->reload(false);
980 }
[email protected]1dda4022010-01-28 18:24:56981}
982
[email protected]e6f546c32009-07-01 17:12:55983void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29984 bool new_navigation,
985 const GURL& display_url,
986 const std::string& security_info) {
987 if (!webview())
988 return;
989
[email protected]e6f546c32009-07-01 17:12:55990 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00991 new_navigation ? -1 : page_id_,
992 history_list_offset_,
993 PageTransition::LINK,
994 Time::Now()));
[email protected]e6f546c32009-07-01 17:12:55995 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29996
[email protected]26aa0482009-09-30 16:55:27997 webview()->mainFrame()->loadHTMLString(
998 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55999
1000 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291001}
1002
1003void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271004 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291005}
1006
[email protected]68b1e922009-06-23 16:00:251007void RenderView::OnExecuteEditCommand(const std::string& name,
1008 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271009 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251010 return;
1011
[email protected]26aa0482009-09-30 16:55:271012 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451013 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251014}
1015
[email protected]b2abac72009-02-26 12:39:281016void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111017 DCHECK(!devtools_client_.get());
1018 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281019}
1020
initial.commit09911bf2008-07-26 23:55:291021void RenderView::OnUpdateTargetURLAck() {
1022 // Check if there is a targeturl waiting to be sent.
1023 if (target_url_status_ == TARGET_PENDING) {
1024 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1025 pending_target_url_));
1026 }
1027
1028 target_url_status_ = TARGET_NONE;
1029}
1030
1031void RenderView::OnUndo() {
1032 if (!webview())
1033 return;
1034
[email protected]26aa0482009-09-30 16:55:271035 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121036 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291037}
1038
1039void RenderView::OnRedo() {
1040 if (!webview())
1041 return;
1042
[email protected]26aa0482009-09-30 16:55:271043 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121044 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291045}
1046
1047void RenderView::OnCut() {
1048 if (!webview())
1049 return;
1050
[email protected]26aa0482009-09-30 16:55:271051 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121052 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291053}
1054
1055void RenderView::OnCopy() {
1056 if (!webview())
1057 return;
1058
[email protected]26aa0482009-09-30 16:55:271059 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121060 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291061}
1062
[email protected]c0cc3092009-09-12 08:27:271063#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351064void RenderView::OnCopyToFindPboard() {
1065 if (!webview())
1066 return;
1067
1068 // Since the find pasteboard supports only plain text, this can be simpler
1069 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271070 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351071 if (frame->hasSelection()) {
1072 string16 selection = frame->selectionAsText();
1073 RenderThread::current()->Send(
1074 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1075 }
1076
[email protected]afe3a1672009-11-17 19:04:121077 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351078}
[email protected]c0cc3092009-09-12 08:27:271079#endif
[email protected]a954bf72009-09-12 07:30:351080
initial.commit09911bf2008-07-26 23:55:291081void RenderView::OnPaste() {
1082 if (!webview())
1083 return;
1084
[email protected]26aa0482009-09-30 16:55:271085 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121086 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291087}
1088
[email protected]2a3a7762009-10-19 19:17:321089void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291090 if (!webview())
1091 return;
1092
[email protected]1ff7a032010-02-03 02:46:031093 WebFrame* frame = webview()->focusedFrame();
1094 if (!frame->hasSelection())
1095 frame->selectWordAroundCaret();
1096 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291097}
1098
[email protected]98324892009-09-09 21:16:051099void RenderView::OnAdvanceToNextMisspelling() {
1100 if (!webview())
1101 return;
[email protected]26aa0482009-09-30 16:55:271102 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051103 WebString::fromUTF8("AdvanceToNextMisspelling"));
1104}
1105
1106void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1107 if (!webview())
1108 return;
1109 // We need to tell the webView whether the spelling panel is visible or not so
1110 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261111 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271112 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051113 WebString::fromUTF8("ToggleSpellPanel"));
1114}
1115
[email protected]bbbd545c2008-12-15 20:18:041116void RenderView::OnToggleSpellCheck() {
1117 if (!webview())
1118 return;
1119
[email protected]26aa0482009-09-30 16:55:271120 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451121 frame->enableContinuousSpellChecking(
1122 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041123}
1124
initial.commit09911bf2008-07-26 23:55:291125void RenderView::OnDelete() {
1126 if (!webview())
1127 return;
1128
[email protected]26aa0482009-09-30 16:55:271129 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121130 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291131}
1132
1133void RenderView::OnSelectAll() {
1134 if (!webview())
1135 return;
1136
[email protected]26aa0482009-09-30 16:55:271137 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221138 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121139 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291140}
1141
1142void RenderView::OnSetInitialFocus(bool reverse) {
1143 if (!webview())
1144 return;
[email protected]26aa0482009-09-30 16:55:271145 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291146}
1147
1148///////////////////////////////////////////////////////////////////////////////
1149
[email protected]433819d2010-01-30 20:20:011150void RenderView::SetContentSettings(const ContentSettings& settings) {
1151 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011152}
1153
initial.commit09911bf2008-07-26 23:55:291154// Tell the embedding application that the URL of the active page has changed
1155void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451156 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291157 DCHECK(ds);
1158
[email protected]726985e22009-06-18 21:09:281159 const WebURLRequest& request = ds->request();
1160 const WebURLRequest& original_request = ds->originalRequest();
1161 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291162
[email protected]daa8c58e2009-06-15 17:21:101163 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1164 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291165
1166 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281167 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291168 params.is_post = false;
1169 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281170 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551171 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291172 // SSL state specified in the request takes precedence over the one in the
1173 // response.
1174 // So far this is only intended for error pages that are not expected to be
1175 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281176 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551177 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291178 } else {
[email protected]726985e22009-06-18 21:09:281179 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291180 }
1181
1182 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281183 if (ds->hasUnreachableURL()) {
1184 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291185 } else {
[email protected]726985e22009-06-18 21:09:281186 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291187 }
1188
[email protected]726985e22009-06-18 21:09:281189 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241190 params.should_update_history = !ds->hasUnreachableURL() &&
1191 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291192
[email protected]ce0e250d2009-10-23 21:00:351193 params.searchable_form_url = navigation_state->searchable_form_url();
1194 params.searchable_form_encoding =
1195 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291196
1197 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101198 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291199 if (password_form_data)
1200 params.password_form = *password_form_data;
1201
1202 params.gesture = navigation_gesture_;
1203 navigation_gesture_ = NavigationGestureUnknown;
1204
[email protected]dd7daa82009-08-10 05:46:451205 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291206 // Top-level navigation.
1207
[email protected]71b0d5d2010-02-15 05:43:071208 // Clear "block" flags for the new page. This needs to happen before any of
1209 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1210 // so that these functions can correctly detect that a piece of content
1211 // flipped from "not blocked" to "blocked".
1212 ClearBlockedContentSettings();
1213
[email protected]62d2a112010-04-07 00:53:021214 // Set content settings. Default them from the parent window if one exists.
1215 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011216 HostContentSettings::iterator host_content_settings =
1217 host_content_settings_.find(GURL(request.url()).host());
1218 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011219 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011220
1221 // These content settings were merely recorded transiently for this load.
1222 // We can erase them now. If at some point we reload this page, the
1223 // browser will send us new, up-to-date content settings.
1224 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401225 } else if (frame->opener()) {
1226 WebView* opener_view = frame->opener()->view();
1227 RenderView* opener = FromWebView(opener_view);
1228 SetContentSettings(opener->current_content_settings_);
[email protected]f85f0702010-01-30 09:31:011229 }
1230
[email protected]40bd6582009-12-04 23:49:511231 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011232 HostZoomLevels::iterator host_zoom =
[email protected]40bd6582009-12-04 23:49:511233 host_zoom_levels_.find(GURL(request.url()).host());
[email protected]f85f0702010-01-30 09:31:011234 if (host_zoom != host_zoom_levels_.end()) {
1235 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511236 // This zoom level was merely recorded transiently for this load. We can
1237 // erase it now. If at some point we reload this page, the browser will
1238 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011239 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511240 }
1241
initial.commit09911bf2008-07-26 23:55:291242 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551243 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291244
[email protected]daa8c58e2009-06-15 17:21:101245 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291246 if (!PageTransition::IsMainFrame(params.transition)) {
1247 // If the main frame does a load, it should not be reported as a subframe
1248 // navigation. This can occur in the following case:
1249 // 1. You're on a site with frames.
1250 // 2. You do a subframe navigation. This is stored with transition type
1251 // MANUAL_SUBFRAME.
1252 // 3. You navigate to some non-frame site, say, google.com.
1253 // 4. You navigate back to the page from step 2. Since it was initially
1254 // MANUAL_SUBFRAME, it will be that same transition type here.
1255 // We don't want that, because any navigation that changes the toplevel
1256 // frame should be tracked as a toplevel navigation (this allows us to
1257 // update the URL bar, etc).
1258 params.transition = PageTransition::LINK;
1259 }
1260
initial.commit09911bf2008-07-26 23:55:291261 // If we have a valid consumed client redirect source,
1262 // the page contained a client redirect (meta refresh, document.loc...),
1263 // so we set the referrer and transition to match.
1264 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041265 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291266 params.referrer = completed_client_redirect_src_;
1267 params.transition = static_cast<PageTransition::Type>(
1268 params.transition | PageTransition::CLIENT_REDIRECT);
1269 } else {
1270 // Bug 654101: the referrer will be empty on https->http transitions. It
1271 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281272 params.referrer = GURL(
1273 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291274 }
1275
[email protected]726985e22009-06-18 21:09:281276 string16 method = request.httpMethod();
1277 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291278 params.is_post = true;
1279
[email protected]c2a797d2009-09-21 16:46:321280 // Save some histogram data so we can compute the average memory used per
1281 // page load of the glyphs.
1282 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1283 webkit_glue::GetGlyphPageCount());
1284
[email protected]15cf526b2010-02-12 06:33:491285 // This message needs to be sent before any of allowScripts(),
1286 // allowImages(), allowPlugins() is called for the new page, so that when
1287 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1288 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291289 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1290 } else {
1291 // Subframe navigation: the type depends on whether this navigation
1292 // generated a new session history entry. When they do generate a session
1293 // history entry, it means the user initiated the navigation and we should
1294 // mark it as such. This test checks if this is the first time UpdateURL
1295 // has been called since WillNavigateToURL was called to initiate the load.
1296 if (page_id_ > last_page_id_sent_to_browser_)
1297 params.transition = PageTransition::MANUAL_SUBFRAME;
1298 else
1299 params.transition = PageTransition::AUTO_SUBFRAME;
1300
initial.commit09911bf2008-07-26 23:55:291301 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1302 }
1303
1304 last_page_id_sent_to_browser_ =
1305 std::max(last_page_id_sent_to_browser_, page_id_);
1306
1307 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101308 // we don't want the transition type to persist. Just clear it.
1309 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501310
[email protected]6c8afae52009-01-22 02:24:571311#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151312 if (accessibility_.get()) {
[email protected]17455962010-02-24 01:39:351313 // Remove accessibility info cache.
1314 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501315 }
[email protected]6c8afae52009-01-22 02:24:571316#else
[email protected]7d926f92009-03-03 14:26:541317 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571318#endif
initial.commit09911bf2008-07-26 23:55:291319}
1320
1321// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171322void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291323 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171324 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171325 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171326 routing_id_,
1327 page_id_,
1328 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1329 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171330 }
initial.commit09911bf2008-07-26 23:55:291331}
1332
1333void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401334 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291335 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271336 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291337 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301338 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291339 last_encoding_name_ = encoding_name;
1340
[email protected]e38f40152008-09-12 23:08:301341 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291342 }
1343}
1344
[email protected]f4d34b52008-11-24 23:05:011345// Sends the previous session history state to the browser so it will be saved
1346// before we navigate to a new page. This must be called *before* the page ID
1347// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291348void RenderView::UpdateSessionHistory(WebFrame* frame) {
1349 // If we have a valid page ID at this point, then it corresponds to the page
1350 // we are navigating away from. Otherwise, this is the first navigation, so
1351 // there is no past session history to record.
1352 if (page_id_ == -1)
1353 return;
1354
[email protected]ca948a22009-06-25 19:36:171355 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271356 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171357 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291358 return;
[email protected]ca948a22009-06-25 19:36:171359
1360 Send(new ViewHostMsg_UpdateState(
1361 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291362}
1363
[email protected]3d9689372009-09-10 04:29:171364void RenderView::OpenURL(
1365 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1366 Send(new ViewHostMsg_OpenURL(
1367 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1368}
1369
[email protected]79dbc662009-09-04 05:42:511370// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291371
initial.commit09911bf2008-07-26 23:55:291372void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281373 const WebURLRequest& failed_request,
1374 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291375 const std::string& html,
1376 bool replace) {
[email protected]726985e22009-06-18 21:09:281377 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291378
1379 std::string alt_html;
1380 if (html.empty()) {
1381 // Use a local error page.
1382 int resource_id;
1383 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281384 if (error.reason == net::ERR_CACHE_MISS &&
1385 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291386 GetFormRepostErrorValues(failed_url, &error_strings);
1387 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1388 } else {
1389 GetLocalizedErrorValues(error, &error_strings);
1390 resource_id = IDR_NET_ERROR_HTML;
1391 }
initial.commit09911bf2008-07-26 23:55:291392
1393 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1394 } else {
1395 alt_html = html;
1396 }
1397
[email protected]dd7daa82009-08-10 05:46:451398 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551399 GURL(kUnreachableWebDataURL),
1400 failed_url,
1401 replace);
initial.commit09911bf2008-07-26 23:55:291402}
1403
[email protected]7ccddb8c2009-08-04 17:36:551404void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291405 dom_automation_controller_.set_message_sender(this);
1406 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551407 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291408 L"domAutomationController");
1409}
1410
initial.commit09911bf2008-07-26 23:55:291411bool RenderView::RunJavaScriptMessage(int type,
1412 const std::wstring& message,
1413 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071414 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291415 std::wstring* result) {
1416 bool success = false;
1417 std::wstring result_temp;
1418 if (!result)
1419 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291420
[email protected]12636df2009-09-28 22:32:211421 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1422 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291423 return success;
1424}
1425
[email protected]c1f50aa2010-02-18 03:46:571426bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1427 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1428 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1429 // it is particularly important that we do not call willEnterModalLoop as
1430 // that would defer resource loads for the dialog itself.
1431 if (RenderThread::current()) // Will be NULL during unit tests.
1432 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1433
1434 message->EnableMessagePumping(); // Runs a nested message loop.
1435 return Send(message);
1436}
1437
initial.commit09911bf2008-07-26 23:55:291438void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1439 if (!osd_url.is_empty())
1440 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1441 autodetected));
1442}
1443
[email protected]95056b582010-02-18 01:29:241444void RenderView::OnAutoFillSuggestionsReturned(
1445 int query_id,
[email protected]8f6e6582010-04-09 02:03:071446 const std::vector<string16>& values,
[email protected]95056b582010-02-18 01:29:241447 const std::vector<string16>& labels,
1448 int default_suggestion_index) {
1449 if (webview() && query_id == autofill_query_id_) {
1450 webview()->applyAutoFillSuggestions(
[email protected]8f6e6582010-04-09 02:03:071451 autofill_query_node_, values, labels, default_suggestion_index);
[email protected]95056b582010-02-18 01:29:241452 }
1453 autofill_query_node_.reset();
1454}
1455
[email protected]cf28ec52010-04-09 22:56:341456void RenderView::OnAutoFillForms(
1457 const std::vector<webkit_glue::FormData>& forms) {
1458 form_manager_.FillForms(forms);
1459}
1460
[email protected]95056b582010-02-18 01:29:241461void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a1f2009-10-16 03:53:391462 int query_id,
1463 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031464 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181465 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081466 webview()->applyAutocompleteSuggestions(
[email protected]acca2a1f2009-10-16 03:53:391467 autofill_query_node_, suggestions, default_suggestion_index);
1468 }
1469 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031470}
1471
[email protected]45c6e532010-03-15 23:51:241472void RenderView::OnAutoFillFormDataFilled(int query_id,
1473 const webkit_glue::FormData& form) {
[email protected]c83641732010-02-20 01:04:481474 if (query_id != autofill_query_id_)
1475 return;
1476
1477 form_manager_.FillForm(form);
1478}
1479
[email protected]2c4410d2009-05-06 23:46:221480void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311481 popup_notification_visible_ = visible;
1482}
1483
initial.commit09911bf2008-07-26 23:55:291484uint32 RenderView::GetCPBrowsingContext() {
1485 uint32 context = 0;
1486 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1487 return context;
1488}
1489
initial.commit09911bf2008-07-26 23:55:291490void RenderView::AddSearchProvider(const std::string& url) {
1491 AddGURLSearchProvider(GURL(url),
1492 false); // not autodetected
1493}
1494
[email protected]f103ab72009-09-02 17:10:591495void RenderView::OnMissingPluginStatus(
1496 WebPluginDelegateProxy* delegate,
1497 int status) {
[email protected]6c8afae52009-01-22 02:24:571498#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591499 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291500 // Show the InfoBar for the first available plugin.
1501 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591502 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291503 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1504 }
1505 } else {
1506 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1507 // to start the download/install.
1508 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1509 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1510 }
1511 }
[email protected]6c8afae52009-01-22 02:24:571512#else
1513 // TODO(port): plugins current not supported
1514 NOTIMPLEMENTED();
1515#endif
initial.commit09911bf2008-07-26 23:55:291516}
1517
[email protected]48c9cf2d2009-09-16 16:47:521518// WebKit::WebViewClient ------------------------------------------------------
1519
1520WebView* RenderView::createView(WebFrame* creator) {
1521 // Check to make sure we aren't overloading on popups.
1522 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1523 return NULL;
1524
1525 // This window can't be closed from a window.close() call until we receive a
1526 // message from the Browser process explicitly allowing it.
1527 popup_notification_visible_ = true;
1528
1529 int32 routing_id = MSG_ROUTING_NONE;
1530 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461531 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341532 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521533
[email protected]48c9cf2d2009-09-16 16:47:521534 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341535 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1536 session_storage_namespace_id_,
1537 &routing_id,
1538 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211539 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521540 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521541
[email protected]48c9cf2d2009-09-16 16:47:521542 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421543 0,
[email protected]12636df2009-09-28 22:32:211544 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521545 renderer_preferences_,
1546 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211547 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341548 routing_id,
1549 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521550 view->opened_by_user_gesture_ = user_gesture;
1551
[email protected]007a848b2009-10-26 15:55:461552 // Record whether the creator frame is trying to suppress the opener field.
1553 view->opener_suppressed_ = opener_suppressed;
1554
[email protected]48c9cf2d2009-09-16 16:47:521555 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091556 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521557 if (!creator_url.is_valid() || !creator_url.IsStandard())
1558 creator_url = GURL();
1559 view->creator_url_ = creator_url;
1560
1561 // Copy over the alternate error page URL so we can have alt error pages in
1562 // the new render view (we don't need the browser to send the URL back down).
1563 view->alternate_error_page_url_ = alternate_error_page_url_;
1564
1565 return view->webview();
1566}
1567
[email protected]3e2b375b2010-04-07 17:03:121568WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521569 RenderWidget* widget = RenderWidget::Create(routing_id_,
1570 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121571 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521572 return widget->webwidget();
1573}
1574
1575WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1576 RenderWidget* widget = RenderWidget::Create(routing_id_,
1577 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121578 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521579 widget->ConfigureAsExternalPopupMenu(info);
1580 return widget->webwidget();
1581}
1582
[email protected]bd92c3a2010-01-13 05:02:341583WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1584 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1585 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291586 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1587 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1588 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341589}
1590
[email protected]48c9cf2d2009-09-16 16:47:521591void RenderView::didAddMessageToConsole(
1592 const WebConsoleMessage& message, const WebString& source_name,
1593 unsigned source_line) {
1594 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1595 UTF16ToWideHack(message.text),
1596 static_cast<int32>(source_line),
1597 UTF16ToWideHack(source_name)));
1598}
1599
1600void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581601 DCHECK(frame);
1602 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521603}
1604
1605void RenderView::didStartLoading() {
1606 if (is_loading_) {
1607 DLOG(WARNING) << "didStartLoading called while loading";
1608 return;
1609 }
1610
1611 is_loading_ = true;
1612 // Clear the pointer so that we can assign it only when there is an unknown
1613 // plugin on a page.
1614 first_default_plugin_.reset();
1615
1616 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1617}
1618
1619void RenderView::didStopLoading() {
1620 if (!is_loading_) {
1621 DLOG(WARNING) << "DidStopLoading called while not loading";
1622 return;
1623 }
1624
1625 is_loading_ = false;
1626
1627 // NOTE: For now we're doing the safest thing, and sending out notification
1628 // when done loading. This currently isn't an issue as the favicon is only
1629 // displayed when done loading. Ideally we would send notification when
1630 // finished parsing the head, but webkit doesn't support that yet.
1631 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271632 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521633 if (!favicon_url.is_empty())
1634 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1635
[email protected]26aa0482009-09-30 16:55:271636 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521637 true); // autodetected
1638
1639 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1640
[email protected]f9f4841b2010-03-20 05:41:421641 MessageLoop::current()->PostDelayedTask(
1642 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521643 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1644 false),
1645 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521646}
1647
[email protected]f55039a2010-02-17 14:12:061648bool RenderView::isSmartInsertDeleteEnabled() {
1649#if defined(OS_MACOSX)
1650 return true;
1651#else
1652 return false;
1653#endif
1654}
1655
[email protected]04fc9482009-09-18 22:13:031656bool RenderView::isSelectTrailingWhitespaceEnabled() {
1657#if defined(OS_WIN)
1658 return true;
1659#else
1660 return false;
1661#endif
1662}
1663
1664void RenderView::setInputMethodEnabled(bool enabled) {
1665 // Save the updated IME status and mark the input focus has been updated.
1666 // The IME status is to be sent to a browser process next time when
1667 // the input caret is rendered.
1668 if (!ime_control_busy_) {
1669 ime_control_updated_ = true;
1670 ime_control_new_state_ = enabled;
1671 }
1672}
1673
1674void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031675#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031676 if (!handling_input_event_)
1677 return;
1678 // TODO(estade): investigate incremental updates to the selection so that we
1679 // don't send the entire selection over IPC every time.
1680 if (!is_empty_selection) {
1681 // Sometimes we get repeated didChangeSelection calls from webkit when
1682 // the selection hasn't actually changed. We don't want to report these
1683 // because it will cause us to continually claim the X clipboard.
1684 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271685 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031686 if (this_selection == last_selection_)
1687 return;
1688
1689 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1690 this_selection));
1691 last_selection_ = this_selection;
1692 } else {
1693 last_selection_.clear();
1694 }
1695#endif
1696}
1697
1698void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121699 const std::string& name = UTF16ToUTF8(command_name);
1700 if (StartsWithASCII(name, "Move", true) ||
1701 StartsWithASCII(name, "Insert", true) ||
1702 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031703 return;
1704 UserMetricsRecordAction(name);
1705}
1706
[email protected]b2528b72009-09-24 06:57:101707bool RenderView::handleCurrentKeyboardEvent() {
1708 if (edit_commands_.empty())
1709 return false;
1710
[email protected]26aa0482009-09-30 16:55:271711 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101712 if (!frame)
1713 return false;
1714
1715 EditCommands::iterator it = edit_commands_.begin();
1716 EditCommands::iterator end = edit_commands_.end();
1717
[email protected]507b33ea2009-09-29 03:56:511718 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101719 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331720 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1721 // key (but it's the exception). Once one edit command is not executed, it
1722 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101723 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1724 WebString::fromUTF8(it->value)))
1725 break;
[email protected]507b33ea2009-09-29 03:56:511726 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101727 }
1728
[email protected]507b33ea2009-09-29 03:56:511729 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101730}
1731
[email protected]2a3a7762009-10-19 19:17:321732void RenderView::spellCheck(const WebString& text,
1733 int& misspelled_offset,
1734 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561735 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461736
[email protected]85c55dc2009-11-06 03:05:461737 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171738 RenderThread* thread = RenderThread::current();
1739 // Will be NULL during unit tests.
1740 if (thread) {
[email protected]c27324b2009-11-19 22:44:291741 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171742 word.c_str(), word.size(), document_tag_,
1743 &misspelled_offset, &misspelled_length, NULL);
1744 }
[email protected]1dbafaf72009-09-23 19:43:561745}
1746
1747WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321748 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561749 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261750 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561751 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171752 RenderThread* thread = RenderThread::current();
1753 // Will be NULL during unit tests.
1754 if (thread) {
1755 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291756 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171757 word, document_tag_);
1758 }
[email protected]1dbafaf72009-09-23 19:43:561759 }
[email protected]2a3a7762009-10-19 19:17:321760 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561761}
1762
[email protected]c49085c72009-10-02 16:28:561763void RenderView::showSpellingUI(bool show) {
1764 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1765}
1766
[email protected]8922e1f2009-10-03 05:01:261767bool RenderView::isShowingSpellingUI() {
1768 return spelling_panel_visible_;
1769}
1770
[email protected]1dbafaf72009-09-23 19:43:561771void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321772 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1773 word));
[email protected]1dbafaf72009-09-23 19:43:561774}
1775
[email protected]a1128322009-10-06 18:38:461776bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351777 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471778 WebFileChooserCompletion* chooser_completion) {
1779 ViewHostMsg_RunFileChooser_Params ipc_params;
1780 ipc_params.mode = params.multiSelect ?
1781 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1782 ViewHostMsg_RunFileChooser_Params::Open;
1783 ipc_params.title = params.title;
1784 ipc_params.default_file_name =
1785 webkit_glue::WebStringToFilePath(params.initialValue);
1786
1787 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461788}
1789
[email protected]48c9cf2d2009-09-16 16:47:521790void RenderView::runModalAlertDialog(
1791 WebFrame* frame, const WebString& message) {
1792 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1793 UTF16ToWideHack(message),
1794 std::wstring(),
1795 frame->url(),
1796 NULL);
1797}
1798
1799bool RenderView::runModalConfirmDialog(
1800 WebFrame* frame, const WebString& message) {
1801 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1802 UTF16ToWideHack(message),
1803 std::wstring(),
1804 frame->url(),
1805 NULL);
1806}
1807
1808bool RenderView::runModalPromptDialog(
1809 WebFrame* frame, const WebString& message, const WebString& default_value,
1810 WebString* actual_value) {
1811 std::wstring result;
1812 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1813 UTF16ToWideHack(message),
1814 UTF16ToWideHack(default_value),
1815 frame->url(),
1816 &result);
1817 if (ok)
1818 actual_value->assign(WideToUTF16Hack(result));
1819 return ok;
1820}
1821
1822bool RenderView::runModalBeforeUnloadDialog(
1823 WebFrame* frame, const WebString& message) {
1824 bool success = false;
1825 // This is an ignored return value, but is included so we can accept the same
1826 // response as RunJavaScriptMessage.
1827 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211828 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521829 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211830 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521831 return success;
1832}
1833
[email protected]79e37442009-10-09 18:17:441834void RenderView::showContextMenu(
1835 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291836 ContextMenuParams params = ContextMenuParams(data);
1837 if (!params.misspelled_word.empty() && RenderThread::current()) {
1838 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041839 bool spelled_right = RenderThread::current()->spellchecker()->
1840 SpellCheckWord(
1841 params.misspelled_word.c_str(), params.misspelled_word.size(),
1842 document_tag_,
1843 &misspelled_offset, &misspelled_length,
1844 &params.dictionary_suggestions);
1845 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291846 params.misspelled_word.clear();
1847 }
1848
1849 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441850}
1851
[email protected]48c9cf2d2009-09-16 16:47:521852void RenderView::setStatusText(const WebString& text) {
1853}
1854
[email protected]163f8242009-10-30 20:19:551855void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1856 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521857 if (latest_url == target_url_)
1858 return;
[email protected]163f8242009-10-30 20:19:551859
[email protected]48c9cf2d2009-09-16 16:47:521860 // Tell the browser to display a destination link.
1861 if (target_url_status_ == TARGET_INFLIGHT ||
1862 target_url_status_ == TARGET_PENDING) {
1863 // If we have a request in-flight, save the URL to be sent when we
1864 // receive an ACK to the in-flight request. We can happily overwrite
1865 // any existing pending sends.
1866 pending_target_url_ = latest_url;
1867 target_url_status_ = TARGET_PENDING;
1868 } else {
1869 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1870 target_url_ = latest_url;
1871 target_url_status_ = TARGET_INFLIGHT;
1872 }
1873}
1874
[email protected]882daa92009-11-05 16:31:311875void RenderView::StartNavStateSyncTimerIfNecessary() {
1876 int delay;
1877 if (send_content_state_immediately_)
1878 delay = 0;
1879 else if (is_hidden())
1880 delay = kDelaySecondsForContentStateSyncHidden;
1881 else
1882 delay = kDelaySecondsForContentStateSync;
1883
1884 if (nav_state_sync_timer_.IsRunning()) {
1885 // The timer is already running. If the delay of the timer maches the amount
1886 // we want to delay by, then return. Otherwise stop the timer so that it
1887 // gets started with the right delay.
1888 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1889 return;
1890 nav_state_sync_timer_.Stop();
1891 }
1892
1893 nav_state_sync_timer_.Start(
1894 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1895}
1896
[email protected]163f8242009-10-30 20:19:551897void RenderView::setMouseOverURL(const WebURL& url) {
1898 mouse_over_url_ = GURL(url);
1899 UpdateTargetURL(mouse_over_url_, focus_url_);
1900}
1901
1902void RenderView::setKeyboardFocusURL(const WebURL& url) {
1903 focus_url_ = GURL(url);
1904 UpdateTargetURL(focus_url_, mouse_over_url_);
1905}
1906
[email protected]48c9cf2d2009-09-16 16:47:521907void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1908 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1909 hint));
1910}
1911
[email protected]49fd9da2010-03-17 21:00:471912void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1913 WebDragOperationsMask allowed_ops) {
[email protected]c27ae592010-03-18 15:24:411914 startDragging(data, allowed_ops, WebImage(), WebPoint());
1915}
1916
1917void RenderView::startDragging(const WebDragData& data,
1918 WebDragOperationsMask mask,
1919 const WebImage& image,
1920 const WebPoint& imageOffset) {
1921#if WEBKIT_USING_SKIA
1922 SkBitmap bitmap(image.getSkBitmap());
1923#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331924 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411925#endif
1926
[email protected]48c9cf2d2009-09-16 16:47:521927 Send(new ViewHostMsg_StartDragging(routing_id_,
1928 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411929 mask,
1930 bitmap,
1931 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521932}
1933
[email protected]28b92df2009-09-25 17:35:451934bool RenderView::acceptsLoadDrops() {
1935 return renderer_preferences_.can_accept_load_drops;
1936}
1937
[email protected]48c9cf2d2009-09-16 16:47:521938void RenderView::focusNext() {
1939 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1940}
1941
1942void RenderView::focusPrevious() {
1943 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1944}
1945
1946void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521947 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1948}
1949
1950int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001951 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521952}
1953
1954int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001955 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521956}
1957
[email protected]8922e1f2009-10-03 05:01:261958void RenderView::didUpdateInspectorSettings() {
1959 Send(new ViewHostMsg_UpdateInspectorSettings(
1960 routing_id_, webview()->inspectorSettings().utf8()));
1961}
1962
[email protected]acca2a1f2009-10-16 03:53:391963void RenderView::queryAutofillSuggestions(const WebNode& node,
1964 const WebString& name,
1965 const WebString& value) {
1966 static int query_counter = 0;
1967 autofill_query_id_ = query_counter++;
1968 autofill_query_node_ = node;
[email protected]e250e492010-04-06 21:35:361969
1970 const WebFormControlElement& element =
1971 node.toConstElement<WebFormControlElement>();
1972
[email protected]dede9342010-04-12 16:51:111973 webkit_glue::FormField field;
1974 FormManager::WebFormControlElementToFormField(element, true, &field);
[email protected]e250e492010-04-06 21:35:361975
[email protected]72eb2da2010-04-14 00:31:081976 // WebFormControlElementToFormField does not scrape the DOM for the field
1977 // label, so find the label here.
1978 // TODO(jhawkins): Add form and field identities so we can use the cached form
1979 // data in FormManager.
1980 field.set_label(FormManager::LabelForElement(element));
1981
[email protected]dede9342010-04-12 16:51:111982 Send(new ViewHostMsg_QueryFormFieldAutofill(
1983 routing_id_, autofill_query_id_, field));
[email protected]acca2a1f2009-10-16 03:53:391984}
1985
1986void RenderView::removeAutofillSuggestions(const WebString& name,
1987 const WebString& value) {
1988 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1989}
1990
[email protected]c83641732010-02-20 01:04:481991void RenderView::didAcceptAutoFillSuggestion(
1992 const WebKit::WebNode& node,
[email protected]8f6e6582010-04-09 02:03:071993 const WebKit::WebString& value,
[email protected]c83641732010-02-20 01:04:481994 const WebKit::WebString& label) {
1995 static int query_counter = 0;
1996 autofill_query_id_ = query_counter++;
1997
[email protected]45c6e532010-03-15 23:51:241998 webkit_glue::FormData form;
[email protected]e6efd022010-03-31 09:34:501999 const WebInputElement element = node.toConstElement<WebInputElement>();
[email protected]b1438212010-04-03 00:30:592000 if (!form_manager_.FindFormWithFormControlElement(
[email protected]da592272010-04-14 20:08:492001 element, FormManager::REQUIRE_NONE, &form))
[email protected]c83641732010-02-20 01:04:482002 return;
2003
2004 Send(new ViewHostMsg_FillAutoFillFormData(
[email protected]8f6e6582010-04-09 02:03:072005 routing_id_, autofill_query_id_, form, value, label));
[email protected]c83641732010-02-20 01:04:482006}
2007
[email protected]79dbc662009-09-04 05:42:512008// WebKit::WebWidgetClient ----------------------------------------------------
2009
initial.commit09911bf2008-07-26 23:55:292010// We are supposed to get a single call to Show for a newly created RenderView
2011// that was created via RenderView::CreateWebView. So, we wait until this
2012// point to dispatch the ShowView message.
2013//
2014// This method provides us with the information about how to display the newly
2015// created RenderView (i.e., as a constrained popup or as a new tab).
2016//
[email protected]4873c7d2009-07-16 06:36:282017void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292018 DCHECK(!did_show_) << "received extraneous Show call";
2019 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2020
2021 if (did_show_)
2022 return;
2023 did_show_ = true;
2024
[email protected]28295ec2009-10-16 05:34:332025 // Force new windows to a popup if they were not opened with a user gesture.
2026 if (!opened_by_user_gesture_) {
2027 // We exempt background tabs for compat with older versions of Chrome.
2028 // TODO(darin): This seems bogus. These should have a user gesture, so
2029 // we probably don't need this check.
2030 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2031 policy = WebKit::WebNavigationPolicyNewPopup;
2032 }
2033
initial.commit09911bf2008-07-26 23:55:292034 // NOTE: initial_pos_ may still have its default values at this point, but
2035 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2036 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282037 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2038 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292039 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242040 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292041}
2042
[email protected]4873c7d2009-07-16 06:36:282043void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222044 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282045 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312046}
2047
[email protected]4873c7d2009-07-16 06:36:282048void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292049 DCHECK(did_show_) << "should already have shown the view";
2050
[email protected]c1f50aa2010-02-18 03:46:572051 // We must keep WebKit's shared timer running in this case in order to allow
2052 // showModalDialog to function properly.
2053 //
2054 // TODO(darin): WebKit should really be smarter about suppressing events and
2055 // timers so that we do not need to manage the shared timer in such a heavy
2056 // handed manner.
2057 //
2058 if (RenderThread::current()) // Will be NULL during unit tests.
2059 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2060
[email protected]12636df2009-09-28 22:32:212061 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292062}
2063
[email protected]3d9689372009-09-10 04:29:172064// WebKit::WebFrameClient -----------------------------------------------------
2065
2066WebPlugin* RenderView::createPlugin(
2067 WebFrame* frame, const WebPluginParams& params) {
2068 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2069}
2070
2071WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2072 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
2073}
2074
[email protected]9c00f002009-11-05 22:37:422075WebSharedWorker* RenderView::createSharedWorker(
2076 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372077 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422078
[email protected]30447b62009-11-13 01:13:372079 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512080 bool exists = false;
[email protected]30447b62009-11-13 01:13:372081 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512082 ViewHostMsg_CreateWorker_Params params;
2083 params.url = url;
2084 params.is_shared = true;
2085 params.name = name;
2086 params.document_id = document_id;
2087 params.render_view_route_id = routing_id_;
2088 params.route_id = MSG_ROUTING_NONE;
[email protected]30447b62009-11-13 01:13:372089 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512090 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372091 if (url_mismatch) {
2092 return NULL;
2093 } else {
2094 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492095 document_id,
[email protected]6de0bcf2010-02-17 22:00:512096 exists,
[email protected]30447b62009-11-13 01:13:372097 route_id,
2098 routing_id_);
2099 }
[email protected]9c00f002009-11-05 22:37:422100}
2101
[email protected]3d9689372009-09-10 04:29:172102WebMediaPlayer* RenderView::createMediaPlayer(
2103 WebFrame* frame, WebMediaPlayerClient* client) {
2104 scoped_refptr<media::FilterFactoryCollection> factory =
2105 new media::FilterFactoryCollection();
2106 // Add in any custom filter factories first.
2107 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2108 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2109 // Add the chrome specific audio renderer.
2110 factory->AddFactory(
2111 AudioRendererImpl::CreateFactory(audio_message_filter()));
2112 }
2113
[email protected]80f584d92010-01-21 03:59:042114 WebApplicationCacheHostImpl* appcache_host =
2115 WebApplicationCacheHostImpl::FromFrame(frame);
2116
[email protected]3d9689372009-09-10 04:29:172117 // TODO(hclam): obtain the following parameters from |client|.
2118 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2119 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152120 GURL(), // referrer
2121 "null", // frame origin
2122 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172123 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042124 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172125 routing_id());
2126
[email protected]0436b9a2009-10-23 00:23:052127 // A simple data source that keeps all data in memory.
2128 media::FilterFactory* simple_data_source_factory =
2129 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2130 bridge_factory);
2131 // A sophisticated data source that does memory caching.
2132 media::FilterFactory* buffered_data_source_factory =
2133 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2134 bridge_factory);
2135 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2136 factory->AddFactory(simple_data_source_factory);
2137 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172138 } else {
[email protected]0436b9a2009-10-23 00:23:052139 factory->AddFactory(buffered_data_source_factory);
2140 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172141 }
[email protected]8400e032010-02-26 18:50:112142
2143 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2144 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2145 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2146 } else {
[email protected]b57509eb2010-03-30 01:26:282147 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2148 factory_factory =
2149 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112150 }
2151
2152 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172153}
2154
[email protected]035545f2010-04-09 13:10:212155WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2156 WebFrame* frame, WebApplicationCacheHostClient* client) {
2157 return new RendererWebApplicationCacheHostImpl(
2158 FromWebView(frame->view()), client,
2159 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2160}
2161
[email protected]b921cfd22010-02-25 16:57:512162WebCookieJar* RenderView::cookieJar() {
2163 return &cookie_jar_;
2164}
2165
[email protected]3d9689372009-09-10 04:29:172166void RenderView::willClose(WebFrame* frame) {
2167 if (!frame->parent()) {
2168 const GURL& url = frame->url();
2169 if (url.SchemeIs("http") || url.SchemeIs("https"))
2170 DumpLoadHistograms();
2171 }
[email protected]fa7b6b542009-11-03 05:02:302172
2173 WebDataSource* ds = frame->dataSource();
2174 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2175 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172176}
2177
[email protected]684e4a42010-01-30 06:44:112178bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002179 if (!enabled_per_settings)
2180 return false;
[email protected]c21f1d52010-03-04 03:19:432181 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112182}
2183
2184bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002185 if (!enabled_per_settings)
2186 return false;
2187 if (!AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) {
2188 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2189 return false;
2190 }
2191 return true;
[email protected]684e4a42010-01-30 06:44:112192}
2193
[email protected]3d9689372009-09-10 04:29:172194void RenderView::loadURLExternally(
2195 WebFrame* frame, const WebURLRequest& request,
2196 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592197 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2198 if (policy == WebKit::WebNavigationPolicyDownload) {
2199 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2200 } else {
2201 OpenURL(request.url(), referrer, policy);
2202 }
[email protected]3d9689372009-09-10 04:29:172203}
2204
2205WebNavigationPolicy RenderView::decidePolicyForNavigation(
2206 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222207 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172208 // Webkit is asking whether to navigate to a new URL.
2209 // This is fine normally, except if we're showing UI from one security
2210 // context and they're trying to navigate to a different context.
2211 const GURL& url = request.url();
2212
2213 // If the browser is interested, then give it a chance to look at top level
2214 // navigations
[email protected]61c9f032010-03-31 23:04:192215 if (ShouldRouteNavigationToBrowser(url, frame, type)) {
2216 last_top_level_navigation_page_id_ = page_id_;
2217 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2218 OpenURL(url, referrer, default_policy);
2219 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172220 }
2221
2222 // A content initiated navigation may have originated from a link-click,
2223 // script, drag-n-drop operation, etc.
2224 bool is_content_initiated =
2225 NavigationState::FromDataSource(frame->provisionalDataSource())->
2226 is_content_initiated();
2227
2228 // We only care about navigations that are within the current tab (as opposed
2229 // to, for example, opening a new window).
2230 // But we sometimes navigate to about:blank to clear a tab, and we want to
2231 // still allow that.
2232 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2233 is_content_initiated && frame->parent() == NULL &&
2234 !url.SchemeIs(chrome::kAboutScheme)) {
2235 // When we received such unsolicited navigations, we sometimes want to
2236 // punt them up to the browser to handle.
2237 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2238 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2239 frame->isViewSourceModeEnabled() ||
2240 url.SchemeIs(chrome::kViewSourceScheme) ||
2241 url.SchemeIs(chrome::kPrintScheme)) {
2242 OpenURL(url, GURL(), default_policy);
2243 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2244 }
2245 }
2246
2247 // Detect when a page is "forking" a new tab that can be safely rendered in
2248 // its own process. This is done by sites like Gmail that try to open links
2249 // in new windows without script connections back to the original page. We
2250 // treat such cases as browser navigations (in which we will create a new
2251 // renderer for a cross-site navigation), rather than WebKit navigations.
2252 //
2253 // We use the following heuristic to decide whether to fork a new page in its
2254 // own process:
2255 // The parent page must open a new tab to about:blank, set the new tab's
2256 // window.opener to null, and then redirect the tab to a cross-site URL using
2257 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462258 //
2259 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2260 // (see below).
[email protected]3d9689372009-09-10 04:29:172261 bool is_fork =
2262 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252263 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172264 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522265 historyBackListCount() < 1 &&
2266 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172267 // The parent page must have set the child's window.opener to null before
2268 // redirecting to the desired URL.
2269 frame->opener() == NULL &&
2270 // Must be a top-level frame.
2271 frame->parent() == NULL &&
2272 // Must not have issued the request from this page.
2273 is_content_initiated &&
2274 // Must be targeted at the current tab.
2275 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2276 // Must be a JavaScript navigation, which appears as "other".
2277 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462278
2279 // Recognize if this navigation is from a link with rel=noreferrer and
2280 // target=_blank attributes, in which case the opener will be suppressed. If
2281 // so, it is safe to load cross-site pages in a separate process, so we
2282 // should let the browser handle it.
2283 bool is_noreferrer_and_blank_target =
2284 // Frame should be top level and not yet navigated.
2285 frame->parent() == NULL &&
2286 frame->url().isEmpty() &&
2287 historyBackListCount() < 1 &&
2288 historyForwardListCount() < 1 &&
2289 // Links with rel=noreferrer will have no Referer field, and their
2290 // resulting frame will have its window.opener suppressed.
2291 // TODO(creis): should add a request.httpReferrer() method to help avoid
2292 // typos on the unusual spelling of Referer.
2293 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2294 opener_suppressed_ &&
2295 frame->opener() == NULL &&
2296 // Links with target=_blank will have no name.
2297 frame->name().isNull() &&
2298 // Another frame (with a non-empty creator) should have initiated the
2299 // request, targeted at this frame.
2300 !creator_url_.is_empty() &&
2301 is_content_initiated &&
2302 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2303 type == WebKit::WebNavigationTypeOther;
2304
2305 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172306 // Open the URL via the browser, not via WebKit.
2307 OpenURL(url, GURL(), default_policy);
2308 return WebKit::WebNavigationPolicyIgnore;
2309 }
2310
2311 return default_policy;
2312}
2313
[email protected]6069da8c2009-10-20 20:33:492314bool RenderView::canHandleRequest(
2315 WebFrame* frame, const WebURLRequest& request) {
2316 // We allow WebKit to think that everything can be handled even though
2317 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342318 return true;
2319}
2320
[email protected]6069da8c2009-10-20 20:33:492321WebURLError RenderView::cannotHandleRequestError(
2322 WebFrame* frame, const WebURLRequest& request) {
2323 NOTREACHED(); // Since we said we can handle all requests.
2324 return WebURLError();
2325}
2326
2327WebURLError RenderView::cancelledError(
2328 WebFrame* frame, const WebURLRequest& request) {
2329 WebURLError error;
2330 error.domain = WebString::fromUTF8(net::kErrorDomain);
2331 error.reason = net::ERR_ABORTED;
2332 error.unreachableURL = request.url();
2333 return error;
[email protected]7b7a7dc2009-10-19 02:23:342334}
2335
2336void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492337 WebFrame*, const WebURLError&) {
2338 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342339}
2340
[email protected]979c28b2009-11-07 01:30:482341void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172342 NavigationState* navigation_state =
2343 NavigationState::FromDataSource(frame->provisionalDataSource());
2344
2345 if (navigation_state->transition_type() == PageTransition::LINK)
2346 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2347
2348 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352349 WebSearchableFormData web_searchable_form_data(form);
2350 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2351 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212352 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172353 navigation_state->set_password_form_data(
2354 PasswordFormDomManager::CreatePasswordForm(form));
2355
[email protected]b1438212010-04-03 00:30:592356 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042357 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092358 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592359 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172360}
2361
2362void RenderView::willPerformClientRedirect(
2363 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2364 double fire_time) {
2365 // Ignore
2366}
2367
2368void RenderView::didCancelClientRedirect(WebFrame* frame) {
2369 // Ignore
2370}
2371
2372void RenderView::didCompleteClientRedirect(
2373 WebFrame* frame, const WebURL& from) {
2374 if (!frame->parent())
2375 completed_client_redirect_src_ = from;
2376}
2377
2378void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2379 // The rest of RenderView assumes that a WebDataSource will always have a
2380 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482381 bool content_initiated = !pending_navigation_state_.get();
2382 NavigationState* state = content_initiated ?
2383 NavigationState::CreateContentInitiated() :
2384 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182385 if (content_initiated) {
2386 switch (ds->request().cachePolicy()) {
2387 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2388 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2389 break;
2390 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2391 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2392 break;
2393 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2394 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2395 break;
2396 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2397 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2398 break;
2399 }
2400 }
[email protected]fa7b6b542009-11-03 05:02:302401
2402 state->set_user_script_idle_scheduler(
2403 new UserScriptIdleScheduler(this, frame));
2404 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172405}
2406
2407void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2408 WebDataSource* ds = frame->provisionalDataSource();
2409 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2410
2411 navigation_state->set_start_load_time(Time::Now());
2412
2413 // Update the request time if WebKit has better knowledge of it.
2414 if (navigation_state->request_time().is_null()) {
2415 double event_time = ds->triggeringEventTime();
2416 if (event_time != 0.0)
2417 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2418 }
2419
2420 bool is_top_most = !frame->parent();
2421 if (is_top_most) {
2422 navigation_gesture_ = frame->isProcessingUserGesture() ?
2423 NavigationGestureUnknown : NavigationGestureAuto;
2424
2425 // Make sure redirect tracking state is clear for the new load.
2426 completed_client_redirect_src_ = GURL();
2427 } else if (frame->parent()->isLoading()) {
2428 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002429 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172430 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2431 }
2432
2433 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2434 routing_id_, is_top_most, ds->request().url()));
2435}
2436
2437void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2438 if (frame->parent())
2439 return;
2440 // Received a redirect on the main frame.
2441 WebDataSource* data_source = frame->provisionalDataSource();
2442 if (!data_source) {
2443 // Should only be invoked when we have a data source.
2444 NOTREACHED();
2445 return;
2446 }
2447 std::vector<GURL> redirects;
2448 GetRedirectChain(data_source, &redirects);
2449 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512450 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2451 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172452 }
2453}
2454
[email protected]40bd6582009-12-04 23:49:512455void RenderView::didFailProvisionalLoad(WebFrame* frame,
2456 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172457 // Notify the browser that we failed a provisional load with an error.
2458 //
2459 // Note: It is important this notification occur before DidStopLoading so the
2460 // SSL manager can react to the provisional load failure before being
2461 // notified the load stopped.
2462 //
2463 WebDataSource* ds = frame->provisionalDataSource();
2464 DCHECK(ds);
2465
2466 const WebURLRequest& failed_request = ds->request();
2467
2468 bool show_repost_interstitial =
2469 (error.reason == net::ERR_CACHE_MISS &&
2470 EqualsASCII(failed_request.httpMethod(), "POST"));
2471 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2472 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2473 show_repost_interstitial));
2474
2475 // Don't display an error page if this is simply a cancelled load. Aside
2476 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2477 if (error.reason == net::ERR_ABORTED)
2478 return;
2479
2480 // Make sure we never show errors in view source mode.
2481 frame->enableViewSourceMode(false);
2482
2483 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2484
2485 // If this is a failed back/forward/reload navigation, then we need to do a
2486 // 'replace' load. This is necessary to avoid messing up session history.
2487 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2488 // as session history is concerned.
2489 //
2490 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2491 // the page id.
2492 //
2493 bool replace =
2494 navigation_state->pending_page_id() != -1 ||
2495 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2496
2497 // If we failed on a browser initiated request, then make sure that our error
2498 // page load is regarded as the same browser initiated request.
2499 if (!navigation_state->is_content_initiated()) {
2500 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2501 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002502 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172503 navigation_state->transition_type(),
2504 navigation_state->request_time()));
2505 }
2506
2507 // Provide the user with a more helpful error page?
2508 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2509 return;
2510
2511 // Fallback to a local error page.
2512 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2513 replace);
2514}
2515
2516void RenderView::didReceiveDocumentData(
2517 WebFrame* frame, const char* data, size_t data_len,
2518 bool& prevent_default) {
2519 NavigationState* navigation_state =
2520 NavigationState::FromDataSource(frame->dataSource());
2521 if (!navigation_state->postpone_loading_data())
2522 return;
2523
2524 // We're going to call commitDocumentData ourselves...
2525 prevent_default = true;
2526
2527 // Continue buffering the response data for the original 404 page. If it
2528 // grows too large, then we'll just let it through.
2529 navigation_state->append_postponed_data(data, data_len);
2530 if (navigation_state->postponed_data().size() >= 512) {
2531 navigation_state->set_postpone_loading_data(false);
2532 frame->commitDocumentData(navigation_state->postponed_data().data(),
2533 navigation_state->postponed_data().size());
2534 navigation_state->clear_postponed_data();
2535 }
2536}
2537
[email protected]40bd6582009-12-04 23:49:512538void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2539 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172540 NavigationState* navigation_state =
2541 NavigationState::FromDataSource(frame->dataSource());
2542
2543 navigation_state->set_commit_load_time(Time::Now());
2544 if (is_new_navigation) {
2545 // When we perform a new navigation, we need to update the previous session
2546 // history entry with state for the page we are leaving.
2547 UpdateSessionHistory(frame);
2548
2549 // We bump our Page ID to correspond with the new session history entry.
2550 page_id_ = next_page_id_++;
2551
[email protected]3cc72b12010-03-18 23:03:002552 // Advance our offset in session history, applying the length limit. There
2553 // is now no forward history.
2554 history_list_offset_++;
2555 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2556 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2557 history_list_length_ = history_list_offset_ + 1;
2558
[email protected]f9f4841b2010-03-20 05:41:422559 MessageLoop::current()->PostDelayedTask(
2560 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172561 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2562 page_id_, true),
2563 kDelayForForcedCaptureMs);
2564 } else {
2565 // Inspect the navigation_state on this frame to see if the navigation
2566 // corresponds to a session history navigation... Note: |frame| may or
2567 // may not be the toplevel frame, but for the case of capturing session
2568 // history, the first committed frame suffices. We keep track of whether
2569 // we've seen this commit before so that only capture session history once
2570 // per navigation.
2571 //
2572 // Note that we need to check if the page ID changed. In the case of a
2573 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2574 // previous URL and the current page ID, which would be wrong.
2575 if (navigation_state->pending_page_id() != -1 &&
2576 navigation_state->pending_page_id() != page_id_ &&
2577 !navigation_state->request_committed()) {
2578 // This is a successful session history navigation!
2579 UpdateSessionHistory(frame);
2580 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002581
2582 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172583 }
2584 }
2585
2586 // Remember that we've already processed this request, so we don't update
2587 // the session history again. We do this regardless of whether this is
2588 // a session history navigation, because if we attempted a session history
2589 // navigation without valid HistoryItem state, WebCore will think it is a
2590 // new navigation.
2591 navigation_state->set_request_committed(true);
2592
2593 UpdateURL(frame);
2594
2595 // If this committed load was initiated by a client redirect, we're
2596 // at the last stop now, so clear it.
2597 completed_client_redirect_src_ = GURL();
2598
2599 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272600 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172601}
2602
2603void RenderView::didClearWindowObject(WebFrame* frame) {
2604 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2605 BindDOMAutomationController(frame);
2606 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2607 dom_ui_bindings_.set_message_sender(this);
2608 dom_ui_bindings_.set_routing_id(routing_id_);
2609 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2610 }
2611 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2612 external_host_bindings_.set_message_sender(this);
2613 external_host_bindings_.set_routing_id(routing_id_);
2614 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2615 }
2616}
2617
2618void RenderView::didCreateDocumentElement(WebFrame* frame) {
2619 if (RenderThread::current()) { // Will be NULL during unit tests.
2620 RenderThread::current()->user_script_slave()->InjectScripts(
2621 frame, UserScript::DOCUMENT_START);
2622 }
[email protected]078b34612009-09-19 19:31:512623 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2624 view_type_ == ViewType::EXTENSION_MOLE) {
2625 InjectToolstripCSS();
2626 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2627 }
[email protected]3d9689372009-09-10 04:29:172628
2629 // Notify the browser about non-blank documents loading in the top frame.
2630 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252631 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272632 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172633 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2634 }
2635}
2636
2637void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2638 UpdateTitle(frame, title);
2639
2640 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272641 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172642}
2643
2644void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2645 WebDataSource* ds = frame->dataSource();
2646 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2647 DCHECK(navigation_state);
2648 navigation_state->set_finish_document_load_time(Time::Now());
2649
2650 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2651
[email protected]e9e07992010-02-17 21:04:362652 // The document has now been fully loaded. Scan for forms to be sent up to
2653 // the browser.
2654 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482655 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362656 SendForms(frame);
[email protected]3d9689372009-09-10 04:29:172657 SendPasswordForms(frame);
2658
2659 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272660 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172661
2662 if (RenderThread::current()) { // Will be NULL during unit tests.
2663 RenderThread::current()->user_script_slave()->InjectScripts(
2664 frame, UserScript::DOCUMENT_END);
2665 }
[email protected]fa7b6b542009-11-03 05:02:302666
2667 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2668}
2669
2670void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2671 if (RenderThread::current()) { // Will be NULL during unit tests.
2672 RenderThread::current()->user_script_slave()->InjectScripts(
2673 frame, UserScript::DOCUMENT_IDLE);
2674 }
2675
2676 WebFrame* main_frame = webview()->mainFrame();
2677 if (frame == main_frame) {
2678 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202679 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302680 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202681 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302682 pending_code_execution_queue_.pop();
2683 }
2684 }
[email protected]3d9689372009-09-10 04:29:172685}
2686
2687void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2688 // Ignore
2689}
2690
2691void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2692 // Ignore
2693}
2694
2695void RenderView::didFinishLoad(WebFrame* frame) {
2696 WebDataSource* ds = frame->dataSource();
2697 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2698 DCHECK(navigation_state);
2699 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302700 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172701}
2702
[email protected]ccbe04e2010-03-17 17:58:432703void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172704 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062705
2706 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2707 // since a new one gets created by didCreateDataSource.
2708 NavigationState* state =
2709 NavigationState::FromDataSource(frame->dataSource());
2710 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2711
[email protected]3d9689372009-09-10 04:29:172712 // If this was a reference fragment navigation that we initiated, then we
2713 // could end up having a non-null pending navigation state. We just need to
2714 // update the ExtraData on the datasource so that others who read the
2715 // ExtraData will get the new NavigationState. Similarly, if we did not
2716 // initiate this navigation, then we need to take care to reset any pre-
2717 // existing navigation state to a content-initiated navigation state.
2718 // DidCreateDataSource conveniently takes care of this for us.
2719 didCreateDataSource(frame, frame->dataSource());
2720
[email protected]f6c2459d2010-02-24 22:34:062721 if (idle_scheduler_ran) {
2722 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2723 NavigationState* new_state =
2724 NavigationState::FromDataSource(frame->dataSource());
2725 new_state->user_script_idle_scheduler()->set_has_run(true);
2726 }
2727
[email protected]3d9689372009-09-10 04:29:172728 didCommitProvisionalLoad(frame, is_new_navigation);
2729
[email protected]26aa0482009-09-30 16:55:272730 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172731}
2732
[email protected]476b6f82009-09-10 21:00:592733void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312734 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592735}
2736
[email protected]3d9689372009-09-10 04:29:172737void RenderView::assignIdentifierToRequest(
2738 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2739 // Ignore
2740}
2741
[email protected]fa0a3432010-03-30 16:53:492742// Used in logMimeTypeForCrossOriginRequest(), remove when that function
2743// is removed
2744typedef base::hash_map<unsigned, WebURLRequest::TargetType> TargetTypeMap;
2745static TargetTypeMap target_type_map_;
2746typedef base::hash_map<std::string, int> MimeTypeMap;
2747static MimeTypeMap mime_type_map_;
2748
2749// Copied from net/base/mime_util.cc, supported_non_image_types[]
2750static const char* const cross_origin_mime_types_to_log[] = {
2751 "text/cache-manifest",
2752 "text/html",
2753 "text/xml",
2754 "text/xsl",
2755 "text/plain",
2756 "text/vnd.chromium.ftp-dir",
2757 "text/",
2758 "text/css",
2759 "image/svg+xml",
2760 "application/xml",
2761 "application/xhtml+xml",
2762 "application/rss+xml",
2763 "application/atom+xml",
2764 "application/json",
2765 "application/x-x509-user-cert",
2766 "multipart/x-mixed-replace"
2767};
2768
2769static void initMimeTypeMapIfNeeded() {
2770 if (!mime_type_map_.size()) {
2771 for (size_t i = 0; i < arraysize(cross_origin_mime_types_to_log); ++i)
2772 mime_type_map_[cross_origin_mime_types_to_log[i]] = i;
2773 }
2774}
2775
2776static void logMimeTypeForCrossOriginRequest(
2777 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
2778 initMimeTypeMapIfNeeded();
2779
2780 // Metrics to check the feasability of blocking cross-site requests
2781 // a renderer shouldn't be making (in case we try to move cross-site frames
2782 // into their own process someday). We're erring on the side of counting more
2783 // mime-types then we strictly need (we'd only consider blocking cross-site
2784 // requests with types similar to HTML, XML, or JSON).
2785 // TODO(japhet): Make these more granular. We're ignoring all miscellaneous
2786 // subresource requests, not just the XHRs that might be allowed.
2787 // Also, we should make these metrics be based on something more accurate
2788 // than the mime type header, such as parsing or content sniffing.
2789 TargetTypeMap::iterator iter = target_type_map_.find(identifier);
2790 if (iter != target_type_map_.end()) {
2791 WebURLRequest::TargetType target_type = iter->second;
2792 target_type_map_.erase(iter);
2793 if (target_type != WebURLRequest::TargetIsMainFrame
2794 && target_type != WebURLRequest::TargetIsSubFrame
2795 && target_type != WebURLRequest::TargetIsSubResource
2796 && target_type != WebURLRequest::TargetIsObject
2797 && !frame->securityOrigin().canAccess(
2798 WebSecurityOrigin::create(response.url()))) {
2799 std::string mime_type = response.mimeType().utf8();
2800 MimeTypeMap::iterator mime_type_iter = mime_type_map_.find(mime_type);
2801 if (mime_type_iter != mime_type_map_.end()) {
2802 UMA_HISTOGRAM_ENUMERATION(
2803 "SiteIsolation.CrossSiteNonFrameResponse_MIME_Type",
2804 mime_type_iter->second, arraysize(cross_origin_mime_types_to_log));
2805 }
2806 }
2807 }
2808}
2809
[email protected]3d9689372009-09-10 04:29:172810void RenderView::willSendRequest(
2811 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2812 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302813 WebFrame* top_frame = frame->top();
2814 if (!top_frame)
2815 top_frame = frame;
2816 WebDataSource* data_source = top_frame->provisionalDataSource();
2817 if (!data_source)
2818 data_source = top_frame->dataSource();
2819 if (data_source) {
2820 NavigationState* state = NavigationState::FromDataSource(data_source);
2821 if (state && state->is_cache_policy_override_set())
2822 request.setCachePolicy(state->cache_policy_override());
2823 }
[email protected]3d9689372009-09-10 04:29:172824 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502825 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132826 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492827
2828 target_type_map_[identifier] = request.targetType();
[email protected]3d9689372009-09-10 04:29:172829}
2830
2831void RenderView::didReceiveResponse(
2832 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492833
2834 logMimeTypeForCrossOriginRequest(frame, identifier, response);
2835
[email protected]3d9689372009-09-10 04:29:172836 // Only do this for responses that correspond to a provisional data source
2837 // of the top-most frame. If we have a provisional data source, then we
2838 // can't have any sub-resources yet, so we know that this response must
2839 // correspond to a frame load.
2840 if (!frame->provisionalDataSource() || frame->parent())
2841 return;
2842
2843 // If we are in view source mode, then just let the user see the source of
2844 // the server's 404 error page.
2845 if (frame->isViewSourceModeEnabled())
2846 return;
2847
[email protected]f48013be2010-01-14 22:07:452848 // Record that this was a page loaded over SPDY.
2849 if (response.wasFetchedViaSPDY()) {
2850 NavigationState* navigation_state =
2851 NavigationState::FromDataSource(frame->provisionalDataSource());
2852 navigation_state->set_was_fetched_via_spdy(true);
2853 }
2854
2855 // Consider loading an alternate error page for 404 responses.
2856 if (response.httpStatusCode() != 404)
2857 return;
2858
[email protected]3d9689372009-09-10 04:29:172859 // Can we even load an alternate error page for this URL?
2860 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2861 return;
2862
2863 NavigationState* navigation_state =
2864 NavigationState::FromDataSource(frame->provisionalDataSource());
2865 navigation_state->set_postpone_loading_data(true);
2866 navigation_state->clear_postponed_data();
2867}
2868
2869void RenderView::didFinishResourceLoad(
2870 WebFrame* frame, unsigned identifier) {
2871 NavigationState* navigation_state =
2872 NavigationState::FromDataSource(frame->dataSource());
2873 if (!navigation_state->postpone_loading_data())
2874 return;
2875
2876 // The server returned a 404 and the content was < 512 bytes (which we
2877 // suppressed). Go ahead and fetch the alternate page content.
2878
2879 const GURL& frame_url = frame->url();
2880
2881 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2882 DCHECK(error_page_url.is_valid());
2883
2884 WebURLError original_error;
2885 original_error.unreachableURL = frame_url;
2886
2887 navigation_state->set_alt_error_page_fetcher(
2888 new AltErrorPageResourceFetcher(
2889 error_page_url, frame, original_error,
2890 NewCallback(this, &RenderView::AltErrorPageFinished)));
2891}
2892
2893void RenderView::didFailResourceLoad(
2894 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2895 // Ignore
2896}
2897
2898void RenderView::didLoadResourceFromMemoryCache(
2899 WebFrame* frame, const WebURLRequest& request,
2900 const WebURLResponse& response) {
2901 // Let the browser know we loaded a resource from the memory cache. This
2902 // message is needed to display the correct SSL indicators.
2903 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2904 routing_id_,
2905 request.url(),
[email protected]91733b62009-09-18 06:21:092906 frame->securityOrigin().toString().utf8(),
2907 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172908 response.securityInfo()));
2909}
2910
[email protected]6069da8c2009-10-20 20:33:492911void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292912 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2913}
2914
2915void RenderView::didRunInsecureContent(
2916 WebFrame* frame, const WebSecurityOrigin& origin) {
2917 Send(new ViewHostMsg_DidRunInsecureContent(
2918 routing_id_,
2919 origin.toString().utf8()));
2920}
2921
[email protected]7ea093ba2009-11-03 05:54:592922bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002923 if (enabled_per_settings)
2924 return AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
[email protected]7ea093ba2009-11-03 05:54:592925
2926 WebSecurityOrigin origin = frame->securityOrigin();
2927 if (origin.isEmpty())
2928 return false; // Uninitialized document?
2929
2930 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2931 return true; // Browser UI elements should still work.
2932
2933 // If the scheme is ftp: or file:, an empty file name indicates a directory
2934 // listing, which requires JavaScript to function properly.
2935 GURL frame_url = frame->url();
2936 const char* kDirProtocols[] = { "ftp", "file" };
2937 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2938 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2939 return frame_url.SchemeIs(kDirProtocols[i]) &&
2940 frame_url.ExtractFileName().empty();
2941 }
2942 }
2943
2944 return false; // Other protocols fall through here.
2945}
2946
[email protected]0a1a45432010-03-31 08:09:452947bool RenderView::allowDatabase(
2948 WebFrame* frame, const WebString& name, const WebString& display_name,
2949 unsigned long estimated_size) {
2950 WebSecurityOrigin origin = frame->securityOrigin();
2951 if (origin.isEmpty())
2952 return false; // Uninitialized document?
2953
2954 bool result;
2955 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
2956 origin.toString().utf8(), name, display_name, estimated_size, &result)))
2957 return false;
2958 if (!result)
2959 DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES);
2960 return result;
2961}
[email protected]8934a3b2010-02-25 00:34:002962void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
2963 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
2964}
2965
[email protected]c21f1d52010-03-04 03:19:432966void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
2967 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
2968}
2969
[email protected]3d9689372009-09-10 04:29:172970void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2971 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2972}
2973
[email protected]0c882b282009-10-07 17:01:282974void RenderView::didCreateScriptContext(WebFrame* frame) {
2975 EventBindings::HandleContextCreated(frame, false);
2976}
2977
2978void RenderView::didDestroyScriptContext(WebFrame* frame) {
2979 EventBindings::HandleContextDestroyed(frame);
2980}
2981
2982void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2983 EventBindings::HandleContextCreated(frame, true);
2984}
2985
[email protected]fc86daa2010-03-30 23:52:532986void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
2987 WebFrame* target,
2988 bool cross_origin,
2989 const WebString& property_name,
2990 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:102991 // TODO(johnnyg): track the individual properties and repeat event_ids.
2992 if (cross_origin)
2993 cross_origin_access_count_++;
2994 else
2995 same_origin_access_count_++;
2996}
2997
[email protected]3d9689372009-09-10 04:29:172998void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142999 CheckPreferredSize();
3000}
3001
3002void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173003 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253004 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173005 // message.
[email protected]ab32b16c2009-10-16 14:57:253006 if (send_preferred_size_changes_) {
[email protected]dfca5acf2010-03-22 03:28:433007 if (!webview())
3008 return;
3009
[email protected]3d9689372009-09-10 04:29:173010 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:253011 // cache the width and height and only send the IPC message when we're sure
3012 // they're different.
[email protected]26aa0482009-09-30 16:55:273013 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:393014 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:293015
[email protected]ab32b16c2009-10-16 14:57:253016 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:393017 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:253018 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:393019 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:253020
[email protected]ab32b16c2009-10-16 14:57:253021 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3022 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173023 }
3024 }
3025}
3026
[email protected]143dcd592009-11-06 21:33:493027void RenderView::didChangeScrollOffset(WebFrame* frame) {
3028 StartNavStateSyncTimerIfNecessary();
3029}
3030
[email protected]8922e1f2009-10-03 05:01:263031void RenderView::reportFindInPageMatchCount(int request_id, int count,
3032 bool final_update) {
3033 // If we have a message that has been queued up, then we should just replace
3034 // it. The ACK from the browser will make sure it gets sent when the browser
3035 // wants it.
3036 if (queued_find_reply_message_.get()) {
3037 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3038 routing_id_,
3039 request_id,
3040 count,
3041 gfx::Rect(),
3042 -1, // Don't update active match ordinal.
3043 final_update);
3044 queued_find_reply_message_.reset(msg);
3045 } else {
3046 // Send the search result over to the browser process.
3047 Send(new ViewHostMsg_Find_Reply(
3048 routing_id_,
3049 request_id,
3050 count,
3051 gfx::Rect(),
3052 -1, // // Don't update active match ordinal.
3053 final_update));
3054 }
3055}
3056
3057void RenderView::reportFindInPageSelection(int request_id,
3058 int active_match_ordinal,
3059 const WebRect& selection_rect) {
3060 // Send the search result over to the browser process.
3061 Send(new ViewHostMsg_Find_Reply(routing_id_,
3062 request_id,
3063 -1,
3064 selection_rect,
3065 active_match_ordinal,
3066 false));
3067}
3068
[email protected]24a7f3c2010-03-25 08:26:493069void RenderView::ReportNoFindInPageResults(int request_id) {
3070 Send(new ViewHostMsg_Find_Reply(routing_id_,
3071 request_id,
3072 0,
3073 gfx::Rect(),
3074 0,
3075 true));
3076}
3077
[email protected]79dbc662009-09-04 05:42:513078// webkit_glue::WebPluginPageDelegate -----------------------------------------
3079
[email protected]f103ab72009-09-02 17:10:593080webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
3081 const GURL& url,
3082 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:593083 std::string* actual_mime_type) {
3084 if (!PluginChannelHost::IsListening())
3085 return NULL;
3086
3087 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:273088 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:593089 if (main_frame)
3090 policy_url = main_frame->url();
3091
3092 FilePath path;
[email protected]610c0892009-09-08 19:46:183093 render_thread_->Send(new ViewHostMsg_GetPluginPath(
3094 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:593095 if (path.value().empty())
3096 return NULL;
3097
3098 const std::string* mime_type_to_use;
3099 if (!actual_mime_type->empty())
3100 mime_type_to_use = actual_mime_type;
3101 else
3102 mime_type_to_use = &mime_type;
3103
[email protected]d2139662009-12-10 03:21:143104 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283105 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143106 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163107 const char kPepperPrefix[] = "pepper-";
3108 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143109 if (CommandLine::ForCurrentProcess()->
3110 HasSwitch(switches::kInternalPepper)) {
3111 in_process_plugin = true;
3112 use_pepper_host = true;
3113 } else {
3114 // In process Pepper plugins must be explicitly enabled.
3115 return NULL;
3116 }
[email protected]d7ce4272010-03-27 01:06:013117 } else if (CommandLine::ForCurrentProcess()->
3118 HasSwitch(switches::kInternalPDF) &&
3119 StartsWithASCII(*mime_type_to_use, "application/pdf", true)) {
3120 in_process_plugin = true;
3121 use_pepper_host = true;
[email protected]26e8d5e2009-10-13 02:47:163122 }
[email protected]d2139662009-12-10 03:21:143123 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463124 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3125 if (mime_type == "application/x-nacl-srpc") {
3126 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143127 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463128 }
3129 }
3130 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143131 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283132 WebPluginDelegatePepper* pepper_plugin =
3133 WebPluginDelegatePepper::Create(path, *mime_type_to_use,
3134 AsWeakPtr());
3135 current_pepper_plugins_.insert(pepper_plugin);
3136 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143137 } else {
[email protected]6876dff2010-01-15 19:38:093138#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143139 return WebPluginDelegateImpl::Create(
3140 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093141#else
[email protected]596b2c42010-01-14 20:40:433142 NOTIMPLEMENTED();
3143 return NULL;
[email protected]7b6616f2010-01-14 18:07:553144#endif
[email protected]6876dff2010-01-15 19:38:093145 }
[email protected]f103ab72009-09-02 17:10:593146 }
3147
[email protected]610c0892009-09-08 19:46:183148 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593149}
3150
3151void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033152#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593153 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3154 routing_id(), window));
3155#endif
3156}
3157
3158void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033159#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593160 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3161 routing_id(), window));
3162#endif
3163 CleanupWindowInPluginMoves(window);
3164}
3165
3166void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3167 SchedulePluginMove(move);
3168}
3169
3170void RenderView::DidStartLoadingForPlugin() {
3171 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523172 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593173}
3174
3175void RenderView::DidStopLoadingForPlugin() {
3176 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523177 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593178}
3179
3180void RenderView::ShowModalHTMLDialogForPlugin(
3181 const GURL& url,
3182 const gfx::Size& size,
3183 const std::string& json_arguments,
3184 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213185 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593186 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213187 json_retval));
[email protected]f103ab72009-09-02 17:10:593188}
3189
[email protected]b921cfd22010-02-25 16:57:513190WebCookieJar* RenderView::GetCookieJar() {
3191 return &cookie_jar_;
3192}
3193
initial.commit09911bf2008-07-26 23:55:293194void RenderView::SyncNavigationState() {
3195 if (!webview())
3196 return;
3197
[email protected]26aa0482009-09-30 16:55:273198 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173199 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293200 return;
[email protected]ca948a22009-06-25 19:36:173201
3202 Send(new ViewHostMsg_UpdateState(
3203 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293204}
3205
[email protected]b0950a72009-09-29 23:16:173206bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3207 // Make sure webview was not shut down.
3208 if (!webview())
3209 return false;
3210 // Create an image resource fetcher and assign it with a call back object.
3211 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273212 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173213 NewCallback(this, &RenderView::DidDownloadImage)));
3214 return true;
3215}
3216
3217void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293218 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173219 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473220 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3221 fetcher->id(),
3222 fetcher->image_url(),
3223 image.isNull(),
3224 image));
[email protected]b0950a72009-09-29 23:16:173225 // Dispose of the image fetcher.
3226 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3227 image_fetchers_.erase(fetcher);
3228 // We're in the callback from the ImageResourceFetcher, best to delay
3229 // deletion.
3230 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293231}
3232
[email protected]bf5c2ff392009-07-08 16:24:333233void RenderView::OnDownloadFavIcon(int id,
3234 const GURL& image_url,
3235 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343236 bool data_image_failed = false;
3237 if (image_url.SchemeIs("data")) {
3238 SkBitmap data_image = ImageFromDataUrl(image_url);
3239 data_image_failed = data_image.empty();
3240 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333241 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3242 data_image));
[email protected]f11ca0732009-04-11 00:09:343243 }
3244 }
3245
[email protected]bf5c2ff392009-07-08 16:24:333246 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173247 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333248 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3249 SkBitmap()));
3250 }
initial.commit09911bf2008-07-26 23:55:293251}
3252
[email protected]f11ca0732009-04-11 00:09:343253SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3254 std::string mime_type, char_set, data;
3255 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3256 // Decode the favicon using WebKit's image decoder.
3257 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3258 const unsigned char* src_data =
3259 reinterpret_cast<const unsigned char*>(&data[0]);
3260
3261 return decoder.Decode(src_data, data.size());
3262 }
3263 return SkBitmap();
3264}
3265
initial.commit09911bf2008-07-26 23:55:293266void RenderView::OnGetApplicationInfo(int page_id) {
3267 webkit_glue::WebApplicationInfo app_info;
3268 if (page_id == page_id_)
3269 webkit_glue::GetApplicationInfo(webview(), &app_info);
3270
3271 // Prune out any data URLs in the set of icons. The browser process expects
3272 // any icon with a data URL to have originated from a favicon. We don't want
3273 // to decode arbitrary data URLs in the browser process. See
3274 // http://b/issue?id=1162972
3275 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593276 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293277 app_info.icons.erase(app_info.icons.begin() + i);
3278 --i;
3279 }
3280 }
3281
3282 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3283}
3284
[email protected]7ccddb8c2009-08-04 17:36:553285GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293286 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553287 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293288 // If the URL that failed was secure, then the embedding web page was not
3289 // expecting a network attacker to be able to manipulate its contents. As
3290 // we fetch alternate error pages over HTTP, we would be allowing a network
3291 // attacker to manipulate the contents of the response if we tried to use
3292 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153293 return GURL();
initial.commit09911bf2008-07-26 23:55:293294 }
3295
3296 // Grab the base URL from the browser process.
3297 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153298 return GURL();
initial.commit09911bf2008-07-26 23:55:293299
3300 // Strip query params from the failed URL.
3301 GURL::Replacements remove_params;
3302 remove_params.ClearUsername();
3303 remove_params.ClearPassword();
3304 remove_params.ClearQuery();
3305 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553306 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503307 std::string spec_to_send = url_to_send.spec();
3308 // Notify link doctor of the url truncation by sending of "?" at the end.
3309 if (failed_url.has_query())
3310 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293311
3312 // Construct the query params to send to link doctor.
3313 std::string params(alternate_error_page_url_.query());
3314 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503315 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293316 params.append("&sourceid=chrome");
3317 params.append("&error=");
3318 switch (error_type) {
3319 case DNS_ERROR:
3320 params.append("dnserror");
3321 break;
3322
3323 case HTTP_404:
3324 params.append("http404");
3325 break;
3326
[email protected]5df266ac2008-10-15 19:50:133327 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333328 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133329 break;
3330
initial.commit09911bf2008-07-26 23:55:293331 default:
3332 NOTREACHED() << "unknown ErrorPageType";
3333 }
3334
3335 // OK, build the final url to return.
3336 GURL::Replacements link_doctor_params;
3337 link_doctor_params.SetQueryStr(params);
3338 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3339 return url;
3340}
3341
[email protected]24a7f3c2010-03-25 08:26:493342webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() {
3343 WebPlugin* plugin = webview()->mainFrame()->document().
3344 toElement<WebPluginDocument>().plugin();
3345 return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate();
3346}
3347
[email protected]6069da8c2009-10-20 20:33:493348void RenderView::OnFind(int request_id, const string16& search_text,
3349 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273350 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493351
3352 if (main_frame->document().isPluginDocument()) {
3353 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3354 if (options.findNext) {
3355 // Just navigate back/forward.
3356 delegate->SelectFindResult(options.forward);
3357 } else {
3358 if (delegate->SupportsFind()) {
3359 delegate->StartFind(UTF16ToUTF8(search_text),
3360 options.matchCase,
3361 request_id);
3362 } else {
3363 ReportNoFindInPageResults(request_id);
3364 }
3365 }
3366 return;
3367 }
3368
[email protected]b4bb2502009-10-01 22:35:273369 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273370 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293371 WebFrame* search_frame = focused_frame; // start searching focused frame.
3372
3373 bool multi_frame = (frame_after_main != main_frame);
3374
3375 // If we have multiple frames, we don't want to wrap the search within the
3376 // frame, so we check here if we only have main_frame in the chain.
3377 bool wrap_within_frame = !multi_frame;
3378
[email protected]b3f2b912009-04-09 16:18:523379 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293380 bool result = false;
3381
[email protected]7830da3e2009-11-06 16:27:263382 // If something is selected when we start searching it means we cannot just
3383 // increment the current match ordinal; we need to re-generate it.
3384 WebRange current_selection = focused_frame->selectionRange();
3385
initial.commit09911bf2008-07-26 23:55:293386 do {
[email protected]dd7daa82009-08-10 05:46:453387 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593388 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293389
3390 if (!result) {
3391 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223392 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293393
3394 // Find the next frame, but skip the invisible ones.
3395 do {
3396 // What is the next frame to search? (we might be going backwards). Note
3397 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593398 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273399 search_frame->traverseNext(true) :
3400 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453401 } while (!search_frame->hasVisibleContent() &&
3402 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293403
[email protected]884db412008-11-24 23:46:503404 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223405 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293406
3407 // If we have multiple frames and we have wrapped back around to the
3408 // focused frame, we need to search it once more allowing wrap within
3409 // the frame, otherwise it will report 'no match' if the focused frame has
3410 // reported matches, but no frames after the focused_frame contain a
3411 // match for the search word(s).
3412 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453413 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593414 request_id, search_text, options, true, // Force wrapping.
3415 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293416 }
3417 }
3418
[email protected]26aa0482009-09-30 16:55:273419 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293420 } while (!result && search_frame != focused_frame);
3421
[email protected]7830da3e2009-11-06 16:27:263422 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293423 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453424 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293425 } else {
3426 // If nothing is found, set result to "0 of 0", otherwise, set it to
3427 // "-1 of 1" to indicate that we found at least one item, but we don't know
3428 // yet what is active.
3429 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3430 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293431
[email protected]4f3dc372009-02-24 00:10:293432 // If we find no matches then this will be our last status update.
3433 // Otherwise the scoping effort will send more results.
3434 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293435
[email protected]4f3dc372009-02-24 00:10:293436 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403437 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593438 request_id,
[email protected]4f3dc372009-02-24 00:10:293439 match_count,
3440 selection_rect,
3441 ordinal,
3442 final_status_update));
initial.commit09911bf2008-07-26 23:55:293443
initial.commit09911bf2008-07-26 23:55:293444 // Scoping effort begins, starting with the mainframe.
3445 search_frame = main_frame;
3446
[email protected]dd7daa82009-08-10 05:46:453447 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293448
3449 do {
3450 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453451 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293452
3453 // We don't start another scoping effort unless at least one match has
3454 // been found.
3455 if (result) {
3456 // Start new scoping request. If the scoping function determines that it
3457 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453458 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593459 search_text,
3460 options,
initial.commit09911bf2008-07-26 23:55:293461 true); // reset the tickmarks
3462 }
3463
3464 // Iterate to the next frame. The frame will not necessarily scope, for
3465 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273466 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293467 } while (search_frame != main_frame);
3468 }
3469}
3470
[email protected]24a7f3c2010-03-25 08:26:493471void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3472 WebView* view = webview();
3473 if (!view)
3474 return;
3475
3476 WebDocument doc = view->mainFrame()->document();
3477 if (doc.isPluginDocument()) {
3478 GetDelegateForPluginDocument()->StopFind();
3479 return;
3480 }
3481
3482 bool clear_selection =
3483 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3484 if (clear_selection)
3485 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3486
3487 WebFrame* frame = view->mainFrame();
3488 while (frame) {
3489 frame->stopFinding(clear_selection);
3490 frame = frame->traverseNext(false);
3491 }
3492
3493 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3494 WebFrame* focused_frame = view->focusedFrame();
3495 if (focused_frame) {
3496 WebDocument doc = focused_frame->document();
3497 if (!doc.isNull()) {
3498 WebNode node = doc.focusedNode();
3499 if (!node.isNull())
3500 node.simulateClick();
3501 }
3502 }
3503 }
3504}
3505
3506void RenderView::OnFindReplyAck() {
3507 // Check if there is any queued up request waiting to be sent.
3508 if (queued_find_reply_message_.get()) {
3509 // Send the search result over to the browser process.
3510 Send(queued_find_reply_message_.get());
3511 queued_find_reply_message_.release();
3512 }
3513}
3514
[email protected]8c4cdd42010-01-12 21:31:133515// static
3516std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403517 // Text with less than 100 bytes will probably not provide good results.
3518 // Report it as unknown language.
3519 if (text.length() < 100)
3520 return kUnknownLanguageCode;
3521
[email protected]8c4cdd42010-01-12 21:31:133522 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133523 int num_languages = 0;
3524 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423525 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133526 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423527 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133528 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403529 if (is_reliable && cld_language != NUM_LANGUAGES &&
3530 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483531 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3532 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263533 // language code for tradtional Chinese among others.
3534 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3535 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3536 // for Simplified Chinese.
3537 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133538 }
[email protected]8c4cdd42010-01-12 21:31:133539 return language;
[email protected]7893a982010-01-07 23:25:523540}
3541
[email protected]8934a3b2010-02-25 00:34:003542bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353543 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003544 return current_content_settings_.settings[settings_type] !=
3545 CONTENT_SETTING_BLOCK;
3546}
3547
3548void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3549 if (!content_blocked_[settings_type]) {
3550 content_blocked_[settings_type] = true;
3551 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353552 }
[email protected]0de80162010-02-03 04:52:353553}
3554
[email protected]71b0d5d2010-02-15 05:43:073555void RenderView::ClearBlockedContentSettings() {
3556 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3557 content_blocked_[i] = false;
3558}
3559
initial.commit09911bf2008-07-26 23:55:293560void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3561 Send(new ViewHostMsg_DnsPrefetch(host_names));
3562}
3563
[email protected]40bd6582009-12-04 23:49:513564void RenderView::OnZoom(PageZoom::Function function) {
3565 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3566 return;
3567
[email protected]b03794d2010-03-26 19:57:523568 // Should we be saving zoom levels for plugins? It's not clear, so for now
3569 // don't.
3570 if (webview()->mainFrame()->document().isPluginDocument()) {
3571 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3572 int zoom;
3573 if (function == PageZoom::RESET) {
3574 zoom = 0;
3575 } else if (function == PageZoom::ZOOM_OUT) {
3576 zoom = -1;
3577 } else if (function == PageZoom::ZOOM_IN) {
3578 zoom = 1;
3579 } else {
3580 NOTREACHED();
[email protected]754bb3b2010-03-26 20:12:113581 return;
[email protected]b03794d2010-03-26 19:57:523582 }
3583 delegate->Zoom(zoom);
3584 return;
3585 }
3586
[email protected]40bd6582009-12-04 23:49:513587 int zoom_level = webview()->zoomLevel();
3588 int new_zoom_level = webview()->setZoomLevel(false,
3589 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3590
3591 // Tell the browser which host got zoomed so it can update the saved values.
3592 // Pages like the safe browsing interstitial can have empty hosts; don't
3593 // record those.
3594 std::string host(GURL(webview()->mainFrame()->url()).host());
3595 if (!host.empty())
3596 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3597}
3598
[email protected]f85f0702010-01-30 09:31:013599void RenderView::OnSetContentSettingsForLoadingHost(
3600 std::string host,
3601 const ContentSettings& content_settings) {
3602 host_content_settings_[host] = content_settings;
3603}
3604
[email protected]40bd6582009-12-04 23:49:513605void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3606 int zoom_level) {
3607 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293608}
3609
[email protected]41fc0322009-09-04 22:23:403610void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273611 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293612}
3613
[email protected]a697f4c2009-09-14 22:30:183614void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273615 WebString no_encoding;
3616 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183617}
3618
[email protected]20ad2692009-11-20 18:27:203619bool RenderView::GetAllChildFrames(
3620 WebFrame* parent_frame,
3621 std::vector<WebFrame*>* frames_vector) const {
3622 if (!parent_frame)
3623 return false;
3624 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3625 child_frame = child_frame->nextSibling()) {
3626 frames_vector->push_back(child_frame);
3627 GetAllChildFrames(child_frame, frames_vector);
3628 }
3629 return true;
3630}
3631
[email protected]dd7daa82009-08-10 05:46:453632WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3633 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273634 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453635
3636 // xpath string can represent a frame deep down the tree (across multiple
3637 // frame DOMs).
3638 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3639 // should break into 2 xpaths
3640 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3641
[email protected]26aa0482009-09-30 16:55:273642 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453643
3644 std::wstring xpath_remaining = xpath;
3645 while (!xpath_remaining.empty()) {
3646 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3647 std::wstring xpath_child;
3648 if (delim_pos != std::wstring::npos) {
3649 xpath_child = xpath_remaining.substr(0, delim_pos);
3650 xpath_remaining.erase(0, delim_pos + 1);
3651 } else {
3652 xpath_remaining.swap(xpath_child);
3653 }
3654 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293655 }
3656
[email protected]dd7daa82009-08-10 05:46:453657 return frame;
initial.commit09911bf2008-07-26 23:55:293658}
3659
[email protected]f29acf52008-11-03 20:08:333660void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3661 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293662 WebFrame* web_frame = GetChildFrame(frame_xpath);
3663 if (!web_frame)
3664 return;
3665
[email protected]dd7daa82009-08-10 05:46:453666 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293667}
3668
[email protected]1810e132009-03-24 23:35:483669void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083670 const std::string& css,
3671 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483672 WebFrame* web_frame = GetChildFrame(frame_xpath);
3673 if (!web_frame)
3674 return;
3675
[email protected]ffaef0c2009-09-15 17:08:083676 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483677}
3678
[email protected]00c39612010-03-06 02:53:283679void RenderView::OnPepperPluginDestroy(
3680 WebPluginDelegatePepper* pepper_plugin) {
3681 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
3682 current_pepper_plugins_.find(pepper_plugin);
3683 if (found_pepper == current_pepper_plugins_.end()) {
3684 NOTREACHED();
3685 return;
3686 }
3687 current_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473688
3689 // The plugin could have been destroyed while it was waiting for a file
3690 // choose callback, so check all pending completion callbacks and NULL them.
3691 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3692 file_chooser_completions_.begin();
3693 i != file_chooser_completions_.end(); /* nothing */) {
3694 if ((*i)->completion == pepper_plugin) {
3695 // We NULL the first one instead of deleting it because the plugin might
3696 // be the one waiting for a file choose callback. If the callback later
3697 // comes, we don't want to send the result to the next callback in line.
3698 if (i == file_chooser_completions_.begin())
3699 (*i)->completion = NULL;
3700 else
3701 i = file_chooser_completions_.erase(i);
3702 } else {
3703 ++i;
3704 }
3705 }
[email protected]00c39612010-03-06 02:53:283706}
3707
initial.commit09911bf2008-07-26 23:55:293708void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3709 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333710 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293711}
3712
[email protected]1810e132009-03-24 23:35:483713void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083714 const std::string& css,
3715 const std::string& id) {
3716 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413717
3718 // Notify RenderViewHost that css has been inserted into the frame.
3719 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483720}
3721
[email protected]7ea066a2009-04-06 20:21:593722void RenderView::OnAddMessageToConsole(
3723 const string16& frame_xpath,
3724 const string16& message,
3725 const WebConsoleMessage::Level& level) {
3726 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593727 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453728 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293729}
3730
[email protected]81e63782009-02-27 19:35:093731void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3732 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293733}
3734
3735void RenderView::OnSetDOMUIProperty(const std::string& name,
3736 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093737 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293738 dom_ui_bindings_.SetProperty(name, value);
3739}
3740
3741void RenderView::OnReservePageIDRange(int size_of_range) {
3742 next_page_id_ += size_of_range + 1;
3743}
3744
[email protected]e80c73b2009-04-07 23:24:583745void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3746 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253747 bool ended,
3748 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033749 if (ended) {
[email protected]26aa0482009-09-30 16:55:273750 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033751 }
initial.commit09911bf2008-07-26 23:55:293752}
3753
3754void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273755 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293756}
3757
initial.commit09911bf2008-07-26 23:55:293758void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103759 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293760 webkit_glue::FillPasswordForm(this->webview(), form_data);
3761}
3762
3763void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583764 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253765 const gfx::Point& screen_point,
3766 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273767 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583768 drop_data.ToDragData(),
3769 drop_data.identity,
3770 client_point,
[email protected]1d9f4132009-09-08 17:29:253771 screen_point,
3772 ops);
initial.commit09911bf2008-07-26 23:55:293773
[email protected]1d9f4132009-09-08 17:29:253774 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293775}
3776
[email protected]e80c73b2009-04-07 23:24:583777void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253778 const gfx::Point& screen_point,
3779 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273780 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253781 client_point,
3782 screen_point,
3783 ops);
initial.commit09911bf2008-07-26 23:55:293784
[email protected]1d9f4132009-09-08 17:29:253785 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293786}
3787
3788void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273789 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293790}
3791
[email protected]e80c73b2009-04-07 23:24:583792void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3793 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273794 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293795}
3796
3797void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593798 webkit_preferences_ = prefs;
3799 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293800}
3801
3802void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3803 alternate_error_page_url_ = url;
3804}
3805
[email protected]a0c7153e2009-12-09 14:36:333806void RenderView::OnCustomContextMenuAction(unsigned action) {
3807 webview()->performCustomContextMenuAction(action);
3808}
3809
[email protected]d4a00a72010-01-29 01:44:423810void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:023811 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:423812 const std::string& source_lang,
3813 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:023814 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
3815 translate_script);
[email protected]d4a00a72010-01-29 01:44:423816}
3817
[email protected]85d252e2010-04-06 22:21:023818void RenderView::OnRevertTranslation(int page_id) {
3819 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:323820}
3821
initial.commit09911bf2008-07-26 23:55:293822void RenderView::OnInstallMissingPlugin() {
3823 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593824 if (first_default_plugin_)
3825 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293826}
3827
[email protected]cdaf8d02010-03-30 19:52:473828void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363829 // This could happen if we navigated to a different page before the user
3830 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473831 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363832 return;
3833
[email protected]cdaf8d02010-03-30 19:52:473834 WebVector<WebString> ws_file_names(paths.size());
3835 for (size_t i = 0; i < paths.size(); ++i)
3836 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463837
[email protected]cdaf8d02010-03-30 19:52:473838 if (file_chooser_completions_.front()->completion)
3839 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3840 file_chooser_completions_.pop_front();
3841
3842 // If there are more pending file chooser requests, schedule one now.
3843 if (!file_chooser_completions_.empty()) {
3844 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3845 file_chooser_completions_.front()->params));
3846 }
initial.commit09911bf2008-07-26 23:55:293847}
3848
3849void RenderView::OnEnableViewSourceMode() {
3850 if (!webview())
3851 return;
[email protected]26aa0482009-09-30 16:55:273852 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293853 if (!main_frame)
3854 return;
3855
[email protected]dd7daa82009-08-10 05:46:453856 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293857}
3858
[email protected]ab32b16c2009-10-16 14:57:253859void RenderView::OnEnablePreferredSizeChangedMode() {
3860 send_preferred_size_changes_ = true;
[email protected]e8014aa52010-03-03 14:30:063861
3862 if (ViewType::ShouldAutoResize(view_type_))
[email protected]d8a179c2010-01-31 00:58:143863 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3864 &RenderView::CheckPreferredSize);
[email protected]0666aef2009-05-13 19:48:083865}
3866
[email protected]cda45c02010-02-25 19:28:103867void RenderView::OnDisableScrollbarsForSmallWindows(
3868 const gfx::Size& disable_scrollbar_size_limit) {
3869 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3870}
3871
[email protected]80d96fa2009-06-10 22:34:513872void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3873 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373874 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:033875#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:413876 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3877 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463878 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323879
[email protected]644d77e2010-01-27 01:03:103880 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323881 webview()->setScrollbarColors(
3882 renderer_prefs.thumb_inactive_color,
3883 renderer_prefs.thumb_active_color,
3884 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103885 webview()->setSelectionColors(
3886 renderer_prefs.active_selection_bg_color,
3887 renderer_prefs.active_selection_fg_color,
3888 renderer_prefs.inactive_selection_bg_color,
3889 renderer_prefs.inactive_selection_fg_color);
3890 }
[email protected]7a74e102009-09-03 00:16:563891#endif
[email protected]80d96fa2009-06-10 22:34:513892}
3893
[email protected]952cb702009-10-07 05:50:283894void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3895 const WebMediaPlayerAction& action) {
3896 if (webview())
3897 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563898}
3899
[email protected]7b291f92009-08-14 05:43:533900void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513901 // When this is first set, the bindings aren't fully loaded. We only need
3902 // to call through this API after the page has already been loaded. It's
3903 // also called in didCreateDocumentElement to bootstrap.
3904 if (view_type_ != ViewType::INVALID) {
3905 if (type == ViewType::EXTENSION_MOLE ||
3906 type == ViewType::EXTENSION_TOOLSTRIP) {
3907 ExtensionProcessBindings::SetViewType(webview(), type);
3908 }
3909 }
[email protected]7b291f92009-08-14 05:43:533910 view_type_ = type;
3911}
3912
3913void RenderView::OnUpdateBrowserWindowId(int window_id) {
3914 browser_window_id_ = window_id;
3915}
3916
[email protected]266eb6f2008-09-30 23:56:503917void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253918 const webkit_glue::WebAccessibility::InParams& in_params,
3919 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573920#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153921 if (!accessibility_.get()) {
3922 // TODO(dglazkov): Once implemented for all ports, remove lazy
3923 // instantiation of accessibility_.
3924 accessibility_.reset(WebAccessibilityCache::create());
3925 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253926 }
[email protected]266eb6f2008-09-30 23:56:503927
[email protected]17455962010-02-24 01:39:353928 out_params->return_code =
3929 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3930 in_params,
3931 out_params);
[email protected]c7287a92009-11-04 20:06:153932
[email protected]6c8afae52009-01-22 02:24:573933#else // defined(OS_WIN)
3934 // TODO(port): accessibility not yet implemented
3935 NOTIMPLEMENTED();
3936#endif
[email protected]266eb6f2008-09-30 23:56:503937}
3938
[email protected]6a983b42009-03-20 20:12:253939void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573940#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153941 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503942 // If accessibility is not activated, ignore clearing message.
3943 return;
3944 }
[email protected]e846d0d2009-05-20 00:53:063945
[email protected]c7287a92009-11-04 20:06:153946 if (clear_all) {
3947 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503948 return;
[email protected]c7287a92009-11-04 20:06:153949 }
3950
3951 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063952
[email protected]6c8afae52009-01-22 02:24:573953#else // defined(OS_WIN)
3954 // TODO(port): accessibility not yet implemented
3955 NOTIMPLEMENTED();
3956#endif
[email protected]266eb6f2008-09-30 23:56:503957}
3958
initial.commit09911bf2008-07-26 23:55:293959void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3960 const GURL& page_url) {
3961 // Prepare list to storage all savable resource links.
3962 std::vector<GURL> resources_list;
3963 std::vector<GURL> referrers_list;
3964 std::vector<GURL> frames_list;
3965 webkit_glue::SavableResourcesResult result(&resources_list,
3966 &referrers_list,
3967 &frames_list);
3968
[email protected]dbeb3952009-10-13 18:01:183969 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3970 webview(),
3971 page_url,
3972 &result,
3973 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293974 // If something is wrong when collecting all savable resource links,
3975 // send empty list to embedder(browser) to tell it failed.
3976 referrers_list.clear();
3977 resources_list.clear();
3978 frames_list.clear();
3979 }
3980
3981 // Send result of all savable resource links to embedder.
3982 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3983 resources_list,
3984 referrers_list,
3985 frames_list));
3986}
3987
3988void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323989 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313990 const std::vector<FilePath>& local_paths,
3991 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073992
3993 // Convert std::vector of GURLs to WebVector<WebURL>
3994 WebVector<WebURL> weburl_links(links);
3995
3996 // Convert std::vector of std::strings to WebVector<WebString>
3997 WebVector<WebString> webstring_paths(local_paths.size());
3998 for (size_t i = 0; i < local_paths.size(); i++)
3999 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4000
4001 WebPageSerializer::serialize(webview()->mainFrame(),
4002 true, this, weburl_links, webstring_paths,
4003 webkit_glue::FilePathToWebString(
4004 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294005}
4006
[email protected]d9ec5c0f2009-12-23 11:55:074007void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4008 const WebCString& data,
4009 WebPageSerializerClient::PageSerializationStatus status) {
4010 Send(new ViewHostMsg_SendSerializedHtmlData(
4011 routing_id_,
4012 frame_url,
4013 data.data(),
4014 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294015}
4016
[email protected]04b4a6c2008-08-02 00:44:474017void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:274018 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474019 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294020}
4021
[email protected]eb6b87a2009-07-24 15:57:394022void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294023 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4024 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4025 // in the onunload handler from appearing. For now, we're bypassing that and
4026 // calling the FrameLoader's CloseURL method directly. This should be
4027 // revisited to avoid having two ways to close a page. Having a single way
4028 // to close that can run onunload is also useful for fixing
4029 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274030 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294031 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454032 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174033 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294034 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4035 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454036 if (url.SchemeIs(chrome::kHttpScheme) ||
4037 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294038 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294039 }
[email protected]26aa0482009-09-30 16:55:274040 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294041
[email protected]ab9eabac2010-03-16 16:54:104042 // Reset stats
4043 cross_origin_access_count_ = 0;
4044 same_origin_access_count_ = 0;
4045
[email protected]eb6b87a2009-07-24 15:57:394046 // Just echo back the params in the ACK.
4047 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294048}
4049
4050void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574051#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294052 gfx::NativeTheme::instance()->CloseHandles();
4053 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:284054 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:574055#else // defined(OS_WIN)
4056 // TODO(port): we don't support theming on non-Windows platforms yet
4057 NOTIMPLEMENTED();
4058#endif
initial.commit09911bf2008-07-26 23:55:294059}
4060
[email protected]28790922009-03-09 19:48:374061void RenderView::OnMessageFromExternalHost(const std::string& message,
4062 const std::string& origin,
4063 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154064 if (message.empty())
4065 return;
4066
[email protected]28790922009-03-09 19:48:374067 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4068 target);
[email protected]3ac14a052008-08-15 21:22:154069}
4070
[email protected]0aa55312008-10-17 21:53:084071void RenderView::OnDisassociateFromPopupCount() {
4072 if (decrement_shared_popup_at_destruction_)
4073 shared_popup_counter_->data--;
4074 shared_popup_counter_ = new SharedRenderViewCounter(0);
4075 decrement_shared_popup_at_destruction_ = false;
4076}
4077
[email protected]15d79e12009-08-02 19:23:454078bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4079 const WebURLError& error,
4080 bool replace) {
4081 // We only show alternate error pages in the main frame. They are
4082 // intended to assist the user when navigating, so there is not much
4083 // value in showing them for failed subframes. Ideally, we would be
4084 // able to use the TYPED transition type for this, but that flag is
4085 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454086 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454087 return false;
4088
4089 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374090 // connection failure.
[email protected]15d79e12009-08-02 19:23:454091 int ec = error.reason;
4092 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4093 ec != net::ERR_CONNECTION_FAILED &&
4094 ec != net::ERR_CONNECTION_REFUSED &&
4095 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374096 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454097 return false;
4098
4099 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554100 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454101 if (!error_page_url.is_valid())
4102 return false;
4103
4104 // Load an empty page first so there is an immediate response to the error,
4105 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454106 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454107 GURL(kUnreachableWebDataURL),
4108 error.unreachableURL,
4109 replace);
4110
4111 // Now, create a fetcher for the error page and associate it with the data
4112 // source we just created via the LoadHTMLString call. That way if another
4113 // navigation occurs, the fetcher will get destroyed.
4114 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454115 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454116 navigation_state->set_alt_error_page_fetcher(
4117 new AltErrorPageResourceFetcher(
4118 error_page_url, frame, error,
4119 NewCallback(this, &RenderView::AltErrorPageFinished)));
4120 return true;
4121}
4122
initial.commit09911bf2008-07-26 23:55:294123std::string RenderView::GetAltHTMLForTemplate(
4124 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394125 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294126 ResourceBundle::GetSharedInstance().GetRawDataResource(
4127 template_resource_id));
4128
4129 if (template_html.empty()) {
4130 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4131 return "";
4132 }
[email protected]7cd22a52009-07-14 00:40:254133
initial.commit09911bf2008-07-26 23:55:294134 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254135 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294136 template_html, &error_strings, "t");
4137}
[email protected]0e79b9e2009-02-13 04:20:484138
[email protected]15d79e12009-08-02 19:23:454139void RenderView::AltErrorPageFinished(WebFrame* frame,
4140 const WebURLError& original_error,
4141 const std::string& html) {
4142 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554143
4144 // If we failed to download the alternate error page, fall back to the
4145 // original error page if present. Otherwise, LoadNavigationErrorPage
4146 // will simply display a default error page.
4147 const std::string* html_to_load = &html;
4148 if (html.empty()) {
4149 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454150 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554151 html_to_load = &navigation_state->postponed_data();
4152 }
4153 LoadNavigationErrorPage(
4154 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454155}
4156
[email protected]30f75e62009-02-25 22:01:004157void RenderView::OnMoveOrResizeStarted() {
4158 if (webview())
[email protected]4605325d2010-02-08 23:46:044159 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:004160}
4161
[email protected]30f75e62009-02-25 22:01:004162void RenderView::OnResize(const gfx::Size& new_size,
4163 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104164 if (webview()) {
[email protected]4605325d2010-02-08 23:46:044165 webview()->hideSuggestionsPopup();
[email protected]cda45c02010-02-25 19:28:104166
4167 if (send_preferred_size_changes_) {
4168 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4169 // either width or height, allow scroll bars.
4170 bool allow_scrollbars = (
4171 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244172 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104173 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4174 }
4175 }
4176
[email protected]30f75e62009-02-25 22:01:004177 RenderWidget::OnResize(new_size, resizer_rect);
4178}
[email protected]0aa477bd2009-03-23 22:21:434179
[email protected]00c39612010-03-06 02:53:284180void RenderView::DidInitiatePaint() {
4181 // Notify any pepper plugins that we started painting. The plugin "should"
4182 // never notified that we started painting, this is used for internal
4183 // bookkeeping only, so we know that the set can not change under us.
4184 for (std::set<WebPluginDelegatePepper*>::iterator i =
4185 current_pepper_plugins_.begin();
4186 i != current_pepper_plugins_.end(); ++i)
4187 (*i)->RenderViewInitiatedPaint();
4188}
4189
4190void RenderView::DidFlushPaint() {
4191 // Notify any pepper plugins that we painted. This will call into the plugin,
4192 // and we it may ask to close itself as a result. This will, in turn, modify
4193 // our set, possibly invalidating the iterator. So we iterate on a copy that
4194 // won't change out from under us.
4195 std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_;
4196 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4197 i != plugins.end(); ++i) {
4198 // The copy above makes sure our iterator is never invalid if some plugins
4199 // are destroyed. But some plugin may decide to close all of its views in
4200 // response to a paint in one of them, so we need to make sure each one is
4201 // still "current" before using it.
4202 if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end())
4203 (*i)->RenderViewFlushedPaint();
4204 }
4205
4206 WebFrame* main_frame = webview()->mainFrame();
4207
4208 // If we have a provisional frame we are between the start and commit stages
4209 // of loading and we don't want to save stats.
4210 if (!main_frame->provisionalDataSource()) {
4211 WebDataSource* ds = main_frame->dataSource();
4212 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4213 DCHECK(navigation_state);
4214
4215 Time now = Time::Now();
4216 if (navigation_state->first_paint_time().is_null()) {
4217 navigation_state->set_first_paint_time(now);
4218 }
4219 if (navigation_state->first_paint_after_load_time().is_null() &&
4220 !navigation_state->finish_load_time().is_null()) {
4221 navigation_state->set_first_paint_after_load_time(now);
4222 }
4223 }
4224}
4225
4226
[email protected]05d478752009-04-08 23:38:164227void RenderView::OnClearFocusedNode() {
4228 if (webview())
[email protected]26aa0482009-09-30 16:55:274229 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164230}
4231
[email protected]699ab0d2009-04-23 23:19:144232void RenderView::OnSetBackground(const SkBitmap& background) {
4233 if (webview())
[email protected]b4bb2502009-10-01 22:35:274234 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144235
4236 SetBackground(background);
4237}
4238
[email protected]8c66c5a2009-07-22 17:26:344239void RenderView::OnSetActive(bool active) {
4240 if (webview())
[email protected]b4bb2502009-10-01 22:35:274241 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264242
4243#if defined(OS_MACOSX)
4244 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4245 for (plugin_it = plugin_delegates_.begin();
4246 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4247 (*plugin_it)->SetWindowFocus(active);
4248 }
4249#endif
[email protected]8c66c5a2009-07-22 17:26:344250}
4251
[email protected]6ce7abc52010-02-02 18:40:144252#if defined(OS_MACOSX)
4253void RenderView::OnSetWindowVisibility(bool visible) {
4254 // Inform plugins that their container has changed visibility.
4255 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4256 for (plugin_it = plugin_delegates_.begin();
4257 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4258 (*plugin_it)->SetContainerVisibility(visible);
4259 }
4260}
[email protected]1e6e3c992010-02-08 15:52:134261
4262void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4263 gfx::Rect view_frame) {
4264 // Inform plugins that their window's frame has changed.
4265 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4266 for (plugin_it = plugin_delegates_.begin();
4267 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4268 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4269 }
4270}
[email protected]6ce7abc52010-02-02 18:40:144271#endif // OS_MACOSX
4272
[email protected]309d7a282009-03-24 09:18:274273void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584274 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394275 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324276 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474277 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394278 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4279 name,
4280 args,
4281 source_url,
4282 request_id,
[email protected]2f25d7b92009-06-10 00:06:474283 has_callback));
[email protected]309d7a282009-03-24 09:18:274284}
4285
[email protected]c6619182009-05-12 14:59:324286void RenderView::OnExtensionResponse(int request_id,
4287 bool success,
4288 const std::string& response,
4289 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354290 ExtensionProcessBindings::HandleResponse(
4291 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274292}
[email protected]c20210e62009-04-03 21:39:264293
[email protected]078b34612009-09-19 19:31:514294void RenderView::InjectToolstripCSS() {
4295 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4296 return;
4297
4298 static const base::StringPiece toolstrip_css(
4299 ResourceBundle::GetSharedInstance().GetRawDataResource(
4300 IDR_EXTENSION_TOOLSTRIP_CSS));
4301 std::string css = toolstrip_css.as_string();
4302 InsertCSS(L"", css, "ToolstripDefaultCSS");
4303}
4304
[email protected]7120f132009-07-20 21:05:374305void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494306 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194307 bool requires_incognito_access,
4308 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494309 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194310 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374311}
4312
[email protected]e7e4f3c2009-04-21 15:24:084313// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264314//
[email protected]7a9b51f2009-06-29 21:28:294315// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:264316// The time points we keep are
4317// request: time document was requested by user
4318// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254319// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294320// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264321// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294322// first_paint: first paint performed
4323// first_paint_after_load: first paint performed after load is finished
4324// begin: request if it was user requested, start otherwise
4325//
[email protected]c20210e62009-04-03 21:39:264326// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:254327// request->start,
[email protected]7a9b51f2009-06-29 21:28:294328// start->commit,
4329// commit->finish_document,
4330// finish_document->finish,
4331// begin->commit,
4332// begin->finishDoc,
4333// begin->finish,
4334// begin->first_paint,
4335// begin->first_paint_after_load
4336// commit->finishDoc,
4337// commit->first_paint,
4338// commit->first_paint_after_load,
4339// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264340//
[email protected]e7e4f3c2009-04-21 15:24:084341// It's possible for the request time not to be set, if a client
4342// redirect had been done (the user never requested the page)
4343// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294344// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264345void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274346 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564347 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454348 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294349 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564350
[email protected]f9f4841b2010-03-20 05:41:424351 // If we've already dumped, do nothing.
4352 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294353 return;
[email protected]ed3fb032009-06-16 19:50:564354
[email protected]f9f4841b2010-03-20 05:41:424355 // Handle case where user hits "stop" or "back" before loading completely.
4356 bool abandoned_page = finish.is_null();
4357 if (abandoned_page) {
4358 finish = Time::Now();
4359 navigation_state->set_finish_load_time(finish);
4360 }
4361 UMA_HISTOGRAM_ENUMERATION("Renderer4.Abandoned", abandoned_page ? 1 : 0, 2);
4362
[email protected]f8999642009-10-27 21:39:424363 LogNavigationState(navigation_state, main_frame->dataSource());
4364
[email protected]a7ccc4d2010-01-27 08:14:484365 NavigationState::LoadType load_type = navigation_state->load_type();
4366 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184367 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484368
[email protected]ab9eabac2010-03-16 16:54:104369 // Site isolation metrics.
4370 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4371 cross_origin_access_count_);
4372 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4373 same_origin_access_count_);
4374
[email protected]7a9b51f2009-06-29 21:28:294375 Time request = navigation_state->request_time();
4376 Time start = navigation_state->start_load_time();
4377 Time commit = navigation_state->commit_load_time();
4378 Time finish_doc = navigation_state->finish_document_load_time();
4379 Time first_paint = navigation_state->first_paint_time();
4380 Time first_paint_after_load =
4381 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:264382
[email protected]7a9b51f2009-06-29 21:28:294383 Time begin;
4384 // Client side redirects will have no request time.
4385 if (request.is_null()) {
4386 begin = start;
4387 } else {
4388 begin = request;
4389 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084390 }
[email protected]7a9b51f2009-06-29 21:28:294391 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4392 UMA_HISTOGRAM_MEDIUM_TIMES(
4393 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4394 UMA_HISTOGRAM_MEDIUM_TIMES(
4395 "Renderer4.FinishDocToFinish", finish - finish_doc);
4396
4397 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484398
4399 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4400 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4401 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484402 TimeDelta begin_to_finish_doc = finish_doc - begin;
4403 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184404
4405 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4406 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4407 static const size_t kBeginToFinishBucketCount(100);
4408 TimeDelta begin_to_finish = finish_doc - begin;
4409 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4410 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4411
[email protected]a7ccc4d2010-01-27 08:14:484412 switch (load_type) {
4413 case NavigationState::UNDEFINED_LOAD:
4414 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4415 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4416 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184417 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4418 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4419 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484420 break;
4421 case NavigationState::RELOAD:
4422 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4423 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4424 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184425 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4426 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4427 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484428 break;
4429 case NavigationState::HISTORY_LOAD:
4430 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4431 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4432 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184433 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4434 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4435 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484436 break;
4437 case NavigationState::NORMAL_LOAD:
4438 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4439 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4440 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184441 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4442 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4443 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484444 break;
[email protected]4c1b6f0b2010-02-07 16:38:184445 case NavigationState::LINK_LOAD_NORMAL:
4446 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484447 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4448 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184449 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4450 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4451 kBeginToFinishBucketCount);
4452 break;
4453 case NavigationState::LINK_LOAD_RELOAD:
4454 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4455 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4456 kBeginToFinishDocBucketCount);
4457 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4458 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4459 kBeginToFinishBucketCount);
4460 break;
4461 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4462 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4463 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4464 kBeginToFinishDocBucketCount);
4465 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4466 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4467 kBeginToFinishBucketCount);
4468 break;
4469 case NavigationState::LINK_LOAD_CACHE_ONLY:
4470 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4471 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4472 kBeginToFinishDocBucketCount);
4473 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4474 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4475 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484476 break;
4477 default:
4478 break;
4479 }
4480
4481 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4482 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4483 if (use_dns_histogram) {
[email protected]f9f4841b2010-03-20 05:41:424484 UMA_HISTOGRAM_ENUMERATION(
4485 FieldTrial::MakeName("Renderer4.Abandoned", "DnsImpact"),
4486 abandoned_page ? 1 : 0, 2);
4487 UMA_HISTOGRAM_ENUMERATION(
4488 FieldTrial::MakeName("Renderer4.LoadType", "DnsImpact"),
[email protected]fd11f1752010-02-23 22:35:484489 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484490 switch (load_type) {
4491 case NavigationState::NORMAL_LOAD:
4492 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184493 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4494 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4495 kBeginToFinishBucketCount);
4496 break;
4497 case NavigationState::LINK_LOAD_NORMAL:
4498 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184499 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4500 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4501 kBeginToFinishBucketCount);
4502 break;
4503 case NavigationState::LINK_LOAD_RELOAD:
4504 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184505 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4506 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4507 kBeginToFinishBucketCount);
4508 break;
4509 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4510 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184511 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4512 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4513 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484514 break;
4515 default:
4516 break;
4517 }
4518 }
4519
4520 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4521 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4522 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484523 UMA_HISTOGRAM_ENUMERATION(
4524 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4525 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484526 switch (load_type) {
4527 case NavigationState::NORMAL_LOAD:
4528 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484529 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4530 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4531 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484532 break;
[email protected]4c1b6f0b2010-02-07 16:38:184533 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484534 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484535 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4536 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4537 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184538 break;
4539 case NavigationState::LINK_LOAD_RELOAD:
4540 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484541 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4542 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4543 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184544 break;
4545 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4546 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484547 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4548 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4549 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184550 break;
4551 case NavigationState::LINK_LOAD_CACHE_ONLY:
4552 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484553 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4554 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4555 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484556 break;
4557 default:
4558 break;
4559 }
4560 }
4561
4562 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4563 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184564 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4565 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484566 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4567 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4568 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4569 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544570
[email protected]0a32257a2009-07-09 18:10:414571 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4572 finish - start, kBeginToFinishMin,
4573 kBeginToFinishMax, kBeginToFinishBucketCount);
4574 if (!request.is_null())
4575 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4576 finish - request, kBeginToFinishMin,
4577 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544578
[email protected]7a9b51f2009-06-29 21:28:294579 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4580
4581 if (!first_paint.is_null()) {
4582 UMA_HISTOGRAM_MEDIUM_TIMES(
4583 "Renderer4.BeginToFirstPaint", first_paint - begin);
4584 UMA_HISTOGRAM_MEDIUM_TIMES(
4585 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264586 }
[email protected]7a9b51f2009-06-29 21:28:294587
4588 if (!first_paint_after_load.is_null()) {
4589 UMA_HISTOGRAM_MEDIUM_TIMES(
4590 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4591 UMA_HISTOGRAM_MEDIUM_TIMES(
4592 "Renderer4.CommitToFirstPaintAfterLoad",
4593 first_paint_after_load - commit);
4594 UMA_HISTOGRAM_MEDIUM_TIMES(
4595 "Renderer4.FinishToFirstPaintAfterLoad",
4596 first_paint_after_load - finish);
4597 }
4598
4599 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414600
4601 // Since there are currently no guarantees that renderer histograms will be
4602 // sent to the browser, we initiate a PostTask here to be sure that we send
4603 // the histograms we generated. Without this call, pages that don't have an
4604 // on-close-handler might generate data that is lost when the renderer is
4605 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484606 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4607 // should post when the onload is complete, so that it doesn't interfere with
4608 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414609 if (RenderThread::current()) {
4610 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134611 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414612 }
[email protected]c20210e62009-04-03 21:39:264613}
[email protected]e846d0d2009-05-20 00:53:064614
[email protected]f8999642009-10-27 21:39:424615void RenderView::LogNavigationState(const NavigationState* state,
4616 const WebDataSource* ds) const {
4617 // Because this function gets called on every page load,
4618 // take extra care to optimize it away if logging is turned off.
4619 if (logging::LOG_INFO < logging::GetMinLogLevel())
4620 return;
4621
4622 DCHECK(state);
4623 DCHECK(ds);
4624 GURL url(ds->request().url());
4625 Time start = state->start_load_time();
4626 Time finish = state->finish_load_time();
4627 // TODO(mbelshe): should we log more stats?
4628 LOG(INFO) << "PLT: "
4629 << (finish - start).InMilliseconds()
4630 << "ms "
4631 << url.spec();
4632}
4633
[email protected]cc0445f2009-10-13 16:09:084634void RenderView::focusAccessibilityObject(
4635 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064636#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154637 // TODO(dglazkov): Current logic implies that focus change can only be made
4638 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4639 // where accessibility is initialized. We should determine whether that's
4640 // right.
4641 if (!accessibility_.get())
4642 return;
[email protected]e846d0d2009-05-20 00:53:064643
4644 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154645 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064646
4647 // If id is valid, alert the browser side that an accessibility focus change
4648 // occurred.
4649 if (acc_obj_id >= 0)
4650 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4651
4652#else // defined(OS_WIN)
4653 // TODO(port): accessibility not yet implemented
4654 NOTIMPLEMENTED();
4655#endif
4656}
[email protected]daa8c58e2009-06-15 17:21:104657
[email protected]e9e07992010-02-17 21:04:364658void RenderView::SendForms(WebFrame* frame) {
[email protected]b715f7f2010-04-05 22:01:044659 // TODO(jhawkins): Use FormManager once we have strict ordering of form
4660 // control elements in the cache.
4661 WebVector<WebFormElement> web_forms;
4662 frame->forms(web_forms);
4663
[email protected]b1438212010-04-03 00:30:594664 std::vector<FormData> forms;
[email protected]b715f7f2010-04-05 22:01:044665 for (size_t i = 0; i < web_forms.size(); ++i) {
4666 const WebFormElement& web_form = web_forms[i];
4667
4668 FormData form;
4669 FormManager::RequirementsMask requirements =
[email protected]b1438212010-04-03 00:30:594670 static_cast<FormManager::RequirementsMask>(
4671 FormManager::REQUIRE_AUTOCOMPLETE |
4672 FormManager::REQUIRE_ELEMENTS_ENABLED);
[email protected]b715f7f2010-04-05 22:01:044673 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:094674 web_form, requirements, false, &form))
[email protected]b715f7f2010-04-05 22:01:044675 forms.push_back(form);
4676 }
[email protected]e6efd022010-03-31 09:34:504677
4678 if (!forms.empty())
4679 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
[email protected]e9e07992010-02-17 21:04:364680}
4681
[email protected]a3018be2010-03-09 04:28:484682void RenderView::didChangeAccessibilityObjectState(
4683 const WebKit::WebAccessibilityObject& acc_obj) {
4684#if defined(OS_WIN)
4685 // TODO(dglazkov): Current logic implies that a state change can only be made
4686 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4687 // where accessibility is initialized. We should determine whether that's
4688 // right.
4689 if (!accessibility_.get())
4690 return;
4691
4692 // Retrieve the accessibility object id of the AccessibilityObject.
4693 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4694
4695 // If id is valid, alert the browser side that an accessibility object state
4696 // change occurred.
4697 if (acc_obj_id >= 0)
4698 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4699 acc_obj_id));
4700
4701#else // defined(OS_WIN)
4702 // TODO(port): accessibility not yet implemented
4703 NOTIMPLEMENTED();
4704#endif
4705}
4706
[email protected]daa8c58e2009-06-15 17:21:104707void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:484708 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454709 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104710
4711 std::vector<PasswordForm> password_forms;
4712 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484713 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104714
4715 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:484716 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:104717 scoped_ptr<PasswordForm> password_form(
4718 PasswordFormDomManager::CreatePasswordForm(form));
4719 if (password_form.get())
4720 password_forms.push_back(*password_form);
4721 }
4722 }
4723
4724 if (!password_forms.empty())
4725 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4726}
[email protected]0fda7272009-06-26 15:49:334727
4728void RenderView::Print(WebFrame* frame, bool script_initiated) {
4729 DCHECK(frame);
4730 if (print_helper_.get() == NULL) {
4731 print_helper_.reset(new PrintWebViewHelper(this));
4732 }
4733 print_helper_->Print(frame, script_initiated);
4734}
[email protected]446705872009-09-10 07:22:484735
4736void RenderView::OnSetEditCommandsForNextKeyEvent(
4737 const EditCommands& edit_commands) {
4738 edit_commands_ = edit_commands;
4739}
4740
[email protected]61f5a7b2009-12-22 22:21:204741void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274742 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354743 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204744 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4745 false));
[email protected]912256b32009-09-18 09:47:354746 return;
4747 }
4748
[email protected]fa7b6b542009-11-03 05:02:304749 WebDataSource* ds = main_frame->dataSource();
4750 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4751 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204752 pending_code_execution_queue_.push(
4753 linked_ptr<ViewMsg_ExecuteCode_Params>(
4754 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304755 return;
4756 }
4757
[email protected]61f5a7b2009-12-22 22:21:204758 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304759}
4760
4761void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204762 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484763 // Don't execute scripts in gallery pages.
4764 GURL frame_url = GURL(frame->url());
4765 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4766 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4767 return;
4768 }
4769
[email protected]20ad2692009-11-20 18:27:204770 std::vector<WebFrame*> frame_vector;
4771 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204772 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204773 GetAllChildFrames(frame, &frame_vector);
4774
4775 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4776 frame_it != frame_vector.end(); ++frame_it) {
4777 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204778 if (params.is_javascript) {
4779 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4780 continue;
4781
[email protected]20ad2692009-11-20 18:27:204782 std::vector<WebScriptSource> sources;
4783 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204784 WebScriptSource(WebString::fromUTF8(params.code)));
4785 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204786 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204787 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204788 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4789 } else {
[email protected]61f5a7b2009-12-22 22:21:204790 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204791 }
[email protected]912256b32009-09-18 09:47:354792 }
4793
[email protected]61f5a7b2009-12-22 22:21:204794 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354795}
4796
[email protected]60c42a8c72009-10-09 04:08:594797void RenderView::Close() {
4798 // We need to grab a pointer to the doomed WebView before we destroy it.
4799 WebView* doomed = webview();
4800 RenderWidget::Close();
4801 Singleton<ViewMap>::get()->erase(doomed);
4802}
4803
[email protected]446705872009-09-10 07:22:484804void RenderView::DidHandleKeyEvent() {
4805 edit_commands_.clear();
4806}
4807
[email protected]941e4552010-02-01 21:23:434808#if defined(OS_MACOSX)
4809void RenderView::OnWasHidden() {
4810 RenderWidget::OnWasHidden();
4811
4812 // Inform plugins that their container is no longer visible.
4813 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4814 for (plugin_it = plugin_delegates_.begin();
4815 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4816 (*plugin_it)->SetContainerVisibility(false);
4817 }
4818}
4819
4820void RenderView::OnWasRestored(bool needs_repainting) {
4821 RenderWidget::OnWasRestored(needs_repainting);
4822
4823 // Inform plugins that their container is now visible.
4824 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4825 for (plugin_it = plugin_delegates_.begin();
4826 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4827 (*plugin_it)->SetContainerVisibility(true);
4828 }
4829}
[email protected]1e6e3c992010-02-08 15:52:134830
4831void RenderView::OnSetFocus(bool enable) {
4832 RenderWidget::OnSetFocus(enable);
4833
4834 // RenderWidget's call to setFocus can cause the underlying webview's
4835 // activation state to change just like a call to setIsActive.
4836 if (enable && webview() && webview()->isActive()) {
4837 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4838 for (plugin_it = plugin_delegates_.begin();
4839 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4840 (*plugin_it)->SetWindowFocus(true);
4841 }
4842 }
4843}
[email protected]941e4552010-02-01 21:23:434844#endif // OS_MACOSX
4845
[email protected]83dde542009-09-11 20:59:554846void RenderView::EnsureDocumentTag() {
4847 // TODO(darin): There's actually no reason for this to be here. We should
4848 // have the browser side manage the document tag.
4849#if defined(OS_MACOSX)
4850 if (!has_document_tag_) {
4851 // Make the call to get the tag.
4852 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4853 has_document_tag_ = true;
4854 }
4855#endif
4856}
[email protected]12636df2009-09-28 22:32:214857
[email protected]43f28f832010-02-03 02:28:484858#if defined(OS_MACOSX)
4859gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle() {
4860 gfx::PluginWindowHandle window = NULL;
4861 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
4862 routing_id(), &window));
4863 return window;
4864}
4865
4866void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4867 if (window)
4868 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4869}
4870
[email protected]44ce0b12010-03-12 16:45:334871void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4872 int32 width,
4873 int32 height,
4874 uint64 io_surface_identifier) {
4875 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484876 routing_id(), window, width, height, io_surface_identifier));
4877}
4878
[email protected]44ce0b12010-03-12 16:45:334879void RenderView::AcceleratedSurfaceSetTransportDIB(
4880 gfx::PluginWindowHandle window,
4881 int32 width,
4882 int32 height,
4883 TransportDIB::Handle transport_dib) {
4884 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074885 routing_id(), window, width, height, transport_dib));
4886}
4887
[email protected]44ce0b12010-03-12 16:45:334888TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4889 size_t size) {
[email protected]1aef98132010-02-23 18:00:074890 TransportDIB::Handle dib_handle;
4891 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384892 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074893 return dib_handle;
4894 // Return an invalid handle if Send() fails.
4895 return TransportDIB::DefaultHandleValue();
4896}
4897
[email protected]44ce0b12010-03-12 16:45:334898void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074899 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4900}
4901
[email protected]44ce0b12010-03-12 16:45:334902void RenderView::AcceleratedSurfaceBuffersSwapped(
4903 gfx::PluginWindowHandle window) {
4904 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:484905}
4906#endif
[email protected]58c321d2010-02-19 12:11:284907
[email protected]cdaf8d02010-03-30 19:52:474908bool RenderView::ScheduleFileChooser(
4909 const ViewHostMsg_RunFileChooser_Params& params,
4910 WebFileChooserCompletion* completion) {
4911 static const size_t kMaximumPendingFileChooseRequests = 4;
4912 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4913 // This sanity check prevents too many file choose requests from getting
4914 // queued which could DoS the user. Getting these is most likely a
4915 // programming error (there are many ways to DoS the user so it's not
4916 // considered a "real" security check), either in JS requesting many file
4917 // choosers to pop up, or in a plugin.
4918 //
4919 // TODO(brettw) we might possibly want to require a user gesture to open
4920 // a file picker, which will address this issue in a better way.
4921 return false;
4922 }
4923
4924 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4925 new PendingFileChooser(params, completion)));
4926 if (file_chooser_completions_.size() == 1) {
4927 // Actually show the browse dialog when this is the first request.
4928 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4929 }
4930 return true;
4931}
4932
[email protected]8a5f7002010-03-31 13:47:354933WebKit::WebGeolocationService* RenderView::geolocationService() {
4934
[email protected]58c321d2010-02-19 12:11:284935 if (!geolocation_dispatcher_.get())
4936 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
4937 return geolocation_dispatcher_.get();
4938}
[email protected]61c9f032010-03-31 23:04:194939
4940bool RenderView::ShouldRouteNavigationToBrowser(
4941 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
4942 // If the browser is interested, then give it a chance to look at top level
4943 // navigations
4944 if (!renderer_preferences_.browser_handles_top_level_requests)
4945 return false;
4946
4947 // Must be a top level frame.
4948 if (frame->parent() != NULL)
4949 return false;
4950
4951 // Skip if navigation is on the same page (using '#').
4952 GURL frame_origin = GURL(frame->url()).GetOrigin();
4953 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
4954 // The link click could stay on the same page, in cases where it sends some
4955 // parameters to the same URL.
4956 if (type == WebKit::WebNavigationTypeLinkClicked)
4957 return true;
4958
4959 if (last_top_level_navigation_page_id_ != page_id_ &&
4960 // Not interested in reloads.
4961 type != WebKit::WebNavigationTypeReload &&
4962 type != WebKit::WebNavigationTypeFormSubmitted) {
4963 return true;
4964 }
4965 }
4966 return false;
4967}