blob: 9f34b6c26bf5e60208b0c0051dc19894ed86fa6e [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:371430WebView* RenderViewImpl::createView(
1431 WebFrame* creator,
1432 const WebURLRequest& request,
1433 const WebWindowFeatures& features,
1434 const WebString& frame_name,
1435 WebNavigationPolicy policy) {
[email protected]48c9cf2d2009-09-16 16:47:521436 // Check to make sure we aren't overloading on popups.
1437 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1438 return NULL;
1439
[email protected]8ab04652010-06-12 02:47:261440 ViewHostMsg_CreateWindow_Params params;
1441 params.opener_id = routing_id_;
1442 params.user_gesture = creator->isProcessingUserGesture();
1443 params.window_container_type = WindowFeaturesToContainerType(features);
1444 params.session_storage_namespace_id = session_storage_namespace_id_;
1445 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111446 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411447 params.opener_url = creator->document().url();
1448 params.opener_security_origin =
1449 creator->document().securityOrigin().toString().utf8();
[email protected]f92ce2b2012-03-06 18:02:591450 params.opener_suppressed = creator->willSuppressOpenerInNewFrame();
1451 params.disposition = NavigationPolicyToDisposition(policy);
[email protected]41e65502011-01-21 09:29:111452 if (!request.isNull())
1453 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261454
[email protected]48c9cf2d2009-09-16 16:47:521455 int32 routing_id = MSG_ROUTING_NONE;
[email protected]9f4f3322012-01-18 22:29:561456 int32 surface_id = 0;
[email protected]4e6419c2010-01-15 04:50:341457 int64 cloned_session_storage_namespace_id;
[email protected]48c9cf2d2009-09-16 16:47:521458
[email protected]380244092011-10-07 17:26:271459 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261460 new ViewHostMsg_CreateWindow(params,
1461 &routing_id,
[email protected]9f4f3322012-01-18 22:29:561462 &surface_id,
[email protected]8ab04652010-06-12 02:47:261463 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211464 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521465 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521466
[email protected]310ebd6302011-10-10 19:06:281467 RenderViewImpl* view = RenderViewImpl::Create(
1468 0,
1469 routing_id_,
1470 renderer_preferences_,
1471 webkit_preferences_,
1472 shared_popup_counter_,
1473 routing_id,
[email protected]9f4f3322012-01-18 22:29:561474 surface_id,
[email protected]310ebd6302011-10-10 19:06:281475 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461476 frame_name,
[email protected]6fd35b72012-03-01 19:46:411477 1,
1478 screen_info_);
[email protected]8ab04652010-06-12 02:47:261479 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521480
[email protected]007a848b2009-10-26 15:55:461481 // Record whether the creator frame is trying to suppress the opener field.
[email protected]f92ce2b2012-03-06 18:02:591482 view->opener_suppressed_ = params.opener_suppressed;
[email protected]007a848b2009-10-26 15:55:461483
[email protected]48c9cf2d2009-09-16 16:47:521484 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411485 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521486 if (!creator_url.is_valid() || !creator_url.IsStandard())
1487 creator_url = GURL();
1488 view->creator_url_ = creator_url;
1489
1490 // Copy over the alternate error page URL so we can have alt error pages in
1491 // the new render view (we don't need the browser to send the URL back down).
1492 view->alternate_error_page_url_ = alternate_error_page_url_;
1493
1494 return view->webview();
1495}
1496
[email protected]310ebd6302011-10-10 19:06:281497WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]6fd35b72012-03-01 19:46:411498 RenderWidget* widget =
1499 RenderWidget::Create(routing_id_, popup_type, screen_info_);
[email protected]48c9cf2d2009-09-16 16:47:521500 return widget->webwidget();
1501}
1502
[email protected]310ebd6302011-10-10 19:06:281503WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441504 // TODO(jcivelli): Remove this deprecated method when its been removed from
1505 // the WebViewClient interface. It's been replaced by
1506 // createExternalPopupMenu.
1507 NOTREACHED();
1508 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521509}
1510
[email protected]310ebd6302011-10-10 19:06:281511WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081512 const WebPopupMenuInfo& popup_menu_info,
1513 WebExternalPopupMenuClient* popup_menu_client) {
1514 DCHECK(!external_popup_menu_.get());
1515 external_popup_menu_.reset(
1516 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1517 return external_popup_menu_.get();
1518}
1519
[email protected]310ebd6302011-10-10 19:06:281520RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521521 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531522 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421523 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411524 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531525 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271526 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391527 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561528 return widget;
[email protected]79c7bed2010-09-14 22:28:391529}
1530
[email protected]310ebd6302011-10-10 19:06:281531WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1532 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341533 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391534 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291535 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1536 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1537 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341538}
1539
[email protected]7e8b4d12012-01-20 23:39:511540WebGraphicsContext3D* RenderViewImpl::createGraphicsContext3D(
[email protected]01e69032012-01-31 05:39:061541 const WebGraphicsContext3D::Attributes& attributes,
[email protected]7e8b4d12012-01-20 23:39:511542 bool direct) {
1543 if (!webview())
1544 return NULL;
1545 // The WebGraphicsContext3DInProcessImpl code path is used for
1546 // layout tests (though not through this code) as well as for
1547 // debugging and bringing up new ports.
[email protected]7e8b4d12012-01-20 23:39:511548 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessWebGL)) {
[email protected]56200f012012-02-03 23:13:571549 return webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView(
[email protected]33a9c762012-02-23 22:37:241550 attributes, direct);
[email protected]7e8b4d12012-01-20 23:39:511551 } else {
[email protected]b3e83de2012-02-07 03:33:281552 int surface = direct ? surface_id() : 0;
1553
1554 GURL url;
1555 if (webview()->mainFrame())
1556 url = GURL(webview()->mainFrame()->document().url());
1557
1558 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client;
1559 if (direct)
1560 swap_client = AsWeakPtr();
1561
1562 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
1563 new WebGraphicsContext3DCommandBufferImpl(
1564 surface, url, swap_client));
1565
1566 if (!context->Initialize(attributes))
[email protected]56200f012012-02-03 23:13:571567 return NULL;
1568 return context.release();
[email protected]7e8b4d12012-01-20 23:39:511569 }
[email protected]7e8b4d12012-01-20 23:39:511570}
1571
[email protected]310ebd6302011-10-10 19:06:281572void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521573 const WebConsoleMessage& message, const WebString& source_name,
1574 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081575 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511576 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081577 case WebConsoleMessage::LevelTip:
1578 log_severity = logging::LOG_VERBOSE;
1579 break;
1580 case WebConsoleMessage::LevelLog:
1581 log_severity = logging::LOG_INFO;
1582 break;
1583 case WebConsoleMessage::LevelWarning:
1584 log_severity = logging::LOG_WARNING;
1585 break;
1586 case WebConsoleMessage::LevelError:
1587 log_severity = logging::LOG_ERROR;
1588 break;
1589 default:
1590 NOTREACHED();
1591 }
1592
[email protected]48c9cf2d2009-09-16 16:47:521593 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081594 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311595 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521596 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311597 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521598}
1599
[email protected]310ebd6302011-10-10 19:06:281600void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421601 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521602}
1603
[email protected]310ebd6302011-10-10 19:06:281604WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511605 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021606}
1607
[email protected]310ebd6302011-10-10 19:06:281608bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121609 const WebString& path,
1610 WebFileChooserCompletion* chooser_completion) {
1611 int id = enumeration_completion_id_++;
1612 enumeration_completions_[id] = chooser_completion;
1613 return Send(new ViewHostMsg_EnumerateDirectory(
1614 routing_id_,
1615 id,
1616 webkit_glue::WebStringToFilePath(path)));
1617}
1618
[email protected]310ebd6302011-10-10 19:06:281619void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521620 if (is_loading_) {
[email protected]511754da2012-01-24 20:48:141621 DVLOG(1) << "didStartLoading called while loading";
[email protected]48c9cf2d2009-09-16 16:47:521622 return;
1623 }
1624
1625 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521626
1627 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311628
1629 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521630}
1631
[email protected]310ebd6302011-10-10 19:06:281632void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521633 if (!is_loading_) {
[email protected]511754da2012-01-24 20:48:141634 DVLOG(1) << "DidStopLoading called while not loading";
[email protected]48c9cf2d2009-09-16 16:47:521635 return;
1636 }
1637
1638 is_loading_ = false;
1639
1640 // NOTE: For now we're doing the safest thing, and sending out notification
1641 // when done loading. This currently isn't an issue as the favicon is only
1642 // displayed when done loading. Ideally we would send notification when
1643 // finished parsing the head, but webkit doesn't support that yet.
1644 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521645 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1646
[email protected]90109412010-12-15 17:14:241647 if (load_progress_tracker_ != NULL)
1648 load_progress_tracker_->DidStopLoading();
1649
[email protected]93b9d692011-04-13 00:44:311650 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521651}
1652
[email protected]310ebd6302011-10-10 19:06:281653void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1654 double load_progress) {
[email protected]90109412010-12-15 17:14:241655 if (load_progress_tracker_ != NULL)
1656 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1657}
1658
[email protected]310ebd6302011-10-10 19:06:281659bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061660#if defined(OS_MACOSX)
1661 return true;
1662#else
1663 return false;
1664#endif
1665}
1666
[email protected]310ebd6302011-10-10 19:06:281667bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031668#if defined(OS_WIN)
1669 return true;
1670#else
1671 return false;
1672#endif
1673}
1674
[email protected]310ebd6302011-10-10 19:06:281675void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081676 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031677 return;
[email protected]4fb60142011-08-09 02:22:081678 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011679
[email protected]b781ff282011-08-20 06:19:361680 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031681}
1682
[email protected]310ebd6302011-10-10 19:06:281683void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121684 const std::string& name = UTF16ToUTF8(command_name);
1685 if (StartsWithASCII(name, "Move", true) ||
1686 StartsWithASCII(name, "Insert", true) ||
1687 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031688 return;
[email protected]f1a29a02011-10-06 23:08:441689 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031690}
1691
[email protected]310ebd6302011-10-10 19:06:281692bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101693 if (edit_commands_.empty())
1694 return false;
1695
[email protected]26aa0482009-09-30 16:55:271696 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101697 if (!frame)
1698 return false;
1699
1700 EditCommands::iterator it = edit_commands_.begin();
1701 EditCommands::iterator end = edit_commands_.end();
1702
[email protected]507b33ea2009-09-29 03:56:511703 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101704 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331705 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1706 // key (but it's the exception). Once one edit command is not executed, it
1707 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101708 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1709 WebString::fromUTF8(it->value)))
1710 break;
[email protected]507b33ea2009-09-29 03:56:511711 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101712 }
1713
[email protected]507b33ea2009-09-29 03:56:511714 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101715}
1716
[email protected]310ebd6302011-10-10 19:06:281717bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351718 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471719 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351720 // Do not open the file dialog in a hidden RenderView.
1721 if (is_hidden())
1722 return false;
[email protected]8caadeb2011-11-22 02:45:231723 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261724 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231725 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261726 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231727 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501728 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231729 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261730 else
[email protected]8caadeb2011-11-22 02:45:231731 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471732 ipc_params.title = params.title;
1733 ipc_params.default_file_name =
1734 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461735 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1736 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1737 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471738
1739 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461740}
1741
[email protected]269f86d2011-12-07 02:43:471742void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1743 const WebString& message) {
1744 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411745 message,
1746 string16(),
[email protected]b6cb3a842011-06-24 18:28:411747 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521748 NULL);
1749}
1750
[email protected]269f86d2011-12-07 02:43:471751bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1752 const WebString& message) {
1753 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[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::runModalPromptDialog(WebFrame* frame,
1761 const WebString& message,
1762 const WebString& default_value,
1763 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411764 string16 result;
[email protected]269f86d2011-12-07 02:43:471765 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411766 message,
1767 default_value,
[email protected]b6cb3a842011-06-24 18:28:411768 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521769 &result);
1770 if (ok)
[email protected]4f5ce842011-05-27 19:34:411771 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521772 return ok;
1773}
1774
[email protected]310ebd6302011-10-10 19:06:281775bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521776 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151777 // If we are swapping out, we have already run the beforeunload handler.
1778 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1779 // at all, to avoid running it twice.
1780 if (is_swapped_out_)
1781 return true;
1782
[email protected]3b3301f62012-02-29 04:32:321783 bool is_reload = false;
1784 WebDataSource* ds = frame->provisionalDataSource();
1785 if (ds)
1786 is_reload = (ds->navigationType() == WebKit::WebNavigationTypeReload);
1787
[email protected]48c9cf2d2009-09-16 16:47:521788 bool success = false;
1789 // This is an ignored return value, but is included so we can accept the same
1790 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411791 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211792 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]3b3301f62012-02-29 04:32:321793 routing_id_, frame->document().url(), message, is_reload,
[email protected]b6cb3a842011-06-24 18:28:411794 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521795 return success;
1796}
1797
[email protected]310ebd6302011-10-10 19:06:281798void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441799 WebFrame* frame, const WebContextMenuData& data) {
[email protected]35be7ec2012-02-12 20:42:511800 content::ContextMenuParams params(data);
[email protected]7fcd9b72011-07-27 16:52:371801
1802 // frame is NULL if invoked by BlockedPlugin.
1803 if (frame)
1804 params.frame_id = frame->identifier();
1805
[email protected]db803aae2011-03-05 02:00:421806 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271807 // it. We replace it with an empty GURL so the appropriate items are disabled
1808 // in the context menu.
1809 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1810 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421811 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271812 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101813 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291814 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441815}
1816
[email protected]310ebd6302011-10-10 19:06:281817void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261818 // TODO(darin): Remove once WebKit roll is complete.
1819 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471820}
1821
[email protected]310ebd6302011-10-10 19:06:281822void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261823 // TODO(darin): Remove once WebKit roll is complete.
1824 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471825}
1826
[email protected]310ebd6302011-10-10 19:06:281827void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521828}
1829
[email protected]310ebd6302011-10-10 19:06:281830void RenderViewImpl::UpdateTargetURL(const GURL& url,
1831 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581832 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521833 if (latest_url == target_url_)
1834 return;
[email protected]163f8242009-10-30 20:19:551835
[email protected]48c9cf2d2009-09-16 16:47:521836 // Tell the browser to display a destination link.
1837 if (target_url_status_ == TARGET_INFLIGHT ||
1838 target_url_status_ == TARGET_PENDING) {
1839 // If we have a request in-flight, save the URL to be sent when we
1840 // receive an ACK to the in-flight request. We can happily overwrite
1841 // any existing pending sends.
1842 pending_target_url_ = latest_url;
1843 target_url_status_ = TARGET_PENDING;
1844 } else {
[email protected]c85f0212011-11-04 16:54:411845 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1846 // see |ParamTraits<GURL>|.
1847 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1848 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521849 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1850 target_url_ = latest_url;
1851 target_url_status_ = TARGET_INFLIGHT;
1852 }
1853}
1854
[email protected]310ebd6302011-10-10 19:06:281855void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311856 int delay;
1857 if (send_content_state_immediately_)
1858 delay = 0;
1859 else if (is_hidden())
1860 delay = kDelaySecondsForContentStateSyncHidden;
1861 else
1862 delay = kDelaySecondsForContentStateSync;
1863
1864 if (nav_state_sync_timer_.IsRunning()) {
1865 // The timer is already running. If the delay of the timer maches the amount
1866 // we want to delay by, then return. Otherwise stop the timer so that it
1867 // gets started with the right delay.
1868 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1869 return;
1870 nav_state_sync_timer_.Stop();
1871 }
1872
[email protected]d323a172011-09-02 18:23:021873 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281874 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311875}
1876
[email protected]310ebd6302011-10-10 19:06:281877void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551878 mouse_over_url_ = GURL(url);
1879 UpdateTargetURL(mouse_over_url_, focus_url_);
1880}
1881
[email protected]310ebd6302011-10-10 19:06:281882void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551883 focus_url_ = GURL(url);
1884 UpdateTargetURL(focus_url_, mouse_over_url_);
1885}
1886
[email protected]310ebd6302011-10-10 19:06:281887void RenderViewImpl::startDragging(const WebDragData& data,
1888 WebDragOperationsMask mask,
1889 const WebImage& image,
1890 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411891#if WEBKIT_USING_SKIA
1892 SkBitmap bitmap(image.getSkBitmap());
1893#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331894 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411895#endif
1896
[email protected]59f4f2fa2011-03-23 01:00:551897 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521898 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411899 mask,
1900 bitmap,
1901 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521902}
1903
[email protected]310ebd6302011-10-10 19:06:281904bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451905 return renderer_preferences_.can_accept_load_drops;
1906}
1907
[email protected]310ebd6302011-10-10 19:06:281908void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521909 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1910}
1911
[email protected]310ebd6302011-10-10 19:06:281912void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521913 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1914}
1915
[email protected]310ebd6302011-10-10 19:06:281916void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511917 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071918
[email protected]38b592902011-04-16 02:08:421919 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491920}
1921
[email protected]169d4282011-11-30 19:33:591922void RenderViewImpl::didUpdateLayout() {
1923 // We don't always want to set up a timer, only if we've been put in that
1924 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1925 // message.
1926 if (!send_preferred_size_changes_ || !webview())
1927 return;
1928
1929 if (check_preferred_size_timer_.IsRunning())
1930 return;
1931 check_preferred_size_timer_.Start(FROM_HERE,
1932 TimeDelta::FromMilliseconds(0), this,
1933 &RenderViewImpl::CheckPreferredSize);
1934}
1935
[email protected]310ebd6302011-10-10 19:06:281936void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521937 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1938}
1939
[email protected]310ebd6302011-10-10 19:06:281940int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001941 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521942}
1943
[email protected]310ebd6302011-10-10 19:06:281944int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001945 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521946}
1947
[email protected]310ebd6302011-10-10 19:06:281948void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321949 const WebAccessibilityObject& obj,
1950 WebAccessibilityNotification notification) {
1951 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1952}
1953
[email protected]310ebd6302011-10-10 19:06:281954void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141955 const WebString& value) {
1956 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1957 key.utf8(),
1958 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261959}
1960
[email protected]79dbc662009-09-04 05:42:511961// WebKit::WebWidgetClient ----------------------------------------------------
1962
[email protected]310ebd6302011-10-10 19:06:281963void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121964 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1965 // we won't have to test for user gesture anymore and we can
1966 // move that code back to render_widget.cc
1967 if (webview() && webview()->mainFrame() &&
1968 webview()->mainFrame()->isProcessingUserGesture()) {
1969 Send(new ViewHostMsg_Focus(routing_id_));
1970 }
1971}
1972
[email protected]310ebd6302011-10-10 19:06:281973void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121974 // TODO(jcivelli): see TODO above in didFocus().
1975 if (webview() && webview()->mainFrame() &&
1976 webview()->mainFrame()->isProcessingUserGesture()) {
1977 Send(new ViewHostMsg_Blur(routing_id_));
1978 }
1979}
1980
initial.commit09911bf2008-07-26 23:55:291981// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281982// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291983// point to dispatch the ShowView message.
1984//
1985// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281986// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291987//
[email protected]310ebd6302011-10-10 19:06:281988void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291989 DCHECK(!did_show_) << "received extraneous Show call";
1990 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1991
1992 if (did_show_)
1993 return;
1994 did_show_ = true;
1995
[email protected]6779aa12011-03-29 17:32:241996 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041997 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041998
[email protected]28295ec2009-10-16 05:34:331999 // Force new windows to a popup if they were not opened with a user gesture.
2000 if (!opened_by_user_gesture_) {
2001 // We exempt background tabs for compat with older versions of Chrome.
2002 // TODO(darin): This seems bogus. These should have a user gesture, so
2003 // we probably don't need this check.
2004 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2005 policy = WebKit::WebNavigationPolicyNewPopup;
2006 }
2007
initial.commit09911bf2008-07-26 23:55:292008 // NOTE: initial_pos_ may still have its default values at this point, but
2009 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2010 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282011 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2012 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292013 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242014 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292015}
2016
[email protected]310ebd6302011-10-10 19:06:282017void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:292018 DCHECK(did_show_) << "should already have shown the view";
2019
[email protected]c1f50aa2010-02-18 03:46:572020 // We must keep WebKit's shared timer running in this case in order to allow
2021 // showModalDialog to function properly.
2022 //
2023 // TODO(darin): WebKit should really be smarter about suppressing events and
2024 // timers so that we do not need to manage the shared timer in such a heavy
2025 // handed manner.
2026 //
[email protected]f1a29a02011-10-06 23:08:442027 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
2028 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:572029
[email protected]12636df2009-09-28 22:32:212030 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292031}
2032
[email protected]2b624c562011-10-27 22:58:262033bool RenderViewImpl::enterFullScreen() {
2034 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
2035 return true;
2036}
2037
2038void RenderViewImpl::exitFullScreen() {
2039 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
2040}
2041
[email protected]217690d2012-01-27 07:33:112042bool RenderViewImpl::requestPointerLock() {
2043 return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get());
2044}
2045
2046void RenderViewImpl::requestPointerUnlock() {
2047 mouse_lock_dispatcher_->UnlockMouse(webwidget_mouse_lock_target_.get());
2048}
2049
2050bool RenderViewImpl::isPointerLocked() {
2051 return mouse_lock_dispatcher_->IsMouseLockedTo(
2052 webwidget_mouse_lock_target_.get());
2053}
2054
[email protected]3d9689372009-09-10 04:29:172055// WebKit::WebFrameClient -----------------------------------------------------
2056
[email protected]310ebd6302011-10-10 19:06:282057WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
2058 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:552059 WebPlugin* plugin = NULL;
2060 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
2061 this, frame, params, &plugin)) {
2062 return plugin;
2063 }
2064
[email protected]a813c8e2011-10-08 01:34:112065 webkit::WebPluginInfo info;
2066 std::string mime_type;
2067 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
2068 params.mimeType.utf8(), &info, &mime_type);
2069 if (!found)
2070 return NULL;
2071
2072 WebPluginParams params_to_use = params;
2073 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:312074 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:172075}
2076
[email protected]310ebd6302011-10-10 19:06:282077WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:422078 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372079 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422080
[email protected]30447b62009-11-13 01:13:372081 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512082 bool exists = false;
[email protected]30447b62009-11-13 01:13:372083 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512084 ViewHostMsg_CreateWorker_Params params;
2085 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:512086 params.name = name;
2087 params.document_id = document_id;
2088 params.render_view_route_id = routing_id_;
2089 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232090 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372091 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512092 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372093 if (url_mismatch) {
2094 return NULL;
2095 } else {
[email protected]f1a29a02011-10-06 23:08:442096 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:492097 document_id,
[email protected]6de0bcf2010-02-17 22:00:512098 exists,
[email protected]30447b62009-11-13 01:13:372099 route_id,
2100 routing_id_);
2101 }
[email protected]9c00f002009-11-05 22:37:422102}
2103
[email protected]310ebd6302011-10-10 19:06:282104WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:172105 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442106 FOR_EACH_OBSERVER(
2107 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172108
[email protected]bb6fd402011-12-09 02:45:442109 media::MessageLoopFactory* message_loop_factory =
[email protected]b80322902012-03-06 01:33:502110 new media::MessageLoopFactory();
[email protected]bb6fd402011-12-09 02:45:442111 media::FilterCollection* collection = new media::FilterCollection();
2112 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:372113
[email protected]9e2269d2012-01-07 00:06:212114 RenderAudioSourceProvider* audio_source_provider = NULL;
2115
[email protected]3d9689372009-09-10 04:29:172116 // Add in any custom filter factories first.
2117 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2118 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
[email protected]9e2269d2012-01-07 00:06:212119 // audio_source_provider is a "provider" to WebKit, and a sink
2120 // from the perspective of the audio renderer.
2121 audio_source_provider = new RenderAudioSourceProvider();
2122
2123 // Add the chrome specific audio renderer, using audio_source_provider
2124 // as the sink.
2125 AudioRendererImpl* audio_renderer =
2126 new AudioRendererImpl(audio_source_provider);
2127 collection->AddAudioRenderer(audio_renderer);
[email protected]3d9689372009-09-10 04:29:172128 }
2129
[email protected]e1d69d762011-12-13 05:12:182130#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
2131 // Currently only cros/arm has any HW video decode support in
2132 // GpuVideoDecodeAccelerator so we don't even try to use it on other
2133 // platforms. This is a startup-time optimization. When new VDA
2134 // implementations are added, relax the #if above.
[email protected]43567302012-02-16 23:21:392135 WebGraphicsContext3DCommandBufferImpl* context3d =
2136 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2137 webview()->graphicsContext3D());
2138 if (context3d && context3d->makeContextCurrent()) {
[email protected]e1d69d762011-12-13 05:12:182139 GpuChannelHost* gpu_channel_host =
2140 RenderThreadImpl::current()->EstablishGpuChannelSync(
2141 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
2142 collection->AddVideoDecoder(new media::GpuVideoDecoder(
[email protected]8d4359282012-01-14 00:53:312143 message_loop_factory->GetMessageLoop("GpuVideoDecoder"),
2144 new RendererGpuVideoDecoderFactories(
2145 gpu_channel_host, context3d->context()->AsWeakPtr())));
[email protected]e1d69d762011-12-13 05:12:182146 }
2147#endif
2148
[email protected]da952fd2012-01-13 03:49:252149 webkit_media::WebMediaPlayerImpl* media_player =
2150 content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
2151 this, frame, client, AsWeakPtr(), collection, audio_source_provider,
2152 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]c4dabe452012-02-08 23:58:122153#if defined(OS_ANDROID)
2154 // TODO(qinmin): Implement for android.
2155 // http://crbug.com/113218
2156#else
[email protected]da952fd2012-01-13 03:49:252157 if (!media_player) {
[email protected]cec4eb82012-01-12 17:51:562158 media_player = new webkit_media::WebMediaPlayerImpl(
[email protected]da952fd2012-01-13 03:49:252159 frame, client, AsWeakPtr(), collection, audio_source_provider,
[email protected]9e2269d2012-01-07 00:06:212160 message_loop_factory, media_stream_impl_.get(), render_media_log);
[email protected]bb6fd402011-12-09 02:45:442161 }
[email protected]c4dabe452012-02-08 23:58:122162#endif
[email protected]cec4eb82012-01-12 17:51:562163 return media_player;
[email protected]3d9689372009-09-10 04:29:172164}
2165
[email protected]310ebd6302011-10-10 19:06:282166WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:212167 WebFrame* frame, WebApplicationCacheHostClient* client) {
[email protected]cdeeeb22012-01-11 07:44:232168 if (!frame || !frame->view())
2169 return NULL;
[email protected]035545f2010-04-09 13:10:212170 return new RendererWebApplicationCacheHostImpl(
2171 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:442172 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:212173}
2174
[email protected]310ebd6302011-10-10 19:06:282175WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:382176 return &cookie_jar_;
2177}
2178
[email protected]310ebd6302011-10-10 19:06:282179void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512180 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452181}
2182
[email protected]310ebd6302011-10-10 19:06:282183void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512184 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172185}
2186
[email protected]310ebd6302011-10-10 19:06:282187void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172188 WebFrame* frame, const WebURLRequest& request,
2189 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342190 loadURLExternally(frame, request, policy, WebString());
2191}
2192
[email protected]310ebd6302011-10-10 19:06:282193void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342194 WebFrame* frame, const WebURLRequest& request,
2195 WebNavigationPolicy policy,
2196 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592197 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2198 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342199 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2200 suggested_name));
[email protected]efce17b2009-09-11 18:04:592201 } else {
[email protected]445e1042011-12-03 21:03:152202 OpenURL(frame, request.url(),
[email protected]b9fd01ba2012-02-28 01:50:402203 Referrer(referrer, GetReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592204 }
[email protected]3d9689372009-09-10 04:29:172205}
2206
[email protected]310ebd6302011-10-10 19:06:282207WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172208 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222209 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152210 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2211 if (is_swapped_out_) {
[email protected]73eb2602012-02-09 19:50:552212 // It is possible for in-progress navigations to arrive here just after we
2213 // are swapped out, including iframes. We should cancel them.
2214 if (request.url() != GURL("about:swappedout"))
2215 return WebKit::WebNavigationPolicyIgnore;
2216
2217 // Allow about:swappedout to complete.
[email protected]992db4c2011-05-12 15:37:152218 return default_policy;
2219 }
2220
[email protected]3d9689372009-09-10 04:29:172221 // Webkit is asking whether to navigate to a new URL.
2222 // This is fine normally, except if we're showing UI from one security
2223 // context and they're trying to navigate to a different context.
2224 const GURL& url = request.url();
2225
[email protected]d19ea342011-04-20 20:31:132226 // A content initiated navigation may have originated from a link-click,
2227 // script, drag-n-drop operation, etc.
2228 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072229 DocumentState::FromDataSource(frame->provisionalDataSource())->
2230 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132231
[email protected]a8c269a2011-10-25 20:17:222232 // Experimental:
2233 // If --enable-strict-site-isolation is enabled, send all top-level
2234 // navigations to the browser to let it swap processes when crossing site
2235 // boundaries. This is currently expected to break some script calls and
2236 // navigations, such as form submissions.
2237 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102238 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2239 !frame->parent() && (is_content_initiated || is_redirect)) {
2240 WebString origin_str = frame->document().securityOrigin().toString();
2241 GURL frame_url(origin_str.utf8().data());
2242 // TODO(cevans): revisit whether this origin check is still necessary once
2243 // crbug.com/101395 is fixed.
2244 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]445e1042011-12-03 21:03:152245 Referrer referrer(
2246 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402247 GetReferrerPolicyFromRequest(request));
[email protected]313b80bd2011-11-23 03:49:102248 OpenURL(frame, url, referrer, default_policy);
2249 return WebKit::WebNavigationPolicyIgnore;
2250 }
[email protected]a8c269a2011-10-25 20:17:222251 }
2252
[email protected]3d9689372009-09-10 04:29:172253 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302254 // navigations.
[email protected]5f000f272012-01-19 05:25:082255 if (is_content_initiated) {
2256 bool browser_handles_top_level_requests =
2257 renderer_preferences_.browser_handles_top_level_requests &&
2258 IsNonLocalTopLevelNavigation(url, frame, type);
2259 if (browser_handles_top_level_requests ||
2260 renderer_preferences_.browser_handles_all_requests) {
2261 Referrer referrer(
2262 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402263 GetReferrerPolicyFromRequest(request));
[email protected]5f000f272012-01-19 05:25:082264 // Reset these counters as the RenderView could be reused for the next
2265 // navigation.
2266 page_id_ = -1;
2267 last_page_id_sent_to_browser_ = -1;
2268 OpenURL(frame, url, referrer, default_policy);
2269 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2270 }
[email protected]3d9689372009-09-10 04:29:172271 }
2272
[email protected]6101c342010-12-16 22:44:372273 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552274 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572275 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372276 // opening a new window). But we sometimes navigate to about:blank to clear a
2277 // tab, and we want to still allow that.
2278 //
[email protected]8f4da8c2011-02-09 19:49:572279 // Note: we do this only for GET requests because our mechanism for switching
2280 // processes only issues GET requests. In particular, POST requests don't
2281 // work, because this mechanism does not preserve form POST data. If it
2282 // becomes necessary to support process switching for POST requests, we will
2283 // need to send the request's httpBody data up to the browser process, and
2284 // issue a special POST navigation in WebKit (via
2285 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2286 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222287 if (!frame->parent() && is_content_initiated &&
[email protected]6101c342010-12-16 22:44:372288 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2289 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2290 bool send_referrer = false;
2291 bool should_fork =
[email protected]e091df82011-10-11 18:13:212292 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172293 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372294 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112295
[email protected]e48869a2011-04-01 19:56:032296 if (!should_fork) {
2297 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362298 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032299 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]3f105a2f2012-02-25 18:27:362300 frame, url, is_initial_navigation, &send_referrer);
[email protected]6101c342010-12-16 22:44:372301 }
2302
2303 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152304 Referrer referrer(
2305 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
[email protected]b9fd01ba2012-02-28 01:50:402306 GetReferrerPolicyFromRequest(request));
[email protected]445e1042011-12-03 21:03:152307 OpenURL(
2308 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112309 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2310 }
[email protected]3d9689372009-09-10 04:29:172311 }
2312
[email protected]43763f982011-08-26 18:33:402313 // Use the frame's original request's URL rather than the document's URL for
2314 // this check. For a popup, the document's URL may become the opener window's
2315 // URL if the opener has called document.write. See http://crbug.com/93517.
2316 GURL old_url(frame->dataSource()->request().url());
2317
[email protected]3d9689372009-09-10 04:29:172318 // Detect when a page is "forking" a new tab that can be safely rendered in
2319 // its own process. This is done by sites like Gmail that try to open links
2320 // in new windows without script connections back to the original page. We
2321 // treat such cases as browser navigations (in which we will create a new
2322 // renderer for a cross-site navigation), rather than WebKit navigations.
2323 //
2324 // We use the following heuristic to decide whether to fork a new page in its
2325 // own process:
2326 // The parent page must open a new tab to about:blank, set the new tab's
2327 // window.opener to null, and then redirect the tab to a cross-site URL using
2328 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462329 //
2330 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2331 // (see below).
[email protected]3d9689372009-09-10 04:29:172332 bool is_fork =
2333 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582334 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172335 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522336 historyBackListCount() < 1 &&
2337 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172338 // The parent page must have set the child's window.opener to null before
2339 // redirecting to the desired URL.
2340 frame->opener() == NULL &&
2341 // Must be a top-level frame.
2342 frame->parent() == NULL &&
2343 // Must not have issued the request from this page.
2344 is_content_initiated &&
2345 // Must be targeted at the current tab.
2346 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2347 // Must be a JavaScript navigation, which appears as "other".
2348 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462349
[email protected]f92ce2b2012-03-06 18:02:592350 if (is_fork) {
[email protected]3d9689372009-09-10 04:29:172351 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152352 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172353 return WebKit::WebNavigationPolicyIgnore;
2354 }
2355
2356 return default_policy;
2357}
2358
[email protected]310ebd6302011-10-10 19:06:282359bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492360 WebFrame* frame, const WebURLRequest& request) {
2361 // We allow WebKit to think that everything can be handled even though
2362 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342363 return true;
2364}
2365
[email protected]310ebd6302011-10-10 19:06:282366WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492367 WebFrame* frame, const WebURLRequest& request) {
2368 NOTREACHED(); // Since we said we can handle all requests.
2369 return WebURLError();
2370}
2371
[email protected]310ebd6302011-10-10 19:06:282372WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492373 WebFrame* frame, const WebURLRequest& request) {
2374 WebURLError error;
2375 error.domain = WebString::fromUTF8(net::kErrorDomain);
2376 error.reason = net::ERR_ABORTED;
2377 error.unreachableURL = request.url();
2378 return error;
[email protected]7b7a7dc2009-10-19 02:23:342379}
2380
[email protected]310ebd6302011-10-10 19:06:282381void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492382 WebFrame*, const WebURLError&) {
2383 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342384}
2385
[email protected]310ebd6302011-10-10 19:06:282386void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432387 const WebKit::WebFormElement& form) {
2388 // Some login forms have onSubmit handlers that put a hash of the password
2389 // into a hidden field and then clear the password. (Issue 28910.)
2390 // This method gets called before any of those handlers run, so save away
2391 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072392 DocumentState* document_state =
2393 DocumentState::FromDataSource(frame->dataSource());
2394 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432395 PasswordFormDomManager::CreatePasswordForm(form));
2396}
2397
[email protected]310ebd6302011-10-10 19:06:282398void RenderViewImpl::willSubmitForm(WebFrame* frame,
2399 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072400 DocumentState* document_state =
2401 DocumentState::FromDataSource(frame->provisionalDataSource());
2402 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172403
[email protected]2905f742011-10-13 03:51:582404 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2405 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172406
2407 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352408 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072409 document_state->set_searchable_form_url(web_searchable_form_data.url());
2410 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212411 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432412 PasswordForm* password_form_data =
2413 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072414 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432415
[email protected]098c95cb2011-04-28 16:49:012416 // In order to save the password that the user actually typed and not one
2417 // that may have gotten transformed by the site prior to submit, recover it
2418 // from the form contents already stored by |willSendSubmitEvent| into the
2419 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2420 // which is what we're storing into now.)
2421 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072422 DocumentState* old_document_state =
2423 DocumentState::FromDataSource(frame->dataSource());
2424 if (old_document_state) {
2425 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432426 if (old_form_data && old_form_data->action == password_form_data->action)
2427 password_form_data->password_value = old_form_data->password_value;
2428 }
2429 }
[email protected]3d9689372009-09-10 04:29:172430
[email protected]2a5b1732011-04-01 23:55:552431 FOR_EACH_OBSERVER(
2432 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172433}
2434
[email protected]310ebd6302011-10-10 19:06:282435void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172436 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2437 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382438 FOR_EACH_OBSERVER(
2439 RenderViewObserver, observers_,
2440 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172441}
2442
[email protected]310ebd6302011-10-10 19:06:282443void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382444 FOR_EACH_OBSERVER(
2445 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172446}
2447
[email protected]310ebd6302011-10-10 19:06:282448void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172449 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152450 if (!frame->parent()) {
2451 WebDataSource* ds = frame->provisionalDataSource();
2452 // If there's no provisional data source, it's a reference fragment
2453 // navigation.
2454 completed_client_redirect_src_ = Referrer(
[email protected]b9fd01ba2012-02-28 01:50:402455 from, ds ? GetReferrerPolicyFromRequest(ds->request()) :
[email protected]445e1042011-12-03 21:03:152456 frame->referrerPolicy());
2457 }
[email protected]eb0bff942011-04-07 22:08:382458 FOR_EACH_OBSERVER(
2459 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172460}
2461
[email protected]310ebd6302011-10-10 19:06:282462void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072463 DocumentState* document_state = DocumentState::FromDataSource(ds);
2464 if (!document_state) {
2465 document_state = new DocumentState;
2466 ds->setExtraData(document_state);
2467 }
2468
[email protected]3d9689372009-09-10 04:29:172469 // The rest of RenderView assumes that a WebDataSource will always have a
2470 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072471 bool content_initiated = !pending_navigation_params_.get();
2472 if (content_initiated)
2473 document_state->set_navigation_state(
2474 NavigationState::CreateContentInitiated());
2475 else
2476 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512477
[email protected]007733c2011-11-17 00:34:072478 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512479 // navigating from a page that used prefetching using a link on that
2480 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072481 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512482 // this value appropriately.
2483 // TODO(gavinp): catch the important case of navigation in a new
2484 // renderer process.
2485 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302486 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522487 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512488 const GURL referrer(
2489 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2490 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072491 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512492 old_frame->dataSource())->was_prefetcher()) {
2493 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2494 WebDataSource* old_frame_ds = old_frame->dataSource();
2495 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072496 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512497 break;
2498 }
2499 }
2500 }
2501 }
2502 }
2503
[email protected]4c1b6f0b2010-02-07 16:38:182504 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522505 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512506 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182507 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072508 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182509 break;
2510 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072511 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182512 break;
2513 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072514 document_state->set_load_type(
2515 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182516 break;
2517 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072518 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182519 break;
2520 }
2521 }
[email protected]fa7b6b542009-11-03 05:02:302522
[email protected]946a0032011-03-31 18:42:282523 FOR_EACH_OBSERVER(
2524 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172525}
2526
[email protected]007733c2011-11-17 00:34:072527void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2528 DocumentState* document_state) {
2529 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2530
2531 if (document_state->request_time().is_null())
2532 document_state->set_request_time(params.request_time);
2533
2534 // A navigation resulting from loading a javascript URL should not be treated
2535 // as a browser initiated event. Instead, we want it to look as if the page
2536 // initiated any load resulting from JS execution.
2537 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2538 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2539 params.page_id,
2540 params.pending_history_list_offset,
2541 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482542 navigation_state->set_transferred_request_child_id(
2543 params.transferred_request_child_id);
2544 navigation_state->set_transferred_request_request_id(
2545 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072546 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2547 // We're doing a load of a page that was restored from the last session.
2548 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2549 // which can result in stale data for pages that are set to expire. We
2550 // explicitly override that by setting the policy here so that as
2551 // necessary we load from the network.
2552 document_state->set_cache_policy_override(
2553 WebURLRequest::UseProtocolCachePolicy);
2554 }
2555 document_state->set_navigation_state(navigation_state);
2556 } else {
2557 document_state->set_navigation_state(
2558 NavigationState::CreateContentInitiated());
2559 }
2560
2561 if (IsReload(params))
2562 document_state->set_load_type(DocumentState::RELOAD);
2563 else if (!params.state.empty())
2564 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2565 else
2566 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2567
2568 pending_navigation_params_.reset();
2569}
2570
[email protected]310ebd6302011-10-10 19:06:282571void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172572 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072573 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172574
[email protected]3d9689372009-09-10 04:29:172575 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072576 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172577 double event_time = ds->triggeringEventTime();
2578 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072579 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172580 }
2581
[email protected]05c8e502010-08-15 15:13:522582 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072583 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522584
[email protected]3d9689372009-09-10 04:29:172585 bool is_top_most = !frame->parent();
2586 if (is_top_most) {
2587 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132588 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172589
2590 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152591 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172592 } else if (frame->parent()->isLoading()) {
2593 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002594 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072595 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582596 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172597 }
2598
[email protected]28685da92011-02-07 21:49:172599 FOR_EACH_OBSERVER(
2600 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2601
[email protected]3d9689372009-09-10 04:29:172602 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592603 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262604 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172605}
2606
[email protected]310ebd6302011-10-10 19:06:282607void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2608 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172609 if (frame->parent())
2610 return;
2611 // Received a redirect on the main frame.
2612 WebDataSource* data_source = frame->provisionalDataSource();
2613 if (!data_source) {
2614 // Should only be invoked when we have a data source.
2615 NOTREACHED();
2616 return;
2617 }
2618 std::vector<GURL> redirects;
2619 GetRedirectChain(data_source, &redirects);
2620 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512621 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592622 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172623 }
2624}
2625
[email protected]310ebd6302011-10-10 19:06:282626void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2627 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172628 // Notify the browser that we failed a provisional load with an error.
2629 //
2630 // Note: It is important this notification occur before DidStopLoading so the
2631 // SSL manager can react to the provisional load failure before being
2632 // notified the load stopped.
2633 //
2634 WebDataSource* ds = frame->provisionalDataSource();
2635 DCHECK(ds);
2636
2637 const WebURLRequest& failed_request = ds->request();
2638
[email protected]28685da92011-02-07 21:49:172639 FOR_EACH_OBSERVER(
2640 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2641
[email protected]3d9689372009-09-10 04:29:172642 bool show_repost_interstitial =
2643 (error.reason == net::ERR_CACHE_MISS &&
2644 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582645
2646 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2647 params.frame_id = frame->identifier();
2648 params.is_main_frame = !frame->parent();
2649 params.error_code = error.reason;
2650 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2651 failed_request,
2652 error,
2653 NULL,
2654 &params.error_description);
2655 params.url = error.unreachableURL;
2656 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172657 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582658 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172659
2660 // Don't display an error page if this is simply a cancelled load. Aside
2661 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2662 if (error.reason == net::ERR_ABORTED)
2663 return;
[email protected]b553edd52012-01-10 12:15:232664 // Don't display an error message if the request was handled by an
2665 // external protocol handler.
2666 if (error.reason == net::ERR_UNKNOWN_URL_SCHEME)
2667 return;
[email protected]3d9689372009-09-10 04:29:172668
2669 // Make sure we never show errors in view source mode.
2670 frame->enableViewSourceMode(false);
2671
[email protected]007733c2011-11-17 00:34:072672 DocumentState* document_state = DocumentState::FromDataSource(ds);
2673 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172674
2675 // If this is a failed back/forward/reload navigation, then we need to do a
2676 // 'replace' load. This is necessary to avoid messing up session history.
2677 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2678 // as session history is concerned.
2679 //
2680 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2681 // the page id.
2682 //
2683 bool replace =
2684 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582685 navigation_state->transition_type() ==
2686 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172687
2688 // If we failed on a browser initiated request, then make sure that our error
2689 // page load is regarded as the same browser initiated request.
2690 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072691 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2692 pending_navigation_params_->page_id =
2693 navigation_state->pending_page_id();
2694 pending_navigation_params_->pending_history_list_offset =
2695 navigation_state->pending_history_list_offset();
2696 pending_navigation_params_->transition =
2697 navigation_state->transition_type();
2698 pending_navigation_params_->request_time =
2699 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172700 }
2701
2702 // Provide the user with a more helpful error page?
2703 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2704 return;
2705
2706 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082707 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172708}
2709
[email protected]310ebd6302011-10-10 19:06:282710void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172711 WebFrame* frame, const char* data, size_t data_len,
2712 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072713 DocumentState* document_state =
2714 DocumentState::FromDataSource(frame->dataSource());
2715 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172716}
2717
[email protected]310ebd6302011-10-10 19:06:282718void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2719 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072720 DocumentState* document_state =
2721 DocumentState::FromDataSource(frame->dataSource());
2722 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172723
[email protected]007733c2011-11-17 00:34:072724 if (document_state->commit_load_time().is_null())
2725 document_state->set_commit_load_time(Time::Now());
2726
[email protected]3d9689372009-09-10 04:29:172727 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202728 // When we perform a new navigation, we need to update the last committed
2729 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172730 UpdateSessionHistory(frame);
2731
2732 // We bump our Page ID to correspond with the new session history entry.
2733 page_id_ = next_page_id_++;
2734
[email protected]69ddf852012-02-21 23:21:312735 // Don't update history_page_ids_ (etc) for about:swappedout, since we
2736 // don't want to forget the entry that was there, and since we will
2737 // never come back to about:swappedout. Note that we have to call
2738 // UpdateSessionHistory and update page_id_ even in this case, so that
2739 // the current entry gets a state update and so that we don't send a
2740 // state update to the wrong entry when we swap back in.
2741 if (GetLoadingUrl(frame) != GURL("about:swappedout")) {
2742 // Advance our offset in session history, applying the length limit.
2743 // There is now no forward history.
2744 history_list_offset_++;
2745 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2746 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
2747 history_list_length_ = history_list_offset_ + 1;
2748 history_page_ids_.resize(history_list_length_, -1);
2749 history_page_ids_[history_list_offset_] = page_id_;
2750 }
[email protected]3d9689372009-09-10 04:29:172751 } else {
2752 // Inspect the navigation_state on this frame to see if the navigation
2753 // corresponds to a session history navigation... Note: |frame| may or
2754 // may not be the toplevel frame, but for the case of capturing session
2755 // history, the first committed frame suffices. We keep track of whether
2756 // we've seen this commit before so that only capture session history once
2757 // per navigation.
2758 //
2759 // Note that we need to check if the page ID changed. In the case of a
2760 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2761 // previous URL and the current page ID, which would be wrong.
2762 if (navigation_state->pending_page_id() != -1 &&
2763 navigation_state->pending_page_id() != page_id_ &&
2764 !navigation_state->request_committed()) {
2765 // This is a successful session history navigation!
2766 UpdateSessionHistory(frame);
2767 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002768
2769 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032770
2771 // If the history list is valid, our list of page IDs should be correct.
2772 DCHECK(history_list_length_ <= 0 ||
2773 history_list_offset_ < 0 ||
2774 history_list_offset_ >= history_list_length_ ||
2775 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172776 }
2777 }
2778
[email protected]28685da92011-02-07 21:49:172779 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2780 DidCommitProvisionalLoad(frame, is_new_navigation));
2781
[email protected]3d9689372009-09-10 04:29:172782 // Remember that we've already processed this request, so we don't update
2783 // the session history again. We do this regardless of whether this is
2784 // a session history navigation, because if we attempted a session history
2785 // navigation without valid HistoryItem state, WebCore will think it is a
2786 // new navigation.
2787 navigation_state->set_request_committed(true);
2788
2789 UpdateURL(frame);
2790
2791 // If this committed load was initiated by a client redirect, we're
2792 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152793 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172794
2795 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272796 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172797}
2798
[email protected]310ebd6302011-10-10 19:06:282799void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102800 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2801 DidClearWindowObject(frame));
2802
[email protected]b6cb3a842011-06-24 18:28:412803 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212804 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252805 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2806 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272807 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172808 }
[email protected]766a7082012-02-03 23:39:152809
2810 if (enabled_bindings_ & content::BINDINGS_POLICY_DOM_AUTOMATION) {
2811 if (!dom_automation_controller_.get())
2812 dom_automation_controller_.reset(new DomAutomationController());
2813 dom_automation_controller_->set_message_sender(
2814 static_cast<content::RenderView*>(this));
2815 dom_automation_controller_->set_routing_id(routing_id());
2816 dom_automation_controller_->BindToJavascript(frame,
2817 "domAutomationController");
2818 }
[email protected]3d9689372009-09-10 04:29:172819}
2820
[email protected]310ebd6302011-10-10 19:06:282821void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172822 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412823 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252824 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272825 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172826 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2827 }
[email protected]e48869a2011-04-01 19:56:032828
2829 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2830 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172831}
2832
[email protected]310ebd6302011-10-10 19:06:282833void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2834 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462835 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172836
2837 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272838 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172839}
2840
[email protected]310ebd6302011-10-10 19:06:282841void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132842 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2843 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582844}
2845
[email protected]310ebd6302011-10-10 19:06:282846void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172847 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072848 DocumentState* document_state = DocumentState::FromDataSource(ds);
2849 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172850
[email protected]622474d2010-11-04 09:21:082851 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172852
[email protected]28685da92011-02-07 21:49:172853 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2854 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172855
2856 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272857 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172858}
2859
[email protected]310ebd6302011-10-10 19:06:282860void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082861 if (webview()->mainFrame() == frame) {
2862 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2863 page_id_));
2864 }
[email protected]3d9689372009-09-10 04:29:172865}
2866
[email protected]310ebd6302011-10-10 19:06:282867void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312868 WebDataSource* ds = frame->dataSource();
2869 DCHECK(ds);
2870
2871
[email protected]28685da92011-02-07 21:49:172872 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312873
2874 const WebURLRequest& failed_request = ds->request();
2875 string16 error_description;
2876 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2877 failed_request,
2878 error,
2879 NULL,
2880 &error_description);
2881 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2882 frame->identifier(),
2883 failed_request.url(),
2884 !frame->parent(),
2885 error.reason,
2886 error_description));
[email protected]3d9689372009-09-10 04:29:172887}
2888
[email protected]310ebd6302011-10-10 19:06:282889void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172890 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072891 DocumentState* document_state = DocumentState::FromDataSource(ds);
2892 if (document_state->finish_load_time().is_null())
2893 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412894
[email protected]676126f72011-01-15 00:03:512895 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172896
[email protected]1a55c5be2011-11-29 11:36:312897 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2898 frame->identifier(),
2899 ds->request().url(),
2900 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172901}
2902
[email protected]310ebd6302011-10-10 19:06:282903void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172904 WebFrame* frame, bool is_new_navigation) {
2905 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072906 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172907 // update the ExtraData on the datasource so that others who read the
2908 // ExtraData will get the new NavigationState. Similarly, if we did not
2909 // initiate this navigation, then we need to take care to reset any pre-
2910 // existing navigation state to a content-initiated navigation state.
2911 // DidCreateDataSource conveniently takes care of this for us.
2912 didCreateDataSource(frame, frame->dataSource());
2913
[email protected]007733c2011-11-17 00:34:072914 DocumentState* document_state =
2915 DocumentState::FromDataSource(frame->dataSource());
2916 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092917 new_state->set_was_within_same_page(true);
2918
[email protected]3d9689372009-09-10 04:29:172919 didCommitProvisionalLoad(frame, is_new_navigation);
2920
[email protected]750fcf872011-08-03 23:10:472921 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2922 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172923}
2924
[email protected]310ebd6302011-10-10 19:06:282925void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312926 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592927}
2928
[email protected]310ebd6302011-10-10 19:06:282929void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172930 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2931 // Ignore
2932}
2933
[email protected]310ebd6302011-10-10 19:06:282934void RenderViewImpl::willSendRequest(WebFrame* frame,
2935 unsigned identifier,
2936 WebURLRequest& request,
2937 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302938 WebFrame* top_frame = frame->top();
2939 if (!top_frame)
2940 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512941 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2942 WebDataSource* top_data_source = top_frame->dataSource();
2943 WebDataSource* data_source =
2944 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222945
[email protected]78d5cfe2011-02-04 08:43:222946 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032947 GURL new_url;
2948 if (content::GetContentClient()->renderer()->WillSendRequest(
2949 frame, request_url, &new_url)) {
2950 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222951 }
2952
[email protected]2905f742011-10-13 03:51:582953 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072954 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2955 NavigationState* navigation_state = document_state->navigation_state();
2956 if (document_state) {
2957 if (document_state->is_cache_policy_override_set())
2958 request.setCachePolicy(document_state->cache_policy_override());
2959 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:302960 }
[email protected]8a3125a712010-08-09 18:58:512961
[email protected]91043a8232011-11-04 16:41:192962 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:062963 new RequestExtraData(frame->referrerPolicy(),
2964 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:192965 frame->identifier(),
2966 frame->parent() == top_frame,
2967 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:482968 transition_type,
2969 navigation_state->transferred_request_child_id(),
2970 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:572971
[email protected]007733c2011-11-17 00:34:072972 DocumentState* top_document_state =
2973 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:572974 // TODO(gavinp): separate out prefetching and prerender field trials
2975 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:072976 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:572977 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2978 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:072979 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512980
[email protected]3d9689372009-09-10 04:29:172981 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132982 request.setHasUserGesture(frame->isProcessingUserGesture());
2983
[email protected]0a8db0d2011-04-13 15:15:402984 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132985 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172986}
2987
[email protected]310ebd6302011-10-10 19:06:282988void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:172989 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492990
[email protected]3d9689372009-09-10 04:29:172991 // Only do this for responses that correspond to a provisional data source
2992 // of the top-most frame. If we have a provisional data source, then we
2993 // can't have any sub-resources yet, so we know that this response must
2994 // correspond to a frame load.
2995 if (!frame->provisionalDataSource() || frame->parent())
2996 return;
2997
2998 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082999 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173000 if (frame->isViewSourceModeEnabled())
3001 return;
3002
[email protected]007733c2011-11-17 00:34:073003 DocumentState* document_state =
3004 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:083005 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533006
[email protected]972ebdff2010-06-10 22:59:073007 // Record page load flags.
[email protected]007733c2011-11-17 00:34:073008 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3009 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]b9fd01ba2012-02-28 01:50:403010 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(response);
3011 if (extra_data) {
3012 document_state->set_npn_negotiated_protocol(
3013 extra_data->npn_negotiated_protocol());
3014 }
[email protected]007733c2011-11-17 00:34:073015 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:573016 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:073017 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3018 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:093019 // Whether or not the http status code actually corresponds to an error is
3020 // only checked when the page is done loading, if |use_error_page| is
3021 // still true.
[email protected]007733c2011-11-17 00:34:073022 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:173023}
3024
[email protected]310ebd6302011-10-10 19:06:283025void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:173026 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:073027 DocumentState* document_state =
3028 DocumentState::FromDataSource(frame->dataSource());
3029 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:173030 return;
3031
[email protected]7bfc153f2011-09-23 22:00:203032 // Do not show error page when DevTools is attached.
3033 if (devtools_agent_->IsAttached())
3034 return;
3035
[email protected]06333afe2011-02-24 14:55:093036 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:073037 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:083038 if (http_status_code == 404) {
3039 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:413040 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:173041
[email protected]b6cb3a842011-06-24 18:28:413042 const GURL& error_page_url =
3043 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:093044 if (error_page_url.is_valid()) {
3045 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:473046 original_error.domain = "http";
3047 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:413048 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:173049
[email protected]007733c2011-11-17 00:34:073050 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:093051 new AltErrorPageResourceFetcher(
3052 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:083053 base::Bind(&RenderViewImpl::AltErrorPageFinished,
3054 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:093055 return;
3056 }
3057 }
[email protected]3d9689372009-09-10 04:29:173058
[email protected]e6a2ce52011-10-08 01:40:133059 std::string error_domain;
3060 if (content::GetContentClient()->renderer()->HasErrorPage(
3061 http_status_code, &error_domain)) {
3062 WebURLError error;
3063 error.unreachableURL = frame->document().url();
3064 error.domain = WebString::fromUTF8(error_domain);
3065 error.reason = http_status_code;
3066
3067 LoadNavigationErrorPage(
3068 frame, frame->dataSource()->request(), error, std::string(), true);
3069 }
[email protected]3d9689372009-09-10 04:29:173070}
3071
[email protected]310ebd6302011-10-10 19:06:283072void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:173073 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3074 // Ignore
3075}
3076
[email protected]310ebd6302011-10-10 19:06:283077void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:173078 WebFrame* frame, const WebURLRequest& request,
3079 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:003080 // The recipients of this message have no use for data: URLs: they don't
3081 // affect the page's insecure content list and are not in the disk cache. To
3082 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
3083 // filter them out here.
3084 GURL url(request.url());
3085 if (url.SchemeIs("data"))
3086 return;
3087
[email protected]3d9689372009-09-10 04:29:173088 // Let the browser know we loaded a resource from the memory cache. This
3089 // message is needed to display the correct SSL indicators.
3090 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3091 routing_id_,
[email protected]84703292011-10-28 20:44:003092 url,
[email protected]70435962011-08-02 20:13:283093 response.securityInfo(),
3094 request.httpMethod().utf8(),
3095 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:173096}
3097
[email protected]310ebd6302011-10-10 19:06:283098void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293099 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3100}
3101
[email protected]310ebd6302011-10-10 19:06:283102void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:023103 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293104 Send(new ViewHostMsg_DidRunInsecureContent(
3105 routing_id_,
[email protected]92771112011-01-20 00:13:023106 origin.toString().utf8(),
3107 target));
[email protected]e3d60e5d2009-09-25 21:08:293108}
3109
[email protected]310ebd6302011-10-10 19:06:283110void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:033111 webkit_glue::WebURLLoaderImpl* loader_impl =
3112 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
3113 loader_impl->UpdateRoutingId(routing_id_);
3114}
3115
[email protected]310ebd6302011-10-10 19:06:283116void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:173117 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3118}
3119
[email protected]310ebd6302011-10-10 19:06:283120void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3121 v8::Handle<v8::Context> context,
[email protected]a00fe692012-02-27 05:52:583122 int extension_group,
[email protected]310ebd6302011-10-10 19:06:283123 int world_id) {
[email protected]5bc10932011-09-21 21:03:303124 content::GetContentClient()->renderer()->DidCreateScriptContext(
[email protected]a00fe692012-02-27 05:52:583125 frame, context, extension_group, world_id);
3126}
3127
3128void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
3129 v8::Handle<v8::Context> context,
3130 int world_id) {
3131 content::GetContentClient()->renderer()->DidCreateScriptContext(
3132 frame, context, -1, world_id);
[email protected]0c882b282009-10-07 17:01:283133}
3134
[email protected]310ebd6302011-10-10 19:06:283135void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
3136 v8::Handle<v8::Context> context,
3137 int world_id) {
[email protected]5bc10932011-09-21 21:03:303138 content::GetContentClient()->renderer()->WillReleaseScriptContext(
3139 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:283140}
3141
[email protected]310ebd6302011-10-10 19:06:283142void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:073143 // We don't always want to send the change messages over IPC, only if we've
3144 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
3145 // message.
3146 if (!send_preferred_size_changes_ || !webview())
3147 return;
3148
[email protected]705243f2010-05-05 19:58:073149 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3150 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533151
3152 // In the presence of zoom, these sizes are still reported as if unzoomed,
3153 // so we need to adjust.
3154 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3155 size.set_width(static_cast<int>(size.width() * zoom_factor));
3156 size.set_height(static_cast<int>(size.height() * zoom_factor));
3157
[email protected]705243f2010-05-05 19:58:073158 if (size == preferred_size_)
3159 return;
[email protected]c27324b2009-11-19 22:44:293160
[email protected]705243f2010-05-05 19:58:073161 preferred_size_ = size;
3162 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3163 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173164}
3165
[email protected]273558fb2012-01-12 15:03:513166void RenderViewImpl::EnsureMediaStreamImpl() {
3167#if defined(ENABLE_P2P_APIS)
3168 if (!p2p_socket_dispatcher_)
3169 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
3170#endif
3171
[email protected]5b87e782012-02-09 18:19:323172#if defined(ENABLE_WEBRTC)
[email protected]273558fb2012-01-12 15:03:513173 if (!media_stream_dispatcher_)
3174 media_stream_dispatcher_ = new MediaStreamDispatcher(this);
3175
3176 if (!media_stream_impl_.get()) {
3177 MediaStreamDependencyFactory* factory = new MediaStreamDependencyFactory();
3178 media_stream_impl_ = new MediaStreamImpl(
3179 media_stream_dispatcher_,
3180 p2p_socket_dispatcher_,
3181 RenderThreadImpl::current()->video_capture_impl_manager(),
3182 factory);
3183 }
[email protected]5b87e782012-02-09 18:19:323184#endif
[email protected]273558fb2012-01-12 15:03:513185}
3186
[email protected]310ebd6302011-10-10 19:06:283187void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
3188 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:313189 if (webview()->mainFrame() != frame)
3190 return;
3191 WebView* frameView = frame->view();
3192 if (!frameView)
3193 return;
3194
3195 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
3196 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
3197
3198 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
3199 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
3200 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
3201 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
3202
3203 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
3204 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
3205 }
3206}
3207
[email protected]310ebd6302011-10-10 19:06:283208void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:313209 WebSize offset = frame->scrollOffset();
3210 WebSize minimum_offset = frame->minimumScrollOffset();
3211 WebSize maximum_offset = frame->maximumScrollOffset();
3212
3213 bool is_pinned_to_left = offset.width <= minimum_offset.width;
3214 bool is_pinned_to_right = offset.width >= maximum_offset.width;
3215
3216 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
3217 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
3218 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
3219 routing_id_, is_pinned_to_left, is_pinned_to_right));
3220
3221 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3222 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3223 }
3224}
3225
[email protected]310ebd6302011-10-10 19:06:283226void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493227 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313228
3229 if (webview()->mainFrame() == frame)
3230 UpdateScrollState(frame);
3231}
3232
[email protected]310ebd6302011-10-10 19:06:283233void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313234 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493235}
3236
[email protected]ea931252012-02-15 22:01:033237void RenderViewImpl::numberOfTouchEventHandlersChanged(unsigned num_handlers) {
3238 Send(new ViewHostMsg_DidChangeNumTouchEvents(routing_id_, num_handlers));
3239}
3240
[email protected]310ebd6302011-10-10 19:06:283241void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3242 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113243 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3244 if (!count)
3245 active_match_ordinal = 0;
3246
3247 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3248 routing_id_,
3249 request_id,
3250 count,
3251 gfx::Rect(),
3252 active_match_ordinal,
3253 final_update);
3254
[email protected]8922e1f2009-10-03 05:01:263255 // If we have a message that has been queued up, then we should just replace
3256 // it. The ACK from the browser will make sure it gets sent when the browser
3257 // wants it.
3258 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263259 queued_find_reply_message_.reset(msg);
3260 } else {
3261 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113262 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263263 }
3264}
3265
[email protected]310ebd6302011-10-10 19:06:283266void RenderViewImpl::reportFindInPageSelection(int request_id,
3267 int active_match_ordinal,
3268 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263269 // Send the search result over to the browser process.
3270 Send(new ViewHostMsg_Find_Reply(routing_id_,
3271 request_id,
3272 -1,
3273 selection_rect,
3274 active_match_ordinal,
3275 false));
3276}
3277
[email protected]310ebd6302011-10-10 19:06:283278void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223279 WebFrame* frame,
3280 WebFileSystem::Type type,
3281 long long size,
[email protected]d275d7a2010-11-03 01:34:493282 bool create,
[email protected]2b06a992010-08-21 05:48:223283 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083284 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223285
[email protected]b6cb3a842011-06-24 18:28:413286 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563287 if (origin.isUnique()) {
3288 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083289 callbacks->didFail(WebKit::WebFileErrorAbort);
3290 return;
3291 }
[email protected]2b06a992010-08-21 05:48:223292
[email protected]c5a272d2010-09-27 18:37:083293 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3294 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493295 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223296}
3297
[email protected]310ebd6302011-10-10 19:06:283298void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403299 WebFrame* frame,
3300 WebStorageQuotaType type,
3301 WebStorageQuotaCallbacks* callbacks) {
3302 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413303 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563304 if (origin.isUnique()) {
3305 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403306 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3307 return;
3308 }
3309 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533310 GURL(origin.toString()),
3311 static_cast<quota::StorageType>(type),
3312 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403313}
3314
[email protected]310ebd6302011-10-10 19:06:283315void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403316 WebFrame* frame,
3317 WebStorageQuotaType type,
3318 unsigned long long requested_size,
3319 WebStorageQuotaCallbacks* callbacks) {
3320 DCHECK(frame);
[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]10e5cf12011-04-13 04:10:403324 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3325 return;
3326 }
3327 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533328 routing_id(), GURL(origin.toString()),
3329 static_cast<quota::StorageType>(type), requested_size,
3330 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403331}
3332
[email protected]8b5af492011-11-28 21:50:583333void RenderViewImpl::registerIntentService(
[email protected]ffc8bed2012-01-21 01:23:153334 WebFrame* frame, const WebIntentServiceInfo& service) {
[email protected]e6e35cd2011-12-22 19:37:063335 string16 title = service.title();
3336 if (title.empty())
3337 title = webview()->mainFrame()->document().title();
3338
[email protected]8b5af492011-11-28 21:50:583339 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3340 service.action(),
3341 service.type(),
3342 service.url().spec().utf16(),
[email protected]e6e35cd2011-12-22 19:37:063343 title,
[email protected]8b5af492011-11-28 21:50:583344 service.disposition()));
3345}
3346
[email protected]ffc8bed2012-01-21 01:23:153347void RenderViewImpl::dispatchIntent(
3348 WebFrame* frame, const WebIntentRequest& intentRequest) {
3349 webkit_glue::WebIntentData intent_data(intentRequest.intent());
3350 int id = intents_host_->RegisterWebIntent(intentRequest);
[email protected]8b5af492011-11-28 21:50:583351 Send(new IntentsHostMsg_WebIntentDispatch(
[email protected]ffc8bed2012-01-21 01:23:153352 routing_id_, intent_data, id));
[email protected]8b5af492011-11-28 21:50:583353}
3354
[email protected]18d5be92011-07-25 18:00:193355// WebKit::WebPageSerializerClient implementation ------------------------------
3356
[email protected]310ebd6302011-10-10 19:06:283357void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193358 const WebURL& frame_url,
3359 const WebCString& data,
3360 WebPageSerializerClient::PageSerializationStatus status) {
3361 Send(new ViewHostMsg_SendSerializedHtmlData(
3362 routing_id(),
3363 frame_url,
3364 data.data(),
3365 static_cast<int32>(status)));
3366}
3367
[email protected]a2ef54c2011-10-10 16:20:313368// content::RenderView implementation ------------------------------------------
3369
[email protected]310ebd6302011-10-10 19:06:283370bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313371 return RenderWidget::Send(message);
3372}
3373
[email protected]9f76c1e2012-03-05 15:15:583374int RenderViewImpl::GetRoutingID() const {
[email protected]a2ef54c2011-10-10 16:20:313375 return routing_id_;
3376}
3377
[email protected]310ebd6302011-10-10 19:06:283378int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313379 return page_id_;
3380}
3381
[email protected]310ebd6302011-10-10 19:06:283382gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313383 return size();
3384}
3385
[email protected]310ebd6302011-10-10 19:06:283386gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313387 return host_window();
3388}
3389
[email protected]310ebd6302011-10-10 19:06:283390WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313391 return webkit_preferences_;
3392}
3393
[email protected]310ebd6302011-10-10 19:06:283394WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313395 return webview();
3396}
3397
[email protected]310ebd6302011-10-10 19:06:283398WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313399 if (!webview())
3400 return WebNode();
3401 WebFrame* focused_frame = webview()->focusedFrame();
3402 if (focused_frame) {
3403 WebDocument doc = focused_frame->document();
3404 if (!doc.isNull())
3405 return doc.focusedNode();
3406 }
3407
3408 return WebNode();
3409}
3410
[email protected]310ebd6302011-10-10 19:06:283411WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313412 return context_menu_node_;
3413}
3414
[email protected]310ebd6302011-10-10 19:06:283415bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313416 bool is_editable_node = false;
3417 if (!node.isNull()) {
3418 if (node.isContentEditable()) {
3419 is_editable_node = true;
3420 } else if (node.isElementNode()) {
3421 is_editable_node =
3422 node.toConst<WebElement>().isTextFormControlElement();
3423 }
3424 }
3425 return is_editable_node;
3426}
3427
[email protected]310ebd6302011-10-10 19:06:283428WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313429 WebKit::WebFrame* frame,
3430 const webkit::WebPluginInfo& info,
3431 const WebKit::WebPluginParams& params) {
3432 bool pepper_plugin_was_registered = false;
3433 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3434 pepper_delegate_.CreatePepperPluginModule(info,
3435 &pepper_plugin_was_registered));
3436 if (pepper_plugin_was_registered) {
3437 if (!pepper_module)
3438 return NULL;
3439 return new webkit::ppapi::WebPluginImpl(
3440 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3441 }
3442
[email protected]34b27e442012-01-20 20:07:413443#if defined(USE_AURA)
3444 return NULL;
3445#else
[email protected]a2ef54c2011-10-10 16:20:313446 return new webkit::npapi::WebPluginImpl(
3447 frame, params, info.path, AsWeakPtr());
[email protected]34b27e442012-01-20 20:07:413448#endif
[email protected]a2ef54c2011-10-10 16:20:313449}
3450
[email protected]310ebd6302011-10-10 19:06:283451void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3452 const string16& jscript,
3453 int id,
3454 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313455 v8::Handle<v8::Value> result;
3456 WebFrame* web_frame = GetChildFrame(frame_xpath);
3457 if (web_frame)
3458 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3459 if (notify_result) {
3460 ListValue list;
3461 if (!result.IsEmpty() && web_frame) {
3462 v8::HandleScope handle_scope;
3463 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3464 v8::Context::Scope context_scope(context);
3465 V8ValueConverterImpl converter;
3466 converter.set_allow_date(true);
3467 converter.set_allow_regexp(true);
3468 list.Set(0, converter.FromV8Value(result, context));
3469 } else {
3470 list.Set(0, Value::CreateNullValue());
3471 }
3472 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3473 }
3474}
3475
[email protected]310ebd6302011-10-10 19:06:283476bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313477 return (!send_preferred_size_changes_ ||
3478 (disable_scrollbars_size_limit_.width() <= width ||
3479 disable_scrollbars_size_limit_.height() <= height));
3480}
3481
[email protected]310ebd6302011-10-10 19:06:283482int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313483 return enabled_bindings_;
3484}
3485
[email protected]310ebd6302011-10-10 19:06:283486bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313487 return send_content_state_immediately_;
3488}
3489
[email protected]310ebd6302011-10-10 19:06:283490float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313491 return filtered_time_per_frame();
3492}
3493
[email protected]310ebd6302011-10-10 19:06:283494void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3495 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313496 showContextMenu(frame, data);
3497}
3498
[email protected]310ebd6302011-10-10 19:06:283499WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313500 return visibilityState();
3501}
3502
[email protected]310ebd6302011-10-10 19:06:283503void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3504 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313505 return runModalAlertDialog(frame, message);
3506}
3507
[email protected]310ebd6302011-10-10 19:06:283508void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313509 WebKit::WebFrame* frame,
3510 const WebKit::WebURLRequest& request,
3511 WebKit::WebNavigationPolicy policy) {
3512 loadURLExternally(frame, request, policy);
3513}
3514
3515// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513516
[email protected]310ebd6302011-10-10 19:06:283517webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533518 const FilePath& file_path,
3519 const std::string& mime_type) {
[email protected]94752ee2012-02-10 10:38:203520 if (!PluginChannelHost::IsListening()) {
3521 LOG(ERROR) << "PluginChannelHost isn't listening";
[email protected]f103ab72009-09-02 17:10:593522 return NULL;
[email protected]94752ee2012-02-10 10:38:203523 }
[email protected]f103ab72009-09-02 17:10:593524
[email protected]00c39612010-03-06 02:53:283525 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463526 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323527#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223528 return webkit::npapi::WebPluginDelegateImpl::Create(
3529 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093530#else
[email protected]7398dcc2011-09-06 21:40:323531 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223532 NOTIMPLEMENTED();
3533 return NULL;
[email protected]7b6616f2010-01-14 18:07:553534#endif
[email protected]f103ab72009-09-02 17:10:593535 }
3536
[email protected]4e0616e2010-05-28 14:55:533537 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593538}
3539
[email protected]310ebd6302011-10-10 19:06:283540void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033541#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273542 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593543#endif
3544}
3545
[email protected]310ebd6302011-10-10 19:06:283546void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033547#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273548 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593549#endif
3550 CleanupWindowInPluginMoves(window);
3551}
3552
[email protected]310ebd6302011-10-10 19:06:283553void RenderViewImpl::DidMovePlugin(
3554 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593555 SchedulePluginMove(move);
3556}
3557
[email protected]310ebd6302011-10-10 19:06:283558void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593559 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523560 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593561}
3562
[email protected]310ebd6302011-10-10 19:06:283563void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593564 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523565 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593566}
3567
[email protected]310ebd6302011-10-10 19:06:283568WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513569 return &cookie_jar_;
3570}
3571
[email protected]a9288f52011-11-17 05:18:163572void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073573 Send(new ViewHostMsg_MediaNotification(routing_id_,
3574 reinterpret_cast<int64>(player),
3575 player->hasVideo(),
3576 player->hasAudio(),
3577 true));
3578}
3579
[email protected]a9288f52011-11-17 05:18:163580void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073581 Send(new ViewHostMsg_MediaNotification(routing_id_,
3582 reinterpret_cast<int64>(player),
3583 player->hasVideo(),
3584 player->hasAudio(),
3585 false));
3586}
3587
[email protected]a9288f52011-11-17 05:18:163588void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073589 DidPause(player);
3590}
3591
[email protected]310ebd6302011-10-10 19:06:283592void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293593 if (!webview())
3594 return;
3595
[email protected]26aa0482009-09-30 16:55:273596 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173597 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293598 return;
[email protected]ca948a22009-06-25 19:36:173599
3600 Send(new ViewHostMsg_UpdateState(
3601 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293602}
3603
[email protected]310ebd6302011-10-10 19:06:283604void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363605 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003606 if (!frame)
3607 return;
[email protected]b781ff282011-08-20 06:19:363608
[email protected]b781ff282011-08-20 06:19:363609 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003610 if (!webview()->caretOrSelectionRange(&location, &length))
3611 return;
3612
3613 string16 text;
3614 size_t offset;
3615 ui::Range range(location, location + length);
3616
3617 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3618 // If current focused element is editable, we will send 100 more chars
3619 // before and after selection. It is for input method surrounding text
3620 // feature.
3621 if (location > kExtraCharsBeforeAndAfterSelection)
3622 offset = location - kExtraCharsBeforeAndAfterSelection;
3623 else
3624 offset = 0;
3625 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3626 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3627 if (!webrange.isNull())
3628 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3629 } else {
3630 offset = location;
3631 text = frame->selectionAsText();
[email protected]e8cdf3532011-10-29 00:50:523632 // http://crbug.com/101435
3633 // In some case, frame->selectionAsText() returned text's length is not
3634 // equal to the length returned from webview()->caretOrSelectionRange().
3635 // So we have to set the range according to text.length().
3636 range.set_end(range.start() + text.length());
[email protected]b781ff282011-08-20 06:19:363637 }
3638
[email protected]b781ff282011-08-20 06:19:363639 // Sometimes we get repeated didChangeSelection calls from webkit when
3640 // the selection hasn't actually changed. We don't want to report these
3641 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003642 if (selection_text_offset_ != offset ||
3643 selection_range_ != range ||
3644 selection_text_ != text) {
3645 selection_text_ = text;
3646 selection_text_offset_ = offset;
3647 selection_range_ = range;
3648 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3649 }
[email protected]b781ff282011-08-20 06:19:363650}
3651
[email protected]310ebd6302011-10-10 19:06:283652GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3653 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553654 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293655 // If the URL that failed was secure, then the embedding web page was not
3656 // expecting a network attacker to be able to manipulate its contents. As
3657 // we fetch alternate error pages over HTTP, we would be allowing a network
3658 // attacker to manipulate the contents of the response if we tried to use
3659 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153660 return GURL();
initial.commit09911bf2008-07-26 23:55:293661 }
3662
3663 // Grab the base URL from the browser process.
3664 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153665 return GURL();
initial.commit09911bf2008-07-26 23:55:293666
3667 // Strip query params from the failed URL.
3668 GURL::Replacements remove_params;
3669 remove_params.ClearUsername();
3670 remove_params.ClearPassword();
3671 remove_params.ClearQuery();
3672 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553673 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503674 std::string spec_to_send = url_to_send.spec();
3675 // Notify link doctor of the url truncation by sending of "?" at the end.
3676 if (failed_url.has_query())
3677 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293678
3679 // Construct the query params to send to link doctor.
3680 std::string params(alternate_error_page_url_.query());
3681 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023682 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293683 params.append("&sourceid=chrome");
3684 params.append("&error=");
3685 switch (error_type) {
3686 case DNS_ERROR:
3687 params.append("dnserror");
3688 break;
3689
3690 case HTTP_404:
3691 params.append("http404");
3692 break;
3693
[email protected]5df266ac2008-10-15 19:50:133694 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333695 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133696 break;
3697
initial.commit09911bf2008-07-26 23:55:293698 default:
3699 NOTREACHED() << "unknown ErrorPageType";
3700 }
3701
3702 // OK, build the final url to return.
3703 GURL::Replacements link_doctor_params;
3704 link_doctor_params.SetQueryStr(params);
3705 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3706 return url;
3707}
3708
[email protected]310ebd6302011-10-10 19:06:283709GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593710 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3711 return GURL();
3712 else
3713 return creator_url_;
3714}
3715
[email protected]69ddf852012-02-21 23:21:313716GURL RenderViewImpl::GetLoadingUrl(WebKit::WebFrame* frame) const {
3717 WebDataSource* ds = frame->dataSource();
3718 if (ds->hasUnreachableURL())
3719 return ds->unreachableURL();
3720
3721 const WebURLRequest& request = ds->request();
3722 return request.url();
3723}
3724
[email protected]310ebd6302011-10-10 19:06:283725WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273726 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313727 web_ui_bindings_.reset(new WebUIBindings(
3728 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463729 }
[email protected]c50008512011-02-03 01:17:273730 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463731}
3732
[email protected]310ebd6302011-10-10 19:06:283733WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013734 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493735}
3736
[email protected]310ebd6302011-10-10 19:06:283737void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3738 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273739 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493740
[email protected]872542532011-06-23 00:43:163741 // Check if the plugin still exists in the document.
3742 if (main_frame->document().isPluginDocument() &&
3743 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493744 if (options.findNext) {
3745 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013746 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493747 } else {
[email protected]afdbd142010-07-10 08:01:233748 if (GetWebPluginFromPluginDocument()->startFind(
3749 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493750 } else {
[email protected]e7c58a32010-08-13 19:47:113751 // Send "no results".
3752 Send(new ViewHostMsg_Find_Reply(routing_id_,
3753 request_id,
3754 0,
3755 gfx::Rect(),
3756 0,
3757 true));
[email protected]24a7f3c2010-03-25 08:26:493758 }
3759 }
3760 return;
3761 }
3762
[email protected]b4bb2502009-10-01 22:35:273763 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273764 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293765 WebFrame* search_frame = focused_frame; // start searching focused frame.
3766
3767 bool multi_frame = (frame_after_main != main_frame);
3768
3769 // If we have multiple frames, we don't want to wrap the search within the
3770 // frame, so we check here if we only have main_frame in the chain.
3771 bool wrap_within_frame = !multi_frame;
3772
[email protected]b3f2b912009-04-09 16:18:523773 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293774 bool result = false;
3775
[email protected]7830da3e2009-11-06 16:27:263776 // If something is selected when we start searching it means we cannot just
3777 // increment the current match ordinal; we need to re-generate it.
3778 WebRange current_selection = focused_frame->selectionRange();
3779
initial.commit09911bf2008-07-26 23:55:293780 do {
[email protected]dd7daa82009-08-10 05:46:453781 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593782 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293783
3784 if (!result) {
3785 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223786 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293787
3788 // Find the next frame, but skip the invisible ones.
3789 do {
3790 // What is the next frame to search? (we might be going backwards). Note
3791 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593792 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273793 search_frame->traverseNext(true) :
3794 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453795 } while (!search_frame->hasVisibleContent() &&
3796 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293797
[email protected]884db412008-11-24 23:46:503798 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223799 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293800
3801 // If we have multiple frames and we have wrapped back around to the
3802 // focused frame, we need to search it once more allowing wrap within
3803 // the frame, otherwise it will report 'no match' if the focused frame has
3804 // reported matches, but no frames after the focused_frame contain a
3805 // match for the search word(s).
3806 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453807 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593808 request_id, search_text, options, true, // Force wrapping.
3809 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293810 }
3811 }
3812
[email protected]26aa0482009-09-30 16:55:273813 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293814 } while (!result && search_frame != focused_frame);
3815
[email protected]7830da3e2009-11-06 16:27:263816 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293817 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453818 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293819 } else {
3820 // If nothing is found, set result to "0 of 0", otherwise, set it to
3821 // "-1 of 1" to indicate that we found at least one item, but we don't know
3822 // yet what is active.
3823 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3824 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293825
[email protected]4f3dc372009-02-24 00:10:293826 // If we find no matches then this will be our last status update.
3827 // Otherwise the scoping effort will send more results.
3828 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293829
[email protected]4f3dc372009-02-24 00:10:293830 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403831 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593832 request_id,
[email protected]4f3dc372009-02-24 00:10:293833 match_count,
3834 selection_rect,
3835 ordinal,
3836 final_status_update));
initial.commit09911bf2008-07-26 23:55:293837
initial.commit09911bf2008-07-26 23:55:293838 // Scoping effort begins, starting with the mainframe.
3839 search_frame = main_frame;
3840
[email protected]dd7daa82009-08-10 05:46:453841 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293842
3843 do {
3844 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453845 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293846
3847 // We don't start another scoping effort unless at least one match has
3848 // been found.
3849 if (result) {
3850 // Start new scoping request. If the scoping function determines that it
3851 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453852 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593853 search_text,
3854 options,
initial.commit09911bf2008-07-26 23:55:293855 true); // reset the tickmarks
3856 }
3857
3858 // Iterate to the next frame. The frame will not necessarily scope, for
3859 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273860 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293861 } while (search_frame != main_frame);
3862 }
3863}
3864
[email protected]815dd9872011-11-23 18:40:303865void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493866 WebView* view = webview();
3867 if (!view)
3868 return;
3869
3870 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163871 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013872 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493873 return;
3874 }
3875
[email protected]815dd9872011-11-23 18:40:303876 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493877 if (clear_selection)
3878 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3879
3880 WebFrame* frame = view->mainFrame();
3881 while (frame) {
3882 frame->stopFinding(clear_selection);
3883 frame = frame->traverseNext(false);
3884 }
3885
[email protected]815dd9872011-11-23 18:40:303886 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493887 WebFrame* focused_frame = view->focusedFrame();
3888 if (focused_frame) {
3889 WebDocument doc = focused_frame->document();
3890 if (!doc.isNull()) {
3891 WebNode node = doc.focusedNode();
3892 if (!node.isNull())
3893 node.simulateClick();
3894 }
3895 }
3896 }
3897}
3898
[email protected]310ebd6302011-10-10 19:06:283899void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493900 // Check if there is any queued up request waiting to be sent.
3901 if (queued_find_reply_message_.get()) {
3902 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423903 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493904 }
3905}
3906
[email protected]54087fe2011-10-28 22:02:483907void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513908 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3909 return;
3910
[email protected]258d31122010-05-09 10:59:413911 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103912
[email protected]b75b8292010-10-01 07:28:253913 double old_zoom_level = webview()->zoomLevel();
3914 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483915 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253916 zoom_level = 0;
3917 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3918 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483919 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253920 } else {
3921 // Either the user hit the zoom factor limit and thus the zoom level is now
3922 // not a whole number, or a plugin changed it to a custom value. We want
3923 // to go to the next whole number so that the user can always get back to
3924 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483925 if ((old_zoom_level > 1 && zoom > 0) ||
3926 (old_zoom_level < 1 && zoom < 0)) {
3927 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253928 } else {
3929 // We're going towards 100%, so first go to the next whole number.
3930 zoom_level = static_cast<int>(old_zoom_level);
3931 }
3932 }
[email protected]b75b8292010-10-01 07:28:253933 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413934 zoomLevelChanged();
3935}
3936
3937void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3938 int zoom_center_x, int zoom_center_y) {
3939 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3940 kScalingIncrementForGesture);
3941}
3942
3943void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3944 int zoom_center_x,
3945 int zoom_center_y,
3946 float scaling_increment) {
3947 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3948 return;
3949
[email protected]c514d6372011-08-16 22:54:443950 double old_page_scale_factor = webview()->pageScaleFactor();
3951 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:483952 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:443953 page_scale_factor = 1.0;
3954 } else {
3955 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:413956 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:443957 }
[email protected]47578fa02011-11-02 19:34:413958 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:093959 webview()->setPageScaleFactor(page_scale_factor,
3960 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:413961 }
[email protected]40bd6582009-12-04 23:49:513962}
3963
[email protected]310ebd6302011-10-10 19:06:283964void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173965 webview()->hidePopups();
3966 webview()->setZoomLevel(false, zoom_level);
3967 zoomLevelChanged();
3968}
3969
[email protected]310ebd6302011-10-10 19:06:283970void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3971 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543972 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293973}
3974
[email protected]310ebd6302011-10-10 19:06:283975void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273976 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293977}
3978
[email protected]310ebd6302011-10-10 19:06:283979void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273980 WebString no_encoding;
3981 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183982}
3983
[email protected]310ebd6302011-10-10 19:06:283984WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453985 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273986 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453987
3988 // xpath string can represent a frame deep down the tree (across multiple
3989 // frame DOMs).
3990 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3991 // should break into 2 xpaths
3992 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413993 std::vector<string16> xpaths;
3994 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453995
[email protected]26aa0482009-09-30 16:55:273996 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413997 for (std::vector<string16>::const_iterator i = xpaths.begin();
3998 frame && i != xpaths.end(); ++i) {
3999 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:294000 }
4001
[email protected]dd7daa82009-08-10 05:46:454002 return frame;
initial.commit09911bf2008-07-26 23:55:294003}
4004
[email protected]310ebd6302011-10-10 19:06:284005void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
4006 const string16& jscript,
4007 int id,
4008 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:534009 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294010}
4011
[email protected]310ebd6302011-10-10 19:06:284012void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
4013 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:414014 WebFrame* frame = GetChildFrame(frame_xpath);
4015 if (!frame)
[email protected]216813952011-05-19 22:21:264016 return;
[email protected]ae461542009-06-19 19:03:414017
[email protected]01cf589c2011-07-28 18:04:034018 frame->document().insertUserStyleSheet(
4019 WebString::fromUTF8(css),
4020 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:484021}
4022
[email protected]310ebd6302011-10-10 19:06:284023void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:094024 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294025}
4026
[email protected]310ebd6302011-10-10 19:06:284027void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
4028 const std::string& value) {
[email protected]e091df82011-10-11 18:13:214029 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:274030 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294031}
4032
[email protected]310ebd6302011-10-10 19:06:284033void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
4034 const gfx::Point& client_point,
4035 const gfx::Point& screen_point,
4036 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554037 WebDragOperation operation = webview()->dragTargetDragEnter(
4038 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:554039 client_point,
4040 screen_point,
4041 ops);
4042
4043 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4044}
4045
[email protected]310ebd6302011-10-10 19:06:284046void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
4047 const gfx::Point& screen_point,
4048 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:554049 WebDragOperation operation = webview()->dragTargetDragOver(
4050 client_point,
4051 screen_point,
4052 ops);
4053
4054 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
4055}
4056
[email protected]310ebd6302011-10-10 19:06:284057void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:554058 webview()->dragTargetDragLeave();
4059}
4060
[email protected]310ebd6302011-10-10 19:06:284061void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
4062 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:554063 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:574064
4065 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:554066}
4067
[email protected]310ebd6302011-10-10 19:06:284068void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4069 const gfx::Point& screen_point,
4070 bool ended,
4071 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034072 if (ended) {
[email protected]26aa0482009-09-30 16:55:274073 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204074 } else {
4075 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034076 }
initial.commit09911bf2008-07-26 23:55:294077}
4078
[email protected]310ebd6302011-10-10 19:06:284079void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274080 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294081}
4082
[email protected]310ebd6302011-10-10 19:06:284083void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594084 webkit_preferences_ = prefs;
4085 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294086}
4087
[email protected]310ebd6302011-10-10 19:06:284088void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:294089 alternate_error_page_url_ = url;
4090}
4091
[email protected]310ebd6302011-10-10 19:06:284092void RenderViewImpl::OnCustomContextMenuAction(
[email protected]35be7ec2012-02-12 20:42:514093 const content::CustomContextMenuContext& custom_context,
[email protected]b29aa74b2011-01-31 21:41:084094 unsigned action) {
4095 if (custom_context.is_pepper_menu)
4096 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
4097 else
4098 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:584099 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
4100 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:334101}
4102
[email protected]310ebd6302011-10-10 19:06:284103void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:514104 int id,
4105 const std::vector<FilePath>& paths) {
4106 if (!enumeration_completions_[id])
4107 return;
4108
4109 WebVector<WebString> ws_file_names(paths.size());
4110 for (size_t i = 0; i < paths.size(); ++i)
4111 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
4112
4113 enumeration_completions_[id]->didChooseFile(ws_file_names);
4114 enumeration_completions_.erase(id);
4115}
4116
[email protected]310ebd6302011-10-10 19:06:284117void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364118 // This could happen if we navigated to a different page before the user
4119 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474120 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364121 return;
4122
[email protected]cdaf8d02010-03-30 19:52:474123 WebVector<WebString> ws_file_names(paths.size());
4124 for (size_t i = 0; i < paths.size(); ++i)
4125 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464126
[email protected]cdaf8d02010-03-30 19:52:474127 if (file_chooser_completions_.front()->completion)
4128 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4129 file_chooser_completions_.pop_front();
4130
4131 // If there are more pending file chooser requests, schedule one now.
4132 if (!file_chooser_completions_.empty()) {
4133 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4134 file_chooser_completions_.front()->params));
4135 }
initial.commit09911bf2008-07-26 23:55:294136}
4137
[email protected]244ac1892011-12-02 17:04:474138void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
4139 const gfx::Size& max_size) {
4140 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4141 if (!webview())
4142 return;
[email protected]61e2b3cc2012-03-02 16:13:344143 webview()->enableAutoResizeMode(min_size, max_size);
4144}
4145
4146void RenderViewImpl::OnDisableAutoResize(const gfx::Size& new_size) {
4147 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
4148 if (!webview())
4149 return;
4150 webview()->disableAutoResizeMode();
4151
4152 Resize(new_size, resizer_rect_, is_fullscreen_, NO_RESIZE_ACK);
[email protected]244ac1892011-12-02 17:04:474153}
4154
[email protected]2bf834f2011-11-17 20:02:214155void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:244156 if (send_preferred_size_changes_)
4157 return;
[email protected]9fb325e2010-05-06 18:23:244158 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394159
[email protected]d812fd12011-05-27 23:05:074160 // Start off with an initial preferred size notification (in case
4161 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:594162 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:084163}
4164
[email protected]310ebd6302011-10-10 19:06:284165void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:104166 const gfx::Size& disable_scrollbar_size_limit) {
4167 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4168}
4169
[email protected]310ebd6302011-10-10 19:06:284170void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:314171 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:504172 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:514173 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374174 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134175#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414176 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4177 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464178 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:514179 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:344180 renderer_prefs.thumb_inactive_color,
4181 renderer_prefs.thumb_active_color,
4182 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324183
[email protected]644d77e2010-01-27 01:03:104184 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324185 webview()->setScrollbarColors(
4186 renderer_prefs.thumb_inactive_color,
4187 renderer_prefs.thumb_active_color,
4188 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104189 webview()->setSelectionColors(
4190 renderer_prefs.active_selection_bg_color,
4191 renderer_prefs.active_selection_fg_color,
4192 renderer_prefs.inactive_selection_bg_color,
4193 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464194 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104195 }
[email protected]7a74e102009-09-03 00:16:564196#endif
[email protected]d051d9a2011-12-10 02:02:504197 // If the zoom level for this page matches the old zoom default, and this
4198 // is not a plugin, update the zoom level to match the new default.
4199 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
4200 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
4201 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
4202 zoomLevelChanged();
4203 }
[email protected]80d96fa2009-06-10 22:34:514204}
4205
[email protected]310ebd6302011-10-10 19:06:284206void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
4207 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:284208 if (webview())
4209 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564210}
4211
[email protected]81375e872012-01-11 21:40:364212void RenderViewImpl::OnPluginActionAt(const gfx::Point& location,
4213 const WebPluginAction& action) {
4214 if (webview())
4215 webview()->performPluginAction(action, location);
4216}
4217
[email protected]310ebd6302011-10-10 19:06:284218void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:194219 const GURL& page_url) {
4220 // Prepare list to storage all savable resource links.
4221 std::vector<GURL> resources_list;
4222 std::vector<GURL> referrers_list;
4223 std::vector<GURL> frames_list;
4224 webkit_glue::SavableResourcesResult result(&resources_list,
4225 &referrers_list,
4226 &frames_list);
4227
[email protected]445e1042011-12-03 21:03:154228 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
4229 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:194230 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4231 webview(),
4232 page_url,
4233 &result,
[email protected]2a80aee2011-10-07 16:06:034234 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:194235 // If something is wrong when collecting all savable resource links,
4236 // send empty list to embedder(browser) to tell it failed.
4237 referrers_list.clear();
4238 resources_list.clear();
4239 frames_list.clear();
4240 }
4241
4242 // Send result of all savable resource links to embedder.
4243 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
4244 resources_list,
4245 referrers_list,
4246 frames_list));
4247}
4248
[email protected]310ebd6302011-10-10 19:06:284249void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:194250 const std::vector<GURL>& links,
4251 const std::vector<FilePath>& local_paths,
4252 const FilePath& local_directory_name) {
4253
4254 // Convert std::vector of GURLs to WebVector<WebURL>
4255 WebVector<WebURL> weburl_links(links);
4256
4257 // Convert std::vector of std::strings to WebVector<WebString>
4258 WebVector<WebString> webstring_paths(local_paths.size());
4259 for (size_t i = 0; i < local_paths.size(); i++)
4260 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4261
4262 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4263 webstring_paths,
4264 webkit_glue::FilePathToWebString(
4265 local_directory_name));
4266}
4267
[email protected]310ebd6302011-10-10 19:06:284268void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274269 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]4d346b92012-03-06 05:44:354270 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294271}
4272
[email protected]310ebd6302011-10-10 19:06:284273void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]69ddf852012-02-21 23:21:314274 // Ensure that no other in-progress navigation continues.
4275 OnStop();
4276
[email protected]73eb2602012-02-09 19:50:554277 // Only run unload if we're not swapped out yet, but send the ack either way.
4278 if (!is_swapped_out_) {
4279 // Swap this RenderView out so the tab can navigate to a page rendered by a
4280 // different process. This involves running the unload handler and clearing
4281 // the page. Once WasSwappedOut is called, we also allow this process to
4282 // exit if there are no other active RenderViews in it.
[email protected]992db4c2011-05-12 15:37:154283
[email protected]73eb2602012-02-09 19:50:554284 // Send an UpdateState message before we get swapped out.
4285 SyncNavigationState();
[email protected]992db4c2011-05-12 15:37:154286
[email protected]73eb2602012-02-09 19:50:554287 // Synchronously run the unload handler before sending the ACK.
4288 webview()->dispatchUnloadEvent();
[email protected]992db4c2011-05-12 15:37:154289
[email protected]73eb2602012-02-09 19:50:554290 // Swap out and stop sending any IPC messages that are not ACKs.
4291 SetSwappedOut(true);
[email protected]992db4c2011-05-12 15:37:154292
[email protected]73eb2602012-02-09 19:50:554293 // Replace the page with a blank dummy URL. The unload handler will not be
4294 // run a second time, thanks to a check in FrameLoader::stopLoading.
[email protected]69ddf852012-02-21 23:21:314295 // We use loadRequest instead of loadHTMLString because the former commits
4296 // synchronously. Otherwise a new navigation can interrupt the navigation
4297 // to about:swappedout. If that happens to be to the page we had been
4298 // showing, then WebKit will never send a commit and we'll be left spinning.
[email protected]73eb2602012-02-09 19:50:554299 // TODO(creis): Need to add a better way to do this that avoids running the
4300 // beforeunload handler. For now, we just run it a second time silently.
[email protected]69ddf852012-02-21 23:21:314301 WebURLRequest request(GURL("about:swappedout"));
4302 webview()->mainFrame()->loadRequest(request);
[email protected]73eb2602012-02-09 19:50:554303 }
[email protected]992db4c2011-05-12 15:37:154304
4305 // Just echo back the params in the ACK.
4306 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4307}
4308
[email protected]310ebd6302011-10-10 19:06:284309void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374310 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294311 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4312 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4313 // in the onunload handler from appearing. For now, we're bypassing that and
4314 // calling the FrameLoader's CloseURL method directly. This should be
4315 // revisited to avoid having two ways to close a page. Having a single way
4316 // to close that can run onunload is also useful for fixing
4317 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274318 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294319
[email protected]992db4c2011-05-12 15:37:154320 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294321}
4322
[email protected]310ebd6302011-10-10 19:06:284323void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024324#if defined(USE_AURA)
4325 // Aura doesn't care if we switch themes.
4326#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164327 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464328 if (webview())
4329 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574330#else // defined(OS_WIN)
4331 // TODO(port): we don't support theming on non-Windows platforms yet
4332 NOTIMPLEMENTED();
4333#endif
initial.commit09911bf2008-07-26 23:55:294334}
4335
[email protected]310ebd6302011-10-10 19:06:284336void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084337 if (decrement_shared_popup_at_destruction_)
4338 shared_popup_counter_->data--;
4339 shared_popup_counter_ = new SharedRenderViewCounter(0);
4340 decrement_shared_popup_at_destruction_ = false;
4341}
4342
[email protected]310ebd6302011-10-10 19:06:284343bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4344 const WebURLError& error,
4345 bool replace) {
[email protected]15d79e12009-08-02 19:23:454346 // We only show alternate error pages in the main frame. They are
4347 // intended to assist the user when navigating, so there is not much
4348 // value in showing them for failed subframes. Ideally, we would be
4349 // able to use the TYPED transition type for this, but that flag is
4350 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454351 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454352 return false;
4353
4354 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374355 // connection failure.
[email protected]15d79e12009-08-02 19:23:454356 int ec = error.reason;
4357 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4358 ec != net::ERR_CONNECTION_FAILED &&
4359 ec != net::ERR_CONNECTION_REFUSED &&
4360 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374361 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454362 return false;
4363
4364 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554365 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454366 if (!error_page_url.is_valid())
4367 return false;
4368
4369 // Load an empty page first so there is an immediate response to the error,
4370 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454371 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364372 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454373 error.unreachableURL,
4374 replace);
4375
4376 // Now, create a fetcher for the error page and associate it with the data
4377 // source we just created via the LoadHTMLString call. That way if another
4378 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074379 DocumentState* document_state =
4380 DocumentState::FromDataSource(frame->provisionalDataSource());
4381 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454382 new AltErrorPageResourceFetcher(
4383 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084384 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4385 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454386 return true;
4387}
4388
[email protected]310ebd6302011-10-10 19:06:284389void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4390 const WebURLError& original_error,
4391 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454392 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094393 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554394 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094395 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454396}
4397
[email protected]310ebd6302011-10-10 19:06:284398void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004399 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474400 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004401}
4402
[email protected]310ebd6302011-10-10 19:06:284403void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094404 const gfx::Rect& resizer_rect,
4405 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104406 if (webview()) {
[email protected]7ddea9802012-02-22 23:08:054407 // This setting has no effect if fixed layout is not enabled.
[email protected]43d9d782012-03-01 15:40:094408 if (webkit_preferences_.default_device_scale_factor)
[email protected]7ddea9802012-02-22 23:08:054409 webview()->settings()->setLayoutFallbackWidth(
[email protected]43d9d782012-03-01 15:40:094410 new_size.width() / webkit_preferences_.default_device_scale_factor);
[email protected]a72a1fa2010-05-03 22:18:474411 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104412 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204413 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314414 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104415 }
[email protected]dd6afca2011-08-13 03:44:314416 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104417 }
4418
[email protected]ee41e7d22011-10-14 19:34:094419 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004420}
[email protected]0aa477bd2009-03-23 22:21:434421
[email protected]29ed96a2012-02-04 18:12:164422void RenderViewImpl::WillInitiatePaint() {
4423 // Notify the pepper plugins that we're about to paint.
4424 pepper_delegate_.ViewWillInitiatePaint();
4425}
4426
[email protected]310ebd6302011-10-10 19:06:284427void RenderViewImpl::DidInitiatePaint() {
[email protected]29ed96a2012-02-04 18:12:164428 // Notify the pepper plugins that we've painted, and are waiting to flush.
[email protected]53900d52010-06-16 04:25:014429 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284430}
4431
[email protected]310ebd6302011-10-10 19:06:284432void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284433 // Notify any pepper plugins that we painted. This will call into the plugin,
4434 // and we it may ask to close itself as a result. This will, in turn, modify
4435 // our set, possibly invalidating the iterator. So we iterate on a copy that
4436 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014437 pepper_delegate_.ViewFlushedPaint();
4438
[email protected]5b1dec8c2012-02-07 04:35:384439 // If the RenderWidget is closing down then early-exit, otherwise we'll crash.
4440 // See crbug.com/112921.
4441 if (!webview())
4442 return;
4443
[email protected]00c39612010-03-06 02:53:284444 WebFrame* main_frame = webview()->mainFrame();
4445
4446 // If we have a provisional frame we are between the start and commit stages
4447 // of loading and we don't want to save stats.
4448 if (!main_frame->provisionalDataSource()) {
4449 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074450 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284451
[email protected]05c8e502010-08-15 15:13:524452 // TODO(jar): The following code should all be inside a method, probably in
4453 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284454 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074455 if (document_state->first_paint_time().is_null()) {
4456 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284457 }
[email protected]007733c2011-11-17 00:34:074458 if (document_state->first_paint_after_load_time().is_null() &&
4459 !document_state->finish_load_time().is_null()) {
4460 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284461 }
4462 }
4463}
4464
[email protected]310ebd6302011-10-10 19:06:284465void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084466 RenderWidget::OnSwapBuffersPosted();
4467}
4468
[email protected]310ebd6302011-10-10 19:06:284469void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244470 RenderWidget::OnSwapBuffersComplete();
4471}
4472
[email protected]310ebd6302011-10-10 19:06:284473void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244474 RenderWidget::OnSwapBuffersAborted();
4475}
4476
[email protected]310ebd6302011-10-10 19:06:284477webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154478 const gfx::Rect& paint_bounds,
4479 TransportDIB** dib,
4480 gfx::Rect* location,
4481 gfx::Rect* clip) {
4482 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4483 paint_bounds, dib, location, clip);
4484}
4485
[email protected]310ebd6302011-10-10 19:06:284486gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074487 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434488 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524489}
4490
[email protected]310ebd6302011-10-10 19:06:284491void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164492 if (webview())
[email protected]26aa0482009-09-30 16:55:274493 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164494}
4495
[email protected]310ebd6302011-10-10 19:06:284496void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144497 if (webview())
[email protected]b4bb2502009-10-01 22:35:274498 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144499
4500 SetBackground(background);
4501}
4502
[email protected]310ebd6302011-10-10 19:06:284503void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344504 if (webview())
[email protected]b4bb2502009-10-01 22:35:274505 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264506
4507#if defined(OS_MACOSX)
4508 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4509 for (plugin_it = plugin_delegates_.begin();
4510 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4511 (*plugin_it)->SetWindowFocus(active);
4512 }
4513#endif
[email protected]8c66c5a2009-07-22 17:26:344514}
4515
[email protected]6ce7abc52010-02-02 18:40:144516#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284517void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144518 // Inform plugins that their container has changed visibility.
4519 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4520 for (plugin_it = plugin_delegates_.begin();
4521 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4522 (*plugin_it)->SetContainerVisibility(visible);
4523 }
4524}
[email protected]1e6e3c992010-02-08 15:52:134525
[email protected]310ebd6302011-10-10 19:06:284526void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4527 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134528 // Inform plugins that their window's frame has changed.
4529 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4530 for (plugin_it = plugin_delegates_.begin();
4531 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4532 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4533 }
4534}
[email protected]935d63d2010-10-15 23:31:554535
[email protected]310ebd6302011-10-10 19:06:284536void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4537 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134538 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554539 // applies to it or not, so inform all the delegates.
4540 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4541 for (plugin_it = plugin_delegates_.begin();
4542 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134543 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554544 }
4545}
[email protected]6ce7abc52010-02-02 18:40:144546#endif // OS_MACOSX
4547
[email protected]310ebd6302011-10-10 19:06:284548void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484549 const EditCommands& edit_commands) {
4550 edit_commands_ = edit_commands;
4551}
4552
[email protected]310ebd6302011-10-10 19:06:284553void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594554 // We need to grab a pointer to the doomed WebView before we destroy it.
4555 WebView* doomed = webview();
4556 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494557 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594558}
4559
[email protected]310ebd6302011-10-10 19:06:284560void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484561 edit_commands_.clear();
4562}
4563
[email protected]310ebd6302011-10-10 19:06:284564bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]217690d2012-01-27 07:33:114565 pepper_delegate_.WillHandleMouseEvent();
4566
4567 // If the mouse is locked, only the current owner of the mouse lock can
4568 // process mouse events.
4569 return mouse_lock_dispatcher_->WillHandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374570}
4571
[email protected]310ebd6302011-10-10 19:06:284572void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514573 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064574}
4575
[email protected]310ebd6302011-10-10 19:06:284576void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244577 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4578}
4579
[email protected]310ebd6302011-10-10 19:06:284580void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434581 RenderWidget::OnWasHidden();
4582
[email protected]a6939ca42011-02-18 17:58:074583 if (webview()) {
4584 webview()->settings()->setMinimumTimerInterval(
4585 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444586 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074587 }
4588
[email protected]204f1df2012-01-04 20:21:134589 // Inform PPAPI plugins that their page is no longer visible.
4590 pepper_delegate_.PageVisibilityChanged(false);
4591
[email protected]a6939ca42011-02-18 17:58:074592#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134593 // Inform NPAPI plugins that their container is no longer visible.
[email protected]941e4552010-02-01 21:23:434594 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4595 for (plugin_it = plugin_delegates_.begin();
4596 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4597 (*plugin_it)->SetContainerVisibility(false);
4598 }
[email protected]a6939ca42011-02-18 17:58:074599#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434600}
4601
[email protected]310ebd6302011-10-10 19:06:284602void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434603 RenderWidget::OnWasRestored(needs_repainting);
4604
[email protected]a6939ca42011-02-18 17:58:074605 if (webview()) {
4606 webview()->settings()->setMinimumTimerInterval(
4607 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444608 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074609 }
4610
[email protected]204f1df2012-01-04 20:21:134611 // Inform PPAPI plugins that their page is visible.
4612 pepper_delegate_.PageVisibilityChanged(true);
4613
[email protected]a6939ca42011-02-18 17:58:074614#if defined(OS_MACOSX)
[email protected]204f1df2012-01-04 20:21:134615 // Inform NPAPI plugins that their container is now visible.
[email protected]941e4552010-02-01 21:23:434616 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4617 for (plugin_it = plugin_delegates_.begin();
4618 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4619 (*plugin_it)->SetContainerVisibility(true);
4620 }
[email protected]784ea1ab2010-09-18 00:02:344621#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074622}
[email protected]1e6e3c992010-02-08 15:52:134623
[email protected]310ebd6302011-10-10 19:06:284624bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384625 if (WebWidgetHandlesCompositorScheduling())
4626 return false;
4627
[email protected]05a980d7a2012-02-07 22:16:424628 if (queried_for_swapbuffers_complete_callback_)
4629 return context_has_swapbuffers_complete_callback_;
4630
4631 queried_for_swapbuffers_complete_callback_ = true;
4632
[email protected]65225772011-05-12 21:10:244633 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
[email protected]05a980d7a2012-02-07 22:16:424634 if (context && context->makeContextCurrent()) {
4635 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4636 context_has_swapbuffers_complete_callback_ =
4637 extensions.find("GL_CHROMIUM_swapbuffers_complete_callback")
4638 != std::string::npos;
4639 }
4640
4641 return context_has_swapbuffers_complete_callback_;
[email protected]65225772011-05-12 21:10:244642}
4643
[email protected]310ebd6302011-10-10 19:06:284644void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134645 RenderWidget::OnSetFocus(enable);
4646
[email protected]7d3c02c2010-05-05 23:10:314647 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074648 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134649 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4650 for (plugin_it = plugin_delegates_.begin();
4651 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344652#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314653 // RenderWidget's call to setFocus can cause the underlying webview's
4654 // activation state to change just like a call to setIsActive.
4655 if (enable)
4656 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344657#endif
[email protected]7d3c02c2010-05-05 23:10:314658 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134659 }
[email protected]589621b2010-09-23 22:01:074660
4661 // Notify all Pepper plugins.
4662 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134663 }
4664}
[email protected]941e4552010-02-01 21:23:434665
[email protected]310ebd6302011-10-10 19:06:284666void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004667 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504668 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574669}
4670
[email protected]73bf95812011-10-12 11:38:324671void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004672 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324673}
4674
[email protected]3f783362011-10-21 22:40:504675void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4676 UpdateSelectionBounds();
4677}
4678
[email protected]b25b3ee2012-01-13 05:19:544679bool RenderViewImpl::GetPpapiPluginCaretBounds(gfx::Rect* rect) {
4680 if (!pepper_delegate_.IsPluginFocused())
4681 return false;
4682 *rect = pepper_delegate_.GetCaretBounds();
4683 return true;
4684}
4685
[email protected]73bf95812011-10-12 11:38:324686void RenderViewImpl::PpapiPluginCancelComposition() {
4687 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4688 ui::Range range(ui::Range::InvalidRange());
4689 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4690}
4691
[email protected]310ebd6302011-10-10 19:06:284692void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574693 const string16& text,
4694 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4695 int selection_start,
4696 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324697 if (pepper_delegate_.IsPluginFocused()) {
4698 // When a PPAPI plugin has focus, we bypass WebKit.
4699 pepper_delegate_.OnImeSetComposition(text,
4700 underlines,
4701 selection_start,
4702 selection_end);
4703 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234704#if defined(OS_WIN)
4705 // When a plug-in has focus, we create platform-specific IME data used by
4706 // our IME emulator and send it directly to the focused plug-in, i.e. we
4707 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4708 // instance ID is the same one as the specified ID.)
4709 if (focused_plugin_id_ >= 0) {
4710 std::vector<int> clauses;
4711 std::vector<int> target;
4712 for (size_t i = 0; i < underlines.size(); ++i) {
4713 clauses.push_back(underlines[i].startOffset);
4714 clauses.push_back(underlines[i].endOffset);
4715 if (underlines[i].thick) {
4716 target.clear();
4717 target.push_back(underlines[i].startOffset);
4718 target.push_back(underlines[i].endOffset);
4719 }
4720 }
4721 std::set<WebPluginDelegateProxy*>::iterator it;
4722 for (it = plugin_delegates_.begin();
4723 it != plugin_delegates_.end(); ++it) {
4724 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4725 focused_plugin_id_);
4726 }
4727 return;
4728 }
4729#endif
[email protected]56ea1a62011-05-30 07:05:574730 RenderWidget::OnImeSetComposition(text,
4731 underlines,
4732 selection_start,
4733 selection_end);
4734 }
4735}
4736
[email protected]4de6d1692011-10-12 08:45:444737void RenderViewImpl::OnImeConfirmComposition(
4738 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574739 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324740 // When a PPAPI plugin has focus, we bypass WebKit.
4741 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574742 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234743#if defined(OS_WIN)
4744 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4745 // plug-ins. When we send IME text directly to plug-ins, we should not send
4746 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444747 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234748 if (focused_plugin_id_ >= 0) {
4749 std::set<WebPluginDelegateProxy*>::iterator it;
4750 for (it = plugin_delegates_.begin();
4751 it != plugin_delegates_.end(); ++it) {
4752 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4753 }
4754 return;
4755 }
4756#endif
[email protected]ebd28ac2011-10-13 18:49:054757 if (replacement_range.IsValid() && webview()) {
4758 // Select the text in |replacement_range|, it will then be replaced by
4759 // text added by the call to RenderWidget::OnImeConfirmComposition().
4760 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164761 WebRange webrange = WebRange::fromDocumentRange(
4762 frame, replacement_range.start(), replacement_range.length());
4763 if (!webrange.isNull())
4764 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054765 }
4766 }
[email protected]4de6d1692011-10-12 08:45:444767 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574768 }
4769}
4770
[email protected]310ebd6302011-10-10 19:06:284771ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324772 return pepper_delegate_.IsPluginFocused() ?
4773 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4774}
4775
[email protected]3f783362011-10-21 22:40:504776void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4777 if (pepper_delegate_.IsPluginFocused()) {
4778 // TODO(kinaba) http://crbug.com/101101
4779 // Current Pepper IME API does not handle selection bounds. So we simply
4780 // use the caret position as an empty range for now. It will be updated
4781 // after Pepper API equips features related to surrounding text retrieval.
4782 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4783 *start = caret;
4784 *end = caret;
4785 return;
4786 }
4787 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454788}
4789
[email protected]310ebd6302011-10-10 19:06:284790bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324791 return pepper_delegate_.IsPluginFocused() ?
4792 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574793}
4794
[email protected]e6ae0f6c2011-10-04 10:39:234795#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284796void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234797 if (focused)
4798 focused_plugin_id_ = plugin_id;
4799 else
4800 focused_plugin_id_ = -1;
4801}
4802#endif
4803
[email protected]43f28f832010-02-03 02:28:484804#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284805void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134806 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4807 focused, plugin_id);
4808 Send(msg);
4809}
4810
[email protected]310ebd6302011-10-10 19:06:284811void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134812 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554813 // This message can be sent during event-handling, and needs to be delivered
4814 // within that context.
4815 msg->set_unblock(true);
4816 Send(msg);
4817}
4818
[email protected]310ebd6302011-10-10 19:06:284819gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234820 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484821 gfx::PluginWindowHandle window = NULL;
4822 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234823 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114824 if (window) {
4825 fake_plugin_window_handles_.insert(window);
4826 }
[email protected]43f28f832010-02-03 02:28:484827 return window;
4828}
4829
[email protected]310ebd6302011-10-10 19:06:284830void RenderViewImpl::DestroyFakePluginWindowHandle(
4831 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114832 if (window && fake_plugin_window_handles_.find(window) !=
4833 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484834 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114835 fake_plugin_window_handles_.erase(window);
4836 }
[email protected]43f28f832010-02-03 02:28:484837}
4838
[email protected]310ebd6302011-10-10 19:06:284839void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4840 gfx::PluginWindowHandle window,
4841 int32 width,
4842 int32 height,
4843 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334844 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484845 routing_id(), window, width, height, io_surface_identifier));
4846}
4847
[email protected]310ebd6302011-10-10 19:06:284848void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334849 gfx::PluginWindowHandle window,
4850 int32 width,
4851 int32 height,
4852 TransportDIB::Handle transport_dib) {
4853 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074854 routing_id(), window, width, height, transport_dib));
4855}
4856
[email protected]310ebd6302011-10-10 19:06:284857TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334858 size_t size) {
[email protected]1aef98132010-02-23 18:00:074859 TransportDIB::Handle dib_handle;
4860 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384861 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074862 return dib_handle;
4863 // Return an invalid handle if Send() fails.
4864 return TransportDIB::DefaultHandleValue();
4865}
4866
[email protected]310ebd6302011-10-10 19:06:284867void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4868 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074869 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4870}
4871
[email protected]310ebd6302011-10-10 19:06:284872void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144873 gfx::PluginWindowHandle window, uint64 surface_id) {
4874 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4875 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484876}
4877#endif
[email protected]58c321d2010-02-19 12:11:284878
[email protected]310ebd6302011-10-10 19:06:284879bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234880 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474881 WebFileChooserCompletion* completion) {
4882 static const size_t kMaximumPendingFileChooseRequests = 4;
4883 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4884 // This sanity check prevents too many file choose requests from getting
4885 // queued which could DoS the user. Getting these is most likely a
4886 // programming error (there are many ways to DoS the user so it's not
4887 // considered a "real" security check), either in JS requesting many file
4888 // choosers to pop up, or in a plugin.
4889 //
4890 // TODO(brettw) we might possibly want to require a user gesture to open
4891 // a file picker, which will address this issue in a better way.
4892 return false;
4893 }
4894
4895 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4896 new PendingFileChooser(params, completion)));
4897 if (file_chooser_completions_.size() == 1) {
4898 // Actually show the browse dialog when this is the first request.
4899 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4900 }
4901 return true;
4902}
4903
[email protected]310ebd6302011-10-10 19:06:284904WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514905 if (!geolocation_dispatcher_)
4906 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4907 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254908}
[email protected]61c9f032010-03-31 23:04:194909
[email protected]310ebd6302011-10-10 19:06:284910WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114911 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224912#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514913 if (!speech_input_dispatcher_)
4914 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224915#endif
[email protected]676126f72011-01-15 00:03:514916 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114917}
4918
[email protected]310ebd6302011-10-10 19:06:284919WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514920 if (!device_orientation_dispatcher_)
4921 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4922 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534923}
4924
[email protected]310ebd6302011-10-10 19:06:284925void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4926 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254927 // For now, don't remember plugin zoom values. We don't want to mix them with
4928 // normal web content (i.e. a fixed layout plugin would usually want them
4929 // different).
4930 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4931
[email protected]b75b8292010-10-01 07:28:254932 int minimum_percent = static_cast<int>(
4933 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4934 int maximum_percent = static_cast<int>(
4935 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254936
4937 Send(new ViewHostMsg_UpdateZoomLimits(
4938 routing_id_, minimum_percent, maximum_percent, remember));
4939}
4940
[email protected]310ebd6302011-10-10 19:06:284941void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254942 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084943 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:254944 // Tell the browser which url got zoomed so it can update the menu and the
4945 // saved values if necessary
4946 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084947 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414948 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254949}
4950
[email protected]310ebd6302011-10-10 19:06:284951void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4952 const WebString& base_url,
4953 const WebString& url,
4954 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484955 GURL base(base_url);
4956 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4957 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4958 return;
4959 }
[email protected]f1a29a02011-10-06 23:08:444960 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4961 UTF16ToUTF8(scheme),
4962 absolute_url,
4963 title));
[email protected]a6d36cc2011-02-23 00:39:484964}
4965
[email protected]310ebd6302011-10-10 19:06:284966WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444967 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4968 WebKit::WebPageVisibilityStateHidden :
4969 WebKit::WebPageVisibilityStateVisible;
4970 WebKit::WebPageVisibilityState override_state = current_state;
4971 if (content::GetContentClient()->renderer()->
4972 ShouldOverridePageVisibilityState(this,
4973 &override_state))
4974 return override_state;
4975 return current_state;
[email protected]94dec932011-05-26 20:04:214976}
4977
[email protected]273558fb2012-01-12 15:03:514978WebKit::WebUserMediaClient* RenderViewImpl::userMediaClient() {
4979 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
4980 if (!cmd_line->HasSwitch(switches::kEnableMediaStream))
4981 return NULL;
4982 EnsureMediaStreamImpl();
4983 return media_stream_impl_;
4984}
4985
[email protected]310ebd6302011-10-10 19:06:284986bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194987 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454988 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194989 if (frame->parent() != NULL)
4990 return false;
4991
[email protected]f0a3d0b2010-08-06 22:51:534992 // Navigations initiated within Webkit are not sent out to the external host
4993 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274994 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134995 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534996 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134997 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334998 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534999 return false;
5000
[email protected]2fc22d12010-12-02 23:08:165001 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325002 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015003 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165004 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015005 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325006 // The opener relationship between the new window and the parent allows the
5007 // new window to script the parent and vice versa. This is not allowed if
5008 // the origins of the two domains are different. This can be treated as a
5009 // top level navigation and routed back to the host.
5010 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275011 if (!opener) {
[email protected]86965362011-04-21 18:42:515012 return true;
[email protected]d19ea342011-04-20 20:31:135013 } else {
[email protected]b6cb3a842011-06-24 18:28:415014 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:325015 return true;
5016 }
5017 }
[email protected]61c9f032010-03-31 23:04:195018 return false;
5019}
[email protected]2b06a992010-08-21 05:48:225020
[email protected]310ebd6302011-10-10 19:06:285021void RenderViewImpl::OnAsyncFileOpened(
5022 base::PlatformFileError error_code,
5023 IPC::PlatformFileForTransit file_for_transit,
5024 int message_id) {
[email protected]27a9ef32010-09-10 04:06:245025 pepper_delegate_.OnAsyncFileOpened(
5026 error_code,
5027 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5028 message_id);
5029}
[email protected]caf706f2010-10-26 17:54:085030
[email protected]310ebd6302011-10-10 19:06:285031void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:475032 int request_id,
5033 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:435034 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:475035 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
5036 broker_process_handle,
5037 handle);
[email protected]eb415bf0e2011-04-14 02:45:425038}
5039
[email protected]caf706f2010-10-26 17:54:085040#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:285041void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155042 if (external_popup_menu_ == NULL) {
5043 // Crash reports from the field indicate that we can be notified with a
5044 // NULL external popup menu (we probably get notified twice).
5045 // If you hit this please file a bug against jcivelli and include the page
5046 // and steps to repro.
5047 NOTREACHED();
5048 return;
5049 }
[email protected]caf706f2010-10-26 17:54:085050 external_popup_menu_->DidSelectItem(selected_index);
5051 external_popup_menu_.reset();
5052}
5053#endif
[email protected]bb461532010-11-26 21:50:235054
[email protected]1b4209f2011-01-07 00:25:405055#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:285056void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:405057 int request_id,
5058 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:495059 const PP_NetAddress_Private& local_addr,
5060 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:405061 pepper_delegate_.OnConnectTcpACK(
5062 request_id,
5063 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5064 local_addr,
5065 remote_addr);
5066}
5067#endif
[email protected]a6097f42011-01-10 08:50:515068
[email protected]310ebd6302011-10-10 19:06:285069void RenderViewImpl::OnContextMenuClosed(
[email protected]35be7ec2012-02-12 20:42:515070 const content::CustomContextMenuContext& custom_context) {
[email protected]b29aa74b2011-01-31 21:41:085071 if (custom_context.is_pepper_menu)
5072 pepper_delegate_.OnContextMenuClosed(custom_context);
5073 else
5074 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:105075}
[email protected]5a7b15a2011-08-22 22:48:185076
[email protected]310ebd6302011-10-10 19:06:285077void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:185078 if (!webview())
5079 return;
5080 WebFrame* main_frame = webview()->mainFrame();
5081 if (!main_frame)
5082 return;
5083 main_frame->enableViewSourceMode(true);
5084}
[email protected]67bfb83f2011-09-22 03:36:375085
[email protected]310ebd6302011-10-10 19:06:285086bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:085087 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:405088}
[email protected]7f3c7af2011-10-20 22:52:515089
[email protected]64d0e192011-12-09 14:44:205090void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:515091 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:185092#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:205093 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:185094#endif
[email protected]7f3c7af2011-10-20 22:52:515095}