blob: 33238d65a3b2bc58e46da9e6ee1f4bc54c536691 [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"
[email protected]534c66c2010-04-28 22:53:1137#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2539#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1140#include "chrome/renderer/devtools_agent.h"
41#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3542#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3243#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3544#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3745#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2846#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2947#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5648#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1149#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5650#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1251#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3052#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5053#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2554#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2855#include "chrome/renderer/render_thread.h"
[email protected]035545f2010-04-09 13:10:2156#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3457#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4658#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3559#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2960#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2961#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2962#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4263#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5664#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1565#include "gfx/color_utils.h"
66#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5767#include "gfx/native_widget_types.h"
[email protected]34ac8f32009-02-22 23:03:2768#include "grit/generated_resources.h"
69#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3470#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2971#include "net/base/escape.h"
72#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0073#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1074#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3075#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]418ed5ab2009-11-12 01:14:4976#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
77#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:0778#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4979#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
80#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3281#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4982#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3583#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]b1438212010-04-03 00:30:5984#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:4985#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
86#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
87#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:4188#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:5089#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4990#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3291#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0792#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:4993#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
94#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4995#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
96#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
97#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
98#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
99#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
100#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34102#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49103#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
104#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
105#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
106#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
107#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
108#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]534c66c2010-04-28 22:53:11109#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04110#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29111#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29112#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59113#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24114#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24115#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34116#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17117#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51118#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09119#include "webkit/glue/media/video_renderer_impl.h"
initial.commit09911bf2008-07-26 23:55:29120#include "webkit/glue/password_form.h"
[email protected]ba4b17f2009-02-11 21:32:29121#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30122#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23123#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30124#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]85cc78c2010-05-04 18:30:09125#include "webkit/glue/site_isolation_metrics.h"
initial.commit09911bf2008-07-26 23:55:29126#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29127#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17128#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29129
[email protected]6c8afae52009-01-22 02:24:57130#if defined(OS_WIN)
131// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57132// * theming
[email protected]cd818412010-03-19 03:23:15133#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03134#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46135#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33136#elif defined(OS_MACOSX)
137#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57138#endif
139
[email protected]80f584d92010-01-21 03:59:04140using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26141using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33142using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45143using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59144using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24145using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17146using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56147using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10148using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09149using webkit_glue::SiteIsolationMetrics;
[email protected]c7287a92009-11-04 20:06:15150using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08151using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21152using WebKit::WebApplicationCacheHost;
153using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41154using WebKit::WebColor;
155using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59156using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44157using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51158using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07159using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55160using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28161using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29162using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00163using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58164using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25165using WebKit::WebDragOperation;
166using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51167using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47168using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49169using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59170using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48171using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45172using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17173using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41174using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50175using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17176using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28177using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17178using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28179using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28180using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51181using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07182using WebKit::WebPageSerializer;
183using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17184using WebKit::WebPlugin;
185using WebKit::WebPluginParams;
[email protected]24a7f3c2010-03-25 08:26:49186using WebKit::WebPluginDocument;
[email protected]48c9cf2d2009-09-16 16:47:52187using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59188using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51189using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52190using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40191using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35192using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29193using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59194using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42195using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02196using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34197using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28198using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51199using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52200using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28201using WebKit::WebURL;
202using WebKit::WebURLError;
203using WebKit::WebURLRequest;
204using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28205using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03206using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28207using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43208using WebKit::WebWorker;
209using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11210using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33211
initial.commit09911bf2008-07-26 23:55:29212//-----------------------------------------------------------------------------
213
214// define to write the time necessary for thumbnail/DOM text retrieval,
215// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29216// #define TIME_TEXT_RETRIEVAL
217
218// maximum number of characters in the document to index, any text beyond this
219// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57220static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29221
222// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37223static const int kThumbnailWidth = 212;
224static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29225
226// Delay in milliseconds that we'll wait before capturing the page contents
227// and thumbnail.
228static const int kDelayForCaptureMs = 500;
229
230// Typically, we capture the page data once the page is loaded.
231// Sometimes, the page never finishes to load, preventing the page capture
232// To workaround this problem, we always perform a capture after the following
233// delay.
234static const int kDelayForForcedCaptureMs = 6000;
235
[email protected]882daa92009-11-05 16:31:31236// Time, in seconds, we delay before sending content state changes (such as form
237// state and scroll position) to the browser. We delay sending changes to avoid
238// spamming the browser.
239// To avoid having tab/session restore require sending a message to get the
240// current content state during tab closing we use a shorter timeout for the
241// foreground renderer. This means there is a small window of time from which
242// content state is modified and not sent to session restore, but this is
243// better than having to wake up all renderers during shutdown.
244static const int kDelaySecondsForContentStateSyncHidden = 5;
245static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29246
[email protected]0aa55312008-10-17 21:53:08247// The maximum number of popups that can be spawned from one page.
248static const int kMaximumNumberOfUnacknowledgedPopups = 25;
249
initial.commit09911bf2008-07-26 23:55:29250static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16251 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29252
[email protected]50b691c2008-10-31 19:08:35253static const char* const kBackForwardNavigationScheme = "history";
254
[email protected]d64b07b2010-04-20 22:14:06255// static
256const char* const RenderView::kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13257
[email protected]726985e22009-06-18 21:09:28258static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
259 WebVector<WebURL> urls;
260 ds->redirectChain(urls);
261 result->reserve(urls.size());
262 for (size_t i = 0; i < urls.size(); ++i)
263 result->push_back(urls[i]);
264}
265
[email protected]61f5a7b2009-12-22 22:21:20266static bool UrlMatchesPermissions(
267 const GURL& url, const std::vector<URLPattern>& host_permissions) {
268 for (size_t i = 0; i < host_permissions.size(); ++i) {
269 if (host_permissions[i].MatchesUrl(url))
270 return true;
271 }
272
273 return false;
274}
275
[email protected]30507922010-01-15 16:48:23276static bool PaintViewIntoCanvas(WebView* view,
277 skia::PlatformCanvas& canvas) {
278 view->layout();
279 const WebSize& size = view->size();
280
281 if (!canvas.initialize(size.width, size.height, true))
282 return false;
283
284 view->paint(webkit_glue::ToWebCanvas(&canvas),
285 WebRect(0, 0, size.width, size.height));
286 // TODO: Add a way to snapshot the whole page, not just the currently
287 // visible part.
288
289 return true;
290}
291
292// Calculates how "boring" a thumbnail is. The boring score is the
293// 0,1 ranged percentage of pixels that are the most common
294// luma. Higher boring scores indicate that a higher percentage of a
295// bitmap are all the same brightness.
296static double CalculateBoringScore(SkBitmap* bitmap) {
297 int histogram[256] = {0};
298 color_utils::BuildLumaHistogram(bitmap, histogram);
299
300 int color_count = *std::max_element(histogram, histogram + 256);
301 int pixel_count = bitmap->width() * bitmap->height();
302 return static_cast<double>(color_count) / pixel_count;
303}
304
[email protected]12bc8472010-04-15 07:29:40305// True if |frame| contains content that is white-listed for content settings.
306static bool IsWhitelistedForContentSettings(WebFrame* frame) {
307 WebSecurityOrigin origin = frame->securityOrigin();
308 if (origin.isEmpty())
309 return false; // Uninitialized document?
310
311 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
312 return true; // Browser UI elements should still work.
313
314 // If the scheme is ftp: or file:, an empty file name indicates a directory
315 // listing, which requires JavaScript to function properly.
316 GURL frame_url = frame->url();
317 const char* kDirProtocols[] = { "ftp", "file" };
318 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
319 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
320 return frame_url.SchemeIs(kDirProtocols[i]) &&
321 frame_url.ExtractFileName().empty();
322 }
323 }
324
325 return false;
326}
327
[email protected]3a8eecb2010-04-22 23:56:30328// Returns true if the frame is navigating to an URL either into or out of an
329// extension app's extent.
330static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
331 if (!RenderThread::current())
332 return false;
333
334 // If the URL is still empty, this is a window.open navigation. Check the
335 // opener's URL.
336 GURL old_url(frame->url());
337 if (old_url.is_empty() && frame->opener())
338 old_url = frame->opener()->url();
339
340 std::string old_extension =
341 RenderThread::current()->GetExtensionIdForURL(old_url);
342 std::string new_extension =
343 RenderThread::current()->GetExtensionIdForURL(new_url);
344 return (old_extension != new_extension);
345}
346
initial.commit09911bf2008-07-26 23:55:29347///////////////////////////////////////////////////////////////////////////////
348
[email protected]60c42a8c72009-10-09 04:08:59349int32 RenderView::next_page_id_ = 1;
350
[email protected]cdaf8d02010-03-30 19:52:47351struct RenderView::PendingFileChooser {
352 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
353 WebFileChooserCompletion* c)
354 : params(p),
355 completion(c) {
356 }
357 ViewHostMsg_RunFileChooser_Params params;
358 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
359};
360
[email protected]2fab253a2009-08-17 23:00:59361RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34362 const WebPreferences& webkit_preferences,
363 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12364 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]81e63782009-02-27 19:35:09365 enabled_bindings_(0),
[email protected]e75cb49e2009-01-05 23:13:21366 target_url_status_(TARGET_NONE),
[email protected]81a34412009-01-05 19:17:24367 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21368 navigation_gesture_(NavigationGestureUnknown),
[email protected]81a34412009-01-05 19:17:24369 page_id_(-1),
370 last_page_id_sent_to_browser_(-1),
371 last_indexed_page_id_(-1),
[email protected]81a34412009-01-05 19:17:24372 opened_by_user_gesture_(true),
[email protected]007a848b2009-10-26 15:55:46373 opener_suppressed_(false),
[email protected]bb063b72009-03-27 23:18:50374 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
[email protected]e4ac5df2009-03-17 15:33:11375 devtools_agent_(NULL),
376 devtools_client_(NULL),
[email protected]3cc72b12010-03-18 23:03:00377 history_list_offset_(-1),
378 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24379 has_unload_listener_(false),
380 decrement_shared_popup_at_destruction_(false),
[email protected]acca2a1f2009-10-16 03:53:39381 autofill_query_id_(0),
[email protected]81a34412009-01-05 19:17:24382 popup_notification_visible_(false),
[email protected]8922e1f2009-10-03 05:01:26383 spelling_panel_visible_(false),
[email protected]882daa92009-11-05 16:31:31384 send_content_state_immediately_(false),
[email protected]ab32b16c2009-10-16 14:57:25385 send_preferred_size_changes_(false),
[email protected]b6849bda2009-10-14 23:59:26386 ALLOW_THIS_IN_INITIALIZER_LIST(
387 notification_provider_(new NotificationProvider(this))),
[email protected]7b291f92009-08-14 05:43:53388 view_type_(ViewType::INVALID),
389 browser_window_id_(-1),
[email protected]83dde542009-09-11 20:59:55390 last_top_level_navigation_page_id_(-1),
391#if defined(OS_MACOSX)
392 has_document_tag_(false),
393#endif
[email protected]98324892009-09-09 21:16:05394 document_tag_(0),
[email protected]0bedb8a2010-01-14 19:36:32395 webkit_preferences_(webkit_preferences),
[email protected]4e6419c2010-01-15 04:50:34396 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ab9eabac2010-03-16 16:54:10397 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]85d252e2010-04-06 22:21:02398 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
[email protected]ab9eabac2010-03-16 16:54:10399 cross_origin_access_count_(0),
400 same_origin_access_count_(0) {
[email protected]71b0d5d2010-02-15 05:43:07401 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29402}
403
404RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08405 if (decrement_shared_popup_at_destruction_)
406 shared_popup_counter_->data--;
407
[email protected]b0950a72009-09-29 23:16:17408 // Dispose of un-disposed image fetchers.
409 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
410 i != image_fetchers_.end(); ++i) {
411 delete *i;
412 }
413
[email protected]a1128322009-10-06 18:38:46414 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47415 while (!file_chooser_completions_.empty()) {
416 if (file_chooser_completions_.front()->completion) {
417 file_chooser_completions_.front()->completion->didChooseFile(
418 WebVector<WebString>());
419 }
420 file_chooser_completions_.pop_front();
421 }
[email protected]a1128322009-10-06 18:38:46422
[email protected]83dde542009-09-11 20:59:55423#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05424 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55425 if (has_document_tag_)
426 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
427#endif
[email protected]98324892009-09-09 21:16:05428
[email protected]5fb88962009-04-16 19:03:25429 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59430
431#ifndef NDEBUG
432 // Make sure we are no longer referenced by the ViewMap.
433 ViewMap* views = Singleton<ViewMap>::get();
434 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
435 DCHECK_NE(this, it->second) << "Failed to call Close?";
436#endif
437}
438
439/*static*/
440void RenderView::ForEach(RenderViewVisitor* visitor) {
441 ViewMap* views = Singleton<ViewMap>::get();
442 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
443 if (!visitor->Visit(it->second))
444 return;
445 }
446}
447
448/*static*/
449RenderView* RenderView::FromWebView(WebView* webview) {
450 ViewMap* views = Singleton<ViewMap>::get();
451 ViewMap::iterator it = views->find(webview);
452 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29453}
454
455/*static*/
[email protected]0aa55312008-10-17 21:53:08456RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24457 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15458 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08459 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51460 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08461 const WebPreferences& webkit_prefs,
462 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34463 int32 routing_id,
464 int64 session_storage_namespace_id) {
initial.commit09911bf2008-07-26 23:55:29465 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34466 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
467 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29468 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29469 opener_id,
[email protected]80d96fa2009-06-10 22:34:51470 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08471 counter,
initial.commit09911bf2008-07-26 23:55:29472 routing_id); // adds reference
473 return view;
474}
475
476/*static*/
477void RenderView::SetNextPageID(int32 next_page_id) {
478 // This method should only be called during process startup, and the given
479 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05480 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29481 DCHECK(next_page_id >= next_page_id_);
482 next_page_id_ = next_page_id;
483}
484
[email protected]afe3a1672009-11-17 19:04:12485void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56486 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
487}
488
[email protected]a3a8fb6d2009-10-22 20:12:51489void RenderView::PluginCrashed(const FilePath& plugin_path) {
490 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29491}
492
[email protected]d8fd6fa2010-02-01 15:54:26493#if defined(OS_MACOSX)
494void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
495 plugin_delegates_.insert(delegate);
496}
497
498void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
499 plugin_delegates_.erase(delegate);
500}
501#endif
502
[email protected]18bcc3c2009-01-27 21:39:15503void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29504 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51505 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08506 SharedRenderViewCounter* counter,
initial.commit09911bf2008-07-26 23:55:29507 int32 routing_id) {
508 DCHECK(!webview());
509
510 if (opener_id != MSG_ROUTING_NONE)
511 opener_id_ = opener_id;
512
[email protected]0aa55312008-10-17 21:53:08513 if (counter) {
514 shared_popup_counter_ = counter;
515 shared_popup_counter_->data++;
516 decrement_shared_popup_at_destruction_ = true;
517 } else {
518 shared_popup_counter_ = new SharedRenderViewCounter(0);
519 decrement_shared_popup_at_destruction_ = false;
520 }
521
[email protected]58bfc6b2009-06-24 09:45:02522 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04523
[email protected]50ae00ef2009-10-19 05:11:03524 webwidget_ = WebView::create(this);
[email protected]60c42a8c72009-10-09 04:08:59525 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59526 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27527 webview()->initializeMainFrame(this);
[email protected]2661b332009-11-03 18:42:29528 webview()->setDevToolsAgent(
529 WebDevToolsAgent::create(webview(), devtools_agent_.get()));
initial.commit09911bf2008-07-26 23:55:29530
[email protected]d3ba77272009-09-03 00:06:09531 OnSetRendererPrefs(renderer_prefs);
532
initial.commit09911bf2008-07-26 23:55:29533 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24534 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29535 // Take a reference on behalf of the RenderThread. This will be balanced
536 // when we receive ViewMsg_Close.
537 AddRef();
538
539 // If this is a popup, we must wait for the CreatingNew_ACK message before
540 // completing initialization. Otherwise, we can finish it now.
541 if (opener_id == MSG_ROUTING_NONE) {
542 did_show_ = true;
543 CompleteInit(parent_hwnd);
544 }
545
546 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29547
[email protected]58bfc6b2009-06-24 09:45:02548 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09549 if (command_line.HasSwitch(switches::kDomAutomationController))
550 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29551
[email protected]5fb88962009-04-16 19:03:25552 audio_message_filter_ = new AudioMessageFilter(routing_id_);
553 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29554}
555
556void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27557 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27558 if (main_frame)
559 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26560
[email protected]b2abac72009-02-26 12:39:28561 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11562 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28563 return;
[email protected]b4b967e2009-04-22 11:33:05564 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
565 return;
[email protected]b6849bda2009-10-14 23:59:26566 if (notification_provider_->OnMessageReceived(message))
567 return;
[email protected]58c321d2010-02-19 12:11:28568 if (geolocation_dispatcher_.get() &&
569 geolocation_dispatcher_->OnMessageReceived(message)) {
570 return;
571 }
[email protected]b2abac72009-02-26 12:39:28572
initial.commit09911bf2008-07-26 23:55:29573 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29574 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail)
[email protected]30507922010-01-15 16:48:23575 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot)
initial.commit09911bf2008-07-26 23:55:29576 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01577 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29578 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
579 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56580 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29581 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
582 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
583 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
584 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27585#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35586 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27587#endif
initial.commit09911bf2008-07-26 23:55:29588 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
589 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05590 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
591 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
592 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04593 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29594 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
595 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
596 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15597 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29598 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49599 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
600 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17601 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54602 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
603 OnSetContentSettingsForLoadingURL)
604 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
605 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29606 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18607 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
608 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28609 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33610 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29611 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48612 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29613 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29614 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29615 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
616 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
617 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
618 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
619 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45620 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29621 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50622 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
623 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29624 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
625 OnDragSourceSystemDragEnded)
626 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29627 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
628 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
629 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
630 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
631 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
632 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29633 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
634 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04635 IPC_MESSAGE_HANDLER(
636 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
637 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29638 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]266eb6f2008-09-30 23:56:50639 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo)
640 IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo,
641 OnClearAccessibilityInfo)
initial.commit09911bf2008-07-26 23:55:29642 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose)
643 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
644 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45645 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
646 OnMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08647 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
648 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24649 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
650 OnAutoFillSuggestionsReturned)
[email protected]cf28ec52010-04-09 22:56:34651 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillForms, OnAutoFillForms)
[email protected]95056b582010-02-18 01:29:24652 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
653 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48654 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
655 OnAutoFillFormDataFilled)
[email protected]2c4410d2009-05-06 23:46:22656 IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
657 OnPopupNotificationVisibilityChanged)
[email protected]30f75e62009-02-25 22:01:00658 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27659 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37660 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
661 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16662 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14663 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25664 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
665 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10666 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
667 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51668 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53669 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
670 OnUpdateBrowserWindowId)
671 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
672 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56673 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34674 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14675#if defined(OS_MACOSX)
676 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13677 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14678#endif
[email protected]446705872009-09-10 07:22:48679 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33680 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35681 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
682 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33683 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
684 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42685 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02686 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]634a6f92008-12-01 21:39:31687
initial.commit09911bf2008-07-26 23:55:29688 // Have the super handle all other messages.
689 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
690 IPC_END_MESSAGE_MAP()
691}
692
initial.commit09911bf2008-07-26 23:55:29693void RenderView::SendThumbnail() {
[email protected]26aa0482009-09-30 16:55:27694 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29695 if (!main_frame)
696 return;
697
698 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45699 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29700 if (url.is_empty())
701 return;
702
703 if (size_.IsEmpty())
704 return; // Don't create an empty thumbnail!
705
706 ThumbnailScore score;
707 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02708 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15709 &thumbnail, &score))
710 return;
711
initial.commit09911bf2008-07-26 23:55:29712 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46713 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29714}
715
[email protected]30507922010-01-15 16:48:23716void RenderView::SendSnapshot() {
717 SkBitmap snapshot;
718 bool error = false;
719
720 WebFrame* main_frame = webview()->mainFrame();
721 if (!main_frame)
722 error = true;
723
724 if (!error && !CaptureSnapshot(webview(), &snapshot))
725 error = true;
726
727 DCHECK(error == snapshot.empty()) <<
728 "Snapshot should be empty on error, non-empty otherwise.";
729
730 // Send the snapshot to the browser process.
731 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
732}
733
[email protected]068637222009-01-29 16:58:07734void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29735 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58736 if (webview()) {
737 // If the user has selected text in the currently focused frame we print
738 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27739 if (webview()->focusedFrame()->hasSelection())
740 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58741 else
[email protected]26aa0482009-09-30 16:55:27742 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58743 }
initial.commit09911bf2008-07-26 23:55:29744}
745
[email protected]82270452009-06-19 15:58:01746void RenderView::OnPrintingDone(int document_cookie, bool success) {
747 // Ignoring document cookie here since only one print job can be outstanding
748 // per renderer and document_cookie is 0 when printing is successful.
749 DCHECK(print_helper_.get());
750 if (print_helper_.get() != NULL) {
751 print_helper_->DidFinishPrinting(success);
752 }
753}
754
initial.commit09911bf2008-07-26 23:55:29755void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
756 if (load_id != page_id_)
757 return; // this capture call is no longer relevant due to navigation
758 if (load_id == last_indexed_page_id_)
759 return; // we already indexed this page
760
761 if (!webview())
762 return;
763
[email protected]26aa0482009-09-30 16:55:27764 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29765 if (!main_frame)
766 return;
767
768 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45769 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29770 return;
771
772 // Don't index/capture pages that failed to load. This only checks the top
773 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45774 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28775 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29776 return;
777
778 if (!preliminary_capture)
779 last_indexed_page_id_ = load_id;
780
[email protected]a8a81292010-01-21 00:32:45781 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45782 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29783 if (url.is_empty())
784 return;
785
[email protected]a8a81292010-01-21 00:32:45786 // Retrieve the frame's full text.
initial.commit09911bf2008-07-26 23:55:29787 std::wstring contents;
788 CaptureText(main_frame, &contents);
789 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45790 base::TimeTicks begin_time = base::TimeTicks::Now();
791 std::string language = DetermineTextLanguage(contents);
792 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
793 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52794
[email protected]a8a81292010-01-21 00:32:45795 // Send the text to the browser for indexing (the browser might decide not
796 // to index, if the URL is HTTPS for instance) and language discovery.
797 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
798 language));
[email protected]5c4266922009-07-10 16:41:27799 }
800
initial.commit09911bf2008-07-26 23:55:29801 // thumbnail
802 SendThumbnail();
803}
804
805void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) {
806 contents->clear();
807 if (!frame)
808 return;
809
810#ifdef TIME_TEXT_RETRIEVAL
811 double begin = time_util::GetHighResolutionTimeNow();
812#endif
813
814 // get the contents of the frame
[email protected]dd7daa82009-08-10 05:46:45815 *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars));
initial.commit09911bf2008-07-26 23:55:29816
817#ifdef TIME_TEXT_RETRIEVAL
818 double end = time_util::GetHighResolutionTimeNow();
819 char buf[128];
820 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
821 contents.size(), (end - begin)*1000);
822 OutputDebugStringA(buf);
823#endif
824
825 // When the contents are clipped to the maximum, we don't want to have a
826 // partial word indexed at the end that might have been clipped. Therefore,
827 // terminate the string at the last space to ensure no words are clipped.
828 if (contents->size() == kMaxIndexChars) {
829 size_t last_space_index = contents->find_last_of(kWhitespaceWide);
830 if (last_space_index == std::wstring::npos)
831 return; // don't index if we got a huge block of text with no spaces
832 contents->resize(last_space_index);
833 }
834}
835
[email protected]8649fb32009-06-26 17:51:02836bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29837 int w,
838 int h,
839 SkBitmap* thumbnail,
840 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23841 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15842
[email protected]8649fb32009-06-26 17:51:02843 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23844
845 // Paint |view| into |canvas|.
846 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02847 return false;
[email protected]8649fb32009-06-26 17:51:02848
849 skia::BitmapPlatformDevice& device =
850 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
851
852 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29853
[email protected]cab34d6a2009-09-24 01:14:52854 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29855 float dest_aspect = dest_rect.width() / dest_rect.height();
856
857 // Get the src rect so that we can preserve the aspect ratio while filling
858 // the destination.
859 SkIRect src_rect;
860 if (src_bmp.width() < dest_rect.width() ||
861 src_bmp.height() < dest_rect.height()) {
862 // Source image is smaller: we clip the part of source image within the
863 // dest rect, and then stretch it to fill the dest rect. We don't respect
864 // the aspect ratio in this case.
865 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
866 static_cast<S16CPU>(dest_rect.height()));
867 score->good_clipping = false;
868 } else {
869 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
870 if (src_aspect > dest_aspect) {
871 // Wider than tall, clip horizontally: we center the smaller thumbnail in
872 // the wider screen.
873 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
874 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
875 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
876 score->good_clipping = false;
877 } else {
878 src_rect.set(0, 0, src_bmp.width(),
879 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
880 score->good_clipping = true;
881 }
882 }
883
[email protected]26aa0482009-09-30 16:55:27884 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29885
886 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02887 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29888
889 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14890 *thumbnail = skia::ImageOperations::Resize(
891 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29892
893 score->boring_score = CalculateBoringScore(thumbnail);
894
[email protected]30507922010-01-15 16:48:23895 HISTOGRAM_TIMES("Renderer4.Thumbnail",
896 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15897 return true;
initial.commit09911bf2008-07-26 23:55:29898}
899
[email protected]30507922010-01-15 16:48:23900bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
901 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29902
[email protected]30507922010-01-15 16:48:23903 skia::PlatformCanvas canvas;
904 if (!PaintViewIntoCanvas(view, canvas))
905 return false;
906
907 skia::BitmapPlatformDevice& device =
908 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
909
910 const SkBitmap& bitmap = device.accessBitmap(false);
911 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
912 return false;
913
914 HISTOGRAM_TIMES("Renderer4.Snapshot",
915 base::TimeTicks::Now() - beginning_time);
916 return true;
initial.commit09911bf2008-07-26 23:55:29917}
918
919void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
920 if (!webview())
921 return;
922
[email protected]3cc72b12010-03-18 23:03:00923 history_list_offset_ = params.current_history_list_offset;
924 history_list_length_ = params.current_history_list_length;
925
[email protected]8c785c62009-07-13 14:20:15926 if (devtools_agent_.get())
927 devtools_agent_->OnNavigate();
928
[email protected]422197532010-01-25 17:38:23929 if (notification_provider_.get())
930 notification_provider_->OnNavigate();
931
[email protected]a9f607e2009-10-23 19:59:27932 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26933
initial.commit09911bf2008-07-26 23:55:29934 AboutHandler::MaybeHandle(params.url);
935
[email protected]ecbf10d2010-02-18 13:03:29936 bool is_reload =
937 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
938 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29939
[email protected]26aa0482009-09-30 16:55:27940 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45941 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29942 // We cannot reload if we do not have any history state. This happens, for
943 // example, when recovering from a crash. Our workaround here is a bit of
944 // a hack since it means that reload after a crashed tab does not cause an
945 // end-to-end cache validation.
946 is_reload = false;
947 }
948
[email protected]77f17a82009-05-21 04:42:54949 // A navigation resulting from loading a javascript URL should not be treated
950 // as a browser initiated event. Instead, we want it to look as if the page
951 // initiated any load resulting from JS execution.
952 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30953 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00954 params.page_id,
955 params.pending_history_list_offset,
956 params.transition,
957 params.request_time);
[email protected]5e369672009-11-03 23:48:30958 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
959 // We're doing a load of a page that was restored from the last session.
960 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
961 // which can result in stale data for pages that are set to expire. We
962 // explicitly override that by setting the policy here so that as
963 // necessary we load from the network.
964 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
965 }
966 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54967 }
initial.commit09911bf2008-07-26 23:55:29968
[email protected]a7ccc4d2010-01-27 08:14:48969 NavigationState* navigation_state = pending_navigation_state_.get();
970
[email protected]04d3c6e2009-05-22 17:00:13971 // If we are reloading, then WebKit will use the history state of the current
972 // page, so we should just ignore any given history state. Otherwise, if we
973 // have history state, then we need to navigate to it, which corresponds to a
974 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55975 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48976 if (navigation_state)
977 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29978 bool ignore_cache = (params.navigation_type ==
979 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
980 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55981 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13982 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58983 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48984 if (navigation_state)
985 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45986 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17987 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13988 } else {
989 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28990 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29991
[email protected]e6f546c32009-07-01 17:12:55992 // A session history navigation should have been accompanied by state.
993 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13994
[email protected]dd7daa82009-08-10 05:46:45995 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55996 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13997
[email protected]726985e22009-06-18 21:09:28998 if (params.referrer.is_valid()) {
999 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1000 WebString::fromUTF8(params.referrer.spec()));
1001 }
[email protected]04d3c6e2009-05-22 17:00:131002
[email protected]a7ccc4d2010-01-27 08:14:481003 if (navigation_state)
1004 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451005 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501006 }
1007
[email protected]77f17a82009-05-21 04:42:541008 // In case LoadRequest failed before DidCreateDataSource was called.
1009 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291010}
1011
1012// Stop loading the current page
1013void RenderView::OnStop() {
1014 if (webview())
[email protected]b4bb2502009-10-01 22:35:271015 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291016}
1017
[email protected]ecbf10d2010-02-18 13:03:291018// Reload current focused frame.
1019// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561020void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291021 if (webview() && webview()->focusedFrame()) {
1022 // We always obey the cache (ignore_cache=false) here.
1023 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1024 // a cache-ignoring reload of the frame.
1025 webview()->focusedFrame()->reload(false);
1026 }
[email protected]1dda4022010-01-28 18:24:561027}
1028
initial.commit09911bf2008-07-26 23:55:291029void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271030 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291031}
1032
[email protected]68b1e922009-06-23 16:00:251033void RenderView::OnExecuteEditCommand(const std::string& name,
1034 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271035 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251036 return;
1037
[email protected]26aa0482009-09-30 16:55:271038 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451039 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251040}
1041
[email protected]b2abac72009-02-26 12:39:281042void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111043 DCHECK(!devtools_client_.get());
1044 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281045}
1046
initial.commit09911bf2008-07-26 23:55:291047void RenderView::OnUpdateTargetURLAck() {
1048 // Check if there is a targeturl waiting to be sent.
1049 if (target_url_status_ == TARGET_PENDING) {
1050 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1051 pending_target_url_));
1052 }
1053
1054 target_url_status_ = TARGET_NONE;
1055}
1056
1057void RenderView::OnUndo() {
1058 if (!webview())
1059 return;
1060
[email protected]26aa0482009-09-30 16:55:271061 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121062 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291063}
1064
1065void RenderView::OnRedo() {
1066 if (!webview())
1067 return;
1068
[email protected]26aa0482009-09-30 16:55:271069 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121070 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291071}
1072
1073void RenderView::OnCut() {
1074 if (!webview())
1075 return;
1076
[email protected]26aa0482009-09-30 16:55:271077 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121078 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291079}
1080
1081void RenderView::OnCopy() {
1082 if (!webview())
1083 return;
1084
[email protected]26aa0482009-09-30 16:55:271085 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121086 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291087}
1088
[email protected]c0cc3092009-09-12 08:27:271089#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351090void RenderView::OnCopyToFindPboard() {
1091 if (!webview())
1092 return;
1093
1094 // Since the find pasteboard supports only plain text, this can be simpler
1095 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271096 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351097 if (frame->hasSelection()) {
1098 string16 selection = frame->selectionAsText();
1099 RenderThread::current()->Send(
1100 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1101 }
1102
[email protected]afe3a1672009-11-17 19:04:121103 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351104}
[email protected]c0cc3092009-09-12 08:27:271105#endif
[email protected]a954bf72009-09-12 07:30:351106
initial.commit09911bf2008-07-26 23:55:291107void RenderView::OnPaste() {
1108 if (!webview())
1109 return;
1110
[email protected]26aa0482009-09-30 16:55:271111 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121112 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291113}
1114
[email protected]2a3a7762009-10-19 19:17:321115void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291116 if (!webview())
1117 return;
1118
[email protected]1ff7a032010-02-03 02:46:031119 WebFrame* frame = webview()->focusedFrame();
1120 if (!frame->hasSelection())
1121 frame->selectWordAroundCaret();
1122 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291123}
1124
[email protected]98324892009-09-09 21:16:051125void RenderView::OnAdvanceToNextMisspelling() {
1126 if (!webview())
1127 return;
[email protected]26aa0482009-09-30 16:55:271128 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051129 WebString::fromUTF8("AdvanceToNextMisspelling"));
1130}
1131
1132void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1133 if (!webview())
1134 return;
1135 // We need to tell the webView whether the spelling panel is visible or not so
1136 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261137 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271138 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051139 WebString::fromUTF8("ToggleSpellPanel"));
1140}
1141
[email protected]bbbd545c2008-12-15 20:18:041142void RenderView::OnToggleSpellCheck() {
1143 if (!webview())
1144 return;
1145
[email protected]26aa0482009-09-30 16:55:271146 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451147 frame->enableContinuousSpellChecking(
1148 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041149}
1150
initial.commit09911bf2008-07-26 23:55:291151void RenderView::OnDelete() {
1152 if (!webview())
1153 return;
1154
[email protected]26aa0482009-09-30 16:55:271155 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121156 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291157}
1158
1159void RenderView::OnSelectAll() {
1160 if (!webview())
1161 return;
1162
[email protected]26aa0482009-09-30 16:55:271163 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221164 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121165 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291166}
1167
1168void RenderView::OnSetInitialFocus(bool reverse) {
1169 if (!webview())
1170 return;
[email protected]26aa0482009-09-30 16:55:271171 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291172}
1173
1174///////////////////////////////////////////////////////////////////////////////
1175
[email protected]433819d2010-01-30 20:20:011176void RenderView::SetContentSettings(const ContentSettings& settings) {
1177 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011178}
1179
initial.commit09911bf2008-07-26 23:55:291180// Tell the embedding application that the URL of the active page has changed
1181void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451182 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291183 DCHECK(ds);
1184
[email protected]726985e22009-06-18 21:09:281185 const WebURLRequest& request = ds->request();
1186 const WebURLRequest& original_request = ds->originalRequest();
1187 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291188
[email protected]daa8c58e2009-06-15 17:21:101189 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1190 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291191
1192 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281193 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291194 params.is_post = false;
1195 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281196 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551197 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291198 // SSL state specified in the request takes precedence over the one in the
1199 // response.
1200 // So far this is only intended for error pages that are not expected to be
1201 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281202 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551203 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291204 } else {
[email protected]726985e22009-06-18 21:09:281205 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291206 }
1207
1208 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281209 if (ds->hasUnreachableURL()) {
1210 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291211 } else {
[email protected]726985e22009-06-18 21:09:281212 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291213 }
1214
[email protected]726985e22009-06-18 21:09:281215 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241216 params.should_update_history = !ds->hasUnreachableURL() &&
1217 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291218
[email protected]ce0e250d2009-10-23 21:00:351219 params.searchable_form_url = navigation_state->searchable_form_url();
1220 params.searchable_form_encoding =
1221 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291222
1223 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101224 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291225 if (password_form_data)
1226 params.password_form = *password_form_data;
1227
1228 params.gesture = navigation_gesture_;
1229 navigation_gesture_ = NavigationGestureUnknown;
1230
[email protected]dd7daa82009-08-10 05:46:451231 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291232 // Top-level navigation.
1233
[email protected]71b0d5d2010-02-15 05:43:071234 // Clear "block" flags for the new page. This needs to happen before any of
1235 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1236 // so that these functions can correctly detect that a piece of content
1237 // flipped from "not blocked" to "blocked".
1238 ClearBlockedContentSettings();
1239
[email protected]62d2a112010-04-07 00:53:021240 // Set content settings. Default them from the parent window if one exists.
1241 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011242 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541243 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011244 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011245 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011246
1247 // These content settings were merely recorded transiently for this load.
1248 // We can erase them now. If at some point we reload this page, the
1249 // browser will send us new, up-to-date content settings.
1250 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401251 } else if (frame->opener()) {
1252 WebView* opener_view = frame->opener()->view();
1253 RenderView* opener = FromWebView(opener_view);
1254 SetContentSettings(opener->current_content_settings_);
[email protected]f85f0702010-01-30 09:31:011255 }
1256
[email protected]40bd6582009-12-04 23:49:511257 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011258 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541259 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011260 if (host_zoom != host_zoom_levels_.end()) {
1261 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511262 // This zoom level was merely recorded transiently for this load. We can
1263 // erase it now. If at some point we reload this page, the browser will
1264 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011265 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511266 }
1267
initial.commit09911bf2008-07-26 23:55:291268 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551269 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291270
[email protected]daa8c58e2009-06-15 17:21:101271 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291272 if (!PageTransition::IsMainFrame(params.transition)) {
1273 // If the main frame does a load, it should not be reported as a subframe
1274 // navigation. This can occur in the following case:
1275 // 1. You're on a site with frames.
1276 // 2. You do a subframe navigation. This is stored with transition type
1277 // MANUAL_SUBFRAME.
1278 // 3. You navigate to some non-frame site, say, google.com.
1279 // 4. You navigate back to the page from step 2. Since it was initially
1280 // MANUAL_SUBFRAME, it will be that same transition type here.
1281 // We don't want that, because any navigation that changes the toplevel
1282 // frame should be tracked as a toplevel navigation (this allows us to
1283 // update the URL bar, etc).
1284 params.transition = PageTransition::LINK;
1285 }
1286
initial.commit09911bf2008-07-26 23:55:291287 // If we have a valid consumed client redirect source,
1288 // the page contained a client redirect (meta refresh, document.loc...),
1289 // so we set the referrer and transition to match.
1290 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041291 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291292 params.referrer = completed_client_redirect_src_;
1293 params.transition = static_cast<PageTransition::Type>(
1294 params.transition | PageTransition::CLIENT_REDIRECT);
1295 } else {
1296 // Bug 654101: the referrer will be empty on https->http transitions. It
1297 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281298 params.referrer = GURL(
1299 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291300 }
1301
[email protected]726985e22009-06-18 21:09:281302 string16 method = request.httpMethod();
1303 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291304 params.is_post = true;
1305
[email protected]c2a797d2009-09-21 16:46:321306 // Save some histogram data so we can compute the average memory used per
1307 // page load of the glyphs.
1308 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1309 webkit_glue::GetGlyphPageCount());
1310
[email protected]15cf526b2010-02-12 06:33:491311 // This message needs to be sent before any of allowScripts(),
1312 // allowImages(), allowPlugins() is called for the new page, so that when
1313 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1314 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291315 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1316 } else {
1317 // Subframe navigation: the type depends on whether this navigation
1318 // generated a new session history entry. When they do generate a session
1319 // history entry, it means the user initiated the navigation and we should
1320 // mark it as such. This test checks if this is the first time UpdateURL
1321 // has been called since WillNavigateToURL was called to initiate the load.
1322 if (page_id_ > last_page_id_sent_to_browser_)
1323 params.transition = PageTransition::MANUAL_SUBFRAME;
1324 else
1325 params.transition = PageTransition::AUTO_SUBFRAME;
1326
initial.commit09911bf2008-07-26 23:55:291327 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1328 }
1329
1330 last_page_id_sent_to_browser_ =
1331 std::max(last_page_id_sent_to_browser_, page_id_);
1332
1333 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101334 // we don't want the transition type to persist. Just clear it.
1335 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501336
[email protected]6c8afae52009-01-22 02:24:571337#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:151338 if (accessibility_.get()) {
[email protected]17455962010-02-24 01:39:351339 // Remove accessibility info cache.
1340 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501341 }
[email protected]6c8afae52009-01-22 02:24:571342#else
[email protected]7d926f92009-03-03 14:26:541343 // TODO(port): accessibility not yet implemented. See http://crbug.com/8288.
[email protected]6c8afae52009-01-22 02:24:571344#endif
initial.commit09911bf2008-07-26 23:55:291345}
1346
1347// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171348void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291349 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171350 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171351 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171352 routing_id_,
1353 page_id_,
1354 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1355 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171356 }
initial.commit09911bf2008-07-26 23:55:291357}
1358
1359void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401360 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291361 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271362 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291363 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301364 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291365 last_encoding_name_ = encoding_name;
1366
[email protected]e38f40152008-09-12 23:08:301367 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291368 }
1369}
1370
[email protected]f4d34b52008-11-24 23:05:011371// Sends the previous session history state to the browser so it will be saved
1372// before we navigate to a new page. This must be called *before* the page ID
1373// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291374void RenderView::UpdateSessionHistory(WebFrame* frame) {
1375 // If we have a valid page ID at this point, then it corresponds to the page
1376 // we are navigating away from. Otherwise, this is the first navigation, so
1377 // there is no past session history to record.
1378 if (page_id_ == -1)
1379 return;
1380
[email protected]ca948a22009-06-25 19:36:171381 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271382 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171383 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291384 return;
[email protected]ca948a22009-06-25 19:36:171385
1386 Send(new ViewHostMsg_UpdateState(
1387 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291388}
1389
[email protected]3d9689372009-09-10 04:29:171390void RenderView::OpenURL(
1391 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1392 Send(new ViewHostMsg_OpenURL(
1393 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1394}
1395
[email protected]79dbc662009-09-04 05:42:511396// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291397
initial.commit09911bf2008-07-26 23:55:291398void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281399 const WebURLRequest& failed_request,
1400 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291401 const std::string& html,
1402 bool replace) {
[email protected]726985e22009-06-18 21:09:281403 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291404
1405 std::string alt_html;
1406 if (html.empty()) {
1407 // Use a local error page.
1408 int resource_id;
1409 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281410 if (error.reason == net::ERR_CACHE_MISS &&
1411 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291412 GetFormRepostErrorValues(failed_url, &error_strings);
1413 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1414 } else {
1415 GetLocalizedErrorValues(error, &error_strings);
1416 resource_id = IDR_NET_ERROR_HTML;
1417 }
initial.commit09911bf2008-07-26 23:55:291418
1419 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1420 } else {
1421 alt_html = html;
1422 }
1423
[email protected]dd7daa82009-08-10 05:46:451424 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551425 GURL(kUnreachableWebDataURL),
1426 failed_url,
1427 replace);
initial.commit09911bf2008-07-26 23:55:291428}
1429
[email protected]7ccddb8c2009-08-04 17:36:551430void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291431 dom_automation_controller_.set_message_sender(this);
1432 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551433 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291434 L"domAutomationController");
1435}
1436
initial.commit09911bf2008-07-26 23:55:291437bool RenderView::RunJavaScriptMessage(int type,
1438 const std::wstring& message,
1439 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071440 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291441 std::wstring* result) {
1442 bool success = false;
1443 std::wstring result_temp;
1444 if (!result)
1445 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291446
[email protected]12636df2009-09-28 22:32:211447 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1448 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291449 return success;
1450}
1451
[email protected]c1f50aa2010-02-18 03:46:571452bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1453 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1454 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1455 // it is particularly important that we do not call willEnterModalLoop as
1456 // that would defer resource loads for the dialog itself.
1457 if (RenderThread::current()) // Will be NULL during unit tests.
1458 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1459
1460 message->EnableMessagePumping(); // Runs a nested message loop.
1461 return Send(message);
1462}
1463
initial.commit09911bf2008-07-26 23:55:291464void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1465 if (!osd_url.is_empty())
1466 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1467 autodetected));
1468}
1469
[email protected]95056b582010-02-18 01:29:241470void RenderView::OnAutoFillSuggestionsReturned(
1471 int query_id,
[email protected]8f6e6582010-04-09 02:03:071472 const std::vector<string16>& values,
[email protected]95056b582010-02-18 01:29:241473 const std::vector<string16>& labels,
1474 int default_suggestion_index) {
1475 if (webview() && query_id == autofill_query_id_) {
1476 webview()->applyAutoFillSuggestions(
[email protected]8f6e6582010-04-09 02:03:071477 autofill_query_node_, values, labels, default_suggestion_index);
[email protected]95056b582010-02-18 01:29:241478 }
1479 autofill_query_node_.reset();
1480}
1481
[email protected]cf28ec52010-04-09 22:56:341482void RenderView::OnAutoFillForms(
1483 const std::vector<webkit_glue::FormData>& forms) {
1484 form_manager_.FillForms(forms);
1485}
1486
[email protected]95056b582010-02-18 01:29:241487void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a1f2009-10-16 03:53:391488 int query_id,
1489 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031490 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181491 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081492 webview()->applyAutocompleteSuggestions(
[email protected]acca2a1f2009-10-16 03:53:391493 autofill_query_node_, suggestions, default_suggestion_index);
1494 }
1495 autofill_query_node_.reset();
[email protected]0ebf3872008-11-07 21:35:031496}
1497
[email protected]45c6e532010-03-15 23:51:241498void RenderView::OnAutoFillFormDataFilled(int query_id,
1499 const webkit_glue::FormData& form) {
[email protected]c83641732010-02-20 01:04:481500 if (query_id != autofill_query_id_)
1501 return;
1502
1503 form_manager_.FillForm(form);
1504}
1505
[email protected]2c4410d2009-05-06 23:46:221506void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
[email protected]634a6f92008-12-01 21:39:311507 popup_notification_visible_ = visible;
1508}
1509
initial.commit09911bf2008-07-26 23:55:291510uint32 RenderView::GetCPBrowsingContext() {
1511 uint32 context = 0;
1512 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1513 return context;
1514}
1515
initial.commit09911bf2008-07-26 23:55:291516void RenderView::AddSearchProvider(const std::string& url) {
1517 AddGURLSearchProvider(GURL(url),
1518 false); // not autodetected
1519}
1520
[email protected]f103ab72009-09-02 17:10:591521void RenderView::OnMissingPluginStatus(
1522 WebPluginDelegateProxy* delegate,
1523 int status) {
[email protected]6c8afae52009-01-22 02:24:571524#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591525 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291526 // Show the InfoBar for the first available plugin.
1527 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591528 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291529 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1530 }
1531 } else {
1532 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1533 // to start the download/install.
1534 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1535 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1536 }
1537 }
[email protected]6c8afae52009-01-22 02:24:571538#else
1539 // TODO(port): plugins current not supported
1540 NOTIMPLEMENTED();
1541#endif
initial.commit09911bf2008-07-26 23:55:291542}
1543
[email protected]48c9cf2d2009-09-16 16:47:521544// WebKit::WebViewClient ------------------------------------------------------
1545
[email protected]534c66c2010-04-28 22:53:111546// TODO(rafaelw): remove when
1547// WebViewClient::createView(WebFrame,WebWindowFeatures) lands.
[email protected]48c9cf2d2009-09-16 16:47:521548WebView* RenderView::createView(WebFrame* creator) {
[email protected]534c66c2010-04-28 22:53:111549 return createView(creator, WebWindowFeatures());
1550}
1551
1552WebView* RenderView::createView(
1553 WebFrame* creator,
1554 const WebWindowFeatures& features) {
[email protected]48c9cf2d2009-09-16 16:47:521555 // Check to make sure we aren't overloading on popups.
1556 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1557 return NULL;
1558
1559 // This window can't be closed from a window.close() call until we receive a
1560 // message from the Browser process explicitly allowing it.
1561 popup_notification_visible_ = true;
1562
1563 int32 routing_id = MSG_ROUTING_NONE;
1564 bool user_gesture = creator->isProcessingUserGesture();
[email protected]007a848b2009-10-26 15:55:461565 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]4e6419c2010-01-15 04:50:341566 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521567
[email protected]48c9cf2d2009-09-16 16:47:521568 render_thread_->Send(
[email protected]534c66c2010-04-28 22:53:111569 new ViewHostMsg_CreateWindow(
1570 routing_id_,
1571 user_gesture,
1572 WindowFeaturesToContainerType(features),
1573 session_storage_namespace_id_,
1574 &routing_id,
1575 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211576 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521577 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521578
[email protected]48c9cf2d2009-09-16 16:47:521579 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421580 0,
[email protected]12636df2009-09-28 22:32:211581 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521582 renderer_preferences_,
1583 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211584 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341585 routing_id,
1586 cloned_session_storage_namespace_id);
[email protected]48c9cf2d2009-09-16 16:47:521587 view->opened_by_user_gesture_ = user_gesture;
1588
[email protected]007a848b2009-10-26 15:55:461589 // Record whether the creator frame is trying to suppress the opener field.
1590 view->opener_suppressed_ = opener_suppressed;
1591
[email protected]48c9cf2d2009-09-16 16:47:521592 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091593 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521594 if (!creator_url.is_valid() || !creator_url.IsStandard())
1595 creator_url = GURL();
1596 view->creator_url_ = creator_url;
1597
1598 // Copy over the alternate error page URL so we can have alt error pages in
1599 // the new render view (we don't need the browser to send the URL back down).
1600 view->alternate_error_page_url_ = alternate_error_page_url_;
1601
1602 return view->webview();
1603}
1604
[email protected]3e2b375b2010-04-07 17:03:121605WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521606 RenderWidget* widget = RenderWidget::Create(routing_id_,
1607 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121608 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521609 return widget->webwidget();
1610}
1611
1612WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1613 RenderWidget* widget = RenderWidget::Create(routing_id_,
1614 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121615 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521616 widget->ConfigureAsExternalPopupMenu(info);
1617 return widget->webwidget();
1618}
1619
[email protected]bd92c3a2010-01-13 05:02:341620WebStorageNamespace* RenderView::createSessionStorageNamespace() {
1621 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
1622 return WebStorageNamespace::createSessionStorageNamespace();
[email protected]59afea12010-01-20 04:48:291623 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1624 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1625 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341626}
1627
[email protected]48c9cf2d2009-09-16 16:47:521628void RenderView::didAddMessageToConsole(
1629 const WebConsoleMessage& message, const WebString& source_name,
1630 unsigned source_line) {
1631 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1632 UTF16ToWideHack(message.text),
1633 static_cast<int32>(source_line),
1634 UTF16ToWideHack(source_name)));
1635}
1636
1637void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581638 DCHECK(frame);
1639 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521640}
1641
1642void RenderView::didStartLoading() {
1643 if (is_loading_) {
1644 DLOG(WARNING) << "didStartLoading called while loading";
1645 return;
1646 }
1647
1648 is_loading_ = true;
1649 // Clear the pointer so that we can assign it only when there is an unknown
1650 // plugin on a page.
1651 first_default_plugin_.reset();
1652
1653 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1654}
1655
1656void RenderView::didStopLoading() {
1657 if (!is_loading_) {
1658 DLOG(WARNING) << "DidStopLoading called while not loading";
1659 return;
1660 }
1661
1662 is_loading_ = false;
1663
1664 // NOTE: For now we're doing the safest thing, and sending out notification
1665 // when done loading. This currently isn't an issue as the favicon is only
1666 // displayed when done loading. Ideally we would send notification when
1667 // finished parsing the head, but webkit doesn't support that yet.
1668 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271669 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521670 if (!favicon_url.is_empty())
1671 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1672
[email protected]26aa0482009-09-30 16:55:271673 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521674 true); // autodetected
1675
1676 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1677
[email protected]f9f4841b2010-03-20 05:41:421678 MessageLoop::current()->PostDelayedTask(
1679 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521680 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1681 false),
1682 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521683}
1684
[email protected]f55039a2010-02-17 14:12:061685bool RenderView::isSmartInsertDeleteEnabled() {
1686#if defined(OS_MACOSX)
1687 return true;
1688#else
1689 return false;
1690#endif
1691}
1692
[email protected]04fc9482009-09-18 22:13:031693bool RenderView::isSelectTrailingWhitespaceEnabled() {
1694#if defined(OS_WIN)
1695 return true;
1696#else
1697 return false;
1698#endif
1699}
1700
1701void RenderView::setInputMethodEnabled(bool enabled) {
1702 // Save the updated IME status and mark the input focus has been updated.
1703 // The IME status is to be sent to a browser process next time when
1704 // the input caret is rendered.
1705 if (!ime_control_busy_) {
1706 ime_control_updated_ = true;
1707 ime_control_new_state_ = enabled;
1708 }
1709}
1710
1711void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031712#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031713 if (!handling_input_event_)
1714 return;
1715 // TODO(estade): investigate incremental updates to the selection so that we
1716 // don't send the entire selection over IPC every time.
1717 if (!is_empty_selection) {
1718 // Sometimes we get repeated didChangeSelection calls from webkit when
1719 // the selection hasn't actually changed. We don't want to report these
1720 // because it will cause us to continually claim the X clipboard.
1721 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271722 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031723 if (this_selection == last_selection_)
1724 return;
1725
1726 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1727 this_selection));
1728 last_selection_ = this_selection;
1729 } else {
1730 last_selection_.clear();
1731 }
1732#endif
1733}
1734
1735void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121736 const std::string& name = UTF16ToUTF8(command_name);
1737 if (StartsWithASCII(name, "Move", true) ||
1738 StartsWithASCII(name, "Insert", true) ||
1739 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031740 return;
1741 UserMetricsRecordAction(name);
1742}
1743
[email protected]b2528b72009-09-24 06:57:101744bool RenderView::handleCurrentKeyboardEvent() {
1745 if (edit_commands_.empty())
1746 return false;
1747
[email protected]26aa0482009-09-30 16:55:271748 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101749 if (!frame)
1750 return false;
1751
1752 EditCommands::iterator it = edit_commands_.begin();
1753 EditCommands::iterator end = edit_commands_.end();
1754
[email protected]507b33ea2009-09-29 03:56:511755 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101756 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331757 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1758 // key (but it's the exception). Once one edit command is not executed, it
1759 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101760 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1761 WebString::fromUTF8(it->value)))
1762 break;
[email protected]507b33ea2009-09-29 03:56:511763 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101764 }
1765
[email protected]507b33ea2009-09-29 03:56:511766 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101767}
1768
[email protected]2a3a7762009-10-19 19:17:321769void RenderView::spellCheck(const WebString& text,
1770 int& misspelled_offset,
1771 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561772 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461773
[email protected]85c55dc2009-11-06 03:05:461774 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171775 RenderThread* thread = RenderThread::current();
1776 // Will be NULL during unit tests.
1777 if (thread) {
[email protected]c27324b2009-11-19 22:44:291778 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171779 word.c_str(), word.size(), document_tag_,
1780 &misspelled_offset, &misspelled_length, NULL);
1781 }
[email protected]1dbafaf72009-09-23 19:43:561782}
1783
1784WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321785 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561786 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261787 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561788 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171789 RenderThread* thread = RenderThread::current();
1790 // Will be NULL during unit tests.
1791 if (thread) {
1792 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291793 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171794 word, document_tag_);
1795 }
[email protected]1dbafaf72009-09-23 19:43:561796 }
[email protected]2a3a7762009-10-19 19:17:321797 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561798}
1799
[email protected]c49085c72009-10-02 16:28:561800void RenderView::showSpellingUI(bool show) {
1801 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1802}
1803
[email protected]8922e1f2009-10-03 05:01:261804bool RenderView::isShowingSpellingUI() {
1805 return spelling_panel_visible_;
1806}
1807
[email protected]1dbafaf72009-09-23 19:43:561808void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321809 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1810 word));
[email protected]1dbafaf72009-09-23 19:43:561811}
1812
[email protected]a1128322009-10-06 18:38:461813bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351814 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471815 WebFileChooserCompletion* chooser_completion) {
1816 ViewHostMsg_RunFileChooser_Params ipc_params;
1817 ipc_params.mode = params.multiSelect ?
1818 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1819 ViewHostMsg_RunFileChooser_Params::Open;
1820 ipc_params.title = params.title;
1821 ipc_params.default_file_name =
1822 webkit_glue::WebStringToFilePath(params.initialValue);
1823
1824 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461825}
1826
[email protected]48c9cf2d2009-09-16 16:47:521827void RenderView::runModalAlertDialog(
1828 WebFrame* frame, const WebString& message) {
1829 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1830 UTF16ToWideHack(message),
1831 std::wstring(),
1832 frame->url(),
1833 NULL);
1834}
1835
1836bool RenderView::runModalConfirmDialog(
1837 WebFrame* frame, const WebString& message) {
1838 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1839 UTF16ToWideHack(message),
1840 std::wstring(),
1841 frame->url(),
1842 NULL);
1843}
1844
1845bool RenderView::runModalPromptDialog(
1846 WebFrame* frame, const WebString& message, const WebString& default_value,
1847 WebString* actual_value) {
1848 std::wstring result;
1849 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1850 UTF16ToWideHack(message),
1851 UTF16ToWideHack(default_value),
1852 frame->url(),
1853 &result);
1854 if (ok)
1855 actual_value->assign(WideToUTF16Hack(result));
1856 return ok;
1857}
1858
1859bool RenderView::runModalBeforeUnloadDialog(
1860 WebFrame* frame, const WebString& message) {
1861 bool success = false;
1862 // This is an ignored return value, but is included so we can accept the same
1863 // response as RunJavaScriptMessage.
1864 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211865 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521866 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211867 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521868 return success;
1869}
1870
[email protected]79e37442009-10-09 18:17:441871void RenderView::showContextMenu(
1872 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291873 ContextMenuParams params = ContextMenuParams(data);
1874 if (!params.misspelled_word.empty() && RenderThread::current()) {
1875 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041876 bool spelled_right = RenderThread::current()->spellchecker()->
1877 SpellCheckWord(
1878 params.misspelled_word.c_str(), params.misspelled_word.size(),
1879 document_tag_,
1880 &misspelled_offset, &misspelled_length,
1881 &params.dictionary_suggestions);
1882 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291883 params.misspelled_word.clear();
1884 }
1885
1886 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441887}
1888
[email protected]48c9cf2d2009-09-16 16:47:521889void RenderView::setStatusText(const WebString& text) {
1890}
1891
[email protected]163f8242009-10-30 20:19:551892void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581893 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521894 if (latest_url == target_url_)
1895 return;
[email protected]163f8242009-10-30 20:19:551896
[email protected]48c9cf2d2009-09-16 16:47:521897 // Tell the browser to display a destination link.
1898 if (target_url_status_ == TARGET_INFLIGHT ||
1899 target_url_status_ == TARGET_PENDING) {
1900 // If we have a request in-flight, save the URL to be sent when we
1901 // receive an ACK to the in-flight request. We can happily overwrite
1902 // any existing pending sends.
1903 pending_target_url_ = latest_url;
1904 target_url_status_ = TARGET_PENDING;
1905 } else {
1906 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1907 target_url_ = latest_url;
1908 target_url_status_ = TARGET_INFLIGHT;
1909 }
1910}
1911
[email protected]882daa92009-11-05 16:31:311912void RenderView::StartNavStateSyncTimerIfNecessary() {
1913 int delay;
1914 if (send_content_state_immediately_)
1915 delay = 0;
1916 else if (is_hidden())
1917 delay = kDelaySecondsForContentStateSyncHidden;
1918 else
1919 delay = kDelaySecondsForContentStateSync;
1920
1921 if (nav_state_sync_timer_.IsRunning()) {
1922 // The timer is already running. If the delay of the timer maches the amount
1923 // we want to delay by, then return. Otherwise stop the timer so that it
1924 // gets started with the right delay.
1925 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1926 return;
1927 nav_state_sync_timer_.Stop();
1928 }
1929
1930 nav_state_sync_timer_.Start(
1931 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1932}
1933
[email protected]163f8242009-10-30 20:19:551934void RenderView::setMouseOverURL(const WebURL& url) {
1935 mouse_over_url_ = GURL(url);
1936 UpdateTargetURL(mouse_over_url_, focus_url_);
1937}
1938
1939void RenderView::setKeyboardFocusURL(const WebURL& url) {
1940 focus_url_ = GURL(url);
1941 UpdateTargetURL(focus_url_, mouse_over_url_);
1942}
1943
[email protected]48c9cf2d2009-09-16 16:47:521944void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1945 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1946 hint));
1947}
1948
[email protected]c27ae592010-03-18 15:24:411949void RenderView::startDragging(const WebDragData& data,
1950 WebDragOperationsMask mask,
1951 const WebImage& image,
1952 const WebPoint& imageOffset) {
1953#if WEBKIT_USING_SKIA
1954 SkBitmap bitmap(image.getSkBitmap());
1955#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331956 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411957#endif
1958
[email protected]48c9cf2d2009-09-16 16:47:521959 Send(new ViewHostMsg_StartDragging(routing_id_,
1960 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411961 mask,
1962 bitmap,
1963 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521964}
1965
[email protected]28b92df2009-09-25 17:35:451966bool RenderView::acceptsLoadDrops() {
1967 return renderer_preferences_.can_accept_load_drops;
1968}
1969
[email protected]48c9cf2d2009-09-16 16:47:521970void RenderView::focusNext() {
1971 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1972}
1973
1974void RenderView::focusPrevious() {
1975 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1976}
1977
1978void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521979 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1980}
1981
1982int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001983 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521984}
1985
1986int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001987 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521988}
1989
[email protected]8922e1f2009-10-03 05:01:261990void RenderView::didUpdateInspectorSettings() {
1991 Send(new ViewHostMsg_UpdateInspectorSettings(
1992 routing_id_, webview()->inspectorSettings().utf8()));
1993}
1994
[email protected]acca2a1f2009-10-16 03:53:391995void RenderView::queryAutofillSuggestions(const WebNode& node,
1996 const WebString& name,
1997 const WebString& value) {
1998 static int query_counter = 0;
1999 autofill_query_id_ = query_counter++;
2000 autofill_query_node_ = node;
[email protected]e250e492010-04-06 21:35:362001
2002 const WebFormControlElement& element =
2003 node.toConstElement<WebFormControlElement>();
2004
[email protected]dede9342010-04-12 16:51:112005 webkit_glue::FormField field;
2006 FormManager::WebFormControlElementToFormField(element, true, &field);
[email protected]e250e492010-04-06 21:35:362007
[email protected]72eb2da2010-04-14 00:31:082008 // WebFormControlElementToFormField does not scrape the DOM for the field
2009 // label, so find the label here.
2010 // TODO(jhawkins): Add form and field identities so we can use the cached form
2011 // data in FormManager.
2012 field.set_label(FormManager::LabelForElement(element));
2013
[email protected]dede9342010-04-12 16:51:112014 Send(new ViewHostMsg_QueryFormFieldAutofill(
2015 routing_id_, autofill_query_id_, field));
[email protected]acca2a1f2009-10-16 03:53:392016}
2017
2018void RenderView::removeAutofillSuggestions(const WebString& name,
2019 const WebString& value) {
2020 Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
2021}
2022
[email protected]c83641732010-02-20 01:04:482023void RenderView::didAcceptAutoFillSuggestion(
2024 const WebKit::WebNode& node,
[email protected]8f6e6582010-04-09 02:03:072025 const WebKit::WebString& value,
[email protected]c83641732010-02-20 01:04:482026 const WebKit::WebString& label) {
2027 static int query_counter = 0;
2028 autofill_query_id_ = query_counter++;
2029
[email protected]45c6e532010-03-15 23:51:242030 webkit_glue::FormData form;
[email protected]e6efd022010-03-31 09:34:502031 const WebInputElement element = node.toConstElement<WebInputElement>();
[email protected]b1438212010-04-03 00:30:592032 if (!form_manager_.FindFormWithFormControlElement(
[email protected]da592272010-04-14 20:08:492033 element, FormManager::REQUIRE_NONE, &form))
[email protected]c83641732010-02-20 01:04:482034 return;
2035
2036 Send(new ViewHostMsg_FillAutoFillFormData(
[email protected]8f6e6582010-04-09 02:03:072037 routing_id_, autofill_query_id_, form, value, label));
[email protected]c83641732010-02-20 01:04:482038}
2039
[email protected]79dbc662009-09-04 05:42:512040// WebKit::WebWidgetClient ----------------------------------------------------
2041
initial.commit09911bf2008-07-26 23:55:292042// We are supposed to get a single call to Show for a newly created RenderView
2043// that was created via RenderView::CreateWebView. So, we wait until this
2044// point to dispatch the ShowView message.
2045//
2046// This method provides us with the information about how to display the newly
2047// created RenderView (i.e., as a constrained popup or as a new tab).
2048//
[email protected]4873c7d2009-07-16 06:36:282049void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292050 DCHECK(!did_show_) << "received extraneous Show call";
2051 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2052
2053 if (did_show_)
2054 return;
2055 did_show_ = true;
2056
[email protected]28295ec2009-10-16 05:34:332057 // Force new windows to a popup if they were not opened with a user gesture.
2058 if (!opened_by_user_gesture_) {
2059 // We exempt background tabs for compat with older versions of Chrome.
2060 // TODO(darin): This seems bogus. These should have a user gesture, so
2061 // we probably don't need this check.
2062 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2063 policy = WebKit::WebNavigationPolicyNewPopup;
2064 }
2065
initial.commit09911bf2008-07-26 23:55:292066 // NOTE: initial_pos_ may still have its default values at this point, but
2067 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2068 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282069 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2070 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292071 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242072 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292073}
2074
[email protected]4873c7d2009-07-16 06:36:282075void RenderView::closeWidgetSoon() {
[email protected]2c4410d2009-05-06 23:46:222076 if (!popup_notification_visible_)
[email protected]4873c7d2009-07-16 06:36:282077 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312078}
2079
[email protected]4873c7d2009-07-16 06:36:282080void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292081 DCHECK(did_show_) << "should already have shown the view";
2082
[email protected]c1f50aa2010-02-18 03:46:572083 // We must keep WebKit's shared timer running in this case in order to allow
2084 // showModalDialog to function properly.
2085 //
2086 // TODO(darin): WebKit should really be smarter about suppressing events and
2087 // timers so that we do not need to manage the shared timer in such a heavy
2088 // handed manner.
2089 //
2090 if (RenderThread::current()) // Will be NULL during unit tests.
2091 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2092
[email protected]12636df2009-09-28 22:32:212093 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292094}
2095
[email protected]3d9689372009-09-10 04:29:172096// WebKit::WebFrameClient -----------------------------------------------------
2097
2098WebPlugin* RenderView::createPlugin(
2099 WebFrame* frame, const WebPluginParams& params) {
2100 return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr());
2101}
2102
2103WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
2104 return new WebWorkerProxy(client, RenderThread::current(), routing_id_);
2105}
2106
[email protected]9c00f002009-11-05 22:37:422107WebSharedWorker* RenderView::createSharedWorker(
2108 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372109 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422110
[email protected]30447b62009-11-13 01:13:372111 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512112 bool exists = false;
[email protected]30447b62009-11-13 01:13:372113 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512114 ViewHostMsg_CreateWorker_Params params;
2115 params.url = url;
2116 params.is_shared = true;
2117 params.name = name;
2118 params.document_id = document_id;
2119 params.render_view_route_id = routing_id_;
2120 params.route_id = MSG_ROUTING_NONE;
[email protected]30447b62009-11-13 01:13:372121 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512122 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372123 if (url_mismatch) {
2124 return NULL;
2125 } else {
2126 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492127 document_id,
[email protected]6de0bcf2010-02-17 22:00:512128 exists,
[email protected]30447b62009-11-13 01:13:372129 route_id,
2130 routing_id_);
2131 }
[email protected]9c00f002009-11-05 22:37:422132}
2133
[email protected]3d9689372009-09-10 04:29:172134WebMediaPlayer* RenderView::createMediaPlayer(
2135 WebFrame* frame, WebMediaPlayerClient* client) {
2136 scoped_refptr<media::FilterFactoryCollection> factory =
2137 new media::FilterFactoryCollection();
2138 // Add in any custom filter factories first.
2139 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2140 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2141 // Add the chrome specific audio renderer.
2142 factory->AddFactory(
2143 AudioRendererImpl::CreateFactory(audio_message_filter()));
2144 }
2145
[email protected]80f584d92010-01-21 03:59:042146 WebApplicationCacheHostImpl* appcache_host =
2147 WebApplicationCacheHostImpl::FromFrame(frame);
2148
[email protected]3d9689372009-09-10 04:29:172149 // TODO(hclam): obtain the following parameters from |client|.
2150 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2151 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152152 GURL(), // referrer
2153 "null", // frame origin
2154 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172155 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042156 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172157 routing_id());
2158
[email protected]0436b9a2009-10-23 00:23:052159 // A simple data source that keeps all data in memory.
2160 media::FilterFactory* simple_data_source_factory =
2161 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2162 bridge_factory);
2163 // A sophisticated data source that does memory caching.
2164 media::FilterFactory* buffered_data_source_factory =
2165 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2166 bridge_factory);
2167 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2168 factory->AddFactory(simple_data_source_factory);
2169 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172170 } else {
[email protected]0436b9a2009-10-23 00:23:052171 factory->AddFactory(buffered_data_source_factory);
2172 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172173 }
[email protected]8400e032010-02-26 18:50:112174
2175 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2176 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2177 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2178 } else {
[email protected]b57509eb2010-03-30 01:26:282179 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2180 factory_factory =
2181 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112182 }
2183
2184 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172185}
2186
[email protected]035545f2010-04-09 13:10:212187WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2188 WebFrame* frame, WebApplicationCacheHostClient* client) {
2189 return new RendererWebApplicationCacheHostImpl(
2190 FromWebView(frame->view()), client,
2191 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2192}
2193
[email protected]b921cfd22010-02-25 16:57:512194WebCookieJar* RenderView::cookieJar() {
2195 return &cookie_jar_;
2196}
2197
[email protected]3d9689372009-09-10 04:29:172198void RenderView::willClose(WebFrame* frame) {
2199 if (!frame->parent()) {
2200 const GURL& url = frame->url();
2201 if (url.SchemeIs("http") || url.SchemeIs("https"))
2202 DumpLoadHistograms();
2203 }
[email protected]fa7b6b542009-11-03 05:02:302204
2205 WebDataSource* ds = frame->dataSource();
2206 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2207 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]3d9689372009-09-10 04:29:172208}
2209
[email protected]684e4a42010-01-30 06:44:112210bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002211 if (!enabled_per_settings)
2212 return false;
[email protected]c21f1d52010-03-04 03:19:432213 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112214}
2215
2216bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402217 if (enabled_per_settings &&
2218 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2219 return true;
2220
2221 if (IsWhitelistedForContentSettings(frame))
2222 return true;
2223
2224 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2225 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112226}
2227
[email protected]3d9689372009-09-10 04:29:172228void RenderView::loadURLExternally(
2229 WebFrame* frame, const WebURLRequest& request,
2230 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592231 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2232 if (policy == WebKit::WebNavigationPolicyDownload) {
2233 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2234 } else {
2235 OpenURL(request.url(), referrer, policy);
2236 }
[email protected]3d9689372009-09-10 04:29:172237}
2238
2239WebNavigationPolicy RenderView::decidePolicyForNavigation(
2240 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222241 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172242 // Webkit is asking whether to navigate to a new URL.
2243 // This is fine normally, except if we're showing UI from one security
2244 // context and they're trying to navigate to a different context.
2245 const GURL& url = request.url();
2246
2247 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302248 // navigations.
[email protected]61c9f032010-03-31 23:04:192249 if (ShouldRouteNavigationToBrowser(url, frame, type)) {
2250 last_top_level_navigation_page_id_ = page_id_;
2251 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2252 OpenURL(url, referrer, default_policy);
2253 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172254 }
2255
2256 // A content initiated navigation may have originated from a link-click,
2257 // script, drag-n-drop operation, etc.
2258 bool is_content_initiated =
2259 NavigationState::FromDataSource(frame->provisionalDataSource())->
2260 is_content_initiated();
2261
2262 // We only care about navigations that are within the current tab (as opposed
2263 // to, for example, opening a new window).
2264 // But we sometimes navigate to about:blank to clear a tab, and we want to
2265 // still allow that.
2266 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2267 is_content_initiated && frame->parent() == NULL &&
2268 !url.SchemeIs(chrome::kAboutScheme)) {
2269 // When we received such unsolicited navigations, we sometimes want to
2270 // punt them up to the browser to handle.
[email protected]3a8eecb2010-04-22 23:56:302271 if (CrossesExtensionExtents(frame, url) ||
2272 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172273 BindingsPolicy::is_extension_enabled(enabled_bindings_) ||
2274 frame->isViewSourceModeEnabled() ||
2275 url.SchemeIs(chrome::kViewSourceScheme) ||
2276 url.SchemeIs(chrome::kPrintScheme)) {
2277 OpenURL(url, GURL(), default_policy);
2278 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2279 }
2280 }
2281
2282 // Detect when a page is "forking" a new tab that can be safely rendered in
2283 // its own process. This is done by sites like Gmail that try to open links
2284 // in new windows without script connections back to the original page. We
2285 // treat such cases as browser navigations (in which we will create a new
2286 // renderer for a cross-site navigation), rather than WebKit navigations.
2287 //
2288 // We use the following heuristic to decide whether to fork a new page in its
2289 // own process:
2290 // The parent page must open a new tab to about:blank, set the new tab's
2291 // window.opener to null, and then redirect the tab to a cross-site URL using
2292 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462293 //
2294 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2295 // (see below).
[email protected]3d9689372009-09-10 04:29:172296 bool is_fork =
2297 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252298 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172299 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522300 historyBackListCount() < 1 &&
2301 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172302 // The parent page must have set the child's window.opener to null before
2303 // redirecting to the desired URL.
2304 frame->opener() == NULL &&
2305 // Must be a top-level frame.
2306 frame->parent() == NULL &&
2307 // Must not have issued the request from this page.
2308 is_content_initiated &&
2309 // Must be targeted at the current tab.
2310 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2311 // Must be a JavaScript navigation, which appears as "other".
2312 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462313
2314 // Recognize if this navigation is from a link with rel=noreferrer and
2315 // target=_blank attributes, in which case the opener will be suppressed. If
2316 // so, it is safe to load cross-site pages in a separate process, so we
2317 // should let the browser handle it.
2318 bool is_noreferrer_and_blank_target =
2319 // Frame should be top level and not yet navigated.
2320 frame->parent() == NULL &&
2321 frame->url().isEmpty() &&
2322 historyBackListCount() < 1 &&
2323 historyForwardListCount() < 1 &&
2324 // Links with rel=noreferrer will have no Referer field, and their
2325 // resulting frame will have its window.opener suppressed.
2326 // TODO(creis): should add a request.httpReferrer() method to help avoid
2327 // typos on the unusual spelling of Referer.
2328 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2329 opener_suppressed_ &&
2330 frame->opener() == NULL &&
2331 // Links with target=_blank will have no name.
2332 frame->name().isNull() &&
2333 // Another frame (with a non-empty creator) should have initiated the
2334 // request, targeted at this frame.
2335 !creator_url_.is_empty() &&
2336 is_content_initiated &&
2337 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2338 type == WebKit::WebNavigationTypeOther;
2339
2340 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172341 // Open the URL via the browser, not via WebKit.
2342 OpenURL(url, GURL(), default_policy);
2343 return WebKit::WebNavigationPolicyIgnore;
2344 }
2345
2346 return default_policy;
2347}
2348
[email protected]6069da8c2009-10-20 20:33:492349bool RenderView::canHandleRequest(
2350 WebFrame* frame, const WebURLRequest& request) {
2351 // We allow WebKit to think that everything can be handled even though
2352 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342353 return true;
2354}
2355
[email protected]6069da8c2009-10-20 20:33:492356WebURLError RenderView::cannotHandleRequestError(
2357 WebFrame* frame, const WebURLRequest& request) {
2358 NOTREACHED(); // Since we said we can handle all requests.
2359 return WebURLError();
2360}
2361
2362WebURLError RenderView::cancelledError(
2363 WebFrame* frame, const WebURLRequest& request) {
2364 WebURLError error;
2365 error.domain = WebString::fromUTF8(net::kErrorDomain);
2366 error.reason = net::ERR_ABORTED;
2367 error.unreachableURL = request.url();
2368 return error;
[email protected]7b7a7dc2009-10-19 02:23:342369}
2370
2371void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492372 WebFrame*, const WebURLError&) {
2373 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342374}
2375
[email protected]979c28b2009-11-07 01:30:482376void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172377 NavigationState* navigation_state =
2378 NavigationState::FromDataSource(frame->provisionalDataSource());
2379
2380 if (navigation_state->transition_type() == PageTransition::LINK)
2381 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2382
2383 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352384 WebSearchableFormData web_searchable_form_data(form);
2385 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2386 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212387 web_searchable_form_data.encoding().utf8());
[email protected]66561e72010-05-04 22:29:212388 navigation_state->set_password_form_data(
2389 PasswordFormDomManager::CreatePasswordForm(form));
[email protected]3d9689372009-09-10 04:29:172390
[email protected]b1438212010-04-03 00:30:592391 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042392 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092393 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592394 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172395}
2396
2397void RenderView::willPerformClientRedirect(
2398 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2399 double fire_time) {
2400 // Ignore
2401}
2402
2403void RenderView::didCancelClientRedirect(WebFrame* frame) {
2404 // Ignore
2405}
2406
2407void RenderView::didCompleteClientRedirect(
2408 WebFrame* frame, const WebURL& from) {
2409 if (!frame->parent())
2410 completed_client_redirect_src_ = from;
2411}
2412
2413void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2414 // The rest of RenderView assumes that a WebDataSource will always have a
2415 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482416 bool content_initiated = !pending_navigation_state_.get();
2417 NavigationState* state = content_initiated ?
2418 NavigationState::CreateContentInitiated() :
2419 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182420 if (content_initiated) {
2421 switch (ds->request().cachePolicy()) {
2422 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2423 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2424 break;
2425 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2426 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2427 break;
2428 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2429 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2430 break;
2431 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2432 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2433 break;
2434 }
2435 }
[email protected]fa7b6b542009-11-03 05:02:302436
2437 state->set_user_script_idle_scheduler(
2438 new UserScriptIdleScheduler(this, frame));
2439 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172440}
2441
2442void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2443 WebDataSource* ds = frame->provisionalDataSource();
2444 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2445
2446 navigation_state->set_start_load_time(Time::Now());
2447
2448 // Update the request time if WebKit has better knowledge of it.
2449 if (navigation_state->request_time().is_null()) {
2450 double event_time = ds->triggeringEventTime();
2451 if (event_time != 0.0)
2452 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2453 }
2454
2455 bool is_top_most = !frame->parent();
2456 if (is_top_most) {
2457 navigation_gesture_ = frame->isProcessingUserGesture() ?
2458 NavigationGestureUnknown : NavigationGestureAuto;
2459
2460 // Make sure redirect tracking state is clear for the new load.
2461 completed_client_redirect_src_ = GURL();
2462 } else if (frame->parent()->isLoading()) {
2463 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002464 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172465 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2466 }
2467
2468 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2469 routing_id_, is_top_most, ds->request().url()));
2470}
2471
2472void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2473 if (frame->parent())
2474 return;
2475 // Received a redirect on the main frame.
2476 WebDataSource* data_source = frame->provisionalDataSource();
2477 if (!data_source) {
2478 // Should only be invoked when we have a data source.
2479 NOTREACHED();
2480 return;
2481 }
2482 std::vector<GURL> redirects;
2483 GetRedirectChain(data_source, &redirects);
2484 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512485 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2486 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172487 }
2488}
2489
[email protected]40bd6582009-12-04 23:49:512490void RenderView::didFailProvisionalLoad(WebFrame* frame,
2491 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172492 // Notify the browser that we failed a provisional load with an error.
2493 //
2494 // Note: It is important this notification occur before DidStopLoading so the
2495 // SSL manager can react to the provisional load failure before being
2496 // notified the load stopped.
2497 //
2498 WebDataSource* ds = frame->provisionalDataSource();
2499 DCHECK(ds);
2500
2501 const WebURLRequest& failed_request = ds->request();
2502
2503 bool show_repost_interstitial =
2504 (error.reason == net::ERR_CACHE_MISS &&
2505 EqualsASCII(failed_request.httpMethod(), "POST"));
2506 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2507 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2508 show_repost_interstitial));
2509
2510 // Don't display an error page if this is simply a cancelled load. Aside
2511 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2512 if (error.reason == net::ERR_ABORTED)
2513 return;
2514
2515 // Make sure we never show errors in view source mode.
2516 frame->enableViewSourceMode(false);
2517
2518 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2519
2520 // If this is a failed back/forward/reload navigation, then we need to do a
2521 // 'replace' load. This is necessary to avoid messing up session history.
2522 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2523 // as session history is concerned.
2524 //
2525 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2526 // the page id.
2527 //
2528 bool replace =
2529 navigation_state->pending_page_id() != -1 ||
2530 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2531
2532 // If we failed on a browser initiated request, then make sure that our error
2533 // page load is regarded as the same browser initiated request.
2534 if (!navigation_state->is_content_initiated()) {
2535 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2536 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002537 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172538 navigation_state->transition_type(),
2539 navigation_state->request_time()));
2540 }
2541
2542 // Provide the user with a more helpful error page?
2543 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2544 return;
2545
2546 // Fallback to a local error page.
2547 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2548 replace);
2549}
2550
2551void RenderView::didReceiveDocumentData(
2552 WebFrame* frame, const char* data, size_t data_len,
2553 bool& prevent_default) {
2554 NavigationState* navigation_state =
2555 NavigationState::FromDataSource(frame->dataSource());
2556 if (!navigation_state->postpone_loading_data())
2557 return;
2558
2559 // We're going to call commitDocumentData ourselves...
2560 prevent_default = true;
2561
2562 // Continue buffering the response data for the original 404 page. If it
2563 // grows too large, then we'll just let it through.
2564 navigation_state->append_postponed_data(data, data_len);
2565 if (navigation_state->postponed_data().size() >= 512) {
2566 navigation_state->set_postpone_loading_data(false);
2567 frame->commitDocumentData(navigation_state->postponed_data().data(),
2568 navigation_state->postponed_data().size());
2569 navigation_state->clear_postponed_data();
2570 }
2571}
2572
[email protected]40bd6582009-12-04 23:49:512573void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2574 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172575 NavigationState* navigation_state =
2576 NavigationState::FromDataSource(frame->dataSource());
2577
2578 navigation_state->set_commit_load_time(Time::Now());
2579 if (is_new_navigation) {
2580 // When we perform a new navigation, we need to update the previous session
2581 // history entry with state for the page we are leaving.
2582 UpdateSessionHistory(frame);
2583
2584 // We bump our Page ID to correspond with the new session history entry.
2585 page_id_ = next_page_id_++;
2586
[email protected]d64b07b2010-04-20 22:14:062587 // Any pending translation is now obsolete.
2588 translate_helper_.CancelPendingTranslation();
2589
[email protected]3cc72b12010-03-18 23:03:002590 // Advance our offset in session history, applying the length limit. There
2591 // is now no forward history.
2592 history_list_offset_++;
2593 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2594 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2595 history_list_length_ = history_list_offset_ + 1;
2596
[email protected]f9f4841b2010-03-20 05:41:422597 MessageLoop::current()->PostDelayedTask(
2598 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172599 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2600 page_id_, true),
2601 kDelayForForcedCaptureMs);
2602 } else {
2603 // Inspect the navigation_state on this frame to see if the navigation
2604 // corresponds to a session history navigation... Note: |frame| may or
2605 // may not be the toplevel frame, but for the case of capturing session
2606 // history, the first committed frame suffices. We keep track of whether
2607 // we've seen this commit before so that only capture session history once
2608 // per navigation.
2609 //
2610 // Note that we need to check if the page ID changed. In the case of a
2611 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2612 // previous URL and the current page ID, which would be wrong.
2613 if (navigation_state->pending_page_id() != -1 &&
2614 navigation_state->pending_page_id() != page_id_ &&
2615 !navigation_state->request_committed()) {
2616 // This is a successful session history navigation!
2617 UpdateSessionHistory(frame);
2618 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002619
2620 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172621 }
2622 }
2623
2624 // Remember that we've already processed this request, so we don't update
2625 // the session history again. We do this regardless of whether this is
2626 // a session history navigation, because if we attempted a session history
2627 // navigation without valid HistoryItem state, WebCore will think it is a
2628 // new navigation.
2629 navigation_state->set_request_committed(true);
2630
2631 UpdateURL(frame);
2632
2633 // If this committed load was initiated by a client redirect, we're
2634 // at the last stop now, so clear it.
2635 completed_client_redirect_src_ = GURL();
2636
2637 // 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::didClearWindowObject(WebFrame* frame) {
2642 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2643 BindDOMAutomationController(frame);
2644 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2645 dom_ui_bindings_.set_message_sender(this);
2646 dom_ui_bindings_.set_routing_id(routing_id_);
2647 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2648 }
2649 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2650 external_host_bindings_.set_message_sender(this);
2651 external_host_bindings_.set_routing_id(routing_id_);
2652 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2653 }
2654}
2655
2656void RenderView::didCreateDocumentElement(WebFrame* frame) {
2657 if (RenderThread::current()) { // Will be NULL during unit tests.
2658 RenderThread::current()->user_script_slave()->InjectScripts(
2659 frame, UserScript::DOCUMENT_START);
2660 }
[email protected]078b34612009-09-19 19:31:512661 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2662 view_type_ == ViewType::EXTENSION_MOLE) {
2663 InjectToolstripCSS();
2664 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2665 }
[email protected]3d9689372009-09-10 04:29:172666
2667 // Notify the browser about non-blank documents loading in the top frame.
2668 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252669 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272670 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172671 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2672 }
2673}
2674
2675void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2676 UpdateTitle(frame, title);
2677
2678 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272679 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172680}
2681
[email protected]5019ef12010-04-27 17:26:582682void RenderView::didChangeIcons(WebFrame* frame) {
2683 if (!frame->parent()) {
2684 Send(new ViewHostMsg_UpdateFavIconURL(
2685 routing_id_,
2686 page_id_,
2687 frame->favIconURL()));
2688 }
2689}
2690
[email protected]3d9689372009-09-10 04:29:172691void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2692 WebDataSource* ds = frame->dataSource();
2693 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2694 DCHECK(navigation_state);
2695 navigation_state->set_finish_document_load_time(Time::Now());
2696
2697 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2698
[email protected]e9e07992010-02-17 21:04:362699 // The document has now been fully loaded. Scan for forms to be sent up to
2700 // the browser.
2701 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482702 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362703 SendForms(frame);
[email protected]4d44a1c2010-04-28 19:20:412704 SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:172705
2706 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272707 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172708
2709 if (RenderThread::current()) { // Will be NULL during unit tests.
2710 RenderThread::current()->user_script_slave()->InjectScripts(
2711 frame, UserScript::DOCUMENT_END);
2712 }
[email protected]fa7b6b542009-11-03 05:02:302713
2714 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2715}
2716
2717void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2718 if (RenderThread::current()) { // Will be NULL during unit tests.
2719 RenderThread::current()->user_script_slave()->InjectScripts(
2720 frame, UserScript::DOCUMENT_IDLE);
2721 }
2722
2723 WebFrame* main_frame = webview()->mainFrame();
2724 if (frame == main_frame) {
2725 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202726 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302727 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202728 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302729 pending_code_execution_queue_.pop();
2730 }
2731 }
[email protected]3d9689372009-09-10 04:29:172732}
2733
2734void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]7256c5042010-05-01 08:07:502735 // Ignore
[email protected]3d9689372009-09-10 04:29:172736}
2737
2738void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2739 // Ignore
2740}
2741
2742void RenderView::didFinishLoad(WebFrame* frame) {
2743 WebDataSource* ds = frame->dataSource();
2744 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2745 DCHECK(navigation_state);
2746 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302747 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:412748
2749 // Let the password manager know which password forms are actually visible.
2750 SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:172751}
2752
[email protected]ccbe04e2010-03-17 17:58:432753void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172754 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062755
2756 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2757 // since a new one gets created by didCreateDataSource.
2758 NavigationState* state =
2759 NavigationState::FromDataSource(frame->dataSource());
2760 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2761
[email protected]3d9689372009-09-10 04:29:172762 // If this was a reference fragment navigation that we initiated, then we
2763 // could end up having a non-null pending navigation state. We just need to
2764 // update the ExtraData on the datasource so that others who read the
2765 // ExtraData will get the new NavigationState. Similarly, if we did not
2766 // initiate this navigation, then we need to take care to reset any pre-
2767 // existing navigation state to a content-initiated navigation state.
2768 // DidCreateDataSource conveniently takes care of this for us.
2769 didCreateDataSource(frame, frame->dataSource());
2770
[email protected]f6c2459d2010-02-24 22:34:062771 if (idle_scheduler_ran) {
2772 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2773 NavigationState* new_state =
2774 NavigationState::FromDataSource(frame->dataSource());
2775 new_state->user_script_idle_scheduler()->set_has_run(true);
2776 }
2777
[email protected]3d9689372009-09-10 04:29:172778 didCommitProvisionalLoad(frame, is_new_navigation);
2779
[email protected]26aa0482009-09-30 16:55:272780 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172781}
2782
[email protected]476b6f82009-09-10 21:00:592783void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312784 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592785}
2786
[email protected]3d9689372009-09-10 04:29:172787void RenderView::assignIdentifierToRequest(
2788 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2789 // Ignore
2790}
2791
2792void RenderView::willSendRequest(
2793 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2794 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302795 WebFrame* top_frame = frame->top();
2796 if (!top_frame)
2797 top_frame = frame;
2798 WebDataSource* data_source = top_frame->provisionalDataSource();
2799 if (!data_source)
2800 data_source = top_frame->dataSource();
2801 if (data_source) {
2802 NavigationState* state = NavigationState::FromDataSource(data_source);
2803 if (state && state->is_cache_policy_override_set())
2804 request.setCachePolicy(state->cache_policy_override());
2805 }
[email protected]3d9689372009-09-10 04:29:172806 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502807 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132808 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492809
[email protected]85cc78c2010-05-04 18:30:092810 // Temporary metrics, see site_isolation_metrics.h
2811 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:172812}
2813
2814void RenderView::didReceiveResponse(
2815 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492816
[email protected]85cc78c2010-05-04 18:30:092817 // Temporary metrics, see site_isolation_metrics.h
2818 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
2819 identifier,
2820 response);
[email protected]fa0a3432010-03-30 16:53:492821
[email protected]3d9689372009-09-10 04:29:172822 // Only do this for responses that correspond to a provisional data source
2823 // of the top-most frame. If we have a provisional data source, then we
2824 // can't have any sub-resources yet, so we know that this response must
2825 // correspond to a frame load.
2826 if (!frame->provisionalDataSource() || frame->parent())
2827 return;
2828
2829 // If we are in view source mode, then just let the user see the source of
2830 // the server's 404 error page.
2831 if (frame->isViewSourceModeEnabled())
2832 return;
2833
[email protected]f48013be2010-01-14 22:07:452834 // Record that this was a page loaded over SPDY.
2835 if (response.wasFetchedViaSPDY()) {
2836 NavigationState* navigation_state =
2837 NavigationState::FromDataSource(frame->provisionalDataSource());
2838 navigation_state->set_was_fetched_via_spdy(true);
2839 }
2840
2841 // Consider loading an alternate error page for 404 responses.
2842 if (response.httpStatusCode() != 404)
2843 return;
2844
[email protected]3d9689372009-09-10 04:29:172845 // Can we even load an alternate error page for this URL?
2846 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
2847 return;
2848
2849 NavigationState* navigation_state =
2850 NavigationState::FromDataSource(frame->provisionalDataSource());
2851 navigation_state->set_postpone_loading_data(true);
2852 navigation_state->clear_postponed_data();
2853}
2854
2855void RenderView::didFinishResourceLoad(
2856 WebFrame* frame, unsigned identifier) {
2857 NavigationState* navigation_state =
2858 NavigationState::FromDataSource(frame->dataSource());
2859 if (!navigation_state->postpone_loading_data())
2860 return;
2861
2862 // The server returned a 404 and the content was < 512 bytes (which we
2863 // suppressed). Go ahead and fetch the alternate page content.
2864
2865 const GURL& frame_url = frame->url();
2866
2867 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
2868 DCHECK(error_page_url.is_valid());
2869
2870 WebURLError original_error;
2871 original_error.unreachableURL = frame_url;
2872
2873 navigation_state->set_alt_error_page_fetcher(
2874 new AltErrorPageResourceFetcher(
2875 error_page_url, frame, original_error,
2876 NewCallback(this, &RenderView::AltErrorPageFinished)));
2877}
2878
2879void RenderView::didFailResourceLoad(
2880 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2881 // Ignore
2882}
2883
2884void RenderView::didLoadResourceFromMemoryCache(
2885 WebFrame* frame, const WebURLRequest& request,
2886 const WebURLResponse& response) {
2887 // Let the browser know we loaded a resource from the memory cache. This
2888 // message is needed to display the correct SSL indicators.
2889 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2890 routing_id_,
2891 request.url(),
[email protected]91733b62009-09-18 06:21:092892 frame->securityOrigin().toString().utf8(),
2893 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:172894 response.securityInfo()));
2895}
2896
[email protected]6069da8c2009-10-20 20:33:492897void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292898 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2899}
2900
2901void RenderView::didRunInsecureContent(
2902 WebFrame* frame, const WebSecurityOrigin& origin) {
2903 Send(new ViewHostMsg_DidRunInsecureContent(
2904 routing_id_,
2905 origin.toString().utf8()));
2906}
2907
[email protected]7ea093ba2009-11-03 05:54:592908bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402909 if (enabled_per_settings &&
2910 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
2911 return true;
[email protected]7ea093ba2009-11-03 05:54:592912
[email protected]12bc8472010-04-15 07:29:402913 if (IsWhitelistedForContentSettings(frame))
2914 return true;
[email protected]7ea093ba2009-11-03 05:54:592915
2916 return false; // Other protocols fall through here.
2917}
2918
[email protected]0a1a45432010-03-31 08:09:452919bool RenderView::allowDatabase(
2920 WebFrame* frame, const WebString& name, const WebString& display_name,
2921 unsigned long estimated_size) {
2922 WebSecurityOrigin origin = frame->securityOrigin();
2923 if (origin.isEmpty())
2924 return false; // Uninitialized document?
2925
2926 bool result;
2927 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
2928 origin.toString().utf8(), name, display_name, estimated_size, &result)))
2929 return false;
2930 if (!result)
2931 DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES);
2932 return result;
2933}
[email protected]8934a3b2010-02-25 00:34:002934void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
2935 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
2936}
2937
[email protected]c21f1d52010-03-04 03:19:432938void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
2939 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
2940}
2941
[email protected]3d9689372009-09-10 04:29:172942void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2943 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2944}
2945
[email protected]0c882b282009-10-07 17:01:282946void RenderView::didCreateScriptContext(WebFrame* frame) {
2947 EventBindings::HandleContextCreated(frame, false);
2948}
2949
2950void RenderView::didDestroyScriptContext(WebFrame* frame) {
2951 EventBindings::HandleContextDestroyed(frame);
2952}
2953
2954void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
2955 EventBindings::HandleContextCreated(frame, true);
2956}
2957
[email protected]fc86daa2010-03-30 23:52:532958void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
2959 WebFrame* target,
2960 bool cross_origin,
2961 const WebString& property_name,
2962 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:102963 // TODO(johnnyg): track the individual properties and repeat event_ids.
2964 if (cross_origin)
2965 cross_origin_access_count_++;
2966 else
2967 same_origin_access_count_++;
2968}
2969
[email protected]3d9689372009-09-10 04:29:172970void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142971 CheckPreferredSize();
2972}
2973
2974void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172975 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252976 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172977 // message.
[email protected]705243f2010-05-05 19:58:072978 if (!send_preferred_size_changes_ || !webview())
2979 return;
[email protected]dfca5acf2010-03-22 03:28:432980
[email protected]705243f2010-05-05 19:58:072981 // WebCore likes to tell us things have changed even when they haven't, so
2982 // cache the width and height and only send the IPC message when we're sure
2983 // they're different.
2984 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2985 webview()->mainFrame()->documentElementScrollHeight());
2986 if (size == preferred_size_)
2987 return;
[email protected]c27324b2009-11-19 22:44:292988
[email protected]705243f2010-05-05 19:58:072989 preferred_size_ = size;
2990 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2991 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172992}
2993
[email protected]143dcd592009-11-06 21:33:492994void RenderView::didChangeScrollOffset(WebFrame* frame) {
2995 StartNavStateSyncTimerIfNecessary();
2996}
2997
[email protected]8922e1f2009-10-03 05:01:262998void RenderView::reportFindInPageMatchCount(int request_id, int count,
2999 bool final_update) {
3000 // If we have a message that has been queued up, then we should just replace
3001 // it. The ACK from the browser will make sure it gets sent when the browser
3002 // wants it.
3003 if (queued_find_reply_message_.get()) {
3004 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3005 routing_id_,
3006 request_id,
3007 count,
3008 gfx::Rect(),
3009 -1, // Don't update active match ordinal.
3010 final_update);
3011 queued_find_reply_message_.reset(msg);
3012 } else {
3013 // Send the search result over to the browser process.
3014 Send(new ViewHostMsg_Find_Reply(
3015 routing_id_,
3016 request_id,
3017 count,
3018 gfx::Rect(),
[email protected]705243f2010-05-05 19:58:073019 -1, // Don't update active match ordinal.
[email protected]8922e1f2009-10-03 05:01:263020 final_update));
3021 }
3022}
3023
3024void RenderView::reportFindInPageSelection(int request_id,
3025 int active_match_ordinal,
3026 const WebRect& selection_rect) {
3027 // Send the search result over to the browser process.
3028 Send(new ViewHostMsg_Find_Reply(routing_id_,
3029 request_id,
3030 -1,
3031 selection_rect,
3032 active_match_ordinal,
3033 false));
3034}
3035
[email protected]24a7f3c2010-03-25 08:26:493036void RenderView::ReportNoFindInPageResults(int request_id) {
3037 Send(new ViewHostMsg_Find_Reply(routing_id_,
3038 request_id,
3039 0,
3040 gfx::Rect(),
3041 0,
3042 true));
3043}
3044
[email protected]79dbc662009-09-04 05:42:513045// webkit_glue::WebPluginPageDelegate -----------------------------------------
3046
[email protected]f103ab72009-09-02 17:10:593047webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
3048 const GURL& url,
3049 const std::string& mime_type,
[email protected]f103ab72009-09-02 17:10:593050 std::string* actual_mime_type) {
3051 if (!PluginChannelHost::IsListening())
3052 return NULL;
3053
3054 GURL policy_url;
[email protected]26aa0482009-09-30 16:55:273055 WebFrame* main_frame = webview()->mainFrame();
[email protected]f103ab72009-09-02 17:10:593056 if (main_frame)
3057 policy_url = main_frame->url();
3058
3059 FilePath path;
[email protected]610c0892009-09-08 19:46:183060 render_thread_->Send(new ViewHostMsg_GetPluginPath(
3061 url, policy_url, mime_type, &path, actual_mime_type));
[email protected]f103ab72009-09-02 17:10:593062 if (path.value().empty())
3063 return NULL;
3064
3065 const std::string* mime_type_to_use;
3066 if (!actual_mime_type->empty())
3067 mime_type_to_use = actual_mime_type;
3068 else
3069 mime_type_to_use = &mime_type;
3070
[email protected]d2139662009-12-10 03:21:143071 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283072 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143073 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163074 const char kPepperPrefix[] = "pepper-";
3075 if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143076 if (CommandLine::ForCurrentProcess()->
3077 HasSwitch(switches::kInternalPepper)) {
3078 in_process_plugin = true;
3079 use_pepper_host = true;
3080 } else {
3081 // In process Pepper plugins must be explicitly enabled.
3082 return NULL;
3083 }
[email protected]d7ce4272010-03-27 01:06:013084 } else if (CommandLine::ForCurrentProcess()->
3085 HasSwitch(switches::kInternalPDF) &&
3086 StartsWithASCII(*mime_type_to_use, "application/pdf", true)) {
3087 in_process_plugin = true;
3088 use_pepper_host = true;
[email protected]26e8d5e2009-10-13 02:47:163089 }
[email protected]d2139662009-12-10 03:21:143090 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463091 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3092 if (mime_type == "application/x-nacl-srpc") {
3093 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143094 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463095 }
3096 }
3097 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143098 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283099 WebPluginDelegatePepper* pepper_plugin =
3100 WebPluginDelegatePepper::Create(path, *mime_type_to_use,
3101 AsWeakPtr());
3102 current_pepper_plugins_.insert(pepper_plugin);
3103 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143104 } else {
[email protected]6876dff2010-01-15 19:38:093105#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143106 return WebPluginDelegateImpl::Create(
3107 path, *mime_type_to_use, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093108#else
[email protected]596b2c42010-01-14 20:40:433109 NOTIMPLEMENTED();
3110 return NULL;
[email protected]7b6616f2010-01-14 18:07:553111#endif
[email protected]6876dff2010-01-15 19:38:093112 }
[email protected]f103ab72009-09-02 17:10:593113 }
3114
[email protected]610c0892009-09-08 19:46:183115 return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593116}
3117
3118void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033119#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593120 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3121 routing_id(), window));
3122#endif
3123}
3124
3125void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033126#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593127 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3128 routing_id(), window));
3129#endif
3130 CleanupWindowInPluginMoves(window);
3131}
3132
3133void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3134 SchedulePluginMove(move);
3135}
3136
3137void RenderView::DidStartLoadingForPlugin() {
3138 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523139 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593140}
3141
3142void RenderView::DidStopLoadingForPlugin() {
3143 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523144 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593145}
3146
3147void RenderView::ShowModalHTMLDialogForPlugin(
3148 const GURL& url,
3149 const gfx::Size& size,
3150 const std::string& json_arguments,
3151 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213152 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593153 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213154 json_retval));
[email protected]f103ab72009-09-02 17:10:593155}
3156
[email protected]b921cfd22010-02-25 16:57:513157WebCookieJar* RenderView::GetCookieJar() {
3158 return &cookie_jar_;
3159}
3160
initial.commit09911bf2008-07-26 23:55:293161void RenderView::SyncNavigationState() {
3162 if (!webview())
3163 return;
3164
[email protected]26aa0482009-09-30 16:55:273165 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173166 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293167 return;
[email protected]ca948a22009-06-25 19:36:173168
3169 Send(new ViewHostMsg_UpdateState(
3170 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293171}
3172
[email protected]b0950a72009-09-29 23:16:173173bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3174 // Make sure webview was not shut down.
3175 if (!webview())
3176 return false;
3177 // Create an image resource fetcher and assign it with a call back object.
3178 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273179 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173180 NewCallback(this, &RenderView::DidDownloadImage)));
3181 return true;
3182}
3183
3184void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293185 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173186 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473187 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3188 fetcher->id(),
3189 fetcher->image_url(),
3190 image.isNull(),
3191 image));
[email protected]b0950a72009-09-29 23:16:173192 // Dispose of the image fetcher.
3193 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3194 image_fetchers_.erase(fetcher);
3195 // We're in the callback from the ImageResourceFetcher, best to delay
3196 // deletion.
3197 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293198}
3199
[email protected]bf5c2ff392009-07-08 16:24:333200void RenderView::OnDownloadFavIcon(int id,
3201 const GURL& image_url,
3202 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343203 bool data_image_failed = false;
3204 if (image_url.SchemeIs("data")) {
3205 SkBitmap data_image = ImageFromDataUrl(image_url);
3206 data_image_failed = data_image.empty();
3207 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333208 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3209 data_image));
[email protected]f11ca0732009-04-11 00:09:343210 }
3211 }
3212
[email protected]bf5c2ff392009-07-08 16:24:333213 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173214 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333215 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3216 SkBitmap()));
3217 }
initial.commit09911bf2008-07-26 23:55:293218}
3219
[email protected]f11ca0732009-04-11 00:09:343220SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3221 std::string mime_type, char_set, data;
3222 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3223 // Decode the favicon using WebKit's image decoder.
3224 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3225 const unsigned char* src_data =
3226 reinterpret_cast<const unsigned char*>(&data[0]);
3227
3228 return decoder.Decode(src_data, data.size());
3229 }
3230 return SkBitmap();
3231}
3232
initial.commit09911bf2008-07-26 23:55:293233void RenderView::OnGetApplicationInfo(int page_id) {
3234 webkit_glue::WebApplicationInfo app_info;
3235 if (page_id == page_id_)
3236 webkit_glue::GetApplicationInfo(webview(), &app_info);
3237
3238 // Prune out any data URLs in the set of icons. The browser process expects
3239 // any icon with a data URL to have originated from a favicon. We don't want
3240 // to decode arbitrary data URLs in the browser process. See
3241 // http://b/issue?id=1162972
3242 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593243 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293244 app_info.icons.erase(app_info.icons.begin() + i);
3245 --i;
3246 }
3247 }
3248
3249 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3250}
3251
[email protected]7ccddb8c2009-08-04 17:36:553252GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293253 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553254 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293255 // If the URL that failed was secure, then the embedding web page was not
3256 // expecting a network attacker to be able to manipulate its contents. As
3257 // we fetch alternate error pages over HTTP, we would be allowing a network
3258 // attacker to manipulate the contents of the response if we tried to use
3259 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153260 return GURL();
initial.commit09911bf2008-07-26 23:55:293261 }
3262
3263 // Grab the base URL from the browser process.
3264 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153265 return GURL();
initial.commit09911bf2008-07-26 23:55:293266
3267 // Strip query params from the failed URL.
3268 GURL::Replacements remove_params;
3269 remove_params.ClearUsername();
3270 remove_params.ClearPassword();
3271 remove_params.ClearQuery();
3272 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553273 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503274 std::string spec_to_send = url_to_send.spec();
3275 // Notify link doctor of the url truncation by sending of "?" at the end.
3276 if (failed_url.has_query())
3277 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293278
3279 // Construct the query params to send to link doctor.
3280 std::string params(alternate_error_page_url_.query());
3281 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503282 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293283 params.append("&sourceid=chrome");
3284 params.append("&error=");
3285 switch (error_type) {
3286 case DNS_ERROR:
3287 params.append("dnserror");
3288 break;
3289
3290 case HTTP_404:
3291 params.append("http404");
3292 break;
3293
[email protected]5df266ac2008-10-15 19:50:133294 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333295 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133296 break;
3297
initial.commit09911bf2008-07-26 23:55:293298 default:
3299 NOTREACHED() << "unknown ErrorPageType";
3300 }
3301
3302 // OK, build the final url to return.
3303 GURL::Replacements link_doctor_params;
3304 link_doctor_params.SetQueryStr(params);
3305 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3306 return url;
3307}
3308
[email protected]24a7f3c2010-03-25 08:26:493309webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() {
3310 WebPlugin* plugin = webview()->mainFrame()->document().
3311 toElement<WebPluginDocument>().plugin();
3312 return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate();
3313}
3314
[email protected]6069da8c2009-10-20 20:33:493315void RenderView::OnFind(int request_id, const string16& search_text,
3316 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273317 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493318
3319 if (main_frame->document().isPluginDocument()) {
3320 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3321 if (options.findNext) {
3322 // Just navigate back/forward.
3323 delegate->SelectFindResult(options.forward);
3324 } else {
3325 if (delegate->SupportsFind()) {
3326 delegate->StartFind(UTF16ToUTF8(search_text),
3327 options.matchCase,
3328 request_id);
3329 } else {
3330 ReportNoFindInPageResults(request_id);
3331 }
3332 }
3333 return;
3334 }
3335
[email protected]b4bb2502009-10-01 22:35:273336 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273337 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293338 WebFrame* search_frame = focused_frame; // start searching focused frame.
3339
3340 bool multi_frame = (frame_after_main != main_frame);
3341
3342 // If we have multiple frames, we don't want to wrap the search within the
3343 // frame, so we check here if we only have main_frame in the chain.
3344 bool wrap_within_frame = !multi_frame;
3345
[email protected]b3f2b912009-04-09 16:18:523346 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293347 bool result = false;
3348
[email protected]7830da3e2009-11-06 16:27:263349 // If something is selected when we start searching it means we cannot just
3350 // increment the current match ordinal; we need to re-generate it.
3351 WebRange current_selection = focused_frame->selectionRange();
3352
initial.commit09911bf2008-07-26 23:55:293353 do {
[email protected]dd7daa82009-08-10 05:46:453354 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593355 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293356
3357 if (!result) {
3358 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223359 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293360
3361 // Find the next frame, but skip the invisible ones.
3362 do {
3363 // What is the next frame to search? (we might be going backwards). Note
3364 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593365 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273366 search_frame->traverseNext(true) :
3367 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453368 } while (!search_frame->hasVisibleContent() &&
3369 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293370
[email protected]884db412008-11-24 23:46:503371 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223372 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293373
3374 // If we have multiple frames and we have wrapped back around to the
3375 // focused frame, we need to search it once more allowing wrap within
3376 // the frame, otherwise it will report 'no match' if the focused frame has
3377 // reported matches, but no frames after the focused_frame contain a
3378 // match for the search word(s).
3379 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453380 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593381 request_id, search_text, options, true, // Force wrapping.
3382 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293383 }
3384 }
3385
[email protected]26aa0482009-09-30 16:55:273386 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293387 } while (!result && search_frame != focused_frame);
3388
[email protected]7830da3e2009-11-06 16:27:263389 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293390 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453391 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293392 } else {
3393 // If nothing is found, set result to "0 of 0", otherwise, set it to
3394 // "-1 of 1" to indicate that we found at least one item, but we don't know
3395 // yet what is active.
3396 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3397 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293398
[email protected]4f3dc372009-02-24 00:10:293399 // If we find no matches then this will be our last status update.
3400 // Otherwise the scoping effort will send more results.
3401 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293402
[email protected]4f3dc372009-02-24 00:10:293403 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403404 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593405 request_id,
[email protected]4f3dc372009-02-24 00:10:293406 match_count,
3407 selection_rect,
3408 ordinal,
3409 final_status_update));
initial.commit09911bf2008-07-26 23:55:293410
initial.commit09911bf2008-07-26 23:55:293411 // Scoping effort begins, starting with the mainframe.
3412 search_frame = main_frame;
3413
[email protected]dd7daa82009-08-10 05:46:453414 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293415
3416 do {
3417 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453418 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293419
3420 // We don't start another scoping effort unless at least one match has
3421 // been found.
3422 if (result) {
3423 // Start new scoping request. If the scoping function determines that it
3424 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453425 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593426 search_text,
3427 options,
initial.commit09911bf2008-07-26 23:55:293428 true); // reset the tickmarks
3429 }
3430
3431 // Iterate to the next frame. The frame will not necessarily scope, for
3432 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273433 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293434 } while (search_frame != main_frame);
3435 }
3436}
3437
[email protected]24a7f3c2010-03-25 08:26:493438void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3439 WebView* view = webview();
3440 if (!view)
3441 return;
3442
3443 WebDocument doc = view->mainFrame()->document();
3444 if (doc.isPluginDocument()) {
3445 GetDelegateForPluginDocument()->StopFind();
3446 return;
3447 }
3448
3449 bool clear_selection =
3450 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3451 if (clear_selection)
3452 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3453
3454 WebFrame* frame = view->mainFrame();
3455 while (frame) {
3456 frame->stopFinding(clear_selection);
3457 frame = frame->traverseNext(false);
3458 }
3459
3460 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3461 WebFrame* focused_frame = view->focusedFrame();
3462 if (focused_frame) {
3463 WebDocument doc = focused_frame->document();
3464 if (!doc.isNull()) {
3465 WebNode node = doc.focusedNode();
3466 if (!node.isNull())
3467 node.simulateClick();
3468 }
3469 }
3470 }
3471}
3472
3473void RenderView::OnFindReplyAck() {
3474 // Check if there is any queued up request waiting to be sent.
3475 if (queued_find_reply_message_.get()) {
3476 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423477 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493478 }
3479}
3480
[email protected]8c4cdd42010-01-12 21:31:133481// static
3482std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
[email protected]70082aab2010-02-24 01:44:403483 // Text with less than 100 bytes will probably not provide good results.
3484 // Report it as unknown language.
3485 if (text.length() < 100)
3486 return kUnknownLanguageCode;
3487
[email protected]8c4cdd42010-01-12 21:31:133488 std::string language = kUnknownLanguageCode;
[email protected]8c4cdd42010-01-12 21:31:133489 int num_languages = 0;
3490 bool is_reliable = false;
[email protected]8dc5a2052010-01-19 21:32:423491 string16 input = WideToUTF16(text);
[email protected]8c4cdd42010-01-12 21:31:133492 Language cld_language =
[email protected]8dc5a2052010-01-19 21:32:423493 DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
[email protected]8c4cdd42010-01-12 21:31:133494 &num_languages, NULL);
[email protected]70082aab2010-02-24 01:44:403495 if (is_reliable && cld_language != NUM_LANGUAGES &&
3496 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
[email protected]a7ccc4d2010-01-27 08:14:483497 // We should not use LanguageCode_ISO_639_1 because it does not cover all
3498 // the languages CLD can detect. As a result, it'll return the invalid
[email protected]8d022a92010-02-04 02:49:263499 // language code for tradtional Chinese among others.
3500 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
3501 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
3502 // for Simplified Chinese.
3503 language = LanguageCodeWithDialects(cld_language);
[email protected]8c4cdd42010-01-12 21:31:133504 }
[email protected]8c4cdd42010-01-12 21:31:133505 return language;
[email protected]7893a982010-01-07 23:25:523506}
3507
[email protected]8934a3b2010-02-25 00:34:003508bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353509 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003510 return current_content_settings_.settings[settings_type] !=
3511 CONTENT_SETTING_BLOCK;
3512}
3513
3514void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3515 if (!content_blocked_[settings_type]) {
3516 content_blocked_[settings_type] = true;
3517 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353518 }
[email protected]0de80162010-02-03 04:52:353519}
3520
[email protected]71b0d5d2010-02-15 05:43:073521void RenderView::ClearBlockedContentSettings() {
3522 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3523 content_blocked_[i] = false;
3524}
3525
initial.commit09911bf2008-07-26 23:55:293526void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) {
3527 Send(new ViewHostMsg_DnsPrefetch(host_names));
3528}
3529
[email protected]40bd6582009-12-04 23:49:513530void RenderView::OnZoom(PageZoom::Function function) {
3531 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3532 return;
3533
[email protected]b03794d2010-03-26 19:57:523534 // Should we be saving zoom levels for plugins? It's not clear, so for now
3535 // don't.
3536 if (webview()->mainFrame()->document().isPluginDocument()) {
3537 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3538 int zoom;
3539 if (function == PageZoom::RESET) {
3540 zoom = 0;
3541 } else if (function == PageZoom::ZOOM_OUT) {
3542 zoom = -1;
3543 } else if (function == PageZoom::ZOOM_IN) {
3544 zoom = 1;
3545 } else {
3546 NOTREACHED();
[email protected]754bb3b2010-03-26 20:12:113547 return;
[email protected]b03794d2010-03-26 19:57:523548 }
3549 delegate->Zoom(zoom);
3550 return;
3551 }
3552
[email protected]40bd6582009-12-04 23:49:513553 int zoom_level = webview()->zoomLevel();
3554 int new_zoom_level = webview()->setZoomLevel(false,
3555 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3556
[email protected]9d797f32010-04-23 07:17:543557 // Tell the browser which url got zoomed so it can update the saved values.
3558 Send(new ViewHostMsg_DidZoomURL(
3559 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:513560}
3561
[email protected]9d797f32010-04-23 07:17:543562void RenderView::OnSetContentSettingsForLoadingURL(
3563 const GURL& url,
[email protected]f85f0702010-01-30 09:31:013564 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:543565 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:013566}
3567
[email protected]9d797f32010-04-23 07:17:543568void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
3569 int zoom_level) {
3570 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293571}
3572
[email protected]41fc0322009-09-04 22:23:403573void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273574 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293575}
3576
[email protected]a697f4c2009-09-14 22:30:183577void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273578 WebString no_encoding;
3579 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183580}
3581
[email protected]20ad2692009-11-20 18:27:203582bool RenderView::GetAllChildFrames(
3583 WebFrame* parent_frame,
3584 std::vector<WebFrame*>* frames_vector) const {
3585 if (!parent_frame)
3586 return false;
3587 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3588 child_frame = child_frame->nextSibling()) {
3589 frames_vector->push_back(child_frame);
3590 GetAllChildFrames(child_frame, frames_vector);
3591 }
3592 return true;
3593}
3594
[email protected]dd7daa82009-08-10 05:46:453595WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3596 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273597 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453598
3599 // xpath string can represent a frame deep down the tree (across multiple
3600 // frame DOMs).
3601 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3602 // should break into 2 xpaths
3603 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3604
[email protected]26aa0482009-09-30 16:55:273605 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453606
3607 std::wstring xpath_remaining = xpath;
3608 while (!xpath_remaining.empty()) {
3609 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3610 std::wstring xpath_child;
3611 if (delim_pos != std::wstring::npos) {
3612 xpath_child = xpath_remaining.substr(0, delim_pos);
3613 xpath_remaining.erase(0, delim_pos + 1);
3614 } else {
3615 xpath_remaining.swap(xpath_child);
3616 }
3617 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293618 }
3619
[email protected]dd7daa82009-08-10 05:46:453620 return frame;
initial.commit09911bf2008-07-26 23:55:293621}
3622
[email protected]f29acf52008-11-03 20:08:333623void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3624 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293625 WebFrame* web_frame = GetChildFrame(frame_xpath);
3626 if (!web_frame)
3627 return;
3628
[email protected]dd7daa82009-08-10 05:46:453629 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293630}
3631
[email protected]1810e132009-03-24 23:35:483632void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083633 const std::string& css,
3634 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483635 WebFrame* web_frame = GetChildFrame(frame_xpath);
3636 if (!web_frame)
3637 return;
3638
[email protected]ffaef0c2009-09-15 17:08:083639 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483640}
3641
[email protected]00c39612010-03-06 02:53:283642void RenderView::OnPepperPluginDestroy(
3643 WebPluginDelegatePepper* pepper_plugin) {
3644 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
3645 current_pepper_plugins_.find(pepper_plugin);
3646 if (found_pepper == current_pepper_plugins_.end()) {
3647 NOTREACHED();
3648 return;
3649 }
3650 current_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473651
3652 // The plugin could have been destroyed while it was waiting for a file
3653 // choose callback, so check all pending completion callbacks and NULL them.
3654 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3655 file_chooser_completions_.begin();
3656 i != file_chooser_completions_.end(); /* nothing */) {
3657 if ((*i)->completion == pepper_plugin) {
3658 // We NULL the first one instead of deleting it because the plugin might
3659 // be the one waiting for a file choose callback. If the callback later
3660 // comes, we don't want to send the result to the next callback in line.
3661 if (i == file_chooser_completions_.begin())
3662 (*i)->completion = NULL;
3663 else
3664 i = file_chooser_completions_.erase(i);
3665 } else {
3666 ++i;
3667 }
3668 }
[email protected]00c39612010-03-06 02:53:283669}
3670
initial.commit09911bf2008-07-26 23:55:293671void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3672 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333673 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293674}
3675
[email protected]1810e132009-03-24 23:35:483676void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083677 const std::string& css,
3678 const std::string& id) {
3679 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413680
3681 // Notify RenderViewHost that css has been inserted into the frame.
3682 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483683}
3684
[email protected]7ea066a2009-04-06 20:21:593685void RenderView::OnAddMessageToConsole(
3686 const string16& frame_xpath,
3687 const string16& message,
3688 const WebConsoleMessage::Level& level) {
3689 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593690 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453691 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293692}
3693
[email protected]81e63782009-02-27 19:35:093694void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3695 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293696}
3697
3698void RenderView::OnSetDOMUIProperty(const std::string& name,
3699 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093700 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293701 dom_ui_bindings_.SetProperty(name, value);
3702}
3703
3704void RenderView::OnReservePageIDRange(int size_of_range) {
3705 next_page_id_ += size_of_range + 1;
3706}
3707
[email protected]e80c73b2009-04-07 23:24:583708void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3709 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253710 bool ended,
3711 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033712 if (ended) {
[email protected]26aa0482009-09-30 16:55:273713 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033714 }
initial.commit09911bf2008-07-26 23:55:293715}
3716
3717void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273718 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293719}
3720
initial.commit09911bf2008-07-26 23:55:293721void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103722 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293723 webkit_glue::FillPasswordForm(this->webview(), form_data);
3724}
3725
3726void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583727 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253728 const gfx::Point& screen_point,
3729 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273730 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583731 drop_data.ToDragData(),
3732 drop_data.identity,
3733 client_point,
[email protected]1d9f4132009-09-08 17:29:253734 screen_point,
3735 ops);
initial.commit09911bf2008-07-26 23:55:293736
[email protected]1d9f4132009-09-08 17:29:253737 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293738}
3739
[email protected]e80c73b2009-04-07 23:24:583740void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253741 const gfx::Point& screen_point,
3742 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273743 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253744 client_point,
3745 screen_point,
3746 ops);
initial.commit09911bf2008-07-26 23:55:293747
[email protected]1d9f4132009-09-08 17:29:253748 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293749}
3750
3751void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273752 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293753}
3754
[email protected]e80c73b2009-04-07 23:24:583755void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3756 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273757 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293758}
3759
3760void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593761 webkit_preferences_ = prefs;
3762 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293763}
3764
3765void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3766 alternate_error_page_url_ = url;
3767}
3768
[email protected]a0c7153e2009-12-09 14:36:333769void RenderView::OnCustomContextMenuAction(unsigned action) {
3770 webview()->performCustomContextMenuAction(action);
3771}
3772
[email protected]d4a00a72010-01-29 01:44:423773void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:023774 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:423775 const std::string& source_lang,
3776 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:023777 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
3778 translate_script);
[email protected]d4a00a72010-01-29 01:44:423779}
3780
[email protected]85d252e2010-04-06 22:21:023781void RenderView::OnRevertTranslation(int page_id) {
3782 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:323783}
3784
initial.commit09911bf2008-07-26 23:55:293785void RenderView::OnInstallMissingPlugin() {
3786 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593787 if (first_default_plugin_)
3788 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293789}
3790
[email protected]cdaf8d02010-03-30 19:52:473791void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363792 // This could happen if we navigated to a different page before the user
3793 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473794 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363795 return;
3796
[email protected]cdaf8d02010-03-30 19:52:473797 WebVector<WebString> ws_file_names(paths.size());
3798 for (size_t i = 0; i < paths.size(); ++i)
3799 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463800
[email protected]cdaf8d02010-03-30 19:52:473801 if (file_chooser_completions_.front()->completion)
3802 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3803 file_chooser_completions_.pop_front();
3804
3805 // If there are more pending file chooser requests, schedule one now.
3806 if (!file_chooser_completions_.empty()) {
3807 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3808 file_chooser_completions_.front()->params));
3809 }
initial.commit09911bf2008-07-26 23:55:293810}
3811
3812void RenderView::OnEnableViewSourceMode() {
3813 if (!webview())
3814 return;
[email protected]26aa0482009-09-30 16:55:273815 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293816 if (!main_frame)
3817 return;
3818
[email protected]dd7daa82009-08-10 05:46:453819 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293820}
3821
[email protected]ab32b16c2009-10-16 14:57:253822void RenderView::OnEnablePreferredSizeChangedMode() {
[email protected]705243f2010-05-05 19:58:073823 DCHECK(!send_preferred_size_changes_);
[email protected]ab32b16c2009-10-16 14:57:253824 send_preferred_size_changes_ = true;
[email protected]e8014aa52010-03-03 14:30:063825
3826 if (ViewType::ShouldAutoResize(view_type_))
[email protected]d8a179c2010-01-31 00:58:143827 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3828 &RenderView::CheckPreferredSize);
[email protected]0666aef2009-05-13 19:48:083829}
3830
[email protected]cda45c02010-02-25 19:28:103831void RenderView::OnDisableScrollbarsForSmallWindows(
3832 const gfx::Size& disable_scrollbar_size_limit) {
3833 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3834}
3835
[email protected]80d96fa2009-06-10 22:34:513836void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3837 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373838 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:033839#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:413840 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3841 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463842 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323843
[email protected]644d77e2010-01-27 01:03:103844 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323845 webview()->setScrollbarColors(
3846 renderer_prefs.thumb_inactive_color,
3847 renderer_prefs.thumb_active_color,
3848 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103849 webview()->setSelectionColors(
3850 renderer_prefs.active_selection_bg_color,
3851 renderer_prefs.active_selection_fg_color,
3852 renderer_prefs.inactive_selection_bg_color,
3853 renderer_prefs.inactive_selection_fg_color);
3854 }
[email protected]7a74e102009-09-03 00:16:563855#endif
[email protected]80d96fa2009-06-10 22:34:513856}
3857
[email protected]952cb702009-10-07 05:50:283858void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3859 const WebMediaPlayerAction& action) {
3860 if (webview())
3861 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563862}
3863
[email protected]7b291f92009-08-14 05:43:533864void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:513865 // When this is first set, the bindings aren't fully loaded. We only need
3866 // to call through this API after the page has already been loaded. It's
3867 // also called in didCreateDocumentElement to bootstrap.
3868 if (view_type_ != ViewType::INVALID) {
3869 if (type == ViewType::EXTENSION_MOLE ||
3870 type == ViewType::EXTENSION_TOOLSTRIP) {
3871 ExtensionProcessBindings::SetViewType(webview(), type);
3872 }
3873 }
[email protected]7b291f92009-08-14 05:43:533874 view_type_ = type;
3875}
3876
3877void RenderView::OnUpdateBrowserWindowId(int window_id) {
3878 browser_window_id_ = window_id;
3879}
3880
[email protected]266eb6f2008-09-30 23:56:503881void RenderView::OnGetAccessibilityInfo(
[email protected]6a983b42009-03-20 20:12:253882 const webkit_glue::WebAccessibility::InParams& in_params,
3883 webkit_glue::WebAccessibility::OutParams* out_params) {
[email protected]6c8afae52009-01-22 02:24:573884#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153885 if (!accessibility_.get()) {
3886 // TODO(dglazkov): Once implemented for all ports, remove lazy
3887 // instantiation of accessibility_.
3888 accessibility_.reset(WebAccessibilityCache::create());
3889 accessibility_->initialize(webview());
[email protected]6a983b42009-03-20 20:12:253890 }
[email protected]266eb6f2008-09-30 23:56:503891
[email protected]17455962010-02-24 01:39:353892 out_params->return_code =
3893 webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(),
3894 in_params,
3895 out_params);
[email protected]c7287a92009-11-04 20:06:153896
[email protected]6c8afae52009-01-22 02:24:573897#else // defined(OS_WIN)
3898 // TODO(port): accessibility not yet implemented
3899 NOTIMPLEMENTED();
3900#endif
[email protected]266eb6f2008-09-30 23:56:503901}
3902
[email protected]6a983b42009-03-20 20:12:253903void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) {
[email protected]6c8afae52009-01-22 02:24:573904#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:153905 if (!accessibility_.get()) {
[email protected]266eb6f2008-09-30 23:56:503906 // If accessibility is not activated, ignore clearing message.
3907 return;
3908 }
[email protected]e846d0d2009-05-20 00:53:063909
[email protected]c7287a92009-11-04 20:06:153910 if (clear_all) {
3911 accessibility_->clear();
[email protected]266eb6f2008-09-30 23:56:503912 return;
[email protected]c7287a92009-11-04 20:06:153913 }
3914
3915 accessibility_->remove(acc_obj_id);
[email protected]e846d0d2009-05-20 00:53:063916
[email protected]6c8afae52009-01-22 02:24:573917#else // defined(OS_WIN)
3918 // TODO(port): accessibility not yet implemented
3919 NOTIMPLEMENTED();
3920#endif
[email protected]266eb6f2008-09-30 23:56:503921}
3922
initial.commit09911bf2008-07-26 23:55:293923void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3924 const GURL& page_url) {
3925 // Prepare list to storage all savable resource links.
3926 std::vector<GURL> resources_list;
3927 std::vector<GURL> referrers_list;
3928 std::vector<GURL> frames_list;
3929 webkit_glue::SavableResourcesResult result(&resources_list,
3930 &referrers_list,
3931 &frames_list);
3932
[email protected]dbeb3952009-10-13 18:01:183933 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3934 webview(),
3935 page_url,
3936 &result,
3937 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:293938 // If something is wrong when collecting all savable resource links,
3939 // send empty list to embedder(browser) to tell it failed.
3940 referrers_list.clear();
3941 resources_list.clear();
3942 frames_list.clear();
3943 }
3944
3945 // Send result of all savable resource links to embedder.
3946 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
3947 resources_list,
3948 referrers_list,
3949 frames_list));
3950}
3951
3952void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:323953 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:313954 const std::vector<FilePath>& local_paths,
3955 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:073956
3957 // Convert std::vector of GURLs to WebVector<WebURL>
3958 WebVector<WebURL> weburl_links(links);
3959
3960 // Convert std::vector of std::strings to WebVector<WebString>
3961 WebVector<WebString> webstring_paths(local_paths.size());
3962 for (size_t i = 0; i < local_paths.size(); i++)
3963 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3964
3965 WebPageSerializer::serialize(webview()->mainFrame(),
3966 true, this, weburl_links, webstring_paths,
3967 webkit_glue::FilePathToWebString(
3968 local_directory_name));
initial.commit09911bf2008-07-26 23:55:293969}
3970
[email protected]d9ec5c0f2009-12-23 11:55:073971void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
3972 const WebCString& data,
3973 WebPageSerializerClient::PageSerializationStatus status) {
3974 Send(new ViewHostMsg_SendSerializedHtmlData(
3975 routing_id_,
3976 frame_url,
3977 data.data(),
3978 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:293979}
3980
[email protected]04b4a6c2008-08-02 00:44:473981void RenderView::OnMsgShouldClose() {
[email protected]26aa0482009-09-30 16:55:273982 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473983 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293984}
3985
[email protected]eb6b87a2009-07-24 15:57:393986void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:293987 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3988 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3989 // in the onunload handler from appearing. For now, we're bypassing that and
3990 // calling the FrameLoader's CloseURL method directly. This should be
3991 // revisited to avoid having two ways to close a page. Having a single way
3992 // to close that can run onunload is also useful for fixing
3993 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273994 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:293995 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:453996 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:173997 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:293998 // called when a page is destroyed. DumpLoadHistograms() is safe to call
3999 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454000 if (url.SchemeIs(chrome::kHttpScheme) ||
4001 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294002 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294003 }
[email protected]26aa0482009-09-30 16:55:274004 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294005
[email protected]ab9eabac2010-03-16 16:54:104006 // Reset stats
4007 cross_origin_access_count_ = 0;
4008 same_origin_access_count_ = 0;
4009
[email protected]eb6b87a2009-07-24 15:57:394010 // Just echo back the params in the ACK.
4011 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294012}
4013
4014void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574015#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294016 gfx::NativeTheme::instance()->CloseHandles();
4017 gfx::Rect view_rect(0, 0, size_.width(), size_.height());
[email protected]4873c7d2009-07-16 06:36:284018 didInvalidateRect(view_rect);
[email protected]6c8afae52009-01-22 02:24:574019#else // defined(OS_WIN)
4020 // TODO(port): we don't support theming on non-Windows platforms yet
4021 NOTIMPLEMENTED();
4022#endif
initial.commit09911bf2008-07-26 23:55:294023}
4024
[email protected]28790922009-03-09 19:48:374025void RenderView::OnMessageFromExternalHost(const std::string& message,
4026 const std::string& origin,
4027 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154028 if (message.empty())
4029 return;
4030
[email protected]28790922009-03-09 19:48:374031 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4032 target);
[email protected]3ac14a052008-08-15 21:22:154033}
4034
[email protected]0aa55312008-10-17 21:53:084035void RenderView::OnDisassociateFromPopupCount() {
4036 if (decrement_shared_popup_at_destruction_)
4037 shared_popup_counter_->data--;
4038 shared_popup_counter_ = new SharedRenderViewCounter(0);
4039 decrement_shared_popup_at_destruction_ = false;
4040}
4041
[email protected]15d79e12009-08-02 19:23:454042bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4043 const WebURLError& error,
4044 bool replace) {
4045 // We only show alternate error pages in the main frame. They are
4046 // intended to assist the user when navigating, so there is not much
4047 // value in showing them for failed subframes. Ideally, we would be
4048 // able to use the TYPED transition type for this, but that flag is
4049 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454050 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454051 return false;
4052
4053 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374054 // connection failure.
[email protected]15d79e12009-08-02 19:23:454055 int ec = error.reason;
4056 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4057 ec != net::ERR_CONNECTION_FAILED &&
4058 ec != net::ERR_CONNECTION_REFUSED &&
4059 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374060 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454061 return false;
4062
4063 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554064 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454065 if (!error_page_url.is_valid())
4066 return false;
4067
4068 // Load an empty page first so there is an immediate response to the error,
4069 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454070 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454071 GURL(kUnreachableWebDataURL),
4072 error.unreachableURL,
4073 replace);
4074
4075 // Now, create a fetcher for the error page and associate it with the data
4076 // source we just created via the LoadHTMLString call. That way if another
4077 // navigation occurs, the fetcher will get destroyed.
4078 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454079 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454080 navigation_state->set_alt_error_page_fetcher(
4081 new AltErrorPageResourceFetcher(
4082 error_page_url, frame, error,
4083 NewCallback(this, &RenderView::AltErrorPageFinished)));
4084 return true;
4085}
4086
initial.commit09911bf2008-07-26 23:55:294087std::string RenderView::GetAltHTMLForTemplate(
4088 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394089 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294090 ResourceBundle::GetSharedInstance().GetRawDataResource(
4091 template_resource_id));
4092
4093 if (template_html.empty()) {
4094 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4095 return "";
4096 }
[email protected]7cd22a52009-07-14 00:40:254097
initial.commit09911bf2008-07-26 23:55:294098 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254099 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294100 template_html, &error_strings, "t");
4101}
[email protected]0e79b9e2009-02-13 04:20:484102
[email protected]15d79e12009-08-02 19:23:454103void RenderView::AltErrorPageFinished(WebFrame* frame,
4104 const WebURLError& original_error,
4105 const std::string& html) {
4106 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554107
4108 // If we failed to download the alternate error page, fall back to the
4109 // original error page if present. Otherwise, LoadNavigationErrorPage
4110 // will simply display a default error page.
4111 const std::string* html_to_load = &html;
4112 if (html.empty()) {
4113 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454114 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554115 html_to_load = &navigation_state->postponed_data();
4116 }
4117 LoadNavigationErrorPage(
4118 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454119}
4120
[email protected]30f75e62009-02-25 22:01:004121void RenderView::OnMoveOrResizeStarted() {
4122 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474123 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004124}
4125
[email protected]30f75e62009-02-25 22:01:004126void RenderView::OnResize(const gfx::Size& new_size,
4127 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104128 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474129 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104130
4131 if (send_preferred_size_changes_) {
4132 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4133 // either width or height, allow scroll bars.
4134 bool allow_scrollbars = (
4135 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244136 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104137 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4138 }
4139 }
4140
[email protected]30f75e62009-02-25 22:01:004141 RenderWidget::OnResize(new_size, resizer_rect);
4142}
[email protected]0aa477bd2009-03-23 22:21:434143
[email protected]00c39612010-03-06 02:53:284144void RenderView::DidInitiatePaint() {
4145 // Notify any pepper plugins that we started painting. The plugin "should"
4146 // never notified that we started painting, this is used for internal
4147 // bookkeeping only, so we know that the set can not change under us.
4148 for (std::set<WebPluginDelegatePepper*>::iterator i =
4149 current_pepper_plugins_.begin();
4150 i != current_pepper_plugins_.end(); ++i)
4151 (*i)->RenderViewInitiatedPaint();
4152}
4153
4154void RenderView::DidFlushPaint() {
4155 // Notify any pepper plugins that we painted. This will call into the plugin,
4156 // and we it may ask to close itself as a result. This will, in turn, modify
4157 // our set, possibly invalidating the iterator. So we iterate on a copy that
4158 // won't change out from under us.
4159 std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_;
4160 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4161 i != plugins.end(); ++i) {
4162 // The copy above makes sure our iterator is never invalid if some plugins
4163 // are destroyed. But some plugin may decide to close all of its views in
4164 // response to a paint in one of them, so we need to make sure each one is
4165 // still "current" before using it.
4166 if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end())
4167 (*i)->RenderViewFlushedPaint();
4168 }
4169
4170 WebFrame* main_frame = webview()->mainFrame();
4171
4172 // If we have a provisional frame we are between the start and commit stages
4173 // of loading and we don't want to save stats.
4174 if (!main_frame->provisionalDataSource()) {
4175 WebDataSource* ds = main_frame->dataSource();
4176 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4177 DCHECK(navigation_state);
4178
4179 Time now = Time::Now();
4180 if (navigation_state->first_paint_time().is_null()) {
4181 navigation_state->set_first_paint_time(now);
4182 }
4183 if (navigation_state->first_paint_after_load_time().is_null() &&
4184 !navigation_state->finish_load_time().is_null()) {
4185 navigation_state->set_first_paint_after_load_time(now);
4186 }
4187 }
4188}
4189
4190
[email protected]05d478752009-04-08 23:38:164191void RenderView::OnClearFocusedNode() {
4192 if (webview())
[email protected]26aa0482009-09-30 16:55:274193 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164194}
4195
[email protected]699ab0d2009-04-23 23:19:144196void RenderView::OnSetBackground(const SkBitmap& background) {
4197 if (webview())
[email protected]b4bb2502009-10-01 22:35:274198 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144199
4200 SetBackground(background);
4201}
4202
[email protected]8c66c5a2009-07-22 17:26:344203void RenderView::OnSetActive(bool active) {
4204 if (webview())
[email protected]b4bb2502009-10-01 22:35:274205 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264206
4207#if defined(OS_MACOSX)
4208 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4209 for (plugin_it = plugin_delegates_.begin();
4210 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4211 (*plugin_it)->SetWindowFocus(active);
4212 }
4213#endif
[email protected]8c66c5a2009-07-22 17:26:344214}
4215
[email protected]6ce7abc52010-02-02 18:40:144216#if defined(OS_MACOSX)
4217void RenderView::OnSetWindowVisibility(bool visible) {
4218 // Inform plugins that their container has changed visibility.
4219 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4220 for (plugin_it = plugin_delegates_.begin();
4221 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4222 (*plugin_it)->SetContainerVisibility(visible);
4223 }
4224}
[email protected]1e6e3c992010-02-08 15:52:134225
4226void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4227 gfx::Rect view_frame) {
4228 // Inform plugins that their window's frame has changed.
4229 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4230 for (plugin_it = plugin_delegates_.begin();
4231 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4232 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4233 }
4234}
[email protected]6ce7abc52010-02-02 18:40:144235#endif // OS_MACOSX
4236
[email protected]309d7a282009-03-24 09:18:274237void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584238 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394239 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324240 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474241 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394242 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4243 name,
4244 args,
4245 source_url,
4246 request_id,
[email protected]2f25d7b92009-06-10 00:06:474247 has_callback));
[email protected]309d7a282009-03-24 09:18:274248}
4249
[email protected]c6619182009-05-12 14:59:324250void RenderView::OnExtensionResponse(int request_id,
4251 bool success,
4252 const std::string& response,
4253 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354254 ExtensionProcessBindings::HandleResponse(
4255 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274256}
[email protected]c20210e62009-04-03 21:39:264257
[email protected]078b34612009-09-19 19:31:514258void RenderView::InjectToolstripCSS() {
4259 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4260 return;
4261
4262 static const base::StringPiece toolstrip_css(
4263 ResourceBundle::GetSharedInstance().GetRawDataResource(
4264 IDR_EXTENSION_TOOLSTRIP_CSS));
4265 std::string css = toolstrip_css.as_string();
4266 InsertCSS(L"", css, "ToolstripDefaultCSS");
4267}
4268
[email protected]7120f132009-07-20 21:05:374269void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494270 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194271 bool requires_incognito_access,
4272 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494273 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194274 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374275}
4276
[email protected]e7e4f3c2009-04-21 15:24:084277// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264278//
[email protected]7a9b51f2009-06-29 21:28:294279// There are 13 histograms measuring various times.
[email protected]c20210e62009-04-03 21:39:264280// The time points we keep are
4281// request: time document was requested by user
4282// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254283// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294284// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264285// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294286// first_paint: first paint performed
4287// first_paint_after_load: first paint performed after load is finished
4288// begin: request if it was user requested, start otherwise
4289//
[email protected]c20210e62009-04-03 21:39:264290// The times that we histogram are
[email protected]a2f6bc112009-06-27 16:27:254291// request->start,
[email protected]7a9b51f2009-06-29 21:28:294292// start->commit,
4293// commit->finish_document,
4294// finish_document->finish,
4295// begin->commit,
4296// begin->finishDoc,
4297// begin->finish,
4298// begin->first_paint,
4299// begin->first_paint_after_load
4300// commit->finishDoc,
4301// commit->first_paint,
4302// commit->first_paint_after_load,
4303// finish->first_paint_after_load,
[email protected]c20210e62009-04-03 21:39:264304//
[email protected]e7e4f3c2009-04-21 15:24:084305// It's possible for the request time not to be set, if a client
4306// redirect had been done (the user never requested the page)
4307// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294308// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264309void RenderView::DumpLoadHistograms() const {
[email protected]26aa0482009-09-30 16:55:274310 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564311 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454312 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294313 Time finish = navigation_state->finish_load_time();
[email protected]ed3fb032009-06-16 19:50:564314
[email protected]f9f4841b2010-03-20 05:41:424315 // If we've already dumped, do nothing.
4316 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294317 return;
[email protected]ed3fb032009-06-16 19:50:564318
[email protected]f9f4841b2010-03-20 05:41:424319 // Handle case where user hits "stop" or "back" before loading completely.
4320 bool abandoned_page = finish.is_null();
4321 if (abandoned_page) {
4322 finish = Time::Now();
4323 navigation_state->set_finish_load_time(finish);
4324 }
4325 UMA_HISTOGRAM_ENUMERATION("Renderer4.Abandoned", abandoned_page ? 1 : 0, 2);
4326
[email protected]f8999642009-10-27 21:39:424327 LogNavigationState(navigation_state, main_frame->dataSource());
4328
[email protected]a7ccc4d2010-01-27 08:14:484329 NavigationState::LoadType load_type = navigation_state->load_type();
4330 UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type,
[email protected]4c1b6f0b2010-02-07 16:38:184331 NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484332
[email protected]ab9eabac2010-03-16 16:54:104333 // Site isolation metrics.
4334 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4335 cross_origin_access_count_);
4336 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4337 same_origin_access_count_);
4338
[email protected]7a9b51f2009-06-29 21:28:294339 Time request = navigation_state->request_time();
4340 Time start = navigation_state->start_load_time();
4341 Time commit = navigation_state->commit_load_time();
4342 Time finish_doc = navigation_state->finish_document_load_time();
4343 Time first_paint = navigation_state->first_paint_time();
4344 Time first_paint_after_load =
4345 navigation_state->first_paint_after_load_time();
[email protected]c20210e62009-04-03 21:39:264346
[email protected]7a9b51f2009-06-29 21:28:294347 Time begin;
4348 // Client side redirects will have no request time.
4349 if (request.is_null()) {
4350 begin = start;
4351 } else {
4352 begin = request;
4353 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request);
[email protected]e7e4f3c2009-04-21 15:24:084354 }
[email protected]7a9b51f2009-06-29 21:28:294355 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start);
4356 UMA_HISTOGRAM_MEDIUM_TIMES(
4357 "Renderer4.CommitToFinishDoc", finish_doc - commit);
4358 UMA_HISTOGRAM_MEDIUM_TIMES(
4359 "Renderer4.FinishDocToFinish", finish - finish_doc);
4360
4361 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin);
[email protected]a7ccc4d2010-01-27 08:14:484362
4363 static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10));
4364 static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10));
4365 static const size_t kBeginToFinishDocBucketCount(100);
[email protected]a7ccc4d2010-01-27 08:14:484366 TimeDelta begin_to_finish_doc = finish_doc - begin;
4367 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc);
[email protected]4c1b6f0b2010-02-07 16:38:184368
4369 static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10));
4370 static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10));
4371 static const size_t kBeginToFinishBucketCount(100);
4372 TimeDelta begin_to_finish = finish_doc - begin;
4373 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish,
4374 kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount);
4375
[email protected]a7ccc4d2010-01-27 08:14:484376 switch (load_type) {
4377 case NavigationState::UNDEFINED_LOAD:
4378 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad",
4379 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4380 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184381 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad",
4382 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4383 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484384 break;
4385 case NavigationState::RELOAD:
4386 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload",
4387 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4388 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184389 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload",
4390 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4391 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484392 break;
4393 case NavigationState::HISTORY_LOAD:
4394 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad",
4395 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4396 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184397 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad",
4398 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4399 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484400 break;
4401 case NavigationState::NORMAL_LOAD:
4402 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad",
4403 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4404 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184405 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad",
4406 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4407 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484408 break;
[email protected]4c1b6f0b2010-02-07 16:38:184409 case NavigationState::LINK_LOAD_NORMAL:
4410 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal",
[email protected]a7ccc4d2010-01-27 08:14:484411 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4412 kBeginToFinishDocBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184413 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal",
4414 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4415 kBeginToFinishBucketCount);
4416 break;
4417 case NavigationState::LINK_LOAD_RELOAD:
4418 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload",
4419 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4420 kBeginToFinishDocBucketCount);
4421 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload",
4422 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4423 kBeginToFinishBucketCount);
4424 break;
4425 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4426 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk",
4427 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4428 kBeginToFinishDocBucketCount);
4429 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk",
4430 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4431 kBeginToFinishBucketCount);
4432 break;
4433 case NavigationState::LINK_LOAD_CACHE_ONLY:
4434 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly",
4435 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4436 kBeginToFinishDocBucketCount);
4437 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly",
4438 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4439 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484440 break;
4441 default:
4442 break;
4443 }
4444
4445 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4446 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4447 if (use_dns_histogram) {
[email protected]f9f4841b2010-03-20 05:41:424448 UMA_HISTOGRAM_ENUMERATION(
4449 FieldTrial::MakeName("Renderer4.Abandoned", "DnsImpact"),
4450 abandoned_page ? 1 : 0, 2);
4451 UMA_HISTOGRAM_ENUMERATION(
4452 FieldTrial::MakeName("Renderer4.LoadType", "DnsImpact"),
[email protected]fd11f1752010-02-23 22:35:484453 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484454 switch (load_type) {
4455 case NavigationState::NORMAL_LOAD:
4456 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184457 "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"),
4458 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4459 kBeginToFinishBucketCount);
4460 break;
4461 case NavigationState::LINK_LOAD_NORMAL:
4462 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184463 "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4464 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4465 kBeginToFinishBucketCount);
4466 break;
4467 case NavigationState::LINK_LOAD_RELOAD:
4468 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184469 "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"),
4470 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4471 kBeginToFinishBucketCount);
4472 break;
4473 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4474 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]4c1b6f0b2010-02-07 16:38:184475 "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4476 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4477 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484478 break;
4479 default:
4480 break;
4481 }
4482 }
4483
4484 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4485 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4486 if (use_sdch_histogram) {
[email protected]fd11f1752010-02-23 22:35:484487 UMA_HISTOGRAM_ENUMERATION(
4488 FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"),
4489 load_type, NavigationState::kLoadTypeMax);
[email protected]a7ccc4d2010-01-27 08:14:484490 switch (load_type) {
4491 case NavigationState::NORMAL_LOAD:
4492 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484493 "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"),
4494 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4495 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484496 break;
[email protected]4c1b6f0b2010-02-07 16:38:184497 case NavigationState::LINK_LOAD_NORMAL:
[email protected]a7ccc4d2010-01-27 08:14:484498 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484499 "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4500 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4501 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184502 break;
4503 case NavigationState::LINK_LOAD_RELOAD:
4504 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484505 "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4506 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4507 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184508 break;
4509 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4510 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484511 "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4512 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4513 kBeginToFinishBucketCount);
[email protected]4c1b6f0b2010-02-07 16:38:184514 break;
4515 case NavigationState::LINK_LOAD_CACHE_ONLY:
4516 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
[email protected]fd11f1752010-02-23 22:35:484517 "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4518 begin_to_finish, kBeginToFinishMin, kBeginToFinishMax,
4519 kBeginToFinishBucketCount);
[email protected]a7ccc4d2010-01-27 08:14:484520 break;
4521 default:
4522 break;
4523 }
4524 }
4525
4526 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4527 !FieldTrialList::Find("CacheSize")->group_name().empty());
[email protected]4c1b6f0b2010-02-07 16:38:184528 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4529 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type)
[email protected]a7ccc4d2010-01-27 08:14:484530 UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName(
4531 "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"),
4532 begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax,
4533 kBeginToFinishDocBucketCount);
[email protected]e695fbd62009-06-30 16:31:544534
[email protected]0a32257a2009-07-09 18:10:414535 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish",
4536 finish - start, kBeginToFinishMin,
4537 kBeginToFinishMax, kBeginToFinishBucketCount);
4538 if (!request.is_null())
4539 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish",
4540 finish - request, kBeginToFinishMin,
4541 kBeginToFinishMax, kBeginToFinishBucketCount);
[email protected]e695fbd62009-06-30 16:31:544542
[email protected]7a9b51f2009-06-29 21:28:294543 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit);
4544
4545 if (!first_paint.is_null()) {
4546 UMA_HISTOGRAM_MEDIUM_TIMES(
4547 "Renderer4.BeginToFirstPaint", first_paint - begin);
4548 UMA_HISTOGRAM_MEDIUM_TIMES(
4549 "Renderer4.CommitToFirstPaint", first_paint - commit);
[email protected]c20210e62009-04-03 21:39:264550 }
[email protected]7a9b51f2009-06-29 21:28:294551
4552 if (!first_paint_after_load.is_null()) {
4553 UMA_HISTOGRAM_MEDIUM_TIMES(
4554 "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin);
4555 UMA_HISTOGRAM_MEDIUM_TIMES(
4556 "Renderer4.CommitToFirstPaintAfterLoad",
4557 first_paint_after_load - commit);
4558 UMA_HISTOGRAM_MEDIUM_TIMES(
4559 "Renderer4.FinishToFirstPaintAfterLoad",
4560 first_paint_after_load - finish);
4561 }
4562
4563 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414564
4565 // Since there are currently no guarantees that renderer histograms will be
4566 // sent to the browser, we initiate a PostTask here to be sure that we send
4567 // the histograms we generated. Without this call, pages that don't have an
4568 // on-close-handler might generate data that is lost when the renderer is
4569 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484570 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4571 // should post when the onload is complete, so that it doesn't interfere with
4572 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414573 if (RenderThread::current()) {
4574 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134575 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414576 }
[email protected]c20210e62009-04-03 21:39:264577}
[email protected]e846d0d2009-05-20 00:53:064578
[email protected]f8999642009-10-27 21:39:424579void RenderView::LogNavigationState(const NavigationState* state,
4580 const WebDataSource* ds) const {
4581 // Because this function gets called on every page load,
4582 // take extra care to optimize it away if logging is turned off.
4583 if (logging::LOG_INFO < logging::GetMinLogLevel())
4584 return;
4585
4586 DCHECK(state);
4587 DCHECK(ds);
4588 GURL url(ds->request().url());
4589 Time start = state->start_load_time();
4590 Time finish = state->finish_load_time();
4591 // TODO(mbelshe): should we log more stats?
4592 LOG(INFO) << "PLT: "
4593 << (finish - start).InMilliseconds()
4594 << "ms "
4595 << url.spec();
4596}
4597
[email protected]cc0445f2009-10-13 16:09:084598void RenderView::focusAccessibilityObject(
4599 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064600#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154601 // TODO(dglazkov): Current logic implies that focus change can only be made
4602 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4603 // where accessibility is initialized. We should determine whether that's
4604 // right.
4605 if (!accessibility_.get())
4606 return;
[email protected]e846d0d2009-05-20 00:53:064607
4608 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154609 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064610
4611 // If id is valid, alert the browser side that an accessibility focus change
4612 // occurred.
4613 if (acc_obj_id >= 0)
4614 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4615
4616#else // defined(OS_WIN)
4617 // TODO(port): accessibility not yet implemented
4618 NOTIMPLEMENTED();
4619#endif
4620}
[email protected]daa8c58e2009-06-15 17:21:104621
[email protected]e9e07992010-02-17 21:04:364622void RenderView::SendForms(WebFrame* frame) {
[email protected]b715f7f2010-04-05 22:01:044623 // TODO(jhawkins): Use FormManager once we have strict ordering of form
4624 // control elements in the cache.
4625 WebVector<WebFormElement> web_forms;
4626 frame->forms(web_forms);
4627
[email protected]b1438212010-04-03 00:30:594628 std::vector<FormData> forms;
[email protected]b715f7f2010-04-05 22:01:044629 for (size_t i = 0; i < web_forms.size(); ++i) {
4630 const WebFormElement& web_form = web_forms[i];
4631
4632 FormData form;
4633 FormManager::RequirementsMask requirements =
[email protected]b1438212010-04-03 00:30:594634 static_cast<FormManager::RequirementsMask>(
4635 FormManager::REQUIRE_AUTOCOMPLETE |
4636 FormManager::REQUIRE_ELEMENTS_ENABLED);
[email protected]b715f7f2010-04-05 22:01:044637 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:094638 web_form, requirements, false, &form))
[email protected]b715f7f2010-04-05 22:01:044639 forms.push_back(form);
4640 }
[email protected]e6efd022010-03-31 09:34:504641
4642 if (!forms.empty())
4643 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
[email protected]e9e07992010-02-17 21:04:364644}
4645
[email protected]a3018be2010-03-09 04:28:484646void RenderView::didChangeAccessibilityObjectState(
4647 const WebKit::WebAccessibilityObject& acc_obj) {
4648#if defined(OS_WIN)
4649 // TODO(dglazkov): Current logic implies that a state change can only be made
4650 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4651 // where accessibility is initialized. We should determine whether that's
4652 // right.
4653 if (!accessibility_.get())
4654 return;
4655
4656 // Retrieve the accessibility object id of the AccessibilityObject.
4657 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4658
4659 // If id is valid, alert the browser side that an accessibility object state
4660 // change occurred.
4661 if (acc_obj_id >= 0)
4662 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4663 acc_obj_id));
4664
4665#else // defined(OS_WIN)
4666 // TODO(port): accessibility not yet implemented
4667 NOTIMPLEMENTED();
4668#endif
4669}
4670
[email protected]4d44a1c2010-04-28 19:20:414671void RenderView::SendPasswordForms(WebFrame* frame, bool only_visible) {
[email protected]979c28b2009-11-07 01:30:484672 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454673 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104674
4675 std::vector<PasswordForm> password_forms;
4676 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484677 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104678
4679 // Respect autocomplete=off.
[email protected]4d44a1c2010-04-28 19:20:414680 if (!form.autoComplete())
4681 continue;
4682 if (only_visible && !form.hasNonEmptyBoundingBox())
4683 continue;
4684 scoped_ptr<PasswordForm> password_form(
4685 PasswordFormDomManager::CreatePasswordForm(form));
4686 if (password_form.get())
4687 password_forms.push_back(*password_form);
[email protected]daa8c58e2009-06-15 17:21:104688 }
4689
[email protected]4d44a1c2010-04-28 19:20:414690 if (password_forms.empty())
4691 return;
4692 if (only_visible)
4693 Send(new ViewHostMsg_PasswordFormsVisible(routing_id_, password_forms));
4694 else
4695 Send(new ViewHostMsg_PasswordFormsFound(routing_id_, password_forms));
[email protected]daa8c58e2009-06-15 17:21:104696}
[email protected]0fda7272009-06-26 15:49:334697
4698void RenderView::Print(WebFrame* frame, bool script_initiated) {
4699 DCHECK(frame);
4700 if (print_helper_.get() == NULL) {
4701 print_helper_.reset(new PrintWebViewHelper(this));
4702 }
4703 print_helper_->Print(frame, script_initiated);
4704}
[email protected]446705872009-09-10 07:22:484705
4706void RenderView::OnSetEditCommandsForNextKeyEvent(
4707 const EditCommands& edit_commands) {
4708 edit_commands_ = edit_commands;
4709}
4710
[email protected]61f5a7b2009-12-22 22:21:204711void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:274712 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:354713 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:204714 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
4715 false));
[email protected]912256b32009-09-18 09:47:354716 return;
4717 }
4718
[email protected]fa7b6b542009-11-03 05:02:304719 WebDataSource* ds = main_frame->dataSource();
4720 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4721 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:204722 pending_code_execution_queue_.push(
4723 linked_ptr<ViewMsg_ExecuteCode_Params>(
4724 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:304725 return;
4726 }
4727
[email protected]61f5a7b2009-12-22 22:21:204728 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:304729}
4730
4731void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:204732 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:484733 // Don't execute scripts in gallery pages.
4734 GURL frame_url = GURL(frame->url());
4735 if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) {
4736 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
4737 return;
4738 }
4739
[email protected]20ad2692009-11-20 18:27:204740 std::vector<WebFrame*> frame_vector;
4741 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:204742 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:204743 GetAllChildFrames(frame, &frame_vector);
4744
4745 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
4746 frame_it != frame_vector.end(); ++frame_it) {
4747 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:204748 if (params.is_javascript) {
4749 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
4750 continue;
4751
[email protected]20ad2692009-11-20 18:27:204752 std::vector<WebScriptSource> sources;
4753 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:204754 WebScriptSource(WebString::fromUTF8(params.code)));
4755 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:204756 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:204757 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:204758 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
4759 } else {
[email protected]61f5a7b2009-12-22 22:21:204760 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:204761 }
[email protected]912256b32009-09-18 09:47:354762 }
4763
[email protected]61f5a7b2009-12-22 22:21:204764 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:354765}
4766
[email protected]60c42a8c72009-10-09 04:08:594767void RenderView::Close() {
4768 // We need to grab a pointer to the doomed WebView before we destroy it.
4769 WebView* doomed = webview();
4770 RenderWidget::Close();
4771 Singleton<ViewMap>::get()->erase(doomed);
4772}
4773
[email protected]446705872009-09-10 07:22:484774void RenderView::DidHandleKeyEvent() {
4775 edit_commands_.clear();
4776}
4777
[email protected]941e4552010-02-01 21:23:434778#if defined(OS_MACOSX)
4779void RenderView::OnWasHidden() {
4780 RenderWidget::OnWasHidden();
4781
4782 // Inform plugins that their container is no longer visible.
4783 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4784 for (plugin_it = plugin_delegates_.begin();
4785 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4786 (*plugin_it)->SetContainerVisibility(false);
4787 }
4788}
4789
4790void RenderView::OnWasRestored(bool needs_repainting) {
4791 RenderWidget::OnWasRestored(needs_repainting);
4792
4793 // Inform plugins that their container is now visible.
4794 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4795 for (plugin_it = plugin_delegates_.begin();
4796 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4797 (*plugin_it)->SetContainerVisibility(true);
4798 }
4799}
[email protected]1e6e3c992010-02-08 15:52:134800
4801void RenderView::OnSetFocus(bool enable) {
4802 RenderWidget::OnSetFocus(enable);
4803
4804 // RenderWidget's call to setFocus can cause the underlying webview's
4805 // activation state to change just like a call to setIsActive.
4806 if (enable && webview() && webview()->isActive()) {
4807 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4808 for (plugin_it = plugin_delegates_.begin();
4809 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4810 (*plugin_it)->SetWindowFocus(true);
4811 }
4812 }
4813}
[email protected]941e4552010-02-01 21:23:434814#endif // OS_MACOSX
4815
[email protected]83dde542009-09-11 20:59:554816void RenderView::EnsureDocumentTag() {
4817 // TODO(darin): There's actually no reason for this to be here. We should
4818 // have the browser side manage the document tag.
4819#if defined(OS_MACOSX)
4820 if (!has_document_tag_) {
4821 // Make the call to get the tag.
4822 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
4823 has_document_tag_ = true;
4824 }
4825#endif
4826}
[email protected]12636df2009-09-28 22:32:214827
[email protected]43f28f832010-02-03 02:28:484828#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:034829gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
4830 bool opaque) {
[email protected]43f28f832010-02-03 02:28:484831 gfx::PluginWindowHandle window = NULL;
4832 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]ea04a4e12010-04-15 00:58:034833 routing_id(), opaque, &window));
[email protected]43f28f832010-02-03 02:28:484834 return window;
4835}
4836
4837void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
4838 if (window)
4839 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
4840}
4841
[email protected]44ce0b12010-03-12 16:45:334842void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4843 int32 width,
4844 int32 height,
4845 uint64 io_surface_identifier) {
4846 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484847 routing_id(), window, width, height, io_surface_identifier));
4848}
4849
[email protected]44ce0b12010-03-12 16:45:334850void RenderView::AcceleratedSurfaceSetTransportDIB(
4851 gfx::PluginWindowHandle window,
4852 int32 width,
4853 int32 height,
4854 TransportDIB::Handle transport_dib) {
4855 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074856 routing_id(), window, width, height, transport_dib));
4857}
4858
[email protected]44ce0b12010-03-12 16:45:334859TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4860 size_t size) {
[email protected]1aef98132010-02-23 18:00:074861 TransportDIB::Handle dib_handle;
4862 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384863 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074864 return dib_handle;
4865 // Return an invalid handle if Send() fails.
4866 return TransportDIB::DefaultHandleValue();
4867}
4868
[email protected]44ce0b12010-03-12 16:45:334869void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074870 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4871}
4872
[email protected]44ce0b12010-03-12 16:45:334873void RenderView::AcceleratedSurfaceBuffersSwapped(
4874 gfx::PluginWindowHandle window) {
4875 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:484876}
4877#endif
[email protected]58c321d2010-02-19 12:11:284878
[email protected]cdaf8d02010-03-30 19:52:474879bool RenderView::ScheduleFileChooser(
4880 const ViewHostMsg_RunFileChooser_Params& params,
4881 WebFileChooserCompletion* completion) {
4882 static const size_t kMaximumPendingFileChooseRequests = 4;
4883 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4884 // This sanity check prevents too many file choose requests from getting
4885 // queued which could DoS the user. Getting these is most likely a
4886 // programming error (there are many ways to DoS the user so it's not
4887 // considered a "real" security check), either in JS requesting many file
4888 // choosers to pop up, or in a plugin.
4889 //
4890 // TODO(brettw) we might possibly want to require a user gesture to open
4891 // a file picker, which will address this issue in a better way.
4892 return false;
4893 }
4894
4895 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4896 new PendingFileChooser(params, completion)));
4897 if (file_chooser_completions_.size() == 1) {
4898 // Actually show the browse dialog when this is the first request.
4899 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4900 }
4901 return true;
4902}
4903
[email protected]290838a2010-04-27 17:37:014904void RenderView::OnPageTranslated() {
4905 WebFrame* frame = webview()->mainFrame();
4906 if (!frame)
4907 return;
4908
4909 // The page is translated, so try to extract the form data again.
4910 form_manager_.ExtractForms(frame);
4911 SendForms(frame);
4912}
4913
[email protected]8a5f7002010-03-31 13:47:354914WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:284915 if (!geolocation_dispatcher_.get())
4916 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
4917 return geolocation_dispatcher_.get();
4918}
[email protected]61c9f032010-03-31 23:04:194919
4920bool RenderView::ShouldRouteNavigationToBrowser(
4921 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
4922 // If the browser is interested, then give it a chance to look at top level
4923 // navigations
4924 if (!renderer_preferences_.browser_handles_top_level_requests)
4925 return false;
4926
4927 // Must be a top level frame.
4928 if (frame->parent() != NULL)
4929 return false;
4930
4931 // Skip if navigation is on the same page (using '#').
4932 GURL frame_origin = GURL(frame->url()).GetOrigin();
4933 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
4934 // The link click could stay on the same page, in cases where it sends some
4935 // parameters to the same URL.
4936 if (type == WebKit::WebNavigationTypeLinkClicked)
4937 return true;
4938
4939 if (last_top_level_navigation_page_id_ != page_id_ &&
4940 // Not interested in reloads.
4941 type != WebKit::WebNavigationTypeReload &&
4942 type != WebKit::WebNavigationTypeFormSubmitted) {
4943 return true;
4944 }
4945 }
4946 return false;
4947}