blob: 305057dab1202486549a374b3eaece98608df5d2 [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]b5558cf22010-07-12 17:30:0679#include "third_party/skia/include/core/SkBitmap.h"
[email protected]418ed5ab2009-11-12 01:14:4980#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]d9ec5c0f2009-12-23 11:55:0781#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:4982#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
83#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:3284#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4985#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]01178b52010-01-15 06:59:3586#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]b1438212010-04-03 00:30:5987#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:4988#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
89#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
90#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:4191#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:5092#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:4993#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:3294#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:0795#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:4996#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]b4f68dea2010-05-13 06:03:1797#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]24a7f3c2010-03-25 08:26:4998#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]418ed5ab2009-11-12 01:14:4999#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
100#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
101#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
102#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
103#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
104#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
105#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34106#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49107#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
108#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
109#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
110#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
111#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
112#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]534c66c2010-04-28 22:53:11113#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]80f584d92010-01-21 03:59:04114#include "webkit/appcache/web_application_cache_host_impl.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]0d64bb72010-07-07 05:36:38124#include "webkit/glue/plugins/default_plugin_shared.h"
[email protected]b4f68dea2010-05-13 06:03:17125#include "webkit/glue/plugins/pepper_webplugin_impl.h"
[email protected]ba4b17f2009-02-11 21:32:29126#include "webkit/glue/plugins/plugin_list.h"
[email protected]e612d762010-03-31 04:32:30127#include "webkit/glue/plugins/webplugin_delegate.h"
[email protected]8a3b7962009-09-04 05:53:23128#include "webkit/glue/plugins/webplugin_delegate_impl.h"
[email protected]e612d762010-03-31 04:32:30129#include "webkit/glue/plugins/webplugin_impl.h"
[email protected]85cc78c2010-05-04 18:30:09130#include "webkit/glue/site_isolation_metrics.h"
initial.commit09911bf2008-07-26 23:55:29131#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29132#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17133#include "webkit/glue/webmediaplayer_impl.h"
initial.commit09911bf2008-07-26 23:55:29134
[email protected]6c8afae52009-01-22 02:24:57135#if defined(OS_WIN)
136// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57137// * theming
[email protected]cd818412010-03-19 03:23:15138#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03139#elif defined(USE_X11)
[email protected]39cd64ed2010-02-05 02:18:46140#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33141#elif defined(OS_MACOSX)
142#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57143#endif
144
[email protected]80f584d92010-01-21 03:59:04145using appcache::WebApplicationCacheHostImpl;
[email protected]c20210e62009-04-03 21:39:26146using base::Time;
[email protected]e1acf6f2008-10-27 20:43:33147using base::TimeDelta;
[email protected]15d79e12009-08-02 19:23:45148using webkit_glue::AltErrorPageResourceFetcher;
[email protected]b1438212010-04-03 00:30:59149using webkit_glue::FormData;
[email protected]95056b582010-02-18 01:29:24150using webkit_glue::FormField;
[email protected]b0950a72009-09-29 23:16:17151using webkit_glue::ImageResourceFetcher;
[email protected]ed3fb032009-06-16 19:50:56152using webkit_glue::PasswordForm;
[email protected]daa8c58e2009-06-15 17:21:10153using webkit_glue::PasswordFormDomManager;
[email protected]85cc78c2010-05-04 18:30:09154using webkit_glue::SiteIsolationMetrics;
[email protected]c7287a92009-11-04 20:06:15155using WebKit::WebAccessibilityCache;
[email protected]cc0445f2009-10-13 16:09:08156using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21157using WebKit::WebApplicationCacheHost;
158using WebKit::WebApplicationCacheHostClient;
[email protected]1c83eb42009-09-11 21:08:41159using WebKit::WebColor;
160using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59161using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44162using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51163using WebKit::WebCookieJar;
[email protected]d9ec5c0f2009-12-23 11:55:07164using WebKit::WebCString;
[email protected]e6f546c32009-07-01 17:12:55165using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28166using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29167using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00168using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58169using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25170using WebKit::WebDragOperation;
171using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51172using WebKit::WebEditingAction;
[email protected]cdaf8d02010-03-30 19:52:47173using WebKit::WebFileChooserCompletion;
[email protected]6069da8c2009-10-20 20:33:49174using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59175using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48176using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45177using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17178using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41179using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50180using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17181using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28182using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17183using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28184using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28185using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51186using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07187using WebKit::WebPageSerializer;
188using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17189using WebKit::WebPlugin;
190using WebKit::WebPluginParams;
[email protected]24a7f3c2010-03-25 08:26:49191using WebKit::WebPluginDocument;
[email protected]48c9cf2d2009-09-16 16:47:52192using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59193using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51194using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52195using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40196using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35197using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29198using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59199using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42200using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02201using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34202using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28203using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51204using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52205using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28206using WebKit::WebURL;
207using WebKit::WebURLError;
208using WebKit::WebURLRequest;
209using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28210using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03211using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28212using WebKit::WebWidget;
[email protected]27ba8532009-04-24 20:22:43213using WebKit::WebWorker;
214using WebKit::WebWorkerClient;
[email protected]534c66c2010-04-28 22:53:11215using WebKit::WebWindowFeatures;
[email protected]e1acf6f2008-10-27 20:43:33216
initial.commit09911bf2008-07-26 23:55:29217//-----------------------------------------------------------------------------
218
[email protected]3354d3e2010-06-10 19:53:02219typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
220
initial.commit09911bf2008-07-26 23:55:29221// define to write the time necessary for thumbnail/DOM text retrieval,
222// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29223// #define TIME_TEXT_RETRIEVAL
224
225// maximum number of characters in the document to index, any text beyond this
226// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57227static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29228
229// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37230static const int kThumbnailWidth = 212;
231static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29232
233// Delay in milliseconds that we'll wait before capturing the page contents
234// and thumbnail.
235static const int kDelayForCaptureMs = 500;
236
237// Typically, we capture the page data once the page is loaded.
238// Sometimes, the page never finishes to load, preventing the page capture
239// To workaround this problem, we always perform a capture after the following
240// delay.
241static const int kDelayForForcedCaptureMs = 6000;
242
[email protected]882daa92009-11-05 16:31:31243// Time, in seconds, we delay before sending content state changes (such as form
244// state and scroll position) to the browser. We delay sending changes to avoid
245// spamming the browser.
246// To avoid having tab/session restore require sending a message to get the
247// current content state during tab closing we use a shorter timeout for the
248// foreground renderer. This means there is a small window of time from which
249// content state is modified and not sent to session restore, but this is
250// better than having to wake up all renderers during shutdown.
251static const int kDelaySecondsForContentStateSyncHidden = 5;
252static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29253
[email protected]0aa55312008-10-17 21:53:08254// The maximum number of popups that can be spawned from one page.
255static const int kMaximumNumberOfUnacknowledgedPopups = 25;
256
initial.commit09911bf2008-07-26 23:55:29257static const char* const kUnreachableWebDataURL =
[email protected]60e448982009-05-06 04:21:16258 "chrome://chromewebdata/";
initial.commit09911bf2008-07-26 23:55:29259
[email protected]50b691c2008-10-31 19:08:35260static const char* const kBackForwardNavigationScheme = "history";
261
[email protected]d64b07b2010-04-20 22:14:06262// static
263const char* const RenderView::kUnknownLanguageCode = "und";
[email protected]8c4cdd42010-01-12 21:31:13264
[email protected]726985e22009-06-18 21:09:28265static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
266 WebVector<WebURL> urls;
267 ds->redirectChain(urls);
268 result->reserve(urls.size());
269 for (size_t i = 0; i < urls.size(); ++i)
270 result->push_back(urls[i]);
271}
272
[email protected]61f5a7b2009-12-22 22:21:20273static bool UrlMatchesPermissions(
274 const GURL& url, const std::vector<URLPattern>& host_permissions) {
275 for (size_t i = 0; i < host_permissions.size(); ++i) {
276 if (host_permissions[i].MatchesUrl(url))
277 return true;
278 }
279
280 return false;
281}
282
[email protected]30507922010-01-15 16:48:23283static bool PaintViewIntoCanvas(WebView* view,
284 skia::PlatformCanvas& canvas) {
285 view->layout();
286 const WebSize& size = view->size();
287
288 if (!canvas.initialize(size.width, size.height, true))
289 return false;
290
291 view->paint(webkit_glue::ToWebCanvas(&canvas),
292 WebRect(0, 0, size.width, size.height));
293 // TODO: Add a way to snapshot the whole page, not just the currently
294 // visible part.
295
296 return true;
297}
298
299// Calculates how "boring" a thumbnail is. The boring score is the
300// 0,1 ranged percentage of pixels that are the most common
301// luma. Higher boring scores indicate that a higher percentage of a
302// bitmap are all the same brightness.
303static double CalculateBoringScore(SkBitmap* bitmap) {
304 int histogram[256] = {0};
305 color_utils::BuildLumaHistogram(bitmap, histogram);
306
307 int color_count = *std::max_element(histogram, histogram + 256);
308 int pixel_count = bitmap->width() * bitmap->height();
309 return static_cast<double>(color_count) / pixel_count;
310}
311
[email protected]12bc8472010-04-15 07:29:40312// True if |frame| contains content that is white-listed for content settings.
313static bool IsWhitelistedForContentSettings(WebFrame* frame) {
314 WebSecurityOrigin origin = frame->securityOrigin();
315 if (origin.isEmpty())
316 return false; // Uninitialized document?
317
318 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
319 return true; // Browser UI elements should still work.
320
321 // If the scheme is ftp: or file:, an empty file name indicates a directory
322 // listing, which requires JavaScript to function properly.
323 GURL frame_url = frame->url();
324 const char* kDirProtocols[] = { "ftp", "file" };
325 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
326 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
327 return frame_url.SchemeIs(kDirProtocols[i]) &&
328 frame_url.ExtractFileName().empty();
329 }
330 }
331
332 return false;
333}
334
[email protected]3a8eecb2010-04-22 23:56:30335// Returns true if the frame is navigating to an URL either into or out of an
336// extension app's extent.
337static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) {
338 if (!RenderThread::current())
339 return false;
340
341 // If the URL is still empty, this is a window.open navigation. Check the
342 // opener's URL.
343 GURL old_url(frame->url());
344 if (old_url.is_empty() && frame->opener())
345 old_url = frame->opener()->url();
346
347 std::string old_extension =
[email protected]4fdbc1492010-07-01 01:20:59348 RenderThread::current()->GetExtensionIdByURL(old_url);
349 if (!old_extension.empty()) {
350 if (RenderThread::current()->GetExtensionIdByBrowseExtent(new_url) ==
351 old_extension) {
352 return false;
353 }
354 }
355
[email protected]3a8eecb2010-04-22 23:56:30356 std::string new_extension =
[email protected]4fdbc1492010-07-01 01:20:59357 RenderThread::current()->GetExtensionIdByURL(new_url);
358 return old_extension != new_extension;
[email protected]3a8eecb2010-04-22 23:56:30359}
360
[email protected]3354d3e2010-06-10 19:53:02361// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
362// if it failed.
363//
364// Note this only works on Windows at this time. It always returns 'unknown'
365// on other platforms.
[email protected]e5106202010-06-11 21:12:36366static std::string DetermineTextLanguage(const string16& text) {
[email protected]3354d3e2010-06-10 19:53:02367 // Text with less than 100 bytes will probably not provide good results.
368 // Report it as unknown language.
369 if (text.length() < 100)
370 return RenderView::kUnknownLanguageCode;
371
372 std::string language = RenderView::kUnknownLanguageCode;
373 int num_languages = 0;
374 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02375 Language cld_language =
[email protected]e5106202010-06-11 21:12:36376 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]3354d3e2010-06-10 19:53:02377 &num_languages, NULL);
378 if (is_reliable && cld_language != NUM_LANGUAGES &&
379 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
380 // We should not use LanguageCode_ISO_639_1 because it does not cover all
381 // the languages CLD can detect. As a result, it'll return the invalid
382 // language code for tradtional Chinese among others.
383 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
384 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
385 // for Simplified Chinese.
386 language = LanguageCodeWithDialects(cld_language);
387 }
388 return language;
389}
390
initial.commit09911bf2008-07-26 23:55:29391///////////////////////////////////////////////////////////////////////////////
392
[email protected]60c42a8c72009-10-09 04:08:59393int32 RenderView::next_page_id_ = 1;
394
[email protected]cdaf8d02010-03-30 19:52:47395struct RenderView::PendingFileChooser {
396 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
397 WebFileChooserCompletion* c)
398 : params(p),
399 completion(c) {
400 }
401 ViewHostMsg_RunFileChooser_Params params;
402 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
403};
404
[email protected]2fab253a2009-08-17 23:00:59405RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34406 const WebPreferences& webkit_preferences,
407 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12408 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02409 webkit_preferences_(webkit_preferences),
410 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09411 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02412 send_preferred_size_changes_(false),
413 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24414 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21415 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02416 opened_by_user_gesture_(true),
417 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24418 page_id_(-1),
419 last_page_id_sent_to_browser_(-1),
420 last_indexed_page_id_(-1),
[email protected]3354d3e2010-06-10 19:53:02421 last_top_level_navigation_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00422 history_list_offset_(-1),
423 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24424 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55425#if defined(OS_MACOSX)
426 has_document_tag_(false),
427#endif
[email protected]98324892009-09-09 21:16:05428 document_tag_(0),
[email protected]ab9eabac2010-03-16 16:54:10429 cross_origin_access_count_(0),
[email protected]b4f68dea2010-05-13 06:03:17430 same_origin_access_count_(0),
[email protected]3354d3e2010-06-10 19:53:02431 target_url_status_(TARGET_NONE),
432 spelling_panel_visible_(false),
433 view_type_(ViewType::INVALID),
434 browser_window_id_(-1),
435 autofill_query_id_(0),
436 autofill_action_(AUTOFILL_NONE),
[email protected]33bd60f2010-07-07 17:50:58437 suggestions_clear_index_(-1),
438 suggestions_options_index_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18439 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]3354d3e2010-06-10 19:53:02440 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
441 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
[email protected]03f57072010-07-14 17:36:08442 ALLOW_THIS_IN_INITIALIZER_LIST(password_autocomplete_manager_(this)),
[email protected]3354d3e2010-06-10 19:53:02443 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
444 ALLOW_THIS_IN_INITIALIZER_LIST(
445 notification_provider_(new NotificationProvider(this))),
446 session_storage_namespace_id_(session_storage_namespace_id),
447 decrement_shared_popup_at_destruction_(false) {
[email protected]71b0d5d2010-02-15 05:43:07448 ClearBlockedContentSettings();
initial.commit09911bf2008-07-26 23:55:29449}
450
451RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08452 if (decrement_shared_popup_at_destruction_)
453 shared_popup_counter_->data--;
454
[email protected]b0950a72009-09-29 23:16:17455 // Dispose of un-disposed image fetchers.
456 for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin();
457 i != image_fetchers_.end(); ++i) {
458 delete *i;
459 }
460
[email protected]a1128322009-10-06 18:38:46461 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47462 while (!file_chooser_completions_.empty()) {
463 if (file_chooser_completions_.front()->completion) {
464 file_chooser_completions_.front()->completion->didChooseFile(
465 WebVector<WebString>());
466 }
467 file_chooser_completions_.pop_front();
468 }
[email protected]a1128322009-10-06 18:38:46469
[email protected]83dde542009-09-11 20:59:55470#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05471 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55472 if (has_document_tag_)
473 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
474#endif
[email protected]98324892009-09-09 21:16:05475
[email protected]5fb88962009-04-16 19:03:25476 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59477
478#ifndef NDEBUG
479 // Make sure we are no longer referenced by the ViewMap.
480 ViewMap* views = Singleton<ViewMap>::get();
481 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
482 DCHECK_NE(this, it->second) << "Failed to call Close?";
483#endif
484}
485
486/*static*/
487void RenderView::ForEach(RenderViewVisitor* visitor) {
488 ViewMap* views = Singleton<ViewMap>::get();
489 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
490 if (!visitor->Visit(it->second))
491 return;
492 }
493}
494
495/*static*/
496RenderView* RenderView::FromWebView(WebView* webview) {
497 ViewMap* views = Singleton<ViewMap>::get();
498 ViewMap::iterator it = views->find(webview);
499 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29500}
501
502/*static*/
[email protected]0aa55312008-10-17 21:53:08503RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24504 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15505 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08506 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51507 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08508 const WebPreferences& webkit_prefs,
509 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34510 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26511 int64 session_storage_namespace_id,
512 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29513 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]4e6419c2010-01-15 04:50:34514 scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs,
515 session_storage_namespace_id);
initial.commit09911bf2008-07-26 23:55:29516 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29517 opener_id,
[email protected]80d96fa2009-06-10 22:34:51518 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08519 counter,
[email protected]8ab04652010-06-12 02:47:26520 routing_id,
521 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29522 return view;
523}
524
525/*static*/
526void RenderView::SetNextPageID(int32 next_page_id) {
527 // This method should only be called during process startup, and the given
528 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05529 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29530 DCHECK(next_page_id >= next_page_id_);
531 next_page_id_ = next_page_id;
532}
533
[email protected]afe3a1672009-11-17 19:04:12534void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]1dbafaf72009-09-23 19:43:56535 Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action));
536}
537
[email protected]a3a8fb6d2009-10-22 20:12:51538void RenderView::PluginCrashed(const FilePath& plugin_path) {
539 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29540}
541
[email protected]d8fd6fa2010-02-01 15:54:26542#if defined(OS_MACOSX)
543void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
544 plugin_delegates_.insert(delegate);
545}
546
547void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
548 plugin_delegates_.erase(delegate);
549}
550#endif
551
[email protected]18bcc3c2009-01-27 21:39:15552void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29553 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51554 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08555 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26556 int32 routing_id,
557 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29558 DCHECK(!webview());
559
560 if (opener_id != MSG_ROUTING_NONE)
561 opener_id_ = opener_id;
562
[email protected]0aa55312008-10-17 21:53:08563 if (counter) {
564 shared_popup_counter_ = counter;
565 shared_popup_counter_->data++;
566 decrement_shared_popup_at_destruction_ = true;
567 } else {
568 shared_popup_counter_ = new SharedRenderViewCounter(0);
569 decrement_shared_popup_at_destruction_ = false;
570 }
571
[email protected]58bfc6b2009-06-24 09:45:02572 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04573
[email protected]9a6c6232010-06-25 11:46:49574 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]60c42a8c72009-10-09 04:08:59575 Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59576 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27577 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23578 if (!frame_name.empty())
579 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29580
[email protected]d3ba77272009-09-03 00:06:09581 OnSetRendererPrefs(renderer_prefs);
582
initial.commit09911bf2008-07-26 23:55:29583 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24584 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29585 // Take a reference on behalf of the RenderThread. This will be balanced
586 // when we receive ViewMsg_Close.
587 AddRef();
588
589 // If this is a popup, we must wait for the CreatingNew_ACK message before
590 // completing initialization. Otherwise, we can finish it now.
591 if (opener_id == MSG_ROUTING_NONE) {
592 did_show_ = true;
593 CompleteInit(parent_hwnd);
594 }
595
596 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29597
[email protected]58bfc6b2009-06-24 09:45:02598 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09599 if (command_line.HasSwitch(switches::kDomAutomationController))
600 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
initial.commit09911bf2008-07-26 23:55:29601
[email protected]5fb88962009-04-16 19:03:25602 audio_message_filter_ = new AudioMessageFilter(routing_id_);
603 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29604}
605
606void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27607 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27608 if (main_frame)
609 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26610
[email protected]b2abac72009-02-26 12:39:28611 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11612 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28613 return;
[email protected]b4b967e2009-04-22 11:33:05614 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
615 return;
[email protected]b6849bda2009-10-14 23:59:26616 if (notification_provider_->OnMessageReceived(message))
617 return;
[email protected]58c321d2010-02-19 12:11:28618 if (geolocation_dispatcher_.get() &&
619 geolocation_dispatcher_->OnMessageReceived(message)) {
620 return;
621 }
[email protected]b2abac72009-02-26 12:39:28622
initial.commit09911bf2008-07-26 23:55:29623 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04624 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
625 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29626 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01627 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29628 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
629 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56630 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29631 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
632 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
633 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
634 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27635#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35636 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27637#endif
initial.commit09911bf2008-07-26 23:55:29638 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
639 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05640 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
641 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
642 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04643 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29644 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
645 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
646 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15647 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29648 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49649 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
650 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17651 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54652 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
653 OnSetContentSettingsForLoadingURL)
654 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
655 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29656 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18657 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
658 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:28659 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:33660 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:29661 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48662 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29663 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:29664 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:29665 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
666 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
667 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
668 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
669 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:45670 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:29671 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:50672 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
673 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:29674 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
675 OnDragSourceSystemDragEnded)
676 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
initial.commit09911bf2008-07-26 23:55:29677 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
678 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
679 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
680 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
681 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
682 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:29683 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
684 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:04685 IPC_MESSAGE_HANDLER(
686 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
687 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:29688 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:04689 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:29690 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
691 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:45692 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:04693 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:08694 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
695 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:24696 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
697 OnAutoFillSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:48698 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
699 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:40700 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
701 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:00702 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:27703 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:37704 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
705 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:16706 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14707 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25708 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
709 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10710 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
711 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51712 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:53713 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
714 OnUpdateBrowserWindowId)
715 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
716 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:56717 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34718 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14719#if defined(OS_MACOSX)
720 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13721 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]6ce7abc52010-02-02 18:40:14722#endif
[email protected]446705872009-09-10 07:22:48723 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33724 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:35725 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
726 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:33727 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
728 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:42729 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:02730 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]b3df5a42010-05-11 14:31:09731 IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree)
[email protected]aef92842010-05-21 16:54:36732 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
733 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
734 OnAccessibilityDoDefaultAction)
[email protected]634a6f92008-12-01 21:39:31735
initial.commit09911bf2008-07-26 23:55:29736 // Have the super handle all other messages.
737 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
738 IPC_END_MESSAGE_MAP()
739}
740
[email protected]9b18a84f2010-06-10 15:54:04741void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:27742 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29743 if (!main_frame)
744 return;
745
746 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:45747 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29748 if (url.is_empty())
749 return;
750
751 if (size_.IsEmpty())
752 return; // Don't create an empty thumbnail!
753
754 ThumbnailScore score;
755 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:02756 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:15757 &thumbnail, &score))
758 return;
759
initial.commit09911bf2008-07-26 23:55:29760 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:46761 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:29762}
763
[email protected]9b18a84f2010-06-10 15:54:04764void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:23765 SkBitmap snapshot;
766 bool error = false;
767
768 WebFrame* main_frame = webview()->mainFrame();
769 if (!main_frame)
770 error = true;
771
772 if (!error && !CaptureSnapshot(webview(), &snapshot))
773 error = true;
774
775 DCHECK(error == snapshot.empty()) <<
776 "Snapshot should be empty on error, non-empty otherwise.";
777
778 // Send the snapshot to the browser process.
779 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
780}
781
[email protected]068637222009-01-29 16:58:07782void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:29783 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:58784 if (webview()) {
785 // If the user has selected text in the currently focused frame we print
786 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:27787 if (webview()->focusedFrame()->hasSelection())
788 Print(webview()->focusedFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58789 else
[email protected]26aa0482009-09-30 16:55:27790 Print(webview()->mainFrame(), false);
[email protected]aa82249f2009-07-16 17:23:58791 }
initial.commit09911bf2008-07-26 23:55:29792}
793
[email protected]82270452009-06-19 15:58:01794void RenderView::OnPrintingDone(int document_cookie, bool success) {
795 // Ignoring document cookie here since only one print job can be outstanding
796 // per renderer and document_cookie is 0 when printing is successful.
797 DCHECK(print_helper_.get());
798 if (print_helper_.get() != NULL) {
799 print_helper_->DidFinishPrinting(success);
800 }
801}
802
initial.commit09911bf2008-07-26 23:55:29803void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
804 if (load_id != page_id_)
805 return; // this capture call is no longer relevant due to navigation
806 if (load_id == last_indexed_page_id_)
807 return; // we already indexed this page
808
809 if (!webview())
810 return;
811
[email protected]26aa0482009-09-30 16:55:27812 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:29813 if (!main_frame)
814 return;
815
816 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:45817 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:29818 return;
819
820 // Don't index/capture pages that failed to load. This only checks the top
821 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:45822 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:28823 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:29824 return;
825
826 if (!preliminary_capture)
827 last_indexed_page_id_ = load_id;
828
[email protected]a8a81292010-01-21 00:32:45829 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:45830 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:29831 if (url.is_empty())
832 return;
833
[email protected]a8a81292010-01-21 00:32:45834 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:36835 string16 contents;
initial.commit09911bf2008-07-26 23:55:29836 CaptureText(main_frame, &contents);
837 if (contents.size()) {
[email protected]a8a81292010-01-21 00:32:45838 base::TimeTicks begin_time = base::TimeTicks::Now();
839 std::string language = DetermineTextLanguage(contents);
840 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
841 base::TimeTicks::Now() - begin_time);
[email protected]1c57b7b2010-07-12 17:38:10842 WebKit::WebDocument document = main_frame->document();
[email protected]a8a81292010-01-21 00:32:45843 // Send the text to the browser for indexing (the browser might decide not
844 // to index, if the URL is HTTPS for instance) and language discovery.
845 Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents,
[email protected]1c57b7b2010-07-12 17:38:10846 language, IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:27847 }
848
[email protected]9b18a84f2010-06-10 15:54:04849 OnCaptureThumbnail();
initial.commit09911bf2008-07-26 23:55:29850}
851
[email protected]e5106202010-06-11 21:12:36852void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:29853 contents->clear();
854 if (!frame)
855 return;
856
857#ifdef TIME_TEXT_RETRIEVAL
858 double begin = time_util::GetHighResolutionTimeNow();
859#endif
860
861 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:36862 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:29863
864#ifdef TIME_TEXT_RETRIEVAL
865 double end = time_util::GetHighResolutionTimeNow();
866 char buf[128];
867 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
868 contents.size(), (end - begin)*1000);
869 OutputDebugStringA(buf);
870#endif
871
872 // When the contents are clipped to the maximum, we don't want to have a
873 // partial word indexed at the end that might have been clipped. Therefore,
874 // terminate the string at the last space to ensure no words are clipped.
875 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:36876 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:29877 if (last_space_index == std::wstring::npos)
878 return; // don't index if we got a huge block of text with no spaces
879 contents->resize(last_space_index);
880 }
881}
882
[email protected]8649fb32009-06-26 17:51:02883bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:29884 int w,
885 int h,
886 SkBitmap* thumbnail,
887 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:23888 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:15889
[email protected]8649fb32009-06-26 17:51:02890 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:23891
892 // Paint |view| into |canvas|.
893 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:02894 return false;
[email protected]8649fb32009-06-26 17:51:02895
896 skia::BitmapPlatformDevice& device =
897 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
898
899 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:29900
[email protected]cab34d6a2009-09-24 01:14:52901 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:29902 float dest_aspect = dest_rect.width() / dest_rect.height();
903
904 // Get the src rect so that we can preserve the aspect ratio while filling
905 // the destination.
906 SkIRect src_rect;
907 if (src_bmp.width() < dest_rect.width() ||
908 src_bmp.height() < dest_rect.height()) {
909 // Source image is smaller: we clip the part of source image within the
910 // dest rect, and then stretch it to fill the dest rect. We don't respect
911 // the aspect ratio in this case.
912 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
913 static_cast<S16CPU>(dest_rect.height()));
914 score->good_clipping = false;
915 } else {
916 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
917 if (src_aspect > dest_aspect) {
918 // Wider than tall, clip horizontally: we center the smaller thumbnail in
919 // the wider screen.
920 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
921 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
922 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
923 score->good_clipping = false;
924 } else {
925 src_rect.set(0, 0, src_bmp.width(),
926 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
927 score->good_clipping = true;
928 }
929 }
930
[email protected]26aa0482009-09-30 16:55:27931 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:29932
933 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:02934 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:29935
936 // Resample the subset that we want to get it the right size.
[email protected]465b34b72008-12-12 20:19:14937 *thumbnail = skia::ImageOperations::Resize(
938 subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:29939
940 score->boring_score = CalculateBoringScore(thumbnail);
941
[email protected]30507922010-01-15 16:48:23942 HISTOGRAM_TIMES("Renderer4.Thumbnail",
943 base::TimeTicks::Now() - beginning_time);
[email protected]b6e4bec2008-11-12 01:17:15944 return true;
initial.commit09911bf2008-07-26 23:55:29945}
946
[email protected]30507922010-01-15 16:48:23947bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
948 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:29949
[email protected]30507922010-01-15 16:48:23950 skia::PlatformCanvas canvas;
951 if (!PaintViewIntoCanvas(view, canvas))
952 return false;
953
954 skia::BitmapPlatformDevice& device =
955 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
956
957 const SkBitmap& bitmap = device.accessBitmap(false);
958 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
959 return false;
960
961 HISTOGRAM_TIMES("Renderer4.Snapshot",
962 base::TimeTicks::Now() - beginning_time);
963 return true;
initial.commit09911bf2008-07-26 23:55:29964}
965
966void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
967 if (!webview())
968 return;
969
[email protected]3cc72b12010-03-18 23:03:00970 history_list_offset_ = params.current_history_list_offset;
971 history_list_length_ = params.current_history_list_length;
972
[email protected]8c785c62009-07-13 14:20:15973 if (devtools_agent_.get())
974 devtools_agent_->OnNavigate();
975
[email protected]422197532010-01-25 17:38:23976 if (notification_provider_.get())
977 notification_provider_->OnNavigate();
978
[email protected]a9f607e2009-10-23 19:59:27979 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:26980
initial.commit09911bf2008-07-26 23:55:29981 AboutHandler::MaybeHandle(params.url);
982
[email protected]ecbf10d2010-02-18 13:03:29983 bool is_reload =
984 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
985 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29986
[email protected]26aa0482009-09-30 16:55:27987 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45988 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29989 // We cannot reload if we do not have any history state. This happens, for
990 // example, when recovering from a crash. Our workaround here is a bit of
991 // a hack since it means that reload after a crashed tab does not cause an
992 // end-to-end cache validation.
993 is_reload = false;
994 }
995
[email protected]77f17a82009-05-21 04:42:54996 // A navigation resulting from loading a javascript URL should not be treated
997 // as a browser initiated event. Instead, we want it to look as if the page
998 // initiated any load resulting from JS execution.
999 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301000 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001001 params.page_id,
1002 params.pending_history_list_offset,
1003 params.transition,
1004 params.request_time);
[email protected]5e369672009-11-03 23:48:301005 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1006 // We're doing a load of a page that was restored from the last session.
1007 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1008 // which can result in stale data for pages that are set to expire. We
1009 // explicitly override that by setting the policy here so that as
1010 // necessary we load from the network.
1011 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1012 }
1013 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541014 }
initial.commit09911bf2008-07-26 23:55:291015
[email protected]a7ccc4d2010-01-27 08:14:481016 NavigationState* navigation_state = pending_navigation_state_.get();
1017
[email protected]04d3c6e2009-05-22 17:00:131018 // If we are reloading, then WebKit will use the history state of the current
1019 // page, so we should just ignore any given history state. Otherwise, if we
1020 // have history state, then we need to navigate to it, which corresponds to a
1021 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551022 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481023 if (navigation_state)
1024 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291025 bool ignore_cache = (params.navigation_type ==
1026 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1027 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551028 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131029 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581030 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481031 if (navigation_state)
1032 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451033 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171034 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131035 } else {
1036 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281037 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291038
[email protected]e6f546c32009-07-01 17:12:551039 // A session history navigation should have been accompanied by state.
1040 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131041
[email protected]dd7daa82009-08-10 05:46:451042 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551043 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131044
[email protected]726985e22009-06-18 21:09:281045 if (params.referrer.is_valid()) {
1046 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1047 WebString::fromUTF8(params.referrer.spec()));
1048 }
[email protected]04d3c6e2009-05-22 17:00:131049
[email protected]a7ccc4d2010-01-27 08:14:481050 if (navigation_state)
1051 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451052 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501053 }
1054
[email protected]77f17a82009-05-21 04:42:541055 // In case LoadRequest failed before DidCreateDataSource was called.
1056 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291057}
1058
1059// Stop loading the current page
1060void RenderView::OnStop() {
1061 if (webview())
[email protected]b4bb2502009-10-01 22:35:271062 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291063}
1064
[email protected]ecbf10d2010-02-18 13:03:291065// Reload current focused frame.
1066// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561067void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291068 if (webview() && webview()->focusedFrame()) {
1069 // We always obey the cache (ignore_cache=false) here.
1070 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1071 // a cache-ignoring reload of the frame.
1072 webview()->focusedFrame()->reload(false);
1073 }
[email protected]1dda4022010-01-28 18:24:561074}
1075
initial.commit09911bf2008-07-26 23:55:291076void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271077 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291078}
1079
[email protected]68b1e922009-06-23 16:00:251080void RenderView::OnExecuteEditCommand(const std::string& name,
1081 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271082 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251083 return;
1084
[email protected]26aa0482009-09-30 16:55:271085 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451086 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251087}
1088
[email protected]b2abac72009-02-26 12:39:281089void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111090 DCHECK(!devtools_client_.get());
1091 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281092}
1093
initial.commit09911bf2008-07-26 23:55:291094void RenderView::OnUpdateTargetURLAck() {
1095 // Check if there is a targeturl waiting to be sent.
1096 if (target_url_status_ == TARGET_PENDING) {
1097 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1098 pending_target_url_));
1099 }
1100
1101 target_url_status_ = TARGET_NONE;
1102}
1103
1104void RenderView::OnUndo() {
1105 if (!webview())
1106 return;
1107
[email protected]26aa0482009-09-30 16:55:271108 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121109 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291110}
1111
1112void RenderView::OnRedo() {
1113 if (!webview())
1114 return;
1115
[email protected]26aa0482009-09-30 16:55:271116 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121117 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291118}
1119
1120void RenderView::OnCut() {
1121 if (!webview())
1122 return;
1123
[email protected]26aa0482009-09-30 16:55:271124 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121125 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291126}
1127
1128void RenderView::OnCopy() {
1129 if (!webview())
1130 return;
1131
[email protected]26aa0482009-09-30 16:55:271132 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121133 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291134}
1135
[email protected]c0cc3092009-09-12 08:27:271136#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351137void RenderView::OnCopyToFindPboard() {
1138 if (!webview())
1139 return;
1140
1141 // Since the find pasteboard supports only plain text, this can be simpler
1142 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271143 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351144 if (frame->hasSelection()) {
1145 string16 selection = frame->selectionAsText();
1146 RenderThread::current()->Send(
1147 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1148 }
1149
[email protected]afe3a1672009-11-17 19:04:121150 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351151}
[email protected]c0cc3092009-09-12 08:27:271152#endif
[email protected]a954bf72009-09-12 07:30:351153
initial.commit09911bf2008-07-26 23:55:291154void RenderView::OnPaste() {
1155 if (!webview())
1156 return;
1157
[email protected]26aa0482009-09-30 16:55:271158 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121159 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291160}
1161
[email protected]2a3a7762009-10-19 19:17:321162void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291163 if (!webview())
1164 return;
1165
[email protected]1ff7a032010-02-03 02:46:031166 WebFrame* frame = webview()->focusedFrame();
1167 if (!frame->hasSelection())
1168 frame->selectWordAroundCaret();
1169 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291170}
1171
[email protected]98324892009-09-09 21:16:051172void RenderView::OnAdvanceToNextMisspelling() {
1173 if (!webview())
1174 return;
[email protected]26aa0482009-09-30 16:55:271175 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051176 WebString::fromUTF8("AdvanceToNextMisspelling"));
1177}
1178
1179void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1180 if (!webview())
1181 return;
1182 // We need to tell the webView whether the spelling panel is visible or not so
1183 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261184 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271185 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051186 WebString::fromUTF8("ToggleSpellPanel"));
1187}
1188
[email protected]bbbd545c2008-12-15 20:18:041189void RenderView::OnToggleSpellCheck() {
1190 if (!webview())
1191 return;
1192
[email protected]26aa0482009-09-30 16:55:271193 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451194 frame->enableContinuousSpellChecking(
1195 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041196}
1197
initial.commit09911bf2008-07-26 23:55:291198void RenderView::OnDelete() {
1199 if (!webview())
1200 return;
1201
[email protected]26aa0482009-09-30 16:55:271202 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121203 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291204}
1205
1206void RenderView::OnSelectAll() {
1207 if (!webview())
1208 return;
1209
[email protected]26aa0482009-09-30 16:55:271210 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221211 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121212 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291213}
1214
1215void RenderView::OnSetInitialFocus(bool reverse) {
1216 if (!webview())
1217 return;
[email protected]26aa0482009-09-30 16:55:271218 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291219}
1220
1221///////////////////////////////////////////////////////////////////////////////
1222
[email protected]433819d2010-01-30 20:20:011223void RenderView::SetContentSettings(const ContentSettings& settings) {
1224 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011225}
1226
initial.commit09911bf2008-07-26 23:55:291227// Tell the embedding application that the URL of the active page has changed
1228void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451229 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291230 DCHECK(ds);
1231
[email protected]726985e22009-06-18 21:09:281232 const WebURLRequest& request = ds->request();
1233 const WebURLRequest& original_request = ds->originalRequest();
1234 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291235
[email protected]daa8c58e2009-06-15 17:21:101236 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1237 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291238
1239 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281240 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291241 params.is_post = false;
1242 params.page_id = page_id_;
[email protected]726985e22009-06-18 21:09:281243 params.is_content_filtered = response.isContentFiltered();
[email protected]e6f546c32009-07-01 17:12:551244 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291245 // SSL state specified in the request takes precedence over the one in the
1246 // response.
1247 // So far this is only intended for error pages that are not expected to be
1248 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281249 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551250 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291251 } else {
[email protected]726985e22009-06-18 21:09:281252 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291253 }
1254
1255 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281256 if (ds->hasUnreachableURL()) {
1257 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291258 } else {
[email protected]726985e22009-06-18 21:09:281259 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291260 }
1261
[email protected]726985e22009-06-18 21:09:281262 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241263 params.should_update_history = !ds->hasUnreachableURL() &&
1264 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291265
[email protected]ce0e250d2009-10-23 21:00:351266 params.searchable_form_url = navigation_state->searchable_form_url();
1267 params.searchable_form_encoding =
1268 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291269
1270 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101271 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291272 if (password_form_data)
1273 params.password_form = *password_form_data;
1274
1275 params.gesture = navigation_gesture_;
1276 navigation_gesture_ = NavigationGestureUnknown;
1277
[email protected]dd7daa82009-08-10 05:46:451278 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291279 // Top-level navigation.
1280
[email protected]71b0d5d2010-02-15 05:43:071281 // Clear "block" flags for the new page. This needs to happen before any of
1282 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1283 // so that these functions can correctly detect that a piece of content
1284 // flipped from "not blocked" to "blocked".
1285 ClearBlockedContentSettings();
1286
[email protected]62d2a112010-04-07 00:53:021287 // Set content settings. Default them from the parent window if one exists.
1288 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011289 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541290 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011291 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011292 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011293
1294 // These content settings were merely recorded transiently for this load.
1295 // We can erase them now. If at some point we reload this page, the
1296 // browser will send us new, up-to-date content settings.
1297 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401298 } else if (frame->opener()) {
1299 WebView* opener_view = frame->opener()->view();
1300 RenderView* opener = FromWebView(opener_view);
1301 SetContentSettings(opener->current_content_settings_);
[email protected]f85f0702010-01-30 09:31:011302 }
1303
[email protected]40bd6582009-12-04 23:49:511304 // Set zoom level.
[email protected]f85f0702010-01-30 09:31:011305 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541306 host_zoom_levels_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011307 if (host_zoom != host_zoom_levels_.end()) {
1308 webview()->setZoomLevel(false, host_zoom->second);
[email protected]40bd6582009-12-04 23:49:511309 // This zoom level was merely recorded transiently for this load. We can
1310 // erase it now. If at some point we reload this page, the browser will
1311 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011312 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511313 }
1314
initial.commit09911bf2008-07-26 23:55:291315 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551316 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291317
[email protected]daa8c58e2009-06-15 17:21:101318 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291319 if (!PageTransition::IsMainFrame(params.transition)) {
1320 // If the main frame does a load, it should not be reported as a subframe
1321 // navigation. This can occur in the following case:
1322 // 1. You're on a site with frames.
1323 // 2. You do a subframe navigation. This is stored with transition type
1324 // MANUAL_SUBFRAME.
1325 // 3. You navigate to some non-frame site, say, google.com.
1326 // 4. You navigate back to the page from step 2. Since it was initially
1327 // MANUAL_SUBFRAME, it will be that same transition type here.
1328 // We don't want that, because any navigation that changes the toplevel
1329 // frame should be tracked as a toplevel navigation (this allows us to
1330 // update the URL bar, etc).
1331 params.transition = PageTransition::LINK;
1332 }
1333
initial.commit09911bf2008-07-26 23:55:291334 // If we have a valid consumed client redirect source,
1335 // the page contained a client redirect (meta refresh, document.loc...),
1336 // so we set the referrer and transition to match.
1337 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041338 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291339 params.referrer = completed_client_redirect_src_;
1340 params.transition = static_cast<PageTransition::Type>(
1341 params.transition | PageTransition::CLIENT_REDIRECT);
1342 } else {
1343 // Bug 654101: the referrer will be empty on https->http transitions. It
1344 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281345 params.referrer = GURL(
1346 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291347 }
1348
[email protected]726985e22009-06-18 21:09:281349 string16 method = request.httpMethod();
1350 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291351 params.is_post = true;
1352
[email protected]c2a797d2009-09-21 16:46:321353 // Save some histogram data so we can compute the average memory used per
1354 // page load of the glyphs.
1355 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1356 webkit_glue::GetGlyphPageCount());
1357
[email protected]15cf526b2010-02-12 06:33:491358 // This message needs to be sent before any of allowScripts(),
1359 // allowImages(), allowPlugins() is called for the new page, so that when
1360 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1361 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291362 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1363 } else {
1364 // Subframe navigation: the type depends on whether this navigation
1365 // generated a new session history entry. When they do generate a session
1366 // history entry, it means the user initiated the navigation and we should
1367 // mark it as such. This test checks if this is the first time UpdateURL
1368 // has been called since WillNavigateToURL was called to initiate the load.
1369 if (page_id_ > last_page_id_sent_to_browser_)
1370 params.transition = PageTransition::MANUAL_SUBFRAME;
1371 else
1372 params.transition = PageTransition::AUTO_SUBFRAME;
1373
initial.commit09911bf2008-07-26 23:55:291374 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1375 }
1376
1377 last_page_id_sent_to_browser_ =
1378 std::max(last_page_id_sent_to_browser_, page_id_);
1379
1380 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101381 // we don't want the transition type to persist. Just clear it.
1382 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501383
[email protected]c7287a92009-11-04 20:06:151384 if (accessibility_.get()) {
[email protected]b3df5a42010-05-11 14:31:091385 accessibility_->clear();
[email protected]17455962010-02-24 01:39:351386 accessibility_.reset();
[email protected]266eb6f2008-09-30 23:56:501387 }
initial.commit09911bf2008-07-26 23:55:291388}
1389
1390// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171391void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291392 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171393 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171394 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171395 routing_id_,
1396 page_id_,
1397 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1398 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171399 }
initial.commit09911bf2008-07-26 23:55:291400}
1401
1402void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401403 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291404 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271405 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291406 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301407 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291408 last_encoding_name_ = encoding_name;
1409
[email protected]e38f40152008-09-12 23:08:301410 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291411 }
1412}
1413
[email protected]f4d34b52008-11-24 23:05:011414// Sends the previous session history state to the browser so it will be saved
1415// before we navigate to a new page. This must be called *before* the page ID
1416// has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291417void RenderView::UpdateSessionHistory(WebFrame* frame) {
1418 // If we have a valid page ID at this point, then it corresponds to the page
1419 // we are navigating away from. Otherwise, this is the first navigation, so
1420 // there is no past session history to record.
1421 if (page_id_ == -1)
1422 return;
1423
[email protected]ca948a22009-06-25 19:36:171424 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271425 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171426 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291427 return;
[email protected]ca948a22009-06-25 19:36:171428
1429 Send(new ViewHostMsg_UpdateState(
1430 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291431}
1432
[email protected]3d9689372009-09-10 04:29:171433void RenderView::OpenURL(
1434 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1435 Send(new ViewHostMsg_OpenURL(
1436 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1437}
1438
[email protected]79dbc662009-09-04 05:42:511439// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291440
initial.commit09911bf2008-07-26 23:55:291441void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281442 const WebURLRequest& failed_request,
1443 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291444 const std::string& html,
1445 bool replace) {
[email protected]726985e22009-06-18 21:09:281446 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291447
1448 std::string alt_html;
1449 if (html.empty()) {
1450 // Use a local error page.
1451 int resource_id;
1452 DictionaryValue error_strings;
[email protected]726985e22009-06-18 21:09:281453 if (error.reason == net::ERR_CACHE_MISS &&
1454 EqualsASCII(failed_request.httpMethod(), "POST")) {
initial.commit09911bf2008-07-26 23:55:291455 GetFormRepostErrorValues(failed_url, &error_strings);
1456 resource_id = IDR_ERROR_NO_DETAILS_HTML;
1457 } else {
1458 GetLocalizedErrorValues(error, &error_strings);
1459 resource_id = IDR_NET_ERROR_HTML;
1460 }
initial.commit09911bf2008-07-26 23:55:291461
1462 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1463 } else {
1464 alt_html = html;
1465 }
1466
[email protected]dd7daa82009-08-10 05:46:451467 frame->loadHTMLString(alt_html,
[email protected]e6f546c32009-07-01 17:12:551468 GURL(kUnreachableWebDataURL),
1469 failed_url,
1470 replace);
initial.commit09911bf2008-07-26 23:55:291471}
1472
[email protected]7ccddb8c2009-08-04 17:36:551473void RenderView::BindDOMAutomationController(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291474 dom_automation_controller_.set_message_sender(this);
1475 dom_automation_controller_.set_routing_id(routing_id_);
[email protected]7ccddb8c2009-08-04 17:36:551476 dom_automation_controller_.BindToJavascript(frame,
initial.commit09911bf2008-07-26 23:55:291477 L"domAutomationController");
1478}
1479
initial.commit09911bf2008-07-26 23:55:291480bool RenderView::RunJavaScriptMessage(int type,
1481 const std::wstring& message,
1482 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071483 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291484 std::wstring* result) {
1485 bool success = false;
1486 std::wstring result_temp;
1487 if (!result)
1488 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291489
[email protected]12636df2009-09-28 22:32:211490 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1491 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291492 return success;
1493}
1494
[email protected]c1f50aa2010-02-18 03:46:571495bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1496 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1497 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1498 // it is particularly important that we do not call willEnterModalLoop as
1499 // that would defer resource loads for the dialog itself.
1500 if (RenderThread::current()) // Will be NULL during unit tests.
1501 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1502
1503 message->EnableMessagePumping(); // Runs a nested message loop.
1504 return Send(message);
1505}
1506
initial.commit09911bf2008-07-26 23:55:291507void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
1508 if (!osd_url.is_empty())
1509 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
1510 autodetected));
1511}
1512
[email protected]95056b582010-02-18 01:29:241513void RenderView::OnAutoFillSuggestionsReturned(
1514 int query_id,
[email protected]8f6e6582010-04-09 02:03:071515 const std::vector<string16>& values,
[email protected]1cf47dd52010-06-10 22:41:201516 const std::vector<string16>& labels) {
[email protected]95056b582010-02-18 01:29:241517 if (webview() && query_id == autofill_query_id_) {
[email protected]1cf47dd52010-06-10 22:41:201518 std::vector<string16> v(values);
1519 std::vector<string16> l(labels);
[email protected]33bd60f2010-07-07 17:50:581520 int separator_index = -1;
[email protected]631ec052010-06-13 22:26:301521
1522 // The form has been auto-filled, so give the user the chance to clear the
[email protected]33bd60f2010-07-07 17:50:581523 // form. Append the 'Clear form' menu item.
[email protected]631ec052010-06-13 22:26:301524 if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) {
[email protected]33bd60f2010-07-07 17:50:581525 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM));
[email protected]631ec052010-06-13 22:26:301526 l.push_back(string16());
[email protected]33bd60f2010-07-07 17:50:581527 suggestions_clear_index_ = v.size() - 1;
1528 separator_index = values.size();
[email protected]631ec052010-06-13 22:26:301529 }
1530
[email protected]33bd60f2010-07-07 17:50:581531 size_t labeled_item_count = 0;
1532 for (size_t i = 0; i < l.size(); ++i) {
1533 if (!l[i].empty())
1534 labeled_item_count++;
1535 }
[email protected]cf28ec52010-04-09 22:56:341536
[email protected]33bd60f2010-07-07 17:50:581537 // Only include "AutoFill Options" special menu item if we have labeled
1538 // items.
1539 if (labeled_item_count > 0) {
1540 // Append the 'AutoFill Options...' menu item.
1541 v.push_back(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS));
1542 l.push_back(string16());
1543 suggestions_options_index_ = v.size() - 1;
1544 separator_index = values.size();
1545 }
1546
1547 // Send to WebKit for display.
1548 if (!v.empty())
1549 webview()->applyAutoFillSuggestions(
1550 autofill_query_node_, v, l, separator_index);
[email protected]acca2a1f2009-10-16 03:53:391551 }
[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]03f57072010-07-14 17:36:081801void RenderView::textFieldDidBeginEditing(
1802 const WebKit::WebInputElement& element) {
1803#if defined(WEBKIT_BUG_41283_IS_FIXED)
1804 password_autocomplete_manager_.TextFieldDidBeginEditing(element);
1805#endif
1806}
1807
1808void RenderView::textFieldDidEndEditing(
1809 const WebKit::WebInputElement& element) {
1810#if defined(WEBKIT_BUG_41283_IS_FIXED)
1811 password_autocomplete_manager_.TextFieldDidEndEditing(element);
1812#endif
1813}
1814
1815void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) {
1816#if defined(WEBKIT_BUG_41283_IS_FIXED)
1817 password_autocomplete_manager_.TextDidChangeInTextField(element);
1818#endif
1819}
1820
1821void RenderView::textFieldDidReceiveKeyDown(
1822 const WebKit::WebInputElement& element,
1823 const WebKit::WebKeyboardEvent& event) {
1824#if defined(WEBKIT_BUG_41283_IS_FIXED)
1825 password_autocomplete_manager_.TextFieldHandlingKeyDown(element, event);
1826#endif
1827}
1828
[email protected]b2528b72009-09-24 06:57:101829bool RenderView::handleCurrentKeyboardEvent() {
1830 if (edit_commands_.empty())
1831 return false;
1832
[email protected]26aa0482009-09-30 16:55:271833 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101834 if (!frame)
1835 return false;
1836
1837 EditCommands::iterator it = edit_commands_.begin();
1838 EditCommands::iterator end = edit_commands_.end();
1839
[email protected]507b33ea2009-09-29 03:56:511840 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101841 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331842 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1843 // key (but it's the exception). Once one edit command is not executed, it
1844 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101845 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1846 WebString::fromUTF8(it->value)))
1847 break;
[email protected]507b33ea2009-09-29 03:56:511848 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101849 }
1850
[email protected]507b33ea2009-09-29 03:56:511851 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101852}
1853
[email protected]2a3a7762009-10-19 19:17:321854void RenderView::spellCheck(const WebString& text,
1855 int& misspelled_offset,
1856 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:561857 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:461858
[email protected]85c55dc2009-11-06 03:05:461859 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:171860 RenderThread* thread = RenderThread::current();
1861 // Will be NULL during unit tests.
1862 if (thread) {
[email protected]c27324b2009-11-19 22:44:291863 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:171864 word.c_str(), word.size(), document_tag_,
1865 &misspelled_offset, &misspelled_length, NULL);
1866 }
[email protected]1dbafaf72009-09-23 19:43:561867}
1868
1869WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321870 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561871 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:261872 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:561873 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:171874 RenderThread* thread = RenderThread::current();
1875 // Will be NULL during unit tests.
1876 if (thread) {
1877 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:291878 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:171879 word, document_tag_);
1880 }
[email protected]1dbafaf72009-09-23 19:43:561881 }
[email protected]2a3a7762009-10-19 19:17:321882 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:561883}
1884
[email protected]c49085c72009-10-02 16:28:561885void RenderView::showSpellingUI(bool show) {
1886 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
1887}
1888
[email protected]8922e1f2009-10-03 05:01:261889bool RenderView::isShowingSpellingUI() {
1890 return spelling_panel_visible_;
1891}
1892
[email protected]1dbafaf72009-09-23 19:43:561893void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:321894 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
1895 word));
[email protected]1dbafaf72009-09-23 19:43:561896}
1897
[email protected]a1128322009-10-06 18:38:461898bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351899 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471900 WebFileChooserCompletion* chooser_completion) {
1901 ViewHostMsg_RunFileChooser_Params ipc_params;
1902 ipc_params.mode = params.multiSelect ?
1903 ViewHostMsg_RunFileChooser_Params::OpenMultiple :
1904 ViewHostMsg_RunFileChooser_Params::Open;
1905 ipc_params.title = params.title;
1906 ipc_params.default_file_name =
1907 webkit_glue::WebStringToFilePath(params.initialValue);
1908
1909 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461910}
1911
[email protected]48c9cf2d2009-09-16 16:47:521912void RenderView::runModalAlertDialog(
1913 WebFrame* frame, const WebString& message) {
1914 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
1915 UTF16ToWideHack(message),
1916 std::wstring(),
1917 frame->url(),
1918 NULL);
1919}
1920
1921bool RenderView::runModalConfirmDialog(
1922 WebFrame* frame, const WebString& message) {
1923 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
1924 UTF16ToWideHack(message),
1925 std::wstring(),
1926 frame->url(),
1927 NULL);
1928}
1929
1930bool RenderView::runModalPromptDialog(
1931 WebFrame* frame, const WebString& message, const WebString& default_value,
1932 WebString* actual_value) {
1933 std::wstring result;
1934 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
1935 UTF16ToWideHack(message),
1936 UTF16ToWideHack(default_value),
1937 frame->url(),
1938 &result);
1939 if (ok)
1940 actual_value->assign(WideToUTF16Hack(result));
1941 return ok;
1942}
1943
1944bool RenderView::runModalBeforeUnloadDialog(
1945 WebFrame* frame, const WebString& message) {
1946 bool success = false;
1947 // This is an ignored return value, but is included so we can accept the same
1948 // response as RunJavaScriptMessage.
1949 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211950 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521951 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211952 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521953 return success;
1954}
1955
[email protected]79e37442009-10-09 18:17:441956void RenderView::showContextMenu(
1957 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291958 ContextMenuParams params = ContextMenuParams(data);
1959 if (!params.misspelled_word.empty() && RenderThread::current()) {
1960 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:041961 bool spelled_right = RenderThread::current()->spellchecker()->
1962 SpellCheckWord(
1963 params.misspelled_word.c_str(), params.misspelled_word.size(),
1964 document_tag_,
1965 &misspelled_offset, &misspelled_length,
1966 &params.dictionary_suggestions);
1967 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:291968 params.misspelled_word.clear();
1969 }
1970
1971 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441972}
1973
[email protected]52f139e2c2010-06-11 16:56:091974bool RenderView::supportsFullscreen() {
1975 return CommandLine::ForCurrentProcess()->HasSwitch(
1976 switches::kEnableVideoFullscreen);
1977}
1978
1979void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1980 NOTIMPLEMENTED();
1981}
1982
1983void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1984 NOTIMPLEMENTED();
1985}
1986
[email protected]48c9cf2d2009-09-16 16:47:521987void RenderView::setStatusText(const WebString& text) {
1988}
1989
[email protected]163f8242009-10-30 20:19:551990void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581991 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521992 if (latest_url == target_url_)
1993 return;
[email protected]163f8242009-10-30 20:19:551994
[email protected]48c9cf2d2009-09-16 16:47:521995 // Tell the browser to display a destination link.
1996 if (target_url_status_ == TARGET_INFLIGHT ||
1997 target_url_status_ == TARGET_PENDING) {
1998 // If we have a request in-flight, save the URL to be sent when we
1999 // receive an ACK to the in-flight request. We can happily overwrite
2000 // any existing pending sends.
2001 pending_target_url_ = latest_url;
2002 target_url_status_ = TARGET_PENDING;
2003 } else {
2004 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2005 target_url_ = latest_url;
2006 target_url_status_ = TARGET_INFLIGHT;
2007 }
2008}
2009
[email protected]1c57b7b2010-07-12 17:38:102010bool RenderView::IsPageTranslatable(WebKit::WebDocument* document) {
2011 std::vector<WebKit::WebElement> meta_elements;
2012 webkit_glue::GetMetaElementsWithName(document, ASCIIToUTF16("google"),
2013 &meta_elements);
2014 std::vector<WebKit::WebElement>::const_iterator iter;
2015 for (iter = meta_elements.begin(); iter != meta_elements.end(); ++iter) {
2016 WebString attribute = iter->getAttribute("value");
2017 if (attribute.isNull()) // We support both 'value' and 'content'.
2018 attribute = iter->getAttribute("content");
2019 if (attribute.isNull())
2020 continue;
2021 if (LowerCaseEqualsASCII(attribute, "notranslate"))
2022 return false;
2023 }
2024 return true;
2025}
2026
[email protected]882daa92009-11-05 16:31:312027void RenderView::StartNavStateSyncTimerIfNecessary() {
2028 int delay;
2029 if (send_content_state_immediately_)
2030 delay = 0;
2031 else if (is_hidden())
2032 delay = kDelaySecondsForContentStateSyncHidden;
2033 else
2034 delay = kDelaySecondsForContentStateSync;
2035
2036 if (nav_state_sync_timer_.IsRunning()) {
2037 // The timer is already running. If the delay of the timer maches the amount
2038 // we want to delay by, then return. Otherwise stop the timer so that it
2039 // gets started with the right delay.
2040 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2041 return;
2042 nav_state_sync_timer_.Stop();
2043 }
2044
2045 nav_state_sync_timer_.Start(
2046 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2047}
2048
[email protected]163f8242009-10-30 20:19:552049void RenderView::setMouseOverURL(const WebURL& url) {
2050 mouse_over_url_ = GURL(url);
2051 UpdateTargetURL(mouse_over_url_, focus_url_);
2052}
2053
2054void RenderView::setKeyboardFocusURL(const WebURL& url) {
2055 focus_url_ = GURL(url);
2056 UpdateTargetURL(focus_url_, mouse_over_url_);
2057}
2058
[email protected]48c9cf2d2009-09-16 16:47:522059void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2060 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2061 hint));
2062}
2063
[email protected]c27ae592010-03-18 15:24:412064void RenderView::startDragging(const WebDragData& data,
2065 WebDragOperationsMask mask,
2066 const WebImage& image,
2067 const WebPoint& imageOffset) {
2068#if WEBKIT_USING_SKIA
2069 SkBitmap bitmap(image.getSkBitmap());
2070#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332071 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412072#endif
2073
[email protected]48c9cf2d2009-09-16 16:47:522074 Send(new ViewHostMsg_StartDragging(routing_id_,
2075 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412076 mask,
2077 bitmap,
2078 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522079}
2080
[email protected]28b92df2009-09-25 17:35:452081bool RenderView::acceptsLoadDrops() {
2082 return renderer_preferences_.can_accept_load_drops;
2083}
2084
[email protected]48c9cf2d2009-09-16 16:47:522085void RenderView::focusNext() {
2086 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2087}
2088
2089void RenderView::focusPrevious() {
2090 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2091}
2092
[email protected]08e9e132010-06-01 16:58:492093void RenderView::focusedNodeChanged(const WebNode& node) {
2094 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_));
2095}
2096
[email protected]48c9cf2d2009-09-16 16:47:522097void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522098 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2099}
2100
2101int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002102 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522103}
2104
2105int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002106 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522107}
2108
[email protected]c4e98902010-06-01 10:20:142109void RenderView::didUpdateInspectorSetting(const WebString& key,
2110 const WebString& value) {
2111 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2112 key.utf8(),
2113 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262114}
2115
[email protected]acca2a1f2009-10-16 03:53:392116void RenderView::queryAutofillSuggestions(const WebNode& node,
2117 const WebString& name,
2118 const WebString& value) {
2119 static int query_counter = 0;
2120 autofill_query_id_ = query_counter++;
2121 autofill_query_node_ = node;
[email protected]e250e492010-04-06 21:35:362122
2123 const WebFormControlElement& element =
[email protected]f40b49e2010-05-05 22:38:452124 node.toConst<WebFormControlElement>();
[email protected]e250e492010-04-06 21:35:362125
[email protected]dede9342010-04-12 16:51:112126 webkit_glue::FormField field;
2127 FormManager::WebFormControlElementToFormField(element, true, &field);
[email protected]e250e492010-04-06 21:35:362128
[email protected]72eb2da2010-04-14 00:31:082129 // WebFormControlElementToFormField does not scrape the DOM for the field
2130 // label, so find the label here.
2131 // TODO(jhawkins): Add form and field identities so we can use the cached form
2132 // data in FormManager.
2133 field.set_label(FormManager::LabelForElement(element));
2134
[email protected]25bacf32010-06-24 23:23:162135 bool form_autofilled = form_manager_.FormWithNodeIsAutoFilled(node);
[email protected]1cf47dd52010-06-10 22:41:202136 Send(new ViewHostMsg_QueryFormFieldAutoFill(
[email protected]25bacf32010-06-24 23:23:162137 routing_id_, autofill_query_id_, form_autofilled, field));
[email protected]acca2a1f2009-10-16 03:53:392138}
2139
2140void RenderView::removeAutofillSuggestions(const WebString& name,
2141 const WebString& value) {
[email protected]1cf47dd52010-06-10 22:41:202142 Send(new ViewHostMsg_RemoveAutocompleteEntry(routing_id_, name, value));
[email protected]acca2a1f2009-10-16 03:53:392143}
2144
[email protected]18ca9a6b2010-06-02 19:05:182145void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2146 const WebKit::WebString& value,
2147 const WebKit::WebString& label) {
[email protected]1cf47dd52010-06-10 22:41:202148 // DEPRECATED
2149 didAcceptAutoFillSuggestion(node, value, label, -1);
2150}
2151
2152void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2153 const WebKit::WebString& value,
2154 const WebKit::WebString& label,
2155 unsigned index) {
[email protected]33bd60f2010-07-07 17:50:582156 if (suggestions_options_index_ != -1 &&
2157 index == static_cast<unsigned>(suggestions_options_index_)) {
2158 // User selected 'AutoFill Options'.
[email protected]1cf47dd52010-06-10 22:41:202159 Send(new ViewHostMsg_ShowAutoFillDialog(routing_id_));
[email protected]33bd60f2010-07-07 17:50:582160 } else if (suggestions_clear_index_ != -1 &&
2161 index == static_cast<unsigned>(suggestions_clear_index_)) {
2162 // User selected 'Clear form'.
[email protected]631ec052010-06-13 22:26:302163 // The form has been auto-filled, so give the user the chance to clear the
2164 // form.
2165 form_manager_.ClearFormWithNode(node);
[email protected]33bd60f2010-07-07 17:50:582166 } else if (form_manager_.FormWithNodeIsAutoFilled(node) || label.isEmpty()) {
2167 // User selected an unlabeled menu item, so we fill directly.
[email protected]785710ca2010-06-30 00:40:142168 WebInputElement element = node.toConst<WebInputElement>();
2169 element.setValue(value);
[email protected]33bd60f2010-07-07 17:50:582170
2171 WebFrame* webframe = node.document().frame();
2172 if (webframe) {
2173 webframe->notifiyPasswordListenerOfAutocomplete(element);
2174 }
[email protected]631ec052010-06-13 22:26:302175 } else {
[email protected]785710ca2010-06-30 00:40:142176 // Fill the values for the whole form.
[email protected]1cf47dd52010-06-10 22:41:202177 QueryAutoFillFormData(node, value, label, AUTOFILL_FILL);
[email protected]631ec052010-06-13 22:26:302178 }
[email protected]1cf47dd52010-06-10 22:41:202179
[email protected]33bd60f2010-07-07 17:50:582180 suggestions_clear_index_ = -1;
2181 suggestions_options_index_ = -1;
[email protected]18ca9a6b2010-06-02 19:05:182182}
[email protected]c83641732010-02-20 01:04:482183
[email protected]18ca9a6b2010-06-02 19:05:182184void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2185 const WebKit::WebString& value,
2186 const WebKit::WebString& label) {
2187 didClearAutoFillSelection(node);
2188 QueryAutoFillFormData(node, value, label, AUTOFILL_PREVIEW);
2189}
2190
2191void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]45c6e532010-03-15 23:51:242192 webkit_glue::FormData form;
[email protected]18ca9a6b2010-06-02 19:05:182193 const WebFormControlElement element = node.toConst<WebFormControlElement>();
[email protected]b1438212010-04-03 00:30:592194 if (!form_manager_.FindFormWithFormControlElement(
[email protected]da592272010-04-14 20:08:492195 element, FormManager::REQUIRE_NONE, &form))
[email protected]c83641732010-02-20 01:04:482196 return;
[email protected]18ca9a6b2010-06-02 19:05:182197 form_manager_.ClearPreviewedForm(form);
[email protected]c83641732010-02-20 01:04:482198}
2199
[email protected]03f57072010-07-14 17:36:082200void RenderView::didAcceptAutocompleteSuggestion(
2201 const WebKit::WebInputElement& user_element) {
2202#if defined(WEBKIT_BUG_41283_IS_FIXED)
2203 bool result = password_autocomplete_manager_.FillPassword(user_element);
2204 // Since this user name was selected from a suggestion list, we should always
2205 // have password for it.
2206 DCHECK(result);
2207#endif
2208}
2209
[email protected]79dbc662009-09-04 05:42:512210// WebKit::WebWidgetClient ----------------------------------------------------
2211
initial.commit09911bf2008-07-26 23:55:292212// We are supposed to get a single call to Show for a newly created RenderView
2213// that was created via RenderView::CreateWebView. So, we wait until this
2214// point to dispatch the ShowView message.
2215//
2216// This method provides us with the information about how to display the newly
2217// created RenderView (i.e., as a constrained popup or as a new tab).
2218//
[email protected]4873c7d2009-07-16 06:36:282219void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292220 DCHECK(!did_show_) << "received extraneous Show call";
2221 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2222
2223 if (did_show_)
2224 return;
2225 did_show_ = true;
2226
[email protected]28295ec2009-10-16 05:34:332227 // Force new windows to a popup if they were not opened with a user gesture.
2228 if (!opened_by_user_gesture_) {
2229 // We exempt background tabs for compat with older versions of Chrome.
2230 // TODO(darin): This seems bogus. These should have a user gesture, so
2231 // we probably don't need this check.
2232 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2233 policy = WebKit::WebNavigationPolicyNewPopup;
2234 }
2235
initial.commit09911bf2008-07-26 23:55:292236 // NOTE: initial_pos_ may still have its default values at this point, but
2237 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2238 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282239 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2240 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292241 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242242 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292243}
2244
[email protected]4873c7d2009-07-16 06:36:282245void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132246 // Cancel pending translations so that the translate_helper_ does not attempt
2247 // to access the WebView.
2248 translate_helper_.CancelPendingTranslation();
2249
[email protected]e8345242010-05-06 03:00:402250 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282251 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312252}
2253
[email protected]4873c7d2009-07-16 06:36:282254void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292255 DCHECK(did_show_) << "should already have shown the view";
2256
[email protected]c1f50aa2010-02-18 03:46:572257 // We must keep WebKit's shared timer running in this case in order to allow
2258 // showModalDialog to function properly.
2259 //
2260 // TODO(darin): WebKit should really be smarter about suppressing events and
2261 // timers so that we do not need to manage the shared timer in such a heavy
2262 // handed manner.
2263 //
2264 if (RenderThread::current()) // Will be NULL during unit tests.
2265 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2266
[email protected]12636df2009-09-28 22:32:212267 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292268}
2269
[email protected]3d9689372009-09-10 04:29:172270// WebKit::WebFrameClient -----------------------------------------------------
2271
2272WebPlugin* RenderView::createPlugin(
2273 WebFrame* frame, const WebPluginParams& params) {
[email protected]4e0616e2010-05-28 14:55:532274 FilePath path;
2275 std::string actual_mime_type;
2276 render_thread_->Send(new ViewHostMsg_GetPluginPath(
2277 params.url, frame->top()->url(), params.mimeType.utf8(), &path,
2278 &actual_mime_type));
2279 if (path.value().empty())
2280 return NULL;
2281
2282 if (actual_mime_type.empty())
2283 actual_mime_type = params.mimeType.utf8();
2284
[email protected]53af1d62010-05-14 03:40:262285 scoped_refptr<pepper::PluginModule> pepper_module =
[email protected]4e0616e2010-05-28 14:55:532286 PepperPluginRegistry::GetInstance()->GetModule(path);
[email protected]53af1d62010-05-14 03:40:262287 if (pepper_module) {
[email protected]4e0616e2010-05-28 14:55:532288 return new pepper::WebPluginImpl(pepper_module, params,
[email protected]b4f68dea2010-05-13 06:03:172289 pepper_delegate_.AsWeakPtr());
2290 }
[email protected]4e0616e2010-05-28 14:55:532291
2292 return new webkit_glue::WebPluginImpl(frame, params, path, actual_mime_type,
2293 AsWeakPtr());
[email protected]3d9689372009-09-10 04:29:172294}
2295
2296WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562297 WebApplicationCacheHostImpl* appcache_host =
2298 WebApplicationCacheHostImpl::FromFrame(frame);
2299 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2300 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2301 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172302}
2303
[email protected]9c00f002009-11-05 22:37:422304WebSharedWorker* RenderView::createSharedWorker(
2305 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372306 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422307
[email protected]30447b62009-11-13 01:13:372308 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512309 bool exists = false;
[email protected]30447b62009-11-13 01:13:372310 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512311 ViewHostMsg_CreateWorker_Params params;
2312 params.url = url;
2313 params.is_shared = true;
2314 params.name = name;
2315 params.document_id = document_id;
2316 params.render_view_route_id = routing_id_;
2317 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232318 params.parent_appcache_host_id = 0;
2319 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372320 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512321 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372322 if (url_mismatch) {
2323 return NULL;
2324 } else {
2325 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492326 document_id,
[email protected]6de0bcf2010-02-17 22:00:512327 exists,
[email protected]30447b62009-11-13 01:13:372328 route_id,
2329 routing_id_);
2330 }
[email protected]9c00f002009-11-05 22:37:422331}
2332
[email protected]3d9689372009-09-10 04:29:172333WebMediaPlayer* RenderView::createMediaPlayer(
2334 WebFrame* frame, WebMediaPlayerClient* client) {
2335 scoped_refptr<media::FilterFactoryCollection> factory =
2336 new media::FilterFactoryCollection();
2337 // Add in any custom filter factories first.
2338 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2339 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2340 // Add the chrome specific audio renderer.
2341 factory->AddFactory(
2342 AudioRendererImpl::CreateFactory(audio_message_filter()));
2343 }
2344
[email protected]80f584d92010-01-21 03:59:042345 WebApplicationCacheHostImpl* appcache_host =
2346 WebApplicationCacheHostImpl::FromFrame(frame);
2347
[email protected]3d9689372009-09-10 04:29:172348 // TODO(hclam): obtain the following parameters from |client|.
2349 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory =
2350 new webkit_glue::MediaResourceLoaderBridgeFactory(
[email protected]810a52ef2010-01-08 01:22:152351 GURL(), // referrer
2352 "null", // frame origin
2353 "null", // main_frame_origin
[email protected]3d9689372009-09-10 04:29:172354 base::GetCurrentProcId(),
[email protected]80f584d92010-01-21 03:59:042355 appcache_host ? appcache_host->host_id() : appcache::kNoHostId,
[email protected]3d9689372009-09-10 04:29:172356 routing_id());
2357
[email protected]0436b9a2009-10-23 00:23:052358 // A simple data source that keeps all data in memory.
2359 media::FilterFactory* simple_data_source_factory =
2360 webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(),
2361 bridge_factory);
2362 // A sophisticated data source that does memory caching.
2363 media::FilterFactory* buffered_data_source_factory =
2364 webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(),
2365 bridge_factory);
2366 if (cmd_line->HasSwitch(switches::kSimpleDataSource)) {
2367 factory->AddFactory(simple_data_source_factory);
2368 factory->AddFactory(buffered_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172369 } else {
[email protected]0436b9a2009-10-23 00:23:052370 factory->AddFactory(buffered_data_source_factory);
2371 factory->AddFactory(simple_data_source_factory);
[email protected]3d9689372009-09-10 04:29:172372 }
[email protected]8400e032010-02-26 18:50:112373
2374 webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL;
2375 if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) {
2376 factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_);
2377 } else {
[email protected]b57509eb2010-03-30 01:26:282378 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2379 factory_factory =
2380 new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging);
[email protected]8400e032010-02-26 18:50:112381 }
2382
2383 return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory);
[email protected]3d9689372009-09-10 04:29:172384}
2385
[email protected]035545f2010-04-09 13:10:212386WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2387 WebFrame* frame, WebApplicationCacheHostClient* client) {
2388 return new RendererWebApplicationCacheHostImpl(
2389 FromWebView(frame->view()), client,
2390 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2391}
2392
[email protected]b921cfd22010-02-25 16:57:512393WebCookieJar* RenderView::cookieJar() {
2394 return &cookie_jar_;
2395}
2396
[email protected]3d9689372009-09-10 04:29:172397void RenderView::willClose(WebFrame* frame) {
2398 if (!frame->parent()) {
2399 const GURL& url = frame->url();
2400 if (url.SchemeIs("http") || url.SchemeIs("https"))
2401 DumpLoadHistograms();
2402 }
[email protected]fa7b6b542009-11-03 05:02:302403
2404 WebDataSource* ds = frame->dataSource();
2405 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2406 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162407
2408 form_manager_.ResetFrame(frame);
[email protected]3d9689372009-09-10 04:29:172409}
2410
[email protected]684e4a42010-01-30 06:44:112411bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]8934a3b2010-02-25 00:34:002412 if (!enabled_per_settings)
2413 return false;
[email protected]c21f1d52010-03-04 03:19:432414 return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
[email protected]684e4a42010-01-30 06:44:112415}
2416
2417bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402418 if (enabled_per_settings &&
2419 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2420 return true;
2421
2422 if (IsWhitelistedForContentSettings(frame))
2423 return true;
2424
2425 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES);
2426 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112427}
2428
[email protected]3d9689372009-09-10 04:29:172429void RenderView::loadURLExternally(
2430 WebFrame* frame, const WebURLRequest& request,
2431 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592432 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2433 if (policy == WebKit::WebNavigationPolicyDownload) {
2434 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2435 } else {
2436 OpenURL(request.url(), referrer, policy);
2437 }
[email protected]3d9689372009-09-10 04:29:172438}
2439
2440WebNavigationPolicy RenderView::decidePolicyForNavigation(
2441 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222442 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172443 // Webkit is asking whether to navigate to a new URL.
2444 // This is fine normally, except if we're showing UI from one security
2445 // context and they're trying to navigate to a different context.
2446 const GURL& url = request.url();
2447
2448 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302449 // navigations.
[email protected]8079b362010-05-07 18:37:452450 if (renderer_preferences_.browser_handles_top_level_requests &&
2451 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192452 last_top_level_navigation_page_id_ = page_id_;
2453 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2454 OpenURL(url, referrer, default_policy);
2455 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172456 }
2457
2458 // A content initiated navigation may have originated from a link-click,
2459 // script, drag-n-drop operation, etc.
2460 bool is_content_initiated =
2461 NavigationState::FromDataSource(frame->provisionalDataSource())->
2462 is_content_initiated();
2463
2464 // We only care about navigations that are within the current tab (as opposed
2465 // to, for example, opening a new window).
2466 // But we sometimes navigate to about:blank to clear a tab, and we want to
2467 // still allow that.
2468 if (default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2469 is_content_initiated && frame->parent() == NULL &&
[email protected]c240ace2010-06-16 18:31:532470 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]3d9689372009-09-10 04:29:172471 !url.SchemeIs(chrome::kAboutScheme)) {
2472 // When we received such unsolicited navigations, we sometimes want to
2473 // punt them up to the browser to handle.
[email protected]3a8eecb2010-04-22 23:56:302474 if (CrossesExtensionExtents(frame, url) ||
2475 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172476 frame->isViewSourceModeEnabled() ||
[email protected]918059b2010-05-25 17:08:422477 url.SchemeIs(chrome::kViewSourceScheme)) {
[email protected]3d9689372009-09-10 04:29:172478 OpenURL(url, GURL(), default_policy);
2479 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2480 }
[email protected]8079b362010-05-07 18:37:452481
2482 // We forward navigations from extensions to the browser if they are
2483 // top-level events, even if the browser hasn't expressed interest.
2484 //
2485 // Note that we've already forwarded cross-extension extents navigations
2486 // above.
2487 if (BindingsPolicy::is_extension_enabled(enabled_bindings_) &&
[email protected]c240ace2010-06-16 18:31:532488 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]8079b362010-05-07 18:37:452489 OpenURL(url, GURL(), default_policy);
2490 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2491 }
[email protected]3d9689372009-09-10 04:29:172492 }
2493
2494 // Detect when a page is "forking" a new tab that can be safely rendered in
2495 // its own process. This is done by sites like Gmail that try to open links
2496 // in new windows without script connections back to the original page. We
2497 // treat such cases as browser navigations (in which we will create a new
2498 // renderer for a cross-site navigation), rather than WebKit navigations.
2499 //
2500 // We use the following heuristic to decide whether to fork a new page in its
2501 // own process:
2502 // The parent page must open a new tab to about:blank, set the new tab's
2503 // window.opener to null, and then redirect the tab to a cross-site URL using
2504 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462505 //
2506 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2507 // (see below).
[email protected]3d9689372009-09-10 04:29:172508 bool is_fork =
2509 // Must start from a tab showing about:blank, which is later redirected.
[email protected]e0d481582009-09-15 21:06:252510 GURL(frame->url()) == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172511 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522512 historyBackListCount() < 1 &&
2513 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172514 // The parent page must have set the child's window.opener to null before
2515 // redirecting to the desired URL.
2516 frame->opener() == NULL &&
2517 // Must be a top-level frame.
2518 frame->parent() == NULL &&
2519 // Must not have issued the request from this page.
2520 is_content_initiated &&
2521 // Must be targeted at the current tab.
2522 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2523 // Must be a JavaScript navigation, which appears as "other".
2524 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462525
2526 // Recognize if this navigation is from a link with rel=noreferrer and
2527 // target=_blank attributes, in which case the opener will be suppressed. If
2528 // so, it is safe to load cross-site pages in a separate process, so we
2529 // should let the browser handle it.
2530 bool is_noreferrer_and_blank_target =
2531 // Frame should be top level and not yet navigated.
2532 frame->parent() == NULL &&
2533 frame->url().isEmpty() &&
2534 historyBackListCount() < 1 &&
2535 historyForwardListCount() < 1 &&
2536 // Links with rel=noreferrer will have no Referer field, and their
2537 // resulting frame will have its window.opener suppressed.
2538 // TODO(creis): should add a request.httpReferrer() method to help avoid
2539 // typos on the unusual spelling of Referer.
2540 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2541 opener_suppressed_ &&
2542 frame->opener() == NULL &&
2543 // Links with target=_blank will have no name.
2544 frame->name().isNull() &&
2545 // Another frame (with a non-empty creator) should have initiated the
2546 // request, targeted at this frame.
2547 !creator_url_.is_empty() &&
2548 is_content_initiated &&
2549 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2550 type == WebKit::WebNavigationTypeOther;
2551
2552 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172553 // Open the URL via the browser, not via WebKit.
2554 OpenURL(url, GURL(), default_policy);
2555 return WebKit::WebNavigationPolicyIgnore;
2556 }
2557
2558 return default_policy;
2559}
2560
[email protected]6069da8c2009-10-20 20:33:492561bool RenderView::canHandleRequest(
2562 WebFrame* frame, const WebURLRequest& request) {
2563 // We allow WebKit to think that everything can be handled even though
2564 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342565 return true;
2566}
2567
[email protected]6069da8c2009-10-20 20:33:492568WebURLError RenderView::cannotHandleRequestError(
2569 WebFrame* frame, const WebURLRequest& request) {
2570 NOTREACHED(); // Since we said we can handle all requests.
2571 return WebURLError();
2572}
2573
2574WebURLError RenderView::cancelledError(
2575 WebFrame* frame, const WebURLRequest& request) {
2576 WebURLError error;
2577 error.domain = WebString::fromUTF8(net::kErrorDomain);
2578 error.reason = net::ERR_ABORTED;
2579 error.unreachableURL = request.url();
2580 return error;
[email protected]7b7a7dc2009-10-19 02:23:342581}
2582
2583void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492584 WebFrame*, const WebURLError&) {
2585 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342586}
2587
[email protected]90eeddb2010-05-06 21:06:432588void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2589 const WebKit::WebFormElement& form) {
2590 // Some login forms have onSubmit handlers that put a hash of the password
2591 // into a hidden field and then clear the password. (Issue 28910.)
2592 // This method gets called before any of those handlers run, so save away
2593 // a copy of the password in case it gets lost.
2594 NavigationState* navigation_state =
2595 NavigationState::FromDataSource(frame->dataSource());
2596 navigation_state->set_password_form_data(
2597 PasswordFormDomManager::CreatePasswordForm(form));
2598}
2599
[email protected]979c28b2009-11-07 01:30:482600void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172601 NavigationState* navigation_state =
2602 NavigationState::FromDataSource(frame->provisionalDataSource());
2603
2604 if (navigation_state->transition_type() == PageTransition::LINK)
2605 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2606
2607 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352608 WebSearchableFormData web_searchable_form_data(form);
2609 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2610 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212611 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432612 PasswordForm* password_form_data =
2613 PasswordFormDomManager::CreatePasswordForm(form);
2614 navigation_state->set_password_form_data(password_form_data);
2615
2616 // If the password has been cleared, recover it from the form contents already
2617 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
2618 // opposed to the provisionalDataSource's, which is what we're storing into
2619 // now.)
2620 if (password_form_data && password_form_data->password_value.empty()) {
2621 NavigationState* old_navigation_state =
2622 NavigationState::FromDataSource(frame->dataSource());
2623 if (old_navigation_state) {
2624 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2625 if (old_form_data && old_form_data->action == password_form_data->action)
2626 password_form_data->password_value = old_form_data->password_value;
2627 }
2628 }
[email protected]3d9689372009-09-10 04:29:172629
[email protected]b1438212010-04-03 00:30:592630 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:042631 if (FormManager::WebFormElementToFormData(
[email protected]3347bab32010-04-09 04:11:092632 form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data))
[email protected]b1438212010-04-03 00:30:592633 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]3d9689372009-09-10 04:29:172634}
2635
2636void RenderView::willPerformClientRedirect(
2637 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2638 double fire_time) {
2639 // Ignore
2640}
2641
2642void RenderView::didCancelClientRedirect(WebFrame* frame) {
2643 // Ignore
2644}
2645
2646void RenderView::didCompleteClientRedirect(
2647 WebFrame* frame, const WebURL& from) {
2648 if (!frame->parent())
2649 completed_client_redirect_src_ = from;
2650}
2651
2652void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2653 // The rest of RenderView assumes that a WebDataSource will always have a
2654 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482655 bool content_initiated = !pending_navigation_state_.get();
2656 NavigationState* state = content_initiated ?
2657 NavigationState::CreateContentInitiated() :
2658 pending_navigation_state_.release();
[email protected]4c1b6f0b2010-02-07 16:38:182659 if (content_initiated) {
2660 switch (ds->request().cachePolicy()) {
2661 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2662 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2663 break;
2664 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2665 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2666 break;
2667 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2668 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2669 break;
2670 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2671 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2672 break;
2673 }
2674 }
[email protected]fa7b6b542009-11-03 05:02:302675
2676 state->set_user_script_idle_scheduler(
2677 new UserScriptIdleScheduler(this, frame));
2678 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:172679}
2680
2681void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2682 WebDataSource* ds = frame->provisionalDataSource();
2683 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2684
2685 navigation_state->set_start_load_time(Time::Now());
2686
2687 // Update the request time if WebKit has better knowledge of it.
2688 if (navigation_state->request_time().is_null()) {
2689 double event_time = ds->triggeringEventTime();
2690 if (event_time != 0.0)
2691 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2692 }
2693
2694 bool is_top_most = !frame->parent();
2695 if (is_top_most) {
2696 navigation_gesture_ = frame->isProcessingUserGesture() ?
2697 NavigationGestureUnknown : NavigationGestureAuto;
2698
2699 // Make sure redirect tracking state is clear for the new load.
2700 completed_client_redirect_src_ = GURL();
2701 } else if (frame->parent()->isLoading()) {
2702 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002703 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172704 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2705 }
2706
2707 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
2708 routing_id_, is_top_most, ds->request().url()));
2709}
2710
2711void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2712 if (frame->parent())
2713 return;
2714 // Received a redirect on the main frame.
2715 WebDataSource* data_source = frame->provisionalDataSource();
2716 if (!data_source) {
2717 // Should only be invoked when we have a data source.
2718 NOTREACHED();
2719 return;
2720 }
2721 std::vector<GURL> redirects;
2722 GetRedirectChain(data_source, &redirects);
2723 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512724 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2725 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172726 }
2727}
2728
[email protected]40bd6582009-12-04 23:49:512729void RenderView::didFailProvisionalLoad(WebFrame* frame,
2730 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172731 // Notify the browser that we failed a provisional load with an error.
2732 //
2733 // Note: It is important this notification occur before DidStopLoading so the
2734 // SSL manager can react to the provisional load failure before being
2735 // notified the load stopped.
2736 //
2737 WebDataSource* ds = frame->provisionalDataSource();
2738 DCHECK(ds);
2739
2740 const WebURLRequest& failed_request = ds->request();
2741
2742 bool show_repost_interstitial =
2743 (error.reason == net::ERR_CACHE_MISS &&
2744 EqualsASCII(failed_request.httpMethod(), "POST"));
2745 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
2746 routing_id_, !frame->parent(), error.reason, error.unreachableURL,
2747 show_repost_interstitial));
2748
2749 // Don't display an error page if this is simply a cancelled load. Aside
2750 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2751 if (error.reason == net::ERR_ABORTED)
2752 return;
2753
2754 // Make sure we never show errors in view source mode.
2755 frame->enableViewSourceMode(false);
2756
2757 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2758
2759 // If this is a failed back/forward/reload navigation, then we need to do a
2760 // 'replace' load. This is necessary to avoid messing up session history.
2761 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2762 // as session history is concerned.
2763 //
2764 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2765 // the page id.
2766 //
2767 bool replace =
2768 navigation_state->pending_page_id() != -1 ||
2769 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2770
2771 // If we failed on a browser initiated request, then make sure that our error
2772 // page load is regarded as the same browser initiated request.
2773 if (!navigation_state->is_content_initiated()) {
2774 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2775 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002776 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172777 navigation_state->transition_type(),
2778 navigation_state->request_time()));
2779 }
2780
2781 // Provide the user with a more helpful error page?
2782 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2783 return;
2784
2785 // Fallback to a local error page.
2786 LoadNavigationErrorPage(frame, failed_request, error, std::string(),
2787 replace);
2788}
2789
2790void RenderView::didReceiveDocumentData(
2791 WebFrame* frame, const char* data, size_t data_len,
2792 bool& prevent_default) {
2793 NavigationState* navigation_state =
2794 NavigationState::FromDataSource(frame->dataSource());
2795 if (!navigation_state->postpone_loading_data())
2796 return;
2797
2798 // We're going to call commitDocumentData ourselves...
2799 prevent_default = true;
2800
2801 // Continue buffering the response data for the original 404 page. If it
2802 // grows too large, then we'll just let it through.
2803 navigation_state->append_postponed_data(data, data_len);
2804 if (navigation_state->postponed_data().size() >= 512) {
2805 navigation_state->set_postpone_loading_data(false);
2806 frame->commitDocumentData(navigation_state->postponed_data().data(),
2807 navigation_state->postponed_data().size());
2808 navigation_state->clear_postponed_data();
2809 }
2810}
2811
[email protected]40bd6582009-12-04 23:49:512812void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2813 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172814 NavigationState* navigation_state =
2815 NavigationState::FromDataSource(frame->dataSource());
2816
2817 navigation_state->set_commit_load_time(Time::Now());
2818 if (is_new_navigation) {
2819 // When we perform a new navigation, we need to update the previous session
2820 // history entry with state for the page we are leaving.
2821 UpdateSessionHistory(frame);
2822
2823 // We bump our Page ID to correspond with the new session history entry.
2824 page_id_ = next_page_id_++;
2825
[email protected]d64b07b2010-04-20 22:14:062826 // Any pending translation is now obsolete.
2827 translate_helper_.CancelPendingTranslation();
2828
[email protected]3cc72b12010-03-18 23:03:002829 // Advance our offset in session history, applying the length limit. There
2830 // is now no forward history.
2831 history_list_offset_++;
2832 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
2833 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
2834 history_list_length_ = history_list_offset_ + 1;
2835
[email protected]f9f4841b2010-03-20 05:41:422836 MessageLoop::current()->PostDelayedTask(
2837 FROM_HERE,
[email protected]3d9689372009-09-10 04:29:172838 method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo,
2839 page_id_, true),
2840 kDelayForForcedCaptureMs);
2841 } else {
2842 // Inspect the navigation_state on this frame to see if the navigation
2843 // corresponds to a session history navigation... Note: |frame| may or
2844 // may not be the toplevel frame, but for the case of capturing session
2845 // history, the first committed frame suffices. We keep track of whether
2846 // we've seen this commit before so that only capture session history once
2847 // per navigation.
2848 //
2849 // Note that we need to check if the page ID changed. In the case of a
2850 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2851 // previous URL and the current page ID, which would be wrong.
2852 if (navigation_state->pending_page_id() != -1 &&
2853 navigation_state->pending_page_id() != page_id_ &&
2854 !navigation_state->request_committed()) {
2855 // This is a successful session history navigation!
2856 UpdateSessionHistory(frame);
2857 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002858
2859 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172860 }
2861 }
2862
2863 // Remember that we've already processed this request, so we don't update
2864 // the session history again. We do this regardless of whether this is
2865 // a session history navigation, because if we attempted a session history
2866 // navigation without valid HistoryItem state, WebCore will think it is a
2867 // new navigation.
2868 navigation_state->set_request_committed(true);
2869
2870 UpdateURL(frame);
2871
2872 // If this committed load was initiated by a client redirect, we're
2873 // at the last stop now, so clear it.
2874 completed_client_redirect_src_ = GURL();
2875
2876 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272877 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172878}
2879
2880void RenderView::didClearWindowObject(WebFrame* frame) {
2881 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
2882 BindDOMAutomationController(frame);
2883 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) {
2884 dom_ui_bindings_.set_message_sender(this);
2885 dom_ui_bindings_.set_routing_id(routing_id_);
2886 dom_ui_bindings_.BindToJavascript(frame, L"chrome");
2887 }
2888 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
2889 external_host_bindings_.set_message_sender(this);
2890 external_host_bindings_.set_routing_id(routing_id_);
2891 external_host_bindings_.BindToJavascript(frame, L"externalHost");
2892 }
2893}
2894
2895void RenderView::didCreateDocumentElement(WebFrame* frame) {
2896 if (RenderThread::current()) { // Will be NULL during unit tests.
2897 RenderThread::current()->user_script_slave()->InjectScripts(
2898 frame, UserScript::DOCUMENT_START);
2899 }
[email protected]078b34612009-09-19 19:31:512900 if (view_type_ == ViewType::EXTENSION_TOOLSTRIP ||
2901 view_type_ == ViewType::EXTENSION_MOLE) {
2902 InjectToolstripCSS();
2903 ExtensionProcessBindings::SetViewType(webview(), view_type_);
2904 }
[email protected]3d9689372009-09-10 04:29:172905
2906 // Notify the browser about non-blank documents loading in the top frame.
2907 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252908 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272909 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172910 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2911 }
2912}
2913
2914void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
2915 UpdateTitle(frame, title);
2916
2917 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272918 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172919}
2920
[email protected]5019ef12010-04-27 17:26:582921void RenderView::didChangeIcons(WebFrame* frame) {
2922 if (!frame->parent()) {
2923 Send(new ViewHostMsg_UpdateFavIconURL(
2924 routing_id_,
2925 page_id_,
2926 frame->favIconURL()));
2927 }
2928}
2929
[email protected]3d9689372009-09-10 04:29:172930void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2931 WebDataSource* ds = frame->dataSource();
2932 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2933 DCHECK(navigation_state);
2934 navigation_state->set_finish_document_load_time(Time::Now());
2935
2936 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_));
2937
[email protected]e9e07992010-02-17 21:04:362938 // The document has now been fully loaded. Scan for forms to be sent up to
2939 // the browser.
2940 // TODO(jhawkins): Make these use the FormManager.
[email protected]c83641732010-02-20 01:04:482941 form_manager_.ExtractForms(frame);
[email protected]e9e07992010-02-17 21:04:362942 SendForms(frame);
[email protected]4d44a1c2010-04-28 19:20:412943 SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:172944
2945 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272946 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172947
2948 if (RenderThread::current()) { // Will be NULL during unit tests.
2949 RenderThread::current()->user_script_slave()->InjectScripts(
2950 frame, UserScript::DOCUMENT_END);
2951 }
[email protected]fa7b6b542009-11-03 05:02:302952
2953 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
2954}
2955
2956void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
2957 if (RenderThread::current()) { // Will be NULL during unit tests.
2958 RenderThread::current()->user_script_slave()->InjectScripts(
2959 frame, UserScript::DOCUMENT_IDLE);
2960 }
2961
2962 WebFrame* main_frame = webview()->mainFrame();
2963 if (frame == main_frame) {
2964 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:202965 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:302966 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:202967 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:302968 pending_code_execution_queue_.pop();
2969 }
2970 }
[email protected]3d9689372009-09-10 04:29:172971}
2972
2973void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]dd3c3e682010-05-12 18:51:262974 if (webview()->mainFrame() == frame)
2975 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_));
[email protected]3d9689372009-09-10 04:29:172976}
2977
2978void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
2979 // Ignore
2980}
2981
2982void RenderView::didFinishLoad(WebFrame* frame) {
2983 WebDataSource* ds = frame->dataSource();
2984 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2985 DCHECK(navigation_state);
2986 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:302987 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:412988
2989 // Let the password manager know which password forms are actually visible.
2990 SendPasswordForms(frame, true);
[email protected]3d9689372009-09-10 04:29:172991}
2992
[email protected]ccbe04e2010-03-17 17:58:432993void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172994 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:062995
2996 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
2997 // since a new one gets created by didCreateDataSource.
2998 NavigationState* state =
2999 NavigationState::FromDataSource(frame->dataSource());
3000 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
3001
[email protected]3d9689372009-09-10 04:29:173002 // If this was a reference fragment navigation that we initiated, then we
3003 // could end up having a non-null pending navigation state. We just need to
3004 // update the ExtraData on the datasource so that others who read the
3005 // ExtraData will get the new NavigationState. Similarly, if we did not
3006 // initiate this navigation, then we need to take care to reset any pre-
3007 // existing navigation state to a content-initiated navigation state.
3008 // DidCreateDataSource conveniently takes care of this for us.
3009 didCreateDataSource(frame, frame->dataSource());
3010
[email protected]f6c2459d2010-02-24 22:34:063011 if (idle_scheduler_ran) {
3012 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
3013 NavigationState* new_state =
3014 NavigationState::FromDataSource(frame->dataSource());
3015 new_state->user_script_idle_scheduler()->set_has_run(true);
3016 }
3017
[email protected]3d9689372009-09-10 04:29:173018 didCommitProvisionalLoad(frame, is_new_navigation);
3019
[email protected]26aa0482009-09-30 16:55:273020 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173021}
3022
[email protected]476b6f82009-09-10 21:00:593023void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313024 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593025}
3026
[email protected]3d9689372009-09-10 04:29:173027void RenderView::assignIdentifierToRequest(
3028 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3029 // Ignore
3030}
3031
3032void RenderView::willSendRequest(
3033 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3034 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303035 WebFrame* top_frame = frame->top();
3036 if (!top_frame)
3037 top_frame = frame;
3038 WebDataSource* data_source = top_frame->provisionalDataSource();
3039 if (!data_source)
3040 data_source = top_frame->dataSource();
3041 if (data_source) {
3042 NavigationState* state = NavigationState::FromDataSource(data_source);
3043 if (state && state->is_cache_policy_override_set())
3044 request.setCachePolicy(state->cache_policy_override());
3045 }
[email protected]3d9689372009-09-10 04:29:173046 request.setRequestorID(routing_id_);
[email protected]c5bbc2452010-03-08 08:33:503047 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133048 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493049
[email protected]85cc78c2010-05-04 18:30:093050 // Temporary metrics, see site_isolation_metrics.h
3051 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173052}
3053
3054void RenderView::didReceiveResponse(
3055 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493056
[email protected]85cc78c2010-05-04 18:30:093057 // Temporary metrics, see site_isolation_metrics.h
3058 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3059 identifier,
3060 response);
[email protected]fa0a3432010-03-30 16:53:493061
[email protected]3d9689372009-09-10 04:29:173062 // Only do this for responses that correspond to a provisional data source
3063 // of the top-most frame. If we have a provisional data source, then we
3064 // can't have any sub-resources yet, so we know that this response must
3065 // correspond to a frame load.
3066 if (!frame->provisionalDataSource() || frame->parent())
3067 return;
3068
3069 // If we are in view source mode, then just let the user see the source of
3070 // the server's 404 error page.
3071 if (frame->isViewSourceModeEnabled())
3072 return;
3073
[email protected]65041fa2010-05-21 06:56:533074 NavigationState* navigation_state =
3075 NavigationState::FromDataSource(frame->provisionalDataSource());
3076 CHECK(navigation_state);
3077
[email protected]972ebdff2010-06-10 22:59:073078 // Record page load flags.
3079 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3080 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573081 navigation_state->set_was_alternate_protocol_available(
3082 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073083 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]65041fa2010-05-21 06:56:533084
[email protected]f48013be2010-01-14 22:07:453085 // Consider loading an alternate error page for 404 responses.
3086 if (response.httpStatusCode() != 404)
3087 return;
3088
[email protected]3d9689372009-09-10 04:29:173089 // Can we even load an alternate error page for this URL?
3090 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3091 return;
3092
[email protected]3d9689372009-09-10 04:29:173093 navigation_state->set_postpone_loading_data(true);
3094 navigation_state->clear_postponed_data();
3095}
3096
3097void RenderView::didFinishResourceLoad(
3098 WebFrame* frame, unsigned identifier) {
3099 NavigationState* navigation_state =
3100 NavigationState::FromDataSource(frame->dataSource());
3101 if (!navigation_state->postpone_loading_data())
3102 return;
3103
3104 // The server returned a 404 and the content was < 512 bytes (which we
3105 // suppressed). Go ahead and fetch the alternate page content.
3106
3107 const GURL& frame_url = frame->url();
3108
3109 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3110 DCHECK(error_page_url.is_valid());
3111
3112 WebURLError original_error;
3113 original_error.unreachableURL = frame_url;
3114
3115 navigation_state->set_alt_error_page_fetcher(
3116 new AltErrorPageResourceFetcher(
3117 error_page_url, frame, original_error,
3118 NewCallback(this, &RenderView::AltErrorPageFinished)));
3119}
3120
3121void RenderView::didFailResourceLoad(
3122 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3123 // Ignore
3124}
3125
3126void RenderView::didLoadResourceFromMemoryCache(
3127 WebFrame* frame, const WebURLRequest& request,
3128 const WebURLResponse& response) {
3129 // Let the browser know we loaded a resource from the memory cache. This
3130 // message is needed to display the correct SSL indicators.
3131 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3132 routing_id_,
3133 request.url(),
[email protected]91733b62009-09-18 06:21:093134 frame->securityOrigin().toString().utf8(),
3135 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173136 response.securityInfo()));
3137}
3138
[email protected]6069da8c2009-10-20 20:33:493139void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293140 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3141}
3142
3143void RenderView::didRunInsecureContent(
3144 WebFrame* frame, const WebSecurityOrigin& origin) {
3145 Send(new ViewHostMsg_DidRunInsecureContent(
3146 routing_id_,
3147 origin.toString().utf8()));
3148}
3149
[email protected]7ea093ba2009-11-03 05:54:593150bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403151 if (enabled_per_settings &&
3152 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3153 return true;
[email protected]7ea093ba2009-11-03 05:54:593154
[email protected]12bc8472010-04-15 07:29:403155 if (IsWhitelistedForContentSettings(frame))
3156 return true;
[email protected]7ea093ba2009-11-03 05:54:593157
3158 return false; // Other protocols fall through here.
3159}
3160
[email protected]0a1a45432010-03-31 08:09:453161bool RenderView::allowDatabase(
3162 WebFrame* frame, const WebString& name, const WebString& display_name,
3163 unsigned long estimated_size) {
3164 WebSecurityOrigin origin = frame->securityOrigin();
3165 if (origin.isEmpty())
3166 return false; // Uninitialized document?
3167
3168 bool result;
3169 if (!Send(new ViewHostMsg_AllowDatabase(routing_id_,
3170 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3171 return false;
[email protected]9fb83e82010-07-02 18:24:553172 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3173 GURL(origin.toString().utf8()),
3174 name,
3175 display_name,
3176 estimated_size,
3177 !result));
[email protected]0a1a45432010-03-31 08:09:453178 return result;
3179}
[email protected]8934a3b2010-02-25 00:34:003180void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
3181 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT);
3182}
3183
[email protected]c21f1d52010-03-04 03:19:433184void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
3185 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS);
3186}
3187
[email protected]3d9689372009-09-10 04:29:173188void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3189 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3190}
3191
[email protected]0c882b282009-10-07 17:01:283192void RenderView::didCreateScriptContext(WebFrame* frame) {
3193 EventBindings::HandleContextCreated(frame, false);
3194}
3195
3196void RenderView::didDestroyScriptContext(WebFrame* frame) {
3197 EventBindings::HandleContextDestroyed(frame);
3198}
3199
3200void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3201 EventBindings::HandleContextCreated(frame, true);
3202}
3203
[email protected]fc86daa2010-03-30 23:52:533204void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3205 WebFrame* target,
3206 bool cross_origin,
3207 const WebString& property_name,
3208 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103209 // TODO(johnnyg): track the individual properties and repeat event_ids.
3210 if (cross_origin)
3211 cross_origin_access_count_++;
3212 else
3213 same_origin_access_count_++;
3214}
3215
[email protected]3d9689372009-09-10 04:29:173216void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143217 CheckPreferredSize();
3218}
3219
3220void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173221 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253222 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173223 // message.
[email protected]705243f2010-05-05 19:58:073224 if (!send_preferred_size_changes_ || !webview())
3225 return;
[email protected]dfca5acf2010-03-22 03:28:433226
[email protected]705243f2010-05-05 19:58:073227 // WebCore likes to tell us things have changed even when they haven't, so
3228 // cache the width and height and only send the IPC message when we're sure
3229 // they're different.
3230 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3231 webview()->mainFrame()->documentElementScrollHeight());
3232 if (size == preferred_size_)
3233 return;
[email protected]c27324b2009-11-19 22:44:293234
[email protected]705243f2010-05-05 19:58:073235 preferred_size_ = size;
3236 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3237 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173238}
3239
[email protected]143dcd592009-11-06 21:33:493240void RenderView::didChangeScrollOffset(WebFrame* frame) {
3241 StartNavStateSyncTimerIfNecessary();
3242}
3243
[email protected]8922e1f2009-10-03 05:01:263244void RenderView::reportFindInPageMatchCount(int request_id, int count,
3245 bool final_update) {
3246 // If we have a message that has been queued up, then we should just replace
3247 // it. The ACK from the browser will make sure it gets sent when the browser
3248 // wants it.
3249 if (queued_find_reply_message_.get()) {
3250 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3251 routing_id_,
3252 request_id,
3253 count,
3254 gfx::Rect(),
3255 -1, // Don't update active match ordinal.
3256 final_update);
3257 queued_find_reply_message_.reset(msg);
3258 } else {
3259 // Send the search result over to the browser process.
3260 Send(new ViewHostMsg_Find_Reply(
3261 routing_id_,
3262 request_id,
3263 count,
3264 gfx::Rect(),
[email protected]705243f2010-05-05 19:58:073265 -1, // Don't update active match ordinal.
[email protected]8922e1f2009-10-03 05:01:263266 final_update));
3267 }
3268}
3269
3270void RenderView::reportFindInPageSelection(int request_id,
3271 int active_match_ordinal,
3272 const WebRect& selection_rect) {
3273 // Send the search result over to the browser process.
3274 Send(new ViewHostMsg_Find_Reply(routing_id_,
3275 request_id,
3276 -1,
3277 selection_rect,
3278 active_match_ordinal,
3279 false));
3280}
3281
[email protected]24a7f3c2010-03-25 08:26:493282void RenderView::ReportNoFindInPageResults(int request_id) {
3283 Send(new ViewHostMsg_Find_Reply(routing_id_,
3284 request_id,
3285 0,
3286 gfx::Rect(),
3287 0,
3288 true));
3289}
3290
[email protected]79dbc662009-09-04 05:42:513291// webkit_glue::WebPluginPageDelegate -----------------------------------------
3292
[email protected]f103ab72009-09-02 17:10:593293webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533294 const FilePath& file_path,
3295 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593296 if (!PluginChannelHost::IsListening())
3297 return NULL;
3298
[email protected]d2139662009-12-10 03:21:143299 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283300 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143301 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163302 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533303 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143304 if (CommandLine::ForCurrentProcess()->
3305 HasSwitch(switches::kInternalPepper)) {
3306 in_process_plugin = true;
3307 use_pepper_host = true;
3308 } else {
3309 // In process Pepper plugins must be explicitly enabled.
3310 return NULL;
3311 }
[email protected]4e0616e2010-05-28 14:55:533312 } else {
3313 FilePath internal_pdf_path;
3314 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3315 if (file_path == internal_pdf_path) {
3316 in_process_plugin = true;
3317 use_pepper_host = true;
3318 }
[email protected]26e8d5e2009-10-13 02:47:163319 }
[email protected]4e0616e2010-05-28 14:55:533320
[email protected]d2139662009-12-10 03:21:143321 // Check for Native Client modules.
[email protected]d032f492009-09-29 00:33:463322 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3323 if (mime_type == "application/x-nacl-srpc") {
3324 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143325 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463326 }
3327 }
[email protected]4e0616e2010-05-28 14:55:533328
[email protected]d032f492009-09-29 00:33:463329 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143330 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283331 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533332 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]53900d52010-06-16 04:25:013333 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283334 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143335 } else {
[email protected]6876dff2010-01-15 19:38:093336#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]d2139662009-12-10 03:21:143337 return WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533338 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093339#else
[email protected]596b2c42010-01-14 20:40:433340 NOTIMPLEMENTED();
3341 return NULL;
[email protected]7b6616f2010-01-14 18:07:553342#endif
[email protected]6876dff2010-01-15 19:38:093343 }
[email protected]f103ab72009-09-02 17:10:593344 }
3345
[email protected]4e0616e2010-05-28 14:55:533346 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593347}
3348
3349void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033350#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593351 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3352 routing_id(), window));
3353#endif
3354}
3355
3356void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033357#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593358 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3359 routing_id(), window));
3360#endif
3361 CleanupWindowInPluginMoves(window);
3362}
3363
3364void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) {
3365 SchedulePluginMove(move);
3366}
3367
3368void RenderView::DidStartLoadingForPlugin() {
3369 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523370 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593371}
3372
3373void RenderView::DidStopLoadingForPlugin() {
3374 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523375 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593376}
3377
3378void RenderView::ShowModalHTMLDialogForPlugin(
3379 const GURL& url,
3380 const gfx::Size& size,
3381 const std::string& json_arguments,
3382 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:213383 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:593384 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:213385 json_retval));
[email protected]f103ab72009-09-02 17:10:593386}
3387
[email protected]b921cfd22010-02-25 16:57:513388WebCookieJar* RenderView::GetCookieJar() {
3389 return &cookie_jar_;
3390}
3391
initial.commit09911bf2008-07-26 23:55:293392void RenderView::SyncNavigationState() {
3393 if (!webview())
3394 return;
3395
[email protected]26aa0482009-09-30 16:55:273396 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173397 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293398 return;
[email protected]ca948a22009-06-25 19:36:173399
3400 Send(new ViewHostMsg_UpdateState(
3401 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293402}
3403
[email protected]b0950a72009-09-29 23:16:173404bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3405 // Make sure webview was not shut down.
3406 if (!webview())
3407 return false;
3408 // Create an image resource fetcher and assign it with a call back object.
3409 image_fetchers_.insert(new ImageResourceFetcher(
[email protected]26aa0482009-09-30 16:55:273410 image_url, webview()->mainFrame(), id, image_size,
[email protected]b0950a72009-09-29 23:16:173411 NewCallback(this, &RenderView::DidDownloadImage)));
3412 return true;
3413}
3414
3415void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:293416 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:173417 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:473418 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
3419 fetcher->id(),
3420 fetcher->image_url(),
3421 image.isNull(),
3422 image));
[email protected]b0950a72009-09-29 23:16:173423 // Dispose of the image fetcher.
3424 DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end());
3425 image_fetchers_.erase(fetcher);
3426 // We're in the callback from the ImageResourceFetcher, best to delay
3427 // deletion.
3428 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:293429}
3430
[email protected]bf5c2ff392009-07-08 16:24:333431void RenderView::OnDownloadFavIcon(int id,
3432 const GURL& image_url,
3433 int image_size) {
[email protected]f11ca0732009-04-11 00:09:343434 bool data_image_failed = false;
3435 if (image_url.SchemeIs("data")) {
3436 SkBitmap data_image = ImageFromDataUrl(image_url);
3437 data_image_failed = data_image.empty();
3438 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:333439 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
3440 data_image));
[email protected]f11ca0732009-04-11 00:09:343441 }
3442 }
3443
[email protected]bf5c2ff392009-07-08 16:24:333444 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:173445 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:333446 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
3447 SkBitmap()));
3448 }
initial.commit09911bf2008-07-26 23:55:293449}
3450
[email protected]f11ca0732009-04-11 00:09:343451SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
3452 std::string mime_type, char_set, data;
3453 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
3454 // Decode the favicon using WebKit's image decoder.
3455 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
3456 const unsigned char* src_data =
3457 reinterpret_cast<const unsigned char*>(&data[0]);
3458
3459 return decoder.Decode(src_data, data.size());
3460 }
3461 return SkBitmap();
3462}
3463
initial.commit09911bf2008-07-26 23:55:293464void RenderView::OnGetApplicationInfo(int page_id) {
3465 webkit_glue::WebApplicationInfo app_info;
3466 if (page_id == page_id_)
3467 webkit_glue::GetApplicationInfo(webview(), &app_info);
3468
3469 // Prune out any data URLs in the set of icons. The browser process expects
3470 // any icon with a data URL to have originated from a favicon. We don't want
3471 // to decode arbitrary data URLs in the browser process. See
3472 // http://b/issue?id=1162972
3473 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:593474 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:293475 app_info.icons.erase(app_info.icons.begin() + i);
3476 --i;
3477 }
3478 }
3479
3480 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
3481}
3482
[email protected]7ccddb8c2009-08-04 17:36:553483GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293484 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553485 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293486 // If the URL that failed was secure, then the embedding web page was not
3487 // expecting a network attacker to be able to manipulate its contents. As
3488 // we fetch alternate error pages over HTTP, we would be allowing a network
3489 // attacker to manipulate the contents of the response if we tried to use
3490 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153491 return GURL();
initial.commit09911bf2008-07-26 23:55:293492 }
3493
3494 // Grab the base URL from the browser process.
3495 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153496 return GURL();
initial.commit09911bf2008-07-26 23:55:293497
3498 // Strip query params from the failed URL.
3499 GURL::Replacements remove_params;
3500 remove_params.ClearUsername();
3501 remove_params.ClearPassword();
3502 remove_params.ClearQuery();
3503 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553504 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503505 std::string spec_to_send = url_to_send.spec();
3506 // Notify link doctor of the url truncation by sending of "?" at the end.
3507 if (failed_url.has_query())
3508 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293509
3510 // Construct the query params to send to link doctor.
3511 std::string params(alternate_error_page_url_.query());
3512 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503513 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293514 params.append("&sourceid=chrome");
3515 params.append("&error=");
3516 switch (error_type) {
3517 case DNS_ERROR:
3518 params.append("dnserror");
3519 break;
3520
3521 case HTTP_404:
3522 params.append("http404");
3523 break;
3524
[email protected]5df266ac2008-10-15 19:50:133525 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333526 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133527 break;
3528
initial.commit09911bf2008-07-26 23:55:293529 default:
3530 NOTREACHED() << "unknown ErrorPageType";
3531 }
3532
3533 // OK, build the final url to return.
3534 GURL::Replacements link_doctor_params;
3535 link_doctor_params.SetQueryStr(params);
3536 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3537 return url;
3538}
3539
[email protected]0fdbf8c2010-07-08 20:33:013540WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3541 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493542}
3543
[email protected]6069da8c2009-10-20 20:33:493544void RenderView::OnFind(int request_id, const string16& search_text,
3545 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273546 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493547
3548 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493549 if (options.findNext) {
3550 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013551 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493552 } else {
[email protected]afdbd142010-07-10 08:01:233553#if defined(WEBPLUGIN_FIND_HAS_RETURN_TYPE)
3554 if (GetWebPluginFromPluginDocument()->startFind(
3555 search_text, options.matchCase, request_id)) {
3556#else
[email protected]0fdbf8c2010-07-08 20:33:013557 if (GetWebPluginFromPluginDocument()->supportsFind()) {
3558 GetWebPluginFromPluginDocument()->startFind(
3559 search_text, options.matchCase, request_id);
[email protected]afdbd142010-07-10 08:01:233560#endif
[email protected]24a7f3c2010-03-25 08:26:493561 } else {
3562 ReportNoFindInPageResults(request_id);
3563 }
3564 }
3565 return;
3566 }
3567
[email protected]b4bb2502009-10-01 22:35:273568 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273569 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293570 WebFrame* search_frame = focused_frame; // start searching focused frame.
3571
3572 bool multi_frame = (frame_after_main != main_frame);
3573
3574 // If we have multiple frames, we don't want to wrap the search within the
3575 // frame, so we check here if we only have main_frame in the chain.
3576 bool wrap_within_frame = !multi_frame;
3577
[email protected]b3f2b912009-04-09 16:18:523578 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293579 bool result = false;
3580
[email protected]7830da3e2009-11-06 16:27:263581 // If something is selected when we start searching it means we cannot just
3582 // increment the current match ordinal; we need to re-generate it.
3583 WebRange current_selection = focused_frame->selectionRange();
3584
initial.commit09911bf2008-07-26 23:55:293585 do {
[email protected]dd7daa82009-08-10 05:46:453586 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593587 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293588
3589 if (!result) {
3590 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223591 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293592
3593 // Find the next frame, but skip the invisible ones.
3594 do {
3595 // What is the next frame to search? (we might be going backwards). Note
3596 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593597 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273598 search_frame->traverseNext(true) :
3599 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453600 } while (!search_frame->hasVisibleContent() &&
3601 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293602
[email protected]884db412008-11-24 23:46:503603 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223604 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293605
3606 // If we have multiple frames and we have wrapped back around to the
3607 // focused frame, we need to search it once more allowing wrap within
3608 // the frame, otherwise it will report 'no match' if the focused frame has
3609 // reported matches, but no frames after the focused_frame contain a
3610 // match for the search word(s).
3611 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453612 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593613 request_id, search_text, options, true, // Force wrapping.
3614 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293615 }
3616 }
3617
[email protected]26aa0482009-09-30 16:55:273618 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293619 } while (!result && search_frame != focused_frame);
3620
[email protected]7830da3e2009-11-06 16:27:263621 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293622 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453623 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293624 } else {
3625 // If nothing is found, set result to "0 of 0", otherwise, set it to
3626 // "-1 of 1" to indicate that we found at least one item, but we don't know
3627 // yet what is active.
3628 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3629 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293630
[email protected]4f3dc372009-02-24 00:10:293631 // If we find no matches then this will be our last status update.
3632 // Otherwise the scoping effort will send more results.
3633 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293634
[email protected]4f3dc372009-02-24 00:10:293635 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403636 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593637 request_id,
[email protected]4f3dc372009-02-24 00:10:293638 match_count,
3639 selection_rect,
3640 ordinal,
3641 final_status_update));
initial.commit09911bf2008-07-26 23:55:293642
initial.commit09911bf2008-07-26 23:55:293643 // Scoping effort begins, starting with the mainframe.
3644 search_frame = main_frame;
3645
[email protected]dd7daa82009-08-10 05:46:453646 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293647
3648 do {
3649 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453650 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293651
3652 // We don't start another scoping effort unless at least one match has
3653 // been found.
3654 if (result) {
3655 // Start new scoping request. If the scoping function determines that it
3656 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453657 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593658 search_text,
3659 options,
initial.commit09911bf2008-07-26 23:55:293660 true); // reset the tickmarks
3661 }
3662
3663 // Iterate to the next frame. The frame will not necessarily scope, for
3664 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273665 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293666 } while (search_frame != main_frame);
3667 }
3668}
3669
[email protected]24a7f3c2010-03-25 08:26:493670void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3671 WebView* view = webview();
3672 if (!view)
3673 return;
3674
3675 WebDocument doc = view->mainFrame()->document();
3676 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013677 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493678 return;
3679 }
3680
3681 bool clear_selection =
3682 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3683 if (clear_selection)
3684 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3685
3686 WebFrame* frame = view->mainFrame();
3687 while (frame) {
3688 frame->stopFinding(clear_selection);
3689 frame = frame->traverseNext(false);
3690 }
3691
3692 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3693 WebFrame* focused_frame = view->focusedFrame();
3694 if (focused_frame) {
3695 WebDocument doc = focused_frame->document();
3696 if (!doc.isNull()) {
3697 WebNode node = doc.focusedNode();
3698 if (!node.isNull())
3699 node.simulateClick();
3700 }
3701 }
3702 }
3703}
3704
3705void RenderView::OnFindReplyAck() {
3706 // Check if there is any queued up request waiting to be sent.
3707 if (queued_find_reply_message_.get()) {
3708 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423709 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493710 }
3711}
3712
[email protected]8934a3b2010-02-25 00:34:003713bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:353714 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:003715 return current_content_settings_.settings[settings_type] !=
3716 CONTENT_SETTING_BLOCK;
3717}
3718
3719void RenderView::DidBlockContentType(ContentSettingsType settings_type) {
3720 if (!content_blocked_[settings_type]) {
3721 content_blocked_[settings_type] = true;
3722 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type));
[email protected]0de80162010-02-03 04:52:353723 }
[email protected]0de80162010-02-03 04:52:353724}
3725
[email protected]71b0d5d2010-02-15 05:43:073726void RenderView::ClearBlockedContentSettings() {
3727 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
3728 content_blocked_[i] = false;
3729}
3730
[email protected]40bd6582009-12-04 23:49:513731void RenderView::OnZoom(PageZoom::Function function) {
3732 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3733 return;
3734
[email protected]258d31122010-05-09 10:59:413735 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523736
[email protected]40bd6582009-12-04 23:49:513737 int zoom_level = webview()->zoomLevel();
3738 int new_zoom_level = webview()->setZoomLevel(false,
3739 (function == PageZoom::RESET) ? 0 : (zoom_level + function));
3740
[email protected]9d797f32010-04-23 07:17:543741 // Tell the browser which url got zoomed so it can update the saved values.
3742 Send(new ViewHostMsg_DidZoomURL(
3743 GURL(webview()->mainFrame()->url()), new_zoom_level));
[email protected]40bd6582009-12-04 23:49:513744}
3745
[email protected]9d797f32010-04-23 07:17:543746void RenderView::OnSetContentSettingsForLoadingURL(
3747 const GURL& url,
[email protected]f85f0702010-01-30 09:31:013748 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:543749 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:013750}
3751
[email protected]9d797f32010-04-23 07:17:543752void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
3753 int zoom_level) {
3754 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293755}
3756
[email protected]41fc0322009-09-04 22:23:403757void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273758 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293759}
3760
[email protected]a697f4c2009-09-14 22:30:183761void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273762 WebString no_encoding;
3763 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183764}
3765
[email protected]20ad2692009-11-20 18:27:203766bool RenderView::GetAllChildFrames(
3767 WebFrame* parent_frame,
3768 std::vector<WebFrame*>* frames_vector) const {
3769 if (!parent_frame)
3770 return false;
3771 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
3772 child_frame = child_frame->nextSibling()) {
3773 frames_vector->push_back(child_frame);
3774 GetAllChildFrames(child_frame, frames_vector);
3775 }
3776 return true;
3777}
3778
[email protected]dd7daa82009-08-10 05:46:453779WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3780 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273781 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453782
3783 // xpath string can represent a frame deep down the tree (across multiple
3784 // frame DOMs).
3785 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3786 // should break into 2 xpaths
3787 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3788
[email protected]26aa0482009-09-30 16:55:273789 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453790
3791 std::wstring xpath_remaining = xpath;
3792 while (!xpath_remaining.empty()) {
3793 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3794 std::wstring xpath_child;
3795 if (delim_pos != std::wstring::npos) {
3796 xpath_child = xpath_remaining.substr(0, delim_pos);
3797 xpath_remaining.erase(0, delim_pos + 1);
3798 } else {
3799 xpath_remaining.swap(xpath_child);
3800 }
3801 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293802 }
3803
[email protected]dd7daa82009-08-10 05:46:453804 return frame;
initial.commit09911bf2008-07-26 23:55:293805}
3806
[email protected]f29acf52008-11-03 20:08:333807void RenderView::EvaluateScript(const std::wstring& frame_xpath,
3808 const std::wstring& script) {
initial.commit09911bf2008-07-26 23:55:293809 WebFrame* web_frame = GetChildFrame(frame_xpath);
3810 if (!web_frame)
3811 return;
3812
[email protected]dd7daa82009-08-10 05:46:453813 web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script)));
initial.commit09911bf2008-07-26 23:55:293814}
3815
[email protected]1810e132009-03-24 23:35:483816void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083817 const std::string& css,
3818 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483819 WebFrame* web_frame = GetChildFrame(frame_xpath);
3820 if (!web_frame)
3821 return;
3822
[email protected]ffaef0c2009-09-15 17:08:083823 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483824}
3825
[email protected]00c39612010-03-06 02:53:283826void RenderView::OnPepperPluginDestroy(
3827 WebPluginDelegatePepper* pepper_plugin) {
3828 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:013829 current_oldstyle_pepper_plugins_.find(pepper_plugin);
3830 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:283831 NOTREACHED();
3832 return;
3833 }
[email protected]53900d52010-06-16 04:25:013834 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:473835
3836 // The plugin could have been destroyed while it was waiting for a file
3837 // choose callback, so check all pending completion callbacks and NULL them.
3838 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
3839 file_chooser_completions_.begin();
3840 i != file_chooser_completions_.end(); /* nothing */) {
3841 if ((*i)->completion == pepper_plugin) {
3842 // We NULL the first one instead of deleting it because the plugin might
3843 // be the one waiting for a file choose callback. If the callback later
3844 // comes, we don't want to send the result to the next callback in line.
3845 if (i == file_chooser_completions_.begin())
3846 (*i)->completion = NULL;
3847 else
3848 i = file_chooser_completions_.erase(i);
3849 } else {
3850 ++i;
3851 }
3852 }
[email protected]00c39612010-03-06 02:53:283853}
3854
initial.commit09911bf2008-07-26 23:55:293855void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath,
3856 const std::wstring& jscript) {
[email protected]f29acf52008-11-03 20:08:333857 EvaluateScript(frame_xpath, jscript);
initial.commit09911bf2008-07-26 23:55:293858}
3859
[email protected]1810e132009-03-24 23:35:483860void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083861 const std::string& css,
3862 const std::string& id) {
3863 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413864
3865 // Notify RenderViewHost that css has been inserted into the frame.
3866 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483867}
3868
[email protected]7ea066a2009-04-06 20:21:593869void RenderView::OnAddMessageToConsole(
3870 const string16& frame_xpath,
3871 const string16& message,
3872 const WebConsoleMessage::Level& level) {
3873 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:593874 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:453875 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:293876}
3877
[email protected]81e63782009-02-27 19:35:093878void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3879 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293880}
3881
3882void RenderView::OnSetDOMUIProperty(const std::string& name,
3883 const std::string& value) {
[email protected]81e63782009-02-27 19:35:093884 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
initial.commit09911bf2008-07-26 23:55:293885 dom_ui_bindings_.SetProperty(name, value);
3886}
3887
3888void RenderView::OnReservePageIDRange(int size_of_range) {
3889 next_page_id_ += size_of_range + 1;
3890}
3891
[email protected]e80c73b2009-04-07 23:24:583892void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3893 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253894 bool ended,
3895 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033896 if (ended) {
[email protected]26aa0482009-09-30 16:55:273897 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203898 } else {
3899 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033900 }
initial.commit09911bf2008-07-26 23:55:293901}
3902
3903void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273904 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293905}
3906
initial.commit09911bf2008-07-26 23:55:293907void RenderView::OnFillPasswordForm(
[email protected]daa8c58e2009-06-15 17:21:103908 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
[email protected]03f57072010-07-14 17:36:083909#if defined(WEBKIT_BUG_41283_IS_FIXED)
3910 password_autocomplete_manager_.ReceivedPasswordFormFillData(webview(),
3911 form_data);
3912#endif
initial.commit09911bf2008-07-26 23:55:293913}
3914
3915void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:583916 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253917 const gfx::Point& screen_point,
3918 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273919 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:583920 drop_data.ToDragData(),
3921 drop_data.identity,
3922 client_point,
[email protected]1d9f4132009-09-08 17:29:253923 screen_point,
3924 ops);
initial.commit09911bf2008-07-26 23:55:293925
[email protected]1d9f4132009-09-08 17:29:253926 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293927}
3928
[email protected]e80c73b2009-04-07 23:24:583929void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:253930 const gfx::Point& screen_point,
3931 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:273932 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:253933 client_point,
3934 screen_point,
3935 ops);
initial.commit09911bf2008-07-26 23:55:293936
[email protected]1d9f4132009-09-08 17:29:253937 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:293938}
3939
3940void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:273941 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:293942}
3943
[email protected]e80c73b2009-04-07 23:24:583944void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3945 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:273946 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:293947}
3948
3949void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593950 webkit_preferences_ = prefs;
3951 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293952}
3953
3954void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3955 alternate_error_page_url_ = url;
3956}
3957
[email protected]a0c7153e2009-12-09 14:36:333958void RenderView::OnCustomContextMenuAction(unsigned action) {
3959 webview()->performCustomContextMenuAction(action);
3960}
3961
[email protected]d4a00a72010-01-29 01:44:423962void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:023963 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:423964 const std::string& source_lang,
3965 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:023966 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
3967 translate_script);
[email protected]d4a00a72010-01-29 01:44:423968}
3969
[email protected]85d252e2010-04-06 22:21:023970void RenderView::OnRevertTranslation(int page_id) {
3971 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:323972}
3973
initial.commit09911bf2008-07-26 23:55:293974void RenderView::OnInstallMissingPlugin() {
3975 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593976 if (first_default_plugin_)
3977 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293978}
3979
[email protected]cdaf8d02010-03-30 19:52:473980void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363981 // This could happen if we navigated to a different page before the user
3982 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473983 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363984 return;
3985
[email protected]cdaf8d02010-03-30 19:52:473986 WebVector<WebString> ws_file_names(paths.size());
3987 for (size_t i = 0; i < paths.size(); ++i)
3988 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463989
[email protected]cdaf8d02010-03-30 19:52:473990 if (file_chooser_completions_.front()->completion)
3991 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3992 file_chooser_completions_.pop_front();
3993
3994 // If there are more pending file chooser requests, schedule one now.
3995 if (!file_chooser_completions_.empty()) {
3996 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3997 file_chooser_completions_.front()->params));
3998 }
initial.commit09911bf2008-07-26 23:55:293999}
4000
4001void RenderView::OnEnableViewSourceMode() {
4002 if (!webview())
4003 return;
[email protected]26aa0482009-09-30 16:55:274004 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294005 if (!main_frame)
4006 return;
4007
[email protected]dd7daa82009-08-10 05:46:454008 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294009}
4010
[email protected]770dd8b2010-05-24 18:11:394011void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4012 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244013 if (send_preferred_size_changes_)
4014 return;
[email protected]9fb325e2010-05-06 18:23:244015 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394016
4017 // WebKit doesn't send a notification of the effective height of the page
4018 // changes, so poll for it.
4019 // TODO: Add a notification for this to WebKit, remove polling. After that's
4020 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4021 // http://crbug.com/44850
4022 if (flags & kPreferredSizeHeightThisIsSlow) {
4023 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4024 &RenderView::CheckPreferredSize);
4025 }
[email protected]0666aef2009-05-13 19:48:084026}
4027
[email protected]cda45c02010-02-25 19:28:104028void RenderView::OnDisableScrollbarsForSmallWindows(
4029 const gfx::Size& disable_scrollbar_size_limit) {
4030 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4031}
4032
[email protected]80d96fa2009-06-10 22:34:514033void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4034 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374035 UpdateFontRenderingFromRendererPrefs();
[email protected]6981f7f2010-03-09 00:53:034036#if defined(TOOLKIT_GTK)
[email protected]1c83eb42009-09-11 21:08:414037 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4038 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464039 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]93623c5d2009-12-10 21:40:324040
[email protected]644d77e2010-01-27 01:03:104041 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324042 webview()->setScrollbarColors(
4043 renderer_prefs.thumb_inactive_color,
4044 renderer_prefs.thumb_active_color,
4045 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104046 webview()->setSelectionColors(
4047 renderer_prefs.active_selection_bg_color,
4048 renderer_prefs.active_selection_fg_color,
4049 renderer_prefs.inactive_selection_bg_color,
4050 renderer_prefs.inactive_selection_fg_color);
[email protected]61c64402010-05-25 22:05:014051 didInvalidateRect(gfx::Rect(size_));
[email protected]644d77e2010-01-27 01:03:104052 }
[email protected]7a74e102009-09-03 00:16:564053#endif
[email protected]80d96fa2009-06-10 22:34:514054}
4055
[email protected]952cb702009-10-07 05:50:284056void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4057 const WebMediaPlayerAction& action) {
4058 if (webview())
4059 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564060}
4061
[email protected]7b291f92009-08-14 05:43:534062void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
[email protected]078b34612009-09-19 19:31:514063 // When this is first set, the bindings aren't fully loaded. We only need
4064 // to call through this API after the page has already been loaded. It's
4065 // also called in didCreateDocumentElement to bootstrap.
4066 if (view_type_ != ViewType::INVALID) {
4067 if (type == ViewType::EXTENSION_MOLE ||
4068 type == ViewType::EXTENSION_TOOLSTRIP) {
4069 ExtensionProcessBindings::SetViewType(webview(), type);
4070 }
4071 }
[email protected]7b291f92009-08-14 05:43:534072 view_type_ = type;
4073}
4074
4075void RenderView::OnUpdateBrowserWindowId(int window_id) {
4076 browser_window_id_ = window_id;
4077}
4078
[email protected]b3df5a42010-05-11 14:31:094079void RenderView::OnGetAccessibilityTree() {
[email protected]aef92842010-05-21 16:54:364080 if (accessibility_.get())
[email protected]9f4db512010-05-10 20:21:414081 accessibility_->clear();
[email protected]039a1da2010-05-12 02:08:114082 accessibility_.reset(WebAccessibilityCache::create());
4083 accessibility_->initialize(webview());
[email protected]9f4db512010-05-10 20:21:414084
[email protected]b3df5a42010-05-11 14:31:094085 WebAccessibilityObject src_tree = webview()->accessibilityObject();
4086 webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get());
4087 Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree));
[email protected]266eb6f2008-09-30 23:56:504088}
4089
[email protected]aef92842010-05-21 16:54:364090void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4091 if (!accessibility_.get())
4092 return;
4093 if (accessibility_->isValidId(acc_obj_id)) {
4094 // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number.
4095 // By convention, calling SetFocus on the root of the tree (id = 1000)
4096 // should clear the current focus. Otherwise set the focus to the new
4097 // node.
4098 if (acc_obj_id == 1000)
4099 webview()->clearFocusedNode();
4100 else
4101 accessibility_->getObjectById(acc_obj_id).setFocused(true);
4102 }
4103}
4104
4105void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4106 if (!accessibility_.get())
4107 return;
4108 if (accessibility_->isValidId(acc_obj_id)) {
4109 accessibility_->getObjectById(acc_obj_id).performDefaultAction();
4110 }
4111}
4112
initial.commit09911bf2008-07-26 23:55:294113void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4114 const GURL& page_url) {
4115 // Prepare list to storage all savable resource links.
4116 std::vector<GURL> resources_list;
4117 std::vector<GURL> referrers_list;
4118 std::vector<GURL> frames_list;
4119 webkit_glue::SavableResourcesResult result(&resources_list,
4120 &referrers_list,
4121 &frames_list);
4122
[email protected]dbeb3952009-10-13 18:01:184123 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4124 webview(),
4125 page_url,
4126 &result,
4127 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294128 // If something is wrong when collecting all savable resource links,
4129 // send empty list to embedder(browser) to tell it failed.
4130 referrers_list.clear();
4131 resources_list.clear();
4132 frames_list.clear();
4133 }
4134
4135 // Send result of all savable resource links to embedder.
4136 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4137 resources_list,
4138 referrers_list,
4139 frames_list));
4140}
4141
4142void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324143 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314144 const std::vector<FilePath>& local_paths,
4145 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074146
4147 // Convert std::vector of GURLs to WebVector<WebURL>
4148 WebVector<WebURL> weburl_links(links);
4149
4150 // Convert std::vector of std::strings to WebVector<WebString>
4151 WebVector<WebString> webstring_paths(local_paths.size());
4152 for (size_t i = 0; i < local_paths.size(); i++)
4153 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4154
4155 WebPageSerializer::serialize(webview()->mainFrame(),
4156 true, this, weburl_links, webstring_paths,
4157 webkit_glue::FilePathToWebString(
4158 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294159}
4160
[email protected]d9ec5c0f2009-12-23 11:55:074161void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4162 const WebCString& data,
4163 WebPageSerializerClient::PageSerializationStatus status) {
4164 Send(new ViewHostMsg_SendSerializedHtmlData(
4165 routing_id_,
4166 frame_url,
4167 data.data(),
4168 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294169}
4170
[email protected]9b18a84f2010-06-10 15:54:044171void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274172 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474173 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294174}
4175
[email protected]eb6b87a2009-07-24 15:57:394176void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294177 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4178 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4179 // in the onunload handler from appearing. For now, we're bypassing that and
4180 // calling the FrameLoader's CloseURL method directly. This should be
4181 // revisited to avoid having two ways to close a page. Having a single way
4182 // to close that can run onunload is also useful for fixing
4183 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274184 WebFrame* main_frame = webview()->mainFrame();
[email protected]7a9b51f2009-06-29 21:28:294185 if (main_frame) {
[email protected]dd7daa82009-08-10 05:46:454186 const GURL& url = main_frame->url();
[email protected]3d9689372009-09-10 04:29:174187 // TODO(davemoore) this code should be removed once willClose() gets
[email protected]7a9b51f2009-06-29 21:28:294188 // called when a page is destroyed. DumpLoadHistograms() is safe to call
4189 // multiple times for the same frame, but it will simplify things.
[email protected]dd7daa82009-08-10 05:46:454190 if (url.SchemeIs(chrome::kHttpScheme) ||
4191 url.SchemeIs(chrome::kHttpsScheme))
[email protected]7a9b51f2009-06-29 21:28:294192 DumpLoadHistograms();
[email protected]7a9b51f2009-06-29 21:28:294193 }
[email protected]26aa0482009-09-30 16:55:274194 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294195
[email protected]ab9eabac2010-03-16 16:54:104196 // Reset stats
4197 cross_origin_access_count_ = 0;
4198 same_origin_access_count_ = 0;
4199
[email protected]eb6b87a2009-07-24 15:57:394200 // Just echo back the params in the ACK.
4201 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294202}
4203
4204void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574205#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294206 gfx::NativeTheme::instance()->CloseHandles();
[email protected]61c64402010-05-25 22:05:014207 didInvalidateRect(gfx::Rect(size_));
[email protected]6c8afae52009-01-22 02:24:574208#else // defined(OS_WIN)
4209 // TODO(port): we don't support theming on non-Windows platforms yet
4210 NOTIMPLEMENTED();
4211#endif
initial.commit09911bf2008-07-26 23:55:294212}
4213
[email protected]9b18a84f2010-06-10 15:54:044214void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4215 const std::string& origin,
4216 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154217 if (message.empty())
4218 return;
[email protected]28790922009-03-09 19:48:374219 external_host_bindings_.ForwardMessageFromExternalHost(message, origin,
4220 target);
[email protected]3ac14a052008-08-15 21:22:154221}
4222
[email protected]0aa55312008-10-17 21:53:084223void RenderView::OnDisassociateFromPopupCount() {
4224 if (decrement_shared_popup_at_destruction_)
4225 shared_popup_counter_->data--;
4226 shared_popup_counter_ = new SharedRenderViewCounter(0);
4227 decrement_shared_popup_at_destruction_ = false;
4228}
4229
[email protected]15d79e12009-08-02 19:23:454230bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4231 const WebURLError& error,
4232 bool replace) {
4233 // We only show alternate error pages in the main frame. They are
4234 // intended to assist the user when navigating, so there is not much
4235 // value in showing them for failed subframes. Ideally, we would be
4236 // able to use the TYPED transition type for this, but that flag is
4237 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454238 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454239 return false;
4240
4241 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374242 // connection failure.
[email protected]15d79e12009-08-02 19:23:454243 int ec = error.reason;
4244 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4245 ec != net::ERR_CONNECTION_FAILED &&
4246 ec != net::ERR_CONNECTION_REFUSED &&
4247 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374248 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454249 return false;
4250
4251 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554252 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454253 if (!error_page_url.is_valid())
4254 return false;
4255
4256 // Load an empty page first so there is an immediate response to the error,
4257 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454258 frame->loadHTMLString(std::string(),
[email protected]15d79e12009-08-02 19:23:454259 GURL(kUnreachableWebDataURL),
4260 error.unreachableURL,
4261 replace);
4262
4263 // Now, create a fetcher for the error page and associate it with the data
4264 // source we just created via the LoadHTMLString call. That way if another
4265 // navigation occurs, the fetcher will get destroyed.
4266 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454267 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454268 navigation_state->set_alt_error_page_fetcher(
4269 new AltErrorPageResourceFetcher(
4270 error_page_url, frame, error,
4271 NewCallback(this, &RenderView::AltErrorPageFinished)));
4272 return true;
4273}
4274
initial.commit09911bf2008-07-26 23:55:294275std::string RenderView::GetAltHTMLForTemplate(
4276 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394277 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294278 ResourceBundle::GetSharedInstance().GetRawDataResource(
4279 template_resource_id));
4280
4281 if (template_html.empty()) {
4282 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4283 return "";
4284 }
[email protected]7cd22a52009-07-14 00:40:254285
initial.commit09911bf2008-07-26 23:55:294286 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254287 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294288 template_html, &error_strings, "t");
4289}
[email protected]0e79b9e2009-02-13 04:20:484290
[email protected]15d79e12009-08-02 19:23:454291void RenderView::AltErrorPageFinished(WebFrame* frame,
4292 const WebURLError& original_error,
4293 const std::string& html) {
4294 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:554295
4296 // If we failed to download the alternate error page, fall back to the
4297 // original error page if present. Otherwise, LoadNavigationErrorPage
4298 // will simply display a default error page.
4299 const std::string* html_to_load = &html;
4300 if (html.empty()) {
4301 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454302 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:554303 html_to_load = &navigation_state->postponed_data();
4304 }
4305 LoadNavigationErrorPage(
4306 frame, WebURLRequest(), original_error, *html_to_load, true);
[email protected]15d79e12009-08-02 19:23:454307}
4308
[email protected]30f75e62009-02-25 22:01:004309void RenderView::OnMoveOrResizeStarted() {
4310 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474311 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004312}
4313
[email protected]30f75e62009-02-25 22:01:004314void RenderView::OnResize(const gfx::Size& new_size,
4315 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104316 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474317 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104318
4319 if (send_preferred_size_changes_) {
4320 // If resizing to a size larger than |disable_scrollbars_size_limit_| in
4321 // either width or height, allow scroll bars.
4322 bool allow_scrollbars = (
4323 disable_scrollbars_size_limit_.width() <= new_size.width() ||
[email protected]45c6e532010-03-15 23:51:244324 disable_scrollbars_size_limit_.height() <= new_size.height());
[email protected]cda45c02010-02-25 19:28:104325 webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
4326 }
4327 }
4328
[email protected]30f75e62009-02-25 22:01:004329 RenderWidget::OnResize(new_size, resizer_rect);
4330}
[email protected]0aa477bd2009-03-23 22:21:434331
[email protected]00c39612010-03-06 02:53:284332void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014333 // Notify the pepper plugins that we started painting.
4334 pepper_delegate_.ViewInitiatedPaint();
4335
4336 // Notify any "old-style" pepper plugins that we started painting. This is
4337 // used for internal bookkeeping only, so we know that the set can not change
4338 // under us.
[email protected]00c39612010-03-06 02:53:284339 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:014340 current_oldstyle_pepper_plugins_.begin();
4341 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:284342 (*i)->RenderViewInitiatedPaint();
4343}
4344
4345void RenderView::DidFlushPaint() {
4346 // Notify any pepper plugins that we painted. This will call into the plugin,
4347 // and we it may ask to close itself as a result. This will, in turn, modify
4348 // our set, possibly invalidating the iterator. So we iterate on a copy that
4349 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014350 pepper_delegate_.ViewFlushedPaint();
4351
4352 // Notify any old-style pepper plugins that we painted. This will call into
4353 // the plugin, and we it may ask to close itself as a result. This will, in
4354 // turn, modify our set, possibly invalidating the iterator. So we iterate on
4355 // a copy that won't change out from under us.
4356 // This should be deleted when we don't support old Pepper anymore.
4357 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:284358 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
4359 i != plugins.end(); ++i) {
4360 // The copy above makes sure our iterator is never invalid if some plugins
4361 // are destroyed. But some plugin may decide to close all of its views in
4362 // response to a paint in one of them, so we need to make sure each one is
4363 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:014364 if (current_oldstyle_pepper_plugins_.find(*i) !=
4365 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:284366 (*i)->RenderViewFlushedPaint();
4367 }
4368
4369 WebFrame* main_frame = webview()->mainFrame();
4370
4371 // If we have a provisional frame we are between the start and commit stages
4372 // of loading and we don't want to save stats.
4373 if (!main_frame->provisionalDataSource()) {
4374 WebDataSource* ds = main_frame->dataSource();
4375 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4376 DCHECK(navigation_state);
4377
4378 Time now = Time::Now();
4379 if (navigation_state->first_paint_time().is_null()) {
4380 navigation_state->set_first_paint_time(now);
4381 }
4382 if (navigation_state->first_paint_after_load_time().is_null() &&
4383 !navigation_state->finish_load_time().is_null()) {
4384 navigation_state->set_first_paint_after_load_time(now);
4385 }
4386 }
4387}
4388
[email protected]05d478752009-04-08 23:38:164389void RenderView::OnClearFocusedNode() {
4390 if (webview())
[email protected]26aa0482009-09-30 16:55:274391 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164392}
4393
[email protected]699ab0d2009-04-23 23:19:144394void RenderView::OnSetBackground(const SkBitmap& background) {
4395 if (webview())
[email protected]b4bb2502009-10-01 22:35:274396 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144397
4398 SetBackground(background);
4399}
4400
[email protected]8c66c5a2009-07-22 17:26:344401void RenderView::OnSetActive(bool active) {
4402 if (webview())
[email protected]b4bb2502009-10-01 22:35:274403 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264404
4405#if defined(OS_MACOSX)
4406 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4407 for (plugin_it = plugin_delegates_.begin();
4408 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4409 (*plugin_it)->SetWindowFocus(active);
4410 }
4411#endif
[email protected]8c66c5a2009-07-22 17:26:344412}
4413
[email protected]6ce7abc52010-02-02 18:40:144414#if defined(OS_MACOSX)
4415void RenderView::OnSetWindowVisibility(bool visible) {
4416 // Inform plugins that their container has changed visibility.
4417 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4418 for (plugin_it = plugin_delegates_.begin();
4419 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4420 (*plugin_it)->SetContainerVisibility(visible);
4421 }
4422}
[email protected]1e6e3c992010-02-08 15:52:134423
4424void RenderView::OnWindowFrameChanged(gfx::Rect window_frame,
4425 gfx::Rect view_frame) {
4426 // Inform plugins that their window's frame has changed.
4427 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4428 for (plugin_it = plugin_delegates_.begin();
4429 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4430 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4431 }
4432}
[email protected]6ce7abc52010-02-02 18:40:144433#endif // OS_MACOSX
4434
[email protected]309d7a282009-03-24 09:18:274435void RenderView::SendExtensionRequest(const std::string& name,
[email protected]e4dad9fb2009-10-06 18:15:584436 const ListValue& args,
[email protected]bb64b512010-04-02 21:01:394437 const GURL& source_url,
[email protected]c6619182009-05-12 14:59:324438 int request_id,
[email protected]2f25d7b92009-06-10 00:06:474439 bool has_callback) {
[email protected]bb64b512010-04-02 21:01:394440 Send(new ViewHostMsg_ExtensionRequest(routing_id_,
4441 name,
4442 args,
4443 source_url,
4444 request_id,
[email protected]2f25d7b92009-06-10 00:06:474445 has_callback));
[email protected]309d7a282009-03-24 09:18:274446}
4447
[email protected]c6619182009-05-12 14:59:324448void RenderView::OnExtensionResponse(int request_id,
4449 bool success,
4450 const std::string& response,
4451 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:354452 ExtensionProcessBindings::HandleResponse(
4453 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:274454}
[email protected]c20210e62009-04-03 21:39:264455
[email protected]078b34612009-09-19 19:31:514456void RenderView::InjectToolstripCSS() {
4457 if (view_type_ != ViewType::EXTENSION_TOOLSTRIP)
4458 return;
4459
4460 static const base::StringPiece toolstrip_css(
4461 ResourceBundle::GetSharedInstance().GetRawDataResource(
4462 IDR_EXTENSION_TOOLSTRIP_CSS));
4463 std::string css = toolstrip_css.as_string();
4464 InsertCSS(L"", css, "ToolstripDefaultCSS");
4465}
4466
[email protected]7120f132009-07-20 21:05:374467void RenderView::OnExtensionMessageInvoke(const std::string& function_name,
[email protected]d7259472010-03-24 08:40:494468 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:194469 bool requires_incognito_access,
4470 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:494471 RendererExtensionBindings::Invoke(
[email protected]a807bbe2010-04-14 10:51:194472 function_name, args, this, requires_incognito_access, event_url);
[email protected]7120f132009-07-20 21:05:374473}
4474
[email protected]e7e4f3c2009-04-21 15:24:084475// Dump all load time histograms.
[email protected]c20210e62009-04-03 21:39:264476//
[email protected]c20210e62009-04-03 21:39:264477// The time points we keep are
4478// request: time document was requested by user
4479// start: time load of document started
[email protected]a2f6bc112009-06-27 16:27:254480// commit: time load of document started
[email protected]7a9b51f2009-06-29 21:28:294481// finish_document: main document loaded, before onload()
[email protected]c20210e62009-04-03 21:39:264482// finish: after onload() and all resources are loaded
[email protected]7a9b51f2009-06-29 21:28:294483// first_paint: first paint performed
4484// first_paint_after_load: first paint performed after load is finished
4485// begin: request if it was user requested, start otherwise
4486//
[email protected]e7e4f3c2009-04-21 15:24:084487// It's possible for the request time not to be set, if a client
4488// redirect had been done (the user never requested the page)
4489// Also, it's possible to load a page without ever laying it out
[email protected]7a9b51f2009-06-29 21:28:294490// so first_paint and first_paint_after_load can be 0.
[email protected]c20210e62009-04-03 21:39:264491void RenderView::DumpLoadHistograms() const {
[email protected]cf9a7bc2010-06-11 18:54:504492 // Configuration for PLT related histograms.
4493 static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10));
4494 static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10));
4495 static const size_t kPLTCount(100);
4496 #define PLT_HISTOGRAM(name, sample) \
4497 UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount);
4498
[email protected]26aa0482009-09-30 16:55:274499 WebFrame* main_frame = webview()->mainFrame();
[email protected]ed3fb032009-06-16 19:50:564500 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454501 NavigationState::FromDataSource(main_frame->dataSource());
[email protected]ed3fb032009-06-16 19:50:564502
[email protected]f9f4841b2010-03-20 05:41:424503 // If we've already dumped, do nothing.
4504 if (navigation_state->load_histograms_recorded())
[email protected]7a9b51f2009-06-29 21:28:294505 return;
[email protected]cf9a7bc2010-06-11 18:54:504506
4507 // Collect measurement times.
[email protected]b855ebe62010-05-12 23:01:454508 Time start = navigation_state->start_load_time();
4509 if (start.is_null())
4510 return; // Probably very premature abandonment of page.
4511 Time commit = navigation_state->commit_load_time();
4512 if (commit.is_null())
4513 return; // Probably very premature abandonment of page.
[email protected]cf9a7bc2010-06-11 18:54:504514
[email protected]b855ebe62010-05-12 23:01:454515 // We properly handle null values for the next 3 variables.
4516 Time request = navigation_state->request_time();
4517 Time first_paint = navigation_state->first_paint_time();
4518 Time first_paint_after_load = navigation_state->first_paint_after_load_time();
[email protected]b855ebe62010-05-12 23:01:454519 Time finish = navigation_state->finish_load_time();
4520 Time finish_doc = navigation_state->finish_document_load_time();
[email protected]ed3fb032009-06-16 19:50:564521
[email protected]f9f4841b2010-03-20 05:41:424522 // Handle case where user hits "stop" or "back" before loading completely.
4523 bool abandoned_page = finish.is_null();
4524 if (abandoned_page) {
4525 finish = Time::Now();
4526 navigation_state->set_finish_load_time(finish);
4527 }
[email protected]f9f4841b2010-03-20 05:41:424528
[email protected]cf9a7bc2010-06-11 18:54:504529 if (finish_doc.is_null()) {
4530 DCHECK(abandoned_page); // how can the doc have finished but not the page?
4531 if (!abandoned_page)
4532 return; // Don't try to record a stat which is broken.
4533 finish_doc = finish;
4534 navigation_state->set_finish_document_load_time(finish_doc);
4535 }
4536
4537 // Note: Client side redirects will have no request time.
4538 Time begin = request.is_null() ? start : request;
4539 TimeDelta begin_to_finish_doc = finish_doc - begin;
4540 TimeDelta begin_to_finish = finish - begin;
4541 TimeDelta start_to_finish = finish - start;
[email protected]ef1d8d322010-06-13 18:31:254542 TimeDelta start_to_commit = commit - start;
[email protected]f8999642009-10-27 21:39:424543
[email protected]a7ccc4d2010-01-27 08:14:484544 NavigationState::LoadType load_type = navigation_state->load_type();
[email protected]cf9a7bc2010-06-11 18:54:504545
4546 // Aggregate PLT data across all link types.
4547 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2);
4548 UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type,
4549 NavigationState::kLoadTypeMax);
[email protected]ef1d8d322010-06-13 18:31:254550 PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504551 PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit);
4552 PLT_HISTOGRAM("PLT.FinishDocToFinish", finish - finish_doc);
4553 PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin);
4554 PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish);
4555 if (!request.is_null()) {
4556 PLT_HISTOGRAM("PLT.RequestToStart", start - request);
4557 PLT_HISTOGRAM("PLT.RequestToFinish", finish - request);
4558 }
4559 PLT_HISTOGRAM("PLT.CommitToFinish", finish - commit);
4560 if (!first_paint.is_null()) {
4561 DCHECK(begin <= first_paint);
4562 PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin);
4563 DCHECK(commit <= first_paint);
4564 PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit);
4565 }
4566 if (!first_paint_after_load.is_null()) {
4567 DCHECK(begin <= first_paint_after_load);
4568 PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad",
4569 first_paint_after_load - begin);
4570 DCHECK(commit <= first_paint_after_load);
4571 PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad",
4572 first_paint_after_load - commit);
4573 DCHECK(finish <= first_paint_after_load);
4574 PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad",
4575 first_paint_after_load - finish);
4576 }
4577 PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc);
4578 PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish);
4579
4580 // Load type related histograms.
4581 switch (load_type) {
4582 case NavigationState::UNDEFINED_LOAD:
4583 PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc);
4584 PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish);
4585 break;
4586 case NavigationState::RELOAD:
4587 PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc);
4588 PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish);
4589 break;
4590 case NavigationState::HISTORY_LOAD:
4591 PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc);
4592 PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish);
4593 break;
4594 case NavigationState::NORMAL_LOAD:
4595 PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc);
4596 PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish);
4597 break;
4598 case NavigationState::LINK_LOAD_NORMAL:
4599 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal",
4600 begin_to_finish_doc);
4601 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal", begin_to_finish);
4602 break;
4603 case NavigationState::LINK_LOAD_RELOAD:
4604 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload",
4605 begin_to_finish_doc);
4606 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload", begin_to_finish);
4607 break;
4608 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4609 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk",
4610 begin_to_finish_doc);
4611 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk", begin_to_finish);
4612 break;
4613 case NavigationState::LINK_LOAD_CACHE_ONLY:
4614 PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly",
4615 begin_to_finish_doc);
4616 PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly", begin_to_finish);
4617 break;
4618 default:
4619 break;
4620 }
4621
4622 // Histograms to determine if DNS prefetching has an impact on PLT.
4623 static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") &&
4624 !FieldTrialList::Find("DnsImpact")->group_name().empty());
4625 if (use_dns_histogram) {
4626 UMA_HISTOGRAM_ENUMERATION(
4627 FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"),
4628 abandoned_page ? 1 : 0, 2);
4629 UMA_HISTOGRAM_ENUMERATION(
4630 FieldTrial::MakeName("PLT.LoadType", "DnsImpact"),
4631 load_type, NavigationState::kLoadTypeMax);
4632 switch (load_type) {
4633 case NavigationState::NORMAL_LOAD:
4634 PLT_HISTOGRAM(FieldTrial::MakeName(
4635 "PLT.BeginToFinish_NormalLoad", "DnsImpact"), begin_to_finish);
4636 break;
4637 case NavigationState::LINK_LOAD_NORMAL:
4638 PLT_HISTOGRAM(FieldTrial::MakeName(
4639 "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"),
4640 begin_to_finish);
4641 break;
4642 case NavigationState::LINK_LOAD_RELOAD:
4643 PLT_HISTOGRAM(FieldTrial::MakeName(
4644 "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"),
4645 begin_to_finish);
4646 break;
4647 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4648 PLT_HISTOGRAM(FieldTrial::MakeName(
4649 "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"),
4650 begin_to_finish);
4651 break;
4652 default:
4653 break;
4654 }
4655 }
4656
4657 // Histograms to determine if the number of connections has an
4658 // impact on PLT.
4659 // TODO(jar): Consider removing the per-link-type versions. We
4660 // really only need LINK_LOAD_NORMAL and NORMAL_LOAD.
4661 static bool use_conn_impact_histogram(
4662 FieldTrialList::Find("ConnCountImpact") &&
4663 !FieldTrialList::Find("ConnCountImpact")->group_name().empty());
4664 if (use_conn_impact_histogram) {
4665 UMA_HISTOGRAM_ENUMERATION(
4666 FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"),
4667 abandoned_page ? 1 : 0, 2);
4668 switch (load_type) {
4669 case NavigationState::NORMAL_LOAD:
4670 PLT_HISTOGRAM(FieldTrial::MakeName(
4671 "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"),
4672 begin_to_finish);
4673 break;
4674 case NavigationState::LINK_LOAD_NORMAL:
4675 PLT_HISTOGRAM(FieldTrial::MakeName(
4676 "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"),
4677 begin_to_finish);
4678 break;
4679 case NavigationState::LINK_LOAD_RELOAD:
4680 PLT_HISTOGRAM(FieldTrial::MakeName(
4681 "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"),
4682 begin_to_finish);
4683 break;
4684 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4685 PLT_HISTOGRAM(FieldTrial::MakeName(
4686 "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"),
4687 begin_to_finish);
4688 break;
4689 default:
4690 break;
4691 }
4692 }
4693
[email protected]241c5c2c2010-06-21 18:46:004694
4695 static bool use_idle_socket_timeout_histogram(
4696 FieldTrialList::Find("IdleSktToImpact") &&
4697 !FieldTrialList::Find("IdleSktToImpact")->group_name().empty());
4698 if (use_idle_socket_timeout_histogram) {
4699 UMA_HISTOGRAM_ENUMERATION(
4700 FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"),
4701 abandoned_page ? 1 : 0, 2);
4702 switch (load_type) {
4703 case NavigationState::NORMAL_LOAD:
4704 PLT_HISTOGRAM(FieldTrial::MakeName(
4705 "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"),
4706 begin_to_finish);
4707 break;
4708 case NavigationState::LINK_LOAD_NORMAL:
4709 PLT_HISTOGRAM(FieldTrial::MakeName(
4710 "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"),
4711 begin_to_finish);
4712 break;
4713 case NavigationState::LINK_LOAD_RELOAD:
4714 PLT_HISTOGRAM(FieldTrial::MakeName(
4715 "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"),
4716 begin_to_finish);
4717 break;
4718 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4719 PLT_HISTOGRAM(FieldTrial::MakeName(
4720 "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"),
4721 begin_to_finish);
4722 break;
4723 default:
4724 break;
4725 }
4726 }
4727
[email protected]cf9a7bc2010-06-11 18:54:504728 // Histograms to determine if SDCH has an impact.
4729 // TODO(jar): Consider removing per-link load types and the enumeration.
4730 static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") &&
4731 !FieldTrialList::Find("GlobalSdch")->group_name().empty());
4732 if (use_sdch_histogram) {
4733 UMA_HISTOGRAM_ENUMERATION(
4734 FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"),
4735 load_type, NavigationState::kLoadTypeMax);
4736 switch (load_type) {
4737 case NavigationState::NORMAL_LOAD:
4738 PLT_HISTOGRAM(FieldTrial::MakeName(
4739 "PLT.BeginToFinish_NormalLoad", "GlobalSdch"),
4740 begin_to_finish);
4741 break;
4742 case NavigationState::LINK_LOAD_NORMAL:
4743 PLT_HISTOGRAM(FieldTrial::MakeName(
4744 "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"),
4745 begin_to_finish);
4746 break;
4747 case NavigationState::LINK_LOAD_RELOAD:
4748 PLT_HISTOGRAM(FieldTrial::MakeName(
4749 "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"),
4750 begin_to_finish);
4751 break;
4752 case NavigationState::LINK_LOAD_CACHE_STALE_OK:
4753 PLT_HISTOGRAM(FieldTrial::MakeName(
4754 "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"),
4755 begin_to_finish);
4756 break;
4757 case NavigationState::LINK_LOAD_CACHE_ONLY:
4758 PLT_HISTOGRAM(FieldTrial::MakeName(
4759 "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"),
4760 begin_to_finish);
4761 break;
4762 default:
4763 break;
4764 }
4765 }
4766
4767 // Histograms to determine if cache size has an impact on PLT.
4768 static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") &&
4769 !FieldTrialList::Find("CacheSize")->group_name().empty());
4770 if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type &&
4771 NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) {
4772 // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like
4773 // StartToFinish or BeginToFinish would be better.
4774 PLT_HISTOGRAM(FieldTrial::MakeName(
4775 "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc);
4776 }
4777
4778 // Histograms to determine if SPDY has an impact.
4779 // TODO(mbelshe): After we've seen the difference between BeginToFinish
4780 // and StartToFinish, consider removing one or the other.
4781 static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") &&
4782 !FieldTrialList::Find("SpdyImpact")->group_name().empty());
[email protected]193b0b892010-06-26 03:57:574783 // Spdy requests triggered by alternate protocol are excluded here.
4784 // This is because when alternate protocol is avaiable, FieldTrial will
4785 // either use npn_spdy or pure http, not npn_http via TLS. That will cause
4786 // bias for npn_spdy and npn_http.
4787 if (use_spdy_histogram && navigation_state->was_npn_negotiated() &&
4788 !navigation_state->was_alternate_protocol_available()) {
[email protected]30b35882010-06-14 21:21:014789 UMA_HISTOGRAM_ENUMERATION(
4790 FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"),
4791 abandoned_page ? 1 : 0, 2);
[email protected]cf9a7bc2010-06-11 18:54:504792 switch (load_type) {
4793 case NavigationState::LINK_LOAD_NORMAL:
4794 PLT_HISTOGRAM(FieldTrial::MakeName(
4795 "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4796 begin_to_finish);
4797 PLT_HISTOGRAM(FieldTrial::MakeName(
4798 "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4799 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:254800 PLT_HISTOGRAM(FieldTrial::MakeName(
4801 "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"),
4802 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504803 break;
4804 case NavigationState::NORMAL_LOAD:
4805 PLT_HISTOGRAM(FieldTrial::MakeName(
4806 "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
4807 begin_to_finish);
4808 PLT_HISTOGRAM(FieldTrial::MakeName(
4809 "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"),
4810 start_to_finish);
[email protected]ef1d8d322010-06-13 18:31:254811 PLT_HISTOGRAM(FieldTrial::MakeName(
4812 "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"),
4813 start_to_commit);
[email protected]cf9a7bc2010-06-11 18:54:504814 break;
4815 default:
4816 break;
4817 }
4818 }
4819
[email protected]193b0b892010-06-26 03:57:574820 // Histograms to compare the impact of alternate protocol: when the
4821 // protocol(spdy) is used vs. when it is ignored and http is used.
4822 if (navigation_state->was_alternate_protocol_available()) {
4823 if (!navigation_state->was_npn_negotiated()) {
4824 // This means that even there is alternate protocols for npn_http or
4825 // npn_spdy, they are not taken (due to the fieldtrial).
4826 switch (load_type) {
4827 case NavigationState::LINK_LOAD_NORMAL:
4828 PLT_HISTOGRAM(
4829 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http",
4830 start_to_finish);
4831 PLT_HISTOGRAM(
4832 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http",
4833 start_to_commit);
4834 break;
4835 case NavigationState::NORMAL_LOAD:
4836 PLT_HISTOGRAM(
4837 "PLT.StartToFinish_NormalLoad_AlternateProtocol_http",
4838 start_to_finish);
4839 PLT_HISTOGRAM(
4840 "PLT.StartToCommit_NormalLoad_AlternateProtocol_http",
4841 start_to_commit);
4842 break;
4843 default:
4844 break;
4845 }
4846 } else if (navigation_state->was_fetched_via_spdy()) {
4847 switch (load_type) {
4848 case NavigationState::LINK_LOAD_NORMAL:
4849 PLT_HISTOGRAM(
4850 "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy",
4851 start_to_finish);
4852 PLT_HISTOGRAM(
4853 "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy",
4854 start_to_commit);
4855 break;
4856 case NavigationState::NORMAL_LOAD:
4857 PLT_HISTOGRAM(
4858 "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy",
4859 start_to_finish);
4860 PLT_HISTOGRAM(
4861 "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy",
4862 start_to_commit);
4863 break;
4864 default:
4865 break;
4866 }
4867 }
4868 }
4869
[email protected]cf9a7bc2010-06-11 18:54:504870 // Record page load time and abandonment rates for proxy cases.
4871 GURL url = GURL(main_frame->url());
4872 if (navigation_state->was_fetched_via_proxy()) {
4873 if (url.SchemeIs("https")) {
4874 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish);
4875 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https",
4876 abandoned_page ? 1 : 0, 2);
4877 } else {
4878 PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish);
4879 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http",
4880 abandoned_page ? 1 : 0, 2);
4881 }
4882 } else {
4883 if (url.SchemeIs("https")) {
4884 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https", start_to_finish);
4885 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https",
4886 abandoned_page ? 1 : 0, 2);
4887 } else {
4888 PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http", start_to_finish);
4889 UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http",
4890 abandoned_page ? 1 : 0, 2);
4891 }
4892 }
[email protected]a7ccc4d2010-01-27 08:14:484893
[email protected]ab9eabac2010-03-16 16:54:104894 // Site isolation metrics.
4895 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess",
4896 cross_origin_access_count_);
4897 UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess",
4898 same_origin_access_count_);
4899
[email protected]cf9a7bc2010-06-11 18:54:504900 // Log some PLT data to the error log.
4901 LogNavigationState(navigation_state, main_frame->dataSource());
[email protected]7a9b51f2009-06-29 21:28:294902
4903 navigation_state->set_load_histograms_recorded(true);
[email protected]1f4fc8e8c2010-01-02 00:46:414904
4905 // Since there are currently no guarantees that renderer histograms will be
4906 // sent to the browser, we initiate a PostTask here to be sure that we send
4907 // the histograms we generated. Without this call, pages that don't have an
4908 // on-close-handler might generate data that is lost when the renderer is
4909 // shutdown abruptly (perchance because the user closed the tab).
[email protected]a7ccc4d2010-01-27 08:14:484910 // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it
4911 // should post when the onload is complete, so that it doesn't interfere with
4912 // the next load.
[email protected]1f4fc8e8c2010-01-02 00:46:414913 if (RenderThread::current()) {
4914 RenderThread::current()->SendHistograms(
[email protected]7c927b62010-02-24 09:54:134915 chrome::kHistogramSynchronizerReservedSequenceNumber);
[email protected]1f4fc8e8c2010-01-02 00:46:414916 }
[email protected]c20210e62009-04-03 21:39:264917}
[email protected]e846d0d2009-05-20 00:53:064918
[email protected]f8999642009-10-27 21:39:424919void RenderView::LogNavigationState(const NavigationState* state,
4920 const WebDataSource* ds) const {
4921 // Because this function gets called on every page load,
4922 // take extra care to optimize it away if logging is turned off.
4923 if (logging::LOG_INFO < logging::GetMinLogLevel())
4924 return;
4925
4926 DCHECK(state);
4927 DCHECK(ds);
4928 GURL url(ds->request().url());
4929 Time start = state->start_load_time();
4930 Time finish = state->finish_load_time();
4931 // TODO(mbelshe): should we log more stats?
4932 LOG(INFO) << "PLT: "
4933 << (finish - start).InMilliseconds()
4934 << "ms "
4935 << url.spec();
4936}
4937
[email protected]cc0445f2009-10-13 16:09:084938void RenderView::focusAccessibilityObject(
4939 const WebAccessibilityObject& acc_obj) {
[email protected]e846d0d2009-05-20 00:53:064940#if defined(OS_WIN)
[email protected]c7287a92009-11-04 20:06:154941 // TODO(dglazkov): Current logic implies that focus change can only be made
4942 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4943 // where accessibility is initialized. We should determine whether that's
4944 // right.
4945 if (!accessibility_.get())
4946 return;
[email protected]e846d0d2009-05-20 00:53:064947
4948 // Retrieve the accessibility object id of the AccessibilityObject.
[email protected]c7287a92009-11-04 20:06:154949 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
[email protected]e846d0d2009-05-20 00:53:064950
4951 // If id is valid, alert the browser side that an accessibility focus change
4952 // occurred.
4953 if (acc_obj_id >= 0)
4954 Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id));
4955
4956#else // defined(OS_WIN)
4957 // TODO(port): accessibility not yet implemented
4958 NOTIMPLEMENTED();
4959#endif
4960}
[email protected]daa8c58e2009-06-15 17:21:104961
[email protected]e9e07992010-02-17 21:04:364962void RenderView::SendForms(WebFrame* frame) {
[email protected]b715f7f2010-04-05 22:01:044963 // TODO(jhawkins): Use FormManager once we have strict ordering of form
4964 // control elements in the cache.
4965 WebVector<WebFormElement> web_forms;
4966 frame->forms(web_forms);
4967
[email protected]b1438212010-04-03 00:30:594968 std::vector<FormData> forms;
[email protected]b715f7f2010-04-05 22:01:044969 for (size_t i = 0; i < web_forms.size(); ++i) {
4970 const WebFormElement& web_form = web_forms[i];
4971
4972 FormData form;
[email protected]b715f7f2010-04-05 22:01:044973 if (FormManager::WebFormElementToFormData(
[email protected]573c1c272010-05-25 19:28:064974 web_form, FormManager::REQUIRE_NONE, false, &form))
[email protected]b715f7f2010-04-05 22:01:044975 forms.push_back(form);
4976 }
[email protected]e6efd022010-03-31 09:34:504977
4978 if (!forms.empty())
4979 Send(new ViewHostMsg_FormsSeen(routing_id_, forms));
[email protected]e9e07992010-02-17 21:04:364980}
4981
[email protected]a3018be2010-03-09 04:28:484982void RenderView::didChangeAccessibilityObjectState(
4983 const WebKit::WebAccessibilityObject& acc_obj) {
4984#if defined(OS_WIN)
4985 // TODO(dglazkov): Current logic implies that a state change can only be made
4986 // after at least one call to RenderView::OnGetAccessibilityInfo, which is
4987 // where accessibility is initialized. We should determine whether that's
4988 // right.
4989 if (!accessibility_.get())
4990 return;
4991
4992 // Retrieve the accessibility object id of the AccessibilityObject.
4993 int acc_obj_id = accessibility_->addOrGetId(acc_obj);
4994
4995 // If id is valid, alert the browser side that an accessibility object state
4996 // change occurred.
4997 if (acc_obj_id >= 0)
4998 Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_,
4999 acc_obj_id));
5000
5001#else // defined(OS_WIN)
5002 // TODO(port): accessibility not yet implemented
5003 NOTIMPLEMENTED();
5004#endif
5005}
5006
[email protected]4d44a1c2010-04-28 19:20:415007void RenderView::SendPasswordForms(WebFrame* frame, bool only_visible) {
[email protected]55ced002010-05-21 04:49:595008 // Make sure that this security origin is allowed to use password manager.
5009 WebSecurityOrigin security_origin = frame->securityOrigin();
5010 if (!security_origin.canAccessPasswordManager())
5011 return;
5012
[email protected]979c28b2009-11-07 01:30:485013 WebVector<WebFormElement> forms;
[email protected]dd7daa82009-08-10 05:46:455014 frame->forms(forms);
[email protected]daa8c58e2009-06-15 17:21:105015
5016 std::vector<PasswordForm> password_forms;
5017 for (size_t i = 0; i < forms.size(); ++i) {
[email protected]979c28b2009-11-07 01:30:485018 const WebFormElement& form = forms[i];
[email protected]daa8c58e2009-06-15 17:21:105019
5020 // Respect autocomplete=off.
[email protected]4d44a1c2010-04-28 19:20:415021 if (!form.autoComplete())
5022 continue;
5023 if (only_visible && !form.hasNonEmptyBoundingBox())
5024 continue;
5025 scoped_ptr<PasswordForm> password_form(
5026 PasswordFormDomManager::CreatePasswordForm(form));
5027 if (password_form.get())
5028 password_forms.push_back(*password_form);
[email protected]daa8c58e2009-06-15 17:21:105029 }
5030
[email protected]4d44a1c2010-04-28 19:20:415031 if (password_forms.empty())
5032 return;
5033 if (only_visible)
5034 Send(new ViewHostMsg_PasswordFormsVisible(routing_id_, password_forms));
5035 else
5036 Send(new ViewHostMsg_PasswordFormsFound(routing_id_, password_forms));
[email protected]daa8c58e2009-06-15 17:21:105037}
[email protected]0fda7272009-06-26 15:49:335038
5039void RenderView::Print(WebFrame* frame, bool script_initiated) {
5040 DCHECK(frame);
5041 if (print_helper_.get() == NULL) {
5042 print_helper_.reset(new PrintWebViewHelper(this));
5043 }
5044 print_helper_->Print(frame, script_initiated);
5045}
[email protected]446705872009-09-10 07:22:485046
5047void RenderView::OnSetEditCommandsForNextKeyEvent(
5048 const EditCommands& edit_commands) {
5049 edit_commands_ = edit_commands;
5050}
5051
[email protected]61f5a7b2009-12-22 22:21:205052void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275053 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355054 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205055 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5056 false));
[email protected]912256b32009-09-18 09:47:355057 return;
5058 }
5059
[email protected]fa7b6b542009-11-03 05:02:305060 WebDataSource* ds = main_frame->dataSource();
5061 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5062 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205063 pending_code_execution_queue_.push(
5064 linked_ptr<ViewMsg_ExecuteCode_Params>(
5065 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305066 return;
5067 }
5068
[email protected]61f5a7b2009-12-22 22:21:205069 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305070}
5071
5072void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205073 const ViewMsg_ExecuteCode_Params& params) {
[email protected]d146b832009-12-23 02:45:485074 // Don't execute scripts in gallery pages.
5075 GURL frame_url = GURL(frame->url());
[email protected]638d45d2010-07-09 17:35:085076 if (frame_url.host() == GURL(Extension::ChromeStoreURL()).host()
5077 && !CommandLine::ForCurrentProcess()->HasSwitch(
5078 switches::kAllowScriptingGallery)) {
[email protected]d146b832009-12-23 02:45:485079 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
5080 return;
5081 }
5082
[email protected]20ad2692009-11-20 18:27:205083 std::vector<WebFrame*> frame_vector;
5084 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205085 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205086 GetAllChildFrames(frame, &frame_vector);
5087
5088 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5089 frame_it != frame_vector.end(); ++frame_it) {
5090 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205091 if (params.is_javascript) {
5092 if (!UrlMatchesPermissions(frame->url(), params.host_permissions))
5093 continue;
5094
[email protected]20ad2692009-11-20 18:27:205095 std::vector<WebScriptSource> sources;
5096 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205097 WebScriptSource(WebString::fromUTF8(params.code)));
5098 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205099 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205100 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205101 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5102 } else {
[email protected]61f5a7b2009-12-22 22:21:205103 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205104 }
[email protected]912256b32009-09-18 09:47:355105 }
5106
[email protected]61f5a7b2009-12-22 22:21:205107 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355108}
5109
[email protected]60c42a8c72009-10-09 04:08:595110void RenderView::Close() {
5111 // We need to grab a pointer to the doomed WebView before we destroy it.
5112 WebView* doomed = webview();
5113 RenderWidget::Close();
5114 Singleton<ViewMap>::get()->erase(doomed);
5115}
5116
[email protected]446705872009-09-10 07:22:485117void RenderView::DidHandleKeyEvent() {
5118 edit_commands_.clear();
5119}
5120
[email protected]941e4552010-02-01 21:23:435121#if defined(OS_MACOSX)
5122void RenderView::OnWasHidden() {
5123 RenderWidget::OnWasHidden();
5124
5125 // Inform plugins that their container is no longer visible.
5126 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5127 for (plugin_it = plugin_delegates_.begin();
5128 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5129 (*plugin_it)->SetContainerVisibility(false);
5130 }
5131}
5132
5133void RenderView::OnWasRestored(bool needs_repainting) {
5134 RenderWidget::OnWasRestored(needs_repainting);
5135
5136 // Inform plugins that their container is now visible.
5137 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5138 for (plugin_it = plugin_delegates_.begin();
5139 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5140 (*plugin_it)->SetContainerVisibility(true);
5141 }
5142}
[email protected]1e6e3c992010-02-08 15:52:135143
5144void RenderView::OnSetFocus(bool enable) {
5145 RenderWidget::OnSetFocus(enable);
5146
[email protected]7d3c02c2010-05-05 23:10:315147 if (webview() && webview()->isActive()) {
[email protected]1e6e3c992010-02-08 15:52:135148 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5149 for (plugin_it = plugin_delegates_.begin();
5150 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]7d3c02c2010-05-05 23:10:315151 // RenderWidget's call to setFocus can cause the underlying webview's
5152 // activation state to change just like a call to setIsActive.
5153 if (enable)
5154 (*plugin_it)->SetWindowFocus(true);
5155 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135156 }
5157 }
5158}
[email protected]941e4552010-02-01 21:23:435159#endif // OS_MACOSX
5160
[email protected]83dde542009-09-11 20:59:555161void RenderView::EnsureDocumentTag() {
5162 // TODO(darin): There's actually no reason for this to be here. We should
5163 // have the browser side manage the document tag.
5164#if defined(OS_MACOSX)
5165 if (!has_document_tag_) {
5166 // Make the call to get the tag.
5167 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5168 has_document_tag_ = true;
5169 }
5170#endif
5171}
[email protected]12636df2009-09-28 22:32:215172
[email protected]43f28f832010-02-03 02:28:485173#if defined(OS_MACOSX)
[email protected]ea04a4e12010-04-15 00:58:035174gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
5175 bool opaque) {
[email protected]43f28f832010-02-03 02:28:485176 gfx::PluginWindowHandle window = NULL;
5177 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]ea04a4e12010-04-15 00:58:035178 routing_id(), opaque, &window));
[email protected]43f28f832010-02-03 02:28:485179 return window;
5180}
5181
5182void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
5183 if (window)
5184 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
5185}
5186
[email protected]44ce0b12010-03-12 16:45:335187void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5188 int32 width,
5189 int32 height,
5190 uint64 io_surface_identifier) {
5191 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485192 routing_id(), window, width, height, io_surface_identifier));
5193}
5194
[email protected]44ce0b12010-03-12 16:45:335195void RenderView::AcceleratedSurfaceSetTransportDIB(
5196 gfx::PluginWindowHandle window,
5197 int32 width,
5198 int32 height,
5199 TransportDIB::Handle transport_dib) {
5200 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075201 routing_id(), window, width, height, transport_dib));
5202}
5203
[email protected]44ce0b12010-03-12 16:45:335204TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5205 size_t size) {
[email protected]1aef98132010-02-23 18:00:075206 TransportDIB::Handle dib_handle;
5207 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385208 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075209 return dib_handle;
5210 // Return an invalid handle if Send() fails.
5211 return TransportDIB::DefaultHandleValue();
5212}
5213
[email protected]44ce0b12010-03-12 16:45:335214void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075215 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5216}
5217
[email protected]44ce0b12010-03-12 16:45:335218void RenderView::AcceleratedSurfaceBuffersSwapped(
5219 gfx::PluginWindowHandle window) {
5220 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window));
[email protected]43f28f832010-02-03 02:28:485221}
5222#endif
[email protected]58c321d2010-02-19 12:11:285223
[email protected]cdaf8d02010-03-30 19:52:475224bool RenderView::ScheduleFileChooser(
5225 const ViewHostMsg_RunFileChooser_Params& params,
5226 WebFileChooserCompletion* completion) {
5227 static const size_t kMaximumPendingFileChooseRequests = 4;
5228 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5229 // This sanity check prevents too many file choose requests from getting
5230 // queued which could DoS the user. Getting these is most likely a
5231 // programming error (there are many ways to DoS the user so it's not
5232 // considered a "real" security check), either in JS requesting many file
5233 // choosers to pop up, or in a plugin.
5234 //
5235 // TODO(brettw) we might possibly want to require a user gesture to open
5236 // a file picker, which will address this issue in a better way.
5237 return false;
5238 }
5239
5240 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5241 new PendingFileChooser(params, completion)));
5242 if (file_chooser_completions_.size() == 1) {
5243 // Actually show the browse dialog when this is the first request.
5244 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5245 }
5246 return true;
5247}
5248
[email protected]290838a2010-04-27 17:37:015249void RenderView::OnPageTranslated() {
5250 WebFrame* frame = webview()->mainFrame();
5251 if (!frame)
5252 return;
5253
5254 // The page is translated, so try to extract the form data again.
5255 form_manager_.ExtractForms(frame);
5256 SendForms(frame);
5257}
5258
[email protected]8a5f7002010-03-31 13:47:355259WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285260 if (!geolocation_dispatcher_.get())
5261 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5262 return geolocation_dispatcher_.get();
5263}
[email protected]61c9f032010-03-31 23:04:195264
[email protected]8079b362010-05-07 18:37:455265bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195266 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455267 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195268 if (frame->parent() != NULL)
5269 return false;
5270
5271 // Skip if navigation is on the same page (using '#').
5272 GURL frame_origin = GURL(frame->url()).GetOrigin();
5273 if (url.GetOrigin() != frame_origin || url.ref().empty()) {
5274 // The link click could stay on the same page, in cases where it sends some
5275 // parameters to the same URL.
5276 if (type == WebKit::WebNavigationTypeLinkClicked)
5277 return true;
5278
5279 if (last_top_level_navigation_page_id_ != page_id_ &&
5280 // Not interested in reloads.
5281 type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015282 type != WebKit::WebNavigationTypeFormSubmitted &&
5283 type != WebKit::WebNavigationTypeBackForward) {
[email protected]61c9f032010-03-31 23:04:195284 return true;
5285 }
5286 }
[email protected]d0ed50d2010-06-22 01:01:325287 // Not interested in reloads.
5288 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015289 type != WebKit::WebNavigationTypeFormSubmitted &&
5290 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325291 // The opener relationship between the new window and the parent allows the
5292 // new window to script the parent and vice versa. This is not allowed if
5293 // the origins of the two domains are different. This can be treated as a
5294 // top level navigation and routed back to the host.
5295 WebKit::WebFrame* opener = frame->opener();
5296 if (opener) {
5297 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5298 return true;
5299 }
5300 }
[email protected]61c9f032010-03-31 23:04:195301 return false;
5302}
[email protected]18ca9a6b2010-06-02 19:05:185303
5304void RenderView::QueryAutoFillFormData(const WebKit::WebNode& node,
5305 const WebKit::WebString& value,
5306 const WebKit::WebString& label,
5307 AutoFillAction action) {
5308 static int query_counter = 0;
5309 autofill_query_id_ = query_counter++;
5310
5311 webkit_glue::FormData form;
5312 const WebInputElement element = node.toConst<WebInputElement>();
5313 if (!form_manager_.FindFormWithFormControlElement(
5314 element, FormManager::REQUIRE_NONE, &form))
5315 return;
5316
5317 autofill_action_ = action;
5318 Send(new ViewHostMsg_FillAutoFillFormData(
5319 routing_id_, autofill_query_id_, form, value, label));
5320}