blob: a04ad303fb5cec62907fc4f674c2e83c84f1f47d [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]c4a9e932011-03-05 04:05:5525#include "chrome/common/autofill_messages.h"
[email protected]81e63782009-02-27 19:35:0926#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5527#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1728#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2829#include "chrome/common/chrome_paths.h"
30#include "chrome/common/chrome_switches.h"
[email protected]a0cf04a2010-06-23 03:29:5531#include "chrome/common/extensions/extension.h"
[email protected]46fd1ea42011-02-16 15:59:3332#include "chrome/common/extensions/extension_constants.h"
[email protected]ec7db282011-01-29 01:11:3633#include "chrome/common/extensions/extension_set.h"
[email protected]bb461532010-11-26 21:50:2334#include "chrome/common/json_value_serializer.h"
initial.commit09911bf2008-07-26 23:55:2935#include "chrome/common/jstemplate_builder.h"
[email protected]4e0616e2010-05-28 14:55:5336#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2937#include "chrome/common/render_messages.h"
[email protected]a527a022011-02-10 02:32:3638#include "chrome/common/render_messages_params.h"
[email protected]13a1e4c3c2011-02-03 21:07:0939#include "chrome/common/render_view_commands.h"
[email protected]9b6f40e2009-06-11 15:54:2640#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2941#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5942#include "chrome/common/url_constants.h"
[email protected]38789d82010-11-17 06:03:4443#include "chrome/common/web_apps.h"
[email protected]534c66c2010-04-28 22:53:1144#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/renderer/about_handler.h"
[email protected]78192082011-01-29 05:43:4446#include "chrome/renderer/autofill/autofill_agent.h"
47#include "chrome/renderer/autofill/form_manager.h"
48#include "chrome/renderer/autofill/password_autofill_manager.h"
[email protected]2f979172010-09-16 21:54:0349#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]00152e92010-07-19 11:47:4050#include "chrome/renderer/blocked_plugin.h"
[email protected]e4ac5df2009-03-17 15:33:1151#include "chrome/renderer/devtools_agent.h"
52#include "chrome/renderer/devtools_client.h"
[email protected]912256b32009-09-18 09:47:3553#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0454#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]f816c012009-06-26 21:48:3255#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3556#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]78d5cfe2011-02-04 08:43:2257#include "chrome/renderer/extensions/extension_resource_request_policy.h"
[email protected]7120f132009-07-20 21:05:3758#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0359#include "chrome/renderer/external_host_bindings.h"
[email protected]caf706f2010-10-26 17:54:0860#include "chrome/renderer/external_popup_menu.h"
initial.commit09911bf2008-07-26 23:55:2961#include "chrome/renderer/localized_error.h"
[email protected]6a8ddba52010-09-05 04:38:0662#include "chrome/renderer/page_click_tracker.h"
[email protected]a5a65ac2010-11-05 18:14:3663#include "chrome/renderer/page_load_histograms.h"
[email protected]d81c1e52009-06-03 22:09:5064#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2565#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2866#include "chrome/renderer/render_thread.h"
[email protected]676126f72011-01-15 00:03:5167#include "chrome/renderer/render_view_observer.h"
[email protected]4d51d5bf2010-07-26 18:48:2668#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1869#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]79c7bed2010-09-14 22:28:3970#include "chrome/renderer/render_widget_fullscreen_pepper.h"
[email protected]32ca14682011-02-16 19:05:1071#include "chrome/renderer/safe_browsing/malware_dom_details.h"
[email protected]3ead1322010-11-19 20:01:0072#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
[email protected]6c2f73202011-02-14 20:21:5473#include "chrome/renderer/searchbox.h"
[email protected]85c55dc2009-11-06 03:05:4674#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]c4a9e932011-03-05 04:05:5575#include "chrome/renderer/spellchecker/spellcheck_provider.h"
[email protected]81273622011-02-02 03:56:1376#include "chrome/renderer/translate_helper.h"
[email protected]25e18f82010-10-27 16:38:4377#include "chrome/renderer/user_script_idle_scheduler.h"
[email protected]0938d3c2009-01-09 20:37:3578#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2979#include "chrome/renderer/visitedlink_slave.h"
[email protected]e93e04e2011-03-14 00:27:1080#include "content/common/appcache/appcache_dispatcher.h"
[email protected]127dd582011-03-16 21:32:1081#include "content/common/clipboard_messages.h"
[email protected]db803aae2011-03-05 02:00:4282#include "content/common/content_constants.h"
[email protected]37666cf2011-03-13 21:51:4283#include "content/common/database_messages.h"
[email protected]7ef40ffe12011-03-08 05:05:2884#include "content/common/file_system/file_system_dispatcher.h"
85#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]7f070d42011-03-09 20:25:3286#include "content/common/notification_service.h"
[email protected]4dd57932011-03-17 06:06:1287#include "content/common/page_zoom.h"
[email protected]127dd582011-03-16 21:32:1088#include "content/common/pepper_messages.h"
[email protected]230b7ef2011-03-16 22:30:1989#include "content/renderer/audio_message_filter.h"
90#include "content/renderer/device_orientation_dispatcher.h"
91#include "content/renderer/geolocation_dispatcher.h"
[email protected]ccc70d8e2011-03-16 20:40:3792#include "content/renderer/ggl.h"
[email protected]921f1592011-03-18 00:41:0293#include "content/renderer/load_progress_tracker.h"
[email protected]ccc70d8e2011-03-16 20:40:3794#include "content/renderer/media/audio_renderer_impl.h"
95#include "content/renderer/media/ipc_video_decoder.h"
[email protected]921f1592011-03-18 00:41:0296#include "content/renderer/navigation_state.h"
[email protected]230b7ef2011-03-16 22:30:1997#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3798#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3599#include "content/renderer/plugin_channel_host.h"
[email protected]acb94722011-03-18 01:33:34100#include "content/renderer/renderer_webapplicationcachehost_impl.h"
101#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:19102#include "content/renderer/speech_input_dispatcher.h"
[email protected]6f516082011-03-17 19:15:35103#include "content/renderer/webgraphicscontext3d_command_buffer_impl.h"
104#include "content/renderer/webplugin_delegate_proxy.h"
105#include "content/renderer/websharedworker_proxy.h"
106#include "content/renderer/webworker_proxy.h"
[email protected]921f1592011-03-18 00:41:02107#include "content/renderer/web_ui_bindings.h"
[email protected]34ac8f32009-02-22 23:03:27108#include "grit/generated_resources.h"
109#include "grit/renderer_resources.h"
[email protected]f8db8132010-12-03 00:27:49110#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41111#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:27112#include "media/base/message_loop_factory_impl.h"
[email protected]f11ca0732009-04-11 00:09:34113#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29114#include "net/base/escape.h"
115#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04116#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:57117#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]c399a8a2008-11-22 19:38:00118#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:10119#include "skia/ext/image_operations.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]69f110d62011-03-17 19:01:14139#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]232a5812011-03-04 22:42:08140#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
[email protected]8bd0fe62011-01-17 06:44:37141#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
152#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
154#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
155#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
157#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
[email protected]5efcef62011-02-22 09:00:13158#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingCompletion.h"
159#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextCheckingResult.h"
[email protected]8bd0fe62011-01-17 06:44:37160#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
161#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
162#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
163#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
164#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
165#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
166#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26167#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
168#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c051a1b2011-01-21 23:30:17169#include "ui/base/l10n/l10n_util.h"
[email protected]c4a9e932011-03-05 04:05:55170#include "ui/base/message_box_flags.h"
[email protected]42ce29d2011-01-20 23:19:46171#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:38172#include "ui/gfx/color_utils.h"
173#include "ui/gfx/favicon_size.h"
174#include "ui/gfx/native_widget_types.h"
175#include "ui/gfx/point.h"
176#include "ui/gfx/rect.h"
177#include "ui/gfx/skbitmap_operations.h"
[email protected]a6097f42011-01-10 08:50:51178#include "v8/include/v8-testing.h"
[email protected]c4a9e932011-03-05 04:05:55179#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04180#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43181#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24182#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29183#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59184#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24185#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24186#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34187#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26188#include "webkit/glue/image_resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09189#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26190#include "webkit/glue/password_form_dom_manager.h"
[email protected]bb461532010-11-26 21:50:23191#include "webkit/glue/resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09192#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24193#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29194#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07195#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29196#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17197#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50198#include "webkit/plugins/npapi/default_plugin_shared.h"
199#include "webkit/plugins/npapi/plugin_list.h"
200#include "webkit/plugins/npapi/webplugin_delegate.h"
201#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
202#include "webkit/plugins/npapi/webplugin_impl.h"
203#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52204#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29205
[email protected]6c8afae52009-01-22 02:24:57206#if defined(OS_WIN)
207// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57208// * theming
[email protected]08397d52011-02-05 01:53:38209#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03210#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37211#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]08397d52011-02-05 01:53:38212#include "ui/gfx/native_theme_linux.h"
[email protected]78043bdd2010-04-05 18:45:33213#elif defined(OS_MACOSX)
214#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57215#endif
216
[email protected]c7287a92009-11-04 20:06:15217using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42218using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08219using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21220using WebKit::WebApplicationCacheHost;
221using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26222using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41223using WebKit::WebColor;
224using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59225using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44226using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51227using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55228using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28229using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29230using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00231using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58232using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25233using WebKit::WebDragOperation;
234using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51235using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51236using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08237using WebKit::WebExternalPopupMenu;
238using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47239using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22240using WebKit::WebFileSystem;
241using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49242using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59243using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48244using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45245using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17246using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41247using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50248using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17249using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28250using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17251using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28252using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28253using WebKit::WebNavigationType;
[email protected]232a5812011-03-04 22:42:08254using WebKit::WebNetworkStateNotifier;
[email protected]79dbc662009-09-04 05:42:51255using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07256using WebKit::WebPageSerializer;
257using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17258using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40259using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49260using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09261using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52262using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59263using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51264using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52265using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40266using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35267using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29268using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59269using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42270using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02271using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34272using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28273using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51274using WebKit::WebTextAffinity;
[email protected]5efcef62011-02-22 09:00:13275using WebKit::WebTextCheckingResult;
[email protected]de570ef2009-07-29 18:27:52276using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28277using WebKit::WebURL;
278using WebKit::WebURLError;
279using WebKit::WebURLRequest;
280using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28281using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03282using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28283using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26284using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43285using WebKit::WebWorker;
286using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26287using appcache::WebApplicationCacheHostImpl;
[email protected]78192082011-01-29 05:43:44288using autofill::AutoFillAgent;
289using autofill::FormManager;
[email protected]c4a9e932011-03-05 04:05:55290using autofill::PasswordAutofillManager;
[email protected]6fdd4182010-10-14 23:59:26291using base::Time;
292using base::TimeDelta;
293using webkit_glue::AltErrorPageResourceFetcher;
294using webkit_glue::FormData;
295using webkit_glue::FormField;
296using webkit_glue::ImageResourceFetcher;
297using webkit_glue::PasswordForm;
298using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23299using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26300using webkit_glue::SiteIsolationMetrics;
301using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33302
initial.commit09911bf2008-07-26 23:55:29303//-----------------------------------------------------------------------------
304
[email protected]3354d3e2010-06-10 19:53:02305typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49306static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02307
initial.commit09911bf2008-07-26 23:55:29308// define to write the time necessary for thumbnail/DOM text retrieval,
309// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29310// #define TIME_TEXT_RETRIEVAL
311
312// maximum number of characters in the document to index, any text beyond this
313// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57314static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29315
316// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37317static const int kThumbnailWidth = 212;
318static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29319
320// Delay in milliseconds that we'll wait before capturing the page contents
321// and thumbnail.
322static const int kDelayForCaptureMs = 500;
323
324// Typically, we capture the page data once the page is loaded.
325// Sometimes, the page never finishes to load, preventing the page capture
326// To workaround this problem, we always perform a capture after the following
327// delay.
328static const int kDelayForForcedCaptureMs = 6000;
329
[email protected]882daa92009-11-05 16:31:31330// Time, in seconds, we delay before sending content state changes (such as form
331// state and scroll position) to the browser. We delay sending changes to avoid
332// spamming the browser.
333// To avoid having tab/session restore require sending a message to get the
334// current content state during tab closing we use a shorter timeout for the
335// foreground renderer. This means there is a small window of time from which
336// content state is modified and not sent to session restore, but this is
337// better than having to wake up all renderers during shutdown.
338static const int kDelaySecondsForContentStateSyncHidden = 5;
339static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29340
[email protected]0aa55312008-10-17 21:53:08341// The maximum number of popups that can be spawned from one page.
342static const int kMaximumNumberOfUnacknowledgedPopups = 25;
343
[email protected]6fdd4182010-10-14 23:59:26344static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35345
[email protected]726985e22009-06-18 21:09:28346static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
347 WebVector<WebURL> urls;
348 ds->redirectChain(urls);
349 result->reserve(urls.size());
350 for (size_t i = 0; i < urls.size(); ++i)
351 result->push_back(urls[i]);
352}
353
[email protected]30507922010-01-15 16:48:23354static bool PaintViewIntoCanvas(WebView* view,
355 skia::PlatformCanvas& canvas) {
356 view->layout();
357 const WebSize& size = view->size();
358
359 if (!canvas.initialize(size.width, size.height, true))
360 return false;
361
362 view->paint(webkit_glue::ToWebCanvas(&canvas),
363 WebRect(0, 0, size.width, size.height));
364 // TODO: Add a way to snapshot the whole page, not just the currently
365 // visible part.
366
367 return true;
368}
369
370// Calculates how "boring" a thumbnail is. The boring score is the
371// 0,1 ranged percentage of pixels that are the most common
372// luma. Higher boring scores indicate that a higher percentage of a
373// bitmap are all the same brightness.
374static double CalculateBoringScore(SkBitmap* bitmap) {
375 int histogram[256] = {0};
376 color_utils::BuildLumaHistogram(bitmap, histogram);
377
378 int color_count = *std::max_element(histogram, histogram + 256);
379 int pixel_count = bitmap->width() * bitmap->height();
380 return static_cast<double>(color_count) / pixel_count;
381}
382
[email protected]12bc8472010-04-15 07:29:40383// True if |frame| contains content that is white-listed for content settings.
384static bool IsWhitelistedForContentSettings(WebFrame* frame) {
385 WebSecurityOrigin origin = frame->securityOrigin();
386 if (origin.isEmpty())
387 return false; // Uninitialized document?
388
389 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
390 return true; // Browser UI elements should still work.
391
392 // If the scheme is ftp: or file:, an empty file name indicates a directory
393 // listing, which requires JavaScript to function properly.
394 GURL frame_url = frame->url();
395 const char* kDirProtocols[] = { "ftp", "file" };
396 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
397 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
398 return frame_url.SchemeIs(kDirProtocols[i]) &&
399 frame_url.ExtractFileName().empty();
400 }
401 }
402
403 return false;
404}
405
[email protected]3a8eecb2010-04-22 23:56:30406// Returns true if the frame is navigating to an URL either into or out of an
407// extension app's extent.
[email protected]08e94b82010-12-15 22:51:04408// TODO(creis): Temporary workaround for crbug.com/65953: Only return true if
[email protected]88c15e972011-02-05 04:19:53409// we would enter an extension app's extent from a non-app, or if we leave an
410// extension with no web extent. We avoid swapping processes to exit a hosted
411// app with a web extent for now, since we do not yet restore context (such
[email protected]08e94b82010-12-15 22:51:04412// as window.opener) if the window navigates back.
[email protected]88c15e972011-02-05 04:19:53413static bool CrossesExtensionExtents(const ExtensionSet* extensions,
414 WebFrame* frame,
415 const GURL& new_url) {
[email protected]3a8eecb2010-04-22 23:56:30416 // If the URL is still empty, this is a window.open navigation. Check the
417 // opener's URL.
418 GURL old_url(frame->url());
419 if (old_url.is_empty() && frame->opener())
420 old_url = frame->opener()->url();
421
[email protected]88c15e972011-02-05 04:19:53422 bool old_url_is_hosted_app = extensions->GetByURL(old_url) &&
423 !extensions->GetByURL(old_url)->web_extent().is_empty();
[email protected]2a521c52011-01-26 18:45:21424 return !extensions->InSameExtent(old_url, new_url) &&
[email protected]88c15e972011-02-05 04:19:53425 !old_url_is_hosted_app;
[email protected]3a8eecb2010-04-22 23:56:30426}
427
[email protected]3354d3e2010-06-10 19:53:02428// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
429// if it failed.
[email protected]e5106202010-06-11 21:12:36430static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17431 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02432 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08433 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02434 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02435 Language cld_language =
[email protected]e5106202010-06-11 21:12:36436 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08437 &num_languages, NULL, &text_bytes);
438 // We don't trust the result if the CLD reports that the detection is not
439 // reliable, or if the actual text used to detect the language was less than
440 // 100 bytes (short texts can often lead to wrong results).
441 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02442 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
443 // We should not use LanguageCode_ISO_639_1 because it does not cover all
444 // the languages CLD can detect. As a result, it'll return the invalid
445 // language code for tradtional Chinese among others.
446 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
447 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
448 // for Simplified Chinese.
449 language = LanguageCodeWithDialects(cld_language);
450 }
451 return language;
452}
453
[email protected]9b66f34bf2010-10-27 20:45:51454// Returns true if the parameter node is a textfield, text area or a content
455// editable div.
456static bool IsEditableNode(const WebNode& node) {
457 bool is_editable_node = false;
458 if (!node.isNull()) {
459 if (node.isContentEditable()) {
460 is_editable_node = true;
461 } else if (node.isElementNode()) {
462 is_editable_node =
463 node.toConst<WebElement>().isTextFormControlElement();
464 }
465 }
466 return is_editable_node;
467}
468
[email protected]54ec7f82010-10-21 22:32:51469static bool WebAccessibilityNotificationToViewHostMsg(
470 WebAccessibilityNotification notification,
471 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) {
472 switch (notification) {
473 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
474 *type = ViewHostMsg_AccessibilityNotification_Params::
475 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
476 break;
477 case WebKit::WebAccessibilityNotificationChildrenChanged:
478 *type = ViewHostMsg_AccessibilityNotification_Params::
479 NOTIFICATION_TYPE_CHILDREN_CHANGED;
480 break;
481 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
482 *type = ViewHostMsg_AccessibilityNotification_Params::
483 NOTIFICATION_TYPE_FOCUS_CHANGED;
484 break;
485 case WebKit::WebAccessibilityNotificationLoadComplete:
486 *type = ViewHostMsg_AccessibilityNotification_Params::
487 NOTIFICATION_TYPE_LOAD_COMPLETE;
488 break;
489 case WebKit::WebAccessibilityNotificationValueChanged:
490 *type = ViewHostMsg_AccessibilityNotification_Params::
491 NOTIFICATION_TYPE_VALUE_CHANGED;
492 break;
493 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
494 *type = ViewHostMsg_AccessibilityNotification_Params::
495 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
496 break;
497 default:
498 // TODO(ctguil): Support additional webkit notifications.
499 return false;
500 }
501 return true;
502}
503
[email protected]81f9fe0b2010-12-07 00:35:29504// Conversion for the incoming value. The map isn't perfect; v8 has Uint32,
505// and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into
[email protected]fb534c92011-02-01 01:02:07506// being TYPE_DOUBLEs. Dates are converted to a string (which can then be
507// parsed into a base::Time), as are regexps. Arrays are converted into lists,
[email protected]81f9fe0b2010-12-07 00:35:29508// recursively. We don't deal with binary objects or functions - they become
509// null values.
510static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) {
511 if (v8value->IsBoolean()) {
512 return Value::CreateBooleanValue(v8value->BooleanValue());
513 } else if (v8value->IsInt32()) {
514 return Value::CreateIntegerValue(v8value->Int32Value());
515 } else if (v8value->IsNumber()) {
[email protected]fb534c92011-02-01 01:02:07516 return Value::CreateDoubleValue(v8value->NumberValue());
[email protected]81f9fe0b2010-12-07 00:35:29517 } else if (v8value->IsString()) {
518 return Value::CreateStringValue(*v8::String::Utf8Value(v8value));
519 } else if (v8value->IsDate()) {
520 v8::Date* date = v8::Date::Cast(*v8value);
[email protected]fb534c92011-02-01 01:02:07521 return Value::CreateDoubleValue(date->NumberValue() / 1000.0);
[email protected]81f9fe0b2010-12-07 00:35:29522 } else if (v8value->IsRegExp()) {
523 return Value::CreateStringValue(
524 *v8::String::Utf8Value(v8value->ToString()));
525 } else if (v8value->IsArray()) {
526 v8::Array* array = v8::Array::Cast(*v8value);
527 uint32_t length = array->Length();
528 scoped_ptr<ListValue> list(new ListValue);
529 for (uint32_t i = 0 ; i < length ; ++i) {
530 list->Set(i, ConvertV8Value(array->Get(i)));
531 }
532 return list.release();
533 }
534 return Value::CreateNullValue();
535}
536
initial.commit09911bf2008-07-26 23:55:29537///////////////////////////////////////////////////////////////////////////////
538
[email protected]60c42a8c72009-10-09 04:08:59539int32 RenderView::next_page_id_ = 1;
540
[email protected]cdaf8d02010-03-30 19:52:47541struct RenderView::PendingFileChooser {
542 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
543 WebFileChooserCompletion* c)
544 : params(p),
545 completion(c) {
546 }
547 ViewHostMsg_RunFileChooser_Params params;
548 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
549};
550
[email protected]2fab253a2009-08-17 23:00:59551RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51552 gfx::NativeViewId parent_hwnd,
553 int32 opener_id,
554 const RendererPreferences& renderer_prefs,
555 const WebPreferences& webkit_prefs,
556 SharedRenderViewCounter* counter,
557 int32 routing_id,
558 int64 session_storage_namespace_id,
559 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12560 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51561 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02562 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09563 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02564 send_preferred_size_changes_(false),
565 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24566 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21567 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02568 opened_by_user_gesture_(true),
569 opener_suppressed_(false),
[email protected]987d51af2011-02-24 17:50:18570 is_prerendering_(false),
[email protected]81a34412009-01-05 19:17:24571 page_id_(-1),
572 last_page_id_sent_to_browser_(-1),
573 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00574 history_list_offset_(-1),
575 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24576 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55577#if defined(OS_MACOSX)
578 has_document_tag_(false),
579#endif
[email protected]98324892009-09-09 21:16:05580 document_tag_(0),
[email protected]3354d3e2010-06-10 19:53:02581 target_url_status_(TARGET_NONE),
582 spelling_panel_visible_(false),
583 view_type_(ViewType::INVALID),
584 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18585 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30586 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
[email protected]54ec7f82010-10-21 22:32:51587 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02588 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51589 devtools_client_(NULL),
590 geolocation_dispatcher_(NULL),
591 speech_input_dispatcher_(NULL),
592 device_orientation_dispatcher_(NULL),
[email protected]dec1f292011-02-11 20:20:20593 print_helper_(NULL),
[email protected]6c2f73202011-02-14 20:21:54594 searchbox_(NULL),
[email protected]5efcef62011-02-22 09:00:13595 spellcheck_provider_(NULL),
[email protected]54ec7f82010-10-21 22:32:51596 accessibility_ack_pending_(false),
[email protected]cae8c8492011-03-03 11:12:18597 p2p_socket_dispatcher_(NULL),
[email protected]bb461532010-11-26 21:50:23598 pending_app_icon_requests_(0),
[email protected]5ee0cfd02011-01-18 05:42:22599 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]8de12d942010-11-17 20:42:44600#if defined(OS_MACOSX)
601 // On Mac, the select popups are rendered by the browser.
602 // Note that we don't do this in RenderMain otherwise this would not be called
603 // in single-process mode.
604 WebKit::WebView::setUseExternalPopupMenus(true);
605#endif
[email protected]676126f72011-01-15 00:03:51606
[email protected]71b0d5d2010-02-15 05:43:07607 ClearBlockedContentSettings();
[email protected]676126f72011-01-15 00:03:51608
609 routing_id_ = routing_id;
610 if (opener_id != MSG_ROUTING_NONE)
611 opener_id_ = opener_id;
612
613 if (counter) {
614 shared_popup_counter_ = counter;
615 shared_popup_counter_->data++;
616 decrement_shared_popup_at_destruction_ = true;
617 } else {
618 shared_popup_counter_ = new SharedRenderViewCounter(0);
619 decrement_shared_popup_at_destruction_ = false;
620 }
621
622 notification_provider_ = new NotificationProvider(this);
623
624 devtools_agent_ = new DevToolsAgent(this);
[email protected]c4a9e932011-03-05 04:05:55625 PasswordAutofillManager* password_autofill_manager =
626 new PasswordAutofillManager(this);
[email protected]78192082011-01-29 05:43:44627 AutoFillAgent* autofill_agent = new AutoFillAgent(this,
628 password_autofill_manager);
[email protected]676126f72011-01-15 00:03:51629
[email protected]78192082011-01-29 05:43:44630 webwidget_ = WebView::create(this, devtools_agent_, autofill_agent);
[email protected]676126f72011-01-15 00:03:51631 g_view_map.Get().insert(std::make_pair(webview(), this));
632 webkit_preferences_.Apply(webview());
633 webview()->initializeMainFrame(this);
634 if (!frame_name.empty())
635 webview()->mainFrame()->setName(frame_name);
[email protected]1ee59cb2011-02-23 02:45:51636 webview()->settings()->setMinimumTimerInterval(
637 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
638 webkit_glue::kForegroundTabTimerInterval);
[email protected]676126f72011-01-15 00:03:51639
640 OnSetRendererPrefs(renderer_prefs);
641
642 render_thread_->AddRoute(routing_id_, this);
643 // Take a reference on behalf of the RenderThread. This will be balanced
644 // when we receive ViewMsg_Close.
645 AddRef();
646
647 // If this is a popup, we must wait for the CreatingNew_ACK message before
648 // completing initialization. Otherwise, we can finish it now.
649 if (opener_id == MSG_ROUTING_NONE) {
650 did_show_ = true;
651 CompleteInit(parent_hwnd);
652 }
653
654 host_window_ = parent_hwnd;
655
656 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
657 if (command_line.HasSwitch(switches::kDomAutomationController))
658 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
659 if (command_line.HasSwitch(switches::kEnableAccessibility))
660 WebAccessibilityCache::enableAccessibility();
661
662 audio_message_filter_ = new AudioMessageFilter(routing_id_);
663 render_thread_->AddFilter(audio_message_filter_);
664
665 PageClickTracker* page_click_tracker = new PageClickTracker(this);
666 // Note that the order of insertion of the listeners is important.
667 // The password_autocomplete_manager takes the first shot at processing the
668 // notification and can stop the propagation.
[email protected]78192082011-01-29 05:43:44669 page_click_tracker->AddListener(password_autofill_manager);
670 page_click_tracker->AddListener(autofill_agent);
[email protected]81273622011-02-02 03:56:13671 new TranslateHelper(this);
[email protected]dec1f292011-02-11 20:20:20672 print_helper_ = new PrintWebViewHelper(this);
[email protected]6c2f73202011-02-14 20:21:54673 searchbox_ = new SearchBox(this);
[email protected]28685da92011-02-07 21:49:17674
[email protected]5efcef62011-02-22 09:00:13675 RenderThread* current_thread = RenderThread::current();
676 SpellCheck* spellcheck = current_thread ? current_thread->spellchecker() : 0;
677 spellcheck_provider_ = new SpellCheckProvider(this, spellcheck);
678
[email protected]28685da92011-02-07 21:49:17679 if (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]cae8c8492011-03-03 11:12:18680 switches::kEnableP2PApi)) {
681 p2p_socket_dispatcher_ = new P2PSocketDispatcher(this);
682 }
683
684 if (CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]28685da92011-02-07 21:49:17685 switches::kEnableClientSidePhishingDetection)) {
686 new safe_browsing::PhishingClassifierDelegate(this, NULL);
687 }
[email protected]32ca14682011-02-16 19:05:10688
689 // Observer for Malware DOM details messages.
690 new safe_browsing::MalwareDOMDetails(this);
initial.commit09911bf2008-07-26 23:55:29691}
692
693RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08694 if (decrement_shared_popup_at_destruction_)
695 shared_popup_counter_->data--;
696
[email protected]a1128322009-10-06 18:38:46697 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47698 while (!file_chooser_completions_.empty()) {
699 if (file_chooser_completions_.front()->completion) {
700 file_chooser_completions_.front()->completion->didChooseFile(
701 WebVector<WebString>());
702 }
703 file_chooser_completions_.pop_front();
704 }
[email protected]a1128322009-10-06 18:38:46705
[email protected]83dde542009-09-11 20:59:55706#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05707 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55708 if (has_document_tag_)
709 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
[email protected]c36a9b62010-10-14 00:41:11710
711 // Destroy all fake plugin window handles on the browser side.
712 while (!fake_plugin_window_handles_.empty()) {
713 // Make sure no NULL plugin window handles were inserted into this list.
714 DCHECK(*fake_plugin_window_handles_.begin());
715 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
716 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
717 }
[email protected]83dde542009-09-11 20:59:55718#endif
[email protected]98324892009-09-09 21:16:05719
[email protected]5fb88962009-04-16 19:03:25720 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59721
722#ifndef NDEBUG
723 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49724 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59725 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
726 DCHECK_NE(this, it->second) << "Failed to call Close?";
727#endif
[email protected]676126f72011-01-15 00:03:51728
729 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
730 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59731}
732
733/*static*/
734void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49735 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59736 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
737 if (!visitor->Visit(it->second))
738 return;
739 }
740}
741
742/*static*/
743RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49744 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59745 ViewMap::iterator it = views->find(webview);
746 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29747}
748
749/*static*/
[email protected]0aa55312008-10-17 21:53:08750RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24751 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15752 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08753 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51754 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08755 const WebPreferences& webkit_prefs,
756 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34757 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26758 int64 session_storage_namespace_id,
759 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29760 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51761 return new RenderView(
762 render_thread,
763 parent_hwnd,
764 opener_id,
765 renderer_prefs,
766 webkit_prefs,
767 counter,
768 routing_id,
769 session_storage_namespace_id,
770 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29771}
772
[email protected]bb461532010-11-26 21:50:23773// static
initial.commit09911bf2008-07-26 23:55:29774void RenderView::SetNextPageID(int32 next_page_id) {
775 // This method should only be called during process startup, and the given
776 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05777 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29778 DCHECK(next_page_id >= next_page_id_);
779 next_page_id_ = next_page_id;
780}
781
[email protected]676126f72011-01-15 00:03:51782void RenderView::AddObserver(RenderViewObserver* observer) {
783 observers_.AddObserver(observer);
784}
785
786void RenderView::RemoveObserver(RenderViewObserver* observer) {
787 observer->set_render_view(NULL);
788 observers_.RemoveObserver(observer);
789}
790
[email protected]70eee342010-11-05 01:59:37791bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
792 typedef ViewHostMsg_AccessibilityNotification_Params params;
[email protected]a527a022011-02-10 02:32:36793 if (type == WebKit::WebAccessibilityNotificationChildrenChanged ||
794 type == WebKit::WebAccessibilityNotificationLoadComplete) {
[email protected]70eee342010-11-05 01:59:37795 return true;
796 }
797 return false;
798}
799
[email protected]8a3125a712010-08-09 18:58:51800WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26801 return static_cast<WebKit::WebView*>(webwidget());
802}
803
[email protected]afe3a1672009-11-17 19:04:12804void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]15d04ae2010-10-30 01:04:50805 Send(new ViewHostMsg_UserMetricsRecordAction(action));
[email protected]1dbafaf72009-09-23 19:43:56806}
807
[email protected]bb461532010-11-26 21:50:23808bool RenderView::InstallWebApplicationUsingDefinitionFile(WebFrame* frame,
809 string16* error) {
810 // There is an issue of drive-by installs with the below implementation. A web
811 // site could force a user to install an app by timing the dialog to come up
812 // just before the user clicks.
813 //
814 // We do show a success UI that allows users to uninstall, but it seems that
815 // we might still want to put up an infobar before showing the install dialog.
816 //
817 // TODO(aa): Figure out this issue before removing the kEnableCrxlessWebApps
818 // switch.
819 if (!CommandLine::ForCurrentProcess()->HasSwitch(
820 switches::kEnableCrxlessWebApps)) {
821 *error = ASCIIToUTF16("CRX-less web apps aren't enabled.");
822 return false;
823 }
824
825 if (frame != frame->top()) {
826 *error = ASCIIToUTF16("Applications can only be installed from the top "
827 "frame.");
828 return false;
829 }
830
831 if (pending_app_info_.get()) {
832 *error = ASCIIToUTF16("An application install is already in progress.");
833 return false;
834 }
835
836 pending_app_info_.reset(new WebApplicationInfo());
837 if (!web_apps::ParseWebAppFromWebDocument(frame, pending_app_info_.get(),
838 error)) {
839 return false;
840 }
841
842 if (!pending_app_info_->manifest_url.is_valid()) {
843 *error = ASCIIToUTF16("Web application definition not found or invalid.");
844 return false;
845 }
846
847 app_definition_fetcher_.reset(new ResourceFetcher(
848 pending_app_info_->manifest_url, webview()->mainFrame(),
849 NewCallback(this, &RenderView::DidDownloadApplicationDefinition)));
850 return true;
851}
852
[email protected]1a3c3cb2010-12-16 21:03:40853void RenderView::SetReportLoadProgressEnabled(bool enabled) {
854 if (!enabled) {
855 load_progress_tracker_.reset(NULL);
856 return;
857 }
858 if (load_progress_tracker_ == NULL)
859 load_progress_tracker_.reset(new LoadProgressTracker(this));
860}
861
[email protected]bb461532010-11-26 21:50:23862void RenderView::DidDownloadApplicationDefinition(
863 const WebKit::WebURLResponse& response,
864 const std::string& data) {
865 scoped_ptr<WebApplicationInfo> app_info(
866 pending_app_info_.release());
867
868 JSONStringValueSerializer serializer(data);
869 int error_code = 0;
870 std::string error_message;
871 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message));
872 if (!result.get()) {
873 AddErrorToRootConsole(UTF8ToUTF16(error_message));
874 return;
875 }
876
877 string16 error_message_16;
878 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(),
879 &error_message_16)) {
880 AddErrorToRootConsole(error_message_16);
881 return;
882 }
883
884 if (!app_info->icons.empty()) {
885 pending_app_info_.reset(app_info.release());
886 pending_app_icon_requests_ =
887 static_cast<int>(pending_app_info_->icons.size());
888 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
889 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
890 new ImageResourceFetcher(
891 pending_app_info_->icons[i].url,
892 webview()->mainFrame(),
893 static_cast<int>(i),
894 pending_app_info_->icons[i].width,
895 NewCallback(this, &RenderView::DidDownloadApplicationIcon))));
896 }
897 } else {
898 Send(new ViewHostMsg_InstallApplication(routing_id_, *app_info));
899 }
900}
901
902void RenderView::DidDownloadApplicationIcon(ImageResourceFetcher* fetcher,
903 const SkBitmap& image) {
904 pending_app_info_->icons[fetcher->id()].data = image;
905
906 // Remove the image fetcher from our pending list. We're in the callback from
907 // ImageResourceFetcher, best to delay deletion.
908 for (ImageResourceFetcherList::iterator iter = app_icon_fetchers_.begin();
909 iter != app_icon_fetchers_.end(); ++iter) {
910 if (iter->get() == fetcher) {
911 iter->release();
912 app_icon_fetchers_.erase(iter);
913 break;
914 }
915 }
916
917 // We're in the callback from the ImageResourceFetcher, best to delay
918 // deletion.
919 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
920
921 if (--pending_app_icon_requests_ > 0)
922 return;
923
924 // There is a maximum size of IPC on OS X and Linux that we have run into in
925 // some situations. We're not sure what it is, but our hypothesis is in the
926 // neighborhood of 1 MB.
927 //
928 // To be on the safe side, we give ourselves 128 KB for just the image data.
929 // This should be more than enough for 128, 48, and 16 px 32-bit icons. If we
930 // want to start allowing larger icons (see bug 63406), we'll have to either
931 // experiment mor ewith this and find the real limit, or else come up with
932 // some alternative way to transmit the icon data to the browser process.
933 //
934 // See also: bug 63729.
[email protected]678a7d72011-01-05 20:37:32935 const size_t kMaxIconSize = 1024 * 128;
936 size_t actual_icon_size = 0;
[email protected]bb461532010-11-26 21:50:23937 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
[email protected]678a7d72011-01-05 20:37:32938 size_t current_size = pending_app_info_->icons[i].data.getSize();
939 if (current_size > kMaxIconSize - actual_icon_size) {
940 AddErrorToRootConsole(ASCIIToUTF16(
[email protected]bb461532010-11-26 21:50:23941 "Icons are too large. Maximum total size for app icons is 128 KB."));
[email protected]678a7d72011-01-05 20:37:32942 return;
943 }
944 actual_icon_size += current_size;
[email protected]bb461532010-11-26 21:50:23945 }
946
947 Send(new ViewHostMsg_InstallApplication(routing_id_, *pending_app_info_));
948 pending_app_info_.reset(NULL);
949}
950
[email protected]a3a8fb6d2009-10-22 20:12:51951void RenderView::PluginCrashed(const FilePath& plugin_path) {
952 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29953}
954
[email protected]aad51d1c2010-08-05 08:38:09955WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
956 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50957 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26958 bool found;
959 ContentSetting setting;
960 std::string mime_type;
961 Send(new ViewHostMsg_GetPluginInfo(
[email protected]c8f73ab2011-01-22 00:05:17962 routing_id_, params.url, frame->top()->url(), params.mimeType.utf8(),
963 &found, &info, &setting, &mime_type));
[email protected]b83ff222011-01-24 17:37:12964 if (!found || !webkit::npapi::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09965 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45966
[email protected]0bd753682010-12-16 18:15:52967 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:45968 pepper_delegate_.CreatePepperPlugin(info.path));
[email protected]aad51d1c2010-08-05 08:38:09969 if (pepper_module)
[email protected]6fdd4182010-10-14 23:59:26970 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]1a78d9f32010-12-08 06:38:45971 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09972}
973
[email protected]d8fd6fa2010-02-01 15:54:26974void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
975 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30976 // If the renderer is visible, set initial visibility and focus state.
977 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34978#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30979 delegate->SetContainerVisibility(true);
980 if (webview() && webview()->isActive())
981 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34982#endif
[email protected]49232292010-09-03 19:07:30983 }
[email protected]784ea1ab2010-09-18 00:02:34984 // Plugins start assuming the content has focus (so that they work in
985 // environments where RenderView isn't hosting them), so we always have to
986 // set the initial state. See webplugin_delegate_impl.h for details.
987 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26988}
989
990void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
991 plugin_delegates_.erase(delegate);
992}
[email protected]d8fd6fa2010-02-01 15:54:26993
[email protected]a95986a82010-12-24 06:19:28994bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27995 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27996 if (main_frame)
997 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26998
[email protected]676126f72011-01-15 00:03:51999 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
1000 RenderViewObserver* observer;
1001 while ((observer = it.GetNext()) != NULL)
1002 if (observer->OnMessageReceived(message))
1003 return true;
[email protected]b2abac72009-02-26 12:39:281004
[email protected]a95986a82010-12-24 06:19:281005 bool handled = true;
initial.commit09911bf2008-07-26 23:55:291006 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:041007 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
1008 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:291009 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
1010 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:561011 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:291012 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
1013 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
1014 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
1015 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:271016#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351017 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:271018#endif
initial.commit09911bf2008-07-26 23:55:291019 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
1020 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:051021 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
1022 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
1023 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:041024 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:291025 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
1026 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
1027 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:151028 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:291029 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:491030 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
1031 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:171032 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:541033 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
1034 OnSetContentSettingsForLoadingURL)
[email protected]d0b8d092010-10-25 04:05:171035 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:541036 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1037 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291038 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181039 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1040 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:281041 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]d8e74e82011-03-15 19:38:481042 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavicon, OnDownloadFavicon)
initial.commit09911bf2008-07-26 23:55:291043 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:481044 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:291045 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:291046 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:291047 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
1048 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
1049 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
1050 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:451051 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:401052 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
[email protected]266eb6f2008-09-30 23:56:501053 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
1054 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:291055 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
1056 OnDragSourceSystemDragEnded)
1057 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:511058 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
1059 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:291060 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1061 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1062 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1063 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]90dba072011-01-20 20:10:201064 IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage,
1065 OnDisplayPrerenderedPage)
initial.commit09911bf2008-07-26 23:55:291066 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1067 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:291068 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1069 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:041070 IPC_MESSAGE_HANDLER(
1071 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1072 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:291073 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:041074 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:291075 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1076 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:451077 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:041078 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:081079 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1080 OnDisassociateFromPopupCount)
[email protected]e8345242010-05-06 03:00:401081 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
1082 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:001083 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:271084 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:371085 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
1086 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:161087 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141088 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251089 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1090 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:101091 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1092 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511093 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:531094 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
1095 OnUpdateBrowserWindowId)
1096 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
1097 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:561098 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:341099 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:141100#if defined(OS_MACOSX)
1101 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:131102 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:131103 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1104 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:141105#endif
[email protected]446705872009-09-10 07:22:481106 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331107 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:351108 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
1109 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:331110 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1111 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:141112 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:361113 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
1114 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
1115 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:421116 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
1117 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:241118 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]caf706f2010-10-26 17:54:081119#if defined(OS_MACOSX)
1120 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1121#endif
[email protected]a6097f42011-01-10 08:50:511122 IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl,
1123 OnJavaScriptStressTestControl)
[email protected]521b2482011-01-15 00:10:101124 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]232a5812011-03-04 22:42:081125 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]634a6f92008-12-01 21:39:311126
[email protected]f0557932011-01-25 20:20:511127 // TODO(viettrungluu): Move to a separate message filter.
1128#if defined(ENABLE_FLAPPER_HACKS)
1129 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
1130#endif
1131
initial.commit09911bf2008-07-26 23:55:291132 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281133 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291134 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281135 return handled;
initial.commit09911bf2008-07-26 23:55:291136}
1137
[email protected]9b18a84f2010-06-10 15:54:041138void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:271139 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291140 if (!main_frame)
1141 return;
1142
1143 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:451144 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291145 if (url.is_empty())
1146 return;
1147
1148 if (size_.IsEmpty())
1149 return; // Don't create an empty thumbnail!
1150
1151 ThumbnailScore score;
1152 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:021153 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:151154 &thumbnail, &score))
1155 return;
1156
initial.commit09911bf2008-07-26 23:55:291157 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:461158 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:291159}
1160
[email protected]9b18a84f2010-06-10 15:54:041161void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:231162 SkBitmap snapshot;
1163 bool error = false;
1164
1165 WebFrame* main_frame = webview()->mainFrame();
1166 if (!main_frame)
1167 error = true;
1168
1169 if (!error && !CaptureSnapshot(webview(), &snapshot))
1170 error = true;
1171
1172 DCHECK(error == snapshot.empty()) <<
1173 "Snapshot should be empty on error, non-empty otherwise.";
1174
1175 // Send the snapshot to the browser process.
1176 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
1177}
1178
initial.commit09911bf2008-07-26 23:55:291179void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
1180 if (load_id != page_id_)
1181 return; // this capture call is no longer relevant due to navigation
1182 if (load_id == last_indexed_page_id_)
1183 return; // we already indexed this page
1184
1185 if (!webview())
1186 return;
1187
[email protected]26aa0482009-09-30 16:55:271188 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291189 if (!main_frame)
1190 return;
1191
1192 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:451193 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:291194 return;
1195
1196 // Don't index/capture pages that failed to load. This only checks the top
1197 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:451198 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:281199 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:291200 return;
1201
1202 if (!preliminary_capture)
1203 last_indexed_page_id_ = load_id;
1204
[email protected]a8a81292010-01-21 00:32:451205 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:451206 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291207 if (url.is_empty())
1208 return;
1209
[email protected]a8a81292010-01-21 00:32:451210 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:361211 string16 contents;
initial.commit09911bf2008-07-26 23:55:291212 CaptureText(main_frame, &contents);
1213 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:101214 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:371215 // If the page explicitly specifies a language, use it, otherwise we'll
1216 // determine it based on the text content using the CLD.
1217 std::string language =
1218 TranslateHelper::GetPageLanguageFromMetaTag(&document);
1219 if (language.empty()) {
1220 base::TimeTicks begin_time = base::TimeTicks::Now();
1221 language = DetermineTextLanguage(contents);
1222 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
1223 base::TimeTicks::Now() - begin_time);
1224 }
[email protected]a8a81292010-01-21 00:32:451225 // Send the text to the browser for indexing (the browser might decide not
1226 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:371227 Send(new ViewHostMsg_PageContents(
1228 routing_id_, url, load_id, contents, language,
1229 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:271230 }
1231
[email protected]d54169e92011-01-21 09:19:521232 // Generate the thumbnail here if the in-browser thumbnailing isn't
1233 // enabled. TODO(satorux): Remove this and related code once
1234 // crbug.com/65936 is complete.
1235 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1236 switches::kEnableInBrowserThumbnailing)) {
1237 OnCaptureThumbnail();
1238 }
[email protected]3ead1322010-11-19 20:01:001239
[email protected]28685da92011-02-07 21:49:171240 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PageCaptured(contents));
initial.commit09911bf2008-07-26 23:55:291241}
1242
[email protected]e5106202010-06-11 21:12:361243void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:291244 contents->clear();
1245 if (!frame)
1246 return;
1247
1248#ifdef TIME_TEXT_RETRIEVAL
1249 double begin = time_util::GetHighResolutionTimeNow();
1250#endif
1251
1252 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:361253 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:291254
1255#ifdef TIME_TEXT_RETRIEVAL
1256 double end = time_util::GetHighResolutionTimeNow();
1257 char buf[128];
1258 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
1259 contents.size(), (end - begin)*1000);
1260 OutputDebugStringA(buf);
1261#endif
1262
1263 // When the contents are clipped to the maximum, we don't want to have a
1264 // partial word indexed at the end that might have been clipped. Therefore,
1265 // terminate the string at the last space to ensure no words are clipped.
1266 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:361267 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:291268 if (last_space_index == std::wstring::npos)
1269 return; // don't index if we got a huge block of text with no spaces
1270 contents->resize(last_space_index);
1271 }
1272}
1273
[email protected]8649fb32009-06-26 17:51:021274bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:291275 int w,
1276 int h,
1277 SkBitmap* thumbnail,
1278 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:231279 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:151280
[email protected]8649fb32009-06-26 17:51:021281 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:231282
1283 // Paint |view| into |canvas|.
1284 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:021285 return false;
[email protected]8649fb32009-06-26 17:51:021286
1287 skia::BitmapPlatformDevice& device =
1288 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1289
1290 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:291291
[email protected]cab34d6a2009-09-24 01:14:521292 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:291293 float dest_aspect = dest_rect.width() / dest_rect.height();
1294
1295 // Get the src rect so that we can preserve the aspect ratio while filling
1296 // the destination.
1297 SkIRect src_rect;
1298 if (src_bmp.width() < dest_rect.width() ||
1299 src_bmp.height() < dest_rect.height()) {
1300 // Source image is smaller: we clip the part of source image within the
1301 // dest rect, and then stretch it to fill the dest rect. We don't respect
1302 // the aspect ratio in this case.
1303 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
1304 static_cast<S16CPU>(dest_rect.height()));
1305 score->good_clipping = false;
1306 } else {
1307 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1308 if (src_aspect > dest_aspect) {
1309 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1310 // the wider screen.
1311 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1312 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1313 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1314 score->good_clipping = false;
1315 } else {
1316 src_rect.set(0, 0, src_bmp.width(),
1317 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1318 score->good_clipping = true;
1319 }
1320 }
1321
[email protected]26aa0482009-09-30 16:55:271322 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291323
1324 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021325 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291326
[email protected]82afe4b2010-11-12 20:36:221327 // First do a fast downsample by powers of two to get close to the final size.
1328 SkBitmap downsampled_subset =
1329 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h);
1330
1331 // Do a high-quality resize from the downscaled size to the final size.
[email protected]465b34b72008-12-12 20:19:141332 *thumbnail = skia::ImageOperations::Resize(
[email protected]82afe4b2010-11-12 20:36:221333 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291334
1335 score->boring_score = CalculateBoringScore(thumbnail);
1336
[email protected]30507922010-01-15 16:48:231337 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1338 base::TimeTicks::Now() - beginning_time);
[email protected]82afe4b2010-11-12 20:36:221339
[email protected]b6e4bec2008-11-12 01:17:151340 return true;
initial.commit09911bf2008-07-26 23:55:291341}
1342
[email protected]30507922010-01-15 16:48:231343bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1344 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291345
[email protected]30507922010-01-15 16:48:231346 skia::PlatformCanvas canvas;
1347 if (!PaintViewIntoCanvas(view, canvas))
1348 return false;
1349
1350 skia::BitmapPlatformDevice& device =
1351 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1352
1353 const SkBitmap& bitmap = device.accessBitmap(false);
1354 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1355 return false;
1356
1357 HISTOGRAM_TIMES("Renderer4.Snapshot",
1358 base::TimeTicks::Now() - beginning_time);
1359 return true;
initial.commit09911bf2008-07-26 23:55:291360}
1361
1362void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1363 if (!webview())
1364 return;
1365
[email protected]3cc72b12010-03-18 23:03:001366 history_list_offset_ = params.current_history_list_offset;
1367 history_list_length_ = params.current_history_list_length;
1368
[email protected]a9f607e2009-10-23 19:59:271369 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261370
initial.commit09911bf2008-07-26 23:55:291371 AboutHandler::MaybeHandle(params.url);
1372
[email protected]ecbf10d2010-02-18 13:03:291373 bool is_reload =
1374 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1375 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291376
[email protected]26aa0482009-09-30 16:55:271377 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451378 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291379 // We cannot reload if we do not have any history state. This happens, for
1380 // example, when recovering from a crash. Our workaround here is a bit of
1381 // a hack since it means that reload after a crashed tab does not cause an
1382 // end-to-end cache validation.
1383 is_reload = false;
1384 }
1385
[email protected]77f17a82009-05-21 04:42:541386 // A navigation resulting from loading a javascript URL should not be treated
1387 // as a browser initiated event. Instead, we want it to look as if the page
1388 // initiated any load resulting from JS execution.
1389 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301390 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001391 params.page_id,
1392 params.pending_history_list_offset,
1393 params.transition,
1394 params.request_time);
[email protected]5e369672009-11-03 23:48:301395 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1396 // We're doing a load of a page that was restored from the last session.
1397 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1398 // which can result in stale data for pages that are set to expire. We
1399 // explicitly override that by setting the policy here so that as
1400 // necessary we load from the network.
1401 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1402 }
1403 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541404 }
initial.commit09911bf2008-07-26 23:55:291405
[email protected]a7ccc4d2010-01-27 08:14:481406 NavigationState* navigation_state = pending_navigation_state_.get();
1407
[email protected]04d3c6e2009-05-22 17:00:131408 // If we are reloading, then WebKit will use the history state of the current
1409 // page, so we should just ignore any given history state. Otherwise, if we
1410 // have history state, then we need to navigate to it, which corresponds to a
1411 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551412 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481413 if (navigation_state)
1414 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291415 bool ignore_cache = (params.navigation_type ==
1416 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1417 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551418 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131419 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581420 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481421 if (navigation_state)
1422 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451423 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171424 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131425 } else {
1426 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281427 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291428
[email protected]e6f546c32009-07-01 17:12:551429 // A session history navigation should have been accompanied by state.
1430 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131431
[email protected]dd7daa82009-08-10 05:46:451432 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551433 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131434
[email protected]726985e22009-06-18 21:09:281435 if (params.referrer.is_valid()) {
1436 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1437 WebString::fromUTF8(params.referrer.spec()));
1438 }
[email protected]04d3c6e2009-05-22 17:00:131439
[email protected]52c68652010-12-07 17:47:041440 if (!params.extra_headers.empty()) {
1441 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1442 params.extra_headers.end(), "\n");
1443 i.GetNext(); ) {
1444 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1445 WebString::fromUTF8(i.values()));
1446 }
1447 }
1448
[email protected]90dba072011-01-20 20:10:201449 if (navigation_state) {
1450 if (params.navigation_type != ViewMsg_Navigate_Params::PRERENDER) {
1451 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
1452 } else {
1453 navigation_state->set_load_type(NavigationState::PRERENDER_LOAD);
[email protected]987d51af2011-02-24 17:50:181454 is_prerendering_ = true;
[email protected]90dba072011-01-20 20:10:201455 }
1456 }
[email protected]dd7daa82009-08-10 05:46:451457 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501458 }
1459
[email protected]77f17a82009-05-21 04:42:541460 // In case LoadRequest failed before DidCreateDataSource was called.
1461 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291462}
1463
1464// Stop loading the current page
1465void RenderView::OnStop() {
1466 if (webview())
[email protected]b4bb2502009-10-01 22:35:271467 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291468}
1469
[email protected]ecbf10d2010-02-18 13:03:291470// Reload current focused frame.
1471// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561472void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291473 if (webview() && webview()->focusedFrame()) {
1474 // We always obey the cache (ignore_cache=false) here.
1475 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1476 // a cache-ignoring reload of the frame.
1477 webview()->focusedFrame()->reload(false);
1478 }
[email protected]1dda4022010-01-28 18:24:561479}
1480
initial.commit09911bf2008-07-26 23:55:291481void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271482 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291483}
1484
[email protected]68b1e922009-06-23 16:00:251485void RenderView::OnExecuteEditCommand(const std::string& name,
1486 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271487 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251488 return;
1489
[email protected]26aa0482009-09-30 16:55:271490 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451491 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251492}
1493
[email protected]b2abac72009-02-26 12:39:281494void RenderView::OnSetupDevToolsClient() {
[email protected]676126f72011-01-15 00:03:511495 DCHECK(!devtools_client_);
1496 devtools_client_ = new DevToolsClient(this);
[email protected]b2abac72009-02-26 12:39:281497}
1498
initial.commit09911bf2008-07-26 23:55:291499void RenderView::OnUpdateTargetURLAck() {
1500 // Check if there is a targeturl waiting to be sent.
1501 if (target_url_status_ == TARGET_PENDING) {
1502 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1503 pending_target_url_));
1504 }
1505
1506 target_url_status_ = TARGET_NONE;
1507}
1508
1509void RenderView::OnUndo() {
1510 if (!webview())
1511 return;
1512
[email protected]26aa0482009-09-30 16:55:271513 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121514 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291515}
1516
1517void RenderView::OnRedo() {
1518 if (!webview())
1519 return;
1520
[email protected]26aa0482009-09-30 16:55:271521 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121522 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291523}
1524
1525void RenderView::OnCut() {
1526 if (!webview())
1527 return;
1528
[email protected]26aa0482009-09-30 16:55:271529 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121530 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291531}
1532
1533void RenderView::OnCopy() {
1534 if (!webview())
1535 return;
1536
[email protected]26aa0482009-09-30 16:55:271537 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121538 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291539}
1540
[email protected]c0cc3092009-09-12 08:27:271541#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351542void RenderView::OnCopyToFindPboard() {
1543 if (!webview())
1544 return;
1545
1546 // Since the find pasteboard supports only plain text, this can be simpler
1547 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271548 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351549 if (frame->hasSelection()) {
1550 string16 selection = frame->selectionAsText();
1551 RenderThread::current()->Send(
[email protected]7e3589742011-03-10 18:49:171552 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351553 }
1554
[email protected]afe3a1672009-11-17 19:04:121555 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351556}
[email protected]c0cc3092009-09-12 08:27:271557#endif
[email protected]a954bf72009-09-12 07:30:351558
initial.commit09911bf2008-07-26 23:55:291559void RenderView::OnPaste() {
1560 if (!webview())
1561 return;
1562
[email protected]26aa0482009-09-30 16:55:271563 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121564 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291565}
1566
[email protected]2a3a7762009-10-19 19:17:321567void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291568 if (!webview())
1569 return;
1570
[email protected]1ff7a032010-02-03 02:46:031571 WebFrame* frame = webview()->focusedFrame();
1572 if (!frame->hasSelection())
1573 frame->selectWordAroundCaret();
1574 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291575}
1576
[email protected]98324892009-09-09 21:16:051577void RenderView::OnAdvanceToNextMisspelling() {
1578 if (!webview())
1579 return;
[email protected]26aa0482009-09-30 16:55:271580 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051581 WebString::fromUTF8("AdvanceToNextMisspelling"));
1582}
1583
1584void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1585 if (!webview())
1586 return;
1587 // We need to tell the webView whether the spelling panel is visible or not so
1588 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261589 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271590 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051591 WebString::fromUTF8("ToggleSpellPanel"));
1592}
1593
[email protected]bbbd545c2008-12-15 20:18:041594void RenderView::OnToggleSpellCheck() {
1595 if (!webview())
1596 return;
1597
[email protected]26aa0482009-09-30 16:55:271598 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451599 frame->enableContinuousSpellChecking(
1600 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041601}
1602
initial.commit09911bf2008-07-26 23:55:291603void RenderView::OnDelete() {
1604 if (!webview())
1605 return;
1606
[email protected]26aa0482009-09-30 16:55:271607 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121608 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291609}
1610
1611void RenderView::OnSelectAll() {
1612 if (!webview())
1613 return;
1614
[email protected]26aa0482009-09-30 16:55:271615 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221616 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121617 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291618}
1619
1620void RenderView::OnSetInitialFocus(bool reverse) {
1621 if (!webview())
1622 return;
[email protected]26aa0482009-09-30 16:55:271623 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291624}
1625
[email protected]9b66f34bf2010-10-27 20:45:511626void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:091627 WebKit::WebNode node = GetFocusedNode();
1628 if (!node.isNull()) {
1629 if (IsEditableNode(node))
1630 // TODO(varunjain): Change webkit API to scroll a particular node into
1631 // view and use that API here instead.
1632 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:511633 }
1634}
1635
initial.commit09911bf2008-07-26 23:55:291636///////////////////////////////////////////////////////////////////////////////
1637
[email protected]433819d2010-01-30 20:20:011638void RenderView::SetContentSettings(const ContentSettings& settings) {
1639 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011640}
1641
initial.commit09911bf2008-07-26 23:55:291642// Tell the embedding application that the URL of the active page has changed
1643void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451644 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291645 DCHECK(ds);
1646
[email protected]726985e22009-06-18 21:09:281647 const WebURLRequest& request = ds->request();
1648 const WebURLRequest& original_request = ds->originalRequest();
1649 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291650
[email protected]daa8c58e2009-06-15 17:21:101651 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1652 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291653
1654 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281655 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291656 params.is_post = false;
1657 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071658 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191659 params.socket_address.set_host(response.remoteIPAddress().utf8());
1660 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031661 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091662 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551663 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291664 // SSL state specified in the request takes precedence over the one in the
1665 // response.
1666 // So far this is only intended for error pages that are not expected to be
1667 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281668 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551669 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291670 } else {
[email protected]726985e22009-06-18 21:09:281671 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291672 }
1673
1674 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281675 if (ds->hasUnreachableURL()) {
1676 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291677 } else {
[email protected]726985e22009-06-18 21:09:281678 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291679 }
1680
[email protected]726985e22009-06-18 21:09:281681 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241682 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041683 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291684
[email protected]ce0e250d2009-10-23 21:00:351685 params.searchable_form_url = navigation_state->searchable_form_url();
1686 params.searchable_form_encoding =
1687 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291688
1689 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101690 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291691 if (password_form_data)
1692 params.password_form = *password_form_data;
1693
1694 params.gesture = navigation_gesture_;
1695 navigation_gesture_ = NavigationGestureUnknown;
1696
[email protected]0f38dc4552011-02-25 11:24:001697 // Make navigation state a part of the FrameNavigate message so that commited
1698 // entry had it at all times.
1699 const WebHistoryItem& item = frame->currentHistoryItem();
1700 if (!item.isNull()) {
1701 params.content_state = webkit_glue::HistoryItemToString(item);
1702 } else {
1703 params.content_state =
1704 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1705 }
1706
[email protected]dd7daa82009-08-10 05:46:451707 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291708 // Top-level navigation.
1709
[email protected]71b0d5d2010-02-15 05:43:071710 // Clear "block" flags for the new page. This needs to happen before any of
1711 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1712 // so that these functions can correctly detect that a piece of content
1713 // flipped from "not blocked" to "blocked".
1714 ClearBlockedContentSettings();
1715
[email protected]62d2a112010-04-07 00:53:021716 // Set content settings. Default them from the parent window if one exists.
1717 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011718 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541719 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011720 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011721 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011722
1723 // These content settings were merely recorded transiently for this load.
1724 // We can erase them now. If at some point we reload this page, the
1725 // browser will send us new, up-to-date content settings.
1726 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401727 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101728 // The opener's view is not guaranteed to be non-null (it could be
1729 // detached from its page but not yet destructed).
1730 if (WebView* opener_view = frame->opener()->view()) {
1731 RenderView* opener = FromWebView(opener_view);
1732 SetContentSettings(opener->current_content_settings_);
1733 }
[email protected]f85f0702010-01-30 09:31:011734 }
1735
[email protected]b75b8292010-10-01 07:28:251736 // Set zoom level, but don't do it for full-page plugin since they don't use
1737 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011738 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541739 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251740 if (webview()->mainFrame()->document().isPluginDocument()) {
1741 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251742 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251743 } else {
1744 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251745 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251746 }
1747
[email protected]f85f0702010-01-30 09:31:011748 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511749 // This zoom level was merely recorded transiently for this load. We can
1750 // erase it now. If at some point we reload this page, the browser will
1751 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011752 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511753 }
1754
[email protected]b75b8292010-10-01 07:28:251755 // Reset the zoom limits in case a plugin had changed them previously. This
1756 // will also call us back which will cause us to send a message to
1757 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251758 webview()->zoomLimitsChanged(
1759 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1760 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251761
initial.commit09911bf2008-07-26 23:55:291762 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551763 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291764
[email protected]daa8c58e2009-06-15 17:21:101765 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291766 if (!PageTransition::IsMainFrame(params.transition)) {
1767 // If the main frame does a load, it should not be reported as a subframe
1768 // navigation. This can occur in the following case:
1769 // 1. You're on a site with frames.
1770 // 2. You do a subframe navigation. This is stored with transition type
1771 // MANUAL_SUBFRAME.
1772 // 3. You navigate to some non-frame site, say, google.com.
1773 // 4. You navigate back to the page from step 2. Since it was initially
1774 // MANUAL_SUBFRAME, it will be that same transition type here.
1775 // We don't want that, because any navigation that changes the toplevel
1776 // frame should be tracked as a toplevel navigation (this allows us to
1777 // update the URL bar, etc).
1778 params.transition = PageTransition::LINK;
1779 }
1780
initial.commit09911bf2008-07-26 23:55:291781 // If we have a valid consumed client redirect source,
1782 // the page contained a client redirect (meta refresh, document.loc...),
1783 // so we set the referrer and transition to match.
1784 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041785 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291786 params.referrer = completed_client_redirect_src_;
1787 params.transition = static_cast<PageTransition::Type>(
1788 params.transition | PageTransition::CLIENT_REDIRECT);
1789 } else {
1790 // Bug 654101: the referrer will be empty on https->http transitions. It
1791 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281792 params.referrer = GURL(
1793 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291794 }
1795
[email protected]726985e22009-06-18 21:09:281796 string16 method = request.httpMethod();
1797 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291798 params.is_post = true;
1799
[email protected]c2a797d2009-09-21 16:46:321800 // Save some histogram data so we can compute the average memory used per
1801 // page load of the glyphs.
1802 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1803 webkit_glue::GetGlyphPageCount());
1804
[email protected]15cf526b2010-02-12 06:33:491805 // This message needs to be sent before any of allowScripts(),
1806 // allowImages(), allowPlugins() is called for the new page, so that when
1807 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1808 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291809 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1810 } else {
1811 // Subframe navigation: the type depends on whether this navigation
1812 // generated a new session history entry. When they do generate a session
1813 // history entry, it means the user initiated the navigation and we should
1814 // mark it as such. This test checks if this is the first time UpdateURL
1815 // has been called since WillNavigateToURL was called to initiate the load.
1816 if (page_id_ > last_page_id_sent_to_browser_)
1817 params.transition = PageTransition::MANUAL_SUBFRAME;
1818 else
1819 params.transition = PageTransition::AUTO_SUBFRAME;
1820
initial.commit09911bf2008-07-26 23:55:291821 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1822 }
1823
1824 last_page_id_sent_to_browser_ =
1825 std::max(last_page_id_sent_to_browser_, page_id_);
1826
1827 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101828 // we don't want the transition type to persist. Just clear it.
1829 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501830
[email protected]af15bed2010-08-25 21:12:091831 // Check if the navigation was within the same page, in which case we don't
1832 // want to clear the accessibility cache.
1833 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351834 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141835 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501836 }
initial.commit09911bf2008-07-26 23:55:291837}
1838
1839// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171840void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291841 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171842 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171843 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171844 routing_id_,
1845 page_id_,
1846 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1847 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171848 }
initial.commit09911bf2008-07-26 23:55:291849}
1850
1851void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401852 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291853 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271854 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291855 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301856 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291857 last_encoding_name_ = encoding_name;
1858
[email protected]e38f40152008-09-12 23:08:301859 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291860 }
1861}
1862
[email protected]e15f680732010-11-23 22:30:201863// Sends the last committed session history state to the browser so it will be
1864// saved before we navigate to a new page. This must be called *before* the
1865// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291866void RenderView::UpdateSessionHistory(WebFrame* frame) {
1867 // If we have a valid page ID at this point, then it corresponds to the page
1868 // we are navigating away from. Otherwise, this is the first navigation, so
1869 // there is no past session history to record.
1870 if (page_id_ == -1)
1871 return;
1872
[email protected]ca948a22009-06-25 19:36:171873 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271874 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171875 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291876 return;
[email protected]ca948a22009-06-25 19:36:171877
1878 Send(new ViewHostMsg_UpdateState(
1879 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291880}
1881
[email protected]3d9689372009-09-10 04:29:171882void RenderView::OpenURL(
1883 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1884 Send(new ViewHostMsg_OpenURL(
1885 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1886}
1887
[email protected]79dbc662009-09-04 05:42:511888// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291889
initial.commit09911bf2008-07-26 23:55:291890void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281891 const WebURLRequest& failed_request,
1892 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291893 const std::string& html,
1894 bool replace) {
[email protected]726985e22009-06-18 21:09:281895 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291896 std::string alt_html;
[email protected]2a521c52011-01-26 18:45:211897 const Extension* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291898 if (html.empty()) {
1899 // Use a local error page.
1900 int resource_id;
1901 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111902
[email protected]81654282010-10-04 17:08:061903 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
[email protected]2a521c52011-01-26 18:45:211904 extension = render_thread_->GetExtensions()->GetByURL(failed_url);
[email protected]5351dbc2010-08-27 15:22:111905 if (extension) {
[email protected]3f853a52010-09-13 19:15:081906 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1907 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111908
1909 // TODO(erikkay): Should we use a different template for different
1910 // error messages?
1911 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291912 } else {
[email protected]3f853a52010-09-13 19:15:081913 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1914 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111915 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081916 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111917 } else {
[email protected]3f853a52010-09-13 19:15:081918 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111919 }
[email protected]75891fe2010-11-20 15:55:181920 resource_id = IDR_NET_ERROR_HTML;
initial.commit09911bf2008-07-26 23:55:291921 }
initial.commit09911bf2008-07-26 23:55:291922
1923 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1924 } else {
1925 alt_html = html;
1926 }
1927
[email protected]dd7daa82009-08-10 05:46:451928 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361929 GURL(chrome::kUnreachableWebDataURL),
[email protected]e6f546c32009-07-01 17:12:551930 failed_url,
1931 replace);
initial.commit09911bf2008-07-26 23:55:291932}
1933
[email protected]7ccddb8c2009-08-04 17:36:551934void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031935 if (!dom_automation_controller_.get()) {
1936 dom_automation_controller_.reset(new DomAutomationController());
1937 }
1938 dom_automation_controller_->set_message_sender(this);
1939 dom_automation_controller_->set_routing_id(routing_id_);
1940 dom_automation_controller_->BindToJavascript(frame,
[email protected]906690b2010-12-03 18:11:251941 "domAutomationController");
initial.commit09911bf2008-07-26 23:55:291942}
1943
initial.commit09911bf2008-07-26 23:55:291944bool RenderView::RunJavaScriptMessage(int type,
1945 const std::wstring& message,
1946 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071947 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291948 std::wstring* result) {
1949 bool success = false;
1950 std::wstring result_temp;
1951 if (!result)
1952 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291953
[email protected]12636df2009-09-28 22:32:211954 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1955 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291956 return success;
1957}
1958
[email protected]c1f50aa2010-02-18 03:46:571959bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1960 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1961 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1962 // it is particularly important that we do not call willEnterModalLoop as
1963 // that would defer resource loads for the dialog itself.
1964 if (RenderThread::current()) // Will be NULL during unit tests.
1965 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1966
1967 message->EnableMessagePumping(); // Runs a nested message loop.
1968 return Send(message);
1969}
1970
[email protected]2de7e002010-10-11 22:58:201971void RenderView::AddGURLSearchProvider(
1972 const GURL& osd_url,
1973 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
initial.commit09911bf2008-07-26 23:55:291974 if (!osd_url.is_empty())
1975 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
[email protected]2de7e002010-10-11 22:58:201976 provider_type));
initial.commit09911bf2008-07-26 23:55:291977}
1978
[email protected]e8345242010-05-06 03:00:401979void RenderView::OnAllowScriptToClose(bool script_can_close) {
1980 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311981}
1982
[email protected]2de7e002010-10-11 22:58:201983void RenderView::AddSearchProvider(
1984 const std::string& url,
1985 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
1986 if (provider_type.type ==
1987 ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER &&
1988 !webview()->mainFrame()->isProcessingUserGesture())
1989 return;
1990
1991 AddGURLSearchProvider(GURL(url), provider_type);
initial.commit09911bf2008-07-26 23:55:291992}
1993
[email protected]155f35e2010-07-17 00:30:181994ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251995RenderView::GetSearchProviderInstallState(WebFrame* frame,
1996 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:181997 GURL inquiry_url = GURL(url);
1998 if (inquiry_url.is_empty())
1999 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:252000
[email protected]155f35e2010-07-17 00:30:182001 ViewHostMsg_GetSearchProviderInstallState_Params install;
2002 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:252003 frame->url(),
[email protected]155f35e2010-07-17 00:30:182004 inquiry_url,
2005 &install));
2006 return install;
2007}
2008
[email protected]f103ab72009-09-02 17:10:592009void RenderView::OnMissingPluginStatus(
2010 WebPluginDelegateProxy* delegate,
2011 int status) {
[email protected]6c8afae52009-01-22 02:24:572012#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:592013 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:292014 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:502015 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:592016 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:292017 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2018 }
2019 } else {
2020 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
2021 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:502022 if (status ==
2023 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:292024 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2025 }
2026 }
[email protected]6c8afae52009-01-22 02:24:572027#else
[email protected]76c3b312010-05-20 21:38:292028 // TODO(port): Implement the infobar that accompanies the default plugin.
2029 // Linux: http://crbug.com/10952
2030 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:572031 NOTIMPLEMENTED();
2032#endif
initial.commit09911bf2008-07-26 23:55:292033}
2034
[email protected]48c9cf2d2009-09-16 16:47:522035// WebKit::WebViewClient ------------------------------------------------------
2036
[email protected]844acf372011-01-14 10:49:272037WebView* RenderView::createView(
2038 WebFrame* creator,
2039 const WebURLRequest& request,
2040 const WebWindowFeatures& features,
2041 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:522042 // Check to make sure we aren't overloading on popups.
2043 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2044 return NULL;
2045
2046 // This window can't be closed from a window.close() call until we receive a
2047 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:402048 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:522049
[email protected]8ab04652010-06-12 02:47:262050 ViewHostMsg_CreateWindow_Params params;
2051 params.opener_id = routing_id_;
2052 params.user_gesture = creator->isProcessingUserGesture();
2053 params.window_container_type = WindowFeaturesToContainerType(features);
2054 params.session_storage_namespace_id = session_storage_namespace_id_;
2055 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112056 params.opener_frame_id = creator->identifier();
2057 params.opener_url = creator->url();
2058 params.opener_security_origin = creator->securityOrigin().toString().utf8();
2059 if (!request.isNull())
2060 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:262061
[email protected]48c9cf2d2009-09-16 16:47:522062 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:342063 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:262064 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:522065
[email protected]48c9cf2d2009-09-16 16:47:522066 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:262067 new ViewHostMsg_CreateWindow(params,
2068 &routing_id,
2069 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212070 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522071 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522072
[email protected]48c9cf2d2009-09-16 16:47:522073 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:422074 0,
[email protected]12636df2009-09-28 22:32:212075 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:522076 renderer_preferences_,
2077 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:212078 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:342079 routing_id,
[email protected]8ab04652010-06-12 02:47:262080 cloned_session_storage_namespace_id,
2081 frame_name);
2082 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522083
[email protected]007a848b2009-10-26 15:55:462084 // Record whether the creator frame is trying to suppress the opener field.
2085 view->opener_suppressed_ = opener_suppressed;
2086
[email protected]48c9cf2d2009-09-16 16:47:522087 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:092088 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:522089 if (!creator_url.is_valid() || !creator_url.IsStandard())
2090 creator_url = GURL();
2091 view->creator_url_ = creator_url;
2092
2093 // Copy over the alternate error page URL so we can have alt error pages in
2094 // the new render view (we don't need the browser to send the URL back down).
2095 view->alternate_error_page_url_ = alternate_error_page_url_;
2096
2097 return view->webview();
2098}
2099
[email protected]3e2b375b2010-04-07 17:03:122100WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:522101 RenderWidget* widget = RenderWidget::Create(routing_id_,
2102 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:122103 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:522104 return widget->webwidget();
2105}
2106
2107WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:442108 // TODO(jcivelli): Remove this deprecated method when its been removed from
2109 // the WebViewClient interface. It's been replaced by
2110 // createExternalPopupMenu.
2111 NOTREACHED();
2112 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522113}
2114
[email protected]caf706f2010-10-26 17:54:082115WebExternalPopupMenu* RenderView::createExternalPopupMenu(
2116 const WebPopupMenuInfo& popup_menu_info,
2117 WebExternalPopupMenuClient* popup_menu_client) {
2118 DCHECK(!external_popup_menu_.get());
2119 external_popup_menu_.reset(
2120 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2121 return external_popup_menu_.get();
2122}
2123
[email protected]0bd753682010-12-16 18:15:522124webkit::ppapi::FullscreenContainer*
2125RenderView::CreatePepperFullscreenContainer(
2126 webkit::ppapi::PluginInstance* plugin) {
[email protected]79c7bed2010-09-14 22:28:392127 RenderWidgetFullscreenPepper* widget =
2128 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
2129 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:562130 return widget;
[email protected]79c7bed2010-09-14 22:28:392131}
2132
[email protected]68c50e52010-05-12 11:14:392133WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:342134 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:392135 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:292136 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
2137 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
2138 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342139}
2140
[email protected]48c9cf2d2009-09-16 16:47:522141void RenderView::didAddMessageToConsole(
2142 const WebConsoleMessage& message, const WebString& source_name,
2143 unsigned source_line) {
2144 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2145 UTF16ToWideHack(message.text),
2146 static_cast<int32>(source_line),
2147 UTF16ToWideHack(source_name)));
2148}
2149
2150void RenderView::printPage(WebFrame* frame) {
[email protected]09285ec2011-03-11 21:04:342151 // TODO(thestig) Handle print preview case. http://crbug.com/75505.
[email protected]71a14262009-09-22 20:02:582152 DCHECK(frame);
[email protected]09285ec2011-03-11 21:04:342153 print_helper_->ScriptInitiatedPrint(frame);
[email protected]48c9cf2d2009-09-16 16:47:522154}
2155
[email protected]3354d3e2010-06-10 19:53:022156WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512157 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022158}
2159
[email protected]48c9cf2d2009-09-16 16:47:522160void RenderView::didStartLoading() {
2161 if (is_loading_) {
2162 DLOG(WARNING) << "didStartLoading called while loading";
2163 return;
2164 }
2165
2166 is_loading_ = true;
2167 // Clear the pointer so that we can assign it only when there is an unknown
2168 // plugin on a page.
2169 first_default_plugin_.reset();
2170
2171 Send(new ViewHostMsg_DidStartLoading(routing_id_));
2172}
2173
2174void RenderView::didStopLoading() {
2175 if (!is_loading_) {
2176 DLOG(WARNING) << "DidStopLoading called while not loading";
2177 return;
2178 }
2179
2180 is_loading_ = false;
2181
2182 // NOTE: For now we're doing the safest thing, and sending out notification
2183 // when done loading. This currently isn't an issue as the favicon is only
2184 // displayed when done loading. Ideally we would send notification when
2185 // finished parsing the head, but webkit doesn't support that yet.
2186 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:272187 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:522188 if (!favicon_url.is_empty())
[email protected]d8e74e82011-03-15 19:38:482189 Send(new ViewHostMsg_UpdateFaviconURL(routing_id_, page_id_, favicon_url));
[email protected]48c9cf2d2009-09-16 16:47:522190
[email protected]26aa0482009-09-30 16:55:272191 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]2de7e002010-10-11 22:58:202192 ViewHostMsg_PageHasOSDD_Type::Autodetected());
[email protected]48c9cf2d2009-09-16 16:47:522193
2194 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2195
[email protected]90109412010-12-15 17:14:242196 if (load_progress_tracker_ != NULL)
2197 load_progress_tracker_->DidStopLoading();
2198
[email protected]f9f4841b2010-03-20 05:41:422199 MessageLoop::current()->PostDelayedTask(
2200 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302201 page_info_method_factory_.NewRunnableMethod(
2202 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:372203 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:522204}
2205
[email protected]90109412010-12-15 17:14:242206void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
2207 if (load_progress_tracker_ != NULL)
2208 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2209}
2210
[email protected]f55039a2010-02-17 14:12:062211bool RenderView::isSmartInsertDeleteEnabled() {
2212#if defined(OS_MACOSX)
2213 return true;
2214#else
2215 return false;
2216#endif
2217}
2218
[email protected]04fc9482009-09-18 22:13:032219bool RenderView::isSelectTrailingWhitespaceEnabled() {
2220#if defined(OS_WIN)
2221 return true;
2222#else
2223 return false;
2224#endif
2225}
2226
[email protected]04fc9482009-09-18 22:13:032227void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:422228#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032229 if (!handling_input_event_)
2230 return;
2231 // TODO(estade): investigate incremental updates to the selection so that we
2232 // don't send the entire selection over IPC every time.
2233 if (!is_empty_selection) {
2234 // Sometimes we get repeated didChangeSelection calls from webkit when
2235 // the selection hasn't actually changed. We don't want to report these
2236 // because it will cause us to continually claim the X clipboard.
2237 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:272238 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:032239 if (this_selection == last_selection_)
2240 return;
2241
2242 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2243 this_selection));
2244 last_selection_ = this_selection;
2245 } else {
2246 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:162247 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2248 last_selection_));
[email protected]04fc9482009-09-18 22:13:032249 }
[email protected]0ff0ff32010-12-21 19:34:422250#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032251}
2252
2253void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122254 const std::string& name = UTF16ToUTF8(command_name);
2255 if (StartsWithASCII(name, "Move", true) ||
2256 StartsWithASCII(name, "Insert", true) ||
2257 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032258 return;
2259 UserMetricsRecordAction(name);
2260}
2261
[email protected]54ec7f82010-10-21 22:32:512262void RenderView::SendPendingAccessibilityNotifications() {
2263 if (!accessibility_.get())
2264 return;
2265
2266 if (pending_accessibility_notifications_.empty())
2267 return;
2268
2269 // Send all pending accessibility notifications.
2270 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
2271 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
2272 RendererAccessibilityNotification& notification =
2273 pending_accessibility_notifications_[i];
2274 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
2275 if (!obj.isValid())
2276 continue;
2277
2278 ViewHostMsg_AccessibilityNotification_Params param;
[email protected]a527a022011-02-10 02:32:362279 WebAccessibilityNotificationToViewHostMsg(
2280 pending_accessibility_notifications_[i].type, &param.notification_type);
[email protected]70eee342010-11-05 01:59:372281 param.acc_obj = WebAccessibility(
2282 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:512283 notifications.push_back(param);
2284 }
2285 pending_accessibility_notifications_.clear();
2286 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
2287 accessibility_ack_pending_ = true;
2288}
2289
[email protected]b2528b72009-09-24 06:57:102290bool RenderView::handleCurrentKeyboardEvent() {
2291 if (edit_commands_.empty())
2292 return false;
2293
[email protected]26aa0482009-09-30 16:55:272294 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102295 if (!frame)
2296 return false;
2297
2298 EditCommands::iterator it = edit_commands_.begin();
2299 EditCommands::iterator end = edit_commands_.end();
2300
[email protected]507b33ea2009-09-29 03:56:512301 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102302 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332303 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2304 // key (but it's the exception). Once one edit command is not executed, it
2305 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102306 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2307 WebString::fromUTF8(it->value)))
2308 break;
[email protected]507b33ea2009-09-29 03:56:512309 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102310 }
2311
[email protected]507b33ea2009-09-29 03:56:512312 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102313}
2314
[email protected]2a3a7762009-10-19 19:17:322315void RenderView::spellCheck(const WebString& text,
2316 int& misspelled_offset,
2317 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:562318 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:462319
[email protected]85c55dc2009-11-06 03:05:462320 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:172321 RenderThread* thread = RenderThread::current();
2322 // Will be NULL during unit tests.
2323 if (thread) {
[email protected]c27324b2009-11-19 22:44:292324 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:172325 word.c_str(), word.size(), document_tag_,
2326 &misspelled_offset, &misspelled_length, NULL);
2327 }
[email protected]1dbafaf72009-09-23 19:43:562328}
2329
[email protected]5efcef62011-02-22 09:00:132330void RenderView::requestCheckingOfText(
2331 const WebString& text,
2332 WebKit::WebTextCheckingCompletion* completion) {
2333 spellcheck_provider_->RequestTextChecking(text, document_tag_, completion);
2334}
2335
[email protected]1dbafaf72009-09-23 19:43:562336WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322337 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562338 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:262339 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:562340 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:172341 RenderThread* thread = RenderThread::current();
2342 // Will be NULL during unit tests.
2343 if (thread) {
2344 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:292345 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:172346 word, document_tag_);
2347 }
[email protected]1dbafaf72009-09-23 19:43:562348 }
[email protected]2a3a7762009-10-19 19:17:322349 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562350}
2351
[email protected]c49085c72009-10-02 16:28:562352void RenderView::showSpellingUI(bool show) {
2353 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2354}
2355
[email protected]8922e1f2009-10-03 05:01:262356bool RenderView::isShowingSpellingUI() {
2357 return spelling_panel_visible_;
2358}
2359
[email protected]1dbafaf72009-09-23 19:43:562360void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322361 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2362 word));
[email protected]1dbafaf72009-09-23 19:43:562363}
2364
[email protected]13a1e4c3c2011-02-03 21:07:092365void RenderView::continuousSpellCheckingEnabledStateChanged() {
2366 UpdateToggleSpellCheckCommandState();
2367}
2368
[email protected]a1128322009-10-06 18:38:462369bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352370 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472371 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352372 // Do not open the file dialog in a hidden RenderView.
2373 if (is_hidden())
2374 return false;
[email protected]cdaf8d02010-03-30 19:52:472375 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262376 if (params.directory)
2377 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2378 else if (params.multiSelect)
2379 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2380 else
2381 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472382 ipc_params.title = params.title;
2383 ipc_params.default_file_name =
2384 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592385 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472386
2387 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462388}
2389
[email protected]48c9cf2d2009-09-16 16:47:522390void RenderView::runModalAlertDialog(
2391 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062392 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]48c9cf2d2009-09-16 16:47:522393 UTF16ToWideHack(message),
2394 std::wstring(),
2395 frame->url(),
2396 NULL);
2397}
2398
2399bool RenderView::runModalConfirmDialog(
2400 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062401 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]48c9cf2d2009-09-16 16:47:522402 UTF16ToWideHack(message),
2403 std::wstring(),
2404 frame->url(),
2405 NULL);
2406}
2407
2408bool RenderView::runModalPromptDialog(
2409 WebFrame* frame, const WebString& message, const WebString& default_value,
2410 WebString* actual_value) {
2411 std::wstring result;
[email protected]9dd7e3d72011-01-20 18:27:062412 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]48c9cf2d2009-09-16 16:47:522413 UTF16ToWideHack(message),
2414 UTF16ToWideHack(default_value),
2415 frame->url(),
2416 &result);
2417 if (ok)
2418 actual_value->assign(WideToUTF16Hack(result));
2419 return ok;
2420}
2421
2422bool RenderView::runModalBeforeUnloadDialog(
2423 WebFrame* frame, const WebString& message) {
2424 bool success = false;
2425 // This is an ignored return value, but is included so we can accept the same
2426 // response as RunJavaScriptMessage.
2427 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212428 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522429 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212430 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522431 return success;
2432}
2433
[email protected]79e37442009-10-09 18:17:442434void RenderView::showContextMenu(
2435 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292436 ContextMenuParams params = ContextMenuParams(data);
2437 if (!params.misspelled_word.empty() && RenderThread::current()) {
2438 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042439 bool spelled_right = RenderThread::current()->spellchecker()->
2440 SpellCheckWord(
2441 params.misspelled_word.c_str(), params.misspelled_word.size(),
2442 document_tag_,
2443 &misspelled_offset, &misspelled_length,
2444 &params.dictionary_suggestions);
2445 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292446 params.misspelled_word.clear();
2447 }
[email protected]db803aae2011-03-05 02:00:422448 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:272449 // it. We replace it with an empty GURL so the appropriate items are disabled
2450 // in the context menu.
2451 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2452 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:422453 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:272454 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102455 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:292456 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442457}
2458
[email protected]52f139e2c2010-06-11 16:56:092459bool RenderView::supportsFullscreen() {
2460 return CommandLine::ForCurrentProcess()->HasSwitch(
2461 switches::kEnableVideoFullscreen);
2462}
2463
2464void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2465 NOTIMPLEMENTED();
2466}
2467
2468void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2469 NOTIMPLEMENTED();
2470}
2471
[email protected]48c9cf2d2009-09-16 16:47:522472void RenderView::setStatusText(const WebString& text) {
2473}
2474
[email protected]163f8242009-10-30 20:19:552475void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582476 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522477 if (latest_url == target_url_)
2478 return;
[email protected]163f8242009-10-30 20:19:552479
[email protected]48c9cf2d2009-09-16 16:47:522480 // Tell the browser to display a destination link.
2481 if (target_url_status_ == TARGET_INFLIGHT ||
2482 target_url_status_ == TARGET_PENDING) {
2483 // If we have a request in-flight, save the URL to be sent when we
2484 // receive an ACK to the in-flight request. We can happily overwrite
2485 // any existing pending sends.
2486 pending_target_url_ = latest_url;
2487 target_url_status_ = TARGET_PENDING;
2488 } else {
2489 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2490 target_url_ = latest_url;
2491 target_url_status_ = TARGET_INFLIGHT;
2492 }
2493}
2494
[email protected]13a1e4c3c2011-02-03 21:07:092495void RenderView::UpdateToggleSpellCheckCommandState() {
2496 bool is_enabled = false;
2497 WebKit::WebNode node = GetFocusedNode();
2498 if (!node.isNull())
2499 is_enabled = IsEditableNode(node);
2500
2501 RenderViewCommandCheckedState checked_state =
2502 RENDER_VIEW_COMMAND_CHECKED_STATE_UNCHECKED;
2503 if (is_enabled && webview()) {
2504 WebFrame* frame = webview()->focusedFrame();
2505 if (frame->isContinuousSpellCheckingEnabled())
2506 checked_state = RENDER_VIEW_COMMAND_CHECKED_STATE_CHECKED;
2507 }
2508
2509 Send(new ViewHostMsg_CommandStateChanged(
2510 routing_id_,
2511 RENDER_VIEW_COMMAND_TOGGLE_SPELL_CHECK,
2512 is_enabled,
2513 checked_state));
2514}
2515
[email protected]882daa92009-11-05 16:31:312516void RenderView::StartNavStateSyncTimerIfNecessary() {
2517 int delay;
2518 if (send_content_state_immediately_)
2519 delay = 0;
2520 else if (is_hidden())
2521 delay = kDelaySecondsForContentStateSyncHidden;
2522 else
2523 delay = kDelaySecondsForContentStateSync;
2524
2525 if (nav_state_sync_timer_.IsRunning()) {
2526 // The timer is already running. If the delay of the timer maches the amount
2527 // we want to delay by, then return. Otherwise stop the timer so that it
2528 // gets started with the right delay.
2529 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2530 return;
2531 nav_state_sync_timer_.Stop();
2532 }
2533
2534 nav_state_sync_timer_.Start(
2535 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2536}
2537
[email protected]163f8242009-10-30 20:19:552538void RenderView::setMouseOverURL(const WebURL& url) {
2539 mouse_over_url_ = GURL(url);
2540 UpdateTargetURL(mouse_over_url_, focus_url_);
2541}
2542
2543void RenderView::setKeyboardFocusURL(const WebURL& url) {
2544 focus_url_ = GURL(url);
2545 UpdateTargetURL(focus_url_, mouse_over_url_);
2546}
2547
[email protected]48c9cf2d2009-09-16 16:47:522548void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2549 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2550 hint));
2551}
2552
[email protected]c27ae592010-03-18 15:24:412553void RenderView::startDragging(const WebDragData& data,
2554 WebDragOperationsMask mask,
2555 const WebImage& image,
2556 const WebPoint& imageOffset) {
2557#if WEBKIT_USING_SKIA
2558 SkBitmap bitmap(image.getSkBitmap());
2559#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332560 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412561#endif
2562
[email protected]48c9cf2d2009-09-16 16:47:522563 Send(new ViewHostMsg_StartDragging(routing_id_,
2564 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412565 mask,
2566 bitmap,
2567 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522568}
2569
[email protected]28b92df2009-09-25 17:35:452570bool RenderView::acceptsLoadDrops() {
2571 return renderer_preferences_.can_accept_load_drops;
2572}
2573
[email protected]48c9cf2d2009-09-16 16:47:522574void RenderView::focusNext() {
2575 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2576}
2577
2578void RenderView::focusPrevious() {
2579 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2580}
2581
[email protected]08e9e132010-06-01 16:58:492582void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512583 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072584
2585 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2586 // TODO(ctguil): Make WebKit send this notification.
2587 // When focus is cleared notify accessibility that the document is focused.
2588 postAccessibilityNotification(
2589 webview()->accessibilityObject(),
2590 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2591 }
[email protected]13a1e4c3c2011-02-03 21:07:092592
2593 UpdateToggleSpellCheckCommandState();
[email protected]08e9e132010-06-01 16:58:492594}
2595
[email protected]48c9cf2d2009-09-16 16:47:522596void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522597 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2598}
2599
2600int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002601 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522602}
2603
2604int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002605 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522606}
2607
[email protected]c4e98902010-06-01 10:20:142608void RenderView::didUpdateInspectorSetting(const WebString& key,
2609 const WebString& value) {
2610 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2611 key.utf8(),
2612 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262613}
2614
[email protected]79dbc662009-09-04 05:42:512615// WebKit::WebWidgetClient ----------------------------------------------------
2616
[email protected]ea42e7782010-08-23 23:58:122617void RenderView::didFocus() {
2618 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2619 // we won't have to test for user gesture anymore and we can
2620 // move that code back to render_widget.cc
2621 if (webview() && webview()->mainFrame() &&
2622 webview()->mainFrame()->isProcessingUserGesture()) {
2623 Send(new ViewHostMsg_Focus(routing_id_));
2624 }
2625}
2626
2627void RenderView::didBlur() {
2628 // TODO(jcivelli): see TODO above in didFocus().
2629 if (webview() && webview()->mainFrame() &&
2630 webview()->mainFrame()->isProcessingUserGesture()) {
2631 Send(new ViewHostMsg_Blur(routing_id_));
2632 }
2633}
2634
initial.commit09911bf2008-07-26 23:55:292635// We are supposed to get a single call to Show for a newly created RenderView
2636// that was created via RenderView::CreateWebView. So, we wait until this
2637// point to dispatch the ShowView message.
2638//
2639// This method provides us with the information about how to display the newly
2640// created RenderView (i.e., as a constrained popup or as a new tab).
2641//
[email protected]4873c7d2009-07-16 06:36:282642void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292643 DCHECK(!did_show_) << "received extraneous Show call";
2644 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2645
2646 if (did_show_)
2647 return;
2648 did_show_ = true;
2649
[email protected]4026ce1e2010-09-14 19:35:042650 // Extensions and apps always allowed to create unrequested popups. The second
2651 // check is necessary to include content scripts.
[email protected]2a521c52011-01-26 18:45:212652 if (render_thread_->GetExtensions()->GetByURL(creator_url_) ||
[email protected]4026ce1e2010-09-14 19:35:042653 bindings_utils::GetInfoForCurrentContext()) {
2654 opened_by_user_gesture_ = true;
2655 }
2656
[email protected]28295ec2009-10-16 05:34:332657 // Force new windows to a popup if they were not opened with a user gesture.
2658 if (!opened_by_user_gesture_) {
2659 // We exempt background tabs for compat with older versions of Chrome.
2660 // TODO(darin): This seems bogus. These should have a user gesture, so
2661 // we probably don't need this check.
2662 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2663 policy = WebKit::WebNavigationPolicyNewPopup;
2664 }
2665
initial.commit09911bf2008-07-26 23:55:292666 // NOTE: initial_pos_ may still have its default values at this point, but
2667 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2668 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282669 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2670 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292671 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242672 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292673}
2674
[email protected]4873c7d2009-07-16 06:36:282675void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292676 DCHECK(did_show_) << "should already have shown the view";
2677
[email protected]c1f50aa2010-02-18 03:46:572678 // We must keep WebKit's shared timer running in this case in order to allow
2679 // showModalDialog to function properly.
2680 //
2681 // TODO(darin): WebKit should really be smarter about suppressing events and
2682 // timers so that we do not need to manage the shared timer in such a heavy
2683 // handed manner.
2684 //
2685 if (RenderThread::current()) // Will be NULL during unit tests.
2686 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2687
[email protected]12636df2009-09-28 22:32:212688 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292689}
2690
[email protected]3d9689372009-09-10 04:29:172691// WebKit::WebFrameClient -----------------------------------------------------
2692
[email protected]00152e92010-07-19 11:47:402693WebPlugin* RenderView::createPlugin(WebFrame* frame,
2694 const WebPluginParams& params) {
[email protected]6fdd4182010-10-14 23:59:262695 bool found = false;
[email protected]414508d2010-11-02 10:45:392696 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
[email protected]55126132010-08-19 14:53:282697 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]191eb3f72010-12-21 06:27:502698 webkit::npapi::WebPluginInfo info;
[email protected]7a13e792010-08-03 08:18:242699 GURL url(params.url);
[email protected]6fdd4182010-10-14 23:59:262700 std::string actual_mime_type;
[email protected]c8f73ab2011-01-22 00:05:172701 Send(new ViewHostMsg_GetPluginInfo(routing_id_,
2702 url,
[email protected]6fdd4182010-10-14 23:59:262703 frame->top()->url(),
2704 params.mimeType.utf8(),
2705 &found,
2706 &info,
[email protected]44fda5c2010-11-02 10:50:542707 &plugin_setting,
[email protected]6fdd4182010-10-14 23:59:262708 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242709
[email protected]6fdd4182010-10-14 23:59:262710 if (!found)
[email protected]0cdafff2010-07-26 09:54:372711 return NULL;
[email protected]414508d2010-11-02 10:45:392712 DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
[email protected]8d91f862011-02-24 13:38:102713 if (!webkit::npapi::IsPluginEnabled(info))
2714 return NULL;
[email protected]4e0616e2010-05-28 14:55:532715
[email protected]191eb3f72010-12-21 06:27:502716 const webkit::npapi::PluginGroup* group =
2717 webkit::npapi::PluginList::Singleton()->GetPluginGroup(info);
[email protected]79ce1032010-12-07 13:29:412718 DCHECK(group != NULL);
[email protected]851b1eb2010-08-09 13:32:292719
[email protected]6e74a3b2010-12-21 22:27:542720 if (group->IsVulnerable() &&
2721 !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) {
[email protected]3c2826852010-12-16 19:09:142722 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2723 group->GetGroupName(),
2724 GURL(group->GetUpdateURL())));
2725 return CreatePluginPlaceholder(frame,
2726 params,
2727 *group,
[email protected]2e34ab3f2010-12-17 05:47:372728 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202729 IDS_PLUGIN_OUTDATED,
2730 false);
[email protected]851b1eb2010-08-09 13:32:292731 }
[email protected]6e74a3b2010-12-21 22:27:542732
[email protected]414508d2010-11-02 10:45:392733 ContentSetting host_setting =
2734 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS];
[email protected]d12dcdd62011-01-27 06:53:252735
2736 if (group->RequiresAuthorization() &&
2737 !cmd->HasSwitch(switches::kAlwaysAuthorizePlugins) &&
2738 (plugin_setting == CONTENT_SETTING_ALLOW ||
2739 plugin_setting == CONTENT_SETTING_ASK) &&
2740 host_setting == CONTENT_SETTING_DEFAULT) {
2741 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2742 group->GetGroupName(),
2743 GURL()));
2744 return CreatePluginPlaceholder(frame,
2745 params,
2746 *group,
2747 IDR_BLOCKED_PLUGIN_HTML,
2748 IDS_PLUGIN_NOT_AUTHORIZED,
2749 false);
2750 }
2751
[email protected]191eb3f72010-12-21 06:27:502752 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName ||
[email protected]414508d2010-11-02 10:45:392753 plugin_setting == CONTENT_SETTING_ALLOW ||
2754 host_setting == CONTENT_SETTING_ALLOW) {
[email protected]987d51af2011-02-24 17:50:182755 // Delay loading plugins if prerendering.
2756 if (is_prerendering_) {
[email protected]90dba072011-01-20 20:10:202757 return CreatePluginPlaceholder(frame,
2758 params,
2759 *group,
2760 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
2761 IDS_PLUGIN_LOAD,
2762 true);
2763 }
2764
[email protected]0bd753682010-12-16 18:15:522765 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:452766 pepper_delegate_.CreatePepperPlugin(info.path));
2767 if (pepper_module)
2768 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]6fdd4182010-10-14 23:59:262769 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]0cdafff2010-07-26 09:54:372770 }
[email protected]fc61e222010-10-11 15:42:142771 std::string resource;
2772 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2773 resource = group->identifier();
2774 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]414508d2010-11-02 10:45:392775 if (plugin_setting == CONTENT_SETTING_ASK) {
[email protected]3c2826852010-12-16 19:09:142776 return CreatePluginPlaceholder(frame,
2777 params,
2778 *group,
[email protected]2e34ab3f2010-12-17 05:47:372779 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202780 IDS_PLUGIN_LOAD,
2781 false);
[email protected]fc61e222010-10-11 15:42:142782 } else {
[email protected]3c2826852010-12-16 19:09:142783 return CreatePluginPlaceholder(frame,
2784 params,
2785 *group,
[email protected]2e34ab3f2010-12-17 05:47:372786 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202787 IDS_PLUGIN_BLOCKED,
2788 false);
[email protected]fc61e222010-10-11 15:42:142789 }
[email protected]3d9689372009-09-10 04:29:172790}
2791
2792WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562793 WebApplicationCacheHostImpl* appcache_host =
2794 WebApplicationCacheHostImpl::FromFrame(frame);
2795 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2796 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2797 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172798}
2799
[email protected]9c00f002009-11-05 22:37:422800WebSharedWorker* RenderView::createSharedWorker(
2801 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372802 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422803
[email protected]30447b62009-11-13 01:13:372804 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512805 bool exists = false;
[email protected]30447b62009-11-13 01:13:372806 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512807 ViewHostMsg_CreateWorker_Params params;
2808 params.url = url;
2809 params.is_shared = true;
2810 params.name = name;
2811 params.document_id = document_id;
2812 params.render_view_route_id = routing_id_;
2813 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232814 params.parent_appcache_host_id = 0;
2815 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372816 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512817 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372818 if (url_mismatch) {
2819 return NULL;
2820 } else {
2821 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492822 document_id,
[email protected]6de0bcf2010-02-17 22:00:512823 exists,
[email protected]30447b62009-11-13 01:13:372824 route_id,
2825 routing_id_);
2826 }
[email protected]9c00f002009-11-05 22:37:422827}
2828
[email protected]3d9689372009-09-10 04:29:172829WebMediaPlayer* RenderView::createMediaPlayer(
2830 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]f78d1dfc2011-01-15 07:09:272831 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
2832 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:492833 scoped_ptr<media::FilterCollection> collection(
2834 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:372835
[email protected]3d9689372009-09-10 04:29:172836 // Add in any custom filter factories first.
2837 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2838 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2839 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:492840 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:172841 }
2842
[email protected]3bb08602010-10-07 21:47:172843 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:122844 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:072845 WebGraphicsContext3DCommandBufferImpl* context =
2846 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2847 frame->view()->graphicsContext3D());
2848 if (!context)
2849 return NULL;
[email protected]a9a43012010-11-05 01:54:062850
[email protected]5aa6a312010-11-06 00:00:072851 // Add the hardware video decoder factory.
2852 // TODO(hclam): This will cause the renderer process to crash on context
2853 // lost.
2854 bool ret = context->makeContextCurrent();
2855 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:492856 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:072857 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:172858 }
2859
[email protected]457d8342010-10-23 01:20:372860 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:312861 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2862 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
2863 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:492864 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:312865 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:112866
[email protected]a8e24d522010-12-01 07:13:582867 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:272868 new webkit_glue::WebMediaPlayerImpl(client,
2869 collection.release(),
2870 message_loop_factory.release()));
[email protected]79684282010-12-06 21:15:462871 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:582872 cmd_line->HasSwitch(switches::kSimpleDataSource),
2873 video_renderer)) {
2874 return NULL;
2875 }
2876 return result.release();
[email protected]3d9689372009-09-10 04:29:172877}
2878
[email protected]035545f2010-04-09 13:10:212879WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2880 WebFrame* frame, WebApplicationCacheHostClient* client) {
2881 return new RendererWebApplicationCacheHostImpl(
2882 FromWebView(frame->view()), client,
2883 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2884}
2885
[email protected]8ff181072010-11-29 17:09:382886WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
2887 return &cookie_jar_;
2888}
2889
[email protected]5041f982010-08-11 21:40:452890void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512891 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452892}
2893
[email protected]3d9689372009-09-10 04:29:172894void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302895 WebDataSource* ds = frame->dataSource();
2896 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522897
[email protected]a5a65ac2010-11-05 18:14:362898 page_load_histograms_.Dump(frame);
[email protected]fa7b6b542009-11-03 05:02:302899 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]f3ce0a32011-01-11 08:18:182900
[email protected]676126f72011-01-15 00:03:512901 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172902}
2903
[email protected]684e4a42010-01-30 06:44:112904bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402905 if (enabled_per_settings &&
2906 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2907 return true;
2908
2909 if (IsWhitelistedForContentSettings(frame))
2910 return true;
2911
[email protected]55126132010-08-19 14:53:282912 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402913 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112914}
2915
[email protected]d5f9e4f2010-07-28 08:31:302916bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]3627b06d2010-11-12 16:36:162917 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
[email protected]d5f9e4f2010-07-28 08:31:302918}
2919
2920
[email protected]3d9689372009-09-10 04:29:172921void RenderView::loadURLExternally(
2922 WebFrame* frame, const WebURLRequest& request,
2923 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592924 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2925 if (policy == WebKit::WebNavigationPolicyDownload) {
2926 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2927 } else {
2928 OpenURL(request.url(), referrer, policy);
2929 }
[email protected]3d9689372009-09-10 04:29:172930}
2931
2932WebNavigationPolicy RenderView::decidePolicyForNavigation(
2933 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222934 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172935 // Webkit is asking whether to navigate to a new URL.
2936 // This is fine normally, except if we're showing UI from one security
2937 // context and they're trying to navigate to a different context.
2938 const GURL& url = request.url();
2939
2940 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302941 // navigations.
[email protected]8079b362010-05-07 18:37:452942 if (renderer_preferences_.browser_handles_top_level_requests &&
2943 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192944 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232945 // Reset these counters as the RenderView could be reused for the next
2946 // navigation.
2947 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232948 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192949 OpenURL(url, referrer, default_policy);
2950 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172951 }
2952
2953 // A content initiated navigation may have originated from a link-click,
2954 // script, drag-n-drop operation, etc.
2955 bool is_content_initiated =
2956 NavigationState::FromDataSource(frame->provisionalDataSource())->
2957 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582958 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172959
[email protected]6101c342010-12-16 22:44:372960 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552961 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572962 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372963 // opening a new window). But we sometimes navigate to about:blank to clear a
2964 // tab, and we want to still allow that.
2965 //
[email protected]8f4da8c2011-02-09 19:49:572966 // Note: we do this only for GET requests because our mechanism for switching
2967 // processes only issues GET requests. In particular, POST requests don't
2968 // work, because this mechanism does not preserve form POST data. If it
2969 // becomes necessary to support process switching for POST requests, we will
2970 // need to send the request's httpBody data up to the browser process, and
2971 // issue a special POST navigation in WebKit (via
2972 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2973 // for examples of how to send the httpBody data.
2974 // Note2: We normally don't do this for browser-initiated navigations, since
2975 // it's pointless to tell the browser about navigations it gave us. But
2976 // we do potentially ask the browser to handle a redirect that was originally
2977 // initiated by the browser. See http://crbug.com/70943
2978 //
2979 // TODO(creis): Move this redirect check to the browser process to avoid
2980 // ping-ponging. See http://crbug.com/72380.
2981 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372982 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2983 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2984 bool send_referrer = false;
2985 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552986 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172987 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372988 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112989
2990 // If the navigation would cross an app extent boundary, we also need
2991 // to defer to the browser to ensure process isolation.
2992 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2993 // which means that things like the back button won't trigger it. Is that
2994 // OK?
[email protected]88c15e972011-02-05 04:19:532995 // TODO(creis): For hosted apps, we currently only swap processes to enter
2996 // the app and not exit it, since we currently lose context (e.g.,
2997 // window.opener) if the window navigates back. See crbug.com/65953.
[email protected]2a521c52011-01-26 18:45:212998 if (!should_fork &&
[email protected]88c15e972011-02-05 04:19:532999 CrossesExtensionExtents(
[email protected]2a521c52011-01-26 18:45:213000 render_thread_->GetExtensions(),
3001 frame,
3002 url)) {
[email protected]5351dbc2010-08-27 15:22:113003 // Include the referrer in this case since we're going from a hosted web
3004 // page. (the packaged case is handled previously by the extension
3005 // navigation test)
[email protected]6101c342010-12-16 22:44:373006 should_fork = true;
3007 send_referrer = true;
[email protected]46fd1ea42011-02-16 15:59:333008
3009 if (is_content_initiated) {
3010 const Extension* extension =
3011 render_thread_->GetExtensions()->GetByURL(url);
3012 if (extension && extension->is_app()) {
3013 UMA_HISTOGRAM_ENUMERATION(
3014 extension_misc::kAppLaunchHistogram,
3015 extension_misc::APP_LAUNCH_CONTENT_NAVIGATION,
3016 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY);
3017 }
3018 }
[email protected]6101c342010-12-16 22:44:373019 }
3020
3021 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:113022 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:373023 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:113024 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3025 }
[email protected]3d9689372009-09-10 04:29:173026 }
3027
3028 // Detect when a page is "forking" a new tab that can be safely rendered in
3029 // its own process. This is done by sites like Gmail that try to open links
3030 // in new windows without script connections back to the original page. We
3031 // treat such cases as browser navigations (in which we will create a new
3032 // renderer for a cross-site navigation), rather than WebKit navigations.
3033 //
3034 // We use the following heuristic to decide whether to fork a new page in its
3035 // own process:
3036 // The parent page must open a new tab to about:blank, set the new tab's
3037 // window.opener to null, and then redirect the tab to a cross-site URL using
3038 // JavaScript.
[email protected]007a848b2009-10-26 15:55:463039 //
3040 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
3041 // (see below).
[email protected]3d9689372009-09-10 04:29:173042 bool is_fork =
3043 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:583044 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173045 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523046 historyBackListCount() < 1 &&
3047 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173048 // The parent page must have set the child's window.opener to null before
3049 // redirecting to the desired URL.
3050 frame->opener() == NULL &&
3051 // Must be a top-level frame.
3052 frame->parent() == NULL &&
3053 // Must not have issued the request from this page.
3054 is_content_initiated &&
3055 // Must be targeted at the current tab.
3056 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3057 // Must be a JavaScript navigation, which appears as "other".
3058 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463059
3060 // Recognize if this navigation is from a link with rel=noreferrer and
3061 // target=_blank attributes, in which case the opener will be suppressed. If
3062 // so, it is safe to load cross-site pages in a separate process, so we
3063 // should let the browser handle it.
3064 bool is_noreferrer_and_blank_target =
3065 // Frame should be top level and not yet navigated.
3066 frame->parent() == NULL &&
3067 frame->url().isEmpty() &&
3068 historyBackListCount() < 1 &&
3069 historyForwardListCount() < 1 &&
3070 // Links with rel=noreferrer will have no Referer field, and their
3071 // resulting frame will have its window.opener suppressed.
3072 // TODO(creis): should add a request.httpReferrer() method to help avoid
3073 // typos on the unusual spelling of Referer.
3074 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
3075 opener_suppressed_ &&
3076 frame->opener() == NULL &&
3077 // Links with target=_blank will have no name.
3078 frame->name().isNull() &&
3079 // Another frame (with a non-empty creator) should have initiated the
3080 // request, targeted at this frame.
3081 !creator_url_.is_empty() &&
3082 is_content_initiated &&
3083 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3084 type == WebKit::WebNavigationTypeOther;
3085
3086 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:173087 // Open the URL via the browser, not via WebKit.
3088 OpenURL(url, GURL(), default_policy);
3089 return WebKit::WebNavigationPolicyIgnore;
3090 }
3091
3092 return default_policy;
3093}
3094
[email protected]6069da8c2009-10-20 20:33:493095bool RenderView::canHandleRequest(
3096 WebFrame* frame, const WebURLRequest& request) {
3097 // We allow WebKit to think that everything can be handled even though
3098 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:343099 return true;
3100}
3101
[email protected]6069da8c2009-10-20 20:33:493102WebURLError RenderView::cannotHandleRequestError(
3103 WebFrame* frame, const WebURLRequest& request) {
3104 NOTREACHED(); // Since we said we can handle all requests.
3105 return WebURLError();
3106}
3107
3108WebURLError RenderView::cancelledError(
3109 WebFrame* frame, const WebURLRequest& request) {
3110 WebURLError error;
3111 error.domain = WebString::fromUTF8(net::kErrorDomain);
3112 error.reason = net::ERR_ABORTED;
3113 error.unreachableURL = request.url();
3114 return error;
[email protected]7b7a7dc2009-10-19 02:23:343115}
3116
3117void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:493118 WebFrame*, const WebURLError&) {
3119 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:343120}
3121
[email protected]90eeddb2010-05-06 21:06:433122void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
3123 const WebKit::WebFormElement& form) {
3124 // Some login forms have onSubmit handlers that put a hash of the password
3125 // into a hidden field and then clear the password. (Issue 28910.)
3126 // This method gets called before any of those handlers run, so save away
3127 // a copy of the password in case it gets lost.
3128 NavigationState* navigation_state =
3129 NavigationState::FromDataSource(frame->dataSource());
3130 navigation_state->set_password_form_data(
3131 PasswordFormDomManager::CreatePasswordForm(form));
3132}
3133
[email protected]979c28b2009-11-07 01:30:483134void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:173135 NavigationState* navigation_state =
3136 NavigationState::FromDataSource(frame->provisionalDataSource());
3137
3138 if (navigation_state->transition_type() == PageTransition::LINK)
3139 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
3140
3141 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:353142 WebSearchableFormData web_searchable_form_data(form);
3143 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
3144 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:213145 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:433146 PasswordForm* password_form_data =
3147 PasswordFormDomManager::CreatePasswordForm(form);
3148 navigation_state->set_password_form_data(password_form_data);
3149
3150 // If the password has been cleared, recover it from the form contents already
3151 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
3152 // opposed to the provisionalDataSource's, which is what we're storing into
3153 // now.)
3154 if (password_form_data && password_form_data->password_value.empty()) {
3155 NavigationState* old_navigation_state =
3156 NavigationState::FromDataSource(frame->dataSource());
3157 if (old_navigation_state) {
3158 PasswordForm* old_form_data = old_navigation_state->password_form_data();
3159 if (old_form_data && old_form_data->action == password_form_data->action)
3160 password_form_data->password_value = old_form_data->password_value;
3161 }
3162 }
[email protected]3d9689372009-09-10 04:29:173163
[email protected]b1438212010-04-03 00:30:593164 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:043165 if (FormManager::WebFormElementToFormData(
[email protected]5af80432010-11-01 01:25:223166 form,
3167 FormManager::REQUIRE_AUTOCOMPLETE,
[email protected]78192082011-01-29 05:43:443168 static_cast<FormManager::ExtractMask>(
3169 FormManager::EXTRACT_VALUE | FormManager::EXTRACT_OPTION_TEXT),
[email protected]5af80432010-11-01 01:25:223170 &form_data)) {
[email protected]19d6e1e82011-01-26 05:08:583171 Send(new AutoFillHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]5af80432010-11-01 01:25:223172 }
[email protected]3d9689372009-09-10 04:29:173173}
3174
3175void RenderView::willPerformClientRedirect(
3176 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3177 double fire_time) {
3178 // Ignore
3179}
3180
3181void RenderView::didCancelClientRedirect(WebFrame* frame) {
3182 // Ignore
3183}
3184
3185void RenderView::didCompleteClientRedirect(
3186 WebFrame* frame, const WebURL& from) {
3187 if (!frame->parent())
3188 completed_client_redirect_src_ = from;
3189}
3190
3191void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]bb461532010-11-26 21:50:233192 // If there are any app-related fetches in progress, they can be cancelled now
3193 // since we have navigated away from the page that created them.
3194 if (!frame->parent()) {
3195 app_icon_fetchers_.clear();
3196 app_definition_fetcher_.reset(NULL);
3197 }
3198
[email protected]3d9689372009-09-10 04:29:173199 // The rest of RenderView assumes that a WebDataSource will always have a
3200 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:483201 bool content_initiated = !pending_navigation_state_.get();
3202 NavigationState* state = content_initiated ?
3203 NavigationState::CreateContentInitiated() :
3204 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:513205
[email protected]8a3125a712010-08-09 18:58:513206 // NavigationState::referred_by_prefetcher_ is true if we are
3207 // navigating from a page that used prefetching using a link on that
3208 // page. We are early enough in the request process here that we
3209 // can still see the NavigationState of the previous page and set
3210 // this value appropriately.
3211 // TODO(gavinp): catch the important case of navigation in a new
3212 // renderer process.
3213 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303214 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523215 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513216 const GURL referrer(
3217 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3218 if (!referrer.is_empty() &&
3219 NavigationState::FromDataSource(
3220 old_frame->dataSource())->was_prefetcher()) {
3221 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
3222 WebDataSource* old_frame_ds = old_frame->dataSource();
3223 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
3224 state->set_was_referred_by_prefetcher(true);
3225 break;
3226 }
3227 }
3228 }
3229 }
3230 }
3231
[email protected]4c1b6f0b2010-02-07 16:38:183232 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523233 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513234 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183235 case WebURLRequest::UseProtocolCachePolicy: // normal load.
3236 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
3237 break;
3238 case WebURLRequest::ReloadIgnoringCacheData: // reload.
3239 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
3240 break;
3241 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
3242 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
3243 break;
3244 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
3245 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
3246 break;
3247 }
3248 }
[email protected]fa7b6b542009-11-03 05:02:303249
[email protected]5792d932011-01-18 20:33:293250 // If this datasource already has a UserScriptIdleScheduler, reuse that one.
3251 // This is for navigations within a page (didNavigateWithinPage). See
3252 // http://code.google.com/p/chromium/issues/detail?id=64093
3253 NavigationState* old_state = NavigationState::FromDataSource(ds);
3254 if (old_state && old_state->user_script_idle_scheduler()) {
3255 state->swap_user_script_idle_scheduler(old_state);
3256 } else {
3257 state->set_user_script_idle_scheduler(
3258 new UserScriptIdleScheduler(this, frame));
3259 }
[email protected]375e8bd2011-02-07 19:15:353260
[email protected]987d51af2011-02-24 17:50:183261 state->set_was_started_as_prerender(is_prerendering_);
[email protected]375e8bd2011-02-07 19:15:353262
[email protected]fa7b6b542009-11-03 05:02:303263 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:173264}
3265
3266void RenderView::didStartProvisionalLoad(WebFrame* frame) {
3267 WebDataSource* ds = frame->provisionalDataSource();
3268 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3269
[email protected]3d9689372009-09-10 04:29:173270 // Update the request time if WebKit has better knowledge of it.
3271 if (navigation_state->request_time().is_null()) {
3272 double event_time = ds->triggeringEventTime();
3273 if (event_time != 0.0)
3274 navigation_state->set_request_time(Time::FromDoubleT(event_time));
3275 }
3276
[email protected]05c8e502010-08-15 15:13:523277 // Start time is only set after request time.
3278 navigation_state->set_start_load_time(Time::Now());
3279
[email protected]3d9689372009-09-10 04:29:173280 bool is_top_most = !frame->parent();
3281 if (is_top_most) {
3282 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133283 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173284
3285 // Make sure redirect tracking state is clear for the new load.
3286 completed_client_redirect_src_ = GURL();
3287 } else if (frame->parent()->isLoading()) {
3288 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003289 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:173290 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
3291 }
3292
[email protected]28685da92011-02-07 21:49:173293 FOR_EACH_OBSERVER(
3294 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
3295
[email protected]3d9689372009-09-10 04:29:173296 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:073297 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173298}
3299
3300void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
3301 if (frame->parent())
3302 return;
3303 // Received a redirect on the main frame.
3304 WebDataSource* data_source = frame->provisionalDataSource();
3305 if (!data_source) {
3306 // Should only be invoked when we have a data source.
3307 NOTREACHED();
3308 return;
3309 }
3310 std::vector<GURL> redirects;
3311 GetRedirectChain(data_source, &redirects);
3312 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:513313 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3314 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:173315 }
3316}
3317
[email protected]40bd6582009-12-04 23:49:513318void RenderView::didFailProvisionalLoad(WebFrame* frame,
3319 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173320 // Notify the browser that we failed a provisional load with an error.
3321 //
3322 // Note: It is important this notification occur before DidStopLoading so the
3323 // SSL manager can react to the provisional load failure before being
3324 // notified the load stopped.
3325 //
3326 WebDataSource* ds = frame->provisionalDataSource();
3327 DCHECK(ds);
3328
3329 const WebURLRequest& failed_request = ds->request();
3330
[email protected]28685da92011-02-07 21:49:173331 FOR_EACH_OBSERVER(
3332 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
3333
[email protected]3d9689372009-09-10 04:29:173334 bool show_repost_interstitial =
3335 (error.reason == net::ERR_CACHE_MISS &&
3336 EqualsASCII(failed_request.httpMethod(), "POST"));
3337 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:073338 routing_id_, frame->identifier(), !frame->parent(), error.reason,
3339 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:173340
3341 // Don't display an error page if this is simply a cancelled load. Aside
3342 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3343 if (error.reason == net::ERR_ABORTED)
3344 return;
3345
3346 // Make sure we never show errors in view source mode.
3347 frame->enableViewSourceMode(false);
3348
3349 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3350
3351 // If this is a failed back/forward/reload navigation, then we need to do a
3352 // 'replace' load. This is necessary to avoid messing up session history.
3353 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3354 // as session history is concerned.
3355 //
3356 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3357 // the page id.
3358 //
3359 bool replace =
3360 navigation_state->pending_page_id() != -1 ||
3361 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
3362
3363 // If we failed on a browser initiated request, then make sure that our error
3364 // page load is regarded as the same browser initiated request.
3365 if (!navigation_state->is_content_initiated()) {
3366 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
3367 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:003368 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:173369 navigation_state->transition_type(),
3370 navigation_state->request_time()));
3371 }
3372
3373 // Provide the user with a more helpful error page?
3374 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3375 return;
3376
3377 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083378 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173379}
3380
3381void RenderView::didReceiveDocumentData(
3382 WebFrame* frame, const char* data, size_t data_len,
3383 bool& prevent_default) {
3384 NavigationState* navigation_state =
3385 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:093386 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:173387}
3388
[email protected]40bd6582009-12-04 23:49:513389void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3390 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:173391 NavigationState* navigation_state =
3392 NavigationState::FromDataSource(frame->dataSource());
3393
3394 navigation_state->set_commit_load_time(Time::Now());
3395 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203396 // When we perform a new navigation, we need to update the last committed
3397 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173398 UpdateSessionHistory(frame);
3399
3400 // We bump our Page ID to correspond with the new session history entry.
3401 page_id_ = next_page_id_++;
3402
[email protected]3cc72b12010-03-18 23:03:003403 // Advance our offset in session history, applying the length limit. There
3404 // is now no forward history.
3405 history_list_offset_++;
3406 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3407 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3408 history_list_length_ = history_list_offset_ + 1;
3409
[email protected]f9f4841b2010-03-20 05:41:423410 MessageLoop::current()->PostDelayedTask(
3411 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303412 page_info_method_factory_.NewRunnableMethod(
3413 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173414 kDelayForForcedCaptureMs);
3415 } else {
3416 // Inspect the navigation_state on this frame to see if the navigation
3417 // corresponds to a session history navigation... Note: |frame| may or
3418 // may not be the toplevel frame, but for the case of capturing session
3419 // history, the first committed frame suffices. We keep track of whether
3420 // we've seen this commit before so that only capture session history once
3421 // per navigation.
3422 //
3423 // Note that we need to check if the page ID changed. In the case of a
3424 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3425 // previous URL and the current page ID, which would be wrong.
3426 if (navigation_state->pending_page_id() != -1 &&
3427 navigation_state->pending_page_id() != page_id_ &&
3428 !navigation_state->request_committed()) {
3429 // This is a successful session history navigation!
3430 UpdateSessionHistory(frame);
3431 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003432
3433 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173434 }
3435 }
3436
[email protected]28685da92011-02-07 21:49:173437 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3438 DidCommitProvisionalLoad(frame, is_new_navigation));
3439
[email protected]3d9689372009-09-10 04:29:173440 // Remember that we've already processed this request, so we don't update
3441 // the session history again. We do this regardless of whether this is
3442 // a session history navigation, because if we attempted a session history
3443 // navigation without valid HistoryItem state, WebCore will think it is a
3444 // new navigation.
3445 navigation_state->set_request_committed(true);
3446
3447 UpdateURL(frame);
3448
3449 // If this committed load was initiated by a client redirect, we're
3450 // at the last stop now, so clear it.
3451 completed_client_redirect_src_ = GURL();
3452
3453 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273454 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173455}
3456
3457void RenderView::didClearWindowObject(WebFrame* frame) {
3458 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3459 BindDOMAutomationController(frame);
[email protected]0d7ae862010-10-01 13:52:453460 GURL frame_url = frame->url();
[email protected]c09163a2011-02-15 00:05:553461 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:253462 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
3463 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:273464 GetWebUIBindings()->set_message_sender(this);
3465 GetWebUIBindings()->set_routing_id(routing_id_);
3466 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173467 }
3468 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463469 GetExternalHostBindings()->set_message_sender(this);
3470 GetExternalHostBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253471 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
[email protected]3d9689372009-09-10 04:29:173472 }
3473}
3474
3475void RenderView::didCreateDocumentElement(WebFrame* frame) {
3476 if (RenderThread::current()) { // Will be NULL during unit tests.
3477 RenderThread::current()->user_script_slave()->InjectScripts(
3478 frame, UserScript::DOCUMENT_START);
3479 }
3480
3481 // Notify the browser about non-blank documents loading in the top frame.
3482 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253483 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273484 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173485 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3486 }
3487}
3488
3489void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3490 UpdateTitle(frame, title);
3491
3492 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273493 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173494}
3495
[email protected]5019ef12010-04-27 17:26:583496void RenderView::didChangeIcons(WebFrame* frame) {
3497 if (!frame->parent()) {
[email protected]d8e74e82011-03-15 19:38:483498 Send(new ViewHostMsg_UpdateFaviconURL(
[email protected]5019ef12010-04-27 17:26:583499 routing_id_,
3500 page_id_,
3501 frame->favIconURL()));
3502 }
3503}
3504
[email protected]3d9689372009-09-10 04:29:173505void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3506 WebDataSource* ds = frame->dataSource();
3507 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3508 DCHECK(navigation_state);
3509 navigation_state->set_finish_document_load_time(Time::Now());
3510
[email protected]622474d2010-11-04 09:21:083511 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173512
[email protected]28685da92011-02-07 21:49:173513 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3514 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173515
3516 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273517 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173518
3519 if (RenderThread::current()) { // Will be NULL during unit tests.
3520 RenderThread::current()->user_script_slave()->InjectScripts(
3521 frame, UserScript::DOCUMENT_END);
3522 }
[email protected]fa7b6b542009-11-03 05:02:303523
[email protected]41f16632010-10-20 01:21:323524 // InjectScripts() can end up creating a new NavigationState if it triggers a
3525 // fragment navigation, so we need to re-fetch it here.
3526 navigation_state = NavigationState::FromDataSource(ds);
[email protected]fa7b6b542009-11-03 05:02:303527 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3528}
3529
3530void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3531 if (RenderThread::current()) { // Will be NULL during unit tests.
3532 RenderThread::current()->user_script_slave()->InjectScripts(
3533 frame, UserScript::DOCUMENT_IDLE);
3534 }
3535
3536 WebFrame* main_frame = webview()->mainFrame();
3537 if (frame == main_frame) {
3538 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203539 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303540 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203541 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303542 pending_code_execution_queue_.pop();
3543 }
3544 }
[email protected]3d9689372009-09-10 04:29:173545}
3546
3547void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083548 if (webview()->mainFrame() == frame) {
3549 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3550 page_id_));
3551 }
[email protected]3d9689372009-09-10 04:29:173552}
3553
3554void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:173555 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:173556}
3557
3558void RenderView::didFinishLoad(WebFrame* frame) {
3559 WebDataSource* ds = frame->dataSource();
3560 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3561 DCHECK(navigation_state);
3562 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303563 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413564
[email protected]676126f72011-01-15 00:03:513565 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173566
3567 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173568}
3569
[email protected]ccbe04e2010-03-17 17:58:433570void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173571 WebFrame* frame, bool is_new_navigation) {
3572 // If this was a reference fragment navigation that we initiated, then we
3573 // could end up having a non-null pending navigation state. We just need to
3574 // update the ExtraData on the datasource so that others who read the
3575 // ExtraData will get the new NavigationState. Similarly, if we did not
3576 // initiate this navigation, then we need to take care to reset any pre-
3577 // existing navigation state to a content-initiated navigation state.
3578 // DidCreateDataSource conveniently takes care of this for us.
3579 didCreateDataSource(frame, frame->dataSource());
3580
[email protected]af15bed2010-08-25 21:12:093581 NavigationState* new_state =
3582 NavigationState::FromDataSource(frame->dataSource());
3583 new_state->set_was_within_same_page(true);
3584
[email protected]3d9689372009-09-10 04:29:173585 didCommitProvisionalLoad(frame, is_new_navigation);
3586
[email protected]26aa0482009-09-30 16:55:273587 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173588}
3589
[email protected]476b6f82009-09-10 21:00:593590void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313591 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593592}
3593
[email protected]3d9689372009-09-10 04:29:173594void RenderView::assignIdentifierToRequest(
3595 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3596 // Ignore
3597}
3598
3599void RenderView::willSendRequest(
3600 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3601 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303602 WebFrame* top_frame = frame->top();
3603 if (!top_frame)
3604 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513605 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3606 WebDataSource* top_data_source = top_frame->dataSource();
3607 WebDataSource* data_source =
3608 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:223609
3610 // If the request is for an extension resource, check whether it should be
3611 // allowed. If not allowed, we reset the URL to something invalid to prevent
3612 // the request and cause an error.
3613 GURL request_url(request.url());
3614 if (request_url.SchemeIs(chrome::kExtensionScheme) &&
3615 !ExtensionResourceRequestPolicy::CanRequestResource(
3616 request_url,
3617 GURL(frame->url()),
3618 render_thread_->GetExtensions())) {
3619 request.setURL(WebURL(GURL("chrome-extension://invalid/")));
3620 }
3621
[email protected]5e369672009-11-03 23:48:303622 if (data_source) {
3623 NavigationState* state = NavigationState::FromDataSource(data_source);
3624 if (state && state->is_cache_policy_override_set())
3625 request.setCachePolicy(state->cache_policy_override());
3626 }
[email protected]8a3125a712010-08-09 18:58:513627
3628 if (top_data_source) {
3629 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3630 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3631 state->set_was_prefetcher(true);
3632 }
3633
[email protected]3d9689372009-09-10 04:29:173634 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133635 request.setHasUserGesture(frame->isProcessingUserGesture());
3636
[email protected]c5bbc2452010-03-08 08:33:503637 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133638 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493639
[email protected]85cc78c2010-05-04 18:30:093640 // Temporary metrics, see site_isolation_metrics.h
3641 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173642}
3643
3644void RenderView::didReceiveResponse(
3645 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493646
[email protected]85cc78c2010-05-04 18:30:093647 // Temporary metrics, see site_isolation_metrics.h
3648 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3649 identifier,
3650 response);
[email protected]fa0a3432010-03-30 16:53:493651
[email protected]3d9689372009-09-10 04:29:173652 // Only do this for responses that correspond to a provisional data source
3653 // of the top-most frame. If we have a provisional data source, then we
3654 // can't have any sub-resources yet, so we know that this response must
3655 // correspond to a frame load.
3656 if (!frame->provisionalDataSource() || frame->parent())
3657 return;
3658
3659 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083660 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173661 if (frame->isViewSourceModeEnabled())
3662 return;
3663
[email protected]65041fa2010-05-21 06:56:533664 NavigationState* navigation_state =
3665 NavigationState::FromDataSource(frame->provisionalDataSource());
3666 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083667 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533668
[email protected]972ebdff2010-06-10 22:59:073669 // Record page load flags.
3670 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3671 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573672 navigation_state->set_was_alternate_protocol_available(
3673 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073674 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083675 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093676 // Whether or not the http status code actually corresponds to an error is
3677 // only checked when the page is done loading, if |use_error_page| is
3678 // still true.
3679 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173680}
3681
3682void RenderView::didFinishResourceLoad(
3683 WebFrame* frame, unsigned identifier) {
3684 NavigationState* navigation_state =
3685 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:093686 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173687 return;
3688
[email protected]06333afe2011-02-24 14:55:093689 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:083690 int http_status_code = navigation_state->http_status_code();
3691 if (http_status_code == 404) {
3692 // On 404s, try a remote search page as a fallback.
3693 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173694
[email protected]3f853a52010-09-13 19:15:083695 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093696 if (error_page_url.is_valid()) {
3697 WebURLError original_error;
3698 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173699
[email protected]06333afe2011-02-24 14:55:093700 navigation_state->set_alt_error_page_fetcher(
3701 new AltErrorPageResourceFetcher(
3702 error_page_url, frame, original_error,
3703 NewCallback(this, &RenderView::AltErrorPageFinished)));
3704 return;
3705 }
3706 }
[email protected]3d9689372009-09-10 04:29:173707
[email protected]06333afe2011-02-24 14:55:093708 // Use an internal error page, if we have one for the status code.
3709 if (LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3710 http_status_code)) {
[email protected]3f853a52010-09-13 19:15:083711 WebURLError error;
3712 error.unreachableURL = frame->url();
3713 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3714 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173715
[email protected]3f853a52010-09-13 19:15:083716 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3717 std::string(), true);
3718 }
[email protected]3d9689372009-09-10 04:29:173719}
3720
3721void RenderView::didFailResourceLoad(
3722 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3723 // Ignore
3724}
3725
3726void RenderView::didLoadResourceFromMemoryCache(
3727 WebFrame* frame, const WebURLRequest& request,
3728 const WebURLResponse& response) {
3729 // Let the browser know we loaded a resource from the memory cache. This
3730 // message is needed to display the correct SSL indicators.
3731 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3732 routing_id_,
3733 request.url(),
[email protected]3d9689372009-09-10 04:29:173734 response.securityInfo()));
3735}
3736
[email protected]6069da8c2009-10-20 20:33:493737void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293738 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3739}
3740
[email protected]92771112011-01-20 00:13:023741void RenderView::didRunInsecureContent(
3742 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293743 Send(new ViewHostMsg_DidRunInsecureContent(
3744 routing_id_,
[email protected]92771112011-01-20 00:13:023745 origin.toString().utf8(),
3746 target));
[email protected]e3d60e5d2009-09-25 21:08:293747}
3748
[email protected]7ea093ba2009-11-03 05:54:593749bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403750 if (enabled_per_settings &&
3751 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3752 return true;
[email protected]7ea093ba2009-11-03 05:54:593753
[email protected]12bc8472010-04-15 07:29:403754 if (IsWhitelistedForContentSettings(frame))
3755 return true;
[email protected]7ea093ba2009-11-03 05:54:593756
3757 return false; // Other protocols fall through here.
3758}
3759
[email protected]0a1a45432010-03-31 08:09:453760bool RenderView::allowDatabase(
3761 WebFrame* frame, const WebString& name, const WebString& display_name,
3762 unsigned long estimated_size) {
3763 WebSecurityOrigin origin = frame->securityOrigin();
3764 if (origin.isEmpty())
3765 return false; // Uninitialized document?
3766
3767 bool result;
[email protected]26a9acf2010-12-13 19:35:053768 if (!Send(new DatabaseHostMsg_Allow(routing_id_,
[email protected]0a1a45432010-03-31 08:09:453769 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3770 return false;
[email protected]9fb83e82010-07-02 18:24:553771 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3772 GURL(origin.toString().utf8()),
3773 name,
3774 display_name,
3775 estimated_size,
3776 !result));
[email protected]0a1a45432010-03-31 08:09:453777 return result;
3778}
[email protected]8934a3b2010-02-25 00:34:003779void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283780 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003781}
3782
[email protected]c21f1d52010-03-04 03:19:433783void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283784 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433785}
3786
[email protected]3d9689372009-09-10 04:29:173787void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3788 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3789}
3790
[email protected]0c882b282009-10-07 17:01:283791void RenderView::didCreateScriptContext(WebFrame* frame) {
3792 EventBindings::HandleContextCreated(frame, false);
3793}
3794
3795void RenderView::didDestroyScriptContext(WebFrame* frame) {
3796 EventBindings::HandleContextDestroyed(frame);
3797}
3798
3799void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3800 EventBindings::HandleContextCreated(frame, true);
3801}
3802
[email protected]af7eb3fb2010-09-23 21:31:063803bool RenderView::allowScriptExtension(WebFrame* frame,
3804 const WebString& extension_name,
3805 int extension_group) {
3806 // NULL in unit tests.
3807 if (!RenderThread::current())
3808 return true;
3809
3810 // Note: we prefer the provisional URL here instead of the document URL
3811 // because we might be currently loading an URL into a blank page.
3812 // See http://code.google.com/p/chromium/issues/detail?id=10924
3813 WebDataSource* ds = frame->provisionalDataSource();
3814 if (!ds)
3815 ds = frame->dataSource();
3816 return RenderThread::current()->AllowScriptExtension(
3817 extension_name.utf8(), ds->request().url(), extension_group);
3818}
3819
[email protected]fc86daa2010-03-30 23:52:533820void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3821 WebFrame* target,
3822 bool cross_origin,
3823 const WebString& property_name,
3824 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103825 // TODO(johnnyg): track the individual properties and repeat event_ids.
[email protected]a5a65ac2010-11-05 18:14:363826 page_load_histograms_.IncrementCrossFramePropertyAccess(cross_origin);
[email protected]ab9eabac2010-03-16 16:54:103827}
3828
[email protected]3d9689372009-09-10 04:29:173829void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143830 CheckPreferredSize();
3831}
3832
3833void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173834 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253835 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173836 // message.
[email protected]705243f2010-05-05 19:58:073837 if (!send_preferred_size_changes_ || !webview())
3838 return;
[email protected]dfca5acf2010-03-22 03:28:433839
[email protected]705243f2010-05-05 19:58:073840 // WebCore likes to tell us things have changed even when they haven't, so
3841 // cache the width and height and only send the IPC message when we're sure
3842 // they're different.
3843 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3844 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533845
3846 // In the presence of zoom, these sizes are still reported as if unzoomed,
3847 // so we need to adjust.
3848 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3849 size.set_width(static_cast<int>(size.width() * zoom_factor));
3850 size.set_height(static_cast<int>(size.height() * zoom_factor));
3851
[email protected]705243f2010-05-05 19:58:073852 if (size == preferred_size_)
3853 return;
[email protected]c27324b2009-11-19 22:44:293854
[email protected]705243f2010-05-05 19:58:073855 preferred_size_ = size;
3856 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3857 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173858}
3859
[email protected]143dcd592009-11-06 21:33:493860void RenderView::didChangeScrollOffset(WebFrame* frame) {
3861 StartNavStateSyncTimerIfNecessary();
3862}
3863
[email protected]8922e1f2009-10-03 05:01:263864void RenderView::reportFindInPageMatchCount(int request_id, int count,
3865 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113866 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3867 if (!count)
3868 active_match_ordinal = 0;
3869
3870 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3871 routing_id_,
3872 request_id,
3873 count,
3874 gfx::Rect(),
3875 active_match_ordinal,
3876 final_update);
3877
[email protected]8922e1f2009-10-03 05:01:263878 // If we have a message that has been queued up, then we should just replace
3879 // it. The ACK from the browser will make sure it gets sent when the browser
3880 // wants it.
3881 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263882 queued_find_reply_message_.reset(msg);
3883 } else {
3884 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113885 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263886 }
3887}
3888
3889void RenderView::reportFindInPageSelection(int request_id,
3890 int active_match_ordinal,
3891 const WebRect& selection_rect) {
3892 // Send the search result over to the browser process.
3893 Send(new ViewHostMsg_Find_Reply(routing_id_,
3894 request_id,
3895 -1,
3896 selection_rect,
3897 active_match_ordinal,
3898 false));
3899}
3900
[email protected]2b06a992010-08-21 05:48:223901void RenderView::openFileSystem(
3902 WebFrame* frame,
3903 WebFileSystem::Type type,
3904 long long size,
[email protected]d275d7a2010-11-03 01:34:493905 bool create,
[email protected]2b06a992010-08-21 05:48:223906 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083907 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223908
3909 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:083910 if (origin.isEmpty()) {
3911 // Uninitialized document?
3912 callbacks->didFail(WebKit::WebFileErrorAbort);
3913 return;
3914 }
[email protected]2b06a992010-08-21 05:48:223915
[email protected]c5a272d2010-09-27 18:37:083916 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3917 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493918 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223919}
3920
[email protected]79dbc662009-09-04 05:42:513921// webkit_glue::WebPluginPageDelegate -----------------------------------------
3922
[email protected]191eb3f72010-12-21 06:27:503923webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533924 const FilePath& file_path,
3925 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593926 if (!PluginChannelHost::IsListening())
3927 return NULL;
3928
[email protected]00c39612010-03-06 02:53:283929 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463930 if (in_process_plugin) {
[email protected]6876dff2010-01-15 19:38:093931#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]e8f7a182011-03-10 00:50:223932 return webkit::npapi::WebPluginDelegateImpl::Create(
3933 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093934#else
[email protected]e8f7a182011-03-10 00:50:223935 NOTIMPLEMENTED();
3936 return NULL;
[email protected]7b6616f2010-01-14 18:07:553937#endif
[email protected]f103ab72009-09-02 17:10:593938 }
3939
[email protected]4e0616e2010-05-28 14:55:533940 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593941}
3942
3943void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033944#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593945 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3946 routing_id(), window));
3947#endif
3948}
3949
3950void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033951#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593952 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3953 routing_id(), window));
3954#endif
3955 CleanupWindowInPluginMoves(window);
3956}
3957
[email protected]191eb3f72010-12-21 06:27:503958void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593959 SchedulePluginMove(move);
3960}
3961
3962void RenderView::DidStartLoadingForPlugin() {
3963 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523964 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593965}
3966
3967void RenderView::DidStopLoadingForPlugin() {
3968 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523969 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593970}
3971
[email protected]b921cfd22010-02-25 16:57:513972WebCookieJar* RenderView::GetCookieJar() {
3973 return &cookie_jar_;
3974}
3975
initial.commit09911bf2008-07-26 23:55:293976void RenderView::SyncNavigationState() {
3977 if (!webview())
3978 return;
3979
[email protected]26aa0482009-09-30 16:55:273980 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173981 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293982 return;
[email protected]ca948a22009-06-25 19:36:173983
3984 Send(new ViewHostMsg_UpdateState(
3985 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293986}
3987
[email protected]b0950a72009-09-29 23:16:173988bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
3989 // Make sure webview was not shut down.
3990 if (!webview())
3991 return false;
3992 // Create an image resource fetcher and assign it with a call back object.
[email protected]bb461532010-11-26 21:50:233993 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
3994 new ImageResourceFetcher(
3995 image_url, webview()->mainFrame(), id, image_size,
3996 NewCallback(this, &RenderView::DidDownloadImage))));
[email protected]b0950a72009-09-29 23:16:173997 return true;
3998}
3999
4000void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:294001 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:174002 // Notify requester of image download status.
[email protected]d8e74e82011-03-15 19:38:484003 Send(new ViewHostMsg_DidDownloadFavicon(routing_id_,
[email protected]51bd36612009-10-20 22:49:474004 fetcher->id(),
4005 fetcher->image_url(),
4006 image.isNull(),
4007 image));
[email protected]bb461532010-11-26 21:50:234008
4009 // Remove the image fetcher from our pending list. We're in the callback from
4010 // ImageResourceFetcher, best to delay deletion.
4011 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin();
4012 iter != image_fetchers_.end(); ++iter) {
4013 if (iter->get() == fetcher) {
4014 iter->release();
4015 image_fetchers_.erase(iter);
4016 break;
4017 }
4018 }
[email protected]b0950a72009-09-29 23:16:174019 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:294020}
4021
[email protected]d8e74e82011-03-15 19:38:484022void RenderView::OnDownloadFavicon(int id,
[email protected]bf5c2ff392009-07-08 16:24:334023 const GURL& image_url,
4024 int image_size) {
[email protected]f11ca0732009-04-11 00:09:344025 bool data_image_failed = false;
4026 if (image_url.SchemeIs("data")) {
4027 SkBitmap data_image = ImageFromDataUrl(image_url);
4028 data_image_failed = data_image.empty();
4029 if (!data_image_failed) {
[email protected]d8e74e82011-03-15 19:38:484030 Send(new ViewHostMsg_DidDownloadFavicon(routing_id_, id, image_url, false,
[email protected]bf5c2ff392009-07-08 16:24:334031 data_image));
[email protected]f11ca0732009-04-11 00:09:344032 }
4033 }
4034
[email protected]bf5c2ff392009-07-08 16:24:334035 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:174036 !DownloadImage(id, image_url, image_size)) {
[email protected]d8e74e82011-03-15 19:38:484037 Send(new ViewHostMsg_DidDownloadFavicon(routing_id_, id, image_url, true,
[email protected]bf5c2ff392009-07-08 16:24:334038 SkBitmap()));
4039 }
initial.commit09911bf2008-07-26 23:55:294040}
4041
[email protected]f11ca0732009-04-11 00:09:344042SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
4043 std::string mime_type, char_set, data;
4044 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
4045 // Decode the favicon using WebKit's image decoder.
[email protected]f23a8c12011-03-15 14:43:434046 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize));
[email protected]f11ca0732009-04-11 00:09:344047 const unsigned char* src_data =
4048 reinterpret_cast<const unsigned char*>(&data[0]);
4049
4050 return decoder.Decode(src_data, data.size());
4051 }
4052 return SkBitmap();
4053}
4054
initial.commit09911bf2008-07-26 23:55:294055void RenderView::OnGetApplicationInfo(int page_id) {
[email protected]38789d82010-11-17 06:03:444056 WebApplicationInfo app_info;
4057 if (page_id == page_id_) {
4058 string16 error;
4059 web_apps::ParseWebAppFromWebDocument(webview()->mainFrame(), &app_info,
4060 &error);
4061 }
initial.commit09911bf2008-07-26 23:55:294062
4063 // Prune out any data URLs in the set of icons. The browser process expects
4064 // any icon with a data URL to have originated from a favicon. We don't want
4065 // to decode arbitrary data URLs in the browser process. See
4066 // http://b/issue?id=1162972
4067 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:594068 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:294069 app_info.icons.erase(app_info.icons.begin() + i);
4070 --i;
4071 }
4072 }
4073
4074 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
4075}
4076
[email protected]7ccddb8c2009-08-04 17:36:554077GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:294078 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554079 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294080 // If the URL that failed was secure, then the embedding web page was not
4081 // expecting a network attacker to be able to manipulate its contents. As
4082 // we fetch alternate error pages over HTTP, we would be allowing a network
4083 // attacker to manipulate the contents of the response if we tried to use
4084 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154085 return GURL();
initial.commit09911bf2008-07-26 23:55:294086 }
4087
4088 // Grab the base URL from the browser process.
4089 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154090 return GURL();
initial.commit09911bf2008-07-26 23:55:294091
4092 // Strip query params from the failed URL.
4093 GURL::Replacements remove_params;
4094 remove_params.ClearUsername();
4095 remove_params.ClearPassword();
4096 remove_params.ClearQuery();
4097 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554098 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504099 std::string spec_to_send = url_to_send.spec();
4100 // Notify link doctor of the url truncation by sending of "?" at the end.
4101 if (failed_url.has_query())
4102 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294103
4104 // Construct the query params to send to link doctor.
4105 std::string params(alternate_error_page_url_.query());
4106 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:504107 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294108 params.append("&sourceid=chrome");
4109 params.append("&error=");
4110 switch (error_type) {
4111 case DNS_ERROR:
4112 params.append("dnserror");
4113 break;
4114
4115 case HTTP_404:
4116 params.append("http404");
4117 break;
4118
[email protected]5df266ac2008-10-15 19:50:134119 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334120 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134121 break;
4122
initial.commit09911bf2008-07-26 23:55:294123 default:
4124 NOTREACHED() << "unknown ErrorPageType";
4125 }
4126
4127 // OK, build the final url to return.
4128 GURL::Replacements link_doctor_params;
4129 link_doctor_params.SetQueryStr(params);
4130 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4131 return url;
4132}
4133
[email protected]c50008512011-02-03 01:17:274134WebUIBindings* RenderView::GetWebUIBindings() {
4135 if (!web_ui_bindings_.get()) {
4136 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:464137 }
[email protected]c50008512011-02-03 01:17:274138 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:464139}
4140
4141ExternalHostBindings* RenderView::GetExternalHostBindings() {
4142 if (!external_host_bindings_.get()) {
4143 external_host_bindings_.reset(new ExternalHostBindings());
4144 }
4145 return external_host_bindings_.get();
4146}
4147
[email protected]0fdbf8c2010-07-08 20:33:014148WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
4149 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494150}
4151
[email protected]6069da8c2009-10-20 20:33:494152void RenderView::OnFind(int request_id, const string16& search_text,
4153 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274154 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494155
4156 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494157 if (options.findNext) {
4158 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014159 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494160 } else {
[email protected]afdbd142010-07-10 08:01:234161 if (GetWebPluginFromPluginDocument()->startFind(
4162 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494163 } else {
[email protected]e7c58a32010-08-13 19:47:114164 // Send "no results".
4165 Send(new ViewHostMsg_Find_Reply(routing_id_,
4166 request_id,
4167 0,
4168 gfx::Rect(),
4169 0,
4170 true));
[email protected]24a7f3c2010-03-25 08:26:494171 }
4172 }
4173 return;
4174 }
4175
[email protected]b4bb2502009-10-01 22:35:274176 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274177 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294178 WebFrame* search_frame = focused_frame; // start searching focused frame.
4179
4180 bool multi_frame = (frame_after_main != main_frame);
4181
4182 // If we have multiple frames, we don't want to wrap the search within the
4183 // frame, so we check here if we only have main_frame in the chain.
4184 bool wrap_within_frame = !multi_frame;
4185
[email protected]b3f2b912009-04-09 16:18:524186 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294187 bool result = false;
4188
[email protected]7830da3e2009-11-06 16:27:264189 // If something is selected when we start searching it means we cannot just
4190 // increment the current match ordinal; we need to re-generate it.
4191 WebRange current_selection = focused_frame->selectionRange();
4192
initial.commit09911bf2008-07-26 23:55:294193 do {
[email protected]dd7daa82009-08-10 05:46:454194 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594195 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294196
4197 if (!result) {
4198 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224199 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294200
4201 // Find the next frame, but skip the invisible ones.
4202 do {
4203 // What is the next frame to search? (we might be going backwards). Note
4204 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594205 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274206 search_frame->traverseNext(true) :
4207 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454208 } while (!search_frame->hasVisibleContent() &&
4209 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294210
[email protected]884db412008-11-24 23:46:504211 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224212 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294213
4214 // If we have multiple frames and we have wrapped back around to the
4215 // focused frame, we need to search it once more allowing wrap within
4216 // the frame, otherwise it will report 'no match' if the focused frame has
4217 // reported matches, but no frames after the focused_frame contain a
4218 // match for the search word(s).
4219 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454220 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594221 request_id, search_text, options, true, // Force wrapping.
4222 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294223 }
4224 }
4225
[email protected]26aa0482009-09-30 16:55:274226 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294227 } while (!result && search_frame != focused_frame);
4228
[email protected]7830da3e2009-11-06 16:27:264229 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294230 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454231 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294232 } else {
4233 // If nothing is found, set result to "0 of 0", otherwise, set it to
4234 // "-1 of 1" to indicate that we found at least one item, but we don't know
4235 // yet what is active.
4236 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4237 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294238
[email protected]4f3dc372009-02-24 00:10:294239 // If we find no matches then this will be our last status update.
4240 // Otherwise the scoping effort will send more results.
4241 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294242
[email protected]4f3dc372009-02-24 00:10:294243 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404244 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594245 request_id,
[email protected]4f3dc372009-02-24 00:10:294246 match_count,
4247 selection_rect,
4248 ordinal,
4249 final_status_update));
initial.commit09911bf2008-07-26 23:55:294250
initial.commit09911bf2008-07-26 23:55:294251 // Scoping effort begins, starting with the mainframe.
4252 search_frame = main_frame;
4253
[email protected]dd7daa82009-08-10 05:46:454254 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294255
4256 do {
4257 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454258 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294259
4260 // We don't start another scoping effort unless at least one match has
4261 // been found.
4262 if (result) {
4263 // Start new scoping request. If the scoping function determines that it
4264 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454265 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594266 search_text,
4267 options,
initial.commit09911bf2008-07-26 23:55:294268 true); // reset the tickmarks
4269 }
4270
4271 // Iterate to the next frame. The frame will not necessarily scope, for
4272 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274273 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294274 } while (search_frame != main_frame);
4275 }
4276}
4277
[email protected]24a7f3c2010-03-25 08:26:494278void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
4279 WebView* view = webview();
4280 if (!view)
4281 return;
4282
4283 WebDocument doc = view->mainFrame()->document();
4284 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014285 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494286 return;
4287 }
4288
4289 bool clear_selection =
4290 params.action == ViewMsg_StopFinding_Params::kClearSelection;
4291 if (clear_selection)
4292 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4293
4294 WebFrame* frame = view->mainFrame();
4295 while (frame) {
4296 frame->stopFinding(clear_selection);
4297 frame = frame->traverseNext(false);
4298 }
4299
4300 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
4301 WebFrame* focused_frame = view->focusedFrame();
4302 if (focused_frame) {
4303 WebDocument doc = focused_frame->document();
4304 if (!doc.isNull()) {
4305 WebNode node = doc.focusedNode();
4306 if (!node.isNull())
4307 node.simulateClick();
4308 }
4309 }
4310 }
4311}
4312
4313void RenderView::OnFindReplyAck() {
4314 // Check if there is any queued up request waiting to be sent.
4315 if (queued_find_reply_message_.get()) {
4316 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424317 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494318 }
4319}
4320
[email protected]8934a3b2010-02-25 00:34:004321bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:354322 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:004323 return current_content_settings_.settings[settings_type] !=
4324 CONTENT_SETTING_BLOCK;
4325}
4326
[email protected]55126132010-08-19 14:53:284327void RenderView::DidBlockContentType(ContentSettingsType settings_type,
4328 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:004329 if (!content_blocked_[settings_type]) {
4330 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:284331 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
4332 resource_identifier));
[email protected]0de80162010-02-03 04:52:354333 }
[email protected]0de80162010-02-03 04:52:354334}
4335
[email protected]71b0d5d2010-02-15 05:43:074336void RenderView::ClearBlockedContentSettings() {
4337 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4338 content_blocked_[i] = false;
4339}
4340
[email protected]0bd753682010-12-16 18:15:524341WebPlugin* RenderView::CreatePepperPlugin(
4342 WebFrame* frame,
4343 const WebPluginParams& params,
4344 const FilePath& path,
4345 webkit::ppapi::PluginModule* pepper_module) {
4346 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:254347 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:094348}
[email protected]00152e92010-07-19 11:47:404349
[email protected]191eb3f72010-12-21 06:27:504350WebPlugin* RenderView::CreateNPAPIPlugin(
4351 WebFrame* frame,
4352 const WebPluginParams& params,
4353 const FilePath& path,
4354 const std::string& mime_type) {
4355 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:084356 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404357}
4358
[email protected]3c2826852010-12-16 19:09:144359WebPlugin* RenderView::CreatePluginPlaceholder(
[email protected]57b66d02010-09-30 11:24:514360 WebFrame* frame,
4361 const WebPluginParams& params,
[email protected]191eb3f72010-12-21 06:27:504362 const webkit::npapi::PluginGroup& group,
[email protected]3c2826852010-12-16 19:09:144363 int resource_id,
[email protected]90dba072011-01-20 20:10:204364 int message_id,
4365 bool is_blocked_for_prerendering) {
[email protected]3c2826852010-12-16 19:09:144366 // |blocked_plugin| will delete itself when the WebViewPlugin
4367 // is destroyed.
4368 BlockedPlugin* blocked_plugin =
4369 new BlockedPlugin(this,
4370 frame,
4371 group,
4372 params,
4373 webkit_preferences_,
4374 resource_id,
[email protected]2e34ab3f2010-12-17 05:47:374375 l10n_util::GetStringFUTF16(message_id,
[email protected]90dba072011-01-20 20:10:204376 group.GetGroupName()),
4377 is_blocked_for_prerendering);
[email protected]3c2826852010-12-16 19:09:144378 return blocked_plugin->plugin();
[email protected]57b66d02010-09-30 11:24:514379}
4380
[email protected]40bd6582009-12-04 23:49:514381void RenderView::OnZoom(PageZoom::Function function) {
4382 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4383 return;
4384
[email protected]258d31122010-05-09 10:59:414385 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524386
[email protected]b75b8292010-10-01 07:28:254387 double old_zoom_level = webview()->zoomLevel();
4388 double zoom_level;
4389 if (function == PageZoom::RESET) {
4390 zoom_level = 0;
4391 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4392 // Previous zoom level is a whole number, so just increment/decrement.
4393 zoom_level = old_zoom_level + function;
4394 } else {
4395 // Either the user hit the zoom factor limit and thus the zoom level is now
4396 // not a whole number, or a plugin changed it to a custom value. We want
4397 // to go to the next whole number so that the user can always get back to
4398 // 100% with the keyboard/menu.
4399 if ((old_zoom_level > 1 && function > 0) ||
4400 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:454401 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:254402 } else {
4403 // We're going towards 100%, so first go to the next whole number.
4404 zoom_level = static_cast<int>(old_zoom_level);
4405 }
4406 }
[email protected]40bd6582009-12-04 23:49:514407
[email protected]b75b8292010-10-01 07:28:254408 webview()->setZoomLevel(false, zoom_level);
4409 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:514410}
4411
[email protected]d0b8d092010-10-25 04:05:174412void RenderView::OnSetZoomLevel(double zoom_level) {
4413 // Don't set zoom level for full-page plugin since they don't use the same
4414 // zoom settings.
4415 if (webview()->mainFrame()->document().isPluginDocument())
4416 return;
4417
4418 webview()->hidePopups();
4419 webview()->setZoomLevel(false, zoom_level);
4420 zoomLevelChanged();
4421}
4422
[email protected]9d797f32010-04-23 07:17:544423void RenderView::OnSetContentSettingsForLoadingURL(
4424 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014425 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544426 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014427}
4428
[email protected]9d797f32010-04-23 07:17:544429void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:254430 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544431 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294432}
4433
[email protected]41fc0322009-09-04 22:23:404434void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274435 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294436}
4437
[email protected]a697f4c2009-09-14 22:30:184438void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274439 WebString no_encoding;
4440 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184441}
4442
[email protected]20ad2692009-11-20 18:27:204443bool RenderView::GetAllChildFrames(
4444 WebFrame* parent_frame,
4445 std::vector<WebFrame*>* frames_vector) const {
4446 if (!parent_frame)
4447 return false;
4448 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4449 child_frame = child_frame->nextSibling()) {
4450 frames_vector->push_back(child_frame);
4451 GetAllChildFrames(child_frame, frames_vector);
4452 }
4453 return true;
4454}
4455
[email protected]dd7daa82009-08-10 05:46:454456WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4457 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274458 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454459
4460 // xpath string can represent a frame deep down the tree (across multiple
4461 // frame DOMs).
4462 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4463 // should break into 2 xpaths
4464 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4465
[email protected]26aa0482009-09-30 16:55:274466 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454467
4468 std::wstring xpath_remaining = xpath;
4469 while (!xpath_remaining.empty()) {
4470 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4471 std::wstring xpath_child;
4472 if (delim_pos != std::wstring::npos) {
4473 xpath_child = xpath_remaining.substr(0, delim_pos);
4474 xpath_remaining.erase(0, delim_pos + 1);
4475 } else {
4476 xpath_remaining.swap(xpath_child);
4477 }
4478 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294479 }
4480
[email protected]dd7daa82009-08-10 05:46:454481 return frame;
initial.commit09911bf2008-07-26 23:55:294482}
4483
[email protected]13a1e4c3c2011-02-03 21:07:094484WebNode RenderView::GetFocusedNode() const {
4485 if (!webview())
4486 return WebNode();
4487 WebFrame* focused_frame = webview()->focusedFrame();
4488 if (focused_frame) {
4489 WebDocument doc = focused_frame->document();
4490 if (!doc.isNull())
4491 return doc.focusedNode();
4492 }
4493
4494 return WebNode();
4495}
4496
[email protected]882b7b22010-10-05 03:34:534497void RenderView::EvaluateScript(const string16& frame_xpath,
4498 const string16& script,
4499 int id,
4500 bool notify_result) {
4501 v8::Handle<v8::Value> result;
4502 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
4503 if (web_frame)
4504 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
4505 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:294506 ListValue list;
4507 if (web_frame) {
4508 v8::HandleScope handle_scope;
4509 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4510 v8::Context::Scope context_scope(context);
4511 list.Set(0, ConvertV8Value(result));
4512 } else {
4513 list.Set(0, Value::CreateNullValue());
4514 }
4515 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:534516 }
initial.commit09911bf2008-07-26 23:55:294517}
4518
[email protected]1810e132009-03-24 23:35:484519void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084520 const std::string& css,
4521 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484522 WebFrame* web_frame = GetChildFrame(frame_xpath);
4523 if (!web_frame)
4524 return;
4525
[email protected]ffaef0c2009-09-15 17:08:084526 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484527}
4528
[email protected]882b7b22010-10-05 03:34:534529void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
4530 const string16& jscript,
4531 int id,
4532 bool notify_result) {
4533 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294534}
4535
[email protected]1810e132009-03-24 23:35:484536void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084537 const std::string& css,
4538 const std::string& id) {
4539 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414540
4541 // Notify RenderViewHost that css has been inserted into the frame.
4542 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484543}
4544
[email protected]7ea066a2009-04-06 20:21:594545void RenderView::OnAddMessageToConsole(
4546 const string16& frame_xpath,
4547 const string16& message,
4548 const WebConsoleMessage::Level& level) {
4549 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594550 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454551 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294552}
4553
[email protected]81e63782009-02-27 19:35:094554void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4555 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294556}
4557
[email protected]d0980792011-02-13 19:41:404558void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:294559 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:554560 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:274561 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294562}
4563
4564void RenderView::OnReservePageIDRange(int size_of_range) {
4565 next_page_id_ += size_of_range + 1;
4566}
4567
[email protected]e80c73b2009-04-07 23:24:584568void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4569 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254570 bool ended,
4571 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034572 if (ended) {
[email protected]26aa0482009-09-30 16:55:274573 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204574 } else {
4575 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034576 }
initial.commit09911bf2008-07-26 23:55:294577}
4578
4579void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274580 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294581}
4582
initial.commit09911bf2008-07-26 23:55:294583void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584584 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254585 const gfx::Point& screen_point,
4586 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274587 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584588 drop_data.ToDragData(),
[email protected]50285ff2011-03-11 23:10:564589 0, // drag identity, unused
[email protected]e80c73b2009-04-07 23:24:584590 client_point,
[email protected]1d9f4132009-09-08 17:29:254591 screen_point,
4592 ops);
initial.commit09911bf2008-07-26 23:55:294593
[email protected]1d9f4132009-09-08 17:29:254594 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294595}
4596
[email protected]e80c73b2009-04-07 23:24:584597void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254598 const gfx::Point& screen_point,
4599 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274600 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254601 client_point,
4602 screen_point,
4603 ops);
initial.commit09911bf2008-07-26 23:55:294604
[email protected]1d9f4132009-09-08 17:29:254605 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294606}
4607
4608void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274609 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294610}
4611
[email protected]e80c73b2009-04-07 23:24:584612void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4613 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274614 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294615}
4616
4617void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594618 webkit_preferences_ = prefs;
4619 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294620}
4621
4622void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4623 alternate_error_page_url_ = url;
4624}
4625
[email protected]b29aa74b2011-01-31 21:41:084626void RenderView::OnCustomContextMenuAction(
4627 const webkit_glue::CustomContextMenuContext& custom_context,
4628 unsigned action) {
4629 if (custom_context.is_pepper_menu)
4630 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4631 else
4632 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:334633}
4634
initial.commit09911bf2008-07-26 23:55:294635void RenderView::OnInstallMissingPlugin() {
4636 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594637 if (first_default_plugin_)
4638 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294639}
4640
[email protected]90dba072011-01-20 20:10:204641void RenderView::OnDisplayPrerenderedPage() {
[email protected]987d51af2011-02-24 17:50:184642 DCHECK(is_prerendering_);
4643 is_prerendering_ = false;
[email protected]90dba072011-01-20 20:10:204644
[email protected]987d51af2011-02-24 17:50:184645 // Update NavigationState for histograms.
4646 WebDataSource* ds = webview()->mainFrame()->dataSource();
4647 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]e0b181752011-02-13 23:56:434648 navigation_state->set_prerendered_page_display_time(Time::Now());
[email protected]987d51af2011-02-24 17:50:184649
4650 // If there is a provisional data source, update its NavigationState, too.
4651 WebDataSource* provisional_ds =
4652 webview()->mainFrame()->provisionalDataSource();
4653 if (provisional_ds) {
4654 NavigationState* provisional_navigation_state =
4655 NavigationState::FromDataSource(provisional_ds);
4656 if (provisional_navigation_state) {
4657 provisional_navigation_state->set_prerendered_page_display_time(
4658 Time::Now());
4659 }
4660 }
[email protected]90dba072011-01-20 20:10:204661}
4662
[email protected]cdaf8d02010-03-30 19:52:474663void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364664 // This could happen if we navigated to a different page before the user
4665 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474666 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364667 return;
4668
[email protected]cdaf8d02010-03-30 19:52:474669 WebVector<WebString> ws_file_names(paths.size());
4670 for (size_t i = 0; i < paths.size(); ++i)
4671 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464672
[email protected]cdaf8d02010-03-30 19:52:474673 if (file_chooser_completions_.front()->completion)
4674 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4675 file_chooser_completions_.pop_front();
4676
4677 // If there are more pending file chooser requests, schedule one now.
4678 if (!file_chooser_completions_.empty()) {
4679 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4680 file_chooser_completions_.front()->params));
4681 }
initial.commit09911bf2008-07-26 23:55:294682}
4683
4684void RenderView::OnEnableViewSourceMode() {
4685 if (!webview())
4686 return;
[email protected]26aa0482009-09-30 16:55:274687 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294688 if (!main_frame)
4689 return;
4690
[email protected]dd7daa82009-08-10 05:46:454691 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294692}
4693
[email protected]770dd8b2010-05-24 18:11:394694void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4695 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244696 if (send_preferred_size_changes_)
4697 return;
[email protected]9fb325e2010-05-06 18:23:244698 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394699
4700 // WebKit doesn't send a notification of the effective height of the page
4701 // changes, so poll for it.
4702 // TODO: Add a notification for this to WebKit, remove polling. After that's
4703 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4704 // http://crbug.com/44850
4705 if (flags & kPreferredSizeHeightThisIsSlow) {
4706 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4707 &RenderView::CheckPreferredSize);
4708 }
[email protected]0666aef2009-05-13 19:48:084709}
4710
[email protected]cda45c02010-02-25 19:28:104711void RenderView::OnDisableScrollbarsForSmallWindows(
4712 const gfx::Size& disable_scrollbar_size_limit) {
4713 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4714}
4715
[email protected]80d96fa2009-06-10 22:34:514716void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4717 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374718 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134719#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414720 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4721 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464722 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]8d1b864d12010-10-10 00:04:344723 gfx::NativeThemeLinux::instance()->SetScrollbarColors(
4724 renderer_prefs.thumb_inactive_color,
4725 renderer_prefs.thumb_active_color,
4726 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324727
[email protected]644d77e2010-01-27 01:03:104728 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324729 webview()->setScrollbarColors(
4730 renderer_prefs.thumb_inactive_color,
4731 renderer_prefs.thumb_active_color,
4732 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104733 webview()->setSelectionColors(
4734 renderer_prefs.active_selection_bg_color,
4735 renderer_prefs.active_selection_fg_color,
4736 renderer_prefs.inactive_selection_bg_color,
4737 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464738 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104739 }
[email protected]7a74e102009-09-03 00:16:564740#endif
[email protected]80d96fa2009-06-10 22:34:514741}
4742
[email protected]952cb702009-10-07 05:50:284743void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4744 const WebMediaPlayerAction& action) {
4745 if (webview())
4746 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564747}
4748
[email protected]7b291f92009-08-14 05:43:534749void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4750 view_type_ = type;
4751}
4752
4753void RenderView::OnUpdateBrowserWindowId(int window_id) {
4754 browser_window_id_ = window_id;
4755}
4756
[email protected]dea2d372010-09-25 06:41:144757void RenderView::OnEnableAccessibility() {
4758 if (WebAccessibilityCache::accessibilityEnabled())
4759 return;
[email protected]9f4db512010-05-10 20:21:414760
[email protected]dea2d372010-09-25 06:41:144761 WebAccessibilityCache::enableAccessibility();
4762
4763 if (webview()) {
4764 // It's possible that the webview has already loaded a webpage without
4765 // accessibility being enabled. Initialize the browser's cached
4766 // accessibility tree by sending it a 'load complete' notification.
4767 postAccessibilityNotification(
4768 webview()->accessibilityObject(),
4769 WebKit::WebAccessibilityNotificationLoadComplete);
4770 }
[email protected]266eb6f2008-09-30 23:56:504771}
4772
[email protected]aef92842010-05-21 16:54:364773void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4774 if (!accessibility_.get())
4775 return;
[email protected]02ea2f312010-09-27 17:03:364776
4777 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4778 WebAccessibilityObject root = webview()->accessibilityObject();
4779 if (!obj.isValid() || !root.isValid())
4780 return;
4781
4782 // By convention, calling SetFocus on the root of the tree should clear the
4783 // current focus. Otherwise set the focus to the new node.
4784 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
4785 webview()->clearFocusedNode();
4786 else
4787 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:364788}
4789
4790void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4791 if (!accessibility_.get())
4792 return;
[email protected]02ea2f312010-09-27 17:03:364793
4794 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4795 if (!obj.isValid())
4796 return;
4797
4798 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:364799}
4800
[email protected]9892b472010-09-16 00:23:424801void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:514802 DCHECK(accessibility_ack_pending_);
4803 accessibility_ack_pending_ = false;
4804 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:314805}
4806
initial.commit09911bf2008-07-26 23:55:294807void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4808 const GURL& page_url) {
4809 // Prepare list to storage all savable resource links.
4810 std::vector<GURL> resources_list;
4811 std::vector<GURL> referrers_list;
4812 std::vector<GURL> frames_list;
4813 webkit_glue::SavableResourcesResult result(&resources_list,
4814 &referrers_list,
4815 &frames_list);
4816
[email protected]dbeb3952009-10-13 18:01:184817 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4818 webview(),
4819 page_url,
4820 &result,
4821 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294822 // If something is wrong when collecting all savable resource links,
4823 // send empty list to embedder(browser) to tell it failed.
4824 referrers_list.clear();
4825 resources_list.clear();
4826 frames_list.clear();
4827 }
4828
4829 // Send result of all savable resource links to embedder.
4830 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4831 resources_list,
4832 referrers_list,
4833 frames_list));
4834}
4835
4836void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324837 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314838 const std::vector<FilePath>& local_paths,
4839 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074840
4841 // Convert std::vector of GURLs to WebVector<WebURL>
4842 WebVector<WebURL> weburl_links(links);
4843
4844 // Convert std::vector of std::strings to WebVector<WebString>
4845 WebVector<WebString> webstring_paths(local_paths.size());
4846 for (size_t i = 0; i < local_paths.size(); i++)
4847 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4848
4849 WebPageSerializer::serialize(webview()->mainFrame(),
4850 true, this, weburl_links, webstring_paths,
4851 webkit_glue::FilePathToWebString(
4852 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294853}
4854
[email protected]d9ec5c0f2009-12-23 11:55:074855void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4856 const WebCString& data,
4857 WebPageSerializerClient::PageSerializationStatus status) {
4858 Send(new ViewHostMsg_SendSerializedHtmlData(
4859 routing_id_,
4860 frame_url,
4861 data.data(),
4862 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294863}
4864
[email protected]9b18a84f2010-06-10 15:54:044865void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274866 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474867 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294868}
4869
[email protected]eb6b87a2009-07-24 15:57:394870void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294871 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4872 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4873 // in the onunload handler from appearing. For now, we're bypassing that and
4874 // calling the FrameLoader's CloseURL method directly. This should be
4875 // revisited to avoid having two ways to close a page. Having a single way
4876 // to close that can run onunload is also useful for fixing
4877 // http://b/issue?id=753080.
[email protected]a5a65ac2010-11-05 18:14:364878 // TODO(davemoore) This code should be removed once willClose() gets
4879 // called when a page is destroyed. page_load_histograms_.Dump() is safe
4880 // to call multiple times for the same frame, but it will simplify things.
4881 page_load_histograms_.Dump(webview()->mainFrame());
4882 page_load_histograms_.ResetCrossFramePropertyAccess();
[email protected]26aa0482009-09-30 16:55:274883 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294884
[email protected]eb6b87a2009-07-24 15:57:394885 // Just echo back the params in the ACK.
4886 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294887}
4888
4889void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574890#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:294891 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464892 if (webview())
4893 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574894#else // defined(OS_WIN)
4895 // TODO(port): we don't support theming on non-Windows platforms yet
4896 NOTIMPLEMENTED();
4897#endif
initial.commit09911bf2008-07-26 23:55:294898}
4899
[email protected]9b18a84f2010-06-10 15:54:044900void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
4901 const std::string& origin,
4902 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:154903 if (message.empty())
4904 return;
[email protected]c091c2c2010-09-17 19:05:464905 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
4906 target);
[email protected]3ac14a052008-08-15 21:22:154907}
4908
[email protected]0aa55312008-10-17 21:53:084909void RenderView::OnDisassociateFromPopupCount() {
4910 if (decrement_shared_popup_at_destruction_)
4911 shared_popup_counter_->data--;
4912 shared_popup_counter_ = new SharedRenderViewCounter(0);
4913 decrement_shared_popup_at_destruction_ = false;
4914}
4915
[email protected]15d79e12009-08-02 19:23:454916bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
4917 const WebURLError& error,
4918 bool replace) {
4919 // We only show alternate error pages in the main frame. They are
4920 // intended to assist the user when navigating, so there is not much
4921 // value in showing them for failed subframes. Ideally, we would be
4922 // able to use the TYPED transition type for this, but that flag is
4923 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454924 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454925 return false;
4926
4927 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374928 // connection failure.
[email protected]15d79e12009-08-02 19:23:454929 int ec = error.reason;
4930 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4931 ec != net::ERR_CONNECTION_FAILED &&
4932 ec != net::ERR_CONNECTION_REFUSED &&
4933 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374934 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454935 return false;
4936
4937 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554938 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454939 if (!error_page_url.is_valid())
4940 return false;
4941
4942 // Load an empty page first so there is an immediate response to the error,
4943 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454944 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364945 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454946 error.unreachableURL,
4947 replace);
4948
4949 // Now, create a fetcher for the error page and associate it with the data
4950 // source we just created via the LoadHTMLString call. That way if another
4951 // navigation occurs, the fetcher will get destroyed.
4952 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:454953 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:454954 navigation_state->set_alt_error_page_fetcher(
4955 new AltErrorPageResourceFetcher(
4956 error_page_url, frame, error,
4957 NewCallback(this, &RenderView::AltErrorPageFinished)));
4958 return true;
4959}
4960
initial.commit09911bf2008-07-26 23:55:294961std::string RenderView::GetAltHTMLForTemplate(
4962 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:394963 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:294964 ResourceBundle::GetSharedInstance().GetRawDataResource(
4965 template_resource_id));
4966
4967 if (template_html.empty()) {
4968 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
4969 return "";
4970 }
[email protected]7cd22a52009-07-14 00:40:254971
initial.commit09911bf2008-07-26 23:55:294972 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:254973 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:294974 template_html, &error_strings, "t");
4975}
[email protected]0e79b9e2009-02-13 04:20:484976
[email protected]15d79e12009-08-02 19:23:454977void RenderView::AltErrorPageFinished(WebFrame* frame,
4978 const WebURLError& original_error,
4979 const std::string& html) {
4980 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094981 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554982 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094983 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454984}
4985
[email protected]30f75e62009-02-25 22:01:004986void RenderView::OnMoveOrResizeStarted() {
4987 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474988 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004989}
4990
[email protected]30f75e62009-02-25 22:01:004991void RenderView::OnResize(const gfx::Size& new_size,
4992 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:104993 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474994 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104995 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204996 webview()->mainFrame()->setCanHaveScrollbars(
4997 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104998 }
4999 }
5000
[email protected]30f75e62009-02-25 22:01:005001 RenderWidget::OnResize(new_size, resizer_rect);
5002}
[email protected]0aa477bd2009-03-23 22:21:435003
[email protected]00c39612010-03-06 02:53:285004void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:015005 // Notify the pepper plugins that we started painting.
5006 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:285007}
5008
5009void RenderView::DidFlushPaint() {
5010 // Notify any pepper plugins that we painted. This will call into the plugin,
5011 // and we it may ask to close itself as a result. This will, in turn, modify
5012 // our set, possibly invalidating the iterator. So we iterate on a copy that
5013 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015014 pepper_delegate_.ViewFlushedPaint();
5015
[email protected]00c39612010-03-06 02:53:285016 WebFrame* main_frame = webview()->mainFrame();
5017
5018 // If we have a provisional frame we are between the start and commit stages
5019 // of loading and we don't want to save stats.
5020 if (!main_frame->provisionalDataSource()) {
5021 WebDataSource* ds = main_frame->dataSource();
5022 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5023 DCHECK(navigation_state);
5024
[email protected]05c8e502010-08-15 15:13:525025 // TODO(jar): The following code should all be inside a method, probably in
5026 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285027 Time now = Time::Now();
5028 if (navigation_state->first_paint_time().is_null()) {
5029 navigation_state->set_first_paint_time(now);
5030 }
5031 if (navigation_state->first_paint_after_load_time().is_null() &&
5032 !navigation_state->finish_load_time().is_null()) {
5033 navigation_state->set_first_paint_after_load_time(now);
5034 }
5035 }
5036}
5037
[email protected]719b36f2010-12-22 20:36:465038webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155039 const gfx::Rect& paint_bounds,
5040 TransportDIB** dib,
5041 gfx::Rect* location,
5042 gfx::Rect* clip) {
5043 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
5044 paint_bounds, dib, location, clip);
5045}
5046
[email protected]bcaf2272011-02-15 15:29:435047gfx::Point RenderView::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:525048 WebKit::WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:435049 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:525050}
5051
[email protected]05d478752009-04-08 23:38:165052void RenderView::OnClearFocusedNode() {
5053 if (webview())
[email protected]26aa0482009-09-30 16:55:275054 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165055}
5056
[email protected]699ab0d2009-04-23 23:19:145057void RenderView::OnSetBackground(const SkBitmap& background) {
5058 if (webview())
[email protected]b4bb2502009-10-01 22:35:275059 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145060
5061 SetBackground(background);
5062}
5063
[email protected]8c66c5a2009-07-22 17:26:345064void RenderView::OnSetActive(bool active) {
5065 if (webview())
[email protected]b4bb2502009-10-01 22:35:275066 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265067
5068#if defined(OS_MACOSX)
5069 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5070 for (plugin_it = plugin_delegates_.begin();
5071 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5072 (*plugin_it)->SetWindowFocus(active);
5073 }
5074#endif
[email protected]8c66c5a2009-07-22 17:26:345075}
5076
[email protected]6ce7abc52010-02-02 18:40:145077#if defined(OS_MACOSX)
5078void RenderView::OnSetWindowVisibility(bool visible) {
5079 // Inform plugins that their container has changed visibility.
5080 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5081 for (plugin_it = plugin_delegates_.begin();
5082 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5083 (*plugin_it)->SetContainerVisibility(visible);
5084 }
5085}
[email protected]1e6e3c992010-02-08 15:52:135086
[email protected]4d51d5bf2010-07-26 18:48:265087void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
5088 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135089 // Inform plugins that their window's frame has changed.
5090 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5091 for (plugin_it = plugin_delegates_.begin();
5092 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5093 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5094 }
5095}
[email protected]935d63d2010-10-15 23:31:555096
[email protected]b7f75862011-01-21 21:15:135097void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:555098 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135099 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555100 // applies to it or not, so inform all the delegates.
5101 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5102 for (plugin_it = plugin_delegates_.begin();
5103 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135104 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555105 }
5106}
[email protected]6ce7abc52010-02-02 18:40:145107#endif // OS_MACOSX
5108
[email protected]8b8e7c92010-08-19 18:05:565109void RenderView::SendExtensionRequest(
5110 const ViewHostMsg_DomMessage_Params& params) {
5111 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:275112}
5113
[email protected]c6619182009-05-12 14:59:325114void RenderView::OnExtensionResponse(int request_id,
5115 bool success,
5116 const std::string& response,
5117 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:355118 ExtensionProcessBindings::HandleResponse(
5119 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:275120}
[email protected]c20210e62009-04-03 21:39:265121
[email protected]a7ab1b782010-10-21 23:24:165122void RenderView::OnExtensionMessageInvoke(const std::string& extension_id,
5123 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:495124 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:195125 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:495126 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:165127 extension_id, function_name, args, this, event_url);
[email protected]7120f132009-07-20 21:05:375128}
5129
[email protected]9892b472010-09-16 00:23:425130void RenderView::postAccessibilityNotification(
5131 const WebAccessibilityObject& obj,
5132 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:145133 if (!accessibility_.get() && webview()) {
5134 // Load complete should be our first notification sent.
5135 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
5136 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
5137 return;
5138
5139 // Create and initialize our accessibility cache
5140 accessibility_.reset(WebAccessibilityCache::create());
5141 accessibility_->initialize(webview());
5142 }
5143
[email protected]a3fa4f92010-09-30 22:19:335144 if (!accessibility_->isCached(obj)) {
5145 // The browser doesn't know about objects that are not in the cache. Send a
5146 // children change for the first accestor that actually is in the cache.
5147 WebAccessibilityObject parent = obj;
5148 while (parent.isValid() && !accessibility_->isCached(parent))
5149 parent = parent.parentObject();
5150
5151 DCHECK(parent.isValid() && accessibility_->isCached(parent));
5152 if (!parent.isValid())
5153 return;
5154 postAccessibilityNotification(
5155 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
5156
5157 // The parent's children change takes care of the child's children change.
5158 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
5159 return;
5160 }
5161
[email protected]dea2d372010-09-25 06:41:145162 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:515163 RendererAccessibilityNotification acc_notification;
5164 acc_notification.id = accessibility_->addOrGetId(obj);
[email protected]a527a022011-02-10 02:32:365165 acc_notification.type = notification;
[email protected]54ec7f82010-10-21 22:32:515166 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:485167 return;
5168
[email protected]a527a022011-02-10 02:32:365169 ViewHostMsg_AccessibilityNotification_Params::NotificationType temp;
5170 if (!WebAccessibilityNotificationToViewHostMsg(notification, &temp))
[email protected]54ec7f82010-10-21 22:32:515171 return;
[email protected]54ec7f82010-10-21 22:32:515172
5173 // Discard duplicate accessibility notifications.
5174 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
5175 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
5176 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:425177 return;
[email protected]54ec7f82010-10-21 22:32:515178 }
[email protected]9892b472010-09-16 00:23:425179 }
[email protected]54ec7f82010-10-21 22:32:515180 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:485181
[email protected]54ec7f82010-10-21 22:32:515182 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
5183 // When no accessibility notifications are in-flight post a task to send
5184 // the notifications to the browser. We use PostTask so that we can queue
5185 // up additional notifications.
5186 MessageLoop::current()->PostTask(
5187 FROM_HERE,
5188 accessibility_method_factory_.NewRunnableMethod(
5189 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:315190 }
[email protected]520cb7d72010-08-31 11:54:315191}
5192
[email protected]446705872009-09-10 07:22:485193void RenderView::OnSetEditCommandsForNextKeyEvent(
5194 const EditCommands& edit_commands) {
5195 edit_commands_ = edit_commands;
5196}
5197
[email protected]61f5a7b2009-12-22 22:21:205198void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275199 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355200 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205201 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5202 false));
[email protected]912256b32009-09-18 09:47:355203 return;
5204 }
5205
[email protected]fa7b6b542009-11-03 05:02:305206 WebDataSource* ds = main_frame->dataSource();
5207 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5208 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205209 pending_code_execution_queue_.push(
5210 linked_ptr<ViewMsg_ExecuteCode_Params>(
5211 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305212 return;
5213 }
5214
[email protected]61f5a7b2009-12-22 22:21:205215 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305216}
5217
5218void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205219 const ViewMsg_ExecuteCode_Params& params) {
[email protected]20ad2692009-11-20 18:27:205220 std::vector<WebFrame*> frame_vector;
5221 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205222 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205223 GetAllChildFrames(frame, &frame_vector);
5224
5225 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5226 frame_it != frame_vector.end(); ++frame_it) {
5227 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205228 if (params.is_javascript) {
[email protected]2a521c52011-01-26 18:45:215229 const Extension* extension =
5230 render_thread_->GetExtensions()->GetByID(params.extension_id);
[email protected]be7e5cb2010-10-04 12:53:175231
[email protected]1f6228c2010-10-21 03:19:445232 // Since extension info is sent separately from user script info, they can
5233 // be out of sync. We just ignore this situation.
5234 if (!extension)
5235 continue;
5236
[email protected]2a521c52011-01-26 18:45:215237 if (!extension->CanExecuteScriptOnPage(frame->url(), NULL, NULL))
[email protected]61f5a7b2009-12-22 22:21:205238 continue;
5239
[email protected]20ad2692009-11-20 18:27:205240 std::vector<WebScriptSource> sources;
5241 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205242 WebScriptSource(WebString::fromUTF8(params.code)));
5243 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205244 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205245 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205246 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5247 } else {
[email protected]61f5a7b2009-12-22 22:21:205248 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205249 }
[email protected]912256b32009-09-18 09:47:355250 }
5251
[email protected]61f5a7b2009-12-22 22:21:205252 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355253}
5254
[email protected]60c42a8c72009-10-09 04:08:595255void RenderView::Close() {
5256 // We need to grab a pointer to the doomed WebView before we destroy it.
5257 WebView* doomed = webview();
5258 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495259 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595260}
5261
[email protected]446705872009-09-10 07:22:485262void RenderView::DidHandleKeyEvent() {
5263 edit_commands_.clear();
5264}
5265
[email protected]6a8ddba52010-09-05 04:38:065266void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515267 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065268}
5269
[email protected]941e4552010-02-01 21:23:435270void RenderView::OnWasHidden() {
5271 RenderWidget::OnWasHidden();
5272
[email protected]a6939ca42011-02-18 17:58:075273 if (webview()) {
5274 webview()->settings()->setMinimumTimerInterval(
5275 webkit_glue::kBackgroundTabTimerInterval);
5276 }
5277
5278#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:435279 // Inform plugins that their container is no longer visible.
5280 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5281 for (plugin_it = plugin_delegates_.begin();
5282 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5283 (*plugin_it)->SetContainerVisibility(false);
5284 }
[email protected]a6939ca42011-02-18 17:58:075285#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:435286}
5287
5288void RenderView::OnWasRestored(bool needs_repainting) {
5289 RenderWidget::OnWasRestored(needs_repainting);
5290
[email protected]a6939ca42011-02-18 17:58:075291 if (webview()) {
5292 webview()->settings()->setMinimumTimerInterval(
5293 webkit_glue::kForegroundTabTimerInterval);
5294 }
5295
5296#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:435297 // Inform plugins that their container is now visible.
5298 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5299 for (plugin_it = plugin_delegates_.begin();
5300 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5301 (*plugin_it)->SetContainerVisibility(true);
5302 }
[email protected]784ea1ab2010-09-18 00:02:345303#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:075304}
[email protected]1e6e3c992010-02-08 15:52:135305
5306void RenderView::OnSetFocus(bool enable) {
5307 RenderWidget::OnSetFocus(enable);
5308
[email protected]7d3c02c2010-05-05 23:10:315309 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075310 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135311 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5312 for (plugin_it = plugin_delegates_.begin();
5313 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345314#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315315 // RenderWidget's call to setFocus can cause the underlying webview's
5316 // activation state to change just like a call to setIsActive.
5317 if (enable)
5318 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345319#endif
[email protected]7d3c02c2010-05-05 23:10:315320 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135321 }
[email protected]589621b2010-09-23 22:01:075322
5323 // Notify all Pepper plugins.
5324 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135325 }
5326}
[email protected]941e4552010-02-01 21:23:435327
[email protected]83dde542009-09-11 20:59:555328void RenderView::EnsureDocumentTag() {
5329 // TODO(darin): There's actually no reason for this to be here. We should
5330 // have the browser side manage the document tag.
5331#if defined(OS_MACOSX)
5332 if (!has_document_tag_) {
5333 // Make the call to get the tag.
5334 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5335 has_document_tag_ = true;
5336 }
5337#endif
5338}
[email protected]12636df2009-09-28 22:32:215339
[email protected]43f28f832010-02-03 02:28:485340#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:135341void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
5342 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
5343 focused, plugin_id);
5344 Send(msg);
5345}
5346
5347void RenderView::StartPluginIme() {
5348 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555349 // This message can be sent during event-handling, and needs to be delivered
5350 // within that context.
5351 msg->set_unblock(true);
5352 Send(msg);
5353}
5354
[email protected]ea04a4e12010-04-15 00:58:035355gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235356 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485357 gfx::PluginWindowHandle window = NULL;
5358 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235359 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115360 if (window) {
5361 fake_plugin_window_handles_.insert(window);
5362 }
[email protected]43f28f832010-02-03 02:28:485363 return window;
5364}
5365
5366void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115367 if (window && fake_plugin_window_handles_.find(window) !=
5368 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485369 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115370 fake_plugin_window_handles_.erase(window);
5371 }
[email protected]43f28f832010-02-03 02:28:485372}
5373
[email protected]44ce0b12010-03-12 16:45:335374void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5375 int32 width,
5376 int32 height,
5377 uint64 io_surface_identifier) {
5378 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485379 routing_id(), window, width, height, io_surface_identifier));
5380}
5381
[email protected]44ce0b12010-03-12 16:45:335382void RenderView::AcceleratedSurfaceSetTransportDIB(
5383 gfx::PluginWindowHandle window,
5384 int32 width,
5385 int32 height,
5386 TransportDIB::Handle transport_dib) {
5387 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075388 routing_id(), window, width, height, transport_dib));
5389}
5390
[email protected]44ce0b12010-03-12 16:45:335391TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5392 size_t size) {
[email protected]1aef98132010-02-23 18:00:075393 TransportDIB::Handle dib_handle;
5394 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385395 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075396 return dib_handle;
5397 // Return an invalid handle if Send() fails.
5398 return TransportDIB::DefaultHandleValue();
5399}
5400
[email protected]44ce0b12010-03-12 16:45:335401void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075402 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5403}
5404
[email protected]44ce0b12010-03-12 16:45:335405void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:145406 gfx::PluginWindowHandle window, uint64 surface_id) {
5407 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
5408 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:485409}
5410#endif
[email protected]58c321d2010-02-19 12:11:285411
[email protected]cdaf8d02010-03-30 19:52:475412bool RenderView::ScheduleFileChooser(
5413 const ViewHostMsg_RunFileChooser_Params& params,
5414 WebFileChooserCompletion* completion) {
5415 static const size_t kMaximumPendingFileChooseRequests = 4;
5416 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5417 // This sanity check prevents too many file choose requests from getting
5418 // queued which could DoS the user. Getting these is most likely a
5419 // programming error (there are many ways to DoS the user so it's not
5420 // considered a "real" security check), either in JS requesting many file
5421 // choosers to pop up, or in a plugin.
5422 //
5423 // TODO(brettw) we might possibly want to require a user gesture to open
5424 // a file picker, which will address this issue in a better way.
5425 return false;
5426 }
5427
5428 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5429 new PendingFileChooser(params, completion)));
5430 if (file_chooser_completions_.size() == 1) {
5431 // Actually show the browse dialog when this is the first request.
5432 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5433 }
5434 return true;
5435}
5436
[email protected]290838a2010-04-27 17:37:015437void RenderView::OnPageTranslated() {
5438 WebFrame* frame = webview()->mainFrame();
5439 if (!frame)
5440 return;
5441
[email protected]676126f72011-01-15 00:03:515442 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameTranslated(frame));
[email protected]290838a2010-04-27 17:37:015443}
5444
[email protected]0ff0ff32010-12-21 19:34:425445WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515446 if (!geolocation_dispatcher_)
5447 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5448 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255449}
[email protected]61c9f032010-03-31 23:04:195450
[email protected]638694c2010-08-04 22:24:115451WebKit::WebSpeechInputController* RenderView::speechInputController(
5452 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:515453 if (!speech_input_dispatcher_)
5454 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
5455 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:115456}
5457
[email protected]57ead352010-08-11 14:42:535458WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515459 if (!device_orientation_dispatcher_)
5460 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5461 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535462}
5463
[email protected]b75b8292010-10-01 07:28:255464void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
5465 // For now, don't remember plugin zoom values. We don't want to mix them with
5466 // normal web content (i.e. a fixed layout plugin would usually want them
5467 // different).
5468 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5469
[email protected]b75b8292010-10-01 07:28:255470 int minimum_percent = static_cast<int>(
5471 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5472 int maximum_percent = static_cast<int>(
5473 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255474
5475 Send(new ViewHostMsg_UpdateZoomLimits(
5476 routing_id_, minimum_percent, maximum_percent, remember));
5477}
5478
5479void RenderView::zoomLevelChanged() {
5480 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5481
[email protected]b75b8292010-10-01 07:28:255482 // Tell the browser which url got zoomed so it can update the menu and the
5483 // saved values if necessary
5484 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:415485 routing_id_, webview()->zoomLevel(), remember,
5486 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:255487}
5488
[email protected]a6d36cc2011-02-23 00:39:485489void RenderView::registerProtocolHandler(const WebString& scheme,
5490 const WebString& base_url,
5491 const WebString& url,
5492 const WebString& title) {
5493 GURL base(base_url);
5494 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
5495 if (base.GetOrigin() != absolute_url.GetOrigin()) {
5496 return;
5497 }
5498 RenderThread::current()->Send(
5499 new ViewHostMsg_RegisterProtocolHandler(routing_id_,
5500 UTF16ToUTF8(scheme),
5501 absolute_url,
5502 title));
5503}
5504
[email protected]8079b362010-05-07 18:37:455505bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195506 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455507 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195508 if (frame->parent() != NULL)
5509 return false;
5510
[email protected]f0a3d0b2010-08-06 22:51:535511 // Navigations initiated within Webkit are not sent out to the external host
5512 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275513 // 1. The url scheme is not http/https
5514 // 2. There is no opener and this is not the first url being opened by this
5515 // RenderView.
5516 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535517 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535518 // 4. Reloads/form submits/back forward navigations
5519 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5520 return false;
5521
[email protected]2fc22d12010-12-02 23:08:165522 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325523 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015524 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165525 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015526 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325527 // The opener relationship between the new window and the parent allows the
5528 // new window to script the parent and vice versa. This is not allowed if
5529 // the origins of the two domains are different. This can be treated as a
5530 // top level navigation and routed back to the host.
5531 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275532 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475533 // Force link click navigations to always be routed to the host as they
5534 // may update session state on the server.
5535 if (type == WebKit::WebNavigationTypeLinkClicked)
5536 return true;
[email protected]900eb2f12010-08-23 22:36:275537 // If this is the first page being loaded by this RenderView instance then
5538 // it should stay here.
5539 if (page_id_ == -1) {
5540 return false;
5541 } else {
[email protected]d0ed50d2010-06-22 01:01:325542 return true;
[email protected]900eb2f12010-08-23 22:36:275543 }
[email protected]d0ed50d2010-06-22 01:01:325544 }
[email protected]900eb2f12010-08-23 22:36:275545
5546 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5547 return true;
[email protected]d0ed50d2010-06-22 01:01:325548 }
[email protected]61c9f032010-03-31 23:04:195549 return false;
5550}
[email protected]2b06a992010-08-21 05:48:225551
[email protected]27a9ef32010-09-10 04:06:245552void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5553 IPC::PlatformFileForTransit file_for_transit,
5554 int message_id) {
5555 pepper_delegate_.OnAsyncFileOpened(
5556 error_code,
5557 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5558 message_id);
5559}
[email protected]caf706f2010-10-26 17:54:085560
5561#if defined(OS_MACOSX)
5562void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155563 if (external_popup_menu_ == NULL) {
5564 // Crash reports from the field indicate that we can be notified with a
5565 // NULL external popup menu (we probably get notified twice).
5566 // If you hit this please file a bug against jcivelli and include the page
5567 // and steps to repro.
5568 NOTREACHED();
5569 return;
5570 }
[email protected]caf706f2010-10-26 17:54:085571 external_popup_menu_->DidSelectItem(selected_index);
5572 external_popup_menu_.reset();
5573}
5574#endif
[email protected]bb461532010-11-26 21:50:235575
5576void RenderView::AddErrorToRootConsole(const string16& message) {
5577 if (webview() && webview()->mainFrame()) {
5578 webview()->mainFrame()->addMessageToConsole(
5579 WebConsoleMessage(WebConsoleMessage::LevelError, message));
5580 }
5581}
[email protected]1b4209f2011-01-07 00:25:405582
5583#if defined(ENABLE_FLAPPER_HACKS)
5584void RenderView::OnConnectTcpACK(
5585 int request_id,
5586 IPC::PlatformFileForTransit socket_for_transit,
5587 const PP_Flash_NetAddress& local_addr,
5588 const PP_Flash_NetAddress& remote_addr) {
5589 pepper_delegate_.OnConnectTcpACK(
5590 request_id,
5591 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5592 local_addr,
5593 remote_addr);
5594}
5595#endif
[email protected]a6097f42011-01-10 08:50:515596
5597void RenderView::OnJavaScriptStressTestControl(int cmd, int param) {
5598 if (cmd == kJavaScriptStressTestSetStressRunType) {
5599 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5600 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5601 v8::Testing::PrepareStressRun(param);
5602 }
5603}
[email protected]521b2482011-01-15 00:10:105604
[email protected]b29aa74b2011-01-31 21:41:085605void RenderView::OnContextMenuClosed(
5606 const webkit_glue::CustomContextMenuContext& custom_context) {
5607 if (custom_context.is_pepper_menu)
5608 pepper_delegate_.OnContextMenuClosed(custom_context);
5609 else
5610 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105611}
[email protected]232a5812011-03-04 22:42:085612
5613void RenderView::OnNetworkStateChanged(bool online) {
5614 WebNetworkStateNotifier::setOnLine(online);
5615}