blob: d66d7910aa7f84df12a72e298011747a4f0afb75 [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]7bf795d92010-05-22 00:14:2819#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
[email protected]7b291f92009-08-14 05:43:5321#include "base/singleton.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_piece.h"
23#include "base/string_util.h"
[email protected]30507922010-01-15 16:48:2324#include "base/time.h"
[email protected]6c8afae52009-01-22 02:24:5725#include "build/build_config.h"
[email protected]035545f2010-04-09 13:10:2126#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0927#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5528#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1729#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2830#include "chrome/common/chrome_paths.h"
31#include "chrome/common/chrome_switches.h"
[email protected]a0cf04a2010-06-23 03:29:5532#include "chrome/common/extensions/extension.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/common/jstemplate_builder.h"
[email protected]630e26b2008-10-14 22:55:1734#include "chrome/common/page_zoom.h"
[email protected]4e0616e2010-05-28 14:55:5335#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2936#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2637#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5939#include "chrome/common/url_constants.h"
[email protected]534c66c2010-04-28 22:53:1140#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2941#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2542#include "chrome/renderer/audio_message_filter.h"
[email protected]e4ac5df2009-03-17 15:33:1143#include "chrome/renderer/devtools_agent.h"
44#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3545#include "chrome/renderer/extension_groups.h"
[email protected]f816c012009-06-26 21:48:3246#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3547#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]7120f132009-07-20 21:05:3748#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]58c321d2010-02-19 12:11:2849#include "chrome/renderer/geolocation_dispatcher.h"
initial.commit09911bf2008-07-26 23:55:2950#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5651#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]8400e032010-02-26 18:50:1152#include "chrome/renderer/media/ipc_video_renderer.h"
[email protected]ed3fb032009-06-16 19:50:5653#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1254#include "chrome/renderer/notification_provider.h"
[email protected]8beff0762009-09-29 02:18:3055#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5056#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2557#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2858#include "chrome/renderer/render_thread.h"
[email protected]035545f2010-04-09 13:10:2159#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3460#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]85c55dc2009-11-06 03:05:4661#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]0938d3c2009-01-09 20:37:3562#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2963#include "chrome/renderer/visitedlink_slave.h"
[email protected]d439ba072009-10-17 22:32:2964#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2965#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4266#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5667#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1568#include "gfx/color_utils.h"
69#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5770#include "gfx/native_widget_types.h"
[email protected]34ac8f32009-02-22 23:03:2771#include "grit/generated_resources.h"
72#include "grit/renderer_resources.h"
[email protected]f11ca0732009-04-11 00:09:3473#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:2974#include "net/base/escape.h"
75#include "net/base/net_errors.h"
[email protected]c399a8a2008-11-22 19:38:0076#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:1077#include "skia/ext/image_operations.h"
[email protected]651272792010-02-04 23:16:3078#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
[email protected]418ed5ab2009-11-12 01:14:4979#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]d9ec5c0f2009-12-23 11:55:0780#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4981#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
82#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3283#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4984#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3585#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]b1438212010-04-03 00:30:5986#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:4987#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
88#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
89#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:4190#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:5091#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4992#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3293#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0794#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:4995#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]b4f68dea2010-05-13 06:03:1796#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:4997#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4998#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
99#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
100#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
102#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
103#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
104#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34105#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49106#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
107#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
108#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
109#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
110#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
111#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]534c66c2010-04-28 22:53:11112#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04113#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29114#include "webkit/default_plugin/default_plugin_shared.h"
initial.commit09911bf2008-07-26 23:55:29115#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59116#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24117#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24118#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34119#include "webkit/glue/image_decoder.h"
[email protected]8e296bbd2009-07-22 21:37:17120#include "webkit/glue/media/buffered_data_source.h"
[email protected]8380c092009-06-25 17:45:51121#include "webkit/glue/media/simple_data_source.h"
[email protected]85cc78c2010-05-04 18:30:09122#include "webkit/glue/media/video_renderer_impl.h"
initial.commit09911bf2008-07-26 23:55:29123#include "webkit/glue/password_form.h"
[email protected]b4f68dea2010-05-13 06:03:17124#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29125#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30126#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23127#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30128#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]85cc78c2010-05-04 18:30:09129#include "webkit/glue/site_isolation_metrics.h"
initial.commit09911bf2008-07-26 23:55:29130#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29131#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17132#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29133
[email protected]6c8afae52009-01-22 02:24:57134#if defined(OS_WIN)
135// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57136// * theming
[email protected]cd818412010-03-19 03:23:15137#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03138#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46139#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33140#elif defined(OS_MACOSX)
141#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57142#endif
143
[email protected]80f584d92010-01-21 03:59:04144using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26145using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33146using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45147using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59148using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24149using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17150using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56151using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10152using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09153using webkit_glue::SiteIsolationMetrics;
[email protected]c7287a92009-11-04 20:06:15154using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08155using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21156using WebKit::WebApplicationCacheHost;
157using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41158using WebKit::WebColor;
159using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59160using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44161using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51162using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07163using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55164using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28165using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29166using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00167using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58168using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25169using WebKit::WebDragOperation;
170using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51171using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47172using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49173using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59174using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48175using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45176using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17177using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41178using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50179using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17180using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28181using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17182using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28183using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28184using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51185using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07186using WebKit::WebPageSerializer;
187using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17188using WebKit::WebPlugin;
189using WebKit::WebPluginParams;
[email protected]24a7f3c2010-03-25 08:26:49190using WebKit::WebPluginDocument;
[email protected]48c9cf2d2009-09-16 16:47:52191using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59192using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51193using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52194using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40195using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35196using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29197using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59198using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42199using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02200using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34201using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28202using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51203using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52204using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28205using WebKit::WebURL;
206using WebKit::WebURLError;
207using WebKit::WebURLRequest;
208using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28209using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03210using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28211using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43212using WebKit::WebWorker;
213using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11214using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33215
initial.commit09911bf2008-07-26 23:55:29216//-----------------------------------------------------------------------------
217
[email protected]3354d3e2010-06-10 19:53:02218typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
219
initial.commit09911bf2008-07-26 23:55:29220// define to write the time necessary for thumbnail/DOM text retrieval,
221// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29222// #define TIME_TEXT_RETRIEVAL
223
224// maximum number of characters in the document to index, any text beyond this
225// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57226static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29227
228// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37229static const int kThumbnailWidth = 212;
230static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29231
232// Delay in milliseconds that we'll wait before capturing the page contents
233// and thumbnail.
234static const int kDelayForCaptureMs = 500;
235
236// Typically, we capture the page data once the page is loaded.
237// Sometimes, the page never finishes to load, preventing the page capture
238// To workaround this problem, we always perform a capture after the following
239// delay.
240static const int kDelayForForcedCaptureMs = 6000;
241
[email protected]882daa92009-11-05 16:31:31242// Time, in seconds, we delay before sending content state changes (such as form
243// state and scroll position) to the browser. We delay sending changes to avoid
244// spamming the browser.
245// To avoid having tab/session restore require sending a message to get the
246// current content state during tab closing we use a shorter timeout for the
247// foreground renderer. This means there is a small window of time from which
248// content state is modified and not sent to session restore, but this is
249// better than having to wake up all renderers during shutdown.
250static const int kDelaySecondsForContentStateSyncHidden = 5;
251static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29252
[email protected]0aa55312008-10-17 21:53:08253// The maximum number of popups that can be spawned from one page.
254static const int kMaximumNumberOfUnacknowledgedPopups = 25;
255
initial.commit09911bf2008-07-26 23:55:29256static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16257 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29258
[email protected]50b691c2008-10-31 19:08:35259static const char* const kBackForwardNavigationScheme = "history";
260
[email protected]d64b07b2010-04-20 22:14:06261// static
262const char* const RenderView::kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13263
[email protected]726985e22009-06-18 21:09:28264static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
265 WebVector<WebURL> urls;
266 ds->redirectChain(urls);
267 result->reserve(urls.size());
268 for (size_t i = 0; i < urls.size(); ++i)
269 result->push_back(urls[i]);
270}
271
[email protected]61f5a7b2009-12-22 22:21:20272static bool UrlMatchesPermissions(
273 const GURL& url, const std::vector<URLPattern>& host_permissions) {
274 for (size_t i = 0; i < host_permissions.size(); ++i) {
275 if (host_permissions[i].MatchesUrl(url))
276 return true;
277 }
278
279 return false;
280}
281
[email protected]30507922010-01-15 16:48:23282static bool PaintViewIntoCanvas(WebView* view,
283 skia::PlatformCanvas& canvas) {
284 view->layout();
285 const WebSize& size = view->size();
286
287 if (!canvas.initialize(size.width, size.height, true))
288 return false;
289
290 view->paint(webkit_glue::ToWebCanvas(&canvas),
291 WebRect(0, 0, size.width, size.height));
292 // TODO: Add a way to snapshot the whole page, not just the currently
293 // visible part.
294
295 return true;
296}
297
298// Calculates how "boring" a thumbnail is. The boring score is the
299// 0,1 ranged percentage of pixels that are the most common
300// luma. Higher boring scores indicate that a higher percentage of a
301// bitmap are all the same brightness.
302static double CalculateBoringScore(SkBitmap* bitmap) {
303 int histogram[256] = {0};
304 color_utils::BuildLumaHistogram(bitmap, histogram);
305
306 int color_count = *std::max_element(histogram, histogram + 256);
307 int pixel_count = bitmap->width() * bitmap->height();
308 return static_cast<double>(color_count) / pixel_count;
309}
310
[email protected]12bc8472010-04-15 07:29:40311// True if |frame| contains content that is white-listed for content settings.
312static bool IsWhitelistedForContentSettings(WebFrame* frame) {
313 WebSecurityOrigin origin = frame->securityOrigin();
314 if (origin.isEmpty())
315 return false; // Uninitialized document?
316
317 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
318 return true; // Browser UI elements should still work.
319
320 // If the scheme is ftp: or file:, an empty file name indicates a directory
321 // listing, which requires JavaScript to function properly.
322 GURL frame_url = frame->url();
323 const char* kDirProtocols[] = { "ftp", "file" };
324 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
325 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
326 return frame_url.SchemeIs(kDirProtocols[i]) &&
327 frame_url.ExtractFileName().empty();
328 }
329 }
330
331 return false;
332}
333
[email protected]3a8eecb2010-04-22 23:56:30334// Returns true if the frame is navigating to an URL either into or out of an
335// extension app's extent.
336static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
337 if (!RenderThread::current())
338 return false;
339
340 // If the URL is still empty, this is a window.open navigation. Check the
341 // opener's URL.
342 GURL old_url(frame->url());
343 if (old_url.is_empty() && frame->opener())
344 old_url = frame->opener()->url();
345
346 std::string old_extension =
[email protected]4fdbc1492010-07-01 01:20:59347 RenderThread::current()->GetExtensionIdByURL(old_url);
348 if (!old_extension.empty()) {
349 if (RenderThread::current()->GetExtensionIdByBrowseExtent(new_url) ==
350 old_extension) {
351 return false;
352 }
353 }
354
[email protected]3a8eecb2010-04-22 23:56:30355 std::string new_extension =
[email protected]4fdbc1492010-07-01 01:20:59356 RenderThread::current()->GetExtensionIdByURL(new_url);
357 return old_extension != new_extension;
[email protected]3a8eecb2010-04-22 23:56:30358}
359
[email protected]3354d3e2010-06-10 19:53:02360// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
361// if it failed.
362//
363// Note this only works on Windows at this time. It always returns 'unknown'
364// on other platforms.
[email protected]e5106202010-06-11 21:12:36365static std::string DetermineTextLanguage(const string16& text) {
[email protected]3354d3e2010-06-10 19:53:02366 // Text with less than 100 bytes will probably not provide good results.
367 // Report it as unknown language.
368 if (text.length() < 100)
369 return RenderView::kUnknownLanguageCode;
370
371 std::string language = RenderView::kUnknownLanguageCode;
372 int num_languages = 0;
373 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02374 Language cld_language =
[email protected]e5106202010-06-11 21:12:36375 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]3354d3e2010-06-10 19:53:02376 &num_languages, NULL);
377 if (is_reliable && cld_language != NUM_LANGUAGES &&
378 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
379 // We should not use LanguageCode_ISO_639_1 because it does not cover all
380 // the languages CLD can detect. As a result, it'll return the invalid
381 // language code for tradtional Chinese among others.
382 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
383 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
384 // for Simplified Chinese.
385 language = LanguageCodeWithDialects(cld_language);
386 }
387 return language;
388}
389
initial.commit09911bf2008-07-26 23:55:29390///////////////////////////////////////////////////////////////////////////////
391
[email protected]60c42a8c72009-10-09 04:08:59392int32 RenderView::next_page_id_ = 1;
393
[email protected]cdaf8d02010-03-30 19:52:47394struct RenderView::PendingFileChooser {
395 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
396 WebFileChooserCompletion* c)
397 : params(p),
398 completion(c) {
399 }
400 ViewHostMsg_RunFileChooser_Params params;
401 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
402};
403
[email protected]2fab253a2009-08-17 23:00:59404RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34405 const WebPreferences& webkit_preferences,
406 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12407 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02408 webkit_preferences_(webkit_preferences),
409 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09410 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02411 send_preferred_size_changes_(false),
412 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24413 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21414 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02415 opened_by_user_gesture_(true),
416 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24417 page_id_(-1),
418 last_page_id_sent_to_browser_(-1),
419 last_indexed_page_id_(-1),
[email protected]3354d3e2010-06-10 19:53:02420 last_top_level_navigation_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00421 history_list_offset_(-1),
422 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24423 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55424#if defined(OS_MACOSX)
425 has_document_tag_(false),
426#endif
[email protected]98324892009-09-09 21:16:05427 document_tag_(0),
[email protected]ab9eabac2010-03-16 16:54:10428 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17429 same_origin_access_count_(0),
[email protected]3354d3e2010-06-10 19:53:02430 target_url_status_(TARGET_NONE),
431 spelling_panel_visible_(false),
432 view_type_(ViewType::INVALID),
433 browser_window_id_(-1),
434 autofill_query_id_(0),
435 autofill_action_(AUTOFILL_NONE),
[email protected]1cf47dd52010-06-10 22:41:20436 suggestions_count_(0),
[email protected]18ca9a6b2010-06-02 19:05:18437 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]3354d3e2010-06-10 19:53:02438 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
439 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
440 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
441 ALLOW_THIS_IN_INITIALIZER_LIST(
442 notification_provider_(new NotificationProvider(this))),
443 session_storage_namespace_id_(session_storage_namespace_id),
444 decrement_shared_popup_at_destruction_(false) {
[email protected]71b0d5d2010-02-15 05:43:07445 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29446}
447
448RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08449 if (decrement_shared_popup_at_destruction_)
450 shared_popup_counter_->data--;
451
[email protected]b0950a72009-09-29 23:16:17452 // Dispose of un-disposed image fetchers.
453 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
454 i != image_fetchers_.end(); ++i) {
455 delete *i;
456 }
457
[email protected]a1128322009-10-06 18:38:46458 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47459 while (!file_chooser_completions_.empty()) {
460 if (file_chooser_completions_.front()->completion) {
461 file_chooser_completions_.front()->completion->didChooseFile(
462 WebVector<WebString>());
463 }
464 file_chooser_completions_.pop_front();
465 }
[email protected]a1128322009-10-06 18:38:46466
[email protected]83dde542009-09-11 20:59:55467#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05468 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55469 if (has_document_tag_)
470 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
471#endif
[email protected]98324892009-09-09 21:16:05472
[email protected]5fb88962009-04-16 19:03:25473 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59474
475#ifndef NDEBUG
476 // Make sure we are no longer referenced by the ViewMap.
477 ViewMap* views = Singleton<ViewMap>::get();
478 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
479 DCHECK_NE(this, it->second) << "Failed to call Close?";
480#endif
481}
482
483/*static*/
484void RenderView::ForEach(RenderViewVisitor* visitor) {
485 ViewMap* views = Singleton<ViewMap>::get();
486 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
487 if (!visitor->Visit(it->second))
488 return;
489 }
490}
491
492/*static*/
493RenderView* RenderView::FromWebView(WebView* webview) {
494 ViewMap* views = Singleton<ViewMap>::get();
495 ViewMap::iterator it = views->find(webview);
496 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29497}
498
499/*static*/
[email protected]0aa55312008-10-17 21:53:08500RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24501 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15502 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08503 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51504 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08505 const WebPreferences& webkit_prefs,
506 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34507 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26508 int64 session_storage_namespace_id,
509 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29510 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34511 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
512 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29513 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29514 opener_id,
[email protected]80d96fa2009-06-10 22:34:51515 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08516 counter,
[email protected]8ab04652010-06-12 02:47:26517 routing_id,
518 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29519 return view;
520}
521
522/*static*/
523void RenderView::SetNextPageID(int32 next_page_id) {
524 // This method should only be called during process startup, and the given
525 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05526 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29527 DCHECK(next_page_id >= next_page_id_);
528 next_page_id_ = next_page_id;
529}
530
[email protected]afe3a1672009-11-17 19:04:12531void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56532 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
533}
534
[email protected]a3a8fb6d2009-10-22 20:12:51535void RenderView::PluginCrashed(const FilePath& plugin_path) {
536 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29537}
538
[email protected]d8fd6fa2010-02-01 15:54:26539#if defined(OS_MACOSX)
540void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
541 plugin_delegates_.insert(delegate);
542}
543
544void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
545 plugin_delegates_.erase(delegate);
546}
547#endif
548
[email protected]18bcc3c2009-01-27 21:39:15549void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29550 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51551 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08552 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26553 int32 routing_id,
554 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29555 DCHECK(!webview());
556
557 if (opener_id != MSG_ROUTING_NONE)
558 opener_id_ = opener_id;
559
[email protected]0aa55312008-10-17 21:53:08560 if (counter) {
561 shared_popup_counter_ = counter;
562 shared_popup_counter_->data++;
563 decrement_shared_popup_at_destruction_ = true;
564 } else {
565 shared_popup_counter_ = new SharedRenderViewCounter(0);
566 decrement_shared_popup_at_destruction_ = false;
567 }
568
[email protected]58bfc6b2009-06-24 09:45:02569 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04570
[email protected]9a6c6232010-06-25 11:46:49571 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]60c42a8c72009-10-09 04:08:59572 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59573 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27574 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23575 if (!frame_name.empty())
576 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29577
[email protected]d3ba77272009-09-03 00:06:09578 OnSetRendererPrefs(renderer_prefs);
579
initial.commit09911bf2008-07-26 23:55:29580 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24581 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29582 // Take a reference on behalf of the RenderThread. This will be balanced
583 // when we receive ViewMsg_Close.
584 AddRef();
585
586 // If this is a popup, we must wait for the CreatingNew_ACK message before
587 // completing initialization. Otherwise, we can finish it now.
588 if (opener_id == MSG_ROUTING_NONE) {
589 did_show_ = true;
590 CompleteInit(parent_hwnd);
591 }
592
593 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29594
[email protected]58bfc6b2009-06-24 09:45:02595 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09596 if (command_line.HasSwitch(switches::kDomAutomationController))
597 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29598
[email protected]5fb88962009-04-16 19:03:25599 audio_message_filter_ = new AudioMessageFilter(routing_id_);
600 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29601}
602
603void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27604 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27605 if (main_frame)
606 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26607
[email protected]b2abac72009-02-26 12:39:28608 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11609 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28610 return;
[email protected]b4b967e2009-04-22 11:33:05611 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
612 return;
[email protected]b6849bda2009-10-14 23:59:26613 if (notification_provider_->OnMessageReceived(message))
614 return;
[email protected]58c321d2010-02-19 12:11:28615 if (geolocation_dispatcher_.get() &&
616 geolocation_dispatcher_->OnMessageReceived(message)) {
617 return;
618 }
[email protected]b2abac72009-02-26 12:39:28619
initial.commit09911bf2008-07-26 23:55:29620 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04621 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
622 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29623 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01624 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29625 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
626 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56627 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29628 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
629 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
630 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
631 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27632#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35633 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27634#endif
initial.commit09911bf2008-07-26 23:55:29635 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
636 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05637 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
638 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
639 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04640 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29641 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
642 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
643 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15644 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29645 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49646 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
647 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17648 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54649 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
650 OnSetContentSettingsForLoadingURL)
651 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
652 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29653 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18654 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
655 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28656 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33657 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29658 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48659 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29660 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29661 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29662 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
663 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
664 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
665 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
666 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45667 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29668 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50669 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
670 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29671 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
672 OnDragSourceSystemDragEnded)
673 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29674 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
675 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
676 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
677 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
678 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
679 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29680 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
681 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04682 IPC_MESSAGE_HANDLER(
683 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
684 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29685 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:04686 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:29687 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
688 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45689 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:04690 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08691 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
692 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24693 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
694 OnAutoFillSuggestionsReturned)
695 IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned,
696 OnAutocompleteSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48697 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
698 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40699 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
700 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00701 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27702 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37703 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
704 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16705 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14706 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25707 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
708 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10709 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
710 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51711 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53712 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
713 OnUpdateBrowserWindowId)
714 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
715 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56716 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34717 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14718#if defined(OS_MACOSX)
719 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13720 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14721#endif
[email protected]446705872009-09-10 07:22:48722 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33723 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35724 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
725 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33726 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
727 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42728 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02729 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]b3df5a42010-05-11 14:31:09730 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree)
[email protected]aef92842010-05-21 16:54:36731 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
732 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
733 OnAccessibilityDoDefaultAction)
[email protected]634a6f92008-12-01 21:39:31734
initial.commit09911bf2008-07-26 23:55:29735 // Have the super handle all other messages.
736 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
737 IPC_END_MESSAGE_MAP()
738}
739
[email protected]9b18a84f2010-06-10 15:54:04740void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:27741 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29742 if (!main_frame)
743 return;
744
745 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45746 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29747 if (url.is_empty())
748 return;
749
750 if (size_.IsEmpty())
751 return; // Don't create an empty thumbnail!
752
753 ThumbnailScore score;
754 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02755 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15756 &thumbnail, &score))
757 return;
758
initial.commit09911bf2008-07-26 23:55:29759 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46760 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29761}
762
[email protected]9b18a84f2010-06-10 15:54:04763void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:23764 SkBitmap snapshot;
765 bool error = false;
766
767 WebFrame* main_frame = webview()->mainFrame();
768 if (!main_frame)
769 error = true;
770
771 if (!error && !CaptureSnapshot(webview(), &snapshot))
772 error = true;
773
774 DCHECK(error == snapshot.empty()) <<
775 "Snapshot should be empty on error, non-empty otherwise.";
776
777 // Send the snapshot to the browser process.
778 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
779}
780
[email protected]068637222009-01-29 16:58:07781void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29782 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58783 if (webview()) {
784 // If the user has selected text in the currently focused frame we print
785 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27786 if (webview()->focusedFrame()->hasSelection())
787 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58788 else
[email protected]26aa0482009-09-30 16:55:27789 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58790 }
initial.commit09911bf2008-07-26 23:55:29791}
792
[email protected]82270452009-06-19 15:58:01793void RenderView::OnPrintingDone(int document_cookie, bool success) {
794 // Ignoring document cookie here since only one print job can be outstanding
795 // per renderer and document_cookie is 0 when printing is successful.
796 DCHECK(print_helper_.get());
797 if (print_helper_.get() != NULL) {
798 print_helper_->DidFinishPrinting(success);
799 }
800}
801
initial.commit09911bf2008-07-26 23:55:29802void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
803 if (load_id != page_id_)
804 return; // this capture call is no longer relevant due to navigation
805 if (load_id == last_indexed_page_id_)
806 return; // we already indexed this page
807
808 if (!webview())
809 return;
810
[email protected]26aa0482009-09-30 16:55:27811 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29812 if (!main_frame)
813 return;
814
815 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45816 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29817 return;
818
819 // Don't index/capture pages that failed to load. This only checks the top
820 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45821 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28822 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29823 return;
824
825 if (!preliminary_capture)
826 last_indexed_page_id_ = load_id;
827
[email protected]a8a81292010-01-21 00:32:45828 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45829 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29830 if (url.is_empty())
831 return;
832
[email protected]a8a81292010-01-21 00:32:45833 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:36834 string16 contents;
initial.commit09911bf2008-07-26 23:55:29835 CaptureText(main_frame, &contents);
836 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45837 base::TimeTicks begin_time = base::TimeTicks::Now();
838 std::string language = DetermineTextLanguage(contents);
839 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
840 base::TimeTicks::Now() - begin_time);
[email protected]7893a982010-01-07 23:25:52841
[email protected]a8a81292010-01-21 00:32:45842 // Send the text to the browser for indexing (the browser might decide not
843 // to index, if the URL is HTTPS for instance) and language discovery.
844 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
845 language));
[email protected]5c4266922009-07-10 16:41:27846 }
847
[email protected]9b18a84f2010-06-10 15:54:04848 OnCaptureThumbnail();
initial.commit09911bf2008-07-26 23:55:29849}
850
[email protected]e5106202010-06-11 21:12:36851void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:29852 contents->clear();
853 if (!frame)
854 return;
855
856#ifdef TIME_TEXT_RETRIEVAL
857 double begin = time_util::GetHighResolutionTimeNow();
858#endif
859
860 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:36861 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:29862
863#ifdef TIME_TEXT_RETRIEVAL
864 double end = time_util::GetHighResolutionTimeNow();
865 char buf[128];
866 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
867 contents.size(), (end - begin)*1000);
868 OutputDebugStringA(buf);
869#endif
870
871 // When the contents are clipped to the maximum, we don't want to have a
872 // partial word indexed at the end that might have been clipped. Therefore,
873 // terminate the string at the last space to ensure no words are clipped.
874 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:36875 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:29876 if (last_space_index == std::wstring::npos)
877 return; // don't index if we got a huge block of text with no spaces
878 contents->resize(last_space_index);
879 }
880}
881
[email protected]8649fb32009-06-26 17:51:02882bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29883 int w,
884 int h,
885 SkBitmap* thumbnail,
886 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23887 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15888
[email protected]8649fb32009-06-26 17:51:02889 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23890
891 // Paint |view| into |canvas|.
892 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02893 return false;
[email protected]8649fb32009-06-26 17:51:02894
895 skia::BitmapPlatformDevice& device =
896 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
897
898 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29899
[email protected]cab34d6a2009-09-24 01:14:52900 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29901 float dest_aspect = dest_rect.width() / dest_rect.height();
902
903 // Get the src rect so that we can preserve the aspect ratio while filling
904 // the destination.
905 SkIRect src_rect;
906 if (src_bmp.width() < dest_rect.width() ||
907 src_bmp.height() < dest_rect.height()) {
908 // Source image is smaller: we clip the part of source image within the
909 // dest rect, and then stretch it to fill the dest rect. We don't respect
910 // the aspect ratio in this case.
911 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
912 static_cast<S16CPU>(dest_rect.height()));
913 score->good_clipping = false;
914 } else {
915 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
916 if (src_aspect > dest_aspect) {
917 // Wider than tall, clip horizontally: we center the smaller thumbnail in
918 // the wider screen.
919 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
920 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
921 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
922 score->good_clipping = false;
923 } else {
924 src_rect.set(0, 0, src_bmp.width(),
925 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
926 score->good_clipping = true;
927 }
928 }
929
[email protected]26aa0482009-09-30 16:55:27930 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29931
932 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02933 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29934
935 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14936 *thumbnail = skia::ImageOperations::Resize(
937 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29938
939 score->boring_score = CalculateBoringScore(thumbnail);
940
[email protected]30507922010-01-15 16:48:23941 HISTOGRAM_TIMES("Renderer4.Thumbnail",
942 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15943 return true;
initial.commit09911bf2008-07-26 23:55:29944}
945
[email protected]30507922010-01-15 16:48:23946bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
947 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29948
[email protected]30507922010-01-15 16:48:23949 skia::PlatformCanvas canvas;
950 if (!PaintViewIntoCanvas(view, canvas))
951 return false;
952
953 skia::BitmapPlatformDevice& device =
954 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
955
956 const SkBitmap& bitmap = device.accessBitmap(false);
957 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
958 return false;
959
960 HISTOGRAM_TIMES("Renderer4.Snapshot",
961 base::TimeTicks::Now() - beginning_time);
962 return true;
initial.commit09911bf2008-07-26 23:55:29963}
964
965void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
966 if (!webview())
967 return;
968
[email protected]3cc72b12010-03-18 23:03:00969 history_list_offset_ = params.current_history_list_offset;
970 history_list_length_ = params.current_history_list_length;
971
[email protected]8c785c62009-07-13 14:20:15972 if (devtools_agent_.get())
973 devtools_agent_->OnNavigate();
974
[email protected]422197532010-01-25 17:38:23975 if (notification_provider_.get())
976 notification_provider_->OnNavigate();
977
[email protected]a9f607e2009-10-23 19:59:27978 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26979
initial.commit09911bf2008-07-26 23:55:29980 AboutHandler::MaybeHandle(params.url);
981
[email protected]ecbf10d2010-02-18 13:03:29982 bool is_reload =
983 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
984 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29985
[email protected]26aa0482009-09-30 16:55:27986 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45987 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29988 // We cannot reload if we do not have any history state. This happens, for
989 // example, when recovering from a crash. Our workaround here is a bit of
990 // a hack since it means that reload after a crashed tab does not cause an
991 // end-to-end cache validation.
992 is_reload = false;
993 }
994
[email protected]77f17a82009-05-21 04:42:54995 // A navigation resulting from loading a javascript URL should not be treated
996 // as a browser initiated event. Instead, we want it to look as if the page
997 // initiated any load resulting from JS execution.
998 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30999 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001000 params.page_id,
1001 params.pending_history_list_offset,
1002 params.transition,
1003 params.request_time);
[email protected]5e369672009-11-03 23:48:301004 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1005 // We're doing a load of a page that was restored from the last session.
1006 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1007 // which can result in stale data for pages that are set to expire. We
1008 // explicitly override that by setting the policy here so that as
1009 // necessary we load from the network.
1010 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1011 }
1012 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541013 }
initial.commit09911bf2008-07-26 23:55:291014
[email protected]a7ccc4d2010-01-27 08:14:481015 NavigationState* navigation_state = pending_navigation_state_.get();
1016
[email protected]04d3c6e2009-05-22 17:00:131017 // If we are reloading, then WebKit will use the history state of the current
1018 // page, so we should just ignore any given history state. Otherwise, if we
1019 // have history state, then we need to navigate to it, which corresponds to a
1020 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551021 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481022 if (navigation_state)
1023 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291024 bool ignore_cache = (params.navigation_type ==
1025 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1026 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551027 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131028 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581029 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481030 if (navigation_state)
1031 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451032 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171033 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131034 } else {
1035 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281036 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291037
[email protected]e6f546c32009-07-01 17:12:551038 // A session history navigation should have been accompanied by state.
1039 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131040
[email protected]dd7daa82009-08-10 05:46:451041 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551042 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131043
[email protected]726985e22009-06-18 21:09:281044 if (params.referrer.is_valid()) {
1045 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1046 WebString::fromUTF8(params.referrer.spec()));
1047 }
[email protected]04d3c6e2009-05-22 17:00:131048
[email protected]a7ccc4d2010-01-27 08:14:481049 if (navigation_state)
1050 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451051 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501052 }
1053
[email protected]77f17a82009-05-21 04:42:541054 // In case LoadRequest failed before DidCreateDataSource was called.
1055 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291056}
1057
1058// Stop loading the current page
1059void RenderView::OnStop() {
1060 if (webview())
[email protected]b4bb2502009-10-01 22:35:271061 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291062}
1063
[email protected]ecbf10d2010-02-18 13:03:291064// Reload current focused frame.
1065// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561066void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291067 if (webview() && webview()->focusedFrame()) {
1068 // We always obey the cache (ignore_cache=false) here.
1069 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1070 // a cache-ignoring reload of the frame.
1071 webview()->focusedFrame()->reload(false);
1072 }
[email protected]1dda4022010-01-28 18:24:561073}
1074
initial.commit09911bf2008-07-26 23:55:291075void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271076 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291077}
1078
[email protected]68b1e922009-06-23 16:00:251079void RenderView::OnExecuteEditCommand(const std::string& name,
1080 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271081 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251082 return;
1083
[email protected]26aa0482009-09-30 16:55:271084 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451085 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251086}
1087
[email protected]b2abac72009-02-26 12:39:281088void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111089 DCHECK(!devtools_client_.get());
1090 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281091}
1092
initial.commit09911bf2008-07-26 23:55:291093void RenderView::OnUpdateTargetURLAck() {
1094 // Check if there is a targeturl waiting to be sent.
1095 if (target_url_status_ == TARGET_PENDING) {
1096 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1097 pending_target_url_));
1098 }
1099
1100 target_url_status_ = TARGET_NONE;
1101}
1102
1103void RenderView::OnUndo() {
1104 if (!webview())
1105 return;
1106
[email protected]26aa0482009-09-30 16:55:271107 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121108 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291109}
1110
1111void RenderView::OnRedo() {
1112 if (!webview())
1113 return;
1114
[email protected]26aa0482009-09-30 16:55:271115 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121116 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291117}
1118
1119void RenderView::OnCut() {
1120 if (!webview())
1121 return;
1122
[email protected]26aa0482009-09-30 16:55:271123 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121124 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291125}
1126
1127void RenderView::OnCopy() {
1128 if (!webview())
1129 return;
1130
[email protected]6f496b22010-05-27 22:59:201131 if (webview()->mainFrame()->document().isPluginDocument()) {
1132 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
1133 delegate->Copy();
1134 return;
1135 }
1136
[email protected]26aa0482009-09-30 16:55:271137 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121138 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291139}
1140
[email protected]c0cc3092009-09-12 08:27:271141#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351142void RenderView::OnCopyToFindPboard() {
1143 if (!webview())
1144 return;
1145
1146 // Since the find pasteboard supports only plain text, this can be simpler
1147 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271148 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351149 if (frame->hasSelection()) {
1150 string16 selection = frame->selectionAsText();
1151 RenderThread::current()->Send(
1152 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1153 }
1154
[email protected]afe3a1672009-11-17 19:04:121155 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351156}
[email protected]c0cc3092009-09-12 08:27:271157#endif
[email protected]a954bf72009-09-12 07:30:351158
initial.commit09911bf2008-07-26 23:55:291159void RenderView::OnPaste() {
1160 if (!webview())
1161 return;
1162
[email protected]26aa0482009-09-30 16:55:271163 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121164 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291165}
1166
[email protected]2a3a7762009-10-19 19:17:321167void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291168 if (!webview())
1169 return;
1170
[email protected]1ff7a032010-02-03 02:46:031171 WebFrame* frame = webview()->focusedFrame();
1172 if (!frame->hasSelection())
1173 frame->selectWordAroundCaret();
1174 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291175}
1176
[email protected]98324892009-09-09 21:16:051177void RenderView::OnAdvanceToNextMisspelling() {
1178 if (!webview())
1179 return;
[email protected]26aa0482009-09-30 16:55:271180 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051181 WebString::fromUTF8("AdvanceToNextMisspelling"));
1182}
1183
1184void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1185 if (!webview())
1186 return;
1187 // We need to tell the webView whether the spelling panel is visible or not so
1188 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261189 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271190 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051191 WebString::fromUTF8("ToggleSpellPanel"));
1192}
1193
[email protected]bbbd545c2008-12-15 20:18:041194void RenderView::OnToggleSpellCheck() {
1195 if (!webview())
1196 return;
1197
[email protected]26aa0482009-09-30 16:55:271198 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451199 frame->enableContinuousSpellChecking(
1200 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041201}
1202
initial.commit09911bf2008-07-26 23:55:291203void RenderView::OnDelete() {
1204 if (!webview())
1205 return;
1206
[email protected]26aa0482009-09-30 16:55:271207 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121208 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291209}
1210
1211void RenderView::OnSelectAll() {
1212 if (!webview())
1213 return;
1214
[email protected]26aa0482009-09-30 16:55:271215 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221216 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121217 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291218}
1219
1220void RenderView::OnSetInitialFocus(bool reverse) {
1221 if (!webview())
1222 return;
[email protected]26aa0482009-09-30 16:55:271223 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291224}
1225
1226///////////////////////////////////////////////////////////////////////////////
1227
[email protected]433819d2010-01-30 20:20:011228void RenderView::SetContentSettings(const ContentSettings& settings) {
1229 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011230}
1231
initial.commit09911bf2008-07-26 23:55:291232// Tell the embedding application that the URL of the active page has changed
1233void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451234 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291235 DCHECK(ds);
1236
[email protected]726985e22009-06-18 21:09:281237 const WebURLRequest& request = ds->request();
1238 const WebURLRequest& original_request = ds->originalRequest();
1239 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291240
[email protected]daa8c58e2009-06-15 17:21:101241 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1242 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291243
1244 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281245 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291246 params.is_post = false;
1247 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281248 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551249 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291250 // SSL state specified in the request takes precedence over the one in the
1251 // response.
1252 // So far this is only intended for error pages that are not expected to be
1253 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281254 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551255 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291256 } else {
[email protected]726985e22009-06-18 21:09:281257 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291258 }
1259
1260 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281261 if (ds->hasUnreachableURL()) {
1262 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291263 } else {
[email protected]726985e22009-06-18 21:09:281264 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291265 }
1266
[email protected]726985e22009-06-18 21:09:281267 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241268 params.should_update_history = !ds->hasUnreachableURL() &&
1269 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291270
[email protected]ce0e250d2009-10-23 21:00:351271 params.searchable_form_url = navigation_state->searchable_form_url();
1272 params.searchable_form_encoding =
1273 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291274
1275 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101276 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291277 if (password_form_data)
1278 params.password_form = *password_form_data;
1279
1280 params.gesture = navigation_gesture_;
1281 navigation_gesture_ = NavigationGestureUnknown;
1282
[email protected]dd7daa82009-08-10 05:46:451283 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291284 // Top-level navigation.
1285
[email protected]71b0d5d2010-02-15 05:43:071286 // Clear "block" flags for the new page. This needs to happen before any of
1287 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1288 // so that these functions can correctly detect that a piece of content
1289 // flipped from "not blocked" to "blocked".
1290 ClearBlockedContentSettings();
1291
[email protected]62d2a112010-04-07 00:53:021292 // Set content settings. Default them from the parent window if one exists.
1293 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011294 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541295 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011296 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011297 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011298
1299 // These content settings were merely recorded transiently for this load.
1300 // We can erase them now. If at some point we reload this page, the
1301 // browser will send us new, up-to-date content settings.
1302 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401303 } else if (frame->opener()) {
1304 WebView* opener_view = frame->opener()->view();
1305 RenderView* opener = FromWebView(opener_view);
1306 SetContentSettings(opener->current_content_settings_);
[email protected]f85f0702010-01-30 09:31:011307 }
1308
[email protected]40bd6582009-12-04 23:49:511309 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011310 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541311 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011312 if (host_zoom != host_zoom_levels_.end()) {
1313 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511314 // This zoom level was merely recorded transiently for this load. We can
1315 // erase it now. If at some point we reload this page, the browser will
1316 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011317 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511318 }
1319
initial.commit09911bf2008-07-26 23:55:291320 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551321 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291322
[email protected]daa8c58e2009-06-15 17:21:101323 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291324 if (!PageTransition::IsMainFrame(params.transition)) {
1325 // If the main frame does a load, it should not be reported as a subframe
1326 // navigation. This can occur in the following case:
1327 // 1. You're on a site with frames.
1328 // 2. You do a subframe navigation. This is stored with transition type
1329 // MANUAL_SUBFRAME.
1330 // 3. You navigate to some non-frame site, say, google.com.
1331 // 4. You navigate back to the page from step 2. Since it was initially
1332 // MANUAL_SUBFRAME, it will be that same transition type here.
1333 // We don't want that, because any navigation that changes the toplevel
1334 // frame should be tracked as a toplevel navigation (this allows us to
1335 // update the URL bar, etc).
1336 params.transition = PageTransition::LINK;
1337 }
1338
initial.commit09911bf2008-07-26 23:55:291339 // If we have a valid consumed client redirect source,
1340 // the page contained a client redirect (meta refresh, document.loc...),
1341 // so we set the referrer and transition to match.
1342 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041343 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291344 params.referrer = completed_client_redirect_src_;
1345 params.transition = static_cast<PageTransition::Type>(
1346 params.transition | PageTransition::CLIENT_REDIRECT);
1347 } else {
1348 // Bug 654101: the referrer will be empty on https->http transitions. It
1349 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281350 params.referrer = GURL(
1351 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291352 }
1353
[email protected]726985e22009-06-18 21:09:281354 string16 method = request.httpMethod();
1355 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291356 params.is_post = true;
1357
[email protected]c2a797d2009-09-21 16:46:321358 // Save some histogram data so we can compute the average memory used per
1359 // page load of the glyphs.
1360 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1361 webkit_glue::GetGlyphPageCount());
1362
[email protected]15cf526b2010-02-12 06:33:491363 // This message needs to be sent before any of allowScripts(),
1364 // allowImages(), allowPlugins() is called for the new page, so that when
1365 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1366 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291367 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1368 } else {
1369 // Subframe navigation: the type depends on whether this navigation
1370 // generated a new session history entry. When they do generate a session
1371 // history entry, it means the user initiated the navigation and we should
1372 // mark it as such. This test checks if this is the first time UpdateURL
1373 // has been called since WillNavigateToURL was called to initiate the load.
1374 if (page_id_ > last_page_id_sent_to_browser_)
1375 params.transition = PageTransition::MANUAL_SUBFRAME;
1376 else
1377 params.transition = PageTransition::AUTO_SUBFRAME;
1378
initial.commit09911bf2008-07-26 23:55:291379 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1380 }
1381
1382 last_page_id_sent_to_browser_ =
1383 std::max(last_page_id_sent_to_browser_, page_id_);
1384
1385 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101386 // we don't want the transition type to persist. Just clear it.
1387 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501388
[email protected]c7287a92009-11-04 20:06:151389 if (accessibility_.get()) {
[email protected]b3df5a42010-05-11 14:31:091390 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351391 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501392 }
initial.commit09911bf2008-07-26 23:55:291393}
1394
1395// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171396void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291397 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171398 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171399 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171400 routing_id_,
1401 page_id_,
1402 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1403 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171404 }
initial.commit09911bf2008-07-26 23:55:291405}
1406
1407void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401408 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291409 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271410 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291411 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301412 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291413 last_encoding_name_ = encoding_name;
1414
[email protected]e38f40152008-09-12 23:08:301415 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291416 }
1417}
1418
[email protected]f4d34b52008-11-24 23:05:011419// Sends the previous session history state to the browser so it will be saved
1420// before we navigate to a new page. This must be called *before* the page ID
1421// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291422void RenderView::UpdateSessionHistory(WebFrame* frame) {
1423 // If we have a valid page ID at this point, then it corresponds to the page
1424 // we are navigating away from. Otherwise, this is the first navigation, so
1425 // there is no past session history to record.
1426 if (page_id_ == -1)
1427 return;
1428
[email protected]ca948a22009-06-25 19:36:171429 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271430 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171431 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291432 return;
[email protected]ca948a22009-06-25 19:36:171433
1434 Send(new ViewHostMsg_UpdateState(
1435 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291436}
1437
[email protected]3d9689372009-09-10 04:29:171438void RenderView::OpenURL(
1439 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1440 Send(new ViewHostMsg_OpenURL(
1441 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1442}
1443
[email protected]79dbc662009-09-04 05:42:511444// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291445
initial.commit09911bf2008-07-26 23:55:291446void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281447 const WebURLRequest& failed_request,
1448 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291449 const std::string& html,
1450 bool replace) {
[email protected]726985e22009-06-18 21:09:281451 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291452
1453 std::string alt_html;
1454 if (html.empty()) {
1455 // Use a local error page.
1456 int resource_id;
1457 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281458 if (error.reason == net::ERR_CACHE_MISS &&
1459 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291460 GetFormRepostErrorValues(failed_url, &error_strings);
1461 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1462 } else {
1463 GetLocalizedErrorValues(error, &error_strings);
1464 resource_id = IDR_NET_ERROR_HTML;
1465 }
initial.commit09911bf2008-07-26 23:55:291466
1467 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1468 } else {
1469 alt_html = html;
1470 }
1471
[email protected]dd7daa82009-08-10 05:46:451472 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551473 GURL(kUnreachableWebDataURL),
1474 failed_url,
1475 replace);
initial.commit09911bf2008-07-26 23:55:291476}
1477
[email protected]7ccddb8c2009-08-04 17:36:551478void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291479 dom_automation_controller_.set_message_sender(this);
1480 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551481 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291482 L"domAutomationController");
1483}
1484
initial.commit09911bf2008-07-26 23:55:291485bool RenderView::RunJavaScriptMessage(int type,
1486 const std::wstring& message,
1487 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071488 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291489 std::wstring* result) {
1490 bool success = false;
1491 std::wstring result_temp;
1492 if (!result)
1493 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291494
[email protected]12636df2009-09-28 22:32:211495 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1496 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291497 return success;
1498}
1499
[email protected]c1f50aa2010-02-18 03:46:571500bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1501 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1502 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1503 // it is particularly important that we do not call willEnterModalLoop as
1504 // that would defer resource loads for the dialog itself.
1505 if (RenderThread::current()) // Will be NULL during unit tests.
1506 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1507
1508 message->EnableMessagePumping(); // Runs a nested message loop.
1509 return Send(message);
1510}
1511
initial.commit09911bf2008-07-26 23:55:291512void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1513 if (!osd_url.is_empty())
1514 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1515 autodetected));
1516}
1517
[email protected]95056b582010-02-18 01:29:241518void RenderView::OnAutoFillSuggestionsReturned(
1519 int query_id,
[email protected]8f6e6582010-04-09 02:03:071520 const std::vector<string16>& values,
[email protected]1cf47dd52010-06-10 22:41:201521 const std::vector<string16>& labels) {
[email protected]95056b582010-02-18 01:29:241522 if (webview() && query_id == autofill_query_id_) {
[email protected]1cf47dd52010-06-10 22:41:201523 std::vector<string16> v(values);
1524 std::vector<string16> l(labels);
[email protected]631ec052010-06-13 22:26:301525 int separator_index = v.size();
1526
1527 // The form has been auto-filled, so give the user the chance to clear the
1528 // form.
1529 if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) {
1530 v.push_back(l10n_util::GetStringUTF16(
1531 IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM));
1532 l.push_back(string16());
1533 }
1534
1535 // Append the 'AutoFill Options...' menu item.
[email protected]9765e8f2010-06-25 19:54:361536 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS));
[email protected]1cf47dd52010-06-10 22:41:201537 l.push_back(string16());
1538 suggestions_count_ = v.size();
[email protected]95056b582010-02-18 01:29:241539 webview()->applyAutoFillSuggestions(
[email protected]631ec052010-06-13 22:26:301540 autofill_query_node_, v, l, separator_index);
[email protected]95056b582010-02-18 01:29:241541 }
[email protected]cf28ec52010-04-09 22:56:341542}
1543
[email protected]95056b582010-02-18 01:29:241544void RenderView::OnAutocompleteSuggestionsReturned(
[email protected]acca2a1f2009-10-16 03:53:391545 int query_id,
1546 const std::vector<string16>& suggestions,
[email protected]0ebf3872008-11-07 21:35:031547 int default_suggestion_index) {
[email protected]7e089f272009-11-03 17:07:181548 if (webview() && query_id == autofill_query_id_) {
[email protected]9e3444c2010-02-11 21:30:081549 webview()->applyAutocompleteSuggestions(
[email protected]acca2a1f2009-10-16 03:53:391550 autofill_query_node_, suggestions, default_suggestion_index);
1551 }
[email protected]0ebf3872008-11-07 21:35:031552}
1553
[email protected]45c6e532010-03-15 23:51:241554void RenderView::OnAutoFillFormDataFilled(int query_id,
1555 const webkit_glue::FormData& form) {
[email protected]18ca9a6b2010-06-02 19:05:181556 if (!webview() || query_id != autofill_query_id_)
[email protected]c83641732010-02-20 01:04:481557 return;
1558
[email protected]18ca9a6b2010-06-02 19:05:181559 DCHECK_NE(AUTOFILL_NONE, autofill_action_);
1560
1561 if (autofill_action_ == AUTOFILL_FILL)
[email protected]2ad69c892010-06-10 22:00:171562 form_manager_.FillForm(form, autofill_query_node_);
[email protected]18ca9a6b2010-06-02 19:05:181563 else if (autofill_action_ == AUTOFILL_PREVIEW)
1564 form_manager_.PreviewForm(form);
1565
1566 autofill_action_ = AUTOFILL_NONE;
[email protected]c83641732010-02-20 01:04:481567}
1568
[email protected]e8345242010-05-06 03:00:401569void RenderView::OnAllowScriptToClose(bool script_can_close) {
1570 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311571}
1572
initial.commit09911bf2008-07-26 23:55:291573uint32 RenderView::GetCPBrowsingContext() {
1574 uint32 context = 0;
1575 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1576 return context;
1577}
1578
initial.commit09911bf2008-07-26 23:55:291579void RenderView::AddSearchProvider(const std::string& url) {
1580 AddGURLSearchProvider(GURL(url),
1581 false); // not autodetected
1582}
1583
[email protected]f103ab72009-09-02 17:10:591584void RenderView::OnMissingPluginStatus(
1585 WebPluginDelegateProxy* delegate,
1586 int status) {
[email protected]6c8afae52009-01-22 02:24:571587#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591588 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291589 // Show the InfoBar for the first available plugin.
1590 if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591591 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291592 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1593 }
1594 } else {
1595 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1596 // to start the download/install.
1597 if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
1598 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1599 }
1600 }
[email protected]6c8afae52009-01-22 02:24:571601#else
[email protected]76c3b312010-05-20 21:38:291602 // TODO(port): Implement the infobar that accompanies the default plugin.
1603 // Linux: http://crbug.com/10952
1604 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571605 NOTIMPLEMENTED();
1606#endif
initial.commit09911bf2008-07-26 23:55:291607}
1608
[email protected]48c9cf2d2009-09-16 16:47:521609// WebKit::WebViewClient ------------------------------------------------------
1610
[email protected]8ab04652010-06-12 02:47:261611WebView* RenderView::createView(
1612 WebFrame* creator,
1613 const WebWindowFeatures& features,
1614 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521615 // Check to make sure we aren't overloading on popups.
1616 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1617 return NULL;
1618
1619 // This window can't be closed from a window.close() call until we receive a
1620 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:401621 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:521622
[email protected]8ab04652010-06-12 02:47:261623 ViewHostMsg_CreateWindow_Params params;
1624 params.opener_id = routing_id_;
1625 params.user_gesture = creator->isProcessingUserGesture();
1626 params.window_container_type = WindowFeaturesToContainerType(features);
1627 params.session_storage_namespace_id = session_storage_namespace_id_;
1628 params.frame_name = frame_name;
1629
[email protected]48c9cf2d2009-09-16 16:47:521630 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341631 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261632 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521633
[email protected]48c9cf2d2009-09-16 16:47:521634 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261635 new ViewHostMsg_CreateWindow(params,
1636 &routing_id,
1637 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211638 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521639 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521640
[email protected]48c9cf2d2009-09-16 16:47:521641 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421642 0,
[email protected]12636df2009-09-28 22:32:211643 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521644 renderer_preferences_,
1645 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211646 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341647 routing_id,
[email protected]8ab04652010-06-12 02:47:261648 cloned_session_storage_namespace_id,
1649 frame_name);
1650 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521651
[email protected]007a848b2009-10-26 15:55:461652 // Record whether the creator frame is trying to suppress the opener field.
1653 view->opener_suppressed_ = opener_suppressed;
1654
[email protected]48c9cf2d2009-09-16 16:47:521655 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091656 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521657 if (!creator_url.is_valid() || !creator_url.IsStandard())
1658 creator_url = GURL();
1659 view->creator_url_ = creator_url;
1660
1661 // Copy over the alternate error page URL so we can have alt error pages in
1662 // the new render view (we don't need the browser to send the URL back down).
1663 view->alternate_error_page_url_ = alternate_error_page_url_;
1664
1665 return view->webview();
1666}
1667
[email protected]3e2b375b2010-04-07 17:03:121668WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521669 RenderWidget* widget = RenderWidget::Create(routing_id_,
1670 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121671 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521672 return widget->webwidget();
1673}
1674
1675WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
1676 RenderWidget* widget = RenderWidget::Create(routing_id_,
1677 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121678 WebKit::WebPopupTypeSelect);
[email protected]48c9cf2d2009-09-16 16:47:521679 widget->ConfigureAsExternalPopupMenu(info);
1680 return widget->webwidget();
1681}
1682
[email protected]68c50e52010-05-12 11:14:391683WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341684 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391685 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291686 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1687 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1688 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341689}
1690
[email protected]48c9cf2d2009-09-16 16:47:521691void RenderView::didAddMessageToConsole(
1692 const WebConsoleMessage& message, const WebString& source_name,
1693 unsigned source_line) {
1694 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
1695 UTF16ToWideHack(message.text),
1696 static_cast<int32>(source_line),
1697 UTF16ToWideHack(source_name)));
1698}
1699
1700void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:581701 DCHECK(frame);
1702 Print(frame, true);
[email protected]48c9cf2d2009-09-16 16:47:521703}
1704
[email protected]3354d3e2010-06-10 19:53:021705WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
1706 return notification_provider_.get();
1707}
1708
[email protected]48c9cf2d2009-09-16 16:47:521709void RenderView::didStartLoading() {
1710 if (is_loading_) {
1711 DLOG(WARNING) << "didStartLoading called while loading";
1712 return;
1713 }
1714
1715 is_loading_ = true;
1716 // Clear the pointer so that we can assign it only when there is an unknown
1717 // plugin on a page.
1718 first_default_plugin_.reset();
1719
1720 Send(new ViewHostMsg_DidStartLoading(routing_id_));
1721}
1722
1723void RenderView::didStopLoading() {
1724 if (!is_loading_) {
1725 DLOG(WARNING) << "DidStopLoading called while not loading";
1726 return;
1727 }
1728
1729 is_loading_ = false;
1730
1731 // NOTE: For now we're doing the safest thing, and sending out notification
1732 // when done loading. This currently isn't an issue as the favicon is only
1733 // displayed when done loading. Ideally we would send notification when
1734 // finished parsing the head, but webkit doesn't support that yet.
1735 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:271736 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:521737 if (!favicon_url.is_empty())
1738 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
1739
[email protected]26aa0482009-09-30 16:55:271740 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]48c9cf2d2009-09-16 16:47:521741 true); // autodetected
1742
1743 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1744
[email protected]f9f4841b2010-03-20 05:41:421745 MessageLoop::current()->PostDelayedTask(
1746 FROM_HERE,
[email protected]48c9cf2d2009-09-16 16:47:521747 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_,
1748 false),
1749 kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:521750}
1751
[email protected]f55039a2010-02-17 14:12:061752bool RenderView::isSmartInsertDeleteEnabled() {
1753#if defined(OS_MACOSX)
1754 return true;
1755#else
1756 return false;
1757#endif
1758}
1759
[email protected]04fc9482009-09-18 22:13:031760bool RenderView::isSelectTrailingWhitespaceEnabled() {
1761#if defined(OS_WIN)
1762 return true;
1763#else
1764 return false;
1765#endif
1766}
1767
[email protected]04fc9482009-09-18 22:13:031768void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]6981f7f2010-03-09 00:53:031769#if defined(USE_X11)
[email protected]04fc9482009-09-18 22:13:031770 if (!handling_input_event_)
1771 return;
1772 // TODO(estade): investigate incremental updates to the selection so that we
1773 // don't send the entire selection over IPC every time.
1774 if (!is_empty_selection) {
1775 // Sometimes we get repeated didChangeSelection calls from webkit when
1776 // the selection hasn't actually changed. We don't want to report these
1777 // because it will cause us to continually claim the X clipboard.
1778 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:271779 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031780 if (this_selection == last_selection_)
1781 return;
1782
1783 Send(new ViewHostMsg_SelectionChanged(routing_id_,
1784 this_selection));
1785 last_selection_ = this_selection;
1786 } else {
1787 last_selection_.clear();
1788 }
1789#endif
1790}
1791
1792void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121793 const std::string& name = UTF16ToUTF8(command_name);
1794 if (StartsWithASCII(name, "Move", true) ||
1795 StartsWithASCII(name, "Insert", true) ||
1796 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031797 return;
1798 UserMetricsRecordAction(name);
1799}
1800
[email protected]b2528b72009-09-24 06:57:101801bool RenderView::handleCurrentKeyboardEvent() {
1802 if (edit_commands_.empty())
1803 return false;
1804
[email protected]26aa0482009-09-30 16:55:271805 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101806 if (!frame)
1807 return false;
1808
1809 EditCommands::iterator it = edit_commands_.begin();
1810 EditCommands::iterator end = edit_commands_.end();
1811
[email protected]507b33ea2009-09-29 03:56:511812 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101813 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331814 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1815 // key (but it's the exception). Once one edit command is not executed, it
1816 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101817 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1818 WebString::fromUTF8(it->value)))
1819 break;
[email protected]507b33ea2009-09-29 03:56:511820 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101821 }
1822
[email protected]507b33ea2009-09-29 03:56:511823 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101824}
1825
[email protected]2a3a7762009-10-19 19:17:321826void RenderView::spellCheck(const WebString& text,
1827 int& misspelled_offset,
1828 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561829 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461830
[email protected]85c55dc2009-11-06 03:05:461831 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171832 RenderThread* thread = RenderThread::current();
1833 // Will be NULL during unit tests.
1834 if (thread) {
[email protected]c27324b2009-11-19 22:44:291835 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171836 word.c_str(), word.size(), document_tag_,
1837 &misspelled_offset, &misspelled_length, NULL);
1838 }
[email protected]1dbafaf72009-09-23 19:43:561839}
1840
1841WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321842 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561843 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261844 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561845 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171846 RenderThread* thread = RenderThread::current();
1847 // Will be NULL during unit tests.
1848 if (thread) {
1849 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291850 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171851 word, document_tag_);
1852 }
[email protected]1dbafaf72009-09-23 19:43:561853 }
[email protected]2a3a7762009-10-19 19:17:321854 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561855}
1856
[email protected]c49085c72009-10-02 16:28:561857void RenderView::showSpellingUI(bool show) {
1858 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1859}
1860
[email protected]8922e1f2009-10-03 05:01:261861bool RenderView::isShowingSpellingUI() {
1862 return spelling_panel_visible_;
1863}
1864
[email protected]1dbafaf72009-09-23 19:43:561865void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321866 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1867 word));
[email protected]1dbafaf72009-09-23 19:43:561868}
1869
[email protected]a1128322009-10-06 18:38:461870bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351871 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471872 WebFileChooserCompletion* chooser_completion) {
1873 ViewHostMsg_RunFileChooser_Params ipc_params;
1874 ipc_params.mode = params.multiSelect ?
1875 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1876 ViewHostMsg_RunFileChooser_Params::Open;
1877 ipc_params.title = params.title;
1878 ipc_params.default_file_name =
1879 webkit_glue::WebStringToFilePath(params.initialValue);
1880
1881 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461882}
1883
[email protected]48c9cf2d2009-09-16 16:47:521884void RenderView::runModalAlertDialog(
1885 WebFrame* frame, const WebString& message) {
1886 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1887 UTF16ToWideHack(message),
1888 std::wstring(),
1889 frame->url(),
1890 NULL);
1891}
1892
1893bool RenderView::runModalConfirmDialog(
1894 WebFrame* frame, const WebString& message) {
1895 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1896 UTF16ToWideHack(message),
1897 std::wstring(),
1898 frame->url(),
1899 NULL);
1900}
1901
1902bool RenderView::runModalPromptDialog(
1903 WebFrame* frame, const WebString& message, const WebString& default_value,
1904 WebString* actual_value) {
1905 std::wstring result;
1906 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1907 UTF16ToWideHack(message),
1908 UTF16ToWideHack(default_value),
1909 frame->url(),
1910 &result);
1911 if (ok)
1912 actual_value->assign(WideToUTF16Hack(result));
1913 return ok;
1914}
1915
1916bool RenderView::runModalBeforeUnloadDialog(
1917 WebFrame* frame, const WebString& message) {
1918 bool success = false;
1919 // This is an ignored return value, but is included so we can accept the same
1920 // response as RunJavaScriptMessage.
1921 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211922 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521923 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211924 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521925 return success;
1926}
1927
[email protected]79e37442009-10-09 18:17:441928void RenderView::showContextMenu(
1929 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291930 ContextMenuParams params = ContextMenuParams(data);
1931 if (!params.misspelled_word.empty() && RenderThread::current()) {
1932 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041933 bool spelled_right = RenderThread::current()->spellchecker()->
1934 SpellCheckWord(
1935 params.misspelled_word.c_str(), params.misspelled_word.size(),
1936 document_tag_,
1937 &misspelled_offset, &misspelled_length,
1938 &params.dictionary_suggestions);
1939 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291940 params.misspelled_word.clear();
1941 }
1942
1943 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441944}
1945
[email protected]52f139e2c2010-06-11 16:56:091946bool RenderView::supportsFullscreen() {
1947 return CommandLine::ForCurrentProcess()->HasSwitch(
1948 switches::kEnableVideoFullscreen);
1949}
1950
1951void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1952 NOTIMPLEMENTED();
1953}
1954
1955void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1956 NOTIMPLEMENTED();
1957}
1958
[email protected]48c9cf2d2009-09-16 16:47:521959void RenderView::setStatusText(const WebString& text) {
1960}
1961
[email protected]163f8242009-10-30 20:19:551962void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581963 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521964 if (latest_url == target_url_)
1965 return;
[email protected]163f8242009-10-30 20:19:551966
[email protected]48c9cf2d2009-09-16 16:47:521967 // Tell the browser to display a destination link.
1968 if (target_url_status_ == TARGET_INFLIGHT ||
1969 target_url_status_ == TARGET_PENDING) {
1970 // If we have a request in-flight, save the URL to be sent when we
1971 // receive an ACK to the in-flight request. We can happily overwrite
1972 // any existing pending sends.
1973 pending_target_url_ = latest_url;
1974 target_url_status_ = TARGET_PENDING;
1975 } else {
1976 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1977 target_url_ = latest_url;
1978 target_url_status_ = TARGET_INFLIGHT;
1979 }
1980}
1981
[email protected]882daa92009-11-05 16:31:311982void RenderView::StartNavStateSyncTimerIfNecessary() {
1983 int delay;
1984 if (send_content_state_immediately_)
1985 delay = 0;
1986 else if (is_hidden())
1987 delay = kDelaySecondsForContentStateSyncHidden;
1988 else
1989 delay = kDelaySecondsForContentStateSync;
1990
1991 if (nav_state_sync_timer_.IsRunning()) {
1992 // The timer is already running. If the delay of the timer maches the amount
1993 // we want to delay by, then return. Otherwise stop the timer so that it
1994 // gets started with the right delay.
1995 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1996 return;
1997 nav_state_sync_timer_.Stop();
1998 }
1999
2000 nav_state_sync_timer_.Start(
2001 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2002}
2003
[email protected]163f8242009-10-30 20:19:552004void RenderView::setMouseOverURL(const WebURL& url) {
2005 mouse_over_url_ = GURL(url);
2006 UpdateTargetURL(mouse_over_url_, focus_url_);
2007}
2008
2009void RenderView::setKeyboardFocusURL(const WebURL& url) {
2010 focus_url_ = GURL(url);
2011 UpdateTargetURL(focus_url_, mouse_over_url_);
2012}
2013
[email protected]48c9cf2d2009-09-16 16:47:522014void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2015 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2016 hint));
2017}
2018
[email protected]c27ae592010-03-18 15:24:412019void RenderView::startDragging(const WebDragData& data,
2020 WebDragOperationsMask mask,
2021 const WebImage& image,
2022 const WebPoint& imageOffset) {
2023#if WEBKIT_USING_SKIA
2024 SkBitmap bitmap(image.getSkBitmap());
2025#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332026 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412027#endif
2028
[email protected]48c9cf2d2009-09-16 16:47:522029 Send(new ViewHostMsg_StartDragging(routing_id_,
2030 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412031 mask,
2032 bitmap,
2033 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522034}
2035
[email protected]28b92df2009-09-25 17:35:452036bool RenderView::acceptsLoadDrops() {
2037 return renderer_preferences_.can_accept_load_drops;
2038}
2039
[email protected]48c9cf2d2009-09-16 16:47:522040void RenderView::focusNext() {
2041 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2042}
2043
2044void RenderView::focusPrevious() {
2045 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2046}
2047
[email protected]08e9e132010-06-01 16:58:492048void RenderView::focusedNodeChanged(const WebNode& node) {
2049 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
2050}
2051
[email protected]48c9cf2d2009-09-16 16:47:522052void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522053 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2054}
2055
2056int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002057 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522058}
2059
2060int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002061 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522062}
2063
[email protected]c4e98902010-06-01 10:20:142064void RenderView::didUpdateInspectorSetting(const WebString& key,
2065 const WebString& value) {
2066 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2067 key.utf8(),
2068 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262069}
2070
[email protected]acca2a1f2009-10-16 03:53:392071void RenderView::queryAutofillSuggestions(const WebNode& node,
2072 const WebString& name,
2073 const WebString& value) {
2074 static int query_counter = 0;
2075 autofill_query_id_ = query_counter++;
2076 autofill_query_node_ = node;
[email protected]e250e492010-04-06 21:35:362077
2078 const WebFormControlElement& element =
[email protected]f40b49e2010-05-05 22:38:452079 node.toConst<WebFormControlElement>();
[email protected]e250e492010-04-06 21:35:362080
[email protected]dede9342010-04-12 16:51:112081 webkit_glue::FormField field;
2082 FormManager::WebFormControlElementToFormField(element, true, &field);
[email protected]e250e492010-04-06 21:35:362083
[email protected]72eb2da2010-04-14 00:31:082084 // WebFormControlElementToFormField does not scrape the DOM for the field
2085 // label, so find the label here.
2086 // TODO(jhawkins): Add form and field identities so we can use the cached form
2087 // data in FormManager.
2088 field.set_label(FormManager::LabelForElement(element));
2089
[email protected]25bacf32010-06-24 23:23:162090 bool form_autofilled = form_manager_.FormWithNodeIsAutoFilled(node);
[email protected]1cf47dd52010-06-10 22:41:202091 Send(new ViewHostMsg_QueryFormFieldAutoFill(
[email protected]25bacf32010-06-24 23:23:162092 routing_id_, autofill_query_id_, form_autofilled, field));
[email protected]acca2a1f2009-10-16 03:53:392093}
2094
2095void RenderView::removeAutofillSuggestions(const WebString& name,
2096 const WebString& value) {
[email protected]1cf47dd52010-06-10 22:41:202097 Send(new ViewHostMsg_RemoveAutocompleteEntry(routing_id_, name, value));
[email protected]acca2a1f2009-10-16 03:53:392098}
2099
[email protected]18ca9a6b2010-06-02 19:05:182100void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2101 const WebKit::WebString& value,
2102 const WebKit::WebString& label) {
[email protected]1cf47dd52010-06-10 22:41:202103 // DEPRECATED
2104 didAcceptAutoFillSuggestion(node, value, label, -1);
2105}
2106
2107void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2108 const WebKit::WebString& value,
2109 const WebKit::WebString& label,
2110 unsigned index) {
2111 DCHECK_NE(0U, suggestions_count_);
2112
[email protected]631ec052010-06-13 22:26:302113 if (index == suggestions_count_ - 1) {
2114 // User selected 'AutoFill Options...'.
[email protected]1cf47dd52010-06-10 22:41:202115 Send(new ViewHostMsg_ShowAutoFillDialog(routing_id_));
[email protected]631ec052010-06-13 22:26:302116 } else if (form_manager_.FormWithNodeIsAutoFilled(node) &&
2117 index == suggestions_count_ - 2) {
2118 // The form has been auto-filled, so give the user the chance to clear the
2119 // form.
2120 form_manager_.ClearFormWithNode(node);
[email protected]785710ca2010-06-30 00:40:142121 } else if (form_manager_.FormWithNodeIsAutoFilled(node)) {
2122 // Fill a specific field value.
2123 // Cast away const'ness in this case where we're filling the element
2124 // directly.
2125 WebInputElement element = node.toConst<WebInputElement>();
2126 element.setValue(value);
[email protected]631ec052010-06-13 22:26:302127 } else {
[email protected]785710ca2010-06-30 00:40:142128 // Fill the values for the whole form.
[email protected]1cf47dd52010-06-10 22:41:202129 QueryAutoFillFormData(node, value, label, AUTOFILL_FILL);
[email protected]631ec052010-06-13 22:26:302130 }
[email protected]1cf47dd52010-06-10 22:41:202131
2132 suggestions_count_ = 0;
[email protected]18ca9a6b2010-06-02 19:05:182133}
[email protected]c83641732010-02-20 01:04:482134
[email protected]18ca9a6b2010-06-02 19:05:182135void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2136 const WebKit::WebString& value,
2137 const WebKit::WebString& label) {
2138 didClearAutoFillSelection(node);
2139 QueryAutoFillFormData(node, value, label, AUTOFILL_PREVIEW);
2140}
2141
2142void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]45c6e532010-03-15 23:51:242143 webkit_glue::FormData form;
[email protected]18ca9a6b2010-06-02 19:05:182144 const WebFormControlElement element = node.toConst<WebFormControlElement>();
[email protected]b1438212010-04-03 00:30:592145 if (!form_manager_.FindFormWithFormControlElement(
[email protected]da592272010-04-14 20:08:492146 element, FormManager::REQUIRE_NONE, &form))
[email protected]c83641732010-02-20 01:04:482147 return;
[email protected]18ca9a6b2010-06-02 19:05:182148 form_manager_.ClearPreviewedForm(form);
[email protected]c83641732010-02-20 01:04:482149}
2150
[email protected]79dbc662009-09-04 05:42:512151// WebKit::WebWidgetClient ----------------------------------------------------
2152
initial.commit09911bf2008-07-26 23:55:292153// We are supposed to get a single call to Show for a newly created RenderView
2154// that was created via RenderView::CreateWebView. So, we wait until this
2155// point to dispatch the ShowView message.
2156//
2157// This method provides us with the information about how to display the newly
2158// created RenderView (i.e., as a constrained popup or as a new tab).
2159//
[email protected]4873c7d2009-07-16 06:36:282160void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292161 DCHECK(!did_show_) << "received extraneous Show call";
2162 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2163
2164 if (did_show_)
2165 return;
2166 did_show_ = true;
2167
[email protected]28295ec2009-10-16 05:34:332168 // Force new windows to a popup if they were not opened with a user gesture.
2169 if (!opened_by_user_gesture_) {
2170 // We exempt background tabs for compat with older versions of Chrome.
2171 // TODO(darin): This seems bogus. These should have a user gesture, so
2172 // we probably don't need this check.
2173 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2174 policy = WebKit::WebNavigationPolicyNewPopup;
2175 }
2176
initial.commit09911bf2008-07-26 23:55:292177 // NOTE: initial_pos_ may still have its default values at this point, but
2178 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2179 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282180 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2181 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292182 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242183 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292184}
2185
[email protected]4873c7d2009-07-16 06:36:282186void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132187 // Cancel pending translations so that the translate_helper_ does not attempt
2188 // to access the WebView.
2189 translate_helper_.CancelPendingTranslation();
2190
[email protected]e8345242010-05-06 03:00:402191 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282192 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312193}
2194
[email protected]4873c7d2009-07-16 06:36:282195void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292196 DCHECK(did_show_) << "should already have shown the view";
2197
[email protected]c1f50aa2010-02-18 03:46:572198 // We must keep WebKit's shared timer running in this case in order to allow
2199 // showModalDialog to function properly.
2200 //
2201 // TODO(darin): WebKit should really be smarter about suppressing events and
2202 // timers so that we do not need to manage the shared timer in such a heavy
2203 // handed manner.
2204 //
2205 if (RenderThread::current()) // Will be NULL during unit tests.
2206 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2207
[email protected]12636df2009-09-28 22:32:212208 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292209}
2210
[email protected]3d9689372009-09-10 04:29:172211// WebKit::WebFrameClient -----------------------------------------------------
2212
2213WebPlugin* RenderView::createPlugin(
2214 WebFrame* frame, const WebPluginParams& params) {
[email protected]4e0616e2010-05-28 14:55:532215 FilePath path;
2216 std::string actual_mime_type;
2217 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2218 params.url, frame->top()->url(), params.mimeType.utf8(), &path,
2219 &actual_mime_type));
2220 if (path.value().empty())
2221 return NULL;
2222
2223 if (actual_mime_type.empty())
2224 actual_mime_type = params.mimeType.utf8();
2225
[email protected]53af1d62010-05-14 03:40:262226 scoped_refptr<pepper::PluginModule> pepper_module =
[email protected]4e0616e2010-05-28 14:55:532227 PepperPluginRegistry::GetInstance()->GetModule(path);
[email protected]53af1d62010-05-14 03:40:262228 if (pepper_module) {
[email protected]4e0616e2010-05-28 14:55:532229 return new pepper::WebPluginImpl(pepper_module, params,
[email protected]b4f68dea2010-05-13 06:03:172230 pepper_delegate_.AsWeakPtr());
2231 }
[email protected]4e0616e2010-05-28 14:55:532232
2233 return new webkit_glue::WebPluginImpl(frame, params, path, actual_mime_type,
2234 AsWeakPtr());
[email protected]3d9689372009-09-10 04:29:172235}
2236
2237WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562238 WebApplicationCacheHostImpl* appcache_host =
2239 WebApplicationCacheHostImpl::FromFrame(frame);
2240 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2241 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2242 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172243}
2244
[email protected]9c00f002009-11-05 22:37:422245WebSharedWorker* RenderView::createSharedWorker(
2246 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372247 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422248
[email protected]30447b62009-11-13 01:13:372249 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512250 bool exists = false;
[email protected]30447b62009-11-13 01:13:372251 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512252 ViewHostMsg_CreateWorker_Params params;
2253 params.url = url;
2254 params.is_shared = true;
2255 params.name = name;
2256 params.document_id = document_id;
2257 params.render_view_route_id = routing_id_;
2258 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232259 params.parent_appcache_host_id = 0;
2260 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372261 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512262 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372263 if (url_mismatch) {
2264 return NULL;
2265 } else {
2266 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492267 document_id,
[email protected]6de0bcf2010-02-17 22:00:512268 exists,
[email protected]30447b62009-11-13 01:13:372269 route_id,
2270 routing_id_);
2271 }
[email protected]9c00f002009-11-05 22:37:422272}
2273
[email protected]3d9689372009-09-10 04:29:172274WebMediaPlayer* RenderView::createMediaPlayer(
2275 WebFrame* frame, WebMediaPlayerClient* client) {
2276 scoped_refptr<media::FilterFactoryCollection> factory =
2277 new media::FilterFactoryCollection();
2278 // Add in any custom filter factories first.
2279 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2280 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2281 // Add the chrome specific audio renderer.
2282 factory->AddFactory(
2283 AudioRendererImpl::CreateFactory(audio_message_filter()));
2284 }
2285
[email protected]80f584d92010-01-21 03:59:042286 WebApplicationCacheHostImpl* appcache_host =
2287 WebApplicationCacheHostImpl::FromFrame(frame);
2288
[email protected]3d9689372009-09-10 04:29:172289 // TODO(hclam): obtain the following parameters from |client|.
2290 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2291 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152292 GURL(), // referrer
2293 "null", // frame origin
2294 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172295 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042296 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172297 routing_id());
2298
[email protected]0436b9a2009-10-23 00:23:052299 // A simple data source that keeps all data in memory.
2300 media::FilterFactory* simple_data_source_factory =
2301 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2302 bridge_factory);
2303 // A sophisticated data source that does memory caching.
2304 media::FilterFactory* buffered_data_source_factory =
2305 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2306 bridge_factory);
2307 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2308 factory->AddFactory(simple_data_source_factory);
2309 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172310 } else {
[email protected]0436b9a2009-10-23 00:23:052311 factory->AddFactory(buffered_data_source_factory);
2312 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172313 }
[email protected]8400e032010-02-26 18:50:112314
2315 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2316 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2317 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2318 } else {
[email protected]b57509eb2010-03-30 01:26:282319 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2320 factory_factory =
2321 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112322 }
2323
2324 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172325}
2326
[email protected]035545f2010-04-09 13:10:212327WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2328 WebFrame* frame, WebApplicationCacheHostClient* client) {
2329 return new RendererWebApplicationCacheHostImpl(
2330 FromWebView(frame->view()), client,
2331 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2332}
2333
[email protected]b921cfd22010-02-25 16:57:512334WebCookieJar* RenderView::cookieJar() {
2335 return &cookie_jar_;
2336}
2337
[email protected]3d9689372009-09-10 04:29:172338void RenderView::willClose(WebFrame* frame) {
2339 if (!frame->parent()) {
2340 const GURL& url = frame->url();
2341 if (url.SchemeIs("http") || url.SchemeIs("https"))
2342 DumpLoadHistograms();
2343 }
[email protected]fa7b6b542009-11-03 05:02:302344
2345 WebDataSource* ds = frame->dataSource();
2346 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2347 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162348
2349 form_manager_.ResetFrame(frame);
[email protected]3d9689372009-09-10 04:29:172350}
2351
[email protected]684e4a42010-01-30 06:44:112352bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002353 if (!enabled_per_settings)
2354 return false;
[email protected]c21f1d52010-03-04 03:19:432355 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112356}
2357
2358bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402359 if (enabled_per_settings &&
2360 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2361 return true;
2362
2363 if (IsWhitelistedForContentSettings(frame))
2364 return true;
2365
2366 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2367 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112368}
2369
[email protected]3d9689372009-09-10 04:29:172370void RenderView::loadURLExternally(
2371 WebFrame* frame, const WebURLRequest& request,
2372 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592373 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2374 if (policy == WebKit::WebNavigationPolicyDownload) {
2375 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2376 } else {
2377 OpenURL(request.url(), referrer, policy);
2378 }
[email protected]3d9689372009-09-10 04:29:172379}
2380
2381WebNavigationPolicy RenderView::decidePolicyForNavigation(
2382 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222383 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172384 // Webkit is asking whether to navigate to a new URL.
2385 // This is fine normally, except if we're showing UI from one security
2386 // context and they're trying to navigate to a different context.
2387 const GURL& url = request.url();
2388
2389 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302390 // navigations.
[email protected]8079b362010-05-07 18:37:452391 if (renderer_preferences_.browser_handles_top_level_requests &&
2392 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192393 last_top_level_navigation_page_id_ = page_id_;
2394 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2395 OpenURL(url, referrer, default_policy);
2396 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172397 }
2398
2399 // A content initiated navigation may have originated from a link-click,
2400 // script, drag-n-drop operation, etc.
2401 bool is_content_initiated =
2402 NavigationState::FromDataSource(frame->provisionalDataSource())->
2403 is_content_initiated();
2404
2405 // We only care about navigations that are within the current tab (as opposed
2406 // to, for example, opening a new window).
2407 // But we sometimes navigate to about:blank to clear a tab, and we want to
2408 // still allow that.
2409 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2410 is_content_initiated && frame->parent() == NULL &&
[email protected]c240ace2010-06-16 18:31:532411 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]3d9689372009-09-10 04:29:172412 !url.SchemeIs(chrome::kAboutScheme)) {
2413 // When we received such unsolicited navigations, we sometimes want to
2414 // punt them up to the browser to handle.
[email protected]3a8eecb2010-04-22 23:56:302415 if (CrossesExtensionExtents(frame, url) ||
2416 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172417 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422418 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]3d9689372009-09-10 04:29:172419 OpenURL(url, GURL(), default_policy);
2420 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2421 }
[email protected]8079b362010-05-07 18:37:452422
2423 // We forward navigations from extensions to the browser if they are
2424 // top-level events, even if the browser hasn't expressed interest.
2425 //
2426 // Note that we've already forwarded cross-extension extents navigations
2427 // above.
2428 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
[email protected]c240ace2010-06-16 18:31:532429 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]8079b362010-05-07 18:37:452430 OpenURL(url, GURL(), default_policy);
2431 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2432 }
[email protected]3d9689372009-09-10 04:29:172433 }
2434
2435 // Detect when a page is "forking" a new tab that can be safely rendered in
2436 // its own process. This is done by sites like Gmail that try to open links
2437 // in new windows without script connections back to the original page. We
2438 // treat such cases as browser navigations (in which we will create a new
2439 // renderer for a cross-site navigation), rather than WebKit navigations.
2440 //
2441 // We use the following heuristic to decide whether to fork a new page in its
2442 // own process:
2443 // The parent page must open a new tab to about:blank, set the new tab's
2444 // window.opener to null, and then redirect the tab to a cross-site URL using
2445 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462446 //
2447 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2448 // (see below).
[email protected]3d9689372009-09-10 04:29:172449 bool is_fork =
2450 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252451 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172452 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522453 historyBackListCount() < 1 &&
2454 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172455 // The parent page must have set the child's window.opener to null before
2456 // redirecting to the desired URL.
2457 frame->opener() == NULL &&
2458 // Must be a top-level frame.
2459 frame->parent() == NULL &&
2460 // Must not have issued the request from this page.
2461 is_content_initiated &&
2462 // Must be targeted at the current tab.
2463 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2464 // Must be a JavaScript navigation, which appears as "other".
2465 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462466
2467 // Recognize if this navigation is from a link with rel=noreferrer and
2468 // target=_blank attributes, in which case the opener will be suppressed. If
2469 // so, it is safe to load cross-site pages in a separate process, so we
2470 // should let the browser handle it.
2471 bool is_noreferrer_and_blank_target =
2472 // Frame should be top level and not yet navigated.
2473 frame->parent() == NULL &&
2474 frame->url().isEmpty() &&
2475 historyBackListCount() < 1 &&
2476 historyForwardListCount() < 1 &&
2477 // Links with rel=noreferrer will have no Referer field, and their
2478 // resulting frame will have its window.opener suppressed.
2479 // TODO(creis): should add a request.httpReferrer() method to help avoid
2480 // typos on the unusual spelling of Referer.
2481 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2482 opener_suppressed_ &&
2483 frame->opener() == NULL &&
2484 // Links with target=_blank will have no name.
2485 frame->name().isNull() &&
2486 // Another frame (with a non-empty creator) should have initiated the
2487 // request, targeted at this frame.
2488 !creator_url_.is_empty() &&
2489 is_content_initiated &&
2490 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2491 type == WebKit::WebNavigationTypeOther;
2492
2493 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172494 // Open the URL via the browser, not via WebKit.
2495 OpenURL(url, GURL(), default_policy);
2496 return WebKit::WebNavigationPolicyIgnore;
2497 }
2498
2499 return default_policy;
2500}
2501
[email protected]6069da8c2009-10-20 20:33:492502bool RenderView::canHandleRequest(
2503 WebFrame* frame, const WebURLRequest& request) {
2504 // We allow WebKit to think that everything can be handled even though
2505 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342506 return true;
2507}
2508
[email protected]6069da8c2009-10-20 20:33:492509WebURLError RenderView::cannotHandleRequestError(
2510 WebFrame* frame, const WebURLRequest& request) {
2511 NOTREACHED(); // Since we said we can handle all requests.
2512 return WebURLError();
2513}
2514
2515WebURLError RenderView::cancelledError(
2516 WebFrame* frame, const WebURLRequest& request) {
2517 WebURLError error;
2518 error.domain = WebString::fromUTF8(net::kErrorDomain);
2519 error.reason = net::ERR_ABORTED;
2520 error.unreachableURL = request.url();
2521 return error;
[email protected]7b7a7dc2009-10-19 02:23:342522}
2523
2524void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492525 WebFrame*, const WebURLError&) {
2526 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342527}
2528
[email protected]90eeddb2010-05-06 21:06:432529void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2530 const WebKit::WebFormElement& form) {
2531 // Some login forms have onSubmit handlers that put a hash of the password
2532 // into a hidden field and then clear the password. (Issue 28910.)
2533 // This method gets called before any of those handlers run, so save away
2534 // a copy of the password in case it gets lost.
2535 NavigationState* navigation_state =
2536 NavigationState::FromDataSource(frame->dataSource());
2537 navigation_state->set_password_form_data(
2538 PasswordFormDomManager::CreatePasswordForm(form));
2539}
2540
[email protected]979c28b2009-11-07 01:30:482541void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172542 NavigationState* navigation_state =
2543 NavigationState::FromDataSource(frame->provisionalDataSource());
2544
2545 if (navigation_state->transition_type() == PageTransition::LINK)
2546 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2547
2548 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352549 WebSearchableFormData web_searchable_form_data(form);
2550 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2551 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212552 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432553 PasswordForm* password_form_data =
2554 PasswordFormDomManager::CreatePasswordForm(form);
2555 navigation_state->set_password_form_data(password_form_data);
2556
2557 // If the password has been cleared, recover it from the form contents already
2558 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2559 // opposed to the provisionalDataSource's, which is what we're storing into
2560 // now.)
2561 if (password_form_data && password_form_data->password_value.empty()) {
2562 NavigationState* old_navigation_state =
2563 NavigationState::FromDataSource(frame->dataSource());
2564 if (old_navigation_state) {
2565 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2566 if (old_form_data && old_form_data->action == password_form_data->action)
2567 password_form_data->password_value = old_form_data->password_value;
2568 }
2569 }
[email protected]3d9689372009-09-10 04:29:172570
[email protected]b1438212010-04-03 00:30:592571 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042572 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092573 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592574 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172575}
2576
2577void RenderView::willPerformClientRedirect(
2578 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2579 double fire_time) {
2580 // Ignore
2581}
2582
2583void RenderView::didCancelClientRedirect(WebFrame* frame) {
2584 // Ignore
2585}
2586
2587void RenderView::didCompleteClientRedirect(
2588 WebFrame* frame, const WebURL& from) {
2589 if (!frame->parent())
2590 completed_client_redirect_src_ = from;
2591}
2592
2593void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2594 // The rest of RenderView assumes that a WebDataSource will always have a
2595 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482596 bool content_initiated = !pending_navigation_state_.get();
2597 NavigationState* state = content_initiated ?
2598 NavigationState::CreateContentInitiated() :
2599 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182600 if (content_initiated) {
2601 switch (ds->request().cachePolicy()) {
2602 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2603 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2604 break;
2605 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2606 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2607 break;
2608 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2609 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2610 break;
2611 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2612 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2613 break;
2614 }
2615 }
[email protected]fa7b6b542009-11-03 05:02:302616
2617 state->set_user_script_idle_scheduler(
2618 new UserScriptIdleScheduler(this, frame));
2619 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172620}
2621
2622void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2623 WebDataSource* ds = frame->provisionalDataSource();
2624 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2625
2626 navigation_state->set_start_load_time(Time::Now());
2627
2628 // Update the request time if WebKit has better knowledge of it.
2629 if (navigation_state->request_time().is_null()) {
2630 double event_time = ds->triggeringEventTime();
2631 if (event_time != 0.0)
2632 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2633 }
2634
2635 bool is_top_most = !frame->parent();
2636 if (is_top_most) {
2637 navigation_gesture_ = frame->isProcessingUserGesture() ?
2638 NavigationGestureUnknown : NavigationGestureAuto;
2639
2640 // Make sure redirect tracking state is clear for the new load.
2641 completed_client_redirect_src_ = GURL();
2642 } else if (frame->parent()->isLoading()) {
2643 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002644 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172645 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2646 }
2647
2648 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2649 routing_id_, is_top_most, ds->request().url()));
2650}
2651
2652void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2653 if (frame->parent())
2654 return;
2655 // Received a redirect on the main frame.
2656 WebDataSource* data_source = frame->provisionalDataSource();
2657 if (!data_source) {
2658 // Should only be invoked when we have a data source.
2659 NOTREACHED();
2660 return;
2661 }
2662 std::vector<GURL> redirects;
2663 GetRedirectChain(data_source, &redirects);
2664 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512665 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2666 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172667 }
2668}
2669
[email protected]40bd6582009-12-04 23:49:512670void RenderView::didFailProvisionalLoad(WebFrame* frame,
2671 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172672 // Notify the browser that we failed a provisional load with an error.
2673 //
2674 // Note: It is important this notification occur before DidStopLoading so the
2675 // SSL manager can react to the provisional load failure before being
2676 // notified the load stopped.
2677 //
2678 WebDataSource* ds = frame->provisionalDataSource();
2679 DCHECK(ds);
2680
2681 const WebURLRequest& failed_request = ds->request();
2682
2683 bool show_repost_interstitial =
2684 (error.reason == net::ERR_CACHE_MISS &&
2685 EqualsASCII(failed_request.httpMethod(), "POST"));
2686 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2687 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2688 show_repost_interstitial));
2689
2690 // Don't display an error page if this is simply a cancelled load. Aside
2691 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2692 if (error.reason == net::ERR_ABORTED)
2693 return;
2694
2695 // Make sure we never show errors in view source mode.
2696 frame->enableViewSourceMode(false);
2697
2698 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2699
2700 // If this is a failed back/forward/reload navigation, then we need to do a
2701 // 'replace' load. This is necessary to avoid messing up session history.
2702 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2703 // as session history is concerned.
2704 //
2705 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2706 // the page id.
2707 //
2708 bool replace =
2709 navigation_state->pending_page_id() != -1 ||
2710 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2711
2712 // If we failed on a browser initiated request, then make sure that our error
2713 // page load is regarded as the same browser initiated request.
2714 if (!navigation_state->is_content_initiated()) {
2715 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2716 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002717 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172718 navigation_state->transition_type(),
2719 navigation_state->request_time()));
2720 }
2721
2722 // Provide the user with a more helpful error page?
2723 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2724 return;
2725
2726 // Fallback to a local error page.
2727 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2728 replace);
2729}
2730
2731void RenderView::didReceiveDocumentData(
2732 WebFrame* frame, const char* data, size_t data_len,
2733 bool& prevent_default) {
2734 NavigationState* navigation_state =
2735 NavigationState::FromDataSource(frame->dataSource());
2736 if (!navigation_state->postpone_loading_data())
2737 return;
2738
2739 // We're going to call commitDocumentData ourselves...
2740 prevent_default = true;
2741
2742 // Continue buffering the response data for the original 404 page. If it
2743 // grows too large, then we'll just let it through.
2744 navigation_state->append_postponed_data(data, data_len);
2745 if (navigation_state->postponed_data().size() >= 512) {
2746 navigation_state->set_postpone_loading_data(false);
2747 frame->commitDocumentData(navigation_state->postponed_data().data(),
2748 navigation_state->postponed_data().size());
2749 navigation_state->clear_postponed_data();
2750 }
2751}
2752
[email protected]40bd6582009-12-04 23:49:512753void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2754 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172755 NavigationState* navigation_state =
2756 NavigationState::FromDataSource(frame->dataSource());
2757
2758 navigation_state->set_commit_load_time(Time::Now());
2759 if (is_new_navigation) {
2760 // When we perform a new navigation, we need to update the previous session
2761 // history entry with state for the page we are leaving.
2762 UpdateSessionHistory(frame);
2763
2764 // We bump our Page ID to correspond with the new session history entry.
2765 page_id_ = next_page_id_++;
2766
[email protected]d64b07b2010-04-20 22:14:062767 // Any pending translation is now obsolete.
2768 translate_helper_.CancelPendingTranslation();
2769
[email protected]3cc72b12010-03-18 23:03:002770 // Advance our offset in session history, applying the length limit. There
2771 // is now no forward history.
2772 history_list_offset_++;
2773 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2774 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2775 history_list_length_ = history_list_offset_ + 1;
2776
[email protected]f9f4841b2010-03-20 05:41:422777 MessageLoop::current()->PostDelayedTask(
2778 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172779 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2780 page_id_, true),
2781 kDelayForForcedCaptureMs);
2782 } else {
2783 // Inspect the navigation_state on this frame to see if the navigation
2784 // corresponds to a session history navigation... Note: |frame| may or
2785 // may not be the toplevel frame, but for the case of capturing session
2786 // history, the first committed frame suffices. We keep track of whether
2787 // we've seen this commit before so that only capture session history once
2788 // per navigation.
2789 //
2790 // Note that we need to check if the page ID changed. In the case of a
2791 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2792 // previous URL and the current page ID, which would be wrong.
2793 if (navigation_state->pending_page_id() != -1 &&
2794 navigation_state->pending_page_id() != page_id_ &&
2795 !navigation_state->request_committed()) {
2796 // This is a successful session history navigation!
2797 UpdateSessionHistory(frame);
2798 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002799
2800 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172801 }
2802 }
2803
2804 // Remember that we've already processed this request, so we don't update
2805 // the session history again. We do this regardless of whether this is
2806 // a session history navigation, because if we attempted a session history
2807 // navigation without valid HistoryItem state, WebCore will think it is a
2808 // new navigation.
2809 navigation_state->set_request_committed(true);
2810
2811 UpdateURL(frame);
2812
2813 // If this committed load was initiated by a client redirect, we're
2814 // at the last stop now, so clear it.
2815 completed_client_redirect_src_ = GURL();
2816
2817 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272818 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172819}
2820
2821void RenderView::didClearWindowObject(WebFrame* frame) {
2822 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2823 BindDOMAutomationController(frame);
2824 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2825 dom_ui_bindings_.set_message_sender(this);
2826 dom_ui_bindings_.set_routing_id(routing_id_);
2827 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2828 }
2829 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2830 external_host_bindings_.set_message_sender(this);
2831 external_host_bindings_.set_routing_id(routing_id_);
2832 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2833 }
2834}
2835
2836void RenderView::didCreateDocumentElement(WebFrame* frame) {
2837 if (RenderThread::current()) { // Will be NULL during unit tests.
2838 RenderThread::current()->user_script_slave()->InjectScripts(
2839 frame, UserScript::DOCUMENT_START);
2840 }
[email protected]078b34612009-09-19 19:31:512841 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2842 view_type_ == ViewType::EXTENSION_MOLE) {
2843 InjectToolstripCSS();
2844 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2845 }
[email protected]3d9689372009-09-10 04:29:172846
2847 // Notify the browser about non-blank documents loading in the top frame.
2848 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252849 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272850 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172851 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2852 }
2853}
2854
2855void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2856 UpdateTitle(frame, title);
2857
2858 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272859 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172860}
2861
[email protected]5019ef12010-04-27 17:26:582862void RenderView::didChangeIcons(WebFrame* frame) {
2863 if (!frame->parent()) {
2864 Send(new ViewHostMsg_UpdateFavIconURL(
2865 routing_id_,
2866 page_id_,
2867 frame->favIconURL()));
2868 }
2869}
2870
[email protected]3d9689372009-09-10 04:29:172871void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2872 WebDataSource* ds = frame->dataSource();
2873 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2874 DCHECK(navigation_state);
2875 navigation_state->set_finish_document_load_time(Time::Now());
2876
2877 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2878
[email protected]e9e07992010-02-17 21:04:362879 // The document has now been fully loaded. Scan for forms to be sent up to
2880 // the browser.
2881 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482882 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362883 SendForms(frame);
[email protected]4d44a1c2010-04-28 19:20:412884 SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:172885
2886 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272887 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172888
2889 if (RenderThread::current()) { // Will be NULL during unit tests.
2890 RenderThread::current()->user_script_slave()->InjectScripts(
2891 frame, UserScript::DOCUMENT_END);
2892 }
[email protected]fa7b6b542009-11-03 05:02:302893
2894 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2895}
2896
2897void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2898 if (RenderThread::current()) { // Will be NULL during unit tests.
2899 RenderThread::current()->user_script_slave()->InjectScripts(
2900 frame, UserScript::DOCUMENT_IDLE);
2901 }
2902
2903 WebFrame* main_frame = webview()->mainFrame();
2904 if (frame == main_frame) {
2905 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202906 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302907 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202908 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302909 pending_code_execution_queue_.pop();
2910 }
2911 }
[email protected]3d9689372009-09-10 04:29:172912}
2913
2914void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]dd3c3e682010-05-12 18:51:262915 if (webview()->mainFrame() == frame)
2916 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:172917}
2918
2919void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2920 // Ignore
2921}
2922
2923void RenderView::didFinishLoad(WebFrame* frame) {
2924 WebDataSource* ds = frame->dataSource();
2925 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2926 DCHECK(navigation_state);
2927 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302928 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:412929
2930 // Let the password manager know which password forms are actually visible.
2931 SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:172932}
2933
[email protected]ccbe04e2010-03-17 17:58:432934void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172935 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062936
2937 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2938 // since a new one gets created by didCreateDataSource.
2939 NavigationState* state =
2940 NavigationState::FromDataSource(frame->dataSource());
2941 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
2942
[email protected]3d9689372009-09-10 04:29:172943 // If this was a reference fragment navigation that we initiated, then we
2944 // could end up having a non-null pending navigation state. We just need to
2945 // update the ExtraData on the datasource so that others who read the
2946 // ExtraData will get the new NavigationState. Similarly, if we did not
2947 // initiate this navigation, then we need to take care to reset any pre-
2948 // existing navigation state to a content-initiated navigation state.
2949 // DidCreateDataSource conveniently takes care of this for us.
2950 didCreateDataSource(frame, frame->dataSource());
2951
[email protected]f6c2459d2010-02-24 22:34:062952 if (idle_scheduler_ran) {
2953 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
2954 NavigationState* new_state =
2955 NavigationState::FromDataSource(frame->dataSource());
2956 new_state->user_script_idle_scheduler()->set_has_run(true);
2957 }
2958
[email protected]3d9689372009-09-10 04:29:172959 didCommitProvisionalLoad(frame, is_new_navigation);
2960
[email protected]26aa0482009-09-30 16:55:272961 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172962}
2963
[email protected]476b6f82009-09-10 21:00:592964void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312965 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592966}
2967
[email protected]3d9689372009-09-10 04:29:172968void RenderView::assignIdentifierToRequest(
2969 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2970 // Ignore
2971}
2972
2973void RenderView::willSendRequest(
2974 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2975 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302976 WebFrame* top_frame = frame->top();
2977 if (!top_frame)
2978 top_frame = frame;
2979 WebDataSource* data_source = top_frame->provisionalDataSource();
2980 if (!data_source)
2981 data_source = top_frame->dataSource();
2982 if (data_source) {
2983 NavigationState* state = NavigationState::FromDataSource(data_source);
2984 if (state && state->is_cache_policy_override_set())
2985 request.setCachePolicy(state->cache_policy_override());
2986 }
[email protected]3d9689372009-09-10 04:29:172987 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:502988 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:132989 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492990
[email protected]85cc78c2010-05-04 18:30:092991 // Temporary metrics, see site_isolation_metrics.h
2992 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:172993}
2994
2995void RenderView::didReceiveResponse(
2996 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492997
[email protected]85cc78c2010-05-04 18:30:092998 // Temporary metrics, see site_isolation_metrics.h
2999 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3000 identifier,
3001 response);
[email protected]fa0a3432010-03-30 16:53:493002
[email protected]3d9689372009-09-10 04:29:173003 // Only do this for responses that correspond to a provisional data source
3004 // of the top-most frame. If we have a provisional data source, then we
3005 // can't have any sub-resources yet, so we know that this response must
3006 // correspond to a frame load.
3007 if (!frame->provisionalDataSource() || frame->parent())
3008 return;
3009
3010 // If we are in view source mode, then just let the user see the source of
3011 // the server's 404 error page.
3012 if (frame->isViewSourceModeEnabled())
3013 return;
3014
[email protected]65041fa2010-05-21 06:56:533015 NavigationState* navigation_state =
3016 NavigationState::FromDataSource(frame->provisionalDataSource());
3017 CHECK(navigation_state);
3018
[email protected]972ebdff2010-06-10 22:59:073019 // Record page load flags.
3020 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3021 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573022 navigation_state->set_was_alternate_protocol_available(
3023 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073024 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]65041fa2010-05-21 06:56:533025
[email protected]f48013be2010-01-14 22:07:453026 // Consider loading an alternate error page for 404 responses.
3027 if (response.httpStatusCode() != 404)
3028 return;
3029
[email protected]3d9689372009-09-10 04:29:173030 // Can we even load an alternate error page for this URL?
3031 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3032 return;
3033
[email protected]3d9689372009-09-10 04:29:173034 navigation_state->set_postpone_loading_data(true);
3035 navigation_state->clear_postponed_data();
3036}
3037
3038void RenderView::didFinishResourceLoad(
3039 WebFrame* frame, unsigned identifier) {
3040 NavigationState* navigation_state =
3041 NavigationState::FromDataSource(frame->dataSource());
3042 if (!navigation_state->postpone_loading_data())
3043 return;
3044
3045 // The server returned a 404 and the content was < 512 bytes (which we
3046 // suppressed). Go ahead and fetch the alternate page content.
3047
3048 const GURL& frame_url = frame->url();
3049
3050 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3051 DCHECK(error_page_url.is_valid());
3052
3053 WebURLError original_error;
3054 original_error.unreachableURL = frame_url;
3055
3056 navigation_state->set_alt_error_page_fetcher(
3057 new AltErrorPageResourceFetcher(
3058 error_page_url, frame, original_error,
3059 NewCallback(this, &RenderView::AltErrorPageFinished)));
3060}
3061
3062void RenderView::didFailResourceLoad(
3063 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3064 // Ignore
3065}
3066
3067void RenderView::didLoadResourceFromMemoryCache(
3068 WebFrame* frame, const WebURLRequest& request,
3069 const WebURLResponse& response) {
3070 // Let the browser know we loaded a resource from the memory cache. This
3071 // message is needed to display the correct SSL indicators.
3072 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3073 routing_id_,
3074 request.url(),
[email protected]91733b62009-09-18 06:21:093075 frame->securityOrigin().toString().utf8(),
3076 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173077 response.securityInfo()));
3078}
3079
[email protected]6069da8c2009-10-20 20:33:493080void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293081 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3082}
3083
3084void RenderView::didRunInsecureContent(
3085 WebFrame* frame, const WebSecurityOrigin& origin) {
3086 Send(new ViewHostMsg_DidRunInsecureContent(
3087 routing_id_,
3088 origin.toString().utf8()));
3089}
3090
[email protected]7ea093ba2009-11-03 05:54:593091bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403092 if (enabled_per_settings &&
3093 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3094 return true;
[email protected]7ea093ba2009-11-03 05:54:593095
[email protected]12bc8472010-04-15 07:29:403096 if (IsWhitelistedForContentSettings(frame))
3097 return true;
[email protected]7ea093ba2009-11-03 05:54:593098
3099 return false; // Other protocols fall through here.
3100}
3101
[email protected]0a1a45432010-03-31 08:09:453102bool RenderView::allowDatabase(
3103 WebFrame* frame, const WebString& name, const WebString& display_name,
3104 unsigned long estimated_size) {
3105 WebSecurityOrigin origin = frame->securityOrigin();
3106 if (origin.isEmpty())
3107 return false; // Uninitialized document?
3108
3109 bool result;
3110 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3111 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3112 return false;
3113 if (!result)
3114 DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES);
3115 return result;
3116}
[email protected]8934a3b2010-02-25 00:34:003117void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
3118 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
3119}
3120
[email protected]c21f1d52010-03-04 03:19:433121void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
3122 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
3123}
3124
[email protected]3d9689372009-09-10 04:29:173125void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3126 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3127}
3128
[email protected]0c882b282009-10-07 17:01:283129void RenderView::didCreateScriptContext(WebFrame* frame) {
3130 EventBindings::HandleContextCreated(frame, false);
3131}
3132
3133void RenderView::didDestroyScriptContext(WebFrame* frame) {
3134 EventBindings::HandleContextDestroyed(frame);
3135}
3136
3137void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3138 EventBindings::HandleContextCreated(frame, true);
3139}
3140
[email protected]fc86daa2010-03-30 23:52:533141void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3142 WebFrame* target,
3143 bool cross_origin,
3144 const WebString& property_name,
3145 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103146 // TODO(johnnyg): track the individual properties and repeat event_ids.
3147 if (cross_origin)
3148 cross_origin_access_count_++;
3149 else
3150 same_origin_access_count_++;
3151}
3152
[email protected]3d9689372009-09-10 04:29:173153void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143154 CheckPreferredSize();
3155}
3156
3157void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173158 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253159 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173160 // message.
[email protected]705243f2010-05-05 19:58:073161 if (!send_preferred_size_changes_ || !webview())
3162 return;
[email protected]dfca5acf2010-03-22 03:28:433163
[email protected]705243f2010-05-05 19:58:073164 // WebCore likes to tell us things have changed even when they haven't, so
3165 // cache the width and height and only send the IPC message when we're sure
3166 // they're different.
3167 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3168 webview()->mainFrame()->documentElementScrollHeight());
3169 if (size == preferred_size_)
3170 return;
[email protected]c27324b2009-11-19 22:44:293171
[email protected]705243f2010-05-05 19:58:073172 preferred_size_ = size;
3173 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3174 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173175}
3176
[email protected]143dcd592009-11-06 21:33:493177void RenderView::didChangeScrollOffset(WebFrame* frame) {
3178 StartNavStateSyncTimerIfNecessary();
3179}
3180
[email protected]8922e1f2009-10-03 05:01:263181void RenderView::reportFindInPageMatchCount(int request_id, int count,
3182 bool final_update) {
3183 // If we have a message that has been queued up, then we should just replace
3184 // it. The ACK from the browser will make sure it gets sent when the browser
3185 // wants it.
3186 if (queued_find_reply_message_.get()) {
3187 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3188 routing_id_,
3189 request_id,
3190 count,
3191 gfx::Rect(),
3192 -1, // Don't update active match ordinal.
3193 final_update);
3194 queued_find_reply_message_.reset(msg);
3195 } else {
3196 // Send the search result over to the browser process.
3197 Send(new ViewHostMsg_Find_Reply(
3198 routing_id_,
3199 request_id,
3200 count,
3201 gfx::Rect(),
[email protected]705243f2010-05-05 19:58:073202 -1, // Don't update active match ordinal.
[email protected]8922e1f2009-10-03 05:01:263203 final_update));
3204 }
3205}
3206
3207void RenderView::reportFindInPageSelection(int request_id,
3208 int active_match_ordinal,
3209 const WebRect& selection_rect) {
3210 // Send the search result over to the browser process.
3211 Send(new ViewHostMsg_Find_Reply(routing_id_,
3212 request_id,
3213 -1,
3214 selection_rect,
3215 active_match_ordinal,
3216 false));
3217}
3218
[email protected]24a7f3c2010-03-25 08:26:493219void RenderView::ReportNoFindInPageResults(int request_id) {
3220 Send(new ViewHostMsg_Find_Reply(routing_id_,
3221 request_id,
3222 0,
3223 gfx::Rect(),
3224 0,
3225 true));
3226}
3227
[email protected]79dbc662009-09-04 05:42:513228// webkit_glue::WebPluginPageDelegate -----------------------------------------
3229
[email protected]f103ab72009-09-02 17:10:593230webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533231 const FilePath& file_path,
3232 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593233 if (!PluginChannelHost::IsListening())
3234 return NULL;
3235
[email protected]d2139662009-12-10 03:21:143236 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283237 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143238 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163239 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533240 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143241 if (CommandLine::ForCurrentProcess()->
3242 HasSwitch(switches::kInternalPepper)) {
3243 in_process_plugin = true;
3244 use_pepper_host = true;
3245 } else {
3246 // In process Pepper plugins must be explicitly enabled.
3247 return NULL;
3248 }
[email protected]4e0616e2010-05-28 14:55:533249 } else {
3250 FilePath internal_pdf_path;
3251 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3252 if (file_path == internal_pdf_path) {
3253 in_process_plugin = true;
3254 use_pepper_host = true;
3255 }
[email protected]26e8d5e2009-10-13 02:47:163256 }
[email protected]4e0616e2010-05-28 14:55:533257
[email protected]d2139662009-12-10 03:21:143258 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463259 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3260 if (mime_type == "application/x-nacl-srpc") {
3261 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143262 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463263 }
3264 }
[email protected]4e0616e2010-05-28 14:55:533265
[email protected]d032f492009-09-29 00:33:463266 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143267 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283268 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533269 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]53900d52010-06-16 04:25:013270 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283271 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143272 } else {
[email protected]6876dff2010-01-15 19:38:093273#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143274 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533275 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093276#else
[email protected]596b2c42010-01-14 20:40:433277 NOTIMPLEMENTED();
3278 return NULL;
[email protected]7b6616f2010-01-14 18:07:553279#endif
[email protected]6876dff2010-01-15 19:38:093280 }
[email protected]f103ab72009-09-02 17:10:593281 }
3282
[email protected]4e0616e2010-05-28 14:55:533283 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593284}
3285
3286void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033287#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593288 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3289 routing_id(), window));
3290#endif
3291}
3292
3293void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033294#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593295 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3296 routing_id(), window));
3297#endif
3298 CleanupWindowInPluginMoves(window);
3299}
3300
3301void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3302 SchedulePluginMove(move);
3303}
3304
3305void RenderView::DidStartLoadingForPlugin() {
3306 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523307 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593308}
3309
3310void RenderView::DidStopLoadingForPlugin() {
3311 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523312 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593313}
3314
3315void RenderView::ShowModalHTMLDialogForPlugin(
3316 const GURL& url,
3317 const gfx::Size& size,
3318 const std::string& json_arguments,
3319 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213320 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593321 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213322 json_retval));
[email protected]f103ab72009-09-02 17:10:593323}
3324
[email protected]b921cfd22010-02-25 16:57:513325WebCookieJar* RenderView::GetCookieJar() {
3326 return &cookie_jar_;
3327}
3328
initial.commit09911bf2008-07-26 23:55:293329void RenderView::SyncNavigationState() {
3330 if (!webview())
3331 return;
3332
[email protected]26aa0482009-09-30 16:55:273333 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173334 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293335 return;
[email protected]ca948a22009-06-25 19:36:173336
3337 Send(new ViewHostMsg_UpdateState(
3338 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293339}
3340
[email protected]b0950a72009-09-29 23:16:173341bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3342 // Make sure webview was not shut down.
3343 if (!webview())
3344 return false;
3345 // Create an image resource fetcher and assign it with a call back object.
3346 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273347 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173348 NewCallback(this, &RenderView::DidDownloadImage)));
3349 return true;
3350}
3351
3352void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293353 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173354 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473355 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3356 fetcher->id(),
3357 fetcher->image_url(),
3358 image.isNull(),
3359 image));
[email protected]b0950a72009-09-29 23:16:173360 // Dispose of the image fetcher.
3361 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3362 image_fetchers_.erase(fetcher);
3363 // We're in the callback from the ImageResourceFetcher, best to delay
3364 // deletion.
3365 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293366}
3367
[email protected]bf5c2ff392009-07-08 16:24:333368void RenderView::OnDownloadFavIcon(int id,
3369 const GURL& image_url,
3370 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343371 bool data_image_failed = false;
3372 if (image_url.SchemeIs("data")) {
3373 SkBitmap data_image = ImageFromDataUrl(image_url);
3374 data_image_failed = data_image.empty();
3375 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333376 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3377 data_image));
[email protected]f11ca0732009-04-11 00:09:343378 }
3379 }
3380
[email protected]bf5c2ff392009-07-08 16:24:333381 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173382 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333383 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3384 SkBitmap()));
3385 }
initial.commit09911bf2008-07-26 23:55:293386}
3387
[email protected]f11ca0732009-04-11 00:09:343388SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3389 std::string mime_type, char_set, data;
3390 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3391 // Decode the favicon using WebKit's image decoder.
3392 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3393 const unsigned char* src_data =
3394 reinterpret_cast<const unsigned char*>(&data[0]);
3395
3396 return decoder.Decode(src_data, data.size());
3397 }
3398 return SkBitmap();
3399}
3400
initial.commit09911bf2008-07-26 23:55:293401void RenderView::OnGetApplicationInfo(int page_id) {
3402 webkit_glue::WebApplicationInfo app_info;
3403 if (page_id == page_id_)
3404 webkit_glue::GetApplicationInfo(webview(), &app_info);
3405
3406 // Prune out any data URLs in the set of icons. The browser process expects
3407 // any icon with a data URL to have originated from a favicon. We don't want
3408 // to decode arbitrary data URLs in the browser process. See
3409 // http://b/issue?id=1162972
3410 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593411 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293412 app_info.icons.erase(app_info.icons.begin() + i);
3413 --i;
3414 }
3415 }
3416
3417 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3418}
3419
[email protected]7ccddb8c2009-08-04 17:36:553420GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293421 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553422 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293423 // If the URL that failed was secure, then the embedding web page was not
3424 // expecting a network attacker to be able to manipulate its contents. As
3425 // we fetch alternate error pages over HTTP, we would be allowing a network
3426 // attacker to manipulate the contents of the response if we tried to use
3427 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153428 return GURL();
initial.commit09911bf2008-07-26 23:55:293429 }
3430
3431 // Grab the base URL from the browser process.
3432 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153433 return GURL();
initial.commit09911bf2008-07-26 23:55:293434
3435 // Strip query params from the failed URL.
3436 GURL::Replacements remove_params;
3437 remove_params.ClearUsername();
3438 remove_params.ClearPassword();
3439 remove_params.ClearQuery();
3440 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553441 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503442 std::string spec_to_send = url_to_send.spec();
3443 // Notify link doctor of the url truncation by sending of "?" at the end.
3444 if (failed_url.has_query())
3445 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293446
3447 // Construct the query params to send to link doctor.
3448 std::string params(alternate_error_page_url_.query());
3449 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503450 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293451 params.append("&sourceid=chrome");
3452 params.append("&error=");
3453 switch (error_type) {
3454 case DNS_ERROR:
3455 params.append("dnserror");
3456 break;
3457
3458 case HTTP_404:
3459 params.append("http404");
3460 break;
3461
[email protected]5df266ac2008-10-15 19:50:133462 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333463 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133464 break;
3465
initial.commit09911bf2008-07-26 23:55:293466 default:
3467 NOTREACHED() << "unknown ErrorPageType";
3468 }
3469
3470 // OK, build the final url to return.
3471 GURL::Replacements link_doctor_params;
3472 link_doctor_params.SetQueryStr(params);
3473 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3474 return url;
3475}
3476
[email protected]24a7f3c2010-03-25 08:26:493477webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() {
[email protected]f40b49e2010-05-05 22:38:453478 WebPlugin* plugin =
3479 webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493480 return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate();
3481}
3482
[email protected]6069da8c2009-10-20 20:33:493483void RenderView::OnFind(int request_id, const string16& search_text,
3484 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273485 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493486
3487 if (main_frame->document().isPluginDocument()) {
3488 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3489 if (options.findNext) {
3490 // Just navigate back/forward.
3491 delegate->SelectFindResult(options.forward);
3492 } else {
3493 if (delegate->SupportsFind()) {
3494 delegate->StartFind(UTF16ToUTF8(search_text),
3495 options.matchCase,
3496 request_id);
3497 } else {
3498 ReportNoFindInPageResults(request_id);
3499 }
3500 }
3501 return;
3502 }
3503
[email protected]b4bb2502009-10-01 22:35:273504 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273505 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293506 WebFrame* search_frame = focused_frame; // start searching focused frame.
3507
3508 bool multi_frame = (frame_after_main != main_frame);
3509
3510 // If we have multiple frames, we don't want to wrap the search within the
3511 // frame, so we check here if we only have main_frame in the chain.
3512 bool wrap_within_frame = !multi_frame;
3513
[email protected]b3f2b912009-04-09 16:18:523514 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293515 bool result = false;
3516
[email protected]7830da3e2009-11-06 16:27:263517 // If something is selected when we start searching it means we cannot just
3518 // increment the current match ordinal; we need to re-generate it.
3519 WebRange current_selection = focused_frame->selectionRange();
3520
initial.commit09911bf2008-07-26 23:55:293521 do {
[email protected]dd7daa82009-08-10 05:46:453522 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593523 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293524
3525 if (!result) {
3526 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223527 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293528
3529 // Find the next frame, but skip the invisible ones.
3530 do {
3531 // What is the next frame to search? (we might be going backwards). Note
3532 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593533 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273534 search_frame->traverseNext(true) :
3535 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453536 } while (!search_frame->hasVisibleContent() &&
3537 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293538
[email protected]884db412008-11-24 23:46:503539 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223540 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293541
3542 // If we have multiple frames and we have wrapped back around to the
3543 // focused frame, we need to search it once more allowing wrap within
3544 // the frame, otherwise it will report 'no match' if the focused frame has
3545 // reported matches, but no frames after the focused_frame contain a
3546 // match for the search word(s).
3547 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453548 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593549 request_id, search_text, options, true, // Force wrapping.
3550 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293551 }
3552 }
3553
[email protected]26aa0482009-09-30 16:55:273554 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293555 } while (!result && search_frame != focused_frame);
3556
[email protected]7830da3e2009-11-06 16:27:263557 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293558 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453559 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293560 } else {
3561 // If nothing is found, set result to "0 of 0", otherwise, set it to
3562 // "-1 of 1" to indicate that we found at least one item, but we don't know
3563 // yet what is active.
3564 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3565 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293566
[email protected]4f3dc372009-02-24 00:10:293567 // If we find no matches then this will be our last status update.
3568 // Otherwise the scoping effort will send more results.
3569 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293570
[email protected]4f3dc372009-02-24 00:10:293571 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403572 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593573 request_id,
[email protected]4f3dc372009-02-24 00:10:293574 match_count,
3575 selection_rect,
3576 ordinal,
3577 final_status_update));
initial.commit09911bf2008-07-26 23:55:293578
initial.commit09911bf2008-07-26 23:55:293579 // Scoping effort begins, starting with the mainframe.
3580 search_frame = main_frame;
3581
[email protected]dd7daa82009-08-10 05:46:453582 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293583
3584 do {
3585 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453586 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293587
3588 // We don't start another scoping effort unless at least one match has
3589 // been found.
3590 if (result) {
3591 // Start new scoping request. If the scoping function determines that it
3592 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453593 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593594 search_text,
3595 options,
initial.commit09911bf2008-07-26 23:55:293596 true); // reset the tickmarks
3597 }
3598
3599 // Iterate to the next frame. The frame will not necessarily scope, for
3600 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273601 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293602 } while (search_frame != main_frame);
3603 }
3604}
3605
[email protected]24a7f3c2010-03-25 08:26:493606void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3607 WebView* view = webview();
3608 if (!view)
3609 return;
3610
3611 WebDocument doc = view->mainFrame()->document();
3612 if (doc.isPluginDocument()) {
3613 GetDelegateForPluginDocument()->StopFind();
3614 return;
3615 }
3616
3617 bool clear_selection =
3618 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3619 if (clear_selection)
3620 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3621
3622 WebFrame* frame = view->mainFrame();
3623 while (frame) {
3624 frame->stopFinding(clear_selection);
3625 frame = frame->traverseNext(false);
3626 }
3627
3628 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3629 WebFrame* focused_frame = view->focusedFrame();
3630 if (focused_frame) {
3631 WebDocument doc = focused_frame->document();
3632 if (!doc.isNull()) {
3633 WebNode node = doc.focusedNode();
3634 if (!node.isNull())
3635 node.simulateClick();
3636 }
3637 }
3638 }
3639}
3640
3641void RenderView::OnFindReplyAck() {
3642 // Check if there is any queued up request waiting to be sent.
3643 if (queued_find_reply_message_.get()) {
3644 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423645 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493646 }
3647}
3648
[email protected]8934a3b2010-02-25 00:34:003649bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353650 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003651 return current_content_settings_.settings[settings_type] !=
3652 CONTENT_SETTING_BLOCK;
3653}
3654
3655void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3656 if (!content_blocked_[settings_type]) {
3657 content_blocked_[settings_type] = true;
3658 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353659 }
[email protected]0de80162010-02-03 04:52:353660}
3661
[email protected]71b0d5d2010-02-15 05:43:073662void RenderView::ClearBlockedContentSettings() {
3663 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3664 content_blocked_[i] = false;
3665}
3666
[email protected]40bd6582009-12-04 23:49:513667void RenderView::OnZoom(PageZoom::Function function) {
3668 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3669 return;
3670
[email protected]258d31122010-05-09 10:59:413671 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523672 // Should we be saving zoom levels for plugins? It's not clear, so for now
3673 // don't.
3674 if (webview()->mainFrame()->document().isPluginDocument()) {
3675 webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument();
3676 int zoom;
3677 if (function == PageZoom::RESET) {
3678 zoom = 0;
3679 } else if (function == PageZoom::ZOOM_OUT) {
3680 zoom = -1;
3681 } else if (function == PageZoom::ZOOM_IN) {
3682 zoom = 1;
3683 } else {
3684 NOTREACHED();
[email protected]754bb3b2010-03-26 20:12:113685 return;
[email protected]b03794d2010-03-26 19:57:523686 }
3687 delegate->Zoom(zoom);
3688 return;
3689 }
3690
[email protected]40bd6582009-12-04 23:49:513691 int zoom_level = webview()->zoomLevel();
3692 int new_zoom_level = webview()->setZoomLevel(false,
3693 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3694
[email protected]9d797f32010-04-23 07:17:543695 // Tell the browser which url got zoomed so it can update the saved values.
3696 Send(new ViewHostMsg_DidZoomURL(
3697 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:513698}
3699
[email protected]9d797f32010-04-23 07:17:543700void RenderView::OnSetContentSettingsForLoadingURL(
3701 const GURL& url,
[email protected]f85f0702010-01-30 09:31:013702 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:543703 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:013704}
3705
[email protected]9d797f32010-04-23 07:17:543706void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
3707 int zoom_level) {
3708 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293709}
3710
[email protected]41fc0322009-09-04 22:23:403711void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273712 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293713}
3714
[email protected]a697f4c2009-09-14 22:30:183715void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273716 WebString no_encoding;
3717 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183718}
3719
[email protected]20ad2692009-11-20 18:27:203720bool RenderView::GetAllChildFrames(
3721 WebFrame* parent_frame,
3722 std::vector<WebFrame*>* frames_vector) const {
3723 if (!parent_frame)
3724 return false;
3725 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3726 child_frame = child_frame->nextSibling()) {
3727 frames_vector->push_back(child_frame);
3728 GetAllChildFrames(child_frame, frames_vector);
3729 }
3730 return true;
3731}
3732
[email protected]dd7daa82009-08-10 05:46:453733WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3734 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273735 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453736
3737 // xpath string can represent a frame deep down the tree (across multiple
3738 // frame DOMs).
3739 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3740 // should break into 2 xpaths
3741 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3742
[email protected]26aa0482009-09-30 16:55:273743 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453744
3745 std::wstring xpath_remaining = xpath;
3746 while (!xpath_remaining.empty()) {
3747 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3748 std::wstring xpath_child;
3749 if (delim_pos != std::wstring::npos) {
3750 xpath_child = xpath_remaining.substr(0, delim_pos);
3751 xpath_remaining.erase(0, delim_pos + 1);
3752 } else {
3753 xpath_remaining.swap(xpath_child);
3754 }
3755 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293756 }
3757
[email protected]dd7daa82009-08-10 05:46:453758 return frame;
initial.commit09911bf2008-07-26 23:55:293759}
3760
[email protected]f29acf52008-11-03 20:08:333761void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3762 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293763 WebFrame* web_frame = GetChildFrame(frame_xpath);
3764 if (!web_frame)
3765 return;
3766
[email protected]dd7daa82009-08-10 05:46:453767 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293768}
3769
[email protected]1810e132009-03-24 23:35:483770void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083771 const std::string& css,
3772 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483773 WebFrame* web_frame = GetChildFrame(frame_xpath);
3774 if (!web_frame)
3775 return;
3776
[email protected]ffaef0c2009-09-15 17:08:083777 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483778}
3779
[email protected]00c39612010-03-06 02:53:283780void RenderView::OnPepperPluginDestroy(
3781 WebPluginDelegatePepper* pepper_plugin) {
3782 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:013783 current_oldstyle_pepper_plugins_.find(pepper_plugin);
3784 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:283785 NOTREACHED();
3786 return;
3787 }
[email protected]53900d52010-06-16 04:25:013788 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473789
3790 // The plugin could have been destroyed while it was waiting for a file
3791 // choose callback, so check all pending completion callbacks and NULL them.
3792 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3793 file_chooser_completions_.begin();
3794 i != file_chooser_completions_.end(); /* nothing */) {
3795 if ((*i)->completion == pepper_plugin) {
3796 // We NULL the first one instead of deleting it because the plugin might
3797 // be the one waiting for a file choose callback. If the callback later
3798 // comes, we don't want to send the result to the next callback in line.
3799 if (i == file_chooser_completions_.begin())
3800 (*i)->completion = NULL;
3801 else
3802 i = file_chooser_completions_.erase(i);
3803 } else {
3804 ++i;
3805 }
3806 }
[email protected]00c39612010-03-06 02:53:283807}
3808
initial.commit09911bf2008-07-26 23:55:293809void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3810 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333811 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293812}
3813
[email protected]1810e132009-03-24 23:35:483814void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083815 const std::string& css,
3816 const std::string& id) {
3817 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413818
3819 // Notify RenderViewHost that css has been inserted into the frame.
3820 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483821}
3822
[email protected]7ea066a2009-04-06 20:21:593823void RenderView::OnAddMessageToConsole(
3824 const string16& frame_xpath,
3825 const string16& message,
3826 const WebConsoleMessage::Level& level) {
3827 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593828 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453829 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293830}
3831
[email protected]81e63782009-02-27 19:35:093832void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3833 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293834}
3835
3836void RenderView::OnSetDOMUIProperty(const std::string& name,
3837 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093838 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293839 dom_ui_bindings_.SetProperty(name, value);
3840}
3841
3842void RenderView::OnReservePageIDRange(int size_of_range) {
3843 next_page_id_ += size_of_range + 1;
3844}
3845
[email protected]e80c73b2009-04-07 23:24:583846void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3847 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253848 bool ended,
3849 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033850 if (ended) {
[email protected]26aa0482009-09-30 16:55:273851 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203852 } else {
3853 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033854 }
initial.commit09911bf2008-07-26 23:55:293855}
3856
3857void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273858 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293859}
3860
initial.commit09911bf2008-07-26 23:55:293861void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103862 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
initial.commit09911bf2008-07-26 23:55:293863 webkit_glue::FillPasswordForm(this->webview(), form_data);
3864}
3865
3866void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583867 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253868 const gfx::Point& screen_point,
3869 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273870 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583871 drop_data.ToDragData(),
3872 drop_data.identity,
3873 client_point,
[email protected]1d9f4132009-09-08 17:29:253874 screen_point,
3875 ops);
initial.commit09911bf2008-07-26 23:55:293876
[email protected]1d9f4132009-09-08 17:29:253877 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293878}
3879
[email protected]e80c73b2009-04-07 23:24:583880void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253881 const gfx::Point& screen_point,
3882 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273883 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253884 client_point,
3885 screen_point,
3886 ops);
initial.commit09911bf2008-07-26 23:55:293887
[email protected]1d9f4132009-09-08 17:29:253888 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293889}
3890
3891void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273892 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293893}
3894
[email protected]e80c73b2009-04-07 23:24:583895void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3896 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273897 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293898}
3899
3900void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593901 webkit_preferences_ = prefs;
3902 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293903}
3904
3905void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3906 alternate_error_page_url_ = url;
3907}
3908
[email protected]a0c7153e2009-12-09 14:36:333909void RenderView::OnCustomContextMenuAction(unsigned action) {
3910 webview()->performCustomContextMenuAction(action);
3911}
3912
[email protected]d4a00a72010-01-29 01:44:423913void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:023914 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:423915 const std::string& source_lang,
3916 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:023917 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
3918 translate_script);
[email protected]d4a00a72010-01-29 01:44:423919}
3920
[email protected]85d252e2010-04-06 22:21:023921void RenderView::OnRevertTranslation(int page_id) {
3922 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:323923}
3924
initial.commit09911bf2008-07-26 23:55:293925void RenderView::OnInstallMissingPlugin() {
3926 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593927 if (first_default_plugin_)
3928 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293929}
3930
[email protected]cdaf8d02010-03-30 19:52:473931void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363932 // This could happen if we navigated to a different page before the user
3933 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473934 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363935 return;
3936
[email protected]cdaf8d02010-03-30 19:52:473937 WebVector<WebString> ws_file_names(paths.size());
3938 for (size_t i = 0; i < paths.size(); ++i)
3939 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463940
[email protected]cdaf8d02010-03-30 19:52:473941 if (file_chooser_completions_.front()->completion)
3942 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3943 file_chooser_completions_.pop_front();
3944
3945 // If there are more pending file chooser requests, schedule one now.
3946 if (!file_chooser_completions_.empty()) {
3947 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3948 file_chooser_completions_.front()->params));
3949 }
initial.commit09911bf2008-07-26 23:55:293950}
3951
3952void RenderView::OnEnableViewSourceMode() {
3953 if (!webview())
3954 return;
[email protected]26aa0482009-09-30 16:55:273955 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:293956 if (!main_frame)
3957 return;
3958
[email protected]dd7daa82009-08-10 05:46:453959 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:293960}
3961
[email protected]770dd8b2010-05-24 18:11:393962void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3963 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243964 if (send_preferred_size_changes_)
3965 return;
[email protected]9fb325e2010-05-06 18:23:243966 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393967
3968 // WebKit doesn't send a notification of the effective height of the page
3969 // changes, so poll for it.
3970 // TODO: Add a notification for this to WebKit, remove polling. After that's
3971 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
3972 // http://crbug.com/44850
3973 if (flags & kPreferredSizeHeightThisIsSlow) {
3974 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3975 &RenderView::CheckPreferredSize);
3976 }
[email protected]0666aef2009-05-13 19:48:083977}
3978
[email protected]cda45c02010-02-25 19:28:103979void RenderView::OnDisableScrollbarsForSmallWindows(
3980 const gfx::Size& disable_scrollbar_size_limit) {
3981 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3982}
3983
[email protected]80d96fa2009-06-10 22:34:513984void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3985 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373986 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:033987#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:413988 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3989 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463990 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:323991
[email protected]644d77e2010-01-27 01:03:103992 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323993 webview()->setScrollbarColors(
3994 renderer_prefs.thumb_inactive_color,
3995 renderer_prefs.thumb_active_color,
3996 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103997 webview()->setSelectionColors(
3998 renderer_prefs.active_selection_bg_color,
3999 renderer_prefs.active_selection_fg_color,
4000 renderer_prefs.inactive_selection_bg_color,
4001 renderer_prefs.inactive_selection_fg_color);
[email protected]61c64402010-05-25 22:05:014002 didInvalidateRect(gfx::Rect(size_));
[email protected]644d77e2010-01-27 01:03:104003 }
[email protected]7a74e102009-09-03 00:16:564004#endif
[email protected]80d96fa2009-06-10 22:34:514005}
4006
[email protected]952cb702009-10-07 05:50:284007void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4008 const WebMediaPlayerAction& action) {
4009 if (webview())
4010 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564011}
4012
[email protected]7b291f92009-08-14 05:43:534013void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:514014 // When this is first set, the bindings aren't fully loaded. We only need
4015 // to call through this API after the page has already been loaded. It's
4016 // also called in didCreateDocumentElement to bootstrap.
4017 if (view_type_ != ViewType::INVALID) {
4018 if (type == ViewType::EXTENSION_MOLE ||
4019 type == ViewType::EXTENSION_TOOLSTRIP) {
4020 ExtensionProcessBindings::SetViewType(webview(), type);
4021 }
4022 }
[email protected]7b291f92009-08-14 05:43:534023 view_type_ = type;
4024}
4025
4026void RenderView::OnUpdateBrowserWindowId(int window_id) {
4027 browser_window_id_ = window_id;
4028}
4029
[email protected]b3df5a42010-05-11 14:31:094030void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:364031 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:414032 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:114033 accessibility_.reset(WebAccessibilityCache::create());
4034 accessibility_->initialize(webview());
[email protected]9f4db512010-05-10 20:21:414035
[email protected]b3df5a42010-05-11 14:31:094036 WebAccessibilityObject src_tree = webview()->accessibilityObject();
4037 webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get());
4038 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:504039}
4040
[email protected]aef92842010-05-21 16:54:364041void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4042 if (!accessibility_.get())
4043 return;
4044 if (accessibility_->isValidId(acc_obj_id)) {
4045 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
4046 // By convention, calling SetFocus on the root of the tree (id = 1000)
4047 // should clear the current focus. Otherwise set the focus to the new
4048 // node.
4049 if (acc_obj_id == 1000)
4050 webview()->clearFocusedNode();
4051 else
4052 accessibility_->getObjectById(acc_obj_id).setFocused(true);
4053 }
4054}
4055
4056void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4057 if (!accessibility_.get())
4058 return;
4059 if (accessibility_->isValidId(acc_obj_id)) {
4060 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
4061 }
4062}
4063
initial.commit09911bf2008-07-26 23:55:294064void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4065 const GURL& page_url) {
4066 // Prepare list to storage all savable resource links.
4067 std::vector<GURL> resources_list;
4068 std::vector<GURL> referrers_list;
4069 std::vector<GURL> frames_list;
4070 webkit_glue::SavableResourcesResult result(&resources_list,
4071 &referrers_list,
4072 &frames_list);
4073
[email protected]dbeb3952009-10-13 18:01:184074 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4075 webview(),
4076 page_url,
4077 &result,
4078 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294079 // If something is wrong when collecting all savable resource links,
4080 // send empty list to embedder(browser) to tell it failed.
4081 referrers_list.clear();
4082 resources_list.clear();
4083 frames_list.clear();
4084 }
4085
4086 // Send result of all savable resource links to embedder.
4087 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4088 resources_list,
4089 referrers_list,
4090 frames_list));
4091}
4092
4093void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324094 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314095 const std::vector<FilePath>& local_paths,
4096 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074097
4098 // Convert std::vector of GURLs to WebVector<WebURL>
4099 WebVector<WebURL> weburl_links(links);
4100
4101 // Convert std::vector of std::strings to WebVector<WebString>
4102 WebVector<WebString> webstring_paths(local_paths.size());
4103 for (size_t i = 0; i < local_paths.size(); i++)
4104 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4105
4106 WebPageSerializer::serialize(webview()->mainFrame(),
4107 true, this, weburl_links, webstring_paths,
4108 webkit_glue::FilePathToWebString(
4109 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294110}
4111
[email protected]d9ec5c0f2009-12-23 11:55:074112void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4113 const WebCString& data,
4114 WebPageSerializerClient::PageSerializationStatus status) {
4115 Send(new ViewHostMsg_SendSerializedHtmlData(
4116 routing_id_,
4117 frame_url,
4118 data.data(),
4119 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294120}
4121
[email protected]9b18a84f2010-06-10 15:54:044122void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274123 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474124 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294125}
4126
[email protected]eb6b87a2009-07-24 15:57:394127void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294128 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4129 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4130 // in the onunload handler from appearing. For now, we're bypassing that and
4131 // calling the FrameLoader's CloseURL method directly. This should be
4132 // revisited to avoid having two ways to close a page. Having a single way
4133 // to close that can run onunload is also useful for fixing
4134 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274135 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294136 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454137 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174138 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294139 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4140 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454141 if (url.SchemeIs(chrome::kHttpScheme) ||
4142 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294143 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294144 }
[email protected]26aa0482009-09-30 16:55:274145 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294146
[email protected]ab9eabac2010-03-16 16:54:104147 // Reset stats
4148 cross_origin_access_count_ = 0;
4149 same_origin_access_count_ = 0;
4150
[email protected]eb6b87a2009-07-24 15:57:394151 // Just echo back the params in the ACK.
4152 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294153}
4154
4155void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574156#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294157 gfx::NativeTheme::instance()->CloseHandles();
[email protected]61c64402010-05-25 22:05:014158 didInvalidateRect(gfx::Rect(size_));
[email protected]6c8afae52009-01-22 02:24:574159#else // defined(OS_WIN)
4160 // TODO(port): we don't support theming on non-Windows platforms yet
4161 NOTIMPLEMENTED();
4162#endif
initial.commit09911bf2008-07-26 23:55:294163}
4164
[email protected]9b18a84f2010-06-10 15:54:044165void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4166 const std::string& origin,
4167 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154168 if (message.empty())
4169 return;
[email protected]28790922009-03-09 19:48:374170 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4171 target);
[email protected]3ac14a052008-08-15 21:22:154172}
4173
[email protected]0aa55312008-10-17 21:53:084174void RenderView::OnDisassociateFromPopupCount() {
4175 if (decrement_shared_popup_at_destruction_)
4176 shared_popup_counter_->data--;
4177 shared_popup_counter_ = new SharedRenderViewCounter(0);
4178 decrement_shared_popup_at_destruction_ = false;
4179}
4180
[email protected]15d79e12009-08-02 19:23:454181bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4182 const WebURLError& error,
4183 bool replace) {
4184 // We only show alternate error pages in the main frame. They are
4185 // intended to assist the user when navigating, so there is not much
4186 // value in showing them for failed subframes. Ideally, we would be
4187 // able to use the TYPED transition type for this, but that flag is
4188 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454189 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454190 return false;
4191
4192 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374193 // connection failure.
[email protected]15d79e12009-08-02 19:23:454194 int ec = error.reason;
4195 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4196 ec != net::ERR_CONNECTION_FAILED &&
4197 ec != net::ERR_CONNECTION_REFUSED &&
4198 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374199 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454200 return false;
4201
4202 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554203 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454204 if (!error_page_url.is_valid())
4205 return false;
4206
4207 // Load an empty page first so there is an immediate response to the error,
4208 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454209 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454210 GURL(kUnreachableWebDataURL),
4211 error.unreachableURL,
4212 replace);
4213
4214 // Now, create a fetcher for the error page and associate it with the data
4215 // source we just created via the LoadHTMLString call. That way if another
4216 // navigation occurs, the fetcher will get destroyed.
4217 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454218 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454219 navigation_state->set_alt_error_page_fetcher(
4220 new AltErrorPageResourceFetcher(
4221 error_page_url, frame, error,
4222 NewCallback(this, &RenderView::AltErrorPageFinished)));
4223 return true;
4224}
4225
initial.commit09911bf2008-07-26 23:55:294226std::string RenderView::GetAltHTMLForTemplate(
4227 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394228 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294229 ResourceBundle::GetSharedInstance().GetRawDataResource(
4230 template_resource_id));
4231
4232 if (template_html.empty()) {
4233 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4234 return "";
4235 }
[email protected]7cd22a52009-07-14 00:40:254236
initial.commit09911bf2008-07-26 23:55:294237 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254238 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294239 template_html, &error_strings, "t");
4240}
[email protected]0e79b9e2009-02-13 04:20:484241
[email protected]15d79e12009-08-02 19:23:454242void RenderView::AltErrorPageFinished(WebFrame* frame,
4243 const WebURLError& original_error,
4244 const std::string& html) {
4245 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554246
4247 // If we failed to download the alternate error page, fall back to the
4248 // original error page if present. Otherwise, LoadNavigationErrorPage
4249 // will simply display a default error page.
4250 const std::string* html_to_load = &html;
4251 if (html.empty()) {
4252 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454253 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554254 html_to_load = &navigation_state->postponed_data();
4255 }
4256 LoadNavigationErrorPage(
4257 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454258}
4259
[email protected]30f75e62009-02-25 22:01:004260void RenderView::OnMoveOrResizeStarted() {
4261 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474262 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004263}
4264
[email protected]30f75e62009-02-25 22:01:004265void RenderView::OnResize(const gfx::Size& new_size,
4266 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104267 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474268 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104269
4270 if (send_preferred_size_changes_) {
4271 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4272 // either width or height, allow scroll bars.
4273 bool allow_scrollbars = (
4274 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244275 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104276 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4277 }
4278 }
4279
[email protected]30f75e62009-02-25 22:01:004280 RenderWidget::OnResize(new_size, resizer_rect);
4281}
[email protected]0aa477bd2009-03-23 22:21:434282
[email protected]00c39612010-03-06 02:53:284283void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014284 // Notify the pepper plugins that we started painting.
4285 pepper_delegate_.ViewInitiatedPaint();
4286
4287 // Notify any "old-style" pepper plugins that we started painting. This is
4288 // used for internal bookkeeping only, so we know that the set can not change
4289 // under us.
[email protected]00c39612010-03-06 02:53:284290 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:014291 current_oldstyle_pepper_plugins_.begin();
4292 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:284293 (*i)->RenderViewInitiatedPaint();
4294}
4295
4296void RenderView::DidFlushPaint() {
4297 // Notify any pepper plugins that we painted. This will call into the plugin,
4298 // and we it may ask to close itself as a result. This will, in turn, modify
4299 // our set, possibly invalidating the iterator. So we iterate on a copy that
4300 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014301 pepper_delegate_.ViewFlushedPaint();
4302
4303 // Notify any old-style pepper plugins that we painted. This will call into
4304 // the plugin, and we it may ask to close itself as a result. This will, in
4305 // turn, modify our set, possibly invalidating the iterator. So we iterate on
4306 // a copy that won't change out from under us.
4307 // This should be deleted when we don't support old Pepper anymore.
4308 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:284309 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4310 i != plugins.end(); ++i) {
4311 // The copy above makes sure our iterator is never invalid if some plugins
4312 // are destroyed. But some plugin may decide to close all of its views in
4313 // response to a paint in one of them, so we need to make sure each one is
4314 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:014315 if (current_oldstyle_pepper_plugins_.find(*i) !=
4316 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:284317 (*i)->RenderViewFlushedPaint();
4318 }
4319
4320 WebFrame* main_frame = webview()->mainFrame();
4321
4322 // If we have a provisional frame we are between the start and commit stages
4323 // of loading and we don't want to save stats.
4324 if (!main_frame->provisionalDataSource()) {
4325 WebDataSource* ds = main_frame->dataSource();
4326 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4327 DCHECK(navigation_state);
4328
4329 Time now = Time::Now();
4330 if (navigation_state->first_paint_time().is_null()) {
4331 navigation_state->set_first_paint_time(now);
4332 }
4333 if (navigation_state->first_paint_after_load_time().is_null() &&
4334 !navigation_state->finish_load_time().is_null()) {
4335 navigation_state->set_first_paint_after_load_time(now);
4336 }
4337 }
4338}
4339
[email protected]05d478752009-04-08 23:38:164340void RenderView::OnClearFocusedNode() {
4341 if (webview())
[email protected]26aa0482009-09-30 16:55:274342 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164343}
4344
[email protected]699ab0d2009-04-23 23:19:144345void RenderView::OnSetBackground(const SkBitmap& background) {
4346 if (webview())
[email protected]b4bb2502009-10-01 22:35:274347 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144348
4349 SetBackground(background);
4350}
4351
[email protected]8c66c5a2009-07-22 17:26:344352void RenderView::OnSetActive(bool active) {
4353 if (webview())
[email protected]b4bb2502009-10-01 22:35:274354 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264355
4356#if defined(OS_MACOSX)
4357 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4358 for (plugin_it = plugin_delegates_.begin();
4359 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4360 (*plugin_it)->SetWindowFocus(active);
4361 }
4362#endif
[email protected]8c66c5a2009-07-22 17:26:344363}
4364
[email protected]6ce7abc52010-02-02 18:40:144365#if defined(OS_MACOSX)
4366void RenderView::OnSetWindowVisibility(bool visible) {
4367 // Inform plugins that their container has changed visibility.
4368 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4369 for (plugin_it = plugin_delegates_.begin();
4370 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4371 (*plugin_it)->SetContainerVisibility(visible);
4372 }
4373}
[email protected]1e6e3c992010-02-08 15:52:134374
4375void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4376 gfx::Rect view_frame) {
4377 // Inform plugins that their window's frame has changed.
4378 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4379 for (plugin_it = plugin_delegates_.begin();
4380 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4381 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4382 }
4383}
[email protected]6ce7abc52010-02-02 18:40:144384#endif // OS_MACOSX
4385
[email protected]309d7a282009-03-24 09:18:274386void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584387 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394388 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324389 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474390 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394391 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4392 name,
4393 args,
4394 source_url,
4395 request_id,
[email protected]2f25d7b92009-06-10 00:06:474396 has_callback));
[email protected]309d7a282009-03-24 09:18:274397}
4398
[email protected]c6619182009-05-12 14:59:324399void RenderView::OnExtensionResponse(int request_id,
4400 bool success,
4401 const std::string& response,
4402 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354403 ExtensionProcessBindings::HandleResponse(
4404 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274405}
[email protected]c20210e62009-04-03 21:39:264406
[email protected]078b34612009-09-19 19:31:514407void RenderView::InjectToolstripCSS() {
4408 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4409 return;
4410
4411 static const base::StringPiece toolstrip_css(
4412 ResourceBundle::GetSharedInstance().GetRawDataResource(
4413 IDR_EXTENSION_TOOLSTRIP_CSS));
4414 std::string css = toolstrip_css.as_string();
4415 InsertCSS(L"", css, "ToolstripDefaultCSS");
4416}
4417
[email protected]7120f132009-07-20 21:05:374418void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494419 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194420 bool requires_incognito_access,
4421 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494422 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194423 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374424}
4425
[email protected]e7e4f3c2009-04-21 15:24:084426// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264427//
[email protected]c20210e62009-04-03 21:39:264428// The time points we keep are
4429// request: time document was requested by user
4430// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254431// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294432// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264433// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294434// first_paint: first paint performed
4435// first_paint_after_load: first paint performed after load is finished
4436// begin: request if it was user requested, start otherwise
4437//
[email protected]e7e4f3c2009-04-21 15:24:084438// It's possible for the request time not to be set, if a client
4439// redirect had been done (the user never requested the page)
4440// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294441// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264442void RenderView::DumpLoadHistograms() const {
[email protected]cf9a7bc2010-06-11 18:54:504443 // Configuration for PLT related histograms.
4444 static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10));
4445 static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10));
4446 static const size_t kPLTCount(100);
4447 #define PLT_HISTOGRAM(name, sample) \
4448 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount);
4449
[email protected]26aa0482009-09-30 16:55:274450 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564451 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454452 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564453
[email protected]f9f4841b2010-03-20 05:41:424454 // If we've already dumped, do nothing.
4455 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294456 return;
[email protected]cf9a7bc2010-06-11 18:54:504457
4458 // Collect measurement times.
[email protected]b855ebe62010-05-12 23:01:454459 Time start = navigation_state->start_load_time();
4460 if (start.is_null())
4461 return; // Probably very premature abandonment of page.
4462 Time commit = navigation_state->commit_load_time();
4463 if (commit.is_null())
4464 return; // Probably very premature abandonment of page.
[email protected]cf9a7bc2010-06-11 18:54:504465
[email protected]b855ebe62010-05-12 23:01:454466 // We properly handle null values for the next 3 variables.
4467 Time request = navigation_state->request_time();
4468 Time first_paint = navigation_state->first_paint_time();
4469 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
[email protected]b855ebe62010-05-12 23:01:454470 Time finish = navigation_state->finish_load_time();
4471 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]ed3fb032009-06-16 19:50:564472
[email protected]f9f4841b2010-03-20 05:41:424473 // Handle case where user hits "stop" or "back" before loading completely.
4474 bool abandoned_page = finish.is_null();
4475 if (abandoned_page) {
4476 finish = Time::Now();
4477 navigation_state->set_finish_load_time(finish);
4478 }
[email protected]f9f4841b2010-03-20 05:41:424479
[email protected]cf9a7bc2010-06-11 18:54:504480 if (finish_doc.is_null()) {
4481 DCHECK(abandoned_page); // how can the doc have finished but not the page?
4482 if (!abandoned_page)
4483 return; // Don't try to record a stat which is broken.
4484 finish_doc = finish;
4485 navigation_state->set_finish_document_load_time(finish_doc);
4486 }
4487
4488 // Note: Client side redirects will have no request time.
4489 Time begin = request.is_null() ? start : request;
4490 TimeDelta begin_to_finish_doc = finish_doc - begin;
4491 TimeDelta begin_to_finish = finish - begin;
4492 TimeDelta start_to_finish = finish - start;
[email protected]ef1d8d322010-06-13 18:31:254493 TimeDelta start_to_commit = commit - start;
[email protected]f8999642009-10-27 21:39:424494
[email protected]a7ccc4d2010-01-27 08:14:484495 NavigationState::LoadType load_type = navigation_state->load_type();
[email protected]cf9a7bc2010-06-11 18:54:504496
4497 // Aggregate PLT data across all link types.
4498 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2);
4499 UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type,
4500 NavigationState::kLoadTypeMax);
[email protected]ef1d8d322010-06-13 18:31:254501 PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504502 PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit);
4503 PLT_HISTOGRAM("PLT.FinishDocToFinish", finish - finish_doc);
4504 PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin);
4505 PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish);
4506 if (!request.is_null()) {
4507 PLT_HISTOGRAM("PLT.RequestToStart", start - request);
4508 PLT_HISTOGRAM("PLT.RequestToFinish", finish - request);
4509 }
4510 PLT_HISTOGRAM("PLT.CommitToFinish", finish - commit);
4511 if (!first_paint.is_null()) {
4512 DCHECK(begin <= first_paint);
4513 PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin);
4514 DCHECK(commit <= first_paint);
4515 PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit);
4516 }
4517 if (!first_paint_after_load.is_null()) {
4518 DCHECK(begin <= first_paint_after_load);
4519 PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad",
4520 first_paint_after_load - begin);
4521 DCHECK(commit <= first_paint_after_load);
4522 PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad",
4523 first_paint_after_load - commit);
4524 DCHECK(finish <= first_paint_after_load);
4525 PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad",
4526 first_paint_after_load - finish);
4527 }
4528 PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc);
4529 PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish);
4530
4531 // Load type related histograms.
4532 switch (load_type) {
4533 case NavigationState::UNDEFINED_LOAD:
4534 PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc);
4535 PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish);
4536 break;
4537 case NavigationState::RELOAD:
4538 PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc);
4539 PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish);
4540 break;
4541 case NavigationState::HISTORY_LOAD:
4542 PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc);
4543 PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish);
4544 break;
4545 case NavigationState::NORMAL_LOAD:
4546 PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc);
4547 PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish);
4548 break;
4549 case NavigationState::LINK_LOAD_NORMAL:
4550 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal",
4551 begin_to_finish_doc);
4552 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal", begin_to_finish);
4553 break;
4554 case NavigationState::LINK_LOAD_RELOAD:
4555 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload",
4556 begin_to_finish_doc);
4557 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload", begin_to_finish);
4558 break;
4559 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4560 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk",
4561 begin_to_finish_doc);
4562 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk", begin_to_finish);
4563 break;
4564 case NavigationState::LINK_LOAD_CACHE_ONLY:
4565 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly",
4566 begin_to_finish_doc);
4567 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly", begin_to_finish);
4568 break;
4569 default:
4570 break;
4571 }
4572
4573 // Histograms to determine if DNS prefetching has an impact on PLT.
4574 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4575 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4576 if (use_dns_histogram) {
4577 UMA_HISTOGRAM_ENUMERATION(
4578 FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"),
4579 abandoned_page ? 1 : 0, 2);
4580 UMA_HISTOGRAM_ENUMERATION(
4581 FieldTrial::MakeName("PLT.LoadType", "DnsImpact"),
4582 load_type, NavigationState::kLoadTypeMax);
4583 switch (load_type) {
4584 case NavigationState::NORMAL_LOAD:
4585 PLT_HISTOGRAM(FieldTrial::MakeName(
4586 "PLT.BeginToFinish_NormalLoad", "DnsImpact"), begin_to_finish);
4587 break;
4588 case NavigationState::LINK_LOAD_NORMAL:
4589 PLT_HISTOGRAM(FieldTrial::MakeName(
4590 "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4591 begin_to_finish);
4592 break;
4593 case NavigationState::LINK_LOAD_RELOAD:
4594 PLT_HISTOGRAM(FieldTrial::MakeName(
4595 "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"),
4596 begin_to_finish);
4597 break;
4598 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4599 PLT_HISTOGRAM(FieldTrial::MakeName(
4600 "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4601 begin_to_finish);
4602 break;
4603 default:
4604 break;
4605 }
4606 }
4607
4608 // Histograms to determine if the number of connections has an
4609 // impact on PLT.
4610 // TODO(jar): Consider removing the per-link-type versions. We
4611 // really only need LINK_LOAD_NORMAL and NORMAL_LOAD.
4612 static bool use_conn_impact_histogram(
4613 FieldTrialList::Find("ConnCountImpact") &&
4614 !FieldTrialList::Find("ConnCountImpact")->group_name().empty());
4615 if (use_conn_impact_histogram) {
4616 UMA_HISTOGRAM_ENUMERATION(
4617 FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"),
4618 abandoned_page ? 1 : 0, 2);
4619 switch (load_type) {
4620 case NavigationState::NORMAL_LOAD:
4621 PLT_HISTOGRAM(FieldTrial::MakeName(
4622 "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"),
4623 begin_to_finish);
4624 break;
4625 case NavigationState::LINK_LOAD_NORMAL:
4626 PLT_HISTOGRAM(FieldTrial::MakeName(
4627 "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"),
4628 begin_to_finish);
4629 break;
4630 case NavigationState::LINK_LOAD_RELOAD:
4631 PLT_HISTOGRAM(FieldTrial::MakeName(
4632 "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"),
4633 begin_to_finish);
4634 break;
4635 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4636 PLT_HISTOGRAM(FieldTrial::MakeName(
4637 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"),
4638 begin_to_finish);
4639 break;
4640 default:
4641 break;
4642 }
4643 }
4644
[email protected]241c5c2c2010-06-21 18:46:004645
4646 static bool use_idle_socket_timeout_histogram(
4647 FieldTrialList::Find("IdleSktToImpact") &&
4648 !FieldTrialList::Find("IdleSktToImpact")->group_name().empty());
4649 if (use_idle_socket_timeout_histogram) {
4650 UMA_HISTOGRAM_ENUMERATION(
4651 FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"),
4652 abandoned_page ? 1 : 0, 2);
4653 switch (load_type) {
4654 case NavigationState::NORMAL_LOAD:
4655 PLT_HISTOGRAM(FieldTrial::MakeName(
4656 "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"),
4657 begin_to_finish);
4658 break;
4659 case NavigationState::LINK_LOAD_NORMAL:
4660 PLT_HISTOGRAM(FieldTrial::MakeName(
4661 "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"),
4662 begin_to_finish);
4663 break;
4664 case NavigationState::LINK_LOAD_RELOAD:
4665 PLT_HISTOGRAM(FieldTrial::MakeName(
4666 "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"),
4667 begin_to_finish);
4668 break;
4669 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4670 PLT_HISTOGRAM(FieldTrial::MakeName(
4671 "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"),
4672 begin_to_finish);
4673 break;
4674 default:
4675 break;
4676 }
4677 }
4678
[email protected]cf9a7bc2010-06-11 18:54:504679 // Histograms to determine if SDCH has an impact.
4680 // TODO(jar): Consider removing per-link load types and the enumeration.
4681 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4682 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4683 if (use_sdch_histogram) {
4684 UMA_HISTOGRAM_ENUMERATION(
4685 FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"),
4686 load_type, NavigationState::kLoadTypeMax);
4687 switch (load_type) {
4688 case NavigationState::NORMAL_LOAD:
4689 PLT_HISTOGRAM(FieldTrial::MakeName(
4690 "PLT.BeginToFinish_NormalLoad", "GlobalSdch"),
4691 begin_to_finish);
4692 break;
4693 case NavigationState::LINK_LOAD_NORMAL:
4694 PLT_HISTOGRAM(FieldTrial::MakeName(
4695 "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4696 begin_to_finish);
4697 break;
4698 case NavigationState::LINK_LOAD_RELOAD:
4699 PLT_HISTOGRAM(FieldTrial::MakeName(
4700 "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4701 begin_to_finish);
4702 break;
4703 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4704 PLT_HISTOGRAM(FieldTrial::MakeName(
4705 "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4706 begin_to_finish);
4707 break;
4708 case NavigationState::LINK_LOAD_CACHE_ONLY:
4709 PLT_HISTOGRAM(FieldTrial::MakeName(
4710 "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4711 begin_to_finish);
4712 break;
4713 default:
4714 break;
4715 }
4716 }
4717
4718 // Histograms to determine if cache size has an impact on PLT.
4719 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4720 !FieldTrialList::Find("CacheSize")->group_name().empty());
4721 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4722 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
4723 // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like
4724 // StartToFinish or BeginToFinish would be better.
4725 PLT_HISTOGRAM(FieldTrial::MakeName(
4726 "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc);
4727 }
4728
4729 // Histograms to determine if SPDY has an impact.
4730 // TODO(mbelshe): After we've seen the difference between BeginToFinish
4731 // and StartToFinish, consider removing one or the other.
4732 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
4733 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
[email protected]193b0b892010-06-26 03:57:574734 // Spdy requests triggered by alternate protocol are excluded here.
4735 // This is because when alternate protocol is avaiable, FieldTrial will
4736 // either use npn_spdy or pure http, not npn_http via TLS. That will cause
4737 // bias for npn_spdy and npn_http.
4738 if (use_spdy_histogram && navigation_state->was_npn_negotiated() &&
4739 !navigation_state->was_alternate_protocol_available()) {
[email protected]30b35882010-06-14 21:21:014740 UMA_HISTOGRAM_ENUMERATION(
4741 FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"),
4742 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:504743 switch (load_type) {
4744 case NavigationState::LINK_LOAD_NORMAL:
4745 PLT_HISTOGRAM(FieldTrial::MakeName(
4746 "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4747 begin_to_finish);
4748 PLT_HISTOGRAM(FieldTrial::MakeName(
4749 "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4750 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:254751 PLT_HISTOGRAM(FieldTrial::MakeName(
4752 "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4753 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504754 break;
4755 case NavigationState::NORMAL_LOAD:
4756 PLT_HISTOGRAM(FieldTrial::MakeName(
4757 "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
4758 begin_to_finish);
4759 PLT_HISTOGRAM(FieldTrial::MakeName(
4760 "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
4761 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:254762 PLT_HISTOGRAM(FieldTrial::MakeName(
4763 "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"),
4764 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504765 break;
4766 default:
4767 break;
4768 }
4769 }
4770
[email protected]193b0b892010-06-26 03:57:574771 // Histograms to compare the impact of alternate protocol: when the
4772 // protocol(spdy) is used vs. when it is ignored and http is used.
4773 if (navigation_state->was_alternate_protocol_available()) {
4774 if (!navigation_state->was_npn_negotiated()) {
4775 // This means that even there is alternate protocols for npn_http or
4776 // npn_spdy, they are not taken (due to the fieldtrial).
4777 switch (load_type) {
4778 case NavigationState::LINK_LOAD_NORMAL:
4779 PLT_HISTOGRAM(
4780 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http",
4781 start_to_finish);
4782 PLT_HISTOGRAM(
4783 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http",
4784 start_to_commit);
4785 break;
4786 case NavigationState::NORMAL_LOAD:
4787 PLT_HISTOGRAM(
4788 "PLT.StartToFinish_NormalLoad_AlternateProtocol_http",
4789 start_to_finish);
4790 PLT_HISTOGRAM(
4791 "PLT.StartToCommit_NormalLoad_AlternateProtocol_http",
4792 start_to_commit);
4793 break;
4794 default:
4795 break;
4796 }
4797 } else if (navigation_state->was_fetched_via_spdy()) {
4798 switch (load_type) {
4799 case NavigationState::LINK_LOAD_NORMAL:
4800 PLT_HISTOGRAM(
4801 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy",
4802 start_to_finish);
4803 PLT_HISTOGRAM(
4804 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy",
4805 start_to_commit);
4806 break;
4807 case NavigationState::NORMAL_LOAD:
4808 PLT_HISTOGRAM(
4809 "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy",
4810 start_to_finish);
4811 PLT_HISTOGRAM(
4812 "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy",
4813 start_to_commit);
4814 break;
4815 default:
4816 break;
4817 }
4818 }
4819 }
4820
[email protected]cf9a7bc2010-06-11 18:54:504821 // Record page load time and abandonment rates for proxy cases.
4822 GURL url = GURL(main_frame->url());
4823 if (navigation_state->was_fetched_via_proxy()) {
4824 if (url.SchemeIs("https")) {
4825 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish);
4826 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https",
4827 abandoned_page ? 1 : 0, 2);
4828 } else {
4829 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish);
4830 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http",
4831 abandoned_page ? 1 : 0, 2);
4832 }
4833 } else {
4834 if (url.SchemeIs("https")) {
4835 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https", start_to_finish);
4836 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https",
4837 abandoned_page ? 1 : 0, 2);
4838 } else {
4839 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http", start_to_finish);
4840 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http",
4841 abandoned_page ? 1 : 0, 2);
4842 }
4843 }
[email protected]a7ccc4d2010-01-27 08:14:484844
[email protected]ab9eabac2010-03-16 16:54:104845 // Site isolation metrics.
4846 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4847 cross_origin_access_count_);
4848 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4849 same_origin_access_count_);
4850
[email protected]cf9a7bc2010-06-11 18:54:504851 // Log some PLT data to the error log.
4852 LogNavigationState(navigation_state, main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294853
4854 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414855
4856 // Since there are currently no guarantees that renderer histograms will be
4857 // sent to the browser, we initiate a PostTask here to be sure that we send
4858 // the histograms we generated. Without this call, pages that don't have an
4859 // on-close-handler might generate data that is lost when the renderer is
4860 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484861 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4862 // should post when the onload is complete, so that it doesn't interfere with
4863 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414864 if (RenderThread::current()) {
4865 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134866 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414867 }
[email protected]c20210e62009-04-03 21:39:264868}
[email protected]e846d0d2009-05-20 00:53:064869
[email protected]f8999642009-10-27 21:39:424870void RenderView::LogNavigationState(const NavigationState* state,
4871 const WebDataSource* ds) const {
4872 // Because this function gets called on every page load,
4873 // take extra care to optimize it away if logging is turned off.
4874 if (logging::LOG_INFO < logging::GetMinLogLevel())
4875 return;
4876
4877 DCHECK(state);
4878 DCHECK(ds);
4879 GURL url(ds->request().url());
4880 Time start = state->start_load_time();
4881 Time finish = state->finish_load_time();
4882 // TODO(mbelshe): should we log more stats?
4883 LOG(INFO) << "PLT: "
4884 << (finish - start).InMilliseconds()
4885 << "ms "
4886 << url.spec();
4887}
4888
[email protected]cc0445f2009-10-13 16:09:084889void RenderView::focusAccessibilityObject(
4890 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064891#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154892 // TODO(dglazkov): Current logic implies that focus change can only be made
4893 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4894 // where accessibility is initialized. We should determine whether that's
4895 // right.
4896 if (!accessibility_.get())
4897 return;
[email protected]e846d0d2009-05-20 00:53:064898
4899 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154900 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064901
4902 // If id is valid, alert the browser side that an accessibility focus change
4903 // occurred.
4904 if (acc_obj_id >= 0)
4905 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4906
4907#else // defined(OS_WIN)
4908 // TODO(port): accessibility not yet implemented
4909 NOTIMPLEMENTED();
4910#endif
4911}
[email protected]daa8c58e2009-06-15 17:21:104912
[email protected]e9e07992010-02-17 21:04:364913void RenderView::SendForms(WebFrame* frame) {
[email protected]b715f7f2010-04-05 22:01:044914 // TODO(jhawkins): Use FormManager once we have strict ordering of form
4915 // control elements in the cache.
4916 WebVector<WebFormElement> web_forms;
4917 frame->forms(web_forms);
4918
[email protected]b1438212010-04-03 00:30:594919 std::vector<FormData> forms;
[email protected]b715f7f2010-04-05 22:01:044920 for (size_t i = 0; i < web_forms.size(); ++i) {
4921 const WebFormElement& web_form = web_forms[i];
4922
4923 FormData form;
[email protected]b715f7f2010-04-05 22:01:044924 if (FormManager::WebFormElementToFormData(
[email protected]573c1c272010-05-25 19:28:064925 web_form, FormManager::REQUIRE_NONE, false, &form))
[email protected]b715f7f2010-04-05 22:01:044926 forms.push_back(form);
4927 }
[email protected]e6efd022010-03-31 09:34:504928
4929 if (!forms.empty())
4930 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
[email protected]e9e07992010-02-17 21:04:364931}
4932
[email protected]a3018be2010-03-09 04:28:484933void RenderView::didChangeAccessibilityObjectState(
4934 const WebKit::WebAccessibilityObject& acc_obj) {
4935#if defined(OS_WIN)
4936 // TODO(dglazkov): Current logic implies that a state change can only be made
4937 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4938 // where accessibility is initialized. We should determine whether that's
4939 // right.
4940 if (!accessibility_.get())
4941 return;
4942
4943 // Retrieve the accessibility object id of the AccessibilityObject.
4944 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4945
4946 // If id is valid, alert the browser side that an accessibility object state
4947 // change occurred.
4948 if (acc_obj_id >= 0)
4949 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4950 acc_obj_id));
4951
4952#else // defined(OS_WIN)
4953 // TODO(port): accessibility not yet implemented
4954 NOTIMPLEMENTED();
4955#endif
4956}
4957
[email protected]4d44a1c2010-04-28 19:20:414958void RenderView::SendPasswordForms(WebFrame* frame, bool only_visible) {
[email protected]55ced002010-05-21 04:49:594959 // Make sure that this security origin is allowed to use password manager.
4960 WebSecurityOrigin security_origin = frame->securityOrigin();
4961 if (!security_origin.canAccessPasswordManager())
4962 return;
4963
[email protected]979c28b2009-11-07 01:30:484964 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:454965 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:104966
4967 std::vector<PasswordForm> password_forms;
4968 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:484969 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:104970
4971 // Respect autocomplete=off.
[email protected]4d44a1c2010-04-28 19:20:414972 if (!form.autoComplete())
4973 continue;
4974 if (only_visible && !form.hasNonEmptyBoundingBox())
4975 continue;
4976 scoped_ptr<PasswordForm> password_form(
4977 PasswordFormDomManager::CreatePasswordForm(form));
4978 if (password_form.get())
4979 password_forms.push_back(*password_form);
[email protected]daa8c58e2009-06-15 17:21:104980 }
4981
[email protected]4d44a1c2010-04-28 19:20:414982 if (password_forms.empty())
4983 return;
4984 if (only_visible)
4985 Send(new ViewHostMsg_PasswordFormsVisible(routing_id_, password_forms));
4986 else
4987 Send(new ViewHostMsg_PasswordFormsFound(routing_id_, password_forms));
[email protected]daa8c58e2009-06-15 17:21:104988}
[email protected]0fda7272009-06-26 15:49:334989
4990void RenderView::Print(WebFrame* frame, bool script_initiated) {
4991 DCHECK(frame);
4992 if (print_helper_.get() == NULL) {
4993 print_helper_.reset(new PrintWebViewHelper(this));
4994 }
4995 print_helper_->Print(frame, script_initiated);
4996}
[email protected]446705872009-09-10 07:22:484997
4998void RenderView::OnSetEditCommandsForNextKeyEvent(
4999 const EditCommands& edit_commands) {
5000 edit_commands_ = edit_commands;
5001}
5002
[email protected]61f5a7b2009-12-22 22:21:205003void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275004 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355005 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205006 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5007 false));
[email protected]912256b32009-09-18 09:47:355008 return;
5009 }
5010
[email protected]fa7b6b542009-11-03 05:02:305011 WebDataSource* ds = main_frame->dataSource();
5012 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5013 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205014 pending_code_execution_queue_.push(
5015 linked_ptr<ViewMsg_ExecuteCode_Params>(
5016 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305017 return;
5018 }
5019
[email protected]61f5a7b2009-12-22 22:21:205020 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305021}
5022
5023void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205024 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:485025 // Don't execute scripts in gallery pages.
5026 GURL frame_url = GURL(frame->url());
[email protected]a0cf04a2010-06-23 03:29:555027 if (frame_url.host() == GURL(Extension::ChromeStoreURL()).host()) {
[email protected]d146b832009-12-23 02:45:485028 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
5029 return;
5030 }
5031
[email protected]20ad2692009-11-20 18:27:205032 std::vector<WebFrame*> frame_vector;
5033 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205034 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205035 GetAllChildFrames(frame, &frame_vector);
5036
5037 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5038 frame_it != frame_vector.end(); ++frame_it) {
5039 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205040 if (params.is_javascript) {
5041 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
5042 continue;
5043
[email protected]20ad2692009-11-20 18:27:205044 std::vector<WebScriptSource> sources;
5045 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205046 WebScriptSource(WebString::fromUTF8(params.code)));
5047 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205048 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205049 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205050 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5051 } else {
[email protected]61f5a7b2009-12-22 22:21:205052 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205053 }
[email protected]912256b32009-09-18 09:47:355054 }
5055
[email protected]61f5a7b2009-12-22 22:21:205056 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355057}
5058
[email protected]60c42a8c72009-10-09 04:08:595059void RenderView::Close() {
5060 // We need to grab a pointer to the doomed WebView before we destroy it.
5061 WebView* doomed = webview();
5062 RenderWidget::Close();
5063 Singleton<ViewMap>::get()->erase(doomed);
5064}
5065
[email protected]446705872009-09-10 07:22:485066void RenderView::DidHandleKeyEvent() {
5067 edit_commands_.clear();
5068}
5069
[email protected]e53668962010-06-23 15:35:255070bool RenderView::OptimizedPluginPaintInRect(skia::PlatformCanvas* canvas,
5071 const gfx::Rect& rect) {
5072 return pepper_delegate_.OptimizedPluginPaintInRect(canvas, rect);
5073}
5074
[email protected]941e4552010-02-01 21:23:435075#if defined(OS_MACOSX)
5076void RenderView::OnWasHidden() {
5077 RenderWidget::OnWasHidden();
5078
5079 // Inform plugins that their container is no longer visible.
5080 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5081 for (plugin_it = plugin_delegates_.begin();
5082 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5083 (*plugin_it)->SetContainerVisibility(false);
5084 }
5085}
5086
5087void RenderView::OnWasRestored(bool needs_repainting) {
5088 RenderWidget::OnWasRestored(needs_repainting);
5089
5090 // Inform plugins that their container is now visible.
5091 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5092 for (plugin_it = plugin_delegates_.begin();
5093 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5094 (*plugin_it)->SetContainerVisibility(true);
5095 }
5096}
[email protected]1e6e3c992010-02-08 15:52:135097
5098void RenderView::OnSetFocus(bool enable) {
5099 RenderWidget::OnSetFocus(enable);
5100
[email protected]7d3c02c2010-05-05 23:10:315101 if (webview() && webview()->isActive()) {
[email protected]1e6e3c992010-02-08 15:52:135102 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5103 for (plugin_it = plugin_delegates_.begin();
5104 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]7d3c02c2010-05-05 23:10:315105 // RenderWidget's call to setFocus can cause the underlying webview's
5106 // activation state to change just like a call to setIsActive.
5107 if (enable)
5108 (*plugin_it)->SetWindowFocus(true);
5109 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135110 }
5111 }
5112}
[email protected]941e4552010-02-01 21:23:435113#endif // OS_MACOSX
5114
[email protected]83dde542009-09-11 20:59:555115void RenderView::EnsureDocumentTag() {
5116 // TODO(darin): There's actually no reason for this to be here. We should
5117 // have the browser side manage the document tag.
5118#if defined(OS_MACOSX)
5119 if (!has_document_tag_) {
5120 // Make the call to get the tag.
5121 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5122 has_document_tag_ = true;
5123 }
5124#endif
5125}
[email protected]12636df2009-09-28 22:32:215126
[email protected]43f28f832010-02-03 02:28:485127#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:035128gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
5129 bool opaque) {
[email protected]43f28f832010-02-03 02:28:485130 gfx::PluginWindowHandle window = NULL;
5131 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]ea04a4e12010-04-15 00:58:035132 routing_id(), opaque, &window));
[email protected]43f28f832010-02-03 02:28:485133 return window;
5134}
5135
5136void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
5137 if (window)
5138 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
5139}
5140
[email protected]44ce0b12010-03-12 16:45:335141void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5142 int32 width,
5143 int32 height,
5144 uint64 io_surface_identifier) {
5145 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485146 routing_id(), window, width, height, io_surface_identifier));
5147}
5148
[email protected]44ce0b12010-03-12 16:45:335149void RenderView::AcceleratedSurfaceSetTransportDIB(
5150 gfx::PluginWindowHandle window,
5151 int32 width,
5152 int32 height,
5153 TransportDIB::Handle transport_dib) {
5154 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075155 routing_id(), window, width, height, transport_dib));
5156}
5157
[email protected]44ce0b12010-03-12 16:45:335158TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5159 size_t size) {
[email protected]1aef98132010-02-23 18:00:075160 TransportDIB::Handle dib_handle;
5161 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385162 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075163 return dib_handle;
5164 // Return an invalid handle if Send() fails.
5165 return TransportDIB::DefaultHandleValue();
5166}
5167
[email protected]44ce0b12010-03-12 16:45:335168void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075169 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5170}
5171
[email protected]44ce0b12010-03-12 16:45:335172void RenderView::AcceleratedSurfaceBuffersSwapped(
5173 gfx::PluginWindowHandle window) {
5174 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:485175}
5176#endif
[email protected]58c321d2010-02-19 12:11:285177
[email protected]cdaf8d02010-03-30 19:52:475178bool RenderView::ScheduleFileChooser(
5179 const ViewHostMsg_RunFileChooser_Params& params,
5180 WebFileChooserCompletion* completion) {
5181 static const size_t kMaximumPendingFileChooseRequests = 4;
5182 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5183 // This sanity check prevents too many file choose requests from getting
5184 // queued which could DoS the user. Getting these is most likely a
5185 // programming error (there are many ways to DoS the user so it's not
5186 // considered a "real" security check), either in JS requesting many file
5187 // choosers to pop up, or in a plugin.
5188 //
5189 // TODO(brettw) we might possibly want to require a user gesture to open
5190 // a file picker, which will address this issue in a better way.
5191 return false;
5192 }
5193
5194 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5195 new PendingFileChooser(params, completion)));
5196 if (file_chooser_completions_.size() == 1) {
5197 // Actually show the browse dialog when this is the first request.
5198 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5199 }
5200 return true;
5201}
5202
[email protected]290838a2010-04-27 17:37:015203void RenderView::OnPageTranslated() {
5204 WebFrame* frame = webview()->mainFrame();
5205 if (!frame)
5206 return;
5207
5208 // The page is translated, so try to extract the form data again.
5209 form_manager_.ExtractForms(frame);
5210 SendForms(frame);
5211}
5212
[email protected]8a5f7002010-03-31 13:47:355213WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285214 if (!geolocation_dispatcher_.get())
5215 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5216 return geolocation_dispatcher_.get();
5217}
[email protected]61c9f032010-03-31 23:04:195218
[email protected]8079b362010-05-07 18:37:455219bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195220 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455221 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195222 if (frame->parent() != NULL)
5223 return false;
5224
5225 // Skip if navigation is on the same page (using '#').
5226 GURL frame_origin = GURL(frame->url()).GetOrigin();
5227 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
5228 // The link click could stay on the same page, in cases where it sends some
5229 // parameters to the same URL.
5230 if (type == WebKit::WebNavigationTypeLinkClicked)
5231 return true;
5232
5233 if (last_top_level_navigation_page_id_ != page_id_ &&
5234 // Not interested in reloads.
5235 type != WebKit::WebNavigationTypeReload &&
5236 type != WebKit::WebNavigationTypeFormSubmitted) {
5237 return true;
5238 }
5239 }
[email protected]d0ed50d2010-06-22 01:01:325240 // Not interested in reloads.
5241 if (type != WebKit::WebNavigationTypeReload &&
5242 type != WebKit::WebNavigationTypeFormSubmitted) {
5243 // The opener relationship between the new window and the parent allows the
5244 // new window to script the parent and vice versa. This is not allowed if
5245 // the origins of the two domains are different. This can be treated as a
5246 // top level navigation and routed back to the host.
5247 WebKit::WebFrame* opener = frame->opener();
5248 if (opener) {
5249 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5250 return true;
5251 }
5252 }
[email protected]61c9f032010-03-31 23:04:195253 return false;
5254}
[email protected]18ca9a6b2010-06-02 19:05:185255
5256void RenderView::QueryAutoFillFormData(const WebKit::WebNode& node,
5257 const WebKit::WebString& value,
5258 const WebKit::WebString& label,
5259 AutoFillAction action) {
5260 static int query_counter = 0;
5261 autofill_query_id_ = query_counter++;
5262
5263 webkit_glue::FormData form;
5264 const WebInputElement element = node.toConst<WebInputElement>();
5265 if (!form_manager_.FindFormWithFormControlElement(
5266 element, FormManager::REQUIRE_NONE, &form))
5267 return;
5268
5269 autofill_action_ = action;
5270 Send(new ViewHostMsg_FillAutoFillFormData(
5271 routing_id_, autofill_query_id_, form, value, label));
5272}