blob: 9dc64424258209d38a1b6f279f6e21bcd40a1c3f [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)
605 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
606 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48607 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
608 OnAutoFillFormDataFilled)
[email protected]2c4410d2009-05-06 23:46:22609 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
610 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00611 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27612 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37613 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
614 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16615 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14616 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25617 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
618 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10619 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
620 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51621 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53622 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
623 OnUpdateBrowserWindowId)
624 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
625 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56626 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34627 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14628#if defined(OS_MACOSX)
629 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13630 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14631#endif
[email protected]446705872009-09-10 07:22:48632 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33633 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35634 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
635 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33636 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
637 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42638 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02639 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]634a6f92008-12-01 21:39:31640
initial.commit09911bf2008-07-26 23:55:29641 // Have the super handle all other messages.
642 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
643 IPC_END_MESSAGE_MAP()
644}
645
initial.commit09911bf2008-07-26 23:55:29646void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27647 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29648 if (!main_frame)
649 return;
650
651 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45652 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29653 if (url.is_empty())
654 return;
655
656 if (size_.IsEmpty())
657 return; // Don't create an empty thumbnail!
658
659 ThumbnailScore score;
660 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02661 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15662 &thumbnail, &score))
663 return;
664
initial.commit09911bf2008-07-26 23:55:29665 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46666 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29667}
668
[email protected]30507922010-01-15 16:48:23669void RenderView::SendSnapshot() {
670 SkBitmap snapshot;
671 bool error = false;
672
673 WebFrame* main_frame = webview()->mainFrame();
674 if (!main_frame)
675 error = true;
676
677 if (!error && !CaptureSnapshot(webview(), &snapshot))
678 error = true;
679
680 DCHECK(error == snapshot.empty()) <<
681 "Snapshot should be empty on error, non-empty otherwise.";
682
683 // Send the snapshot to the browser process.
684 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
685}
686
[email protected]068637222009-01-29 16:58:07687void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29688 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58689 if (webview()) {
690 // If the user has selected text in the currently focused frame we print
691 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27692 if (webview()->focusedFrame()->hasSelection())
693 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58694 else
[email protected]26aa0482009-09-30 16:55:27695 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58696 }
initial.commit09911bf2008-07-26 23:55:29697}
698
[email protected]82270452009-06-19 15:58:01699void RenderView::OnPrintingDone(int document_cookie, bool success) {
700 // Ignoring document cookie here since only one print job can be outstanding
701 // per renderer and document_cookie is 0 when printing is successful.
702 DCHECK(print_helper_.get());
703 if (print_helper_.get() != NULL) {
704 print_helper_->DidFinishPrinting(success);
705 }
706}
707
initial.commit09911bf2008-07-26 23:55:29708void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
709 if (load_id != page_id_)
710 return; // this capture call is no longer relevant due to navigation
711 if (load_id == last_indexed_page_id_)
712 return; // we already indexed this page
713
714 if (!webview())
715 return;
716
[email protected]26aa0482009-09-30 16:55:27717 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29718 if (!main_frame)
719 return;
720
721 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45722 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29723 return;
724
725 // Don't index/capture pages that failed to load. This only checks the top
726 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45727 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28728 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29729 return;
730
731 if (!preliminary_capture)
732 last_indexed_page_id_ = load_id;
733
[email protected]a8a81292010-01-21 00:32:45734 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45735 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29736 if (url.is_empty())
737 return;
738
[email protected]a8a81292010-01-21 00:32:45739 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29740 std::wstring contents;
741 CaptureText(main_frame, &contents);
742 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45743 base::TimeTicks begin_time = base::TimeTicks::Now();
744 std::string language = DetermineTextLanguage(contents);
745 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
746 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52747
[email protected]a8a81292010-01-21 00:32:45748 // Send the text to the browser for indexing (the browser might decide not
749 // to index, if the URL is HTTPS for instance) and language discovery.
750 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
751 language));
[email protected]5c4266922009-07-10 16:41:27752 }
753
initial.commit09911bf2008-07-26 23:55:29754 // thumbnail
755 SendThumbnail();
756}
757
758void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
759 contents->clear();
760 if (!frame)
761 return;
762
763#ifdef TIME_TEXT_RETRIEVAL
764 double begin = time_util::GetHighResolutionTimeNow();
765#endif
766
767 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45768 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29769
770#ifdef TIME_TEXT_RETRIEVAL
771 double end = time_util::GetHighResolutionTimeNow();
772 char buf[128];
773 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
774 contents.size(), (end - begin)*1000);
775 OutputDebugStringA(buf);
776#endif
777
778 // When the contents are clipped to the maximum, we don't want to have a
779 // partial word indexed at the end that might have been clipped. Therefore,
780 // terminate the string at the last space to ensure no words are clipped.
781 if (contents->size() == kMaxIndexChars) {
782 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
783 if (last_space_index == std::wstring::npos)
784 return; // don't index if we got a huge block of text with no spaces
785 contents->resize(last_space_index);
786 }
787}
788
[email protected]8649fb32009-06-26 17:51:02789bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29790 int w,
791 int h,
792 SkBitmap* thumbnail,
793 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23794 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15795
[email protected]8649fb32009-06-26 17:51:02796 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23797
798 // Paint |view| into |canvas|.
799 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02800 return false;
[email protected]8649fb32009-06-26 17:51:02801
802 skia::BitmapPlatformDevice& device =
803 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
804
805 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29806
[email protected]cab34d6a2009-09-24 01:14:52807 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29808 float dest_aspect = dest_rect.width() / dest_rect.height();
809
810 // Get the src rect so that we can preserve the aspect ratio while filling
811 // the destination.
812 SkIRect src_rect;
813 if (src_bmp.width() < dest_rect.width() ||
814 src_bmp.height() < dest_rect.height()) {
815 // Source image is smaller: we clip the part of source image within the
816 // dest rect, and then stretch it to fill the dest rect. We don't respect
817 // the aspect ratio in this case.
818 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
819 static_cast<S16CPU>(dest_rect.height()));
820 score->good_clipping = false;
821 } else {
822 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
823 if (src_aspect > dest_aspect) {
824 // Wider than tall, clip horizontally: we center the smaller thumbnail in
825 // the wider screen.
826 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
827 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
828 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
829 score->good_clipping = false;
830 } else {
831 src_rect.set(0, 0, src_bmp.width(),
832 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
833 score->good_clipping = true;
834 }
835 }
836
[email protected]26aa0482009-09-30 16:55:27837 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29838
839 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02840 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29841
842 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14843 *thumbnail = skia::ImageOperations::Resize(
844 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29845
846 score->boring_score = CalculateBoringScore(thumbnail);
847
[email protected]30507922010-01-15 16:48:23848 HISTOGRAM_TIMES("Renderer4.Thumbnail",
849 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15850 return true;
initial.commit09911bf2008-07-26 23:55:29851}
852
[email protected]30507922010-01-15 16:48:23853bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
854 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29855
[email protected]30507922010-01-15 16:48:23856 skia::PlatformCanvas canvas;
857 if (!PaintViewIntoCanvas(view, canvas))
858 return false;
859
860 skia::BitmapPlatformDevice& device =
861 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
862
863 const SkBitmap& bitmap = device.accessBitmap(false);
864 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
865 return false;
866
867 HISTOGRAM_TIMES("Renderer4.Snapshot",
868 base::TimeTicks::Now() - beginning_time);
869 return true;
initial.commit09911bf2008-07-26 23:55:29870}
871
872void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
873 if (!webview())
874 return;
875
[email protected]3cc72b12010-03-18 23:03:00876 history_list_offset_ = params.current_history_list_offset;
877 history_list_length_ = params.current_history_list_length;
878
[email protected]8c785c62009-07-13 14:20:15879 if (devtools_agent_.get())
880 devtools_agent_->OnNavigate();
881
[email protected]422197532010-01-25 17:38:23882 if (notification_provider_.get())
883 notification_provider_->OnNavigate();
884
[email protected]a9f607e2009-10-23 19:59:27885 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26886
initial.commit09911bf2008-07-26 23:55:29887 AboutHandler::MaybeHandle(params.url);
888
[email protected]ecbf10d2010-02-18 13:03:29889 bool is_reload =
890 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
891 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29892
[email protected]26aa0482009-09-30 16:55:27893 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45894 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29895 // We cannot reload if we do not have any history state. This happens, for
896 // example, when recovering from a crash. Our workaround here is a bit of
897 // a hack since it means that reload after a crashed tab does not cause an
898 // end-to-end cache validation.
899 is_reload = false;
900 }
901
[email protected]77f17a82009-05-21 04:42:54902 // A navigation resulting from loading a javascript URL should not be treated
903 // as a browser initiated event. Instead, we want it to look as if the page
904 // initiated any load resulting from JS execution.
905 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30906 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00907 params.page_id,
908 params.pending_history_list_offset,
909 params.transition,
910 params.request_time);
[email protected]5e369672009-11-03 23:48:30911 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
912 // We're doing a load of a page that was restored from the last session.
913 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
914 // which can result in stale data for pages that are set to expire. We
915 // explicitly override that by setting the policy here so that as
916 // necessary we load from the network.
917 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
918 }
919 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54920 }
initial.commit09911bf2008-07-26 23:55:29921
[email protected]a7ccc4d2010-01-27 08:14:48922 NavigationState* navigation_state = pending_navigation_state_.get();
923
[email protected]04d3c6e2009-05-22 17:00:13924 // If we are reloading, then WebKit will use the history state of the current
925 // page, so we should just ignore any given history state. Otherwise, if we
926 // have history state, then we need to navigate to it, which corresponds to a
927 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55928 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48929 if (navigation_state)
930 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29931 bool ignore_cache = (params.navigation_type ==
932 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
933 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55934 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13935 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58936 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48937 if (navigation_state)
938 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45939 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17940 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13941 } else {
942 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28943 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29944
[email protected]e6f546c32009-07-01 17:12:55945 // A session history navigation should have been accompanied by state.
946 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13947
[email protected]dd7daa82009-08-10 05:46:45948 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55949 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13950
[email protected]726985e22009-06-18 21:09:28951 if (params.referrer.is_valid()) {
952 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
953 WebString::fromUTF8(params.referrer.spec()));
954 }
[email protected]04d3c6e2009-05-22 17:00:13955
[email protected]a7ccc4d2010-01-27 08:14:48956 if (navigation_state)
957 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45958 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50959 }
960
[email protected]77f17a82009-05-21 04:42:54961 // In case LoadRequest failed before DidCreateDataSource was called.
962 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29963}
964
965// Stop loading the current page
966void RenderView::OnStop() {
967 if (webview())
[email protected]b4bb2502009-10-01 22:35:27968 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:29969}
970
[email protected]ecbf10d2010-02-18 13:03:29971// Reload current focused frame.
972// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56973void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29974 if (webview() && webview()->focusedFrame()) {
975 // We always obey the cache (ignore_cache=false) here.
976 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
977 // a cache-ignoring reload of the frame.
978 webview()->focusedFrame()->reload(false);
979 }
[email protected]1dda4022010-01-28 18:24:56980}
981
[email protected]e6f546c32009-07-01 17:12:55982void RenderView::OnLoadAlternateHTMLText(const std::string& html,
initial.commit09911bf2008-07-26 23:55:29983 bool new_navigation,
984 const GURL& display_url,
985 const std::string& security_info) {
986 if (!webview())
987 return;
988
[email protected]e6f546c32009-07-01 17:12:55989 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00990 new_navigation ? -1 : page_id_,
991 history_list_offset_,
992 PageTransition::LINK,
993 Time::Now()));
[email protected]e6f546c32009-07-01 17:12:55994 pending_navigation_state_->set_security_info(security_info);
initial.commit09911bf2008-07-26 23:55:29995
[email protected]26aa0482009-09-30 16:55:27996 webview()->mainFrame()->loadHTMLString(
997 html, GURL(kUnreachableWebDataURL), display_url, !new_navigation);
[email protected]e6f546c32009-07-01 17:12:55998
999 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291000}
1001
1002void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271003 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291004}
1005
[email protected]68b1e922009-06-23 16:00:251006void RenderView::OnExecuteEditCommand(const std::string& name,
1007 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271008 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251009 return;
1010
[email protected]26aa0482009-09-30 16:55:271011 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451012 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251013}
1014
[email protected]b2abac72009-02-26 12:39:281015void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111016 DCHECK(!devtools_client_.get());
1017 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281018}
1019
initial.commit09911bf2008-07-26 23:55:291020void RenderView::OnUpdateTargetURLAck() {
1021 // Check if there is a targeturl waiting to be sent.
1022 if (target_url_status_ == TARGET_PENDING) {
1023 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1024 pending_target_url_));
1025 }
1026
1027 target_url_status_ = TARGET_NONE;
1028}
1029
1030void RenderView::OnUndo() {
1031 if (!webview())
1032 return;
1033
[email protected]26aa0482009-09-30 16:55:271034 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121035 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291036}
1037
1038void RenderView::OnRedo() {
1039 if (!webview())
1040 return;
1041
[email protected]26aa0482009-09-30 16:55:271042 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121043 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291044}
1045
1046void RenderView::OnCut() {
1047 if (!webview())
1048 return;
1049
[email protected]26aa0482009-09-30 16:55:271050 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121051 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291052}
1053
1054void RenderView::OnCopy() {
1055 if (!webview())
1056 return;
1057
[email protected]26aa0482009-09-30 16:55:271058 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121059 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291060}
1061
[email protected]c0cc3092009-09-12 08:27:271062#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351063void RenderView::OnCopyToFindPboard() {
1064 if (!webview())
1065 return;
1066
1067 // Since the find pasteboard supports only plain text, this can be simpler
1068 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271069 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351070 if (frame->hasSelection()) {
1071 string16 selection = frame->selectionAsText();
1072 RenderThread::current()->Send(
1073 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1074 }
1075
[email protected]afe3a1672009-11-17 19:04:121076 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351077}
[email protected]c0cc3092009-09-12 08:27:271078#endif
[email protected]a954bf72009-09-12 07:30:351079
initial.commit09911bf2008-07-26 23:55:291080void RenderView::OnPaste() {
1081 if (!webview())
1082 return;
1083
[email protected]26aa0482009-09-30 16:55:271084 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121085 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291086}
1087
[email protected]2a3a7762009-10-19 19:17:321088void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291089 if (!webview())
1090 return;
1091
[email protected]1ff7a032010-02-03 02:46:031092 WebFrame* frame = webview()->focusedFrame();
1093 if (!frame->hasSelection())
1094 frame->selectWordAroundCaret();
1095 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291096}
1097
[email protected]98324892009-09-09 21:16:051098void RenderView::OnAdvanceToNextMisspelling() {
1099 if (!webview())
1100 return;
[email protected]26aa0482009-09-30 16:55:271101 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051102 WebString::fromUTF8("AdvanceToNextMisspelling"));
1103}
1104
1105void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1106 if (!webview())
1107 return;
1108 // We need to tell the webView whether the spelling panel is visible or not so
1109 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261110 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271111 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051112 WebString::fromUTF8("ToggleSpellPanel"));
1113}
1114
[email protected]bbbd545c2008-12-15 20:18:041115void RenderView::OnToggleSpellCheck() {
1116 if (!webview())
1117 return;
1118
[email protected]26aa0482009-09-30 16:55:271119 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451120 frame->enableContinuousSpellChecking(
1121 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041122}
1123
initial.commit09911bf2008-07-26 23:55:291124void RenderView::OnDelete() {
1125 if (!webview())
1126 return;
1127
[email protected]26aa0482009-09-30 16:55:271128 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121129 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291130}
1131
1132void RenderView::OnSelectAll() {
1133 if (!webview())
1134 return;
1135
[email protected]26aa0482009-09-30 16:55:271136 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221137 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121138 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291139}
1140
1141void RenderView::OnSetInitialFocus(bool reverse) {
1142 if (!webview())
1143 return;
[email protected]26aa0482009-09-30 16:55:271144 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291145}
1146
1147///////////////////////////////////////////////////////////////////////////////
1148
[email protected]433819d2010-01-30 20:20:011149void RenderView::SetContentSettings(const ContentSettings& settings) {
1150 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011151}
1152
initial.commit09911bf2008-07-26 23:55:291153// Tell the embedding application that the URL of the active page has changed
1154void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451155 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291156 DCHECK(ds);
1157
[email protected]726985e22009-06-18 21:09:281158 const WebURLRequest& request = ds->request();
1159 const WebURLRequest& original_request = ds->originalRequest();
1160 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291161
[email protected]daa8c58e2009-06-15 17:21:101162 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1163 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291164
1165 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281166 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291167 params.is_post = false;
1168 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281169 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551170 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291171 // SSL state specified in the request takes precedence over the one in the
1172 // response.
1173 // So far this is only intended for error pages that are not expected to be
1174 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281175 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551176 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291177 } else {
[email protected]726985e22009-06-18 21:09:281178 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291179 }
1180
1181 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281182 if (ds->hasUnreachableURL()) {
1183 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291184 } else {
[email protected]726985e22009-06-18 21:09:281185 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291186 }
1187
[email protected]726985e22009-06-18 21:09:281188 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241189 params.should_update_history = !ds->hasUnreachableURL() &&
1190 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291191
[email protected]ce0e250d2009-10-23 21:00:351192 params.searchable_form_url = navigation_state->searchable_form_url();
1193 params.searchable_form_encoding =
1194 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291195
1196 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101197 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291198 if (password_form_data)
1199 params.password_form = *password_form_data;
1200
1201 params.gesture = navigation_gesture_;
1202 navigation_gesture_ = NavigationGestureUnknown;
1203
[email protected]dd7daa82009-08-10 05:46:451204 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291205 // Top-level navigation.
1206
[email protected]71b0d5d2010-02-15 05:43:071207 // Clear "block" flags for the new page. This needs to happen before any of
1208 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1209 // so that these functions can correctly detect that a piece of content
1210 // flipped from "not blocked" to "blocked".
1211 ClearBlockedContentSettings();
1212
[email protected]62d2a112010-04-07 00:53:021213 // Set content settings. Default them from the parent window if one exists.
1214 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011215 HostContentSettings::iterator host_content_settings =
1216 host_content_settings_.find(GURL(request.url()).host());
1217 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011218 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011219
1220 // These content settings were merely recorded transiently for this load.
1221 // We can erase them now. If at some point we reload this page, the
1222 // browser will send us new, up-to-date content settings.
1223 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401224 } else if (frame->opener()) {
1225 WebView* opener_view = frame->opener()->view();
1226 RenderView* opener = FromWebView(opener_view);
1227 SetContentSettings(opener->current_content_settings_);
[email protected]f85f0702010-01-30 09:31:011228 }
1229
[email protected]40bd6582009-12-04 23:49:511230 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011231 HostZoomLevels::iterator host_zoom =
[email protected]40bd6582009-12-04 23:49:511232 host_zoom_levels_.find(GURL(request.url()).host());
[email protected]f85f0702010-01-30 09:31:011233 if (host_zoom != host_zoom_levels_.end()) {
1234 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511235 // This zoom level was merely recorded transiently for this load. We can
1236 // erase it now. If at some point we reload this page, the browser will
1237 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011238 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511239 }
1240
initial.commit09911bf2008-07-26 23:55:291241 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551242 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291243
[email protected]daa8c58e2009-06-15 17:21:101244 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291245 if (!PageTransition::IsMainFrame(params.transition)) {
1246 // If the main frame does a load, it should not be reported as a subframe
1247 // navigation. This can occur in the following case:
1248 // 1. You're on a site with frames.
1249 // 2. You do a subframe navigation. This is stored with transition type
1250 // MANUAL_SUBFRAME.
1251 // 3. You navigate to some non-frame site, say, google.com.
1252 // 4. You navigate back to the page from step 2. Since it was initially
1253 // MANUAL_SUBFRAME, it will be that same transition type here.
1254 // We don't want that, because any navigation that changes the toplevel
1255 // frame should be tracked as a toplevel navigation (this allows us to
1256 // update the URL bar, etc).
1257 params.transition = PageTransition::LINK;
1258 }
1259
initial.commit09911bf2008-07-26 23:55:291260 // If we have a valid consumed client redirect source,
1261 // the page contained a client redirect (meta refresh, document.loc...),
1262 // so we set the referrer and transition to match.
1263 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041264 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291265 params.referrer = completed_client_redirect_src_;
1266 params.transition = static_cast<PageTransition::Type>(
1267 params.transition | PageTransition::CLIENT_REDIRECT);
1268 } else {
1269 // Bug 654101: the referrer will be empty on https->http transitions. It
1270 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281271 params.referrer = GURL(
1272 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291273 }
1274
[email protected]726985e22009-06-18 21:09:281275 string16 method = request.httpMethod();
1276 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291277 params.is_post = true;
1278
[email protected]c2a797d2009-09-21 16:46:321279 // Save some histogram data so we can compute the average memory used per
1280 // page load of the glyphs.
1281 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1282 webkit_glue::GetGlyphPageCount());
1283
[email protected]15cf526b2010-02-12 06:33:491284 // This message needs to be sent before any of allowScripts(),
1285 // allowImages(), allowPlugins() is called for the new page, so that when
1286 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1287 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291288 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1289 } else {
1290 // Subframe navigation: the type depends on whether this navigation
1291 // generated a new session history entry. When they do generate a session
1292 // history entry, it means the user initiated the navigation and we should
1293 // mark it as such. This test checks if this is the first time UpdateURL
1294 // has been called since WillNavigateToURL was called to initiate the load.
1295 if (page_id_ > last_page_id_sent_to_browser_)
1296 params.transition = PageTransition::MANUAL_SUBFRAME;
1297 else
1298 params.transition = PageTransition::AUTO_SUBFRAME;
1299
initial.commit09911bf2008-07-26 23:55:291300 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1301 }
1302
1303 last_page_id_sent_to_browser_ =
1304 std::max(last_page_id_sent_to_browser_, page_id_);
1305
1306 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101307 // we don't want the transition type to persist. Just clear it.
1308 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501309
[email protected]6c8afae52009-01-22 02:24:571310#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151311 if (accessibility_.get()) {
[email protected]17455962010-02-24 01:39:351312 // Remove accessibility info cache.
1313 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501314 }
[email protected]6c8afae52009-01-22 02:24:571315#else
[email protected]7d926f92009-03-03 14:26:541316 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571317#endif
initial.commit09911bf2008-07-26 23:55:291318}
1319
1320// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171321void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291322 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171323 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171324 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171325 routing_id_,
1326 page_id_,
1327 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1328 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171329 }
initial.commit09911bf2008-07-26 23:55:291330}
1331
1332void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401333 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291334 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271335 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291336 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301337 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291338 last_encoding_name_ = encoding_name;
1339
[email protected]e38f40152008-09-12 23:08:301340 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291341 }
1342}
1343
[email protected]f4d34b52008-11-24 23:05:011344// Sends the previous session history state to the browser so it will be saved
1345// before we navigate to a new page. This must be called *before* the page ID
1346// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291347void RenderView::UpdateSessionHistory(WebFrame* frame) {
1348 // If we have a valid page ID at this point, then it corresponds to the page
1349 // we are navigating away from. Otherwise, this is the first navigation, so
1350 // there is no past session history to record.
1351 if (page_id_ == -1)
1352 return;
1353
[email protected]ca948a22009-06-25 19:36:171354 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271355 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171356 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291357 return;
[email protected]ca948a22009-06-25 19:36:171358
1359 Send(new ViewHostMsg_UpdateState(
1360 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291361}
1362
[email protected]3d9689372009-09-10 04:29:171363void RenderView::OpenURL(
1364 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1365 Send(new ViewHostMsg_OpenURL(
1366 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1367}
1368
[email protected]79dbc662009-09-04 05:42:511369// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291370
initial.commit09911bf2008-07-26 23:55:291371void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281372 const WebURLRequest& failed_request,
1373 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291374 const std::string& html,
1375 bool replace) {
[email protected]726985e22009-06-18 21:09:281376 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291377
1378 std::string alt_html;
1379 if (html.empty()) {
1380 // Use a local error page.
1381 int resource_id;
1382 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281383 if (error.reason == net::ERR_CACHE_MISS &&
1384 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291385 GetFormRepostErrorValues(failed_url, &error_strings);
1386 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1387 } else {
1388 GetLocalizedErrorValues(error, &error_strings);
1389 resource_id = IDR_NET_ERROR_HTML;
1390 }
initial.commit09911bf2008-07-26 23:55:291391
1392 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1393 } else {
1394 alt_html = html;
1395 }
1396
[email protected]dd7daa82009-08-10 05:46:451397 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551398 GURL(kUnreachableWebDataURL),
1399 failed_url,
1400 replace);
initial.commit09911bf2008-07-26 23:55:291401}
1402
[email protected]7ccddb8c2009-08-04 17:36:551403void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291404 dom_automation_controller_.set_message_sender(this);
1405 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551406 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291407 L"domAutomationController");
1408}
1409
initial.commit09911bf2008-07-26 23:55:291410bool RenderView::RunJavaScriptMessage(int type,
1411 const std::wstring& message,
1412 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071413 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291414 std::wstring* result) {
1415 bool success = false;
1416 std::wstring result_temp;
1417 if (!result)
1418 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291419
[email protected]12636df2009-09-28 22:32:211420 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1421 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291422 return success;
1423}
1424
[email protected]c1f50aa2010-02-18 03:46:571425bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1426 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1427 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1428 // it is particularly important that we do not call willEnterModalLoop as
1429 // that would defer resource loads for the dialog itself.
1430 if (RenderThread::current()) // Will be NULL during unit tests.
1431 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1432
1433 message->EnableMessagePumping(); // Runs a nested message loop.
1434 return Send(message);
1435}
1436
initial.commit09911bf2008-07-26 23:55:291437void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1438 if (!osd_url.is_empty())
1439 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1440 autodetected));
1441}
1442
[email protected]95056b582010-02-18 01:29:241443void RenderView::OnAutoFillSuggestionsReturned(
1444 int query_id,
[email protected]8f6e6582010-04-09 02:03:071445 const std::vector<string16>& values,
[email protected]95056b582010-02-18 01:29:241446 const std::vector<string16>& labels,
1447 int default_suggestion_index) {
1448 if (webview() && query_id == autofill_query_id_) {
1449 webview()->applyAutoFillSuggestions(
[email protected]8f6e6582010-04-09 02:03:071450 autofill_query_node_, values, labels, default_suggestion_index);
[email protected]95056b582010-02-18 01:29:241451 }
1452 autofill_query_node_.reset();
1453}
1454
1455void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a1f2009-10-16 03:53:391456 int query_id,
1457 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031458 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181459 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081460 webview()->applyAutocompleteSuggestions(
[email protected]acca2a1f2009-10-16 03:53:391461 autofill_query_node_, suggestions, default_suggestion_index);
1462 }
1463 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031464}
1465
[email protected]45c6e532010-03-15 23:51:241466void RenderView::OnAutoFillFormDataFilled(int query_id,
1467 const webkit_glue::FormData& form) {
[email protected]c83641732010-02-20 01:04:481468 if (query_id != autofill_query_id_)
1469 return;
1470
1471 form_manager_.FillForm(form);
1472}
1473
[email protected]2c4410d2009-05-06 23:46:221474void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311475 popup_notification_visible_ = visible;
1476}
1477
initial.commit09911bf2008-07-26 23:55:291478uint32 RenderView::GetCPBrowsingContext() {
1479 uint32 context = 0;
1480 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1481 return context;
1482}
1483
initial.commit09911bf2008-07-26 23:55:291484void RenderView::AddSearchProvider(const std::string& url) {
1485 AddGURLSearchProvider(GURL(url),
1486 false); // not autodetected
1487}
1488
[email protected]f103ab72009-09-02 17:10:591489void RenderView::OnMissingPluginStatus(
1490 WebPluginDelegateProxy* delegate,
1491 int status) {
[email protected]6c8afae52009-01-22 02:24:571492#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591493 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291494 // Show the InfoBar for the first available plugin.
1495 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591496 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291497 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1498 }
1499 } else {
1500 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1501 // to start the download/install.
1502 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1503 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1504 }
1505 }
[email protected]6c8afae52009-01-22 02:24:571506#else
1507 // TODO(port): plugins current not supported
1508 NOTIMPLEMENTED();
1509#endif
initial.commit09911bf2008-07-26 23:55:291510}
1511
[email protected]48c9cf2d2009-09-16 16:47:521512// WebKit::WebViewClient ------------------------------------------------------
1513
1514WebView* RenderView::createView(WebFrame* creator) {
1515 // Check to make sure we aren't overloading on popups.
1516 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1517 return NULL;
1518
1519 // This window can't be closed from a window.close() call until we receive a
1520 // message from the Browser process explicitly allowing it.
1521 popup_notification_visible_ = true;
1522
1523 int32 routing_id = MSG_ROUTING_NONE;
1524 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461525 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341526 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521527
[email protected]48c9cf2d2009-09-16 16:47:521528 render_thread_->Send(
[email protected]4e6419c2010-01-15 04:50:341529 new ViewHostMsg_CreateWindow(routing_id_, user_gesture,
1530 session_storage_namespace_id_,
1531 &routing_id,
1532 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211533 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521534 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521535
[email protected]48c9cf2d2009-09-16 16:47:521536 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421537 0,
[email protected]12636df2009-09-28 22:32:211538 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521539 renderer_preferences_,
1540 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211541 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341542 routing_id,
1543 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521544 view->opened_by_user_gesture_ = user_gesture;
1545
[email protected]007a848b2009-10-26 15:55:461546 // Record whether the creator frame is trying to suppress the opener field.
1547 view->opener_suppressed_ = opener_suppressed;
1548
[email protected]48c9cf2d2009-09-16 16:47:521549 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091550 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521551 if (!creator_url.is_valid() || !creator_url.IsStandard())
1552 creator_url = GURL();
1553 view->creator_url_ = creator_url;
1554
1555 // Copy over the alternate error page URL so we can have alt error pages in
1556 // the new render view (we don't need the browser to send the URL back down).
1557 view->alternate_error_page_url_ = alternate_error_page_url_;
1558
1559 return view->webview();
1560}
1561
[email protected]3e2b375b2010-04-07 17:03:121562WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521563 RenderWidget* widget = RenderWidget::Create(routing_id_,
1564 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121565 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521566 return widget->webwidget();
1567}
1568
1569WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1570 RenderWidget* widget = RenderWidget::Create(routing_id_,
1571 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121572 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521573 widget->ConfigureAsExternalPopupMenu(info);
1574 return widget->webwidget();
1575}
1576
[email protected]bd92c3a2010-01-13 05:02:341577WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1578 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1579 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291580 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1581 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1582 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341583}
1584
[email protected]48c9cf2d2009-09-16 16:47:521585void RenderView::didAddMessageToConsole(
1586 const WebConsoleMessage& message, const WebString& source_name,
1587 unsigned source_line) {
1588 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1589 UTF16ToWideHack(message.text),
1590 static_cast<int32>(source_line),
1591 UTF16ToWideHack(source_name)));
1592}
1593
1594void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581595 DCHECK(frame);
1596 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521597}
1598
1599void RenderView::didStartLoading() {
1600 if (is_loading_) {
1601 DLOG(WARNING) << "didStartLoading called while loading";
1602 return;
1603 }
1604
1605 is_loading_ = true;
1606 // Clear the pointer so that we can assign it only when there is an unknown
1607 // plugin on a page.
1608 first_default_plugin_.reset();
1609
1610 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1611}
1612
1613void RenderView::didStopLoading() {
1614 if (!is_loading_) {
1615 DLOG(WARNING) << "DidStopLoading called while not loading";
1616 return;
1617 }
1618
1619 is_loading_ = false;
1620
1621 // NOTE: For now we're doing the safest thing, and sending out notification
1622 // when done loading. This currently isn't an issue as the favicon is only
1623 // displayed when done loading. Ideally we would send notification when
1624 // finished parsing the head, but webkit doesn't support that yet.
1625 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271626 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521627 if (!favicon_url.is_empty())
1628 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1629
[email protected]26aa0482009-09-30 16:55:271630 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521631 true); // autodetected
1632
1633 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1634
[email protected]f9f4841b2010-03-20 05:41:421635 MessageLoop::current()->PostDelayedTask(
1636 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521637 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1638 false),
1639 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521640}
1641
[email protected]f55039a2010-02-17 14:12:061642bool RenderView::isSmartInsertDeleteEnabled() {
1643#if defined(OS_MACOSX)
1644 return true;
1645#else
1646 return false;
1647#endif
1648}
1649
[email protected]04fc9482009-09-18 22:13:031650bool RenderView::isSelectTrailingWhitespaceEnabled() {
1651#if defined(OS_WIN)
1652 return true;
1653#else
1654 return false;
1655#endif
1656}
1657
1658void RenderView::setInputMethodEnabled(bool enabled) {
1659 // Save the updated IME status and mark the input focus has been updated.
1660 // The IME status is to be sent to a browser process next time when
1661 // the input caret is rendered.
1662 if (!ime_control_busy_) {
1663 ime_control_updated_ = true;
1664 ime_control_new_state_ = enabled;
1665 }
1666}
1667
1668void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031669#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031670 if (!handling_input_event_)
1671 return;
1672 // TODO(estade): investigate incremental updates to the selection so that we
1673 // don't send the entire selection over IPC every time.
1674 if (!is_empty_selection) {
1675 // Sometimes we get repeated didChangeSelection calls from webkit when
1676 // the selection hasn't actually changed. We don't want to report these
1677 // because it will cause us to continually claim the X clipboard.
1678 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271679 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031680 if (this_selection == last_selection_)
1681 return;
1682
1683 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1684 this_selection));
1685 last_selection_ = this_selection;
1686 } else {
1687 last_selection_.clear();
1688 }
1689#endif
1690}
1691
1692void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121693 const std::string& name = UTF16ToUTF8(command_name);
1694 if (StartsWithASCII(name, "Move", true) ||
1695 StartsWithASCII(name, "Insert", true) ||
1696 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031697 return;
1698 UserMetricsRecordAction(name);
1699}
1700
[email protected]b2528b72009-09-24 06:57:101701bool RenderView::handleCurrentKeyboardEvent() {
1702 if (edit_commands_.empty())
1703 return false;
1704
[email protected]26aa0482009-09-30 16:55:271705 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101706 if (!frame)
1707 return false;
1708
1709 EditCommands::iterator it = edit_commands_.begin();
1710 EditCommands::iterator end = edit_commands_.end();
1711
[email protected]507b33ea2009-09-29 03:56:511712 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101713 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331714 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1715 // key (but it's the exception). Once one edit command is not executed, it
1716 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101717 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1718 WebString::fromUTF8(it->value)))
1719 break;
[email protected]507b33ea2009-09-29 03:56:511720 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101721 }
1722
[email protected]507b33ea2009-09-29 03:56:511723 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101724}
1725
[email protected]2a3a7762009-10-19 19:17:321726void RenderView::spellCheck(const WebString& text,
1727 int& misspelled_offset,
1728 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561729 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461730
[email protected]85c55dc2009-11-06 03:05:461731 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171732 RenderThread* thread = RenderThread::current();
1733 // Will be NULL during unit tests.
1734 if (thread) {
[email protected]c27324b2009-11-19 22:44:291735 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171736 word.c_str(), word.size(), document_tag_,
1737 &misspelled_offset, &misspelled_length, NULL);
1738 }
[email protected]1dbafaf72009-09-23 19:43:561739}
1740
1741WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321742 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561743 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261744 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561745 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171746 RenderThread* thread = RenderThread::current();
1747 // Will be NULL during unit tests.
1748 if (thread) {
1749 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291750 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171751 word, document_tag_);
1752 }
[email protected]1dbafaf72009-09-23 19:43:561753 }
[email protected]2a3a7762009-10-19 19:17:321754 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561755}
1756
[email protected]c49085c72009-10-02 16:28:561757void RenderView::showSpellingUI(bool show) {
1758 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1759}
1760
[email protected]8922e1f2009-10-03 05:01:261761bool RenderView::isShowingSpellingUI() {
1762 return spelling_panel_visible_;
1763}
1764
[email protected]1dbafaf72009-09-23 19:43:561765void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321766 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1767 word));
[email protected]1dbafaf72009-09-23 19:43:561768}
1769
[email protected]a1128322009-10-06 18:38:461770bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351771 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471772 WebFileChooserCompletion* chooser_completion) {
1773 ViewHostMsg_RunFileChooser_Params ipc_params;
1774 ipc_params.mode = params.multiSelect ?
1775 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1776 ViewHostMsg_RunFileChooser_Params::Open;
1777 ipc_params.title = params.title;
1778 ipc_params.default_file_name =
1779 webkit_glue::WebStringToFilePath(params.initialValue);
1780
1781 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461782}
1783
[email protected]48c9cf2d2009-09-16 16:47:521784void RenderView::runModalAlertDialog(
1785 WebFrame* frame, const WebString& message) {
1786 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1787 UTF16ToWideHack(message),
1788 std::wstring(),
1789 frame->url(),
1790 NULL);
1791}
1792
1793bool RenderView::runModalConfirmDialog(
1794 WebFrame* frame, const WebString& message) {
1795 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1796 UTF16ToWideHack(message),
1797 std::wstring(),
1798 frame->url(),
1799 NULL);
1800}
1801
1802bool RenderView::runModalPromptDialog(
1803 WebFrame* frame, const WebString& message, const WebString& default_value,
1804 WebString* actual_value) {
1805 std::wstring result;
1806 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1807 UTF16ToWideHack(message),
1808 UTF16ToWideHack(default_value),
1809 frame->url(),
1810 &result);
1811 if (ok)
1812 actual_value->assign(WideToUTF16Hack(result));
1813 return ok;
1814}
1815
1816bool RenderView::runModalBeforeUnloadDialog(
1817 WebFrame* frame, const WebString& message) {
1818 bool success = false;
1819 // This is an ignored return value, but is included so we can accept the same
1820 // response as RunJavaScriptMessage.
1821 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211822 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521823 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211824 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521825 return success;
1826}
1827
[email protected]79e37442009-10-09 18:17:441828void RenderView::showContextMenu(
1829 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291830 ContextMenuParams params = ContextMenuParams(data);
1831 if (!params.misspelled_word.empty() && RenderThread::current()) {
1832 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041833 bool spelled_right = RenderThread::current()->spellchecker()->
1834 SpellCheckWord(
1835 params.misspelled_word.c_str(), params.misspelled_word.size(),
1836 document_tag_,
1837 &misspelled_offset, &misspelled_length,
1838 &params.dictionary_suggestions);
1839 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291840 params.misspelled_word.clear();
1841 }
1842
1843 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441844}
1845
[email protected]48c9cf2d2009-09-16 16:47:521846void RenderView::setStatusText(const WebString& text) {
1847}
1848
[email protected]163f8242009-10-30 20:19:551849void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
1850 GURL latest_url = url.spec().empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521851 if (latest_url == target_url_)
1852 return;
[email protected]163f8242009-10-30 20:19:551853
[email protected]48c9cf2d2009-09-16 16:47:521854 // Tell the browser to display a destination link.
1855 if (target_url_status_ == TARGET_INFLIGHT ||
1856 target_url_status_ == TARGET_PENDING) {
1857 // If we have a request in-flight, save the URL to be sent when we
1858 // receive an ACK to the in-flight request. We can happily overwrite
1859 // any existing pending sends.
1860 pending_target_url_ = latest_url;
1861 target_url_status_ = TARGET_PENDING;
1862 } else {
1863 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1864 target_url_ = latest_url;
1865 target_url_status_ = TARGET_INFLIGHT;
1866 }
1867}
1868
[email protected]882daa92009-11-05 16:31:311869void RenderView::StartNavStateSyncTimerIfNecessary() {
1870 int delay;
1871 if (send_content_state_immediately_)
1872 delay = 0;
1873 else if (is_hidden())
1874 delay = kDelaySecondsForContentStateSyncHidden;
1875 else
1876 delay = kDelaySecondsForContentStateSync;
1877
1878 if (nav_state_sync_timer_.IsRunning()) {
1879 // The timer is already running. If the delay of the timer maches the amount
1880 // we want to delay by, then return. Otherwise stop the timer so that it
1881 // gets started with the right delay.
1882 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1883 return;
1884 nav_state_sync_timer_.Stop();
1885 }
1886
1887 nav_state_sync_timer_.Start(
1888 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1889}
1890
[email protected]163f8242009-10-30 20:19:551891void RenderView::setMouseOverURL(const WebURL& url) {
1892 mouse_over_url_ = GURL(url);
1893 UpdateTargetURL(mouse_over_url_, focus_url_);
1894}
1895
1896void RenderView::setKeyboardFocusURL(const WebURL& url) {
1897 focus_url_ = GURL(url);
1898 UpdateTargetURL(focus_url_, mouse_over_url_);
1899}
1900
[email protected]48c9cf2d2009-09-16 16:47:521901void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1902 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1903 hint));
1904}
1905
[email protected]49fd9da2010-03-17 21:00:471906void RenderView::startDragging(const WebPoint& from, const WebDragData& data,
1907 WebDragOperationsMask allowed_ops) {
[email protected]c27ae592010-03-18 15:24:411908 startDragging(data, allowed_ops, WebImage(), WebPoint());
1909}
1910
1911void RenderView::startDragging(const WebDragData& data,
1912 WebDragOperationsMask mask,
1913 const WebImage& image,
1914 const WebPoint& imageOffset) {
1915#if WEBKIT_USING_SKIA
1916 SkBitmap bitmap(image.getSkBitmap());
1917#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331918 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411919#endif
1920
[email protected]48c9cf2d2009-09-16 16:47:521921 Send(new ViewHostMsg_StartDragging(routing_id_,
1922 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411923 mask,
1924 bitmap,
1925 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521926}
1927
[email protected]28b92df2009-09-25 17:35:451928bool RenderView::acceptsLoadDrops() {
1929 return renderer_preferences_.can_accept_load_drops;
1930}
1931
[email protected]48c9cf2d2009-09-16 16:47:521932void RenderView::focusNext() {
1933 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1934}
1935
1936void RenderView::focusPrevious() {
1937 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1938}
1939
1940void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521941 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1942}
1943
1944int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001945 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521946}
1947
1948int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001949 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521950}
1951
[email protected]8922e1f2009-10-03 05:01:261952void RenderView::didUpdateInspectorSettings() {
1953 Send(new ViewHostMsg_UpdateInspectorSettings(
1954 routing_id_, webview()->inspectorSettings().utf8()));
1955}
1956
[email protected]acca2a1f2009-10-16 03:53:391957void RenderView::queryAutofillSuggestions(const WebNode& node,
1958 const WebString& name,
1959 const WebString& value) {
1960 static int query_counter = 0;
1961 autofill_query_id_ = query_counter++;
1962 autofill_query_node_ = node;
[email protected]e250e492010-04-06 21:35:361963
1964 const WebFormControlElement& element =
1965 node.toConstElement<WebFormControlElement>();
1966
1967 FormData form;
1968 if (!form_manager_.FindFormWithFormControlElement(element,
1969 FormManager::REQUIRE_NONE,
1970 &form))
1971 return;
1972
1973 // TODO(jhawkins): This is very slow. Add a label cache to FormManager.
1974 for (std::vector<FormField>::const_iterator iter = form.fields.begin();
1975 iter != form.fields.end(); ++iter) {
1976 if (iter->name() == element.nameForAutofill()) {
1977 Send(new ViewHostMsg_QueryFormFieldAutofill(
1978 routing_id_, autofill_query_id_, *iter));
1979 }
1980 }
[email protected]acca2a1f2009-10-16 03:53:391981}
1982
1983void RenderView::removeAutofillSuggestions(const WebString& name,
1984 const WebString& value) {
1985 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
1986}
1987
[email protected]c83641732010-02-20 01:04:481988void RenderView::didAcceptAutoFillSuggestion(
1989 const WebKit::WebNode& node,
[email protected]8f6e6582010-04-09 02:03:071990 const WebKit::WebString& value,
[email protected]c83641732010-02-20 01:04:481991 const WebKit::WebString& label) {
1992 static int query_counter = 0;
1993 autofill_query_id_ = query_counter++;
1994
[email protected]45c6e532010-03-15 23:51:241995 webkit_glue::FormData form;
[email protected]e6efd022010-03-31 09:34:501996 const WebInputElement element = node.toConstElement<WebInputElement>();
[email protected]b1438212010-04-03 00:30:591997 if (!form_manager_.FindFormWithFormControlElement(
1998 element, FormManager::REQUIRE_AUTOCOMPLETE, &form))
[email protected]c83641732010-02-20 01:04:481999 return;
2000
2001 Send(new ViewHostMsg_FillAutoFillFormData(
[email protected]8f6e6582010-04-09 02:03:072002 routing_id_, autofill_query_id_, form, value, label));
[email protected]c83641732010-02-20 01:04:482003}
2004
[email protected]79dbc662009-09-04 05:42:512005// WebKit::WebWidgetClient ----------------------------------------------------
2006
initial.commit09911bf2008-07-26 23:55:292007// We are supposed to get a single call to Show for a newly created RenderView
2008// that was created via RenderView::CreateWebView. So, we wait until this
2009// point to dispatch the ShowView message.
2010//
2011// This method provides us with the information about how to display the newly
2012// created RenderView (i.e., as a constrained popup or as a new tab).
2013//
[email protected]4873c7d2009-07-16 06:36:282014void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292015 DCHECK(!did_show_) << "received extraneous Show call";
2016 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2017
2018 if (did_show_)
2019 return;
2020 did_show_ = true;
2021
[email protected]28295ec2009-10-16 05:34:332022 // Force new windows to a popup if they were not opened with a user gesture.
2023 if (!opened_by_user_gesture_) {
2024 // We exempt background tabs for compat with older versions of Chrome.
2025 // TODO(darin): This seems bogus. These should have a user gesture, so
2026 // we probably don't need this check.
2027 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2028 policy = WebKit::WebNavigationPolicyNewPopup;
2029 }
2030
initial.commit09911bf2008-07-26 23:55:292031 // NOTE: initial_pos_ may still have its default values at this point, but
2032 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2033 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282034 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2035 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292036 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242037 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292038}
2039
[email protected]4873c7d2009-07-16 06:36:282040void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222041 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282042 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312043}
2044
[email protected]4873c7d2009-07-16 06:36:282045void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292046 DCHECK(did_show_) << "should already have shown the view";
2047
[email protected]c1f50aa2010-02-18 03:46:572048 // We must keep WebKit's shared timer running in this case in order to allow
2049 // showModalDialog to function properly.
2050 //
2051 // TODO(darin): WebKit should really be smarter about suppressing events and
2052 // timers so that we do not need to manage the shared timer in such a heavy
2053 // handed manner.
2054 //
2055 if (RenderThread::current()) // Will be NULL during unit tests.
2056 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2057
[email protected]12636df2009-09-28 22:32:212058 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292059}
2060
[email protected]3d9689372009-09-10 04:29:172061// WebKit::WebFrameClient -----------------------------------------------------
2062
2063WebPlugin* RenderView::createPlugin(
2064 WebFrame* frame, const WebPluginParams& params) {
2065 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2066}
2067
2068WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2069 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
2070}
2071
[email protected]9c00f002009-11-05 22:37:422072WebSharedWorker* RenderView::createSharedWorker(
2073 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372074 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422075
[email protected]30447b62009-11-13 01:13:372076 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512077 bool exists = false;
[email protected]30447b62009-11-13 01:13:372078 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512079 ViewHostMsg_CreateWorker_Params params;
2080 params.url = url;
2081 params.is_shared = true;
2082 params.name = name;
2083 params.document_id = document_id;
2084 params.render_view_route_id = routing_id_;
2085 params.route_id = MSG_ROUTING_NONE;
[email protected]30447b62009-11-13 01:13:372086 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512087 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372088 if (url_mismatch) {
2089 return NULL;
2090 } else {
2091 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492092 document_id,
[email protected]6de0bcf2010-02-17 22:00:512093 exists,
[email protected]30447b62009-11-13 01:13:372094 route_id,
2095 routing_id_);
2096 }
[email protected]9c00f002009-11-05 22:37:422097}
2098
[email protected]3d9689372009-09-10 04:29:172099WebMediaPlayer* RenderView::createMediaPlayer(
2100 WebFrame* frame, WebMediaPlayerClient* client) {
2101 scoped_refptr<media::FilterFactoryCollection> factory =
2102 new media::FilterFactoryCollection();
2103 // Add in any custom filter factories first.
2104 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2105 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2106 // Add the chrome specific audio renderer.
2107 factory->AddFactory(
2108 AudioRendererImpl::CreateFactory(audio_message_filter()));
2109 }
2110
[email protected]80f584d92010-01-21 03:59:042111 WebApplicationCacheHostImpl* appcache_host =
2112 WebApplicationCacheHostImpl::FromFrame(frame);
2113
[email protected]3d9689372009-09-10 04:29:172114 // TODO(hclam): obtain the following parameters from |client|.
2115 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2116 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152117 GURL(), // referrer
2118 "null", // frame origin
2119 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172120 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042121 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172122 routing_id());
2123
[email protected]0436b9a2009-10-23 00:23:052124 // A simple data source that keeps all data in memory.
2125 media::FilterFactory* simple_data_source_factory =
2126 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2127 bridge_factory);
2128 // A sophisticated data source that does memory caching.
2129 media::FilterFactory* buffered_data_source_factory =
2130 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2131 bridge_factory);
2132 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2133 factory->AddFactory(simple_data_source_factory);
2134 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172135 } else {
[email protected]0436b9a2009-10-23 00:23:052136 factory->AddFactory(buffered_data_source_factory);
2137 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172138 }
[email protected]8400e032010-02-26 18:50:112139
2140 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2141 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2142 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2143 } else {
[email protected]b57509eb2010-03-30 01:26:282144 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2145 factory_factory =
2146 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112147 }
2148
2149 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172150}
2151
[email protected]035545f2010-04-09 13:10:212152WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2153 WebFrame* frame, WebApplicationCacheHostClient* client) {
2154 return new RendererWebApplicationCacheHostImpl(
2155 FromWebView(frame->view()), client,
2156 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2157}
2158
[email protected]b921cfd22010-02-25 16:57:512159WebCookieJar* RenderView::cookieJar() {
2160 return &cookie_jar_;
2161}
2162
[email protected]3d9689372009-09-10 04:29:172163void RenderView::willClose(WebFrame* frame) {
2164 if (!frame->parent()) {
2165 const GURL& url = frame->url();
2166 if (url.SchemeIs("http") || url.SchemeIs("https"))
2167 DumpLoadHistograms();
2168 }
[email protected]fa7b6b542009-11-03 05:02:302169
2170 WebDataSource* ds = frame->dataSource();
2171 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2172 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172173}
2174
[email protected]684e4a42010-01-30 06:44:112175bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002176 if (!enabled_per_settings)
2177 return false;
[email protected]c21f1d52010-03-04 03:19:432178 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112179}
2180
2181bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002182 if (!enabled_per_settings)
2183 return false;
2184 if (!AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) {
2185 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2186 return false;
2187 }
2188 return true;
[email protected]684e4a42010-01-30 06:44:112189}
2190
[email protected]3d9689372009-09-10 04:29:172191void RenderView::loadURLExternally(
2192 WebFrame* frame, const WebURLRequest& request,
2193 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592194 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2195 if (policy == WebKit::WebNavigationPolicyDownload) {
2196 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2197 } else {
2198 OpenURL(request.url(), referrer, policy);
2199 }
[email protected]3d9689372009-09-10 04:29:172200}
2201
2202WebNavigationPolicy RenderView::decidePolicyForNavigation(
2203 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222204 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172205 // Webkit is asking whether to navigate to a new URL.
2206 // This is fine normally, except if we're showing UI from one security
2207 // context and they're trying to navigate to a different context.
2208 const GURL& url = request.url();
2209
2210 // If the browser is interested, then give it a chance to look at top level
2211 // navigations
[email protected]61c9f032010-03-31 23:04:192212 if (ShouldRouteNavigationToBrowser(url, frame, type)) {
2213 last_top_level_navigation_page_id_ = page_id_;
2214 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2215 OpenURL(url, referrer, default_policy);
2216 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172217 }
2218
2219 // A content initiated navigation may have originated from a link-click,
2220 // script, drag-n-drop operation, etc.
2221 bool is_content_initiated =
2222 NavigationState::FromDataSource(frame->provisionalDataSource())->
2223 is_content_initiated();
2224
2225 // We only care about navigations that are within the current tab (as opposed
2226 // to, for example, opening a new window).
2227 // But we sometimes navigate to about:blank to clear a tab, and we want to
2228 // still allow that.
2229 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2230 is_content_initiated && frame->parent() == NULL &&
2231 !url.SchemeIs(chrome::kAboutScheme)) {
2232 // When we received such unsolicited navigations, we sometimes want to
2233 // punt them up to the browser to handle.
2234 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
2235 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2236 frame->isViewSourceModeEnabled() ||
2237 url.SchemeIs(chrome::kViewSourceScheme) ||
2238 url.SchemeIs(chrome::kPrintScheme)) {
2239 OpenURL(url, GURL(), default_policy);
2240 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2241 }
2242 }
2243
2244 // Detect when a page is "forking" a new tab that can be safely rendered in
2245 // its own process. This is done by sites like Gmail that try to open links
2246 // in new windows without script connections back to the original page. We
2247 // treat such cases as browser navigations (in which we will create a new
2248 // renderer for a cross-site navigation), rather than WebKit navigations.
2249 //
2250 // We use the following heuristic to decide whether to fork a new page in its
2251 // own process:
2252 // The parent page must open a new tab to about:blank, set the new tab's
2253 // window.opener to null, and then redirect the tab to a cross-site URL using
2254 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462255 //
2256 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2257 // (see below).
[email protected]3d9689372009-09-10 04:29:172258 bool is_fork =
2259 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252260 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172261 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522262 historyBackListCount() < 1 &&
2263 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172264 // The parent page must have set the child's window.opener to null before
2265 // redirecting to the desired URL.
2266 frame->opener() == NULL &&
2267 // Must be a top-level frame.
2268 frame->parent() == NULL &&
2269 // Must not have issued the request from this page.
2270 is_content_initiated &&
2271 // Must be targeted at the current tab.
2272 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2273 // Must be a JavaScript navigation, which appears as "other".
2274 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462275
2276 // Recognize if this navigation is from a link with rel=noreferrer and
2277 // target=_blank attributes, in which case the opener will be suppressed. If
2278 // so, it is safe to load cross-site pages in a separate process, so we
2279 // should let the browser handle it.
2280 bool is_noreferrer_and_blank_target =
2281 // Frame should be top level and not yet navigated.
2282 frame->parent() == NULL &&
2283 frame->url().isEmpty() &&
2284 historyBackListCount() < 1 &&
2285 historyForwardListCount() < 1 &&
2286 // Links with rel=noreferrer will have no Referer field, and their
2287 // resulting frame will have its window.opener suppressed.
2288 // TODO(creis): should add a request.httpReferrer() method to help avoid
2289 // typos on the unusual spelling of Referer.
2290 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2291 opener_suppressed_ &&
2292 frame->opener() == NULL &&
2293 // Links with target=_blank will have no name.
2294 frame->name().isNull() &&
2295 // Another frame (with a non-empty creator) should have initiated the
2296 // request, targeted at this frame.
2297 !creator_url_.is_empty() &&
2298 is_content_initiated &&
2299 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2300 type == WebKit::WebNavigationTypeOther;
2301
2302 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172303 // Open the URL via the browser, not via WebKit.
2304 OpenURL(url, GURL(), default_policy);
2305 return WebKit::WebNavigationPolicyIgnore;
2306 }
2307
2308 return default_policy;
2309}
2310
[email protected]6069da8c2009-10-20 20:33:492311bool RenderView::canHandleRequest(
2312 WebFrame* frame, const WebURLRequest& request) {
2313 // We allow WebKit to think that everything can be handled even though
2314 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342315 return true;
2316}
2317
[email protected]6069da8c2009-10-20 20:33:492318WebURLError RenderView::cannotHandleRequestError(
2319 WebFrame* frame, const WebURLRequest& request) {
2320 NOTREACHED(); // Since we said we can handle all requests.
2321 return WebURLError();
2322}
2323
2324WebURLError RenderView::cancelledError(
2325 WebFrame* frame, const WebURLRequest& request) {
2326 WebURLError error;
2327 error.domain = WebString::fromUTF8(net::kErrorDomain);
2328 error.reason = net::ERR_ABORTED;
2329 error.unreachableURL = request.url();
2330 return error;
[email protected]7b7a7dc2009-10-19 02:23:342331}
2332
2333void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492334 WebFrame*, const WebURLError&) {
2335 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342336}
2337
[email protected]979c28b2009-11-07 01:30:482338void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172339 NavigationState* navigation_state =
2340 NavigationState::FromDataSource(frame->provisionalDataSource());
2341
2342 if (navigation_state->transition_type() == PageTransition::LINK)
2343 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2344
2345 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352346 WebSearchableFormData web_searchable_form_data(form);
2347 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2348 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212349 web_searchable_form_data.encoding().utf8());
[email protected]3d9689372009-09-10 04:29:172350 navigation_state->set_password_form_data(
2351 PasswordFormDomManager::CreatePasswordForm(form));
2352
[email protected]b1438212010-04-03 00:30:592353 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042354 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092355 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592356 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172357}
2358
2359void RenderView::willPerformClientRedirect(
2360 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2361 double fire_time) {
2362 // Ignore
2363}
2364
2365void RenderView::didCancelClientRedirect(WebFrame* frame) {
2366 // Ignore
2367}
2368
2369void RenderView::didCompleteClientRedirect(
2370 WebFrame* frame, const WebURL& from) {
2371 if (!frame->parent())
2372 completed_client_redirect_src_ = from;
2373}
2374
2375void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2376 // The rest of RenderView assumes that a WebDataSource will always have a
2377 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482378 bool content_initiated = !pending_navigation_state_.get();
2379 NavigationState* state = content_initiated ?
2380 NavigationState::CreateContentInitiated() :
2381 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182382 if (content_initiated) {
2383 switch (ds->request().cachePolicy()) {
2384 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2385 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2386 break;
2387 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2388 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2389 break;
2390 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2391 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2392 break;
2393 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2394 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2395 break;
2396 }
2397 }
[email protected]fa7b6b542009-11-03 05:02:302398
2399 state->set_user_script_idle_scheduler(
2400 new UserScriptIdleScheduler(this, frame));
2401 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172402}
2403
2404void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2405 WebDataSource* ds = frame->provisionalDataSource();
2406 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2407
2408 navigation_state->set_start_load_time(Time::Now());
2409
2410 // Update the request time if WebKit has better knowledge of it.
2411 if (navigation_state->request_time().is_null()) {
2412 double event_time = ds->triggeringEventTime();
2413 if (event_time != 0.0)
2414 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2415 }
2416
2417 bool is_top_most = !frame->parent();
2418 if (is_top_most) {
2419 navigation_gesture_ = frame->isProcessingUserGesture() ?
2420 NavigationGestureUnknown : NavigationGestureAuto;
2421
2422 // Make sure redirect tracking state is clear for the new load.
2423 completed_client_redirect_src_ = GURL();
2424 } else if (frame->parent()->isLoading()) {
2425 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002426 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172427 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2428 }
2429
2430 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2431 routing_id_, is_top_most, ds->request().url()));
2432}
2433
2434void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2435 if (frame->parent())
2436 return;
2437 // Received a redirect on the main frame.
2438 WebDataSource* data_source = frame->provisionalDataSource();
2439 if (!data_source) {
2440 // Should only be invoked when we have a data source.
2441 NOTREACHED();
2442 return;
2443 }
2444 std::vector<GURL> redirects;
2445 GetRedirectChain(data_source, &redirects);
2446 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512447 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2448 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172449 }
2450}
2451
[email protected]40bd6582009-12-04 23:49:512452void RenderView::didFailProvisionalLoad(WebFrame* frame,
2453 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172454 // Notify the browser that we failed a provisional load with an error.
2455 //
2456 // Note: It is important this notification occur before DidStopLoading so the
2457 // SSL manager can react to the provisional load failure before being
2458 // notified the load stopped.
2459 //
2460 WebDataSource* ds = frame->provisionalDataSource();
2461 DCHECK(ds);
2462
2463 const WebURLRequest& failed_request = ds->request();
2464
2465 bool show_repost_interstitial =
2466 (error.reason == net::ERR_CACHE_MISS &&
2467 EqualsASCII(failed_request.httpMethod(), "POST"));
2468 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2469 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2470 show_repost_interstitial));
2471
2472 // Don't display an error page if this is simply a cancelled load. Aside
2473 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2474 if (error.reason == net::ERR_ABORTED)
2475 return;
2476
2477 // Make sure we never show errors in view source mode.
2478 frame->enableViewSourceMode(false);
2479
2480 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2481
2482 // If this is a failed back/forward/reload navigation, then we need to do a
2483 // 'replace' load. This is necessary to avoid messing up session history.
2484 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2485 // as session history is concerned.
2486 //
2487 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2488 // the page id.
2489 //
2490 bool replace =
2491 navigation_state->pending_page_id() != -1 ||
2492 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2493
2494 // If we failed on a browser initiated request, then make sure that our error
2495 // page load is regarded as the same browser initiated request.
2496 if (!navigation_state->is_content_initiated()) {
2497 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2498 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002499 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172500 navigation_state->transition_type(),
2501 navigation_state->request_time()));
2502 }
2503
2504 // Provide the user with a more helpful error page?
2505 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2506 return;
2507
2508 // Fallback to a local error page.
2509 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2510 replace);
2511}
2512
2513void RenderView::didReceiveDocumentData(
2514 WebFrame* frame, const char* data, size_t data_len,
2515 bool& prevent_default) {
2516 NavigationState* navigation_state =
2517 NavigationState::FromDataSource(frame->dataSource());
2518 if (!navigation_state->postpone_loading_data())
2519 return;
2520
2521 // We're going to call commitDocumentData ourselves...
2522 prevent_default = true;
2523
2524 // Continue buffering the response data for the original 404 page. If it
2525 // grows too large, then we'll just let it through.
2526 navigation_state->append_postponed_data(data, data_len);
2527 if (navigation_state->postponed_data().size() >= 512) {
2528 navigation_state->set_postpone_loading_data(false);
2529 frame->commitDocumentData(navigation_state->postponed_data().data(),
2530 navigation_state->postponed_data().size());
2531 navigation_state->clear_postponed_data();
2532 }
2533}
2534
[email protected]40bd6582009-12-04 23:49:512535void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2536 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172537 NavigationState* navigation_state =
2538 NavigationState::FromDataSource(frame->dataSource());
2539
2540 navigation_state->set_commit_load_time(Time::Now());
2541 if (is_new_navigation) {
2542 // When we perform a new navigation, we need to update the previous session
2543 // history entry with state for the page we are leaving.
2544 UpdateSessionHistory(frame);
2545
2546 // We bump our Page ID to correspond with the new session history entry.
2547 page_id_ = next_page_id_++;
2548
[email protected]3cc72b12010-03-18 23:03:002549 // Advance our offset in session history, applying the length limit. There
2550 // is now no forward history.
2551 history_list_offset_++;
2552 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2553 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2554 history_list_length_ = history_list_offset_ + 1;
2555
[email protected]f9f4841b2010-03-20 05:41:422556 MessageLoop::current()->PostDelayedTask(
2557 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172558 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2559 page_id_, true),
2560 kDelayForForcedCaptureMs);
2561 } else {
2562 // Inspect the navigation_state on this frame to see if the navigation
2563 // corresponds to a session history navigation... Note: |frame| may or
2564 // may not be the toplevel frame, but for the case of capturing session
2565 // history, the first committed frame suffices. We keep track of whether
2566 // we've seen this commit before so that only capture session history once
2567 // per navigation.
2568 //
2569 // Note that we need to check if the page ID changed. In the case of a
2570 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2571 // previous URL and the current page ID, which would be wrong.
2572 if (navigation_state->pending_page_id() != -1 &&
2573 navigation_state->pending_page_id() != page_id_ &&
2574 !navigation_state->request_committed()) {
2575 // This is a successful session history navigation!
2576 UpdateSessionHistory(frame);
2577 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002578
2579 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172580 }
2581 }
2582
2583 // Remember that we've already processed this request, so we don't update
2584 // the session history again. We do this regardless of whether this is
2585 // a session history navigation, because if we attempted a session history
2586 // navigation without valid HistoryItem state, WebCore will think it is a
2587 // new navigation.
2588 navigation_state->set_request_committed(true);
2589
2590 UpdateURL(frame);
2591
2592 // If this committed load was initiated by a client redirect, we're
2593 // at the last stop now, so clear it.
2594 completed_client_redirect_src_ = GURL();
2595
2596 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272597 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172598}
2599
2600void RenderView::didClearWindowObject(WebFrame* frame) {
2601 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2602 BindDOMAutomationController(frame);
2603 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2604 dom_ui_bindings_.set_message_sender(this);
2605 dom_ui_bindings_.set_routing_id(routing_id_);
2606 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2607 }
2608 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2609 external_host_bindings_.set_message_sender(this);
2610 external_host_bindings_.set_routing_id(routing_id_);
2611 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2612 }
2613}
2614
2615void RenderView::didCreateDocumentElement(WebFrame* frame) {
2616 if (RenderThread::current()) { // Will be NULL during unit tests.
2617 RenderThread::current()->user_script_slave()->InjectScripts(
2618 frame, UserScript::DOCUMENT_START);
2619 }
[email protected]078b34612009-09-19 19:31:512620 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2621 view_type_ == ViewType::EXTENSION_MOLE) {
2622 InjectToolstripCSS();
2623 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2624 }
[email protected]3d9689372009-09-10 04:29:172625
2626 // Notify the browser about non-blank documents loading in the top frame.
2627 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252628 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272629 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172630 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2631 }
2632}
2633
2634void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2635 UpdateTitle(frame, title);
2636
2637 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272638 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172639}
2640
2641void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2642 WebDataSource* ds = frame->dataSource();
2643 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2644 DCHECK(navigation_state);
2645 navigation_state->set_finish_document_load_time(Time::Now());
2646
2647 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2648
[email protected]e9e07992010-02-17 21:04:362649 // The document has now been fully loaded. Scan for forms to be sent up to
2650 // the browser.
2651 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482652 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362653 SendForms(frame);
[email protected]3d9689372009-09-10 04:29:172654 SendPasswordForms(frame);
2655
2656 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272657 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172658
2659 if (RenderThread::current()) { // Will be NULL during unit tests.
2660 RenderThread::current()->user_script_slave()->InjectScripts(
2661 frame, UserScript::DOCUMENT_END);
2662 }
[email protected]fa7b6b542009-11-03 05:02:302663
2664 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2665}
2666
2667void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2668 if (RenderThread::current()) { // Will be NULL during unit tests.
2669 RenderThread::current()->user_script_slave()->InjectScripts(
2670 frame, UserScript::DOCUMENT_IDLE);
2671 }
2672
2673 WebFrame* main_frame = webview()->mainFrame();
2674 if (frame == main_frame) {
2675 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202676 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302677 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202678 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302679 pending_code_execution_queue_.pop();
2680 }
2681 }
[email protected]3d9689372009-09-10 04:29:172682}
2683
2684void RenderView::didHandleOnloadEvents(WebFrame* frame) {
2685 // Ignore
2686}
2687
2688void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2689 // Ignore
2690}
2691
2692void RenderView::didFinishLoad(WebFrame* frame) {
2693 WebDataSource* ds = frame->dataSource();
2694 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2695 DCHECK(navigation_state);
2696 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302697 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]3d9689372009-09-10 04:29:172698}
2699
[email protected]ccbe04e2010-03-17 17:58:432700void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172701 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062702
2703 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2704 // since a new one gets created by didCreateDataSource.
2705 NavigationState* state =
2706 NavigationState::FromDataSource(frame->dataSource());
2707 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2708
[email protected]3d9689372009-09-10 04:29:172709 // If this was a reference fragment navigation that we initiated, then we
2710 // could end up having a non-null pending navigation state. We just need to
2711 // update the ExtraData on the datasource so that others who read the
2712 // ExtraData will get the new NavigationState. Similarly, if we did not
2713 // initiate this navigation, then we need to take care to reset any pre-
2714 // existing navigation state to a content-initiated navigation state.
2715 // DidCreateDataSource conveniently takes care of this for us.
2716 didCreateDataSource(frame, frame->dataSource());
2717
[email protected]f6c2459d2010-02-24 22:34:062718 if (idle_scheduler_ran) {
2719 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2720 NavigationState* new_state =
2721 NavigationState::FromDataSource(frame->dataSource());
2722 new_state->user_script_idle_scheduler()->set_has_run(true);
2723 }
2724
[email protected]3d9689372009-09-10 04:29:172725 didCommitProvisionalLoad(frame, is_new_navigation);
2726
[email protected]26aa0482009-09-30 16:55:272727 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172728}
2729
[email protected]476b6f82009-09-10 21:00:592730void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312731 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592732}
2733
[email protected]3d9689372009-09-10 04:29:172734void RenderView::assignIdentifierToRequest(
2735 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2736 // Ignore
2737}
2738
[email protected]fa0a3432010-03-30 16:53:492739// Used in logMimeTypeForCrossOriginRequest(), remove when that function
2740// is removed
2741typedef base::hash_map<unsigned, WebURLRequest::TargetType> TargetTypeMap;
2742static TargetTypeMap target_type_map_;
2743typedef base::hash_map<std::string, int> MimeTypeMap;
2744static MimeTypeMap mime_type_map_;
2745
2746// Copied from net/base/mime_util.cc, supported_non_image_types[]
2747static const char* const cross_origin_mime_types_to_log[] = {
2748 "text/cache-manifest",
2749 "text/html",
2750 "text/xml",
2751 "text/xsl",
2752 "text/plain",
2753 "text/vnd.chromium.ftp-dir",
2754 "text/",
2755 "text/css",
2756 "image/svg+xml",
2757 "application/xml",
2758 "application/xhtml+xml",
2759 "application/rss+xml",
2760 "application/atom+xml",
2761 "application/json",
2762 "application/x-x509-user-cert",
2763 "multipart/x-mixed-replace"
2764};
2765
2766static void initMimeTypeMapIfNeeded() {
2767 if (!mime_type_map_.size()) {
2768 for (size_t i = 0; i < arraysize(cross_origin_mime_types_to_log); ++i)
2769 mime_type_map_[cross_origin_mime_types_to_log[i]] = i;
2770 }
2771}
2772
2773static void logMimeTypeForCrossOriginRequest(
2774 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
2775 initMimeTypeMapIfNeeded();
2776
2777 // Metrics to check the feasability of blocking cross-site requests
2778 // a renderer shouldn't be making (in case we try to move cross-site frames
2779 // into their own process someday). We're erring on the side of counting more
2780 // mime-types then we strictly need (we'd only consider blocking cross-site
2781 // requests with types similar to HTML, XML, or JSON).
2782 // TODO(japhet): Make these more granular. We're ignoring all miscellaneous
2783 // subresource requests, not just the XHRs that might be allowed.
2784 // Also, we should make these metrics be based on something more accurate
2785 // than the mime type header, such as parsing or content sniffing.
2786 TargetTypeMap::iterator iter = target_type_map_.find(identifier);
2787 if (iter != target_type_map_.end()) {
2788 WebURLRequest::TargetType target_type = iter->second;
2789 target_type_map_.erase(iter);
2790 if (target_type != WebURLRequest::TargetIsMainFrame
2791 && target_type != WebURLRequest::TargetIsSubFrame
2792 && target_type != WebURLRequest::TargetIsSubResource
2793 && target_type != WebURLRequest::TargetIsObject
2794 && !frame->securityOrigin().canAccess(
2795 WebSecurityOrigin::create(response.url()))) {
2796 std::string mime_type = response.mimeType().utf8();
2797 MimeTypeMap::iterator mime_type_iter = mime_type_map_.find(mime_type);
2798 if (mime_type_iter != mime_type_map_.end()) {
2799 UMA_HISTOGRAM_ENUMERATION(
2800 "SiteIsolation.CrossSiteNonFrameResponse_MIME_Type",
2801 mime_type_iter->second, arraysize(cross_origin_mime_types_to_log));
2802 }
2803 }
2804 }
2805}
2806
[email protected]3d9689372009-09-10 04:29:172807void RenderView::willSendRequest(
2808 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2809 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302810 WebFrame* top_frame = frame->top();
2811 if (!top_frame)
2812 top_frame = frame;
2813 WebDataSource* data_source = top_frame->provisionalDataSource();
2814 if (!data_source)
2815 data_source = top_frame->dataSource();
2816 if (data_source) {
2817 NavigationState* state = NavigationState::FromDataSource(data_source);
2818 if (state && state->is_cache_policy_override_set())
2819 request.setCachePolicy(state->cache_policy_override());
2820 }
[email protected]3d9689372009-09-10 04:29:172821 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502822 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132823 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492824
2825 target_type_map_[identifier] = request.targetType();
[email protected]3d9689372009-09-10 04:29:172826}
2827
2828void RenderView::didReceiveResponse(
2829 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492830
2831 logMimeTypeForCrossOriginRequest(frame, identifier, response);
2832
[email protected]3d9689372009-09-10 04:29:172833 // Only do this for responses that correspond to a provisional data source
2834 // of the top-most frame. If we have a provisional data source, then we
2835 // can't have any sub-resources yet, so we know that this response must
2836 // correspond to a frame load.
2837 if (!frame->provisionalDataSource() || frame->parent())
2838 return;
2839
2840 // If we are in view source mode, then just let the user see the source of
2841 // the server's 404 error page.
2842 if (frame->isViewSourceModeEnabled())
2843 return;
2844
[email protected]f48013be2010-01-14 22:07:452845 // Record that this was a page loaded over SPDY.
2846 if (response.wasFetchedViaSPDY()) {
2847 NavigationState* navigation_state =
2848 NavigationState::FromDataSource(frame->provisionalDataSource());
2849 navigation_state->set_was_fetched_via_spdy(true);
2850 }
2851
2852 // Consider loading an alternate error page for 404 responses.
2853 if (response.httpStatusCode() != 404)
2854 return;
2855
[email protected]3d9689372009-09-10 04:29:172856 // Can we even load an alternate error page for this URL?
2857 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2858 return;
2859
2860 NavigationState* navigation_state =
2861 NavigationState::FromDataSource(frame->provisionalDataSource());
2862 navigation_state->set_postpone_loading_data(true);
2863 navigation_state->clear_postponed_data();
2864}
2865
2866void RenderView::didFinishResourceLoad(
2867 WebFrame* frame, unsigned identifier) {
2868 NavigationState* navigation_state =
2869 NavigationState::FromDataSource(frame->dataSource());
2870 if (!navigation_state->postpone_loading_data())
2871 return;
2872
2873 // The server returned a 404 and the content was < 512 bytes (which we
2874 // suppressed). Go ahead and fetch the alternate page content.
2875
2876 const GURL& frame_url = frame->url();
2877
2878 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2879 DCHECK(error_page_url.is_valid());
2880
2881 WebURLError original_error;
2882 original_error.unreachableURL = frame_url;
2883
2884 navigation_state->set_alt_error_page_fetcher(
2885 new AltErrorPageResourceFetcher(
2886 error_page_url, frame, original_error,
2887 NewCallback(this, &RenderView::AltErrorPageFinished)));
2888}
2889
2890void RenderView::didFailResourceLoad(
2891 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2892 // Ignore
2893}
2894
2895void RenderView::didLoadResourceFromMemoryCache(
2896 WebFrame* frame, const WebURLRequest& request,
2897 const WebURLResponse& response) {
2898 // Let the browser know we loaded a resource from the memory cache. This
2899 // message is needed to display the correct SSL indicators.
2900 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2901 routing_id_,
2902 request.url(),
[email protected]91733b62009-09-18 06:21:092903 frame->securityOrigin().toString().utf8(),
2904 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172905 response.securityInfo()));
2906}
2907
[email protected]6069da8c2009-10-20 20:33:492908void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292909 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2910}
2911
2912void RenderView::didRunInsecureContent(
2913 WebFrame* frame, const WebSecurityOrigin& origin) {
2914 Send(new ViewHostMsg_DidRunInsecureContent(
2915 routing_id_,
2916 origin.toString().utf8()));
2917}
2918
[email protected]7ea093ba2009-11-03 05:54:592919bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002920 if (enabled_per_settings)
2921 return AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
[email protected]7ea093ba2009-11-03 05:54:592922
2923 WebSecurityOrigin origin = frame->securityOrigin();
2924 if (origin.isEmpty())
2925 return false; // Uninitialized document?
2926
2927 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
2928 return true; // Browser UI elements should still work.
2929
2930 // If the scheme is ftp: or file:, an empty file name indicates a directory
2931 // listing, which requires JavaScript to function properly.
2932 GURL frame_url = frame->url();
2933 const char* kDirProtocols[] = { "ftp", "file" };
2934 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
2935 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
2936 return frame_url.SchemeIs(kDirProtocols[i]) &&
2937 frame_url.ExtractFileName().empty();
2938 }
2939 }
2940
2941 return false; // Other protocols fall through here.
2942}
2943
[email protected]0a1a45432010-03-31 08:09:452944bool RenderView::allowDatabase(
2945 WebFrame* frame, const WebString& name, const WebString& display_name,
2946 unsigned long estimated_size) {
2947 WebSecurityOrigin origin = frame->securityOrigin();
2948 if (origin.isEmpty())
2949 return false; // Uninitialized document?
2950
2951 bool result;
2952 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
2953 origin.toString().utf8(), name, display_name, estimated_size, &result)))
2954 return false;
2955 if (!result)
2956 DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES);
2957 return result;
2958}
[email protected]8934a3b2010-02-25 00:34:002959void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
2960 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
2961}
2962
[email protected]c21f1d52010-03-04 03:19:432963void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
2964 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
2965}
2966
[email protected]3d9689372009-09-10 04:29:172967void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2968 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2969}
2970
[email protected]0c882b282009-10-07 17:01:282971void RenderView::didCreateScriptContext(WebFrame* frame) {
2972 EventBindings::HandleContextCreated(frame, false);
2973}
2974
2975void RenderView::didDestroyScriptContext(WebFrame* frame) {
2976 EventBindings::HandleContextDestroyed(frame);
2977}
2978
2979void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2980 EventBindings::HandleContextCreated(frame, true);
2981}
2982
[email protected]fc86daa2010-03-30 23:52:532983void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
2984 WebFrame* target,
2985 bool cross_origin,
2986 const WebString& property_name,
2987 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:102988 // TODO(johnnyg): track the individual properties and repeat event_ids.
2989 if (cross_origin)
2990 cross_origin_access_count_++;
2991 else
2992 same_origin_access_count_++;
2993}
2994
[email protected]3d9689372009-09-10 04:29:172995void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142996 CheckPreferredSize();
2997}
2998
2999void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173000 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253001 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173002 // message.
[email protected]ab32b16c2009-10-16 14:57:253003 if (send_preferred_size_changes_) {
[email protected]dfca5acf2010-03-22 03:28:433004 if (!webview())
3005 return;
3006
[email protected]3d9689372009-09-10 04:29:173007 // WebCore likes to tell us things have changed even when they haven't, so
[email protected]ab32b16c2009-10-16 14:57:253008 // cache the width and height and only send the IPC message when we're sure
3009 // they're different.
[email protected]26aa0482009-09-30 16:55:273010 int width = webview()->mainFrame()->contentsPreferredWidth();
[email protected]440a52a2009-11-18 07:23:393011 int height = webview()->mainFrame()->documentElementScrollHeight();
[email protected]c27324b2009-11-19 22:44:293012
[email protected]ab32b16c2009-10-16 14:57:253013 if (width != preferred_size_.width() ||
[email protected]440a52a2009-11-18 07:23:393014 height != preferred_size_.height()) {
[email protected]ab32b16c2009-10-16 14:57:253015 preferred_size_.set_width(width);
[email protected]440a52a2009-11-18 07:23:393016 preferred_size_.set_height(height);
[email protected]ab32b16c2009-10-16 14:57:253017
[email protected]ab32b16c2009-10-16 14:57:253018 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3019 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173020 }
3021 }
3022}
3023
[email protected]143dcd592009-11-06 21:33:493024void RenderView::didChangeScrollOffset(WebFrame* frame) {
3025 StartNavStateSyncTimerIfNecessary();
3026}
3027
[email protected]8922e1f2009-10-03 05:01:263028void RenderView::reportFindInPageMatchCount(int request_id, int count,
3029 bool final_update) {
3030 // If we have a message that has been queued up, then we should just replace
3031 // it. The ACK from the browser will make sure it gets sent when the browser
3032 // wants it.
3033 if (queued_find_reply_message_.get()) {
3034 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3035 routing_id_,
3036 request_id,
3037 count,
3038 gfx::Rect(),
3039 -1, // Don't update active match ordinal.
3040 final_update);
3041 queued_find_reply_message_.reset(msg);
3042 } else {
3043 // Send the search result over to the browser process.
3044 Send(new ViewHostMsg_Find_Reply(
3045 routing_id_,
3046 request_id,
3047 count,
3048 gfx::Rect(),
3049 -1, // // Don't update active match ordinal.
3050 final_update));
3051 }
3052}
3053
3054void RenderView::reportFindInPageSelection(int request_id,
3055 int active_match_ordinal,
3056 const WebRect& selection_rect) {
3057 // Send the search result over to the browser process.
3058 Send(new ViewHostMsg_Find_Reply(routing_id_,
3059 request_id,
3060 -1,
3061 selection_rect,
3062 active_match_ordinal,
3063 false));
3064}
3065
[email protected]24a7f3c2010-03-25 08:26:493066void RenderView::ReportNoFindInPageResults(int request_id) {
3067 Send(new ViewHostMsg_Find_Reply(routing_id_,
3068 request_id,
3069 0,
3070 gfx::Rect(),
3071 0,
3072 true));
3073}
3074
[email protected]79dbc662009-09-04 05:42:513075// webkit_glue::WebPluginPageDelegate -----------------------------------------
3076
[email protected]f103ab72009-09-02 17:10:593077webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
3078 const GURL& url,
3079 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:593080 std::string* actual_mime_type) {
3081 if (!PluginChannelHost::IsListening())
3082 return NULL;
3083
3084 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:273085 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:593086 if (main_frame)
3087 policy_url = main_frame->url();
3088
3089 FilePath path;
[email protected]610c0892009-09-08 19:46:183090 render_thread_->Send(new ViewHostMsg_GetPluginPath(
3091 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:593092 if (path.value().empty())
3093 return NULL;
3094
3095 const std::string* mime_type_to_use;
3096 if (!actual_mime_type->empty())
3097 mime_type_to_use = actual_mime_type;
3098 else
3099 mime_type_to_use = &mime_type;
3100
[email protected]d2139662009-12-10 03:21:143101 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283102 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143103 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163104 const char kPepperPrefix[] = "pepper-";
3105 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143106 if (CommandLine::ForCurrentProcess()->
3107 HasSwitch(switches::kInternalPepper)) {
3108 in_process_plugin = true;
3109 use_pepper_host = true;
3110 } else {
3111 // In process Pepper plugins must be explicitly enabled.
3112 return NULL;
3113 }
[email protected]d7ce4272010-03-27 01:06:013114 } else if (CommandLine::ForCurrentProcess()->
3115 HasSwitch(switches::kInternalPDF) &&
3116 StartsWithASCII(*mime_type_to_use, "application/pdf", true)) {
3117 in_process_plugin = true;
3118 use_pepper_host = true;
[email protected]26e8d5e2009-10-13 02:47:163119 }
[email protected]d2139662009-12-10 03:21:143120 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463121 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3122 if (mime_type == "application/x-nacl-srpc") {
3123 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143124 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463125 }
3126 }
3127 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143128 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283129 WebPluginDelegatePepper* pepper_plugin =
3130 WebPluginDelegatePepper::Create(path, *mime_type_to_use,
3131 AsWeakPtr());
3132 current_pepper_plugins_.insert(pepper_plugin);
3133 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143134 } else {
[email protected]6876dff2010-01-15 19:38:093135#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143136 return WebPluginDelegateImpl::Create(
3137 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093138#else
[email protected]596b2c42010-01-14 20:40:433139 NOTIMPLEMENTED();
3140 return NULL;
[email protected]7b6616f2010-01-14 18:07:553141#endif
[email protected]6876dff2010-01-15 19:38:093142 }
[email protected]f103ab72009-09-02 17:10:593143 }
3144
[email protected]610c0892009-09-08 19:46:183145 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593146}
3147
3148void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033149#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593150 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3151 routing_id(), window));
3152#endif
3153}
3154
3155void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033156#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593157 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3158 routing_id(), window));
3159#endif
3160 CleanupWindowInPluginMoves(window);
3161}
3162
3163void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3164 SchedulePluginMove(move);
3165}
3166
3167void RenderView::DidStartLoadingForPlugin() {
3168 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523169 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593170}
3171
3172void RenderView::DidStopLoadingForPlugin() {
3173 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523174 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593175}
3176
3177void RenderView::ShowModalHTMLDialogForPlugin(
3178 const GURL& url,
3179 const gfx::Size& size,
3180 const std::string& json_arguments,
3181 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213182 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593183 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213184 json_retval));
[email protected]f103ab72009-09-02 17:10:593185}
3186
[email protected]b921cfd22010-02-25 16:57:513187WebCookieJar* RenderView::GetCookieJar() {
3188 return &cookie_jar_;
3189}
3190
initial.commit09911bf2008-07-26 23:55:293191void RenderView::SyncNavigationState() {
3192 if (!webview())
3193 return;
3194
[email protected]26aa0482009-09-30 16:55:273195 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173196 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293197 return;
[email protected]ca948a22009-06-25 19:36:173198
3199 Send(new ViewHostMsg_UpdateState(
3200 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293201}
3202
[email protected]b0950a72009-09-29 23:16:173203bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3204 // Make sure webview was not shut down.
3205 if (!webview())
3206 return false;
3207 // Create an image resource fetcher and assign it with a call back object.
3208 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273209 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173210 NewCallback(this, &RenderView::DidDownloadImage)));
3211 return true;
3212}
3213
3214void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293215 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173216 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473217 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3218 fetcher->id(),
3219 fetcher->image_url(),
3220 image.isNull(),
3221 image));
[email protected]b0950a72009-09-29 23:16:173222 // Dispose of the image fetcher.
3223 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3224 image_fetchers_.erase(fetcher);
3225 // We're in the callback from the ImageResourceFetcher, best to delay
3226 // deletion.
3227 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293228}
3229
[email protected]bf5c2ff392009-07-08 16:24:333230void RenderView::OnDownloadFavIcon(int id,
3231 const GURL& image_url,
3232 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343233 bool data_image_failed = false;
3234 if (image_url.SchemeIs("data")) {
3235 SkBitmap data_image = ImageFromDataUrl(image_url);
3236 data_image_failed = data_image.empty();
3237 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333238 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3239 data_image));
[email protected]f11ca0732009-04-11 00:09:343240 }
3241 }
3242
[email protected]bf5c2ff392009-07-08 16:24:333243 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173244 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333245 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3246 SkBitmap()));
3247 }
initial.commit09911bf2008-07-26 23:55:293248}
3249
[email protected]f11ca0732009-04-11 00:09:343250SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3251 std::string mime_type, char_set, data;
3252 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3253 // Decode the favicon using WebKit's image decoder.
3254 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3255 const unsigned char* src_data =
3256 reinterpret_cast<const unsigned char*>(&data[0]);
3257
3258 return decoder.Decode(src_data, data.size());
3259 }
3260 return SkBitmap();
3261}
3262
initial.commit09911bf2008-07-26 23:55:293263void RenderView::OnGetApplicationInfo(int page_id) {
3264 webkit_glue::WebApplicationInfo app_info;
3265 if (page_id == page_id_)
3266 webkit_glue::GetApplicationInfo(webview(), &app_info);
3267
3268 // Prune out any data URLs in the set of icons. The browser process expects
3269 // any icon with a data URL to have originated from a favicon. We don't want
3270 // to decode arbitrary data URLs in the browser process. See
3271 // http://b/issue?id=1162972
3272 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593273 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293274 app_info.icons.erase(app_info.icons.begin() + i);
3275 --i;
3276 }
3277 }
3278
3279 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3280}
3281
[email protected]7ccddb8c2009-08-04 17:36:553282GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293283 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553284 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293285 // If the URL that failed was secure, then the embedding web page was not
3286 // expecting a network attacker to be able to manipulate its contents. As
3287 // we fetch alternate error pages over HTTP, we would be allowing a network
3288 // attacker to manipulate the contents of the response if we tried to use
3289 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153290 return GURL();
initial.commit09911bf2008-07-26 23:55:293291 }
3292
3293 // Grab the base URL from the browser process.
3294 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153295 return GURL();
initial.commit09911bf2008-07-26 23:55:293296
3297 // Strip query params from the failed URL.
3298 GURL::Replacements remove_params;
3299 remove_params.ClearUsername();
3300 remove_params.ClearPassword();
3301 remove_params.ClearQuery();
3302 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553303 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503304 std::string spec_to_send = url_to_send.spec();
3305 // Notify link doctor of the url truncation by sending of "?" at the end.
3306 if (failed_url.has_query())
3307 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293308
3309 // Construct the query params to send to link doctor.
3310 std::string params(alternate_error_page_url_.query());
3311 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503312 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293313 params.append("&sourceid=chrome");
3314 params.append("&error=");
3315 switch (error_type) {
3316 case DNS_ERROR:
3317 params.append("dnserror");
3318 break;
3319
3320 case HTTP_404:
3321 params.append("http404");
3322 break;
3323
[email protected]5df266ac2008-10-15 19:50:133324 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333325 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133326 break;
3327
initial.commit09911bf2008-07-26 23:55:293328 default:
3329 NOTREACHED() << "unknown ErrorPageType";
3330 }
3331
3332 // OK, build the final url to return.
3333 GURL::Replacements link_doctor_params;
3334 link_doctor_params.SetQueryStr(params);
3335 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3336 return url;
3337}
3338
[email protected]24a7f3c2010-03-25 08:26:493339webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() {
3340 WebPlugin* plugin = webview()->mainFrame()->document().
3341 toElement<WebPluginDocument>().plugin();
3342 return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate();
3343}
3344
[email protected]6069da8c2009-10-20 20:33:493345void RenderView::OnFind(int request_id, const string16& search_text,
3346 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273347 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493348
3349 if (main_frame->document().isPluginDocument()) {
3350 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3351 if (options.findNext) {
3352 // Just navigate back/forward.
3353 delegate->SelectFindResult(options.forward);
3354 } else {
3355 if (delegate->SupportsFind()) {
3356 delegate->StartFind(UTF16ToUTF8(search_text),
3357 options.matchCase,
3358 request_id);
3359 } else {
3360 ReportNoFindInPageResults(request_id);
3361 }
3362 }
3363 return;
3364 }
3365
[email protected]b4bb2502009-10-01 22:35:273366 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273367 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293368 WebFrame* search_frame = focused_frame; // start searching focused frame.
3369
3370 bool multi_frame = (frame_after_main != main_frame);
3371
3372 // If we have multiple frames, we don't want to wrap the search within the
3373 // frame, so we check here if we only have main_frame in the chain.
3374 bool wrap_within_frame = !multi_frame;
3375
[email protected]b3f2b912009-04-09 16:18:523376 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293377 bool result = false;
3378
[email protected]7830da3e2009-11-06 16:27:263379 // If something is selected when we start searching it means we cannot just
3380 // increment the current match ordinal; we need to re-generate it.
3381 WebRange current_selection = focused_frame->selectionRange();
3382
initial.commit09911bf2008-07-26 23:55:293383 do {
[email protected]dd7daa82009-08-10 05:46:453384 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593385 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293386
3387 if (!result) {
3388 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223389 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293390
3391 // Find the next frame, but skip the invisible ones.
3392 do {
3393 // What is the next frame to search? (we might be going backwards). Note
3394 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593395 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273396 search_frame->traverseNext(true) :
3397 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453398 } while (!search_frame->hasVisibleContent() &&
3399 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293400
[email protected]884db412008-11-24 23:46:503401 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223402 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293403
3404 // If we have multiple frames and we have wrapped back around to the
3405 // focused frame, we need to search it once more allowing wrap within
3406 // the frame, otherwise it will report 'no match' if the focused frame has
3407 // reported matches, but no frames after the focused_frame contain a
3408 // match for the search word(s).
3409 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453410 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593411 request_id, search_text, options, true, // Force wrapping.
3412 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293413 }
3414 }
3415
[email protected]26aa0482009-09-30 16:55:273416 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293417 } while (!result && search_frame != focused_frame);
3418
[email protected]7830da3e2009-11-06 16:27:263419 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293420 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453421 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293422 } else {
3423 // If nothing is found, set result to "0 of 0", otherwise, set it to
3424 // "-1 of 1" to indicate that we found at least one item, but we don't know
3425 // yet what is active.
3426 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3427 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293428
[email protected]4f3dc372009-02-24 00:10:293429 // If we find no matches then this will be our last status update.
3430 // Otherwise the scoping effort will send more results.
3431 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293432
[email protected]4f3dc372009-02-24 00:10:293433 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403434 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593435 request_id,
[email protected]4f3dc372009-02-24 00:10:293436 match_count,
3437 selection_rect,
3438 ordinal,
3439 final_status_update));
initial.commit09911bf2008-07-26 23:55:293440
initial.commit09911bf2008-07-26 23:55:293441 // Scoping effort begins, starting with the mainframe.
3442 search_frame = main_frame;
3443
[email protected]dd7daa82009-08-10 05:46:453444 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293445
3446 do {
3447 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453448 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293449
3450 // We don't start another scoping effort unless at least one match has
3451 // been found.
3452 if (result) {
3453 // Start new scoping request. If the scoping function determines that it
3454 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453455 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593456 search_text,
3457 options,
initial.commit09911bf2008-07-26 23:55:293458 true); // reset the tickmarks
3459 }
3460
3461 // Iterate to the next frame. The frame will not necessarily scope, for
3462 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273463 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293464 } while (search_frame != main_frame);
3465 }
3466}
3467
[email protected]24a7f3c2010-03-25 08:26:493468void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3469 WebView* view = webview();
3470 if (!view)
3471 return;
3472
3473 WebDocument doc = view->mainFrame()->document();
3474 if (doc.isPluginDocument()) {
3475 GetDelegateForPluginDocument()->StopFind();
3476 return;
3477 }
3478
3479 bool clear_selection =
3480 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3481 if (clear_selection)
3482 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3483
3484 WebFrame* frame = view->mainFrame();
3485 while (frame) {
3486 frame->stopFinding(clear_selection);
3487 frame = frame->traverseNext(false);
3488 }
3489
3490 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3491 WebFrame* focused_frame = view->focusedFrame();
3492 if (focused_frame) {
3493 WebDocument doc = focused_frame->document();
3494 if (!doc.isNull()) {
3495 WebNode node = doc.focusedNode();
3496 if (!node.isNull())
3497 node.simulateClick();
3498 }
3499 }
3500 }
3501}
3502
3503void RenderView::OnFindReplyAck() {
3504 // Check if there is any queued up request waiting to be sent.
3505 if (queued_find_reply_message_.get()) {
3506 // Send the search result over to the browser process.
3507 Send(queued_find_reply_message_.get());
3508 queued_find_reply_message_.release();
3509 }
3510}
3511
[email protected]8c4cdd42010-01-12 21:31:133512// static
3513std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403514 // Text with less than 100 bytes will probably not provide good results.
3515 // Report it as unknown language.
3516 if (text.length() < 100)
3517 return kUnknownLanguageCode;
3518
[email protected]8c4cdd42010-01-12 21:31:133519 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133520 int num_languages = 0;
3521 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423522 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133523 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423524 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133525 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403526 if (is_reliable && cld_language != NUM_LANGUAGES &&
3527 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483528 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3529 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263530 // language code for tradtional Chinese among others.
3531 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3532 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3533 // for Simplified Chinese.
3534 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133535 }
[email protected]8c4cdd42010-01-12 21:31:133536 return language;
[email protected]7893a982010-01-07 23:25:523537}
3538
[email protected]8934a3b2010-02-25 00:34:003539bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353540 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003541 return current_content_settings_.settings[settings_type] !=
3542 CONTENT_SETTING_BLOCK;
3543}
3544
3545void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3546 if (!content_blocked_[settings_type]) {
3547 content_blocked_[settings_type] = true;
3548 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353549 }
[email protected]0de80162010-02-03 04:52:353550}
3551
[email protected]71b0d5d2010-02-15 05:43:073552void RenderView::ClearBlockedContentSettings() {
3553 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3554 content_blocked_[i] = false;
3555}
3556
initial.commit09911bf2008-07-26 23:55:293557void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3558 Send(new ViewHostMsg_DnsPrefetch(host_names));
3559}
3560
[email protected]40bd6582009-12-04 23:49:513561void RenderView::OnZoom(PageZoom::Function function) {
3562 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3563 return;
3564
[email protected]b03794d2010-03-26 19:57:523565 // Should we be saving zoom levels for plugins? It's not clear, so for now
3566 // don't.
3567 if (webview()->mainFrame()->document().isPluginDocument()) {
3568 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3569 int zoom;
3570 if (function == PageZoom::RESET) {
3571 zoom = 0;
3572 } else if (function == PageZoom::ZOOM_OUT) {
3573 zoom = -1;
3574 } else if (function == PageZoom::ZOOM_IN) {
3575 zoom = 1;
3576 } else {
3577 NOTREACHED();
[email protected]754bb3b2010-03-26 20:12:113578 return;
[email protected]b03794d2010-03-26 19:57:523579 }
3580 delegate->Zoom(zoom);
3581 return;
3582 }
3583
[email protected]40bd6582009-12-04 23:49:513584 int zoom_level = webview()->zoomLevel();
3585 int new_zoom_level = webview()->setZoomLevel(false,
3586 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3587
3588 // Tell the browser which host got zoomed so it can update the saved values.
3589 // Pages like the safe browsing interstitial can have empty hosts; don't
3590 // record those.
3591 std::string host(GURL(webview()->mainFrame()->url()).host());
3592 if (!host.empty())
3593 Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
3594}
3595
[email protected]f85f0702010-01-30 09:31:013596void RenderView::OnSetContentSettingsForLoadingHost(
3597 std::string host,
3598 const ContentSettings& content_settings) {
3599 host_content_settings_[host] = content_settings;
3600}
3601
[email protected]40bd6582009-12-04 23:49:513602void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
3603 int zoom_level) {
3604 host_zoom_levels_[host] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293605}
3606
[email protected]41fc0322009-09-04 22:23:403607void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273608 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293609}
3610
[email protected]a697f4c2009-09-14 22:30:183611void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273612 WebString no_encoding;
3613 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183614}
3615
[email protected]20ad2692009-11-20 18:27:203616bool RenderView::GetAllChildFrames(
3617 WebFrame* parent_frame,
3618 std::vector<WebFrame*>* frames_vector) const {
3619 if (!parent_frame)
3620 return false;
3621 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3622 child_frame = child_frame->nextSibling()) {
3623 frames_vector->push_back(child_frame);
3624 GetAllChildFrames(child_frame, frames_vector);
3625 }
3626 return true;
3627}
3628
[email protected]dd7daa82009-08-10 05:46:453629WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3630 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273631 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453632
3633 // xpath string can represent a frame deep down the tree (across multiple
3634 // frame DOMs).
3635 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3636 // should break into 2 xpaths
3637 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3638
[email protected]26aa0482009-09-30 16:55:273639 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453640
3641 std::wstring xpath_remaining = xpath;
3642 while (!xpath_remaining.empty()) {
3643 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3644 std::wstring xpath_child;
3645 if (delim_pos != std::wstring::npos) {
3646 xpath_child = xpath_remaining.substr(0, delim_pos);
3647 xpath_remaining.erase(0, delim_pos + 1);
3648 } else {
3649 xpath_remaining.swap(xpath_child);
3650 }
3651 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293652 }
3653
[email protected]dd7daa82009-08-10 05:46:453654 return frame;
initial.commit09911bf2008-07-26 23:55:293655}
3656
[email protected]f29acf52008-11-03 20:08:333657void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3658 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293659 WebFrame* web_frame = GetChildFrame(frame_xpath);
3660 if (!web_frame)
3661 return;
3662
[email protected]dd7daa82009-08-10 05:46:453663 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293664}
3665
[email protected]1810e132009-03-24 23:35:483666void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083667 const std::string& css,
3668 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483669 WebFrame* web_frame = GetChildFrame(frame_xpath);
3670 if (!web_frame)
3671 return;
3672
[email protected]ffaef0c2009-09-15 17:08:083673 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483674}
3675
[email protected]00c39612010-03-06 02:53:283676void RenderView::OnPepperPluginDestroy(
3677 WebPluginDelegatePepper* pepper_plugin) {
3678 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
3679 current_pepper_plugins_.find(pepper_plugin);
3680 if (found_pepper == current_pepper_plugins_.end()) {
3681 NOTREACHED();
3682 return;
3683 }
3684 current_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473685
3686 // The plugin could have been destroyed while it was waiting for a file
3687 // choose callback, so check all pending completion callbacks and NULL them.
3688 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3689 file_chooser_completions_.begin();
3690 i != file_chooser_completions_.end(); /* nothing */) {
3691 if ((*i)->completion == pepper_plugin) {
3692 // We NULL the first one instead of deleting it because the plugin might
3693 // be the one waiting for a file choose callback. If the callback later
3694 // comes, we don't want to send the result to the next callback in line.
3695 if (i == file_chooser_completions_.begin())
3696 (*i)->completion = NULL;
3697 else
3698 i = file_chooser_completions_.erase(i);
3699 } else {
3700 ++i;
3701 }
3702 }
[email protected]00c39612010-03-06 02:53:283703}
3704
initial.commit09911bf2008-07-26 23:55:293705void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3706 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333707 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293708}
3709
[email protected]1810e132009-03-24 23:35:483710void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083711 const std::string& css,
3712 const std::string& id) {
3713 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413714
3715 // Notify RenderViewHost that css has been inserted into the frame.
3716 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483717}
3718
[email protected]7ea066a2009-04-06 20:21:593719void RenderView::OnAddMessageToConsole(
3720 const string16& frame_xpath,
3721 const string16& message,
3722 const WebConsoleMessage::Level& level) {
3723 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593724 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453725 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293726}
3727
[email protected]81e63782009-02-27 19:35:093728void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3729 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293730}
3731
3732void RenderView::OnSetDOMUIProperty(const std::string& name,
3733 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093734 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293735 dom_ui_bindings_.SetProperty(name, value);
3736}
3737
3738void RenderView::OnReservePageIDRange(int size_of_range) {
3739 next_page_id_ += size_of_range + 1;
3740}
3741
[email protected]e80c73b2009-04-07 23:24:583742void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3743 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253744 bool ended,
3745 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033746 if (ended) {
[email protected]26aa0482009-09-30 16:55:273747 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033748 }
initial.commit09911bf2008-07-26 23:55:293749}
3750
3751void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273752 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293753}
3754
initial.commit09911bf2008-07-26 23:55:293755void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103756 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293757 webkit_glue::FillPasswordForm(this->webview(), form_data);
3758}
3759
3760void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583761 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253762 const gfx::Point& screen_point,
3763 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273764 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583765 drop_data.ToDragData(),
3766 drop_data.identity,
3767 client_point,
[email protected]1d9f4132009-09-08 17:29:253768 screen_point,
3769 ops);
initial.commit09911bf2008-07-26 23:55:293770
[email protected]1d9f4132009-09-08 17:29:253771 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293772}
3773
[email protected]e80c73b2009-04-07 23:24:583774void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253775 const gfx::Point& screen_point,
3776 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273777 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253778 client_point,
3779 screen_point,
3780 ops);
initial.commit09911bf2008-07-26 23:55:293781
[email protected]1d9f4132009-09-08 17:29:253782 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293783}
3784
3785void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273786 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293787}
3788
[email protected]e80c73b2009-04-07 23:24:583789void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3790 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273791 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293792}
3793
3794void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593795 webkit_preferences_ = prefs;
3796 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293797}
3798
3799void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3800 alternate_error_page_url_ = url;
3801}
3802
[email protected]a0c7153e2009-12-09 14:36:333803void RenderView::OnCustomContextMenuAction(unsigned action) {
3804 webview()->performCustomContextMenuAction(action);
3805}
3806
[email protected]d4a00a72010-01-29 01:44:423807void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:023808 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:423809 const std::string& source_lang,
3810 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:023811 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
3812 translate_script);
[email protected]d4a00a72010-01-29 01:44:423813}
3814
[email protected]85d252e2010-04-06 22:21:023815void RenderView::OnRevertTranslation(int page_id) {
3816 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:323817}
3818
initial.commit09911bf2008-07-26 23:55:293819void RenderView::OnInstallMissingPlugin() {
3820 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593821 if (first_default_plugin_)
3822 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293823}
3824
[email protected]cdaf8d02010-03-30 19:52:473825void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363826 // This could happen if we navigated to a different page before the user
3827 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473828 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363829 return;
3830
[email protected]cdaf8d02010-03-30 19:52:473831 WebVector<WebString> ws_file_names(paths.size());
3832 for (size_t i = 0; i < paths.size(); ++i)
3833 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463834
[email protected]cdaf8d02010-03-30 19:52:473835 if (file_chooser_completions_.front()->completion)
3836 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3837 file_chooser_completions_.pop_front();
3838
3839 // If there are more pending file chooser requests, schedule one now.
3840 if (!file_chooser_completions_.empty()) {
3841 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3842 file_chooser_completions_.front()->params));
3843 }
initial.commit09911bf2008-07-26 23:55:293844}
3845
3846void RenderView::OnEnableViewSourceMode() {
3847 if (!webview())
3848 return;
[email protected]26aa0482009-09-30 16:55:273849 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293850 if (!main_frame)
3851 return;
3852
[email protected]dd7daa82009-08-10 05:46:453853 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293854}
3855
[email protected]ab32b16c2009-10-16 14:57:253856void RenderView::OnEnablePreferredSizeChangedMode() {
3857 send_preferred_size_changes_ = true;
[email protected]e8014aa52010-03-03 14:30:063858
3859 if (ViewType::ShouldAutoResize(view_type_))
[email protected]d8a179c2010-01-31 00:58:143860 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3861 &RenderView::CheckPreferredSize);
[email protected]0666aef2009-05-13 19:48:083862}
3863
[email protected]cda45c02010-02-25 19:28:103864void RenderView::OnDisableScrollbarsForSmallWindows(
3865 const gfx::Size& disable_scrollbar_size_limit) {
3866 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3867}
3868
[email protected]80d96fa2009-06-10 22:34:513869void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3870 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373871 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:033872#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:413873 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3874 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463875 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323876
[email protected]644d77e2010-01-27 01:03:103877 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323878 webview()->setScrollbarColors(
3879 renderer_prefs.thumb_inactive_color,
3880 renderer_prefs.thumb_active_color,
3881 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103882 webview()->setSelectionColors(
3883 renderer_prefs.active_selection_bg_color,
3884 renderer_prefs.active_selection_fg_color,
3885 renderer_prefs.inactive_selection_bg_color,
3886 renderer_prefs.inactive_selection_fg_color);
3887 }
[email protected]7a74e102009-09-03 00:16:563888#endif
[email protected]80d96fa2009-06-10 22:34:513889}
3890
[email protected]952cb702009-10-07 05:50:283891void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3892 const WebMediaPlayerAction& action) {
3893 if (webview())
3894 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563895}
3896
[email protected]7b291f92009-08-14 05:43:533897void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513898 // When this is first set, the bindings aren't fully loaded. We only need
3899 // to call through this API after the page has already been loaded. It's
3900 // also called in didCreateDocumentElement to bootstrap.
3901 if (view_type_ != ViewType::INVALID) {
3902 if (type == ViewType::EXTENSION_MOLE ||
3903 type == ViewType::EXTENSION_TOOLSTRIP) {
3904 ExtensionProcessBindings::SetViewType(webview(), type);
3905 }
3906 }
[email protected]7b291f92009-08-14 05:43:533907 view_type_ = type;
3908}
3909
3910void RenderView::OnUpdateBrowserWindowId(int window_id) {
3911 browser_window_id_ = window_id;
3912}
3913
[email protected]266eb6f2008-09-30 23:56:503914void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253915 const webkit_glue::WebAccessibility::InParams& in_params,
3916 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573917#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153918 if (!accessibility_.get()) {
3919 // TODO(dglazkov): Once implemented for all ports, remove lazy
3920 // instantiation of accessibility_.
3921 accessibility_.reset(WebAccessibilityCache::create());
3922 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253923 }
[email protected]266eb6f2008-09-30 23:56:503924
[email protected]17455962010-02-24 01:39:353925 out_params->return_code =
3926 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3927 in_params,
3928 out_params);
[email protected]c7287a92009-11-04 20:06:153929
[email protected]6c8afae52009-01-22 02:24:573930#else // defined(OS_WIN)
3931 // TODO(port): accessibility not yet implemented
3932 NOTIMPLEMENTED();
3933#endif
[email protected]266eb6f2008-09-30 23:56:503934}
3935
[email protected]6a983b42009-03-20 20:12:253936void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573937#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153938 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503939 // If accessibility is not activated, ignore clearing message.
3940 return;
3941 }
[email protected]e846d0d2009-05-20 00:53:063942
[email protected]c7287a92009-11-04 20:06:153943 if (clear_all) {
3944 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503945 return;
[email protected]c7287a92009-11-04 20:06:153946 }
3947
3948 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063949
[email protected]6c8afae52009-01-22 02:24:573950#else // defined(OS_WIN)
3951 // TODO(port): accessibility not yet implemented
3952 NOTIMPLEMENTED();
3953#endif
[email protected]266eb6f2008-09-30 23:56:503954}
3955
initial.commit09911bf2008-07-26 23:55:293956void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3957 const GURL& page_url) {
3958 // Prepare list to storage all savable resource links.
3959 std::vector<GURL> resources_list;
3960 std::vector<GURL> referrers_list;
3961 std::vector<GURL> frames_list;
3962 webkit_glue::SavableResourcesResult result(&resources_list,
3963 &referrers_list,
3964 &frames_list);
3965
[email protected]dbeb3952009-10-13 18:01:183966 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3967 webview(),
3968 page_url,
3969 &result,
3970 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293971 // If something is wrong when collecting all savable resource links,
3972 // send empty list to embedder(browser) to tell it failed.
3973 referrers_list.clear();
3974 resources_list.clear();
3975 frames_list.clear();
3976 }
3977
3978 // Send result of all savable resource links to embedder.
3979 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3980 resources_list,
3981 referrers_list,
3982 frames_list));
3983}
3984
3985void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323986 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313987 const std::vector<FilePath>& local_paths,
3988 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073989
3990 // Convert std::vector of GURLs to WebVector<WebURL>
3991 WebVector<WebURL> weburl_links(links);
3992
3993 // Convert std::vector of std::strings to WebVector<WebString>
3994 WebVector<WebString> webstring_paths(local_paths.size());
3995 for (size_t i = 0; i < local_paths.size(); i++)
3996 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3997
3998 WebPageSerializer::serialize(webview()->mainFrame(),
3999 true, this, weburl_links, webstring_paths,
4000 webkit_glue::FilePathToWebString(
4001 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294002}
4003
[email protected]d9ec5c0f2009-12-23 11:55:074004void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4005 const WebCString& data,
4006 WebPageSerializerClient::PageSerializationStatus status) {
4007 Send(new ViewHostMsg_SendSerializedHtmlData(
4008 routing_id_,
4009 frame_url,
4010 data.data(),
4011 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294012}
4013
[email protected]04b4a6c2008-08-02 00:44:474014void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:274015 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474016 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294017}
4018
[email protected]eb6b87a2009-07-24 15:57:394019void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294020 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4021 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4022 // in the onunload handler from appearing. For now, we're bypassing that and
4023 // calling the FrameLoader's CloseURL method directly. This should be
4024 // revisited to avoid having two ways to close a page. Having a single way
4025 // to close that can run onunload is also useful for fixing
4026 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274027 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294028 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454029 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174030 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294031 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4032 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454033 if (url.SchemeIs(chrome::kHttpScheme) ||
4034 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294035 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294036 }
[email protected]26aa0482009-09-30 16:55:274037 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294038
[email protected]ab9eabac2010-03-16 16:54:104039 // Reset stats
4040 cross_origin_access_count_ = 0;
4041 same_origin_access_count_ = 0;
4042
[email protected]eb6b87a2009-07-24 15:57:394043 // Just echo back the params in the ACK.
4044 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294045}
4046
4047void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574048#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294049 gfx::NativeTheme::instance()->CloseHandles();
4050 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:284051 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:574052#else // defined(OS_WIN)
4053 // TODO(port): we don't support theming on non-Windows platforms yet
4054 NOTIMPLEMENTED();
4055#endif
initial.commit09911bf2008-07-26 23:55:294056}
4057
[email protected]28790922009-03-09 19:48:374058void RenderView::OnMessageFromExternalHost(const std::string& message,
4059 const std::string& origin,
4060 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154061 if (message.empty())
4062 return;
4063
[email protected]28790922009-03-09 19:48:374064 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4065 target);
[email protected]3ac14a052008-08-15 21:22:154066}
4067
[email protected]0aa55312008-10-17 21:53:084068void RenderView::OnDisassociateFromPopupCount() {
4069 if (decrement_shared_popup_at_destruction_)
4070 shared_popup_counter_->data--;
4071 shared_popup_counter_ = new SharedRenderViewCounter(0);
4072 decrement_shared_popup_at_destruction_ = false;
4073}
4074
[email protected]15d79e12009-08-02 19:23:454075bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4076 const WebURLError& error,
4077 bool replace) {
4078 // We only show alternate error pages in the main frame. They are
4079 // intended to assist the user when navigating, so there is not much
4080 // value in showing them for failed subframes. Ideally, we would be
4081 // able to use the TYPED transition type for this, but that flag is
4082 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454083 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454084 return false;
4085
4086 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374087 // connection failure.
[email protected]15d79e12009-08-02 19:23:454088 int ec = error.reason;
4089 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4090 ec != net::ERR_CONNECTION_FAILED &&
4091 ec != net::ERR_CONNECTION_REFUSED &&
4092 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374093 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454094 return false;
4095
4096 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554097 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454098 if (!error_page_url.is_valid())
4099 return false;
4100
4101 // Load an empty page first so there is an immediate response to the error,
4102 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454103 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454104 GURL(kUnreachableWebDataURL),
4105 error.unreachableURL,
4106 replace);
4107
4108 // Now, create a fetcher for the error page and associate it with the data
4109 // source we just created via the LoadHTMLString call. That way if another
4110 // navigation occurs, the fetcher will get destroyed.
4111 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454112 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454113 navigation_state->set_alt_error_page_fetcher(
4114 new AltErrorPageResourceFetcher(
4115 error_page_url, frame, error,
4116 NewCallback(this, &RenderView::AltErrorPageFinished)));
4117 return true;
4118}
4119
initial.commit09911bf2008-07-26 23:55:294120std::string RenderView::GetAltHTMLForTemplate(
4121 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394122 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294123 ResourceBundle::GetSharedInstance().GetRawDataResource(
4124 template_resource_id));
4125
4126 if (template_html.empty()) {
4127 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4128 return "";
4129 }
[email protected]7cd22a52009-07-14 00:40:254130
initial.commit09911bf2008-07-26 23:55:294131 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254132 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294133 template_html, &error_strings, "t");
4134}
[email protected]0e79b9e2009-02-13 04:20:484135
[email protected]15d79e12009-08-02 19:23:454136void RenderView::AltErrorPageFinished(WebFrame* frame,
4137 const WebURLError& original_error,
4138 const std::string& html) {
4139 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554140
4141 // If we failed to download the alternate error page, fall back to the
4142 // original error page if present. Otherwise, LoadNavigationErrorPage
4143 // will simply display a default error page.
4144 const std::string* html_to_load = &html;
4145 if (html.empty()) {
4146 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454147 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554148 html_to_load = &navigation_state->postponed_data();
4149 }
4150 LoadNavigationErrorPage(
4151 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454152}
4153
[email protected]30f75e62009-02-25 22:01:004154void RenderView::OnMoveOrResizeStarted() {
4155 if (webview())
[email protected]4605325d2010-02-08 23:46:044156 webview()->hideSuggestionsPopup();
[email protected]30f75e62009-02-25 22:01:004157}
4158
[email protected]30f75e62009-02-25 22:01:004159void RenderView::OnResize(const gfx::Size& new_size,
4160 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104161 if (webview()) {
[email protected]4605325d2010-02-08 23:46:044162 webview()->hideSuggestionsPopup();
[email protected]cda45c02010-02-25 19:28:104163
4164 if (send_preferred_size_changes_) {
4165 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4166 // either width or height, allow scroll bars.
4167 bool allow_scrollbars = (
4168 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244169 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104170 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4171 }
4172 }
4173
[email protected]30f75e62009-02-25 22:01:004174 RenderWidget::OnResize(new_size, resizer_rect);
4175}
[email protected]0aa477bd2009-03-23 22:21:434176
[email protected]00c39612010-03-06 02:53:284177void RenderView::DidInitiatePaint() {
4178 // Notify any pepper plugins that we started painting. The plugin "should"
4179 // never notified that we started painting, this is used for internal
4180 // bookkeeping only, so we know that the set can not change under us.
4181 for (std::set<WebPluginDelegatePepper*>::iterator i =
4182 current_pepper_plugins_.begin();
4183 i != current_pepper_plugins_.end(); ++i)
4184 (*i)->RenderViewInitiatedPaint();
4185}
4186
4187void RenderView::DidFlushPaint() {
4188 // Notify any pepper plugins that we painted. This will call into the plugin,
4189 // and we it may ask to close itself as a result. This will, in turn, modify
4190 // our set, possibly invalidating the iterator. So we iterate on a copy that
4191 // won't change out from under us.
4192 std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_;
4193 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4194 i != plugins.end(); ++i) {
4195 // The copy above makes sure our iterator is never invalid if some plugins
4196 // are destroyed. But some plugin may decide to close all of its views in
4197 // response to a paint in one of them, so we need to make sure each one is
4198 // still "current" before using it.
4199 if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end())
4200 (*i)->RenderViewFlushedPaint();
4201 }
4202
4203 WebFrame* main_frame = webview()->mainFrame();
4204
4205 // If we have a provisional frame we are between the start and commit stages
4206 // of loading and we don't want to save stats.
4207 if (!main_frame->provisionalDataSource()) {
4208 WebDataSource* ds = main_frame->dataSource();
4209 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4210 DCHECK(navigation_state);
4211
4212 Time now = Time::Now();
4213 if (navigation_state->first_paint_time().is_null()) {
4214 navigation_state->set_first_paint_time(now);
4215 }
4216 if (navigation_state->first_paint_after_load_time().is_null() &&
4217 !navigation_state->finish_load_time().is_null()) {
4218 navigation_state->set_first_paint_after_load_time(now);
4219 }
4220 }
4221}
4222
4223
[email protected]05d478752009-04-08 23:38:164224void RenderView::OnClearFocusedNode() {
4225 if (webview())
[email protected]26aa0482009-09-30 16:55:274226 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164227}
4228
[email protected]699ab0d2009-04-23 23:19:144229void RenderView::OnSetBackground(const SkBitmap& background) {
4230 if (webview())
[email protected]b4bb2502009-10-01 22:35:274231 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144232
4233 SetBackground(background);
4234}
4235
[email protected]8c66c5a2009-07-22 17:26:344236void RenderView::OnSetActive(bool active) {
4237 if (webview())
[email protected]b4bb2502009-10-01 22:35:274238 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264239
4240#if defined(OS_MACOSX)
4241 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4242 for (plugin_it = plugin_delegates_.begin();
4243 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4244 (*plugin_it)->SetWindowFocus(active);
4245 }
4246#endif
[email protected]8c66c5a2009-07-22 17:26:344247}
4248
[email protected]6ce7abc52010-02-02 18:40:144249#if defined(OS_MACOSX)
4250void RenderView::OnSetWindowVisibility(bool visible) {
4251 // Inform plugins that their container has changed visibility.
4252 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4253 for (plugin_it = plugin_delegates_.begin();
4254 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4255 (*plugin_it)->SetContainerVisibility(visible);
4256 }
4257}
[email protected]1e6e3c992010-02-08 15:52:134258
4259void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4260 gfx::Rect view_frame) {
4261 // Inform plugins that their window's frame has changed.
4262 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4263 for (plugin_it = plugin_delegates_.begin();
4264 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4265 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4266 }
4267}
[email protected]6ce7abc52010-02-02 18:40:144268#endif // OS_MACOSX
4269
[email protected]309d7a282009-03-24 09:18:274270void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584271 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394272 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324273 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474274 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394275 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4276 name,
4277 args,
4278 source_url,
4279 request_id,
[email protected]2f25d7b92009-06-10 00:06:474280 has_callback));
[email protected]309d7a282009-03-24 09:18:274281}
4282
[email protected]c6619182009-05-12 14:59:324283void RenderView::OnExtensionResponse(int request_id,
4284 bool success,
4285 const std::string& response,
4286 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354287 ExtensionProcessBindings::HandleResponse(
4288 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274289}
[email protected]c20210e62009-04-03 21:39:264290
[email protected]078b34612009-09-19 19:31:514291void RenderView::InjectToolstripCSS() {
4292 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4293 return;
4294
4295 static const base::StringPiece toolstrip_css(
4296 ResourceBundle::GetSharedInstance().GetRawDataResource(
4297 IDR_EXTENSION_TOOLSTRIP_CSS));
4298 std::string css = toolstrip_css.as_string();
4299 InsertCSS(L"", css, "ToolstripDefaultCSS");
4300}
4301
[email protected]7120f132009-07-20 21:05:374302void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494303 const ListValue& args,
4304 bool requires_incognito_access) {
4305 RendererExtensionBindings::Invoke(
4306 function_name, args, this, requires_incognito_access);
[email protected]7120f132009-07-20 21:05:374307}
4308
[email protected]e7e4f3c2009-04-21 15:24:084309// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264310//
[email protected]7a9b51f2009-06-29 21:28:294311// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:264312// The time points we keep are
4313// request: time document was requested by user
4314// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254315// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294316// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264317// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294318// first_paint: first paint performed
4319// first_paint_after_load: first paint performed after load is finished
4320// begin: request if it was user requested, start otherwise
4321//
[email protected]c20210e62009-04-03 21:39:264322// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:254323// request->start,
[email protected]7a9b51f2009-06-29 21:28:294324// start->commit,
4325// commit->finish_document,
4326// finish_document->finish,
4327// begin->commit,
4328// begin->finishDoc,
4329// begin->finish,
4330// begin->first_paint,
4331// begin->first_paint_after_load
4332// commit->finishDoc,
4333// commit->first_paint,
4334// commit->first_paint_after_load,
4335// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264336//
[email protected]e7e4f3c2009-04-21 15:24:084337// It's possible for the request time not to be set, if a client
4338// redirect had been done (the user never requested the page)
4339// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294340// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264341void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274342 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564343 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454344 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294345 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564346
[email protected]f9f4841b2010-03-20 05:41:424347 // If we've already dumped, do nothing.
4348 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294349 return;
[email protected]ed3fb032009-06-16 19:50:564350
[email protected]f9f4841b2010-03-20 05:41:424351 // Handle case where user hits "stop" or "back" before loading completely.
4352 bool abandoned_page = finish.is_null();
4353 if (abandoned_page) {
4354 finish = Time::Now();
4355 navigation_state->set_finish_load_time(finish);
4356 }
4357 UMA_HISTOGRAM_ENUMERATION("Renderer4.Abandoned", abandoned_page ? 1 : 0, 2);
4358
[email protected]f8999642009-10-27 21:39:424359 LogNavigationState(navigation_state, main_frame->dataSource());
4360
[email protected]a7ccc4d2010-01-27 08:14:484361 NavigationState::LoadType load_type = navigation_state->load_type();
4362 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184363 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484364
[email protected]ab9eabac2010-03-16 16:54:104365 // Site isolation metrics.
4366 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4367 cross_origin_access_count_);
4368 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4369 same_origin_access_count_);
4370
[email protected]7a9b51f2009-06-29 21:28:294371 Time request = navigation_state->request_time();
4372 Time start = navigation_state->start_load_time();
4373 Time commit = navigation_state->commit_load_time();
4374 Time finish_doc = navigation_state->finish_document_load_time();
4375 Time first_paint = navigation_state->first_paint_time();
4376 Time first_paint_after_load =
4377 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:264378
[email protected]7a9b51f2009-06-29 21:28:294379 Time begin;
4380 // Client side redirects will have no request time.
4381 if (request.is_null()) {
4382 begin = start;
4383 } else {
4384 begin = request;
4385 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084386 }
[email protected]7a9b51f2009-06-29 21:28:294387 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4388 UMA_HISTOGRAM_MEDIUM_TIMES(
4389 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4390 UMA_HISTOGRAM_MEDIUM_TIMES(
4391 "Renderer4.FinishDocToFinish", finish - finish_doc);
4392
4393 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484394
4395 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4396 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4397 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484398 TimeDelta begin_to_finish_doc = finish_doc - begin;
4399 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184400
4401 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4402 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4403 static const size_t kBeginToFinishBucketCount(100);
4404 TimeDelta begin_to_finish = finish_doc - begin;
4405 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4406 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4407
[email protected]a7ccc4d2010-01-27 08:14:484408 switch (load_type) {
4409 case NavigationState::UNDEFINED_LOAD:
4410 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4411 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4412 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184413 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4414 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4415 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484416 break;
4417 case NavigationState::RELOAD:
4418 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4419 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4420 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184421 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4422 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4423 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484424 break;
4425 case NavigationState::HISTORY_LOAD:
4426 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4427 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4428 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184429 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4430 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4431 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484432 break;
4433 case NavigationState::NORMAL_LOAD:
4434 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4435 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4436 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184437 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4438 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4439 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484440 break;
[email protected]4c1b6f0b2010-02-07 16:38:184441 case NavigationState::LINK_LOAD_NORMAL:
4442 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484443 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4444 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184445 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4446 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4447 kBeginToFinishBucketCount);
4448 break;
4449 case NavigationState::LINK_LOAD_RELOAD:
4450 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4451 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4452 kBeginToFinishDocBucketCount);
4453 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4454 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4455 kBeginToFinishBucketCount);
4456 break;
4457 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4458 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4459 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4460 kBeginToFinishDocBucketCount);
4461 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4462 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4463 kBeginToFinishBucketCount);
4464 break;
4465 case NavigationState::LINK_LOAD_CACHE_ONLY:
4466 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4467 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4468 kBeginToFinishDocBucketCount);
4469 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4470 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4471 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484472 break;
4473 default:
4474 break;
4475 }
4476
4477 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4478 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4479 if (use_dns_histogram) {
[email protected]f9f4841b2010-03-20 05:41:424480 UMA_HISTOGRAM_ENUMERATION(
4481 FieldTrial::MakeName("Renderer4.Abandoned", "DnsImpact"),
4482 abandoned_page ? 1 : 0, 2);
4483 UMA_HISTOGRAM_ENUMERATION(
4484 FieldTrial::MakeName("Renderer4.LoadType", "DnsImpact"),
[email protected]fd11f1752010-02-23 22:35:484485 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484486 switch (load_type) {
4487 case NavigationState::NORMAL_LOAD:
4488 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184489 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4490 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4491 kBeginToFinishBucketCount);
4492 break;
4493 case NavigationState::LINK_LOAD_NORMAL:
4494 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184495 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4496 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4497 kBeginToFinishBucketCount);
4498 break;
4499 case NavigationState::LINK_LOAD_RELOAD:
4500 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184501 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4502 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4503 kBeginToFinishBucketCount);
4504 break;
4505 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4506 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184507 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4508 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4509 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484510 break;
4511 default:
4512 break;
4513 }
4514 }
4515
4516 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4517 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4518 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484519 UMA_HISTOGRAM_ENUMERATION(
4520 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4521 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484522 switch (load_type) {
4523 case NavigationState::NORMAL_LOAD:
4524 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484525 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4526 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4527 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484528 break;
[email protected]4c1b6f0b2010-02-07 16:38:184529 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484530 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484531 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4532 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4533 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184534 break;
4535 case NavigationState::LINK_LOAD_RELOAD:
4536 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484537 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4538 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4539 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184540 break;
4541 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4542 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484543 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4544 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4545 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184546 break;
4547 case NavigationState::LINK_LOAD_CACHE_ONLY:
4548 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484549 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4550 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4551 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484552 break;
4553 default:
4554 break;
4555 }
4556 }
4557
4558 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4559 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184560 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4561 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484562 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4563 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4564 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4565 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544566
[email protected]0a32257a2009-07-09 18:10:414567 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4568 finish - start, kBeginToFinishMin,
4569 kBeginToFinishMax, kBeginToFinishBucketCount);
4570 if (!request.is_null())
4571 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4572 finish - request, kBeginToFinishMin,
4573 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544574
[email protected]7a9b51f2009-06-29 21:28:294575 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4576
4577 if (!first_paint.is_null()) {
4578 UMA_HISTOGRAM_MEDIUM_TIMES(
4579 "Renderer4.BeginToFirstPaint", first_paint - begin);
4580 UMA_HISTOGRAM_MEDIUM_TIMES(
4581 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264582 }
[email protected]7a9b51f2009-06-29 21:28:294583
4584 if (!first_paint_after_load.is_null()) {
4585 UMA_HISTOGRAM_MEDIUM_TIMES(
4586 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4587 UMA_HISTOGRAM_MEDIUM_TIMES(
4588 "Renderer4.CommitToFirstPaintAfterLoad",
4589 first_paint_after_load - commit);
4590 UMA_HISTOGRAM_MEDIUM_TIMES(
4591 "Renderer4.FinishToFirstPaintAfterLoad",
4592 first_paint_after_load - finish);
4593 }
4594
4595 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414596
4597 // Since there are currently no guarantees that renderer histograms will be
4598 // sent to the browser, we initiate a PostTask here to be sure that we send
4599 // the histograms we generated. Without this call, pages that don't have an
4600 // on-close-handler might generate data that is lost when the renderer is
4601 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484602 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4603 // should post when the onload is complete, so that it doesn't interfere with
4604 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414605 if (RenderThread::current()) {
4606 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134607 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414608 }
[email protected]c20210e62009-04-03 21:39:264609}
[email protected]e846d0d2009-05-20 00:53:064610
[email protected]f8999642009-10-27 21:39:424611void RenderView::LogNavigationState(const NavigationState* state,
4612 const WebDataSource* ds) const {
4613 // Because this function gets called on every page load,
4614 // take extra care to optimize it away if logging is turned off.
4615 if (logging::LOG_INFO < logging::GetMinLogLevel())
4616 return;
4617
4618 DCHECK(state);
4619 DCHECK(ds);
4620 GURL url(ds->request().url());
4621 Time start = state->start_load_time();
4622 Time finish = state->finish_load_time();
4623 // TODO(mbelshe): should we log more stats?
4624 LOG(INFO) << "PLT: "
4625 << (finish - start).InMilliseconds()
4626 << "ms "
4627 << url.spec();
4628}
4629
[email protected]cc0445f2009-10-13 16:09:084630void RenderView::focusAccessibilityObject(
4631 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064632#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154633 // TODO(dglazkov): Current logic implies that focus change can only be made
4634 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4635 // where accessibility is initialized. We should determine whether that's
4636 // right.
4637 if (!accessibility_.get())
4638 return;
[email protected]e846d0d2009-05-20 00:53:064639
4640 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154641 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064642
4643 // If id is valid, alert the browser side that an accessibility focus change
4644 // occurred.
4645 if (acc_obj_id >= 0)
4646 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4647
4648#else // defined(OS_WIN)
4649 // TODO(port): accessibility not yet implemented
4650 NOTIMPLEMENTED();
4651#endif
4652}
[email protected]daa8c58e2009-06-15 17:21:104653
[email protected]e9e07992010-02-17 21:04:364654void RenderView::SendForms(WebFrame* frame) {
[email protected]b715f7f2010-04-05 22:01:044655 // TODO(jhawkins): Use FormManager once we have strict ordering of form
4656 // control elements in the cache.
4657 WebVector<WebFormElement> web_forms;
4658 frame->forms(web_forms);
4659
[email protected]b1438212010-04-03 00:30:594660 std::vector<FormData> forms;
[email protected]b715f7f2010-04-05 22:01:044661 for (size_t i = 0; i < web_forms.size(); ++i) {
4662 const WebFormElement& web_form = web_forms[i];
4663
4664 FormData form;
4665 FormManager::RequirementsMask requirements =
[email protected]b1438212010-04-03 00:30:594666 static_cast<FormManager::RequirementsMask>(
4667 FormManager::REQUIRE_AUTOCOMPLETE |
4668 FormManager::REQUIRE_ELEMENTS_ENABLED);
[email protected]b715f7f2010-04-05 22:01:044669 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:094670 web_form, requirements, false, &form))
[email protected]b715f7f2010-04-05 22:01:044671 forms.push_back(form);
4672 }
[email protected]e6efd022010-03-31 09:34:504673
4674 if (!forms.empty())
4675 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
[email protected]e9e07992010-02-17 21:04:364676}
4677
[email protected]a3018be2010-03-09 04:28:484678void RenderView::didChangeAccessibilityObjectState(
4679 const WebKit::WebAccessibilityObject& acc_obj) {
4680#if defined(OS_WIN)
4681 // TODO(dglazkov): Current logic implies that a state change can only be made
4682 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4683 // where accessibility is initialized. We should determine whether that's
4684 // right.
4685 if (!accessibility_.get())
4686 return;
4687
4688 // Retrieve the accessibility object id of the AccessibilityObject.
4689 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4690
4691 // If id is valid, alert the browser side that an accessibility object state
4692 // change occurred.
4693 if (acc_obj_id >= 0)
4694 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4695 acc_obj_id));
4696
4697#else // defined(OS_WIN)
4698 // TODO(port): accessibility not yet implemented
4699 NOTIMPLEMENTED();
4700#endif
4701}
4702
[email protected]daa8c58e2009-06-15 17:21:104703void RenderView::SendPasswordForms(WebFrame* frame) {
[email protected]979c28b2009-11-07 01:30:484704 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454705 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104706
4707 std::vector<PasswordForm> password_forms;
4708 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484709 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104710
4711 // Respect autocomplete=off.
[email protected]979c28b2009-11-07 01:30:484712 if (form.autoComplete()) {
[email protected]daa8c58e2009-06-15 17:21:104713 scoped_ptr<PasswordForm> password_form(
4714 PasswordFormDomManager::CreatePasswordForm(form));
4715 if (password_form.get())
4716 password_forms.push_back(*password_form);
4717 }
4718 }
4719
4720 if (!password_forms.empty())
4721 Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms));
4722}
[email protected]0fda7272009-06-26 15:49:334723
4724void RenderView::Print(WebFrame* frame, bool script_initiated) {
4725 DCHECK(frame);
4726 if (print_helper_.get() == NULL) {
4727 print_helper_.reset(new PrintWebViewHelper(this));
4728 }
4729 print_helper_->Print(frame, script_initiated);
4730}
[email protected]446705872009-09-10 07:22:484731
4732void RenderView::OnSetEditCommandsForNextKeyEvent(
4733 const EditCommands& edit_commands) {
4734 edit_commands_ = edit_commands;
4735}
4736
[email protected]61f5a7b2009-12-22 22:21:204737void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274738 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354739 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204740 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4741 false));
[email protected]912256b32009-09-18 09:47:354742 return;
4743 }
4744
[email protected]fa7b6b542009-11-03 05:02:304745 WebDataSource* ds = main_frame->dataSource();
4746 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4747 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204748 pending_code_execution_queue_.push(
4749 linked_ptr<ViewMsg_ExecuteCode_Params>(
4750 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304751 return;
4752 }
4753
[email protected]61f5a7b2009-12-22 22:21:204754 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304755}
4756
4757void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204758 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484759 // Don't execute scripts in gallery pages.
4760 GURL frame_url = GURL(frame->url());
4761 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4762 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4763 return;
4764 }
4765
[email protected]20ad2692009-11-20 18:27:204766 std::vector<WebFrame*> frame_vector;
4767 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204768 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204769 GetAllChildFrames(frame, &frame_vector);
4770
4771 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4772 frame_it != frame_vector.end(); ++frame_it) {
4773 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204774 if (params.is_javascript) {
4775 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4776 continue;
4777
[email protected]20ad2692009-11-20 18:27:204778 std::vector<WebScriptSource> sources;
4779 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204780 WebScriptSource(WebString::fromUTF8(params.code)));
4781 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204782 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204783 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204784 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4785 } else {
[email protected]61f5a7b2009-12-22 22:21:204786 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204787 }
[email protected]912256b32009-09-18 09:47:354788 }
4789
[email protected]61f5a7b2009-12-22 22:21:204790 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354791}
4792
[email protected]60c42a8c72009-10-09 04:08:594793void RenderView::Close() {
4794 // We need to grab a pointer to the doomed WebView before we destroy it.
4795 WebView* doomed = webview();
4796 RenderWidget::Close();
4797 Singleton<ViewMap>::get()->erase(doomed);
4798}
4799
[email protected]446705872009-09-10 07:22:484800void RenderView::DidHandleKeyEvent() {
4801 edit_commands_.clear();
4802}
4803
[email protected]941e4552010-02-01 21:23:434804#if defined(OS_MACOSX)
4805void RenderView::OnWasHidden() {
4806 RenderWidget::OnWasHidden();
4807
4808 // Inform plugins that their container is no longer visible.
4809 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4810 for (plugin_it = plugin_delegates_.begin();
4811 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4812 (*plugin_it)->SetContainerVisibility(false);
4813 }
4814}
4815
4816void RenderView::OnWasRestored(bool needs_repainting) {
4817 RenderWidget::OnWasRestored(needs_repainting);
4818
4819 // Inform plugins that their container is now visible.
4820 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4821 for (plugin_it = plugin_delegates_.begin();
4822 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4823 (*plugin_it)->SetContainerVisibility(true);
4824 }
4825}
[email protected]1e6e3c992010-02-08 15:52:134826
4827void RenderView::OnSetFocus(bool enable) {
4828 RenderWidget::OnSetFocus(enable);
4829
4830 // RenderWidget's call to setFocus can cause the underlying webview's
4831 // activation state to change just like a call to setIsActive.
4832 if (enable && webview() && webview()->isActive()) {
4833 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4834 for (plugin_it = plugin_delegates_.begin();
4835 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4836 (*plugin_it)->SetWindowFocus(true);
4837 }
4838 }
4839}
[email protected]941e4552010-02-01 21:23:434840#endif // OS_MACOSX
4841
[email protected]83dde542009-09-11 20:59:554842void RenderView::EnsureDocumentTag() {
4843 // TODO(darin): There's actually no reason for this to be here. We should
4844 // have the browser side manage the document tag.
4845#if defined(OS_MACOSX)
4846 if (!has_document_tag_) {
4847 // Make the call to get the tag.
4848 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4849 has_document_tag_ = true;
4850 }
4851#endif
4852}
[email protected]12636df2009-09-28 22:32:214853
[email protected]43f28f832010-02-03 02:28:484854#if defined(OS_MACOSX)
4855gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle() {
4856 gfx::PluginWindowHandle window = NULL;
4857 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
4858 routing_id(), &window));
4859 return window;
4860}
4861
4862void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4863 if (window)
4864 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4865}
4866
[email protected]44ce0b12010-03-12 16:45:334867void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4868 int32 width,
4869 int32 height,
4870 uint64 io_surface_identifier) {
4871 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484872 routing_id(), window, width, height, io_surface_identifier));
4873}
4874
[email protected]44ce0b12010-03-12 16:45:334875void RenderView::AcceleratedSurfaceSetTransportDIB(
4876 gfx::PluginWindowHandle window,
4877 int32 width,
4878 int32 height,
4879 TransportDIB::Handle transport_dib) {
4880 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074881 routing_id(), window, width, height, transport_dib));
4882}
4883
[email protected]44ce0b12010-03-12 16:45:334884TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4885 size_t size) {
[email protected]1aef98132010-02-23 18:00:074886 TransportDIB::Handle dib_handle;
4887 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384888 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074889 return dib_handle;
4890 // Return an invalid handle if Send() fails.
4891 return TransportDIB::DefaultHandleValue();
4892}
4893
[email protected]44ce0b12010-03-12 16:45:334894void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074895 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4896}
4897
[email protected]44ce0b12010-03-12 16:45:334898void RenderView::AcceleratedSurfaceBuffersSwapped(
4899 gfx::PluginWindowHandle window) {
4900 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:484901}
4902#endif
[email protected]58c321d2010-02-19 12:11:284903
[email protected]cdaf8d02010-03-30 19:52:474904bool RenderView::ScheduleFileChooser(
4905 const ViewHostMsg_RunFileChooser_Params& params,
4906 WebFileChooserCompletion* completion) {
4907 static const size_t kMaximumPendingFileChooseRequests = 4;
4908 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4909 // This sanity check prevents too many file choose requests from getting
4910 // queued which could DoS the user. Getting these is most likely a
4911 // programming error (there are many ways to DoS the user so it's not
4912 // considered a "real" security check), either in JS requesting many file
4913 // choosers to pop up, or in a plugin.
4914 //
4915 // TODO(brettw) we might possibly want to require a user gesture to open
4916 // a file picker, which will address this issue in a better way.
4917 return false;
4918 }
4919
4920 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4921 new PendingFileChooser(params, completion)));
4922 if (file_chooser_completions_.size() == 1) {
4923 // Actually show the browse dialog when this is the first request.
4924 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4925 }
4926 return true;
4927}
4928
[email protected]8a5f7002010-03-31 13:47:354929WebKit::WebGeolocationService* RenderView::geolocationService() {
4930
[email protected]58c321d2010-02-19 12:11:284931 if (!geolocation_dispatcher_.get())
4932 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
4933 return geolocation_dispatcher_.get();
4934}
[email protected]61c9f032010-03-31 23:04:194935
4936bool RenderView::ShouldRouteNavigationToBrowser(
4937 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
4938 // If the browser is interested, then give it a chance to look at top level
4939 // navigations
4940 if (!renderer_preferences_.browser_handles_top_level_requests)
4941 return false;
4942
4943 // Must be a top level frame.
4944 if (frame->parent() != NULL)
4945 return false;
4946
4947 // Skip if navigation is on the same page (using '#').
4948 GURL frame_origin = GURL(frame->url()).GetOrigin();
4949 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
4950 // The link click could stay on the same page, in cases where it sends some
4951 // parameters to the same URL.
4952 if (type == WebKit::WebNavigationTypeLinkClicked)
4953 return true;
4954
4955 if (last_top_level_navigation_page_id_ != page_id_ &&
4956 // Not interested in reloads.
4957 type != WebKit::WebNavigationTypeReload &&
4958 type != WebKit::WebNavigationTypeFormSubmitted) {
4959 return true;
4960 }
4961 }
4962 return false;
4963}