blob: 5dd33599af9d17b83fbe1a07271df31691935b49 [file] [log] [blame]
[email protected]810a52ef2010-01-08 01:22:151// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
[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]57b66d02010-09-30 11:24:5112#include "app/l10n_util.h"
[email protected]6fdd4182010-10-14 23:59:2613#include "app/message_box_flags.h"
[email protected]9929da92009-05-05 02:05:1114#include "app/resource_bundle.h"
[email protected]2041cf342010-02-19 03:15:5915#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2916#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5017#include "base/compiler_specific.h"
[email protected]625332e02010-12-14 07:48:4918#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2820#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_piece.h"
23#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2824#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2625#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2226#include "base/utf_string_conversions.h"
[email protected]6c8afae52009-01-22 02:24:5727#include "build/build_config.h"
[email protected]035545f2010-04-09 13:10:2128#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0929#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5530#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1731#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2832#include "chrome/common/chrome_paths.h"
33#include "chrome/common/chrome_switches.h"
[email protected]26a9acf2010-12-13 19:35:0534#include "chrome/common/database_messages.h"
[email protected]a0cf04a2010-06-23 03:29:5535#include "chrome/common/extensions/extension.h"
[email protected]c5a272d2010-09-27 18:37:0836#include "chrome/common/file_system/file_system_dispatcher.h"
37#include "chrome/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]bb461532010-11-26 21:50:2338#include "chrome/common/json_value_serializer.h"
initial.commit09911bf2008-07-26 23:55:2939#include "chrome/common/jstemplate_builder.h"
[email protected]97c5c592010-08-03 08:22:2140#include "chrome/common/notification_service.h"
[email protected]630e26b2008-10-14 22:55:1741#include "chrome/common/page_zoom.h"
[email protected]4e0616e2010-05-28 14:55:5342#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2943#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2644#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2945#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5946#include "chrome/common/url_constants.h"
[email protected]38789d82010-11-17 06:03:4447#include "chrome/common/web_apps.h"
[email protected]534c66c2010-04-28 22:53:1148#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2949#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2550#include "chrome/renderer/audio_message_filter.h"
[email protected]6a8ddba52010-09-05 04:38:0651#include "chrome/renderer/autofill_helper.h"
[email protected]2f979172010-09-16 21:54:0352#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]00152e92010-07-19 11:47:4053#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5354#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1155#include "chrome/renderer/devtools_agent.h"
56#include "chrome/renderer/devtools_client.h"
[email protected]2f979172010-09-16 21:54:0357#include "chrome/renderer/dom_ui_bindings.h"
[email protected]912256b32009-09-18 09:47:3558#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0459#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]f816c012009-06-26 21:48:3260#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3561#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]6fdd4182010-10-14 23:59:2662#include "chrome/renderer/extensions/extension_renderer_info.h"
[email protected]7120f132009-07-20 21:05:3763#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0364#include "chrome/renderer/external_host_bindings.h"
[email protected]caf706f2010-10-26 17:54:0865#include "chrome/renderer/external_popup_menu.h"
[email protected]ffd0abd2010-12-14 17:45:5066#if ENABLE_CLIENT_BASED_GEOLOCATION
67#include "chrome/renderer/geolocation_dispatcher.h"
68#else
[email protected]ecad7762010-10-22 13:58:4869#include "chrome/renderer/geolocation_dispatcher_old.h"
[email protected]ffd0abd2010-12-14 17:45:5070#endif
[email protected]3bb08602010-10-07 21:47:1771#include "chrome/renderer/ggl/ggl.h"
[email protected]90109412010-12-15 17:14:2472#include "chrome/renderer/load_progress_tracker.h"
initial.commit09911bf2008-07-26 23:55:2973#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5674#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4175#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]ed3fb032009-06-16 19:50:5676#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1277#include "chrome/renderer/notification_provider.h"
[email protected]6a8ddba52010-09-05 04:38:0678#include "chrome/renderer/page_click_tracker.h"
[email protected]a5a65ac2010-11-05 18:14:3679#include "chrome/renderer/page_load_histograms.h"
[email protected]6a8ddba52010-09-05 04:38:0680#include "chrome/renderer/password_autocomplete_manager.h"
[email protected]8beff0762009-09-29 02:18:3081#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5082#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2583#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2884#include "chrome/renderer/render_thread.h"
[email protected]4d51d5bf2010-07-26 18:48:2685#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1886#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]79c7bed2010-09-14 22:28:3987#include "chrome/renderer/render_widget_fullscreen_pepper.h"
[email protected]035545f2010-04-09 13:10:2188#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3489#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]3ead1322010-11-19 20:01:0090#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
[email protected]ce833282010-11-04 15:48:3991#include "chrome/renderer/searchbox_extension.h"
[email protected]638694c2010-08-04 22:24:1192#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4693#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]25e18f82010-10-27 16:38:4394#include "chrome/renderer/user_script_idle_scheduler.h"
[email protected]0938d3c2009-01-09 20:37:3595#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2996#include "chrome/renderer/visitedlink_slave.h"
[email protected]5aa6a312010-11-06 00:00:0797#include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h"
[email protected]d439ba072009-10-17 22:32:2998#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2999#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:42100#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:56101#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:15102#include "gfx/color_utils.h"
103#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:57104#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:26105#include "gfx/point.h"
106#include "gfx/rect.h"
[email protected]82afe4b2010-11-12 20:36:22107#include "gfx/skbitmap_operations.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]f11ca0732009-04-11 00:09:34112#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29113#include "net/base/escape.h"
114#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04115#include "net/http/http_util.h"
[email protected]c399a8a2008-11-22 19:38:00116#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:10117#include "skia/ext/image_operations.h"
[email protected]418ed5ab2009-11-12 01:14:49118#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
[email protected]4d51d5bf2010-07-26 18:48:26119#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]d9ec5c0f2009-12-23 11:55:07120#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
[email protected]418ed5ab2009-11-12 01:14:49121#include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
122#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
[email protected]0bedb8a2010-01-14 19:36:32123#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
[email protected]418ed5ab2009-11-12 01:14:49124#include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
[email protected]9b66f34bf2010-10-27 20:45:51125#include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
[email protected]01178b52010-01-15 06:59:35126#include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]2b06a992010-08-21 05:48:22127#include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
128#include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
[email protected]6fdd4182010-10-14 23:59:26129#include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
[email protected]b1438212010-04-03 00:30:59130#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
[email protected]418ed5ab2009-11-12 01:14:49131#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
132#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
[email protected]3bb08602010-10-07 21:47:17133#include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h"
[email protected]418ed5ab2009-11-12 01:14:49134#include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
[email protected]c27ae592010-03-18 15:24:41135#include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
[email protected]e6efd022010-03-31 09:34:50136#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
[email protected]418ed5ab2009-11-12 01:14:49137#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
[email protected]0bedb8a2010-01-14 19:36:32138#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
[email protected]d9ec5c0f2009-12-23 11:55:07139#include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h"
[email protected]24a7f3c2010-03-25 08:26:49140#include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h"
[email protected]00152e92010-07-19 11:47:40141#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
[email protected]24a7f3c2010-03-25 08:26:49142#include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h"
[email protected]6fdd4182010-10-14 23:59:26143#include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
[email protected]418ed5ab2009-11-12 01:14:49144#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
145#include "third_party/WebKit/WebKit/chromium/public/WebRange.h"
146#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
147#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
148#include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h"
149#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]00152e92010-07-19 11:47:40150#include "third_party/WebKit/WebKit/chromium/public/WebSettings.h"
[email protected]418ed5ab2009-11-12 01:14:49151#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
[email protected]bd92c3a2010-01-13 05:02:34152#include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]418ed5ab2009-11-12 01:14:49153#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
154#include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
155#include "third_party/WebKit/WebKit/chromium/public/WebURLError.h"
156#include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h"
157#include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h"
158#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
[email protected]4d51d5bf2010-07-26 18:48:26159#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]534c66c2010-04-28 22:53:11160#include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26161#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
162#include "third_party/skia/include/core/SkBitmap.h"
[email protected]882b7b22010-10-05 03:34:53163#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04164#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43165#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24166#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29167#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59168#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24169#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24170#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34171#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26172#include "webkit/glue/image_resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09173#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26174#include "webkit/glue/password_form_dom_manager.h"
[email protected]bb461532010-11-26 21:50:23175#include "webkit/glue/resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09176#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24177#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29178#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29179#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17180#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50181#include "webkit/plugins/npapi/default_plugin_shared.h"
182#include "webkit/plugins/npapi/plugin_list.h"
183#include "webkit/plugins/npapi/webplugin_delegate.h"
184#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
185#include "webkit/plugins/npapi/webplugin_impl.h"
186#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52187#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29188
[email protected]6c8afae52009-01-22 02:24:57189#if defined(OS_WIN)
190// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57191// * theming
[email protected]cd818412010-03-19 03:23:15192#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03193#elif defined(USE_X11)
[email protected]8d1b864d12010-10-10 00:04:34194#include "gfx/native_theme_linux.h"
[email protected]39cd64ed2010-02-05 02:18:46195#include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33196#elif defined(OS_MACOSX)
197#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57198#endif
199
[email protected]c7287a92009-11-04 20:06:15200using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42201using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08202using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21203using WebKit::WebApplicationCacheHost;
204using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26205using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41206using WebKit::WebColor;
207using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59208using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44209using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51210using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55211using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28212using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29213using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00214using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58215using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25216using WebKit::WebDragOperation;
217using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51218using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51219using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08220using WebKit::WebExternalPopupMenu;
221using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47222using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22223using WebKit::WebFileSystem;
224using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49225using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59226using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48227using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45228using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17229using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41230using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50231using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17232using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28233using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17234using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28235using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28236using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51237using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07238using WebKit::WebPageSerializer;
239using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17240using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40241using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49242using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09243using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52244using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59245using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51246using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52247using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40248using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35249using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29250using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59251using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42252using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02253using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34254using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28255using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51256using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52257using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28258using WebKit::WebURL;
259using WebKit::WebURLError;
260using WebKit::WebURLRequest;
261using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28262using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03263using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28264using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26265using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43266using WebKit::WebWorker;
267using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26268using appcache::WebApplicationCacheHostImpl;
269using base::Time;
270using base::TimeDelta;
271using webkit_glue::AltErrorPageResourceFetcher;
272using webkit_glue::FormData;
273using webkit_glue::FormField;
274using webkit_glue::ImageResourceFetcher;
275using webkit_glue::PasswordForm;
276using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23277using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26278using webkit_glue::SiteIsolationMetrics;
279using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33280
initial.commit09911bf2008-07-26 23:55:29281//-----------------------------------------------------------------------------
282
[email protected]3354d3e2010-06-10 19:53:02283typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49284static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02285
initial.commit09911bf2008-07-26 23:55:29286// define to write the time necessary for thumbnail/DOM text retrieval,
287// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29288// #define TIME_TEXT_RETRIEVAL
289
290// maximum number of characters in the document to index, any text beyond this
291// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57292static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29293
294// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37295static const int kThumbnailWidth = 212;
296static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29297
298// Delay in milliseconds that we'll wait before capturing the page contents
299// and thumbnail.
300static const int kDelayForCaptureMs = 500;
301
302// Typically, we capture the page data once the page is loaded.
303// Sometimes, the page never finishes to load, preventing the page capture
304// To workaround this problem, we always perform a capture after the following
305// delay.
306static const int kDelayForForcedCaptureMs = 6000;
307
[email protected]882daa92009-11-05 16:31:31308// Time, in seconds, we delay before sending content state changes (such as form
309// state and scroll position) to the browser. We delay sending changes to avoid
310// spamming the browser.
311// To avoid having tab/session restore require sending a message to get the
312// current content state during tab closing we use a shorter timeout for the
313// foreground renderer. This means there is a small window of time from which
314// content state is modified and not sent to session restore, but this is
315// better than having to wake up all renderers during shutdown.
316static const int kDelaySecondsForContentStateSyncHidden = 5;
317static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29318
[email protected]0aa55312008-10-17 21:53:08319// The maximum number of popups that can be spawned from one page.
320static const int kMaximumNumberOfUnacknowledgedPopups = 25;
321
[email protected]6fdd4182010-10-14 23:59:26322static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35323
[email protected]726985e22009-06-18 21:09:28324static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
325 WebVector<WebURL> urls;
326 ds->redirectChain(urls);
327 result->reserve(urls.size());
328 for (size_t i = 0; i < urls.size(); ++i)
329 result->push_back(urls[i]);
330}
331
[email protected]30507922010-01-15 16:48:23332static bool PaintViewIntoCanvas(WebView* view,
333 skia::PlatformCanvas& canvas) {
334 view->layout();
335 const WebSize& size = view->size();
336
337 if (!canvas.initialize(size.width, size.height, true))
338 return false;
339
340 view->paint(webkit_glue::ToWebCanvas(&canvas),
341 WebRect(0, 0, size.width, size.height));
342 // TODO: Add a way to snapshot the whole page, not just the currently
343 // visible part.
344
345 return true;
346}
347
348// Calculates how "boring" a thumbnail is. The boring score is the
349// 0,1 ranged percentage of pixels that are the most common
350// luma. Higher boring scores indicate that a higher percentage of a
351// bitmap are all the same brightness.
352static double CalculateBoringScore(SkBitmap* bitmap) {
353 int histogram[256] = {0};
354 color_utils::BuildLumaHistogram(bitmap, histogram);
355
356 int color_count = *std::max_element(histogram, histogram + 256);
357 int pixel_count = bitmap->width() * bitmap->height();
358 return static_cast<double>(color_count) / pixel_count;
359}
360
[email protected]12bc8472010-04-15 07:29:40361// True if |frame| contains content that is white-listed for content settings.
362static bool IsWhitelistedForContentSettings(WebFrame* frame) {
363 WebSecurityOrigin origin = frame->securityOrigin();
364 if (origin.isEmpty())
365 return false; // Uninitialized document?
366
367 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
368 return true; // Browser UI elements should still work.
369
370 // If the scheme is ftp: or file:, an empty file name indicates a directory
371 // listing, which requires JavaScript to function properly.
372 GURL frame_url = frame->url();
373 const char* kDirProtocols[] = { "ftp", "file" };
374 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
375 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
376 return frame_url.SchemeIs(kDirProtocols[i]) &&
377 frame_url.ExtractFileName().empty();
378 }
379 }
380
381 return false;
382}
383
[email protected]3a8eecb2010-04-22 23:56:30384// Returns true if the frame is navigating to an URL either into or out of an
385// extension app's extent.
[email protected]08e94b82010-12-15 22:51:04386// TODO(creis): Temporary workaround for crbug.com/65953: Only return true if
387// we would enter an extension app's extent from a non-app. We avoid swapping
388// processes to exit an app for now, since we do not yet restore context (such
389// as window.opener) if the window navigates back.
390static bool CrossesIntoExtensionExtent(WebFrame* frame, const GURL& new_url) {
[email protected]3a8eecb2010-04-22 23:56:30391 // If the URL is still empty, this is a window.open navigation. Check the
392 // opener's URL.
393 GURL old_url(frame->url());
394 if (old_url.is_empty() && frame->opener())
395 old_url = frame->opener()->url();
396
[email protected]08e94b82010-12-15 22:51:04397 return !ExtensionRendererInfo::InSameExtent(old_url, new_url) &&
398 !ExtensionRendererInfo::GetByURL(old_url);
[email protected]3a8eecb2010-04-22 23:56:30399}
400
[email protected]3354d3e2010-06-10 19:53:02401// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
402// if it failed.
[email protected]e5106202010-06-11 21:12:36403static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17404 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02405 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08406 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02407 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02408 Language cld_language =
[email protected]e5106202010-06-11 21:12:36409 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08410 &num_languages, NULL, &text_bytes);
411 // We don't trust the result if the CLD reports that the detection is not
412 // reliable, or if the actual text used to detect the language was less than
413 // 100 bytes (short texts can often lead to wrong results).
414 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02415 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
416 // We should not use LanguageCode_ISO_639_1 because it does not cover all
417 // the languages CLD can detect. As a result, it'll return the invalid
418 // language code for tradtional Chinese among others.
419 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
420 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
421 // for Simplified Chinese.
422 language = LanguageCodeWithDialects(cld_language);
423 }
424 return language;
425}
426
[email protected]9b66f34bf2010-10-27 20:45:51427// Returns true if the parameter node is a textfield, text area or a content
428// editable div.
429static bool IsEditableNode(const WebNode& node) {
430 bool is_editable_node = false;
431 if (!node.isNull()) {
432 if (node.isContentEditable()) {
433 is_editable_node = true;
434 } else if (node.isElementNode()) {
435 is_editable_node =
436 node.toConst<WebElement>().isTextFormControlElement();
437 }
438 }
439 return is_editable_node;
440}
441
[email protected]54ec7f82010-10-21 22:32:51442static bool WebAccessibilityNotificationToViewHostMsg(
443 WebAccessibilityNotification notification,
444 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) {
445 switch (notification) {
446 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
447 *type = ViewHostMsg_AccessibilityNotification_Params::
448 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
449 break;
450 case WebKit::WebAccessibilityNotificationChildrenChanged:
451 *type = ViewHostMsg_AccessibilityNotification_Params::
452 NOTIFICATION_TYPE_CHILDREN_CHANGED;
453 break;
454 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
455 *type = ViewHostMsg_AccessibilityNotification_Params::
456 NOTIFICATION_TYPE_FOCUS_CHANGED;
457 break;
458 case WebKit::WebAccessibilityNotificationLoadComplete:
459 *type = ViewHostMsg_AccessibilityNotification_Params::
460 NOTIFICATION_TYPE_LOAD_COMPLETE;
461 break;
462 case WebKit::WebAccessibilityNotificationValueChanged:
463 *type = ViewHostMsg_AccessibilityNotification_Params::
464 NOTIFICATION_TYPE_VALUE_CHANGED;
465 break;
466 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
467 *type = ViewHostMsg_AccessibilityNotification_Params::
468 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
469 break;
470 default:
471 // TODO(ctguil): Support additional webkit notifications.
472 return false;
473 }
474 return true;
475}
476
[email protected]81f9fe0b2010-12-07 00:35:29477// Conversion for the incoming value. The map isn't perfect; v8 has Uint32,
478// and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into
479// being TYPE_REALs. Dates are converted to a string (which can then be parsed
480// into a base::Time), as are regexps. Arrays are converted into lists,
481// recursively. We don't deal with binary objects or functions - they become
482// null values.
483static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) {
484 if (v8value->IsBoolean()) {
485 return Value::CreateBooleanValue(v8value->BooleanValue());
486 } else if (v8value->IsInt32()) {
487 return Value::CreateIntegerValue(v8value->Int32Value());
488 } else if (v8value->IsNumber()) {
489 return Value::CreateRealValue(v8value->NumberValue());
490 } else if (v8value->IsString()) {
491 return Value::CreateStringValue(*v8::String::Utf8Value(v8value));
492 } else if (v8value->IsDate()) {
493 v8::Date* date = v8::Date::Cast(*v8value);
494 return Value::CreateRealValue(date->NumberValue() / 1000.0);
495 } else if (v8value->IsRegExp()) {
496 return Value::CreateStringValue(
497 *v8::String::Utf8Value(v8value->ToString()));
498 } else if (v8value->IsArray()) {
499 v8::Array* array = v8::Array::Cast(*v8value);
500 uint32_t length = array->Length();
501 scoped_ptr<ListValue> list(new ListValue);
502 for (uint32_t i = 0 ; i < length ; ++i) {
503 list->Set(i, ConvertV8Value(array->Get(i)));
504 }
505 return list.release();
506 }
507 return Value::CreateNullValue();
508}
509
initial.commit09911bf2008-07-26 23:55:29510///////////////////////////////////////////////////////////////////////////////
511
[email protected]60c42a8c72009-10-09 04:08:59512int32 RenderView::next_page_id_ = 1;
513
[email protected]cdaf8d02010-03-30 19:52:47514struct RenderView::PendingFileChooser {
515 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
516 WebFileChooserCompletion* c)
517 : params(p),
518 completion(c) {
519 }
520 ViewHostMsg_RunFileChooser_Params params;
521 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
522};
523
[email protected]2fab253a2009-08-17 23:00:59524RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]4e6419c2010-01-15 04:50:34525 const WebPreferences& webkit_preferences,
526 int64 session_storage_namespace_id)
[email protected]3e2b375b2010-04-07 17:03:12527 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]3354d3e2010-06-10 19:53:02528 webkit_preferences_(webkit_preferences),
529 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09530 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02531 send_preferred_size_changes_(false),
532 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24533 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21534 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02535 opened_by_user_gesture_(true),
536 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24537 page_id_(-1),
538 last_page_id_sent_to_browser_(-1),
539 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00540 history_list_offset_(-1),
541 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24542 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55543#if defined(OS_MACOSX)
544 has_document_tag_(false),
545#endif
[email protected]98324892009-09-09 21:16:05546 document_tag_(0),
[email protected]3354d3e2010-06-10 19:53:02547 target_url_status_(TARGET_NONE),
548 spelling_panel_visible_(false),
549 view_type_(ViewType::INVALID),
550 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18551 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30552 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
553 ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)),
[email protected]54ec7f82010-10-21 22:32:51554 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02555 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
556 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
557 ALLOW_THIS_IN_INITIALIZER_LIST(
558 notification_provider_(new NotificationProvider(this))),
[email protected]54ec7f82010-10-21 22:32:51559 accessibility_ack_pending_(false),
[email protected]bb461532010-11-26 21:50:23560 pending_app_icon_requests_(0),
[email protected]3354d3e2010-06-10 19:53:02561 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]6a8b86c2010-12-09 05:24:30562 decrement_shared_popup_at_destruction_(false),
563 custom_menu_listener_(NULL) {
[email protected]8de12d942010-11-17 20:42:44564#if defined(OS_MACOSX)
565 // On Mac, the select popups are rendered by the browser.
566 // Note that we don't do this in RenderMain otherwise this would not be called
567 // in single-process mode.
568 WebKit::WebView::setUseExternalPopupMenus(true);
569#endif
[email protected]6a8ddba52010-09-05 04:38:06570 password_autocomplete_manager_.reset(new PasswordAutocompleteManager(this));
571 autofill_helper_.reset(new AutoFillHelper(this));
572 page_click_tracker_.reset(new PageClickTracker(this));
573 // Note that the order of insertion of the listeners is important.
574 // The password_autocomplete_manager_ takes the first shot at processing the
575 // notification and can stop the propagation.
576 page_click_tracker_->AddListener(password_autocomplete_manager_.get());
577 page_click_tracker_->AddListener(autofill_helper_.get());
[email protected]71b0d5d2010-02-15 05:43:07578 ClearBlockedContentSettings();
[email protected]3ead1322010-11-19 20:01:00579 if (CommandLine::ForCurrentProcess()->HasSwitch(
580 switches::kEnableClientSidePhishingDetection)) {
581 phishing_delegate_.reset(
582 new safe_browsing::PhishingClassifierDelegate(this, NULL));
583 RenderThread* thread = RenderThread::current();
584 if (thread && thread->phishing_scorer()) {
585 phishing_delegate_->SetPhishingScorer(thread->phishing_scorer());
586 }
587 }
initial.commit09911bf2008-07-26 23:55:29588}
589
590RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08591 if (decrement_shared_popup_at_destruction_)
592 shared_popup_counter_->data--;
593
[email protected]a1128322009-10-06 18:38:46594 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47595 while (!file_chooser_completions_.empty()) {
596 if (file_chooser_completions_.front()->completion) {
597 file_chooser_completions_.front()->completion->didChooseFile(
598 WebVector<WebString>());
599 }
600 file_chooser_completions_.pop_front();
601 }
[email protected]a1128322009-10-06 18:38:46602
[email protected]83dde542009-09-11 20:59:55603#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05604 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55605 if (has_document_tag_)
606 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
[email protected]c36a9b62010-10-14 00:41:11607
608 // Destroy all fake plugin window handles on the browser side.
609 while (!fake_plugin_window_handles_.empty()) {
610 // Make sure no NULL plugin window handles were inserted into this list.
611 DCHECK(*fake_plugin_window_handles_.begin());
612 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
613 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
614 }
[email protected]83dde542009-09-11 20:59:55615#endif
[email protected]98324892009-09-09 21:16:05616
[email protected]5fb88962009-04-16 19:03:25617 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59618
[email protected]3ead1322010-11-19 20:01:00619 // Tell the PhishingClassifierDelegate that the view is going away.
620 if (phishing_delegate_.get())
621 phishing_delegate_->CancelPendingClassification();
622
[email protected]60c42a8c72009-10-09 04:08:59623#ifndef NDEBUG
624 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49625 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59626 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
627 DCHECK_NE(this, it->second) << "Failed to call Close?";
628#endif
629}
630
631/*static*/
632void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49633 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59634 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
635 if (!visitor->Visit(it->second))
636 return;
637 }
638}
639
640/*static*/
641RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49642 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59643 ViewMap::iterator it = views->find(webview);
644 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29645}
646
647/*static*/
[email protected]0aa55312008-10-17 21:53:08648RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24649 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15650 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08651 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51652 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08653 const WebPreferences& webkit_prefs,
654 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34655 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26656 int64 session_storage_namespace_id,
657 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29658 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]ad8e04a2010-11-01 04:16:27659 scoped_refptr<RenderView> view(new RenderView(render_thread, webkit_prefs,
660 session_storage_namespace_id));
initial.commit09911bf2008-07-26 23:55:29661 view->Init(parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29662 opener_id,
[email protected]80d96fa2009-06-10 22:34:51663 renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08664 counter,
[email protected]8ab04652010-06-12 02:47:26665 routing_id,
666 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29667 return view;
668}
669
[email protected]bb461532010-11-26 21:50:23670// static
initial.commit09911bf2008-07-26 23:55:29671void RenderView::SetNextPageID(int32 next_page_id) {
672 // This method should only be called during process startup, and the given
673 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05674 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29675 DCHECK(next_page_id >= next_page_id_);
676 next_page_id_ = next_page_id;
677}
678
[email protected]70eee342010-11-05 01:59:37679bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
680 typedef ViewHostMsg_AccessibilityNotification_Params params;
681 if (type == params::NOTIFICATION_TYPE_CHILDREN_CHANGED ||
682 type == params::NOTIFICATION_TYPE_LOAD_COMPLETE) {
683 return true;
684 }
685 return false;
686}
687
[email protected]8a3125a712010-08-09 18:58:51688WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26689 return static_cast<WebKit::WebView*>(webwidget());
690}
691
[email protected]afe3a1672009-11-17 19:04:12692void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]15d04ae2010-10-30 01:04:50693 Send(new ViewHostMsg_UserMetricsRecordAction(action));
[email protected]1dbafaf72009-09-23 19:43:56694}
695
[email protected]bb461532010-11-26 21:50:23696bool RenderView::InstallWebApplicationUsingDefinitionFile(WebFrame* frame,
697 string16* error) {
698 // There is an issue of drive-by installs with the below implementation. A web
699 // site could force a user to install an app by timing the dialog to come up
700 // just before the user clicks.
701 //
702 // We do show a success UI that allows users to uninstall, but it seems that
703 // we might still want to put up an infobar before showing the install dialog.
704 //
705 // TODO(aa): Figure out this issue before removing the kEnableCrxlessWebApps
706 // switch.
707 if (!CommandLine::ForCurrentProcess()->HasSwitch(
708 switches::kEnableCrxlessWebApps)) {
709 *error = ASCIIToUTF16("CRX-less web apps aren't enabled.");
710 return false;
711 }
712
713 if (frame != frame->top()) {
714 *error = ASCIIToUTF16("Applications can only be installed from the top "
715 "frame.");
716 return false;
717 }
718
719 if (pending_app_info_.get()) {
720 *error = ASCIIToUTF16("An application install is already in progress.");
721 return false;
722 }
723
724 pending_app_info_.reset(new WebApplicationInfo());
725 if (!web_apps::ParseWebAppFromWebDocument(frame, pending_app_info_.get(),
726 error)) {
727 return false;
728 }
729
730 if (!pending_app_info_->manifest_url.is_valid()) {
731 *error = ASCIIToUTF16("Web application definition not found or invalid.");
732 return false;
733 }
734
735 app_definition_fetcher_.reset(new ResourceFetcher(
736 pending_app_info_->manifest_url, webview()->mainFrame(),
737 NewCallback(this, &RenderView::DidDownloadApplicationDefinition)));
738 return true;
739}
740
[email protected]1a3c3cb2010-12-16 21:03:40741void RenderView::SetReportLoadProgressEnabled(bool enabled) {
742 if (!enabled) {
743 load_progress_tracker_.reset(NULL);
744 return;
745 }
746 if (load_progress_tracker_ == NULL)
747 load_progress_tracker_.reset(new LoadProgressTracker(this));
748}
749
[email protected]bb461532010-11-26 21:50:23750void RenderView::DidDownloadApplicationDefinition(
751 const WebKit::WebURLResponse& response,
752 const std::string& data) {
753 scoped_ptr<WebApplicationInfo> app_info(
754 pending_app_info_.release());
755
756 JSONStringValueSerializer serializer(data);
757 int error_code = 0;
758 std::string error_message;
759 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message));
760 if (!result.get()) {
761 AddErrorToRootConsole(UTF8ToUTF16(error_message));
762 return;
763 }
764
765 string16 error_message_16;
766 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(),
767 &error_message_16)) {
768 AddErrorToRootConsole(error_message_16);
769 return;
770 }
771
772 if (!app_info->icons.empty()) {
773 pending_app_info_.reset(app_info.release());
774 pending_app_icon_requests_ =
775 static_cast<int>(pending_app_info_->icons.size());
776 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
777 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
778 new ImageResourceFetcher(
779 pending_app_info_->icons[i].url,
780 webview()->mainFrame(),
781 static_cast<int>(i),
782 pending_app_info_->icons[i].width,
783 NewCallback(this, &RenderView::DidDownloadApplicationIcon))));
784 }
785 } else {
786 Send(new ViewHostMsg_InstallApplication(routing_id_, *app_info));
787 }
788}
789
790void RenderView::DidDownloadApplicationIcon(ImageResourceFetcher* fetcher,
791 const SkBitmap& image) {
792 pending_app_info_->icons[fetcher->id()].data = image;
793
794 // Remove the image fetcher from our pending list. We're in the callback from
795 // ImageResourceFetcher, best to delay deletion.
796 for (ImageResourceFetcherList::iterator iter = app_icon_fetchers_.begin();
797 iter != app_icon_fetchers_.end(); ++iter) {
798 if (iter->get() == fetcher) {
799 iter->release();
800 app_icon_fetchers_.erase(iter);
801 break;
802 }
803 }
804
805 // We're in the callback from the ImageResourceFetcher, best to delay
806 // deletion.
807 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
808
809 if (--pending_app_icon_requests_ > 0)
810 return;
811
812 // There is a maximum size of IPC on OS X and Linux that we have run into in
813 // some situations. We're not sure what it is, but our hypothesis is in the
814 // neighborhood of 1 MB.
815 //
816 // To be on the safe side, we give ourselves 128 KB for just the image data.
817 // This should be more than enough for 128, 48, and 16 px 32-bit icons. If we
818 // want to start allowing larger icons (see bug 63406), we'll have to either
819 // experiment mor ewith this and find the real limit, or else come up with
820 // some alternative way to transmit the icon data to the browser process.
821 //
822 // See also: bug 63729.
823 const int kMaxIconSize = 1024 * 128;
824 int actual_icon_size = 0;
825 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
826 actual_icon_size += pending_app_info_->icons[i].data.getSize();
827 }
828
829 if (actual_icon_size > kMaxIconSize) {
830 AddErrorToRootConsole(ASCIIToUTF16(
831 "Icons are too large. Maximum total size for app icons is 128 KB."));
832 return;
833 }
834
835 Send(new ViewHostMsg_InstallApplication(routing_id_, *pending_app_info_));
836 pending_app_info_.reset(NULL);
837}
838
[email protected]a3a8fb6d2009-10-22 20:12:51839void RenderView::PluginCrashed(const FilePath& plugin_path) {
840 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29841}
842
[email protected]aad51d1c2010-08-05 08:38:09843WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
844 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50845 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26846 bool found;
847 ContentSetting setting;
848 std::string mime_type;
849 Send(new ViewHostMsg_GetPluginInfo(
850 params.url, frame->top()->url(), params.mimeType.utf8(), &found,
851 &info, &setting, &mime_type));
852 if (!found || !info.enabled)
[email protected]aad51d1c2010-08-05 08:38:09853 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45854
[email protected]0bd753682010-12-16 18:15:52855 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:45856 pepper_delegate_.CreatePepperPlugin(info.path));
[email protected]aad51d1c2010-08-05 08:38:09857 if (pepper_module)
[email protected]6fdd4182010-10-14 23:59:26858 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]1a78d9f32010-12-08 06:38:45859 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09860}
861
[email protected]6a8b86c2010-12-09 05:24:30862void RenderView::CustomMenuListenerInstall(CustomMenuListener* listening) {
863 custom_menu_listener_ = listening;
864}
865
866void RenderView::CustomMenuListenerDestroyed(CustomMenuListener* dead) {
867 if (custom_menu_listener_ == dead)
868 custom_menu_listener_ = NULL;
869}
870
[email protected]d8fd6fa2010-02-01 15:54:26871void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
872 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30873 // If the renderer is visible, set initial visibility and focus state.
874 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34875#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30876 delegate->SetContainerVisibility(true);
877 if (webview() && webview()->isActive())
878 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34879#endif
[email protected]49232292010-09-03 19:07:30880 }
[email protected]784ea1ab2010-09-18 00:02:34881 // Plugins start assuming the content has focus (so that they work in
882 // environments where RenderView isn't hosting them), so we always have to
883 // set the initial state. See webplugin_delegate_impl.h for details.
884 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26885}
886
887void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
888 plugin_delegates_.erase(delegate);
889}
[email protected]d8fd6fa2010-02-01 15:54:26890
[email protected]18bcc3c2009-01-27 21:39:15891void RenderView::Init(gfx::NativeViewId parent_hwnd,
initial.commit09911bf2008-07-26 23:55:29892 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51893 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08894 SharedRenderViewCounter* counter,
[email protected]8ab04652010-06-12 02:47:26895 int32 routing_id,
896 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29897 DCHECK(!webview());
898
899 if (opener_id != MSG_ROUTING_NONE)
900 opener_id_ = opener_id;
901
[email protected]0aa55312008-10-17 21:53:08902 if (counter) {
903 shared_popup_counter_ = counter;
904 shared_popup_counter_->data++;
905 decrement_shared_popup_at_destruction_ = true;
906 } else {
907 shared_popup_counter_ = new SharedRenderViewCounter(0);
908 decrement_shared_popup_at_destruction_ = false;
909 }
910
[email protected]58bfc6b2009-06-24 09:45:02911 devtools_agent_.reset(new DevToolsAgent(routing_id, this));
[email protected]9b9d7282009-04-08 14:13:04912
[email protected]9a6c6232010-06-25 11:46:49913 webwidget_ = WebView::create(this, devtools_agent_.get());
[email protected]625332e02010-12-14 07:48:49914 g_view_map.Get().insert(std::make_pair(webview(), this));
[email protected]2fab253a2009-08-17 23:00:59915 webkit_preferences_.Apply(webview());
[email protected]b4bb2502009-10-01 22:35:27916 webview()->initializeMainFrame(this);
[email protected]c1e06962010-06-17 16:53:23917 if (!frame_name.empty())
918 webview()->mainFrame()->setName(frame_name);
initial.commit09911bf2008-07-26 23:55:29919
[email protected]d3ba77272009-09-03 00:06:09920 OnSetRendererPrefs(renderer_prefs);
921
initial.commit09911bf2008-07-26 23:55:29922 routing_id_ = routing_id;
[email protected]81a34412009-01-05 19:17:24923 render_thread_->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29924 // Take a reference on behalf of the RenderThread. This will be balanced
925 // when we receive ViewMsg_Close.
926 AddRef();
927
928 // If this is a popup, we must wait for the CreatingNew_ACK message before
929 // completing initialization. Otherwise, we can finish it now.
930 if (opener_id == MSG_ROUTING_NONE) {
931 did_show_ = true;
932 CompleteInit(parent_hwnd);
933 }
934
935 host_window_ = parent_hwnd;
initial.commit09911bf2008-07-26 23:55:29936
[email protected]58bfc6b2009-06-24 09:45:02937 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]81e63782009-02-27 19:35:09938 if (command_line.HasSwitch(switches::kDomAutomationController))
939 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
[email protected]dea2d372010-09-25 06:41:14940 if (command_line.HasSwitch(switches::kEnableAccessibility))
941 WebAccessibilityCache::enableAccessibility();
initial.commit09911bf2008-07-26 23:55:29942
[email protected]5fb88962009-04-16 19:03:25943 audio_message_filter_ = new AudioMessageFilter(routing_id_);
944 render_thread_->AddFilter(audio_message_filter_);
initial.commit09911bf2008-07-26 23:55:29945}
946
947void RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27948 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27949 if (main_frame)
950 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26951
[email protected]b2abac72009-02-26 12:39:28952 // If this is developer tools renderer intercept tools messages first.
[email protected]e4ac5df2009-03-17 15:33:11953 if (devtools_client_.get() && devtools_client_->OnMessageReceived(message))
[email protected]b2abac72009-02-26 12:39:28954 return;
[email protected]b4b967e2009-04-22 11:33:05955 if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message))
956 return;
[email protected]b6849bda2009-10-14 23:59:26957 if (notification_provider_->OnMessageReceived(message))
958 return;
[email protected]58c321d2010-02-19 12:11:28959 if (geolocation_dispatcher_.get() &&
960 geolocation_dispatcher_->OnMessageReceived(message)) {
961 return;
962 }
[email protected]638694c2010-08-04 22:24:11963 if (speech_input_dispatcher_.get() &&
964 speech_input_dispatcher_->OnMessageReceived(message)) {
965 return;
966 }
[email protected]57ead352010-08-11 14:42:53967 if (device_orientation_dispatcher_.get() &&
968 device_orientation_dispatcher_->OnMessageReceived(message)) {
969 return;
970 }
[email protected]b2abac72009-02-26 12:39:28971
initial.commit09911bf2008-07-26 23:55:29972 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04973 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
974 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29975 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01976 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
initial.commit09911bf2008-07-26 23:55:29977 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
978 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56979 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29980 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
981 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
982 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
983 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27984#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35985 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27986#endif
initial.commit09911bf2008-07-26 23:55:29987 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
988 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05989 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
990 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
991 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04992 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29993 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
994 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
995 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15996 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29997 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49998 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
999 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:171000 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:541001 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
1002 OnSetContentSettingsForLoadingURL)
[email protected]d0b8d092010-10-25 04:05:171003 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:541004 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1005 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291006 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181007 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1008 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:281009 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:331010 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:291011 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:481012 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:291013 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:291014 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:291015 IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm)
1016 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
1017 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
1018 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
1019 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:451020 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291021 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:501022 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
1023 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:291024 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
1025 OnDragSourceSystemDragEnded)
1026 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:511027 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
1028 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:291029 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1030 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1031 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1032 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]97c5c592010-08-03 08:22:211033 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
initial.commit09911bf2008-07-26 23:55:291034 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1035 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:291036 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1037 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:041038 IPC_MESSAGE_HANDLER(
1039 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1040 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:291041 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:041042 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:291043 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1044 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:451045 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:041046 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:081047 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1048 OnDisassociateFromPopupCount)
[email protected]95056b582010-02-18 01:29:241049 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned,
1050 OnAutoFillSuggestionsReturned)
[email protected]c83641732010-02-20 01:04:481051 IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled,
1052 OnAutoFillFormDataFilled)
[email protected]e8345242010-05-06 03:00:401053 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
1054 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:001055 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:271056 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:371057 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
1058 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:161059 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141060 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251061 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1062 OnEnablePreferredSizeChangedMode)
[email protected]ce833282010-11-04 15:48:391063 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxChange, OnSearchBoxChange)
1064 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxSubmit, OnSearchBoxSubmit)
1065 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxCancel, OnSearchBoxCancel)
1066 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxResize, OnSearchBoxResize)
1067 IPC_MESSAGE_HANDLER(ViewMsg_DetermineIfPageSupportsInstant,
1068 OnDetermineIfPageSupportsInstant)
[email protected]cda45c02010-02-25 19:28:101069 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1070 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511071 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:531072 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
1073 OnUpdateBrowserWindowId)
1074 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
1075 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:561076 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:341077 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:141078#if defined(OS_MACOSX)
1079 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:131080 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]935d63d2010-10-15 23:31:551081 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionConfirmed,
1082 OnPluginImeCompositionConfirmed)
[email protected]6ce7abc52010-02-02 18:40:141083#endif
[email protected]446705872009-09-10 07:22:481084 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331085 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:351086 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
1087 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:331088 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1089 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:421090 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:021091 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]dea2d372010-09-25 06:41:141092 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:361093 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
1094 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
1095 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:421096 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
1097 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:241098 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]caf706f2010-10-26 17:54:081099#if defined(OS_MACOSX)
1100 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1101#endif
[email protected]212a49d2010-10-25 18:23:471102 IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview)
[email protected]634a6f92008-12-01 21:39:311103
initial.commit09911bf2008-07-26 23:55:291104 // Have the super handle all other messages.
1105 IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
1106 IPC_END_MESSAGE_MAP()
1107}
1108
[email protected]9b18a84f2010-06-10 15:54:041109void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:271110 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291111 if (!main_frame)
1112 return;
1113
1114 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:451115 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291116 if (url.is_empty())
1117 return;
1118
1119 if (size_.IsEmpty())
1120 return; // Don't create an empty thumbnail!
1121
1122 ThumbnailScore score;
1123 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:021124 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:151125 &thumbnail, &score))
1126 return;
1127
initial.commit09911bf2008-07-26 23:55:291128 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:461129 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:291130}
1131
[email protected]9b18a84f2010-06-10 15:54:041132void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:231133 SkBitmap snapshot;
1134 bool error = false;
1135
1136 WebFrame* main_frame = webview()->mainFrame();
1137 if (!main_frame)
1138 error = true;
1139
1140 if (!error && !CaptureSnapshot(webview(), &snapshot))
1141 error = true;
1142
1143 DCHECK(error == snapshot.empty()) <<
1144 "Snapshot should be empty on error, non-empty otherwise.";
1145
1146 // Send the snapshot to the browser process.
1147 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
1148}
1149
[email protected]068637222009-01-29 16:58:071150void RenderView::OnPrintPages() {
initial.commit09911bf2008-07-26 23:55:291151 DCHECK(webview());
[email protected]aa82249f2009-07-16 17:23:581152 if (webview()) {
1153 // If the user has selected text in the currently focused frame we print
1154 // only that frame (this makes print selection work for multiple frames).
[email protected]26aa0482009-09-30 16:55:271155 if (webview()->focusedFrame()->hasSelection())
[email protected]212a49d2010-10-25 18:23:471156 Print(webview()->focusedFrame(), false, false);
[email protected]aa82249f2009-07-16 17:23:581157 else
[email protected]212a49d2010-10-25 18:23:471158 Print(webview()->mainFrame(), false, false);
[email protected]aa82249f2009-07-16 17:23:581159 }
initial.commit09911bf2008-07-26 23:55:291160}
1161
[email protected]82270452009-06-19 15:58:011162void RenderView::OnPrintingDone(int document_cookie, bool success) {
1163 // Ignoring document cookie here since only one print job can be outstanding
1164 // per renderer and document_cookie is 0 when printing is successful.
1165 DCHECK(print_helper_.get());
1166 if (print_helper_.get() != NULL) {
1167 print_helper_->DidFinishPrinting(success);
1168 }
1169}
1170
[email protected]212a49d2010-10-25 18:23:471171void RenderView::OnPrintPreview() {
1172 DCHECK(webview());
1173 if (webview()) {
1174 // If the user has selected text in the currently focused frame we print
1175 // only that frame (this makes print selection work for multiple frames).
1176 if (webview()->focusedFrame()->hasSelection())
1177 Print(webview()->focusedFrame(), false, true);
1178 else
1179 Print(webview()->focusedFrame(), false, true);
1180 }
1181}
1182
initial.commit09911bf2008-07-26 23:55:291183void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
1184 if (load_id != page_id_)
1185 return; // this capture call is no longer relevant due to navigation
1186 if (load_id == last_indexed_page_id_)
1187 return; // we already indexed this page
1188
1189 if (!webview())
1190 return;
1191
[email protected]26aa0482009-09-30 16:55:271192 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291193 if (!main_frame)
1194 return;
1195
1196 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:451197 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:291198 return;
1199
1200 // Don't index/capture pages that failed to load. This only checks the top
1201 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:451202 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:281203 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:291204 return;
1205
1206 if (!preliminary_capture)
1207 last_indexed_page_id_ = load_id;
1208
[email protected]a8a81292010-01-21 00:32:451209 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:451210 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291211 if (url.is_empty())
1212 return;
1213
[email protected]a8a81292010-01-21 00:32:451214 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:361215 string16 contents;
initial.commit09911bf2008-07-26 23:55:291216 CaptureText(main_frame, &contents);
1217 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:101218 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:371219 // If the page explicitly specifies a language, use it, otherwise we'll
1220 // determine it based on the text content using the CLD.
1221 std::string language =
1222 TranslateHelper::GetPageLanguageFromMetaTag(&document);
1223 if (language.empty()) {
1224 base::TimeTicks begin_time = base::TimeTicks::Now();
1225 language = DetermineTextLanguage(contents);
1226 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
1227 base::TimeTicks::Now() - begin_time);
1228 }
[email protected]a8a81292010-01-21 00:32:451229 // Send the text to the browser for indexing (the browser might decide not
1230 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:371231 Send(new ViewHostMsg_PageContents(
1232 routing_id_, url, load_id, contents, language,
1233 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:271234 }
1235
[email protected]9b18a84f2010-06-10 15:54:041236 OnCaptureThumbnail();
[email protected]3ead1322010-11-19 20:01:001237
1238 if (phishing_delegate_.get())
1239 phishing_delegate_->FinishedLoad(&contents);
initial.commit09911bf2008-07-26 23:55:291240}
1241
[email protected]e5106202010-06-11 21:12:361242void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:291243 contents->clear();
1244 if (!frame)
1245 return;
1246
1247#ifdef TIME_TEXT_RETRIEVAL
1248 double begin = time_util::GetHighResolutionTimeNow();
1249#endif
1250
1251 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:361252 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:291253
1254#ifdef TIME_TEXT_RETRIEVAL
1255 double end = time_util::GetHighResolutionTimeNow();
1256 char buf[128];
1257 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
1258 contents.size(), (end - begin)*1000);
1259 OutputDebugStringA(buf);
1260#endif
1261
1262 // When the contents are clipped to the maximum, we don't want to have a
1263 // partial word indexed at the end that might have been clipped. Therefore,
1264 // terminate the string at the last space to ensure no words are clipped.
1265 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:361266 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:291267 if (last_space_index == std::wstring::npos)
1268 return; // don't index if we got a huge block of text with no spaces
1269 contents->resize(last_space_index);
1270 }
1271}
1272
[email protected]8649fb32009-06-26 17:51:021273bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:291274 int w,
1275 int h,
1276 SkBitmap* thumbnail,
1277 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:231278 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:151279
[email protected]8649fb32009-06-26 17:51:021280 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:231281
1282 // Paint |view| into |canvas|.
1283 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:021284 return false;
[email protected]8649fb32009-06-26 17:51:021285
1286 skia::BitmapPlatformDevice& device =
1287 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1288
1289 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:291290
[email protected]cab34d6a2009-09-24 01:14:521291 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:291292 float dest_aspect = dest_rect.width() / dest_rect.height();
1293
1294 // Get the src rect so that we can preserve the aspect ratio while filling
1295 // the destination.
1296 SkIRect src_rect;
1297 if (src_bmp.width() < dest_rect.width() ||
1298 src_bmp.height() < dest_rect.height()) {
1299 // Source image is smaller: we clip the part of source image within the
1300 // dest rect, and then stretch it to fill the dest rect. We don't respect
1301 // the aspect ratio in this case.
1302 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
1303 static_cast<S16CPU>(dest_rect.height()));
1304 score->good_clipping = false;
1305 } else {
1306 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1307 if (src_aspect > dest_aspect) {
1308 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1309 // the wider screen.
1310 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1311 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1312 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1313 score->good_clipping = false;
1314 } else {
1315 src_rect.set(0, 0, src_bmp.width(),
1316 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1317 score->good_clipping = true;
1318 }
1319 }
1320
[email protected]26aa0482009-09-30 16:55:271321 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291322
1323 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021324 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291325
[email protected]82afe4b2010-11-12 20:36:221326 // First do a fast downsample by powers of two to get close to the final size.
1327 SkBitmap downsampled_subset =
1328 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h);
1329
1330 // Do a high-quality resize from the downscaled size to the final size.
[email protected]465b34b72008-12-12 20:19:141331 *thumbnail = skia::ImageOperations::Resize(
[email protected]82afe4b2010-11-12 20:36:221332 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291333
1334 score->boring_score = CalculateBoringScore(thumbnail);
1335
[email protected]30507922010-01-15 16:48:231336 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1337 base::TimeTicks::Now() - beginning_time);
[email protected]82afe4b2010-11-12 20:36:221338
[email protected]b6e4bec2008-11-12 01:17:151339 return true;
initial.commit09911bf2008-07-26 23:55:291340}
1341
[email protected]30507922010-01-15 16:48:231342bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1343 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291344
[email protected]30507922010-01-15 16:48:231345 skia::PlatformCanvas canvas;
1346 if (!PaintViewIntoCanvas(view, canvas))
1347 return false;
1348
1349 skia::BitmapPlatformDevice& device =
1350 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1351
1352 const SkBitmap& bitmap = device.accessBitmap(false);
1353 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1354 return false;
1355
1356 HISTOGRAM_TIMES("Renderer4.Snapshot",
1357 base::TimeTicks::Now() - beginning_time);
1358 return true;
initial.commit09911bf2008-07-26 23:55:291359}
1360
1361void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1362 if (!webview())
1363 return;
1364
[email protected]3cc72b12010-03-18 23:03:001365 history_list_offset_ = params.current_history_list_offset;
1366 history_list_length_ = params.current_history_list_length;
1367
[email protected]8c785c62009-07-13 14:20:151368 if (devtools_agent_.get())
1369 devtools_agent_->OnNavigate();
1370
[email protected]422197532010-01-25 17:38:231371 if (notification_provider_.get())
1372 notification_provider_->OnNavigate();
1373
[email protected]a9f607e2009-10-23 19:59:271374 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261375
initial.commit09911bf2008-07-26 23:55:291376 AboutHandler::MaybeHandle(params.url);
1377
[email protected]ecbf10d2010-02-18 13:03:291378 bool is_reload =
1379 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1380 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291381
[email protected]26aa0482009-09-30 16:55:271382 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451383 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291384 // We cannot reload if we do not have any history state. This happens, for
1385 // example, when recovering from a crash. Our workaround here is a bit of
1386 // a hack since it means that reload after a crashed tab does not cause an
1387 // end-to-end cache validation.
1388 is_reload = false;
1389 }
1390
[email protected]77f17a82009-05-21 04:42:541391 // A navigation resulting from loading a javascript URL should not be treated
1392 // as a browser initiated event. Instead, we want it to look as if the page
1393 // initiated any load resulting from JS execution.
1394 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301395 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001396 params.page_id,
1397 params.pending_history_list_offset,
1398 params.transition,
1399 params.request_time);
[email protected]5e369672009-11-03 23:48:301400 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1401 // We're doing a load of a page that was restored from the last session.
1402 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1403 // which can result in stale data for pages that are set to expire. We
1404 // explicitly override that by setting the policy here so that as
1405 // necessary we load from the network.
1406 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1407 }
1408 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541409 }
initial.commit09911bf2008-07-26 23:55:291410
[email protected]a7ccc4d2010-01-27 08:14:481411 NavigationState* navigation_state = pending_navigation_state_.get();
1412
[email protected]04d3c6e2009-05-22 17:00:131413 // If we are reloading, then WebKit will use the history state of the current
1414 // page, so we should just ignore any given history state. Otherwise, if we
1415 // have history state, then we need to navigate to it, which corresponds to a
1416 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551417 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481418 if (navigation_state)
1419 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291420 bool ignore_cache = (params.navigation_type ==
1421 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1422 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551423 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131424 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581425 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481426 if (navigation_state)
1427 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451428 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171429 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131430 } else {
1431 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281432 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291433
[email protected]e6f546c32009-07-01 17:12:551434 // A session history navigation should have been accompanied by state.
1435 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131436
[email protected]dd7daa82009-08-10 05:46:451437 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551438 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131439
[email protected]726985e22009-06-18 21:09:281440 if (params.referrer.is_valid()) {
1441 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1442 WebString::fromUTF8(params.referrer.spec()));
1443 }
[email protected]04d3c6e2009-05-22 17:00:131444
[email protected]52c68652010-12-07 17:47:041445 if (!params.extra_headers.empty()) {
1446 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1447 params.extra_headers.end(), "\n");
1448 i.GetNext(); ) {
1449 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1450 WebString::fromUTF8(i.values()));
1451 }
1452 }
1453
[email protected]a7ccc4d2010-01-27 08:14:481454 if (navigation_state)
1455 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:451456 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501457 }
1458
[email protected]77f17a82009-05-21 04:42:541459 // In case LoadRequest failed before DidCreateDataSource was called.
1460 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291461}
1462
1463// Stop loading the current page
1464void RenderView::OnStop() {
1465 if (webview())
[email protected]b4bb2502009-10-01 22:35:271466 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291467}
1468
[email protected]ecbf10d2010-02-18 13:03:291469// Reload current focused frame.
1470// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561471void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291472 if (webview() && webview()->focusedFrame()) {
1473 // We always obey the cache (ignore_cache=false) here.
1474 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1475 // a cache-ignoring reload of the frame.
1476 webview()->focusedFrame()->reload(false);
1477 }
[email protected]1dda4022010-01-28 18:24:561478}
1479
initial.commit09911bf2008-07-26 23:55:291480void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271481 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291482}
1483
[email protected]68b1e922009-06-23 16:00:251484void RenderView::OnExecuteEditCommand(const std::string& name,
1485 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271486 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251487 return;
1488
[email protected]26aa0482009-09-30 16:55:271489 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451490 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251491}
1492
[email protected]b2abac72009-02-26 12:39:281493void RenderView::OnSetupDevToolsClient() {
[email protected]e4ac5df2009-03-17 15:33:111494 DCHECK(!devtools_client_.get());
1495 devtools_client_.reset(new DevToolsClient(this));
[email protected]b2abac72009-02-26 12:39:281496}
1497
initial.commit09911bf2008-07-26 23:55:291498void RenderView::OnUpdateTargetURLAck() {
1499 // Check if there is a targeturl waiting to be sent.
1500 if (target_url_status_ == TARGET_PENDING) {
1501 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1502 pending_target_url_));
1503 }
1504
1505 target_url_status_ = TARGET_NONE;
1506}
1507
1508void RenderView::OnUndo() {
1509 if (!webview())
1510 return;
1511
[email protected]26aa0482009-09-30 16:55:271512 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121513 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291514}
1515
1516void RenderView::OnRedo() {
1517 if (!webview())
1518 return;
1519
[email protected]26aa0482009-09-30 16:55:271520 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121521 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291522}
1523
1524void RenderView::OnCut() {
1525 if (!webview())
1526 return;
1527
[email protected]26aa0482009-09-30 16:55:271528 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121529 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291530}
1531
1532void RenderView::OnCopy() {
1533 if (!webview())
1534 return;
1535
[email protected]26aa0482009-09-30 16:55:271536 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121537 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291538}
1539
[email protected]c0cc3092009-09-12 08:27:271540#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351541void RenderView::OnCopyToFindPboard() {
1542 if (!webview())
1543 return;
1544
1545 // Since the find pasteboard supports only plain text, this can be simpler
1546 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271547 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351548 if (frame->hasSelection()) {
1549 string16 selection = frame->selectionAsText();
1550 RenderThread::current()->Send(
1551 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1552 }
1553
[email protected]afe3a1672009-11-17 19:04:121554 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351555}
[email protected]c0cc3092009-09-12 08:27:271556#endif
[email protected]a954bf72009-09-12 07:30:351557
initial.commit09911bf2008-07-26 23:55:291558void RenderView::OnPaste() {
1559 if (!webview())
1560 return;
1561
[email protected]26aa0482009-09-30 16:55:271562 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121563 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291564}
1565
[email protected]2a3a7762009-10-19 19:17:321566void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291567 if (!webview())
1568 return;
1569
[email protected]1ff7a032010-02-03 02:46:031570 WebFrame* frame = webview()->focusedFrame();
1571 if (!frame->hasSelection())
1572 frame->selectWordAroundCaret();
1573 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291574}
1575
[email protected]98324892009-09-09 21:16:051576void RenderView::OnAdvanceToNextMisspelling() {
1577 if (!webview())
1578 return;
[email protected]26aa0482009-09-30 16:55:271579 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051580 WebString::fromUTF8("AdvanceToNextMisspelling"));
1581}
1582
1583void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1584 if (!webview())
1585 return;
1586 // We need to tell the webView whether the spelling panel is visible or not so
1587 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261588 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271589 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051590 WebString::fromUTF8("ToggleSpellPanel"));
1591}
1592
[email protected]bbbd545c2008-12-15 20:18:041593void RenderView::OnToggleSpellCheck() {
1594 if (!webview())
1595 return;
1596
[email protected]26aa0482009-09-30 16:55:271597 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451598 frame->enableContinuousSpellChecking(
1599 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041600}
1601
initial.commit09911bf2008-07-26 23:55:291602void RenderView::OnDelete() {
1603 if (!webview())
1604 return;
1605
[email protected]26aa0482009-09-30 16:55:271606 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121607 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291608}
1609
1610void RenderView::OnSelectAll() {
1611 if (!webview())
1612 return;
1613
[email protected]26aa0482009-09-30 16:55:271614 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221615 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121616 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291617}
1618
1619void RenderView::OnSetInitialFocus(bool reverse) {
1620 if (!webview())
1621 return;
[email protected]26aa0482009-09-30 16:55:271622 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291623}
1624
[email protected]9b66f34bf2010-10-27 20:45:511625void RenderView::OnScrollFocusedEditableNodeIntoView() {
1626 if (!webview())
1627 return;
1628 WebFrame* focused_frame = webview()->focusedFrame();
1629 if (focused_frame) {
1630 WebDocument doc = focused_frame->document();
1631 if (!doc.isNull()) {
1632 WebNode node = doc.focusedNode();
1633 if (IsEditableNode(node))
1634 // TODO(varunjain): Change webkit API to scroll a particular node into
1635 // view and use that API here instead.
1636 webview()->scrollFocusedNodeIntoView();
1637 }
1638 }
1639}
1640
initial.commit09911bf2008-07-26 23:55:291641///////////////////////////////////////////////////////////////////////////////
1642
[email protected]433819d2010-01-30 20:20:011643void RenderView::SetContentSettings(const ContentSettings& settings) {
1644 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011645}
1646
initial.commit09911bf2008-07-26 23:55:291647// Tell the embedding application that the URL of the active page has changed
1648void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451649 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291650 DCHECK(ds);
1651
[email protected]726985e22009-06-18 21:09:281652 const WebURLRequest& request = ds->request();
1653 const WebURLRequest& original_request = ds->originalRequest();
1654 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291655
[email protected]daa8c58e2009-06-15 17:21:101656 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1657 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291658
1659 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281660 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291661 params.is_post = false;
1662 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071663 params.frame_id = frame->identifier();
[email protected]726985e22009-06-18 21:09:281664 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091665 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551666 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291667 // SSL state specified in the request takes precedence over the one in the
1668 // response.
1669 // So far this is only intended for error pages that are not expected to be
1670 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281671 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551672 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291673 } else {
[email protected]726985e22009-06-18 21:09:281674 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291675 }
1676
1677 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281678 if (ds->hasUnreachableURL()) {
1679 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291680 } else {
[email protected]726985e22009-06-18 21:09:281681 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291682 }
1683
[email protected]726985e22009-06-18 21:09:281684 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241685 params.should_update_history = !ds->hasUnreachableURL() &&
1686 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291687
[email protected]ce0e250d2009-10-23 21:00:351688 params.searchable_form_url = navigation_state->searchable_form_url();
1689 params.searchable_form_encoding =
1690 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291691
1692 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101693 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291694 if (password_form_data)
1695 params.password_form = *password_form_data;
1696
1697 params.gesture = navigation_gesture_;
1698 navigation_gesture_ = NavigationGestureUnknown;
1699
[email protected]dd7daa82009-08-10 05:46:451700 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291701 // Top-level navigation.
1702
[email protected]71b0d5d2010-02-15 05:43:071703 // Clear "block" flags for the new page. This needs to happen before any of
1704 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1705 // so that these functions can correctly detect that a piece of content
1706 // flipped from "not blocked" to "blocked".
1707 ClearBlockedContentSettings();
1708
[email protected]62d2a112010-04-07 00:53:021709 // Set content settings. Default them from the parent window if one exists.
1710 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011711 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541712 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011713 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011714 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011715
1716 // These content settings were merely recorded transiently for this load.
1717 // We can erase them now. If at some point we reload this page, the
1718 // browser will send us new, up-to-date content settings.
1719 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401720 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101721 // The opener's view is not guaranteed to be non-null (it could be
1722 // detached from its page but not yet destructed).
1723 if (WebView* opener_view = frame->opener()->view()) {
1724 RenderView* opener = FromWebView(opener_view);
1725 SetContentSettings(opener->current_content_settings_);
1726 }
[email protected]f85f0702010-01-30 09:31:011727 }
1728
[email protected]b75b8292010-10-01 07:28:251729 // Set zoom level, but don't do it for full-page plugin since they don't use
1730 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011731 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541732 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251733 if (webview()->mainFrame()->document().isPluginDocument()) {
1734 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251735 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251736 } else {
1737 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251738 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251739 }
1740
[email protected]f85f0702010-01-30 09:31:011741 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511742 // This zoom level was merely recorded transiently for this load. We can
1743 // erase it now. If at some point we reload this page, the browser will
1744 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011745 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511746 }
1747
[email protected]b75b8292010-10-01 07:28:251748 // Reset the zoom limits in case a plugin had changed them previously. This
1749 // will also call us back which will cause us to send a message to
1750 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251751 webview()->zoomLimitsChanged(
1752 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1753 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251754
initial.commit09911bf2008-07-26 23:55:291755 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551756 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291757
[email protected]daa8c58e2009-06-15 17:21:101758 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291759 if (!PageTransition::IsMainFrame(params.transition)) {
1760 // If the main frame does a load, it should not be reported as a subframe
1761 // navigation. This can occur in the following case:
1762 // 1. You're on a site with frames.
1763 // 2. You do a subframe navigation. This is stored with transition type
1764 // MANUAL_SUBFRAME.
1765 // 3. You navigate to some non-frame site, say, google.com.
1766 // 4. You navigate back to the page from step 2. Since it was initially
1767 // MANUAL_SUBFRAME, it will be that same transition type here.
1768 // We don't want that, because any navigation that changes the toplevel
1769 // frame should be tracked as a toplevel navigation (this allows us to
1770 // update the URL bar, etc).
1771 params.transition = PageTransition::LINK;
1772 }
1773
initial.commit09911bf2008-07-26 23:55:291774 // If we have a valid consumed client redirect source,
1775 // the page contained a client redirect (meta refresh, document.loc...),
1776 // so we set the referrer and transition to match.
1777 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041778 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291779 params.referrer = completed_client_redirect_src_;
1780 params.transition = static_cast<PageTransition::Type>(
1781 params.transition | PageTransition::CLIENT_REDIRECT);
1782 } else {
1783 // Bug 654101: the referrer will be empty on https->http transitions. It
1784 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281785 params.referrer = GURL(
1786 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291787 }
1788
[email protected]726985e22009-06-18 21:09:281789 string16 method = request.httpMethod();
1790 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291791 params.is_post = true;
1792
[email protected]c2a797d2009-09-21 16:46:321793 // Save some histogram data so we can compute the average memory used per
1794 // page load of the glyphs.
1795 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1796 webkit_glue::GetGlyphPageCount());
1797
[email protected]15cf526b2010-02-12 06:33:491798 // This message needs to be sent before any of allowScripts(),
1799 // allowImages(), allowPlugins() is called for the new page, so that when
1800 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1801 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291802 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1803 } else {
1804 // Subframe navigation: the type depends on whether this navigation
1805 // generated a new session history entry. When they do generate a session
1806 // history entry, it means the user initiated the navigation and we should
1807 // mark it as such. This test checks if this is the first time UpdateURL
1808 // has been called since WillNavigateToURL was called to initiate the load.
1809 if (page_id_ > last_page_id_sent_to_browser_)
1810 params.transition = PageTransition::MANUAL_SUBFRAME;
1811 else
1812 params.transition = PageTransition::AUTO_SUBFRAME;
1813
initial.commit09911bf2008-07-26 23:55:291814 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1815 }
1816
1817 last_page_id_sent_to_browser_ =
1818 std::max(last_page_id_sent_to_browser_, page_id_);
1819
1820 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101821 // we don't want the transition type to persist. Just clear it.
1822 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501823
[email protected]af15bed2010-08-25 21:12:091824 // Check if the navigation was within the same page, in which case we don't
1825 // want to clear the accessibility cache.
1826 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351827 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141828 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501829 }
initial.commit09911bf2008-07-26 23:55:291830}
1831
1832// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171833void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291834 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171835 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171836 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171837 routing_id_,
1838 page_id_,
1839 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1840 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171841 }
initial.commit09911bf2008-07-26 23:55:291842}
1843
1844void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401845 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291846 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271847 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291848 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301849 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291850 last_encoding_name_ = encoding_name;
1851
[email protected]e38f40152008-09-12 23:08:301852 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291853 }
1854}
1855
[email protected]e15f680732010-11-23 22:30:201856// Sends the last committed session history state to the browser so it will be
1857// saved before we navigate to a new page. This must be called *before* the
1858// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291859void RenderView::UpdateSessionHistory(WebFrame* frame) {
1860 // If we have a valid page ID at this point, then it corresponds to the page
1861 // we are navigating away from. Otherwise, this is the first navigation, so
1862 // there is no past session history to record.
1863 if (page_id_ == -1)
1864 return;
1865
[email protected]ca948a22009-06-25 19:36:171866 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271867 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171868 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291869 return;
[email protected]ca948a22009-06-25 19:36:171870
1871 Send(new ViewHostMsg_UpdateState(
1872 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291873}
1874
[email protected]3d9689372009-09-10 04:29:171875void RenderView::OpenURL(
1876 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1877 Send(new ViewHostMsg_OpenURL(
1878 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1879}
1880
[email protected]79dbc662009-09-04 05:42:511881// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291882
initial.commit09911bf2008-07-26 23:55:291883void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281884 const WebURLRequest& failed_request,
1885 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291886 const std::string& html,
1887 bool replace) {
[email protected]726985e22009-06-18 21:09:281888 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291889 std::string alt_html;
[email protected]07b493512010-08-27 15:39:291890 ExtensionRendererInfo* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291891 if (html.empty()) {
1892 // Use a local error page.
1893 int resource_id;
1894 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111895
[email protected]81654282010-10-04 17:08:061896 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
[email protected]5351dbc2010-08-27 15:22:111897 extension = ExtensionRendererInfo::GetByURL(failed_url);
1898 if (extension) {
[email protected]3f853a52010-09-13 19:15:081899 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1900 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111901
1902 // TODO(erikkay): Should we use a different template for different
1903 // error messages?
1904 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291905 } else {
[email protected]3f853a52010-09-13 19:15:081906 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1907 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111908 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081909 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111910 } else {
[email protected]3f853a52010-09-13 19:15:081911 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111912 }
[email protected]75891fe2010-11-20 15:55:181913 resource_id = IDR_NET_ERROR_HTML;
initial.commit09911bf2008-07-26 23:55:291914 }
initial.commit09911bf2008-07-26 23:55:291915
1916 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1917 } else {
1918 alt_html = html;
1919 }
1920
[email protected]dd7daa82009-08-10 05:46:451921 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361922 GURL(chrome::kUnreachableWebDataURL),
[email protected]e6f546c32009-07-01 17:12:551923 failed_url,
1924 replace);
initial.commit09911bf2008-07-26 23:55:291925}
1926
[email protected]7ccddb8c2009-08-04 17:36:551927void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031928 if (!dom_automation_controller_.get()) {
1929 dom_automation_controller_.reset(new DomAutomationController());
1930 }
1931 dom_automation_controller_->set_message_sender(this);
1932 dom_automation_controller_->set_routing_id(routing_id_);
1933 dom_automation_controller_->BindToJavascript(frame,
[email protected]906690b2010-12-03 18:11:251934 "domAutomationController");
initial.commit09911bf2008-07-26 23:55:291935}
1936
initial.commit09911bf2008-07-26 23:55:291937bool RenderView::RunJavaScriptMessage(int type,
1938 const std::wstring& message,
1939 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071940 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291941 std::wstring* result) {
1942 bool success = false;
1943 std::wstring result_temp;
1944 if (!result)
1945 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291946
[email protected]12636df2009-09-28 22:32:211947 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1948 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291949 return success;
1950}
1951
[email protected]c1f50aa2010-02-18 03:46:571952bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1953 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1954 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1955 // it is particularly important that we do not call willEnterModalLoop as
1956 // that would defer resource loads for the dialog itself.
1957 if (RenderThread::current()) // Will be NULL during unit tests.
1958 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1959
1960 message->EnableMessagePumping(); // Runs a nested message loop.
1961 return Send(message);
1962}
1963
[email protected]2de7e002010-10-11 22:58:201964void RenderView::AddGURLSearchProvider(
1965 const GURL& osd_url,
1966 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
initial.commit09911bf2008-07-26 23:55:291967 if (!osd_url.is_empty())
1968 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
[email protected]2de7e002010-10-11 22:58:201969 provider_type));
initial.commit09911bf2008-07-26 23:55:291970}
1971
[email protected]95056b582010-02-18 01:29:241972void RenderView::OnAutoFillSuggestionsReturned(
1973 int query_id,
[email protected]8f6e6582010-04-09 02:03:071974 const std::vector<string16>& values,
[email protected]0a055452010-07-16 17:34:391975 const std::vector<string16>& labels,
[email protected]a53e06832010-07-28 22:46:411976 const std::vector<string16>& icons,
[email protected]0a055452010-07-16 17:34:391977 const std::vector<int>& unique_ids) {
[email protected]6a8ddba52010-09-05 04:38:061978 autofill_helper_->SuggestionsReceived(
[email protected]a53e06832010-07-28 22:46:411979 query_id, values, labels, icons, unique_ids);
[email protected]0ebf3872008-11-07 21:35:031980}
1981
[email protected]45c6e532010-03-15 23:51:241982void RenderView::OnAutoFillFormDataFilled(int query_id,
1983 const webkit_glue::FormData& form) {
[email protected]6a8ddba52010-09-05 04:38:061984 autofill_helper_->FormDataFilled(query_id, form);
[email protected]c83641732010-02-20 01:04:481985}
1986
[email protected]e8345242010-05-06 03:00:401987void RenderView::OnAllowScriptToClose(bool script_can_close) {
1988 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311989}
1990
initial.commit09911bf2008-07-26 23:55:291991uint32 RenderView::GetCPBrowsingContext() {
1992 uint32 context = 0;
1993 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1994 return context;
1995}
1996
[email protected]2de7e002010-10-11 22:58:201997void RenderView::AddSearchProvider(
1998 const std::string& url,
1999 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
2000 if (provider_type.type ==
2001 ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER &&
2002 !webview()->mainFrame()->isProcessingUserGesture())
2003 return;
2004
2005 AddGURLSearchProvider(GURL(url), provider_type);
initial.commit09911bf2008-07-26 23:55:292006}
2007
[email protected]155f35e2010-07-17 00:30:182008ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:252009RenderView::GetSearchProviderInstallState(WebFrame* frame,
2010 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:182011 GURL inquiry_url = GURL(url);
2012 if (inquiry_url.is_empty())
2013 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:252014
[email protected]155f35e2010-07-17 00:30:182015 ViewHostMsg_GetSearchProviderInstallState_Params install;
2016 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:252017 frame->url(),
[email protected]155f35e2010-07-17 00:30:182018 inquiry_url,
2019 &install));
2020 return install;
2021}
2022
[email protected]f103ab72009-09-02 17:10:592023void RenderView::OnMissingPluginStatus(
2024 WebPluginDelegateProxy* delegate,
2025 int status) {
[email protected]6c8afae52009-01-22 02:24:572026#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:592027 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:292028 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:502029 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:592030 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:292031 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2032 }
2033 } else {
2034 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
2035 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:502036 if (status ==
2037 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:292038 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2039 }
2040 }
[email protected]6c8afae52009-01-22 02:24:572041#else
[email protected]76c3b312010-05-20 21:38:292042 // TODO(port): Implement the infobar that accompanies the default plugin.
2043 // Linux: http://crbug.com/10952
2044 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:572045 NOTIMPLEMENTED();
2046#endif
initial.commit09911bf2008-07-26 23:55:292047}
2048
[email protected]48c9cf2d2009-09-16 16:47:522049// WebKit::WebViewClient ------------------------------------------------------
2050
[email protected]8ab04652010-06-12 02:47:262051WebView* RenderView::createView(
2052 WebFrame* creator,
2053 const WebWindowFeatures& features,
2054 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:522055 // Check to make sure we aren't overloading on popups.
2056 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2057 return NULL;
2058
2059 // This window can't be closed from a window.close() call until we receive a
2060 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:402061 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:522062
[email protected]8ab04652010-06-12 02:47:262063 ViewHostMsg_CreateWindow_Params params;
2064 params.opener_id = routing_id_;
2065 params.user_gesture = creator->isProcessingUserGesture();
2066 params.window_container_type = WindowFeaturesToContainerType(features);
2067 params.session_storage_namespace_id = session_storage_namespace_id_;
2068 params.frame_name = frame_name;
2069
[email protected]48c9cf2d2009-09-16 16:47:522070 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:342071 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:262072 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:522073
[email protected]48c9cf2d2009-09-16 16:47:522074 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:262075 new ViewHostMsg_CreateWindow(params,
2076 &routing_id,
2077 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212078 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522079 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522080
[email protected]48c9cf2d2009-09-16 16:47:522081 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:422082 0,
[email protected]12636df2009-09-28 22:32:212083 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:522084 renderer_preferences_,
2085 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:212086 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:342087 routing_id,
[email protected]8ab04652010-06-12 02:47:262088 cloned_session_storage_namespace_id,
2089 frame_name);
2090 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522091
[email protected]007a848b2009-10-26 15:55:462092 // Record whether the creator frame is trying to suppress the opener field.
2093 view->opener_suppressed_ = opener_suppressed;
2094
[email protected]48c9cf2d2009-09-16 16:47:522095 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:092096 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:522097 if (!creator_url.is_valid() || !creator_url.IsStandard())
2098 creator_url = GURL();
2099 view->creator_url_ = creator_url;
2100
2101 // Copy over the alternate error page URL so we can have alt error pages in
2102 // the new render view (we don't need the browser to send the URL back down).
2103 view->alternate_error_page_url_ = alternate_error_page_url_;
2104
2105 return view->webview();
2106}
2107
[email protected]3e2b375b2010-04-07 17:03:122108WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:522109 RenderWidget* widget = RenderWidget::Create(routing_id_,
2110 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:122111 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:522112 return widget->webwidget();
2113}
2114
2115WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:442116 // TODO(jcivelli): Remove this deprecated method when its been removed from
2117 // the WebViewClient interface. It's been replaced by
2118 // createExternalPopupMenu.
2119 NOTREACHED();
2120 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522121}
2122
[email protected]caf706f2010-10-26 17:54:082123WebExternalPopupMenu* RenderView::createExternalPopupMenu(
2124 const WebPopupMenuInfo& popup_menu_info,
2125 WebExternalPopupMenuClient* popup_menu_client) {
2126 DCHECK(!external_popup_menu_.get());
2127 external_popup_menu_.reset(
2128 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2129 return external_popup_menu_.get();
2130}
2131
[email protected]484955942010-08-19 16:13:182132WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) {
2133 RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_,
2134 render_thread_,
2135 popup_type);
2136 return widget->webwidget();
2137}
2138
[email protected]0bd753682010-12-16 18:15:522139webkit::ppapi::FullscreenContainer*
2140RenderView::CreatePepperFullscreenContainer(
2141 webkit::ppapi::PluginInstance* plugin) {
[email protected]79c7bed2010-09-14 22:28:392142 RenderWidgetFullscreenPepper* widget =
2143 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
2144 widget->show(WebKit::WebNavigationPolicyIgnore);
2145 return widget->container();
2146}
2147
[email protected]68c50e52010-05-12 11:14:392148WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:342149 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:392150 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:292151 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
2152 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
2153 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342154}
2155
[email protected]48c9cf2d2009-09-16 16:47:522156void RenderView::didAddMessageToConsole(
2157 const WebConsoleMessage& message, const WebString& source_name,
2158 unsigned source_line) {
2159 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2160 UTF16ToWideHack(message.text),
2161 static_cast<int32>(source_line),
2162 UTF16ToWideHack(source_name)));
2163}
2164
2165void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:582166 DCHECK(frame);
[email protected]212a49d2010-10-25 18:23:472167 if (CommandLine::ForCurrentProcess()->HasSwitch(
2168 switches::kEnablePrintPreview)) {
2169 Print(frame, true, true);
2170 } else {
2171 Print(frame, true, false);
2172 }
[email protected]48c9cf2d2009-09-16 16:47:522173}
2174
[email protected]3354d3e2010-06-10 19:53:022175WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
2176 return notification_provider_.get();
2177}
2178
[email protected]48c9cf2d2009-09-16 16:47:522179void RenderView::didStartLoading() {
2180 if (is_loading_) {
2181 DLOG(WARNING) << "didStartLoading called while loading";
2182 return;
2183 }
2184
2185 is_loading_ = true;
2186 // Clear the pointer so that we can assign it only when there is an unknown
2187 // plugin on a page.
2188 first_default_plugin_.reset();
2189
2190 Send(new ViewHostMsg_DidStartLoading(routing_id_));
2191}
2192
2193void RenderView::didStopLoading() {
2194 if (!is_loading_) {
2195 DLOG(WARNING) << "DidStopLoading called while not loading";
2196 return;
2197 }
2198
2199 is_loading_ = false;
2200
2201 // NOTE: For now we're doing the safest thing, and sending out notification
2202 // when done loading. This currently isn't an issue as the favicon is only
2203 // displayed when done loading. Ideally we would send notification when
2204 // finished parsing the head, but webkit doesn't support that yet.
2205 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:272206 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:522207 if (!favicon_url.is_empty())
2208 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
2209
[email protected]26aa0482009-09-30 16:55:272210 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]2de7e002010-10-11 22:58:202211 ViewHostMsg_PageHasOSDD_Type::Autodetected());
[email protected]48c9cf2d2009-09-16 16:47:522212
2213 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2214
[email protected]90109412010-12-15 17:14:242215 if (load_progress_tracker_ != NULL)
2216 load_progress_tracker_->DidStopLoading();
2217
[email protected]f9f4841b2010-03-20 05:41:422218 MessageLoop::current()->PostDelayedTask(
2219 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302220 page_info_method_factory_.NewRunnableMethod(
2221 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:372222 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:522223}
2224
[email protected]90109412010-12-15 17:14:242225void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
2226 if (load_progress_tracker_ != NULL)
2227 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2228}
2229
[email protected]f55039a2010-02-17 14:12:062230bool RenderView::isSmartInsertDeleteEnabled() {
2231#if defined(OS_MACOSX)
2232 return true;
2233#else
2234 return false;
2235#endif
2236}
2237
[email protected]04fc9482009-09-18 22:13:032238bool RenderView::isSelectTrailingWhitespaceEnabled() {
2239#if defined(OS_WIN)
2240 return true;
2241#else
2242 return false;
2243#endif
2244}
2245
[email protected]04fc9482009-09-18 22:13:032246void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]eef99c22010-08-17 05:55:162247#if defined(USE_X11) || defined(OS_MACOSX)
[email protected]04fc9482009-09-18 22:13:032248 if (!handling_input_event_)
2249 return;
2250 // TODO(estade): investigate incremental updates to the selection so that we
2251 // don't send the entire selection over IPC every time.
2252 if (!is_empty_selection) {
2253 // Sometimes we get repeated didChangeSelection calls from webkit when
2254 // the selection hasn't actually changed. We don't want to report these
2255 // because it will cause us to continually claim the X clipboard.
2256 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:272257 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:032258 if (this_selection == last_selection_)
2259 return;
2260
2261 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2262 this_selection));
2263 last_selection_ = this_selection;
2264 } else {
2265 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:162266 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2267 last_selection_));
[email protected]04fc9482009-09-18 22:13:032268 }
2269#endif
2270}
2271
2272void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122273 const std::string& name = UTF16ToUTF8(command_name);
2274 if (StartsWithASCII(name, "Move", true) ||
2275 StartsWithASCII(name, "Insert", true) ||
2276 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032277 return;
2278 UserMetricsRecordAction(name);
2279}
2280
[email protected]03f57072010-07-14 17:36:082281void RenderView::textFieldDidEndEditing(
2282 const WebKit::WebInputElement& element) {
[email protected]6a8ddba52010-09-05 04:38:062283 password_autocomplete_manager_->TextFieldDidEndEditing(element);
[email protected]03f57072010-07-14 17:36:082284}
2285
2286void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) {
[email protected]e47aec52010-08-12 00:50:302287 // We post a task for doing the AutoFill as the caret position is not set
2288 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
2289 // it is needed to trigger autofill.
2290 autofill_method_factory_.RevokeAll();
2291 MessageLoop::current()->PostTask(
2292 FROM_HERE,
2293 autofill_method_factory_.NewRunnableMethod(
2294 &RenderView::TextFieldDidChangeImpl, element));
[email protected]03f57072010-07-14 17:36:082295}
2296
[email protected]e47aec52010-08-12 00:50:302297void RenderView::TextFieldDidChangeImpl(
2298 const WebKit::WebInputElement& element) {
[email protected]6a8ddba52010-09-05 04:38:062299 if (password_autocomplete_manager_->TextDidChangeInTextField(element))
[email protected]e47aec52010-08-12 00:50:302300 return;
[email protected]6a8ddba52010-09-05 04:38:062301 autofill_helper_->TextDidChangeInTextField(element);
[email protected]e47aec52010-08-12 00:50:302302}
2303
[email protected]54ec7f82010-10-21 22:32:512304void RenderView::SendPendingAccessibilityNotifications() {
2305 if (!accessibility_.get())
2306 return;
2307
2308 if (pending_accessibility_notifications_.empty())
2309 return;
2310
2311 // Send all pending accessibility notifications.
2312 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
2313 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
2314 RendererAccessibilityNotification& notification =
2315 pending_accessibility_notifications_[i];
2316 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
2317 if (!obj.isValid())
2318 continue;
2319
2320 ViewHostMsg_AccessibilityNotification_Params param;
2321 param.notification_type = pending_accessibility_notifications_[i].type;
[email protected]70eee342010-11-05 01:59:372322 param.acc_obj = WebAccessibility(
2323 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:512324 notifications.push_back(param);
2325 }
2326 pending_accessibility_notifications_.clear();
2327 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
2328 accessibility_ack_pending_ = true;
2329}
2330
[email protected]03f57072010-07-14 17:36:082331void RenderView::textFieldDidReceiveKeyDown(
2332 const WebKit::WebInputElement& element,
2333 const WebKit::WebKeyboardEvent& event) {
[email protected]6a8ddba52010-09-05 04:38:062334 password_autocomplete_manager_->TextFieldHandlingKeyDown(element, event);
[email protected]7aab84b2010-11-20 01:04:262335 autofill_helper_->KeyDownInTextField(element, event);
[email protected]03f57072010-07-14 17:36:082336}
2337
[email protected]b2528b72009-09-24 06:57:102338bool RenderView::handleCurrentKeyboardEvent() {
2339 if (edit_commands_.empty())
2340 return false;
2341
[email protected]26aa0482009-09-30 16:55:272342 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102343 if (!frame)
2344 return false;
2345
2346 EditCommands::iterator it = edit_commands_.begin();
2347 EditCommands::iterator end = edit_commands_.end();
2348
[email protected]507b33ea2009-09-29 03:56:512349 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102350 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332351 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2352 // key (but it's the exception). Once one edit command is not executed, it
2353 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102354 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2355 WebString::fromUTF8(it->value)))
2356 break;
[email protected]507b33ea2009-09-29 03:56:512357 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102358 }
2359
[email protected]507b33ea2009-09-29 03:56:512360 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102361}
2362
[email protected]2a3a7762009-10-19 19:17:322363void RenderView::spellCheck(const WebString& text,
2364 int& misspelled_offset,
2365 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:562366 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:462367
[email protected]85c55dc2009-11-06 03:05:462368 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:172369 RenderThread* thread = RenderThread::current();
2370 // Will be NULL during unit tests.
2371 if (thread) {
[email protected]c27324b2009-11-19 22:44:292372 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:172373 word.c_str(), word.size(), document_tag_,
2374 &misspelled_offset, &misspelled_length, NULL);
2375 }
[email protected]1dbafaf72009-09-23 19:43:562376}
2377
2378WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322379 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562380 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:262381 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:562382 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:172383 RenderThread* thread = RenderThread::current();
2384 // Will be NULL during unit tests.
2385 if (thread) {
2386 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:292387 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:172388 word, document_tag_);
2389 }
[email protected]1dbafaf72009-09-23 19:43:562390 }
[email protected]2a3a7762009-10-19 19:17:322391 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562392}
2393
[email protected]c49085c72009-10-02 16:28:562394void RenderView::showSpellingUI(bool show) {
2395 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2396}
2397
[email protected]8922e1f2009-10-03 05:01:262398bool RenderView::isShowingSpellingUI() {
2399 return spelling_panel_visible_;
2400}
2401
[email protected]1dbafaf72009-09-23 19:43:562402void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322403 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2404 word));
[email protected]1dbafaf72009-09-23 19:43:562405}
2406
[email protected]a1128322009-10-06 18:38:462407bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352408 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472409 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352410 // Do not open the file dialog in a hidden RenderView.
2411 if (is_hidden())
2412 return false;
[email protected]cdaf8d02010-03-30 19:52:472413 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262414 if (params.directory)
2415 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2416 else if (params.multiSelect)
2417 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2418 else
2419 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472420 ipc_params.title = params.title;
2421 ipc_params.default_file_name =
2422 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592423 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472424
2425 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462426}
2427
[email protected]48c9cf2d2009-09-16 16:47:522428void RenderView::runModalAlertDialog(
2429 WebFrame* frame, const WebString& message) {
2430 RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert,
2431 UTF16ToWideHack(message),
2432 std::wstring(),
2433 frame->url(),
2434 NULL);
2435}
2436
2437bool RenderView::runModalConfirmDialog(
2438 WebFrame* frame, const WebString& message) {
2439 return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm,
2440 UTF16ToWideHack(message),
2441 std::wstring(),
2442 frame->url(),
2443 NULL);
2444}
2445
2446bool RenderView::runModalPromptDialog(
2447 WebFrame* frame, const WebString& message, const WebString& default_value,
2448 WebString* actual_value) {
2449 std::wstring result;
2450 bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt,
2451 UTF16ToWideHack(message),
2452 UTF16ToWideHack(default_value),
2453 frame->url(),
2454 &result);
2455 if (ok)
2456 actual_value->assign(WideToUTF16Hack(result));
2457 return ok;
2458}
2459
2460bool RenderView::runModalBeforeUnloadDialog(
2461 WebFrame* frame, const WebString& message) {
2462 bool success = false;
2463 // This is an ignored return value, but is included so we can accept the same
2464 // response as RunJavaScriptMessage.
2465 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212466 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522467 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212468 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522469 return success;
2470}
2471
[email protected]79e37442009-10-09 18:17:442472void RenderView::showContextMenu(
2473 WebFrame* frame, const WebContextMenuData& data) {
[email protected]6a8b86c2010-12-09 05:24:302474 custom_menu_listener_ = NULL;
[email protected]c27324b2009-11-19 22:44:292475 ContextMenuParams params = ContextMenuParams(data);
2476 if (!params.misspelled_word.empty() && RenderThread::current()) {
2477 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042478 bool spelled_right = RenderThread::current()->spellchecker()->
2479 SpellCheckWord(
2480 params.misspelled_word.c_str(), params.misspelled_word.size(),
2481 document_tag_,
2482 &misspelled_offset, &misspelled_length,
2483 &params.dictionary_suggestions);
2484 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292485 params.misspelled_word.clear();
2486 }
[email protected]216932c2010-08-26 21:44:272487 // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do
2488 // it. We replace it with an empty GURL so the appropriate items are disabled
2489 // in the context menu.
2490 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2491 // data encoded images. We should have a way to save them.
2492 if (params.src_url.spec().size() > chrome::kMaxURLChars)
2493 params.src_url = GURL();
[email protected]c27324b2009-11-19 22:44:292494 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442495}
2496
[email protected]52f139e2c2010-06-11 16:56:092497bool RenderView::supportsFullscreen() {
2498 return CommandLine::ForCurrentProcess()->HasSwitch(
2499 switches::kEnableVideoFullscreen);
2500}
2501
2502void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2503 NOTIMPLEMENTED();
2504}
2505
2506void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2507 NOTIMPLEMENTED();
2508}
2509
[email protected]48c9cf2d2009-09-16 16:47:522510void RenderView::setStatusText(const WebString& text) {
2511}
2512
[email protected]163f8242009-10-30 20:19:552513void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582514 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522515 if (latest_url == target_url_)
2516 return;
[email protected]163f8242009-10-30 20:19:552517
[email protected]48c9cf2d2009-09-16 16:47:522518 // Tell the browser to display a destination link.
2519 if (target_url_status_ == TARGET_INFLIGHT ||
2520 target_url_status_ == TARGET_PENDING) {
2521 // If we have a request in-flight, save the URL to be sent when we
2522 // receive an ACK to the in-flight request. We can happily overwrite
2523 // any existing pending sends.
2524 pending_target_url_ = latest_url;
2525 target_url_status_ = TARGET_PENDING;
2526 } else {
2527 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2528 target_url_ = latest_url;
2529 target_url_status_ = TARGET_INFLIGHT;
2530 }
2531}
2532
[email protected]882daa92009-11-05 16:31:312533void RenderView::StartNavStateSyncTimerIfNecessary() {
2534 int delay;
2535 if (send_content_state_immediately_)
2536 delay = 0;
2537 else if (is_hidden())
2538 delay = kDelaySecondsForContentStateSyncHidden;
2539 else
2540 delay = kDelaySecondsForContentStateSync;
2541
2542 if (nav_state_sync_timer_.IsRunning()) {
2543 // The timer is already running. If the delay of the timer maches the amount
2544 // we want to delay by, then return. Otherwise stop the timer so that it
2545 // gets started with the right delay.
2546 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2547 return;
2548 nav_state_sync_timer_.Stop();
2549 }
2550
2551 nav_state_sync_timer_.Start(
2552 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2553}
2554
[email protected]163f8242009-10-30 20:19:552555void RenderView::setMouseOverURL(const WebURL& url) {
2556 mouse_over_url_ = GURL(url);
2557 UpdateTargetURL(mouse_over_url_, focus_url_);
2558}
2559
2560void RenderView::setKeyboardFocusURL(const WebURL& url) {
2561 focus_url_ = GURL(url);
2562 UpdateTargetURL(focus_url_, mouse_over_url_);
2563}
2564
[email protected]48c9cf2d2009-09-16 16:47:522565void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2566 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2567 hint));
2568}
2569
[email protected]c27ae592010-03-18 15:24:412570void RenderView::startDragging(const WebDragData& data,
2571 WebDragOperationsMask mask,
2572 const WebImage& image,
2573 const WebPoint& imageOffset) {
2574#if WEBKIT_USING_SKIA
2575 SkBitmap bitmap(image.getSkBitmap());
2576#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332577 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412578#endif
2579
[email protected]48c9cf2d2009-09-16 16:47:522580 Send(new ViewHostMsg_StartDragging(routing_id_,
2581 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412582 mask,
2583 bitmap,
2584 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522585}
2586
[email protected]28b92df2009-09-25 17:35:452587bool RenderView::acceptsLoadDrops() {
2588 return renderer_preferences_.can_accept_load_drops;
2589}
2590
[email protected]48c9cf2d2009-09-16 16:47:522591void RenderView::focusNext() {
2592 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2593}
2594
2595void RenderView::focusPrevious() {
2596 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2597}
2598
[email protected]08e9e132010-06-01 16:58:492599void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512600 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072601
2602 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2603 // TODO(ctguil): Make WebKit send this notification.
2604 // When focus is cleared notify accessibility that the document is focused.
2605 postAccessibilityNotification(
2606 webview()->accessibilityObject(),
2607 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2608 }
[email protected]08e9e132010-06-01 16:58:492609}
2610
[email protected]48c9cf2d2009-09-16 16:47:522611void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522612 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2613}
2614
2615int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002616 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522617}
2618
2619int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002620 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522621}
2622
[email protected]c4e98902010-06-01 10:20:142623void RenderView::didUpdateInspectorSetting(const WebString& key,
2624 const WebString& value) {
2625 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2626 key.utf8(),
2627 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262628}
2629
[email protected]acca2a12009-10-16 03:53:392630void RenderView::removeAutofillSuggestions(const WebString& name,
2631 const WebString& value) {
[email protected]6a8ddba52010-09-05 04:38:062632 autofill_helper_->RemoveAutocompleteSuggestion(name, value);
[email protected]acca2a12009-10-16 03:53:392633}
2634
[email protected]18ca9a6b2010-06-02 19:05:182635void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node,
2636 const WebKit::WebString& value,
[email protected]1cf47dd52010-06-10 22:41:202637 const WebKit::WebString& label,
[email protected]0a055452010-07-16 17:34:392638 int unique_id,
[email protected]1cf47dd52010-06-10 22:41:202639 unsigned index) {
[email protected]a5e84bd2010-09-14 22:23:362640 autofill_helper_->DidAcceptAutoFillSuggestion(node, value, unique_id, index);
[email protected]18ca9a6b2010-06-02 19:05:182641}
[email protected]c83641732010-02-20 01:04:482642
[email protected]18ca9a6b2010-06-02 19:05:182643void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node,
2644 const WebKit::WebString& value,
[email protected]0a055452010-07-16 17:34:392645 const WebKit::WebString& label,
2646 int unique_id) {
[email protected]a5e84bd2010-09-14 22:23:362647 autofill_helper_->DidSelectAutoFillSuggestion(node, unique_id);
[email protected]18ca9a6b2010-06-02 19:05:182648}
2649
2650void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) {
[email protected]6a8ddba52010-09-05 04:38:062651 autofill_helper_->DidClearAutoFillSelection(node);
[email protected]c83641732010-02-20 01:04:482652}
2653
[email protected]03f57072010-07-14 17:36:082654void RenderView::didAcceptAutocompleteSuggestion(
2655 const WebKit::WebInputElement& user_element) {
[email protected]6a8ddba52010-09-05 04:38:062656 bool result = password_autocomplete_manager_->FillPassword(user_element);
[email protected]03f57072010-07-14 17:36:082657 // Since this user name was selected from a suggestion list, we should always
2658 // have password for it.
2659 DCHECK(result);
[email protected]03f57072010-07-14 17:36:082660}
2661
[email protected]79dbc662009-09-04 05:42:512662// WebKit::WebWidgetClient ----------------------------------------------------
2663
[email protected]ea42e7782010-08-23 23:58:122664void RenderView::didFocus() {
2665 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2666 // we won't have to test for user gesture anymore and we can
2667 // move that code back to render_widget.cc
2668 if (webview() && webview()->mainFrame() &&
2669 webview()->mainFrame()->isProcessingUserGesture()) {
2670 Send(new ViewHostMsg_Focus(routing_id_));
2671 }
2672}
2673
2674void RenderView::didBlur() {
2675 // TODO(jcivelli): see TODO above in didFocus().
2676 if (webview() && webview()->mainFrame() &&
2677 webview()->mainFrame()->isProcessingUserGesture()) {
2678 Send(new ViewHostMsg_Blur(routing_id_));
2679 }
2680}
2681
initial.commit09911bf2008-07-26 23:55:292682// We are supposed to get a single call to Show for a newly created RenderView
2683// that was created via RenderView::CreateWebView. So, we wait until this
2684// point to dispatch the ShowView message.
2685//
2686// This method provides us with the information about how to display the newly
2687// created RenderView (i.e., as a constrained popup or as a new tab).
2688//
[email protected]4873c7d2009-07-16 06:36:282689void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292690 DCHECK(!did_show_) << "received extraneous Show call";
2691 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2692
2693 if (did_show_)
2694 return;
2695 did_show_ = true;
2696
[email protected]4026ce1e2010-09-14 19:35:042697 // Extensions and apps always allowed to create unrequested popups. The second
2698 // check is necessary to include content scripts.
2699 if (ExtensionRendererInfo::GetByURL(creator_url_) ||
2700 bindings_utils::GetInfoForCurrentContext()) {
2701 opened_by_user_gesture_ = true;
2702 }
2703
[email protected]28295ec2009-10-16 05:34:332704 // Force new windows to a popup if they were not opened with a user gesture.
2705 if (!opened_by_user_gesture_) {
2706 // We exempt background tabs for compat with older versions of Chrome.
2707 // TODO(darin): This seems bogus. These should have a user gesture, so
2708 // we probably don't need this check.
2709 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2710 policy = WebKit::WebNavigationPolicyNewPopup;
2711 }
2712
initial.commit09911bf2008-07-26 23:55:292713 // NOTE: initial_pos_ may still have its default values at this point, but
2714 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2715 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282716 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2717 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292718 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242719 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292720}
2721
[email protected]4873c7d2009-07-16 06:36:282722void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132723 // Cancel pending translations so that the translate_helper_ does not attempt
2724 // to access the WebView.
2725 translate_helper_.CancelPendingTranslation();
2726
[email protected]3ead1322010-11-19 20:01:002727 // Same for the phishing classifier.
2728 if (phishing_delegate_.get())
2729 phishing_delegate_->CancelPendingClassification();
2730
[email protected]e8345242010-05-06 03:00:402731 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282732 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312733}
2734
[email protected]4873c7d2009-07-16 06:36:282735void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292736 DCHECK(did_show_) << "should already have shown the view";
2737
[email protected]c1f50aa2010-02-18 03:46:572738 // We must keep WebKit's shared timer running in this case in order to allow
2739 // showModalDialog to function properly.
2740 //
2741 // TODO(darin): WebKit should really be smarter about suppressing events and
2742 // timers so that we do not need to manage the shared timer in such a heavy
2743 // handed manner.
2744 //
2745 if (RenderThread::current()) // Will be NULL during unit tests.
2746 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2747
[email protected]12636df2009-09-28 22:32:212748 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292749}
2750
[email protected]3d9689372009-09-10 04:29:172751// WebKit::WebFrameClient -----------------------------------------------------
2752
[email protected]00152e92010-07-19 11:47:402753WebPlugin* RenderView::createPlugin(WebFrame* frame,
2754 const WebPluginParams& params) {
[email protected]6fdd4182010-10-14 23:59:262755 bool found = false;
[email protected]414508d2010-11-02 10:45:392756 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
[email protected]55126132010-08-19 14:53:282757 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]191eb3f72010-12-21 06:27:502758 webkit::npapi::WebPluginInfo info;
[email protected]7a13e792010-08-03 08:18:242759 GURL url(params.url);
[email protected]6fdd4182010-10-14 23:59:262760 std::string actual_mime_type;
2761 Send(new ViewHostMsg_GetPluginInfo(url,
2762 frame->top()->url(),
2763 params.mimeType.utf8(),
2764 &found,
2765 &info,
[email protected]44fda5c2010-11-02 10:50:542766 &plugin_setting,
[email protected]6fdd4182010-10-14 23:59:262767 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242768
[email protected]6fdd4182010-10-14 23:59:262769 if (!found)
[email protected]0cdafff2010-07-26 09:54:372770 return NULL;
[email protected]414508d2010-11-02 10:45:392771 DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
[email protected]4e0616e2010-05-28 14:55:532772
[email protected]191eb3f72010-12-21 06:27:502773 const webkit::npapi::PluginGroup* group =
2774 webkit::npapi::PluginList::Singleton()->GetPluginGroup(info);
[email protected]79ce1032010-12-07 13:29:412775 DCHECK(group != NULL);
[email protected]851b1eb2010-08-09 13:32:292776
[email protected]3c2826852010-12-16 19:09:142777 if (cmd->HasSwitch(switches::kBlockOutdatedPlugins) &&
2778 group->IsVulnerable()) {
2779 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2780 group->GetGroupName(),
2781 GURL(group->GetUpdateURL())));
2782 return CreatePluginPlaceholder(frame,
2783 params,
2784 *group,
[email protected]2e34ab3f2010-12-17 05:47:372785 IDR_BLOCKED_PLUGIN_HTML,
[email protected]3c2826852010-12-16 19:09:142786 IDS_PLUGIN_OUTDATED);
[email protected]851b1eb2010-08-09 13:32:292787 }
[email protected]3c2826852010-12-16 19:09:142788 if (!info.enabled)
2789 return NULL;
[email protected]851b1eb2010-08-09 13:32:292790
[email protected]414508d2010-11-02 10:45:392791 ContentSetting host_setting =
2792 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS];
[email protected]191eb3f72010-12-21 06:27:502793 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName ||
[email protected]414508d2010-11-02 10:45:392794 plugin_setting == CONTENT_SETTING_ALLOW ||
2795 host_setting == CONTENT_SETTING_ALLOW) {
[email protected]0bd753682010-12-16 18:15:522796 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:452797 pepper_delegate_.CreatePepperPlugin(info.path));
2798 if (pepper_module)
2799 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]6fdd4182010-10-14 23:59:262800 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]0cdafff2010-07-26 09:54:372801 }
[email protected]fc61e222010-10-11 15:42:142802 std::string resource;
2803 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2804 resource = group->identifier();
2805 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]414508d2010-11-02 10:45:392806 if (plugin_setting == CONTENT_SETTING_ASK) {
[email protected]3c2826852010-12-16 19:09:142807 return CreatePluginPlaceholder(frame,
2808 params,
2809 *group,
[email protected]2e34ab3f2010-12-17 05:47:372810 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
[email protected]3c2826852010-12-16 19:09:142811 IDS_PLUGIN_LOAD);
[email protected]fc61e222010-10-11 15:42:142812 } else {
[email protected]3c2826852010-12-16 19:09:142813 return CreatePluginPlaceholder(frame,
2814 params,
2815 *group,
[email protected]2e34ab3f2010-12-17 05:47:372816 IDR_BLOCKED_PLUGIN_HTML,
[email protected]3c2826852010-12-16 19:09:142817 IDS_PLUGIN_BLOCKED);
[email protected]fc61e222010-10-11 15:42:142818 }
[email protected]3d9689372009-09-10 04:29:172819}
2820
2821WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562822 WebApplicationCacheHostImpl* appcache_host =
2823 WebApplicationCacheHostImpl::FromFrame(frame);
2824 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2825 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2826 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172827}
2828
[email protected]9c00f002009-11-05 22:37:422829WebSharedWorker* RenderView::createSharedWorker(
2830 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372831 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422832
[email protected]30447b62009-11-13 01:13:372833 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512834 bool exists = false;
[email protected]30447b62009-11-13 01:13:372835 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512836 ViewHostMsg_CreateWorker_Params params;
2837 params.url = url;
2838 params.is_shared = true;
2839 params.name = name;
2840 params.document_id = document_id;
2841 params.render_view_route_id = routing_id_;
2842 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232843 params.parent_appcache_host_id = 0;
2844 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372845 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512846 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372847 if (url_mismatch) {
2848 return NULL;
2849 } else {
2850 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492851 document_id,
[email protected]6de0bcf2010-02-17 22:00:512852 exists,
[email protected]30447b62009-11-13 01:13:372853 route_id,
2854 routing_id_);
2855 }
[email protected]9c00f002009-11-05 22:37:422856}
2857
[email protected]3d9689372009-09-10 04:29:172858WebMediaPlayer* RenderView::createMediaPlayer(
2859 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]f8db8132010-12-03 00:27:492860 scoped_ptr<media::FilterCollection> collection(
2861 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:372862
[email protected]3d9689372009-09-10 04:29:172863 // Add in any custom filter factories first.
2864 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2865 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2866 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:492867 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:172868 }
2869
[email protected]3bb08602010-10-07 21:47:172870 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:122871 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:072872 WebGraphicsContext3DCommandBufferImpl* context =
2873 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2874 frame->view()->graphicsContext3D());
2875 if (!context)
2876 return NULL;
[email protected]a9a43012010-11-05 01:54:062877
[email protected]5aa6a312010-11-06 00:00:072878 // Add the hardware video decoder factory.
2879 // TODO(hclam): This will cause the renderer process to crash on context
2880 // lost.
2881 bool ret = context->makeContextCurrent();
2882 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:492883 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:072884 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:172885 }
2886
[email protected]457d8342010-10-23 01:20:372887 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:312888 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2889 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
2890 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:492891 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:312892 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:112893
[email protected]a8e24d522010-12-01 07:13:582894 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
2895 new webkit_glue::WebMediaPlayerImpl(client, collection.release()));
[email protected]79684282010-12-06 21:15:462896 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:582897 cmd_line->HasSwitch(switches::kSimpleDataSource),
2898 video_renderer)) {
2899 return NULL;
2900 }
2901 return result.release();
[email protected]3d9689372009-09-10 04:29:172902}
2903
[email protected]035545f2010-04-09 13:10:212904WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2905 WebFrame* frame, WebApplicationCacheHostClient* client) {
2906 return new RendererWebApplicationCacheHostImpl(
2907 FromWebView(frame->view()), client,
2908 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2909}
2910
[email protected]8ff181072010-11-29 17:09:382911WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
2912 return &cookie_jar_;
2913}
2914
[email protected]5041f982010-08-11 21:40:452915void RenderView::frameDetached(WebFrame* frame) {
[email protected]6a8ddba52010-09-05 04:38:062916 autofill_helper_->FrameDetached(frame);
2917 page_click_tracker_->StopTrackingFrame(frame, true);
[email protected]5041f982010-08-11 21:40:452918}
2919
[email protected]3d9689372009-09-10 04:29:172920void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302921 WebDataSource* ds = frame->dataSource();
2922 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522923
[email protected]a5a65ac2010-11-05 18:14:362924 page_load_histograms_.Dump(frame);
[email protected]fa7b6b542009-11-03 05:02:302925 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]174e60e2010-05-06 00:21:162926
[email protected]5041f982010-08-11 21:40:452927 // TODO(jhawkins): Remove once frameDetached is called by WebKit.
[email protected]6a8ddba52010-09-05 04:38:062928 autofill_helper_->FrameWillClose(frame);
[email protected]3d9689372009-09-10 04:29:172929}
2930
[email protected]684e4a42010-01-30 06:44:112931bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402932 if (enabled_per_settings &&
2933 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2934 return true;
2935
2936 if (IsWhitelistedForContentSettings(frame))
2937 return true;
2938
[email protected]55126132010-08-19 14:53:282939 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402940 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112941}
2942
[email protected]d5f9e4f2010-07-28 08:31:302943bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]3627b06d2010-11-12 16:36:162944 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
[email protected]d5f9e4f2010-07-28 08:31:302945}
2946
2947
[email protected]3d9689372009-09-10 04:29:172948void RenderView::loadURLExternally(
2949 WebFrame* frame, const WebURLRequest& request,
2950 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592951 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2952 if (policy == WebKit::WebNavigationPolicyDownload) {
2953 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2954 } else {
2955 OpenURL(request.url(), referrer, policy);
2956 }
[email protected]3d9689372009-09-10 04:29:172957}
2958
2959WebNavigationPolicy RenderView::decidePolicyForNavigation(
2960 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222961 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172962 // Webkit is asking whether to navigate to a new URL.
2963 // This is fine normally, except if we're showing UI from one security
2964 // context and they're trying to navigate to a different context.
2965 const GURL& url = request.url();
2966
2967 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302968 // navigations.
[email protected]8079b362010-05-07 18:37:452969 if (renderer_preferences_.browser_handles_top_level_requests &&
2970 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192971 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232972 // Reset these counters as the RenderView could be reused for the next
2973 // navigation.
2974 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232975 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192976 OpenURL(url, referrer, default_policy);
2977 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172978 }
2979
2980 // A content initiated navigation may have originated from a link-click,
2981 // script, drag-n-drop operation, etc.
2982 bool is_content_initiated =
2983 NavigationState::FromDataSource(frame->provisionalDataSource())->
2984 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582985 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172986
[email protected]6101c342010-12-16 22:44:372987 // Detect when we're crossing a permission-based boundary (e.g. into or out of
2988 // an extension or app origin, leaving a DOMUI page, etc). We only care about
2989 // top-level navigations withing the current tab (as opposed to, for example,
2990 // opening a new window). But we sometimes navigate to about:blank to clear a
2991 // tab, and we want to still allow that.
2992 //
2993 // Note: we do this only for GET requests because we our mechanism for
2994 // switching processes only issues GET requests. In particular, POST
2995 // requests don't work, because this mechanism does not preserve form POST
2996 // data. If it becomes necessary to support process switching for POST
2997 // requests, we will need to send the request's httpBody data up to the
2998 // browser process, and issue a special POST navigation in WebKit (via
2999 // FrameLoader::loadFrameRequest). See ResourceDispatcher and
3000 // WebURLLoaderImpl for examples of how to send the httpBody data.
3001 if (!frame->parent() && is_content_initiated &&
3002 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3003 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
3004 bool send_referrer = false;
3005 bool should_fork =
3006 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:173007 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:373008 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:113009
3010 // If the navigation would cross an app extent boundary, we also need
3011 // to defer to the browser to ensure process isolation.
3012 // TODO(erikkay) This is happening inside of a check to is_content_initiated
3013 // which means that things like the back button won't trigger it. Is that
3014 // OK?
[email protected]08e94b82010-12-15 22:51:043015 // TODO(creis): For now, we only swap processes to enter an app and not
3016 // exit it, since we currently lose context (e.g., window.opener) if the
3017 // window navigates back. See crbug.com/65953.
[email protected]6101c342010-12-16 22:44:373018 if (!should_fork && CrossesIntoExtensionExtent(frame, url)) {
[email protected]5351dbc2010-08-27 15:22:113019 // Include the referrer in this case since we're going from a hosted web
3020 // page. (the packaged case is handled previously by the extension
3021 // navigation test)
[email protected]6101c342010-12-16 22:44:373022 should_fork = true;
3023 send_referrer = true;
3024 }
3025
3026 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:113027 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:373028 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:113029 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
3030 }
[email protected]3d9689372009-09-10 04:29:173031 }
3032
3033 // Detect when a page is "forking" a new tab that can be safely rendered in
3034 // its own process. This is done by sites like Gmail that try to open links
3035 // in new windows without script connections back to the original page. We
3036 // treat such cases as browser navigations (in which we will create a new
3037 // renderer for a cross-site navigation), rather than WebKit navigations.
3038 //
3039 // We use the following heuristic to decide whether to fork a new page in its
3040 // own process:
3041 // The parent page must open a new tab to about:blank, set the new tab's
3042 // window.opener to null, and then redirect the tab to a cross-site URL using
3043 // JavaScript.
[email protected]007a848b2009-10-26 15:55:463044 //
3045 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
3046 // (see below).
[email protected]3d9689372009-09-10 04:29:173047 bool is_fork =
3048 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:583049 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:173050 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:523051 historyBackListCount() < 1 &&
3052 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173053 // The parent page must have set the child's window.opener to null before
3054 // redirecting to the desired URL.
3055 frame->opener() == NULL &&
3056 // Must be a top-level frame.
3057 frame->parent() == NULL &&
3058 // Must not have issued the request from this page.
3059 is_content_initiated &&
3060 // Must be targeted at the current tab.
3061 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3062 // Must be a JavaScript navigation, which appears as "other".
3063 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463064
3065 // Recognize if this navigation is from a link with rel=noreferrer and
3066 // target=_blank attributes, in which case the opener will be suppressed. If
3067 // so, it is safe to load cross-site pages in a separate process, so we
3068 // should let the browser handle it.
3069 bool is_noreferrer_and_blank_target =
3070 // Frame should be top level and not yet navigated.
3071 frame->parent() == NULL &&
3072 frame->url().isEmpty() &&
3073 historyBackListCount() < 1 &&
3074 historyForwardListCount() < 1 &&
3075 // Links with rel=noreferrer will have no Referer field, and their
3076 // resulting frame will have its window.opener suppressed.
3077 // TODO(creis): should add a request.httpReferrer() method to help avoid
3078 // typos on the unusual spelling of Referer.
3079 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
3080 opener_suppressed_ &&
3081 frame->opener() == NULL &&
3082 // Links with target=_blank will have no name.
3083 frame->name().isNull() &&
3084 // Another frame (with a non-empty creator) should have initiated the
3085 // request, targeted at this frame.
3086 !creator_url_.is_empty() &&
3087 is_content_initiated &&
3088 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3089 type == WebKit::WebNavigationTypeOther;
3090
3091 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:173092 // Open the URL via the browser, not via WebKit.
3093 OpenURL(url, GURL(), default_policy);
3094 return WebKit::WebNavigationPolicyIgnore;
3095 }
3096
3097 return default_policy;
3098}
3099
[email protected]6069da8c2009-10-20 20:33:493100bool RenderView::canHandleRequest(
3101 WebFrame* frame, const WebURLRequest& request) {
3102 // We allow WebKit to think that everything can be handled even though
3103 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:343104 return true;
3105}
3106
[email protected]6069da8c2009-10-20 20:33:493107WebURLError RenderView::cannotHandleRequestError(
3108 WebFrame* frame, const WebURLRequest& request) {
3109 NOTREACHED(); // Since we said we can handle all requests.
3110 return WebURLError();
3111}
3112
3113WebURLError RenderView::cancelledError(
3114 WebFrame* frame, const WebURLRequest& request) {
3115 WebURLError error;
3116 error.domain = WebString::fromUTF8(net::kErrorDomain);
3117 error.reason = net::ERR_ABORTED;
3118 error.unreachableURL = request.url();
3119 return error;
[email protected]7b7a7dc2009-10-19 02:23:343120}
3121
3122void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:493123 WebFrame*, const WebURLError&) {
3124 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:343125}
3126
[email protected]90eeddb2010-05-06 21:06:433127void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
3128 const WebKit::WebFormElement& form) {
3129 // Some login forms have onSubmit handlers that put a hash of the password
3130 // into a hidden field and then clear the password. (Issue 28910.)
3131 // This method gets called before any of those handlers run, so save away
3132 // a copy of the password in case it gets lost.
3133 NavigationState* navigation_state =
3134 NavigationState::FromDataSource(frame->dataSource());
3135 navigation_state->set_password_form_data(
3136 PasswordFormDomManager::CreatePasswordForm(form));
3137}
3138
[email protected]979c28b2009-11-07 01:30:483139void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:173140 NavigationState* navigation_state =
3141 NavigationState::FromDataSource(frame->provisionalDataSource());
3142
3143 if (navigation_state->transition_type() == PageTransition::LINK)
3144 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
3145
3146 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:353147 WebSearchableFormData web_searchable_form_data(form);
3148 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
3149 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:213150 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:433151 PasswordForm* password_form_data =
3152 PasswordFormDomManager::CreatePasswordForm(form);
3153 navigation_state->set_password_form_data(password_form_data);
3154
3155 // If the password has been cleared, recover it from the form contents already
3156 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
3157 // opposed to the provisionalDataSource's, which is what we're storing into
3158 // now.)
3159 if (password_form_data && password_form_data->password_value.empty()) {
3160 NavigationState* old_navigation_state =
3161 NavigationState::FromDataSource(frame->dataSource());
3162 if (old_navigation_state) {
3163 PasswordForm* old_form_data = old_navigation_state->password_form_data();
3164 if (old_form_data && old_form_data->action == password_form_data->action)
3165 password_form_data->password_value = old_form_data->password_value;
3166 }
3167 }
[email protected]3d9689372009-09-10 04:29:173168
[email protected]b1438212010-04-03 00:30:593169 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:043170 if (FormManager::WebFormElementToFormData(
[email protected]5af80432010-11-01 01:25:223171 form,
3172 FormManager::REQUIRE_AUTOCOMPLETE,
[email protected]18ecd002010-11-16 19:29:553173 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE |
3174 FormManager::EXTRACT_OPTION_TEXT),
[email protected]5af80432010-11-01 01:25:223175 &form_data)) {
[email protected]b1438212010-04-03 00:30:593176 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]5af80432010-11-01 01:25:223177 }
[email protected]3d9689372009-09-10 04:29:173178}
3179
3180void RenderView::willPerformClientRedirect(
3181 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3182 double fire_time) {
3183 // Ignore
3184}
3185
3186void RenderView::didCancelClientRedirect(WebFrame* frame) {
3187 // Ignore
3188}
3189
3190void RenderView::didCompleteClientRedirect(
3191 WebFrame* frame, const WebURL& from) {
3192 if (!frame->parent())
3193 completed_client_redirect_src_ = from;
3194}
3195
3196void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]bb461532010-11-26 21:50:233197 // If there are any app-related fetches in progress, they can be cancelled now
3198 // since we have navigated away from the page that created them.
3199 if (!frame->parent()) {
3200 app_icon_fetchers_.clear();
3201 app_definition_fetcher_.reset(NULL);
3202 }
3203
[email protected]3d9689372009-09-10 04:29:173204 // The rest of RenderView assumes that a WebDataSource will always have a
3205 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:483206 bool content_initiated = !pending_navigation_state_.get();
3207 NavigationState* state = content_initiated ?
3208 NavigationState::CreateContentInitiated() :
3209 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:513210
[email protected]8a3125a712010-08-09 18:58:513211 // NavigationState::referred_by_prefetcher_ is true if we are
3212 // navigating from a page that used prefetching using a link on that
3213 // page. We are early enough in the request process here that we
3214 // can still see the NavigationState of the previous page and set
3215 // this value appropriately.
3216 // TODO(gavinp): catch the important case of navigation in a new
3217 // renderer process.
3218 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303219 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523220 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513221 const GURL referrer(
3222 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3223 if (!referrer.is_empty() &&
3224 NavigationState::FromDataSource(
3225 old_frame->dataSource())->was_prefetcher()) {
3226 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
3227 WebDataSource* old_frame_ds = old_frame->dataSource();
3228 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
3229 state->set_was_referred_by_prefetcher(true);
3230 break;
3231 }
3232 }
3233 }
3234 }
3235 }
3236
[email protected]4c1b6f0b2010-02-07 16:38:183237 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523238 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513239 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183240 case WebURLRequest::UseProtocolCachePolicy: // normal load.
3241 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
3242 break;
3243 case WebURLRequest::ReloadIgnoringCacheData: // reload.
3244 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
3245 break;
3246 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
3247 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
3248 break;
3249 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
3250 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
3251 break;
3252 }
3253 }
[email protected]fa7b6b542009-11-03 05:02:303254
3255 state->set_user_script_idle_scheduler(
3256 new UserScriptIdleScheduler(this, frame));
3257 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:173258}
3259
3260void RenderView::didStartProvisionalLoad(WebFrame* frame) {
3261 WebDataSource* ds = frame->provisionalDataSource();
3262 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3263
[email protected]3d9689372009-09-10 04:29:173264 // Update the request time if WebKit has better knowledge of it.
3265 if (navigation_state->request_time().is_null()) {
3266 double event_time = ds->triggeringEventTime();
3267 if (event_time != 0.0)
3268 navigation_state->set_request_time(Time::FromDoubleT(event_time));
3269 }
3270
[email protected]05c8e502010-08-15 15:13:523271 // Start time is only set after request time.
3272 navigation_state->set_start_load_time(Time::Now());
3273
[email protected]3d9689372009-09-10 04:29:173274 bool is_top_most = !frame->parent();
3275 if (is_top_most) {
3276 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133277 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173278
3279 // Make sure redirect tracking state is clear for the new load.
3280 completed_client_redirect_src_ = GURL();
3281 } else if (frame->parent()->isLoading()) {
3282 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003283 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:173284 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
3285 }
3286
3287 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:073288 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173289}
3290
3291void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
3292 if (frame->parent())
3293 return;
3294 // Received a redirect on the main frame.
3295 WebDataSource* data_source = frame->provisionalDataSource();
3296 if (!data_source) {
3297 // Should only be invoked when we have a data source.
3298 NOTREACHED();
3299 return;
3300 }
3301 std::vector<GURL> redirects;
3302 GetRedirectChain(data_source, &redirects);
3303 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:513304 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3305 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:173306 }
3307}
3308
[email protected]40bd6582009-12-04 23:49:513309void RenderView::didFailProvisionalLoad(WebFrame* frame,
3310 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173311 // Notify the browser that we failed a provisional load with an error.
3312 //
3313 // Note: It is important this notification occur before DidStopLoading so the
3314 // SSL manager can react to the provisional load failure before being
3315 // notified the load stopped.
3316 //
3317 WebDataSource* ds = frame->provisionalDataSource();
3318 DCHECK(ds);
3319
3320 const WebURLRequest& failed_request = ds->request();
3321
3322 bool show_repost_interstitial =
3323 (error.reason == net::ERR_CACHE_MISS &&
3324 EqualsASCII(failed_request.httpMethod(), "POST"));
3325 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:073326 routing_id_, frame->identifier(), !frame->parent(), error.reason,
3327 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:173328
3329 // Don't display an error page if this is simply a cancelled load. Aside
3330 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3331 if (error.reason == net::ERR_ABORTED)
3332 return;
3333
3334 // Make sure we never show errors in view source mode.
3335 frame->enableViewSourceMode(false);
3336
3337 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3338
3339 // If this is a failed back/forward/reload navigation, then we need to do a
3340 // 'replace' load. This is necessary to avoid messing up session history.
3341 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3342 // as session history is concerned.
3343 //
3344 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3345 // the page id.
3346 //
3347 bool replace =
3348 navigation_state->pending_page_id() != -1 ||
3349 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
3350
3351 // If we failed on a browser initiated request, then make sure that our error
3352 // page load is regarded as the same browser initiated request.
3353 if (!navigation_state->is_content_initiated()) {
3354 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
3355 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:003356 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:173357 navigation_state->transition_type(),
3358 navigation_state->request_time()));
3359 }
3360
3361 // Provide the user with a more helpful error page?
3362 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3363 return;
3364
3365 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083366 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173367}
3368
3369void RenderView::didReceiveDocumentData(
3370 WebFrame* frame, const char* data, size_t data_len,
3371 bool& prevent_default) {
3372 NavigationState* navigation_state =
3373 NavigationState::FromDataSource(frame->dataSource());
3374 if (!navigation_state->postpone_loading_data())
3375 return;
3376
3377 // We're going to call commitDocumentData ourselves...
3378 prevent_default = true;
3379
[email protected]3f853a52010-09-13 19:15:083380 // Continue buffering the response data for the original error page. If it
3381 // grows too large, then we'll just let it through. For any error other than
3382 // a 404, "too large" means any data at all.
[email protected]3d9689372009-09-10 04:29:173383 navigation_state->append_postponed_data(data, data_len);
[email protected]3f853a52010-09-13 19:15:083384 if (navigation_state->postponed_data().size() >= 512 ||
3385 navigation_state->http_status_code() != 404) {
[email protected]3d9689372009-09-10 04:29:173386 navigation_state->set_postpone_loading_data(false);
3387 frame->commitDocumentData(navigation_state->postponed_data().data(),
3388 navigation_state->postponed_data().size());
3389 navigation_state->clear_postponed_data();
3390 }
3391}
3392
[email protected]40bd6582009-12-04 23:49:513393void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3394 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:173395 NavigationState* navigation_state =
3396 NavigationState::FromDataSource(frame->dataSource());
3397
3398 navigation_state->set_commit_load_time(Time::Now());
3399 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203400 // When we perform a new navigation, we need to update the last committed
3401 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173402 UpdateSessionHistory(frame);
3403
3404 // We bump our Page ID to correspond with the new session history entry.
3405 page_id_ = next_page_id_++;
3406
[email protected]d64b07b2010-04-20 22:14:063407 // Any pending translation is now obsolete.
3408 translate_helper_.CancelPendingTranslation();
3409
[email protected]3ead1322010-11-19 20:01:003410 // Let the phishing classifier decide whether to cancel classification.
3411 if (phishing_delegate_.get())
3412 phishing_delegate_->CommittedLoadInFrame(frame);
3413
[email protected]3cc72b12010-03-18 23:03:003414 // Advance our offset in session history, applying the length limit. There
3415 // is now no forward history.
3416 history_list_offset_++;
3417 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3418 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3419 history_list_length_ = history_list_offset_ + 1;
3420
[email protected]f9f4841b2010-03-20 05:41:423421 MessageLoop::current()->PostDelayedTask(
3422 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303423 page_info_method_factory_.NewRunnableMethod(
3424 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173425 kDelayForForcedCaptureMs);
3426 } else {
3427 // Inspect the navigation_state on this frame to see if the navigation
3428 // corresponds to a session history navigation... Note: |frame| may or
3429 // may not be the toplevel frame, but for the case of capturing session
3430 // history, the first committed frame suffices. We keep track of whether
3431 // we've seen this commit before so that only capture session history once
3432 // per navigation.
3433 //
3434 // Note that we need to check if the page ID changed. In the case of a
3435 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3436 // previous URL and the current page ID, which would be wrong.
3437 if (navigation_state->pending_page_id() != -1 &&
3438 navigation_state->pending_page_id() != page_id_ &&
3439 !navigation_state->request_committed()) {
3440 // This is a successful session history navigation!
3441 UpdateSessionHistory(frame);
3442 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003443
3444 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173445 }
3446 }
3447
3448 // Remember that we've already processed this request, so we don't update
3449 // the session history again. We do this regardless of whether this is
3450 // a session history navigation, because if we attempted a session history
3451 // navigation without valid HistoryItem state, WebCore will think it is a
3452 // new navigation.
3453 navigation_state->set_request_committed(true);
3454
3455 UpdateURL(frame);
3456
3457 // If this committed load was initiated by a client redirect, we're
3458 // at the last stop now, so clear it.
3459 completed_client_redirect_src_ = GURL();
3460
3461 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273462 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173463}
3464
3465void RenderView::didClearWindowObject(WebFrame* frame) {
3466 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3467 BindDOMAutomationController(frame);
[email protected]0d7ae862010-10-01 13:52:453468 GURL frame_url = frame->url();
3469 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:253470 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]731ae512010-10-15 18:20:173471 frame_url.SchemeIs(chrome::kGearsScheme) ||
[email protected]bfa83eb82010-10-06 08:41:253472 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c091c2c2010-09-17 19:05:463473 GetDOMUIBindings()->set_message_sender(this);
3474 GetDOMUIBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253475 GetDOMUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173476 }
3477 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463478 GetExternalHostBindings()->set_message_sender(this);
3479 GetExternalHostBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253480 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
[email protected]3d9689372009-09-10 04:29:173481 }
3482}
3483
3484void RenderView::didCreateDocumentElement(WebFrame* frame) {
3485 if (RenderThread::current()) { // Will be NULL during unit tests.
3486 RenderThread::current()->user_script_slave()->InjectScripts(
3487 frame, UserScript::DOCUMENT_START);
3488 }
3489
3490 // Notify the browser about non-blank documents loading in the top frame.
3491 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253492 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273493 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173494 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3495 }
3496}
3497
3498void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3499 UpdateTitle(frame, title);
3500
3501 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273502 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173503}
3504
[email protected]5019ef12010-04-27 17:26:583505void RenderView::didChangeIcons(WebFrame* frame) {
3506 if (!frame->parent()) {
3507 Send(new ViewHostMsg_UpdateFavIconURL(
3508 routing_id_,
3509 page_id_,
3510 frame->favIconURL()));
3511 }
3512}
3513
[email protected]3d9689372009-09-10 04:29:173514void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3515 WebDataSource* ds = frame->dataSource();
3516 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3517 DCHECK(navigation_state);
3518 navigation_state->set_finish_document_load_time(Time::Now());
3519
[email protected]622474d2010-11-04 09:21:083520 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173521
[email protected]6a8ddba52010-09-05 04:38:063522 page_click_tracker_->StartTrackingFrame(frame);
[email protected]e9e07992010-02-17 21:04:363523 // The document has now been fully loaded. Scan for forms to be sent up to
3524 // the browser.
[email protected]6a8ddba52010-09-05 04:38:063525 autofill_helper_->FrameContentsAvailable(frame);
3526 password_autocomplete_manager_->SendPasswordForms(frame, false);
[email protected]3d9689372009-09-10 04:29:173527
3528 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273529 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173530
3531 if (RenderThread::current()) { // Will be NULL during unit tests.
3532 RenderThread::current()->user_script_slave()->InjectScripts(
3533 frame, UserScript::DOCUMENT_END);
3534 }
[email protected]fa7b6b542009-11-03 05:02:303535
[email protected]41f16632010-10-20 01:21:323536 // InjectScripts() can end up creating a new NavigationState if it triggers a
3537 // fragment navigation, so we need to re-fetch it here.
3538 navigation_state = NavigationState::FromDataSource(ds);
[email protected]fa7b6b542009-11-03 05:02:303539 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3540}
3541
3542void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3543 if (RenderThread::current()) { // Will be NULL during unit tests.
3544 RenderThread::current()->user_script_slave()->InjectScripts(
3545 frame, UserScript::DOCUMENT_IDLE);
3546 }
3547
3548 WebFrame* main_frame = webview()->mainFrame();
3549 if (frame == main_frame) {
3550 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203551 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303552 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203553 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303554 pending_code_execution_queue_.pop();
3555 }
3556 }
[email protected]3d9689372009-09-10 04:29:173557}
3558
3559void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083560 if (webview()->mainFrame() == frame) {
3561 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3562 page_id_));
3563 }
[email protected]3d9689372009-09-10 04:29:173564}
3565
3566void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3567 // Ignore
3568}
3569
3570void RenderView::didFinishLoad(WebFrame* frame) {
3571 WebDataSource* ds = frame->dataSource();
3572 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3573 DCHECK(navigation_state);
3574 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303575 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413576
3577 // Let the password manager know which password forms are actually visible.
[email protected]6a8ddba52010-09-05 04:38:063578 password_autocomplete_manager_->SendPasswordForms(frame, true);
[email protected]fdd94a02010-11-05 08:07:173579
3580 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173581}
3582
[email protected]ccbe04e2010-03-17 17:58:433583void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173584 WebFrame* frame, bool is_new_navigation) {
[email protected]f6c2459d2010-02-24 22:34:063585 // Determine if the UserScriptIdleScheduler already ran scripts on this page,
3586 // since a new one gets created by didCreateDataSource.
[email protected]af15bed2010-08-25 21:12:093587 NavigationState* state = NavigationState::FromDataSource(frame->dataSource());
[email protected]f6c2459d2010-02-24 22:34:063588 bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run();
3589
[email protected]3d9689372009-09-10 04:29:173590 // If this was a reference fragment navigation that we initiated, then we
3591 // could end up having a non-null pending navigation state. We just need to
3592 // update the ExtraData on the datasource so that others who read the
3593 // ExtraData will get the new NavigationState. Similarly, if we did not
3594 // initiate this navigation, then we need to take care to reset any pre-
3595 // existing navigation state to a content-initiated navigation state.
3596 // DidCreateDataSource conveniently takes care of this for us.
3597 didCreateDataSource(frame, frame->dataSource());
3598
[email protected]af15bed2010-08-25 21:12:093599 NavigationState* new_state =
3600 NavigationState::FromDataSource(frame->dataSource());
3601 new_state->set_was_within_same_page(true);
3602
[email protected]f6c2459d2010-02-24 22:34:063603 if (idle_scheduler_ran) {
3604 // Update the new UserScriptIdleScheduler so we don't re-run scripts.
[email protected]f6c2459d2010-02-24 22:34:063605 new_state->user_script_idle_scheduler()->set_has_run(true);
3606 }
3607
[email protected]3d9689372009-09-10 04:29:173608 didCommitProvisionalLoad(frame, is_new_navigation);
3609
[email protected]26aa0482009-09-30 16:55:273610 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173611}
3612
[email protected]476b6f82009-09-10 21:00:593613void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313614 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593615}
3616
[email protected]3d9689372009-09-10 04:29:173617void RenderView::assignIdentifierToRequest(
3618 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3619 // Ignore
3620}
3621
3622void RenderView::willSendRequest(
3623 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3624 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303625 WebFrame* top_frame = frame->top();
3626 if (!top_frame)
3627 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513628 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3629 WebDataSource* top_data_source = top_frame->dataSource();
3630 WebDataSource* data_source =
3631 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]5e369672009-11-03 23:48:303632 if (data_source) {
3633 NavigationState* state = NavigationState::FromDataSource(data_source);
3634 if (state && state->is_cache_policy_override_set())
3635 request.setCachePolicy(state->cache_policy_override());
3636 }
[email protected]8a3125a712010-08-09 18:58:513637
3638 if (top_data_source) {
3639 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3640 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3641 state->set_was_prefetcher(true);
3642 }
3643
[email protected]3d9689372009-09-10 04:29:173644 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133645 request.setHasUserGesture(frame->isProcessingUserGesture());
3646
[email protected]c5bbc2452010-03-08 08:33:503647 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133648 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493649
[email protected]85cc78c2010-05-04 18:30:093650 // Temporary metrics, see site_isolation_metrics.h
3651 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173652}
3653
3654void RenderView::didReceiveResponse(
3655 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493656
[email protected]85cc78c2010-05-04 18:30:093657 // Temporary metrics, see site_isolation_metrics.h
3658 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3659 identifier,
3660 response);
[email protected]fa0a3432010-03-30 16:53:493661
[email protected]3d9689372009-09-10 04:29:173662 // Only do this for responses that correspond to a provisional data source
3663 // of the top-most frame. If we have a provisional data source, then we
3664 // can't have any sub-resources yet, so we know that this response must
3665 // correspond to a frame load.
3666 if (!frame->provisionalDataSource() || frame->parent())
3667 return;
3668
3669 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083670 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173671 if (frame->isViewSourceModeEnabled())
3672 return;
3673
[email protected]65041fa2010-05-21 06:56:533674 NavigationState* navigation_state =
3675 NavigationState::FromDataSource(frame->provisionalDataSource());
3676 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083677 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533678
[email protected]972ebdff2010-06-10 22:59:073679 // Record page load flags.
3680 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3681 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573682 navigation_state->set_was_alternate_protocol_available(
3683 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073684 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083685 navigation_state->set_http_status_code(http_status_code);
[email protected]65041fa2010-05-21 06:56:533686
[email protected]f48013be2010-01-14 22:07:453687 // Consider loading an alternate error page for 404 responses.
[email protected]3f853a52010-09-13 19:15:083688 if (http_status_code == 404) {
3689 // Can we even load an alternate error page for this URL?
3690 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3691 return;
3692 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3693 http_status_code)) {
3694 // If no corresponding error strings for a particular status code, just
3695 // render any received data, regardless of whether or not the status code
3696 // indicates an error.
[email protected]f48013be2010-01-14 22:07:453697 return;
[email protected]3f853a52010-09-13 19:15:083698 }
[email protected]3d9689372009-09-10 04:29:173699
[email protected]3d9689372009-09-10 04:29:173700 navigation_state->set_postpone_loading_data(true);
3701 navigation_state->clear_postponed_data();
3702}
3703
3704void RenderView::didFinishResourceLoad(
3705 WebFrame* frame, unsigned identifier) {
3706 NavigationState* navigation_state =
3707 NavigationState::FromDataSource(frame->dataSource());
3708 if (!navigation_state->postpone_loading_data())
3709 return;
3710
[email protected]3f853a52010-09-13 19:15:083711 // The server returned an error and the content was < 512 bytes (which we
[email protected]3d9689372009-09-10 04:29:173712 // suppressed). Go ahead and fetch the alternate page content.
[email protected]3f853a52010-09-13 19:15:083713 int http_status_code = navigation_state->http_status_code();
3714 if (http_status_code == 404) {
3715 // On 404s, try a remote search page as a fallback.
3716 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173717
[email protected]3f853a52010-09-13 19:15:083718 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3719 DCHECK(error_page_url.is_valid());
[email protected]3d9689372009-09-10 04:29:173720
[email protected]3f853a52010-09-13 19:15:083721 WebURLError original_error;
3722 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173723
[email protected]3f853a52010-09-13 19:15:083724 navigation_state->set_alt_error_page_fetcher(
3725 new AltErrorPageResourceFetcher(
3726 error_page_url, frame, original_error,
3727 NewCallback(this, &RenderView::AltErrorPageFinished)));
3728 } else {
3729 // On other errors, use an internal error page.
3730 WebURLError error;
3731 error.unreachableURL = frame->url();
3732 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3733 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173734
[email protected]3f853a52010-09-13 19:15:083735 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3736 std::string(), true);
3737 }
[email protected]3d9689372009-09-10 04:29:173738}
3739
3740void RenderView::didFailResourceLoad(
3741 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3742 // Ignore
3743}
3744
3745void RenderView::didLoadResourceFromMemoryCache(
3746 WebFrame* frame, const WebURLRequest& request,
3747 const WebURLResponse& response) {
3748 // Let the browser know we loaded a resource from the memory cache. This
3749 // message is needed to display the correct SSL indicators.
3750 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3751 routing_id_,
3752 request.url(),
[email protected]91733b62009-09-18 06:21:093753 frame->securityOrigin().toString().utf8(),
3754 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173755 response.securityInfo()));
3756}
3757
[email protected]6069da8c2009-10-20 20:33:493758void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293759 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3760}
3761
3762void RenderView::didRunInsecureContent(
3763 WebFrame* frame, const WebSecurityOrigin& origin) {
3764 Send(new ViewHostMsg_DidRunInsecureContent(
3765 routing_id_,
3766 origin.toString().utf8()));
3767}
3768
[email protected]7ea093ba2009-11-03 05:54:593769bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403770 if (enabled_per_settings &&
3771 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3772 return true;
[email protected]7ea093ba2009-11-03 05:54:593773
[email protected]12bc8472010-04-15 07:29:403774 if (IsWhitelistedForContentSettings(frame))
3775 return true;
[email protected]7ea093ba2009-11-03 05:54:593776
3777 return false; // Other protocols fall through here.
3778}
3779
[email protected]0a1a45432010-03-31 08:09:453780bool RenderView::allowDatabase(
3781 WebFrame* frame, const WebString& name, const WebString& display_name,
3782 unsigned long estimated_size) {
3783 WebSecurityOrigin origin = frame->securityOrigin();
3784 if (origin.isEmpty())
3785 return false; // Uninitialized document?
3786
3787 bool result;
[email protected]26a9acf2010-12-13 19:35:053788 if (!Send(new DatabaseHostMsg_Allow(routing_id_,
[email protected]0a1a45432010-03-31 08:09:453789 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3790 return false;
[email protected]9fb83e82010-07-02 18:24:553791 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3792 GURL(origin.toString().utf8()),
3793 name,
3794 display_name,
3795 estimated_size,
3796 !result));
[email protected]0a1a45432010-03-31 08:09:453797 return result;
3798}
[email protected]8934a3b2010-02-25 00:34:003799void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283800 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003801}
3802
[email protected]c21f1d52010-03-04 03:19:433803void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283804 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433805}
3806
[email protected]3d9689372009-09-10 04:29:173807void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3808 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3809}
3810
[email protected]0c882b282009-10-07 17:01:283811void RenderView::didCreateScriptContext(WebFrame* frame) {
3812 EventBindings::HandleContextCreated(frame, false);
3813}
3814
3815void RenderView::didDestroyScriptContext(WebFrame* frame) {
3816 EventBindings::HandleContextDestroyed(frame);
3817}
3818
3819void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3820 EventBindings::HandleContextCreated(frame, true);
3821}
3822
[email protected]af7eb3fb2010-09-23 21:31:063823bool RenderView::allowScriptExtension(WebFrame* frame,
3824 const WebString& extension_name,
3825 int extension_group) {
3826 // NULL in unit tests.
3827 if (!RenderThread::current())
3828 return true;
3829
3830 // Note: we prefer the provisional URL here instead of the document URL
3831 // because we might be currently loading an URL into a blank page.
3832 // See http://code.google.com/p/chromium/issues/detail?id=10924
3833 WebDataSource* ds = frame->provisionalDataSource();
3834 if (!ds)
3835 ds = frame->dataSource();
3836 return RenderThread::current()->AllowScriptExtension(
3837 extension_name.utf8(), ds->request().url(), extension_group);
3838}
3839
[email protected]fc86daa2010-03-30 23:52:533840void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3841 WebFrame* target,
3842 bool cross_origin,
3843 const WebString& property_name,
3844 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103845 // TODO(johnnyg): track the individual properties and repeat event_ids.
[email protected]a5a65ac2010-11-05 18:14:363846 page_load_histograms_.IncrementCrossFramePropertyAccess(cross_origin);
[email protected]ab9eabac2010-03-16 16:54:103847}
3848
[email protected]3d9689372009-09-10 04:29:173849void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143850 CheckPreferredSize();
3851}
3852
3853void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173854 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253855 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173856 // message.
[email protected]705243f2010-05-05 19:58:073857 if (!send_preferred_size_changes_ || !webview())
3858 return;
[email protected]dfca5acf2010-03-22 03:28:433859
[email protected]705243f2010-05-05 19:58:073860 // WebCore likes to tell us things have changed even when they haven't, so
3861 // cache the width and height and only send the IPC message when we're sure
3862 // they're different.
3863 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3864 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533865
3866 // In the presence of zoom, these sizes are still reported as if unzoomed,
3867 // so we need to adjust.
3868 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3869 size.set_width(static_cast<int>(size.width() * zoom_factor));
3870 size.set_height(static_cast<int>(size.height() * zoom_factor));
3871
[email protected]705243f2010-05-05 19:58:073872 if (size == preferred_size_)
3873 return;
[email protected]c27324b2009-11-19 22:44:293874
[email protected]705243f2010-05-05 19:58:073875 preferred_size_ = size;
3876 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3877 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173878}
3879
[email protected]143dcd592009-11-06 21:33:493880void RenderView::didChangeScrollOffset(WebFrame* frame) {
3881 StartNavStateSyncTimerIfNecessary();
3882}
3883
[email protected]8922e1f2009-10-03 05:01:263884void RenderView::reportFindInPageMatchCount(int request_id, int count,
3885 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113886 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3887 if (!count)
3888 active_match_ordinal = 0;
3889
3890 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3891 routing_id_,
3892 request_id,
3893 count,
3894 gfx::Rect(),
3895 active_match_ordinal,
3896 final_update);
3897
[email protected]8922e1f2009-10-03 05:01:263898 // If we have a message that has been queued up, then we should just replace
3899 // it. The ACK from the browser will make sure it gets sent when the browser
3900 // wants it.
3901 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263902 queued_find_reply_message_.reset(msg);
3903 } else {
3904 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113905 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263906 }
3907}
3908
3909void RenderView::reportFindInPageSelection(int request_id,
3910 int active_match_ordinal,
3911 const WebRect& selection_rect) {
3912 // Send the search result over to the browser process.
3913 Send(new ViewHostMsg_Find_Reply(routing_id_,
3914 request_id,
3915 -1,
3916 selection_rect,
3917 active_match_ordinal,
3918 false));
3919}
3920
[email protected]2b06a992010-08-21 05:48:223921void RenderView::openFileSystem(
3922 WebFrame* frame,
3923 WebFileSystem::Type type,
3924 long long size,
[email protected]d275d7a2010-11-03 01:34:493925 bool create,
[email protected]2b06a992010-08-21 05:48:223926 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083927 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223928
3929 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:083930 if (origin.isEmpty()) {
3931 // Uninitialized document?
3932 callbacks->didFail(WebKit::WebFileErrorAbort);
3933 return;
3934 }
[email protected]2b06a992010-08-21 05:48:223935
[email protected]c5a272d2010-09-27 18:37:083936 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3937 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493938 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223939}
3940
[email protected]79dbc662009-09-04 05:42:513941// webkit_glue::WebPluginPageDelegate -----------------------------------------
3942
[email protected]191eb3f72010-12-21 06:27:503943webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533944 const FilePath& file_path,
3945 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593946 if (!PluginChannelHost::IsListening())
3947 return NULL;
3948
[email protected]d2139662009-12-10 03:21:143949 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283950 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143951 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163952 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533953 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143954 if (CommandLine::ForCurrentProcess()->
3955 HasSwitch(switches::kInternalPepper)) {
3956 in_process_plugin = true;
3957 use_pepper_host = true;
3958 } else {
3959 // In process Pepper plugins must be explicitly enabled.
3960 return NULL;
3961 }
[email protected]4e0616e2010-05-28 14:55:533962 } else {
3963 FilePath internal_pdf_path;
3964 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3965 if (file_path == internal_pdf_path) {
3966 in_process_plugin = true;
3967 use_pepper_host = true;
3968 }
[email protected]26e8d5e2009-10-13 02:47:163969 }
[email protected]4e0616e2010-05-28 14:55:533970
[email protected]d2139662009-12-10 03:21:143971 // Check for Native Client modules.
[email protected]5cad70a82010-09-03 22:14:113972 if (mime_type == "application/x-nacl-srpc" &&
3973 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
[email protected]8f05f7f2010-07-30 23:12:433974 // NaCl is only permitted when we're in an extension/application with the
3975 // appropriate permission, or when explicitly enabled on the command line.
3976
[email protected]8f05f7f2010-07-30 23:12:433977 GURL main_frame_url(webview()->mainFrame()->url());
[email protected]5351dbc2010-08-27 15:22:113978 ExtensionRendererInfo* extension =
3979 ExtensionRendererInfo::GetByURL(main_frame_url);
3980 bool in_ext = extension != NULL;
[email protected]8f05f7f2010-07-30 23:12:433981 bool explicit_enable =
3982 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3983
3984 if (in_ext) {
[email protected]5cad70a82010-09-03 22:14:113985 // TODO(cbiffle): NaCl is back to experimental for M7.
[email protected]5351dbc2010-08-27 15:22:113986 if (ExtensionProcessBindings::HasPermission(extension->id(),
[email protected]5cad70a82010-09-03 22:14:113987 Extension::kExperimentalPermission)) {
[email protected]8f05f7f2010-07-30 23:12:433988 in_process_plugin = true;
3989 use_pepper_host = true;
3990 } else {
3991 // Disable NaCl for apps lacking the permission, even with the flag.
3992 return NULL;
3993 }
3994 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463995 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143996 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463997 }
3998 }
[email protected]4e0616e2010-05-28 14:55:533999
[email protected]d032f492009-09-29 00:33:464000 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:144001 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:284002 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:534003 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:334004 if (!pepper_plugin)
4005 return NULL;
4006
[email protected]53900d52010-06-16 04:25:014007 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:284008 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:144009 } else {
[email protected]6876dff2010-01-15 19:38:094010#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]191eb3f72010-12-21 06:27:504011 return webkit::npapi::WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:534012 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:094013#else
[email protected]596b2c42010-01-14 20:40:434014 NOTIMPLEMENTED();
4015 return NULL;
[email protected]7b6616f2010-01-14 18:07:554016#endif
[email protected]6876dff2010-01-15 19:38:094017 }
[email protected]f103ab72009-09-02 17:10:594018 }
4019
[email protected]4e0616e2010-05-28 14:55:534020 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:594021}
4022
4023void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034024#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:594025 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
4026 routing_id(), window));
4027#endif
4028}
4029
4030void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:034031#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:594032 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
4033 routing_id(), window));
4034#endif
4035 CleanupWindowInPluginMoves(window);
4036}
4037
[email protected]191eb3f72010-12-21 06:27:504038void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:594039 SchedulePluginMove(move);
4040}
4041
4042void RenderView::DidStartLoadingForPlugin() {
4043 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524044 didStartLoading();
[email protected]f103ab72009-09-02 17:10:594045}
4046
4047void RenderView::DidStopLoadingForPlugin() {
4048 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524049 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594050}
4051
4052void RenderView::ShowModalHTMLDialogForPlugin(
4053 const GURL& url,
4054 const gfx::Size& size,
4055 const std::string& json_arguments,
4056 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:214057 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:594058 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:214059 json_retval));
[email protected]f103ab72009-09-02 17:10:594060}
4061
[email protected]b921cfd22010-02-25 16:57:514062WebCookieJar* RenderView::GetCookieJar() {
4063 return &cookie_jar_;
4064}
4065
initial.commit09911bf2008-07-26 23:55:294066void RenderView::SyncNavigationState() {
4067 if (!webview())
4068 return;
4069
[email protected]26aa0482009-09-30 16:55:274070 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:174071 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:294072 return;
[email protected]ca948a22009-06-25 19:36:174073
4074 Send(new ViewHostMsg_UpdateState(
4075 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:294076}
4077
[email protected]b0950a72009-09-29 23:16:174078bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
4079 // Make sure webview was not shut down.
4080 if (!webview())
4081 return false;
4082 // Create an image resource fetcher and assign it with a call back object.
[email protected]bb461532010-11-26 21:50:234083 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
4084 new ImageResourceFetcher(
4085 image_url, webview()->mainFrame(), id, image_size,
4086 NewCallback(this, &RenderView::DidDownloadImage))));
[email protected]b0950a72009-09-29 23:16:174087 return true;
4088}
4089
4090void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:294091 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:174092 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:474093 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
4094 fetcher->id(),
4095 fetcher->image_url(),
4096 image.isNull(),
4097 image));
[email protected]bb461532010-11-26 21:50:234098
4099 // Remove the image fetcher from our pending list. We're in the callback from
4100 // ImageResourceFetcher, best to delay deletion.
4101 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin();
4102 iter != image_fetchers_.end(); ++iter) {
4103 if (iter->get() == fetcher) {
4104 iter->release();
4105 image_fetchers_.erase(iter);
4106 break;
4107 }
4108 }
[email protected]b0950a72009-09-29 23:16:174109 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:294110}
4111
[email protected]bf5c2ff392009-07-08 16:24:334112void RenderView::OnDownloadFavIcon(int id,
4113 const GURL& image_url,
4114 int image_size) {
[email protected]f11ca0732009-04-11 00:09:344115 bool data_image_failed = false;
4116 if (image_url.SchemeIs("data")) {
4117 SkBitmap data_image = ImageFromDataUrl(image_url);
4118 data_image_failed = data_image.empty();
4119 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:334120 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
4121 data_image));
[email protected]f11ca0732009-04-11 00:09:344122 }
4123 }
4124
[email protected]bf5c2ff392009-07-08 16:24:334125 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:174126 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:334127 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
4128 SkBitmap()));
4129 }
initial.commit09911bf2008-07-26 23:55:294130}
4131
[email protected]f11ca0732009-04-11 00:09:344132SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
4133 std::string mime_type, char_set, data;
4134 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
4135 // Decode the favicon using WebKit's image decoder.
4136 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
4137 const unsigned char* src_data =
4138 reinterpret_cast<const unsigned char*>(&data[0]);
4139
4140 return decoder.Decode(src_data, data.size());
4141 }
4142 return SkBitmap();
4143}
4144
initial.commit09911bf2008-07-26 23:55:294145void RenderView::OnGetApplicationInfo(int page_id) {
[email protected]38789d82010-11-17 06:03:444146 WebApplicationInfo app_info;
4147 if (page_id == page_id_) {
4148 string16 error;
4149 web_apps::ParseWebAppFromWebDocument(webview()->mainFrame(), &app_info,
4150 &error);
4151 }
initial.commit09911bf2008-07-26 23:55:294152
4153 // Prune out any data URLs in the set of icons. The browser process expects
4154 // any icon with a data URL to have originated from a favicon. We don't want
4155 // to decode arbitrary data URLs in the browser process. See
4156 // http://b/issue?id=1162972
4157 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:594158 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:294159 app_info.icons.erase(app_info.icons.begin() + i);
4160 --i;
4161 }
4162 }
4163
4164 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
4165}
4166
[email protected]7ccddb8c2009-08-04 17:36:554167GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:294168 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554169 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294170 // If the URL that failed was secure, then the embedding web page was not
4171 // expecting a network attacker to be able to manipulate its contents. As
4172 // we fetch alternate error pages over HTTP, we would be allowing a network
4173 // attacker to manipulate the contents of the response if we tried to use
4174 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154175 return GURL();
initial.commit09911bf2008-07-26 23:55:294176 }
4177
4178 // Grab the base URL from the browser process.
4179 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154180 return GURL();
initial.commit09911bf2008-07-26 23:55:294181
4182 // Strip query params from the failed URL.
4183 GURL::Replacements remove_params;
4184 remove_params.ClearUsername();
4185 remove_params.ClearPassword();
4186 remove_params.ClearQuery();
4187 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554188 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504189 std::string spec_to_send = url_to_send.spec();
4190 // Notify link doctor of the url truncation by sending of "?" at the end.
4191 if (failed_url.has_query())
4192 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294193
4194 // Construct the query params to send to link doctor.
4195 std::string params(alternate_error_page_url_.query());
4196 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:504197 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294198 params.append("&sourceid=chrome");
4199 params.append("&error=");
4200 switch (error_type) {
4201 case DNS_ERROR:
4202 params.append("dnserror");
4203 break;
4204
4205 case HTTP_404:
4206 params.append("http404");
4207 break;
4208
[email protected]5df266ac2008-10-15 19:50:134209 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334210 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134211 break;
4212
initial.commit09911bf2008-07-26 23:55:294213 default:
4214 NOTREACHED() << "unknown ErrorPageType";
4215 }
4216
4217 // OK, build the final url to return.
4218 GURL::Replacements link_doctor_params;
4219 link_doctor_params.SetQueryStr(params);
4220 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4221 return url;
4222}
4223
[email protected]c091c2c2010-09-17 19:05:464224DOMUIBindings* RenderView::GetDOMUIBindings() {
4225 if (!dom_ui_bindings_.get()) {
4226 dom_ui_bindings_.reset(new DOMUIBindings());
4227 }
4228 return dom_ui_bindings_.get();
4229}
4230
4231ExternalHostBindings* RenderView::GetExternalHostBindings() {
4232 if (!external_host_bindings_.get()) {
4233 external_host_bindings_.reset(new ExternalHostBindings());
4234 }
4235 return external_host_bindings_.get();
4236}
4237
[email protected]0fdbf8c2010-07-08 20:33:014238WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
4239 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494240}
4241
[email protected]6069da8c2009-10-20 20:33:494242void RenderView::OnFind(int request_id, const string16& search_text,
4243 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274244 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494245
4246 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494247 if (options.findNext) {
4248 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014249 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494250 } else {
[email protected]afdbd142010-07-10 08:01:234251 if (GetWebPluginFromPluginDocument()->startFind(
4252 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494253 } else {
[email protected]e7c58a32010-08-13 19:47:114254 // Send "no results".
4255 Send(new ViewHostMsg_Find_Reply(routing_id_,
4256 request_id,
4257 0,
4258 gfx::Rect(),
4259 0,
4260 true));
[email protected]24a7f3c2010-03-25 08:26:494261 }
4262 }
4263 return;
4264 }
4265
[email protected]b4bb2502009-10-01 22:35:274266 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274267 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294268 WebFrame* search_frame = focused_frame; // start searching focused frame.
4269
4270 bool multi_frame = (frame_after_main != main_frame);
4271
4272 // If we have multiple frames, we don't want to wrap the search within the
4273 // frame, so we check here if we only have main_frame in the chain.
4274 bool wrap_within_frame = !multi_frame;
4275
[email protected]b3f2b912009-04-09 16:18:524276 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294277 bool result = false;
4278
[email protected]7830da3e2009-11-06 16:27:264279 // If something is selected when we start searching it means we cannot just
4280 // increment the current match ordinal; we need to re-generate it.
4281 WebRange current_selection = focused_frame->selectionRange();
4282
initial.commit09911bf2008-07-26 23:55:294283 do {
[email protected]dd7daa82009-08-10 05:46:454284 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594285 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294286
4287 if (!result) {
4288 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224289 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294290
4291 // Find the next frame, but skip the invisible ones.
4292 do {
4293 // What is the next frame to search? (we might be going backwards). Note
4294 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594295 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274296 search_frame->traverseNext(true) :
4297 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454298 } while (!search_frame->hasVisibleContent() &&
4299 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294300
[email protected]884db412008-11-24 23:46:504301 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224302 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294303
4304 // If we have multiple frames and we have wrapped back around to the
4305 // focused frame, we need to search it once more allowing wrap within
4306 // the frame, otherwise it will report 'no match' if the focused frame has
4307 // reported matches, but no frames after the focused_frame contain a
4308 // match for the search word(s).
4309 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454310 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594311 request_id, search_text, options, true, // Force wrapping.
4312 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294313 }
4314 }
4315
[email protected]26aa0482009-09-30 16:55:274316 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294317 } while (!result && search_frame != focused_frame);
4318
[email protected]7830da3e2009-11-06 16:27:264319 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294320 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454321 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294322 } else {
4323 // If nothing is found, set result to "0 of 0", otherwise, set it to
4324 // "-1 of 1" to indicate that we found at least one item, but we don't know
4325 // yet what is active.
4326 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4327 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294328
[email protected]4f3dc372009-02-24 00:10:294329 // If we find no matches then this will be our last status update.
4330 // Otherwise the scoping effort will send more results.
4331 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294332
[email protected]4f3dc372009-02-24 00:10:294333 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404334 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594335 request_id,
[email protected]4f3dc372009-02-24 00:10:294336 match_count,
4337 selection_rect,
4338 ordinal,
4339 final_status_update));
initial.commit09911bf2008-07-26 23:55:294340
initial.commit09911bf2008-07-26 23:55:294341 // Scoping effort begins, starting with the mainframe.
4342 search_frame = main_frame;
4343
[email protected]dd7daa82009-08-10 05:46:454344 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294345
4346 do {
4347 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454348 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294349
4350 // We don't start another scoping effort unless at least one match has
4351 // been found.
4352 if (result) {
4353 // Start new scoping request. If the scoping function determines that it
4354 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454355 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594356 search_text,
4357 options,
initial.commit09911bf2008-07-26 23:55:294358 true); // reset the tickmarks
4359 }
4360
4361 // Iterate to the next frame. The frame will not necessarily scope, for
4362 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274363 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294364 } while (search_frame != main_frame);
4365 }
4366}
4367
[email protected]24a7f3c2010-03-25 08:26:494368void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
4369 WebView* view = webview();
4370 if (!view)
4371 return;
4372
4373 WebDocument doc = view->mainFrame()->document();
4374 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014375 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494376 return;
4377 }
4378
4379 bool clear_selection =
4380 params.action == ViewMsg_StopFinding_Params::kClearSelection;
4381 if (clear_selection)
4382 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4383
4384 WebFrame* frame = view->mainFrame();
4385 while (frame) {
4386 frame->stopFinding(clear_selection);
4387 frame = frame->traverseNext(false);
4388 }
4389
4390 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
4391 WebFrame* focused_frame = view->focusedFrame();
4392 if (focused_frame) {
4393 WebDocument doc = focused_frame->document();
4394 if (!doc.isNull()) {
4395 WebNode node = doc.focusedNode();
4396 if (!node.isNull())
4397 node.simulateClick();
4398 }
4399 }
4400 }
4401}
4402
4403void RenderView::OnFindReplyAck() {
4404 // Check if there is any queued up request waiting to be sent.
4405 if (queued_find_reply_message_.get()) {
4406 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424407 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494408 }
4409}
4410
[email protected]8934a3b2010-02-25 00:34:004411bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:354412 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:004413 return current_content_settings_.settings[settings_type] !=
4414 CONTENT_SETTING_BLOCK;
4415}
4416
[email protected]55126132010-08-19 14:53:284417void RenderView::DidBlockContentType(ContentSettingsType settings_type,
4418 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:004419 if (!content_blocked_[settings_type]) {
4420 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:284421 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
4422 resource_identifier));
[email protected]0de80162010-02-03 04:52:354423 }
[email protected]0de80162010-02-03 04:52:354424}
4425
[email protected]71b0d5d2010-02-15 05:43:074426void RenderView::ClearBlockedContentSettings() {
4427 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4428 content_blocked_[i] = false;
4429}
4430
[email protected]0bd753682010-12-16 18:15:524431WebPlugin* RenderView::CreatePepperPlugin(
4432 WebFrame* frame,
4433 const WebPluginParams& params,
4434 const FilePath& path,
4435 webkit::ppapi::PluginModule* pepper_module) {
4436 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:254437 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:094438}
[email protected]00152e92010-07-19 11:47:404439
[email protected]191eb3f72010-12-21 06:27:504440WebPlugin* RenderView::CreateNPAPIPlugin(
4441 WebFrame* frame,
4442 const WebPluginParams& params,
4443 const FilePath& path,
4444 const std::string& mime_type) {
4445 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:084446 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404447}
4448
[email protected]3c2826852010-12-16 19:09:144449WebPlugin* RenderView::CreatePluginPlaceholder(
[email protected]57b66d02010-09-30 11:24:514450 WebFrame* frame,
4451 const WebPluginParams& params,
[email protected]191eb3f72010-12-21 06:27:504452 const webkit::npapi::PluginGroup& group,
[email protected]3c2826852010-12-16 19:09:144453 int resource_id,
4454 int message_id) {
4455 // |blocked_plugin| will delete itself when the WebViewPlugin
4456 // is destroyed.
4457 BlockedPlugin* blocked_plugin =
4458 new BlockedPlugin(this,
4459 frame,
4460 group,
4461 params,
4462 webkit_preferences_,
4463 resource_id,
[email protected]2e34ab3f2010-12-17 05:47:374464 l10n_util::GetStringFUTF16(message_id,
4465 group.GetGroupName()));
[email protected]3c2826852010-12-16 19:09:144466 return blocked_plugin->plugin();
[email protected]57b66d02010-09-30 11:24:514467}
4468
[email protected]40bd6582009-12-04 23:49:514469void RenderView::OnZoom(PageZoom::Function function) {
4470 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4471 return;
4472
[email protected]258d31122010-05-09 10:59:414473 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524474
[email protected]b75b8292010-10-01 07:28:254475 double old_zoom_level = webview()->zoomLevel();
4476 double zoom_level;
4477 if (function == PageZoom::RESET) {
4478 zoom_level = 0;
4479 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4480 // Previous zoom level is a whole number, so just increment/decrement.
4481 zoom_level = old_zoom_level + function;
4482 } else {
4483 // Either the user hit the zoom factor limit and thus the zoom level is now
4484 // not a whole number, or a plugin changed it to a custom value. We want
4485 // to go to the next whole number so that the user can always get back to
4486 // 100% with the keyboard/menu.
4487 if ((old_zoom_level > 1 && function > 0) ||
4488 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:454489 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:254490 } else {
4491 // We're going towards 100%, so first go to the next whole number.
4492 zoom_level = static_cast<int>(old_zoom_level);
4493 }
4494 }
[email protected]40bd6582009-12-04 23:49:514495
[email protected]b75b8292010-10-01 07:28:254496 webview()->setZoomLevel(false, zoom_level);
4497 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:514498}
4499
[email protected]d0b8d092010-10-25 04:05:174500void RenderView::OnSetZoomLevel(double zoom_level) {
4501 // Don't set zoom level for full-page plugin since they don't use the same
4502 // zoom settings.
4503 if (webview()->mainFrame()->document().isPluginDocument())
4504 return;
4505
4506 webview()->hidePopups();
4507 webview()->setZoomLevel(false, zoom_level);
4508 zoomLevelChanged();
4509}
4510
[email protected]9d797f32010-04-23 07:17:544511void RenderView::OnSetContentSettingsForLoadingURL(
4512 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014513 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544514 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014515}
4516
[email protected]9d797f32010-04-23 07:17:544517void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:254518 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544519 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294520}
4521
[email protected]41fc0322009-09-04 22:23:404522void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274523 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294524}
4525
[email protected]a697f4c2009-09-14 22:30:184526void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274527 WebString no_encoding;
4528 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184529}
4530
[email protected]20ad2692009-11-20 18:27:204531bool RenderView::GetAllChildFrames(
4532 WebFrame* parent_frame,
4533 std::vector<WebFrame*>* frames_vector) const {
4534 if (!parent_frame)
4535 return false;
4536 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4537 child_frame = child_frame->nextSibling()) {
4538 frames_vector->push_back(child_frame);
4539 GetAllChildFrames(child_frame, frames_vector);
4540 }
4541 return true;
4542}
4543
[email protected]dd7daa82009-08-10 05:46:454544WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4545 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274546 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454547
4548 // xpath string can represent a frame deep down the tree (across multiple
4549 // frame DOMs).
4550 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4551 // should break into 2 xpaths
4552 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4553
[email protected]26aa0482009-09-30 16:55:274554 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454555
4556 std::wstring xpath_remaining = xpath;
4557 while (!xpath_remaining.empty()) {
4558 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4559 std::wstring xpath_child;
4560 if (delim_pos != std::wstring::npos) {
4561 xpath_child = xpath_remaining.substr(0, delim_pos);
4562 xpath_remaining.erase(0, delim_pos + 1);
4563 } else {
4564 xpath_remaining.swap(xpath_child);
4565 }
4566 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294567 }
4568
[email protected]dd7daa82009-08-10 05:46:454569 return frame;
initial.commit09911bf2008-07-26 23:55:294570}
4571
[email protected]ce833282010-11-04 15:48:394572void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) {
4573 // Explicitly allow empty vector to be sent to the browser.
4574 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions));
[email protected]15d9c0c2010-09-10 22:36:264575}
4576
[email protected]882b7b22010-10-05 03:34:534577void RenderView::EvaluateScript(const string16& frame_xpath,
4578 const string16& script,
4579 int id,
4580 bool notify_result) {
4581 v8::Handle<v8::Value> result;
4582 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
4583 if (web_frame)
4584 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
4585 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:294586 ListValue list;
4587 if (web_frame) {
4588 v8::HandleScope handle_scope;
4589 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4590 v8::Context::Scope context_scope(context);
4591 list.Set(0, ConvertV8Value(result));
4592 } else {
4593 list.Set(0, Value::CreateNullValue());
4594 }
4595 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:534596 }
initial.commit09911bf2008-07-26 23:55:294597}
4598
[email protected]1810e132009-03-24 23:35:484599void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084600 const std::string& css,
4601 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484602 WebFrame* web_frame = GetChildFrame(frame_xpath);
4603 if (!web_frame)
4604 return;
4605
[email protected]ffaef0c2009-09-15 17:08:084606 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484607}
4608
[email protected]00c39612010-03-06 02:53:284609void RenderView::OnPepperPluginDestroy(
4610 WebPluginDelegatePepper* pepper_plugin) {
4611 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014612 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4613 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284614 NOTREACHED();
4615 return;
4616 }
[email protected]53900d52010-06-16 04:25:014617 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474618
4619 // The plugin could have been destroyed while it was waiting for a file
4620 // choose callback, so check all pending completion callbacks and NULL them.
4621 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4622 file_chooser_completions_.begin();
4623 i != file_chooser_completions_.end(); /* nothing */) {
4624 if ((*i)->completion == pepper_plugin) {
4625 // We NULL the first one instead of deleting it because the plugin might
4626 // be the one waiting for a file choose callback. If the callback later
4627 // comes, we don't want to send the result to the next callback in line.
4628 if (i == file_chooser_completions_.begin())
4629 (*i)->completion = NULL;
4630 else
4631 i = file_chooser_completions_.erase(i);
4632 } else {
4633 ++i;
4634 }
4635 }
[email protected]00c39612010-03-06 02:53:284636}
4637
[email protected]882b7b22010-10-05 03:34:534638void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
4639 const string16& jscript,
4640 int id,
4641 bool notify_result) {
4642 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294643}
4644
[email protected]1810e132009-03-24 23:35:484645void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084646 const std::string& css,
4647 const std::string& id) {
4648 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414649
4650 // Notify RenderViewHost that css has been inserted into the frame.
4651 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484652}
4653
[email protected]7ea066a2009-04-06 20:21:594654void RenderView::OnAddMessageToConsole(
4655 const string16& frame_xpath,
4656 const string16& message,
4657 const WebConsoleMessage::Level& level) {
4658 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594659 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454660 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294661}
4662
[email protected]81e63782009-02-27 19:35:094663void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4664 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294665}
4666
4667void RenderView::OnSetDOMUIProperty(const std::string& name,
4668 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094669 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
[email protected]c091c2c2010-09-17 19:05:464670 GetDOMUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294671}
4672
4673void RenderView::OnReservePageIDRange(int size_of_range) {
4674 next_page_id_ += size_of_range + 1;
4675}
4676
[email protected]e80c73b2009-04-07 23:24:584677void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4678 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254679 bool ended,
4680 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034681 if (ended) {
[email protected]26aa0482009-09-30 16:55:274682 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204683 } else {
4684 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034685 }
initial.commit09911bf2008-07-26 23:55:294686}
4687
4688void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274689 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294690}
4691
initial.commit09911bf2008-07-26 23:55:294692void RenderView::OnFillPasswordForm(
[email protected]e768baf2010-07-16 19:36:164693 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]6a8ddba52010-09-05 04:38:064694 password_autocomplete_manager_->ReceivedPasswordFormFillData(webview(),
[email protected]03f57072010-07-14 17:36:084695 form_data);
initial.commit09911bf2008-07-26 23:55:294696}
4697
4698void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584699 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254700 const gfx::Point& screen_point,
4701 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274702 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584703 drop_data.ToDragData(),
4704 drop_data.identity,
4705 client_point,
[email protected]1d9f4132009-09-08 17:29:254706 screen_point,
4707 ops);
initial.commit09911bf2008-07-26 23:55:294708
[email protected]1d9f4132009-09-08 17:29:254709 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294710}
4711
[email protected]e80c73b2009-04-07 23:24:584712void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254713 const gfx::Point& screen_point,
4714 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274715 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254716 client_point,
4717 screen_point,
4718 ops);
initial.commit09911bf2008-07-26 23:55:294719
[email protected]1d9f4132009-09-08 17:29:254720 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294721}
4722
4723void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274724 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294725}
4726
[email protected]e80c73b2009-04-07 23:24:584727void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4728 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274729 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294730}
4731
4732void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594733 webkit_preferences_ = prefs;
4734 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294735}
4736
4737void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4738 alternate_error_page_url_ = url;
4739}
4740
[email protected]a0c7153e2009-12-09 14:36:334741void RenderView::OnCustomContextMenuAction(unsigned action) {
[email protected]6a8b86c2010-12-09 05:24:304742 if (custom_menu_listener_)
4743 custom_menu_listener_->MenuItemSelected(action);
4744 else
4745 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:334746}
4747
[email protected]d4a00a72010-01-29 01:44:424748void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:024749 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:424750 const std::string& source_lang,
4751 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:024752 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
4753 translate_script);
[email protected]d4a00a72010-01-29 01:44:424754}
4755
[email protected]85d252e2010-04-06 22:21:024756void RenderView::OnRevertTranslation(int page_id) {
4757 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:324758}
4759
initial.commit09911bf2008-07-26 23:55:294760void RenderView::OnInstallMissingPlugin() {
4761 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594762 if (first_default_plugin_)
4763 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294764}
4765
[email protected]97c5c592010-08-03 08:22:214766void RenderView::OnLoadBlockedPlugins() {
[email protected]414508d2010-11-02 10:45:394767 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS] =
4768 CONTENT_SETTING_ALLOW;
[email protected]97c5c592010-08-03 08:22:214769 NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS,
4770 Source<RenderView>(this),
4771 NotificationService::NoDetails());
4772}
4773
[email protected]cdaf8d02010-03-30 19:52:474774void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364775 // This could happen if we navigated to a different page before the user
4776 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474777 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364778 return;
4779
[email protected]cdaf8d02010-03-30 19:52:474780 WebVector<WebString> ws_file_names(paths.size());
4781 for (size_t i = 0; i < paths.size(); ++i)
4782 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464783
[email protected]cdaf8d02010-03-30 19:52:474784 if (file_chooser_completions_.front()->completion)
4785 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4786 file_chooser_completions_.pop_front();
4787
4788 // If there are more pending file chooser requests, schedule one now.
4789 if (!file_chooser_completions_.empty()) {
4790 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4791 file_chooser_completions_.front()->params));
4792 }
initial.commit09911bf2008-07-26 23:55:294793}
4794
4795void RenderView::OnEnableViewSourceMode() {
4796 if (!webview())
4797 return;
[email protected]26aa0482009-09-30 16:55:274798 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294799 if (!main_frame)
4800 return;
4801
[email protected]dd7daa82009-08-10 05:46:454802 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294803}
4804
[email protected]770dd8b2010-05-24 18:11:394805void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4806 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244807 if (send_preferred_size_changes_)
4808 return;
[email protected]9fb325e2010-05-06 18:23:244809 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394810
4811 // WebKit doesn't send a notification of the effective height of the page
4812 // changes, so poll for it.
4813 // TODO: Add a notification for this to WebKit, remove polling. After that's
4814 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4815 // http://crbug.com/44850
4816 if (flags & kPreferredSizeHeightThisIsSlow) {
4817 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4818 &RenderView::CheckPreferredSize);
4819 }
[email protected]0666aef2009-05-13 19:48:084820}
4821
[email protected]ce833282010-11-04 15:48:394822void RenderView::OnSearchBoxChange(const string16& value,
[email protected]368ef4c2010-11-08 21:58:464823 bool verbatim,
[email protected]ce833282010-11-04 15:48:394824 int selection_start,
4825 int selection_end) {
4826 search_box_.value = value;
[email protected]368ef4c2010-11-08 21:58:464827 search_box_.verbatim = verbatim;
[email protected]ce833282010-11-04 15:48:394828 search_box_.selection_start = selection_start;
4829 search_box_.selection_end = selection_end;
4830 if (!webview() || !webview()->mainFrame())
4831 return;
4832 extensions_v8::SearchBoxExtension::DispatchChange(webview()->mainFrame());
4833}
4834
4835void RenderView::OnSearchBoxSubmit(const string16& value, bool verbatim) {
4836 search_box_.value = value;
4837 search_box_.verbatim = verbatim;
4838 if (!webview() || !webview()->mainFrame())
4839 return;
4840 extensions_v8::SearchBoxExtension::DispatchSubmit(webview()->mainFrame());
4841}
4842
4843void RenderView::OnSearchBoxCancel() {
4844 search_box_.verbatim = false;
4845 if (!webview() || !webview()->mainFrame())
4846 return;
4847 extensions_v8::SearchBoxExtension::DispatchCancel(webview()->mainFrame());
4848}
4849
4850void RenderView::OnSearchBoxResize(const gfx::Rect& bounds) {
4851 search_box_.x = bounds.x();
4852 search_box_.y = bounds.y();
4853 search_box_.width = bounds.width();
4854 search_box_.height = bounds.height();
4855 if (!webview() || !webview()->mainFrame())
4856 return;
4857 extensions_v8::SearchBoxExtension::DispatchResize(webview()->mainFrame());
4858}
4859
[email protected]57ad7b8c2010-11-18 19:13:494860void RenderView::OnDetermineIfPageSupportsInstant(const string16& value,
4861 bool verbatim) {
[email protected]ce833282010-11-04 15:48:394862 search_box_.value = value;
[email protected]57ad7b8c2010-11-18 19:13:494863 search_box_.verbatim = verbatim;
[email protected]ce833282010-11-04 15:48:394864 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
4865 webview()->mainFrame());
4866 Send(new ViewHostMsg_InstantSupportDetermined(routing_id_, page_id_, result));
4867}
4868
[email protected]cda45c02010-02-25 19:28:104869void RenderView::OnDisableScrollbarsForSmallWindows(
4870 const gfx::Size& disable_scrollbar_size_limit) {
4871 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4872}
4873
[email protected]80d96fa2009-06-10 22:34:514874void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4875 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374876 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134877#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414878 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4879 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464880 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]8d1b864d12010-10-10 00:04:344881 gfx::NativeThemeLinux::instance()->SetScrollbarColors(
4882 renderer_prefs.thumb_inactive_color,
4883 renderer_prefs.thumb_active_color,
4884 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324885
[email protected]644d77e2010-01-27 01:03:104886 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324887 webview()->setScrollbarColors(
4888 renderer_prefs.thumb_inactive_color,
4889 renderer_prefs.thumb_active_color,
4890 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104891 webview()->setSelectionColors(
4892 renderer_prefs.active_selection_bg_color,
4893 renderer_prefs.active_selection_fg_color,
4894 renderer_prefs.inactive_selection_bg_color,
4895 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464896 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104897 }
[email protected]7a74e102009-09-03 00:16:564898#endif
[email protected]80d96fa2009-06-10 22:34:514899}
4900
[email protected]952cb702009-10-07 05:50:284901void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4902 const WebMediaPlayerAction& action) {
4903 if (webview())
4904 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564905}
4906
[email protected]7b291f92009-08-14 05:43:534907void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4908 view_type_ = type;
4909}
4910
4911void RenderView::OnUpdateBrowserWindowId(int window_id) {
4912 browser_window_id_ = window_id;
4913}
4914
[email protected]dea2d372010-09-25 06:41:144915void RenderView::OnEnableAccessibility() {
4916 if (WebAccessibilityCache::accessibilityEnabled())
4917 return;
[email protected]9f4db512010-05-10 20:21:414918
[email protected]dea2d372010-09-25 06:41:144919 WebAccessibilityCache::enableAccessibility();
4920
4921 if (webview()) {
4922 // It's possible that the webview has already loaded a webpage without
4923 // accessibility being enabled. Initialize the browser's cached
4924 // accessibility tree by sending it a 'load complete' notification.
4925 postAccessibilityNotification(
4926 webview()->accessibilityObject(),
4927 WebKit::WebAccessibilityNotificationLoadComplete);
4928 }
[email protected]266eb6f2008-09-30 23:56:504929}
4930
[email protected]aef92842010-05-21 16:54:364931void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4932 if (!accessibility_.get())
4933 return;
[email protected]02ea2f312010-09-27 17:03:364934
4935 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4936 WebAccessibilityObject root = webview()->accessibilityObject();
4937 if (!obj.isValid() || !root.isValid())
4938 return;
4939
4940 // By convention, calling SetFocus on the root of the tree should clear the
4941 // current focus. Otherwise set the focus to the new node.
4942 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
4943 webview()->clearFocusedNode();
4944 else
4945 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:364946}
4947
4948void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4949 if (!accessibility_.get())
4950 return;
[email protected]02ea2f312010-09-27 17:03:364951
4952 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4953 if (!obj.isValid())
4954 return;
4955
4956 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:364957}
4958
[email protected]9892b472010-09-16 00:23:424959void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:514960 DCHECK(accessibility_ack_pending_);
4961 accessibility_ack_pending_ = false;
4962 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:314963}
4964
initial.commit09911bf2008-07-26 23:55:294965void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4966 const GURL& page_url) {
4967 // Prepare list to storage all savable resource links.
4968 std::vector<GURL> resources_list;
4969 std::vector<GURL> referrers_list;
4970 std::vector<GURL> frames_list;
4971 webkit_glue::SavableResourcesResult result(&resources_list,
4972 &referrers_list,
4973 &frames_list);
4974
[email protected]dbeb3952009-10-13 18:01:184975 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4976 webview(),
4977 page_url,
4978 &result,
4979 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294980 // If something is wrong when collecting all savable resource links,
4981 // send empty list to embedder(browser) to tell it failed.
4982 referrers_list.clear();
4983 resources_list.clear();
4984 frames_list.clear();
4985 }
4986
4987 // Send result of all savable resource links to embedder.
4988 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4989 resources_list,
4990 referrers_list,
4991 frames_list));
4992}
4993
4994void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324995 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314996 const std::vector<FilePath>& local_paths,
4997 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074998
4999 // Convert std::vector of GURLs to WebVector<WebURL>
5000 WebVector<WebURL> weburl_links(links);
5001
5002 // Convert std::vector of std::strings to WebVector<WebString>
5003 WebVector<WebString> webstring_paths(local_paths.size());
5004 for (size_t i = 0; i < local_paths.size(); i++)
5005 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
5006
5007 WebPageSerializer::serialize(webview()->mainFrame(),
5008 true, this, weburl_links, webstring_paths,
5009 webkit_glue::FilePathToWebString(
5010 local_directory_name));
initial.commit09911bf2008-07-26 23:55:295011}
5012
[email protected]d9ec5c0f2009-12-23 11:55:075013void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
5014 const WebCString& data,
5015 WebPageSerializerClient::PageSerializationStatus status) {
5016 Send(new ViewHostMsg_SendSerializedHtmlData(
5017 routing_id_,
5018 frame_url,
5019 data.data(),
5020 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:295021}
5022
[email protected]9b18a84f2010-06-10 15:54:045023void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:275024 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:475025 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:295026}
5027
[email protected]eb6b87a2009-07-24 15:57:395028void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:295029 // TODO(creis): We'd rather use webview()->Close() here, but that currently
5030 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
5031 // in the onunload handler from appearing. For now, we're bypassing that and
5032 // calling the FrameLoader's CloseURL method directly. This should be
5033 // revisited to avoid having two ways to close a page. Having a single way
5034 // to close that can run onunload is also useful for fixing
5035 // http://b/issue?id=753080.
[email protected]a5a65ac2010-11-05 18:14:365036 // TODO(davemoore) This code should be removed once willClose() gets
5037 // called when a page is destroyed. page_load_histograms_.Dump() is safe
5038 // to call multiple times for the same frame, but it will simplify things.
5039 page_load_histograms_.Dump(webview()->mainFrame());
5040 page_load_histograms_.ResetCrossFramePropertyAccess();
[email protected]26aa0482009-09-30 16:55:275041 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:295042
[email protected]eb6b87a2009-07-24 15:57:395043 // Just echo back the params in the ACK.
5044 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:295045}
5046
5047void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:575048#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:295049 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465050 if (webview())
5051 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575052#else // defined(OS_WIN)
5053 // TODO(port): we don't support theming on non-Windows platforms yet
5054 NOTIMPLEMENTED();
5055#endif
initial.commit09911bf2008-07-26 23:55:295056}
5057
[email protected]9b18a84f2010-06-10 15:54:045058void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
5059 const std::string& origin,
5060 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:155061 if (message.empty())
5062 return;
[email protected]c091c2c2010-09-17 19:05:465063 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
5064 target);
[email protected]3ac14a052008-08-15 21:22:155065}
5066
[email protected]0aa55312008-10-17 21:53:085067void RenderView::OnDisassociateFromPopupCount() {
5068 if (decrement_shared_popup_at_destruction_)
5069 shared_popup_counter_->data--;
5070 shared_popup_counter_ = new SharedRenderViewCounter(0);
5071 decrement_shared_popup_at_destruction_ = false;
5072}
5073
[email protected]15d79e12009-08-02 19:23:455074bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
5075 const WebURLError& error,
5076 bool replace) {
5077 // We only show alternate error pages in the main frame. They are
5078 // intended to assist the user when navigating, so there is not much
5079 // value in showing them for failed subframes. Ideally, we would be
5080 // able to use the TYPED transition type for this, but that flag is
5081 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455082 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455083 return false;
5084
5085 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375086 // connection failure.
[email protected]15d79e12009-08-02 19:23:455087 int ec = error.reason;
5088 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5089 ec != net::ERR_CONNECTION_FAILED &&
5090 ec != net::ERR_CONNECTION_REFUSED &&
5091 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:375092 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:455093 return false;
5094
5095 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555096 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455097 if (!error_page_url.is_valid())
5098 return false;
5099
5100 // Load an empty page first so there is an immediate response to the error,
5101 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455102 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:365103 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455104 error.unreachableURL,
5105 replace);
5106
5107 // Now, create a fetcher for the error page and associate it with the data
5108 // source we just created via the LoadHTMLString call. That way if another
5109 // navigation occurs, the fetcher will get destroyed.
5110 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455111 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:455112 navigation_state->set_alt_error_page_fetcher(
5113 new AltErrorPageResourceFetcher(
5114 error_page_url, frame, error,
5115 NewCallback(this, &RenderView::AltErrorPageFinished)));
5116 return true;
5117}
5118
initial.commit09911bf2008-07-26 23:55:295119std::string RenderView::GetAltHTMLForTemplate(
5120 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:395121 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:295122 ResourceBundle::GetSharedInstance().GetRawDataResource(
5123 template_resource_id));
5124
5125 if (template_html.empty()) {
5126 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
5127 return "";
5128 }
[email protected]7cd22a52009-07-14 00:40:255129
initial.commit09911bf2008-07-26 23:55:295130 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:255131 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:295132 template_html, &error_strings, "t");
5133}
[email protected]0e79b9e2009-02-13 04:20:485134
[email protected]15d79e12009-08-02 19:23:455135void RenderView::AltErrorPageFinished(WebFrame* frame,
5136 const WebURLError& original_error,
5137 const std::string& html) {
5138 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:555139
5140 // If we failed to download the alternate error page, fall back to the
5141 // original error page if present. Otherwise, LoadNavigationErrorPage
5142 // will simply display a default error page.
5143 const std::string* html_to_load = &html;
5144 if (html.empty()) {
5145 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455146 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:555147 html_to_load = &navigation_state->postponed_data();
5148 }
[email protected]3f853a52010-09-13 19:15:085149 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
5150 true);
[email protected]15d79e12009-08-02 19:23:455151}
5152
[email protected]30f75e62009-02-25 22:01:005153void RenderView::OnMoveOrResizeStarted() {
5154 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475155 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005156}
5157
[email protected]30f75e62009-02-25 22:01:005158void RenderView::OnResize(const gfx::Size& new_size,
5159 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:105160 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475161 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105162 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205163 webview()->mainFrame()->setCanHaveScrollbars(
5164 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105165 }
5166 }
5167
[email protected]30f75e62009-02-25 22:01:005168 RenderWidget::OnResize(new_size, resizer_rect);
5169}
[email protected]0aa477bd2009-03-23 22:21:435170
[email protected]00c39612010-03-06 02:53:285171void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:015172 // Notify the pepper plugins that we started painting.
5173 pepper_delegate_.ViewInitiatedPaint();
5174
5175 // Notify any "old-style" pepper plugins that we started painting. This is
5176 // used for internal bookkeeping only, so we know that the set can not change
5177 // under us.
[email protected]00c39612010-03-06 02:53:285178 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:015179 current_oldstyle_pepper_plugins_.begin();
5180 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:285181 (*i)->RenderViewInitiatedPaint();
5182}
5183
5184void RenderView::DidFlushPaint() {
5185 // Notify any pepper plugins that we painted. This will call into the plugin,
5186 // and we it may ask to close itself as a result. This will, in turn, modify
5187 // our set, possibly invalidating the iterator. So we iterate on a copy that
5188 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015189 pepper_delegate_.ViewFlushedPaint();
5190
5191 // Notify any old-style pepper plugins that we painted. This will call into
5192 // the plugin, and we it may ask to close itself as a result. This will, in
5193 // turn, modify our set, possibly invalidating the iterator. So we iterate on
5194 // a copy that won't change out from under us.
5195 // This should be deleted when we don't support old Pepper anymore.
5196 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:285197 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
5198 i != plugins.end(); ++i) {
5199 // The copy above makes sure our iterator is never invalid if some plugins
5200 // are destroyed. But some plugin may decide to close all of its views in
5201 // response to a paint in one of them, so we need to make sure each one is
5202 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:015203 if (current_oldstyle_pepper_plugins_.find(*i) !=
5204 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:285205 (*i)->RenderViewFlushedPaint();
5206 }
5207
5208 WebFrame* main_frame = webview()->mainFrame();
5209
5210 // If we have a provisional frame we are between the start and commit stages
5211 // of loading and we don't want to save stats.
5212 if (!main_frame->provisionalDataSource()) {
5213 WebDataSource* ds = main_frame->dataSource();
5214 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5215 DCHECK(navigation_state);
5216
[email protected]05c8e502010-08-15 15:13:525217 // TODO(jar): The following code should all be inside a method, probably in
5218 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285219 Time now = Time::Now();
5220 if (navigation_state->first_paint_time().is_null()) {
5221 navigation_state->set_first_paint_time(now);
5222 }
5223 if (navigation_state->first_paint_after_load_time().is_null() &&
5224 !navigation_state->finish_load_time().is_null()) {
5225 navigation_state->set_first_paint_after_load_time(now);
5226 }
5227 }
5228}
5229
[email protected]ca4847f2010-09-24 05:39:155230bool RenderView::GetBitmapForOptimizedPluginPaint(
5231 const gfx::Rect& paint_bounds,
5232 TransportDIB** dib,
5233 gfx::Rect* location,
5234 gfx::Rect* clip) {
5235 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
5236 paint_bounds, dib, location, clip);
5237}
5238
[email protected]05d478752009-04-08 23:38:165239void RenderView::OnClearFocusedNode() {
5240 if (webview())
[email protected]26aa0482009-09-30 16:55:275241 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165242}
5243
[email protected]699ab0d2009-04-23 23:19:145244void RenderView::OnSetBackground(const SkBitmap& background) {
5245 if (webview())
[email protected]b4bb2502009-10-01 22:35:275246 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145247
5248 SetBackground(background);
5249}
5250
[email protected]8c66c5a2009-07-22 17:26:345251void RenderView::OnSetActive(bool active) {
5252 if (webview())
[email protected]b4bb2502009-10-01 22:35:275253 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265254
5255#if defined(OS_MACOSX)
5256 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5257 for (plugin_it = plugin_delegates_.begin();
5258 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5259 (*plugin_it)->SetWindowFocus(active);
5260 }
5261#endif
[email protected]8c66c5a2009-07-22 17:26:345262}
5263
[email protected]6ce7abc52010-02-02 18:40:145264#if defined(OS_MACOSX)
5265void RenderView::OnSetWindowVisibility(bool visible) {
5266 // Inform plugins that their container has changed visibility.
5267 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5268 for (plugin_it = plugin_delegates_.begin();
5269 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5270 (*plugin_it)->SetContainerVisibility(visible);
5271 }
5272}
[email protected]1e6e3c992010-02-08 15:52:135273
[email protected]4d51d5bf2010-07-26 18:48:265274void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
5275 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135276 // Inform plugins that their window's frame has changed.
5277 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5278 for (plugin_it = plugin_delegates_.begin();
5279 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5280 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5281 }
5282}
[email protected]935d63d2010-10-15 23:31:555283
5284void RenderView::OnPluginImeCompositionConfirmed(const string16& text,
5285 int plugin_id) {
5286 // WebPluginDelegateProxy is responsible for figuring out if this text
5287 // applies to it or not, so inform all the delegates.
5288 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5289 for (plugin_it = plugin_delegates_.begin();
5290 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5291 (*plugin_it)->ImeCompositionConfirmed(text, plugin_id);
5292 }
5293}
[email protected]6ce7abc52010-02-02 18:40:145294#endif // OS_MACOSX
5295
[email protected]8b8e7c92010-08-19 18:05:565296void RenderView::SendExtensionRequest(
5297 const ViewHostMsg_DomMessage_Params& params) {
5298 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:275299}
5300
[email protected]c6619182009-05-12 14:59:325301void RenderView::OnExtensionResponse(int request_id,
5302 bool success,
5303 const std::string& response,
5304 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:355305 ExtensionProcessBindings::HandleResponse(
5306 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:275307}
[email protected]c20210e62009-04-03 21:39:265308
[email protected]a7ab1b782010-10-21 23:24:165309void RenderView::OnExtensionMessageInvoke(const std::string& extension_id,
5310 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:495311 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:195312 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:495313 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:165314 extension_id, function_name, args, this, event_url);
[email protected]7120f132009-07-20 21:05:375315}
5316
[email protected]9892b472010-09-16 00:23:425317void RenderView::postAccessibilityNotification(
5318 const WebAccessibilityObject& obj,
5319 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:145320 if (!accessibility_.get() && webview()) {
5321 // Load complete should be our first notification sent.
5322 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
5323 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
5324 return;
5325
5326 // Create and initialize our accessibility cache
5327 accessibility_.reset(WebAccessibilityCache::create());
5328 accessibility_->initialize(webview());
5329 }
5330
[email protected]a3fa4f92010-09-30 22:19:335331 if (!accessibility_->isCached(obj)) {
5332 // The browser doesn't know about objects that are not in the cache. Send a
5333 // children change for the first accestor that actually is in the cache.
5334 WebAccessibilityObject parent = obj;
5335 while (parent.isValid() && !accessibility_->isCached(parent))
5336 parent = parent.parentObject();
5337
5338 DCHECK(parent.isValid() && accessibility_->isCached(parent));
5339 if (!parent.isValid())
5340 return;
5341 postAccessibilityNotification(
5342 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
5343
5344 // The parent's children change takes care of the child's children change.
5345 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
5346 return;
5347 }
5348
[email protected]dea2d372010-09-25 06:41:145349 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:515350 RendererAccessibilityNotification acc_notification;
5351 acc_notification.id = accessibility_->addOrGetId(obj);
5352 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:485353 return;
5354
[email protected]54ec7f82010-10-21 22:32:515355 if (!WebAccessibilityNotificationToViewHostMsg(
5356 notification,
5357 &acc_notification.type)) {
5358 return;
5359 }
5360
5361 // Discard duplicate accessibility notifications.
5362 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
5363 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
5364 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:425365 return;
[email protected]54ec7f82010-10-21 22:32:515366 }
[email protected]9892b472010-09-16 00:23:425367 }
[email protected]54ec7f82010-10-21 22:32:515368 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:485369
[email protected]54ec7f82010-10-21 22:32:515370 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
5371 // When no accessibility notifications are in-flight post a task to send
5372 // the notifications to the browser. We use PostTask so that we can queue
5373 // up additional notifications.
5374 MessageLoop::current()->PostTask(
5375 FROM_HERE,
5376 accessibility_method_factory_.NewRunnableMethod(
5377 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:315378 }
[email protected]520cb7d72010-08-31 11:54:315379}
5380
[email protected]212a49d2010-10-25 18:23:475381void RenderView::Print(WebFrame* frame,
5382 bool script_initiated,
5383 bool is_preview) {
[email protected]0fda7272009-06-26 15:49:335384 DCHECK(frame);
5385 if (print_helper_.get() == NULL) {
5386 print_helper_.reset(new PrintWebViewHelper(this));
5387 }
[email protected]212a49d2010-10-25 18:23:475388 print_helper_->Print(frame, script_initiated, is_preview);
[email protected]0fda7272009-06-26 15:49:335389}
[email protected]446705872009-09-10 07:22:485390
5391void RenderView::OnSetEditCommandsForNextKeyEvent(
5392 const EditCommands& edit_commands) {
5393 edit_commands_ = edit_commands;
5394}
5395
[email protected]61f5a7b2009-12-22 22:21:205396void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275397 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355398 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205399 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5400 false));
[email protected]912256b32009-09-18 09:47:355401 return;
5402 }
5403
[email protected]fa7b6b542009-11-03 05:02:305404 WebDataSource* ds = main_frame->dataSource();
5405 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5406 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205407 pending_code_execution_queue_.push(
5408 linked_ptr<ViewMsg_ExecuteCode_Params>(
5409 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305410 return;
5411 }
5412
[email protected]61f5a7b2009-12-22 22:21:205413 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305414}
5415
5416void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205417 const ViewMsg_ExecuteCode_Params& params) {
[email protected]20ad2692009-11-20 18:27:205418 std::vector<WebFrame*> frame_vector;
5419 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205420 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205421 GetAllChildFrames(frame, &frame_vector);
5422
5423 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5424 frame_it != frame_vector.end(); ++frame_it) {
5425 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205426 if (params.is_javascript) {
[email protected]be7e5cb2010-10-04 12:53:175427 ExtensionRendererInfo* extension =
5428 ExtensionRendererInfo::GetByID(params.extension_id);
5429
[email protected]1f6228c2010-10-21 03:19:445430 // Since extension info is sent separately from user script info, they can
5431 // be out of sync. We just ignore this situation.
5432 if (!extension)
5433 continue;
5434
[email protected]be7e5cb2010-10-04 12:53:175435 const std::vector<URLPattern> host_permissions =
5436 extension->host_permissions();
5437 if (!Extension::CanExecuteScriptOnPage(
5438 frame->url(),
5439 extension->allowed_to_execute_script_everywhere(),
5440 &host_permissions,
5441 NULL,
5442 NULL)) {
[email protected]61f5a7b2009-12-22 22:21:205443 continue;
[email protected]be7e5cb2010-10-04 12:53:175444 }
[email protected]61f5a7b2009-12-22 22:21:205445
[email protected]20ad2692009-11-20 18:27:205446 std::vector<WebScriptSource> sources;
5447 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205448 WebScriptSource(WebString::fromUTF8(params.code)));
5449 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205450 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205451 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205452 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5453 } else {
[email protected]61f5a7b2009-12-22 22:21:205454 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205455 }
[email protected]912256b32009-09-18 09:47:355456 }
5457
[email protected]61f5a7b2009-12-22 22:21:205458 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355459}
5460
[email protected]60c42a8c72009-10-09 04:08:595461void RenderView::Close() {
5462 // We need to grab a pointer to the doomed WebView before we destroy it.
5463 WebView* doomed = webview();
5464 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495465 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595466}
5467
[email protected]446705872009-09-10 07:22:485468void RenderView::DidHandleKeyEvent() {
5469 edit_commands_.clear();
5470}
5471
[email protected]6a8ddba52010-09-05 04:38:065472void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
5473 page_click_tracker_->DidHandleMouseEvent(event);
5474}
5475
[email protected]941e4552010-02-01 21:23:435476#if defined(OS_MACOSX)
5477void RenderView::OnWasHidden() {
5478 RenderWidget::OnWasHidden();
5479
5480 // Inform plugins that their container is no longer visible.
5481 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5482 for (plugin_it = plugin_delegates_.begin();
5483 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5484 (*plugin_it)->SetContainerVisibility(false);
5485 }
5486}
5487
5488void RenderView::OnWasRestored(bool needs_repainting) {
5489 RenderWidget::OnWasRestored(needs_repainting);
5490
5491 // Inform plugins that their container is now visible.
5492 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5493 for (plugin_it = plugin_delegates_.begin();
5494 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5495 (*plugin_it)->SetContainerVisibility(true);
5496 }
5497}
[email protected]784ea1ab2010-09-18 00:02:345498#endif // OS_MACOSX
[email protected]1e6e3c992010-02-08 15:52:135499
5500void RenderView::OnSetFocus(bool enable) {
5501 RenderWidget::OnSetFocus(enable);
5502
[email protected]7d3c02c2010-05-05 23:10:315503 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075504 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135505 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5506 for (plugin_it = plugin_delegates_.begin();
5507 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345508#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315509 // RenderWidget's call to setFocus can cause the underlying webview's
5510 // activation state to change just like a call to setIsActive.
5511 if (enable)
5512 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345513#endif
[email protected]7d3c02c2010-05-05 23:10:315514 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135515 }
[email protected]589621b2010-09-23 22:01:075516
5517 // Notify all Pepper plugins.
5518 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135519 }
5520}
[email protected]941e4552010-02-01 21:23:435521
[email protected]83dde542009-09-11 20:59:555522void RenderView::EnsureDocumentTag() {
5523 // TODO(darin): There's actually no reason for this to be here. We should
5524 // have the browser side manage the document tag.
5525#if defined(OS_MACOSX)
5526 if (!has_document_tag_) {
5527 // Make the call to get the tag.
5528 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5529 has_document_tag_ = true;
5530 }
5531#endif
5532}
[email protected]12636df2009-09-28 22:32:215533
[email protected]43f28f832010-02-03 02:28:485534#if defined(OS_MACOSX)
[email protected]935d63d2010-10-15 23:31:555535void RenderView::SetPluginImeEnabled(bool enabled, int plugin_id) {
5536 IPC::Message* msg = new ViewHostMsg_SetPluginImeEnabled(routing_id(),
5537 enabled, plugin_id);
5538 // This message can be sent during event-handling, and needs to be delivered
5539 // within that context.
5540 msg->set_unblock(true);
5541 Send(msg);
5542}
5543
[email protected]ea04a4e12010-04-15 00:58:035544gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235545 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485546 gfx::PluginWindowHandle window = NULL;
5547 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235548 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115549 if (window) {
5550 fake_plugin_window_handles_.insert(window);
5551 }
[email protected]43f28f832010-02-03 02:28:485552 return window;
5553}
5554
5555void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115556 if (window && fake_plugin_window_handles_.find(window) !=
5557 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485558 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115559 fake_plugin_window_handles_.erase(window);
5560 }
[email protected]43f28f832010-02-03 02:28:485561}
5562
[email protected]44ce0b12010-03-12 16:45:335563void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5564 int32 width,
5565 int32 height,
5566 uint64 io_surface_identifier) {
5567 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485568 routing_id(), window, width, height, io_surface_identifier));
5569}
5570
[email protected]44ce0b12010-03-12 16:45:335571void RenderView::AcceleratedSurfaceSetTransportDIB(
5572 gfx::PluginWindowHandle window,
5573 int32 width,
5574 int32 height,
5575 TransportDIB::Handle transport_dib) {
5576 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075577 routing_id(), window, width, height, transport_dib));
5578}
5579
[email protected]44ce0b12010-03-12 16:45:335580TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5581 size_t size) {
[email protected]1aef98132010-02-23 18:00:075582 TransportDIB::Handle dib_handle;
5583 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385584 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075585 return dib_handle;
5586 // Return an invalid handle if Send() fails.
5587 return TransportDIB::DefaultHandleValue();
5588}
5589
[email protected]44ce0b12010-03-12 16:45:335590void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075591 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5592}
5593
[email protected]44ce0b12010-03-12 16:45:335594void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:145595 gfx::PluginWindowHandle window, uint64 surface_id) {
5596 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
5597 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:485598}
5599#endif
[email protected]58c321d2010-02-19 12:11:285600
[email protected]cdaf8d02010-03-30 19:52:475601bool RenderView::ScheduleFileChooser(
5602 const ViewHostMsg_RunFileChooser_Params& params,
5603 WebFileChooserCompletion* completion) {
5604 static const size_t kMaximumPendingFileChooseRequests = 4;
5605 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5606 // This sanity check prevents too many file choose requests from getting
5607 // queued which could DoS the user. Getting these is most likely a
5608 // programming error (there are many ways to DoS the user so it's not
5609 // considered a "real" security check), either in JS requesting many file
5610 // choosers to pop up, or in a plugin.
5611 //
5612 // TODO(brettw) we might possibly want to require a user gesture to open
5613 // a file picker, which will address this issue in a better way.
5614 return false;
5615 }
5616
5617 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5618 new PendingFileChooser(params, completion)));
5619 if (file_chooser_completions_.size() == 1) {
5620 // Actually show the browse dialog when this is the first request.
5621 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5622 }
5623 return true;
5624}
5625
[email protected]290838a2010-04-27 17:37:015626void RenderView::OnPageTranslated() {
5627 WebFrame* frame = webview()->mainFrame();
5628 if (!frame)
5629 return;
5630
5631 // The page is translated, so try to extract the form data again.
[email protected]6a8ddba52010-09-05 04:38:065632 autofill_helper_->FrameContentsAvailable(frame);
[email protected]290838a2010-04-27 17:37:015633}
5634
[email protected]ffd0abd2010-12-14 17:45:505635#if defined(ENABLE_CLIENT_BASED_GEOLOCATION)
5636WebKit::WebGeolocationClient* RenderView::geolocationClient()
5637{
5638 if (!geolocation_dispatcher_.get())
5639 geolocation_dispatcher_.reset(new GeolocationDispatcher(this));
5640 return geolocation_dispatcher_.get();
5641}
5642#else
[email protected]8a5f7002010-03-31 13:47:355643WebKit::WebGeolocationService* RenderView::geolocationService() {
[email protected]58c321d2010-02-19 12:11:285644 if (!geolocation_dispatcher_.get())
[email protected]ecad7762010-10-22 13:58:485645 geolocation_dispatcher_.reset(new GeolocationDispatcherOld(this));
[email protected]58c321d2010-02-19 12:11:285646 return geolocation_dispatcher_.get();
5647}
[email protected]ffd0abd2010-12-14 17:45:505648#endif
[email protected]61c9f032010-03-31 23:04:195649
[email protected]638694c2010-08-04 22:24:115650WebKit::WebSpeechInputController* RenderView::speechInputController(
5651 WebKit::WebSpeechInputListener* listener) {
5652 if (!speech_input_dispatcher_.get())
5653 speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener));
5654 return speech_input_dispatcher_.get();
5655}
5656
[email protected]57ead352010-08-11 14:42:535657WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
5658 if (!device_orientation_dispatcher_.get())
5659 device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this));
5660 return device_orientation_dispatcher_.get();
5661}
5662
[email protected]b75b8292010-10-01 07:28:255663void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
5664 // For now, don't remember plugin zoom values. We don't want to mix them with
5665 // normal web content (i.e. a fixed layout plugin would usually want them
5666 // different).
5667 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5668
[email protected]b75b8292010-10-01 07:28:255669 int minimum_percent = static_cast<int>(
5670 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5671 int maximum_percent = static_cast<int>(
5672 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255673
5674 Send(new ViewHostMsg_UpdateZoomLimits(
5675 routing_id_, minimum_percent, maximum_percent, remember));
5676}
5677
5678void RenderView::zoomLevelChanged() {
5679 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5680
[email protected]b75b8292010-10-01 07:28:255681 // Tell the browser which url got zoomed so it can update the menu and the
5682 // saved values if necessary
5683 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:415684 routing_id_, webview()->zoomLevel(), remember,
5685 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:255686}
5687
[email protected]8079b362010-05-07 18:37:455688bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195689 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455690 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195691 if (frame->parent() != NULL)
5692 return false;
5693
[email protected]f0a3d0b2010-08-06 22:51:535694 // Navigations initiated within Webkit are not sent out to the external host
5695 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275696 // 1. The url scheme is not http/https
5697 // 2. There is no opener and this is not the first url being opened by this
5698 // RenderView.
5699 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535700 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535701 // 4. Reloads/form submits/back forward navigations
5702 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5703 return false;
5704
[email protected]2fc22d12010-12-02 23:08:165705 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325706 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015707 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165708 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015709 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325710 // The opener relationship between the new window and the parent allows the
5711 // new window to script the parent and vice versa. This is not allowed if
5712 // the origins of the two domains are different. This can be treated as a
5713 // top level navigation and routed back to the host.
5714 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275715 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475716 // Force link click navigations to always be routed to the host as they
5717 // may update session state on the server.
5718 if (type == WebKit::WebNavigationTypeLinkClicked)
5719 return true;
[email protected]900eb2f12010-08-23 22:36:275720 // If this is the first page being loaded by this RenderView instance then
5721 // it should stay here.
5722 if (page_id_ == -1) {
5723 return false;
5724 } else {
[email protected]d0ed50d2010-06-22 01:01:325725 return true;
[email protected]900eb2f12010-08-23 22:36:275726 }
[email protected]d0ed50d2010-06-22 01:01:325727 }
[email protected]900eb2f12010-08-23 22:36:275728
5729 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5730 return true;
[email protected]d0ed50d2010-06-22 01:01:325731 }
[email protected]61c9f032010-03-31 23:04:195732 return false;
5733}
[email protected]2b06a992010-08-21 05:48:225734
[email protected]27a9ef32010-09-10 04:06:245735void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5736 IPC::PlatformFileForTransit file_for_transit,
5737 int message_id) {
5738 pepper_delegate_.OnAsyncFileOpened(
5739 error_code,
5740 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5741 message_id);
5742}
[email protected]caf706f2010-10-26 17:54:085743
5744#if defined(OS_MACOSX)
5745void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155746 if (external_popup_menu_ == NULL) {
5747 // Crash reports from the field indicate that we can be notified with a
5748 // NULL external popup menu (we probably get notified twice).
5749 // If you hit this please file a bug against jcivelli and include the page
5750 // and steps to repro.
5751 NOTREACHED();
5752 return;
5753 }
[email protected]caf706f2010-10-26 17:54:085754 external_popup_menu_->DidSelectItem(selected_index);
5755 external_popup_menu_.reset();
5756}
5757#endif
[email protected]bb461532010-11-26 21:50:235758
5759void RenderView::AddErrorToRootConsole(const string16& message) {
5760 if (webview() && webview()->mainFrame()) {
5761 webview()->mainFrame()->addMessageToConsole(
5762 WebConsoleMessage(WebConsoleMessage::LevelError, message));
5763 }
5764}