blob: 59a0c467a5a7faf02bd6a56274f340237b3432ec [file] [log] [blame]
[email protected]b553edd52012-01-10 12:15:231// Copyright (c) 2012 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
[email protected]310ebd6302011-10-10 19:06:285#include "content/renderer/render_view_impl.h"
initial.commit09911bf2008-07-26 23:55:296
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]6e806822011-11-19 01:51:0812#include "base/bind.h"
13#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5015#include "base/compiler_specific.h"
[email protected]b1cf3372011-04-20 21:28:1016#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4917#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2819#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/string_piece.h"
[email protected]7ddea9802012-02-22 23:08:0522#include "base/string_number_conversions.h"
[email protected]318bf5802011-08-08 17:12:4123#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2924#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2825#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2626#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2227#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1028#include "content/common/appcache/appcache_dispatcher.h"
[email protected]127dd582011-03-16 21:32:1029#include "content/common/clipboard_messages.h"
[email protected]37666cf2011-03-13 21:51:4230#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5531#include "content/common/drag_messages.h"
[email protected]16dd6e22012-03-01 19:08:2032#include "content/common/fileapi/file_system_dispatcher.h"
33#include "content/common/fileapi/webfilesystem_callback_dispatcher.h"
[email protected]c26ad882012-02-07 06:41:2034#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]a2ef54c2011-10-10 16:20:3135#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5136#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1037#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0038#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4039#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0540#include "content/common/request_extra_data.h"
[email protected]778574e2011-03-21 22:03:5041#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2142#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4843#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2944#include "content/public/common/content_switches.h"
[email protected]35be7ec2012-02-12 20:42:5145#include "content/public/common/context_menu_params.h"
[email protected]8caadeb2011-11-22 02:45:2346#include "content/public/common/file_chooser_params.h"
[email protected]a1d29162011-10-14 17:14:0347#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3448#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0749#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3250#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4451#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3652#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1953#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0254#include "content/renderer/devtools_agent.h"
[email protected]766a7082012-02-03 23:39:1555#include "content/renderer/dom_automation_controller.h"
[email protected]55722152011-03-22 01:33:5356#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1957#include "content/renderer/geolocation_dispatcher.h"
[email protected]1784b2f2011-11-24 10:53:4858#include "content/renderer/idle_user_detector.h"
[email protected]0d9989d2011-12-21 20:26:0059#include "content/renderer/web_intents_host.h"
[email protected]07161902011-11-11 09:57:4260#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0261#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0862#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3763#include "content/renderer/media/audio_renderer_impl.h"
[email protected]273558fb2012-01-12 15:03:5164#include "content/renderer/media/media_stream_dependency_factory.h"
65#include "content/renderer/media/media_stream_dispatcher.h"
[email protected]ab2c4732011-07-20 19:57:4066#include "content/renderer/media/media_stream_impl.h"
[email protected]6048d512012-01-28 03:14:4867#include "content/renderer/media/render_audiosourceprovider.h"
[email protected]090f7312011-08-05 23:26:4068#include "content/renderer/media/render_media_log.h"
[email protected]6048d512012-01-28 03:14:4869#include "content/renderer/media/renderer_gpu_video_decoder_factories.h"
[email protected]4a19be92011-09-22 14:25:0270#include "content/renderer/mhtml_generator.h"
[email protected]217690d2012-01-27 07:33:1171#include "content/renderer/mouse_lock_dispatcher.h"
[email protected]230b7ef2011-03-16 22:30:1972#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3773#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3574#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0575#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4476#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4477#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3278#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0179#include "content/renderer/renderer_webapplicationcachehost_impl.h"
80#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1981#include "content/renderer/speech_input_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3282#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1983#include "content/renderer/v8_value_converter_impl.h"
[email protected]663bd9e2011-03-21 01:07:0184#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3585#include "content/renderer/webplugin_delegate_proxy.h"
86#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4987#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4188#include "media/base/media_switches.h"
[email protected]b80322902012-03-06 01:33:5089#include "media/base/message_loop_factory.h"
[email protected]e1d69d762011-12-13 05:12:1890#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2991#include "net/base/escape.h"
92#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0493#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5794#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3795#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:3796#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3797#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3798#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
99#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:37100#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
101#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
102#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
103#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
104#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:37105#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37106#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57107#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58108#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
[email protected]592e20b2012-01-20 05:53:44109#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentRequest.h"
[email protected]8b5af492011-11-28 21:50:58110#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14111#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37112#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19113#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37114#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
[email protected]81375e872012-01-11 21:40:36115#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginAction.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37119#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17123#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37124#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37125#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40126#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]273558fb2012-01-12 15:03:51127#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h"
[email protected]9c4bf232011-12-15 02:25:08128#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
[email protected]273558fb2012-01-12 15:03:51134#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandler.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConnectionHandlerClient.h"
[email protected]9c4bf232011-12-15 02:25:08136#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]e6e90dc2011-12-03 00:01:37139#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26145#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47146#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38147#include "ui/gfx/native_widget_types.h"
148#include "ui/gfx/point.h"
149#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55150#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04151#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]9c4bf232011-12-15 02:25:08152#include "webkit/forms/form_data.h"
153#include "webkit/forms/form_field.h"
154#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43155#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]18d5be92011-07-25 18:00:19156#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24157#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29158#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07159#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29160#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03161#include "webkit/glue/weburlloader_impl.h"
[email protected]b9fd01ba2012-02-28 01:50:40162#include "webkit/glue/weburlresponse_extradata_impl.h"
[email protected]7e8b4d12012-01-20 23:39:51163#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
[email protected]a9288f52011-11-17 05:18:16164#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50165#include "webkit/plugins/npapi/plugin_list.h"
166#include "webkit/plugins/npapi/webplugin_delegate.h"
167#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
168#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52169#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29170
[email protected]6c8afae52009-01-22 02:24:57171#if defined(OS_WIN)
172// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57173// * theming
[email protected]08397d52011-02-05 01:53:38174#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03175#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37176#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51177#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33178#elif defined(OS_MACOSX)
179#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57180#endif
181
[email protected]9892b472010-09-16 00:23:42182using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08183using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21184using WebKit::WebApplicationCacheHost;
185using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26186using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41187using WebKit::WebColor;
188using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59189using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44190using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51191using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55192using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28193using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00194using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58195using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25196using WebKit::WebDragOperation;
197using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51198using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51199using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08200using WebKit::WebExternalPopupMenu;
201using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47202using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22203using WebKit::WebFileSystem;
204using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49205using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59206using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48207using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45208using WebKit::WebFrame;
[email protected]7e8b4d12012-01-20 23:39:51209using WebKit::WebGraphicsContext3D;
[email protected]ca948a22009-06-25 19:36:17210using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13211using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41212using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50213using WebKit::WebInputElement;
[email protected]ffc8bed2012-01-21 01:23:15214using WebKit::WebIntentRequest;
215using WebKit::WebIntentServiceInfo;
[email protected]3d9689372009-09-10 04:29:17216using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28217using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17218using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28219using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28220using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51221using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19222using WebKit::WebPageSerializer;
223using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17224using WebKit::WebPlugin;
[email protected]81375e872012-01-11 21:40:36225using WebKit::WebPluginAction;
[email protected]00152e92010-07-19 11:47:40226using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49227using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09228using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52229using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59230using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51231using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52232using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15233using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40234using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35235using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29236using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17237using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59238using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42239using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02240using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34241using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40242using WebKit::WebStorageQuotaCallbacks;
243using WebKit::WebStorageQuotaError;
244using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28245using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51246using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52247using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24248using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28249using WebKit::WebURL;
250using WebKit::WebURLError;
251using WebKit::WebURLRequest;
252using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28253using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03254using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28255using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26256using WebKit::WebWindowFeatures;
[email protected]6fdd4182010-10-14 23:59:26257using appcache::WebApplicationCacheHostImpl;
258using base::Time;
259using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07260using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32261using content::NavigationState;
[email protected]380244092011-10-07 17:26:27262using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44263using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36264using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15265using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19266using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08267using webkit::forms::FormField;
268using webkit::forms::PasswordForm;
269using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26270using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23271using webkit_glue::ResourceFetcher;
[email protected]b9fd01ba2012-02-28 01:50:40272using webkit_glue::WebURLResponseExtraDataImpl;
[email protected]e1acf6f2008-10-27 20:43:33273
initial.commit09911bf2008-07-26 23:55:29274//-----------------------------------------------------------------------------
275
[email protected]310ebd6302011-10-10 19:06:28276typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49277static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02278
[email protected]882daa92009-11-05 16:31:31279// Time, in seconds, we delay before sending content state changes (such as form
280// state and scroll position) to the browser. We delay sending changes to avoid
281// spamming the browser.
282// To avoid having tab/session restore require sending a message to get the
283// current content state during tab closing we use a shorter timeout for the
284// foreground renderer. This means there is a small window of time from which
285// content state is modified and not sent to session restore, but this is
286// better than having to wake up all renderers during shutdown.
287static const int kDelaySecondsForContentStateSyncHidden = 5;
288static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29289
[email protected]e99ef6f2011-10-16 01:13:00290static const size_t kExtraCharsBeforeAndAfterSelection = 100;
291
[email protected]0aa55312008-10-17 21:53:08292// The maximum number of popups that can be spawned from one page.
293static const int kMaximumNumberOfUnacknowledgedPopups = 25;
294
[email protected]c514d6372011-08-16 22:54:44295static const float kScalingIncrement = 0.1f;
296
[email protected]47578fa02011-11-02 19:34:41297static const float kScalingIncrementForGesture = 0.01f;
298
[email protected]726985e22009-06-18 21:09:28299static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
300 WebVector<WebURL> urls;
301 ds->redirectChain(urls);
302 result->reserve(urls.size());
303 for (size_t i = 0; i < urls.size(); ++i)
304 result->push_back(urls[i]);
305}
306
[email protected]007733c2011-11-17 00:34:07307// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44308// the AltErrorPageResourceFetcher is reset.
309static void StopAltErrorPageFetcher(WebDataSource* data_source) {
310 if (data_source) {
[email protected]007733c2011-11-17 00:34:07311 DocumentState* document_state = DocumentState::FromDataSource(data_source);
312 if (document_state)
313 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44314 }
315}
316
[email protected]007733c2011-11-17 00:34:07317static bool IsReload(const ViewMsg_Navigate_Params& params) {
318 return
319 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
320 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
321}
322
[email protected]b9fd01ba2012-02-28 01:50:40323static WebReferrerPolicy GetReferrerPolicyFromRequest(
[email protected]445e1042011-12-03 21:03:15324 const WebURLRequest& request) {
325 return request.extraData() ?
326 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
327 WebKit::WebReferrerPolicyDefault;
328}
329
[email protected]b9fd01ba2012-02-28 01:50:40330static WebURLResponseExtraDataImpl* GetExtraDataFromResponse(
331 const WebURLResponse& response) {
332 return static_cast<WebURLResponseExtraDataImpl*>(
333 response.extraData());
334}
335
[email protected]2149cc622012-02-14 01:12:12336NOINLINE static void CrashIntentionally() {
337 // NOTE(shess): Crash directly rather than using NOTREACHED() so
338 // that the signature is easier to triage in crash reports.
339 volatile int* zero = NULL;
340 *zero = 0;
341}
342
[email protected]8bf1048012012-02-08 01:22:18343static void MaybeHandleDebugURL(const GURL& url) {
344 if (!url.SchemeIs(chrome::kChromeUIScheme))
345 return;
346 if (url == GURL(chrome::kChromeUICrashURL)) {
[email protected]2149cc622012-02-14 01:12:12347 CrashIntentionally();
[email protected]8bf1048012012-02-08 01:22:18348 } else if (url == GURL(chrome::kChromeUIKillURL)) {
349 base::KillProcess(base::GetCurrentProcessHandle(), 1, false);
350 } else if (url == GURL(chrome::kChromeUIHangURL)) {
351 for (;;) {
352 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
353 }
354 } else if (url == GURL(chrome::kChromeUIShorthangURL)) {
355 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
356 }
357}
358
initial.commit09911bf2008-07-26 23:55:29359///////////////////////////////////////////////////////////////////////////////
360
[email protected]310ebd6302011-10-10 19:06:28361struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23362 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47363 WebFileChooserCompletion* c)
364 : params(p),
365 completion(c) {
366 }
[email protected]8caadeb2011-11-22 02:45:23367 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47368 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
369};
370
[email protected]217690d2012-01-27 07:33:11371namespace {
372
373class WebWidgetLockTarget : public MouseLockDispatcher::LockTarget {
374 public:
375 WebWidgetLockTarget (WebKit::WebWidget* webwidget)
376 : webwidget_(webwidget) {}
377
378 virtual void OnLockMouseACK(bool succeeded) OVERRIDE {
379 if (succeeded)
380 webwidget_->didAcquirePointerLock();
381 else
382 webwidget_->didNotAcquirePointerLock();
383 }
384
385 virtual void OnMouseLockLost() OVERRIDE {
386 webwidget_->didLosePointerLock();
387 }
388
389 virtual bool HandleMouseLockedInputEvent(
390 const WebKit::WebMouseEvent &event) OVERRIDE {
391 // The WebWidget handles mouse lock in WebKit's handleInputEvent().
392 return false;
393 }
394
395 private:
396 WebKit::WebWidget* webwidget_;
397};
398
[email protected]86cd9472012-02-03 19:51:05399int64 ExtractPostId(const WebHistoryItem& item) {
400 if (item.isNull())
401 return -1;
402
403 if (item.httpBody().isNull())
404 return -1;
405
406 return item.httpBody().identifier();
407}
408
[email protected]217690d2012-01-27 07:33:11409} // namespace
410
[email protected]daf82f82011-10-31 22:35:31411RenderViewImpl::RenderViewImpl(
412 gfx::NativeViewId parent_hwnd,
413 int32 opener_id,
414 const content::RendererPreferences& renderer_prefs,
415 const WebPreferences& webkit_prefs,
416 SharedRenderViewCounter* counter,
417 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56418 int32 surface_id,
[email protected]daf82f82011-10-31 22:35:31419 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46420 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41421 int32 next_page_id,
422 const WebKit::WebScreenInfo& screen_info)
423 : RenderWidget(WebKit::WebPopupTypeNone, screen_info),
[email protected]676126f72011-01-15 00:03:51424 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02425 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09426 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02427 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24428 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21429 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02430 opened_by_user_gesture_(true),
431 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24432 page_id_(-1),
433 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46434 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00435 history_list_offset_(-1),
436 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02437 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55438 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31439 cached_is_main_frame_pinned_to_left_(false),
440 cached_is_main_frame_pinned_to_right_(false),
441 cached_has_main_frame_horizontal_scrollbar_(false),
442 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]05a980d7a2012-02-07 22:16:42443 context_has_swapbuffers_complete_callback_(false),
444 queried_for_swapbuffers_complete_callback_(false),
[email protected]3354d3e2010-06-10 19:53:02445 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51446 geolocation_dispatcher_(NULL),
447 speech_input_dispatcher_(NULL),
448 device_orientation_dispatcher_(NULL),
[email protected]273558fb2012-01-12 15:03:51449 media_stream_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18450 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41451 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32452 renderer_accessibility_(NULL),
[email protected]217690d2012-01-27 07:33:11453 mouse_lock_dispatcher_(NULL),
[email protected]4fb60142011-08-09 02:22:08454 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18455 handling_select_range_(false),
456#if defined(OS_WIN)
457 focused_plugin_id_(-1),
458#endif
459 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51460 routing_id_ = routing_id;
[email protected]9f4f3322012-01-18 22:29:56461 surface_id_ = surface_id;
[email protected]676126f72011-01-15 00:03:51462 if (opener_id != MSG_ROUTING_NONE)
463 opener_id_ = opener_id;
464
[email protected]74ce1ad2011-12-16 21:51:46465 // Ensure we start with a valid next_page_id_ from the browser.
466 DCHECK_GE(next_page_id_, 0);
467
[email protected]21b3a6ae2011-11-30 00:45:29468#if defined(ENABLE_NOTIFICATIONS)
469 notification_provider_ = new NotificationProvider(this);
470#else
471 notification_provider_ = NULL;
472#endif
473
[email protected]11fee2332011-03-29 20:36:35474 webwidget_ = WebView::create(this);
[email protected]217690d2012-01-27 07:33:11475 webwidget_mouse_lock_target_.reset(new WebWidgetLockTarget(webwidget_));
[email protected]11fee2332011-03-29 20:36:35476
[email protected]676126f72011-01-15 00:03:51477 if (counter) {
478 shared_popup_counter_ = counter;
479 shared_popup_counter_->data++;
480 decrement_shared_popup_at_destruction_ = true;
481 } else {
482 shared_popup_counter_ = new SharedRenderViewCounter(0);
483 decrement_shared_popup_at_destruction_ = false;
484 }
485
[email protected]380244092011-10-07 17:26:27486 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51487 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47488 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51489 AddRef();
490
491 // If this is a popup, we must wait for the CreatingNew_ACK message before
492 // completing initialization. Otherwise, we can finish it now.
493 if (opener_id == MSG_ROUTING_NONE) {
494 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55495 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51496 }
497
[email protected]34c61bd52011-05-02 19:38:33498 g_view_map.Get().insert(std::make_pair(webview(), this));
499 webkit_preferences_.Apply(webview());
500 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35501 if (!frame_name.empty())
502 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33503 webview()->settings()->setMinimumTimerInterval(
504 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
505 webkit_glue::kForegroundTabTimerInterval);
506
507 OnSetRendererPrefs(renderer_prefs);
508
[email protected]676126f72011-01-15 00:03:51509 host_window_ = parent_hwnd;
510
[email protected]a026daa2011-04-20 15:49:51511#if defined(ENABLE_P2P_APIS)
[email protected]273558fb2012-01-12 15:03:51512 if (!p2p_socket_dispatcher_)
513 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51514#endif
[email protected]cae8c8492011-03-03 11:12:18515
[email protected]5b87e782012-02-09 18:19:32516#if defined(ENABLE_WEBRTC)
[email protected]735873d2012-01-25 23:31:02517 if (!media_stream_dispatcher_)
518 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
[email protected]5b87e782012-02-09 18:19:32519#endif
[email protected]735873d2012-01-25 23:31:02520
[email protected]8f6a3b852011-07-19 16:48:56521 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32522#if defined(OS_MACOSX)
523 new TextInputClientObserver(this);
524#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56525
[email protected]217690d2012-01-27 07:33:11526 // The next group of objects all implement RenderViewObserver, so are deleted
527 // along with the RenderView automatically.
[email protected]c5c1d6d2011-07-28 18:42:41528 devtools_agent_ = new DevToolsAgent(this);
[email protected]063afcb2011-09-29 07:54:32529 renderer_accessibility_ = new RendererAccessibility(this);
[email protected]217690d2012-01-27 07:33:11530 mouse_lock_dispatcher_ = new MouseLockDispatcher(this);
[email protected]0fc7dea72012-02-09 03:47:40531 intents_host_ = new WebIntentsHost(this);
[email protected]063afcb2011-09-29 07:54:32532
[email protected]1784b2f2011-11-24 10:53:48533 new IdleUserDetector(this);
534
[email protected]766a7082012-02-03 23:39:15535 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
536 if (command_line.HasSwitch(switches::kDomAutomationController))
537 enabled_bindings_ |= content::BINDINGS_POLICY_DOM_AUTOMATION;
538
[email protected]7ddea9802012-02-22 23:08:05539 bool enable_fixed_layout =
540 command_line.HasSwitch(switches::kEnableFixedLayout);
541 webview()->enableFixedLayoutMode(enable_fixed_layout);
542 if (enable_fixed_layout)
543 webview()->settings()->setFixedElementsLayoutRelativeToFrame(true);
[email protected]7ddea9802012-02-22 23:08:05544
[email protected]e48869a2011-04-01 19:56:03545 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29546}
547
[email protected]310ebd6302011-10-10 19:06:28548RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03549 history_page_ids_.clear();
550
[email protected]0aa55312008-10-17 21:53:08551 if (decrement_shared_popup_at_destruction_)
552 shared_popup_counter_->data--;
553
[email protected]a1128322009-10-06 18:38:46554 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47555 while (!file_chooser_completions_.empty()) {
556 if (file_chooser_completions_.front()->completion) {
557 file_chooser_completions_.front()->completion->didChooseFile(
558 WebVector<WebString>());
559 }
560 file_chooser_completions_.pop_front();
561 }
[email protected]a1128322009-10-06 18:38:46562
[email protected]83dde542009-09-11 20:59:55563#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11564 // Destroy all fake plugin window handles on the browser side.
565 while (!fake_plugin_window_handles_.empty()) {
566 // Make sure no NULL plugin window handles were inserted into this list.
567 DCHECK(*fake_plugin_window_handles_.begin());
568 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
569 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
570 }
[email protected]83dde542009-09-11 20:59:55571#endif
[email protected]98324892009-09-09 21:16:05572
[email protected]60c42a8c72009-10-09 04:08:59573#ifndef NDEBUG
574 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49575 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59576 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
577 DCHECK_NE(this, it->second) << "Failed to call Close?";
578#endif
[email protected]676126f72011-01-15 00:03:51579
[email protected]273558fb2012-01-12 15:03:51580 // MediaStreamImpl holds weak references to RenderViewObserver objects,
581 // ensure it's deleted before the observers.
582 media_stream_impl_ = NULL;
583
[email protected]310ebd6302011-10-10 19:06:28584 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51585 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59586}
587
588/*static*/
[email protected]310ebd6302011-10-10 19:06:28589RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31590 ViewMap* views = g_view_map.Pointer();
591 ViewMap::iterator it = views->find(webview);
592 return it == views->end() ? NULL : it->second;
593}
594
595/*static*/
596content::RenderView*
597 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28598 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31599}
600
601/*static*/
602void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49603 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59604 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
605 if (!visitor->Visit(it->second))
606 return;
607 }
608}
609
610/*static*/
[email protected]310ebd6302011-10-10 19:06:28611RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15612 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08613 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31614 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08615 const WebPreferences& webkit_prefs,
616 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34617 int32 routing_id,
[email protected]9f4f3322012-01-18 22:29:56618 int32 surface_id,
[email protected]8ab04652010-06-12 02:47:26619 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46620 const string16& frame_name,
[email protected]6fd35b72012-03-01 19:46:41621 int32 next_page_id,
622 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29623 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28624 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51625 parent_hwnd,
626 opener_id,
627 renderer_prefs,
628 webkit_prefs,
629 counter,
630 routing_id,
[email protected]9f4f3322012-01-18 22:29:56631 surface_id,
[email protected]676126f72011-01-15 00:03:51632 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46633 frame_name,
[email protected]6fd35b72012-03-01 19:46:41634 next_page_id,
635 screen_info);
initial.commit09911bf2008-07-26 23:55:29636}
637
[email protected]273558fb2012-01-12 15:03:51638WebKit::WebPeerConnectionHandler* RenderViewImpl::CreatePeerConnectionHandler(
639 WebKit::WebPeerConnectionHandlerClient* client) {
640 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
641 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
642 return NULL;
643 EnsureMediaStreamImpl();
[email protected]5b87e782012-02-09 18:19:32644 if (!media_stream_impl_.get())
645 return NULL;
[email protected]273558fb2012-01-12 15:03:51646 return media_stream_impl_->CreatePeerConnectionHandler(client);
647}
648
[email protected]310ebd6302011-10-10 19:06:28649void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51650 observers_.AddObserver(observer);
651}
652
[email protected]310ebd6302011-10-10 19:06:28653void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
654 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51655 observers_.RemoveObserver(observer);
656}
657
[email protected]310ebd6302011-10-10 19:06:28658WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26659 return static_cast<WebKit::WebView*>(webwidget());
660}
661
[email protected]310ebd6302011-10-10 19:06:28662void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40663 if (!enabled) {
664 load_progress_tracker_.reset(NULL);
665 return;
666 }
667 if (load_progress_tracker_ == NULL)
668 load_progress_tracker_.reset(new LoadProgressTracker(this));
669}
670
[email protected]310ebd6302011-10-10 19:06:28671void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51672 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29673}
674
[email protected]310ebd6302011-10-10 19:06:28675void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26676 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30677 // If the renderer is visible, set initial visibility and focus state.
678 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34679#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30680 delegate->SetContainerVisibility(true);
681 if (webview() && webview()->isActive())
682 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34683#endif
[email protected]49232292010-09-03 19:07:30684 }
[email protected]784ea1ab2010-09-18 00:02:34685 // Plugins start assuming the content has focus (so that they work in
686 // environments where RenderView isn't hosting them), so we always have to
687 // set the initial state. See webplugin_delegate_impl.h for details.
688 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26689}
690
[email protected]310ebd6302011-10-10 19:06:28691void RenderViewImpl::UnregisterPluginDelegate(
692 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26693 plugin_delegates_.erase(delegate);
694}
[email protected]d8fd6fa2010-02-01 15:54:26695
[email protected]310ebd6302011-10-10 19:06:28696bool RenderViewImpl::GetPluginInfo(const GURL& url,
697 const GURL& page_url,
698 const std::string& mime_type,
699 webkit::WebPluginInfo* plugin_info,
700 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08701 bool found = false;
702 Send(new ViewHostMsg_GetPluginInfo(
703 routing_id_, url, page_url, mime_type, &found, plugin_info,
704 actual_mime_type));
705 return found;
706}
707
[email protected]310ebd6302011-10-10 19:06:28708bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27709 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27710 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41711 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26712
[email protected]676126f72011-01-15 00:03:51713 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
714 RenderViewObserver* observer;
715 while ((observer = it.GetNext()) != NULL)
716 if (observer->OnMessageReceived(message))
717 return true;
[email protected]b2abac72009-02-26 12:39:28718
[email protected]a95986a82010-12-24 06:19:28719 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40720 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28721 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29722 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
723 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56724 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29725 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
726 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
727 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
728 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27729#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35730 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27731#endif
initial.commit09911bf2008-07-26 23:55:29732 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15733 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29734 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
735 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
736 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08737 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29738 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15739 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29740 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49741 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
742 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17743 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17744 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41745 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54746 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
747 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29748 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18749 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
750 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29751 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48752 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55753 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
754 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
755 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
756 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
757 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
758 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
759 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45760 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40761 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29762 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19763 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
764 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29765 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
766 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
767 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51768 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
769 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29770 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04771 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15772 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29773 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
774 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08775 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
776 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00777 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16778 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14779 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25780 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
781 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47782 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]61e2b3cc2012-03-02 16:13:34783 IPC_MESSAGE_HANDLER(ViewMsg_DisableAutoResize, OnDisableAutoResize)
[email protected]cda45c02010-02-25 19:28:10784 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
785 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51786 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56787 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]81375e872012-01-11 21:40:36788 IPC_MESSAGE_HANDLER(ViewMsg_PluginActionAt, OnPluginActionAt)
[email protected]8c66c5a2009-07-22 17:26:34789 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14790#if defined(OS_MACOSX)
791 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13792 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13793 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
794 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14795#endif
[email protected]446705872009-09-10 07:22:48796 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33797 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33798 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
799 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24800 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42801 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
802 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19803 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
804 OnGetAllSavableResourceLinksForCurrentPage)
805 IPC_MESSAGE_HANDLER(
806 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
807 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08808#if defined(OS_MACOSX)
809 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
810#endif
[email protected]521b2482011-01-15 00:10:10811 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51812 // TODO(viettrungluu): Move to a separate message filter.
813#if defined(ENABLE_FLAPPER_HACKS)
814 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
815#endif
[email protected]54ca3ca892011-06-07 21:14:54816#if defined(OS_MACOSX)
817 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
818#endif
[email protected]9e1ad4b2011-08-14 16:49:19819 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
820 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18821 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]7f3c7af2011-10-20 22:52:51822 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19823
initial.commit09911bf2008-07-26 23:55:29824 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28825 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29826 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40827
828 if (!msg_is_ok) {
829 // The message had a handler, but its deserialization failed.
830 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28831 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40832 }
833
[email protected]a95986a82010-12-24 06:19:28834 return handled;
initial.commit09911bf2008-07-26 23:55:29835}
836
[email protected]310ebd6302011-10-10 19:06:28837void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
[email protected]8bf1048012012-02-08 01:22:18838 MaybeHandleDebugURL(params.url);
initial.commit09911bf2008-07-26 23:55:29839 if (!webview())
840 return;
841
[email protected]440a0e52011-09-13 17:38:58842 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
843
[email protected]007733c2011-11-17 00:34:07844 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03845
846 // If this is a stale back/forward (due to a recent navigation the browser
847 // didn't know about), ignore it.
848 if (IsBackForwardToStaleEntry(params, is_reload))
849 return;
850
[email protected]992db4c2011-05-12 15:37:15851 // Swap this renderer back in if necessary.
852 if (is_swapped_out_)
853 SetSwappedOut(false);
854
[email protected]3cc72b12010-03-18 23:03:00855 history_list_offset_ = params.current_history_list_offset;
856 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03857 if (history_list_length_ >= 0)
858 history_page_ids_.resize(history_list_length_, -1);
859 if (params.pending_history_list_offset >= 0 &&
860 params.pending_history_list_offset < history_list_length_)
861 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00862
[email protected]38b592902011-04-16 02:08:42863 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29864
[email protected]26aa0482009-09-30 16:55:27865 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45866 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29867 // We cannot reload if we do not have any history state. This happens, for
868 // example, when recovering from a crash. Our workaround here is a bit of
869 // a hack since it means that reload after a crashed tab does not cause an
870 // end-to-end cache validation.
871 is_reload = false;
872 }
873
[email protected]007733c2011-11-17 00:34:07874 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
875 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50876
[email protected]04d3c6e2009-05-22 17:00:13877 // If we are reloading, then WebKit will use the history state of the current
878 // page, so we should just ignore any given history state. Otherwise, if we
879 // have history state, then we need to navigate to it, which corresponds to a
880 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55881 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29882 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02883 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29884 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55885 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13886 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58887 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45888 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17889 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13890 } else {
891 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28892 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29893
[email protected]e6f546c32009-07-01 17:12:55894 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23895 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13896
[email protected]dd7daa82009-08-10 05:46:45897 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55898 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13899
[email protected]445e1042011-12-03 21:03:15900 if (params.referrer.url.is_valid()) {
901 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
902 params.referrer.policy,
903 params.url,
904 WebString::fromUTF8(params.referrer.url.spec()));
905 if (!referrer.isEmpty())
906 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28907 }
[email protected]04d3c6e2009-05-22 17:00:13908
[email protected]52c68652010-12-07 17:47:04909 if (!params.extra_headers.empty()) {
910 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
911 params.extra_headers.end(), "\n");
912 i.GetNext(); ) {
913 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
914 WebString::fromUTF8(i.values()));
915 }
916 }
917
[email protected]dd7daa82009-08-10 05:46:45918 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50919 }
920
[email protected]77f17a82009-05-21 04:42:54921 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07922 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29923}
924
[email protected]310ebd6302011-10-10 19:06:28925bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03926 const ViewMsg_Navigate_Params& params,
927 bool is_reload) {
928 // Make sure this isn't a back/forward to an entry we have already cropped
929 // or replaced from our history, before the browser knew about it. If so,
930 // a new navigation has committed in the mean time, and we can ignore this.
931 bool is_back_forward = !is_reload && !params.state.empty();
932
933 // Note: if the history_list_length_ is 0 for a back/forward, we must be
934 // restoring from a previous session. We'll update our state in OnNavigate.
935 if (!is_back_forward || history_list_length_ <= 0)
936 return false;
937
938 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
939
940 // Check for whether the forward history has been cropped due to a recent
941 // navigation the browser didn't know about.
942 if (params.pending_history_list_offset >= history_list_length_)
943 return true;
944
945 // Check for whether this entry has been replaced with a new one.
946 int expected_page_id =
947 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44948 if (expected_page_id > 0 && params.page_id != expected_page_id) {
949 if (params.page_id < expected_page_id)
950 return true;
951
952 // Otherwise we've removed an earlier entry and should have shifted all
953 // entries left. For now, it's ok to lazily update the list.
954 // TODO(creis): Notify all live renderers when we remove entries from
955 // the front of the list, so that we don't hit this case.
956 history_page_ids_[params.pending_history_list_offset] = params.page_id;
957 }
[email protected]d466b8a2011-07-15 21:48:03958
959 return false;
960}
961
initial.commit09911bf2008-07-26 23:55:29962// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28963void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44964 if (webview()) {
965 WebFrame* main_frame = webview()->mainFrame();
966 // Stop the alt error page fetcher. If we let it continue it may complete
967 // and cause RenderViewHostManager to swap to this RenderView, even though
968 // it may no longer be active.
969 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
970 StopAltErrorPageFetcher(main_frame->dataSource());
971 main_frame->stopLoading();
972 }
initial.commit09911bf2008-07-26 23:55:29973}
974
[email protected]ecbf10d2010-02-18 13:03:29975// Reload current focused frame.
976// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28977void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29978 if (webview() && webview()->focusedFrame()) {
979 // We always obey the cache (ignore_cache=false) here.
980 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
981 // a cache-ignoring reload of the frame.
982 webview()->focusedFrame()->reload(false);
983 }
[email protected]1dda4022010-01-28 18:24:56984}
985
[email protected]310ebd6302011-10-10 19:06:28986void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27987 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29988}
989
[email protected]310ebd6302011-10-10 19:06:28990void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:25991 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27992 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25993 return;
994
[email protected]26aa0482009-09-30 16:55:27995 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45996 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25997}
998
[email protected]310ebd6302011-10-10 19:06:28999void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:291000 // Check if there is a targeturl waiting to be sent.
1001 if (target_url_status_ == TARGET_PENDING) {
1002 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1003 pending_target_url_));
1004 }
1005
1006 target_url_status_ = TARGET_NONE;
1007}
1008
[email protected]310ebd6302011-10-10 19:06:281009void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:291010 if (!webview())
1011 return;
1012
[email protected]26aa0482009-09-30 16:55:271013 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:291014}
1015
[email protected]310ebd6302011-10-10 19:06:281016void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:291017 if (!webview())
1018 return;
1019
[email protected]26aa0482009-09-30 16:55:271020 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:291021}
1022
[email protected]310ebd6302011-10-10 19:06:281023void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:291024 if (!webview())
1025 return;
1026
[email protected]26aa0482009-09-30 16:55:271027 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:291028}
1029
[email protected]310ebd6302011-10-10 19:06:281030void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:291031 if (!webview())
1032 return;
1033
[email protected]f6b1856b2011-06-29 22:02:531034 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1035 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:291036}
1037
[email protected]c0cc3092009-09-12 08:27:271038#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281039void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:351040 if (!webview())
1041 return;
1042
1043 // Since the find pasteboard supports only plain text, this can be simpler
1044 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271045 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351046 if (frame->hasSelection()) {
1047 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:271048 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:171049 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:351050 }
[email protected]a954bf72009-09-12 07:30:351051}
[email protected]c0cc3092009-09-12 08:27:271052#endif
[email protected]a954bf72009-09-12 07:30:351053
[email protected]310ebd6302011-10-10 19:06:281054void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:291055 if (!webview())
1056 return;
1057
[email protected]26aa0482009-09-30 16:55:271058 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:291059}
1060
[email protected]44bf7002011-10-16 02:46:151061void RenderViewImpl::OnPasteAndMatchStyle() {
1062 if (!webview())
1063 return;
1064
1065 webview()->focusedFrame()->executeCommand(
1066 WebString::fromUTF8("PasteAndMatchStyle"));
1067}
1068
[email protected]310ebd6302011-10-10 19:06:281069void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291070 if (!webview())
1071 return;
1072
[email protected]1ff7a032010-02-03 02:46:031073 WebFrame* frame = webview()->focusedFrame();
1074 if (!frame->hasSelection())
1075 frame->selectWordAroundCaret();
1076 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291077}
1078
[email protected]310ebd6302011-10-10 19:06:281079void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:291080 if (!webview())
1081 return;
1082
[email protected]26aa0482009-09-30 16:55:271083 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:291084}
1085
[email protected]310ebd6302011-10-10 19:06:281086void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:291087 if (!webview())
1088 return;
1089
[email protected]26aa0482009-09-30 16:55:271090 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221091 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:291092}
1093
[email protected]310ebd6302011-10-10 19:06:281094void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1095 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:081096 if (!webview())
1097 return;
1098
1099 handling_select_range_ = true;
1100 webview()->focusedFrame()->selectRange(start, end);
1101 handling_select_range_ = false;
1102}
1103
[email protected]310ebd6302011-10-10 19:06:281104void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
1105 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:191106 DCHECK(history_length >= 0);
1107 DCHECK(history_list_offset_ == history_list_length_ - 1);
1108 DCHECK(minimum_page_id >= -1);
1109
1110 // Generate the new list.
1111 std::vector<int32> new_history_page_ids(history_length, -1);
1112 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1113 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1114 continue;
1115 new_history_page_ids.push_back(history_page_ids_[i]);
1116 }
1117 new_history_page_ids.swap(history_page_ids_);
1118
1119 // Update indexes.
1120 history_list_length_ = history_page_ids_.size();
1121 history_list_offset_ = history_list_length_ - 1;
1122}
1123
1124
[email protected]310ebd6302011-10-10 19:06:281125void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291126 if (!webview())
1127 return;
[email protected]26aa0482009-09-30 16:55:271128 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291129}
1130
[email protected]54ca3ca892011-06-07 21:14:541131#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281132void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331133 if (!webview())
1134 return;
1135 if (in_live_resize)
1136 webview()->willStartLiveResize();
1137 else
1138 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541139}
1140#endif
1141
[email protected]310ebd6302011-10-10 19:06:281142void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1143 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091144 WebKit::WebNode node = GetFocusedNode();
1145 if (!node.isNull()) {
1146 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191147 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511148 }
1149}
1150
initial.commit09911bf2008-07-26 23:55:291151///////////////////////////////////////////////////////////////////////////////
1152
1153// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281154void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451155 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291156 DCHECK(ds);
1157
[email protected]726985e22009-06-18 21:09:281158 const WebURLRequest& request = ds->request();
1159 const WebURLRequest& original_request = ds->originalRequest();
1160 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291161
[email protected]007733c2011-11-17 00:34:071162 DocumentState* document_state = DocumentState::FromDataSource(ds);
1163 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291164
1165 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281166 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291167 params.is_post = false;
[email protected]86cd9472012-02-03 19:51:051168 params.post_id = -1;
initial.commit09911bf2008-07-26 23:55:291169 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071170 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191171 params.socket_address.set_host(response.remoteIPAddress().utf8());
1172 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031173 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091174 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071175 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291176 // SSL state specified in the request takes precedence over the one in the
1177 // response.
1178 // So far this is only intended for error pages that are not expected to be
1179 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281180 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071181 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291182 } else {
[email protected]726985e22009-06-18 21:09:281183 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291184 }
1185
1186 // Set the URL to be displayed in the browser UI to the user.
[email protected]69ddf852012-02-21 23:21:311187 params.url = GetLoadingUrl(frame);
initial.commit09911bf2008-07-26 23:55:291188
[email protected]5f9b8712011-11-23 08:55:571189 if (frame->document().baseURL() != params.url)
1190 params.base_url = frame->document().baseURL();
1191
[email protected]726985e22009-06-18 21:09:281192 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241193 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041194 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291195
[email protected]007733c2011-11-17 00:34:071196 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351197 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071198 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291199
1200 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071201 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291202 if (password_form_data)
1203 params.password_form = *password_form_data;
1204
1205 params.gesture = navigation_gesture_;
1206 navigation_gesture_ = NavigationGestureUnknown;
1207
[email protected]0f38dc4552011-02-25 11:24:001208 // Make navigation state a part of the FrameNavigate message so that commited
1209 // entry had it at all times.
1210 const WebHistoryItem& item = frame->currentHistoryItem();
1211 if (!item.isNull()) {
1212 params.content_state = webkit_glue::HistoryItemToString(item);
1213 } else {
1214 params.content_state =
1215 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1216 }
1217
[email protected]dd7daa82009-08-10 05:46:451218 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291219 // Top-level navigation.
1220
[email protected]b75b8292010-10-01 07:28:251221 // Set zoom level, but don't do it for full-page plugin since they don't use
1222 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011223 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541224 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251225 if (webview()->mainFrame()->document().isPluginDocument()) {
1226 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251227 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251228 } else {
1229 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251230 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251231 }
1232
[email protected]f85f0702010-01-30 09:31:011233 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511234 // This zoom level was merely recorded transiently for this load. We can
1235 // erase it now. If at some point we reload this page, the browser will
1236 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011237 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511238 }
1239
[email protected]b75b8292010-10-01 07:28:251240 // Reset the zoom limits in case a plugin had changed them previously. This
1241 // will also call us back which will cause us to send a message to
1242 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251243 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011244 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1245 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251246
initial.commit09911bf2008-07-26 23:55:291247 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551248 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291249
[email protected]daa8c58e2009-06-15 17:21:101250 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581251 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291252 // If the main frame does a load, it should not be reported as a subframe
1253 // navigation. This can occur in the following case:
1254 // 1. You're on a site with frames.
1255 // 2. You do a subframe navigation. This is stored with transition type
1256 // MANUAL_SUBFRAME.
1257 // 3. You navigate to some non-frame site, say, google.com.
1258 // 4. You navigate back to the page from step 2. Since it was initially
1259 // MANUAL_SUBFRAME, it will be that same transition type here.
1260 // We don't want that, because any navigation that changes the toplevel
1261 // frame should be tracked as a toplevel navigation (this allows us to
1262 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581263 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291264 }
1265
initial.commit09911bf2008-07-26 23:55:291266 // If we have a valid consumed client redirect source,
1267 // the page contained a client redirect (meta refresh, document.loc...),
1268 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151269 if (completed_client_redirect_src_.url.is_valid()) {
1270 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291271 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581272 params.transition = static_cast<content::PageTransition>(
1273 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291274 } else {
1275 // Bug 654101: the referrer will be empty on https->http transitions. It
1276 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151277 params.referrer = Referrer(GURL(
1278 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:401279 GetReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291280 }
1281
[email protected]726985e22009-06-18 21:09:281282 string16 method = request.httpMethod();
[email protected]86cd9472012-02-03 19:51:051283 if (EqualsASCII(method, "POST")) {
initial.commit09911bf2008-07-26 23:55:291284 params.is_post = true;
[email protected]86cd9472012-02-03 19:51:051285 params.post_id = ExtractPostId(item);
1286 }
initial.commit09911bf2008-07-26 23:55:291287
[email protected]c2a797d2009-09-21 16:46:321288 // Save some histogram data so we can compute the average memory used per
1289 // page load of the glyphs.
1290 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1291 webkit_glue::GetGlyphPageCount());
1292
[email protected]15cf526b2010-02-12 06:33:491293 // This message needs to be sent before any of allowScripts(),
1294 // allowImages(), allowPlugins() is called for the new page, so that when
1295 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1296 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291297 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1298 } else {
1299 // Subframe navigation: the type depends on whether this navigation
1300 // generated a new session history entry. When they do generate a session
1301 // history entry, it means the user initiated the navigation and we should
1302 // mark it as such. This test checks if this is the first time UpdateURL
1303 // has been called since WillNavigateToURL was called to initiate the load.
1304 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581305 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291306 else
[email protected]2905f742011-10-13 03:51:581307 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291308
initial.commit09911bf2008-07-26 23:55:291309 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1310 }
1311
1312 last_page_id_sent_to_browser_ =
1313 std::max(last_page_id_sent_to_browser_, page_id_);
1314
1315 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101316 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581317 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291318}
1319
1320// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281321void RenderViewImpl::UpdateTitle(WebFrame* frame,
1322 const string16& title,
1323 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461324 // Ignore all but top level navigations.
1325 if (frame->parent())
1326 return;
1327
1328 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1329 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1330 title_direction));
initial.commit09911bf2008-07-26 23:55:291331}
1332
[email protected]310ebd6302011-10-10 19:06:281333void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1334 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291335 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271336 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291337 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301338 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291339 last_encoding_name_ = encoding_name;
1340
[email protected]e38f40152008-09-12 23:08:301341 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291342 }
1343}
1344
[email protected]e15f680732010-11-23 22:30:201345// Sends the last committed session history state to the browser so it will be
1346// saved before we navigate to a new page. This must be called *before* the
1347// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281348void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291349 // If we have a valid page ID at this point, then it corresponds to the page
1350 // we are navigating away from. Otherwise, this is the first navigation, so
1351 // there is no past session history to record.
1352 if (page_id_ == -1)
1353 return;
1354
[email protected]ca948a22009-06-25 19:36:171355 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271356 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171357 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291358 return;
[email protected]ca948a22009-06-25 19:36:171359
1360 Send(new ViewHostMsg_UpdateState(
1361 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291362}
1363
[email protected]310ebd6302011-10-10 19:06:281364void RenderViewImpl::OpenURL(WebFrame* frame,
1365 const GURL& url,
[email protected]445e1042011-12-03 21:03:151366 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281367 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171368 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581369 routing_id_,
1370 url,
1371 referrer,
1372 NavigationPolicyToDisposition(policy),
1373 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171374}
1375
[email protected]79dbc662009-09-04 05:42:511376// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291377
[email protected]310ebd6302011-10-10 19:06:281378void RenderViewImpl::LoadNavigationErrorPage(
1379 WebFrame* frame,
1380 const WebURLRequest& failed_request,
1381 const WebURLError& error,
1382 const std::string& html,
1383 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581384 std::string alt_html;
1385 const std::string* error_html;
1386
1387 if (!html.empty()) {
1388 error_html = &html;
1389 } else {
1390 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1391 failed_request, error, &alt_html, NULL);
1392 error_html = &alt_html;
1393 }
1394
1395 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361396 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251397 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551398 replace);
initial.commit09911bf2008-07-26 23:55:291399}
1400
[email protected]269f86d2011-12-07 02:43:471401bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281402 const string16& message,
1403 const string16& default_value,
1404 const GURL& frame_url,
1405 string16* result) {
initial.commit09911bf2008-07-26 23:55:291406 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411407 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291408 if (!result)
1409 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291410
[email protected]12636df2009-09-28 22:32:211411 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1412 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291413 return success;
1414}
1415
[email protected]310ebd6302011-10-10 19:06:281416bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571417 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1418 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1419 // it is particularly important that we do not call willEnterModalLoop as
1420 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441421 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1422 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571423
1424 message->EnableMessagePumping(); // Runs a nested message loop.
1425 return Send(message);
1426}
1427
[email protected]48c9cf2d2009-09-16 16:47:521428// WebKit::WebViewClient ------------------------------------------------------
1429
[email protected]916dfb62012-03-05 03:39:371430// TODO(creis): New contract for createView temporarily redirects to the old
1431// contract. Remove the old one as part of http://crbug.com/69267.
1432WebView* RenderViewImpl::createView(
1433 WebFrame* creator,
1434 const WebURLRequest& request,
1435 const WebWindowFeatures& features,
1436 const WebString& frame_name,
1437 WebNavigationPolicy policy) {
1438 return createView(creator, request, features, frame_name);
1439}
1440
[email protected]310ebd6302011-10-10 19:06:281441WebView* RenderViewImpl::createView(
[email protected]844acf372011-01-14 10:49:271442 WebFrame* creator,
1443 const WebURLRequest& request,
1444 const WebWindowFeatures& features,
1445 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521446 // Check to make sure we aren't overloading on popups.
1447 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1448 return NULL;
1449
[email protected]8ab04652010-06-12 02:47:261450 ViewHostMsg_CreateWindow_Params params;
1451 params.opener_id = routing_id_;
1452 params.user_gesture = creator->isProcessingUserGesture();
1453 params.window_container_type = WindowFeaturesToContainerType(features);
1454 params.session_storage_namespace_id = session_storage_namespace_id_;
1455 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111456 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411457 params.opener_url = creator->document().url();
1458 params.opener_security_origin =
1459 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111460 if (!request.isNull())
1461 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261462
[email protected]48c9cf2d2009-09-16 16:47:521463 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561464 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341465 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261466 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521467
[email protected]380244092011-10-07 17:26:271468 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261469 new ViewHostMsg_CreateWindow(params,
1470 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561471 &surface_id,
[email protected]8ab04652010-06-12 02:47:261472 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211473 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521474 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521475
[email protected]310ebd6302011-10-10 19:06:281476 RenderViewImpl* view = RenderViewImpl::Create(
1477 0,
1478 routing_id_,
1479 renderer_preferences_,
1480 webkit_preferences_,
1481 shared_popup_counter_,
1482 routing_id,
[email protected]9f4f3322012-01-18 22:29:561483 surface_id,
[email protected]310ebd6302011-10-10 19:06:281484 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461485 frame_name,
[email protected]6fd35b72012-03-01 19:46:411486 1,
1487 screen_info_);
[email protected]8ab04652010-06-12 02:47:261488 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521489
[email protected]007a848b2009-10-26 15:55:461490 // Record whether the creator frame is trying to suppress the opener field.
1491 view->opener_suppressed_ = opener_suppressed;
1492
[email protected]48c9cf2d2009-09-16 16:47:521493 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411494 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521495 if (!creator_url.is_valid() || !creator_url.IsStandard())
1496 creator_url = GURL();
1497 view->creator_url_ = creator_url;
1498
1499 // Copy over the alternate error page URL so we can have alt error pages in
1500 // the new render view (we don't need the browser to send the URL back down).
1501 view->alternate_error_page_url_ = alternate_error_page_url_;
1502
1503 return view->webview();
1504}
1505
[email protected]310ebd6302011-10-10 19:06:281506WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411507 RenderWidget* widget =
1508 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521509 return widget->webwidget();
1510}
1511
[email protected]310ebd6302011-10-10 19:06:281512WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441513 // TODO(jcivelli): Remove this deprecated method when its been removed from
1514 // the WebViewClient interface. It's been replaced by
1515 // createExternalPopupMenu.
1516 NOTREACHED();
1517 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521518}
1519
[email protected]310ebd6302011-10-10 19:06:281520WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081521 const WebPopupMenuInfo& popup_menu_info,
1522 WebExternalPopupMenuClient* popup_menu_client) {
1523 DCHECK(!external_popup_menu_.get());
1524 external_popup_menu_.reset(
1525 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1526 return external_popup_menu_.get();
1527}
1528
[email protected]310ebd6302011-10-10 19:06:281529RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521530 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531531 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421532 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411533 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531534 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271535 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391536 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561537 return widget;
[email protected]79c7bed2010-09-14 22:28:391538}
1539
[email protected]310ebd6302011-10-10 19:06:281540WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1541 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341542 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391543 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291544 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1545 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1546 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341547}
1548
[email protected]7e8b4d12012-01-20 23:39:511549WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]01e69032012-01-31 05:39:061550 const WebGraphicsContext3D::Attributes& attributes,
[email protected]7e8b4d12012-01-20 23:39:511551 bool direct) {
1552 if (!webview())
1553 return NULL;
1554 // The WebGraphicsContext3DInProcessImpl code path is used for
1555 // layout tests (though not through this code) as well as for
1556 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511557 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571558 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
[email protected]33a9c762012-02-23 22:37:241559 attributes, direct);
[email protected]7e8b4d12012-01-20 23:39:511560 } else {
[email protected]b3e83de2012-02-07 03:33:281561 int surface = direct ? surface_id() : 0;
1562
1563 GURL url;
1564 if (webview()->mainFrame())
1565 url = GURL(webview()->mainFrame()->document().url());
1566
1567 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client;
1568 if (direct)
1569 swap_client = AsWeakPtr();
1570
1571 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1572 new WebGraphicsContext3DCommandBufferImpl(
1573 surface, url, swap_client));
1574
1575 if (!context->Initialize(attributes))
[email protected]56200f012012-02-03 23:13:571576 return NULL;
1577 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511578 }
[email protected]7e8b4d12012-01-20 23:39:511579}
1580
[email protected]310ebd6302011-10-10 19:06:281581void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521582 const WebConsoleMessage& message, const WebString& source_name,
1583 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081584 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511585 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081586 case WebConsoleMessage::LevelTip:
1587 log_severity = logging::LOG_VERBOSE;
1588 break;
1589 case WebConsoleMessage::LevelLog:
1590 log_severity = logging::LOG_INFO;
1591 break;
1592 case WebConsoleMessage::LevelWarning:
1593 log_severity = logging::LOG_WARNING;
1594 break;
1595 case WebConsoleMessage::LevelError:
1596 log_severity = logging::LOG_ERROR;
1597 break;
1598 default:
1599 NOTREACHED();
1600 }
1601
[email protected]48c9cf2d2009-09-16 16:47:521602 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081603 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311604 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521605 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311606 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521607}
1608
[email protected]310ebd6302011-10-10 19:06:281609void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421610 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521611}
1612
[email protected]310ebd6302011-10-10 19:06:281613WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511614 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021615}
1616
[email protected]310ebd6302011-10-10 19:06:281617bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121618 const WebString& path,
1619 WebFileChooserCompletion* chooser_completion) {
1620 int id = enumeration_completion_id_++;
1621 enumeration_completions_[id] = chooser_completion;
1622 return Send(new ViewHostMsg_EnumerateDirectory(
1623 routing_id_,
1624 id,
1625 webkit_glue::WebStringToFilePath(path)));
1626}
1627
[email protected]310ebd6302011-10-10 19:06:281628void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521629 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141630 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521631 return;
1632 }
1633
1634 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521635
1636 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311637
1638 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521639}
1640
[email protected]310ebd6302011-10-10 19:06:281641void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521642 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141643 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521644 return;
1645 }
1646
1647 is_loading_ = false;
1648
1649 // NOTE: For now we're doing the safest thing, and sending out notification
1650 // when done loading. This currently isn't an issue as the favicon is only
1651 // displayed when done loading. Ideally we would send notification when
1652 // finished parsing the head, but webkit doesn't support that yet.
1653 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521654 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1655
[email protected]90109412010-12-15 17:14:241656 if (load_progress_tracker_ != NULL)
1657 load_progress_tracker_->DidStopLoading();
1658
[email protected]93b9d692011-04-13 00:44:311659 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521660}
1661
[email protected]310ebd6302011-10-10 19:06:281662void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1663 double load_progress) {
[email protected]90109412010-12-15 17:14:241664 if (load_progress_tracker_ != NULL)
1665 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1666}
1667
[email protected]310ebd6302011-10-10 19:06:281668bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061669#if defined(OS_MACOSX)
1670 return true;
1671#else
1672 return false;
1673#endif
1674}
1675
[email protected]310ebd6302011-10-10 19:06:281676bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031677#if defined(OS_WIN)
1678 return true;
1679#else
1680 return false;
1681#endif
1682}
1683
[email protected]310ebd6302011-10-10 19:06:281684void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081685 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031686 return;
[email protected]4fb60142011-08-09 02:22:081687 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011688
[email protected]b781ff282011-08-20 06:19:361689 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031690}
1691
[email protected]310ebd6302011-10-10 19:06:281692void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121693 const std::string& name = UTF16ToUTF8(command_name);
1694 if (StartsWithASCII(name, "Move", true) ||
1695 StartsWithASCII(name, "Insert", true) ||
1696 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031697 return;
[email protected]f1a29a02011-10-06 23:08:441698 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031699}
1700
[email protected]310ebd6302011-10-10 19:06:281701bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101702 if (edit_commands_.empty())
1703 return false;
1704
[email protected]26aa0482009-09-30 16:55:271705 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101706 if (!frame)
1707 return false;
1708
1709 EditCommands::iterator it = edit_commands_.begin();
1710 EditCommands::iterator end = edit_commands_.end();
1711
[email protected]507b33ea2009-09-29 03:56:511712 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101713 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331714 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1715 // key (but it's the exception). Once one edit command is not executed, it
1716 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101717 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1718 WebString::fromUTF8(it->value)))
1719 break;
[email protected]507b33ea2009-09-29 03:56:511720 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101721 }
1722
[email protected]507b33ea2009-09-29 03:56:511723 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101724}
1725
[email protected]310ebd6302011-10-10 19:06:281726bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351727 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471728 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351729 // Do not open the file dialog in a hidden RenderView.
1730 if (is_hidden())
1731 return false;
[email protected]8caadeb2011-11-22 02:45:231732 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261733 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231734 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261735 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231736 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501737 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231738 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261739 else
[email protected]8caadeb2011-11-22 02:45:231740 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471741 ipc_params.title = params.title;
1742 ipc_params.default_file_name =
1743 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461744 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1745 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1746 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471747
1748 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461749}
1750
[email protected]269f86d2011-12-07 02:43:471751void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1752 const WebString& message) {
1753 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411754 message,
1755 string16(),
[email protected]b6cb3a842011-06-24 18:28:411756 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521757 NULL);
1758}
1759
[email protected]269f86d2011-12-07 02:43:471760bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1761 const WebString& message) {
1762 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411763 message,
1764 string16(),
[email protected]b6cb3a842011-06-24 18:28:411765 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521766 NULL);
1767}
1768
[email protected]269f86d2011-12-07 02:43:471769bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1770 const WebString& message,
1771 const WebString& default_value,
1772 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411773 string16 result;
[email protected]269f86d2011-12-07 02:43:471774 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411775 message,
1776 default_value,
[email protected]b6cb3a842011-06-24 18:28:411777 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521778 &result);
1779 if (ok)
[email protected]4f5ce842011-05-27 19:34:411780 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521781 return ok;
1782}
1783
[email protected]310ebd6302011-10-10 19:06:281784bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521785 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151786 // If we are swapping out, we have already run the beforeunload handler.
1787 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1788 // at all, to avoid running it twice.
1789 if (is_swapped_out_)
1790 return true;
1791
[email protected]3b3301f62012-02-29 04:32:321792 bool is_reload = false;
1793 WebDataSource* ds = frame->provisionalDataSource();
1794 if (ds)
1795 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
1796
[email protected]48c9cf2d2009-09-16 16:47:521797 bool success = false;
1798 // This is an ignored return value, but is included so we can accept the same
1799 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411800 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211801 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:321802 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:411803 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521804 return success;
1805}
1806
[email protected]310ebd6302011-10-10 19:06:281807void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441808 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:511809 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:371810
1811 // frame is NULL if invoked by BlockedPlugin.
1812 if (frame)
1813 params.frame_id = frame->identifier();
1814
[email protected]db803aae2011-03-05 02:00:421815 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271816 // it. We replace it with an empty GURL so the appropriate items are disabled
1817 // in the context menu.
1818 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1819 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421820 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271821 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101822 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291823 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441824}
1825
[email protected]310ebd6302011-10-10 19:06:281826void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261827 // TODO(darin): Remove once WebKit roll is complete.
1828 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471829}
1830
[email protected]310ebd6302011-10-10 19:06:281831void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261832 // TODO(darin): Remove once WebKit roll is complete.
1833 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471834}
1835
[email protected]310ebd6302011-10-10 19:06:281836void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521837}
1838
[email protected]310ebd6302011-10-10 19:06:281839void RenderViewImpl::UpdateTargetURL(const GURL& url,
1840 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581841 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521842 if (latest_url == target_url_)
1843 return;
[email protected]163f8242009-10-30 20:19:551844
[email protected]48c9cf2d2009-09-16 16:47:521845 // Tell the browser to display a destination link.
1846 if (target_url_status_ == TARGET_INFLIGHT ||
1847 target_url_status_ == TARGET_PENDING) {
1848 // If we have a request in-flight, save the URL to be sent when we
1849 // receive an ACK to the in-flight request. We can happily overwrite
1850 // any existing pending sends.
1851 pending_target_url_ = latest_url;
1852 target_url_status_ = TARGET_PENDING;
1853 } else {
[email protected]c85f0212011-11-04 16:54:411854 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1855 // see |ParamTraits<GURL>|.
1856 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1857 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521858 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1859 target_url_ = latest_url;
1860 target_url_status_ = TARGET_INFLIGHT;
1861 }
1862}
1863
[email protected]310ebd6302011-10-10 19:06:281864void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311865 int delay;
1866 if (send_content_state_immediately_)
1867 delay = 0;
1868 else if (is_hidden())
1869 delay = kDelaySecondsForContentStateSyncHidden;
1870 else
1871 delay = kDelaySecondsForContentStateSync;
1872
1873 if (nav_state_sync_timer_.IsRunning()) {
1874 // The timer is already running. If the delay of the timer maches the amount
1875 // we want to delay by, then return. Otherwise stop the timer so that it
1876 // gets started with the right delay.
1877 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1878 return;
1879 nav_state_sync_timer_.Stop();
1880 }
1881
[email protected]d323a172011-09-02 18:23:021882 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281883 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311884}
1885
[email protected]310ebd6302011-10-10 19:06:281886void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551887 mouse_over_url_ = GURL(url);
1888 UpdateTargetURL(mouse_over_url_, focus_url_);
1889}
1890
[email protected]310ebd6302011-10-10 19:06:281891void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551892 focus_url_ = GURL(url);
1893 UpdateTargetURL(focus_url_, mouse_over_url_);
1894}
1895
[email protected]310ebd6302011-10-10 19:06:281896void RenderViewImpl::startDragging(const WebDragData& data,
1897 WebDragOperationsMask mask,
1898 const WebImage& image,
1899 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411900#if WEBKIT_USING_SKIA
1901 SkBitmap bitmap(image.getSkBitmap());
1902#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331903 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411904#endif
1905
[email protected]59f4f2fa2011-03-23 01:00:551906 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521907 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411908 mask,
1909 bitmap,
1910 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521911}
1912
[email protected]310ebd6302011-10-10 19:06:281913bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451914 return renderer_preferences_.can_accept_load_drops;
1915}
1916
[email protected]310ebd6302011-10-10 19:06:281917void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521918 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1919}
1920
[email protected]310ebd6302011-10-10 19:06:281921void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521922 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1923}
1924
[email protected]310ebd6302011-10-10 19:06:281925void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511926 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071927
[email protected]38b592902011-04-16 02:08:421928 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491929}
1930
[email protected]169d4282011-11-30 19:33:591931void RenderViewImpl::didUpdateLayout() {
1932 // We don't always want to set up a timer, only if we've been put in that
1933 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1934 // message.
1935 if (!send_preferred_size_changes_ || !webview())
1936 return;
1937
1938 if (check_preferred_size_timer_.IsRunning())
1939 return;
1940 check_preferred_size_timer_.Start(FROM_HERE,
1941 TimeDelta::FromMilliseconds(0), this,
1942 &RenderViewImpl::CheckPreferredSize);
1943}
1944
[email protected]310ebd6302011-10-10 19:06:281945void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521946 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1947}
1948
[email protected]310ebd6302011-10-10 19:06:281949int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001950 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521951}
1952
[email protected]310ebd6302011-10-10 19:06:281953int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001954 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521955}
1956
[email protected]310ebd6302011-10-10 19:06:281957void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321958 const WebAccessibilityObject& obj,
1959 WebAccessibilityNotification notification) {
1960 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1961}
1962
[email protected]310ebd6302011-10-10 19:06:281963void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141964 const WebString& value) {
1965 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1966 key.utf8(),
1967 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261968}
1969
[email protected]79dbc662009-09-04 05:42:511970// WebKit::WebWidgetClient ----------------------------------------------------
1971
[email protected]310ebd6302011-10-10 19:06:281972void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121973 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1974 // we won't have to test for user gesture anymore and we can
1975 // move that code back to render_widget.cc
1976 if (webview() && webview()->mainFrame() &&
1977 webview()->mainFrame()->isProcessingUserGesture()) {
1978 Send(new ViewHostMsg_Focus(routing_id_));
1979 }
1980}
1981
[email protected]310ebd6302011-10-10 19:06:281982void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121983 // TODO(jcivelli): see TODO above in didFocus().
1984 if (webview() && webview()->mainFrame() &&
1985 webview()->mainFrame()->isProcessingUserGesture()) {
1986 Send(new ViewHostMsg_Blur(routing_id_));
1987 }
1988}
1989
initial.commit09911bf2008-07-26 23:55:291990// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281991// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291992// point to dispatch the ShowView message.
1993//
1994// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281995// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291996//
[email protected]310ebd6302011-10-10 19:06:281997void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291998 DCHECK(!did_show_) << "received extraneous Show call";
1999 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2000
2001 if (did_show_)
2002 return;
2003 did_show_ = true;
2004
[email protected]6779aa12011-03-29 17:32:242005 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:042006 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:042007
[email protected]28295ec2009-10-16 05:34:332008 // Force new windows to a popup if they were not opened with a user gesture.
2009 if (!opened_by_user_gesture_) {
2010 // We exempt background tabs for compat with older versions of Chrome.
2011 // TODO(darin): This seems bogus. These should have a user gesture, so
2012 // we probably don't need this check.
2013 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2014 policy = WebKit::WebNavigationPolicyNewPopup;
2015 }
2016
initial.commit09911bf2008-07-26 23:55:292017 // NOTE: initial_pos_ may still have its default values at this point, but
2018 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2019 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282020 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2021 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292022 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242023 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292024}
2025
[email protected]310ebd6302011-10-10 19:06:282026void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292027 DCHECK(did_show_) << "should already have shown the view";
2028
[email protected]c1f50aa2010-02-18 03:46:572029 // We must keep WebKit's shared timer running in this case in order to allow
2030 // showModalDialog to function properly.
2031 //
2032 // TODO(darin): WebKit should really be smarter about suppressing events and
2033 // timers so that we do not need to manage the shared timer in such a heavy
2034 // handed manner.
2035 //
[email protected]f1a29a02011-10-06 23:08:442036 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2037 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572038
[email protected]12636df2009-09-28 22:32:212039 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292040}
2041
[email protected]2b624c562011-10-27 22:58:262042bool RenderViewImpl::enterFullScreen() {
2043 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2044 return true;
2045}
2046
2047void RenderViewImpl::exitFullScreen() {
2048 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2049}
2050
[email protected]217690d2012-01-27 07:33:112051bool RenderViewImpl::requestPointerLock() {
2052 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2053}
2054
2055void RenderViewImpl::requestPointerUnlock() {
2056 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2057}
2058
2059bool RenderViewImpl::isPointerLocked() {
2060 return mouse_lock_dispatcher_->IsMouseLockedTo(
2061 webwidget_mouse_lock_target_.get());
2062}
2063
[email protected]3d9689372009-09-10 04:29:172064// WebKit::WebFrameClient -----------------------------------------------------
2065
[email protected]310ebd6302011-10-10 19:06:282066WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2067 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552068 WebPlugin* plugin = NULL;
2069 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2070 this, frame, params, &plugin)) {
2071 return plugin;
2072 }
2073
[email protected]a813c8e2011-10-08 01:34:112074 webkit::WebPluginInfo info;
2075 std::string mime_type;
2076 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2077 params.mimeType.utf8(), &info, &mime_type);
2078 if (!found)
2079 return NULL;
2080
2081 WebPluginParams params_to_use = params;
2082 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312083 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172084}
2085
[email protected]310ebd6302011-10-10 19:06:282086WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422087 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372088 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422089
[email protected]30447b62009-11-13 01:13:372090 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512091 bool exists = false;
[email protected]30447b62009-11-13 01:13:372092 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512093 ViewHostMsg_CreateWorker_Params params;
2094 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512095 params.name = name;
2096 params.document_id = document_id;
2097 params.render_view_route_id = routing_id_;
2098 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232099 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372100 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512101 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372102 if (url_mismatch) {
2103 return NULL;
2104 } else {
[email protected]f1a29a02011-10-06 23:08:442105 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492106 document_id,
[email protected]6de0bcf2010-02-17 22:00:512107 exists,
[email protected]30447b62009-11-13 01:13:372108 route_id,
2109 routing_id_);
2110 }
[email protected]9c00f002009-11-05 22:37:422111}
2112
[email protected]310ebd6302011-10-10 19:06:282113WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172114 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442115 FOR_EACH_OBSERVER(
2116 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172117
[email protected]bb6fd402011-12-09 02:45:442118 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502119 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442120 media::FilterCollection* collection = new media::FilterCollection();
2121 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372122
[email protected]9e2269d2012-01-07 00:06:212123 RenderAudioSourceProvider* audio_source_provider = NULL;
2124
[email protected]3d9689372009-09-10 04:29:172125 // Add in any custom filter factories first.
2126 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2127 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212128 // audio_source_provider is a "provider" to WebKit, and a sink
2129 // from the perspective of the audio renderer.
2130 audio_source_provider = new RenderAudioSourceProvider();
2131
2132 // Add the chrome specific audio renderer, using audio_source_provider
2133 // as the sink.
2134 AudioRendererImpl* audio_renderer =
2135 new AudioRendererImpl(audio_source_provider);
2136 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172137 }
2138
[email protected]e1d69d762011-12-13 05:12:182139#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
2140 // Currently only cros/arm has any HW video decode support in
2141 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2142 // platforms. This is a startup-time optimization. When new VDA
2143 // implementations are added, relax the #if above.
[email protected]43567302012-02-16 23:21:392144 WebGraphicsContext3DCommandBufferImpl* context3d =
2145 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2146 webview()->graphicsContext3D());
2147 if (context3d && context3d->makeContextCurrent()) {
[email protected]e1d69d762011-12-13 05:12:182148 GpuChannelHost* gpu_channel_host =
2149 RenderThreadImpl::current()->EstablishGpuChannelSync(
2150 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2151 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312152 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
2153 new RendererGpuVideoDecoderFactories(
2154 gpu_channel_host, context3d->context()->AsWeakPtr())));
[email protected]e1d69d762011-12-13 05:12:182155 }
2156#endif
2157
[email protected]da952fd2012-01-13 03:49:252158 webkit_media::WebMediaPlayerImpl* media_player =
2159 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2160 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
2161 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]c4dabe452012-02-08 23:58:122162#if defined(OS_ANDROID)
2163 // TODO(qinmin): Implement for android.
2164 // http://crbug.com/113218
2165#else
[email protected]da952fd2012-01-13 03:49:252166 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562167 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252168 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]9e2269d2012-01-07 00:06:212169 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]bb6fd402011-12-09 02:45:442170 }
[email protected]c4dabe452012-02-08 23:58:122171#endif
[email protected]cec4eb82012-01-12 17:51:562172 return media_player;
[email protected]3d9689372009-09-10 04:29:172173}
2174
[email protected]310ebd6302011-10-10 19:06:282175WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212176 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232177 if (!frame || !frame->view())
2178 return NULL;
[email protected]035545f2010-04-09 13:10:212179 return new RendererWebApplicationCacheHostImpl(
2180 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442181 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212182}
2183
[email protected]310ebd6302011-10-10 19:06:282184WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382185 return &cookie_jar_;
2186}
2187
[email protected]310ebd6302011-10-10 19:06:282188void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512189 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452190}
2191
[email protected]310ebd6302011-10-10 19:06:282192void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512193 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172194}
2195
[email protected]310ebd6302011-10-10 19:06:282196void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172197 WebFrame* frame, const WebURLRequest& request,
2198 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342199 loadURLExternally(frame, request, policy, WebString());
2200}
2201
[email protected]310ebd6302011-10-10 19:06:282202void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342203 WebFrame* frame, const WebURLRequest& request,
2204 WebNavigationPolicy policy,
2205 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592206 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2207 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342208 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2209 suggested_name));
[email protected]efce17b2009-09-11 18:04:592210 } else {
[email protected]445e1042011-12-03 21:03:152211 OpenURL(frame, request.url(),
[email protected]b9fd01ba2012-02-28 01:50:402212 Referrer(referrer, GetReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592213 }
[email protected]3d9689372009-09-10 04:29:172214}
2215
[email protected]310ebd6302011-10-10 19:06:282216WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172217 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222218 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152219 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2220 if (is_swapped_out_) {
[email protected]73eb2602012-02-09 19:50:552221 // It is possible for in-progress navigations to arrive here just after we
2222 // are swapped out, including iframes. We should cancel them.
2223 if (request.url() != GURL("about:swappedout"))
2224 return WebKit::WebNavigationPolicyIgnore;
2225
2226 // Allow about:swappedout to complete.
[email protected]992db4c2011-05-12 15:37:152227 return default_policy;
2228 }
2229
[email protected]3d9689372009-09-10 04:29:172230 // Webkit is asking whether to navigate to a new URL.
2231 // This is fine normally, except if we're showing UI from one security
2232 // context and they're trying to navigate to a different context.
2233 const GURL& url = request.url();
2234
[email protected]d19ea342011-04-20 20:31:132235 // A content initiated navigation may have originated from a link-click,
2236 // script, drag-n-drop operation, etc.
2237 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072238 DocumentState::FromDataSource(frame->provisionalDataSource())->
2239 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132240
[email protected]a8c269a2011-10-25 20:17:222241 // Experimental:
2242 // If --enable-strict-site-isolation is enabled, send all top-level
2243 // navigations to the browser to let it swap processes when crossing site
2244 // boundaries. This is currently expected to break some script calls and
2245 // navigations, such as form submissions.
2246 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102247 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2248 !frame->parent() && (is_content_initiated || is_redirect)) {
2249 WebString origin_str = frame->document().securityOrigin().toString();
2250 GURL frame_url(origin_str.utf8().data());
2251 // TODO(cevans): revisit whether this origin check is still necessary once
2252 // crbug.com/101395 is fixed.
2253 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]445e1042011-12-03 21:03:152254 Referrer referrer(
2255 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402256 GetReferrerPolicyFromRequest(request));
[email protected]313b80bd2011-11-23 03:49:102257 OpenURL(frame, url, referrer, default_policy);
2258 return WebKit::WebNavigationPolicyIgnore;
2259 }
[email protected]a8c269a2011-10-25 20:17:222260 }
2261
[email protected]3d9689372009-09-10 04:29:172262 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302263 // navigations.
[email protected]5f000f272012-01-19 05:25:082264 if (is_content_initiated) {
2265 bool browser_handles_top_level_requests =
2266 renderer_preferences_.browser_handles_top_level_requests &&
2267 IsNonLocalTopLevelNavigation(url, frame, type);
2268 if (browser_handles_top_level_requests ||
2269 renderer_preferences_.browser_handles_all_requests) {
2270 Referrer referrer(
2271 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402272 GetReferrerPolicyFromRequest(request));
[email protected]5f000f272012-01-19 05:25:082273 // Reset these counters as the RenderView could be reused for the next
2274 // navigation.
2275 page_id_ = -1;
2276 last_page_id_sent_to_browser_ = -1;
2277 OpenURL(frame, url, referrer, default_policy);
2278 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2279 }
[email protected]3d9689372009-09-10 04:29:172280 }
2281
[email protected]6101c342010-12-16 22:44:372282 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552283 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572284 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372285 // opening a new window). But we sometimes navigate to about:blank to clear a
2286 // tab, and we want to still allow that.
2287 //
[email protected]8f4da8c2011-02-09 19:49:572288 // Note: we do this only for GET requests because our mechanism for switching
2289 // processes only issues GET requests. In particular, POST requests don't
2290 // work, because this mechanism does not preserve form POST data. If it
2291 // becomes necessary to support process switching for POST requests, we will
2292 // need to send the request's httpBody data up to the browser process, and
2293 // issue a special POST navigation in WebKit (via
2294 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2295 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222296 if (!frame->parent() && is_content_initiated &&
[email protected]6101c342010-12-16 22:44:372297 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2298 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2299 bool send_referrer = false;
2300 bool should_fork =
[email protected]e091df82011-10-11 18:13:212301 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172302 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372303 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112304
[email protected]e48869a2011-04-01 19:56:032305 if (!should_fork) {
2306 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362307 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032308 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]3f105a2f2012-02-25 18:27:362309 frame, url, is_initial_navigation, &send_referrer);
[email protected]6101c342010-12-16 22:44:372310 }
2311
2312 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152313 Referrer referrer(
2314 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402315 GetReferrerPolicyFromRequest(request));
[email protected]445e1042011-12-03 21:03:152316 OpenURL(
2317 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112318 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2319 }
[email protected]3d9689372009-09-10 04:29:172320 }
2321
[email protected]43763f982011-08-26 18:33:402322 // Use the frame's original request's URL rather than the document's URL for
2323 // this check. For a popup, the document's URL may become the opener window's
2324 // URL if the opener has called document.write. See http://crbug.com/93517.
2325 GURL old_url(frame->dataSource()->request().url());
2326
[email protected]3d9689372009-09-10 04:29:172327 // Detect when a page is "forking" a new tab that can be safely rendered in
2328 // its own process. This is done by sites like Gmail that try to open links
2329 // in new windows without script connections back to the original page. We
2330 // treat such cases as browser navigations (in which we will create a new
2331 // renderer for a cross-site navigation), rather than WebKit navigations.
2332 //
2333 // We use the following heuristic to decide whether to fork a new page in its
2334 // own process:
2335 // The parent page must open a new tab to about:blank, set the new tab's
2336 // window.opener to null, and then redirect the tab to a cross-site URL using
2337 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462338 //
2339 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2340 // (see below).
[email protected]3d9689372009-09-10 04:29:172341 bool is_fork =
2342 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582343 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172344 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522345 historyBackListCount() < 1 &&
2346 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172347 // The parent page must have set the child's window.opener to null before
2348 // redirecting to the desired URL.
2349 frame->opener() == NULL &&
2350 // Must be a top-level frame.
2351 frame->parent() == NULL &&
2352 // Must not have issued the request from this page.
2353 is_content_initiated &&
2354 // Must be targeted at the current tab.
2355 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2356 // Must be a JavaScript navigation, which appears as "other".
2357 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462358
2359 // Recognize if this navigation is from a link with rel=noreferrer and
2360 // target=_blank attributes, in which case the opener will be suppressed. If
2361 // so, it is safe to load cross-site pages in a separate process, so we
2362 // should let the browser handle it.
2363 bool is_noreferrer_and_blank_target =
2364 // Frame should be top level and not yet navigated.
2365 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412366 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462367 historyBackListCount() < 1 &&
2368 historyForwardListCount() < 1 &&
2369 // Links with rel=noreferrer will have no Referer field, and their
2370 // resulting frame will have its window.opener suppressed.
2371 // TODO(creis): should add a request.httpReferrer() method to help avoid
2372 // typos on the unusual spelling of Referer.
2373 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2374 opener_suppressed_ &&
2375 frame->opener() == NULL &&
2376 // Links with target=_blank will have no name.
2377 frame->name().isNull() &&
2378 // Another frame (with a non-empty creator) should have initiated the
2379 // request, targeted at this frame.
2380 !creator_url_.is_empty() &&
2381 is_content_initiated &&
2382 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2383 type == WebKit::WebNavigationTypeOther;
2384
2385 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172386 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152387 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172388 return WebKit::WebNavigationPolicyIgnore;
2389 }
2390
2391 return default_policy;
2392}
2393
[email protected]310ebd6302011-10-10 19:06:282394bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492395 WebFrame* frame, const WebURLRequest& request) {
2396 // We allow WebKit to think that everything can be handled even though
2397 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342398 return true;
2399}
2400
[email protected]310ebd6302011-10-10 19:06:282401WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492402 WebFrame* frame, const WebURLRequest& request) {
2403 NOTREACHED(); // Since we said we can handle all requests.
2404 return WebURLError();
2405}
2406
[email protected]310ebd6302011-10-10 19:06:282407WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492408 WebFrame* frame, const WebURLRequest& request) {
2409 WebURLError error;
2410 error.domain = WebString::fromUTF8(net::kErrorDomain);
2411 error.reason = net::ERR_ABORTED;
2412 error.unreachableURL = request.url();
2413 return error;
[email protected]7b7a7dc2009-10-19 02:23:342414}
2415
[email protected]310ebd6302011-10-10 19:06:282416void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492417 WebFrame*, const WebURLError&) {
2418 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342419}
2420
[email protected]310ebd6302011-10-10 19:06:282421void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432422 const WebKit::WebFormElement& form) {
2423 // Some login forms have onSubmit handlers that put a hash of the password
2424 // into a hidden field and then clear the password. (Issue 28910.)
2425 // This method gets called before any of those handlers run, so save away
2426 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072427 DocumentState* document_state =
2428 DocumentState::FromDataSource(frame->dataSource());
2429 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432430 PasswordFormDomManager::CreatePasswordForm(form));
2431}
2432
[email protected]310ebd6302011-10-10 19:06:282433void RenderViewImpl::willSubmitForm(WebFrame* frame,
2434 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072435 DocumentState* document_state =
2436 DocumentState::FromDataSource(frame->provisionalDataSource());
2437 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172438
[email protected]2905f742011-10-13 03:51:582439 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2440 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172441
2442 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352443 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072444 document_state->set_searchable_form_url(web_searchable_form_data.url());
2445 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212446 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432447 PasswordForm* password_form_data =
2448 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072449 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432450
[email protected]098c95cb2011-04-28 16:49:012451 // In order to save the password that the user actually typed and not one
2452 // that may have gotten transformed by the site prior to submit, recover it
2453 // from the form contents already stored by |willSendSubmitEvent| into the
2454 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2455 // which is what we're storing into now.)
2456 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072457 DocumentState* old_document_state =
2458 DocumentState::FromDataSource(frame->dataSource());
2459 if (old_document_state) {
2460 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432461 if (old_form_data && old_form_data->action == password_form_data->action)
2462 password_form_data->password_value = old_form_data->password_value;
2463 }
2464 }
[email protected]3d9689372009-09-10 04:29:172465
[email protected]2a5b1732011-04-01 23:55:552466 FOR_EACH_OBSERVER(
2467 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172468}
2469
[email protected]310ebd6302011-10-10 19:06:282470void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172471 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2472 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382473 FOR_EACH_OBSERVER(
2474 RenderViewObserver, observers_,
2475 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172476}
2477
[email protected]310ebd6302011-10-10 19:06:282478void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382479 FOR_EACH_OBSERVER(
2480 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172481}
2482
[email protected]310ebd6302011-10-10 19:06:282483void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172484 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152485 if (!frame->parent()) {
2486 WebDataSource* ds = frame->provisionalDataSource();
2487 // If there's no provisional data source, it's a reference fragment
2488 // navigation.
2489 completed_client_redirect_src_ = Referrer(
[email protected]b9fd01ba2012-02-28 01:50:402490 from, ds ? GetReferrerPolicyFromRequest(ds->request()) :
[email protected]445e1042011-12-03 21:03:152491 frame->referrerPolicy());
2492 }
[email protected]eb0bff942011-04-07 22:08:382493 FOR_EACH_OBSERVER(
2494 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172495}
2496
[email protected]310ebd6302011-10-10 19:06:282497void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072498 DocumentState* document_state = DocumentState::FromDataSource(ds);
2499 if (!document_state) {
2500 document_state = new DocumentState;
2501 ds->setExtraData(document_state);
2502 }
2503
[email protected]3d9689372009-09-10 04:29:172504 // The rest of RenderView assumes that a WebDataSource will always have a
2505 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072506 bool content_initiated = !pending_navigation_params_.get();
2507 if (content_initiated)
2508 document_state->set_navigation_state(
2509 NavigationState::CreateContentInitiated());
2510 else
2511 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512512
[email protected]007733c2011-11-17 00:34:072513 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512514 // navigating from a page that used prefetching using a link on that
2515 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072516 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512517 // this value appropriately.
2518 // TODO(gavinp): catch the important case of navigation in a new
2519 // renderer process.
2520 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302521 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522522 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512523 const GURL referrer(
2524 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2525 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072526 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512527 old_frame->dataSource())->was_prefetcher()) {
2528 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2529 WebDataSource* old_frame_ds = old_frame->dataSource();
2530 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072531 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512532 break;
2533 }
2534 }
2535 }
2536 }
2537 }
2538
[email protected]4c1b6f0b2010-02-07 16:38:182539 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522540 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512541 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182542 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072543 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182544 break;
2545 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072546 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182547 break;
2548 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072549 document_state->set_load_type(
2550 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182551 break;
2552 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072553 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182554 break;
2555 }
2556 }
[email protected]fa7b6b542009-11-03 05:02:302557
[email protected]946a0032011-03-31 18:42:282558 FOR_EACH_OBSERVER(
2559 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172560}
2561
[email protected]007733c2011-11-17 00:34:072562void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2563 DocumentState* document_state) {
2564 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2565
2566 if (document_state->request_time().is_null())
2567 document_state->set_request_time(params.request_time);
2568
2569 // A navigation resulting from loading a javascript URL should not be treated
2570 // as a browser initiated event. Instead, we want it to look as if the page
2571 // initiated any load resulting from JS execution.
2572 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2573 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2574 params.page_id,
2575 params.pending_history_list_offset,
2576 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482577 navigation_state->set_transferred_request_child_id(
2578 params.transferred_request_child_id);
2579 navigation_state->set_transferred_request_request_id(
2580 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072581 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2582 // We're doing a load of a page that was restored from the last session.
2583 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2584 // which can result in stale data for pages that are set to expire. We
2585 // explicitly override that by setting the policy here so that as
2586 // necessary we load from the network.
2587 document_state->set_cache_policy_override(
2588 WebURLRequest::UseProtocolCachePolicy);
2589 }
2590 document_state->set_navigation_state(navigation_state);
2591 } else {
2592 document_state->set_navigation_state(
2593 NavigationState::CreateContentInitiated());
2594 }
2595
2596 if (IsReload(params))
2597 document_state->set_load_type(DocumentState::RELOAD);
2598 else if (!params.state.empty())
2599 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2600 else
2601 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2602
2603 pending_navigation_params_.reset();
2604}
2605
[email protected]310ebd6302011-10-10 19:06:282606void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172607 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072608 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172609
[email protected]3d9689372009-09-10 04:29:172610 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072611 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172612 double event_time = ds->triggeringEventTime();
2613 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072614 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172615 }
2616
[email protected]05c8e502010-08-15 15:13:522617 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072618 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522619
[email protected]3d9689372009-09-10 04:29:172620 bool is_top_most = !frame->parent();
2621 if (is_top_most) {
2622 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132623 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172624
2625 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152626 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172627 } else if (frame->parent()->isLoading()) {
2628 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002629 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072630 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582631 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172632 }
2633
[email protected]28685da92011-02-07 21:49:172634 FOR_EACH_OBSERVER(
2635 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2636
[email protected]3d9689372009-09-10 04:29:172637 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592638 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262639 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172640}
2641
[email protected]310ebd6302011-10-10 19:06:282642void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2643 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172644 if (frame->parent())
2645 return;
2646 // Received a redirect on the main frame.
2647 WebDataSource* data_source = frame->provisionalDataSource();
2648 if (!data_source) {
2649 // Should only be invoked when we have a data source.
2650 NOTREACHED();
2651 return;
2652 }
2653 std::vector<GURL> redirects;
2654 GetRedirectChain(data_source, &redirects);
2655 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512656 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592657 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172658 }
2659}
2660
[email protected]310ebd6302011-10-10 19:06:282661void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2662 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172663 // Notify the browser that we failed a provisional load with an error.
2664 //
2665 // Note: It is important this notification occur before DidStopLoading so the
2666 // SSL manager can react to the provisional load failure before being
2667 // notified the load stopped.
2668 //
2669 WebDataSource* ds = frame->provisionalDataSource();
2670 DCHECK(ds);
2671
2672 const WebURLRequest& failed_request = ds->request();
2673
[email protected]28685da92011-02-07 21:49:172674 FOR_EACH_OBSERVER(
2675 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2676
[email protected]3d9689372009-09-10 04:29:172677 bool show_repost_interstitial =
2678 (error.reason == net::ERR_CACHE_MISS &&
2679 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582680
2681 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2682 params.frame_id = frame->identifier();
2683 params.is_main_frame = !frame->parent();
2684 params.error_code = error.reason;
2685 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2686 failed_request,
2687 error,
2688 NULL,
2689 &params.error_description);
2690 params.url = error.unreachableURL;
2691 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172692 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582693 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172694
2695 // Don't display an error page if this is simply a cancelled load. Aside
2696 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2697 if (error.reason == net::ERR_ABORTED)
2698 return;
[email protected]b553edd52012-01-10 12:15:232699 // Don't display an error message if the request was handled by an
2700 // external protocol handler.
2701 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2702 return;
[email protected]3d9689372009-09-10 04:29:172703
2704 // Make sure we never show errors in view source mode.
2705 frame->enableViewSourceMode(false);
2706
[email protected]007733c2011-11-17 00:34:072707 DocumentState* document_state = DocumentState::FromDataSource(ds);
2708 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172709
2710 // If this is a failed back/forward/reload navigation, then we need to do a
2711 // 'replace' load. This is necessary to avoid messing up session history.
2712 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2713 // as session history is concerned.
2714 //
2715 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2716 // the page id.
2717 //
2718 bool replace =
2719 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582720 navigation_state->transition_type() ==
2721 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172722
2723 // If we failed on a browser initiated request, then make sure that our error
2724 // page load is regarded as the same browser initiated request.
2725 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072726 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2727 pending_navigation_params_->page_id =
2728 navigation_state->pending_page_id();
2729 pending_navigation_params_->pending_history_list_offset =
2730 navigation_state->pending_history_list_offset();
2731 pending_navigation_params_->transition =
2732 navigation_state->transition_type();
2733 pending_navigation_params_->request_time =
2734 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172735 }
2736
2737 // Provide the user with a more helpful error page?
2738 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2739 return;
2740
2741 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082742 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172743}
2744
[email protected]310ebd6302011-10-10 19:06:282745void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172746 WebFrame* frame, const char* data, size_t data_len,
2747 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072748 DocumentState* document_state =
2749 DocumentState::FromDataSource(frame->dataSource());
2750 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172751}
2752
[email protected]310ebd6302011-10-10 19:06:282753void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2754 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072755 DocumentState* document_state =
2756 DocumentState::FromDataSource(frame->dataSource());
2757 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172758
[email protected]007733c2011-11-17 00:34:072759 if (document_state->commit_load_time().is_null())
2760 document_state->set_commit_load_time(Time::Now());
2761
[email protected]3d9689372009-09-10 04:29:172762 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202763 // When we perform a new navigation, we need to update the last committed
2764 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172765 UpdateSessionHistory(frame);
2766
2767 // We bump our Page ID to correspond with the new session history entry.
2768 page_id_ = next_page_id_++;
2769
[email protected]69ddf852012-02-21 23:21:312770 // Don't update history_page_ids_ (etc) for about:swappedout, since we
2771 // don't want to forget the entry that was there, and since we will
2772 // never come back to about:swappedout. Note that we have to call
2773 // UpdateSessionHistory and update page_id_ even in this case, so that
2774 // the current entry gets a state update and so that we don't send a
2775 // state update to the wrong entry when we swap back in.
2776 if (GetLoadingUrl(frame) != GURL("about:swappedout")) {
2777 // Advance our offset in session history, applying the length limit.
2778 // There is now no forward history.
2779 history_list_offset_++;
2780 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2781 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
2782 history_list_length_ = history_list_offset_ + 1;
2783 history_page_ids_.resize(history_list_length_, -1);
2784 history_page_ids_[history_list_offset_] = page_id_;
2785 }
[email protected]3d9689372009-09-10 04:29:172786 } else {
2787 // Inspect the navigation_state on this frame to see if the navigation
2788 // corresponds to a session history navigation... Note: |frame| may or
2789 // may not be the toplevel frame, but for the case of capturing session
2790 // history, the first committed frame suffices. We keep track of whether
2791 // we've seen this commit before so that only capture session history once
2792 // per navigation.
2793 //
2794 // Note that we need to check if the page ID changed. In the case of a
2795 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2796 // previous URL and the current page ID, which would be wrong.
2797 if (navigation_state->pending_page_id() != -1 &&
2798 navigation_state->pending_page_id() != page_id_ &&
2799 !navigation_state->request_committed()) {
2800 // This is a successful session history navigation!
2801 UpdateSessionHistory(frame);
2802 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002803
2804 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032805
2806 // If the history list is valid, our list of page IDs should be correct.
2807 DCHECK(history_list_length_ <= 0 ||
2808 history_list_offset_ < 0 ||
2809 history_list_offset_ >= history_list_length_ ||
2810 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172811 }
2812 }
2813
[email protected]28685da92011-02-07 21:49:172814 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2815 DidCommitProvisionalLoad(frame, is_new_navigation));
2816
[email protected]3d9689372009-09-10 04:29:172817 // Remember that we've already processed this request, so we don't update
2818 // the session history again. We do this regardless of whether this is
2819 // a session history navigation, because if we attempted a session history
2820 // navigation without valid HistoryItem state, WebCore will think it is a
2821 // new navigation.
2822 navigation_state->set_request_committed(true);
2823
2824 UpdateURL(frame);
2825
2826 // If this committed load was initiated by a client redirect, we're
2827 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152828 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172829
2830 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272831 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172832}
2833
[email protected]310ebd6302011-10-10 19:06:282834void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102835 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2836 DidClearWindowObject(frame));
2837
[email protected]b6cb3a842011-06-24 18:28:412838 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212839 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252840 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2841 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272842 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172843 }
[email protected]766a7082012-02-03 23:39:152844
2845 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
2846 if (!dom_automation_controller_.get())
2847 dom_automation_controller_.reset(new DomAutomationController());
2848 dom_automation_controller_->set_message_sender(
2849 static_cast<content::RenderView*>(this));
2850 dom_automation_controller_->set_routing_id(routing_id());
2851 dom_automation_controller_->BindToJavascript(frame,
2852 "domAutomationController");
2853 }
[email protected]3d9689372009-09-10 04:29:172854}
2855
[email protected]310ebd6302011-10-10 19:06:282856void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172857 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412858 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252859 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272860 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172861 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2862 }
[email protected]e48869a2011-04-01 19:56:032863
2864 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2865 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172866}
2867
[email protected]310ebd6302011-10-10 19:06:282868void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2869 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462870 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172871
2872 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272873 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172874}
2875
[email protected]310ebd6302011-10-10 19:06:282876void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132877 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2878 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582879}
2880
[email protected]310ebd6302011-10-10 19:06:282881void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172882 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072883 DocumentState* document_state = DocumentState::FromDataSource(ds);
2884 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172885
[email protected]622474d2010-11-04 09:21:082886 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172887
[email protected]28685da92011-02-07 21:49:172888 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2889 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172890
2891 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272892 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172893}
2894
[email protected]310ebd6302011-10-10 19:06:282895void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082896 if (webview()->mainFrame() == frame) {
2897 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2898 page_id_));
2899 }
[email protected]3d9689372009-09-10 04:29:172900}
2901
[email protected]310ebd6302011-10-10 19:06:282902void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312903 WebDataSource* ds = frame->dataSource();
2904 DCHECK(ds);
2905
2906
[email protected]28685da92011-02-07 21:49:172907 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312908
2909 const WebURLRequest& failed_request = ds->request();
2910 string16 error_description;
2911 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2912 failed_request,
2913 error,
2914 NULL,
2915 &error_description);
2916 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2917 frame->identifier(),
2918 failed_request.url(),
2919 !frame->parent(),
2920 error.reason,
2921 error_description));
[email protected]3d9689372009-09-10 04:29:172922}
2923
[email protected]310ebd6302011-10-10 19:06:282924void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172925 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072926 DocumentState* document_state = DocumentState::FromDataSource(ds);
2927 if (document_state->finish_load_time().is_null())
2928 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412929
[email protected]676126f72011-01-15 00:03:512930 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172931
[email protected]1a55c5be2011-11-29 11:36:312932 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2933 frame->identifier(),
2934 ds->request().url(),
2935 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172936}
2937
[email protected]310ebd6302011-10-10 19:06:282938void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172939 WebFrame* frame, bool is_new_navigation) {
2940 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072941 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172942 // update the ExtraData on the datasource so that others who read the
2943 // ExtraData will get the new NavigationState. Similarly, if we did not
2944 // initiate this navigation, then we need to take care to reset any pre-
2945 // existing navigation state to a content-initiated navigation state.
2946 // DidCreateDataSource conveniently takes care of this for us.
2947 didCreateDataSource(frame, frame->dataSource());
2948
[email protected]007733c2011-11-17 00:34:072949 DocumentState* document_state =
2950 DocumentState::FromDataSource(frame->dataSource());
2951 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092952 new_state->set_was_within_same_page(true);
2953
[email protected]3d9689372009-09-10 04:29:172954 didCommitProvisionalLoad(frame, is_new_navigation);
2955
[email protected]750fcf872011-08-03 23:10:472956 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2957 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172958}
2959
[email protected]310ebd6302011-10-10 19:06:282960void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312961 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592962}
2963
[email protected]310ebd6302011-10-10 19:06:282964void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172965 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2966 // Ignore
2967}
2968
[email protected]310ebd6302011-10-10 19:06:282969void RenderViewImpl::willSendRequest(WebFrame* frame,
2970 unsigned identifier,
2971 WebURLRequest& request,
2972 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302973 WebFrame* top_frame = frame->top();
2974 if (!top_frame)
2975 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512976 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2977 WebDataSource* top_data_source = top_frame->dataSource();
2978 WebDataSource* data_source =
2979 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222980
[email protected]78d5cfe2011-02-04 08:43:222981 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032982 GURL new_url;
2983 if (content::GetContentClient()->renderer()->WillSendRequest(
2984 frame, request_url, &new_url)) {
2985 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222986 }
2987
[email protected]2905f742011-10-13 03:51:582988 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072989 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2990 NavigationState* navigation_state = document_state->navigation_state();
2991 if (document_state) {
2992 if (document_state->is_cache_policy_override_set())
2993 request.setCachePolicy(document_state->cache_policy_override());
2994 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:302995 }
[email protected]8a3125a712010-08-09 18:58:512996
[email protected]91043a8232011-11-04 16:41:192997 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:062998 new RequestExtraData(frame->referrerPolicy(),
2999 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:193000 frame->identifier(),
3001 frame->parent() == top_frame,
3002 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:483003 transition_type,
3004 navigation_state->transferred_request_child_id(),
3005 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:573006
[email protected]007733c2011-11-17 00:34:073007 DocumentState* top_document_state =
3008 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:573009 // TODO(gavinp): separate out prefetching and prerender field trials
3010 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:073011 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:573012 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
3013 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:073014 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:513015
[email protected]3d9689372009-09-10 04:29:173016 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133017 request.setHasUserGesture(frame->isProcessingUserGesture());
3018
[email protected]0a8db0d2011-04-13 15:15:403019 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:133020 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:173021}
3022
[email protected]310ebd6302011-10-10 19:06:283023void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:173024 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493025
[email protected]3d9689372009-09-10 04:29:173026 // Only do this for responses that correspond to a provisional data source
3027 // of the top-most frame. If we have a provisional data source, then we
3028 // can't have any sub-resources yet, so we know that this response must
3029 // correspond to a frame load.
3030 if (!frame->provisionalDataSource() || frame->parent())
3031 return;
3032
3033 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083034 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173035 if (frame->isViewSourceModeEnabled())
3036 return;
3037
[email protected]007733c2011-11-17 00:34:073038 DocumentState* document_state =
3039 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083040 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533041
[email protected]972ebdff2010-06-10 22:59:073042 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073043 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3044 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403045 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3046 if (extra_data) {
3047 document_state->set_npn_negotiated_protocol(
3048 extra_data->npn_negotiated_protocol());
3049 }
[email protected]007733c2011-11-17 00:34:073050 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573051 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073052 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3053 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093054 // Whether or not the http status code actually corresponds to an error is
3055 // only checked when the page is done loading, if |use_error_page| is
3056 // still true.
[email protected]007733c2011-11-17 00:34:073057 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173058}
3059
[email protected]310ebd6302011-10-10 19:06:283060void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173061 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073062 DocumentState* document_state =
3063 DocumentState::FromDataSource(frame->dataSource());
3064 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173065 return;
3066
[email protected]7bfc153f2011-09-23 22:00:203067 // Do not show error page when DevTools is attached.
3068 if (devtools_agent_->IsAttached())
3069 return;
3070
[email protected]06333afe2011-02-24 14:55:093071 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073072 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083073 if (http_status_code == 404) {
3074 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413075 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173076
[email protected]b6cb3a842011-06-24 18:28:413077 const GURL& error_page_url =
3078 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093079 if (error_page_url.is_valid()) {
3080 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473081 original_error.domain = "http";
3082 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413083 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173084
[email protected]007733c2011-11-17 00:34:073085 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093086 new AltErrorPageResourceFetcher(
3087 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083088 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3089 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093090 return;
3091 }
3092 }
[email protected]3d9689372009-09-10 04:29:173093
[email protected]e6a2ce52011-10-08 01:40:133094 std::string error_domain;
3095 if (content::GetContentClient()->renderer()->HasErrorPage(
3096 http_status_code, &error_domain)) {
3097 WebURLError error;
3098 error.unreachableURL = frame->document().url();
3099 error.domain = WebString::fromUTF8(error_domain);
3100 error.reason = http_status_code;
3101
3102 LoadNavigationErrorPage(
3103 frame, frame->dataSource()->request(), error, std::string(), true);
3104 }
[email protected]3d9689372009-09-10 04:29:173105}
3106
[email protected]310ebd6302011-10-10 19:06:283107void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173108 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3109 // Ignore
3110}
3111
[email protected]310ebd6302011-10-10 19:06:283112void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173113 WebFrame* frame, const WebURLRequest& request,
3114 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003115 // The recipients of this message have no use for data: URLs: they don't
3116 // affect the page's insecure content list and are not in the disk cache. To
3117 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3118 // filter them out here.
3119 GURL url(request.url());
3120 if (url.SchemeIs("data"))
3121 return;
3122
[email protected]3d9689372009-09-10 04:29:173123 // Let the browser know we loaded a resource from the memory cache. This
3124 // message is needed to display the correct SSL indicators.
3125 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3126 routing_id_,
[email protected]84703292011-10-28 20:44:003127 url,
[email protected]70435962011-08-02 20:13:283128 response.securityInfo(),
3129 request.httpMethod().utf8(),
3130 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173131}
3132
[email protected]310ebd6302011-10-10 19:06:283133void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293134 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3135}
3136
[email protected]310ebd6302011-10-10 19:06:283137void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023138 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293139 Send(new ViewHostMsg_DidRunInsecureContent(
3140 routing_id_,
[email protected]92771112011-01-20 00:13:023141 origin.toString().utf8(),
3142 target));
[email protected]e3d60e5d2009-09-25 21:08:293143}
3144
[email protected]310ebd6302011-10-10 19:06:283145void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033146 webkit_glue::WebURLLoaderImpl* loader_impl =
3147 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3148 loader_impl->UpdateRoutingId(routing_id_);
3149}
3150
[email protected]310ebd6302011-10-10 19:06:283151void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173152 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3153}
3154
[email protected]310ebd6302011-10-10 19:06:283155void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3156 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583157 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283158 int world_id) {
[email protected]5bc10932011-09-21 21:03:303159 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583160 frame, context, extension_group, world_id);
3161}
3162
3163void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3164 v8::Handle<v8::Context> context,
3165 int world_id) {
3166 content::GetContentClient()->renderer()->DidCreateScriptContext(
3167 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283168}
3169
[email protected]310ebd6302011-10-10 19:06:283170void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3171 v8::Handle<v8::Context> context,
3172 int world_id) {
[email protected]5bc10932011-09-21 21:03:303173 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3174 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283175}
3176
[email protected]310ebd6302011-10-10 19:06:283177void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073178 // We don't always want to send the change messages over IPC, only if we've
3179 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3180 // message.
3181 if (!send_preferred_size_changes_ || !webview())
3182 return;
3183
[email protected]705243f2010-05-05 19:58:073184 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3185 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533186
3187 // In the presence of zoom, these sizes are still reported as if unzoomed,
3188 // so we need to adjust.
3189 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3190 size.set_width(static_cast<int>(size.width() * zoom_factor));
3191 size.set_height(static_cast<int>(size.height() * zoom_factor));
3192
[email protected]705243f2010-05-05 19:58:073193 if (size == preferred_size_)
3194 return;
[email protected]c27324b2009-11-19 22:44:293195
[email protected]705243f2010-05-05 19:58:073196 preferred_size_ = size;
3197 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3198 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173199}
3200
[email protected]273558fb2012-01-12 15:03:513201void RenderViewImpl::EnsureMediaStreamImpl() {
3202#if defined(ENABLE_P2P_APIS)
3203 if (!p2p_socket_dispatcher_)
3204 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3205#endif
3206
[email protected]5b87e782012-02-09 18:19:323207#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513208 if (!media_stream_dispatcher_)
3209 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3210
3211 if (!media_stream_impl_.get()) {
3212 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3213 media_stream_impl_ = new MediaStreamImpl(
3214 media_stream_dispatcher_,
3215 p2p_socket_dispatcher_,
3216 RenderThreadImpl::current()->video_capture_impl_manager(),
3217 factory);
3218 }
[email protected]5b87e782012-02-09 18:19:323219#endif
[email protected]273558fb2012-01-12 15:03:513220}
3221
[email protected]310ebd6302011-10-10 19:06:283222void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3223 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313224 if (webview()->mainFrame() != frame)
3225 return;
3226 WebView* frameView = frame->view();
3227 if (!frameView)
3228 return;
3229
3230 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3231 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3232
3233 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3234 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3235 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3236 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3237
3238 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3239 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3240 }
3241}
3242
[email protected]310ebd6302011-10-10 19:06:283243void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313244 WebSize offset = frame->scrollOffset();
3245 WebSize minimum_offset = frame->minimumScrollOffset();
3246 WebSize maximum_offset = frame->maximumScrollOffset();
3247
3248 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3249 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3250
3251 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3252 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3253 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3254 routing_id_, is_pinned_to_left, is_pinned_to_right));
3255
3256 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3257 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3258 }
3259}
3260
[email protected]310ebd6302011-10-10 19:06:283261void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493262 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313263
3264 if (webview()->mainFrame() == frame)
3265 UpdateScrollState(frame);
3266}
3267
[email protected]310ebd6302011-10-10 19:06:283268void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313269 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493270}
3271
[email protected]ea931252012-02-15 22:01:033272void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3273 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3274}
3275
[email protected]310ebd6302011-10-10 19:06:283276void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3277 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113278 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3279 if (!count)
3280 active_match_ordinal = 0;
3281
3282 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3283 routing_id_,
3284 request_id,
3285 count,
3286 gfx::Rect(),
3287 active_match_ordinal,
3288 final_update);
3289
[email protected]8922e1f2009-10-03 05:01:263290 // If we have a message that has been queued up, then we should just replace
3291 // it. The ACK from the browser will make sure it gets sent when the browser
3292 // wants it.
3293 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263294 queued_find_reply_message_.reset(msg);
3295 } else {
3296 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113297 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263298 }
3299}
3300
[email protected]310ebd6302011-10-10 19:06:283301void RenderViewImpl::reportFindInPageSelection(int request_id,
3302 int active_match_ordinal,
3303 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263304 // Send the search result over to the browser process.
3305 Send(new ViewHostMsg_Find_Reply(routing_id_,
3306 request_id,
3307 -1,
3308 selection_rect,
3309 active_match_ordinal,
3310 false));
3311}
3312
[email protected]310ebd6302011-10-10 19:06:283313void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223314 WebFrame* frame,
3315 WebFileSystem::Type type,
3316 long long size,
[email protected]d275d7a2010-11-03 01:34:493317 bool create,
[email protected]2b06a992010-08-21 05:48:223318 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083319 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223320
[email protected]b6cb3a842011-06-24 18:28:413321 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563322 if (origin.isUnique()) {
3323 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083324 callbacks->didFail(WebKit::WebFileErrorAbort);
3325 return;
3326 }
[email protected]2b06a992010-08-21 05:48:223327
[email protected]c5a272d2010-09-27 18:37:083328 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3329 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493330 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223331}
3332
[email protected]310ebd6302011-10-10 19:06:283333void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403334 WebFrame* frame,
3335 WebStorageQuotaType type,
3336 WebStorageQuotaCallbacks* callbacks) {
3337 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413338 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563339 if (origin.isUnique()) {
3340 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403341 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3342 return;
3343 }
3344 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533345 GURL(origin.toString()),
3346 static_cast<quota::StorageType>(type),
3347 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403348}
3349
[email protected]310ebd6302011-10-10 19:06:283350void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403351 WebFrame* frame,
3352 WebStorageQuotaType type,
3353 unsigned long long requested_size,
3354 WebStorageQuotaCallbacks* callbacks) {
3355 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413356 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563357 if (origin.isUnique()) {
3358 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403359 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3360 return;
3361 }
3362 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533363 routing_id(), GURL(origin.toString()),
3364 static_cast<quota::StorageType>(type), requested_size,
3365 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403366}
3367
[email protected]8b5af492011-11-28 21:50:583368void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153369 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063370 string16 title = service.title();
3371 if (title.empty())
3372 title = webview()->mainFrame()->document().title();
3373
[email protected]8b5af492011-11-28 21:50:583374 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3375 service.action(),
3376 service.type(),
3377 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063378 title,
[email protected]8b5af492011-11-28 21:50:583379 service.disposition()));
3380}
3381
[email protected]ffc8bed2012-01-21 01:23:153382void RenderViewImpl::dispatchIntent(
3383 WebFrame* frame, const WebIntentRequest& intentRequest) {
3384 webkit_glue::WebIntentData intent_data(intentRequest.intent());
3385 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583386 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153387 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583388}
3389
[email protected]18d5be92011-07-25 18:00:193390// WebKit::WebPageSerializerClient implementation ------------------------------
3391
[email protected]310ebd6302011-10-10 19:06:283392void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193393 const WebURL& frame_url,
3394 const WebCString& data,
3395 WebPageSerializerClient::PageSerializationStatus status) {
3396 Send(new ViewHostMsg_SendSerializedHtmlData(
3397 routing_id(),
3398 frame_url,
3399 data.data(),
3400 static_cast<int32>(status)));
3401}
3402
[email protected]a2ef54c2011-10-10 16:20:313403// content::RenderView implementation ------------------------------------------
3404
[email protected]310ebd6302011-10-10 19:06:283405bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313406 return RenderWidget::Send(message);
3407}
3408
[email protected]9f76c1e2012-03-05 15:15:583409int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:313410 return routing_id_;
3411}
3412
[email protected]310ebd6302011-10-10 19:06:283413int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313414 return page_id_;
3415}
3416
[email protected]310ebd6302011-10-10 19:06:283417gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313418 return size();
3419}
3420
[email protected]310ebd6302011-10-10 19:06:283421gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313422 return host_window();
3423}
3424
[email protected]310ebd6302011-10-10 19:06:283425WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313426 return webkit_preferences_;
3427}
3428
[email protected]310ebd6302011-10-10 19:06:283429WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313430 return webview();
3431}
3432
[email protected]310ebd6302011-10-10 19:06:283433WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313434 if (!webview())
3435 return WebNode();
3436 WebFrame* focused_frame = webview()->focusedFrame();
3437 if (focused_frame) {
3438 WebDocument doc = focused_frame->document();
3439 if (!doc.isNull())
3440 return doc.focusedNode();
3441 }
3442
3443 return WebNode();
3444}
3445
[email protected]310ebd6302011-10-10 19:06:283446WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313447 return context_menu_node_;
3448}
3449
[email protected]310ebd6302011-10-10 19:06:283450bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313451 bool is_editable_node = false;
3452 if (!node.isNull()) {
3453 if (node.isContentEditable()) {
3454 is_editable_node = true;
3455 } else if (node.isElementNode()) {
3456 is_editable_node =
3457 node.toConst<WebElement>().isTextFormControlElement();
3458 }
3459 }
3460 return is_editable_node;
3461}
3462
[email protected]310ebd6302011-10-10 19:06:283463WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313464 WebKit::WebFrame* frame,
3465 const webkit::WebPluginInfo& info,
3466 const WebKit::WebPluginParams& params) {
3467 bool pepper_plugin_was_registered = false;
3468 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3469 pepper_delegate_.CreatePepperPluginModule(info,
3470 &pepper_plugin_was_registered));
3471 if (pepper_plugin_was_registered) {
3472 if (!pepper_module)
3473 return NULL;
3474 return new webkit::ppapi::WebPluginImpl(
3475 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3476 }
3477
[email protected]34b27e442012-01-20 20:07:413478#if defined(USE_AURA)
3479 return NULL;
3480#else
[email protected]a2ef54c2011-10-10 16:20:313481 return new webkit::npapi::WebPluginImpl(
3482 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413483#endif
[email protected]a2ef54c2011-10-10 16:20:313484}
3485
[email protected]310ebd6302011-10-10 19:06:283486void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3487 const string16& jscript,
3488 int id,
3489 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313490 v8::Handle<v8::Value> result;
3491 WebFrame* web_frame = GetChildFrame(frame_xpath);
3492 if (web_frame)
3493 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3494 if (notify_result) {
3495 ListValue list;
3496 if (!result.IsEmpty() && web_frame) {
3497 v8::HandleScope handle_scope;
3498 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3499 v8::Context::Scope context_scope(context);
3500 V8ValueConverterImpl converter;
3501 converter.set_allow_date(true);
3502 converter.set_allow_regexp(true);
3503 list.Set(0, converter.FromV8Value(result, context));
3504 } else {
3505 list.Set(0, Value::CreateNullValue());
3506 }
3507 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3508 }
3509}
3510
[email protected]310ebd6302011-10-10 19:06:283511bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313512 return (!send_preferred_size_changes_ ||
3513 (disable_scrollbars_size_limit_.width() <= width ||
3514 disable_scrollbars_size_limit_.height() <= height));
3515}
3516
[email protected]310ebd6302011-10-10 19:06:283517int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313518 return enabled_bindings_;
3519}
3520
[email protected]310ebd6302011-10-10 19:06:283521bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313522 return send_content_state_immediately_;
3523}
3524
[email protected]310ebd6302011-10-10 19:06:283525float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313526 return filtered_time_per_frame();
3527}
3528
[email protected]310ebd6302011-10-10 19:06:283529void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3530 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313531 showContextMenu(frame, data);
3532}
3533
[email protected]310ebd6302011-10-10 19:06:283534WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313535 return visibilityState();
3536}
3537
[email protected]310ebd6302011-10-10 19:06:283538void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3539 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313540 return runModalAlertDialog(frame, message);
3541}
3542
[email protected]310ebd6302011-10-10 19:06:283543void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313544 WebKit::WebFrame* frame,
3545 const WebKit::WebURLRequest& request,
3546 WebKit::WebNavigationPolicy policy) {
3547 loadURLExternally(frame, request, policy);
3548}
3549
3550// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513551
[email protected]310ebd6302011-10-10 19:06:283552webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533553 const FilePath& file_path,
3554 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203555 if (!PluginChannelHost::IsListening()) {
3556 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593557 return NULL;
[email protected]94752ee2012-02-10 10:38:203558 }
[email protected]f103ab72009-09-02 17:10:593559
[email protected]00c39612010-03-06 02:53:283560 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463561 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323562#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223563 return webkit::npapi::WebPluginDelegateImpl::Create(
3564 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093565#else
[email protected]7398dcc2011-09-06 21:40:323566 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223567 NOTIMPLEMENTED();
3568 return NULL;
[email protected]7b6616f2010-01-14 18:07:553569#endif
[email protected]f103ab72009-09-02 17:10:593570 }
3571
[email protected]4e0616e2010-05-28 14:55:533572 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593573}
3574
[email protected]310ebd6302011-10-10 19:06:283575void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033576#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273577 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593578#endif
3579}
3580
[email protected]310ebd6302011-10-10 19:06:283581void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033582#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273583 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593584#endif
3585 CleanupWindowInPluginMoves(window);
3586}
3587
[email protected]310ebd6302011-10-10 19:06:283588void RenderViewImpl::DidMovePlugin(
3589 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593590 SchedulePluginMove(move);
3591}
3592
[email protected]310ebd6302011-10-10 19:06:283593void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593594 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523595 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593596}
3597
[email protected]310ebd6302011-10-10 19:06:283598void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593599 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523600 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593601}
3602
[email protected]310ebd6302011-10-10 19:06:283603WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513604 return &cookie_jar_;
3605}
3606
[email protected]a9288f52011-11-17 05:18:163607void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073608 Send(new ViewHostMsg_MediaNotification(routing_id_,
3609 reinterpret_cast<int64>(player),
3610 player->hasVideo(),
3611 player->hasAudio(),
3612 true));
3613}
3614
[email protected]a9288f52011-11-17 05:18:163615void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073616 Send(new ViewHostMsg_MediaNotification(routing_id_,
3617 reinterpret_cast<int64>(player),
3618 player->hasVideo(),
3619 player->hasAudio(),
3620 false));
3621}
3622
[email protected]a9288f52011-11-17 05:18:163623void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073624 DidPause(player);
3625}
3626
[email protected]310ebd6302011-10-10 19:06:283627void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293628 if (!webview())
3629 return;
3630
[email protected]26aa0482009-09-30 16:55:273631 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173632 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293633 return;
[email protected]ca948a22009-06-25 19:36:173634
3635 Send(new ViewHostMsg_UpdateState(
3636 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293637}
3638
[email protected]310ebd6302011-10-10 19:06:283639void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363640 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003641 if (!frame)
3642 return;
[email protected]b781ff282011-08-20 06:19:363643
[email protected]b781ff282011-08-20 06:19:363644 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003645 if (!webview()->caretOrSelectionRange(&location, &length))
3646 return;
3647
3648 string16 text;
3649 size_t offset;
3650 ui::Range range(location, location + length);
3651
3652 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3653 // If current focused element is editable, we will send 100 more chars
3654 // before and after selection. It is for input method surrounding text
3655 // feature.
3656 if (location > kExtraCharsBeforeAndAfterSelection)
3657 offset = location - kExtraCharsBeforeAndAfterSelection;
3658 else
3659 offset = 0;
3660 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3661 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3662 if (!webrange.isNull())
3663 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3664 } else {
3665 offset = location;
3666 text = frame->selectionAsText();
[email protected]e8cdf3532011-10-29 00:50:523667 // http://crbug.com/101435
3668 // In some case, frame->selectionAsText() returned text's length is not
3669 // equal to the length returned from webview()->caretOrSelectionRange().
3670 // So we have to set the range according to text.length().
3671 range.set_end(range.start() + text.length());
[email protected]b781ff282011-08-20 06:19:363672 }
3673
[email protected]b781ff282011-08-20 06:19:363674 // Sometimes we get repeated didChangeSelection calls from webkit when
3675 // the selection hasn't actually changed. We don't want to report these
3676 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003677 if (selection_text_offset_ != offset ||
3678 selection_range_ != range ||
3679 selection_text_ != text) {
3680 selection_text_ = text;
3681 selection_text_offset_ = offset;
3682 selection_range_ = range;
3683 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3684 }
[email protected]b781ff282011-08-20 06:19:363685}
3686
[email protected]310ebd6302011-10-10 19:06:283687GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3688 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553689 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293690 // If the URL that failed was secure, then the embedding web page was not
3691 // expecting a network attacker to be able to manipulate its contents. As
3692 // we fetch alternate error pages over HTTP, we would be allowing a network
3693 // attacker to manipulate the contents of the response if we tried to use
3694 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153695 return GURL();
initial.commit09911bf2008-07-26 23:55:293696 }
3697
3698 // Grab the base URL from the browser process.
3699 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153700 return GURL();
initial.commit09911bf2008-07-26 23:55:293701
3702 // Strip query params from the failed URL.
3703 GURL::Replacements remove_params;
3704 remove_params.ClearUsername();
3705 remove_params.ClearPassword();
3706 remove_params.ClearQuery();
3707 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553708 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503709 std::string spec_to_send = url_to_send.spec();
3710 // Notify link doctor of the url truncation by sending of "?" at the end.
3711 if (failed_url.has_query())
3712 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293713
3714 // Construct the query params to send to link doctor.
3715 std::string params(alternate_error_page_url_.query());
3716 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023717 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293718 params.append("&sourceid=chrome");
3719 params.append("&error=");
3720 switch (error_type) {
3721 case DNS_ERROR:
3722 params.append("dnserror");
3723 break;
3724
3725 case HTTP_404:
3726 params.append("http404");
3727 break;
3728
[email protected]5df266ac2008-10-15 19:50:133729 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333730 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133731 break;
3732
initial.commit09911bf2008-07-26 23:55:293733 default:
3734 NOTREACHED() << "unknown ErrorPageType";
3735 }
3736
3737 // OK, build the final url to return.
3738 GURL::Replacements link_doctor_params;
3739 link_doctor_params.SetQueryStr(params);
3740 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3741 return url;
3742}
3743
[email protected]310ebd6302011-10-10 19:06:283744GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593745 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3746 return GURL();
3747 else
3748 return creator_url_;
3749}
3750
[email protected]69ddf852012-02-21 23:21:313751GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
3752 WebDataSource* ds = frame->dataSource();
3753 if (ds->hasUnreachableURL())
3754 return ds->unreachableURL();
3755
3756 const WebURLRequest& request = ds->request();
3757 return request.url();
3758}
3759
[email protected]310ebd6302011-10-10 19:06:283760WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273761 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313762 web_ui_bindings_.reset(new WebUIBindings(
3763 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463764 }
[email protected]c50008512011-02-03 01:17:273765 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463766}
3767
[email protected]310ebd6302011-10-10 19:06:283768WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013769 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493770}
3771
[email protected]310ebd6302011-10-10 19:06:283772void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3773 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273774 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493775
[email protected]872542532011-06-23 00:43:163776 // Check if the plugin still exists in the document.
3777 if (main_frame->document().isPluginDocument() &&
3778 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493779 if (options.findNext) {
3780 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013781 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493782 } else {
[email protected]afdbd142010-07-10 08:01:233783 if (GetWebPluginFromPluginDocument()->startFind(
3784 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493785 } else {
[email protected]e7c58a32010-08-13 19:47:113786 // Send "no results".
3787 Send(new ViewHostMsg_Find_Reply(routing_id_,
3788 request_id,
3789 0,
3790 gfx::Rect(),
3791 0,
3792 true));
[email protected]24a7f3c2010-03-25 08:26:493793 }
3794 }
3795 return;
3796 }
3797
[email protected]b4bb2502009-10-01 22:35:273798 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273799 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293800 WebFrame* search_frame = focused_frame; // start searching focused frame.
3801
3802 bool multi_frame = (frame_after_main != main_frame);
3803
3804 // If we have multiple frames, we don't want to wrap the search within the
3805 // frame, so we check here if we only have main_frame in the chain.
3806 bool wrap_within_frame = !multi_frame;
3807
[email protected]b3f2b912009-04-09 16:18:523808 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293809 bool result = false;
3810
[email protected]7830da3e2009-11-06 16:27:263811 // If something is selected when we start searching it means we cannot just
3812 // increment the current match ordinal; we need to re-generate it.
3813 WebRange current_selection = focused_frame->selectionRange();
3814
initial.commit09911bf2008-07-26 23:55:293815 do {
[email protected]dd7daa82009-08-10 05:46:453816 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593817 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293818
3819 if (!result) {
3820 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223821 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293822
3823 // Find the next frame, but skip the invisible ones.
3824 do {
3825 // What is the next frame to search? (we might be going backwards). Note
3826 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593827 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273828 search_frame->traverseNext(true) :
3829 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453830 } while (!search_frame->hasVisibleContent() &&
3831 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293832
[email protected]884db412008-11-24 23:46:503833 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223834 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293835
3836 // If we have multiple frames and we have wrapped back around to the
3837 // focused frame, we need to search it once more allowing wrap within
3838 // the frame, otherwise it will report 'no match' if the focused frame has
3839 // reported matches, but no frames after the focused_frame contain a
3840 // match for the search word(s).
3841 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453842 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593843 request_id, search_text, options, true, // Force wrapping.
3844 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293845 }
3846 }
3847
[email protected]26aa0482009-09-30 16:55:273848 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293849 } while (!result && search_frame != focused_frame);
3850
[email protected]7830da3e2009-11-06 16:27:263851 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293852 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453853 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293854 } else {
3855 // If nothing is found, set result to "0 of 0", otherwise, set it to
3856 // "-1 of 1" to indicate that we found at least one item, but we don't know
3857 // yet what is active.
3858 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3859 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293860
[email protected]4f3dc372009-02-24 00:10:293861 // If we find no matches then this will be our last status update.
3862 // Otherwise the scoping effort will send more results.
3863 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293864
[email protected]4f3dc372009-02-24 00:10:293865 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403866 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593867 request_id,
[email protected]4f3dc372009-02-24 00:10:293868 match_count,
3869 selection_rect,
3870 ordinal,
3871 final_status_update));
initial.commit09911bf2008-07-26 23:55:293872
initial.commit09911bf2008-07-26 23:55:293873 // Scoping effort begins, starting with the mainframe.
3874 search_frame = main_frame;
3875
[email protected]dd7daa82009-08-10 05:46:453876 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293877
3878 do {
3879 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453880 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293881
3882 // We don't start another scoping effort unless at least one match has
3883 // been found.
3884 if (result) {
3885 // Start new scoping request. If the scoping function determines that it
3886 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453887 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593888 search_text,
3889 options,
initial.commit09911bf2008-07-26 23:55:293890 true); // reset the tickmarks
3891 }
3892
3893 // Iterate to the next frame. The frame will not necessarily scope, for
3894 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273895 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293896 } while (search_frame != main_frame);
3897 }
3898}
3899
[email protected]815dd9872011-11-23 18:40:303900void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493901 WebView* view = webview();
3902 if (!view)
3903 return;
3904
3905 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163906 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013907 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493908 return;
3909 }
3910
[email protected]815dd9872011-11-23 18:40:303911 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493912 if (clear_selection)
3913 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3914
3915 WebFrame* frame = view->mainFrame();
3916 while (frame) {
3917 frame->stopFinding(clear_selection);
3918 frame = frame->traverseNext(false);
3919 }
3920
[email protected]815dd9872011-11-23 18:40:303921 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493922 WebFrame* focused_frame = view->focusedFrame();
3923 if (focused_frame) {
3924 WebDocument doc = focused_frame->document();
3925 if (!doc.isNull()) {
3926 WebNode node = doc.focusedNode();
3927 if (!node.isNull())
3928 node.simulateClick();
3929 }
3930 }
3931 }
3932}
3933
[email protected]310ebd6302011-10-10 19:06:283934void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493935 // Check if there is any queued up request waiting to be sent.
3936 if (queued_find_reply_message_.get()) {
3937 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423938 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493939 }
3940}
3941
[email protected]54087fe2011-10-28 22:02:483942void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513943 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3944 return;
3945
[email protected]258d31122010-05-09 10:59:413946 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103947
[email protected]b75b8292010-10-01 07:28:253948 double old_zoom_level = webview()->zoomLevel();
3949 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483950 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253951 zoom_level = 0;
3952 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3953 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483954 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253955 } else {
3956 // Either the user hit the zoom factor limit and thus the zoom level is now
3957 // not a whole number, or a plugin changed it to a custom value. We want
3958 // to go to the next whole number so that the user can always get back to
3959 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483960 if ((old_zoom_level > 1 && zoom > 0) ||
3961 (old_zoom_level < 1 && zoom < 0)) {
3962 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253963 } else {
3964 // We're going towards 100%, so first go to the next whole number.
3965 zoom_level = static_cast<int>(old_zoom_level);
3966 }
3967 }
[email protected]b75b8292010-10-01 07:28:253968 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413969 zoomLevelChanged();
3970}
3971
3972void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3973 int zoom_center_x, int zoom_center_y) {
3974 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3975 kScalingIncrementForGesture);
3976}
3977
3978void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3979 int zoom_center_x,
3980 int zoom_center_y,
3981 float scaling_increment) {
3982 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3983 return;
3984
[email protected]c514d6372011-08-16 22:54:443985 double old_page_scale_factor = webview()->pageScaleFactor();
3986 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:483987 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:443988 page_scale_factor = 1.0;
3989 } else {
3990 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:413991 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:443992 }
[email protected]47578fa02011-11-02 19:34:413993 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:093994 webview()->setPageScaleFactor(page_scale_factor,
3995 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:413996 }
[email protected]40bd6582009-12-04 23:49:513997}
3998
[email protected]310ebd6302011-10-10 19:06:283999void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:174000 webview()->hidePopups();
4001 webview()->setZoomLevel(false, zoom_level);
4002 zoomLevelChanged();
4003}
4004
[email protected]310ebd6302011-10-10 19:06:284005void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
4006 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544007 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294008}
4009
[email protected]310ebd6302011-10-10 19:06:284010void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274011 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294012}
4013
[email protected]310ebd6302011-10-10 19:06:284014void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274015 WebString no_encoding;
4016 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184017}
4018
[email protected]310ebd6302011-10-10 19:06:284019WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:454020 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274021 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454022
4023 // xpath string can represent a frame deep down the tree (across multiple
4024 // frame DOMs).
4025 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4026 // should break into 2 xpaths
4027 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:414028 std::vector<string16> xpaths;
4029 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:454030
[email protected]26aa0482009-09-30 16:55:274031 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:414032 for (std::vector<string16>::const_iterator i = xpaths.begin();
4033 frame && i != xpaths.end(); ++i) {
4034 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294035 }
4036
[email protected]dd7daa82009-08-10 05:46:454037 return frame;
initial.commit09911bf2008-07-26 23:55:294038}
4039
[email protected]310ebd6302011-10-10 19:06:284040void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4041 const string16& jscript,
4042 int id,
4043 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:534044 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294045}
4046
[email protected]310ebd6302011-10-10 19:06:284047void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4048 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414049 WebFrame* frame = GetChildFrame(frame_xpath);
4050 if (!frame)
[email protected]216813952011-05-19 22:21:264051 return;
[email protected]ae461542009-06-19 19:03:414052
[email protected]01cf589c2011-07-28 18:04:034053 frame->document().insertUserStyleSheet(
4054 WebString::fromUTF8(css),
4055 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484056}
4057
[email protected]310ebd6302011-10-10 19:06:284058void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094059 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294060}
4061
[email protected]310ebd6302011-10-10 19:06:284062void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4063 const std::string& value) {
[email protected]e091df82011-10-11 18:13:214064 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:274065 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294066}
4067
[email protected]310ebd6302011-10-10 19:06:284068void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4069 const gfx::Point& client_point,
4070 const gfx::Point& screen_point,
4071 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554072 WebDragOperation operation = webview()->dragTargetDragEnter(
4073 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554074 client_point,
4075 screen_point,
4076 ops);
4077
4078 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4079}
4080
[email protected]310ebd6302011-10-10 19:06:284081void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4082 const gfx::Point& screen_point,
4083 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554084 WebDragOperation operation = webview()->dragTargetDragOver(
4085 client_point,
4086 screen_point,
4087 ops);
4088
4089 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4090}
4091
[email protected]310ebd6302011-10-10 19:06:284092void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554093 webview()->dragTargetDragLeave();
4094}
4095
[email protected]310ebd6302011-10-10 19:06:284096void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
4097 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:554098 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:574099
4100 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554101}
4102
[email protected]310ebd6302011-10-10 19:06:284103void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4104 const gfx::Point& screen_point,
4105 bool ended,
4106 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034107 if (ended) {
[email protected]26aa0482009-09-30 16:55:274108 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204109 } else {
4110 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034111 }
initial.commit09911bf2008-07-26 23:55:294112}
4113
[email protected]310ebd6302011-10-10 19:06:284114void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274115 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294116}
4117
[email protected]310ebd6302011-10-10 19:06:284118void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594119 webkit_preferences_ = prefs;
4120 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294121}
4122
[email protected]310ebd6302011-10-10 19:06:284123void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294124 alternate_error_page_url_ = url;
4125}
4126
[email protected]310ebd6302011-10-10 19:06:284127void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514128 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084129 unsigned action) {
4130 if (custom_context.is_pepper_menu)
4131 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4132 else
4133 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584134 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4135 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334136}
4137
[email protected]310ebd6302011-10-10 19:06:284138void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514139 int id,
4140 const std::vector<FilePath>& paths) {
4141 if (!enumeration_completions_[id])
4142 return;
4143
4144 WebVector<WebString> ws_file_names(paths.size());
4145 for (size_t i = 0; i < paths.size(); ++i)
4146 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4147
4148 enumeration_completions_[id]->didChooseFile(ws_file_names);
4149 enumeration_completions_.erase(id);
4150}
4151
[email protected]310ebd6302011-10-10 19:06:284152void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364153 // This could happen if we navigated to a different page before the user
4154 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474155 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364156 return;
4157
[email protected]cdaf8d02010-03-30 19:52:474158 WebVector<WebString> ws_file_names(paths.size());
4159 for (size_t i = 0; i < paths.size(); ++i)
4160 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464161
[email protected]cdaf8d02010-03-30 19:52:474162 if (file_chooser_completions_.front()->completion)
4163 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4164 file_chooser_completions_.pop_front();
4165
4166 // If there are more pending file chooser requests, schedule one now.
4167 if (!file_chooser_completions_.empty()) {
4168 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4169 file_chooser_completions_.front()->params));
4170 }
initial.commit09911bf2008-07-26 23:55:294171}
4172
[email protected]244ac1892011-12-02 17:04:474173void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4174 const gfx::Size& max_size) {
4175 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4176 if (!webview())
4177 return;
[email protected]61e2b3cc2012-03-02 16:13:344178 webview()->enableAutoResizeMode(min_size, max_size);
4179}
4180
4181void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
4182 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4183 if (!webview())
4184 return;
4185 webview()->disableAutoResizeMode();
4186
4187 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:474188}
4189
[email protected]2bf834f2011-11-17 20:02:214190void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244191 if (send_preferred_size_changes_)
4192 return;
[email protected]9fb325e2010-05-06 18:23:244193 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394194
[email protected]d812fd12011-05-27 23:05:074195 // Start off with an initial preferred size notification (in case
4196 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594197 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084198}
4199
[email protected]310ebd6302011-10-10 19:06:284200void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104201 const gfx::Size& disable_scrollbar_size_limit) {
4202 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4203}
4204
[email protected]310ebd6302011-10-10 19:06:284205void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314206 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504207 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514208 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374209 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134210#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414211 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4212 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464213 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:514214 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344215 renderer_prefs.thumb_inactive_color,
4216 renderer_prefs.thumb_active_color,
4217 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324218
[email protected]644d77e2010-01-27 01:03:104219 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324220 webview()->setScrollbarColors(
4221 renderer_prefs.thumb_inactive_color,
4222 renderer_prefs.thumb_active_color,
4223 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104224 webview()->setSelectionColors(
4225 renderer_prefs.active_selection_bg_color,
4226 renderer_prefs.active_selection_fg_color,
4227 renderer_prefs.inactive_selection_bg_color,
4228 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464229 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104230 }
[email protected]7a74e102009-09-03 00:16:564231#endif
[email protected]d051d9a2011-12-10 02:02:504232 // If the zoom level for this page matches the old zoom default, and this
4233 // is not a plugin, update the zoom level to match the new default.
4234 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4235 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4236 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4237 zoomLevelChanged();
4238 }
[email protected]80d96fa2009-06-10 22:34:514239}
4240
[email protected]310ebd6302011-10-10 19:06:284241void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4242 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284243 if (webview())
4244 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564245}
4246
[email protected]81375e872012-01-11 21:40:364247void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4248 const WebPluginAction& action) {
4249 if (webview())
4250 webview()->performPluginAction(action, location);
4251}
4252
[email protected]310ebd6302011-10-10 19:06:284253void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194254 const GURL& page_url) {
4255 // Prepare list to storage all savable resource links.
4256 std::vector<GURL> resources_list;
4257 std::vector<GURL> referrers_list;
4258 std::vector<GURL> frames_list;
4259 webkit_glue::SavableResourcesResult result(&resources_list,
4260 &referrers_list,
4261 &frames_list);
4262
[email protected]445e1042011-12-03 21:03:154263 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4264 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194265 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4266 webview(),
4267 page_url,
4268 &result,
[email protected]2a80aee2011-10-07 16:06:034269 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194270 // If something is wrong when collecting all savable resource links,
4271 // send empty list to embedder(browser) to tell it failed.
4272 referrers_list.clear();
4273 resources_list.clear();
4274 frames_list.clear();
4275 }
4276
4277 // Send result of all savable resource links to embedder.
4278 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4279 resources_list,
4280 referrers_list,
4281 frames_list));
4282}
4283
[email protected]310ebd6302011-10-10 19:06:284284void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194285 const std::vector<GURL>& links,
4286 const std::vector<FilePath>& local_paths,
4287 const FilePath& local_directory_name) {
4288
4289 // Convert std::vector of GURLs to WebVector<WebURL>
4290 WebVector<WebURL> weburl_links(links);
4291
4292 // Convert std::vector of std::strings to WebVector<WebString>
4293 WebVector<WebString> webstring_paths(local_paths.size());
4294 for (size_t i = 0; i < local_paths.size(); i++)
4295 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4296
4297 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4298 webstring_paths,
4299 webkit_glue::FilePathToWebString(
4300 local_directory_name));
4301}
4302
[email protected]310ebd6302011-10-10 19:06:284303void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274304 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]4d346b92012-03-06 05:44:354305 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294306}
4307
[email protected]310ebd6302011-10-10 19:06:284308void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:314309 // Ensure that no other in-progress navigation continues.
4310 OnStop();
4311
[email protected]73eb2602012-02-09 19:50:554312 // Only run unload if we're not swapped out yet, but send the ack either way.
4313 if (!is_swapped_out_) {
4314 // Swap this RenderView out so the tab can navigate to a page rendered by a
4315 // different process. This involves running the unload handler and clearing
4316 // the page. Once WasSwappedOut is called, we also allow this process to
4317 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154318
[email protected]73eb2602012-02-09 19:50:554319 // Send an UpdateState message before we get swapped out.
4320 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154321
[email protected]73eb2602012-02-09 19:50:554322 // Synchronously run the unload handler before sending the ACK.
4323 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154324
[email protected]73eb2602012-02-09 19:50:554325 // Swap out and stop sending any IPC messages that are not ACKs.
4326 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154327
[email protected]73eb2602012-02-09 19:50:554328 // Replace the page with a blank dummy URL. The unload handler will not be
4329 // run a second time, thanks to a check in FrameLoader::stopLoading.
[email protected]69ddf852012-02-21 23:21:314330 // We use loadRequest instead of loadHTMLString because the former commits
4331 // synchronously. Otherwise a new navigation can interrupt the navigation
4332 // to about:swappedout. If that happens to be to the page we had been
4333 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]73eb2602012-02-09 19:50:554334 // TODO(creis): Need to add a better way to do this that avoids running the
4335 // beforeunload handler. For now, we just run it a second time silently.
[email protected]69ddf852012-02-21 23:21:314336 WebURLRequest request(GURL("about:swappedout"));
4337 webview()->mainFrame()->loadRequest(request);
[email protected]73eb2602012-02-09 19:50:554338 }
[email protected]992db4c2011-05-12 15:37:154339
4340 // Just echo back the params in the ACK.
4341 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4342}
4343
[email protected]310ebd6302011-10-10 19:06:284344void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374345 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294346 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4347 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4348 // in the onunload handler from appearing. For now, we're bypassing that and
4349 // calling the FrameLoader's CloseURL method directly. This should be
4350 // revisited to avoid having two ways to close a page. Having a single way
4351 // to close that can run onunload is also useful for fixing
4352 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274353 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294354
[email protected]992db4c2011-05-12 15:37:154355 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294356}
4357
[email protected]310ebd6302011-10-10 19:06:284358void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024359#if defined(USE_AURA)
4360 // Aura doesn't care if we switch themes.
4361#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164362 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464363 if (webview())
4364 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574365#else // defined(OS_WIN)
4366 // TODO(port): we don't support theming on non-Windows platforms yet
4367 NOTIMPLEMENTED();
4368#endif
initial.commit09911bf2008-07-26 23:55:294369}
4370
[email protected]310ebd6302011-10-10 19:06:284371void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084372 if (decrement_shared_popup_at_destruction_)
4373 shared_popup_counter_->data--;
4374 shared_popup_counter_ = new SharedRenderViewCounter(0);
4375 decrement_shared_popup_at_destruction_ = false;
4376}
4377
[email protected]310ebd6302011-10-10 19:06:284378bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4379 const WebURLError& error,
4380 bool replace) {
[email protected]15d79e12009-08-02 19:23:454381 // We only show alternate error pages in the main frame. They are
4382 // intended to assist the user when navigating, so there is not much
4383 // value in showing them for failed subframes. Ideally, we would be
4384 // able to use the TYPED transition type for this, but that flag is
4385 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454386 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454387 return false;
4388
4389 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374390 // connection failure.
[email protected]15d79e12009-08-02 19:23:454391 int ec = error.reason;
4392 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4393 ec != net::ERR_CONNECTION_FAILED &&
4394 ec != net::ERR_CONNECTION_REFUSED &&
4395 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374396 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454397 return false;
4398
4399 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554400 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454401 if (!error_page_url.is_valid())
4402 return false;
4403
4404 // Load an empty page first so there is an immediate response to the error,
4405 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454406 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364407 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454408 error.unreachableURL,
4409 replace);
4410
4411 // Now, create a fetcher for the error page and associate it with the data
4412 // source we just created via the LoadHTMLString call. That way if another
4413 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074414 DocumentState* document_state =
4415 DocumentState::FromDataSource(frame->provisionalDataSource());
4416 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454417 new AltErrorPageResourceFetcher(
4418 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084419 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4420 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454421 return true;
4422}
4423
[email protected]310ebd6302011-10-10 19:06:284424void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4425 const WebURLError& original_error,
4426 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454427 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094428 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554429 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094430 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454431}
4432
[email protected]310ebd6302011-10-10 19:06:284433void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004434 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474435 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004436}
4437
[email protected]310ebd6302011-10-10 19:06:284438void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094439 const gfx::Rect& resizer_rect,
4440 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104441 if (webview()) {
[email protected]7ddea9802012-02-22 23:08:054442 // This setting has no effect if fixed layout is not enabled.
[email protected]43d9d782012-03-01 15:40:094443 if (webkit_preferences_.default_device_scale_factor)
[email protected]7ddea9802012-02-22 23:08:054444 webview()->settings()->setLayoutFallbackWidth(
[email protected]43d9d782012-03-01 15:40:094445 new_size.width() / webkit_preferences_.default_device_scale_factor);
[email protected]a72a1fa2010-05-03 22:18:474446 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104447 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204448 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314449 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104450 }
[email protected]dd6afca2011-08-13 03:44:314451 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104452 }
4453
[email protected]ee41e7d22011-10-14 19:34:094454 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004455}
[email protected]0aa477bd2009-03-23 22:21:434456
[email protected]29ed96a2012-02-04 18:12:164457void RenderViewImpl::WillInitiatePaint() {
4458 // Notify the pepper plugins that we're about to paint.
4459 pepper_delegate_.ViewWillInitiatePaint();
4460}
4461
[email protected]310ebd6302011-10-10 19:06:284462void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164463 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014464 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284465}
4466
[email protected]310ebd6302011-10-10 19:06:284467void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284468 // Notify any pepper plugins that we painted. This will call into the plugin,
4469 // and we it may ask to close itself as a result. This will, in turn, modify
4470 // our set, possibly invalidating the iterator. So we iterate on a copy that
4471 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014472 pepper_delegate_.ViewFlushedPaint();
4473
[email protected]5b1dec8c2012-02-07 04:35:384474 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4475 // See crbug.com/112921.
4476 if (!webview())
4477 return;
4478
[email protected]00c39612010-03-06 02:53:284479 WebFrame* main_frame = webview()->mainFrame();
4480
4481 // If we have a provisional frame we are between the start and commit stages
4482 // of loading and we don't want to save stats.
4483 if (!main_frame->provisionalDataSource()) {
4484 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074485 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284486
[email protected]05c8e502010-08-15 15:13:524487 // TODO(jar): The following code should all be inside a method, probably in
4488 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284489 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074490 if (document_state->first_paint_time().is_null()) {
4491 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284492 }
[email protected]007733c2011-11-17 00:34:074493 if (document_state->first_paint_after_load_time().is_null() &&
4494 !document_state->finish_load_time().is_null()) {
4495 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284496 }
4497 }
4498}
4499
[email protected]310ebd6302011-10-10 19:06:284500void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084501 RenderWidget::OnSwapBuffersPosted();
4502}
4503
[email protected]310ebd6302011-10-10 19:06:284504void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244505 RenderWidget::OnSwapBuffersComplete();
4506}
4507
[email protected]310ebd6302011-10-10 19:06:284508void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244509 RenderWidget::OnSwapBuffersAborted();
4510}
4511
[email protected]310ebd6302011-10-10 19:06:284512webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154513 const gfx::Rect& paint_bounds,
4514 TransportDIB** dib,
4515 gfx::Rect* location,
4516 gfx::Rect* clip) {
4517 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4518 paint_bounds, dib, location, clip);
4519}
4520
[email protected]310ebd6302011-10-10 19:06:284521gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074522 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434523 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524524}
4525
[email protected]310ebd6302011-10-10 19:06:284526void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164527 if (webview())
[email protected]26aa0482009-09-30 16:55:274528 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164529}
4530
[email protected]310ebd6302011-10-10 19:06:284531void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144532 if (webview())
[email protected]b4bb2502009-10-01 22:35:274533 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144534
4535 SetBackground(background);
4536}
4537
[email protected]310ebd6302011-10-10 19:06:284538void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344539 if (webview())
[email protected]b4bb2502009-10-01 22:35:274540 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264541
4542#if defined(OS_MACOSX)
4543 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4544 for (plugin_it = plugin_delegates_.begin();
4545 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4546 (*plugin_it)->SetWindowFocus(active);
4547 }
4548#endif
[email protected]8c66c5a2009-07-22 17:26:344549}
4550
[email protected]6ce7abc52010-02-02 18:40:144551#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284552void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144553 // Inform plugins that their container has changed visibility.
4554 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4555 for (plugin_it = plugin_delegates_.begin();
4556 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4557 (*plugin_it)->SetContainerVisibility(visible);
4558 }
4559}
[email protected]1e6e3c992010-02-08 15:52:134560
[email protected]310ebd6302011-10-10 19:06:284561void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4562 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134563 // Inform plugins that their window's frame has changed.
4564 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4565 for (plugin_it = plugin_delegates_.begin();
4566 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4567 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4568 }
4569}
[email protected]935d63d2010-10-15 23:31:554570
[email protected]310ebd6302011-10-10 19:06:284571void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4572 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134573 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554574 // applies to it or not, so inform all the delegates.
4575 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4576 for (plugin_it = plugin_delegates_.begin();
4577 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134578 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554579 }
4580}
[email protected]6ce7abc52010-02-02 18:40:144581#endif // OS_MACOSX
4582
[email protected]310ebd6302011-10-10 19:06:284583void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484584 const EditCommands& edit_commands) {
4585 edit_commands_ = edit_commands;
4586}
4587
[email protected]310ebd6302011-10-10 19:06:284588void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594589 // We need to grab a pointer to the doomed WebView before we destroy it.
4590 WebView* doomed = webview();
4591 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494592 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594593}
4594
[email protected]310ebd6302011-10-10 19:06:284595void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484596 edit_commands_.clear();
4597}
4598
[email protected]310ebd6302011-10-10 19:06:284599bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:114600 pepper_delegate_.WillHandleMouseEvent();
4601
4602 // If the mouse is locked, only the current owner of the mouse lock can
4603 // process mouse events.
4604 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374605}
4606
[email protected]310ebd6302011-10-10 19:06:284607void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514608 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064609}
4610
[email protected]310ebd6302011-10-10 19:06:284611void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244612 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4613}
4614
[email protected]310ebd6302011-10-10 19:06:284615void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434616 RenderWidget::OnWasHidden();
4617
[email protected]a6939ca42011-02-18 17:58:074618 if (webview()) {
4619 webview()->settings()->setMinimumTimerInterval(
4620 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444621 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074622 }
4623
[email protected]204f1df2012-01-04 20:21:134624 // Inform PPAPI plugins that their page is no longer visible.
4625 pepper_delegate_.PageVisibilityChanged(false);
4626
[email protected]a6939ca42011-02-18 17:58:074627#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134628 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434629 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4630 for (plugin_it = plugin_delegates_.begin();
4631 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4632 (*plugin_it)->SetContainerVisibility(false);
4633 }
[email protected]a6939ca42011-02-18 17:58:074634#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434635}
4636
[email protected]310ebd6302011-10-10 19:06:284637void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434638 RenderWidget::OnWasRestored(needs_repainting);
4639
[email protected]a6939ca42011-02-18 17:58:074640 if (webview()) {
4641 webview()->settings()->setMinimumTimerInterval(
4642 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444643 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074644 }
4645
[email protected]204f1df2012-01-04 20:21:134646 // Inform PPAPI plugins that their page is visible.
4647 pepper_delegate_.PageVisibilityChanged(true);
4648
[email protected]a6939ca42011-02-18 17:58:074649#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134650 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434651 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4652 for (plugin_it = plugin_delegates_.begin();
4653 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4654 (*plugin_it)->SetContainerVisibility(true);
4655 }
[email protected]784ea1ab2010-09-18 00:02:344656#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074657}
[email protected]1e6e3c992010-02-08 15:52:134658
[email protected]310ebd6302011-10-10 19:06:284659bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384660 if (WebWidgetHandlesCompositorScheduling())
4661 return false;
4662
[email protected]05a980d7a2012-02-07 22:16:424663 if (queried_for_swapbuffers_complete_callback_)
4664 return context_has_swapbuffers_complete_callback_;
4665
4666 queried_for_swapbuffers_complete_callback_ = true;
4667
[email protected]65225772011-05-12 21:10:244668 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:424669 if (context && context->makeContextCurrent()) {
4670 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4671 context_has_swapbuffers_complete_callback_ =
4672 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
4673 != std::string::npos;
4674 }
4675
4676 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:244677}
4678
[email protected]310ebd6302011-10-10 19:06:284679void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134680 RenderWidget::OnSetFocus(enable);
4681
[email protected]7d3c02c2010-05-05 23:10:314682 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074683 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134684 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4685 for (plugin_it = plugin_delegates_.begin();
4686 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344687#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314688 // RenderWidget's call to setFocus can cause the underlying webview's
4689 // activation state to change just like a call to setIsActive.
4690 if (enable)
4691 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344692#endif
[email protected]7d3c02c2010-05-05 23:10:314693 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134694 }
[email protected]589621b2010-09-23 22:01:074695
4696 // Notify all Pepper plugins.
4697 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134698 }
4699}
[email protected]941e4552010-02-01 21:23:434700
[email protected]310ebd6302011-10-10 19:06:284701void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004702 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504703 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574704}
4705
[email protected]73bf95812011-10-12 11:38:324706void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004707 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324708}
4709
[email protected]3f783362011-10-21 22:40:504710void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4711 UpdateSelectionBounds();
4712}
4713
[email protected]b25b3ee2012-01-13 05:19:544714bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4715 if (!pepper_delegate_.IsPluginFocused())
4716 return false;
4717 *rect = pepper_delegate_.GetCaretBounds();
4718 return true;
4719}
4720
[email protected]73bf95812011-10-12 11:38:324721void RenderViewImpl::PpapiPluginCancelComposition() {
4722 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4723 ui::Range range(ui::Range::InvalidRange());
4724 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4725}
4726
[email protected]310ebd6302011-10-10 19:06:284727void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574728 const string16& text,
4729 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4730 int selection_start,
4731 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324732 if (pepper_delegate_.IsPluginFocused()) {
4733 // When a PPAPI plugin has focus, we bypass WebKit.
4734 pepper_delegate_.OnImeSetComposition(text,
4735 underlines,
4736 selection_start,
4737 selection_end);
4738 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234739#if defined(OS_WIN)
4740 // When a plug-in has focus, we create platform-specific IME data used by
4741 // our IME emulator and send it directly to the focused plug-in, i.e. we
4742 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4743 // instance ID is the same one as the specified ID.)
4744 if (focused_plugin_id_ >= 0) {
4745 std::vector<int> clauses;
4746 std::vector<int> target;
4747 for (size_t i = 0; i < underlines.size(); ++i) {
4748 clauses.push_back(underlines[i].startOffset);
4749 clauses.push_back(underlines[i].endOffset);
4750 if (underlines[i].thick) {
4751 target.clear();
4752 target.push_back(underlines[i].startOffset);
4753 target.push_back(underlines[i].endOffset);
4754 }
4755 }
4756 std::set<WebPluginDelegateProxy*>::iterator it;
4757 for (it = plugin_delegates_.begin();
4758 it != plugin_delegates_.end(); ++it) {
4759 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4760 focused_plugin_id_);
4761 }
4762 return;
4763 }
4764#endif
[email protected]56ea1a62011-05-30 07:05:574765 RenderWidget::OnImeSetComposition(text,
4766 underlines,
4767 selection_start,
4768 selection_end);
4769 }
4770}
4771
[email protected]4de6d1692011-10-12 08:45:444772void RenderViewImpl::OnImeConfirmComposition(
4773 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574774 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324775 // When a PPAPI plugin has focus, we bypass WebKit.
4776 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574777 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234778#if defined(OS_WIN)
4779 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4780 // plug-ins. When we send IME text directly to plug-ins, we should not send
4781 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444782 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234783 if (focused_plugin_id_ >= 0) {
4784 std::set<WebPluginDelegateProxy*>::iterator it;
4785 for (it = plugin_delegates_.begin();
4786 it != plugin_delegates_.end(); ++it) {
4787 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4788 }
4789 return;
4790 }
4791#endif
[email protected]ebd28ac2011-10-13 18:49:054792 if (replacement_range.IsValid() && webview()) {
4793 // Select the text in |replacement_range|, it will then be replaced by
4794 // text added by the call to RenderWidget::OnImeConfirmComposition().
4795 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164796 WebRange webrange = WebRange::fromDocumentRange(
4797 frame, replacement_range.start(), replacement_range.length());
4798 if (!webrange.isNull())
4799 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054800 }
4801 }
[email protected]4de6d1692011-10-12 08:45:444802 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574803 }
4804}
4805
[email protected]310ebd6302011-10-10 19:06:284806ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324807 return pepper_delegate_.IsPluginFocused() ?
4808 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4809}
4810
[email protected]3f783362011-10-21 22:40:504811void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4812 if (pepper_delegate_.IsPluginFocused()) {
4813 // TODO(kinaba) http://crbug.com/101101
4814 // Current Pepper IME API does not handle selection bounds. So we simply
4815 // use the caret position as an empty range for now. It will be updated
4816 // after Pepper API equips features related to surrounding text retrieval.
4817 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4818 *start = caret;
4819 *end = caret;
4820 return;
4821 }
4822 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454823}
4824
[email protected]310ebd6302011-10-10 19:06:284825bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324826 return pepper_delegate_.IsPluginFocused() ?
4827 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574828}
4829
[email protected]e6ae0f6c2011-10-04 10:39:234830#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284831void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234832 if (focused)
4833 focused_plugin_id_ = plugin_id;
4834 else
4835 focused_plugin_id_ = -1;
4836}
4837#endif
4838
[email protected]43f28f832010-02-03 02:28:484839#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284840void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134841 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4842 focused, plugin_id);
4843 Send(msg);
4844}
4845
[email protected]310ebd6302011-10-10 19:06:284846void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134847 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554848 // This message can be sent during event-handling, and needs to be delivered
4849 // within that context.
4850 msg->set_unblock(true);
4851 Send(msg);
4852}
4853
[email protected]310ebd6302011-10-10 19:06:284854gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234855 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484856 gfx::PluginWindowHandle window = NULL;
4857 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234858 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114859 if (window) {
4860 fake_plugin_window_handles_.insert(window);
4861 }
[email protected]43f28f832010-02-03 02:28:484862 return window;
4863}
4864
[email protected]310ebd6302011-10-10 19:06:284865void RenderViewImpl::DestroyFakePluginWindowHandle(
4866 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114867 if (window && fake_plugin_window_handles_.find(window) !=
4868 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484869 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114870 fake_plugin_window_handles_.erase(window);
4871 }
[email protected]43f28f832010-02-03 02:28:484872}
4873
[email protected]310ebd6302011-10-10 19:06:284874void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4875 gfx::PluginWindowHandle window,
4876 int32 width,
4877 int32 height,
4878 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334879 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484880 routing_id(), window, width, height, io_surface_identifier));
4881}
4882
[email protected]310ebd6302011-10-10 19:06:284883void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334884 gfx::PluginWindowHandle window,
4885 int32 width,
4886 int32 height,
4887 TransportDIB::Handle transport_dib) {
4888 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074889 routing_id(), window, width, height, transport_dib));
4890}
4891
[email protected]310ebd6302011-10-10 19:06:284892TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334893 size_t size) {
[email protected]1aef98132010-02-23 18:00:074894 TransportDIB::Handle dib_handle;
4895 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384896 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074897 return dib_handle;
4898 // Return an invalid handle if Send() fails.
4899 return TransportDIB::DefaultHandleValue();
4900}
4901
[email protected]310ebd6302011-10-10 19:06:284902void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4903 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074904 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4905}
4906
[email protected]310ebd6302011-10-10 19:06:284907void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144908 gfx::PluginWindowHandle window, uint64 surface_id) {
4909 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4910 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484911}
4912#endif
[email protected]58c321d2010-02-19 12:11:284913
[email protected]310ebd6302011-10-10 19:06:284914bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234915 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474916 WebFileChooserCompletion* completion) {
4917 static const size_t kMaximumPendingFileChooseRequests = 4;
4918 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4919 // This sanity check prevents too many file choose requests from getting
4920 // queued which could DoS the user. Getting these is most likely a
4921 // programming error (there are many ways to DoS the user so it's not
4922 // considered a "real" security check), either in JS requesting many file
4923 // choosers to pop up, or in a plugin.
4924 //
4925 // TODO(brettw) we might possibly want to require a user gesture to open
4926 // a file picker, which will address this issue in a better way.
4927 return false;
4928 }
4929
4930 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4931 new PendingFileChooser(params, completion)));
4932 if (file_chooser_completions_.size() == 1) {
4933 // Actually show the browse dialog when this is the first request.
4934 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4935 }
4936 return true;
4937}
4938
[email protected]310ebd6302011-10-10 19:06:284939WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514940 if (!geolocation_dispatcher_)
4941 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4942 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254943}
[email protected]61c9f032010-03-31 23:04:194944
[email protected]310ebd6302011-10-10 19:06:284945WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114946 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224947#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514948 if (!speech_input_dispatcher_)
4949 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224950#endif
[email protected]676126f72011-01-15 00:03:514951 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114952}
4953
[email protected]310ebd6302011-10-10 19:06:284954WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514955 if (!device_orientation_dispatcher_)
4956 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4957 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534958}
4959
[email protected]310ebd6302011-10-10 19:06:284960void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4961 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254962 // For now, don't remember plugin zoom values. We don't want to mix them with
4963 // normal web content (i.e. a fixed layout plugin would usually want them
4964 // different).
4965 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4966
[email protected]b75b8292010-10-01 07:28:254967 int minimum_percent = static_cast<int>(
4968 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4969 int maximum_percent = static_cast<int>(
4970 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254971
4972 Send(new ViewHostMsg_UpdateZoomLimits(
4973 routing_id_, minimum_percent, maximum_percent, remember));
4974}
4975
[email protected]310ebd6302011-10-10 19:06:284976void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254977 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084978 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:254979 // Tell the browser which url got zoomed so it can update the menu and the
4980 // saved values if necessary
4981 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084982 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414983 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254984}
4985
[email protected]310ebd6302011-10-10 19:06:284986void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4987 const WebString& base_url,
4988 const WebString& url,
4989 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484990 GURL base(base_url);
4991 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4992 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4993 return;
4994 }
[email protected]f1a29a02011-10-06 23:08:444995 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4996 UTF16ToUTF8(scheme),
4997 absolute_url,
4998 title));
[email protected]a6d36cc2011-02-23 00:39:484999}
5000
[email protected]310ebd6302011-10-10 19:06:285001WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:445002 WebKit::WebPageVisibilityState current_state = is_hidden() ?
5003 WebKit::WebPageVisibilityStateHidden :
5004 WebKit::WebPageVisibilityStateVisible;
5005 WebKit::WebPageVisibilityState override_state = current_state;
5006 if (content::GetContentClient()->renderer()->
5007 ShouldOverridePageVisibilityState(this,
5008 &override_state))
5009 return override_state;
5010 return current_state;
[email protected]94dec932011-05-26 20:04:215011}
5012
[email protected]273558fb2012-01-12 15:03:515013WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
5014 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
5015 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
5016 return NULL;
5017 EnsureMediaStreamImpl();
5018 return media_stream_impl_;
5019}
5020
[email protected]310ebd6302011-10-10 19:06:285021bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195022 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455023 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195024 if (frame->parent() != NULL)
5025 return false;
5026
[email protected]f0a3d0b2010-08-06 22:51:535027 // Navigations initiated within Webkit are not sent out to the external host
5028 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275029 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:135030 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535031 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:135032 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:335033 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:535034 return false;
5035
[email protected]2fc22d12010-12-02 23:08:165036 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325037 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015038 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165039 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015040 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325041 // The opener relationship between the new window and the parent allows the
5042 // new window to script the parent and vice versa. This is not allowed if
5043 // the origins of the two domains are different. This can be treated as a
5044 // top level navigation and routed back to the host.
5045 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275046 if (!opener) {
[email protected]86965362011-04-21 18:42:515047 return true;
[email protected]d19ea342011-04-20 20:31:135048 } else {
[email protected]b6cb3a842011-06-24 18:28:415049 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:325050 return true;
5051 }
5052 }
[email protected]61c9f032010-03-31 23:04:195053 return false;
5054}
[email protected]2b06a992010-08-21 05:48:225055
[email protected]310ebd6302011-10-10 19:06:285056void RenderViewImpl::OnAsyncFileOpened(
5057 base::PlatformFileError error_code,
5058 IPC::PlatformFileForTransit file_for_transit,
5059 int message_id) {
[email protected]27a9ef32010-09-10 04:06:245060 pepper_delegate_.OnAsyncFileOpened(
5061 error_code,
5062 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5063 message_id);
5064}
[email protected]caf706f2010-10-26 17:54:085065
[email protected]310ebd6302011-10-10 19:06:285066void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:475067 int request_id,
5068 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:435069 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:475070 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
5071 broker_process_handle,
5072 handle);
[email protected]eb415bf0e2011-04-14 02:45:425073}
5074
[email protected]caf706f2010-10-26 17:54:085075#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285076void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155077 if (external_popup_menu_ == NULL) {
5078 // Crash reports from the field indicate that we can be notified with a
5079 // NULL external popup menu (we probably get notified twice).
5080 // If you hit this please file a bug against jcivelli and include the page
5081 // and steps to repro.
5082 NOTREACHED();
5083 return;
5084 }
[email protected]caf706f2010-10-26 17:54:085085 external_popup_menu_->DidSelectItem(selected_index);
5086 external_popup_menu_.reset();
5087}
5088#endif
[email protected]bb461532010-11-26 21:50:235089
[email protected]1b4209f2011-01-07 00:25:405090#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:285091void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:405092 int request_id,
5093 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:495094 const PP_NetAddress_Private& local_addr,
5095 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:405096 pepper_delegate_.OnConnectTcpACK(
5097 request_id,
5098 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5099 local_addr,
5100 remote_addr);
5101}
5102#endif
[email protected]a6097f42011-01-10 08:50:515103
[email protected]310ebd6302011-10-10 19:06:285104void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515105 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085106 if (custom_context.is_pepper_menu)
5107 pepper_delegate_.OnContextMenuClosed(custom_context);
5108 else
5109 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105110}
[email protected]5a7b15a2011-08-22 22:48:185111
[email protected]310ebd6302011-10-10 19:06:285112void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185113 if (!webview())
5114 return;
5115 WebFrame* main_frame = webview()->mainFrame();
5116 if (!main_frame)
5117 return;
5118 main_frame->enableViewSourceMode(true);
5119}
[email protected]67bfb83f2011-09-22 03:36:375120
[email protected]310ebd6302011-10-10 19:06:285121bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085122 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405123}
[email protected]7f3c7af2011-10-20 22:52:515124
[email protected]64d0e192011-12-09 14:44:205125void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:515126 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:185127#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:205128 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:185129#endif
[email protected]7f3c7af2011-10-20 22:52:515130}