blob: 7ac9c84bd5e041fe389d3ca180aa65f32a16fa7f [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]a527a022011-02-10 02:32:3644#include "chrome/common/render_messages_params.h"
[email protected]13a1e4c3c2011-02-03 21:07:0945#include "chrome/common/render_view_commands.h"
[email protected]9b6f40e2009-06-11 15:54:2646#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2947#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5948#include "chrome/common/url_constants.h"
[email protected]38789d82010-11-17 06:03:4449#include "chrome/common/web_apps.h"
[email protected]534c66c2010-04-28 22:53:1150#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2951#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2552#include "chrome/renderer/audio_message_filter.h"
[email protected]78192082011-01-29 05:43:4453#include "chrome/renderer/autofill/autofill_agent.h"
54#include "chrome/renderer/autofill/form_manager.h"
55#include "chrome/renderer/autofill/password_autofill_manager.h"
[email protected]2f979172010-09-16 21:54:0356#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]00152e92010-07-19 11:47:4057#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5358#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1159#include "chrome/renderer/devtools_agent.h"
60#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3561#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0462#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]f816c012009-06-26 21:48:3263#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3564#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]78d5cfe2011-02-04 08:43:2265#include "chrome/renderer/extensions/extension_resource_request_policy.h"
[email protected]7120f132009-07-20 21:05:3766#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0367#include "chrome/renderer/external_host_bindings.h"
[email protected]caf706f2010-10-26 17:54:0868#include "chrome/renderer/external_popup_menu.h"
[email protected]ffd0abd2010-12-14 17:45:5069#include "chrome/renderer/geolocation_dispatcher.h"
[email protected]3bb08602010-10-07 21:47:1770#include "chrome/renderer/ggl/ggl.h"
[email protected]90109412010-12-15 17:14:2471#include "chrome/renderer/load_progress_tracker.h"
initial.commit09911bf2008-07-26 23:55:2972#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5673#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4174#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]ed3fb032009-06-16 19:50:5675#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1276#include "chrome/renderer/notification_provider.h"
[email protected]6a8ddba52010-09-05 04:38:0677#include "chrome/renderer/page_click_tracker.h"
[email protected]a5a65ac2010-11-05 18:14:3678#include "chrome/renderer/page_load_histograms.h"
[email protected]8beff0762009-09-29 02:18:3079#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5080#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2581#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2882#include "chrome/renderer/render_thread.h"
[email protected]676126f72011-01-15 00:03:5183#include "chrome/renderer/render_view_observer.h"
[email protected]4d51d5bf2010-07-26 18:48:2684#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1885#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]79c7bed2010-09-14 22:28:3986#include "chrome/renderer/render_widget_fullscreen_pepper.h"
[email protected]035545f2010-04-09 13:10:2187#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3488#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]3ead1322010-11-19 20:01:0089#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
[email protected]ce833282010-11-04 15:48:3990#include "chrome/renderer/searchbox_extension.h"
[email protected]638694c2010-08-04 22:24:1191#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4692#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]81273622011-02-02 03:56:1393#include "chrome/renderer/translate_helper.h"
[email protected]25e18f82010-10-27 16:38:4394#include "chrome/renderer/user_script_idle_scheduler.h"
[email protected]0938d3c2009-01-09 20:37:3595#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2996#include "chrome/renderer/visitedlink_slave.h"
[email protected]c50008512011-02-03 01:17:2797#include "chrome/renderer/web_ui_bindings.h"
[email protected]5aa6a312010-11-06 00:00:0798#include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h"
[email protected]d439ba072009-10-17 22:32:2999#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:29100#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:42101#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:56102#include "chrome/renderer/webworker_proxy.h"
[email protected]34ac8f32009-02-22 23:03:27103#include "grit/generated_resources.h"
104#include "grit/renderer_resources.h"
[email protected]f8db8132010-12-03 00:27:49105#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41106#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:27107#include "media/base/message_loop_factory_impl.h"
[email protected]f11ca0732009-04-11 00:09:34108#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29109#include "net/base/escape.h"
110#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04111#include "net/http/http_util.h"
[email protected]1b4209f2011-01-07 00:25:40112#include "ppapi/c/private/ppb_flash.h"
[email protected]c399a8a2008-11-22 19:38:00113#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:10114#include "skia/ext/image_operations.h"
[email protected]8bd0fe62011-01-17 06:44:37115#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
152#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
154#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
155#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
157#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26158#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
159#include "third_party/skia/include/core/SkBitmap.h"
[email protected]9dd7e3d72011-01-20 18:27:06160#include "ui/base/message_box_flags.h"
[email protected]c051a1b2011-01-21 23:30:17161#include "ui/base/l10n/l10n_util.h"
[email protected]42ce29d2011-01-20 23:19:46162#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:38163#include "ui/gfx/color_utils.h"
164#include "ui/gfx/favicon_size.h"
165#include "ui/gfx/native_widget_types.h"
166#include "ui/gfx/point.h"
167#include "ui/gfx/rect.h"
168#include "ui/gfx/skbitmap_operations.h"
[email protected]882b7b22010-10-05 03:34:53169#include "v8/include/v8.h"
[email protected]a6097f42011-01-10 08:50:51170#include "v8/include/v8-testing.h"
[email protected]80f584d92010-01-21 03:59:04171#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43172#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24173#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29174#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59175#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24176#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24177#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34178#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26179#include "webkit/glue/image_resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09180#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26181#include "webkit/glue/password_form_dom_manager.h"
[email protected]bb461532010-11-26 21:50:23182#include "webkit/glue/resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09183#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24184#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29185#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29186#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17187#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50188#include "webkit/plugins/npapi/default_plugin_shared.h"
189#include "webkit/plugins/npapi/plugin_list.h"
190#include "webkit/plugins/npapi/webplugin_delegate.h"
191#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
192#include "webkit/plugins/npapi/webplugin_impl.h"
193#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52194#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29195
[email protected]6c8afae52009-01-22 02:24:57196#if defined(OS_WIN)
197// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57198// * theming
[email protected]08397d52011-02-05 01:53:38199#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03200#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37201#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]08397d52011-02-05 01:53:38202#include "ui/gfx/native_theme_linux.h"
[email protected]78043bdd2010-04-05 18:45:33203#elif defined(OS_MACOSX)
204#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57205#endif
206
[email protected]c7287a92009-11-04 20:06:15207using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42208using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08209using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21210using WebKit::WebApplicationCacheHost;
211using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26212using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41213using WebKit::WebColor;
214using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59215using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44216using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51217using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55218using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28219using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29220using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00221using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58222using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25223using WebKit::WebDragOperation;
224using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51225using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51226using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08227using WebKit::WebExternalPopupMenu;
228using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47229using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22230using WebKit::WebFileSystem;
231using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49232using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59233using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48234using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45235using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17236using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41237using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50238using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17239using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28240using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17241using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28242using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28243using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51244using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07245using WebKit::WebPageSerializer;
246using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17247using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40248using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49249using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09250using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52251using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59252using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51253using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52254using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40255using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35256using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29257using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59258using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42259using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02260using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34261using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28262using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51263using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52264using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28265using WebKit::WebURL;
266using WebKit::WebURLError;
267using WebKit::WebURLRequest;
268using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28269using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03270using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28271using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26272using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43273using WebKit::WebWorker;
274using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26275using appcache::WebApplicationCacheHostImpl;
[email protected]78192082011-01-29 05:43:44276using autofill::AutoFillAgent;
277using autofill::FormManager;
278using autofill::PasswordAutoFillManager;
[email protected]6fdd4182010-10-14 23:59:26279using base::Time;
280using base::TimeDelta;
281using webkit_glue::AltErrorPageResourceFetcher;
282using webkit_glue::FormData;
283using webkit_glue::FormField;
284using webkit_glue::ImageResourceFetcher;
285using webkit_glue::PasswordForm;
286using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23287using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26288using webkit_glue::SiteIsolationMetrics;
289using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33290
initial.commit09911bf2008-07-26 23:55:29291//-----------------------------------------------------------------------------
292
[email protected]3354d3e2010-06-10 19:53:02293typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49294static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02295
initial.commit09911bf2008-07-26 23:55:29296// define to write the time necessary for thumbnail/DOM text retrieval,
297// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29298// #define TIME_TEXT_RETRIEVAL
299
300// maximum number of characters in the document to index, any text beyond this
301// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57302static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29303
304// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37305static const int kThumbnailWidth = 212;
306static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29307
308// Delay in milliseconds that we'll wait before capturing the page contents
309// and thumbnail.
310static const int kDelayForCaptureMs = 500;
311
312// Typically, we capture the page data once the page is loaded.
313// Sometimes, the page never finishes to load, preventing the page capture
314// To workaround this problem, we always perform a capture after the following
315// delay.
316static const int kDelayForForcedCaptureMs = 6000;
317
[email protected]882daa92009-11-05 16:31:31318// Time, in seconds, we delay before sending content state changes (such as form
319// state and scroll position) to the browser. We delay sending changes to avoid
320// spamming the browser.
321// To avoid having tab/session restore require sending a message to get the
322// current content state during tab closing we use a shorter timeout for the
323// foreground renderer. This means there is a small window of time from which
324// content state is modified and not sent to session restore, but this is
325// better than having to wake up all renderers during shutdown.
326static const int kDelaySecondsForContentStateSyncHidden = 5;
327static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29328
[email protected]0aa55312008-10-17 21:53:08329// The maximum number of popups that can be spawned from one page.
330static const int kMaximumNumberOfUnacknowledgedPopups = 25;
331
[email protected]6fdd4182010-10-14 23:59:26332static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35333
[email protected]726985e22009-06-18 21:09:28334static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
335 WebVector<WebURL> urls;
336 ds->redirectChain(urls);
337 result->reserve(urls.size());
338 for (size_t i = 0; i < urls.size(); ++i)
339 result->push_back(urls[i]);
340}
341
[email protected]30507922010-01-15 16:48:23342static bool PaintViewIntoCanvas(WebView* view,
343 skia::PlatformCanvas& canvas) {
344 view->layout();
345 const WebSize& size = view->size();
346
347 if (!canvas.initialize(size.width, size.height, true))
348 return false;
349
350 view->paint(webkit_glue::ToWebCanvas(&canvas),
351 WebRect(0, 0, size.width, size.height));
352 // TODO: Add a way to snapshot the whole page, not just the currently
353 // visible part.
354
355 return true;
356}
357
358// Calculates how "boring" a thumbnail is. The boring score is the
359// 0,1 ranged percentage of pixels that are the most common
360// luma. Higher boring scores indicate that a higher percentage of a
361// bitmap are all the same brightness.
362static double CalculateBoringScore(SkBitmap* bitmap) {
363 int histogram[256] = {0};
364 color_utils::BuildLumaHistogram(bitmap, histogram);
365
366 int color_count = *std::max_element(histogram, histogram + 256);
367 int pixel_count = bitmap->width() * bitmap->height();
368 return static_cast<double>(color_count) / pixel_count;
369}
370
[email protected]12bc8472010-04-15 07:29:40371// True if |frame| contains content that is white-listed for content settings.
372static bool IsWhitelistedForContentSettings(WebFrame* frame) {
373 WebSecurityOrigin origin = frame->securityOrigin();
374 if (origin.isEmpty())
375 return false; // Uninitialized document?
376
377 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
378 return true; // Browser UI elements should still work.
379
380 // If the scheme is ftp: or file:, an empty file name indicates a directory
381 // listing, which requires JavaScript to function properly.
382 GURL frame_url = frame->url();
383 const char* kDirProtocols[] = { "ftp", "file" };
384 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
385 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
386 return frame_url.SchemeIs(kDirProtocols[i]) &&
387 frame_url.ExtractFileName().empty();
388 }
389 }
390
391 return false;
392}
393
[email protected]3a8eecb2010-04-22 23:56:30394// Returns true if the frame is navigating to an URL either into or out of an
395// extension app's extent.
[email protected]08e94b82010-12-15 22:51:04396// TODO(creis): Temporary workaround for crbug.com/65953: Only return true if
[email protected]88c15e972011-02-05 04:19:53397// we would enter an extension app's extent from a non-app, or if we leave an
398// extension with no web extent. We avoid swapping processes to exit a hosted
399// app with a web extent for now, since we do not yet restore context (such
[email protected]08e94b82010-12-15 22:51:04400// as window.opener) if the window navigates back.
[email protected]88c15e972011-02-05 04:19:53401static bool CrossesExtensionExtents(const ExtensionSet* extensions,
402 WebFrame* frame,
403 const GURL& new_url) {
[email protected]3a8eecb2010-04-22 23:56:30404 // If the URL is still empty, this is a window.open navigation. Check the
405 // opener's URL.
406 GURL old_url(frame->url());
407 if (old_url.is_empty() && frame->opener())
408 old_url = frame->opener()->url();
409
[email protected]88c15e972011-02-05 04:19:53410 bool old_url_is_hosted_app = extensions->GetByURL(old_url) &&
411 !extensions->GetByURL(old_url)->web_extent().is_empty();
[email protected]2a521c52011-01-26 18:45:21412 return !extensions->InSameExtent(old_url, new_url) &&
[email protected]88c15e972011-02-05 04:19:53413 !old_url_is_hosted_app;
[email protected]3a8eecb2010-04-22 23:56:30414}
415
[email protected]3354d3e2010-06-10 19:53:02416// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
417// if it failed.
[email protected]e5106202010-06-11 21:12:36418static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17419 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02420 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08421 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02422 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02423 Language cld_language =
[email protected]e5106202010-06-11 21:12:36424 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08425 &num_languages, NULL, &text_bytes);
426 // We don't trust the result if the CLD reports that the detection is not
427 // reliable, or if the actual text used to detect the language was less than
428 // 100 bytes (short texts can often lead to wrong results).
429 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02430 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
431 // We should not use LanguageCode_ISO_639_1 because it does not cover all
432 // the languages CLD can detect. As a result, it'll return the invalid
433 // language code for tradtional Chinese among others.
434 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
435 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
436 // for Simplified Chinese.
437 language = LanguageCodeWithDialects(cld_language);
438 }
439 return language;
440}
441
[email protected]9b66f34bf2010-10-27 20:45:51442// Returns true if the parameter node is a textfield, text area or a content
443// editable div.
444static bool IsEditableNode(const WebNode& node) {
445 bool is_editable_node = false;
446 if (!node.isNull()) {
447 if (node.isContentEditable()) {
448 is_editable_node = true;
449 } else if (node.isElementNode()) {
450 is_editable_node =
451 node.toConst<WebElement>().isTextFormControlElement();
452 }
453 }
454 return is_editable_node;
455}
456
[email protected]54ec7f82010-10-21 22:32:51457static bool WebAccessibilityNotificationToViewHostMsg(
458 WebAccessibilityNotification notification,
459 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) {
460 switch (notification) {
461 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
462 *type = ViewHostMsg_AccessibilityNotification_Params::
463 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
464 break;
465 case WebKit::WebAccessibilityNotificationChildrenChanged:
466 *type = ViewHostMsg_AccessibilityNotification_Params::
467 NOTIFICATION_TYPE_CHILDREN_CHANGED;
468 break;
469 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
470 *type = ViewHostMsg_AccessibilityNotification_Params::
471 NOTIFICATION_TYPE_FOCUS_CHANGED;
472 break;
473 case WebKit::WebAccessibilityNotificationLoadComplete:
474 *type = ViewHostMsg_AccessibilityNotification_Params::
475 NOTIFICATION_TYPE_LOAD_COMPLETE;
476 break;
477 case WebKit::WebAccessibilityNotificationValueChanged:
478 *type = ViewHostMsg_AccessibilityNotification_Params::
479 NOTIFICATION_TYPE_VALUE_CHANGED;
480 break;
481 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
482 *type = ViewHostMsg_AccessibilityNotification_Params::
483 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
484 break;
485 default:
486 // TODO(ctguil): Support additional webkit notifications.
487 return false;
488 }
489 return true;
490}
491
[email protected]81f9fe0b2010-12-07 00:35:29492// Conversion for the incoming value. The map isn't perfect; v8 has Uint32,
493// and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into
[email protected]fb534c92011-02-01 01:02:07494// being TYPE_DOUBLEs. Dates are converted to a string (which can then be
495// parsed into a base::Time), as are regexps. Arrays are converted into lists,
[email protected]81f9fe0b2010-12-07 00:35:29496// recursively. We don't deal with binary objects or functions - they become
497// null values.
498static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) {
499 if (v8value->IsBoolean()) {
500 return Value::CreateBooleanValue(v8value->BooleanValue());
501 } else if (v8value->IsInt32()) {
502 return Value::CreateIntegerValue(v8value->Int32Value());
503 } else if (v8value->IsNumber()) {
[email protected]fb534c92011-02-01 01:02:07504 return Value::CreateDoubleValue(v8value->NumberValue());
[email protected]81f9fe0b2010-12-07 00:35:29505 } else if (v8value->IsString()) {
506 return Value::CreateStringValue(*v8::String::Utf8Value(v8value));
507 } else if (v8value->IsDate()) {
508 v8::Date* date = v8::Date::Cast(*v8value);
[email protected]fb534c92011-02-01 01:02:07509 return Value::CreateDoubleValue(date->NumberValue() / 1000.0);
[email protected]81f9fe0b2010-12-07 00:35:29510 } else if (v8value->IsRegExp()) {
511 return Value::CreateStringValue(
512 *v8::String::Utf8Value(v8value->ToString()));
513 } else if (v8value->IsArray()) {
514 v8::Array* array = v8::Array::Cast(*v8value);
515 uint32_t length = array->Length();
516 scoped_ptr<ListValue> list(new ListValue);
517 for (uint32_t i = 0 ; i < length ; ++i) {
518 list->Set(i, ConvertV8Value(array->Get(i)));
519 }
520 return list.release();
521 }
522 return Value::CreateNullValue();
523}
524
initial.commit09911bf2008-07-26 23:55:29525///////////////////////////////////////////////////////////////////////////////
526
[email protected]60c42a8c72009-10-09 04:08:59527int32 RenderView::next_page_id_ = 1;
528
[email protected]cdaf8d02010-03-30 19:52:47529struct RenderView::PendingFileChooser {
530 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
531 WebFileChooserCompletion* c)
532 : params(p),
533 completion(c) {
534 }
535 ViewHostMsg_RunFileChooser_Params params;
536 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
537};
538
[email protected]2fab253a2009-08-17 23:00:59539RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51540 gfx::NativeViewId parent_hwnd,
541 int32 opener_id,
542 const RendererPreferences& renderer_prefs,
543 const WebPreferences& webkit_prefs,
544 SharedRenderViewCounter* counter,
545 int32 routing_id,
546 int64 session_storage_namespace_id,
547 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12548 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51549 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02550 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09551 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02552 send_preferred_size_changes_(false),
553 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24554 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21555 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02556 opened_by_user_gesture_(true),
557 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24558 page_id_(-1),
559 last_page_id_sent_to_browser_(-1),
560 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00561 history_list_offset_(-1),
562 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24563 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55564#if defined(OS_MACOSX)
565 has_document_tag_(false),
566#endif
[email protected]98324892009-09-09 21:16:05567 document_tag_(0),
[email protected]3354d3e2010-06-10 19:53:02568 target_url_status_(TARGET_NONE),
569 spelling_panel_visible_(false),
570 view_type_(ViewType::INVALID),
571 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18572 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30573 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
[email protected]54ec7f82010-10-21 22:32:51574 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02575 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51576 devtools_client_(NULL),
577 geolocation_dispatcher_(NULL),
578 speech_input_dispatcher_(NULL),
579 device_orientation_dispatcher_(NULL),
[email protected]dec1f292011-02-11 20:20:20580 print_helper_(NULL),
[email protected]54ec7f82010-10-21 22:32:51581 accessibility_ack_pending_(false),
[email protected]bb461532010-11-26 21:50:23582 pending_app_icon_requests_(0),
[email protected]5ee0cfd02011-01-18 05:42:22583 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]8de12d942010-11-17 20:42:44584#if defined(OS_MACOSX)
585 // On Mac, the select popups are rendered by the browser.
586 // Note that we don't do this in RenderMain otherwise this would not be called
587 // in single-process mode.
588 WebKit::WebView::setUseExternalPopupMenus(true);
589#endif
[email protected]676126f72011-01-15 00:03:51590
[email protected]71b0d5d2010-02-15 05:43:07591 ClearBlockedContentSettings();
[email protected]676126f72011-01-15 00:03:51592
593 routing_id_ = routing_id;
594 if (opener_id != MSG_ROUTING_NONE)
595 opener_id_ = opener_id;
596
597 if (counter) {
598 shared_popup_counter_ = counter;
599 shared_popup_counter_->data++;
600 decrement_shared_popup_at_destruction_ = true;
601 } else {
602 shared_popup_counter_ = new SharedRenderViewCounter(0);
603 decrement_shared_popup_at_destruction_ = false;
604 }
605
606 notification_provider_ = new NotificationProvider(this);
607
608 devtools_agent_ = new DevToolsAgent(this);
[email protected]78192082011-01-29 05:43:44609 PasswordAutoFillManager* password_autofill_manager =
610 new PasswordAutoFillManager(this);
611 AutoFillAgent* autofill_agent = new AutoFillAgent(this,
612 password_autofill_manager);
[email protected]676126f72011-01-15 00:03:51613
[email protected]78192082011-01-29 05:43:44614 webwidget_ = WebView::create(this, devtools_agent_, autofill_agent);
[email protected]676126f72011-01-15 00:03:51615 g_view_map.Get().insert(std::make_pair(webview(), this));
616 webkit_preferences_.Apply(webview());
617 webview()->initializeMainFrame(this);
618 if (!frame_name.empty())
619 webview()->mainFrame()->setName(frame_name);
620
621 OnSetRendererPrefs(renderer_prefs);
622
623 render_thread_->AddRoute(routing_id_, this);
624 // Take a reference on behalf of the RenderThread. This will be balanced
625 // when we receive ViewMsg_Close.
626 AddRef();
627
628 // If this is a popup, we must wait for the CreatingNew_ACK message before
629 // completing initialization. Otherwise, we can finish it now.
630 if (opener_id == MSG_ROUTING_NONE) {
631 did_show_ = true;
632 CompleteInit(parent_hwnd);
633 }
634
635 host_window_ = parent_hwnd;
636
637 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
638 if (command_line.HasSwitch(switches::kDomAutomationController))
639 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
640 if (command_line.HasSwitch(switches::kEnableAccessibility))
641 WebAccessibilityCache::enableAccessibility();
642
643 audio_message_filter_ = new AudioMessageFilter(routing_id_);
644 render_thread_->AddFilter(audio_message_filter_);
645
646 PageClickTracker* page_click_tracker = new PageClickTracker(this);
647 // Note that the order of insertion of the listeners is important.
648 // The password_autocomplete_manager takes the first shot at processing the
649 // notification and can stop the propagation.
[email protected]78192082011-01-29 05:43:44650 page_click_tracker->AddListener(password_autofill_manager);
651 page_click_tracker->AddListener(autofill_agent);
[email protected]81273622011-02-02 03:56:13652 new TranslateHelper(this);
[email protected]dec1f292011-02-11 20:20:20653 print_helper_ = new PrintWebViewHelper(this);
[email protected]28685da92011-02-07 21:49:17654
655 if (CommandLine::ForCurrentProcess()->HasSwitch(
656 switches::kEnableClientSidePhishingDetection)) {
657 new safe_browsing::PhishingClassifierDelegate(this, NULL);
658 }
initial.commit09911bf2008-07-26 23:55:29659}
660
661RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08662 if (decrement_shared_popup_at_destruction_)
663 shared_popup_counter_->data--;
664
[email protected]a1128322009-10-06 18:38:46665 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47666 while (!file_chooser_completions_.empty()) {
667 if (file_chooser_completions_.front()->completion) {
668 file_chooser_completions_.front()->completion->didChooseFile(
669 WebVector<WebString>());
670 }
671 file_chooser_completions_.pop_front();
672 }
[email protected]a1128322009-10-06 18:38:46673
[email protected]83dde542009-09-11 20:59:55674#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05675 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55676 if (has_document_tag_)
677 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
[email protected]c36a9b62010-10-14 00:41:11678
679 // Destroy all fake plugin window handles on the browser side.
680 while (!fake_plugin_window_handles_.empty()) {
681 // Make sure no NULL plugin window handles were inserted into this list.
682 DCHECK(*fake_plugin_window_handles_.begin());
683 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
684 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
685 }
[email protected]83dde542009-09-11 20:59:55686#endif
[email protected]98324892009-09-09 21:16:05687
[email protected]5fb88962009-04-16 19:03:25688 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59689
690#ifndef NDEBUG
691 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49692 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59693 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
694 DCHECK_NE(this, it->second) << "Failed to call Close?";
695#endif
[email protected]676126f72011-01-15 00:03:51696
697 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
698 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59699}
700
701/*static*/
702void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49703 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59704 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
705 if (!visitor->Visit(it->second))
706 return;
707 }
708}
709
710/*static*/
711RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49712 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59713 ViewMap::iterator it = views->find(webview);
714 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29715}
716
717/*static*/
[email protected]0aa55312008-10-17 21:53:08718RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24719 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15720 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08721 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51722 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08723 const WebPreferences& webkit_prefs,
724 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34725 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26726 int64 session_storage_namespace_id,
727 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29728 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51729 return new RenderView(
730 render_thread,
731 parent_hwnd,
732 opener_id,
733 renderer_prefs,
734 webkit_prefs,
735 counter,
736 routing_id,
737 session_storage_namespace_id,
738 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29739}
740
[email protected]bb461532010-11-26 21:50:23741// static
initial.commit09911bf2008-07-26 23:55:29742void RenderView::SetNextPageID(int32 next_page_id) {
743 // This method should only be called during process startup, and the given
744 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05745 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29746 DCHECK(next_page_id >= next_page_id_);
747 next_page_id_ = next_page_id;
748}
749
[email protected]676126f72011-01-15 00:03:51750void RenderView::AddObserver(RenderViewObserver* observer) {
751 observers_.AddObserver(observer);
752}
753
754void RenderView::RemoveObserver(RenderViewObserver* observer) {
755 observer->set_render_view(NULL);
756 observers_.RemoveObserver(observer);
757}
758
[email protected]70eee342010-11-05 01:59:37759bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
760 typedef ViewHostMsg_AccessibilityNotification_Params params;
[email protected]a527a022011-02-10 02:32:36761 if (type == WebKit::WebAccessibilityNotificationChildrenChanged ||
762 type == WebKit::WebAccessibilityNotificationLoadComplete) {
[email protected]70eee342010-11-05 01:59:37763 return true;
764 }
765 return false;
766}
767
[email protected]8a3125a712010-08-09 18:58:51768WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26769 return static_cast<WebKit::WebView*>(webwidget());
770}
771
[email protected]afe3a1672009-11-17 19:04:12772void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]15d04ae2010-10-30 01:04:50773 Send(new ViewHostMsg_UserMetricsRecordAction(action));
[email protected]1dbafaf72009-09-23 19:43:56774}
775
[email protected]bb461532010-11-26 21:50:23776bool RenderView::InstallWebApplicationUsingDefinitionFile(WebFrame* frame,
777 string16* error) {
778 // There is an issue of drive-by installs with the below implementation. A web
779 // site could force a user to install an app by timing the dialog to come up
780 // just before the user clicks.
781 //
782 // We do show a success UI that allows users to uninstall, but it seems that
783 // we might still want to put up an infobar before showing the install dialog.
784 //
785 // TODO(aa): Figure out this issue before removing the kEnableCrxlessWebApps
786 // switch.
787 if (!CommandLine::ForCurrentProcess()->HasSwitch(
788 switches::kEnableCrxlessWebApps)) {
789 *error = ASCIIToUTF16("CRX-less web apps aren't enabled.");
790 return false;
791 }
792
793 if (frame != frame->top()) {
794 *error = ASCIIToUTF16("Applications can only be installed from the top "
795 "frame.");
796 return false;
797 }
798
799 if (pending_app_info_.get()) {
800 *error = ASCIIToUTF16("An application install is already in progress.");
801 return false;
802 }
803
804 pending_app_info_.reset(new WebApplicationInfo());
805 if (!web_apps::ParseWebAppFromWebDocument(frame, pending_app_info_.get(),
806 error)) {
807 return false;
808 }
809
810 if (!pending_app_info_->manifest_url.is_valid()) {
811 *error = ASCIIToUTF16("Web application definition not found or invalid.");
812 return false;
813 }
814
815 app_definition_fetcher_.reset(new ResourceFetcher(
816 pending_app_info_->manifest_url, webview()->mainFrame(),
817 NewCallback(this, &RenderView::DidDownloadApplicationDefinition)));
818 return true;
819}
820
[email protected]1a3c3cb2010-12-16 21:03:40821void RenderView::SetReportLoadProgressEnabled(bool enabled) {
822 if (!enabled) {
823 load_progress_tracker_.reset(NULL);
824 return;
825 }
826 if (load_progress_tracker_ == NULL)
827 load_progress_tracker_.reset(new LoadProgressTracker(this));
828}
829
[email protected]bb461532010-11-26 21:50:23830void RenderView::DidDownloadApplicationDefinition(
831 const WebKit::WebURLResponse& response,
832 const std::string& data) {
833 scoped_ptr<WebApplicationInfo> app_info(
834 pending_app_info_.release());
835
836 JSONStringValueSerializer serializer(data);
837 int error_code = 0;
838 std::string error_message;
839 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message));
840 if (!result.get()) {
841 AddErrorToRootConsole(UTF8ToUTF16(error_message));
842 return;
843 }
844
845 string16 error_message_16;
846 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(),
847 &error_message_16)) {
848 AddErrorToRootConsole(error_message_16);
849 return;
850 }
851
852 if (!app_info->icons.empty()) {
853 pending_app_info_.reset(app_info.release());
854 pending_app_icon_requests_ =
855 static_cast<int>(pending_app_info_->icons.size());
856 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
857 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
858 new ImageResourceFetcher(
859 pending_app_info_->icons[i].url,
860 webview()->mainFrame(),
861 static_cast<int>(i),
862 pending_app_info_->icons[i].width,
863 NewCallback(this, &RenderView::DidDownloadApplicationIcon))));
864 }
865 } else {
866 Send(new ViewHostMsg_InstallApplication(routing_id_, *app_info));
867 }
868}
869
870void RenderView::DidDownloadApplicationIcon(ImageResourceFetcher* fetcher,
871 const SkBitmap& image) {
872 pending_app_info_->icons[fetcher->id()].data = image;
873
874 // Remove the image fetcher from our pending list. We're in the callback from
875 // ImageResourceFetcher, best to delay deletion.
876 for (ImageResourceFetcherList::iterator iter = app_icon_fetchers_.begin();
877 iter != app_icon_fetchers_.end(); ++iter) {
878 if (iter->get() == fetcher) {
879 iter->release();
880 app_icon_fetchers_.erase(iter);
881 break;
882 }
883 }
884
885 // We're in the callback from the ImageResourceFetcher, best to delay
886 // deletion.
887 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
888
889 if (--pending_app_icon_requests_ > 0)
890 return;
891
892 // There is a maximum size of IPC on OS X and Linux that we have run into in
893 // some situations. We're not sure what it is, but our hypothesis is in the
894 // neighborhood of 1 MB.
895 //
896 // To be on the safe side, we give ourselves 128 KB for just the image data.
897 // This should be more than enough for 128, 48, and 16 px 32-bit icons. If we
898 // want to start allowing larger icons (see bug 63406), we'll have to either
899 // experiment mor ewith this and find the real limit, or else come up with
900 // some alternative way to transmit the icon data to the browser process.
901 //
902 // See also: bug 63729.
[email protected]678a7d72011-01-05 20:37:32903 const size_t kMaxIconSize = 1024 * 128;
904 size_t actual_icon_size = 0;
[email protected]bb461532010-11-26 21:50:23905 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
[email protected]678a7d72011-01-05 20:37:32906 size_t current_size = pending_app_info_->icons[i].data.getSize();
907 if (current_size > kMaxIconSize - actual_icon_size) {
908 AddErrorToRootConsole(ASCIIToUTF16(
[email protected]bb461532010-11-26 21:50:23909 "Icons are too large. Maximum total size for app icons is 128 KB."));
[email protected]678a7d72011-01-05 20:37:32910 return;
911 }
912 actual_icon_size += current_size;
[email protected]bb461532010-11-26 21:50:23913 }
914
915 Send(new ViewHostMsg_InstallApplication(routing_id_, *pending_app_info_));
916 pending_app_info_.reset(NULL);
917}
918
[email protected]a3a8fb6d2009-10-22 20:12:51919void RenderView::PluginCrashed(const FilePath& plugin_path) {
920 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29921}
922
[email protected]aad51d1c2010-08-05 08:38:09923WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
924 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50925 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26926 bool found;
927 ContentSetting setting;
928 std::string mime_type;
929 Send(new ViewHostMsg_GetPluginInfo(
[email protected]c8f73ab2011-01-22 00:05:17930 routing_id_, params.url, frame->top()->url(), params.mimeType.utf8(),
931 &found, &info, &setting, &mime_type));
[email protected]b83ff222011-01-24 17:37:12932 if (!found || !webkit::npapi::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09933 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45934
[email protected]0bd753682010-12-16 18:15:52935 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:45936 pepper_delegate_.CreatePepperPlugin(info.path));
[email protected]aad51d1c2010-08-05 08:38:09937 if (pepper_module)
[email protected]6fdd4182010-10-14 23:59:26938 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]1a78d9f32010-12-08 06:38:45939 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09940}
941
[email protected]d8fd6fa2010-02-01 15:54:26942void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
943 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30944 // If the renderer is visible, set initial visibility and focus state.
945 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34946#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30947 delegate->SetContainerVisibility(true);
948 if (webview() && webview()->isActive())
949 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34950#endif
[email protected]49232292010-09-03 19:07:30951 }
[email protected]784ea1ab2010-09-18 00:02:34952 // Plugins start assuming the content has focus (so that they work in
953 // environments where RenderView isn't hosting them), so we always have to
954 // set the initial state. See webplugin_delegate_impl.h for details.
955 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26956}
957
958void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
959 plugin_delegates_.erase(delegate);
960}
[email protected]d8fd6fa2010-02-01 15:54:26961
[email protected]a95986a82010-12-24 06:19:28962bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27963 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27964 if (main_frame)
965 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26966
[email protected]676126f72011-01-15 00:03:51967 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
968 RenderViewObserver* observer;
969 while ((observer = it.GetNext()) != NULL)
970 if (observer->OnMessageReceived(message))
971 return true;
[email protected]b2abac72009-02-26 12:39:28972
[email protected]a95986a82010-12-24 06:19:28973 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29974 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04975 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
976 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29977 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
978 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56979 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29980 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
981 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
982 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
983 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27984#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35985 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27986#endif
initial.commit09911bf2008-07-26 23:55:29987 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
988 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05989 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
990 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
991 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04992 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29993 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
994 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
995 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15996 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29997 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49998 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
999 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:171000 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:541001 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
1002 OnSetContentSettingsForLoadingURL)
[email protected]d0b8d092010-10-25 04:05:171003 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:541004 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1005 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291006 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181007 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1008 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:281009 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:331010 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:291011 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:481012 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:291013 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:291014 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:291015 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
1016 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
1017 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
1018 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:451019 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291020 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:501021 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
1022 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:291023 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
1024 OnDragSourceSystemDragEnded)
1025 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:511026 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
1027 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:291028 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1029 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1030 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1031 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]90dba072011-01-20 20:10:201032 IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage,
1033 OnDisplayPrerenderedPage)
initial.commit09911bf2008-07-26 23:55:291034 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1035 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:291036 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1037 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:041038 IPC_MESSAGE_HANDLER(
1039 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1040 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:291041 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:041042 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:291043 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1044 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:451045 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:041046 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:081047 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1048 OnDisassociateFromPopupCount)
[email protected]e8345242010-05-06 03:00:401049 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
1050 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:001051 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:271052 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:371053 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
1054 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:161055 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141056 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251057 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1058 OnEnablePreferredSizeChangedMode)
[email protected]ce833282010-11-04 15:48:391059 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxChange, OnSearchBoxChange)
1060 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxSubmit, OnSearchBoxSubmit)
1061 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxCancel, OnSearchBoxCancel)
1062 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxResize, OnSearchBoxResize)
1063 IPC_MESSAGE_HANDLER(ViewMsg_DetermineIfPageSupportsInstant,
1064 OnDetermineIfPageSupportsInstant)
[email protected]cda45c02010-02-25 19:28:101065 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1066 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511067 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:531068 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
1069 OnUpdateBrowserWindowId)
1070 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
1071 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:561072 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:341073 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:141074#if defined(OS_MACOSX)
1075 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:131076 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:131077 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1078 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:141079#endif
[email protected]446705872009-09-10 07:22:481080 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331081 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:351082 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
1083 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:331084 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1085 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:141086 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:361087 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
1088 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
1089 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:421090 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
1091 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:241092 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]caf706f2010-10-26 17:54:081093#if defined(OS_MACOSX)
1094 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1095#endif
[email protected]a6097f42011-01-10 08:50:511096 IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl,
1097 OnJavaScriptStressTestControl)
[email protected]521b2482011-01-15 00:10:101098 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]634a6f92008-12-01 21:39:311099
[email protected]f0557932011-01-25 20:20:511100 // TODO(viettrungluu): Move to a separate message filter.
1101#if defined(ENABLE_FLAPPER_HACKS)
1102 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
1103#endif
1104
initial.commit09911bf2008-07-26 23:55:291105 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281106 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291107 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281108 return handled;
initial.commit09911bf2008-07-26 23:55:291109}
1110
[email protected]9b18a84f2010-06-10 15:54:041111void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:271112 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291113 if (!main_frame)
1114 return;
1115
1116 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:451117 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291118 if (url.is_empty())
1119 return;
1120
1121 if (size_.IsEmpty())
1122 return; // Don't create an empty thumbnail!
1123
1124 ThumbnailScore score;
1125 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:021126 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:151127 &thumbnail, &score))
1128 return;
1129
initial.commit09911bf2008-07-26 23:55:291130 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:461131 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:291132}
1133
[email protected]9b18a84f2010-06-10 15:54:041134void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:231135 SkBitmap snapshot;
1136 bool error = false;
1137
1138 WebFrame* main_frame = webview()->mainFrame();
1139 if (!main_frame)
1140 error = true;
1141
1142 if (!error && !CaptureSnapshot(webview(), &snapshot))
1143 error = true;
1144
1145 DCHECK(error == snapshot.empty()) <<
1146 "Snapshot should be empty on error, non-empty otherwise.";
1147
1148 // Send the snapshot to the browser process.
1149 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
1150}
1151
initial.commit09911bf2008-07-26 23:55:291152void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
1153 if (load_id != page_id_)
1154 return; // this capture call is no longer relevant due to navigation
1155 if (load_id == last_indexed_page_id_)
1156 return; // we already indexed this page
1157
1158 if (!webview())
1159 return;
1160
[email protected]26aa0482009-09-30 16:55:271161 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291162 if (!main_frame)
1163 return;
1164
1165 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:451166 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:291167 return;
1168
1169 // Don't index/capture pages that failed to load. This only checks the top
1170 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:451171 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:281172 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:291173 return;
1174
1175 if (!preliminary_capture)
1176 last_indexed_page_id_ = load_id;
1177
[email protected]a8a81292010-01-21 00:32:451178 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:451179 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291180 if (url.is_empty())
1181 return;
1182
[email protected]a8a81292010-01-21 00:32:451183 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:361184 string16 contents;
initial.commit09911bf2008-07-26 23:55:291185 CaptureText(main_frame, &contents);
1186 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:101187 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:371188 // If the page explicitly specifies a language, use it, otherwise we'll
1189 // determine it based on the text content using the CLD.
1190 std::string language =
1191 TranslateHelper::GetPageLanguageFromMetaTag(&document);
1192 if (language.empty()) {
1193 base::TimeTicks begin_time = base::TimeTicks::Now();
1194 language = DetermineTextLanguage(contents);
1195 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
1196 base::TimeTicks::Now() - begin_time);
1197 }
[email protected]a8a81292010-01-21 00:32:451198 // Send the text to the browser for indexing (the browser might decide not
1199 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:371200 Send(new ViewHostMsg_PageContents(
1201 routing_id_, url, load_id, contents, language,
1202 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:271203 }
1204
[email protected]d54169e92011-01-21 09:19:521205 // Generate the thumbnail here if the in-browser thumbnailing isn't
1206 // enabled. TODO(satorux): Remove this and related code once
1207 // crbug.com/65936 is complete.
1208 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1209 switches::kEnableInBrowserThumbnailing)) {
1210 OnCaptureThumbnail();
1211 }
[email protected]3ead1322010-11-19 20:01:001212
[email protected]28685da92011-02-07 21:49:171213 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PageCaptured(contents));
initial.commit09911bf2008-07-26 23:55:291214}
1215
[email protected]e5106202010-06-11 21:12:361216void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:291217 contents->clear();
1218 if (!frame)
1219 return;
1220
1221#ifdef TIME_TEXT_RETRIEVAL
1222 double begin = time_util::GetHighResolutionTimeNow();
1223#endif
1224
1225 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:361226 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:291227
1228#ifdef TIME_TEXT_RETRIEVAL
1229 double end = time_util::GetHighResolutionTimeNow();
1230 char buf[128];
1231 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
1232 contents.size(), (end - begin)*1000);
1233 OutputDebugStringA(buf);
1234#endif
1235
1236 // When the contents are clipped to the maximum, we don't want to have a
1237 // partial word indexed at the end that might have been clipped. Therefore,
1238 // terminate the string at the last space to ensure no words are clipped.
1239 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:361240 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:291241 if (last_space_index == std::wstring::npos)
1242 return; // don't index if we got a huge block of text with no spaces
1243 contents->resize(last_space_index);
1244 }
1245}
1246
[email protected]8649fb32009-06-26 17:51:021247bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:291248 int w,
1249 int h,
1250 SkBitmap* thumbnail,
1251 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:231252 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:151253
[email protected]8649fb32009-06-26 17:51:021254 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:231255
1256 // Paint |view| into |canvas|.
1257 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:021258 return false;
[email protected]8649fb32009-06-26 17:51:021259
1260 skia::BitmapPlatformDevice& device =
1261 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1262
1263 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:291264
[email protected]cab34d6a2009-09-24 01:14:521265 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:291266 float dest_aspect = dest_rect.width() / dest_rect.height();
1267
1268 // Get the src rect so that we can preserve the aspect ratio while filling
1269 // the destination.
1270 SkIRect src_rect;
1271 if (src_bmp.width() < dest_rect.width() ||
1272 src_bmp.height() < dest_rect.height()) {
1273 // Source image is smaller: we clip the part of source image within the
1274 // dest rect, and then stretch it to fill the dest rect. We don't respect
1275 // the aspect ratio in this case.
1276 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
1277 static_cast<S16CPU>(dest_rect.height()));
1278 score->good_clipping = false;
1279 } else {
1280 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1281 if (src_aspect > dest_aspect) {
1282 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1283 // the wider screen.
1284 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1285 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1286 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1287 score->good_clipping = false;
1288 } else {
1289 src_rect.set(0, 0, src_bmp.width(),
1290 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1291 score->good_clipping = true;
1292 }
1293 }
1294
[email protected]26aa0482009-09-30 16:55:271295 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291296
1297 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021298 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291299
[email protected]82afe4b2010-11-12 20:36:221300 // First do a fast downsample by powers of two to get close to the final size.
1301 SkBitmap downsampled_subset =
1302 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h);
1303
1304 // Do a high-quality resize from the downscaled size to the final size.
[email protected]465b34b72008-12-12 20:19:141305 *thumbnail = skia::ImageOperations::Resize(
[email protected]82afe4b2010-11-12 20:36:221306 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291307
1308 score->boring_score = CalculateBoringScore(thumbnail);
1309
[email protected]30507922010-01-15 16:48:231310 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1311 base::TimeTicks::Now() - beginning_time);
[email protected]82afe4b2010-11-12 20:36:221312
[email protected]b6e4bec2008-11-12 01:17:151313 return true;
initial.commit09911bf2008-07-26 23:55:291314}
1315
[email protected]30507922010-01-15 16:48:231316bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1317 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291318
[email protected]30507922010-01-15 16:48:231319 skia::PlatformCanvas canvas;
1320 if (!PaintViewIntoCanvas(view, canvas))
1321 return false;
1322
1323 skia::BitmapPlatformDevice& device =
1324 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1325
1326 const SkBitmap& bitmap = device.accessBitmap(false);
1327 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1328 return false;
1329
1330 HISTOGRAM_TIMES("Renderer4.Snapshot",
1331 base::TimeTicks::Now() - beginning_time);
1332 return true;
initial.commit09911bf2008-07-26 23:55:291333}
1334
1335void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1336 if (!webview())
1337 return;
1338
[email protected]3cc72b12010-03-18 23:03:001339 history_list_offset_ = params.current_history_list_offset;
1340 history_list_length_ = params.current_history_list_length;
1341
[email protected]a9f607e2009-10-23 19:59:271342 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261343
initial.commit09911bf2008-07-26 23:55:291344 AboutHandler::MaybeHandle(params.url);
1345
[email protected]ecbf10d2010-02-18 13:03:291346 bool is_reload =
1347 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1348 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291349
[email protected]26aa0482009-09-30 16:55:271350 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451351 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291352 // We cannot reload if we do not have any history state. This happens, for
1353 // example, when recovering from a crash. Our workaround here is a bit of
1354 // a hack since it means that reload after a crashed tab does not cause an
1355 // end-to-end cache validation.
1356 is_reload = false;
1357 }
1358
[email protected]77f17a82009-05-21 04:42:541359 // A navigation resulting from loading a javascript URL should not be treated
1360 // as a browser initiated event. Instead, we want it to look as if the page
1361 // initiated any load resulting from JS execution.
1362 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301363 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001364 params.page_id,
1365 params.pending_history_list_offset,
1366 params.transition,
1367 params.request_time);
[email protected]5e369672009-11-03 23:48:301368 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1369 // We're doing a load of a page that was restored from the last session.
1370 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1371 // which can result in stale data for pages that are set to expire. We
1372 // explicitly override that by setting the policy here so that as
1373 // necessary we load from the network.
1374 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1375 }
1376 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541377 }
initial.commit09911bf2008-07-26 23:55:291378
[email protected]a7ccc4d2010-01-27 08:14:481379 NavigationState* navigation_state = pending_navigation_state_.get();
1380
[email protected]04d3c6e2009-05-22 17:00:131381 // If we are reloading, then WebKit will use the history state of the current
1382 // page, so we should just ignore any given history state. Otherwise, if we
1383 // have history state, then we need to navigate to it, which corresponds to a
1384 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551385 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481386 if (navigation_state)
1387 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291388 bool ignore_cache = (params.navigation_type ==
1389 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1390 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551391 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131392 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581393 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481394 if (navigation_state)
1395 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451396 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171397 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131398 } else {
1399 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281400 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291401
[email protected]e6f546c32009-07-01 17:12:551402 // A session history navigation should have been accompanied by state.
1403 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131404
[email protected]dd7daa82009-08-10 05:46:451405 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551406 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131407
[email protected]726985e22009-06-18 21:09:281408 if (params.referrer.is_valid()) {
1409 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1410 WebString::fromUTF8(params.referrer.spec()));
1411 }
[email protected]04d3c6e2009-05-22 17:00:131412
[email protected]52c68652010-12-07 17:47:041413 if (!params.extra_headers.empty()) {
1414 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1415 params.extra_headers.end(), "\n");
1416 i.GetNext(); ) {
1417 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1418 WebString::fromUTF8(i.values()));
1419 }
1420 }
1421
[email protected]90dba072011-01-20 20:10:201422 if (navigation_state) {
1423 if (params.navigation_type != ViewMsg_Navigate_Params::PRERENDER) {
1424 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
1425 } else {
1426 navigation_state->set_load_type(NavigationState::PRERENDER_LOAD);
1427 navigation_state->set_is_prerendering(true);
1428 }
1429 }
[email protected]dd7daa82009-08-10 05:46:451430 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501431 }
1432
[email protected]77f17a82009-05-21 04:42:541433 // In case LoadRequest failed before DidCreateDataSource was called.
1434 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291435}
1436
1437// Stop loading the current page
1438void RenderView::OnStop() {
1439 if (webview())
[email protected]b4bb2502009-10-01 22:35:271440 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291441}
1442
[email protected]ecbf10d2010-02-18 13:03:291443// Reload current focused frame.
1444// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561445void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291446 if (webview() && webview()->focusedFrame()) {
1447 // We always obey the cache (ignore_cache=false) here.
1448 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1449 // a cache-ignoring reload of the frame.
1450 webview()->focusedFrame()->reload(false);
1451 }
[email protected]1dda4022010-01-28 18:24:561452}
1453
initial.commit09911bf2008-07-26 23:55:291454void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271455 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291456}
1457
[email protected]68b1e922009-06-23 16:00:251458void RenderView::OnExecuteEditCommand(const std::string& name,
1459 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271460 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251461 return;
1462
[email protected]26aa0482009-09-30 16:55:271463 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451464 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251465}
1466
[email protected]b2abac72009-02-26 12:39:281467void RenderView::OnSetupDevToolsClient() {
[email protected]676126f72011-01-15 00:03:511468 DCHECK(!devtools_client_);
1469 devtools_client_ = new DevToolsClient(this);
[email protected]b2abac72009-02-26 12:39:281470}
1471
initial.commit09911bf2008-07-26 23:55:291472void RenderView::OnUpdateTargetURLAck() {
1473 // Check if there is a targeturl waiting to be sent.
1474 if (target_url_status_ == TARGET_PENDING) {
1475 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1476 pending_target_url_));
1477 }
1478
1479 target_url_status_ = TARGET_NONE;
1480}
1481
1482void RenderView::OnUndo() {
1483 if (!webview())
1484 return;
1485
[email protected]26aa0482009-09-30 16:55:271486 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121487 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291488}
1489
1490void RenderView::OnRedo() {
1491 if (!webview())
1492 return;
1493
[email protected]26aa0482009-09-30 16:55:271494 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121495 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291496}
1497
1498void RenderView::OnCut() {
1499 if (!webview())
1500 return;
1501
[email protected]26aa0482009-09-30 16:55:271502 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121503 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291504}
1505
1506void RenderView::OnCopy() {
1507 if (!webview())
1508 return;
1509
[email protected]26aa0482009-09-30 16:55:271510 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121511 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291512}
1513
[email protected]c0cc3092009-09-12 08:27:271514#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351515void RenderView::OnCopyToFindPboard() {
1516 if (!webview())
1517 return;
1518
1519 // Since the find pasteboard supports only plain text, this can be simpler
1520 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271521 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351522 if (frame->hasSelection()) {
1523 string16 selection = frame->selectionAsText();
1524 RenderThread::current()->Send(
1525 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1526 }
1527
[email protected]afe3a1672009-11-17 19:04:121528 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351529}
[email protected]c0cc3092009-09-12 08:27:271530#endif
[email protected]a954bf72009-09-12 07:30:351531
initial.commit09911bf2008-07-26 23:55:291532void RenderView::OnPaste() {
1533 if (!webview())
1534 return;
1535
[email protected]26aa0482009-09-30 16:55:271536 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121537 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291538}
1539
[email protected]2a3a7762009-10-19 19:17:321540void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291541 if (!webview())
1542 return;
1543
[email protected]1ff7a032010-02-03 02:46:031544 WebFrame* frame = webview()->focusedFrame();
1545 if (!frame->hasSelection())
1546 frame->selectWordAroundCaret();
1547 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291548}
1549
[email protected]98324892009-09-09 21:16:051550void RenderView::OnAdvanceToNextMisspelling() {
1551 if (!webview())
1552 return;
[email protected]26aa0482009-09-30 16:55:271553 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051554 WebString::fromUTF8("AdvanceToNextMisspelling"));
1555}
1556
1557void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1558 if (!webview())
1559 return;
1560 // We need to tell the webView whether the spelling panel is visible or not so
1561 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261562 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271563 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051564 WebString::fromUTF8("ToggleSpellPanel"));
1565}
1566
[email protected]bbbd545c2008-12-15 20:18:041567void RenderView::OnToggleSpellCheck() {
1568 if (!webview())
1569 return;
1570
[email protected]26aa0482009-09-30 16:55:271571 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451572 frame->enableContinuousSpellChecking(
1573 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041574}
1575
initial.commit09911bf2008-07-26 23:55:291576void RenderView::OnDelete() {
1577 if (!webview())
1578 return;
1579
[email protected]26aa0482009-09-30 16:55:271580 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121581 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291582}
1583
1584void RenderView::OnSelectAll() {
1585 if (!webview())
1586 return;
1587
[email protected]26aa0482009-09-30 16:55:271588 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221589 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121590 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291591}
1592
1593void RenderView::OnSetInitialFocus(bool reverse) {
1594 if (!webview())
1595 return;
[email protected]26aa0482009-09-30 16:55:271596 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291597}
1598
[email protected]9b66f34bf2010-10-27 20:45:511599void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:091600 WebKit::WebNode node = GetFocusedNode();
1601 if (!node.isNull()) {
1602 if (IsEditableNode(node))
1603 // TODO(varunjain): Change webkit API to scroll a particular node into
1604 // view and use that API here instead.
1605 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:511606 }
1607}
1608
initial.commit09911bf2008-07-26 23:55:291609///////////////////////////////////////////////////////////////////////////////
1610
[email protected]433819d2010-01-30 20:20:011611void RenderView::SetContentSettings(const ContentSettings& settings) {
1612 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011613}
1614
initial.commit09911bf2008-07-26 23:55:291615// Tell the embedding application that the URL of the active page has changed
1616void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451617 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291618 DCHECK(ds);
1619
[email protected]726985e22009-06-18 21:09:281620 const WebURLRequest& request = ds->request();
1621 const WebURLRequest& original_request = ds->originalRequest();
1622 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291623
[email protected]daa8c58e2009-06-15 17:21:101624 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1625 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291626
1627 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281628 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291629 params.is_post = false;
1630 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071631 params.frame_id = frame->identifier();
[email protected]726985e22009-06-18 21:09:281632 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091633 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551634 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291635 // SSL state specified in the request takes precedence over the one in the
1636 // response.
1637 // So far this is only intended for error pages that are not expected to be
1638 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281639 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551640 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291641 } else {
[email protected]726985e22009-06-18 21:09:281642 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291643 }
1644
1645 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281646 if (ds->hasUnreachableURL()) {
1647 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291648 } else {
[email protected]726985e22009-06-18 21:09:281649 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291650 }
1651
[email protected]726985e22009-06-18 21:09:281652 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241653 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041654 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291655
[email protected]ce0e250d2009-10-23 21:00:351656 params.searchable_form_url = navigation_state->searchable_form_url();
1657 params.searchable_form_encoding =
1658 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291659
1660 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101661 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291662 if (password_form_data)
1663 params.password_form = *password_form_data;
1664
1665 params.gesture = navigation_gesture_;
1666 navigation_gesture_ = NavigationGestureUnknown;
1667
[email protected]dd7daa82009-08-10 05:46:451668 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291669 // Top-level navigation.
1670
[email protected]71b0d5d2010-02-15 05:43:071671 // Clear "block" flags for the new page. This needs to happen before any of
1672 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1673 // so that these functions can correctly detect that a piece of content
1674 // flipped from "not blocked" to "blocked".
1675 ClearBlockedContentSettings();
1676
[email protected]62d2a112010-04-07 00:53:021677 // Set content settings. Default them from the parent window if one exists.
1678 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011679 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541680 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011681 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011682 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011683
1684 // These content settings were merely recorded transiently for this load.
1685 // We can erase them now. If at some point we reload this page, the
1686 // browser will send us new, up-to-date content settings.
1687 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401688 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101689 // The opener's view is not guaranteed to be non-null (it could be
1690 // detached from its page but not yet destructed).
1691 if (WebView* opener_view = frame->opener()->view()) {
1692 RenderView* opener = FromWebView(opener_view);
1693 SetContentSettings(opener->current_content_settings_);
1694 }
[email protected]f85f0702010-01-30 09:31:011695 }
1696
[email protected]b75b8292010-10-01 07:28:251697 // Set zoom level, but don't do it for full-page plugin since they don't use
1698 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011699 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541700 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251701 if (webview()->mainFrame()->document().isPluginDocument()) {
1702 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251703 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251704 } else {
1705 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251706 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251707 }
1708
[email protected]f85f0702010-01-30 09:31:011709 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511710 // This zoom level was merely recorded transiently for this load. We can
1711 // erase it now. If at some point we reload this page, the browser will
1712 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011713 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511714 }
1715
[email protected]b75b8292010-10-01 07:28:251716 // Reset the zoom limits in case a plugin had changed them previously. This
1717 // will also call us back which will cause us to send a message to
1718 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251719 webview()->zoomLimitsChanged(
1720 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1721 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251722
initial.commit09911bf2008-07-26 23:55:291723 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551724 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291725
[email protected]daa8c58e2009-06-15 17:21:101726 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291727 if (!PageTransition::IsMainFrame(params.transition)) {
1728 // If the main frame does a load, it should not be reported as a subframe
1729 // navigation. This can occur in the following case:
1730 // 1. You're on a site with frames.
1731 // 2. You do a subframe navigation. This is stored with transition type
1732 // MANUAL_SUBFRAME.
1733 // 3. You navigate to some non-frame site, say, google.com.
1734 // 4. You navigate back to the page from step 2. Since it was initially
1735 // MANUAL_SUBFRAME, it will be that same transition type here.
1736 // We don't want that, because any navigation that changes the toplevel
1737 // frame should be tracked as a toplevel navigation (this allows us to
1738 // update the URL bar, etc).
1739 params.transition = PageTransition::LINK;
1740 }
1741
initial.commit09911bf2008-07-26 23:55:291742 // If we have a valid consumed client redirect source,
1743 // the page contained a client redirect (meta refresh, document.loc...),
1744 // so we set the referrer and transition to match.
1745 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041746 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291747 params.referrer = completed_client_redirect_src_;
1748 params.transition = static_cast<PageTransition::Type>(
1749 params.transition | PageTransition::CLIENT_REDIRECT);
1750 } else {
1751 // Bug 654101: the referrer will be empty on https->http transitions. It
1752 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281753 params.referrer = GURL(
1754 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291755 }
1756
[email protected]726985e22009-06-18 21:09:281757 string16 method = request.httpMethod();
1758 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291759 params.is_post = true;
1760
[email protected]c2a797d2009-09-21 16:46:321761 // Save some histogram data so we can compute the average memory used per
1762 // page load of the glyphs.
1763 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1764 webkit_glue::GetGlyphPageCount());
1765
[email protected]15cf526b2010-02-12 06:33:491766 // This message needs to be sent before any of allowScripts(),
1767 // allowImages(), allowPlugins() is called for the new page, so that when
1768 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1769 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291770 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1771 } else {
1772 // Subframe navigation: the type depends on whether this navigation
1773 // generated a new session history entry. When they do generate a session
1774 // history entry, it means the user initiated the navigation and we should
1775 // mark it as such. This test checks if this is the first time UpdateURL
1776 // has been called since WillNavigateToURL was called to initiate the load.
1777 if (page_id_ > last_page_id_sent_to_browser_)
1778 params.transition = PageTransition::MANUAL_SUBFRAME;
1779 else
1780 params.transition = PageTransition::AUTO_SUBFRAME;
1781
initial.commit09911bf2008-07-26 23:55:291782 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1783 }
1784
1785 last_page_id_sent_to_browser_ =
1786 std::max(last_page_id_sent_to_browser_, page_id_);
1787
1788 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101789 // we don't want the transition type to persist. Just clear it.
1790 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501791
[email protected]af15bed2010-08-25 21:12:091792 // Check if the navigation was within the same page, in which case we don't
1793 // want to clear the accessibility cache.
1794 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351795 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141796 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501797 }
initial.commit09911bf2008-07-26 23:55:291798}
1799
1800// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171801void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291802 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171803 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171804 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171805 routing_id_,
1806 page_id_,
1807 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1808 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171809 }
initial.commit09911bf2008-07-26 23:55:291810}
1811
1812void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401813 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291814 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271815 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291816 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301817 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291818 last_encoding_name_ = encoding_name;
1819
[email protected]e38f40152008-09-12 23:08:301820 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291821 }
1822}
1823
[email protected]e15f680732010-11-23 22:30:201824// Sends the last committed session history state to the browser so it will be
1825// saved before we navigate to a new page. This must be called *before* the
1826// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291827void RenderView::UpdateSessionHistory(WebFrame* frame) {
1828 // If we have a valid page ID at this point, then it corresponds to the page
1829 // we are navigating away from. Otherwise, this is the first navigation, so
1830 // there is no past session history to record.
1831 if (page_id_ == -1)
1832 return;
1833
[email protected]ca948a22009-06-25 19:36:171834 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271835 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171836 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291837 return;
[email protected]ca948a22009-06-25 19:36:171838
1839 Send(new ViewHostMsg_UpdateState(
1840 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291841}
1842
[email protected]3d9689372009-09-10 04:29:171843void RenderView::OpenURL(
1844 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1845 Send(new ViewHostMsg_OpenURL(
1846 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1847}
1848
[email protected]79dbc662009-09-04 05:42:511849// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291850
initial.commit09911bf2008-07-26 23:55:291851void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281852 const WebURLRequest& failed_request,
1853 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291854 const std::string& html,
1855 bool replace) {
[email protected]726985e22009-06-18 21:09:281856 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291857 std::string alt_html;
[email protected]2a521c52011-01-26 18:45:211858 const Extension* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291859 if (html.empty()) {
1860 // Use a local error page.
1861 int resource_id;
1862 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111863
[email protected]81654282010-10-04 17:08:061864 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
[email protected]2a521c52011-01-26 18:45:211865 extension = render_thread_->GetExtensions()->GetByURL(failed_url);
[email protected]5351dbc2010-08-27 15:22:111866 if (extension) {
[email protected]3f853a52010-09-13 19:15:081867 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1868 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111869
1870 // TODO(erikkay): Should we use a different template for different
1871 // error messages?
1872 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291873 } else {
[email protected]3f853a52010-09-13 19:15:081874 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1875 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111876 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081877 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111878 } else {
[email protected]3f853a52010-09-13 19:15:081879 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111880 }
[email protected]75891fe2010-11-20 15:55:181881 resource_id = IDR_NET_ERROR_HTML;
initial.commit09911bf2008-07-26 23:55:291882 }
initial.commit09911bf2008-07-26 23:55:291883
1884 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1885 } else {
1886 alt_html = html;
1887 }
1888
[email protected]dd7daa82009-08-10 05:46:451889 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361890 GURL(chrome::kUnreachableWebDataURL),
[email protected]e6f546c32009-07-01 17:12:551891 failed_url,
1892 replace);
initial.commit09911bf2008-07-26 23:55:291893}
1894
[email protected]7ccddb8c2009-08-04 17:36:551895void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031896 if (!dom_automation_controller_.get()) {
1897 dom_automation_controller_.reset(new DomAutomationController());
1898 }
1899 dom_automation_controller_->set_message_sender(this);
1900 dom_automation_controller_->set_routing_id(routing_id_);
1901 dom_automation_controller_->BindToJavascript(frame,
[email protected]906690b2010-12-03 18:11:251902 "domAutomationController");
initial.commit09911bf2008-07-26 23:55:291903}
1904
initial.commit09911bf2008-07-26 23:55:291905bool RenderView::RunJavaScriptMessage(int type,
1906 const std::wstring& message,
1907 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071908 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291909 std::wstring* result) {
1910 bool success = false;
1911 std::wstring result_temp;
1912 if (!result)
1913 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291914
[email protected]12636df2009-09-28 22:32:211915 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1916 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291917 return success;
1918}
1919
[email protected]c1f50aa2010-02-18 03:46:571920bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1921 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1922 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1923 // it is particularly important that we do not call willEnterModalLoop as
1924 // that would defer resource loads for the dialog itself.
1925 if (RenderThread::current()) // Will be NULL during unit tests.
1926 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1927
1928 message->EnableMessagePumping(); // Runs a nested message loop.
1929 return Send(message);
1930}
1931
[email protected]2de7e002010-10-11 22:58:201932void RenderView::AddGURLSearchProvider(
1933 const GURL& osd_url,
1934 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
initial.commit09911bf2008-07-26 23:55:291935 if (!osd_url.is_empty())
1936 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
[email protected]2de7e002010-10-11 22:58:201937 provider_type));
initial.commit09911bf2008-07-26 23:55:291938}
1939
[email protected]e8345242010-05-06 03:00:401940void RenderView::OnAllowScriptToClose(bool script_can_close) {
1941 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311942}
1943
initial.commit09911bf2008-07-26 23:55:291944uint32 RenderView::GetCPBrowsingContext() {
1945 uint32 context = 0;
1946 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1947 return context;
1948}
1949
[email protected]2de7e002010-10-11 22:58:201950void RenderView::AddSearchProvider(
1951 const std::string& url,
1952 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
1953 if (provider_type.type ==
1954 ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER &&
1955 !webview()->mainFrame()->isProcessingUserGesture())
1956 return;
1957
1958 AddGURLSearchProvider(GURL(url), provider_type);
initial.commit09911bf2008-07-26 23:55:291959}
1960
[email protected]155f35e2010-07-17 00:30:181961ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251962RenderView::GetSearchProviderInstallState(WebFrame* frame,
1963 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:181964 GURL inquiry_url = GURL(url);
1965 if (inquiry_url.is_empty())
1966 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:251967
[email protected]155f35e2010-07-17 00:30:181968 ViewHostMsg_GetSearchProviderInstallState_Params install;
1969 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:251970 frame->url(),
[email protected]155f35e2010-07-17 00:30:181971 inquiry_url,
1972 &install));
1973 return install;
1974}
1975
[email protected]f103ab72009-09-02 17:10:591976void RenderView::OnMissingPluginStatus(
1977 WebPluginDelegateProxy* delegate,
1978 int status) {
[email protected]6c8afae52009-01-22 02:24:571979#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591980 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291981 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:501982 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591983 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291984 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1985 }
1986 } else {
1987 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1988 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:501989 if (status ==
1990 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:291991 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1992 }
1993 }
[email protected]6c8afae52009-01-22 02:24:571994#else
[email protected]76c3b312010-05-20 21:38:291995 // TODO(port): Implement the infobar that accompanies the default plugin.
1996 // Linux: http://crbug.com/10952
1997 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571998 NOTIMPLEMENTED();
1999#endif
initial.commit09911bf2008-07-26 23:55:292000}
2001
[email protected]48c9cf2d2009-09-16 16:47:522002// WebKit::WebViewClient ------------------------------------------------------
2003
[email protected]844acf372011-01-14 10:49:272004WebView* RenderView::createView(
2005 WebFrame* creator,
2006 const WebURLRequest& request,
2007 const WebWindowFeatures& features,
2008 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:522009 // Check to make sure we aren't overloading on popups.
2010 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2011 return NULL;
2012
2013 // This window can't be closed from a window.close() call until we receive a
2014 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:402015 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:522016
[email protected]8ab04652010-06-12 02:47:262017 ViewHostMsg_CreateWindow_Params params;
2018 params.opener_id = routing_id_;
2019 params.user_gesture = creator->isProcessingUserGesture();
2020 params.window_container_type = WindowFeaturesToContainerType(features);
2021 params.session_storage_namespace_id = session_storage_namespace_id_;
2022 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112023 params.opener_frame_id = creator->identifier();
2024 params.opener_url = creator->url();
2025 params.opener_security_origin = creator->securityOrigin().toString().utf8();
2026 if (!request.isNull())
2027 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:262028
[email protected]48c9cf2d2009-09-16 16:47:522029 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:342030 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:262031 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:522032
[email protected]48c9cf2d2009-09-16 16:47:522033 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:262034 new ViewHostMsg_CreateWindow(params,
2035 &routing_id,
2036 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212037 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522038 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522039
[email protected]48c9cf2d2009-09-16 16:47:522040 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:422041 0,
[email protected]12636df2009-09-28 22:32:212042 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:522043 renderer_preferences_,
2044 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:212045 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:342046 routing_id,
[email protected]8ab04652010-06-12 02:47:262047 cloned_session_storage_namespace_id,
2048 frame_name);
2049 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522050
[email protected]007a848b2009-10-26 15:55:462051 // Record whether the creator frame is trying to suppress the opener field.
2052 view->opener_suppressed_ = opener_suppressed;
2053
[email protected]48c9cf2d2009-09-16 16:47:522054 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:092055 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:522056 if (!creator_url.is_valid() || !creator_url.IsStandard())
2057 creator_url = GURL();
2058 view->creator_url_ = creator_url;
2059
2060 // Copy over the alternate error page URL so we can have alt error pages in
2061 // the new render view (we don't need the browser to send the URL back down).
2062 view->alternate_error_page_url_ = alternate_error_page_url_;
2063
2064 return view->webview();
2065}
2066
[email protected]3e2b375b2010-04-07 17:03:122067WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:522068 RenderWidget* widget = RenderWidget::Create(routing_id_,
2069 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:122070 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:522071 return widget->webwidget();
2072}
2073
2074WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:442075 // TODO(jcivelli): Remove this deprecated method when its been removed from
2076 // the WebViewClient interface. It's been replaced by
2077 // createExternalPopupMenu.
2078 NOTREACHED();
2079 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522080}
2081
[email protected]caf706f2010-10-26 17:54:082082WebExternalPopupMenu* RenderView::createExternalPopupMenu(
2083 const WebPopupMenuInfo& popup_menu_info,
2084 WebExternalPopupMenuClient* popup_menu_client) {
2085 DCHECK(!external_popup_menu_.get());
2086 external_popup_menu_.reset(
2087 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2088 return external_popup_menu_.get();
2089}
2090
[email protected]0bd753682010-12-16 18:15:522091webkit::ppapi::FullscreenContainer*
2092RenderView::CreatePepperFullscreenContainer(
2093 webkit::ppapi::PluginInstance* plugin) {
[email protected]79c7bed2010-09-14 22:28:392094 RenderWidgetFullscreenPepper* widget =
2095 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
2096 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:562097 return widget;
[email protected]79c7bed2010-09-14 22:28:392098}
2099
[email protected]68c50e52010-05-12 11:14:392100WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:342101 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:392102 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:292103 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
2104 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
2105 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342106}
2107
[email protected]48c9cf2d2009-09-16 16:47:522108void RenderView::didAddMessageToConsole(
2109 const WebConsoleMessage& message, const WebString& source_name,
2110 unsigned source_line) {
2111 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2112 UTF16ToWideHack(message.text),
2113 static_cast<int32>(source_line),
2114 UTF16ToWideHack(source_name)));
2115}
2116
2117void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:582118 DCHECK(frame);
[email protected]212a49d2010-10-25 18:23:472119 if (CommandLine::ForCurrentProcess()->HasSwitch(
2120 switches::kEnablePrintPreview)) {
[email protected]dec1f292011-02-11 20:20:202121 print_helper_->PrintFrame(frame, true, true);
[email protected]212a49d2010-10-25 18:23:472122 } else {
[email protected]dec1f292011-02-11 20:20:202123 print_helper_->PrintFrame(frame, true, false);
[email protected]212a49d2010-10-25 18:23:472124 }
[email protected]48c9cf2d2009-09-16 16:47:522125}
2126
[email protected]3354d3e2010-06-10 19:53:022127WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512128 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022129}
2130
[email protected]48c9cf2d2009-09-16 16:47:522131void RenderView::didStartLoading() {
2132 if (is_loading_) {
2133 DLOG(WARNING) << "didStartLoading called while loading";
2134 return;
2135 }
2136
2137 is_loading_ = true;
2138 // Clear the pointer so that we can assign it only when there is an unknown
2139 // plugin on a page.
2140 first_default_plugin_.reset();
2141
2142 Send(new ViewHostMsg_DidStartLoading(routing_id_));
2143}
2144
2145void RenderView::didStopLoading() {
2146 if (!is_loading_) {
2147 DLOG(WARNING) << "DidStopLoading called while not loading";
2148 return;
2149 }
2150
2151 is_loading_ = false;
2152
2153 // NOTE: For now we're doing the safest thing, and sending out notification
2154 // when done loading. This currently isn't an issue as the favicon is only
2155 // displayed when done loading. Ideally we would send notification when
2156 // finished parsing the head, but webkit doesn't support that yet.
2157 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:272158 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:522159 if (!favicon_url.is_empty())
2160 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
2161
[email protected]26aa0482009-09-30 16:55:272162 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]2de7e002010-10-11 22:58:202163 ViewHostMsg_PageHasOSDD_Type::Autodetected());
[email protected]48c9cf2d2009-09-16 16:47:522164
2165 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2166
[email protected]90109412010-12-15 17:14:242167 if (load_progress_tracker_ != NULL)
2168 load_progress_tracker_->DidStopLoading();
2169
[email protected]f9f4841b2010-03-20 05:41:422170 MessageLoop::current()->PostDelayedTask(
2171 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302172 page_info_method_factory_.NewRunnableMethod(
2173 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:372174 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:522175}
2176
[email protected]90109412010-12-15 17:14:242177void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
2178 if (load_progress_tracker_ != NULL)
2179 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2180}
2181
[email protected]f55039a2010-02-17 14:12:062182bool RenderView::isSmartInsertDeleteEnabled() {
2183#if defined(OS_MACOSX)
2184 return true;
2185#else
2186 return false;
2187#endif
2188}
2189
[email protected]04fc9482009-09-18 22:13:032190bool RenderView::isSelectTrailingWhitespaceEnabled() {
2191#if defined(OS_WIN)
2192 return true;
2193#else
2194 return false;
2195#endif
2196}
2197
[email protected]04fc9482009-09-18 22:13:032198void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:422199#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032200 if (!handling_input_event_)
2201 return;
2202 // TODO(estade): investigate incremental updates to the selection so that we
2203 // don't send the entire selection over IPC every time.
2204 if (!is_empty_selection) {
2205 // Sometimes we get repeated didChangeSelection calls from webkit when
2206 // the selection hasn't actually changed. We don't want to report these
2207 // because it will cause us to continually claim the X clipboard.
2208 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:272209 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:032210 if (this_selection == last_selection_)
2211 return;
2212
2213 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2214 this_selection));
2215 last_selection_ = this_selection;
2216 } else {
2217 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:162218 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2219 last_selection_));
[email protected]04fc9482009-09-18 22:13:032220 }
[email protected]0ff0ff32010-12-21 19:34:422221#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032222}
2223
2224void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122225 const std::string& name = UTF16ToUTF8(command_name);
2226 if (StartsWithASCII(name, "Move", true) ||
2227 StartsWithASCII(name, "Insert", true) ||
2228 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032229 return;
2230 UserMetricsRecordAction(name);
2231}
2232
[email protected]54ec7f82010-10-21 22:32:512233void RenderView::SendPendingAccessibilityNotifications() {
2234 if (!accessibility_.get())
2235 return;
2236
2237 if (pending_accessibility_notifications_.empty())
2238 return;
2239
2240 // Send all pending accessibility notifications.
2241 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
2242 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
2243 RendererAccessibilityNotification& notification =
2244 pending_accessibility_notifications_[i];
2245 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
2246 if (!obj.isValid())
2247 continue;
2248
2249 ViewHostMsg_AccessibilityNotification_Params param;
[email protected]a527a022011-02-10 02:32:362250 WebAccessibilityNotificationToViewHostMsg(
2251 pending_accessibility_notifications_[i].type, &param.notification_type);
[email protected]70eee342010-11-05 01:59:372252 param.acc_obj = WebAccessibility(
2253 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:512254 notifications.push_back(param);
2255 }
2256 pending_accessibility_notifications_.clear();
2257 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
2258 accessibility_ack_pending_ = true;
2259}
2260
[email protected]b2528b72009-09-24 06:57:102261bool RenderView::handleCurrentKeyboardEvent() {
2262 if (edit_commands_.empty())
2263 return false;
2264
[email protected]26aa0482009-09-30 16:55:272265 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102266 if (!frame)
2267 return false;
2268
2269 EditCommands::iterator it = edit_commands_.begin();
2270 EditCommands::iterator end = edit_commands_.end();
2271
[email protected]507b33ea2009-09-29 03:56:512272 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102273 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332274 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2275 // key (but it's the exception). Once one edit command is not executed, it
2276 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102277 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2278 WebString::fromUTF8(it->value)))
2279 break;
[email protected]507b33ea2009-09-29 03:56:512280 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102281 }
2282
[email protected]507b33ea2009-09-29 03:56:512283 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102284}
2285
[email protected]2a3a7762009-10-19 19:17:322286void RenderView::spellCheck(const WebString& text,
2287 int& misspelled_offset,
2288 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:562289 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:462290
[email protected]85c55dc2009-11-06 03:05:462291 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:172292 RenderThread* thread = RenderThread::current();
2293 // Will be NULL during unit tests.
2294 if (thread) {
[email protected]c27324b2009-11-19 22:44:292295 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:172296 word.c_str(), word.size(), document_tag_,
2297 &misspelled_offset, &misspelled_length, NULL);
2298 }
[email protected]1dbafaf72009-09-23 19:43:562299}
2300
2301WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322302 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562303 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:262304 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:562305 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:172306 RenderThread* thread = RenderThread::current();
2307 // Will be NULL during unit tests.
2308 if (thread) {
2309 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:292310 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:172311 word, document_tag_);
2312 }
[email protected]1dbafaf72009-09-23 19:43:562313 }
[email protected]2a3a7762009-10-19 19:17:322314 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562315}
2316
[email protected]c49085c72009-10-02 16:28:562317void RenderView::showSpellingUI(bool show) {
2318 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2319}
2320
[email protected]8922e1f2009-10-03 05:01:262321bool RenderView::isShowingSpellingUI() {
2322 return spelling_panel_visible_;
2323}
2324
[email protected]1dbafaf72009-09-23 19:43:562325void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322326 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2327 word));
[email protected]1dbafaf72009-09-23 19:43:562328}
2329
[email protected]13a1e4c3c2011-02-03 21:07:092330void RenderView::continuousSpellCheckingEnabledStateChanged() {
2331 UpdateToggleSpellCheckCommandState();
2332}
2333
[email protected]a1128322009-10-06 18:38:462334bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352335 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472336 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352337 // Do not open the file dialog in a hidden RenderView.
2338 if (is_hidden())
2339 return false;
[email protected]cdaf8d02010-03-30 19:52:472340 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262341 if (params.directory)
2342 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2343 else if (params.multiSelect)
2344 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2345 else
2346 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472347 ipc_params.title = params.title;
2348 ipc_params.default_file_name =
2349 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592350 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472351
2352 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462353}
2354
[email protected]48c9cf2d2009-09-16 16:47:522355void RenderView::runModalAlertDialog(
2356 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062357 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]48c9cf2d2009-09-16 16:47:522358 UTF16ToWideHack(message),
2359 std::wstring(),
2360 frame->url(),
2361 NULL);
2362}
2363
2364bool RenderView::runModalConfirmDialog(
2365 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062366 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]48c9cf2d2009-09-16 16:47:522367 UTF16ToWideHack(message),
2368 std::wstring(),
2369 frame->url(),
2370 NULL);
2371}
2372
2373bool RenderView::runModalPromptDialog(
2374 WebFrame* frame, const WebString& message, const WebString& default_value,
2375 WebString* actual_value) {
2376 std::wstring result;
[email protected]9dd7e3d72011-01-20 18:27:062377 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]48c9cf2d2009-09-16 16:47:522378 UTF16ToWideHack(message),
2379 UTF16ToWideHack(default_value),
2380 frame->url(),
2381 &result);
2382 if (ok)
2383 actual_value->assign(WideToUTF16Hack(result));
2384 return ok;
2385}
2386
2387bool RenderView::runModalBeforeUnloadDialog(
2388 WebFrame* frame, const WebString& message) {
2389 bool success = false;
2390 // This is an ignored return value, but is included so we can accept the same
2391 // response as RunJavaScriptMessage.
2392 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212393 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522394 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212395 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522396 return success;
2397}
2398
[email protected]79e37442009-10-09 18:17:442399void RenderView::showContextMenu(
2400 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292401 ContextMenuParams params = ContextMenuParams(data);
2402 if (!params.misspelled_word.empty() && RenderThread::current()) {
2403 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042404 bool spelled_right = RenderThread::current()->spellchecker()->
2405 SpellCheckWord(
2406 params.misspelled_word.c_str(), params.misspelled_word.size(),
2407 document_tag_,
2408 &misspelled_offset, &misspelled_length,
2409 &params.dictionary_suggestions);
2410 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292411 params.misspelled_word.clear();
2412 }
[email protected]216932c2010-08-26 21:44:272413 // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do
2414 // it. We replace it with an empty GURL so the appropriate items are disabled
2415 // in the context menu.
2416 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2417 // data encoded images. We should have a way to save them.
2418 if (params.src_url.spec().size() > chrome::kMaxURLChars)
2419 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102420 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:292421 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442422}
2423
[email protected]52f139e2c2010-06-11 16:56:092424bool RenderView::supportsFullscreen() {
2425 return CommandLine::ForCurrentProcess()->HasSwitch(
2426 switches::kEnableVideoFullscreen);
2427}
2428
2429void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2430 NOTIMPLEMENTED();
2431}
2432
2433void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2434 NOTIMPLEMENTED();
2435}
2436
[email protected]48c9cf2d2009-09-16 16:47:522437void RenderView::setStatusText(const WebString& text) {
2438}
2439
[email protected]163f8242009-10-30 20:19:552440void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582441 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522442 if (latest_url == target_url_)
2443 return;
[email protected]163f8242009-10-30 20:19:552444
[email protected]48c9cf2d2009-09-16 16:47:522445 // Tell the browser to display a destination link.
2446 if (target_url_status_ == TARGET_INFLIGHT ||
2447 target_url_status_ == TARGET_PENDING) {
2448 // If we have a request in-flight, save the URL to be sent when we
2449 // receive an ACK to the in-flight request. We can happily overwrite
2450 // any existing pending sends.
2451 pending_target_url_ = latest_url;
2452 target_url_status_ = TARGET_PENDING;
2453 } else {
2454 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2455 target_url_ = latest_url;
2456 target_url_status_ = TARGET_INFLIGHT;
2457 }
2458}
2459
[email protected]13a1e4c3c2011-02-03 21:07:092460void RenderView::UpdateToggleSpellCheckCommandState() {
2461 bool is_enabled = false;
2462 WebKit::WebNode node = GetFocusedNode();
2463 if (!node.isNull())
2464 is_enabled = IsEditableNode(node);
2465
2466 RenderViewCommandCheckedState checked_state =
2467 RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED;
2468 if (is_enabled && webview()) {
2469 WebFrame* frame = webview()->focusedFrame();
2470 if (frame->isContinuousSpellCheckingEnabled())
2471 checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED;
2472 }
2473
2474 Send(new ViewHostMsg_CommandStateChanged(
2475 routing_id_,
2476 RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK,
2477 is_enabled,
2478 checked_state));
2479}
2480
[email protected]882daa92009-11-05 16:31:312481void RenderView::StartNavStateSyncTimerIfNecessary() {
2482 int delay;
2483 if (send_content_state_immediately_)
2484 delay = 0;
2485 else if (is_hidden())
2486 delay = kDelaySecondsForContentStateSyncHidden;
2487 else
2488 delay = kDelaySecondsForContentStateSync;
2489
2490 if (nav_state_sync_timer_.IsRunning()) {
2491 // The timer is already running. If the delay of the timer maches the amount
2492 // we want to delay by, then return. Otherwise stop the timer so that it
2493 // gets started with the right delay.
2494 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2495 return;
2496 nav_state_sync_timer_.Stop();
2497 }
2498
2499 nav_state_sync_timer_.Start(
2500 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2501}
2502
[email protected]163f8242009-10-30 20:19:552503void RenderView::setMouseOverURL(const WebURL& url) {
2504 mouse_over_url_ = GURL(url);
2505 UpdateTargetURL(mouse_over_url_, focus_url_);
2506}
2507
2508void RenderView::setKeyboardFocusURL(const WebURL& url) {
2509 focus_url_ = GURL(url);
2510 UpdateTargetURL(focus_url_, mouse_over_url_);
2511}
2512
[email protected]48c9cf2d2009-09-16 16:47:522513void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2514 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2515 hint));
2516}
2517
[email protected]c27ae592010-03-18 15:24:412518void RenderView::startDragging(const WebDragData& data,
2519 WebDragOperationsMask mask,
2520 const WebImage& image,
2521 const WebPoint& imageOffset) {
2522#if WEBKIT_USING_SKIA
2523 SkBitmap bitmap(image.getSkBitmap());
2524#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332525 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412526#endif
2527
[email protected]48c9cf2d2009-09-16 16:47:522528 Send(new ViewHostMsg_StartDragging(routing_id_,
2529 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412530 mask,
2531 bitmap,
2532 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522533}
2534
[email protected]28b92df2009-09-25 17:35:452535bool RenderView::acceptsLoadDrops() {
2536 return renderer_preferences_.can_accept_load_drops;
2537}
2538
[email protected]48c9cf2d2009-09-16 16:47:522539void RenderView::focusNext() {
2540 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2541}
2542
2543void RenderView::focusPrevious() {
2544 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2545}
2546
[email protected]08e9e132010-06-01 16:58:492547void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512548 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072549
2550 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2551 // TODO(ctguil): Make WebKit send this notification.
2552 // When focus is cleared notify accessibility that the document is focused.
2553 postAccessibilityNotification(
2554 webview()->accessibilityObject(),
2555 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2556 }
[email protected]13a1e4c3c2011-02-03 21:07:092557
2558 UpdateToggleSpellCheckCommandState();
[email protected]08e9e132010-06-01 16:58:492559}
2560
[email protected]48c9cf2d2009-09-16 16:47:522561void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522562 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2563}
2564
2565int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002566 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522567}
2568
2569int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002570 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522571}
2572
[email protected]c4e98902010-06-01 10:20:142573void RenderView::didUpdateInspectorSetting(const WebString& key,
2574 const WebString& value) {
2575 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2576 key.utf8(),
2577 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262578}
2579
[email protected]79dbc662009-09-04 05:42:512580// WebKit::WebWidgetClient ----------------------------------------------------
2581
[email protected]ea42e7782010-08-23 23:58:122582void RenderView::didFocus() {
2583 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2584 // we won't have to test for user gesture anymore and we can
2585 // move that code back to render_widget.cc
2586 if (webview() && webview()->mainFrame() &&
2587 webview()->mainFrame()->isProcessingUserGesture()) {
2588 Send(new ViewHostMsg_Focus(routing_id_));
2589 }
2590}
2591
2592void RenderView::didBlur() {
2593 // TODO(jcivelli): see TODO above in didFocus().
2594 if (webview() && webview()->mainFrame() &&
2595 webview()->mainFrame()->isProcessingUserGesture()) {
2596 Send(new ViewHostMsg_Blur(routing_id_));
2597 }
2598}
2599
initial.commit09911bf2008-07-26 23:55:292600// We are supposed to get a single call to Show for a newly created RenderView
2601// that was created via RenderView::CreateWebView. So, we wait until this
2602// point to dispatch the ShowView message.
2603//
2604// This method provides us with the information about how to display the newly
2605// created RenderView (i.e., as a constrained popup or as a new tab).
2606//
[email protected]4873c7d2009-07-16 06:36:282607void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292608 DCHECK(!did_show_) << "received extraneous Show call";
2609 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2610
2611 if (did_show_)
2612 return;
2613 did_show_ = true;
2614
[email protected]4026ce1e2010-09-14 19:35:042615 // Extensions and apps always allowed to create unrequested popups. The second
2616 // check is necessary to include content scripts.
[email protected]2a521c52011-01-26 18:45:212617 if (render_thread_->GetExtensions()->GetByURL(creator_url_) ||
[email protected]4026ce1e2010-09-14 19:35:042618 bindings_utils::GetInfoForCurrentContext()) {
2619 opened_by_user_gesture_ = true;
2620 }
2621
[email protected]28295ec2009-10-16 05:34:332622 // Force new windows to a popup if they were not opened with a user gesture.
2623 if (!opened_by_user_gesture_) {
2624 // We exempt background tabs for compat with older versions of Chrome.
2625 // TODO(darin): This seems bogus. These should have a user gesture, so
2626 // we probably don't need this check.
2627 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2628 policy = WebKit::WebNavigationPolicyNewPopup;
2629 }
2630
initial.commit09911bf2008-07-26 23:55:292631 // NOTE: initial_pos_ may still have its default values at this point, but
2632 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2633 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282634 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2635 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292636 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242637 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292638}
2639
[email protected]4873c7d2009-07-16 06:36:282640void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292641 DCHECK(did_show_) << "should already have shown the view";
2642
[email protected]c1f50aa2010-02-18 03:46:572643 // We must keep WebKit's shared timer running in this case in order to allow
2644 // showModalDialog to function properly.
2645 //
2646 // TODO(darin): WebKit should really be smarter about suppressing events and
2647 // timers so that we do not need to manage the shared timer in such a heavy
2648 // handed manner.
2649 //
2650 if (RenderThread::current()) // Will be NULL during unit tests.
2651 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2652
[email protected]12636df2009-09-28 22:32:212653 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292654}
2655
[email protected]3d9689372009-09-10 04:29:172656// WebKit::WebFrameClient -----------------------------------------------------
2657
[email protected]00152e92010-07-19 11:47:402658WebPlugin* RenderView::createPlugin(WebFrame* frame,
2659 const WebPluginParams& params) {
[email protected]6fdd4182010-10-14 23:59:262660 bool found = false;
[email protected]414508d2010-11-02 10:45:392661 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
[email protected]55126132010-08-19 14:53:282662 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]191eb3f72010-12-21 06:27:502663 webkit::npapi::WebPluginInfo info;
[email protected]7a13e792010-08-03 08:18:242664 GURL url(params.url);
[email protected]6fdd4182010-10-14 23:59:262665 std::string actual_mime_type;
[email protected]c8f73ab2011-01-22 00:05:172666 Send(new ViewHostMsg_GetPluginInfo(routing_id_,
2667 url,
[email protected]6fdd4182010-10-14 23:59:262668 frame->top()->url(),
2669 params.mimeType.utf8(),
2670 &found,
2671 &info,
[email protected]44fda5c2010-11-02 10:50:542672 &plugin_setting,
[email protected]6fdd4182010-10-14 23:59:262673 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242674
[email protected]6fdd4182010-10-14 23:59:262675 if (!found)
[email protected]0cdafff2010-07-26 09:54:372676 return NULL;
[email protected]414508d2010-11-02 10:45:392677 DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
[email protected]4e0616e2010-05-28 14:55:532678
[email protected]191eb3f72010-12-21 06:27:502679 const webkit::npapi::PluginGroup* group =
2680 webkit::npapi::PluginList::Singleton()->GetPluginGroup(info);
[email protected]79ce1032010-12-07 13:29:412681 DCHECK(group != NULL);
[email protected]851b1eb2010-08-09 13:32:292682
[email protected]6e74a3b2010-12-21 22:27:542683 if (group->IsVulnerable() &&
2684 !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) {
[email protected]3c2826852010-12-16 19:09:142685 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2686 group->GetGroupName(),
2687 GURL(group->GetUpdateURL())));
2688 return CreatePluginPlaceholder(frame,
2689 params,
2690 *group,
[email protected]2e34ab3f2010-12-17 05:47:372691 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202692 IDS_PLUGIN_OUTDATED,
2693 false);
[email protected]851b1eb2010-08-09 13:32:292694 }
[email protected]6e74a3b2010-12-21 22:27:542695
[email protected]b83ff222011-01-24 17:37:122696 if (!webkit::npapi::IsPluginEnabled(info))
[email protected]3c2826852010-12-16 19:09:142697 return NULL;
[email protected]851b1eb2010-08-09 13:32:292698
[email protected]414508d2010-11-02 10:45:392699 ContentSetting host_setting =
2700 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS];
[email protected]d12dcdd62011-01-27 06:53:252701
2702 if (group->RequiresAuthorization() &&
2703 !cmd->HasSwitch(switches::kAlwaysAuthorizePlugins) &&
2704 (plugin_setting == CONTENT_SETTING_ALLOW ||
2705 plugin_setting == CONTENT_SETTING_ASK) &&
2706 host_setting == CONTENT_SETTING_DEFAULT) {
2707 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2708 group->GetGroupName(),
2709 GURL()));
2710 return CreatePluginPlaceholder(frame,
2711 params,
2712 *group,
2713 IDR_BLOCKED_PLUGIN_HTML,
2714 IDS_PLUGIN_NOT_AUTHORIZED,
2715 false);
2716 }
2717
[email protected]191eb3f72010-12-21 06:27:502718 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName ||
[email protected]414508d2010-11-02 10:45:392719 plugin_setting == CONTENT_SETTING_ALLOW ||
2720 host_setting == CONTENT_SETTING_ALLOW) {
[email protected]90dba072011-01-20 20:10:202721 // Delay loading plugins if prerendering.
2722 WebDataSource* ds = frame->dataSource();
2723 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2724 if (navigation_state->is_prerendering()) {
2725 return CreatePluginPlaceholder(frame,
2726 params,
2727 *group,
2728 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
2729 IDS_PLUGIN_LOAD,
2730 true);
2731 }
2732
[email protected]0bd753682010-12-16 18:15:522733 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:452734 pepper_delegate_.CreatePepperPlugin(info.path));
2735 if (pepper_module)
2736 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]6fdd4182010-10-14 23:59:262737 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]0cdafff2010-07-26 09:54:372738 }
[email protected]fc61e222010-10-11 15:42:142739 std::string resource;
2740 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2741 resource = group->identifier();
2742 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]414508d2010-11-02 10:45:392743 if (plugin_setting == CONTENT_SETTING_ASK) {
[email protected]3c2826852010-12-16 19:09:142744 return CreatePluginPlaceholder(frame,
2745 params,
2746 *group,
[email protected]2e34ab3f2010-12-17 05:47:372747 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202748 IDS_PLUGIN_LOAD,
2749 false);
[email protected]fc61e222010-10-11 15:42:142750 } else {
[email protected]3c2826852010-12-16 19:09:142751 return CreatePluginPlaceholder(frame,
2752 params,
2753 *group,
[email protected]2e34ab3f2010-12-17 05:47:372754 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202755 IDS_PLUGIN_BLOCKED,
2756 false);
[email protected]fc61e222010-10-11 15:42:142757 }
[email protected]3d9689372009-09-10 04:29:172758}
2759
2760WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562761 WebApplicationCacheHostImpl* appcache_host =
2762 WebApplicationCacheHostImpl::FromFrame(frame);
2763 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2764 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2765 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172766}
2767
[email protected]9c00f002009-11-05 22:37:422768WebSharedWorker* RenderView::createSharedWorker(
2769 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372770 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422771
[email protected]30447b62009-11-13 01:13:372772 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512773 bool exists = false;
[email protected]30447b62009-11-13 01:13:372774 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512775 ViewHostMsg_CreateWorker_Params params;
2776 params.url = url;
2777 params.is_shared = true;
2778 params.name = name;
2779 params.document_id = document_id;
2780 params.render_view_route_id = routing_id_;
2781 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232782 params.parent_appcache_host_id = 0;
2783 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372784 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512785 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372786 if (url_mismatch) {
2787 return NULL;
2788 } else {
2789 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492790 document_id,
[email protected]6de0bcf2010-02-17 22:00:512791 exists,
[email protected]30447b62009-11-13 01:13:372792 route_id,
2793 routing_id_);
2794 }
[email protected]9c00f002009-11-05 22:37:422795}
2796
[email protected]3d9689372009-09-10 04:29:172797WebMediaPlayer* RenderView::createMediaPlayer(
2798 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]f78d1dfc2011-01-15 07:09:272799 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
2800 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:492801 scoped_ptr<media::FilterCollection> collection(
2802 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:372803
[email protected]3d9689372009-09-10 04:29:172804 // Add in any custom filter factories first.
2805 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2806 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2807 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:492808 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:172809 }
2810
[email protected]3bb08602010-10-07 21:47:172811 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:122812 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:072813 WebGraphicsContext3DCommandBufferImpl* context =
2814 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2815 frame->view()->graphicsContext3D());
2816 if (!context)
2817 return NULL;
[email protected]a9a43012010-11-05 01:54:062818
[email protected]5aa6a312010-11-06 00:00:072819 // Add the hardware video decoder factory.
2820 // TODO(hclam): This will cause the renderer process to crash on context
2821 // lost.
2822 bool ret = context->makeContextCurrent();
2823 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:492824 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:072825 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:172826 }
2827
[email protected]457d8342010-10-23 01:20:372828 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:312829 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2830 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
2831 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:492832 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:312833 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:112834
[email protected]a8e24d522010-12-01 07:13:582835 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:272836 new webkit_glue::WebMediaPlayerImpl(client,
2837 collection.release(),
2838 message_loop_factory.release()));
[email protected]79684282010-12-06 21:15:462839 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:582840 cmd_line->HasSwitch(switches::kSimpleDataSource),
2841 video_renderer)) {
2842 return NULL;
2843 }
2844 return result.release();
[email protected]3d9689372009-09-10 04:29:172845}
2846
[email protected]035545f2010-04-09 13:10:212847WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2848 WebFrame* frame, WebApplicationCacheHostClient* client) {
2849 return new RendererWebApplicationCacheHostImpl(
2850 FromWebView(frame->view()), client,
2851 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2852}
2853
[email protected]8ff181072010-11-29 17:09:382854WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
2855 return &cookie_jar_;
2856}
2857
[email protected]5041f982010-08-11 21:40:452858void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512859 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452860}
2861
[email protected]3d9689372009-09-10 04:29:172862void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302863 WebDataSource* ds = frame->dataSource();
2864 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522865
[email protected]a5a65ac2010-11-05 18:14:362866 page_load_histograms_.Dump(frame);
[email protected]fa7b6b542009-11-03 05:02:302867 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]f3ce0a32011-01-11 08:18:182868
[email protected]676126f72011-01-15 00:03:512869 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172870}
2871
[email protected]684e4a42010-01-30 06:44:112872bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402873 if (enabled_per_settings &&
2874 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2875 return true;
2876
2877 if (IsWhitelistedForContentSettings(frame))
2878 return true;
2879
[email protected]55126132010-08-19 14:53:282880 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402881 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112882}
2883
[email protected]d5f9e4f2010-07-28 08:31:302884bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]3627b06d2010-11-12 16:36:162885 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
[email protected]d5f9e4f2010-07-28 08:31:302886}
2887
2888
[email protected]3d9689372009-09-10 04:29:172889void RenderView::loadURLExternally(
2890 WebFrame* frame, const WebURLRequest& request,
2891 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592892 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2893 if (policy == WebKit::WebNavigationPolicyDownload) {
2894 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2895 } else {
2896 OpenURL(request.url(), referrer, policy);
2897 }
[email protected]3d9689372009-09-10 04:29:172898}
2899
2900WebNavigationPolicy RenderView::decidePolicyForNavigation(
2901 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222902 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172903 // Webkit is asking whether to navigate to a new URL.
2904 // This is fine normally, except if we're showing UI from one security
2905 // context and they're trying to navigate to a different context.
2906 const GURL& url = request.url();
2907
2908 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302909 // navigations.
[email protected]8079b362010-05-07 18:37:452910 if (renderer_preferences_.browser_handles_top_level_requests &&
2911 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192912 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232913 // Reset these counters as the RenderView could be reused for the next
2914 // navigation.
2915 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232916 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192917 OpenURL(url, referrer, default_policy);
2918 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172919 }
2920
2921 // A content initiated navigation may have originated from a link-click,
2922 // script, drag-n-drop operation, etc.
2923 bool is_content_initiated =
2924 NavigationState::FromDataSource(frame->provisionalDataSource())->
2925 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582926 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172927
[email protected]6101c342010-12-16 22:44:372928 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552929 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572930 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372931 // opening a new window). But we sometimes navigate to about:blank to clear a
2932 // tab, and we want to still allow that.
2933 //
[email protected]8f4da8c2011-02-09 19:49:572934 // Note: we do this only for GET requests because our mechanism for switching
2935 // processes only issues GET requests. In particular, POST requests don't
2936 // work, because this mechanism does not preserve form POST data. If it
2937 // becomes necessary to support process switching for POST requests, we will
2938 // need to send the request's httpBody data up to the browser process, and
2939 // issue a special POST navigation in WebKit (via
2940 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2941 // for examples of how to send the httpBody data.
2942 // Note2: We normally don't do this for browser-initiated navigations, since
2943 // it's pointless to tell the browser about navigations it gave us. But
2944 // we do potentially ask the browser to handle a redirect that was originally
2945 // initiated by the browser. See http://crbug.com/70943
2946 //
2947 // TODO(creis): Move this redirect check to the browser process to avoid
2948 // ping-ponging. See http://crbug.com/72380.
2949 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372950 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2951 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2952 bool send_referrer = false;
2953 bool should_fork =
2954 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172955 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372956 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112957
2958 // If the navigation would cross an app extent boundary, we also need
2959 // to defer to the browser to ensure process isolation.
2960 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2961 // which means that things like the back button won't trigger it. Is that
2962 // OK?
[email protected]88c15e972011-02-05 04:19:532963 // TODO(creis): For hosted apps, we currently only swap processes to enter
2964 // the app and not exit it, since we currently lose context (e.g.,
2965 // window.opener) if the window navigates back. See crbug.com/65953.
[email protected]2a521c52011-01-26 18:45:212966 if (!should_fork &&
[email protected]88c15e972011-02-05 04:19:532967 CrossesExtensionExtents(
[email protected]2a521c52011-01-26 18:45:212968 render_thread_->GetExtensions(),
2969 frame,
2970 url)) {
[email protected]5351dbc2010-08-27 15:22:112971 // Include the referrer in this case since we're going from a hosted web
2972 // page. (the packaged case is handled previously by the extension
2973 // navigation test)
[email protected]6101c342010-12-16 22:44:372974 should_fork = true;
2975 send_referrer = true;
2976 }
2977
2978 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112979 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372980 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112981 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2982 }
[email protected]3d9689372009-09-10 04:29:172983 }
2984
2985 // Detect when a page is "forking" a new tab that can be safely rendered in
2986 // its own process. This is done by sites like Gmail that try to open links
2987 // in new windows without script connections back to the original page. We
2988 // treat such cases as browser navigations (in which we will create a new
2989 // renderer for a cross-site navigation), rather than WebKit navigations.
2990 //
2991 // We use the following heuristic to decide whether to fork a new page in its
2992 // own process:
2993 // The parent page must open a new tab to about:blank, set the new tab's
2994 // window.opener to null, and then redirect the tab to a cross-site URL using
2995 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462996 //
2997 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2998 // (see below).
[email protected]3d9689372009-09-10 04:29:172999 bool is_fork =
3000 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:583001 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173002 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523003 historyBackListCount() < 1 &&
3004 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173005 // The parent page must have set the child's window.opener to null before
3006 // redirecting to the desired URL.
3007 frame->opener() == NULL &&
3008 // Must be a top-level frame.
3009 frame->parent() == NULL &&
3010 // Must not have issued the request from this page.
3011 is_content_initiated &&
3012 // Must be targeted at the current tab.
3013 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3014 // Must be a JavaScript navigation, which appears as "other".
3015 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463016
3017 // Recognize if this navigation is from a link with rel=noreferrer and
3018 // target=_blank attributes, in which case the opener will be suppressed. If
3019 // so, it is safe to load cross-site pages in a separate process, so we
3020 // should let the browser handle it.
3021 bool is_noreferrer_and_blank_target =
3022 // Frame should be top level and not yet navigated.
3023 frame->parent() == NULL &&
3024 frame->url().isEmpty() &&
3025 historyBackListCount() < 1 &&
3026 historyForwardListCount() < 1 &&
3027 // Links with rel=noreferrer will have no Referer field, and their
3028 // resulting frame will have its window.opener suppressed.
3029 // TODO(creis): should add a request.httpReferrer() method to help avoid
3030 // typos on the unusual spelling of Referer.
3031 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
3032 opener_suppressed_ &&
3033 frame->opener() == NULL &&
3034 // Links with target=_blank will have no name.
3035 frame->name().isNull() &&
3036 // Another frame (with a non-empty creator) should have initiated the
3037 // request, targeted at this frame.
3038 !creator_url_.is_empty() &&
3039 is_content_initiated &&
3040 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3041 type == WebKit::WebNavigationTypeOther;
3042
3043 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:173044 // Open the URL via the browser, not via WebKit.
3045 OpenURL(url, GURL(), default_policy);
3046 return WebKit::WebNavigationPolicyIgnore;
3047 }
3048
3049 return default_policy;
3050}
3051
[email protected]6069da8c2009-10-20 20:33:493052bool RenderView::canHandleRequest(
3053 WebFrame* frame, const WebURLRequest& request) {
3054 // We allow WebKit to think that everything can be handled even though
3055 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:343056 return true;
3057}
3058
[email protected]6069da8c2009-10-20 20:33:493059WebURLError RenderView::cannotHandleRequestError(
3060 WebFrame* frame, const WebURLRequest& request) {
3061 NOTREACHED(); // Since we said we can handle all requests.
3062 return WebURLError();
3063}
3064
3065WebURLError RenderView::cancelledError(
3066 WebFrame* frame, const WebURLRequest& request) {
3067 WebURLError error;
3068 error.domain = WebString::fromUTF8(net::kErrorDomain);
3069 error.reason = net::ERR_ABORTED;
3070 error.unreachableURL = request.url();
3071 return error;
[email protected]7b7a7dc2009-10-19 02:23:343072}
3073
3074void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:493075 WebFrame*, const WebURLError&) {
3076 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:343077}
3078
[email protected]90eeddb2010-05-06 21:06:433079void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
3080 const WebKit::WebFormElement& form) {
3081 // Some login forms have onSubmit handlers that put a hash of the password
3082 // into a hidden field and then clear the password. (Issue 28910.)
3083 // This method gets called before any of those handlers run, so save away
3084 // a copy of the password in case it gets lost.
3085 NavigationState* navigation_state =
3086 NavigationState::FromDataSource(frame->dataSource());
3087 navigation_state->set_password_form_data(
3088 PasswordFormDomManager::CreatePasswordForm(form));
3089}
3090
[email protected]979c28b2009-11-07 01:30:483091void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:173092 NavigationState* navigation_state =
3093 NavigationState::FromDataSource(frame->provisionalDataSource());
3094
3095 if (navigation_state->transition_type() == PageTransition::LINK)
3096 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
3097
3098 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:353099 WebSearchableFormData web_searchable_form_data(form);
3100 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
3101 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:213102 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:433103 PasswordForm* password_form_data =
3104 PasswordFormDomManager::CreatePasswordForm(form);
3105 navigation_state->set_password_form_data(password_form_data);
3106
3107 // If the password has been cleared, recover it from the form contents already
3108 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
3109 // opposed to the provisionalDataSource's, which is what we're storing into
3110 // now.)
3111 if (password_form_data && password_form_data->password_value.empty()) {
3112 NavigationState* old_navigation_state =
3113 NavigationState::FromDataSource(frame->dataSource());
3114 if (old_navigation_state) {
3115 PasswordForm* old_form_data = old_navigation_state->password_form_data();
3116 if (old_form_data && old_form_data->action == password_form_data->action)
3117 password_form_data->password_value = old_form_data->password_value;
3118 }
3119 }
[email protected]3d9689372009-09-10 04:29:173120
[email protected]b1438212010-04-03 00:30:593121 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:043122 if (FormManager::WebFormElementToFormData(
[email protected]5af80432010-11-01 01:25:223123 form,
3124 FormManager::REQUIRE_AUTOCOMPLETE,
[email protected]78192082011-01-29 05:43:443125 static_cast<FormManager::ExtractMask>(
3126 FormManager::EXTRACT_VALUE | FormManager::EXTRACT_OPTION_TEXT),
[email protected]5af80432010-11-01 01:25:223127 &form_data)) {
[email protected]19d6e1e82011-01-26 05:08:583128 Send(new AutoFillHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]5af80432010-11-01 01:25:223129 }
[email protected]3d9689372009-09-10 04:29:173130}
3131
3132void RenderView::willPerformClientRedirect(
3133 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3134 double fire_time) {
3135 // Ignore
3136}
3137
3138void RenderView::didCancelClientRedirect(WebFrame* frame) {
3139 // Ignore
3140}
3141
3142void RenderView::didCompleteClientRedirect(
3143 WebFrame* frame, const WebURL& from) {
3144 if (!frame->parent())
3145 completed_client_redirect_src_ = from;
3146}
3147
3148void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]bb461532010-11-26 21:50:233149 // If there are any app-related fetches in progress, they can be cancelled now
3150 // since we have navigated away from the page that created them.
3151 if (!frame->parent()) {
3152 app_icon_fetchers_.clear();
3153 app_definition_fetcher_.reset(NULL);
3154 }
3155
[email protected]3d9689372009-09-10 04:29:173156 // The rest of RenderView assumes that a WebDataSource will always have a
3157 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:483158 bool content_initiated = !pending_navigation_state_.get();
3159 NavigationState* state = content_initiated ?
3160 NavigationState::CreateContentInitiated() :
3161 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:513162
[email protected]8a3125a712010-08-09 18:58:513163 // NavigationState::referred_by_prefetcher_ is true if we are
3164 // navigating from a page that used prefetching using a link on that
3165 // page. We are early enough in the request process here that we
3166 // can still see the NavigationState of the previous page and set
3167 // this value appropriately.
3168 // TODO(gavinp): catch the important case of navigation in a new
3169 // renderer process.
3170 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303171 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523172 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513173 const GURL referrer(
3174 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3175 if (!referrer.is_empty() &&
3176 NavigationState::FromDataSource(
3177 old_frame->dataSource())->was_prefetcher()) {
3178 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
3179 WebDataSource* old_frame_ds = old_frame->dataSource();
3180 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
3181 state->set_was_referred_by_prefetcher(true);
3182 break;
3183 }
3184 }
3185 }
3186 }
3187 }
3188
[email protected]4c1b6f0b2010-02-07 16:38:183189 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523190 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513191 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183192 case WebURLRequest::UseProtocolCachePolicy: // normal load.
3193 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
3194 break;
3195 case WebURLRequest::ReloadIgnoringCacheData: // reload.
3196 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
3197 break;
3198 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
3199 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
3200 break;
3201 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
3202 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
3203 break;
3204 }
3205 }
[email protected]fa7b6b542009-11-03 05:02:303206
[email protected]5792d932011-01-18 20:33:293207 // If this datasource already has a UserScriptIdleScheduler, reuse that one.
3208 // This is for navigations within a page (didNavigateWithinPage). See
3209 // http://code.google.com/p/chromium/issues/detail?id=64093
3210 NavigationState* old_state = NavigationState::FromDataSource(ds);
3211 if (old_state && old_state->user_script_idle_scheduler()) {
3212 state->swap_user_script_idle_scheduler(old_state);
3213 } else {
3214 state->set_user_script_idle_scheduler(
3215 new UserScriptIdleScheduler(this, frame));
3216 }
[email protected]375e8bd2011-02-07 19:15:353217
3218 // If the RenderView was prerendering before, it is still prerendering.
3219 if (!frame->parent() && content_initiated) {
3220 WebDataSource* ds_old = webview()->mainFrame()->dataSource();
3221 if (ds_old) {
3222 NavigationState* navigation_state =
3223 NavigationState::FromDataSource(ds_old);
3224 if (navigation_state)
3225 state->set_is_prerendering(navigation_state->is_prerendering());
3226 }
3227 }
3228
[email protected]fa7b6b542009-11-03 05:02:303229 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:173230}
3231
3232void RenderView::didStartProvisionalLoad(WebFrame* frame) {
3233 WebDataSource* ds = frame->provisionalDataSource();
3234 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3235
[email protected]3d9689372009-09-10 04:29:173236 // Update the request time if WebKit has better knowledge of it.
3237 if (navigation_state->request_time().is_null()) {
3238 double event_time = ds->triggeringEventTime();
3239 if (event_time != 0.0)
3240 navigation_state->set_request_time(Time::FromDoubleT(event_time));
3241 }
3242
[email protected]05c8e502010-08-15 15:13:523243 // Start time is only set after request time.
3244 navigation_state->set_start_load_time(Time::Now());
3245
[email protected]3d9689372009-09-10 04:29:173246 bool is_top_most = !frame->parent();
3247 if (is_top_most) {
3248 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133249 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173250
3251 // Make sure redirect tracking state is clear for the new load.
3252 completed_client_redirect_src_ = GURL();
3253 } else if (frame->parent()->isLoading()) {
3254 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003255 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:173256 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
3257 }
3258
[email protected]28685da92011-02-07 21:49:173259 FOR_EACH_OBSERVER(
3260 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3261
[email protected]3d9689372009-09-10 04:29:173262 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:073263 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173264}
3265
3266void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
3267 if (frame->parent())
3268 return;
3269 // Received a redirect on the main frame.
3270 WebDataSource* data_source = frame->provisionalDataSource();
3271 if (!data_source) {
3272 // Should only be invoked when we have a data source.
3273 NOTREACHED();
3274 return;
3275 }
3276 std::vector<GURL> redirects;
3277 GetRedirectChain(data_source, &redirects);
3278 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:513279 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3280 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:173281 }
3282}
3283
[email protected]40bd6582009-12-04 23:49:513284void RenderView::didFailProvisionalLoad(WebFrame* frame,
3285 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173286 // Notify the browser that we failed a provisional load with an error.
3287 //
3288 // Note: It is important this notification occur before DidStopLoading so the
3289 // SSL manager can react to the provisional load failure before being
3290 // notified the load stopped.
3291 //
3292 WebDataSource* ds = frame->provisionalDataSource();
3293 DCHECK(ds);
3294
3295 const WebURLRequest& failed_request = ds->request();
3296
[email protected]28685da92011-02-07 21:49:173297 FOR_EACH_OBSERVER(
3298 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3299
[email protected]3d9689372009-09-10 04:29:173300 bool show_repost_interstitial =
3301 (error.reason == net::ERR_CACHE_MISS &&
3302 EqualsASCII(failed_request.httpMethod(), "POST"));
3303 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:073304 routing_id_, frame->identifier(), !frame->parent(), error.reason,
3305 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:173306
3307 // Don't display an error page if this is simply a cancelled load. Aside
3308 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3309 if (error.reason == net::ERR_ABORTED)
3310 return;
3311
3312 // Make sure we never show errors in view source mode.
3313 frame->enableViewSourceMode(false);
3314
3315 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3316
3317 // If this is a failed back/forward/reload navigation, then we need to do a
3318 // 'replace' load. This is necessary to avoid messing up session history.
3319 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3320 // as session history is concerned.
3321 //
3322 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3323 // the page id.
3324 //
3325 bool replace =
3326 navigation_state->pending_page_id() != -1 ||
3327 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
3328
3329 // If we failed on a browser initiated request, then make sure that our error
3330 // page load is regarded as the same browser initiated request.
3331 if (!navigation_state->is_content_initiated()) {
3332 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
3333 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:003334 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:173335 navigation_state->transition_type(),
3336 navigation_state->request_time()));
3337 }
3338
3339 // Provide the user with a more helpful error page?
3340 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3341 return;
3342
3343 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083344 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173345}
3346
3347void RenderView::didReceiveDocumentData(
3348 WebFrame* frame, const char* data, size_t data_len,
3349 bool& prevent_default) {
3350 NavigationState* navigation_state =
3351 NavigationState::FromDataSource(frame->dataSource());
3352 if (!navigation_state->postpone_loading_data())
3353 return;
3354
3355 // We're going to call commitDocumentData ourselves...
3356 prevent_default = true;
3357
[email protected]3f853a52010-09-13 19:15:083358 // Continue buffering the response data for the original error page. If it
3359 // grows too large, then we'll just let it through. For any error other than
3360 // a 404, "too large" means any data at all.
[email protected]3d9689372009-09-10 04:29:173361 navigation_state->append_postponed_data(data, data_len);
[email protected]3f853a52010-09-13 19:15:083362 if (navigation_state->postponed_data().size() >= 512 ||
3363 navigation_state->http_status_code() != 404) {
[email protected]3d9689372009-09-10 04:29:173364 navigation_state->set_postpone_loading_data(false);
3365 frame->commitDocumentData(navigation_state->postponed_data().data(),
3366 navigation_state->postponed_data().size());
3367 navigation_state->clear_postponed_data();
3368 }
3369}
3370
[email protected]40bd6582009-12-04 23:49:513371void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3372 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:173373 NavigationState* navigation_state =
3374 NavigationState::FromDataSource(frame->dataSource());
3375
3376 navigation_state->set_commit_load_time(Time::Now());
3377 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203378 // When we perform a new navigation, we need to update the last committed
3379 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173380 UpdateSessionHistory(frame);
3381
3382 // We bump our Page ID to correspond with the new session history entry.
3383 page_id_ = next_page_id_++;
3384
[email protected]3cc72b12010-03-18 23:03:003385 // Advance our offset in session history, applying the length limit. There
3386 // is now no forward history.
3387 history_list_offset_++;
3388 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3389 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3390 history_list_length_ = history_list_offset_ + 1;
3391
[email protected]f9f4841b2010-03-20 05:41:423392 MessageLoop::current()->PostDelayedTask(
3393 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303394 page_info_method_factory_.NewRunnableMethod(
3395 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173396 kDelayForForcedCaptureMs);
3397 } else {
3398 // Inspect the navigation_state on this frame to see if the navigation
3399 // corresponds to a session history navigation... Note: |frame| may or
3400 // may not be the toplevel frame, but for the case of capturing session
3401 // history, the first committed frame suffices. We keep track of whether
3402 // we've seen this commit before so that only capture session history once
3403 // per navigation.
3404 //
3405 // Note that we need to check if the page ID changed. In the case of a
3406 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3407 // previous URL and the current page ID, which would be wrong.
3408 if (navigation_state->pending_page_id() != -1 &&
3409 navigation_state->pending_page_id() != page_id_ &&
3410 !navigation_state->request_committed()) {
3411 // This is a successful session history navigation!
3412 UpdateSessionHistory(frame);
3413 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003414
3415 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173416 }
3417 }
3418
[email protected]28685da92011-02-07 21:49:173419 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3420 DidCommitProvisionalLoad(frame, is_new_navigation));
3421
[email protected]3d9689372009-09-10 04:29:173422 // Remember that we've already processed this request, so we don't update
3423 // the session history again. We do this regardless of whether this is
3424 // a session history navigation, because if we attempted a session history
3425 // navigation without valid HistoryItem state, WebCore will think it is a
3426 // new navigation.
3427 navigation_state->set_request_committed(true);
3428
3429 UpdateURL(frame);
3430
3431 // If this committed load was initiated by a client redirect, we're
3432 // at the last stop now, so clear it.
3433 completed_client_redirect_src_ = GURL();
3434
3435 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273436 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173437}
3438
3439void RenderView::didClearWindowObject(WebFrame* frame) {
3440 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3441 BindDOMAutomationController(frame);
[email protected]0d7ae862010-10-01 13:52:453442 GURL frame_url = frame->url();
3443 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:253444 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]731ae512010-10-15 18:20:173445 frame_url.SchemeIs(chrome::kGearsScheme) ||
[email protected]bfa83eb82010-10-06 08:41:253446 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273447 GetWebUIBindings()->set_message_sender(this);
3448 GetWebUIBindings()->set_routing_id(routing_id_);
3449 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173450 }
3451 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463452 GetExternalHostBindings()->set_message_sender(this);
3453 GetExternalHostBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253454 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
[email protected]3d9689372009-09-10 04:29:173455 }
3456}
3457
3458void RenderView::didCreateDocumentElement(WebFrame* frame) {
3459 if (RenderThread::current()) { // Will be NULL during unit tests.
3460 RenderThread::current()->user_script_slave()->InjectScripts(
3461 frame, UserScript::DOCUMENT_START);
3462 }
3463
3464 // Notify the browser about non-blank documents loading in the top frame.
3465 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253466 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273467 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173468 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3469 }
3470}
3471
3472void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3473 UpdateTitle(frame, title);
3474
3475 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273476 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173477}
3478
[email protected]5019ef12010-04-27 17:26:583479void RenderView::didChangeIcons(WebFrame* frame) {
3480 if (!frame->parent()) {
3481 Send(new ViewHostMsg_UpdateFavIconURL(
3482 routing_id_,
3483 page_id_,
3484 frame->favIconURL()));
3485 }
3486}
3487
[email protected]3d9689372009-09-10 04:29:173488void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3489 WebDataSource* ds = frame->dataSource();
3490 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3491 DCHECK(navigation_state);
3492 navigation_state->set_finish_document_load_time(Time::Now());
3493
[email protected]622474d2010-11-04 09:21:083494 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173495
[email protected]28685da92011-02-07 21:49:173496 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3497 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173498
3499 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273500 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173501
3502 if (RenderThread::current()) { // Will be NULL during unit tests.
3503 RenderThread::current()->user_script_slave()->InjectScripts(
3504 frame, UserScript::DOCUMENT_END);
3505 }
[email protected]fa7b6b542009-11-03 05:02:303506
[email protected]41f16632010-10-20 01:21:323507 // InjectScripts() can end up creating a new NavigationState if it triggers a
3508 // fragment navigation, so we need to re-fetch it here.
3509 navigation_state = NavigationState::FromDataSource(ds);
[email protected]fa7b6b542009-11-03 05:02:303510 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3511}
3512
3513void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3514 if (RenderThread::current()) { // Will be NULL during unit tests.
3515 RenderThread::current()->user_script_slave()->InjectScripts(
3516 frame, UserScript::DOCUMENT_IDLE);
3517 }
3518
3519 WebFrame* main_frame = webview()->mainFrame();
3520 if (frame == main_frame) {
3521 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203522 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303523 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203524 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303525 pending_code_execution_queue_.pop();
3526 }
3527 }
[email protected]3d9689372009-09-10 04:29:173528}
3529
3530void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083531 if (webview()->mainFrame() == frame) {
3532 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3533 page_id_));
3534 }
[email protected]3d9689372009-09-10 04:29:173535}
3536
3537void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:173538 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:173539}
3540
3541void RenderView::didFinishLoad(WebFrame* frame) {
3542 WebDataSource* ds = frame->dataSource();
3543 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3544 DCHECK(navigation_state);
3545 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303546 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413547
[email protected]676126f72011-01-15 00:03:513548 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173549
3550 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173551}
3552
[email protected]ccbe04e2010-03-17 17:58:433553void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173554 WebFrame* frame, bool is_new_navigation) {
3555 // If this was a reference fragment navigation that we initiated, then we
3556 // could end up having a non-null pending navigation state. We just need to
3557 // update the ExtraData on the datasource so that others who read the
3558 // ExtraData will get the new NavigationState. Similarly, if we did not
3559 // initiate this navigation, then we need to take care to reset any pre-
3560 // existing navigation state to a content-initiated navigation state.
3561 // DidCreateDataSource conveniently takes care of this for us.
3562 didCreateDataSource(frame, frame->dataSource());
3563
[email protected]af15bed2010-08-25 21:12:093564 NavigationState* new_state =
3565 NavigationState::FromDataSource(frame->dataSource());
3566 new_state->set_was_within_same_page(true);
3567
[email protected]3d9689372009-09-10 04:29:173568 didCommitProvisionalLoad(frame, is_new_navigation);
3569
[email protected]26aa0482009-09-30 16:55:273570 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173571}
3572
[email protected]476b6f82009-09-10 21:00:593573void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313574 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593575}
3576
[email protected]3d9689372009-09-10 04:29:173577void RenderView::assignIdentifierToRequest(
3578 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3579 // Ignore
3580}
3581
3582void RenderView::willSendRequest(
3583 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3584 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303585 WebFrame* top_frame = frame->top();
3586 if (!top_frame)
3587 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513588 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3589 WebDataSource* top_data_source = top_frame->dataSource();
3590 WebDataSource* data_source =
3591 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223592
3593 // If the request is for an extension resource, check whether it should be
3594 // allowed. If not allowed, we reset the URL to something invalid to prevent
3595 // the request and cause an error.
3596 GURL request_url(request.url());
3597 if (request_url.SchemeIs(chrome::kExtensionScheme) &&
3598 !ExtensionResourceRequestPolicy::CanRequestResource(
3599 request_url,
3600 GURL(frame->url()),
3601 render_thread_->GetExtensions())) {
3602 request.setURL(WebURL(GURL("chrome-extension://invalid/")));
3603 }
3604
[email protected]5e369672009-11-03 23:48:303605 if (data_source) {
3606 NavigationState* state = NavigationState::FromDataSource(data_source);
3607 if (state && state->is_cache_policy_override_set())
3608 request.setCachePolicy(state->cache_policy_override());
3609 }
[email protected]8a3125a712010-08-09 18:58:513610
3611 if (top_data_source) {
3612 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3613 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3614 state->set_was_prefetcher(true);
3615 }
3616
[email protected]3d9689372009-09-10 04:29:173617 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133618 request.setHasUserGesture(frame->isProcessingUserGesture());
3619
[email protected]c5bbc2452010-03-08 08:33:503620 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133621 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493622
[email protected]85cc78c2010-05-04 18:30:093623 // Temporary metrics, see site_isolation_metrics.h
3624 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173625}
3626
3627void RenderView::didReceiveResponse(
3628 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493629
[email protected]85cc78c2010-05-04 18:30:093630 // Temporary metrics, see site_isolation_metrics.h
3631 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3632 identifier,
3633 response);
[email protected]fa0a3432010-03-30 16:53:493634
[email protected]3d9689372009-09-10 04:29:173635 // Only do this for responses that correspond to a provisional data source
3636 // of the top-most frame. If we have a provisional data source, then we
3637 // can't have any sub-resources yet, so we know that this response must
3638 // correspond to a frame load.
3639 if (!frame->provisionalDataSource() || frame->parent())
3640 return;
3641
3642 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083643 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173644 if (frame->isViewSourceModeEnabled())
3645 return;
3646
[email protected]65041fa2010-05-21 06:56:533647 NavigationState* navigation_state =
3648 NavigationState::FromDataSource(frame->provisionalDataSource());
3649 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083650 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533651
[email protected]972ebdff2010-06-10 22:59:073652 // Record page load flags.
3653 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3654 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573655 navigation_state->set_was_alternate_protocol_available(
3656 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073657 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083658 navigation_state->set_http_status_code(http_status_code);
[email protected]65041fa2010-05-21 06:56:533659
[email protected]f48013be2010-01-14 22:07:453660 // Consider loading an alternate error page for 404 responses.
[email protected]3f853a52010-09-13 19:15:083661 if (http_status_code == 404) {
3662 // Can we even load an alternate error page for this URL?
3663 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3664 return;
3665 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3666 http_status_code)) {
3667 // If no corresponding error strings for a particular status code, just
3668 // render any received data, regardless of whether or not the status code
3669 // indicates an error.
[email protected]f48013be2010-01-14 22:07:453670 return;
[email protected]3f853a52010-09-13 19:15:083671 }
[email protected]3d9689372009-09-10 04:29:173672
[email protected]3d9689372009-09-10 04:29:173673 navigation_state->set_postpone_loading_data(true);
3674 navigation_state->clear_postponed_data();
3675}
3676
3677void RenderView::didFinishResourceLoad(
3678 WebFrame* frame, unsigned identifier) {
3679 NavigationState* navigation_state =
3680 NavigationState::FromDataSource(frame->dataSource());
3681 if (!navigation_state->postpone_loading_data())
3682 return;
3683
[email protected]3f853a52010-09-13 19:15:083684 // The server returned an error and the content was < 512 bytes (which we
[email protected]3d9689372009-09-10 04:29:173685 // suppressed). Go ahead and fetch the alternate page content.
[email protected]3f853a52010-09-13 19:15:083686 int http_status_code = navigation_state->http_status_code();
3687 if (http_status_code == 404) {
3688 // On 404s, try a remote search page as a fallback.
3689 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173690
[email protected]3f853a52010-09-13 19:15:083691 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3692 DCHECK(error_page_url.is_valid());
[email protected]3d9689372009-09-10 04:29:173693
[email protected]3f853a52010-09-13 19:15:083694 WebURLError original_error;
3695 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173696
[email protected]3f853a52010-09-13 19:15:083697 navigation_state->set_alt_error_page_fetcher(
3698 new AltErrorPageResourceFetcher(
3699 error_page_url, frame, original_error,
3700 NewCallback(this, &RenderView::AltErrorPageFinished)));
3701 } else {
3702 // On other errors, use an internal error page.
3703 WebURLError error;
3704 error.unreachableURL = frame->url();
3705 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3706 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173707
[email protected]3f853a52010-09-13 19:15:083708 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3709 std::string(), true);
3710 }
[email protected]3d9689372009-09-10 04:29:173711}
3712
3713void RenderView::didFailResourceLoad(
3714 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3715 // Ignore
3716}
3717
3718void RenderView::didLoadResourceFromMemoryCache(
3719 WebFrame* frame, const WebURLRequest& request,
3720 const WebURLResponse& response) {
3721 // Let the browser know we loaded a resource from the memory cache. This
3722 // message is needed to display the correct SSL indicators.
3723 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3724 routing_id_,
3725 request.url(),
[email protected]91733b62009-09-18 06:21:093726 frame->securityOrigin().toString().utf8(),
3727 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173728 response.securityInfo()));
3729}
3730
[email protected]6069da8c2009-10-20 20:33:493731void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293732 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3733}
3734
[email protected]92771112011-01-20 00:13:023735void RenderView::didRunInsecureContent(
3736 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293737 Send(new ViewHostMsg_DidRunInsecureContent(
3738 routing_id_,
[email protected]92771112011-01-20 00:13:023739 origin.toString().utf8(),
3740 target));
[email protected]e3d60e5d2009-09-25 21:08:293741}
3742
[email protected]7ea093ba2009-11-03 05:54:593743bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403744 if (enabled_per_settings &&
3745 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3746 return true;
[email protected]7ea093ba2009-11-03 05:54:593747
[email protected]12bc8472010-04-15 07:29:403748 if (IsWhitelistedForContentSettings(frame))
3749 return true;
[email protected]7ea093ba2009-11-03 05:54:593750
3751 return false; // Other protocols fall through here.
3752}
3753
[email protected]0a1a45432010-03-31 08:09:453754bool RenderView::allowDatabase(
3755 WebFrame* frame, const WebString& name, const WebString& display_name,
3756 unsigned long estimated_size) {
3757 WebSecurityOrigin origin = frame->securityOrigin();
3758 if (origin.isEmpty())
3759 return false; // Uninitialized document?
3760
3761 bool result;
[email protected]26a9acf2010-12-13 19:35:053762 if (!Send(new DatabaseHostMsg_Allow(routing_id_,
[email protected]0a1a45432010-03-31 08:09:453763 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3764 return false;
[email protected]9fb83e82010-07-02 18:24:553765 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3766 GURL(origin.toString().utf8()),
3767 name,
3768 display_name,
3769 estimated_size,
3770 !result));
[email protected]0a1a45432010-03-31 08:09:453771 return result;
3772}
[email protected]8934a3b2010-02-25 00:34:003773void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283774 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003775}
3776
[email protected]c21f1d52010-03-04 03:19:433777void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283778 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433779}
3780
[email protected]3d9689372009-09-10 04:29:173781void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3782 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3783}
3784
[email protected]0c882b282009-10-07 17:01:283785void RenderView::didCreateScriptContext(WebFrame* frame) {
3786 EventBindings::HandleContextCreated(frame, false);
3787}
3788
3789void RenderView::didDestroyScriptContext(WebFrame* frame) {
3790 EventBindings::HandleContextDestroyed(frame);
3791}
3792
3793void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3794 EventBindings::HandleContextCreated(frame, true);
3795}
3796
[email protected]af7eb3fb2010-09-23 21:31:063797bool RenderView::allowScriptExtension(WebFrame* frame,
3798 const WebString& extension_name,
3799 int extension_group) {
3800 // NULL in unit tests.
3801 if (!RenderThread::current())
3802 return true;
3803
3804 // Note: we prefer the provisional URL here instead of the document URL
3805 // because we might be currently loading an URL into a blank page.
3806 // See http://code.google.com/p/chromium/issues/detail?id=10924
3807 WebDataSource* ds = frame->provisionalDataSource();
3808 if (!ds)
3809 ds = frame->dataSource();
3810 return RenderThread::current()->AllowScriptExtension(
3811 extension_name.utf8(), ds->request().url(), extension_group);
3812}
3813
[email protected]fc86daa2010-03-30 23:52:533814void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3815 WebFrame* target,
3816 bool cross_origin,
3817 const WebString& property_name,
3818 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103819 // TODO(johnnyg): track the individual properties and repeat event_ids.
[email protected]a5a65ac2010-11-05 18:14:363820 page_load_histograms_.IncrementCrossFramePropertyAccess(cross_origin);
[email protected]ab9eabac2010-03-16 16:54:103821}
3822
[email protected]3d9689372009-09-10 04:29:173823void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143824 CheckPreferredSize();
3825}
3826
3827void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173828 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253829 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173830 // message.
[email protected]705243f2010-05-05 19:58:073831 if (!send_preferred_size_changes_ || !webview())
3832 return;
[email protected]dfca5acf2010-03-22 03:28:433833
[email protected]705243f2010-05-05 19:58:073834 // WebCore likes to tell us things have changed even when they haven't, so
3835 // cache the width and height and only send the IPC message when we're sure
3836 // they're different.
3837 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3838 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533839
3840 // In the presence of zoom, these sizes are still reported as if unzoomed,
3841 // so we need to adjust.
3842 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3843 size.set_width(static_cast<int>(size.width() * zoom_factor));
3844 size.set_height(static_cast<int>(size.height() * zoom_factor));
3845
[email protected]705243f2010-05-05 19:58:073846 if (size == preferred_size_)
3847 return;
[email protected]c27324b2009-11-19 22:44:293848
[email protected]705243f2010-05-05 19:58:073849 preferred_size_ = size;
3850 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3851 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173852}
3853
[email protected]143dcd592009-11-06 21:33:493854void RenderView::didChangeScrollOffset(WebFrame* frame) {
3855 StartNavStateSyncTimerIfNecessary();
3856}
3857
[email protected]8922e1f2009-10-03 05:01:263858void RenderView::reportFindInPageMatchCount(int request_id, int count,
3859 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113860 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3861 if (!count)
3862 active_match_ordinal = 0;
3863
3864 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3865 routing_id_,
3866 request_id,
3867 count,
3868 gfx::Rect(),
3869 active_match_ordinal,
3870 final_update);
3871
[email protected]8922e1f2009-10-03 05:01:263872 // If we have a message that has been queued up, then we should just replace
3873 // it. The ACK from the browser will make sure it gets sent when the browser
3874 // wants it.
3875 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263876 queued_find_reply_message_.reset(msg);
3877 } else {
3878 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113879 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263880 }
3881}
3882
3883void RenderView::reportFindInPageSelection(int request_id,
3884 int active_match_ordinal,
3885 const WebRect& selection_rect) {
3886 // Send the search result over to the browser process.
3887 Send(new ViewHostMsg_Find_Reply(routing_id_,
3888 request_id,
3889 -1,
3890 selection_rect,
3891 active_match_ordinal,
3892 false));
3893}
3894
[email protected]2b06a992010-08-21 05:48:223895void RenderView::openFileSystem(
3896 WebFrame* frame,
3897 WebFileSystem::Type type,
3898 long long size,
[email protected]d275d7a2010-11-03 01:34:493899 bool create,
[email protected]2b06a992010-08-21 05:48:223900 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083901 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223902
3903 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:083904 if (origin.isEmpty()) {
3905 // Uninitialized document?
3906 callbacks->didFail(WebKit::WebFileErrorAbort);
3907 return;
3908 }
[email protected]2b06a992010-08-21 05:48:223909
[email protected]c5a272d2010-09-27 18:37:083910 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3911 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493912 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223913}
3914
[email protected]79dbc662009-09-04 05:42:513915// webkit_glue::WebPluginPageDelegate -----------------------------------------
3916
[email protected]191eb3f72010-12-21 06:27:503917webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533918 const FilePath& file_path,
3919 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593920 if (!PluginChannelHost::IsListening())
3921 return NULL;
3922
[email protected]d2139662009-12-10 03:21:143923 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283924 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143925 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163926 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533927 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143928 if (CommandLine::ForCurrentProcess()->
3929 HasSwitch(switches::kInternalPepper)) {
3930 in_process_plugin = true;
3931 use_pepper_host = true;
3932 } else {
3933 // In process Pepper plugins must be explicitly enabled.
3934 return NULL;
3935 }
[email protected]4e0616e2010-05-28 14:55:533936 } else {
3937 FilePath internal_pdf_path;
3938 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3939 if (file_path == internal_pdf_path) {
3940 in_process_plugin = true;
3941 use_pepper_host = true;
3942 }
[email protected]26e8d5e2009-10-13 02:47:163943 }
[email protected]4e0616e2010-05-28 14:55:533944
[email protected]d032f492009-09-29 00:33:463945 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143946 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283947 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533948 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333949 if (!pepper_plugin)
3950 return NULL;
3951
[email protected]53900d52010-06-16 04:25:013952 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283953 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143954 } else {
[email protected]6876dff2010-01-15 19:38:093955#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]191eb3f72010-12-21 06:27:503956 return webkit::npapi::WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533957 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093958#else
[email protected]596b2c42010-01-14 20:40:433959 NOTIMPLEMENTED();
3960 return NULL;
[email protected]7b6616f2010-01-14 18:07:553961#endif
[email protected]6876dff2010-01-15 19:38:093962 }
[email protected]f103ab72009-09-02 17:10:593963 }
3964
[email protected]4e0616e2010-05-28 14:55:533965 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593966}
3967
3968void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033969#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593970 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3971 routing_id(), window));
3972#endif
3973}
3974
3975void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033976#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593977 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3978 routing_id(), window));
3979#endif
3980 CleanupWindowInPluginMoves(window);
3981}
3982
[email protected]191eb3f72010-12-21 06:27:503983void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593984 SchedulePluginMove(move);
3985}
3986
3987void RenderView::DidStartLoadingForPlugin() {
3988 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523989 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593990}
3991
3992void RenderView::DidStopLoadingForPlugin() {
3993 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523994 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593995}
3996
3997void RenderView::ShowModalHTMLDialogForPlugin(
3998 const GURL& url,
3999 const gfx::Size& size,
4000 const std::string& json_arguments,
4001 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:214002 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:594003 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:214004 json_retval));
[email protected]f103ab72009-09-02 17:10:594005}
4006
[email protected]b921cfd22010-02-25 16:57:514007WebCookieJar* RenderView::GetCookieJar() {
4008 return &cookie_jar_;
4009}
4010
initial.commit09911bf2008-07-26 23:55:294011void RenderView::SyncNavigationState() {
4012 if (!webview())
4013 return;
4014
[email protected]26aa0482009-09-30 16:55:274015 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:174016 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:294017 return;
[email protected]ca948a22009-06-25 19:36:174018
4019 Send(new ViewHostMsg_UpdateState(
4020 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:294021}
4022
[email protected]b0950a72009-09-29 23:16:174023bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
4024 // Make sure webview was not shut down.
4025 if (!webview())
4026 return false;
4027 // Create an image resource fetcher and assign it with a call back object.
[email protected]bb461532010-11-26 21:50:234028 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
4029 new ImageResourceFetcher(
4030 image_url, webview()->mainFrame(), id, image_size,
4031 NewCallback(this, &RenderView::DidDownloadImage))));
[email protected]b0950a72009-09-29 23:16:174032 return true;
4033}
4034
4035void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:294036 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:174037 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:474038 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
4039 fetcher->id(),
4040 fetcher->image_url(),
4041 image.isNull(),
4042 image));
[email protected]bb461532010-11-26 21:50:234043
4044 // Remove the image fetcher from our pending list. We're in the callback from
4045 // ImageResourceFetcher, best to delay deletion.
4046 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin();
4047 iter != image_fetchers_.end(); ++iter) {
4048 if (iter->get() == fetcher) {
4049 iter->release();
4050 image_fetchers_.erase(iter);
4051 break;
4052 }
4053 }
[email protected]b0950a72009-09-29 23:16:174054 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:294055}
4056
[email protected]bf5c2ff392009-07-08 16:24:334057void RenderView::OnDownloadFavIcon(int id,
4058 const GURL& image_url,
4059 int image_size) {
[email protected]f11ca0732009-04-11 00:09:344060 bool data_image_failed = false;
4061 if (image_url.SchemeIs("data")) {
4062 SkBitmap data_image = ImageFromDataUrl(image_url);
4063 data_image_failed = data_image.empty();
4064 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:334065 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
4066 data_image));
[email protected]f11ca0732009-04-11 00:09:344067 }
4068 }
4069
[email protected]bf5c2ff392009-07-08 16:24:334070 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:174071 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:334072 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
4073 SkBitmap()));
4074 }
initial.commit09911bf2008-07-26 23:55:294075}
4076
[email protected]f11ca0732009-04-11 00:09:344077SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
4078 std::string mime_type, char_set, data;
4079 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
4080 // Decode the favicon using WebKit's image decoder.
4081 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
4082 const unsigned char* src_data =
4083 reinterpret_cast<const unsigned char*>(&data[0]);
4084
4085 return decoder.Decode(src_data, data.size());
4086 }
4087 return SkBitmap();
4088}
4089
initial.commit09911bf2008-07-26 23:55:294090void RenderView::OnGetApplicationInfo(int page_id) {
[email protected]38789d82010-11-17 06:03:444091 WebApplicationInfo app_info;
4092 if (page_id == page_id_) {
4093 string16 error;
4094 web_apps::ParseWebAppFromWebDocument(webview()->mainFrame(), &app_info,
4095 &error);
4096 }
initial.commit09911bf2008-07-26 23:55:294097
4098 // Prune out any data URLs in the set of icons. The browser process expects
4099 // any icon with a data URL to have originated from a favicon. We don't want
4100 // to decode arbitrary data URLs in the browser process. See
4101 // http://b/issue?id=1162972
4102 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:594103 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:294104 app_info.icons.erase(app_info.icons.begin() + i);
4105 --i;
4106 }
4107 }
4108
4109 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
4110}
4111
[email protected]7ccddb8c2009-08-04 17:36:554112GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:294113 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554114 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294115 // If the URL that failed was secure, then the embedding web page was not
4116 // expecting a network attacker to be able to manipulate its contents. As
4117 // we fetch alternate error pages over HTTP, we would be allowing a network
4118 // attacker to manipulate the contents of the response if we tried to use
4119 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154120 return GURL();
initial.commit09911bf2008-07-26 23:55:294121 }
4122
4123 // Grab the base URL from the browser process.
4124 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154125 return GURL();
initial.commit09911bf2008-07-26 23:55:294126
4127 // Strip query params from the failed URL.
4128 GURL::Replacements remove_params;
4129 remove_params.ClearUsername();
4130 remove_params.ClearPassword();
4131 remove_params.ClearQuery();
4132 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554133 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504134 std::string spec_to_send = url_to_send.spec();
4135 // Notify link doctor of the url truncation by sending of "?" at the end.
4136 if (failed_url.has_query())
4137 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294138
4139 // Construct the query params to send to link doctor.
4140 std::string params(alternate_error_page_url_.query());
4141 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:504142 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294143 params.append("&sourceid=chrome");
4144 params.append("&error=");
4145 switch (error_type) {
4146 case DNS_ERROR:
4147 params.append("dnserror");
4148 break;
4149
4150 case HTTP_404:
4151 params.append("http404");
4152 break;
4153
[email protected]5df266ac2008-10-15 19:50:134154 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334155 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134156 break;
4157
initial.commit09911bf2008-07-26 23:55:294158 default:
4159 NOTREACHED() << "unknown ErrorPageType";
4160 }
4161
4162 // OK, build the final url to return.
4163 GURL::Replacements link_doctor_params;
4164 link_doctor_params.SetQueryStr(params);
4165 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4166 return url;
4167}
4168
[email protected]c50008512011-02-03 01:17:274169WebUIBindings* RenderView::GetWebUIBindings() {
4170 if (!web_ui_bindings_.get()) {
4171 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:464172 }
[email protected]c50008512011-02-03 01:17:274173 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464174}
4175
4176ExternalHostBindings* RenderView::GetExternalHostBindings() {
4177 if (!external_host_bindings_.get()) {
4178 external_host_bindings_.reset(new ExternalHostBindings());
4179 }
4180 return external_host_bindings_.get();
4181}
4182
[email protected]0fdbf8c2010-07-08 20:33:014183WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
4184 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494185}
4186
[email protected]6069da8c2009-10-20 20:33:494187void RenderView::OnFind(int request_id, const string16& search_text,
4188 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274189 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494190
4191 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494192 if (options.findNext) {
4193 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014194 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494195 } else {
[email protected]afdbd142010-07-10 08:01:234196 if (GetWebPluginFromPluginDocument()->startFind(
4197 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494198 } else {
[email protected]e7c58a32010-08-13 19:47:114199 // Send "no results".
4200 Send(new ViewHostMsg_Find_Reply(routing_id_,
4201 request_id,
4202 0,
4203 gfx::Rect(),
4204 0,
4205 true));
[email protected]24a7f3c2010-03-25 08:26:494206 }
4207 }
4208 return;
4209 }
4210
[email protected]b4bb2502009-10-01 22:35:274211 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274212 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294213 WebFrame* search_frame = focused_frame; // start searching focused frame.
4214
4215 bool multi_frame = (frame_after_main != main_frame);
4216
4217 // If we have multiple frames, we don't want to wrap the search within the
4218 // frame, so we check here if we only have main_frame in the chain.
4219 bool wrap_within_frame = !multi_frame;
4220
[email protected]b3f2b912009-04-09 16:18:524221 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294222 bool result = false;
4223
[email protected]7830da3e2009-11-06 16:27:264224 // If something is selected when we start searching it means we cannot just
4225 // increment the current match ordinal; we need to re-generate it.
4226 WebRange current_selection = focused_frame->selectionRange();
4227
initial.commit09911bf2008-07-26 23:55:294228 do {
[email protected]dd7daa82009-08-10 05:46:454229 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594230 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294231
4232 if (!result) {
4233 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224234 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294235
4236 // Find the next frame, but skip the invisible ones.
4237 do {
4238 // What is the next frame to search? (we might be going backwards). Note
4239 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594240 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274241 search_frame->traverseNext(true) :
4242 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454243 } while (!search_frame->hasVisibleContent() &&
4244 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294245
[email protected]884db412008-11-24 23:46:504246 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224247 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294248
4249 // If we have multiple frames and we have wrapped back around to the
4250 // focused frame, we need to search it once more allowing wrap within
4251 // the frame, otherwise it will report 'no match' if the focused frame has
4252 // reported matches, but no frames after the focused_frame contain a
4253 // match for the search word(s).
4254 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454255 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594256 request_id, search_text, options, true, // Force wrapping.
4257 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294258 }
4259 }
4260
[email protected]26aa0482009-09-30 16:55:274261 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294262 } while (!result && search_frame != focused_frame);
4263
[email protected]7830da3e2009-11-06 16:27:264264 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294265 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454266 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294267 } else {
4268 // If nothing is found, set result to "0 of 0", otherwise, set it to
4269 // "-1 of 1" to indicate that we found at least one item, but we don't know
4270 // yet what is active.
4271 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4272 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294273
[email protected]4f3dc372009-02-24 00:10:294274 // If we find no matches then this will be our last status update.
4275 // Otherwise the scoping effort will send more results.
4276 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294277
[email protected]4f3dc372009-02-24 00:10:294278 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404279 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594280 request_id,
[email protected]4f3dc372009-02-24 00:10:294281 match_count,
4282 selection_rect,
4283 ordinal,
4284 final_status_update));
initial.commit09911bf2008-07-26 23:55:294285
initial.commit09911bf2008-07-26 23:55:294286 // Scoping effort begins, starting with the mainframe.
4287 search_frame = main_frame;
4288
[email protected]dd7daa82009-08-10 05:46:454289 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294290
4291 do {
4292 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454293 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294294
4295 // We don't start another scoping effort unless at least one match has
4296 // been found.
4297 if (result) {
4298 // Start new scoping request. If the scoping function determines that it
4299 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454300 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594301 search_text,
4302 options,
initial.commit09911bf2008-07-26 23:55:294303 true); // reset the tickmarks
4304 }
4305
4306 // Iterate to the next frame. The frame will not necessarily scope, for
4307 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274308 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294309 } while (search_frame != main_frame);
4310 }
4311}
4312
[email protected]24a7f3c2010-03-25 08:26:494313void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
4314 WebView* view = webview();
4315 if (!view)
4316 return;
4317
4318 WebDocument doc = view->mainFrame()->document();
4319 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014320 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494321 return;
4322 }
4323
4324 bool clear_selection =
4325 params.action == ViewMsg_StopFinding_Params::kClearSelection;
4326 if (clear_selection)
4327 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4328
4329 WebFrame* frame = view->mainFrame();
4330 while (frame) {
4331 frame->stopFinding(clear_selection);
4332 frame = frame->traverseNext(false);
4333 }
4334
4335 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
4336 WebFrame* focused_frame = view->focusedFrame();
4337 if (focused_frame) {
4338 WebDocument doc = focused_frame->document();
4339 if (!doc.isNull()) {
4340 WebNode node = doc.focusedNode();
4341 if (!node.isNull())
4342 node.simulateClick();
4343 }
4344 }
4345 }
4346}
4347
4348void RenderView::OnFindReplyAck() {
4349 // Check if there is any queued up request waiting to be sent.
4350 if (queued_find_reply_message_.get()) {
4351 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424352 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494353 }
4354}
4355
[email protected]8934a3b2010-02-25 00:34:004356bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:354357 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:004358 return current_content_settings_.settings[settings_type] !=
4359 CONTENT_SETTING_BLOCK;
4360}
4361
[email protected]55126132010-08-19 14:53:284362void RenderView::DidBlockContentType(ContentSettingsType settings_type,
4363 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:004364 if (!content_blocked_[settings_type]) {
4365 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:284366 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
4367 resource_identifier));
[email protected]0de80162010-02-03 04:52:354368 }
[email protected]0de80162010-02-03 04:52:354369}
4370
[email protected]71b0d5d2010-02-15 05:43:074371void RenderView::ClearBlockedContentSettings() {
4372 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4373 content_blocked_[i] = false;
4374}
4375
[email protected]0bd753682010-12-16 18:15:524376WebPlugin* RenderView::CreatePepperPlugin(
4377 WebFrame* frame,
4378 const WebPluginParams& params,
4379 const FilePath& path,
4380 webkit::ppapi::PluginModule* pepper_module) {
4381 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:254382 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:094383}
[email protected]00152e92010-07-19 11:47:404384
[email protected]191eb3f72010-12-21 06:27:504385WebPlugin* RenderView::CreateNPAPIPlugin(
4386 WebFrame* frame,
4387 const WebPluginParams& params,
4388 const FilePath& path,
4389 const std::string& mime_type) {
4390 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:084391 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404392}
4393
[email protected]3c2826852010-12-16 19:09:144394WebPlugin* RenderView::CreatePluginPlaceholder(
[email protected]57b66d02010-09-30 11:24:514395 WebFrame* frame,
4396 const WebPluginParams& params,
[email protected]191eb3f72010-12-21 06:27:504397 const webkit::npapi::PluginGroup& group,
[email protected]3c2826852010-12-16 19:09:144398 int resource_id,
[email protected]90dba072011-01-20 20:10:204399 int message_id,
4400 bool is_blocked_for_prerendering) {
[email protected]3c2826852010-12-16 19:09:144401 // |blocked_plugin| will delete itself when the WebViewPlugin
4402 // is destroyed.
4403 BlockedPlugin* blocked_plugin =
4404 new BlockedPlugin(this,
4405 frame,
4406 group,
4407 params,
4408 webkit_preferences_,
4409 resource_id,
[email protected]2e34ab3f2010-12-17 05:47:374410 l10n_util::GetStringFUTF16(message_id,
[email protected]90dba072011-01-20 20:10:204411 group.GetGroupName()),
4412 is_blocked_for_prerendering);
[email protected]3c2826852010-12-16 19:09:144413 return blocked_plugin->plugin();
[email protected]57b66d02010-09-30 11:24:514414}
4415
[email protected]40bd6582009-12-04 23:49:514416void RenderView::OnZoom(PageZoom::Function function) {
4417 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4418 return;
4419
[email protected]258d31122010-05-09 10:59:414420 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524421
[email protected]b75b8292010-10-01 07:28:254422 double old_zoom_level = webview()->zoomLevel();
4423 double zoom_level;
4424 if (function == PageZoom::RESET) {
4425 zoom_level = 0;
4426 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4427 // Previous zoom level is a whole number, so just increment/decrement.
4428 zoom_level = old_zoom_level + function;
4429 } else {
4430 // Either the user hit the zoom factor limit and thus the zoom level is now
4431 // not a whole number, or a plugin changed it to a custom value. We want
4432 // to go to the next whole number so that the user can always get back to
4433 // 100% with the keyboard/menu.
4434 if ((old_zoom_level > 1 && function > 0) ||
4435 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:454436 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:254437 } else {
4438 // We're going towards 100%, so first go to the next whole number.
4439 zoom_level = static_cast<int>(old_zoom_level);
4440 }
4441 }
[email protected]40bd6582009-12-04 23:49:514442
[email protected]b75b8292010-10-01 07:28:254443 webview()->setZoomLevel(false, zoom_level);
4444 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:514445}
4446
[email protected]d0b8d092010-10-25 04:05:174447void RenderView::OnSetZoomLevel(double zoom_level) {
4448 // Don't set zoom level for full-page plugin since they don't use the same
4449 // zoom settings.
4450 if (webview()->mainFrame()->document().isPluginDocument())
4451 return;
4452
4453 webview()->hidePopups();
4454 webview()->setZoomLevel(false, zoom_level);
4455 zoomLevelChanged();
4456}
4457
[email protected]9d797f32010-04-23 07:17:544458void RenderView::OnSetContentSettingsForLoadingURL(
4459 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014460 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544461 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014462}
4463
[email protected]9d797f32010-04-23 07:17:544464void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:254465 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544466 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294467}
4468
[email protected]41fc0322009-09-04 22:23:404469void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274470 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294471}
4472
[email protected]a697f4c2009-09-14 22:30:184473void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274474 WebString no_encoding;
4475 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184476}
4477
[email protected]20ad2692009-11-20 18:27:204478bool RenderView::GetAllChildFrames(
4479 WebFrame* parent_frame,
4480 std::vector<WebFrame*>* frames_vector) const {
4481 if (!parent_frame)
4482 return false;
4483 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4484 child_frame = child_frame->nextSibling()) {
4485 frames_vector->push_back(child_frame);
4486 GetAllChildFrames(child_frame, frames_vector);
4487 }
4488 return true;
4489}
4490
[email protected]dd7daa82009-08-10 05:46:454491WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4492 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274493 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454494
4495 // xpath string can represent a frame deep down the tree (across multiple
4496 // frame DOMs).
4497 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4498 // should break into 2 xpaths
4499 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4500
[email protected]26aa0482009-09-30 16:55:274501 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454502
4503 std::wstring xpath_remaining = xpath;
4504 while (!xpath_remaining.empty()) {
4505 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4506 std::wstring xpath_child;
4507 if (delim_pos != std::wstring::npos) {
4508 xpath_child = xpath_remaining.substr(0, delim_pos);
4509 xpath_remaining.erase(0, delim_pos + 1);
4510 } else {
4511 xpath_remaining.swap(xpath_child);
4512 }
4513 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294514 }
4515
[email protected]dd7daa82009-08-10 05:46:454516 return frame;
initial.commit09911bf2008-07-26 23:55:294517}
4518
[email protected]13a1e4c3c2011-02-03 21:07:094519WebNode RenderView::GetFocusedNode() const {
4520 if (!webview())
4521 return WebNode();
4522 WebFrame* focused_frame = webview()->focusedFrame();
4523 if (focused_frame) {
4524 WebDocument doc = focused_frame->document();
4525 if (!doc.isNull())
4526 return doc.focusedNode();
4527 }
4528
4529 return WebNode();
4530}
4531
[email protected]ce833282010-11-04 15:48:394532void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) {
4533 // Explicitly allow empty vector to be sent to the browser.
4534 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions));
[email protected]15d9c0c2010-09-10 22:36:264535}
4536
[email protected]882b7b22010-10-05 03:34:534537void RenderView::EvaluateScript(const string16& frame_xpath,
4538 const string16& script,
4539 int id,
4540 bool notify_result) {
4541 v8::Handle<v8::Value> result;
4542 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
4543 if (web_frame)
4544 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
4545 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:294546 ListValue list;
4547 if (web_frame) {
4548 v8::HandleScope handle_scope;
4549 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4550 v8::Context::Scope context_scope(context);
4551 list.Set(0, ConvertV8Value(result));
4552 } else {
4553 list.Set(0, Value::CreateNullValue());
4554 }
4555 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:534556 }
initial.commit09911bf2008-07-26 23:55:294557}
4558
[email protected]1810e132009-03-24 23:35:484559void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084560 const std::string& css,
4561 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484562 WebFrame* web_frame = GetChildFrame(frame_xpath);
4563 if (!web_frame)
4564 return;
4565
[email protected]ffaef0c2009-09-15 17:08:084566 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484567}
4568
[email protected]00c39612010-03-06 02:53:284569void RenderView::OnPepperPluginDestroy(
4570 WebPluginDelegatePepper* pepper_plugin) {
4571 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014572 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4573 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284574 NOTREACHED();
4575 return;
4576 }
[email protected]53900d52010-06-16 04:25:014577 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474578
4579 // The plugin could have been destroyed while it was waiting for a file
4580 // choose callback, so check all pending completion callbacks and NULL them.
4581 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4582 file_chooser_completions_.begin();
4583 i != file_chooser_completions_.end(); /* nothing */) {
4584 if ((*i)->completion == pepper_plugin) {
4585 // We NULL the first one instead of deleting it because the plugin might
4586 // be the one waiting for a file choose callback. If the callback later
4587 // comes, we don't want to send the result to the next callback in line.
4588 if (i == file_chooser_completions_.begin())
4589 (*i)->completion = NULL;
4590 else
4591 i = file_chooser_completions_.erase(i);
4592 } else {
4593 ++i;
4594 }
4595 }
[email protected]00c39612010-03-06 02:53:284596}
4597
[email protected]882b7b22010-10-05 03:34:534598void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
4599 const string16& jscript,
4600 int id,
4601 bool notify_result) {
4602 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294603}
4604
[email protected]1810e132009-03-24 23:35:484605void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084606 const std::string& css,
4607 const std::string& id) {
4608 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414609
4610 // Notify RenderViewHost that css has been inserted into the frame.
4611 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484612}
4613
[email protected]7ea066a2009-04-06 20:21:594614void RenderView::OnAddMessageToConsole(
4615 const string16& frame_xpath,
4616 const string16& message,
4617 const WebConsoleMessage::Level& level) {
4618 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594619 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454620 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294621}
4622
[email protected]81e63782009-02-27 19:35:094623void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4624 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294625}
4626
4627void RenderView::OnSetDOMUIProperty(const std::string& name,
4628 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094629 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:274630 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294631}
4632
4633void RenderView::OnReservePageIDRange(int size_of_range) {
4634 next_page_id_ += size_of_range + 1;
4635}
4636
[email protected]e80c73b2009-04-07 23:24:584637void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4638 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254639 bool ended,
4640 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034641 if (ended) {
[email protected]26aa0482009-09-30 16:55:274642 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204643 } else {
4644 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034645 }
initial.commit09911bf2008-07-26 23:55:294646}
4647
4648void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274649 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294650}
4651
initial.commit09911bf2008-07-26 23:55:294652void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584653 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254654 const gfx::Point& screen_point,
4655 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274656 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584657 drop_data.ToDragData(),
4658 drop_data.identity,
4659 client_point,
[email protected]1d9f4132009-09-08 17:29:254660 screen_point,
4661 ops);
initial.commit09911bf2008-07-26 23:55:294662
[email protected]1d9f4132009-09-08 17:29:254663 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294664}
4665
[email protected]e80c73b2009-04-07 23:24:584666void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254667 const gfx::Point& screen_point,
4668 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274669 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254670 client_point,
4671 screen_point,
4672 ops);
initial.commit09911bf2008-07-26 23:55:294673
[email protected]1d9f4132009-09-08 17:29:254674 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294675}
4676
4677void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274678 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294679}
4680
[email protected]e80c73b2009-04-07 23:24:584681void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4682 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274683 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294684}
4685
4686void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594687 webkit_preferences_ = prefs;
4688 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294689}
4690
4691void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4692 alternate_error_page_url_ = url;
4693}
4694
[email protected]b29aa74b2011-01-31 21:41:084695void RenderView::OnCustomContextMenuAction(
4696 const webkit_glue::CustomContextMenuContext& custom_context,
4697 unsigned action) {
4698 if (custom_context.is_pepper_menu)
4699 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4700 else
4701 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:334702}
4703
initial.commit09911bf2008-07-26 23:55:294704void RenderView::OnInstallMissingPlugin() {
4705 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594706 if (first_default_plugin_)
4707 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294708}
4709
[email protected]90dba072011-01-20 20:10:204710void RenderView::OnDisplayPrerenderedPage() {
4711 NavigationState* navigation_state = pending_navigation_state_.get();
4712 if (!navigation_state) {
4713 WebDataSource* ds = webview()->mainFrame()->dataSource();
4714 navigation_state = NavigationState::FromDataSource(ds);
4715 }
4716
4717 DCHECK(navigation_state->is_prerendering());
4718 navigation_state->set_is_prerendering(false);
4719}
4720
[email protected]cdaf8d02010-03-30 19:52:474721void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364722 // This could happen if we navigated to a different page before the user
4723 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474724 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364725 return;
4726
[email protected]cdaf8d02010-03-30 19:52:474727 WebVector<WebString> ws_file_names(paths.size());
4728 for (size_t i = 0; i < paths.size(); ++i)
4729 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464730
[email protected]cdaf8d02010-03-30 19:52:474731 if (file_chooser_completions_.front()->completion)
4732 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4733 file_chooser_completions_.pop_front();
4734
4735 // If there are more pending file chooser requests, schedule one now.
4736 if (!file_chooser_completions_.empty()) {
4737 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4738 file_chooser_completions_.front()->params));
4739 }
initial.commit09911bf2008-07-26 23:55:294740}
4741
4742void RenderView::OnEnableViewSourceMode() {
4743 if (!webview())
4744 return;
[email protected]26aa0482009-09-30 16:55:274745 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294746 if (!main_frame)
4747 return;
4748
[email protected]dd7daa82009-08-10 05:46:454749 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294750}
4751
[email protected]770dd8b2010-05-24 18:11:394752void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4753 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244754 if (send_preferred_size_changes_)
4755 return;
[email protected]9fb325e2010-05-06 18:23:244756 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394757
4758 // WebKit doesn't send a notification of the effective height of the page
4759 // changes, so poll for it.
4760 // TODO: Add a notification for this to WebKit, remove polling. After that's
4761 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4762 // http://crbug.com/44850
4763 if (flags & kPreferredSizeHeightThisIsSlow) {
4764 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4765 &RenderView::CheckPreferredSize);
4766 }
[email protected]0666aef2009-05-13 19:48:084767}
4768
[email protected]ce833282010-11-04 15:48:394769void RenderView::OnSearchBoxChange(const string16& value,
[email protected]368ef4c2010-11-08 21:58:464770 bool verbatim,
[email protected]ce833282010-11-04 15:48:394771 int selection_start,
4772 int selection_end) {
4773 search_box_.value = value;
[email protected]368ef4c2010-11-08 21:58:464774 search_box_.verbatim = verbatim;
[email protected]ce833282010-11-04 15:48:394775 search_box_.selection_start = selection_start;
4776 search_box_.selection_end = selection_end;
4777 if (!webview() || !webview()->mainFrame())
4778 return;
4779 extensions_v8::SearchBoxExtension::DispatchChange(webview()->mainFrame());
4780}
4781
4782void RenderView::OnSearchBoxSubmit(const string16& value, bool verbatim) {
4783 search_box_.value = value;
4784 search_box_.verbatim = verbatim;
4785 if (!webview() || !webview()->mainFrame())
4786 return;
4787 extensions_v8::SearchBoxExtension::DispatchSubmit(webview()->mainFrame());
4788}
4789
4790void RenderView::OnSearchBoxCancel() {
4791 search_box_.verbatim = false;
4792 if (!webview() || !webview()->mainFrame())
4793 return;
4794 extensions_v8::SearchBoxExtension::DispatchCancel(webview()->mainFrame());
4795}
4796
4797void RenderView::OnSearchBoxResize(const gfx::Rect& bounds) {
4798 search_box_.x = bounds.x();
4799 search_box_.y = bounds.y();
4800 search_box_.width = bounds.width();
4801 search_box_.height = bounds.height();
4802 if (!webview() || !webview()->mainFrame())
4803 return;
4804 extensions_v8::SearchBoxExtension::DispatchResize(webview()->mainFrame());
4805}
4806
[email protected]57ad7b8c2010-11-18 19:13:494807void RenderView::OnDetermineIfPageSupportsInstant(const string16& value,
[email protected]0d5ab152011-01-14 23:09:044808 bool verbatim,
4809 int selection_start,
4810 int selection_end) {
[email protected]ce833282010-11-04 15:48:394811 search_box_.value = value;
[email protected]57ad7b8c2010-11-18 19:13:494812 search_box_.verbatim = verbatim;
[email protected]0d5ab152011-01-14 23:09:044813 search_box_.selection_start = selection_start;
4814 search_box_.selection_end = selection_end;
[email protected]ce833282010-11-04 15:48:394815 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
4816 webview()->mainFrame());
4817 Send(new ViewHostMsg_InstantSupportDetermined(routing_id_, page_id_, result));
4818}
4819
[email protected]cda45c02010-02-25 19:28:104820void RenderView::OnDisableScrollbarsForSmallWindows(
4821 const gfx::Size& disable_scrollbar_size_limit) {
4822 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4823}
4824
[email protected]80d96fa2009-06-10 22:34:514825void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4826 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374827 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134828#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414829 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4830 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464831 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]8d1b864d12010-10-10 00:04:344832 gfx::NativeThemeLinux::instance()->SetScrollbarColors(
4833 renderer_prefs.thumb_inactive_color,
4834 renderer_prefs.thumb_active_color,
4835 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324836
[email protected]644d77e2010-01-27 01:03:104837 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324838 webview()->setScrollbarColors(
4839 renderer_prefs.thumb_inactive_color,
4840 renderer_prefs.thumb_active_color,
4841 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104842 webview()->setSelectionColors(
4843 renderer_prefs.active_selection_bg_color,
4844 renderer_prefs.active_selection_fg_color,
4845 renderer_prefs.inactive_selection_bg_color,
4846 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464847 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104848 }
[email protected]7a74e102009-09-03 00:16:564849#endif
[email protected]80d96fa2009-06-10 22:34:514850}
4851
[email protected]952cb702009-10-07 05:50:284852void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4853 const WebMediaPlayerAction& action) {
4854 if (webview())
4855 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564856}
4857
[email protected]7b291f92009-08-14 05:43:534858void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4859 view_type_ = type;
4860}
4861
4862void RenderView::OnUpdateBrowserWindowId(int window_id) {
4863 browser_window_id_ = window_id;
4864}
4865
[email protected]dea2d372010-09-25 06:41:144866void RenderView::OnEnableAccessibility() {
4867 if (WebAccessibilityCache::accessibilityEnabled())
4868 return;
[email protected]9f4db512010-05-10 20:21:414869
[email protected]dea2d372010-09-25 06:41:144870 WebAccessibilityCache::enableAccessibility();
4871
4872 if (webview()) {
4873 // It's possible that the webview has already loaded a webpage without
4874 // accessibility being enabled. Initialize the browser's cached
4875 // accessibility tree by sending it a 'load complete' notification.
4876 postAccessibilityNotification(
4877 webview()->accessibilityObject(),
4878 WebKit::WebAccessibilityNotificationLoadComplete);
4879 }
[email protected]266eb6f2008-09-30 23:56:504880}
4881
[email protected]aef92842010-05-21 16:54:364882void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4883 if (!accessibility_.get())
4884 return;
[email protected]02ea2f312010-09-27 17:03:364885
4886 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4887 WebAccessibilityObject root = webview()->accessibilityObject();
4888 if (!obj.isValid() || !root.isValid())
4889 return;
4890
4891 // By convention, calling SetFocus on the root of the tree should clear the
4892 // current focus. Otherwise set the focus to the new node.
4893 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
4894 webview()->clearFocusedNode();
4895 else
4896 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:364897}
4898
4899void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4900 if (!accessibility_.get())
4901 return;
[email protected]02ea2f312010-09-27 17:03:364902
4903 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4904 if (!obj.isValid())
4905 return;
4906
4907 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:364908}
4909
[email protected]9892b472010-09-16 00:23:424910void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:514911 DCHECK(accessibility_ack_pending_);
4912 accessibility_ack_pending_ = false;
4913 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:314914}
4915
initial.commit09911bf2008-07-26 23:55:294916void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4917 const GURL& page_url) {
4918 // Prepare list to storage all savable resource links.
4919 std::vector<GURL> resources_list;
4920 std::vector<GURL> referrers_list;
4921 std::vector<GURL> frames_list;
4922 webkit_glue::SavableResourcesResult result(&resources_list,
4923 &referrers_list,
4924 &frames_list);
4925
[email protected]dbeb3952009-10-13 18:01:184926 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4927 webview(),
4928 page_url,
4929 &result,
4930 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294931 // If something is wrong when collecting all savable resource links,
4932 // send empty list to embedder(browser) to tell it failed.
4933 referrers_list.clear();
4934 resources_list.clear();
4935 frames_list.clear();
4936 }
4937
4938 // Send result of all savable resource links to embedder.
4939 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4940 resources_list,
4941 referrers_list,
4942 frames_list));
4943}
4944
4945void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324946 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314947 const std::vector<FilePath>& local_paths,
4948 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074949
4950 // Convert std::vector of GURLs to WebVector<WebURL>
4951 WebVector<WebURL> weburl_links(links);
4952
4953 // Convert std::vector of std::strings to WebVector<WebString>
4954 WebVector<WebString> webstring_paths(local_paths.size());
4955 for (size_t i = 0; i < local_paths.size(); i++)
4956 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4957
4958 WebPageSerializer::serialize(webview()->mainFrame(),
4959 true, this, weburl_links, webstring_paths,
4960 webkit_glue::FilePathToWebString(
4961 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294962}
4963
[email protected]d9ec5c0f2009-12-23 11:55:074964void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4965 const WebCString& data,
4966 WebPageSerializerClient::PageSerializationStatus status) {
4967 Send(new ViewHostMsg_SendSerializedHtmlData(
4968 routing_id_,
4969 frame_url,
4970 data.data(),
4971 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294972}
4973
[email protected]9b18a84f2010-06-10 15:54:044974void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274975 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474976 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294977}
4978
[email protected]eb6b87a2009-07-24 15:57:394979void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294980 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4981 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4982 // in the onunload handler from appearing. For now, we're bypassing that and
4983 // calling the FrameLoader's CloseURL method directly. This should be
4984 // revisited to avoid having two ways to close a page. Having a single way
4985 // to close that can run onunload is also useful for fixing
4986 // http://b/issue?id=753080.
[email protected]a5a65ac2010-11-05 18:14:364987 // TODO(davemoore) This code should be removed once willClose() gets
4988 // called when a page is destroyed. page_load_histograms_.Dump() is safe
4989 // to call multiple times for the same frame, but it will simplify things.
4990 page_load_histograms_.Dump(webview()->mainFrame());
4991 page_load_histograms_.ResetCrossFramePropertyAccess();
[email protected]26aa0482009-09-30 16:55:274992 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294993
[email protected]eb6b87a2009-07-24 15:57:394994 // Just echo back the params in the ACK.
4995 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294996}
4997
4998void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574999#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:295000 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465001 if (webview())
5002 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575003#else // defined(OS_WIN)
5004 // TODO(port): we don't support theming on non-Windows platforms yet
5005 NOTIMPLEMENTED();
5006#endif
initial.commit09911bf2008-07-26 23:55:295007}
5008
[email protected]9b18a84f2010-06-10 15:54:045009void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
5010 const std::string& origin,
5011 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:155012 if (message.empty())
5013 return;
[email protected]c091c2c2010-09-17 19:05:465014 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
5015 target);
[email protected]3ac14a052008-08-15 21:22:155016}
5017
[email protected]0aa55312008-10-17 21:53:085018void RenderView::OnDisassociateFromPopupCount() {
5019 if (decrement_shared_popup_at_destruction_)
5020 shared_popup_counter_->data--;
5021 shared_popup_counter_ = new SharedRenderViewCounter(0);
5022 decrement_shared_popup_at_destruction_ = false;
5023}
5024
[email protected]15d79e12009-08-02 19:23:455025bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
5026 const WebURLError& error,
5027 bool replace) {
5028 // We only show alternate error pages in the main frame. They are
5029 // intended to assist the user when navigating, so there is not much
5030 // value in showing them for failed subframes. Ideally, we would be
5031 // able to use the TYPED transition type for this, but that flag is
5032 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455033 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455034 return false;
5035
5036 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375037 // connection failure.
[email protected]15d79e12009-08-02 19:23:455038 int ec = error.reason;
5039 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5040 ec != net::ERR_CONNECTION_FAILED &&
5041 ec != net::ERR_CONNECTION_REFUSED &&
5042 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:375043 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:455044 return false;
5045
5046 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555047 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455048 if (!error_page_url.is_valid())
5049 return false;
5050
5051 // Load an empty page first so there is an immediate response to the error,
5052 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455053 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:365054 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455055 error.unreachableURL,
5056 replace);
5057
5058 // Now, create a fetcher for the error page and associate it with the data
5059 // source we just created via the LoadHTMLString call. That way if another
5060 // navigation occurs, the fetcher will get destroyed.
5061 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455062 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:455063 navigation_state->set_alt_error_page_fetcher(
5064 new AltErrorPageResourceFetcher(
5065 error_page_url, frame, error,
5066 NewCallback(this, &RenderView::AltErrorPageFinished)));
5067 return true;
5068}
5069
initial.commit09911bf2008-07-26 23:55:295070std::string RenderView::GetAltHTMLForTemplate(
5071 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:395072 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:295073 ResourceBundle::GetSharedInstance().GetRawDataResource(
5074 template_resource_id));
5075
5076 if (template_html.empty()) {
5077 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
5078 return "";
5079 }
[email protected]7cd22a52009-07-14 00:40:255080
initial.commit09911bf2008-07-26 23:55:295081 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:255082 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:295083 template_html, &error_strings, "t");
5084}
[email protected]0e79b9e2009-02-13 04:20:485085
[email protected]15d79e12009-08-02 19:23:455086void RenderView::AltErrorPageFinished(WebFrame* frame,
5087 const WebURLError& original_error,
5088 const std::string& html) {
5089 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:555090
5091 // If we failed to download the alternate error page, fall back to the
5092 // original error page if present. Otherwise, LoadNavigationErrorPage
5093 // will simply display a default error page.
5094 const std::string* html_to_load = &html;
5095 if (html.empty()) {
5096 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455097 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:555098 html_to_load = &navigation_state->postponed_data();
5099 }
[email protected]3f853a52010-09-13 19:15:085100 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
5101 true);
[email protected]15d79e12009-08-02 19:23:455102}
5103
[email protected]30f75e62009-02-25 22:01:005104void RenderView::OnMoveOrResizeStarted() {
5105 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475106 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005107}
5108
[email protected]30f75e62009-02-25 22:01:005109void RenderView::OnResize(const gfx::Size& new_size,
5110 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:105111 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475112 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105113 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205114 webview()->mainFrame()->setCanHaveScrollbars(
5115 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105116 }
5117 }
5118
[email protected]30f75e62009-02-25 22:01:005119 RenderWidget::OnResize(new_size, resizer_rect);
5120}
[email protected]0aa477bd2009-03-23 22:21:435121
[email protected]00c39612010-03-06 02:53:285122void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:015123 // Notify the pepper plugins that we started painting.
5124 pepper_delegate_.ViewInitiatedPaint();
5125
5126 // Notify any "old-style" pepper plugins that we started painting. This is
5127 // used for internal bookkeeping only, so we know that the set can not change
5128 // under us.
[email protected]00c39612010-03-06 02:53:285129 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:015130 current_oldstyle_pepper_plugins_.begin();
5131 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:285132 (*i)->RenderViewInitiatedPaint();
5133}
5134
5135void RenderView::DidFlushPaint() {
5136 // Notify any pepper plugins that we painted. This will call into the plugin,
5137 // and we it may ask to close itself as a result. This will, in turn, modify
5138 // our set, possibly invalidating the iterator. So we iterate on a copy that
5139 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015140 pepper_delegate_.ViewFlushedPaint();
5141
5142 // Notify any old-style pepper plugins that we painted. This will call into
5143 // the plugin, and we it may ask to close itself as a result. This will, in
5144 // turn, modify our set, possibly invalidating the iterator. So we iterate on
5145 // a copy that won't change out from under us.
5146 // This should be deleted when we don't support old Pepper anymore.
5147 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:285148 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
5149 i != plugins.end(); ++i) {
5150 // The copy above makes sure our iterator is never invalid if some plugins
5151 // are destroyed. But some plugin may decide to close all of its views in
5152 // response to a paint in one of them, so we need to make sure each one is
5153 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:015154 if (current_oldstyle_pepper_plugins_.find(*i) !=
5155 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:285156 (*i)->RenderViewFlushedPaint();
5157 }
5158
5159 WebFrame* main_frame = webview()->mainFrame();
5160
5161 // If we have a provisional frame we are between the start and commit stages
5162 // of loading and we don't want to save stats.
5163 if (!main_frame->provisionalDataSource()) {
5164 WebDataSource* ds = main_frame->dataSource();
5165 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5166 DCHECK(navigation_state);
5167
[email protected]05c8e502010-08-15 15:13:525168 // TODO(jar): The following code should all be inside a method, probably in
5169 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285170 Time now = Time::Now();
5171 if (navigation_state->first_paint_time().is_null()) {
5172 navigation_state->set_first_paint_time(now);
5173 }
5174 if (navigation_state->first_paint_after_load_time().is_null() &&
5175 !navigation_state->finish_load_time().is_null()) {
5176 navigation_state->set_first_paint_after_load_time(now);
5177 }
5178 }
5179}
5180
[email protected]719b36f2010-12-22 20:36:465181webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155182 const gfx::Rect& paint_bounds,
5183 TransportDIB** dib,
5184 gfx::Rect* location,
5185 gfx::Rect* clip) {
5186 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
5187 paint_bounds, dib, location, clip);
5188}
5189
[email protected]d54169e92011-01-21 09:19:525190gfx::Size RenderView::GetScrollOffset() {
5191 WebKit::WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
5192 return gfx::Size(scroll_offset.width, scroll_offset.height);
5193}
5194
[email protected]05d478752009-04-08 23:38:165195void RenderView::OnClearFocusedNode() {
5196 if (webview())
[email protected]26aa0482009-09-30 16:55:275197 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165198}
5199
[email protected]699ab0d2009-04-23 23:19:145200void RenderView::OnSetBackground(const SkBitmap& background) {
5201 if (webview())
[email protected]b4bb2502009-10-01 22:35:275202 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145203
5204 SetBackground(background);
5205}
5206
[email protected]8c66c5a2009-07-22 17:26:345207void RenderView::OnSetActive(bool active) {
5208 if (webview())
[email protected]b4bb2502009-10-01 22:35:275209 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265210
5211#if defined(OS_MACOSX)
5212 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5213 for (plugin_it = plugin_delegates_.begin();
5214 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5215 (*plugin_it)->SetWindowFocus(active);
5216 }
5217#endif
[email protected]8c66c5a2009-07-22 17:26:345218}
5219
[email protected]6ce7abc52010-02-02 18:40:145220#if defined(OS_MACOSX)
5221void RenderView::OnSetWindowVisibility(bool visible) {
5222 // Inform plugins that their container has changed visibility.
5223 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5224 for (plugin_it = plugin_delegates_.begin();
5225 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5226 (*plugin_it)->SetContainerVisibility(visible);
5227 }
5228}
[email protected]1e6e3c992010-02-08 15:52:135229
[email protected]4d51d5bf2010-07-26 18:48:265230void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
5231 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135232 // Inform plugins that their window's frame has changed.
5233 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5234 for (plugin_it = plugin_delegates_.begin();
5235 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5236 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5237 }
5238}
[email protected]935d63d2010-10-15 23:31:555239
[email protected]b7f75862011-01-21 21:15:135240void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:555241 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135242 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555243 // applies to it or not, so inform all the delegates.
5244 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5245 for (plugin_it = plugin_delegates_.begin();
5246 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135247 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555248 }
5249}
[email protected]6ce7abc52010-02-02 18:40:145250#endif // OS_MACOSX
5251
[email protected]8b8e7c92010-08-19 18:05:565252void RenderView::SendExtensionRequest(
5253 const ViewHostMsg_DomMessage_Params& params) {
5254 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:275255}
5256
[email protected]c6619182009-05-12 14:59:325257void RenderView::OnExtensionResponse(int request_id,
5258 bool success,
5259 const std::string& response,
5260 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:355261 ExtensionProcessBindings::HandleResponse(
5262 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:275263}
[email protected]c20210e62009-04-03 21:39:265264
[email protected]a7ab1b782010-10-21 23:24:165265void RenderView::OnExtensionMessageInvoke(const std::string& extension_id,
5266 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:495267 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:195268 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:495269 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:165270 extension_id, function_name, args, this, event_url);
[email protected]7120f132009-07-20 21:05:375271}
5272
[email protected]9892b472010-09-16 00:23:425273void RenderView::postAccessibilityNotification(
5274 const WebAccessibilityObject& obj,
5275 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:145276 if (!accessibility_.get() && webview()) {
5277 // Load complete should be our first notification sent.
5278 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
5279 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
5280 return;
5281
5282 // Create and initialize our accessibility cache
5283 accessibility_.reset(WebAccessibilityCache::create());
5284 accessibility_->initialize(webview());
5285 }
5286
[email protected]a3fa4f92010-09-30 22:19:335287 if (!accessibility_->isCached(obj)) {
5288 // The browser doesn't know about objects that are not in the cache. Send a
5289 // children change for the first accestor that actually is in the cache.
5290 WebAccessibilityObject parent = obj;
5291 while (parent.isValid() && !accessibility_->isCached(parent))
5292 parent = parent.parentObject();
5293
5294 DCHECK(parent.isValid() && accessibility_->isCached(parent));
5295 if (!parent.isValid())
5296 return;
5297 postAccessibilityNotification(
5298 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
5299
5300 // The parent's children change takes care of the child's children change.
5301 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
5302 return;
5303 }
5304
[email protected]dea2d372010-09-25 06:41:145305 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:515306 RendererAccessibilityNotification acc_notification;
5307 acc_notification.id = accessibility_->addOrGetId(obj);
[email protected]a527a022011-02-10 02:32:365308 acc_notification.type = notification;
[email protected]54ec7f82010-10-21 22:32:515309 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:485310 return;
5311
[email protected]a527a022011-02-10 02:32:365312 ViewHostMsg_AccessibilityNotification_Params::NotificationType temp;
5313 if (!WebAccessibilityNotificationToViewHostMsg(notification, &temp))
[email protected]54ec7f82010-10-21 22:32:515314 return;
[email protected]54ec7f82010-10-21 22:32:515315
5316 // Discard duplicate accessibility notifications.
5317 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
5318 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
5319 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:425320 return;
[email protected]54ec7f82010-10-21 22:32:515321 }
[email protected]9892b472010-09-16 00:23:425322 }
[email protected]54ec7f82010-10-21 22:32:515323 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:485324
[email protected]54ec7f82010-10-21 22:32:515325 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
5326 // When no accessibility notifications are in-flight post a task to send
5327 // the notifications to the browser. We use PostTask so that we can queue
5328 // up additional notifications.
5329 MessageLoop::current()->PostTask(
5330 FROM_HERE,
5331 accessibility_method_factory_.NewRunnableMethod(
5332 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:315333 }
[email protected]520cb7d72010-08-31 11:54:315334}
5335
[email protected]446705872009-09-10 07:22:485336void RenderView::OnSetEditCommandsForNextKeyEvent(
5337 const EditCommands& edit_commands) {
5338 edit_commands_ = edit_commands;
5339}
5340
[email protected]61f5a7b2009-12-22 22:21:205341void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275342 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355343 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205344 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5345 false));
[email protected]912256b32009-09-18 09:47:355346 return;
5347 }
5348
[email protected]fa7b6b542009-11-03 05:02:305349 WebDataSource* ds = main_frame->dataSource();
5350 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5351 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205352 pending_code_execution_queue_.push(
5353 linked_ptr<ViewMsg_ExecuteCode_Params>(
5354 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305355 return;
5356 }
5357
[email protected]61f5a7b2009-12-22 22:21:205358 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305359}
5360
5361void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205362 const ViewMsg_ExecuteCode_Params& params) {
[email protected]20ad2692009-11-20 18:27:205363 std::vector<WebFrame*> frame_vector;
5364 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205365 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205366 GetAllChildFrames(frame, &frame_vector);
5367
5368 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5369 frame_it != frame_vector.end(); ++frame_it) {
5370 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205371 if (params.is_javascript) {
[email protected]2a521c52011-01-26 18:45:215372 const Extension* extension =
5373 render_thread_->GetExtensions()->GetByID(params.extension_id);
[email protected]be7e5cb2010-10-04 12:53:175374
[email protected]1f6228c2010-10-21 03:19:445375 // Since extension info is sent separately from user script info, they can
5376 // be out of sync. We just ignore this situation.
5377 if (!extension)
5378 continue;
5379
[email protected]2a521c52011-01-26 18:45:215380 if (!extension->CanExecuteScriptOnPage(frame->url(), NULL, NULL))
[email protected]61f5a7b2009-12-22 22:21:205381 continue;
5382
[email protected]20ad2692009-11-20 18:27:205383 std::vector<WebScriptSource> sources;
5384 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205385 WebScriptSource(WebString::fromUTF8(params.code)));
5386 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205387 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205388 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205389 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5390 } else {
[email protected]61f5a7b2009-12-22 22:21:205391 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205392 }
[email protected]912256b32009-09-18 09:47:355393 }
5394
[email protected]61f5a7b2009-12-22 22:21:205395 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355396}
5397
[email protected]60c42a8c72009-10-09 04:08:595398void RenderView::Close() {
5399 // We need to grab a pointer to the doomed WebView before we destroy it.
5400 WebView* doomed = webview();
5401 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495402 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595403}
5404
[email protected]446705872009-09-10 07:22:485405void RenderView::DidHandleKeyEvent() {
5406 edit_commands_.clear();
5407}
5408
[email protected]6a8ddba52010-09-05 04:38:065409void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515410 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065411}
5412
[email protected]941e4552010-02-01 21:23:435413#if defined(OS_MACOSX)
5414void RenderView::OnWasHidden() {
5415 RenderWidget::OnWasHidden();
5416
5417 // Inform plugins that their container is no longer visible.
5418 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5419 for (plugin_it = plugin_delegates_.begin();
5420 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5421 (*plugin_it)->SetContainerVisibility(false);
5422 }
5423}
5424
5425void RenderView::OnWasRestored(bool needs_repainting) {
5426 RenderWidget::OnWasRestored(needs_repainting);
5427
5428 // Inform plugins that their container is now visible.
5429 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5430 for (plugin_it = plugin_delegates_.begin();
5431 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5432 (*plugin_it)->SetContainerVisibility(true);
5433 }
5434}
[email protected]784ea1ab2010-09-18 00:02:345435#endif // OS_MACOSX
[email protected]1e6e3c992010-02-08 15:52:135436
5437void RenderView::OnSetFocus(bool enable) {
5438 RenderWidget::OnSetFocus(enable);
5439
[email protected]7d3c02c2010-05-05 23:10:315440 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075441 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135442 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5443 for (plugin_it = plugin_delegates_.begin();
5444 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345445#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315446 // RenderWidget's call to setFocus can cause the underlying webview's
5447 // activation state to change just like a call to setIsActive.
5448 if (enable)
5449 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345450#endif
[email protected]7d3c02c2010-05-05 23:10:315451 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135452 }
[email protected]589621b2010-09-23 22:01:075453
5454 // Notify all Pepper plugins.
5455 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135456 }
5457}
[email protected]941e4552010-02-01 21:23:435458
[email protected]83dde542009-09-11 20:59:555459void RenderView::EnsureDocumentTag() {
5460 // TODO(darin): There's actually no reason for this to be here. We should
5461 // have the browser side manage the document tag.
5462#if defined(OS_MACOSX)
5463 if (!has_document_tag_) {
5464 // Make the call to get the tag.
5465 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5466 has_document_tag_ = true;
5467 }
5468#endif
5469}
[email protected]12636df2009-09-28 22:32:215470
[email protected]43f28f832010-02-03 02:28:485471#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:135472void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
5473 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
5474 focused, plugin_id);
5475 Send(msg);
5476}
5477
5478void RenderView::StartPluginIme() {
5479 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555480 // This message can be sent during event-handling, and needs to be delivered
5481 // within that context.
5482 msg->set_unblock(true);
5483 Send(msg);
5484}
5485
[email protected]ea04a4e12010-04-15 00:58:035486gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235487 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485488 gfx::PluginWindowHandle window = NULL;
5489 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235490 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115491 if (window) {
5492 fake_plugin_window_handles_.insert(window);
5493 }
[email protected]43f28f832010-02-03 02:28:485494 return window;
5495}
5496
5497void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115498 if (window && fake_plugin_window_handles_.find(window) !=
5499 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485500 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115501 fake_plugin_window_handles_.erase(window);
5502 }
[email protected]43f28f832010-02-03 02:28:485503}
5504
[email protected]44ce0b12010-03-12 16:45:335505void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5506 int32 width,
5507 int32 height,
5508 uint64 io_surface_identifier) {
5509 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485510 routing_id(), window, width, height, io_surface_identifier));
5511}
5512
[email protected]44ce0b12010-03-12 16:45:335513void RenderView::AcceleratedSurfaceSetTransportDIB(
5514 gfx::PluginWindowHandle window,
5515 int32 width,
5516 int32 height,
5517 TransportDIB::Handle transport_dib) {
5518 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075519 routing_id(), window, width, height, transport_dib));
5520}
5521
[email protected]44ce0b12010-03-12 16:45:335522TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5523 size_t size) {
[email protected]1aef98132010-02-23 18:00:075524 TransportDIB::Handle dib_handle;
5525 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385526 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075527 return dib_handle;
5528 // Return an invalid handle if Send() fails.
5529 return TransportDIB::DefaultHandleValue();
5530}
5531
[email protected]44ce0b12010-03-12 16:45:335532void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075533 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5534}
5535
[email protected]44ce0b12010-03-12 16:45:335536void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:145537 gfx::PluginWindowHandle window, uint64 surface_id) {
5538 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
5539 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:485540}
5541#endif
[email protected]58c321d2010-02-19 12:11:285542
[email protected]cdaf8d02010-03-30 19:52:475543bool RenderView::ScheduleFileChooser(
5544 const ViewHostMsg_RunFileChooser_Params& params,
5545 WebFileChooserCompletion* completion) {
5546 static const size_t kMaximumPendingFileChooseRequests = 4;
5547 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5548 // This sanity check prevents too many file choose requests from getting
5549 // queued which could DoS the user. Getting these is most likely a
5550 // programming error (there are many ways to DoS the user so it's not
5551 // considered a "real" security check), either in JS requesting many file
5552 // choosers to pop up, or in a plugin.
5553 //
5554 // TODO(brettw) we might possibly want to require a user gesture to open
5555 // a file picker, which will address this issue in a better way.
5556 return false;
5557 }
5558
5559 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5560 new PendingFileChooser(params, completion)));
5561 if (file_chooser_completions_.size() == 1) {
5562 // Actually show the browse dialog when this is the first request.
5563 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5564 }
5565 return true;
5566}
5567
[email protected]290838a2010-04-27 17:37:015568void RenderView::OnPageTranslated() {
5569 WebFrame* frame = webview()->mainFrame();
5570 if (!frame)
5571 return;
5572
[email protected]676126f72011-01-15 00:03:515573 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameTranslated(frame));
[email protected]290838a2010-04-27 17:37:015574}
5575
[email protected]0ff0ff32010-12-21 19:34:425576WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515577 if (!geolocation_dispatcher_)
5578 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5579 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255580}
[email protected]61c9f032010-03-31 23:04:195581
[email protected]638694c2010-08-04 22:24:115582WebKit::WebSpeechInputController* RenderView::speechInputController(
5583 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:515584 if (!speech_input_dispatcher_)
5585 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
5586 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:115587}
5588
[email protected]57ead352010-08-11 14:42:535589WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515590 if (!device_orientation_dispatcher_)
5591 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5592 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535593}
5594
[email protected]b75b8292010-10-01 07:28:255595void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
5596 // For now, don't remember plugin zoom values. We don't want to mix them with
5597 // normal web content (i.e. a fixed layout plugin would usually want them
5598 // different).
5599 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5600
[email protected]b75b8292010-10-01 07:28:255601 int minimum_percent = static_cast<int>(
5602 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5603 int maximum_percent = static_cast<int>(
5604 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255605
5606 Send(new ViewHostMsg_UpdateZoomLimits(
5607 routing_id_, minimum_percent, maximum_percent, remember));
5608}
5609
5610void RenderView::zoomLevelChanged() {
5611 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5612
[email protected]b75b8292010-10-01 07:28:255613 // Tell the browser which url got zoomed so it can update the menu and the
5614 // saved values if necessary
5615 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:415616 routing_id_, webview()->zoomLevel(), remember,
5617 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:255618}
5619
[email protected]8079b362010-05-07 18:37:455620bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195621 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455622 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195623 if (frame->parent() != NULL)
5624 return false;
5625
[email protected]f0a3d0b2010-08-06 22:51:535626 // Navigations initiated within Webkit are not sent out to the external host
5627 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275628 // 1. The url scheme is not http/https
5629 // 2. There is no opener and this is not the first url being opened by this
5630 // RenderView.
5631 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535632 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535633 // 4. Reloads/form submits/back forward navigations
5634 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5635 return false;
5636
[email protected]2fc22d12010-12-02 23:08:165637 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325638 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015639 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165640 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015641 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325642 // The opener relationship between the new window and the parent allows the
5643 // new window to script the parent and vice versa. This is not allowed if
5644 // the origins of the two domains are different. This can be treated as a
5645 // top level navigation and routed back to the host.
5646 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275647 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475648 // Force link click navigations to always be routed to the host as they
5649 // may update session state on the server.
5650 if (type == WebKit::WebNavigationTypeLinkClicked)
5651 return true;
[email protected]900eb2f12010-08-23 22:36:275652 // If this is the first page being loaded by this RenderView instance then
5653 // it should stay here.
5654 if (page_id_ == -1) {
5655 return false;
5656 } else {
[email protected]d0ed50d2010-06-22 01:01:325657 return true;
[email protected]900eb2f12010-08-23 22:36:275658 }
[email protected]d0ed50d2010-06-22 01:01:325659 }
[email protected]900eb2f12010-08-23 22:36:275660
5661 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5662 return true;
[email protected]d0ed50d2010-06-22 01:01:325663 }
[email protected]61c9f032010-03-31 23:04:195664 return false;
5665}
[email protected]2b06a992010-08-21 05:48:225666
[email protected]27a9ef32010-09-10 04:06:245667void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5668 IPC::PlatformFileForTransit file_for_transit,
5669 int message_id) {
5670 pepper_delegate_.OnAsyncFileOpened(
5671 error_code,
5672 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5673 message_id);
5674}
[email protected]caf706f2010-10-26 17:54:085675
5676#if defined(OS_MACOSX)
5677void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155678 if (external_popup_menu_ == NULL) {
5679 // Crash reports from the field indicate that we can be notified with a
5680 // NULL external popup menu (we probably get notified twice).
5681 // If you hit this please file a bug against jcivelli and include the page
5682 // and steps to repro.
5683 NOTREACHED();
5684 return;
5685 }
[email protected]caf706f2010-10-26 17:54:085686 external_popup_menu_->DidSelectItem(selected_index);
5687 external_popup_menu_.reset();
5688}
5689#endif
[email protected]bb461532010-11-26 21:50:235690
5691void RenderView::AddErrorToRootConsole(const string16& message) {
5692 if (webview() && webview()->mainFrame()) {
5693 webview()->mainFrame()->addMessageToConsole(
5694 WebConsoleMessage(WebConsoleMessage::LevelError, message));
5695 }
5696}
[email protected]1b4209f2011-01-07 00:25:405697
5698#if defined(ENABLE_FLAPPER_HACKS)
5699void RenderView::OnConnectTcpACK(
5700 int request_id,
5701 IPC::PlatformFileForTransit socket_for_transit,
5702 const PP_Flash_NetAddress& local_addr,
5703 const PP_Flash_NetAddress& remote_addr) {
5704 pepper_delegate_.OnConnectTcpACK(
5705 request_id,
5706 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5707 local_addr,
5708 remote_addr);
5709}
5710#endif
[email protected]a6097f42011-01-10 08:50:515711
5712void RenderView::OnJavaScriptStressTestControl(int cmd, int param) {
5713 if (cmd == kJavaScriptStressTestSetStressRunType) {
5714 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5715 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5716 v8::Testing::PrepareStressRun(param);
5717 }
5718}
[email protected]521b2482011-01-15 00:10:105719
[email protected]b29aa74b2011-01-31 21:41:085720void RenderView::OnContextMenuClosed(
5721 const webkit_glue::CustomContextMenuContext& custom_context) {
5722 if (custom_context.is_pepper_menu)
5723 pepper_delegate_.OnContextMenuClosed(custom_context);
5724 else
5725 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105726}