blob: 6b8761d3b624caad5e18a4e2ca3f8e1a909ff936 [file] [log] [blame]
[email protected]1b4209f2011-01-07 00:25:401// Copyright (c) 2011 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>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
initial.commit09911bf2008-07-26 23:55:299#include <string>
10#include <vector>
11
[email protected]2041cf342010-02-19 03:15:5912#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5014#include "base/compiler_specific.h"
[email protected]625332e02010-12-14 07:48:4915#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2817#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5118#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/string_piece.h"
20#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2821#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2622#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2223#include "base/utf_string_conversions.h"
[email protected]6c8afae52009-01-22 02:24:5724#include "build/build_config.h"
[email protected]19d6e1e82011-01-26 05:08:5825#include "chrome/common/autofill_messages.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]26a9acf2010-12-13 19:35:0532#include "chrome/common/database_messages.h"
[email protected]a0cf04a2010-06-23 03:29:5533#include "chrome/common/extensions/extension.h"
[email protected]ec7db282011-01-29 01:11:3634#include "chrome/common/extensions/extension_set.h"
[email protected]c5a272d2010-09-27 18:37:0835#include "chrome/common/file_system/file_system_dispatcher.h"
36#include "chrome/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]bb461532010-11-26 21:50:2337#include "chrome/common/json_value_serializer.h"
initial.commit09911bf2008-07-26 23:55:2938#include "chrome/common/jstemplate_builder.h"
[email protected]97c5c592010-08-03 08:22:2139#include "chrome/common/notification_service.h"
[email protected]630e26b2008-10-14 22:55:1740#include "chrome/common/page_zoom.h"
[email protected]f0557932011-01-25 20:20:5141#include "chrome/common/pepper_messages.h"
[email protected]4e0616e2010-05-28 14:55:5342#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2943#include "chrome/common/render_messages.h"
[email protected]13a1e4c3c2011-02-03 21:07:0944#include "chrome/common/render_view_commands.h"
[email protected]9b6f40e2009-06-11 15:54:2645#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2946#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5947#include "chrome/common/url_constants.h"
[email protected]38789d82010-11-17 06:03:4448#include "chrome/common/web_apps.h"
[email protected]534c66c2010-04-28 22:53:1149#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2950#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2551#include "chrome/renderer/audio_message_filter.h"
[email protected]78192082011-01-29 05:43:4452#include "chrome/renderer/autofill/autofill_agent.h"
53#include "chrome/renderer/autofill/form_manager.h"
54#include "chrome/renderer/autofill/password_autofill_manager.h"
[email protected]2f979172010-09-16 21:54:0355#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]00152e92010-07-19 11:47:4056#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5357#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1158#include "chrome/renderer/devtools_agent.h"
59#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3560#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0461#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]f816c012009-06-26 21:48:3262#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3563#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]78d5cfe2011-02-04 08:43:2264#include "chrome/renderer/extensions/extension_resource_request_policy.h"
[email protected]7120f132009-07-20 21:05:3765#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0366#include "chrome/renderer/external_host_bindings.h"
[email protected]caf706f2010-10-26 17:54:0867#include "chrome/renderer/external_popup_menu.h"
[email protected]ffd0abd2010-12-14 17:45:5068#include "chrome/renderer/geolocation_dispatcher.h"
[email protected]3bb08602010-10-07 21:47:1769#include "chrome/renderer/ggl/ggl.h"
[email protected]90109412010-12-15 17:14:2470#include "chrome/renderer/load_progress_tracker.h"
initial.commit09911bf2008-07-26 23:55:2971#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5672#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4173#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]ed3fb032009-06-16 19:50:5674#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1275#include "chrome/renderer/notification_provider.h"
[email protected]6a8ddba52010-09-05 04:38:0676#include "chrome/renderer/page_click_tracker.h"
[email protected]a5a65ac2010-11-05 18:14:3677#include "chrome/renderer/page_load_histograms.h"
[email protected]8beff0762009-09-29 02:18:3078#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5079#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2580#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2881#include "chrome/renderer/render_thread.h"
[email protected]676126f72011-01-15 00:03:5182#include "chrome/renderer/render_view_observer.h"
[email protected]4d51d5bf2010-07-26 18:48:2683#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1884#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]79c7bed2010-09-14 22:28:3985#include "chrome/renderer/render_widget_fullscreen_pepper.h"
[email protected]035545f2010-04-09 13:10:2186#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3487#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]3ead1322010-11-19 20:01:0088#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
[email protected]ce833282010-11-04 15:48:3989#include "chrome/renderer/searchbox_extension.h"
[email protected]638694c2010-08-04 22:24:1190#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4691#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]81273622011-02-02 03:56:1392#include "chrome/renderer/translate_helper.h"
[email protected]25e18f82010-10-27 16:38:4393#include "chrome/renderer/user_script_idle_scheduler.h"
[email protected]0938d3c2009-01-09 20:37:3594#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2995#include "chrome/renderer/visitedlink_slave.h"
[email protected]c50008512011-02-03 01:17:2796#include "chrome/renderer/web_ui_bindings.h"
[email protected]5aa6a312010-11-06 00:00:0797#include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h"
[email protected]d439ba072009-10-17 22:32:2998#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2999#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:42100#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:56101#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:27102#include "grit/generated_resources.h"
103#include "grit/renderer_resources.h"
[email protected]f8db8132010-12-03 00:27:49104#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41105#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:27106#include "media/base/message_loop_factory_impl.h"
[email protected]f11ca0732009-04-11 00:09:34107#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29108#include "net/base/escape.h"
109#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04110#include "net/http/http_util.h"
[email protected]1b4209f2011-01-07 00:25:40111#include "ppapi/c/private/ppb_flash.h"
[email protected]c399a8a2008-11-22 19:38:00112#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:10113#include "skia/ext/image_operations.h"
[email protected]8bd0fe62011-01-17 06:44:37114#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
115#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
152#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
154#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
155#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26157#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
158#include "third_party/skia/include/core/SkBitmap.h"
[email protected]9dd7e3d72011-01-20 18:27:06159#include "ui/base/message_box_flags.h"
[email protected]c051a1b2011-01-21 23:30:17160#include "ui/base/l10n/l10n_util.h"
[email protected]42ce29d2011-01-20 23:19:46161#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:38162#include "ui/gfx/color_utils.h"
163#include "ui/gfx/favicon_size.h"
164#include "ui/gfx/native_widget_types.h"
165#include "ui/gfx/point.h"
166#include "ui/gfx/rect.h"
167#include "ui/gfx/skbitmap_operations.h"
[email protected]882b7b22010-10-05 03:34:53168#include "v8/include/v8.h"
[email protected]a6097f42011-01-10 08:50:51169#include "v8/include/v8-testing.h"
[email protected]80f584d92010-01-21 03:59:04170#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43171#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24172#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29173#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59174#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24175#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24176#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34177#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26178#include "webkit/glue/image_resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09179#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26180#include "webkit/glue/password_form_dom_manager.h"
[email protected]bb461532010-11-26 21:50:23181#include "webkit/glue/resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09182#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24183#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29184#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29185#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17186#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50187#include "webkit/plugins/npapi/default_plugin_shared.h"
188#include "webkit/plugins/npapi/plugin_list.h"
189#include "webkit/plugins/npapi/webplugin_delegate.h"
190#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
191#include "webkit/plugins/npapi/webplugin_impl.h"
192#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52193#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29194
[email protected]6c8afae52009-01-22 02:24:57195#if defined(OS_WIN)
196// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57197// * theming
[email protected]08397d52011-02-05 01:53:38198#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03199#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37200#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]08397d52011-02-05 01:53:38201#include "ui/gfx/native_theme_linux.h"
[email protected]78043bdd2010-04-05 18:45:33202#elif defined(OS_MACOSX)
203#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57204#endif
205
[email protected]c7287a92009-11-04 20:06:15206using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42207using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08208using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21209using WebKit::WebApplicationCacheHost;
210using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26211using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41212using WebKit::WebColor;
213using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59214using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44215using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51216using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55217using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28218using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29219using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00220using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58221using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25222using WebKit::WebDragOperation;
223using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51224using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51225using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08226using WebKit::WebExternalPopupMenu;
227using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47228using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22229using WebKit::WebFileSystem;
230using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49231using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59232using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48233using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45234using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17235using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41236using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50237using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17238using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28239using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17240using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28241using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28242using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51243using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07244using WebKit::WebPageSerializer;
245using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17246using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40247using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49248using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09249using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52250using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59251using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51252using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52253using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40254using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35255using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29256using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59257using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42258using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02259using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34260using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28261using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51262using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52263using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28264using WebKit::WebURL;
265using WebKit::WebURLError;
266using WebKit::WebURLRequest;
267using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28268using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03269using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28270using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26271using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43272using WebKit::WebWorker;
273using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26274using appcache::WebApplicationCacheHostImpl;
[email protected]78192082011-01-29 05:43:44275using autofill::AutoFillAgent;
276using autofill::FormManager;
277using autofill::PasswordAutoFillManager;
[email protected]6fdd4182010-10-14 23:59:26278using base::Time;
279using base::TimeDelta;
280using webkit_glue::AltErrorPageResourceFetcher;
281using webkit_glue::FormData;
282using webkit_glue::FormField;
283using webkit_glue::ImageResourceFetcher;
284using webkit_glue::PasswordForm;
285using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23286using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26287using webkit_glue::SiteIsolationMetrics;
288using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33289
initial.commit09911bf2008-07-26 23:55:29290//-----------------------------------------------------------------------------
291
[email protected]3354d3e2010-06-10 19:53:02292typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49293static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02294
initial.commit09911bf2008-07-26 23:55:29295// define to write the time necessary for thumbnail/DOM text retrieval,
296// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29297// #define TIME_TEXT_RETRIEVAL
298
299// maximum number of characters in the document to index, any text beyond this
300// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57301static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29302
303// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37304static const int kThumbnailWidth = 212;
305static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29306
307// Delay in milliseconds that we'll wait before capturing the page contents
308// and thumbnail.
309static const int kDelayForCaptureMs = 500;
310
311// Typically, we capture the page data once the page is loaded.
312// Sometimes, the page never finishes to load, preventing the page capture
313// To workaround this problem, we always perform a capture after the following
314// delay.
315static const int kDelayForForcedCaptureMs = 6000;
316
[email protected]882daa92009-11-05 16:31:31317// Time, in seconds, we delay before sending content state changes (such as form
318// state and scroll position) to the browser. We delay sending changes to avoid
319// spamming the browser.
320// To avoid having tab/session restore require sending a message to get the
321// current content state during tab closing we use a shorter timeout for the
322// foreground renderer. This means there is a small window of time from which
323// content state is modified and not sent to session restore, but this is
324// better than having to wake up all renderers during shutdown.
325static const int kDelaySecondsForContentStateSyncHidden = 5;
326static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29327
[email protected]0aa55312008-10-17 21:53:08328// The maximum number of popups that can be spawned from one page.
329static const int kMaximumNumberOfUnacknowledgedPopups = 25;
330
[email protected]6fdd4182010-10-14 23:59:26331static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35332
[email protected]726985e22009-06-18 21:09:28333static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
334 WebVector<WebURL> urls;
335 ds->redirectChain(urls);
336 result->reserve(urls.size());
337 for (size_t i = 0; i < urls.size(); ++i)
338 result->push_back(urls[i]);
339}
340
[email protected]30507922010-01-15 16:48:23341static bool PaintViewIntoCanvas(WebView* view,
342 skia::PlatformCanvas& canvas) {
343 view->layout();
344 const WebSize& size = view->size();
345
346 if (!canvas.initialize(size.width, size.height, true))
347 return false;
348
349 view->paint(webkit_glue::ToWebCanvas(&canvas),
350 WebRect(0, 0, size.width, size.height));
351 // TODO: Add a way to snapshot the whole page, not just the currently
352 // visible part.
353
354 return true;
355}
356
357// Calculates how "boring" a thumbnail is. The boring score is the
358// 0,1 ranged percentage of pixels that are the most common
359// luma. Higher boring scores indicate that a higher percentage of a
360// bitmap are all the same brightness.
361static double CalculateBoringScore(SkBitmap* bitmap) {
362 int histogram[256] = {0};
363 color_utils::BuildLumaHistogram(bitmap, histogram);
364
365 int color_count = *std::max_element(histogram, histogram + 256);
366 int pixel_count = bitmap->width() * bitmap->height();
367 return static_cast<double>(color_count) / pixel_count;
368}
369
[email protected]12bc8472010-04-15 07:29:40370// True if |frame| contains content that is white-listed for content settings.
371static bool IsWhitelistedForContentSettings(WebFrame* frame) {
372 WebSecurityOrigin origin = frame->securityOrigin();
373 if (origin.isEmpty())
374 return false; // Uninitialized document?
375
376 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
377 return true; // Browser UI elements should still work.
378
379 // If the scheme is ftp: or file:, an empty file name indicates a directory
380 // listing, which requires JavaScript to function properly.
381 GURL frame_url = frame->url();
382 const char* kDirProtocols[] = { "ftp", "file" };
383 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
384 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
385 return frame_url.SchemeIs(kDirProtocols[i]) &&
386 frame_url.ExtractFileName().empty();
387 }
388 }
389
390 return false;
391}
392
[email protected]3a8eecb2010-04-22 23:56:30393// Returns true if the frame is navigating to an URL either into or out of an
394// extension app's extent.
[email protected]08e94b82010-12-15 22:51:04395// TODO(creis): Temporary workaround for crbug.com/65953: Only return true if
[email protected]88c15e972011-02-05 04:19:53396// we would enter an extension app's extent from a non-app, or if we leave an
397// extension with no web extent. We avoid swapping processes to exit a hosted
398// app with a web extent for now, since we do not yet restore context (such
[email protected]08e94b82010-12-15 22:51:04399// as window.opener) if the window navigates back.
[email protected]88c15e972011-02-05 04:19:53400static bool CrossesExtensionExtents(const ExtensionSet* extensions,
401 WebFrame* frame,
402 const GURL& new_url) {
[email protected]3a8eecb2010-04-22 23:56:30403 // If the URL is still empty, this is a window.open navigation. Check the
404 // opener's URL.
405 GURL old_url(frame->url());
406 if (old_url.is_empty() && frame->opener())
407 old_url = frame->opener()->url();
408
[email protected]88c15e972011-02-05 04:19:53409 bool old_url_is_hosted_app = extensions->GetByURL(old_url) &&
410 !extensions->GetByURL(old_url)->web_extent().is_empty();
[email protected]2a521c52011-01-26 18:45:21411 return !extensions->InSameExtent(old_url, new_url) &&
[email protected]88c15e972011-02-05 04:19:53412 !old_url_is_hosted_app;
[email protected]3a8eecb2010-04-22 23:56:30413}
414
[email protected]3354d3e2010-06-10 19:53:02415// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
416// if it failed.
[email protected]e5106202010-06-11 21:12:36417static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17418 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02419 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08420 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02421 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02422 Language cld_language =
[email protected]e5106202010-06-11 21:12:36423 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08424 &num_languages, NULL, &text_bytes);
425 // We don't trust the result if the CLD reports that the detection is not
426 // reliable, or if the actual text used to detect the language was less than
427 // 100 bytes (short texts can often lead to wrong results).
428 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02429 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
430 // We should not use LanguageCode_ISO_639_1 because it does not cover all
431 // the languages CLD can detect. As a result, it'll return the invalid
432 // language code for tradtional Chinese among others.
433 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
434 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
435 // for Simplified Chinese.
436 language = LanguageCodeWithDialects(cld_language);
437 }
438 return language;
439}
440
[email protected]9b66f34bf2010-10-27 20:45:51441// Returns true if the parameter node is a textfield, text area or a content
442// editable div.
443static bool IsEditableNode(const WebNode& node) {
444 bool is_editable_node = false;
445 if (!node.isNull()) {
446 if (node.isContentEditable()) {
447 is_editable_node = true;
448 } else if (node.isElementNode()) {
449 is_editable_node =
450 node.toConst<WebElement>().isTextFormControlElement();
451 }
452 }
453 return is_editable_node;
454}
455
[email protected]54ec7f82010-10-21 22:32:51456static bool WebAccessibilityNotificationToViewHostMsg(
457 WebAccessibilityNotification notification,
458 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) {
459 switch (notification) {
460 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
461 *type = ViewHostMsg_AccessibilityNotification_Params::
462 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
463 break;
464 case WebKit::WebAccessibilityNotificationChildrenChanged:
465 *type = ViewHostMsg_AccessibilityNotification_Params::
466 NOTIFICATION_TYPE_CHILDREN_CHANGED;
467 break;
468 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
469 *type = ViewHostMsg_AccessibilityNotification_Params::
470 NOTIFICATION_TYPE_FOCUS_CHANGED;
471 break;
472 case WebKit::WebAccessibilityNotificationLoadComplete:
473 *type = ViewHostMsg_AccessibilityNotification_Params::
474 NOTIFICATION_TYPE_LOAD_COMPLETE;
475 break;
476 case WebKit::WebAccessibilityNotificationValueChanged:
477 *type = ViewHostMsg_AccessibilityNotification_Params::
478 NOTIFICATION_TYPE_VALUE_CHANGED;
479 break;
480 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
481 *type = ViewHostMsg_AccessibilityNotification_Params::
482 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
483 break;
484 default:
485 // TODO(ctguil): Support additional webkit notifications.
486 return false;
487 }
488 return true;
489}
490
[email protected]81f9fe0b2010-12-07 00:35:29491// Conversion for the incoming value. The map isn't perfect; v8 has Uint32,
492// and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into
[email protected]fb534c92011-02-01 01:02:07493// being TYPE_DOUBLEs. Dates are converted to a string (which can then be
494// parsed into a base::Time), as are regexps. Arrays are converted into lists,
[email protected]81f9fe0b2010-12-07 00:35:29495// recursively. We don't deal with binary objects or functions - they become
496// null values.
497static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) {
498 if (v8value->IsBoolean()) {
499 return Value::CreateBooleanValue(v8value->BooleanValue());
500 } else if (v8value->IsInt32()) {
501 return Value::CreateIntegerValue(v8value->Int32Value());
502 } else if (v8value->IsNumber()) {
[email protected]fb534c92011-02-01 01:02:07503 return Value::CreateDoubleValue(v8value->NumberValue());
[email protected]81f9fe0b2010-12-07 00:35:29504 } else if (v8value->IsString()) {
505 return Value::CreateStringValue(*v8::String::Utf8Value(v8value));
506 } else if (v8value->IsDate()) {
507 v8::Date* date = v8::Date::Cast(*v8value);
[email protected]fb534c92011-02-01 01:02:07508 return Value::CreateDoubleValue(date->NumberValue() / 1000.0);
[email protected]81f9fe0b2010-12-07 00:35:29509 } else if (v8value->IsRegExp()) {
510 return Value::CreateStringValue(
511 *v8::String::Utf8Value(v8value->ToString()));
512 } else if (v8value->IsArray()) {
513 v8::Array* array = v8::Array::Cast(*v8value);
514 uint32_t length = array->Length();
515 scoped_ptr<ListValue> list(new ListValue);
516 for (uint32_t i = 0 ; i < length ; ++i) {
517 list->Set(i, ConvertV8Value(array->Get(i)));
518 }
519 return list.release();
520 }
521 return Value::CreateNullValue();
522}
523
initial.commit09911bf2008-07-26 23:55:29524///////////////////////////////////////////////////////////////////////////////
525
[email protected]60c42a8c72009-10-09 04:08:59526int32 RenderView::next_page_id_ = 1;
527
[email protected]cdaf8d02010-03-30 19:52:47528struct RenderView::PendingFileChooser {
529 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
530 WebFileChooserCompletion* c)
531 : params(p),
532 completion(c) {
533 }
534 ViewHostMsg_RunFileChooser_Params params;
535 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
536};
537
[email protected]2fab253a2009-08-17 23:00:59538RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51539 gfx::NativeViewId parent_hwnd,
540 int32 opener_id,
541 const RendererPreferences& renderer_prefs,
542 const WebPreferences& webkit_prefs,
543 SharedRenderViewCounter* counter,
544 int32 routing_id,
545 int64 session_storage_namespace_id,
546 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12547 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51548 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02549 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09550 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02551 send_preferred_size_changes_(false),
552 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24553 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21554 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02555 opened_by_user_gesture_(true),
556 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24557 page_id_(-1),
558 last_page_id_sent_to_browser_(-1),
559 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00560 history_list_offset_(-1),
561 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24562 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55563#if defined(OS_MACOSX)
564 has_document_tag_(false),
565#endif
[email protected]98324892009-09-09 21:16:05566 document_tag_(0),
[email protected]3354d3e2010-06-10 19:53:02567 target_url_status_(TARGET_NONE),
568 spelling_panel_visible_(false),
569 view_type_(ViewType::INVALID),
570 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18571 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30572 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
[email protected]54ec7f82010-10-21 22:32:51573 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02574 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51575 devtools_client_(NULL),
576 geolocation_dispatcher_(NULL),
577 speech_input_dispatcher_(NULL),
578 device_orientation_dispatcher_(NULL),
[email protected]54ec7f82010-10-21 22:32:51579 accessibility_ack_pending_(false),
[email protected]bb461532010-11-26 21:50:23580 pending_app_icon_requests_(0),
[email protected]5ee0cfd02011-01-18 05:42:22581 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]8de12d942010-11-17 20:42:44582#if defined(OS_MACOSX)
583 // On Mac, the select popups are rendered by the browser.
584 // Note that we don't do this in RenderMain otherwise this would not be called
585 // in single-process mode.
586 WebKit::WebView::setUseExternalPopupMenus(true);
587#endif
[email protected]676126f72011-01-15 00:03:51588
[email protected]71b0d5d2010-02-15 05:43:07589 ClearBlockedContentSettings();
[email protected]676126f72011-01-15 00:03:51590
591 routing_id_ = routing_id;
592 if (opener_id != MSG_ROUTING_NONE)
593 opener_id_ = opener_id;
594
595 if (counter) {
596 shared_popup_counter_ = counter;
597 shared_popup_counter_->data++;
598 decrement_shared_popup_at_destruction_ = true;
599 } else {
600 shared_popup_counter_ = new SharedRenderViewCounter(0);
601 decrement_shared_popup_at_destruction_ = false;
602 }
603
604 notification_provider_ = new NotificationProvider(this);
605
606 devtools_agent_ = new DevToolsAgent(this);
[email protected]78192082011-01-29 05:43:44607 PasswordAutoFillManager* password_autofill_manager =
608 new PasswordAutoFillManager(this);
609 AutoFillAgent* autofill_agent = new AutoFillAgent(this,
610 password_autofill_manager);
[email protected]676126f72011-01-15 00:03:51611
[email protected]78192082011-01-29 05:43:44612 webwidget_ = WebView::create(this, devtools_agent_, autofill_agent);
[email protected]676126f72011-01-15 00:03:51613 g_view_map.Get().insert(std::make_pair(webview(), this));
614 webkit_preferences_.Apply(webview());
615 webview()->initializeMainFrame(this);
616 if (!frame_name.empty())
617 webview()->mainFrame()->setName(frame_name);
618
619 OnSetRendererPrefs(renderer_prefs);
620
621 render_thread_->AddRoute(routing_id_, this);
622 // Take a reference on behalf of the RenderThread. This will be balanced
623 // when we receive ViewMsg_Close.
624 AddRef();
625
626 // If this is a popup, we must wait for the CreatingNew_ACK message before
627 // completing initialization. Otherwise, we can finish it now.
628 if (opener_id == MSG_ROUTING_NONE) {
629 did_show_ = true;
630 CompleteInit(parent_hwnd);
631 }
632
633 host_window_ = parent_hwnd;
634
635 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
636 if (command_line.HasSwitch(switches::kDomAutomationController))
637 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
638 if (command_line.HasSwitch(switches::kEnableAccessibility))
639 WebAccessibilityCache::enableAccessibility();
640
641 audio_message_filter_ = new AudioMessageFilter(routing_id_);
642 render_thread_->AddFilter(audio_message_filter_);
643
644 PageClickTracker* page_click_tracker = new PageClickTracker(this);
645 // Note that the order of insertion of the listeners is important.
646 // The password_autocomplete_manager takes the first shot at processing the
647 // notification and can stop the propagation.
[email protected]78192082011-01-29 05:43:44648 page_click_tracker->AddListener(password_autofill_manager);
649 page_click_tracker->AddListener(autofill_agent);
[email protected]81273622011-02-02 03:56:13650 new TranslateHelper(this);
[email protected]28685da92011-02-07 21:49:17651
652 if (CommandLine::ForCurrentProcess()->HasSwitch(
653 switches::kEnableClientSidePhishingDetection)) {
654 new safe_browsing::PhishingClassifierDelegate(this, NULL);
655 }
initial.commit09911bf2008-07-26 23:55:29656}
657
658RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08659 if (decrement_shared_popup_at_destruction_)
660 shared_popup_counter_->data--;
661
[email protected]a1128322009-10-06 18:38:46662 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47663 while (!file_chooser_completions_.empty()) {
664 if (file_chooser_completions_.front()->completion) {
665 file_chooser_completions_.front()->completion->didChooseFile(
666 WebVector<WebString>());
667 }
668 file_chooser_completions_.pop_front();
669 }
[email protected]a1128322009-10-06 18:38:46670
[email protected]83dde542009-09-11 20:59:55671#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05672 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55673 if (has_document_tag_)
674 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
[email protected]c36a9b62010-10-14 00:41:11675
676 // Destroy all fake plugin window handles on the browser side.
677 while (!fake_plugin_window_handles_.empty()) {
678 // Make sure no NULL plugin window handles were inserted into this list.
679 DCHECK(*fake_plugin_window_handles_.begin());
680 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
681 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
682 }
[email protected]83dde542009-09-11 20:59:55683#endif
[email protected]98324892009-09-09 21:16:05684
[email protected]5fb88962009-04-16 19:03:25685 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59686
687#ifndef NDEBUG
688 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49689 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59690 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
691 DCHECK_NE(this, it->second) << "Failed to call Close?";
692#endif
[email protected]676126f72011-01-15 00:03:51693
694 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
695 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59696}
697
698/*static*/
699void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49700 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59701 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
702 if (!visitor->Visit(it->second))
703 return;
704 }
705}
706
707/*static*/
708RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49709 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59710 ViewMap::iterator it = views->find(webview);
711 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29712}
713
714/*static*/
[email protected]0aa55312008-10-17 21:53:08715RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24716 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15717 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08718 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51719 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08720 const WebPreferences& webkit_prefs,
721 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34722 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26723 int64 session_storage_namespace_id,
724 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29725 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51726 return new RenderView(
727 render_thread,
728 parent_hwnd,
729 opener_id,
730 renderer_prefs,
731 webkit_prefs,
732 counter,
733 routing_id,
734 session_storage_namespace_id,
735 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29736}
737
[email protected]bb461532010-11-26 21:50:23738// static
initial.commit09911bf2008-07-26 23:55:29739void RenderView::SetNextPageID(int32 next_page_id) {
740 // This method should only be called during process startup, and the given
741 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05742 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29743 DCHECK(next_page_id >= next_page_id_);
744 next_page_id_ = next_page_id;
745}
746
[email protected]676126f72011-01-15 00:03:51747void RenderView::AddObserver(RenderViewObserver* observer) {
748 observers_.AddObserver(observer);
749}
750
751void RenderView::RemoveObserver(RenderViewObserver* observer) {
752 observer->set_render_view(NULL);
753 observers_.RemoveObserver(observer);
754}
755
[email protected]70eee342010-11-05 01:59:37756bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
757 typedef ViewHostMsg_AccessibilityNotification_Params params;
758 if (type == params::NOTIFICATION_TYPE_CHILDREN_CHANGED ||
759 type == params::NOTIFICATION_TYPE_LOAD_COMPLETE) {
760 return true;
761 }
762 return false;
763}
764
[email protected]8a3125a712010-08-09 18:58:51765WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26766 return static_cast<WebKit::WebView*>(webwidget());
767}
768
[email protected]afe3a1672009-11-17 19:04:12769void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]15d04ae2010-10-30 01:04:50770 Send(new ViewHostMsg_UserMetricsRecordAction(action));
[email protected]1dbafaf72009-09-23 19:43:56771}
772
[email protected]bb461532010-11-26 21:50:23773bool RenderView::InstallWebApplicationUsingDefinitionFile(WebFrame* frame,
774 string16* error) {
775 // There is an issue of drive-by installs with the below implementation. A web
776 // site could force a user to install an app by timing the dialog to come up
777 // just before the user clicks.
778 //
779 // We do show a success UI that allows users to uninstall, but it seems that
780 // we might still want to put up an infobar before showing the install dialog.
781 //
782 // TODO(aa): Figure out this issue before removing the kEnableCrxlessWebApps
783 // switch.
784 if (!CommandLine::ForCurrentProcess()->HasSwitch(
785 switches::kEnableCrxlessWebApps)) {
786 *error = ASCIIToUTF16("CRX-less web apps aren't enabled.");
787 return false;
788 }
789
790 if (frame != frame->top()) {
791 *error = ASCIIToUTF16("Applications can only be installed from the top "
792 "frame.");
793 return false;
794 }
795
796 if (pending_app_info_.get()) {
797 *error = ASCIIToUTF16("An application install is already in progress.");
798 return false;
799 }
800
801 pending_app_info_.reset(new WebApplicationInfo());
802 if (!web_apps::ParseWebAppFromWebDocument(frame, pending_app_info_.get(),
803 error)) {
804 return false;
805 }
806
807 if (!pending_app_info_->manifest_url.is_valid()) {
808 *error = ASCIIToUTF16("Web application definition not found or invalid.");
809 return false;
810 }
811
812 app_definition_fetcher_.reset(new ResourceFetcher(
813 pending_app_info_->manifest_url, webview()->mainFrame(),
814 NewCallback(this, &RenderView::DidDownloadApplicationDefinition)));
815 return true;
816}
817
[email protected]1a3c3cb2010-12-16 21:03:40818void RenderView::SetReportLoadProgressEnabled(bool enabled) {
819 if (!enabled) {
820 load_progress_tracker_.reset(NULL);
821 return;
822 }
823 if (load_progress_tracker_ == NULL)
824 load_progress_tracker_.reset(new LoadProgressTracker(this));
825}
826
[email protected]bb461532010-11-26 21:50:23827void RenderView::DidDownloadApplicationDefinition(
828 const WebKit::WebURLResponse& response,
829 const std::string& data) {
830 scoped_ptr<WebApplicationInfo> app_info(
831 pending_app_info_.release());
832
833 JSONStringValueSerializer serializer(data);
834 int error_code = 0;
835 std::string error_message;
836 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message));
837 if (!result.get()) {
838 AddErrorToRootConsole(UTF8ToUTF16(error_message));
839 return;
840 }
841
842 string16 error_message_16;
843 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(),
844 &error_message_16)) {
845 AddErrorToRootConsole(error_message_16);
846 return;
847 }
848
849 if (!app_info->icons.empty()) {
850 pending_app_info_.reset(app_info.release());
851 pending_app_icon_requests_ =
852 static_cast<int>(pending_app_info_->icons.size());
853 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
854 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
855 new ImageResourceFetcher(
856 pending_app_info_->icons[i].url,
857 webview()->mainFrame(),
858 static_cast<int>(i),
859 pending_app_info_->icons[i].width,
860 NewCallback(this, &RenderView::DidDownloadApplicationIcon))));
861 }
862 } else {
863 Send(new ViewHostMsg_InstallApplication(routing_id_, *app_info));
864 }
865}
866
867void RenderView::DidDownloadApplicationIcon(ImageResourceFetcher* fetcher,
868 const SkBitmap& image) {
869 pending_app_info_->icons[fetcher->id()].data = image;
870
871 // Remove the image fetcher from our pending list. We're in the callback from
872 // ImageResourceFetcher, best to delay deletion.
873 for (ImageResourceFetcherList::iterator iter = app_icon_fetchers_.begin();
874 iter != app_icon_fetchers_.end(); ++iter) {
875 if (iter->get() == fetcher) {
876 iter->release();
877 app_icon_fetchers_.erase(iter);
878 break;
879 }
880 }
881
882 // We're in the callback from the ImageResourceFetcher, best to delay
883 // deletion.
884 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
885
886 if (--pending_app_icon_requests_ > 0)
887 return;
888
889 // There is a maximum size of IPC on OS X and Linux that we have run into in
890 // some situations. We're not sure what it is, but our hypothesis is in the
891 // neighborhood of 1 MB.
892 //
893 // To be on the safe side, we give ourselves 128 KB for just the image data.
894 // This should be more than enough for 128, 48, and 16 px 32-bit icons. If we
895 // want to start allowing larger icons (see bug 63406), we'll have to either
896 // experiment mor ewith this and find the real limit, or else come up with
897 // some alternative way to transmit the icon data to the browser process.
898 //
899 // See also: bug 63729.
[email protected]678a7d72011-01-05 20:37:32900 const size_t kMaxIconSize = 1024 * 128;
901 size_t actual_icon_size = 0;
[email protected]bb461532010-11-26 21:50:23902 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
[email protected]678a7d72011-01-05 20:37:32903 size_t current_size = pending_app_info_->icons[i].data.getSize();
904 if (current_size > kMaxIconSize - actual_icon_size) {
905 AddErrorToRootConsole(ASCIIToUTF16(
[email protected]bb461532010-11-26 21:50:23906 "Icons are too large. Maximum total size for app icons is 128 KB."));
[email protected]678a7d72011-01-05 20:37:32907 return;
908 }
909 actual_icon_size += current_size;
[email protected]bb461532010-11-26 21:50:23910 }
911
912 Send(new ViewHostMsg_InstallApplication(routing_id_, *pending_app_info_));
913 pending_app_info_.reset(NULL);
914}
915
[email protected]a3a8fb6d2009-10-22 20:12:51916void RenderView::PluginCrashed(const FilePath& plugin_path) {
917 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29918}
919
[email protected]aad51d1c2010-08-05 08:38:09920WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
921 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50922 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26923 bool found;
924 ContentSetting setting;
925 std::string mime_type;
926 Send(new ViewHostMsg_GetPluginInfo(
[email protected]c8f73ab2011-01-22 00:05:17927 routing_id_, params.url, frame->top()->url(), params.mimeType.utf8(),
928 &found, &info, &setting, &mime_type));
[email protected]b83ff222011-01-24 17:37:12929 if (!found || !webkit::npapi::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09930 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45931
[email protected]0bd753682010-12-16 18:15:52932 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:45933 pepper_delegate_.CreatePepperPlugin(info.path));
[email protected]aad51d1c2010-08-05 08:38:09934 if (pepper_module)
[email protected]6fdd4182010-10-14 23:59:26935 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]1a78d9f32010-12-08 06:38:45936 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09937}
938
[email protected]d8fd6fa2010-02-01 15:54:26939void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
940 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30941 // If the renderer is visible, set initial visibility and focus state.
942 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34943#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30944 delegate->SetContainerVisibility(true);
945 if (webview() && webview()->isActive())
946 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34947#endif
[email protected]49232292010-09-03 19:07:30948 }
[email protected]784ea1ab2010-09-18 00:02:34949 // Plugins start assuming the content has focus (so that they work in
950 // environments where RenderView isn't hosting them), so we always have to
951 // set the initial state. See webplugin_delegate_impl.h for details.
952 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26953}
954
955void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
956 plugin_delegates_.erase(delegate);
957}
[email protected]d8fd6fa2010-02-01 15:54:26958
[email protected]a95986a82010-12-24 06:19:28959bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27960 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27961 if (main_frame)
962 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26963
[email protected]676126f72011-01-15 00:03:51964 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
965 RenderViewObserver* observer;
966 while ((observer = it.GetNext()) != NULL)
967 if (observer->OnMessageReceived(message))
968 return true;
[email protected]b2abac72009-02-26 12:39:28969
[email protected]a95986a82010-12-24 06:19:28970 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29971 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04972 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
973 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29974 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01975 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
[email protected]521b2482011-01-15 00:10:10976 IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview)
977 IPC_MESSAGE_HANDLER(ViewMsg_PrintNodeUnderContextMenu,
978 OnPrintNodeUnderContextMenu)
initial.commit09911bf2008-07-26 23:55:29979 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
980 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56981 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29982 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
983 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
984 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
985 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27986#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35987 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27988#endif
initial.commit09911bf2008-07-26 23:55:29989 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
990 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05991 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
992 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
993 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04994 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29995 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
996 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
997 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15998 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29999 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491000 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
1001 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:171002 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:541003 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
1004 OnSetContentSettingsForLoadingURL)
[email protected]d0b8d092010-10-25 04:05:171005 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:541006 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1007 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291008 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181009 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1010 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:281011 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:331012 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:291013 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:481014 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:291015 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:291016 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:291017 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
1018 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
1019 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
1020 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:451021 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291022 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:501023 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
1024 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:291025 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
1026 OnDragSourceSystemDragEnded)
1027 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:511028 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
1029 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:291030 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1031 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1032 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1033 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]90dba072011-01-20 20:10:201034 IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage,
1035 OnDisplayPrerenderedPage)
initial.commit09911bf2008-07-26 23:55:291036 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1037 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:291038 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1039 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:041040 IPC_MESSAGE_HANDLER(
1041 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1042 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:291043 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:041044 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:291045 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1046 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:451047 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:041048 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:081049 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1050 OnDisassociateFromPopupCount)
[email protected]e8345242010-05-06 03:00:401051 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
1052 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:001053 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:271054 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:371055 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
1056 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:161057 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141058 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251059 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1060 OnEnablePreferredSizeChangedMode)
[email protected]ce833282010-11-04 15:48:391061 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxChange, OnSearchBoxChange)
1062 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxSubmit, OnSearchBoxSubmit)
1063 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxCancel, OnSearchBoxCancel)
1064 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxResize, OnSearchBoxResize)
1065 IPC_MESSAGE_HANDLER(ViewMsg_DetermineIfPageSupportsInstant,
1066 OnDetermineIfPageSupportsInstant)
[email protected]cda45c02010-02-25 19:28:101067 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1068 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511069 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:531070 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
1071 OnUpdateBrowserWindowId)
1072 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
1073 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:561074 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:341075 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:141076#if defined(OS_MACOSX)
1077 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:131078 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:131079 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1080 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:141081#endif
[email protected]446705872009-09-10 07:22:481082 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331083 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:351084 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
1085 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:331086 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1087 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:141088 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:361089 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
1090 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
1091 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:421092 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
1093 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:241094 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]caf706f2010-10-26 17:54:081095#if defined(OS_MACOSX)
1096 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1097#endif
[email protected]a6097f42011-01-10 08:50:511098 IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl,
1099 OnJavaScriptStressTestControl)
[email protected]521b2482011-01-15 00:10:101100 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]634a6f92008-12-01 21:39:311101
[email protected]f0557932011-01-25 20:20:511102 // TODO(viettrungluu): Move to a separate message filter.
1103#if defined(ENABLE_FLAPPER_HACKS)
1104 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
1105#endif
1106
initial.commit09911bf2008-07-26 23:55:291107 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281108 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291109 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281110 return handled;
initial.commit09911bf2008-07-26 23:55:291111}
1112
[email protected]9b18a84f2010-06-10 15:54:041113void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:271114 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291115 if (!main_frame)
1116 return;
1117
1118 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:451119 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291120 if (url.is_empty())
1121 return;
1122
1123 if (size_.IsEmpty())
1124 return; // Don't create an empty thumbnail!
1125
1126 ThumbnailScore score;
1127 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:021128 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:151129 &thumbnail, &score))
1130 return;
1131
initial.commit09911bf2008-07-26 23:55:291132 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:461133 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:291134}
1135
[email protected]9b18a84f2010-06-10 15:54:041136void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:231137 SkBitmap snapshot;
1138 bool error = false;
1139
1140 WebFrame* main_frame = webview()->mainFrame();
1141 if (!main_frame)
1142 error = true;
1143
1144 if (!error && !CaptureSnapshot(webview(), &snapshot))
1145 error = true;
1146
1147 DCHECK(error == snapshot.empty()) <<
1148 "Snapshot should be empty on error, non-empty otherwise.";
1149
1150 // Send the snapshot to the browser process.
1151 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
1152}
1153
[email protected]068637222009-01-29 16:58:071154void RenderView::OnPrintPages() {
[email protected]c7a827e2011-01-21 00:27:011155 OnPrint(false);
initial.commit09911bf2008-07-26 23:55:291156}
1157
[email protected]82270452009-06-19 15:58:011158void RenderView::OnPrintingDone(int document_cookie, bool success) {
1159 // Ignoring document cookie here since only one print job can be outstanding
1160 // per renderer and document_cookie is 0 when printing is successful.
1161 DCHECK(print_helper_.get());
1162 if (print_helper_.get() != NULL) {
1163 print_helper_->DidFinishPrinting(success);
1164 }
1165}
1166
[email protected]212a49d2010-10-25 18:23:471167void RenderView::OnPrintPreview() {
[email protected]c7a827e2011-01-21 00:27:011168 OnPrint(true);
[email protected]212a49d2010-10-25 18:23:471169}
1170
[email protected]521b2482011-01-15 00:10:101171void RenderView::OnPrintNodeUnderContextMenu() {
1172 if (context_menu_node_.isNull()) {
1173 NOTREACHED();
1174 return;
1175 }
1176
1177 // Make a copy of the node, since we will do a sync call to the browser and
1178 // during that time OnContextMenuClosed might reset context_menu_node_.
1179 WebNode context_menu_node(context_menu_node_);
1180 GetPrintWebViewHelper()->PrintNode(&context_menu_node, false, false);
1181}
1182
initial.commit09911bf2008-07-26 23:55:291183void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
1184 if (load_id != page_id_)
1185 return; // this capture call is no longer relevant due to navigation
1186 if (load_id == last_indexed_page_id_)
1187 return; // we already indexed this page
1188
1189 if (!webview())
1190 return;
1191
[email protected]26aa0482009-09-30 16:55:271192 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291193 if (!main_frame)
1194 return;
1195
1196 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:451197 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:291198 return;
1199
1200 // Don't index/capture pages that failed to load. This only checks the top
1201 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:451202 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:281203 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:291204 return;
1205
1206 if (!preliminary_capture)
1207 last_indexed_page_id_ = load_id;
1208
[email protected]a8a81292010-01-21 00:32:451209 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:451210 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291211 if (url.is_empty())
1212 return;
1213
[email protected]a8a81292010-01-21 00:32:451214 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:361215 string16 contents;
initial.commit09911bf2008-07-26 23:55:291216 CaptureText(main_frame, &contents);
1217 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:101218 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:371219 // If the page explicitly specifies a language, use it, otherwise we'll
1220 // determine it based on the text content using the CLD.
1221 std::string language =
1222 TranslateHelper::GetPageLanguageFromMetaTag(&document);
1223 if (language.empty()) {
1224 base::TimeTicks begin_time = base::TimeTicks::Now();
1225 language = DetermineTextLanguage(contents);
1226 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
1227 base::TimeTicks::Now() - begin_time);
1228 }
[email protected]a8a81292010-01-21 00:32:451229 // Send the text to the browser for indexing (the browser might decide not
1230 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:371231 Send(new ViewHostMsg_PageContents(
1232 routing_id_, url, load_id, contents, language,
1233 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:271234 }
1235
[email protected]d54169e92011-01-21 09:19:521236 // Generate the thumbnail here if the in-browser thumbnailing isn't
1237 // enabled. TODO(satorux): Remove this and related code once
1238 // crbug.com/65936 is complete.
1239 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1240 switches::kEnableInBrowserThumbnailing)) {
1241 OnCaptureThumbnail();
1242 }
[email protected]3ead1322010-11-19 20:01:001243
[email protected]28685da92011-02-07 21:49:171244 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PageCaptured(contents));
initial.commit09911bf2008-07-26 23:55:291245}
1246
[email protected]e5106202010-06-11 21:12:361247void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:291248 contents->clear();
1249 if (!frame)
1250 return;
1251
1252#ifdef TIME_TEXT_RETRIEVAL
1253 double begin = time_util::GetHighResolutionTimeNow();
1254#endif
1255
1256 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:361257 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:291258
1259#ifdef TIME_TEXT_RETRIEVAL
1260 double end = time_util::GetHighResolutionTimeNow();
1261 char buf[128];
1262 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
1263 contents.size(), (end - begin)*1000);
1264 OutputDebugStringA(buf);
1265#endif
1266
1267 // When the contents are clipped to the maximum, we don't want to have a
1268 // partial word indexed at the end that might have been clipped. Therefore,
1269 // terminate the string at the last space to ensure no words are clipped.
1270 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:361271 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:291272 if (last_space_index == std::wstring::npos)
1273 return; // don't index if we got a huge block of text with no spaces
1274 contents->resize(last_space_index);
1275 }
1276}
1277
[email protected]8649fb32009-06-26 17:51:021278bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:291279 int w,
1280 int h,
1281 SkBitmap* thumbnail,
1282 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:231283 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:151284
[email protected]8649fb32009-06-26 17:51:021285 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:231286
1287 // Paint |view| into |canvas|.
1288 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:021289 return false;
[email protected]8649fb32009-06-26 17:51:021290
1291 skia::BitmapPlatformDevice& device =
1292 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1293
1294 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:291295
[email protected]cab34d6a2009-09-24 01:14:521296 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:291297 float dest_aspect = dest_rect.width() / dest_rect.height();
1298
1299 // Get the src rect so that we can preserve the aspect ratio while filling
1300 // the destination.
1301 SkIRect src_rect;
1302 if (src_bmp.width() < dest_rect.width() ||
1303 src_bmp.height() < dest_rect.height()) {
1304 // Source image is smaller: we clip the part of source image within the
1305 // dest rect, and then stretch it to fill the dest rect. We don't respect
1306 // the aspect ratio in this case.
1307 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
1308 static_cast<S16CPU>(dest_rect.height()));
1309 score->good_clipping = false;
1310 } else {
1311 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1312 if (src_aspect > dest_aspect) {
1313 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1314 // the wider screen.
1315 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1316 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1317 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1318 score->good_clipping = false;
1319 } else {
1320 src_rect.set(0, 0, src_bmp.width(),
1321 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1322 score->good_clipping = true;
1323 }
1324 }
1325
[email protected]26aa0482009-09-30 16:55:271326 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291327
1328 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021329 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291330
[email protected]82afe4b2010-11-12 20:36:221331 // First do a fast downsample by powers of two to get close to the final size.
1332 SkBitmap downsampled_subset =
1333 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h);
1334
1335 // Do a high-quality resize from the downscaled size to the final size.
[email protected]465b34b72008-12-12 20:19:141336 *thumbnail = skia::ImageOperations::Resize(
[email protected]82afe4b2010-11-12 20:36:221337 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291338
1339 score->boring_score = CalculateBoringScore(thumbnail);
1340
[email protected]30507922010-01-15 16:48:231341 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1342 base::TimeTicks::Now() - beginning_time);
[email protected]82afe4b2010-11-12 20:36:221343
[email protected]b6e4bec2008-11-12 01:17:151344 return true;
initial.commit09911bf2008-07-26 23:55:291345}
1346
[email protected]30507922010-01-15 16:48:231347bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1348 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291349
[email protected]30507922010-01-15 16:48:231350 skia::PlatformCanvas canvas;
1351 if (!PaintViewIntoCanvas(view, canvas))
1352 return false;
1353
1354 skia::BitmapPlatformDevice& device =
1355 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1356
1357 const SkBitmap& bitmap = device.accessBitmap(false);
1358 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1359 return false;
1360
1361 HISTOGRAM_TIMES("Renderer4.Snapshot",
1362 base::TimeTicks::Now() - beginning_time);
1363 return true;
initial.commit09911bf2008-07-26 23:55:291364}
1365
1366void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1367 if (!webview())
1368 return;
1369
[email protected]3cc72b12010-03-18 23:03:001370 history_list_offset_ = params.current_history_list_offset;
1371 history_list_length_ = params.current_history_list_length;
1372
[email protected]a9f607e2009-10-23 19:59:271373 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261374
initial.commit09911bf2008-07-26 23:55:291375 AboutHandler::MaybeHandle(params.url);
1376
[email protected]ecbf10d2010-02-18 13:03:291377 bool is_reload =
1378 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1379 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291380
[email protected]26aa0482009-09-30 16:55:271381 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451382 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291383 // We cannot reload if we do not have any history state. This happens, for
1384 // example, when recovering from a crash. Our workaround here is a bit of
1385 // a hack since it means that reload after a crashed tab does not cause an
1386 // end-to-end cache validation.
1387 is_reload = false;
1388 }
1389
[email protected]77f17a82009-05-21 04:42:541390 // A navigation resulting from loading a javascript URL should not be treated
1391 // as a browser initiated event. Instead, we want it to look as if the page
1392 // initiated any load resulting from JS execution.
1393 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301394 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001395 params.page_id,
1396 params.pending_history_list_offset,
1397 params.transition,
1398 params.request_time);
[email protected]5e369672009-11-03 23:48:301399 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1400 // We're doing a load of a page that was restored from the last session.
1401 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1402 // which can result in stale data for pages that are set to expire. We
1403 // explicitly override that by setting the policy here so that as
1404 // necessary we load from the network.
1405 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1406 }
1407 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541408 }
initial.commit09911bf2008-07-26 23:55:291409
[email protected]a7ccc4d2010-01-27 08:14:481410 NavigationState* navigation_state = pending_navigation_state_.get();
1411
[email protected]04d3c6e2009-05-22 17:00:131412 // If we are reloading, then WebKit will use the history state of the current
1413 // page, so we should just ignore any given history state. Otherwise, if we
1414 // have history state, then we need to navigate to it, which corresponds to a
1415 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551416 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481417 if (navigation_state)
1418 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291419 bool ignore_cache = (params.navigation_type ==
1420 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1421 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551422 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131423 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581424 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481425 if (navigation_state)
1426 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451427 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171428 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131429 } else {
1430 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281431 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291432
[email protected]e6f546c32009-07-01 17:12:551433 // A session history navigation should have been accompanied by state.
1434 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131435
[email protected]dd7daa82009-08-10 05:46:451436 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551437 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131438
[email protected]726985e22009-06-18 21:09:281439 if (params.referrer.is_valid()) {
1440 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1441 WebString::fromUTF8(params.referrer.spec()));
1442 }
[email protected]04d3c6e2009-05-22 17:00:131443
[email protected]52c68652010-12-07 17:47:041444 if (!params.extra_headers.empty()) {
1445 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1446 params.extra_headers.end(), "\n");
1447 i.GetNext(); ) {
1448 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1449 WebString::fromUTF8(i.values()));
1450 }
1451 }
1452
[email protected]90dba072011-01-20 20:10:201453 if (navigation_state) {
1454 if (params.navigation_type != ViewMsg_Navigate_Params::PRERENDER) {
1455 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
1456 } else {
1457 navigation_state->set_load_type(NavigationState::PRERENDER_LOAD);
1458 navigation_state->set_is_prerendering(true);
1459 }
1460 }
[email protected]dd7daa82009-08-10 05:46:451461 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501462 }
1463
[email protected]77f17a82009-05-21 04:42:541464 // In case LoadRequest failed before DidCreateDataSource was called.
1465 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291466}
1467
1468// Stop loading the current page
1469void RenderView::OnStop() {
1470 if (webview())
[email protected]b4bb2502009-10-01 22:35:271471 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291472}
1473
[email protected]ecbf10d2010-02-18 13:03:291474// Reload current focused frame.
1475// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561476void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291477 if (webview() && webview()->focusedFrame()) {
1478 // We always obey the cache (ignore_cache=false) here.
1479 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1480 // a cache-ignoring reload of the frame.
1481 webview()->focusedFrame()->reload(false);
1482 }
[email protected]1dda4022010-01-28 18:24:561483}
1484
initial.commit09911bf2008-07-26 23:55:291485void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271486 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291487}
1488
[email protected]68b1e922009-06-23 16:00:251489void RenderView::OnExecuteEditCommand(const std::string& name,
1490 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271491 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251492 return;
1493
[email protected]26aa0482009-09-30 16:55:271494 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451495 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251496}
1497
[email protected]b2abac72009-02-26 12:39:281498void RenderView::OnSetupDevToolsClient() {
[email protected]676126f72011-01-15 00:03:511499 DCHECK(!devtools_client_);
1500 devtools_client_ = new DevToolsClient(this);
[email protected]b2abac72009-02-26 12:39:281501}
1502
initial.commit09911bf2008-07-26 23:55:291503void RenderView::OnUpdateTargetURLAck() {
1504 // Check if there is a targeturl waiting to be sent.
1505 if (target_url_status_ == TARGET_PENDING) {
1506 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1507 pending_target_url_));
1508 }
1509
1510 target_url_status_ = TARGET_NONE;
1511}
1512
1513void RenderView::OnUndo() {
1514 if (!webview())
1515 return;
1516
[email protected]26aa0482009-09-30 16:55:271517 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121518 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291519}
1520
1521void RenderView::OnRedo() {
1522 if (!webview())
1523 return;
1524
[email protected]26aa0482009-09-30 16:55:271525 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121526 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291527}
1528
1529void RenderView::OnCut() {
1530 if (!webview())
1531 return;
1532
[email protected]26aa0482009-09-30 16:55:271533 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121534 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291535}
1536
1537void RenderView::OnCopy() {
1538 if (!webview())
1539 return;
1540
[email protected]26aa0482009-09-30 16:55:271541 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121542 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291543}
1544
[email protected]c0cc3092009-09-12 08:27:271545#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351546void RenderView::OnCopyToFindPboard() {
1547 if (!webview())
1548 return;
1549
1550 // Since the find pasteboard supports only plain text, this can be simpler
1551 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271552 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351553 if (frame->hasSelection()) {
1554 string16 selection = frame->selectionAsText();
1555 RenderThread::current()->Send(
1556 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1557 }
1558
[email protected]afe3a1672009-11-17 19:04:121559 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351560}
[email protected]c0cc3092009-09-12 08:27:271561#endif
[email protected]a954bf72009-09-12 07:30:351562
initial.commit09911bf2008-07-26 23:55:291563void RenderView::OnPaste() {
1564 if (!webview())
1565 return;
1566
[email protected]26aa0482009-09-30 16:55:271567 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121568 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291569}
1570
[email protected]2a3a7762009-10-19 19:17:321571void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291572 if (!webview())
1573 return;
1574
[email protected]1ff7a032010-02-03 02:46:031575 WebFrame* frame = webview()->focusedFrame();
1576 if (!frame->hasSelection())
1577 frame->selectWordAroundCaret();
1578 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291579}
1580
[email protected]98324892009-09-09 21:16:051581void RenderView::OnAdvanceToNextMisspelling() {
1582 if (!webview())
1583 return;
[email protected]26aa0482009-09-30 16:55:271584 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051585 WebString::fromUTF8("AdvanceToNextMisspelling"));
1586}
1587
1588void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1589 if (!webview())
1590 return;
1591 // We need to tell the webView whether the spelling panel is visible or not so
1592 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261593 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271594 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051595 WebString::fromUTF8("ToggleSpellPanel"));
1596}
1597
[email protected]bbbd545c2008-12-15 20:18:041598void RenderView::OnToggleSpellCheck() {
1599 if (!webview())
1600 return;
1601
[email protected]26aa0482009-09-30 16:55:271602 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451603 frame->enableContinuousSpellChecking(
1604 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041605}
1606
initial.commit09911bf2008-07-26 23:55:291607void RenderView::OnDelete() {
1608 if (!webview())
1609 return;
1610
[email protected]26aa0482009-09-30 16:55:271611 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121612 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291613}
1614
1615void RenderView::OnSelectAll() {
1616 if (!webview())
1617 return;
1618
[email protected]26aa0482009-09-30 16:55:271619 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221620 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121621 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291622}
1623
1624void RenderView::OnSetInitialFocus(bool reverse) {
1625 if (!webview())
1626 return;
[email protected]26aa0482009-09-30 16:55:271627 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291628}
1629
[email protected]9b66f34bf2010-10-27 20:45:511630void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:091631 WebKit::WebNode node = GetFocusedNode();
1632 if (!node.isNull()) {
1633 if (IsEditableNode(node))
1634 // TODO(varunjain): Change webkit API to scroll a particular node into
1635 // view and use that API here instead.
1636 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:511637 }
1638}
1639
initial.commit09911bf2008-07-26 23:55:291640///////////////////////////////////////////////////////////////////////////////
1641
[email protected]433819d2010-01-30 20:20:011642void RenderView::SetContentSettings(const ContentSettings& settings) {
1643 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011644}
1645
initial.commit09911bf2008-07-26 23:55:291646// Tell the embedding application that the URL of the active page has changed
1647void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451648 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291649 DCHECK(ds);
1650
[email protected]726985e22009-06-18 21:09:281651 const WebURLRequest& request = ds->request();
1652 const WebURLRequest& original_request = ds->originalRequest();
1653 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291654
[email protected]daa8c58e2009-06-15 17:21:101655 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1656 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291657
1658 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281659 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291660 params.is_post = false;
1661 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071662 params.frame_id = frame->identifier();
[email protected]726985e22009-06-18 21:09:281663 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091664 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551665 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291666 // SSL state specified in the request takes precedence over the one in the
1667 // response.
1668 // So far this is only intended for error pages that are not expected to be
1669 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281670 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551671 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291672 } else {
[email protected]726985e22009-06-18 21:09:281673 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291674 }
1675
1676 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281677 if (ds->hasUnreachableURL()) {
1678 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291679 } else {
[email protected]726985e22009-06-18 21:09:281680 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291681 }
1682
[email protected]726985e22009-06-18 21:09:281683 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241684 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041685 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291686
[email protected]ce0e250d2009-10-23 21:00:351687 params.searchable_form_url = navigation_state->searchable_form_url();
1688 params.searchable_form_encoding =
1689 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291690
1691 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101692 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291693 if (password_form_data)
1694 params.password_form = *password_form_data;
1695
1696 params.gesture = navigation_gesture_;
1697 navigation_gesture_ = NavigationGestureUnknown;
1698
[email protected]dd7daa82009-08-10 05:46:451699 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291700 // Top-level navigation.
1701
[email protected]71b0d5d2010-02-15 05:43:071702 // Clear "block" flags for the new page. This needs to happen before any of
1703 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1704 // so that these functions can correctly detect that a piece of content
1705 // flipped from "not blocked" to "blocked".
1706 ClearBlockedContentSettings();
1707
[email protected]62d2a112010-04-07 00:53:021708 // Set content settings. Default them from the parent window if one exists.
1709 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011710 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541711 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011712 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011713 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011714
1715 // These content settings were merely recorded transiently for this load.
1716 // We can erase them now. If at some point we reload this page, the
1717 // browser will send us new, up-to-date content settings.
1718 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401719 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101720 // The opener's view is not guaranteed to be non-null (it could be
1721 // detached from its page but not yet destructed).
1722 if (WebView* opener_view = frame->opener()->view()) {
1723 RenderView* opener = FromWebView(opener_view);
1724 SetContentSettings(opener->current_content_settings_);
1725 }
[email protected]f85f0702010-01-30 09:31:011726 }
1727
[email protected]b75b8292010-10-01 07:28:251728 // Set zoom level, but don't do it for full-page plugin since they don't use
1729 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011730 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541731 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251732 if (webview()->mainFrame()->document().isPluginDocument()) {
1733 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251734 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251735 } else {
1736 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251737 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251738 }
1739
[email protected]f85f0702010-01-30 09:31:011740 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511741 // This zoom level was merely recorded transiently for this load. We can
1742 // erase it now. If at some point we reload this page, the browser will
1743 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011744 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511745 }
1746
[email protected]b75b8292010-10-01 07:28:251747 // Reset the zoom limits in case a plugin had changed them previously. This
1748 // will also call us back which will cause us to send a message to
1749 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251750 webview()->zoomLimitsChanged(
1751 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1752 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251753
initial.commit09911bf2008-07-26 23:55:291754 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551755 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291756
[email protected]daa8c58e2009-06-15 17:21:101757 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291758 if (!PageTransition::IsMainFrame(params.transition)) {
1759 // If the main frame does a load, it should not be reported as a subframe
1760 // navigation. This can occur in the following case:
1761 // 1. You're on a site with frames.
1762 // 2. You do a subframe navigation. This is stored with transition type
1763 // MANUAL_SUBFRAME.
1764 // 3. You navigate to some non-frame site, say, google.com.
1765 // 4. You navigate back to the page from step 2. Since it was initially
1766 // MANUAL_SUBFRAME, it will be that same transition type here.
1767 // We don't want that, because any navigation that changes the toplevel
1768 // frame should be tracked as a toplevel navigation (this allows us to
1769 // update the URL bar, etc).
1770 params.transition = PageTransition::LINK;
1771 }
1772
initial.commit09911bf2008-07-26 23:55:291773 // If we have a valid consumed client redirect source,
1774 // the page contained a client redirect (meta refresh, document.loc...),
1775 // so we set the referrer and transition to match.
1776 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041777 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291778 params.referrer = completed_client_redirect_src_;
1779 params.transition = static_cast<PageTransition::Type>(
1780 params.transition | PageTransition::CLIENT_REDIRECT);
1781 } else {
1782 // Bug 654101: the referrer will be empty on https->http transitions. It
1783 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281784 params.referrer = GURL(
1785 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291786 }
1787
[email protected]726985e22009-06-18 21:09:281788 string16 method = request.httpMethod();
1789 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291790 params.is_post = true;
1791
[email protected]c2a797d2009-09-21 16:46:321792 // Save some histogram data so we can compute the average memory used per
1793 // page load of the glyphs.
1794 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1795 webkit_glue::GetGlyphPageCount());
1796
[email protected]15cf526b2010-02-12 06:33:491797 // This message needs to be sent before any of allowScripts(),
1798 // allowImages(), allowPlugins() is called for the new page, so that when
1799 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1800 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291801 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1802 } else {
1803 // Subframe navigation: the type depends on whether this navigation
1804 // generated a new session history entry. When they do generate a session
1805 // history entry, it means the user initiated the navigation and we should
1806 // mark it as such. This test checks if this is the first time UpdateURL
1807 // has been called since WillNavigateToURL was called to initiate the load.
1808 if (page_id_ > last_page_id_sent_to_browser_)
1809 params.transition = PageTransition::MANUAL_SUBFRAME;
1810 else
1811 params.transition = PageTransition::AUTO_SUBFRAME;
1812
initial.commit09911bf2008-07-26 23:55:291813 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1814 }
1815
1816 last_page_id_sent_to_browser_ =
1817 std::max(last_page_id_sent_to_browser_, page_id_);
1818
1819 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101820 // we don't want the transition type to persist. Just clear it.
1821 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501822
[email protected]af15bed2010-08-25 21:12:091823 // Check if the navigation was within the same page, in which case we don't
1824 // want to clear the accessibility cache.
1825 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351826 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141827 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501828 }
initial.commit09911bf2008-07-26 23:55:291829}
1830
1831// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171832void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291833 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171834 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171835 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171836 routing_id_,
1837 page_id_,
1838 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1839 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171840 }
initial.commit09911bf2008-07-26 23:55:291841}
1842
1843void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401844 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291845 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271846 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291847 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301848 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291849 last_encoding_name_ = encoding_name;
1850
[email protected]e38f40152008-09-12 23:08:301851 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291852 }
1853}
1854
[email protected]e15f680732010-11-23 22:30:201855// Sends the last committed session history state to the browser so it will be
1856// saved before we navigate to a new page. This must be called *before* the
1857// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291858void RenderView::UpdateSessionHistory(WebFrame* frame) {
1859 // If we have a valid page ID at this point, then it corresponds to the page
1860 // we are navigating away from. Otherwise, this is the first navigation, so
1861 // there is no past session history to record.
1862 if (page_id_ == -1)
1863 return;
1864
[email protected]ca948a22009-06-25 19:36:171865 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271866 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171867 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291868 return;
[email protected]ca948a22009-06-25 19:36:171869
1870 Send(new ViewHostMsg_UpdateState(
1871 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291872}
1873
[email protected]3d9689372009-09-10 04:29:171874void RenderView::OpenURL(
1875 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1876 Send(new ViewHostMsg_OpenURL(
1877 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1878}
1879
[email protected]79dbc662009-09-04 05:42:511880// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291881
initial.commit09911bf2008-07-26 23:55:291882void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281883 const WebURLRequest& failed_request,
1884 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291885 const std::string& html,
1886 bool replace) {
[email protected]726985e22009-06-18 21:09:281887 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291888 std::string alt_html;
[email protected]2a521c52011-01-26 18:45:211889 const Extension* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291890 if (html.empty()) {
1891 // Use a local error page.
1892 int resource_id;
1893 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111894
[email protected]81654282010-10-04 17:08:061895 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
[email protected]2a521c52011-01-26 18:45:211896 extension = render_thread_->GetExtensions()->GetByURL(failed_url);
[email protected]5351dbc2010-08-27 15:22:111897 if (extension) {
[email protected]3f853a52010-09-13 19:15:081898 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1899 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111900
1901 // TODO(erikkay): Should we use a different template for different
1902 // error messages?
1903 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291904 } else {
[email protected]3f853a52010-09-13 19:15:081905 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1906 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111907 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081908 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111909 } else {
[email protected]3f853a52010-09-13 19:15:081910 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111911 }
[email protected]75891fe2010-11-20 15:55:181912 resource_id = IDR_NET_ERROR_HTML;
initial.commit09911bf2008-07-26 23:55:291913 }
initial.commit09911bf2008-07-26 23:55:291914
1915 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1916 } else {
1917 alt_html = html;
1918 }
1919
[email protected]dd7daa82009-08-10 05:46:451920 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361921 GURL(chrome::kUnreachableWebDataURL),
[email protected]e6f546c32009-07-01 17:12:551922 failed_url,
1923 replace);
initial.commit09911bf2008-07-26 23:55:291924}
1925
[email protected]7ccddb8c2009-08-04 17:36:551926void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031927 if (!dom_automation_controller_.get()) {
1928 dom_automation_controller_.reset(new DomAutomationController());
1929 }
1930 dom_automation_controller_->set_message_sender(this);
1931 dom_automation_controller_->set_routing_id(routing_id_);
1932 dom_automation_controller_->BindToJavascript(frame,
[email protected]906690b2010-12-03 18:11:251933 "domAutomationController");
initial.commit09911bf2008-07-26 23:55:291934}
1935
initial.commit09911bf2008-07-26 23:55:291936bool RenderView::RunJavaScriptMessage(int type,
1937 const std::wstring& message,
1938 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071939 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291940 std::wstring* result) {
1941 bool success = false;
1942 std::wstring result_temp;
1943 if (!result)
1944 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291945
[email protected]12636df2009-09-28 22:32:211946 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1947 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291948 return success;
1949}
1950
[email protected]c1f50aa2010-02-18 03:46:571951bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1952 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1953 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1954 // it is particularly important that we do not call willEnterModalLoop as
1955 // that would defer resource loads for the dialog itself.
1956 if (RenderThread::current()) // Will be NULL during unit tests.
1957 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1958
1959 message->EnableMessagePumping(); // Runs a nested message loop.
1960 return Send(message);
1961}
1962
[email protected]2de7e002010-10-11 22:58:201963void RenderView::AddGURLSearchProvider(
1964 const GURL& osd_url,
1965 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
initial.commit09911bf2008-07-26 23:55:291966 if (!osd_url.is_empty())
1967 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
[email protected]2de7e002010-10-11 22:58:201968 provider_type));
initial.commit09911bf2008-07-26 23:55:291969}
1970
[email protected]e8345242010-05-06 03:00:401971void RenderView::OnAllowScriptToClose(bool script_can_close) {
1972 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311973}
1974
initial.commit09911bf2008-07-26 23:55:291975uint32 RenderView::GetCPBrowsingContext() {
1976 uint32 context = 0;
1977 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1978 return context;
1979}
1980
[email protected]2de7e002010-10-11 22:58:201981void RenderView::AddSearchProvider(
1982 const std::string& url,
1983 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
1984 if (provider_type.type ==
1985 ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER &&
1986 !webview()->mainFrame()->isProcessingUserGesture())
1987 return;
1988
1989 AddGURLSearchProvider(GURL(url), provider_type);
initial.commit09911bf2008-07-26 23:55:291990}
1991
[email protected]155f35e2010-07-17 00:30:181992ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251993RenderView::GetSearchProviderInstallState(WebFrame* frame,
1994 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:181995 GURL inquiry_url = GURL(url);
1996 if (inquiry_url.is_empty())
1997 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:251998
[email protected]155f35e2010-07-17 00:30:181999 ViewHostMsg_GetSearchProviderInstallState_Params install;
2000 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:252001 frame->url(),
[email protected]155f35e2010-07-17 00:30:182002 inquiry_url,
2003 &install));
2004 return install;
2005}
2006
[email protected]f103ab72009-09-02 17:10:592007void RenderView::OnMissingPluginStatus(
2008 WebPluginDelegateProxy* delegate,
2009 int status) {
[email protected]6c8afae52009-01-22 02:24:572010#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:592011 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:292012 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:502013 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:592014 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:292015 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2016 }
2017 } else {
2018 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
2019 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:502020 if (status ==
2021 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:292022 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2023 }
2024 }
[email protected]6c8afae52009-01-22 02:24:572025#else
[email protected]76c3b312010-05-20 21:38:292026 // TODO(port): Implement the infobar that accompanies the default plugin.
2027 // Linux: http://crbug.com/10952
2028 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:572029 NOTIMPLEMENTED();
2030#endif
initial.commit09911bf2008-07-26 23:55:292031}
2032
[email protected]48c9cf2d2009-09-16 16:47:522033// WebKit::WebViewClient ------------------------------------------------------
2034
[email protected]844acf372011-01-14 10:49:272035WebView* RenderView::createView(
2036 WebFrame* creator,
2037 const WebURLRequest& request,
2038 const WebWindowFeatures& features,
2039 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:522040 // Check to make sure we aren't overloading on popups.
2041 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2042 return NULL;
2043
2044 // This window can't be closed from a window.close() call until we receive a
2045 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:402046 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:522047
[email protected]8ab04652010-06-12 02:47:262048 ViewHostMsg_CreateWindow_Params params;
2049 params.opener_id = routing_id_;
2050 params.user_gesture = creator->isProcessingUserGesture();
2051 params.window_container_type = WindowFeaturesToContainerType(features);
2052 params.session_storage_namespace_id = session_storage_namespace_id_;
2053 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112054 params.opener_frame_id = creator->identifier();
2055 params.opener_url = creator->url();
2056 params.opener_security_origin = creator->securityOrigin().toString().utf8();
2057 if (!request.isNull())
2058 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:262059
[email protected]48c9cf2d2009-09-16 16:47:522060 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:342061 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:262062 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:522063
[email protected]48c9cf2d2009-09-16 16:47:522064 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:262065 new ViewHostMsg_CreateWindow(params,
2066 &routing_id,
2067 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212068 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522069 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522070
[email protected]48c9cf2d2009-09-16 16:47:522071 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:422072 0,
[email protected]12636df2009-09-28 22:32:212073 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:522074 renderer_preferences_,
2075 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:212076 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:342077 routing_id,
[email protected]8ab04652010-06-12 02:47:262078 cloned_session_storage_namespace_id,
2079 frame_name);
2080 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522081
[email protected]007a848b2009-10-26 15:55:462082 // Record whether the creator frame is trying to suppress the opener field.
2083 view->opener_suppressed_ = opener_suppressed;
2084
[email protected]48c9cf2d2009-09-16 16:47:522085 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:092086 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:522087 if (!creator_url.is_valid() || !creator_url.IsStandard())
2088 creator_url = GURL();
2089 view->creator_url_ = creator_url;
2090
2091 // Copy over the alternate error page URL so we can have alt error pages in
2092 // the new render view (we don't need the browser to send the URL back down).
2093 view->alternate_error_page_url_ = alternate_error_page_url_;
2094
2095 return view->webview();
2096}
2097
[email protected]3e2b375b2010-04-07 17:03:122098WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:522099 RenderWidget* widget = RenderWidget::Create(routing_id_,
2100 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:122101 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:522102 return widget->webwidget();
2103}
2104
2105WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:442106 // TODO(jcivelli): Remove this deprecated method when its been removed from
2107 // the WebViewClient interface. It's been replaced by
2108 // createExternalPopupMenu.
2109 NOTREACHED();
2110 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522111}
2112
[email protected]caf706f2010-10-26 17:54:082113WebExternalPopupMenu* RenderView::createExternalPopupMenu(
2114 const WebPopupMenuInfo& popup_menu_info,
2115 WebExternalPopupMenuClient* popup_menu_client) {
2116 DCHECK(!external_popup_menu_.get());
2117 external_popup_menu_.reset(
2118 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2119 return external_popup_menu_.get();
2120}
2121
[email protected]484955942010-08-19 16:13:182122WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) {
2123 RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_,
2124 render_thread_,
2125 popup_type);
2126 return widget->webwidget();
2127}
2128
[email protected]0bd753682010-12-16 18:15:522129webkit::ppapi::FullscreenContainer*
2130RenderView::CreatePepperFullscreenContainer(
2131 webkit::ppapi::PluginInstance* plugin) {
[email protected]79c7bed2010-09-14 22:28:392132 RenderWidgetFullscreenPepper* widget =
2133 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
2134 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:562135 return widget;
[email protected]79c7bed2010-09-14 22:28:392136}
2137
[email protected]68c50e52010-05-12 11:14:392138WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:342139 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:392140 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:292141 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
2142 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
2143 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342144}
2145
[email protected]48c9cf2d2009-09-16 16:47:522146void RenderView::didAddMessageToConsole(
2147 const WebConsoleMessage& message, const WebString& source_name,
2148 unsigned source_line) {
2149 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2150 UTF16ToWideHack(message.text),
2151 static_cast<int32>(source_line),
2152 UTF16ToWideHack(source_name)));
2153}
2154
2155void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:582156 DCHECK(frame);
[email protected]212a49d2010-10-25 18:23:472157 if (CommandLine::ForCurrentProcess()->HasSwitch(
2158 switches::kEnablePrintPreview)) {
2159 Print(frame, true, true);
2160 } else {
2161 Print(frame, true, false);
2162 }
[email protected]48c9cf2d2009-09-16 16:47:522163}
2164
[email protected]3354d3e2010-06-10 19:53:022165WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512166 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022167}
2168
[email protected]48c9cf2d2009-09-16 16:47:522169void RenderView::didStartLoading() {
2170 if (is_loading_) {
2171 DLOG(WARNING) << "didStartLoading called while loading";
2172 return;
2173 }
2174
2175 is_loading_ = true;
2176 // Clear the pointer so that we can assign it only when there is an unknown
2177 // plugin on a page.
2178 first_default_plugin_.reset();
2179
2180 Send(new ViewHostMsg_DidStartLoading(routing_id_));
2181}
2182
2183void RenderView::didStopLoading() {
2184 if (!is_loading_) {
2185 DLOG(WARNING) << "DidStopLoading called while not loading";
2186 return;
2187 }
2188
2189 is_loading_ = false;
2190
2191 // NOTE: For now we're doing the safest thing, and sending out notification
2192 // when done loading. This currently isn't an issue as the favicon is only
2193 // displayed when done loading. Ideally we would send notification when
2194 // finished parsing the head, but webkit doesn't support that yet.
2195 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:272196 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:522197 if (!favicon_url.is_empty())
2198 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
2199
[email protected]26aa0482009-09-30 16:55:272200 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]2de7e002010-10-11 22:58:202201 ViewHostMsg_PageHasOSDD_Type::Autodetected());
[email protected]48c9cf2d2009-09-16 16:47:522202
2203 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2204
[email protected]90109412010-12-15 17:14:242205 if (load_progress_tracker_ != NULL)
2206 load_progress_tracker_->DidStopLoading();
2207
[email protected]f9f4841b2010-03-20 05:41:422208 MessageLoop::current()->PostDelayedTask(
2209 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302210 page_info_method_factory_.NewRunnableMethod(
2211 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:372212 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:522213}
2214
[email protected]90109412010-12-15 17:14:242215void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
2216 if (load_progress_tracker_ != NULL)
2217 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2218}
2219
[email protected]f55039a2010-02-17 14:12:062220bool RenderView::isSmartInsertDeleteEnabled() {
2221#if defined(OS_MACOSX)
2222 return true;
2223#else
2224 return false;
2225#endif
2226}
2227
[email protected]04fc9482009-09-18 22:13:032228bool RenderView::isSelectTrailingWhitespaceEnabled() {
2229#if defined(OS_WIN)
2230 return true;
2231#else
2232 return false;
2233#endif
2234}
2235
[email protected]04fc9482009-09-18 22:13:032236void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:422237#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032238 if (!handling_input_event_)
2239 return;
2240 // TODO(estade): investigate incremental updates to the selection so that we
2241 // don't send the entire selection over IPC every time.
2242 if (!is_empty_selection) {
2243 // Sometimes we get repeated didChangeSelection calls from webkit when
2244 // the selection hasn't actually changed. We don't want to report these
2245 // because it will cause us to continually claim the X clipboard.
2246 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:272247 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:032248 if (this_selection == last_selection_)
2249 return;
2250
2251 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2252 this_selection));
2253 last_selection_ = this_selection;
2254 } else {
2255 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:162256 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2257 last_selection_));
[email protected]04fc9482009-09-18 22:13:032258 }
[email protected]0ff0ff32010-12-21 19:34:422259#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032260}
2261
2262void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122263 const std::string& name = UTF16ToUTF8(command_name);
2264 if (StartsWithASCII(name, "Move", true) ||
2265 StartsWithASCII(name, "Insert", true) ||
2266 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032267 return;
2268 UserMetricsRecordAction(name);
2269}
2270
[email protected]54ec7f82010-10-21 22:32:512271void RenderView::SendPendingAccessibilityNotifications() {
2272 if (!accessibility_.get())
2273 return;
2274
2275 if (pending_accessibility_notifications_.empty())
2276 return;
2277
2278 // Send all pending accessibility notifications.
2279 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
2280 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
2281 RendererAccessibilityNotification& notification =
2282 pending_accessibility_notifications_[i];
2283 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
2284 if (!obj.isValid())
2285 continue;
2286
2287 ViewHostMsg_AccessibilityNotification_Params param;
2288 param.notification_type = pending_accessibility_notifications_[i].type;
[email protected]70eee342010-11-05 01:59:372289 param.acc_obj = WebAccessibility(
2290 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:512291 notifications.push_back(param);
2292 }
2293 pending_accessibility_notifications_.clear();
2294 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
2295 accessibility_ack_pending_ = true;
2296}
2297
[email protected]b2528b72009-09-24 06:57:102298bool RenderView::handleCurrentKeyboardEvent() {
2299 if (edit_commands_.empty())
2300 return false;
2301
[email protected]26aa0482009-09-30 16:55:272302 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102303 if (!frame)
2304 return false;
2305
2306 EditCommands::iterator it = edit_commands_.begin();
2307 EditCommands::iterator end = edit_commands_.end();
2308
[email protected]507b33ea2009-09-29 03:56:512309 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102310 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332311 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2312 // key (but it's the exception). Once one edit command is not executed, it
2313 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102314 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2315 WebString::fromUTF8(it->value)))
2316 break;
[email protected]507b33ea2009-09-29 03:56:512317 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102318 }
2319
[email protected]507b33ea2009-09-29 03:56:512320 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102321}
2322
[email protected]2a3a7762009-10-19 19:17:322323void RenderView::spellCheck(const WebString& text,
2324 int& misspelled_offset,
2325 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:562326 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:462327
[email protected]85c55dc2009-11-06 03:05:462328 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:172329 RenderThread* thread = RenderThread::current();
2330 // Will be NULL during unit tests.
2331 if (thread) {
[email protected]c27324b2009-11-19 22:44:292332 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:172333 word.c_str(), word.size(), document_tag_,
2334 &misspelled_offset, &misspelled_length, NULL);
2335 }
[email protected]1dbafaf72009-09-23 19:43:562336}
2337
2338WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322339 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562340 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:262341 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:562342 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:172343 RenderThread* thread = RenderThread::current();
2344 // Will be NULL during unit tests.
2345 if (thread) {
2346 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:292347 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:172348 word, document_tag_);
2349 }
[email protected]1dbafaf72009-09-23 19:43:562350 }
[email protected]2a3a7762009-10-19 19:17:322351 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562352}
2353
[email protected]c49085c72009-10-02 16:28:562354void RenderView::showSpellingUI(bool show) {
2355 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2356}
2357
[email protected]8922e1f2009-10-03 05:01:262358bool RenderView::isShowingSpellingUI() {
2359 return spelling_panel_visible_;
2360}
2361
[email protected]1dbafaf72009-09-23 19:43:562362void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322363 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2364 word));
[email protected]1dbafaf72009-09-23 19:43:562365}
2366
[email protected]13a1e4c3c2011-02-03 21:07:092367void RenderView::continuousSpellCheckingEnabledStateChanged() {
2368 UpdateToggleSpellCheckCommandState();
2369}
2370
[email protected]a1128322009-10-06 18:38:462371bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352372 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472373 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352374 // Do not open the file dialog in a hidden RenderView.
2375 if (is_hidden())
2376 return false;
[email protected]cdaf8d02010-03-30 19:52:472377 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262378 if (params.directory)
2379 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2380 else if (params.multiSelect)
2381 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2382 else
2383 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472384 ipc_params.title = params.title;
2385 ipc_params.default_file_name =
2386 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592387 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472388
2389 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462390}
2391
[email protected]48c9cf2d2009-09-16 16:47:522392void RenderView::runModalAlertDialog(
2393 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062394 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]48c9cf2d2009-09-16 16:47:522395 UTF16ToWideHack(message),
2396 std::wstring(),
2397 frame->url(),
2398 NULL);
2399}
2400
2401bool RenderView::runModalConfirmDialog(
2402 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062403 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]48c9cf2d2009-09-16 16:47:522404 UTF16ToWideHack(message),
2405 std::wstring(),
2406 frame->url(),
2407 NULL);
2408}
2409
2410bool RenderView::runModalPromptDialog(
2411 WebFrame* frame, const WebString& message, const WebString& default_value,
2412 WebString* actual_value) {
2413 std::wstring result;
[email protected]9dd7e3d72011-01-20 18:27:062414 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]48c9cf2d2009-09-16 16:47:522415 UTF16ToWideHack(message),
2416 UTF16ToWideHack(default_value),
2417 frame->url(),
2418 &result);
2419 if (ok)
2420 actual_value->assign(WideToUTF16Hack(result));
2421 return ok;
2422}
2423
2424bool RenderView::runModalBeforeUnloadDialog(
2425 WebFrame* frame, const WebString& message) {
2426 bool success = false;
2427 // This is an ignored return value, but is included so we can accept the same
2428 // response as RunJavaScriptMessage.
2429 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212430 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522431 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212432 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522433 return success;
2434}
2435
[email protected]79e37442009-10-09 18:17:442436void RenderView::showContextMenu(
2437 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292438 ContextMenuParams params = ContextMenuParams(data);
2439 if (!params.misspelled_word.empty() && RenderThread::current()) {
2440 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042441 bool spelled_right = RenderThread::current()->spellchecker()->
2442 SpellCheckWord(
2443 params.misspelled_word.c_str(), params.misspelled_word.size(),
2444 document_tag_,
2445 &misspelled_offset, &misspelled_length,
2446 &params.dictionary_suggestions);
2447 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292448 params.misspelled_word.clear();
2449 }
[email protected]216932c2010-08-26 21:44:272450 // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do
2451 // it. We replace it with an empty GURL so the appropriate items are disabled
2452 // in the context menu.
2453 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2454 // data encoded images. We should have a way to save them.
2455 if (params.src_url.spec().size() > chrome::kMaxURLChars)
2456 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102457 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:292458 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442459}
2460
[email protected]52f139e2c2010-06-11 16:56:092461bool RenderView::supportsFullscreen() {
2462 return CommandLine::ForCurrentProcess()->HasSwitch(
2463 switches::kEnableVideoFullscreen);
2464}
2465
2466void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2467 NOTIMPLEMENTED();
2468}
2469
2470void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2471 NOTIMPLEMENTED();
2472}
2473
[email protected]48c9cf2d2009-09-16 16:47:522474void RenderView::setStatusText(const WebString& text) {
2475}
2476
[email protected]163f8242009-10-30 20:19:552477void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582478 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522479 if (latest_url == target_url_)
2480 return;
[email protected]163f8242009-10-30 20:19:552481
[email protected]48c9cf2d2009-09-16 16:47:522482 // Tell the browser to display a destination link.
2483 if (target_url_status_ == TARGET_INFLIGHT ||
2484 target_url_status_ == TARGET_PENDING) {
2485 // If we have a request in-flight, save the URL to be sent when we
2486 // receive an ACK to the in-flight request. We can happily overwrite
2487 // any existing pending sends.
2488 pending_target_url_ = latest_url;
2489 target_url_status_ = TARGET_PENDING;
2490 } else {
2491 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2492 target_url_ = latest_url;
2493 target_url_status_ = TARGET_INFLIGHT;
2494 }
2495}
2496
[email protected]13a1e4c3c2011-02-03 21:07:092497void RenderView::UpdateToggleSpellCheckCommandState() {
2498 bool is_enabled = false;
2499 WebKit::WebNode node = GetFocusedNode();
2500 if (!node.isNull())
2501 is_enabled = IsEditableNode(node);
2502
2503 RenderViewCommandCheckedState checked_state =
2504 RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED;
2505 if (is_enabled && webview()) {
2506 WebFrame* frame = webview()->focusedFrame();
2507 if (frame->isContinuousSpellCheckingEnabled())
2508 checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED;
2509 }
2510
2511 Send(new ViewHostMsg_CommandStateChanged(
2512 routing_id_,
2513 RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK,
2514 is_enabled,
2515 checked_state));
2516}
2517
[email protected]882daa92009-11-05 16:31:312518void RenderView::StartNavStateSyncTimerIfNecessary() {
2519 int delay;
2520 if (send_content_state_immediately_)
2521 delay = 0;
2522 else if (is_hidden())
2523 delay = kDelaySecondsForContentStateSyncHidden;
2524 else
2525 delay = kDelaySecondsForContentStateSync;
2526
2527 if (nav_state_sync_timer_.IsRunning()) {
2528 // The timer is already running. If the delay of the timer maches the amount
2529 // we want to delay by, then return. Otherwise stop the timer so that it
2530 // gets started with the right delay.
2531 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2532 return;
2533 nav_state_sync_timer_.Stop();
2534 }
2535
2536 nav_state_sync_timer_.Start(
2537 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2538}
2539
[email protected]163f8242009-10-30 20:19:552540void RenderView::setMouseOverURL(const WebURL& url) {
2541 mouse_over_url_ = GURL(url);
2542 UpdateTargetURL(mouse_over_url_, focus_url_);
2543}
2544
2545void RenderView::setKeyboardFocusURL(const WebURL& url) {
2546 focus_url_ = GURL(url);
2547 UpdateTargetURL(focus_url_, mouse_over_url_);
2548}
2549
[email protected]48c9cf2d2009-09-16 16:47:522550void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2551 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2552 hint));
2553}
2554
[email protected]c27ae592010-03-18 15:24:412555void RenderView::startDragging(const WebDragData& data,
2556 WebDragOperationsMask mask,
2557 const WebImage& image,
2558 const WebPoint& imageOffset) {
2559#if WEBKIT_USING_SKIA
2560 SkBitmap bitmap(image.getSkBitmap());
2561#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332562 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412563#endif
2564
[email protected]48c9cf2d2009-09-16 16:47:522565 Send(new ViewHostMsg_StartDragging(routing_id_,
2566 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412567 mask,
2568 bitmap,
2569 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522570}
2571
[email protected]28b92df2009-09-25 17:35:452572bool RenderView::acceptsLoadDrops() {
2573 return renderer_preferences_.can_accept_load_drops;
2574}
2575
[email protected]48c9cf2d2009-09-16 16:47:522576void RenderView::focusNext() {
2577 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2578}
2579
2580void RenderView::focusPrevious() {
2581 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2582}
2583
[email protected]08e9e132010-06-01 16:58:492584void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512585 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072586
2587 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2588 // TODO(ctguil): Make WebKit send this notification.
2589 // When focus is cleared notify accessibility that the document is focused.
2590 postAccessibilityNotification(
2591 webview()->accessibilityObject(),
2592 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2593 }
[email protected]13a1e4c3c2011-02-03 21:07:092594
2595 UpdateToggleSpellCheckCommandState();
[email protected]08e9e132010-06-01 16:58:492596}
2597
[email protected]48c9cf2d2009-09-16 16:47:522598void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522599 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2600}
2601
2602int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002603 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522604}
2605
2606int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002607 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522608}
2609
[email protected]c4e98902010-06-01 10:20:142610void RenderView::didUpdateInspectorSetting(const WebString& key,
2611 const WebString& value) {
2612 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2613 key.utf8(),
2614 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262615}
2616
[email protected]79dbc662009-09-04 05:42:512617// WebKit::WebWidgetClient ----------------------------------------------------
2618
[email protected]ea42e7782010-08-23 23:58:122619void RenderView::didFocus() {
2620 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2621 // we won't have to test for user gesture anymore and we can
2622 // move that code back to render_widget.cc
2623 if (webview() && webview()->mainFrame() &&
2624 webview()->mainFrame()->isProcessingUserGesture()) {
2625 Send(new ViewHostMsg_Focus(routing_id_));
2626 }
2627}
2628
2629void RenderView::didBlur() {
2630 // TODO(jcivelli): see TODO above in didFocus().
2631 if (webview() && webview()->mainFrame() &&
2632 webview()->mainFrame()->isProcessingUserGesture()) {
2633 Send(new ViewHostMsg_Blur(routing_id_));
2634 }
2635}
2636
initial.commit09911bf2008-07-26 23:55:292637// We are supposed to get a single call to Show for a newly created RenderView
2638// that was created via RenderView::CreateWebView. So, we wait until this
2639// point to dispatch the ShowView message.
2640//
2641// This method provides us with the information about how to display the newly
2642// created RenderView (i.e., as a constrained popup or as a new tab).
2643//
[email protected]4873c7d2009-07-16 06:36:282644void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292645 DCHECK(!did_show_) << "received extraneous Show call";
2646 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2647
2648 if (did_show_)
2649 return;
2650 did_show_ = true;
2651
[email protected]4026ce1e2010-09-14 19:35:042652 // Extensions and apps always allowed to create unrequested popups. The second
2653 // check is necessary to include content scripts.
[email protected]2a521c52011-01-26 18:45:212654 if (render_thread_->GetExtensions()->GetByURL(creator_url_) ||
[email protected]4026ce1e2010-09-14 19:35:042655 bindings_utils::GetInfoForCurrentContext()) {
2656 opened_by_user_gesture_ = true;
2657 }
2658
[email protected]28295ec2009-10-16 05:34:332659 // Force new windows to a popup if they were not opened with a user gesture.
2660 if (!opened_by_user_gesture_) {
2661 // We exempt background tabs for compat with older versions of Chrome.
2662 // TODO(darin): This seems bogus. These should have a user gesture, so
2663 // we probably don't need this check.
2664 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2665 policy = WebKit::WebNavigationPolicyNewPopup;
2666 }
2667
initial.commit09911bf2008-07-26 23:55:292668 // NOTE: initial_pos_ may still have its default values at this point, but
2669 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2670 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282671 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2672 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292673 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242674 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292675}
2676
[email protected]4873c7d2009-07-16 06:36:282677void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292678 DCHECK(did_show_) << "should already have shown the view";
2679
[email protected]c1f50aa2010-02-18 03:46:572680 // We must keep WebKit's shared timer running in this case in order to allow
2681 // showModalDialog to function properly.
2682 //
2683 // TODO(darin): WebKit should really be smarter about suppressing events and
2684 // timers so that we do not need to manage the shared timer in such a heavy
2685 // handed manner.
2686 //
2687 if (RenderThread::current()) // Will be NULL during unit tests.
2688 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2689
[email protected]12636df2009-09-28 22:32:212690 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292691}
2692
[email protected]3d9689372009-09-10 04:29:172693// WebKit::WebFrameClient -----------------------------------------------------
2694
[email protected]00152e92010-07-19 11:47:402695WebPlugin* RenderView::createPlugin(WebFrame* frame,
2696 const WebPluginParams& params) {
[email protected]6fdd4182010-10-14 23:59:262697 bool found = false;
[email protected]414508d2010-11-02 10:45:392698 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
[email protected]55126132010-08-19 14:53:282699 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]191eb3f72010-12-21 06:27:502700 webkit::npapi::WebPluginInfo info;
[email protected]7a13e792010-08-03 08:18:242701 GURL url(params.url);
[email protected]6fdd4182010-10-14 23:59:262702 std::string actual_mime_type;
[email protected]c8f73ab2011-01-22 00:05:172703 Send(new ViewHostMsg_GetPluginInfo(routing_id_,
2704 url,
[email protected]6fdd4182010-10-14 23:59:262705 frame->top()->url(),
2706 params.mimeType.utf8(),
2707 &found,
2708 &info,
[email protected]44fda5c2010-11-02 10:50:542709 &plugin_setting,
[email protected]6fdd4182010-10-14 23:59:262710 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242711
[email protected]6fdd4182010-10-14 23:59:262712 if (!found)
[email protected]0cdafff2010-07-26 09:54:372713 return NULL;
[email protected]414508d2010-11-02 10:45:392714 DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
[email protected]4e0616e2010-05-28 14:55:532715
[email protected]191eb3f72010-12-21 06:27:502716 const webkit::npapi::PluginGroup* group =
2717 webkit::npapi::PluginList::Singleton()->GetPluginGroup(info);
[email protected]79ce1032010-12-07 13:29:412718 DCHECK(group != NULL);
[email protected]851b1eb2010-08-09 13:32:292719
[email protected]6e74a3b2010-12-21 22:27:542720 if (group->IsVulnerable() &&
2721 !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) {
[email protected]3c2826852010-12-16 19:09:142722 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2723 group->GetGroupName(),
2724 GURL(group->GetUpdateURL())));
2725 return CreatePluginPlaceholder(frame,
2726 params,
2727 *group,
[email protected]2e34ab3f2010-12-17 05:47:372728 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202729 IDS_PLUGIN_OUTDATED,
2730 false);
[email protected]851b1eb2010-08-09 13:32:292731 }
[email protected]6e74a3b2010-12-21 22:27:542732
[email protected]b83ff222011-01-24 17:37:122733 if (!webkit::npapi::IsPluginEnabled(info))
[email protected]3c2826852010-12-16 19:09:142734 return NULL;
[email protected]851b1eb2010-08-09 13:32:292735
[email protected]414508d2010-11-02 10:45:392736 ContentSetting host_setting =
2737 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS];
[email protected]d12dcdd62011-01-27 06:53:252738
2739 if (group->RequiresAuthorization() &&
2740 !cmd->HasSwitch(switches::kAlwaysAuthorizePlugins) &&
2741 (plugin_setting == CONTENT_SETTING_ALLOW ||
2742 plugin_setting == CONTENT_SETTING_ASK) &&
2743 host_setting == CONTENT_SETTING_DEFAULT) {
2744 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2745 group->GetGroupName(),
2746 GURL()));
2747 return CreatePluginPlaceholder(frame,
2748 params,
2749 *group,
2750 IDR_BLOCKED_PLUGIN_HTML,
2751 IDS_PLUGIN_NOT_AUTHORIZED,
2752 false);
2753 }
2754
[email protected]191eb3f72010-12-21 06:27:502755 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName ||
[email protected]414508d2010-11-02 10:45:392756 plugin_setting == CONTENT_SETTING_ALLOW ||
2757 host_setting == CONTENT_SETTING_ALLOW) {
[email protected]90dba072011-01-20 20:10:202758 // Delay loading plugins if prerendering.
2759 WebDataSource* ds = frame->dataSource();
2760 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2761 if (navigation_state->is_prerendering()) {
2762 return CreatePluginPlaceholder(frame,
2763 params,
2764 *group,
2765 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
2766 IDS_PLUGIN_LOAD,
2767 true);
2768 }
2769
[email protected]0bd753682010-12-16 18:15:522770 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:452771 pepper_delegate_.CreatePepperPlugin(info.path));
2772 if (pepper_module)
2773 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]6fdd4182010-10-14 23:59:262774 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]0cdafff2010-07-26 09:54:372775 }
[email protected]fc61e222010-10-11 15:42:142776 std::string resource;
2777 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2778 resource = group->identifier();
2779 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]414508d2010-11-02 10:45:392780 if (plugin_setting == CONTENT_SETTING_ASK) {
[email protected]3c2826852010-12-16 19:09:142781 return CreatePluginPlaceholder(frame,
2782 params,
2783 *group,
[email protected]2e34ab3f2010-12-17 05:47:372784 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202785 IDS_PLUGIN_LOAD,
2786 false);
[email protected]fc61e222010-10-11 15:42:142787 } else {
[email protected]3c2826852010-12-16 19:09:142788 return CreatePluginPlaceholder(frame,
2789 params,
2790 *group,
[email protected]2e34ab3f2010-12-17 05:47:372791 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202792 IDS_PLUGIN_BLOCKED,
2793 false);
[email protected]fc61e222010-10-11 15:42:142794 }
[email protected]3d9689372009-09-10 04:29:172795}
2796
2797WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562798 WebApplicationCacheHostImpl* appcache_host =
2799 WebApplicationCacheHostImpl::FromFrame(frame);
2800 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2801 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2802 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172803}
2804
[email protected]9c00f002009-11-05 22:37:422805WebSharedWorker* RenderView::createSharedWorker(
2806 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372807 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422808
[email protected]30447b62009-11-13 01:13:372809 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512810 bool exists = false;
[email protected]30447b62009-11-13 01:13:372811 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512812 ViewHostMsg_CreateWorker_Params params;
2813 params.url = url;
2814 params.is_shared = true;
2815 params.name = name;
2816 params.document_id = document_id;
2817 params.render_view_route_id = routing_id_;
2818 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232819 params.parent_appcache_host_id = 0;
2820 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372821 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512822 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372823 if (url_mismatch) {
2824 return NULL;
2825 } else {
2826 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492827 document_id,
[email protected]6de0bcf2010-02-17 22:00:512828 exists,
[email protected]30447b62009-11-13 01:13:372829 route_id,
2830 routing_id_);
2831 }
[email protected]9c00f002009-11-05 22:37:422832}
2833
[email protected]3d9689372009-09-10 04:29:172834WebMediaPlayer* RenderView::createMediaPlayer(
2835 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]f78d1dfc2011-01-15 07:09:272836 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
2837 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:492838 scoped_ptr<media::FilterCollection> collection(
2839 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:372840
[email protected]3d9689372009-09-10 04:29:172841 // Add in any custom filter factories first.
2842 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2843 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2844 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:492845 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:172846 }
2847
[email protected]3bb08602010-10-07 21:47:172848 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:122849 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:072850 WebGraphicsContext3DCommandBufferImpl* context =
2851 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2852 frame->view()->graphicsContext3D());
2853 if (!context)
2854 return NULL;
[email protected]a9a43012010-11-05 01:54:062855
[email protected]5aa6a312010-11-06 00:00:072856 // Add the hardware video decoder factory.
2857 // TODO(hclam): This will cause the renderer process to crash on context
2858 // lost.
2859 bool ret = context->makeContextCurrent();
2860 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:492861 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:072862 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:172863 }
2864
[email protected]457d8342010-10-23 01:20:372865 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:312866 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2867 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
2868 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:492869 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:312870 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:112871
[email protected]a8e24d522010-12-01 07:13:582872 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:272873 new webkit_glue::WebMediaPlayerImpl(client,
2874 collection.release(),
2875 message_loop_factory.release()));
[email protected]79684282010-12-06 21:15:462876 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:582877 cmd_line->HasSwitch(switches::kSimpleDataSource),
2878 video_renderer)) {
2879 return NULL;
2880 }
2881 return result.release();
[email protected]3d9689372009-09-10 04:29:172882}
2883
[email protected]035545f2010-04-09 13:10:212884WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2885 WebFrame* frame, WebApplicationCacheHostClient* client) {
2886 return new RendererWebApplicationCacheHostImpl(
2887 FromWebView(frame->view()), client,
2888 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2889}
2890
[email protected]8ff181072010-11-29 17:09:382891WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
2892 return &cookie_jar_;
2893}
2894
[email protected]5041f982010-08-11 21:40:452895void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512896 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452897}
2898
[email protected]3d9689372009-09-10 04:29:172899void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302900 WebDataSource* ds = frame->dataSource();
2901 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522902
[email protected]a5a65ac2010-11-05 18:14:362903 page_load_histograms_.Dump(frame);
[email protected]fa7b6b542009-11-03 05:02:302904 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]f3ce0a32011-01-11 08:18:182905
[email protected]676126f72011-01-15 00:03:512906 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172907}
2908
[email protected]684e4a42010-01-30 06:44:112909bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402910 if (enabled_per_settings &&
2911 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2912 return true;
2913
2914 if (IsWhitelistedForContentSettings(frame))
2915 return true;
2916
[email protected]55126132010-08-19 14:53:282917 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402918 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112919}
2920
[email protected]d5f9e4f2010-07-28 08:31:302921bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]3627b06d2010-11-12 16:36:162922 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
[email protected]d5f9e4f2010-07-28 08:31:302923}
2924
2925
[email protected]3d9689372009-09-10 04:29:172926void RenderView::loadURLExternally(
2927 WebFrame* frame, const WebURLRequest& request,
2928 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592929 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2930 if (policy == WebKit::WebNavigationPolicyDownload) {
2931 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2932 } else {
2933 OpenURL(request.url(), referrer, policy);
2934 }
[email protected]3d9689372009-09-10 04:29:172935}
2936
2937WebNavigationPolicy RenderView::decidePolicyForNavigation(
2938 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222939 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172940 // Webkit is asking whether to navigate to a new URL.
2941 // This is fine normally, except if we're showing UI from one security
2942 // context and they're trying to navigate to a different context.
2943 const GURL& url = request.url();
2944
2945 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302946 // navigations.
[email protected]8079b362010-05-07 18:37:452947 if (renderer_preferences_.browser_handles_top_level_requests &&
2948 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192949 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232950 // Reset these counters as the RenderView could be reused for the next
2951 // navigation.
2952 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232953 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192954 OpenURL(url, referrer, default_policy);
2955 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172956 }
2957
2958 // A content initiated navigation may have originated from a link-click,
2959 // script, drag-n-drop operation, etc.
2960 bool is_content_initiated =
2961 NavigationState::FromDataSource(frame->provisionalDataSource())->
2962 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582963 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172964
[email protected]6101c342010-12-16 22:44:372965 // Detect when we're crossing a permission-based boundary (e.g. into or out of
2966 // an extension or app origin, leaving a DOMUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572967 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372968 // opening a new window). But we sometimes navigate to about:blank to clear a
2969 // tab, and we want to still allow that.
2970 //
[email protected]8f4da8c2011-02-09 19:49:572971 // Note: we do this only for GET requests because our mechanism for switching
2972 // processes only issues GET requests. In particular, POST requests don't
2973 // work, because this mechanism does not preserve form POST data. If it
2974 // becomes necessary to support process switching for POST requests, we will
2975 // need to send the request's httpBody data up to the browser process, and
2976 // issue a special POST navigation in WebKit (via
2977 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2978 // for examples of how to send the httpBody data.
2979 // Note2: We normally don't do this for browser-initiated navigations, since
2980 // it's pointless to tell the browser about navigations it gave us. But
2981 // we do potentially ask the browser to handle a redirect that was originally
2982 // initiated by the browser. See http://crbug.com/70943
2983 //
2984 // TODO(creis): Move this redirect check to the browser process to avoid
2985 // ping-ponging. See http://crbug.com/72380.
2986 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372987 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2988 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2989 bool send_referrer = false;
2990 bool should_fork =
2991 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172992 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372993 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112994
2995 // If the navigation would cross an app extent boundary, we also need
2996 // to defer to the browser to ensure process isolation.
2997 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2998 // which means that things like the back button won't trigger it. Is that
2999 // OK?
[email protected]88c15e972011-02-05 04:19:533000 // TODO(creis): For hosted apps, we currently only swap processes to enter
3001 // the app and not exit it, since we currently lose context (e.g.,
3002 // window.opener) if the window navigates back. See crbug.com/65953.
[email protected]2a521c52011-01-26 18:45:213003 if (!should_fork &&
[email protected]88c15e972011-02-05 04:19:533004 CrossesExtensionExtents(
[email protected]2a521c52011-01-26 18:45:213005 render_thread_->GetExtensions(),
3006 frame,
3007 url)) {
[email protected]5351dbc2010-08-27 15:22:113008 // Include the referrer in this case since we're going from a hosted web
3009 // page. (the packaged case is handled previously by the extension
3010 // navigation test)
[email protected]6101c342010-12-16 22:44:373011 should_fork = true;
3012 send_referrer = true;
3013 }
3014
3015 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:113016 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:373017 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:113018 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3019 }
[email protected]3d9689372009-09-10 04:29:173020 }
3021
3022 // Detect when a page is "forking" a new tab that can be safely rendered in
3023 // its own process. This is done by sites like Gmail that try to open links
3024 // in new windows without script connections back to the original page. We
3025 // treat such cases as browser navigations (in which we will create a new
3026 // renderer for a cross-site navigation), rather than WebKit navigations.
3027 //
3028 // We use the following heuristic to decide whether to fork a new page in its
3029 // own process:
3030 // The parent page must open a new tab to about:blank, set the new tab's
3031 // window.opener to null, and then redirect the tab to a cross-site URL using
3032 // JavaScript.
[email protected]007a848b2009-10-26 15:55:463033 //
3034 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
3035 // (see below).
[email protected]3d9689372009-09-10 04:29:173036 bool is_fork =
3037 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:583038 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173039 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523040 historyBackListCount() < 1 &&
3041 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173042 // The parent page must have set the child's window.opener to null before
3043 // redirecting to the desired URL.
3044 frame->opener() == NULL &&
3045 // Must be a top-level frame.
3046 frame->parent() == NULL &&
3047 // Must not have issued the request from this page.
3048 is_content_initiated &&
3049 // Must be targeted at the current tab.
3050 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3051 // Must be a JavaScript navigation, which appears as "other".
3052 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463053
3054 // Recognize if this navigation is from a link with rel=noreferrer and
3055 // target=_blank attributes, in which case the opener will be suppressed. If
3056 // so, it is safe to load cross-site pages in a separate process, so we
3057 // should let the browser handle it.
3058 bool is_noreferrer_and_blank_target =
3059 // Frame should be top level and not yet navigated.
3060 frame->parent() == NULL &&
3061 frame->url().isEmpty() &&
3062 historyBackListCount() < 1 &&
3063 historyForwardListCount() < 1 &&
3064 // Links with rel=noreferrer will have no Referer field, and their
3065 // resulting frame will have its window.opener suppressed.
3066 // TODO(creis): should add a request.httpReferrer() method to help avoid
3067 // typos on the unusual spelling of Referer.
3068 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
3069 opener_suppressed_ &&
3070 frame->opener() == NULL &&
3071 // Links with target=_blank will have no name.
3072 frame->name().isNull() &&
3073 // Another frame (with a non-empty creator) should have initiated the
3074 // request, targeted at this frame.
3075 !creator_url_.is_empty() &&
3076 is_content_initiated &&
3077 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3078 type == WebKit::WebNavigationTypeOther;
3079
3080 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:173081 // Open the URL via the browser, not via WebKit.
3082 OpenURL(url, GURL(), default_policy);
3083 return WebKit::WebNavigationPolicyIgnore;
3084 }
3085
3086 return default_policy;
3087}
3088
[email protected]6069da8c2009-10-20 20:33:493089bool RenderView::canHandleRequest(
3090 WebFrame* frame, const WebURLRequest& request) {
3091 // We allow WebKit to think that everything can be handled even though
3092 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:343093 return true;
3094}
3095
[email protected]6069da8c2009-10-20 20:33:493096WebURLError RenderView::cannotHandleRequestError(
3097 WebFrame* frame, const WebURLRequest& request) {
3098 NOTREACHED(); // Since we said we can handle all requests.
3099 return WebURLError();
3100}
3101
3102WebURLError RenderView::cancelledError(
3103 WebFrame* frame, const WebURLRequest& request) {
3104 WebURLError error;
3105 error.domain = WebString::fromUTF8(net::kErrorDomain);
3106 error.reason = net::ERR_ABORTED;
3107 error.unreachableURL = request.url();
3108 return error;
[email protected]7b7a7dc2009-10-19 02:23:343109}
3110
3111void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:493112 WebFrame*, const WebURLError&) {
3113 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:343114}
3115
[email protected]90eeddb2010-05-06 21:06:433116void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
3117 const WebKit::WebFormElement& form) {
3118 // Some login forms have onSubmit handlers that put a hash of the password
3119 // into a hidden field and then clear the password. (Issue 28910.)
3120 // This method gets called before any of those handlers run, so save away
3121 // a copy of the password in case it gets lost.
3122 NavigationState* navigation_state =
3123 NavigationState::FromDataSource(frame->dataSource());
3124 navigation_state->set_password_form_data(
3125 PasswordFormDomManager::CreatePasswordForm(form));
3126}
3127
[email protected]979c28b2009-11-07 01:30:483128void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:173129 NavigationState* navigation_state =
3130 NavigationState::FromDataSource(frame->provisionalDataSource());
3131
3132 if (navigation_state->transition_type() == PageTransition::LINK)
3133 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
3134
3135 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:353136 WebSearchableFormData web_searchable_form_data(form);
3137 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
3138 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:213139 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:433140 PasswordForm* password_form_data =
3141 PasswordFormDomManager::CreatePasswordForm(form);
3142 navigation_state->set_password_form_data(password_form_data);
3143
3144 // If the password has been cleared, recover it from the form contents already
3145 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
3146 // opposed to the provisionalDataSource's, which is what we're storing into
3147 // now.)
3148 if (password_form_data && password_form_data->password_value.empty()) {
3149 NavigationState* old_navigation_state =
3150 NavigationState::FromDataSource(frame->dataSource());
3151 if (old_navigation_state) {
3152 PasswordForm* old_form_data = old_navigation_state->password_form_data();
3153 if (old_form_data && old_form_data->action == password_form_data->action)
3154 password_form_data->password_value = old_form_data->password_value;
3155 }
3156 }
[email protected]3d9689372009-09-10 04:29:173157
[email protected]b1438212010-04-03 00:30:593158 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:043159 if (FormManager::WebFormElementToFormData(
[email protected]5af80432010-11-01 01:25:223160 form,
3161 FormManager::REQUIRE_AUTOCOMPLETE,
[email protected]78192082011-01-29 05:43:443162 static_cast<FormManager::ExtractMask>(
3163 FormManager::EXTRACT_VALUE | FormManager::EXTRACT_OPTION_TEXT),
[email protected]5af80432010-11-01 01:25:223164 &form_data)) {
[email protected]19d6e1e82011-01-26 05:08:583165 Send(new AutoFillHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]5af80432010-11-01 01:25:223166 }
[email protected]3d9689372009-09-10 04:29:173167}
3168
3169void RenderView::willPerformClientRedirect(
3170 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3171 double fire_time) {
3172 // Ignore
3173}
3174
3175void RenderView::didCancelClientRedirect(WebFrame* frame) {
3176 // Ignore
3177}
3178
3179void RenderView::didCompleteClientRedirect(
3180 WebFrame* frame, const WebURL& from) {
3181 if (!frame->parent())
3182 completed_client_redirect_src_ = from;
3183}
3184
3185void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]bb461532010-11-26 21:50:233186 // If there are any app-related fetches in progress, they can be cancelled now
3187 // since we have navigated away from the page that created them.
3188 if (!frame->parent()) {
3189 app_icon_fetchers_.clear();
3190 app_definition_fetcher_.reset(NULL);
3191 }
3192
[email protected]3d9689372009-09-10 04:29:173193 // The rest of RenderView assumes that a WebDataSource will always have a
3194 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:483195 bool content_initiated = !pending_navigation_state_.get();
3196 NavigationState* state = content_initiated ?
3197 NavigationState::CreateContentInitiated() :
3198 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:513199
[email protected]8a3125a712010-08-09 18:58:513200 // NavigationState::referred_by_prefetcher_ is true if we are
3201 // navigating from a page that used prefetching using a link on that
3202 // page. We are early enough in the request process here that we
3203 // can still see the NavigationState of the previous page and set
3204 // this value appropriately.
3205 // TODO(gavinp): catch the important case of navigation in a new
3206 // renderer process.
3207 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303208 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523209 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513210 const GURL referrer(
3211 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3212 if (!referrer.is_empty() &&
3213 NavigationState::FromDataSource(
3214 old_frame->dataSource())->was_prefetcher()) {
3215 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
3216 WebDataSource* old_frame_ds = old_frame->dataSource();
3217 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
3218 state->set_was_referred_by_prefetcher(true);
3219 break;
3220 }
3221 }
3222 }
3223 }
3224 }
3225
[email protected]4c1b6f0b2010-02-07 16:38:183226 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523227 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513228 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183229 case WebURLRequest::UseProtocolCachePolicy: // normal load.
3230 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
3231 break;
3232 case WebURLRequest::ReloadIgnoringCacheData: // reload.
3233 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
3234 break;
3235 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
3236 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
3237 break;
3238 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
3239 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
3240 break;
3241 }
3242 }
[email protected]fa7b6b542009-11-03 05:02:303243
[email protected]5792d932011-01-18 20:33:293244 // If this datasource already has a UserScriptIdleScheduler, reuse that one.
3245 // This is for navigations within a page (didNavigateWithinPage). See
3246 // http://code.google.com/p/chromium/issues/detail?id=64093
3247 NavigationState* old_state = NavigationState::FromDataSource(ds);
3248 if (old_state && old_state->user_script_idle_scheduler()) {
3249 state->swap_user_script_idle_scheduler(old_state);
3250 } else {
3251 state->set_user_script_idle_scheduler(
3252 new UserScriptIdleScheduler(this, frame));
3253 }
[email protected]375e8bd2011-02-07 19:15:353254
3255 // If the RenderView was prerendering before, it is still prerendering.
3256 if (!frame->parent() && content_initiated) {
3257 WebDataSource* ds_old = webview()->mainFrame()->dataSource();
3258 if (ds_old) {
3259 NavigationState* navigation_state =
3260 NavigationState::FromDataSource(ds_old);
3261 if (navigation_state)
3262 state->set_is_prerendering(navigation_state->is_prerendering());
3263 }
3264 }
3265
[email protected]fa7b6b542009-11-03 05:02:303266 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:173267}
3268
3269void RenderView::didStartProvisionalLoad(WebFrame* frame) {
3270 WebDataSource* ds = frame->provisionalDataSource();
3271 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3272
[email protected]3d9689372009-09-10 04:29:173273 // Update the request time if WebKit has better knowledge of it.
3274 if (navigation_state->request_time().is_null()) {
3275 double event_time = ds->triggeringEventTime();
3276 if (event_time != 0.0)
3277 navigation_state->set_request_time(Time::FromDoubleT(event_time));
3278 }
3279
[email protected]05c8e502010-08-15 15:13:523280 // Start time is only set after request time.
3281 navigation_state->set_start_load_time(Time::Now());
3282
[email protected]3d9689372009-09-10 04:29:173283 bool is_top_most = !frame->parent();
3284 if (is_top_most) {
3285 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133286 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173287
3288 // Make sure redirect tracking state is clear for the new load.
3289 completed_client_redirect_src_ = GURL();
3290 } else if (frame->parent()->isLoading()) {
3291 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003292 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:173293 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
3294 }
3295
[email protected]28685da92011-02-07 21:49:173296 FOR_EACH_OBSERVER(
3297 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3298
[email protected]3d9689372009-09-10 04:29:173299 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:073300 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173301}
3302
3303void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
3304 if (frame->parent())
3305 return;
3306 // Received a redirect on the main frame.
3307 WebDataSource* data_source = frame->provisionalDataSource();
3308 if (!data_source) {
3309 // Should only be invoked when we have a data source.
3310 NOTREACHED();
3311 return;
3312 }
3313 std::vector<GURL> redirects;
3314 GetRedirectChain(data_source, &redirects);
3315 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:513316 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3317 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:173318 }
3319}
3320
[email protected]40bd6582009-12-04 23:49:513321void RenderView::didFailProvisionalLoad(WebFrame* frame,
3322 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173323 // Notify the browser that we failed a provisional load with an error.
3324 //
3325 // Note: It is important this notification occur before DidStopLoading so the
3326 // SSL manager can react to the provisional load failure before being
3327 // notified the load stopped.
3328 //
3329 WebDataSource* ds = frame->provisionalDataSource();
3330 DCHECK(ds);
3331
3332 const WebURLRequest& failed_request = ds->request();
3333
[email protected]28685da92011-02-07 21:49:173334 FOR_EACH_OBSERVER(
3335 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3336
[email protected]3d9689372009-09-10 04:29:173337 bool show_repost_interstitial =
3338 (error.reason == net::ERR_CACHE_MISS &&
3339 EqualsASCII(failed_request.httpMethod(), "POST"));
3340 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:073341 routing_id_, frame->identifier(), !frame->parent(), error.reason,
3342 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:173343
3344 // Don't display an error page if this is simply a cancelled load. Aside
3345 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3346 if (error.reason == net::ERR_ABORTED)
3347 return;
3348
3349 // Make sure we never show errors in view source mode.
3350 frame->enableViewSourceMode(false);
3351
3352 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3353
3354 // If this is a failed back/forward/reload navigation, then we need to do a
3355 // 'replace' load. This is necessary to avoid messing up session history.
3356 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3357 // as session history is concerned.
3358 //
3359 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3360 // the page id.
3361 //
3362 bool replace =
3363 navigation_state->pending_page_id() != -1 ||
3364 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
3365
3366 // If we failed on a browser initiated request, then make sure that our error
3367 // page load is regarded as the same browser initiated request.
3368 if (!navigation_state->is_content_initiated()) {
3369 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
3370 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:003371 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:173372 navigation_state->transition_type(),
3373 navigation_state->request_time()));
3374 }
3375
3376 // Provide the user with a more helpful error page?
3377 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3378 return;
3379
3380 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083381 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173382}
3383
3384void RenderView::didReceiveDocumentData(
3385 WebFrame* frame, const char* data, size_t data_len,
3386 bool& prevent_default) {
3387 NavigationState* navigation_state =
3388 NavigationState::FromDataSource(frame->dataSource());
3389 if (!navigation_state->postpone_loading_data())
3390 return;
3391
3392 // We're going to call commitDocumentData ourselves...
3393 prevent_default = true;
3394
[email protected]3f853a52010-09-13 19:15:083395 // Continue buffering the response data for the original error page. If it
3396 // grows too large, then we'll just let it through. For any error other than
3397 // a 404, "too large" means any data at all.
[email protected]3d9689372009-09-10 04:29:173398 navigation_state->append_postponed_data(data, data_len);
[email protected]3f853a52010-09-13 19:15:083399 if (navigation_state->postponed_data().size() >= 512 ||
3400 navigation_state->http_status_code() != 404) {
[email protected]3d9689372009-09-10 04:29:173401 navigation_state->set_postpone_loading_data(false);
3402 frame->commitDocumentData(navigation_state->postponed_data().data(),
3403 navigation_state->postponed_data().size());
3404 navigation_state->clear_postponed_data();
3405 }
3406}
3407
[email protected]40bd6582009-12-04 23:49:513408void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3409 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:173410 NavigationState* navigation_state =
3411 NavigationState::FromDataSource(frame->dataSource());
3412
3413 navigation_state->set_commit_load_time(Time::Now());
3414 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203415 // When we perform a new navigation, we need to update the last committed
3416 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173417 UpdateSessionHistory(frame);
3418
3419 // We bump our Page ID to correspond with the new session history entry.
3420 page_id_ = next_page_id_++;
3421
[email protected]3cc72b12010-03-18 23:03:003422 // Advance our offset in session history, applying the length limit. There
3423 // is now no forward history.
3424 history_list_offset_++;
3425 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3426 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3427 history_list_length_ = history_list_offset_ + 1;
3428
[email protected]f9f4841b2010-03-20 05:41:423429 MessageLoop::current()->PostDelayedTask(
3430 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303431 page_info_method_factory_.NewRunnableMethod(
3432 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173433 kDelayForForcedCaptureMs);
3434 } else {
3435 // Inspect the navigation_state on this frame to see if the navigation
3436 // corresponds to a session history navigation... Note: |frame| may or
3437 // may not be the toplevel frame, but for the case of capturing session
3438 // history, the first committed frame suffices. We keep track of whether
3439 // we've seen this commit before so that only capture session history once
3440 // per navigation.
3441 //
3442 // Note that we need to check if the page ID changed. In the case of a
3443 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3444 // previous URL and the current page ID, which would be wrong.
3445 if (navigation_state->pending_page_id() != -1 &&
3446 navigation_state->pending_page_id() != page_id_ &&
3447 !navigation_state->request_committed()) {
3448 // This is a successful session history navigation!
3449 UpdateSessionHistory(frame);
3450 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003451
3452 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173453 }
3454 }
3455
[email protected]28685da92011-02-07 21:49:173456 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3457 DidCommitProvisionalLoad(frame, is_new_navigation));
3458
[email protected]3d9689372009-09-10 04:29:173459 // Remember that we've already processed this request, so we don't update
3460 // the session history again. We do this regardless of whether this is
3461 // a session history navigation, because if we attempted a session history
3462 // navigation without valid HistoryItem state, WebCore will think it is a
3463 // new navigation.
3464 navigation_state->set_request_committed(true);
3465
3466 UpdateURL(frame);
3467
3468 // If this committed load was initiated by a client redirect, we're
3469 // at the last stop now, so clear it.
3470 completed_client_redirect_src_ = GURL();
3471
3472 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273473 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173474}
3475
3476void RenderView::didClearWindowObject(WebFrame* frame) {
3477 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3478 BindDOMAutomationController(frame);
[email protected]0d7ae862010-10-01 13:52:453479 GURL frame_url = frame->url();
3480 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:253481 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]731ae512010-10-15 18:20:173482 frame_url.SchemeIs(chrome::kGearsScheme) ||
[email protected]bfa83eb82010-10-06 08:41:253483 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273484 GetWebUIBindings()->set_message_sender(this);
3485 GetWebUIBindings()->set_routing_id(routing_id_);
3486 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173487 }
3488 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463489 GetExternalHostBindings()->set_message_sender(this);
3490 GetExternalHostBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253491 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
[email protected]3d9689372009-09-10 04:29:173492 }
3493}
3494
3495void RenderView::didCreateDocumentElement(WebFrame* frame) {
3496 if (RenderThread::current()) { // Will be NULL during unit tests.
3497 RenderThread::current()->user_script_slave()->InjectScripts(
3498 frame, UserScript::DOCUMENT_START);
3499 }
3500
3501 // Notify the browser about non-blank documents loading in the top frame.
3502 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253503 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273504 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173505 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3506 }
3507}
3508
3509void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3510 UpdateTitle(frame, title);
3511
3512 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273513 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173514}
3515
[email protected]5019ef12010-04-27 17:26:583516void RenderView::didChangeIcons(WebFrame* frame) {
3517 if (!frame->parent()) {
3518 Send(new ViewHostMsg_UpdateFavIconURL(
3519 routing_id_,
3520 page_id_,
3521 frame->favIconURL()));
3522 }
3523}
3524
[email protected]3d9689372009-09-10 04:29:173525void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3526 WebDataSource* ds = frame->dataSource();
3527 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3528 DCHECK(navigation_state);
3529 navigation_state->set_finish_document_load_time(Time::Now());
3530
[email protected]622474d2010-11-04 09:21:083531 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173532
[email protected]28685da92011-02-07 21:49:173533 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3534 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173535
3536 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273537 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173538
3539 if (RenderThread::current()) { // Will be NULL during unit tests.
3540 RenderThread::current()->user_script_slave()->InjectScripts(
3541 frame, UserScript::DOCUMENT_END);
3542 }
[email protected]fa7b6b542009-11-03 05:02:303543
[email protected]41f16632010-10-20 01:21:323544 // InjectScripts() can end up creating a new NavigationState if it triggers a
3545 // fragment navigation, so we need to re-fetch it here.
3546 navigation_state = NavigationState::FromDataSource(ds);
[email protected]fa7b6b542009-11-03 05:02:303547 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3548}
3549
3550void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3551 if (RenderThread::current()) { // Will be NULL during unit tests.
3552 RenderThread::current()->user_script_slave()->InjectScripts(
3553 frame, UserScript::DOCUMENT_IDLE);
3554 }
3555
3556 WebFrame* main_frame = webview()->mainFrame();
3557 if (frame == main_frame) {
3558 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203559 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303560 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203561 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303562 pending_code_execution_queue_.pop();
3563 }
3564 }
[email protected]3d9689372009-09-10 04:29:173565}
3566
3567void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083568 if (webview()->mainFrame() == frame) {
3569 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3570 page_id_));
3571 }
[email protected]3d9689372009-09-10 04:29:173572}
3573
3574void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:173575 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:173576}
3577
3578void RenderView::didFinishLoad(WebFrame* frame) {
3579 WebDataSource* ds = frame->dataSource();
3580 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3581 DCHECK(navigation_state);
3582 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303583 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413584
[email protected]676126f72011-01-15 00:03:513585 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173586
3587 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173588}
3589
[email protected]ccbe04e2010-03-17 17:58:433590void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173591 WebFrame* frame, bool is_new_navigation) {
3592 // If this was a reference fragment navigation that we initiated, then we
3593 // could end up having a non-null pending navigation state. We just need to
3594 // update the ExtraData on the datasource so that others who read the
3595 // ExtraData will get the new NavigationState. Similarly, if we did not
3596 // initiate this navigation, then we need to take care to reset any pre-
3597 // existing navigation state to a content-initiated navigation state.
3598 // DidCreateDataSource conveniently takes care of this for us.
3599 didCreateDataSource(frame, frame->dataSource());
3600
[email protected]af15bed2010-08-25 21:12:093601 NavigationState* new_state =
3602 NavigationState::FromDataSource(frame->dataSource());
3603 new_state->set_was_within_same_page(true);
3604
[email protected]3d9689372009-09-10 04:29:173605 didCommitProvisionalLoad(frame, is_new_navigation);
3606
[email protected]26aa0482009-09-30 16:55:273607 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173608}
3609
[email protected]476b6f82009-09-10 21:00:593610void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313611 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593612}
3613
[email protected]3d9689372009-09-10 04:29:173614void RenderView::assignIdentifierToRequest(
3615 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3616 // Ignore
3617}
3618
3619void RenderView::willSendRequest(
3620 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3621 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303622 WebFrame* top_frame = frame->top();
3623 if (!top_frame)
3624 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513625 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3626 WebDataSource* top_data_source = top_frame->dataSource();
3627 WebDataSource* data_source =
3628 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223629
3630 // If the request is for an extension resource, check whether it should be
3631 // allowed. If not allowed, we reset the URL to something invalid to prevent
3632 // the request and cause an error.
3633 GURL request_url(request.url());
3634 if (request_url.SchemeIs(chrome::kExtensionScheme) &&
3635 !ExtensionResourceRequestPolicy::CanRequestResource(
3636 request_url,
3637 GURL(frame->url()),
3638 render_thread_->GetExtensions())) {
3639 request.setURL(WebURL(GURL("chrome-extension://invalid/")));
3640 }
3641
[email protected]5e369672009-11-03 23:48:303642 if (data_source) {
3643 NavigationState* state = NavigationState::FromDataSource(data_source);
3644 if (state && state->is_cache_policy_override_set())
3645 request.setCachePolicy(state->cache_policy_override());
3646 }
[email protected]8a3125a712010-08-09 18:58:513647
3648 if (top_data_source) {
3649 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3650 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3651 state->set_was_prefetcher(true);
3652 }
3653
[email protected]3d9689372009-09-10 04:29:173654 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133655 request.setHasUserGesture(frame->isProcessingUserGesture());
3656
[email protected]c5bbc2452010-03-08 08:33:503657 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133658 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493659
[email protected]85cc78c2010-05-04 18:30:093660 // Temporary metrics, see site_isolation_metrics.h
3661 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173662}
3663
3664void RenderView::didReceiveResponse(
3665 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493666
[email protected]85cc78c2010-05-04 18:30:093667 // Temporary metrics, see site_isolation_metrics.h
3668 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3669 identifier,
3670 response);
[email protected]fa0a3432010-03-30 16:53:493671
[email protected]3d9689372009-09-10 04:29:173672 // Only do this for responses that correspond to a provisional data source
3673 // of the top-most frame. If we have a provisional data source, then we
3674 // can't have any sub-resources yet, so we know that this response must
3675 // correspond to a frame load.
3676 if (!frame->provisionalDataSource() || frame->parent())
3677 return;
3678
3679 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083680 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173681 if (frame->isViewSourceModeEnabled())
3682 return;
3683
[email protected]65041fa2010-05-21 06:56:533684 NavigationState* navigation_state =
3685 NavigationState::FromDataSource(frame->provisionalDataSource());
3686 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083687 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533688
[email protected]972ebdff2010-06-10 22:59:073689 // Record page load flags.
3690 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3691 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573692 navigation_state->set_was_alternate_protocol_available(
3693 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073694 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083695 navigation_state->set_http_status_code(http_status_code);
[email protected]65041fa2010-05-21 06:56:533696
[email protected]f48013be2010-01-14 22:07:453697 // Consider loading an alternate error page for 404 responses.
[email protected]3f853a52010-09-13 19:15:083698 if (http_status_code == 404) {
3699 // Can we even load an alternate error page for this URL?
3700 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3701 return;
3702 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3703 http_status_code)) {
3704 // If no corresponding error strings for a particular status code, just
3705 // render any received data, regardless of whether or not the status code
3706 // indicates an error.
[email protected]f48013be2010-01-14 22:07:453707 return;
[email protected]3f853a52010-09-13 19:15:083708 }
[email protected]3d9689372009-09-10 04:29:173709
[email protected]3d9689372009-09-10 04:29:173710 navigation_state->set_postpone_loading_data(true);
3711 navigation_state->clear_postponed_data();
3712}
3713
3714void RenderView::didFinishResourceLoad(
3715 WebFrame* frame, unsigned identifier) {
3716 NavigationState* navigation_state =
3717 NavigationState::FromDataSource(frame->dataSource());
3718 if (!navigation_state->postpone_loading_data())
3719 return;
3720
[email protected]3f853a52010-09-13 19:15:083721 // The server returned an error and the content was < 512 bytes (which we
[email protected]3d9689372009-09-10 04:29:173722 // suppressed). Go ahead and fetch the alternate page content.
[email protected]3f853a52010-09-13 19:15:083723 int http_status_code = navigation_state->http_status_code();
3724 if (http_status_code == 404) {
3725 // On 404s, try a remote search page as a fallback.
3726 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173727
[email protected]3f853a52010-09-13 19:15:083728 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3729 DCHECK(error_page_url.is_valid());
[email protected]3d9689372009-09-10 04:29:173730
[email protected]3f853a52010-09-13 19:15:083731 WebURLError original_error;
3732 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173733
[email protected]3f853a52010-09-13 19:15:083734 navigation_state->set_alt_error_page_fetcher(
3735 new AltErrorPageResourceFetcher(
3736 error_page_url, frame, original_error,
3737 NewCallback(this, &RenderView::AltErrorPageFinished)));
3738 } else {
3739 // On other errors, use an internal error page.
3740 WebURLError error;
3741 error.unreachableURL = frame->url();
3742 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3743 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173744
[email protected]3f853a52010-09-13 19:15:083745 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3746 std::string(), true);
3747 }
[email protected]3d9689372009-09-10 04:29:173748}
3749
3750void RenderView::didFailResourceLoad(
3751 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3752 // Ignore
3753}
3754
3755void RenderView::didLoadResourceFromMemoryCache(
3756 WebFrame* frame, const WebURLRequest& request,
3757 const WebURLResponse& response) {
3758 // Let the browser know we loaded a resource from the memory cache. This
3759 // message is needed to display the correct SSL indicators.
3760 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3761 routing_id_,
3762 request.url(),
[email protected]91733b62009-09-18 06:21:093763 frame->securityOrigin().toString().utf8(),
3764 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173765 response.securityInfo()));
3766}
3767
[email protected]6069da8c2009-10-20 20:33:493768void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293769 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3770}
3771
[email protected]92771112011-01-20 00:13:023772void RenderView::didRunInsecureContent(
3773 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293774 Send(new ViewHostMsg_DidRunInsecureContent(
3775 routing_id_,
[email protected]92771112011-01-20 00:13:023776 origin.toString().utf8(),
3777 target));
[email protected]e3d60e5d2009-09-25 21:08:293778}
3779
[email protected]7ea093ba2009-11-03 05:54:593780bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403781 if (enabled_per_settings &&
3782 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3783 return true;
[email protected]7ea093ba2009-11-03 05:54:593784
[email protected]12bc8472010-04-15 07:29:403785 if (IsWhitelistedForContentSettings(frame))
3786 return true;
[email protected]7ea093ba2009-11-03 05:54:593787
3788 return false; // Other protocols fall through here.
3789}
3790
[email protected]0a1a45432010-03-31 08:09:453791bool RenderView::allowDatabase(
3792 WebFrame* frame, const WebString& name, const WebString& display_name,
3793 unsigned long estimated_size) {
3794 WebSecurityOrigin origin = frame->securityOrigin();
3795 if (origin.isEmpty())
3796 return false; // Uninitialized document?
3797
3798 bool result;
[email protected]26a9acf2010-12-13 19:35:053799 if (!Send(new DatabaseHostMsg_Allow(routing_id_,
[email protected]0a1a45432010-03-31 08:09:453800 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3801 return false;
[email protected]9fb83e82010-07-02 18:24:553802 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3803 GURL(origin.toString().utf8()),
3804 name,
3805 display_name,
3806 estimated_size,
3807 !result));
[email protected]0a1a45432010-03-31 08:09:453808 return result;
3809}
[email protected]8934a3b2010-02-25 00:34:003810void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283811 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003812}
3813
[email protected]c21f1d52010-03-04 03:19:433814void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283815 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433816}
3817
[email protected]3d9689372009-09-10 04:29:173818void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3819 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3820}
3821
[email protected]0c882b282009-10-07 17:01:283822void RenderView::didCreateScriptContext(WebFrame* frame) {
3823 EventBindings::HandleContextCreated(frame, false);
3824}
3825
3826void RenderView::didDestroyScriptContext(WebFrame* frame) {
3827 EventBindings::HandleContextDestroyed(frame);
3828}
3829
3830void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3831 EventBindings::HandleContextCreated(frame, true);
3832}
3833
[email protected]af7eb3fb2010-09-23 21:31:063834bool RenderView::allowScriptExtension(WebFrame* frame,
3835 const WebString& extension_name,
3836 int extension_group) {
3837 // NULL in unit tests.
3838 if (!RenderThread::current())
3839 return true;
3840
3841 // Note: we prefer the provisional URL here instead of the document URL
3842 // because we might be currently loading an URL into a blank page.
3843 // See http://code.google.com/p/chromium/issues/detail?id=10924
3844 WebDataSource* ds = frame->provisionalDataSource();
3845 if (!ds)
3846 ds = frame->dataSource();
3847 return RenderThread::current()->AllowScriptExtension(
3848 extension_name.utf8(), ds->request().url(), extension_group);
3849}
3850
[email protected]fc86daa2010-03-30 23:52:533851void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3852 WebFrame* target,
3853 bool cross_origin,
3854 const WebString& property_name,
3855 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103856 // TODO(johnnyg): track the individual properties and repeat event_ids.
[email protected]a5a65ac2010-11-05 18:14:363857 page_load_histograms_.IncrementCrossFramePropertyAccess(cross_origin);
[email protected]ab9eabac2010-03-16 16:54:103858}
3859
[email protected]3d9689372009-09-10 04:29:173860void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143861 CheckPreferredSize();
3862}
3863
3864void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173865 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253866 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173867 // message.
[email protected]705243f2010-05-05 19:58:073868 if (!send_preferred_size_changes_ || !webview())
3869 return;
[email protected]dfca5acf2010-03-22 03:28:433870
[email protected]705243f2010-05-05 19:58:073871 // WebCore likes to tell us things have changed even when they haven't, so
3872 // cache the width and height and only send the IPC message when we're sure
3873 // they're different.
3874 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3875 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533876
3877 // In the presence of zoom, these sizes are still reported as if unzoomed,
3878 // so we need to adjust.
3879 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3880 size.set_width(static_cast<int>(size.width() * zoom_factor));
3881 size.set_height(static_cast<int>(size.height() * zoom_factor));
3882
[email protected]705243f2010-05-05 19:58:073883 if (size == preferred_size_)
3884 return;
[email protected]c27324b2009-11-19 22:44:293885
[email protected]705243f2010-05-05 19:58:073886 preferred_size_ = size;
3887 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3888 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173889}
3890
[email protected]143dcd592009-11-06 21:33:493891void RenderView::didChangeScrollOffset(WebFrame* frame) {
3892 StartNavStateSyncTimerIfNecessary();
3893}
3894
[email protected]8922e1f2009-10-03 05:01:263895void RenderView::reportFindInPageMatchCount(int request_id, int count,
3896 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113897 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3898 if (!count)
3899 active_match_ordinal = 0;
3900
3901 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3902 routing_id_,
3903 request_id,
3904 count,
3905 gfx::Rect(),
3906 active_match_ordinal,
3907 final_update);
3908
[email protected]8922e1f2009-10-03 05:01:263909 // If we have a message that has been queued up, then we should just replace
3910 // it. The ACK from the browser will make sure it gets sent when the browser
3911 // wants it.
3912 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263913 queued_find_reply_message_.reset(msg);
3914 } else {
3915 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113916 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263917 }
3918}
3919
3920void RenderView::reportFindInPageSelection(int request_id,
3921 int active_match_ordinal,
3922 const WebRect& selection_rect) {
3923 // Send the search result over to the browser process.
3924 Send(new ViewHostMsg_Find_Reply(routing_id_,
3925 request_id,
3926 -1,
3927 selection_rect,
3928 active_match_ordinal,
3929 false));
3930}
3931
[email protected]2b06a992010-08-21 05:48:223932void RenderView::openFileSystem(
3933 WebFrame* frame,
3934 WebFileSystem::Type type,
3935 long long size,
[email protected]d275d7a2010-11-03 01:34:493936 bool create,
[email protected]2b06a992010-08-21 05:48:223937 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083938 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223939
3940 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:083941 if (origin.isEmpty()) {
3942 // Uninitialized document?
3943 callbacks->didFail(WebKit::WebFileErrorAbort);
3944 return;
3945 }
[email protected]2b06a992010-08-21 05:48:223946
[email protected]c5a272d2010-09-27 18:37:083947 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3948 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493949 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223950}
3951
[email protected]79dbc662009-09-04 05:42:513952// webkit_glue::WebPluginPageDelegate -----------------------------------------
3953
[email protected]191eb3f72010-12-21 06:27:503954webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533955 const FilePath& file_path,
3956 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593957 if (!PluginChannelHost::IsListening())
3958 return NULL;
3959
[email protected]d2139662009-12-10 03:21:143960 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283961 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143962 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163963 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533964 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143965 if (CommandLine::ForCurrentProcess()->
3966 HasSwitch(switches::kInternalPepper)) {
3967 in_process_plugin = true;
3968 use_pepper_host = true;
3969 } else {
3970 // In process Pepper plugins must be explicitly enabled.
3971 return NULL;
3972 }
[email protected]4e0616e2010-05-28 14:55:533973 } else {
3974 FilePath internal_pdf_path;
3975 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3976 if (file_path == internal_pdf_path) {
3977 in_process_plugin = true;
3978 use_pepper_host = true;
3979 }
[email protected]26e8d5e2009-10-13 02:47:163980 }
[email protected]4e0616e2010-05-28 14:55:533981
[email protected]d032f492009-09-29 00:33:463982 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143983 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283984 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533985 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333986 if (!pepper_plugin)
3987 return NULL;
3988
[email protected]53900d52010-06-16 04:25:013989 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283990 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143991 } else {
[email protected]6876dff2010-01-15 19:38:093992#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]191eb3f72010-12-21 06:27:503993 return webkit::npapi::WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533994 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093995#else
[email protected]596b2c42010-01-14 20:40:433996 NOTIMPLEMENTED();
3997 return NULL;
[email protected]7b6616f2010-01-14 18:07:553998#endif
[email protected]6876dff2010-01-15 19:38:093999 }
[email protected]f103ab72009-09-02 17:10:594000 }
4001
[email protected]4e0616e2010-05-28 14:55:534002 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:594003}
4004
4005void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034006#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:594007 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
4008 routing_id(), window));
4009#endif
4010}
4011
4012void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034013#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:594014 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
4015 routing_id(), window));
4016#endif
4017 CleanupWindowInPluginMoves(window);
4018}
4019
[email protected]191eb3f72010-12-21 06:27:504020void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594021 SchedulePluginMove(move);
4022}
4023
4024void RenderView::DidStartLoadingForPlugin() {
4025 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524026 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594027}
4028
4029void RenderView::DidStopLoadingForPlugin() {
4030 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524031 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594032}
4033
4034void RenderView::ShowModalHTMLDialogForPlugin(
4035 const GURL& url,
4036 const gfx::Size& size,
4037 const std::string& json_arguments,
4038 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:214039 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:594040 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:214041 json_retval));
[email protected]f103ab72009-09-02 17:10:594042}
4043
[email protected]b921cfd22010-02-25 16:57:514044WebCookieJar* RenderView::GetCookieJar() {
4045 return &cookie_jar_;
4046}
4047
initial.commit09911bf2008-07-26 23:55:294048void RenderView::SyncNavigationState() {
4049 if (!webview())
4050 return;
4051
[email protected]26aa0482009-09-30 16:55:274052 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:174053 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:294054 return;
[email protected]ca948a22009-06-25 19:36:174055
4056 Send(new ViewHostMsg_UpdateState(
4057 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:294058}
4059
[email protected]b0950a72009-09-29 23:16:174060bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
4061 // Make sure webview was not shut down.
4062 if (!webview())
4063 return false;
4064 // Create an image resource fetcher and assign it with a call back object.
[email protected]bb461532010-11-26 21:50:234065 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
4066 new ImageResourceFetcher(
4067 image_url, webview()->mainFrame(), id, image_size,
4068 NewCallback(this, &RenderView::DidDownloadImage))));
[email protected]b0950a72009-09-29 23:16:174069 return true;
4070}
4071
4072void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:294073 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:174074 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:474075 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
4076 fetcher->id(),
4077 fetcher->image_url(),
4078 image.isNull(),
4079 image));
[email protected]bb461532010-11-26 21:50:234080
4081 // Remove the image fetcher from our pending list. We're in the callback from
4082 // ImageResourceFetcher, best to delay deletion.
4083 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin();
4084 iter != image_fetchers_.end(); ++iter) {
4085 if (iter->get() == fetcher) {
4086 iter->release();
4087 image_fetchers_.erase(iter);
4088 break;
4089 }
4090 }
[email protected]b0950a72009-09-29 23:16:174091 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:294092}
4093
[email protected]bf5c2ff392009-07-08 16:24:334094void RenderView::OnDownloadFavIcon(int id,
4095 const GURL& image_url,
4096 int image_size) {
[email protected]f11ca0732009-04-11 00:09:344097 bool data_image_failed = false;
4098 if (image_url.SchemeIs("data")) {
4099 SkBitmap data_image = ImageFromDataUrl(image_url);
4100 data_image_failed = data_image.empty();
4101 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:334102 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
4103 data_image));
[email protected]f11ca0732009-04-11 00:09:344104 }
4105 }
4106
[email protected]bf5c2ff392009-07-08 16:24:334107 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:174108 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:334109 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
4110 SkBitmap()));
4111 }
initial.commit09911bf2008-07-26 23:55:294112}
4113
[email protected]f11ca0732009-04-11 00:09:344114SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
4115 std::string mime_type, char_set, data;
4116 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
4117 // Decode the favicon using WebKit's image decoder.
4118 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
4119 const unsigned char* src_data =
4120 reinterpret_cast<const unsigned char*>(&data[0]);
4121
4122 return decoder.Decode(src_data, data.size());
4123 }
4124 return SkBitmap();
4125}
4126
initial.commit09911bf2008-07-26 23:55:294127void RenderView::OnGetApplicationInfo(int page_id) {
[email protected]38789d82010-11-17 06:03:444128 WebApplicationInfo app_info;
4129 if (page_id == page_id_) {
4130 string16 error;
4131 web_apps::ParseWebAppFromWebDocument(webview()->mainFrame(), &app_info,
4132 &error);
4133 }
initial.commit09911bf2008-07-26 23:55:294134
4135 // Prune out any data URLs in the set of icons. The browser process expects
4136 // any icon with a data URL to have originated from a favicon. We don't want
4137 // to decode arbitrary data URLs in the browser process. See
4138 // http://b/issue?id=1162972
4139 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:594140 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:294141 app_info.icons.erase(app_info.icons.begin() + i);
4142 --i;
4143 }
4144 }
4145
4146 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
4147}
4148
[email protected]7ccddb8c2009-08-04 17:36:554149GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:294150 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554151 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294152 // If the URL that failed was secure, then the embedding web page was not
4153 // expecting a network attacker to be able to manipulate its contents. As
4154 // we fetch alternate error pages over HTTP, we would be allowing a network
4155 // attacker to manipulate the contents of the response if we tried to use
4156 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154157 return GURL();
initial.commit09911bf2008-07-26 23:55:294158 }
4159
4160 // Grab the base URL from the browser process.
4161 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154162 return GURL();
initial.commit09911bf2008-07-26 23:55:294163
4164 // Strip query params from the failed URL.
4165 GURL::Replacements remove_params;
4166 remove_params.ClearUsername();
4167 remove_params.ClearPassword();
4168 remove_params.ClearQuery();
4169 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554170 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504171 std::string spec_to_send = url_to_send.spec();
4172 // Notify link doctor of the url truncation by sending of "?" at the end.
4173 if (failed_url.has_query())
4174 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294175
4176 // Construct the query params to send to link doctor.
4177 std::string params(alternate_error_page_url_.query());
4178 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:504179 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294180 params.append("&sourceid=chrome");
4181 params.append("&error=");
4182 switch (error_type) {
4183 case DNS_ERROR:
4184 params.append("dnserror");
4185 break;
4186
4187 case HTTP_404:
4188 params.append("http404");
4189 break;
4190
[email protected]5df266ac2008-10-15 19:50:134191 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334192 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134193 break;
4194
initial.commit09911bf2008-07-26 23:55:294195 default:
4196 NOTREACHED() << "unknown ErrorPageType";
4197 }
4198
4199 // OK, build the final url to return.
4200 GURL::Replacements link_doctor_params;
4201 link_doctor_params.SetQueryStr(params);
4202 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4203 return url;
4204}
4205
[email protected]c50008512011-02-03 01:17:274206WebUIBindings* RenderView::GetWebUIBindings() {
4207 if (!web_ui_bindings_.get()) {
4208 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:464209 }
[email protected]c50008512011-02-03 01:17:274210 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464211}
4212
4213ExternalHostBindings* RenderView::GetExternalHostBindings() {
4214 if (!external_host_bindings_.get()) {
4215 external_host_bindings_.reset(new ExternalHostBindings());
4216 }
4217 return external_host_bindings_.get();
4218}
4219
[email protected]0fdbf8c2010-07-08 20:33:014220WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
4221 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494222}
4223
[email protected]6069da8c2009-10-20 20:33:494224void RenderView::OnFind(int request_id, const string16& search_text,
4225 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274226 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494227
4228 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494229 if (options.findNext) {
4230 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014231 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494232 } else {
[email protected]afdbd142010-07-10 08:01:234233 if (GetWebPluginFromPluginDocument()->startFind(
4234 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494235 } else {
[email protected]e7c58a32010-08-13 19:47:114236 // Send "no results".
4237 Send(new ViewHostMsg_Find_Reply(routing_id_,
4238 request_id,
4239 0,
4240 gfx::Rect(),
4241 0,
4242 true));
[email protected]24a7f3c2010-03-25 08:26:494243 }
4244 }
4245 return;
4246 }
4247
[email protected]b4bb2502009-10-01 22:35:274248 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274249 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294250 WebFrame* search_frame = focused_frame; // start searching focused frame.
4251
4252 bool multi_frame = (frame_after_main != main_frame);
4253
4254 // If we have multiple frames, we don't want to wrap the search within the
4255 // frame, so we check here if we only have main_frame in the chain.
4256 bool wrap_within_frame = !multi_frame;
4257
[email protected]b3f2b912009-04-09 16:18:524258 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294259 bool result = false;
4260
[email protected]7830da3e2009-11-06 16:27:264261 // If something is selected when we start searching it means we cannot just
4262 // increment the current match ordinal; we need to re-generate it.
4263 WebRange current_selection = focused_frame->selectionRange();
4264
initial.commit09911bf2008-07-26 23:55:294265 do {
[email protected]dd7daa82009-08-10 05:46:454266 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594267 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294268
4269 if (!result) {
4270 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224271 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294272
4273 // Find the next frame, but skip the invisible ones.
4274 do {
4275 // What is the next frame to search? (we might be going backwards). Note
4276 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594277 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274278 search_frame->traverseNext(true) :
4279 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454280 } while (!search_frame->hasVisibleContent() &&
4281 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294282
[email protected]884db412008-11-24 23:46:504283 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224284 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294285
4286 // If we have multiple frames and we have wrapped back around to the
4287 // focused frame, we need to search it once more allowing wrap within
4288 // the frame, otherwise it will report 'no match' if the focused frame has
4289 // reported matches, but no frames after the focused_frame contain a
4290 // match for the search word(s).
4291 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454292 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594293 request_id, search_text, options, true, // Force wrapping.
4294 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294295 }
4296 }
4297
[email protected]26aa0482009-09-30 16:55:274298 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294299 } while (!result && search_frame != focused_frame);
4300
[email protected]7830da3e2009-11-06 16:27:264301 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294302 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454303 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294304 } else {
4305 // If nothing is found, set result to "0 of 0", otherwise, set it to
4306 // "-1 of 1" to indicate that we found at least one item, but we don't know
4307 // yet what is active.
4308 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4309 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294310
[email protected]4f3dc372009-02-24 00:10:294311 // If we find no matches then this will be our last status update.
4312 // Otherwise the scoping effort will send more results.
4313 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294314
[email protected]4f3dc372009-02-24 00:10:294315 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404316 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594317 request_id,
[email protected]4f3dc372009-02-24 00:10:294318 match_count,
4319 selection_rect,
4320 ordinal,
4321 final_status_update));
initial.commit09911bf2008-07-26 23:55:294322
initial.commit09911bf2008-07-26 23:55:294323 // Scoping effort begins, starting with the mainframe.
4324 search_frame = main_frame;
4325
[email protected]dd7daa82009-08-10 05:46:454326 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294327
4328 do {
4329 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454330 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294331
4332 // We don't start another scoping effort unless at least one match has
4333 // been found.
4334 if (result) {
4335 // Start new scoping request. If the scoping function determines that it
4336 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454337 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594338 search_text,
4339 options,
initial.commit09911bf2008-07-26 23:55:294340 true); // reset the tickmarks
4341 }
4342
4343 // Iterate to the next frame. The frame will not necessarily scope, for
4344 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274345 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294346 } while (search_frame != main_frame);
4347 }
4348}
4349
[email protected]24a7f3c2010-03-25 08:26:494350void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
4351 WebView* view = webview();
4352 if (!view)
4353 return;
4354
4355 WebDocument doc = view->mainFrame()->document();
4356 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014357 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494358 return;
4359 }
4360
4361 bool clear_selection =
4362 params.action == ViewMsg_StopFinding_Params::kClearSelection;
4363 if (clear_selection)
4364 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4365
4366 WebFrame* frame = view->mainFrame();
4367 while (frame) {
4368 frame->stopFinding(clear_selection);
4369 frame = frame->traverseNext(false);
4370 }
4371
4372 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
4373 WebFrame* focused_frame = view->focusedFrame();
4374 if (focused_frame) {
4375 WebDocument doc = focused_frame->document();
4376 if (!doc.isNull()) {
4377 WebNode node = doc.focusedNode();
4378 if (!node.isNull())
4379 node.simulateClick();
4380 }
4381 }
4382 }
4383}
4384
4385void RenderView::OnFindReplyAck() {
4386 // Check if there is any queued up request waiting to be sent.
4387 if (queued_find_reply_message_.get()) {
4388 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424389 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494390 }
4391}
4392
[email protected]8934a3b2010-02-25 00:34:004393bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:354394 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:004395 return current_content_settings_.settings[settings_type] !=
4396 CONTENT_SETTING_BLOCK;
4397}
4398
[email protected]55126132010-08-19 14:53:284399void RenderView::DidBlockContentType(ContentSettingsType settings_type,
4400 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:004401 if (!content_blocked_[settings_type]) {
4402 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:284403 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
4404 resource_identifier));
[email protected]0de80162010-02-03 04:52:354405 }
[email protected]0de80162010-02-03 04:52:354406}
4407
[email protected]71b0d5d2010-02-15 05:43:074408void RenderView::ClearBlockedContentSettings() {
4409 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4410 content_blocked_[i] = false;
4411}
4412
[email protected]0bd753682010-12-16 18:15:524413WebPlugin* RenderView::CreatePepperPlugin(
4414 WebFrame* frame,
4415 const WebPluginParams& params,
4416 const FilePath& path,
4417 webkit::ppapi::PluginModule* pepper_module) {
4418 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:254419 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:094420}
[email protected]00152e92010-07-19 11:47:404421
[email protected]191eb3f72010-12-21 06:27:504422WebPlugin* RenderView::CreateNPAPIPlugin(
4423 WebFrame* frame,
4424 const WebPluginParams& params,
4425 const FilePath& path,
4426 const std::string& mime_type) {
4427 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:084428 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404429}
4430
[email protected]3c2826852010-12-16 19:09:144431WebPlugin* RenderView::CreatePluginPlaceholder(
[email protected]57b66d02010-09-30 11:24:514432 WebFrame* frame,
4433 const WebPluginParams& params,
[email protected]191eb3f72010-12-21 06:27:504434 const webkit::npapi::PluginGroup& group,
[email protected]3c2826852010-12-16 19:09:144435 int resource_id,
[email protected]90dba072011-01-20 20:10:204436 int message_id,
4437 bool is_blocked_for_prerendering) {
[email protected]3c2826852010-12-16 19:09:144438 // |blocked_plugin| will delete itself when the WebViewPlugin
4439 // is destroyed.
4440 BlockedPlugin* blocked_plugin =
4441 new BlockedPlugin(this,
4442 frame,
4443 group,
4444 params,
4445 webkit_preferences_,
4446 resource_id,
[email protected]2e34ab3f2010-12-17 05:47:374447 l10n_util::GetStringFUTF16(message_id,
[email protected]90dba072011-01-20 20:10:204448 group.GetGroupName()),
4449 is_blocked_for_prerendering);
[email protected]3c2826852010-12-16 19:09:144450 return blocked_plugin->plugin();
[email protected]57b66d02010-09-30 11:24:514451}
4452
[email protected]40bd6582009-12-04 23:49:514453void RenderView::OnZoom(PageZoom::Function function) {
4454 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4455 return;
4456
[email protected]258d31122010-05-09 10:59:414457 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524458
[email protected]b75b8292010-10-01 07:28:254459 double old_zoom_level = webview()->zoomLevel();
4460 double zoom_level;
4461 if (function == PageZoom::RESET) {
4462 zoom_level = 0;
4463 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4464 // Previous zoom level is a whole number, so just increment/decrement.
4465 zoom_level = old_zoom_level + function;
4466 } else {
4467 // Either the user hit the zoom factor limit and thus the zoom level is now
4468 // not a whole number, or a plugin changed it to a custom value. We want
4469 // to go to the next whole number so that the user can always get back to
4470 // 100% with the keyboard/menu.
4471 if ((old_zoom_level > 1 && function > 0) ||
4472 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:454473 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:254474 } else {
4475 // We're going towards 100%, so first go to the next whole number.
4476 zoom_level = static_cast<int>(old_zoom_level);
4477 }
4478 }
[email protected]40bd6582009-12-04 23:49:514479
[email protected]b75b8292010-10-01 07:28:254480 webview()->setZoomLevel(false, zoom_level);
4481 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:514482}
4483
[email protected]d0b8d092010-10-25 04:05:174484void RenderView::OnSetZoomLevel(double zoom_level) {
4485 // Don't set zoom level for full-page plugin since they don't use the same
4486 // zoom settings.
4487 if (webview()->mainFrame()->document().isPluginDocument())
4488 return;
4489
4490 webview()->hidePopups();
4491 webview()->setZoomLevel(false, zoom_level);
4492 zoomLevelChanged();
4493}
4494
[email protected]9d797f32010-04-23 07:17:544495void RenderView::OnSetContentSettingsForLoadingURL(
4496 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014497 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544498 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014499}
4500
[email protected]9d797f32010-04-23 07:17:544501void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:254502 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544503 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294504}
4505
[email protected]41fc0322009-09-04 22:23:404506void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274507 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294508}
4509
[email protected]a697f4c2009-09-14 22:30:184510void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274511 WebString no_encoding;
4512 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184513}
4514
[email protected]20ad2692009-11-20 18:27:204515bool RenderView::GetAllChildFrames(
4516 WebFrame* parent_frame,
4517 std::vector<WebFrame*>* frames_vector) const {
4518 if (!parent_frame)
4519 return false;
4520 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4521 child_frame = child_frame->nextSibling()) {
4522 frames_vector->push_back(child_frame);
4523 GetAllChildFrames(child_frame, frames_vector);
4524 }
4525 return true;
4526}
4527
[email protected]dd7daa82009-08-10 05:46:454528WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4529 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274530 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454531
4532 // xpath string can represent a frame deep down the tree (across multiple
4533 // frame DOMs).
4534 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4535 // should break into 2 xpaths
4536 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4537
[email protected]26aa0482009-09-30 16:55:274538 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454539
4540 std::wstring xpath_remaining = xpath;
4541 while (!xpath_remaining.empty()) {
4542 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4543 std::wstring xpath_child;
4544 if (delim_pos != std::wstring::npos) {
4545 xpath_child = xpath_remaining.substr(0, delim_pos);
4546 xpath_remaining.erase(0, delim_pos + 1);
4547 } else {
4548 xpath_remaining.swap(xpath_child);
4549 }
4550 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294551 }
4552
[email protected]dd7daa82009-08-10 05:46:454553 return frame;
initial.commit09911bf2008-07-26 23:55:294554}
4555
[email protected]13a1e4c3c2011-02-03 21:07:094556WebNode RenderView::GetFocusedNode() const {
4557 if (!webview())
4558 return WebNode();
4559 WebFrame* focused_frame = webview()->focusedFrame();
4560 if (focused_frame) {
4561 WebDocument doc = focused_frame->document();
4562 if (!doc.isNull())
4563 return doc.focusedNode();
4564 }
4565
4566 return WebNode();
4567}
4568
[email protected]ce833282010-11-04 15:48:394569void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) {
4570 // Explicitly allow empty vector to be sent to the browser.
4571 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions));
[email protected]15d9c0c2010-09-10 22:36:264572}
4573
[email protected]882b7b22010-10-05 03:34:534574void RenderView::EvaluateScript(const string16& frame_xpath,
4575 const string16& script,
4576 int id,
4577 bool notify_result) {
4578 v8::Handle<v8::Value> result;
4579 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
4580 if (web_frame)
4581 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
4582 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:294583 ListValue list;
4584 if (web_frame) {
4585 v8::HandleScope handle_scope;
4586 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4587 v8::Context::Scope context_scope(context);
4588 list.Set(0, ConvertV8Value(result));
4589 } else {
4590 list.Set(0, Value::CreateNullValue());
4591 }
4592 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:534593 }
initial.commit09911bf2008-07-26 23:55:294594}
4595
[email protected]1810e132009-03-24 23:35:484596void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084597 const std::string& css,
4598 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484599 WebFrame* web_frame = GetChildFrame(frame_xpath);
4600 if (!web_frame)
4601 return;
4602
[email protected]ffaef0c2009-09-15 17:08:084603 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484604}
4605
[email protected]00c39612010-03-06 02:53:284606void RenderView::OnPepperPluginDestroy(
4607 WebPluginDelegatePepper* pepper_plugin) {
4608 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014609 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4610 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284611 NOTREACHED();
4612 return;
4613 }
[email protected]53900d52010-06-16 04:25:014614 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474615
4616 // The plugin could have been destroyed while it was waiting for a file
4617 // choose callback, so check all pending completion callbacks and NULL them.
4618 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4619 file_chooser_completions_.begin();
4620 i != file_chooser_completions_.end(); /* nothing */) {
4621 if ((*i)->completion == pepper_plugin) {
4622 // We NULL the first one instead of deleting it because the plugin might
4623 // be the one waiting for a file choose callback. If the callback later
4624 // comes, we don't want to send the result to the next callback in line.
4625 if (i == file_chooser_completions_.begin())
4626 (*i)->completion = NULL;
4627 else
4628 i = file_chooser_completions_.erase(i);
4629 } else {
4630 ++i;
4631 }
4632 }
[email protected]00c39612010-03-06 02:53:284633}
4634
[email protected]882b7b22010-10-05 03:34:534635void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
4636 const string16& jscript,
4637 int id,
4638 bool notify_result) {
4639 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294640}
4641
[email protected]1810e132009-03-24 23:35:484642void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084643 const std::string& css,
4644 const std::string& id) {
4645 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414646
4647 // Notify RenderViewHost that css has been inserted into the frame.
4648 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484649}
4650
[email protected]7ea066a2009-04-06 20:21:594651void RenderView::OnAddMessageToConsole(
4652 const string16& frame_xpath,
4653 const string16& message,
4654 const WebConsoleMessage::Level& level) {
4655 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594656 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454657 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294658}
4659
[email protected]81e63782009-02-27 19:35:094660void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4661 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294662}
4663
4664void RenderView::OnSetDOMUIProperty(const std::string& name,
4665 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094666 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:274667 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294668}
4669
4670void RenderView::OnReservePageIDRange(int size_of_range) {
4671 next_page_id_ += size_of_range + 1;
4672}
4673
[email protected]e80c73b2009-04-07 23:24:584674void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4675 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254676 bool ended,
4677 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034678 if (ended) {
[email protected]26aa0482009-09-30 16:55:274679 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204680 } else {
4681 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034682 }
initial.commit09911bf2008-07-26 23:55:294683}
4684
4685void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274686 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294687}
4688
initial.commit09911bf2008-07-26 23:55:294689void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584690 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254691 const gfx::Point& screen_point,
4692 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274693 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584694 drop_data.ToDragData(),
4695 drop_data.identity,
4696 client_point,
[email protected]1d9f4132009-09-08 17:29:254697 screen_point,
4698 ops);
initial.commit09911bf2008-07-26 23:55:294699
[email protected]1d9f4132009-09-08 17:29:254700 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294701}
4702
[email protected]e80c73b2009-04-07 23:24:584703void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254704 const gfx::Point& screen_point,
4705 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274706 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254707 client_point,
4708 screen_point,
4709 ops);
initial.commit09911bf2008-07-26 23:55:294710
[email protected]1d9f4132009-09-08 17:29:254711 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294712}
4713
4714void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274715 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294716}
4717
[email protected]e80c73b2009-04-07 23:24:584718void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4719 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274720 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294721}
4722
4723void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594724 webkit_preferences_ = prefs;
4725 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294726}
4727
4728void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4729 alternate_error_page_url_ = url;
4730}
4731
[email protected]b29aa74b2011-01-31 21:41:084732void RenderView::OnCustomContextMenuAction(
4733 const webkit_glue::CustomContextMenuContext& custom_context,
4734 unsigned action) {
4735 if (custom_context.is_pepper_menu)
4736 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4737 else
4738 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:334739}
4740
initial.commit09911bf2008-07-26 23:55:294741void RenderView::OnInstallMissingPlugin() {
4742 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594743 if (first_default_plugin_)
4744 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294745}
4746
[email protected]90dba072011-01-20 20:10:204747void RenderView::OnDisplayPrerenderedPage() {
4748 NavigationState* navigation_state = pending_navigation_state_.get();
4749 if (!navigation_state) {
4750 WebDataSource* ds = webview()->mainFrame()->dataSource();
4751 navigation_state = NavigationState::FromDataSource(ds);
4752 }
4753
4754 DCHECK(navigation_state->is_prerendering());
4755 navigation_state->set_is_prerendering(false);
4756}
4757
[email protected]cdaf8d02010-03-30 19:52:474758void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364759 // This could happen if we navigated to a different page before the user
4760 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474761 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364762 return;
4763
[email protected]cdaf8d02010-03-30 19:52:474764 WebVector<WebString> ws_file_names(paths.size());
4765 for (size_t i = 0; i < paths.size(); ++i)
4766 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464767
[email protected]cdaf8d02010-03-30 19:52:474768 if (file_chooser_completions_.front()->completion)
4769 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4770 file_chooser_completions_.pop_front();
4771
4772 // If there are more pending file chooser requests, schedule one now.
4773 if (!file_chooser_completions_.empty()) {
4774 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4775 file_chooser_completions_.front()->params));
4776 }
initial.commit09911bf2008-07-26 23:55:294777}
4778
4779void RenderView::OnEnableViewSourceMode() {
4780 if (!webview())
4781 return;
[email protected]26aa0482009-09-30 16:55:274782 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294783 if (!main_frame)
4784 return;
4785
[email protected]dd7daa82009-08-10 05:46:454786 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294787}
4788
[email protected]770dd8b2010-05-24 18:11:394789void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4790 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244791 if (send_preferred_size_changes_)
4792 return;
[email protected]9fb325e2010-05-06 18:23:244793 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394794
4795 // WebKit doesn't send a notification of the effective height of the page
4796 // changes, so poll for it.
4797 // TODO: Add a notification for this to WebKit, remove polling. After that's
4798 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4799 // http://crbug.com/44850
4800 if (flags & kPreferredSizeHeightThisIsSlow) {
4801 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4802 &RenderView::CheckPreferredSize);
4803 }
[email protected]0666aef2009-05-13 19:48:084804}
4805
[email protected]ce833282010-11-04 15:48:394806void RenderView::OnSearchBoxChange(const string16& value,
[email protected]368ef4c2010-11-08 21:58:464807 bool verbatim,
[email protected]ce833282010-11-04 15:48:394808 int selection_start,
4809 int selection_end) {
4810 search_box_.value = value;
[email protected]368ef4c2010-11-08 21:58:464811 search_box_.verbatim = verbatim;
[email protected]ce833282010-11-04 15:48:394812 search_box_.selection_start = selection_start;
4813 search_box_.selection_end = selection_end;
4814 if (!webview() || !webview()->mainFrame())
4815 return;
4816 extensions_v8::SearchBoxExtension::DispatchChange(webview()->mainFrame());
4817}
4818
4819void RenderView::OnSearchBoxSubmit(const string16& value, bool verbatim) {
4820 search_box_.value = value;
4821 search_box_.verbatim = verbatim;
4822 if (!webview() || !webview()->mainFrame())
4823 return;
4824 extensions_v8::SearchBoxExtension::DispatchSubmit(webview()->mainFrame());
4825}
4826
4827void RenderView::OnSearchBoxCancel() {
4828 search_box_.verbatim = false;
4829 if (!webview() || !webview()->mainFrame())
4830 return;
4831 extensions_v8::SearchBoxExtension::DispatchCancel(webview()->mainFrame());
4832}
4833
4834void RenderView::OnSearchBoxResize(const gfx::Rect& bounds) {
4835 search_box_.x = bounds.x();
4836 search_box_.y = bounds.y();
4837 search_box_.width = bounds.width();
4838 search_box_.height = bounds.height();
4839 if (!webview() || !webview()->mainFrame())
4840 return;
4841 extensions_v8::SearchBoxExtension::DispatchResize(webview()->mainFrame());
4842}
4843
[email protected]57ad7b8c2010-11-18 19:13:494844void RenderView::OnDetermineIfPageSupportsInstant(const string16& value,
[email protected]0d5ab152011-01-14 23:09:044845 bool verbatim,
4846 int selection_start,
4847 int selection_end) {
[email protected]ce833282010-11-04 15:48:394848 search_box_.value = value;
[email protected]57ad7b8c2010-11-18 19:13:494849 search_box_.verbatim = verbatim;
[email protected]0d5ab152011-01-14 23:09:044850 search_box_.selection_start = selection_start;
4851 search_box_.selection_end = selection_end;
[email protected]ce833282010-11-04 15:48:394852 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
4853 webview()->mainFrame());
4854 Send(new ViewHostMsg_InstantSupportDetermined(routing_id_, page_id_, result));
4855}
4856
[email protected]cda45c02010-02-25 19:28:104857void RenderView::OnDisableScrollbarsForSmallWindows(
4858 const gfx::Size& disable_scrollbar_size_limit) {
4859 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4860}
4861
[email protected]80d96fa2009-06-10 22:34:514862void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4863 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374864 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134865#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414866 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4867 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464868 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]8d1b864d12010-10-10 00:04:344869 gfx::NativeThemeLinux::instance()->SetScrollbarColors(
4870 renderer_prefs.thumb_inactive_color,
4871 renderer_prefs.thumb_active_color,
4872 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324873
[email protected]644d77e2010-01-27 01:03:104874 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324875 webview()->setScrollbarColors(
4876 renderer_prefs.thumb_inactive_color,
4877 renderer_prefs.thumb_active_color,
4878 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104879 webview()->setSelectionColors(
4880 renderer_prefs.active_selection_bg_color,
4881 renderer_prefs.active_selection_fg_color,
4882 renderer_prefs.inactive_selection_bg_color,
4883 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464884 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104885 }
[email protected]7a74e102009-09-03 00:16:564886#endif
[email protected]80d96fa2009-06-10 22:34:514887}
4888
[email protected]952cb702009-10-07 05:50:284889void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4890 const WebMediaPlayerAction& action) {
4891 if (webview())
4892 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564893}
4894
[email protected]7b291f92009-08-14 05:43:534895void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4896 view_type_ = type;
4897}
4898
4899void RenderView::OnUpdateBrowserWindowId(int window_id) {
4900 browser_window_id_ = window_id;
4901}
4902
[email protected]dea2d372010-09-25 06:41:144903void RenderView::OnEnableAccessibility() {
4904 if (WebAccessibilityCache::accessibilityEnabled())
4905 return;
[email protected]9f4db512010-05-10 20:21:414906
[email protected]dea2d372010-09-25 06:41:144907 WebAccessibilityCache::enableAccessibility();
4908
4909 if (webview()) {
4910 // It's possible that the webview has already loaded a webpage without
4911 // accessibility being enabled. Initialize the browser's cached
4912 // accessibility tree by sending it a 'load complete' notification.
4913 postAccessibilityNotification(
4914 webview()->accessibilityObject(),
4915 WebKit::WebAccessibilityNotificationLoadComplete);
4916 }
[email protected]266eb6f2008-09-30 23:56:504917}
4918
[email protected]aef92842010-05-21 16:54:364919void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4920 if (!accessibility_.get())
4921 return;
[email protected]02ea2f312010-09-27 17:03:364922
4923 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4924 WebAccessibilityObject root = webview()->accessibilityObject();
4925 if (!obj.isValid() || !root.isValid())
4926 return;
4927
4928 // By convention, calling SetFocus on the root of the tree should clear the
4929 // current focus. Otherwise set the focus to the new node.
4930 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
4931 webview()->clearFocusedNode();
4932 else
4933 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:364934}
4935
4936void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4937 if (!accessibility_.get())
4938 return;
[email protected]02ea2f312010-09-27 17:03:364939
4940 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4941 if (!obj.isValid())
4942 return;
4943
4944 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:364945}
4946
[email protected]9892b472010-09-16 00:23:424947void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:514948 DCHECK(accessibility_ack_pending_);
4949 accessibility_ack_pending_ = false;
4950 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:314951}
4952
initial.commit09911bf2008-07-26 23:55:294953void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4954 const GURL& page_url) {
4955 // Prepare list to storage all savable resource links.
4956 std::vector<GURL> resources_list;
4957 std::vector<GURL> referrers_list;
4958 std::vector<GURL> frames_list;
4959 webkit_glue::SavableResourcesResult result(&resources_list,
4960 &referrers_list,
4961 &frames_list);
4962
[email protected]dbeb3952009-10-13 18:01:184963 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4964 webview(),
4965 page_url,
4966 &result,
4967 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294968 // If something is wrong when collecting all savable resource links,
4969 // send empty list to embedder(browser) to tell it failed.
4970 referrers_list.clear();
4971 resources_list.clear();
4972 frames_list.clear();
4973 }
4974
4975 // Send result of all savable resource links to embedder.
4976 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4977 resources_list,
4978 referrers_list,
4979 frames_list));
4980}
4981
4982void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324983 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314984 const std::vector<FilePath>& local_paths,
4985 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074986
4987 // Convert std::vector of GURLs to WebVector<WebURL>
4988 WebVector<WebURL> weburl_links(links);
4989
4990 // Convert std::vector of std::strings to WebVector<WebString>
4991 WebVector<WebString> webstring_paths(local_paths.size());
4992 for (size_t i = 0; i < local_paths.size(); i++)
4993 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4994
4995 WebPageSerializer::serialize(webview()->mainFrame(),
4996 true, this, weburl_links, webstring_paths,
4997 webkit_glue::FilePathToWebString(
4998 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294999}
5000
[email protected]d9ec5c0f2009-12-23 11:55:075001void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
5002 const WebCString& data,
5003 WebPageSerializerClient::PageSerializationStatus status) {
5004 Send(new ViewHostMsg_SendSerializedHtmlData(
5005 routing_id_,
5006 frame_url,
5007 data.data(),
5008 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:295009}
5010
[email protected]9b18a84f2010-06-10 15:54:045011void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:275012 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:475013 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:295014}
5015
[email protected]eb6b87a2009-07-24 15:57:395016void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:295017 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5018 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5019 // in the onunload handler from appearing. For now, we're bypassing that and
5020 // calling the FrameLoader's CloseURL method directly. This should be
5021 // revisited to avoid having two ways to close a page. Having a single way
5022 // to close that can run onunload is also useful for fixing
5023 // http://b/issue?id=753080.
[email protected]a5a65ac2010-11-05 18:14:365024 // TODO(davemoore) This code should be removed once willClose() gets
5025 // called when a page is destroyed. page_load_histograms_.Dump() is safe
5026 // to call multiple times for the same frame, but it will simplify things.
5027 page_load_histograms_.Dump(webview()->mainFrame());
5028 page_load_histograms_.ResetCrossFramePropertyAccess();
[email protected]26aa0482009-09-30 16:55:275029 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295030
[email protected]eb6b87a2009-07-24 15:57:395031 // Just echo back the params in the ACK.
5032 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:295033}
5034
5035void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:575036#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:295037 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465038 if (webview())
5039 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575040#else // defined(OS_WIN)
5041 // TODO(port): we don't support theming on non-Windows platforms yet
5042 NOTIMPLEMENTED();
5043#endif
initial.commit09911bf2008-07-26 23:55:295044}
5045
[email protected]9b18a84f2010-06-10 15:54:045046void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
5047 const std::string& origin,
5048 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:155049 if (message.empty())
5050 return;
[email protected]c091c2c2010-09-17 19:05:465051 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
5052 target);
[email protected]3ac14a052008-08-15 21:22:155053}
5054
[email protected]0aa55312008-10-17 21:53:085055void RenderView::OnDisassociateFromPopupCount() {
5056 if (decrement_shared_popup_at_destruction_)
5057 shared_popup_counter_->data--;
5058 shared_popup_counter_ = new SharedRenderViewCounter(0);
5059 decrement_shared_popup_at_destruction_ = false;
5060}
5061
[email protected]15d79e12009-08-02 19:23:455062bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
5063 const WebURLError& error,
5064 bool replace) {
5065 // We only show alternate error pages in the main frame. They are
5066 // intended to assist the user when navigating, so there is not much
5067 // value in showing them for failed subframes. Ideally, we would be
5068 // able to use the TYPED transition type for this, but that flag is
5069 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455070 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455071 return false;
5072
5073 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375074 // connection failure.
[email protected]15d79e12009-08-02 19:23:455075 int ec = error.reason;
5076 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5077 ec != net::ERR_CONNECTION_FAILED &&
5078 ec != net::ERR_CONNECTION_REFUSED &&
5079 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:375080 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:455081 return false;
5082
5083 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555084 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455085 if (!error_page_url.is_valid())
5086 return false;
5087
5088 // Load an empty page first so there is an immediate response to the error,
5089 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455090 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:365091 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455092 error.unreachableURL,
5093 replace);
5094
5095 // Now, create a fetcher for the error page and associate it with the data
5096 // source we just created via the LoadHTMLString call. That way if another
5097 // navigation occurs, the fetcher will get destroyed.
5098 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455099 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:455100 navigation_state->set_alt_error_page_fetcher(
5101 new AltErrorPageResourceFetcher(
5102 error_page_url, frame, error,
5103 NewCallback(this, &RenderView::AltErrorPageFinished)));
5104 return true;
5105}
5106
initial.commit09911bf2008-07-26 23:55:295107std::string RenderView::GetAltHTMLForTemplate(
5108 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:395109 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:295110 ResourceBundle::GetSharedInstance().GetRawDataResource(
5111 template_resource_id));
5112
5113 if (template_html.empty()) {
5114 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
5115 return "";
5116 }
[email protected]7cd22a52009-07-14 00:40:255117
initial.commit09911bf2008-07-26 23:55:295118 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:255119 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:295120 template_html, &error_strings, "t");
5121}
[email protected]0e79b9e2009-02-13 04:20:485122
[email protected]15d79e12009-08-02 19:23:455123void RenderView::AltErrorPageFinished(WebFrame* frame,
5124 const WebURLError& original_error,
5125 const std::string& html) {
5126 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:555127
5128 // If we failed to download the alternate error page, fall back to the
5129 // original error page if present. Otherwise, LoadNavigationErrorPage
5130 // will simply display a default error page.
5131 const std::string* html_to_load = &html;
5132 if (html.empty()) {
5133 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455134 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:555135 html_to_load = &navigation_state->postponed_data();
5136 }
[email protected]3f853a52010-09-13 19:15:085137 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
5138 true);
[email protected]15d79e12009-08-02 19:23:455139}
5140
[email protected]30f75e62009-02-25 22:01:005141void RenderView::OnMoveOrResizeStarted() {
5142 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475143 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005144}
5145
[email protected]30f75e62009-02-25 22:01:005146void RenderView::OnResize(const gfx::Size& new_size,
5147 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:105148 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475149 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105150 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205151 webview()->mainFrame()->setCanHaveScrollbars(
5152 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105153 }
5154 }
5155
[email protected]30f75e62009-02-25 22:01:005156 RenderWidget::OnResize(new_size, resizer_rect);
5157}
[email protected]0aa477bd2009-03-23 22:21:435158
[email protected]00c39612010-03-06 02:53:285159void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:015160 // Notify the pepper plugins that we started painting.
5161 pepper_delegate_.ViewInitiatedPaint();
5162
5163 // Notify any "old-style" pepper plugins that we started painting. This is
5164 // used for internal bookkeeping only, so we know that the set can not change
5165 // under us.
[email protected]00c39612010-03-06 02:53:285166 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:015167 current_oldstyle_pepper_plugins_.begin();
5168 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:285169 (*i)->RenderViewInitiatedPaint();
5170}
5171
5172void RenderView::DidFlushPaint() {
5173 // Notify any pepper plugins that we painted. This will call into the plugin,
5174 // and we it may ask to close itself as a result. This will, in turn, modify
5175 // our set, possibly invalidating the iterator. So we iterate on a copy that
5176 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015177 pepper_delegate_.ViewFlushedPaint();
5178
5179 // Notify any old-style pepper plugins that we painted. This will call into
5180 // the plugin, and we it may ask to close itself as a result. This will, in
5181 // turn, modify our set, possibly invalidating the iterator. So we iterate on
5182 // a copy that won't change out from under us.
5183 // This should be deleted when we don't support old Pepper anymore.
5184 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:285185 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
5186 i != plugins.end(); ++i) {
5187 // The copy above makes sure our iterator is never invalid if some plugins
5188 // are destroyed. But some plugin may decide to close all of its views in
5189 // response to a paint in one of them, so we need to make sure each one is
5190 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:015191 if (current_oldstyle_pepper_plugins_.find(*i) !=
5192 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:285193 (*i)->RenderViewFlushedPaint();
5194 }
5195
5196 WebFrame* main_frame = webview()->mainFrame();
5197
5198 // If we have a provisional frame we are between the start and commit stages
5199 // of loading and we don't want to save stats.
5200 if (!main_frame->provisionalDataSource()) {
5201 WebDataSource* ds = main_frame->dataSource();
5202 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5203 DCHECK(navigation_state);
5204
[email protected]05c8e502010-08-15 15:13:525205 // TODO(jar): The following code should all be inside a method, probably in
5206 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285207 Time now = Time::Now();
5208 if (navigation_state->first_paint_time().is_null()) {
5209 navigation_state->set_first_paint_time(now);
5210 }
5211 if (navigation_state->first_paint_after_load_time().is_null() &&
5212 !navigation_state->finish_load_time().is_null()) {
5213 navigation_state->set_first_paint_after_load_time(now);
5214 }
5215 }
5216}
5217
[email protected]719b36f2010-12-22 20:36:465218webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155219 const gfx::Rect& paint_bounds,
5220 TransportDIB** dib,
5221 gfx::Rect* location,
5222 gfx::Rect* clip) {
5223 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
5224 paint_bounds, dib, location, clip);
5225}
5226
[email protected]d54169e92011-01-21 09:19:525227gfx::Size RenderView::GetScrollOffset() {
5228 WebKit::WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
5229 return gfx::Size(scroll_offset.width, scroll_offset.height);
5230}
5231
[email protected]05d478752009-04-08 23:38:165232void RenderView::OnClearFocusedNode() {
5233 if (webview())
[email protected]26aa0482009-09-30 16:55:275234 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165235}
5236
[email protected]699ab0d2009-04-23 23:19:145237void RenderView::OnSetBackground(const SkBitmap& background) {
5238 if (webview())
[email protected]b4bb2502009-10-01 22:35:275239 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145240
5241 SetBackground(background);
5242}
5243
[email protected]8c66c5a2009-07-22 17:26:345244void RenderView::OnSetActive(bool active) {
5245 if (webview())
[email protected]b4bb2502009-10-01 22:35:275246 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265247
5248#if defined(OS_MACOSX)
5249 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5250 for (plugin_it = plugin_delegates_.begin();
5251 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5252 (*plugin_it)->SetWindowFocus(active);
5253 }
5254#endif
[email protected]8c66c5a2009-07-22 17:26:345255}
5256
[email protected]6ce7abc52010-02-02 18:40:145257#if defined(OS_MACOSX)
5258void RenderView::OnSetWindowVisibility(bool visible) {
5259 // Inform plugins that their container has changed visibility.
5260 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5261 for (plugin_it = plugin_delegates_.begin();
5262 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5263 (*plugin_it)->SetContainerVisibility(visible);
5264 }
5265}
[email protected]1e6e3c992010-02-08 15:52:135266
[email protected]4d51d5bf2010-07-26 18:48:265267void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
5268 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135269 // Inform plugins that their window's frame has changed.
5270 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5271 for (plugin_it = plugin_delegates_.begin();
5272 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5273 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5274 }
5275}
[email protected]935d63d2010-10-15 23:31:555276
[email protected]b7f75862011-01-21 21:15:135277void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:555278 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135279 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555280 // applies to it or not, so inform all the delegates.
5281 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5282 for (plugin_it = plugin_delegates_.begin();
5283 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135284 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555285 }
5286}
[email protected]6ce7abc52010-02-02 18:40:145287#endif // OS_MACOSX
5288
[email protected]8b8e7c92010-08-19 18:05:565289void RenderView::SendExtensionRequest(
5290 const ViewHostMsg_DomMessage_Params& params) {
5291 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:275292}
5293
[email protected]c6619182009-05-12 14:59:325294void RenderView::OnExtensionResponse(int request_id,
5295 bool success,
5296 const std::string& response,
5297 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:355298 ExtensionProcessBindings::HandleResponse(
5299 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:275300}
[email protected]c20210e62009-04-03 21:39:265301
[email protected]a7ab1b782010-10-21 23:24:165302void RenderView::OnExtensionMessageInvoke(const std::string& extension_id,
5303 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:495304 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:195305 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:495306 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:165307 extension_id, function_name, args, this, event_url);
[email protected]7120f132009-07-20 21:05:375308}
5309
[email protected]9892b472010-09-16 00:23:425310void RenderView::postAccessibilityNotification(
5311 const WebAccessibilityObject& obj,
5312 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:145313 if (!accessibility_.get() && webview()) {
5314 // Load complete should be our first notification sent.
5315 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
5316 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
5317 return;
5318
5319 // Create and initialize our accessibility cache
5320 accessibility_.reset(WebAccessibilityCache::create());
5321 accessibility_->initialize(webview());
5322 }
5323
[email protected]a3fa4f92010-09-30 22:19:335324 if (!accessibility_->isCached(obj)) {
5325 // The browser doesn't know about objects that are not in the cache. Send a
5326 // children change for the first accestor that actually is in the cache.
5327 WebAccessibilityObject parent = obj;
5328 while (parent.isValid() && !accessibility_->isCached(parent))
5329 parent = parent.parentObject();
5330
5331 DCHECK(parent.isValid() && accessibility_->isCached(parent));
5332 if (!parent.isValid())
5333 return;
5334 postAccessibilityNotification(
5335 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
5336
5337 // The parent's children change takes care of the child's children change.
5338 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
5339 return;
5340 }
5341
[email protected]dea2d372010-09-25 06:41:145342 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:515343 RendererAccessibilityNotification acc_notification;
5344 acc_notification.id = accessibility_->addOrGetId(obj);
5345 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:485346 return;
5347
[email protected]54ec7f82010-10-21 22:32:515348 if (!WebAccessibilityNotificationToViewHostMsg(
5349 notification,
5350 &acc_notification.type)) {
5351 return;
5352 }
5353
5354 // Discard duplicate accessibility notifications.
5355 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
5356 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
5357 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:425358 return;
[email protected]54ec7f82010-10-21 22:32:515359 }
[email protected]9892b472010-09-16 00:23:425360 }
[email protected]54ec7f82010-10-21 22:32:515361 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:485362
[email protected]54ec7f82010-10-21 22:32:515363 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
5364 // When no accessibility notifications are in-flight post a task to send
5365 // the notifications to the browser. We use PostTask so that we can queue
5366 // up additional notifications.
5367 MessageLoop::current()->PostTask(
5368 FROM_HERE,
5369 accessibility_method_factory_.NewRunnableMethod(
5370 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:315371 }
[email protected]520cb7d72010-08-31 11:54:315372}
5373
[email protected]c7a827e2011-01-21 00:27:015374void RenderView::OnPrint(bool is_preview) {
5375 DCHECK(webview());
5376 if (webview()) {
5377 // If the user has selected text in the currently focused frame we print
5378 // only that frame (this makes print selection work for multiple frames).
5379 if (webview()->focusedFrame()->hasSelection())
5380 Print(webview()->focusedFrame(), false, is_preview);
5381 else
5382 Print(webview()->mainFrame(), false, is_preview);
5383 }
5384}
5385
[email protected]212a49d2010-10-25 18:23:475386void RenderView::Print(WebFrame* frame,
5387 bool script_initiated,
5388 bool is_preview) {
[email protected]0fda7272009-06-26 15:49:335389 DCHECK(frame);
[email protected]521b2482011-01-15 00:10:105390 GetPrintWebViewHelper()->PrintFrame(frame, script_initiated, is_preview);
5391}
5392
5393PrintWebViewHelper* RenderView::GetPrintWebViewHelper() {
5394 if (print_helper_.get() == NULL)
[email protected]0fda7272009-06-26 15:49:335395 print_helper_.reset(new PrintWebViewHelper(this));
[email protected]521b2482011-01-15 00:10:105396 return print_helper_.get();
[email protected]0fda7272009-06-26 15:49:335397}
[email protected]446705872009-09-10 07:22:485398
5399void RenderView::OnSetEditCommandsForNextKeyEvent(
5400 const EditCommands& edit_commands) {
5401 edit_commands_ = edit_commands;
5402}
5403
[email protected]61f5a7b2009-12-22 22:21:205404void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275405 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355406 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205407 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5408 false));
[email protected]912256b32009-09-18 09:47:355409 return;
5410 }
5411
[email protected]fa7b6b542009-11-03 05:02:305412 WebDataSource* ds = main_frame->dataSource();
5413 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5414 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205415 pending_code_execution_queue_.push(
5416 linked_ptr<ViewMsg_ExecuteCode_Params>(
5417 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305418 return;
5419 }
5420
[email protected]61f5a7b2009-12-22 22:21:205421 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305422}
5423
5424void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205425 const ViewMsg_ExecuteCode_Params& params) {
[email protected]20ad2692009-11-20 18:27:205426 std::vector<WebFrame*> frame_vector;
5427 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205428 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205429 GetAllChildFrames(frame, &frame_vector);
5430
5431 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5432 frame_it != frame_vector.end(); ++frame_it) {
5433 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205434 if (params.is_javascript) {
[email protected]2a521c52011-01-26 18:45:215435 const Extension* extension =
5436 render_thread_->GetExtensions()->GetByID(params.extension_id);
[email protected]be7e5cb2010-10-04 12:53:175437
[email protected]1f6228c2010-10-21 03:19:445438 // Since extension info is sent separately from user script info, they can
5439 // be out of sync. We just ignore this situation.
5440 if (!extension)
5441 continue;
5442
[email protected]2a521c52011-01-26 18:45:215443 if (!extension->CanExecuteScriptOnPage(frame->url(), NULL, NULL))
[email protected]61f5a7b2009-12-22 22:21:205444 continue;
5445
[email protected]20ad2692009-11-20 18:27:205446 std::vector<WebScriptSource> sources;
5447 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205448 WebScriptSource(WebString::fromUTF8(params.code)));
5449 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205450 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205451 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205452 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5453 } else {
[email protected]61f5a7b2009-12-22 22:21:205454 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205455 }
[email protected]912256b32009-09-18 09:47:355456 }
5457
[email protected]61f5a7b2009-12-22 22:21:205458 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355459}
5460
[email protected]60c42a8c72009-10-09 04:08:595461void RenderView::Close() {
5462 // We need to grab a pointer to the doomed WebView before we destroy it.
5463 WebView* doomed = webview();
5464 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495465 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595466}
5467
[email protected]446705872009-09-10 07:22:485468void RenderView::DidHandleKeyEvent() {
5469 edit_commands_.clear();
5470}
5471
[email protected]6a8ddba52010-09-05 04:38:065472void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515473 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065474}
5475
[email protected]941e4552010-02-01 21:23:435476#if defined(OS_MACOSX)
5477void RenderView::OnWasHidden() {
5478 RenderWidget::OnWasHidden();
5479
5480 // Inform plugins that their container is no longer visible.
5481 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5482 for (plugin_it = plugin_delegates_.begin();
5483 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5484 (*plugin_it)->SetContainerVisibility(false);
5485 }
5486}
5487
5488void RenderView::OnWasRestored(bool needs_repainting) {
5489 RenderWidget::OnWasRestored(needs_repainting);
5490
5491 // Inform plugins that their container is now visible.
5492 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5493 for (plugin_it = plugin_delegates_.begin();
5494 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5495 (*plugin_it)->SetContainerVisibility(true);
5496 }
5497}
[email protected]784ea1ab2010-09-18 00:02:345498#endif // OS_MACOSX
[email protected]1e6e3c992010-02-08 15:52:135499
5500void RenderView::OnSetFocus(bool enable) {
5501 RenderWidget::OnSetFocus(enable);
5502
[email protected]7d3c02c2010-05-05 23:10:315503 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075504 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135505 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5506 for (plugin_it = plugin_delegates_.begin();
5507 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345508#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315509 // RenderWidget's call to setFocus can cause the underlying webview's
5510 // activation state to change just like a call to setIsActive.
5511 if (enable)
5512 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345513#endif
[email protected]7d3c02c2010-05-05 23:10:315514 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135515 }
[email protected]589621b2010-09-23 22:01:075516
5517 // Notify all Pepper plugins.
5518 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135519 }
5520}
[email protected]941e4552010-02-01 21:23:435521
[email protected]83dde542009-09-11 20:59:555522void RenderView::EnsureDocumentTag() {
5523 // TODO(darin): There's actually no reason for this to be here. We should
5524 // have the browser side manage the document tag.
5525#if defined(OS_MACOSX)
5526 if (!has_document_tag_) {
5527 // Make the call to get the tag.
5528 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5529 has_document_tag_ = true;
5530 }
5531#endif
5532}
[email protected]12636df2009-09-28 22:32:215533
[email protected]43f28f832010-02-03 02:28:485534#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:135535void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
5536 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
5537 focused, plugin_id);
5538 Send(msg);
5539}
5540
5541void RenderView::StartPluginIme() {
5542 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555543 // This message can be sent during event-handling, and needs to be delivered
5544 // within that context.
5545 msg->set_unblock(true);
5546 Send(msg);
5547}
5548
[email protected]ea04a4e12010-04-15 00:58:035549gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235550 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485551 gfx::PluginWindowHandle window = NULL;
5552 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235553 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115554 if (window) {
5555 fake_plugin_window_handles_.insert(window);
5556 }
[email protected]43f28f832010-02-03 02:28:485557 return window;
5558}
5559
5560void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115561 if (window && fake_plugin_window_handles_.find(window) !=
5562 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485563 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115564 fake_plugin_window_handles_.erase(window);
5565 }
[email protected]43f28f832010-02-03 02:28:485566}
5567
[email protected]44ce0b12010-03-12 16:45:335568void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5569 int32 width,
5570 int32 height,
5571 uint64 io_surface_identifier) {
5572 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485573 routing_id(), window, width, height, io_surface_identifier));
5574}
5575
[email protected]44ce0b12010-03-12 16:45:335576void RenderView::AcceleratedSurfaceSetTransportDIB(
5577 gfx::PluginWindowHandle window,
5578 int32 width,
5579 int32 height,
5580 TransportDIB::Handle transport_dib) {
5581 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075582 routing_id(), window, width, height, transport_dib));
5583}
5584
[email protected]44ce0b12010-03-12 16:45:335585TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5586 size_t size) {
[email protected]1aef98132010-02-23 18:00:075587 TransportDIB::Handle dib_handle;
5588 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385589 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075590 return dib_handle;
5591 // Return an invalid handle if Send() fails.
5592 return TransportDIB::DefaultHandleValue();
5593}
5594
[email protected]44ce0b12010-03-12 16:45:335595void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075596 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5597}
5598
[email protected]44ce0b12010-03-12 16:45:335599void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:145600 gfx::PluginWindowHandle window, uint64 surface_id) {
5601 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
5602 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:485603}
5604#endif
[email protected]58c321d2010-02-19 12:11:285605
[email protected]cdaf8d02010-03-30 19:52:475606bool RenderView::ScheduleFileChooser(
5607 const ViewHostMsg_RunFileChooser_Params& params,
5608 WebFileChooserCompletion* completion) {
5609 static const size_t kMaximumPendingFileChooseRequests = 4;
5610 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5611 // This sanity check prevents too many file choose requests from getting
5612 // queued which could DoS the user. Getting these is most likely a
5613 // programming error (there are many ways to DoS the user so it's not
5614 // considered a "real" security check), either in JS requesting many file
5615 // choosers to pop up, or in a plugin.
5616 //
5617 // TODO(brettw) we might possibly want to require a user gesture to open
5618 // a file picker, which will address this issue in a better way.
5619 return false;
5620 }
5621
5622 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5623 new PendingFileChooser(params, completion)));
5624 if (file_chooser_completions_.size() == 1) {
5625 // Actually show the browse dialog when this is the first request.
5626 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5627 }
5628 return true;
5629}
5630
[email protected]290838a2010-04-27 17:37:015631void RenderView::OnPageTranslated() {
5632 WebFrame* frame = webview()->mainFrame();
5633 if (!frame)
5634 return;
5635
[email protected]676126f72011-01-15 00:03:515636 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameTranslated(frame));
[email protected]290838a2010-04-27 17:37:015637}
5638
[email protected]0ff0ff32010-12-21 19:34:425639WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515640 if (!geolocation_dispatcher_)
5641 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5642 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255643}
[email protected]61c9f032010-03-31 23:04:195644
[email protected]638694c2010-08-04 22:24:115645WebKit::WebSpeechInputController* RenderView::speechInputController(
5646 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:515647 if (!speech_input_dispatcher_)
5648 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
5649 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:115650}
5651
[email protected]57ead352010-08-11 14:42:535652WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515653 if (!device_orientation_dispatcher_)
5654 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5655 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535656}
5657
[email protected]b75b8292010-10-01 07:28:255658void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
5659 // For now, don't remember plugin zoom values. We don't want to mix them with
5660 // normal web content (i.e. a fixed layout plugin would usually want them
5661 // different).
5662 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5663
[email protected]b75b8292010-10-01 07:28:255664 int minimum_percent = static_cast<int>(
5665 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5666 int maximum_percent = static_cast<int>(
5667 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255668
5669 Send(new ViewHostMsg_UpdateZoomLimits(
5670 routing_id_, minimum_percent, maximum_percent, remember));
5671}
5672
5673void RenderView::zoomLevelChanged() {
5674 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5675
[email protected]b75b8292010-10-01 07:28:255676 // Tell the browser which url got zoomed so it can update the menu and the
5677 // saved values if necessary
5678 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:415679 routing_id_, webview()->zoomLevel(), remember,
5680 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:255681}
5682
[email protected]8079b362010-05-07 18:37:455683bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195684 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455685 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195686 if (frame->parent() != NULL)
5687 return false;
5688
[email protected]f0a3d0b2010-08-06 22:51:535689 // Navigations initiated within Webkit are not sent out to the external host
5690 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275691 // 1. The url scheme is not http/https
5692 // 2. There is no opener and this is not the first url being opened by this
5693 // RenderView.
5694 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535695 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535696 // 4. Reloads/form submits/back forward navigations
5697 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5698 return false;
5699
[email protected]2fc22d12010-12-02 23:08:165700 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325701 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015702 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165703 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015704 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325705 // The opener relationship between the new window and the parent allows the
5706 // new window to script the parent and vice versa. This is not allowed if
5707 // the origins of the two domains are different. This can be treated as a
5708 // top level navigation and routed back to the host.
5709 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275710 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475711 // Force link click navigations to always be routed to the host as they
5712 // may update session state on the server.
5713 if (type == WebKit::WebNavigationTypeLinkClicked)
5714 return true;
[email protected]900eb2f12010-08-23 22:36:275715 // If this is the first page being loaded by this RenderView instance then
5716 // it should stay here.
5717 if (page_id_ == -1) {
5718 return false;
5719 } else {
[email protected]d0ed50d2010-06-22 01:01:325720 return true;
[email protected]900eb2f12010-08-23 22:36:275721 }
[email protected]d0ed50d2010-06-22 01:01:325722 }
[email protected]900eb2f12010-08-23 22:36:275723
5724 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5725 return true;
[email protected]d0ed50d2010-06-22 01:01:325726 }
[email protected]61c9f032010-03-31 23:04:195727 return false;
5728}
[email protected]2b06a992010-08-21 05:48:225729
[email protected]27a9ef32010-09-10 04:06:245730void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5731 IPC::PlatformFileForTransit file_for_transit,
5732 int message_id) {
5733 pepper_delegate_.OnAsyncFileOpened(
5734 error_code,
5735 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5736 message_id);
5737}
[email protected]caf706f2010-10-26 17:54:085738
5739#if defined(OS_MACOSX)
5740void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155741 if (external_popup_menu_ == NULL) {
5742 // Crash reports from the field indicate that we can be notified with a
5743 // NULL external popup menu (we probably get notified twice).
5744 // If you hit this please file a bug against jcivelli and include the page
5745 // and steps to repro.
5746 NOTREACHED();
5747 return;
5748 }
[email protected]caf706f2010-10-26 17:54:085749 external_popup_menu_->DidSelectItem(selected_index);
5750 external_popup_menu_.reset();
5751}
5752#endif
[email protected]bb461532010-11-26 21:50:235753
5754void RenderView::AddErrorToRootConsole(const string16& message) {
5755 if (webview() && webview()->mainFrame()) {
5756 webview()->mainFrame()->addMessageToConsole(
5757 WebConsoleMessage(WebConsoleMessage::LevelError, message));
5758 }
5759}
[email protected]1b4209f2011-01-07 00:25:405760
5761#if defined(ENABLE_FLAPPER_HACKS)
5762void RenderView::OnConnectTcpACK(
5763 int request_id,
5764 IPC::PlatformFileForTransit socket_for_transit,
5765 const PP_Flash_NetAddress& local_addr,
5766 const PP_Flash_NetAddress& remote_addr) {
5767 pepper_delegate_.OnConnectTcpACK(
5768 request_id,
5769 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5770 local_addr,
5771 remote_addr);
5772}
5773#endif
[email protected]a6097f42011-01-10 08:50:515774
5775void RenderView::OnJavaScriptStressTestControl(int cmd, int param) {
5776 if (cmd == kJavaScriptStressTestSetStressRunType) {
5777 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5778 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5779 v8::Testing::PrepareStressRun(param);
5780 }
5781}
[email protected]521b2482011-01-15 00:10:105782
[email protected]b29aa74b2011-01-31 21:41:085783void RenderView::OnContextMenuClosed(
5784 const webkit_glue::CustomContextMenuContext& custom_context) {
5785 if (custom_context.is_pepper_menu)
5786 pepper_delegate_.OnContextMenuClosed(custom_context);
5787 else
5788 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105789}