blob: d40bcc9d069d6c7ff913ab62e8639f85e49f6f05 [file] [log] [blame]
[email protected]1b4209f2011-01-07 00:25:401// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[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]005bab02011-10-07 18:36:0016#include "base/json/json_value_serializer.h"
[email protected]b1cf3372011-04-20 21:28:1017#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4918#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2820#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_piece.h"
[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]7ef40ffe12011-03-08 05:05:2832#include "content/common/file_system/file_system_dispatcher.h"
33#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]a2ef54c2011-10-10 16:20:3134#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5135#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1036#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0037#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4038#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0539#include "content/common/request_extra_data.h"
[email protected]778574e2011-03-21 22:03:5040#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2141#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4842#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2943#include "content/public/common/content_switches.h"
[email protected]8caadeb2011-11-22 02:45:2344#include "content/public/common/file_chooser_params.h"
[email protected]a1d29162011-10-14 17:14:0345#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3446#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0747#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3248#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4449#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3650#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1951#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0252#include "content/renderer/devtools_agent.h"
[email protected]55722152011-03-22 01:33:5353#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1954#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4055#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]1784b2f2011-11-24 10:53:4856#include "content/renderer/idle_user_detector.h"
[email protected]0d9989d2011-12-21 20:26:0057#include "content/renderer/web_intents_host.h"
[email protected]07161902011-11-11 09:57:4258#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0259#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0860#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3761#include "content/renderer/media/audio_renderer_impl.h"
[email protected]ab2c4732011-07-20 19:57:4062#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:4063#include "content/renderer/media/render_media_log.h"
[email protected]4a19be92011-09-22 14:25:0264#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1965#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3766#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3567#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0568#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4469#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4470#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3271#include "content/renderer/renderer_accessibility.h"
[email protected]e1d69d762011-12-13 05:12:1872#include "content/renderer/renderer_gpu_video_decoder_factories.h"
[email protected]663bd9e2011-03-21 01:07:0173#include "content/renderer/renderer_webapplicationcachehost_impl.h"
74#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1975#include "content/renderer/speech_input_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3276#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1977#include "content/renderer/v8_value_converter_impl.h"
[email protected]663bd9e2011-03-21 01:07:0178#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3579#include "content/renderer/webplugin_delegate_proxy.h"
80#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4981#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4182#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2783#include "media/base/message_loop_factory_impl.h"
[email protected]e1d69d762011-12-13 05:12:1884#include "media/filters/gpu_video_decoder.h"
initial.commit09911bf2008-07-26 23:55:2985#include "net/base/escape.h"
86#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0487#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5788#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3789#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
[email protected]8bd0fe62011-01-17 06:44:3790#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3791#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
[email protected]8bd0fe62011-01-17 06:44:3792#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
93#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3794#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
95#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
96#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
97#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
98#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
[email protected]8bd0fe62011-01-17 06:44:3799#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
[email protected]8bd0fe62011-01-17 06:44:37100#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57101#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]8b5af492011-11-28 21:50:58102#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
103#include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.h"
[email protected]69f110d62011-03-17 19:01:14104#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37105#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19106#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37107#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
[email protected]8bd0fe62011-01-17 06:44:37111#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:37112#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
113#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
114#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17115#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
[email protected]8bd0fe62011-01-17 06:44:37117#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40118#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]9c4bf232011-12-15 02:25:08119#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebImage.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
[email protected]e6e90dc2011-12-03 00:01:37128#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
[email protected]6fdd4182010-10-14 23:59:26134#include "third_party/skia/include/core/SkBitmap.h"
[email protected]269f86d2011-12-07 02:43:47135#include "ui/base/javascript_message_type.h"
[email protected]08397d52011-02-05 01:53:38136#include "ui/gfx/native_widget_types.h"
137#include "ui/gfx/point.h"
138#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55139#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04140#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]9c4bf232011-12-15 02:25:08141#include "webkit/forms/form_data.h"
142#include "webkit/forms/form_field.h"
143#include "webkit/forms/password_form_dom_manager.h"
[email protected]25e18f82010-10-27 16:38:43144#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24145#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19146#include "webkit/glue/dom_operations.h"
[email protected]95056b582010-02-18 01:29:24147#include "webkit/glue/glue_serialize.h"
initial.commit09911bf2008-07-26 23:55:29148#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07149#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29150#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03151#include "webkit/glue/weburlloader_impl.h"
[email protected]a9288f52011-11-17 05:18:16152#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50153#include "webkit/plugins/npapi/plugin_list.h"
154#include "webkit/plugins/npapi/webplugin_delegate.h"
155#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
156#include "webkit/plugins/npapi/webplugin_impl.h"
[email protected]0bd753682010-12-16 18:15:52157#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29158
[email protected]6c8afae52009-01-22 02:24:57159#if defined(OS_WIN)
160// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57161// * theming
[email protected]08397d52011-02-05 01:53:38162#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03163#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37164#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51165#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33166#elif defined(OS_MACOSX)
167#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57168#endif
169
[email protected]9892b472010-09-16 00:23:42170using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08171using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21172using WebKit::WebApplicationCacheHost;
173using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26174using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41175using WebKit::WebColor;
176using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59177using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44178using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51179using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55180using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28181using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00182using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58183using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25184using WebKit::WebDragOperation;
185using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51186using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51187using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08188using WebKit::WebExternalPopupMenu;
189using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47190using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22191using WebKit::WebFileSystem;
192using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49193using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59194using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48195using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45196using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17197using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13198using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41199using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50200using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17201using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28202using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17203using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28204using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28205using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51206using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19207using WebKit::WebPageSerializer;
208using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17209using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40210using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49211using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09212using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52213using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59214using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51215using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52216using WebKit::WebRect;
[email protected]445e1042011-12-03 21:03:15217using WebKit::WebReferrerPolicy;
[email protected]4f999132009-03-31 18:08:40218using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35219using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29220using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17221using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59222using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42223using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02224using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34225using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40226using WebKit::WebStorageQuotaCallbacks;
227using WebKit::WebStorageQuotaError;
228using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28229using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51230using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52231using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24232using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28233using WebKit::WebURL;
234using WebKit::WebURLError;
235using WebKit::WebURLRequest;
236using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28237using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03238using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28239using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26240using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43241using WebKit::WebWorker;
242using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26243using appcache::WebApplicationCacheHostImpl;
244using base::Time;
245using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07246using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32247using content::NavigationState;
[email protected]380244092011-10-07 17:26:27248using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44249using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36250using content::RenderViewVisitor;
[email protected]445e1042011-12-03 21:03:15251using content::Referrer;
[email protected]8d86f13d2011-10-04 17:01:19252using content::V8ValueConverter;
[email protected]9c4bf232011-12-15 02:25:08253using webkit::forms::FormField;
254using webkit::forms::PasswordForm;
255using webkit::forms::PasswordFormDomManager;
[email protected]6fdd4182010-10-14 23:59:26256using webkit_glue::AltErrorPageResourceFetcher;
[email protected]bb461532010-11-26 21:50:23257using webkit_glue::ResourceFetcher;
[email protected]e1acf6f2008-10-27 20:43:33258
initial.commit09911bf2008-07-26 23:55:29259//-----------------------------------------------------------------------------
260
[email protected]310ebd6302011-10-10 19:06:28261typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49262static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02263
[email protected]882daa92009-11-05 16:31:31264// Time, in seconds, we delay before sending content state changes (such as form
265// state and scroll position) to the browser. We delay sending changes to avoid
266// spamming the browser.
267// To avoid having tab/session restore require sending a message to get the
268// current content state during tab closing we use a shorter timeout for the
269// foreground renderer. This means there is a small window of time from which
270// content state is modified and not sent to session restore, but this is
271// better than having to wake up all renderers during shutdown.
272static const int kDelaySecondsForContentStateSyncHidden = 5;
273static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29274
[email protected]e99ef6f2011-10-16 01:13:00275static const size_t kExtraCharsBeforeAndAfterSelection = 100;
276
[email protected]0aa55312008-10-17 21:53:08277// The maximum number of popups that can be spawned from one page.
278static const int kMaximumNumberOfUnacknowledgedPopups = 25;
279
[email protected]c514d6372011-08-16 22:54:44280static const float kScalingIncrement = 0.1f;
281
[email protected]47578fa02011-11-02 19:34:41282static const float kScalingIncrementForGesture = 0.01f;
283
[email protected]726985e22009-06-18 21:09:28284static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
285 WebVector<WebURL> urls;
286 ds->redirectChain(urls);
287 result->reserve(urls.size());
288 for (size_t i = 0; i < urls.size(); ++i)
289 result->push_back(urls[i]);
290}
291
[email protected]007733c2011-11-17 00:34:07292// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44293// the AltErrorPageResourceFetcher is reset.
294static void StopAltErrorPageFetcher(WebDataSource* data_source) {
295 if (data_source) {
[email protected]007733c2011-11-17 00:34:07296 DocumentState* document_state = DocumentState::FromDataSource(data_source);
297 if (document_state)
298 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44299 }
300}
301
[email protected]007733c2011-11-17 00:34:07302static bool IsReload(const ViewMsg_Navigate_Params& params) {
303 return
304 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
305 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
306}
307
[email protected]445e1042011-12-03 21:03:15308static WebReferrerPolicy getReferrerPolicyFromRequest(
309 const WebURLRequest& request) {
310 return request.extraData() ?
311 static_cast<RequestExtraData*>(request.extraData())->referrer_policy() :
312 WebKit::WebReferrerPolicyDefault;
313}
314
initial.commit09911bf2008-07-26 23:55:29315///////////////////////////////////////////////////////////////////////////////
316
[email protected]310ebd6302011-10-10 19:06:28317struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23318 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47319 WebFileChooserCompletion* c)
320 : params(p),
321 completion(c) {
322 }
[email protected]8caadeb2011-11-22 02:45:23323 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47324 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
325};
326
[email protected]daf82f82011-10-31 22:35:31327RenderViewImpl::RenderViewImpl(
328 gfx::NativeViewId parent_hwnd,
329 int32 opener_id,
330 const content::RendererPreferences& renderer_prefs,
331 const WebPreferences& webkit_prefs,
332 SharedRenderViewCounter* counter,
333 int32 routing_id,
334 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46335 const string16& frame_name,
336 int32 next_page_id)
[email protected]380244092011-10-07 17:26:27337 : RenderWidget(WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51338 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02339 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09340 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02341 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24342 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21343 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02344 opened_by_user_gesture_(true),
345 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24346 page_id_(-1),
347 last_page_id_sent_to_browser_(-1),
[email protected]74ce1ad2011-12-16 21:51:46348 next_page_id_(next_page_id),
[email protected]3cc72b12010-03-18 23:03:00349 history_list_offset_(-1),
350 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02351 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55352 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31353 cached_is_main_frame_pinned_to_left_(false),
354 cached_is_main_frame_pinned_to_right_(false),
355 cached_has_main_frame_horizontal_scrollbar_(false),
356 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]3354d3e2010-06-10 19:53:02357 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51358 geolocation_dispatcher_(NULL),
359 speech_input_dispatcher_(NULL),
360 device_orientation_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18361 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41362 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32363 renderer_accessibility_(NULL),
[email protected]4fb60142011-08-09 02:22:08364 session_storage_namespace_id_(session_storage_namespace_id),
[email protected]ef5e98e2011-12-06 09:49:18365 handling_select_range_(false),
366#if defined(OS_WIN)
367 focused_plugin_id_(-1),
368#endif
369 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) {
[email protected]676126f72011-01-15 00:03:51370 routing_id_ = routing_id;
371 if (opener_id != MSG_ROUTING_NONE)
372 opener_id_ = opener_id;
373
[email protected]74ce1ad2011-12-16 21:51:46374 // Ensure we start with a valid next_page_id_ from the browser.
375 DCHECK_GE(next_page_id_, 0);
376
[email protected]21b3a6ae2011-11-30 00:45:29377#if defined(ENABLE_NOTIFICATIONS)
378 notification_provider_ = new NotificationProvider(this);
379#else
380 notification_provider_ = NULL;
381#endif
382
[email protected]11fee2332011-03-29 20:36:35383 webwidget_ = WebView::create(this);
384
[email protected]676126f72011-01-15 00:03:51385 if (counter) {
386 shared_popup_counter_ = counter;
387 shared_popup_counter_->data++;
388 decrement_shared_popup_at_destruction_ = true;
389 } else {
390 shared_popup_counter_ = new SharedRenderViewCounter(0);
391 decrement_shared_popup_at_destruction_ = false;
392 }
393
[email protected]0d9989d2011-12-21 20:26:00394 intents_host_ = new WebIntentsHost(this);
[email protected]7cce3232011-10-28 10:41:57395
[email protected]380244092011-10-07 17:26:27396 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51397 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47398 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51399 AddRef();
400
401 // If this is a popup, we must wait for the CreatingNew_ACK message before
402 // completing initialization. Otherwise, we can finish it now.
403 if (opener_id == MSG_ROUTING_NONE) {
404 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55405 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51406 }
407
[email protected]34c61bd52011-05-02 19:38:33408 g_view_map.Get().insert(std::make_pair(webview(), this));
409 webkit_preferences_.Apply(webview());
410 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35411 if (!frame_name.empty())
412 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33413 webview()->settings()->setMinimumTimerInterval(
414 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
415 webkit_glue::kForegroundTabTimerInterval);
416
417 OnSetRendererPrefs(renderer_prefs);
418
[email protected]676126f72011-01-15 00:03:51419 host_window_ = parent_hwnd;
420
[email protected]a026daa2011-04-20 15:49:51421#if defined(ENABLE_P2P_APIS)
[email protected]7be7b6612011-11-29 19:37:23422 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51423#endif
[email protected]cae8c8492011-03-03 11:12:18424
[email protected]8f6a3b852011-07-19 16:48:56425 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32426#if defined(OS_MACOSX)
427 new TextInputClientObserver(this);
428#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56429
[email protected]c5c1d6d2011-07-28 18:42:41430 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20431
[email protected]063afcb2011-09-29 07:54:32432 renderer_accessibility_ = new RendererAccessibility(this);
433
[email protected]1784b2f2011-11-24 10:53:48434 new IdleUserDetector(this);
435
[email protected]7be7b6612011-11-29 19:37:23436 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
437 if (command_line.HasSwitch(switches::kEnableMediaStream)) {
438 media_stream_impl_ = new MediaStreamImpl(
439 RenderThreadImpl::current()->video_capture_impl_manager());
440 }
441
[email protected]e48869a2011-04-01 19:56:03442 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29443}
444
[email protected]310ebd6302011-10-10 19:06:28445RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03446 history_page_ids_.clear();
447
[email protected]0aa55312008-10-17 21:53:08448 if (decrement_shared_popup_at_destruction_)
449 shared_popup_counter_->data--;
450
[email protected]a1128322009-10-06 18:38:46451 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47452 while (!file_chooser_completions_.empty()) {
453 if (file_chooser_completions_.front()->completion) {
454 file_chooser_completions_.front()->completion->didChooseFile(
455 WebVector<WebString>());
456 }
457 file_chooser_completions_.pop_front();
458 }
[email protected]a1128322009-10-06 18:38:46459
[email protected]83dde542009-09-11 20:59:55460#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11461 // Destroy all fake plugin window handles on the browser side.
462 while (!fake_plugin_window_handles_.empty()) {
463 // Make sure no NULL plugin window handles were inserted into this list.
464 DCHECK(*fake_plugin_window_handles_.begin());
465 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
466 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
467 }
[email protected]83dde542009-09-11 20:59:55468#endif
[email protected]98324892009-09-09 21:16:05469
[email protected]60c42a8c72009-10-09 04:08:59470#ifndef NDEBUG
471 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49472 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59473 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
474 DCHECK_NE(this, it->second) << "Failed to call Close?";
475#endif
[email protected]676126f72011-01-15 00:03:51476
[email protected]310ebd6302011-10-10 19:06:28477 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51478 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59479}
480
481/*static*/
[email protected]310ebd6302011-10-10 19:06:28482RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31483 ViewMap* views = g_view_map.Pointer();
484 ViewMap::iterator it = views->find(webview);
485 return it == views->end() ? NULL : it->second;
486}
487
488/*static*/
489content::RenderView*
490 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28491 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31492}
493
494/*static*/
495void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49496 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59497 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
498 if (!visitor->Visit(it->second))
499 return;
500 }
501}
502
503/*static*/
[email protected]310ebd6302011-10-10 19:06:28504RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15505 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08506 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31507 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08508 const WebPreferences& webkit_prefs,
509 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34510 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26511 int64 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46512 const string16& frame_name,
513 int32 next_page_id) {
initial.commit09911bf2008-07-26 23:55:29514 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28515 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51516 parent_hwnd,
517 opener_id,
518 renderer_prefs,
519 webkit_prefs,
520 counter,
521 routing_id,
522 session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:46523 frame_name,
524 next_page_id); // adds reference
initial.commit09911bf2008-07-26 23:55:29525}
526
[email protected]310ebd6302011-10-10 19:06:28527void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51528 observers_.AddObserver(observer);
529}
530
[email protected]310ebd6302011-10-10 19:06:28531void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
532 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51533 observers_.RemoveObserver(observer);
534}
535
[email protected]310ebd6302011-10-10 19:06:28536WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26537 return static_cast<WebKit::WebView*>(webwidget());
538}
539
[email protected]310ebd6302011-10-10 19:06:28540void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40541 if (!enabled) {
542 load_progress_tracker_.reset(NULL);
543 return;
544 }
545 if (load_progress_tracker_ == NULL)
546 load_progress_tracker_.reset(new LoadProgressTracker(this));
547}
548
[email protected]310ebd6302011-10-10 19:06:28549void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51550 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29551}
552
[email protected]310ebd6302011-10-10 19:06:28553void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26554 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30555 // If the renderer is visible, set initial visibility and focus state.
556 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34557#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30558 delegate->SetContainerVisibility(true);
559 if (webview() && webview()->isActive())
560 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34561#endif
[email protected]49232292010-09-03 19:07:30562 }
[email protected]784ea1ab2010-09-18 00:02:34563 // Plugins start assuming the content has focus (so that they work in
564 // environments where RenderView isn't hosting them), so we always have to
565 // set the initial state. See webplugin_delegate_impl.h for details.
566 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26567}
568
[email protected]310ebd6302011-10-10 19:06:28569void RenderViewImpl::UnregisterPluginDelegate(
570 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26571 plugin_delegates_.erase(delegate);
572}
[email protected]d8fd6fa2010-02-01 15:54:26573
[email protected]310ebd6302011-10-10 19:06:28574bool RenderViewImpl::GetPluginInfo(const GURL& url,
575 const GURL& page_url,
576 const std::string& mime_type,
577 webkit::WebPluginInfo* plugin_info,
578 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08579 bool found = false;
580 Send(new ViewHostMsg_GetPluginInfo(
581 routing_id_, url, page_url, mime_type, &found, plugin_info,
582 actual_mime_type));
583 return found;
584}
585
[email protected]310ebd6302011-10-10 19:06:28586bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27587 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27588 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41589 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26590
[email protected]676126f72011-01-15 00:03:51591 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
592 RenderViewObserver* observer;
593 while ((observer = it.GetNext()) != NULL)
594 if (observer->OnMessageReceived(message))
595 return true;
[email protected]b2abac72009-02-26 12:39:28596
[email protected]a95986a82010-12-24 06:19:28597 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40598 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28599 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29600 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
601 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56602 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29603 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
604 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
605 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
606 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27607#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35608 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27609#endif
initial.commit09911bf2008-07-26 23:55:29610 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15611 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29612 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
613 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
614 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08615 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29616 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15617 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29618 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49619 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
620 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17621 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17622 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41623 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54624 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
625 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29626 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18627 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
628 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29629 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48630 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
[email protected]59f4f2fa2011-03-23 01:00:55631 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
632 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
633 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
634 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
635 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
636 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
637 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45638 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40639 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29640 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19641 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
642 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29643 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
644 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
645 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51646 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
647 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29648 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04649 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15650 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29651 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
652 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08653 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
654 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00655 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16656 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14657 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25658 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
659 OnEnablePreferredSizeChangedMode)
[email protected]244ac1892011-12-02 17:04:47660 IPC_MESSAGE_HANDLER(ViewMsg_EnableAutoResize, OnEnableAutoResize)
[email protected]cda45c02010-02-25 19:28:10661 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
662 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51663 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56664 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34665 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14666#if defined(OS_MACOSX)
667 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13668 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13669 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
670 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14671#endif
[email protected]446705872009-09-10 07:22:48672 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33673 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33674 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
675 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24676 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42677 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
678 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19679 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
680 OnGetAllSavableResourceLinksForCurrentPage)
681 IPC_MESSAGE_HANDLER(
682 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
683 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08684#if defined(OS_MACOSX)
685 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
686#endif
[email protected]521b2482011-01-15 00:10:10687 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51688 // TODO(viettrungluu): Move to a separate message filter.
689#if defined(ENABLE_FLAPPER_HACKS)
690 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
691#endif
[email protected]54ca3ca892011-06-07 21:14:54692#if defined(OS_MACOSX)
693 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
694#endif
[email protected]9e1ad4b2011-08-14 16:49:19695 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
696 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18697 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]67bfb83f2011-09-22 03:36:37698 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
699 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
[email protected]7f3c7af2011-10-20 22:52:51700 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19701
initial.commit09911bf2008-07-26 23:55:29702 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28703 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29704 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40705
706 if (!msg_is_ok) {
707 // The message had a handler, but its deserialization failed.
708 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28709 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40710 }
711
[email protected]a95986a82010-12-24 06:19:28712 return handled;
initial.commit09911bf2008-07-26 23:55:29713}
714
[email protected]310ebd6302011-10-10 19:06:28715void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
initial.commit09911bf2008-07-26 23:55:29716 if (!webview())
717 return;
718
[email protected]440a0e52011-09-13 17:38:58719 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
720
[email protected]007733c2011-11-17 00:34:07721 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03722
723 // If this is a stale back/forward (due to a recent navigation the browser
724 // didn't know about), ignore it.
725 if (IsBackForwardToStaleEntry(params, is_reload))
726 return;
727
[email protected]992db4c2011-05-12 15:37:15728 // Swap this renderer back in if necessary.
729 if (is_swapped_out_)
730 SetSwappedOut(false);
731
[email protected]3cc72b12010-03-18 23:03:00732 history_list_offset_ = params.current_history_list_offset;
733 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03734 if (history_list_length_ >= 0)
735 history_page_ids_.resize(history_list_length_, -1);
736 if (params.pending_history_list_offset >= 0 &&
737 params.pending_history_list_offset < history_list_length_)
738 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00739
[email protected]38b592902011-04-16 02:08:42740 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29741
[email protected]26aa0482009-09-30 16:55:27742 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45743 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29744 // We cannot reload if we do not have any history state. This happens, for
745 // example, when recovering from a crash. Our workaround here is a bit of
746 // a hack since it means that reload after a crashed tab does not cause an
747 // end-to-end cache validation.
748 is_reload = false;
749 }
750
[email protected]007733c2011-11-17 00:34:07751 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
752 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50753
[email protected]04d3c6e2009-05-22 17:00:13754 // If we are reloading, then WebKit will use the history state of the current
755 // page, so we should just ignore any given history state. Otherwise, if we
756 // have history state, then we need to navigate to it, which corresponds to a
757 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55758 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29759 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02760 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29761 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55762 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13763 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58764 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45765 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17766 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13767 } else {
768 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28769 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29770
[email protected]e6f546c32009-07-01 17:12:55771 // A session history navigation should have been accompanied by state.
[email protected]cbc0cb72011-12-06 18:58:23772 CHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13773
[email protected]dd7daa82009-08-10 05:46:45774 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55775 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13776
[email protected]445e1042011-12-03 21:03:15777 if (params.referrer.url.is_valid()) {
778 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
779 params.referrer.policy,
780 params.url,
781 WebString::fromUTF8(params.referrer.url.spec()));
782 if (!referrer.isEmpty())
783 request.setHTTPHeaderField(WebString::fromUTF8("Referer"), referrer);
[email protected]726985e22009-06-18 21:09:28784 }
[email protected]04d3c6e2009-05-22 17:00:13785
[email protected]52c68652010-12-07 17:47:04786 if (!params.extra_headers.empty()) {
787 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
788 params.extra_headers.end(), "\n");
789 i.GetNext(); ) {
790 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
791 WebString::fromUTF8(i.values()));
792 }
793 }
794
[email protected]dd7daa82009-08-10 05:46:45795 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50796 }
797
[email protected]77f17a82009-05-21 04:42:54798 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07799 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29800}
801
[email protected]310ebd6302011-10-10 19:06:28802bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03803 const ViewMsg_Navigate_Params& params,
804 bool is_reload) {
805 // Make sure this isn't a back/forward to an entry we have already cropped
806 // or replaced from our history, before the browser knew about it. If so,
807 // a new navigation has committed in the mean time, and we can ignore this.
808 bool is_back_forward = !is_reload && !params.state.empty();
809
810 // Note: if the history_list_length_ is 0 for a back/forward, we must be
811 // restoring from a previous session. We'll update our state in OnNavigate.
812 if (!is_back_forward || history_list_length_ <= 0)
813 return false;
814
815 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
816
817 // Check for whether the forward history has been cropped due to a recent
818 // navigation the browser didn't know about.
819 if (params.pending_history_list_offset >= history_list_length_)
820 return true;
821
822 // Check for whether this entry has been replaced with a new one.
823 int expected_page_id =
824 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44825 if (expected_page_id > 0 && params.page_id != expected_page_id) {
826 if (params.page_id < expected_page_id)
827 return true;
828
829 // Otherwise we've removed an earlier entry and should have shifted all
830 // entries left. For now, it's ok to lazily update the list.
831 // TODO(creis): Notify all live renderers when we remove entries from
832 // the front of the list, so that we don't hit this case.
833 history_page_ids_[params.pending_history_list_offset] = params.page_id;
834 }
[email protected]d466b8a2011-07-15 21:48:03835
836 return false;
837}
838
initial.commit09911bf2008-07-26 23:55:29839// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28840void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44841 if (webview()) {
842 WebFrame* main_frame = webview()->mainFrame();
843 // Stop the alt error page fetcher. If we let it continue it may complete
844 // and cause RenderViewHostManager to swap to this RenderView, even though
845 // it may no longer be active.
846 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
847 StopAltErrorPageFetcher(main_frame->dataSource());
848 main_frame->stopLoading();
849 }
initial.commit09911bf2008-07-26 23:55:29850}
851
[email protected]ecbf10d2010-02-18 13:03:29852// Reload current focused frame.
853// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28854void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29855 if (webview() && webview()->focusedFrame()) {
856 // We always obey the cache (ignore_cache=false) here.
857 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
858 // a cache-ignoring reload of the frame.
859 webview()->focusedFrame()->reload(false);
860 }
[email protected]1dda4022010-01-28 18:24:56861}
862
[email protected]310ebd6302011-10-10 19:06:28863void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27864 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29865}
866
[email protected]310ebd6302011-10-10 19:06:28867void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:25868 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27869 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25870 return;
871
[email protected]26aa0482009-09-30 16:55:27872 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45873 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25874}
875
[email protected]310ebd6302011-10-10 19:06:28876void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:29877 // Check if there is a targeturl waiting to be sent.
878 if (target_url_status_ == TARGET_PENDING) {
879 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
880 pending_target_url_));
881 }
882
883 target_url_status_ = TARGET_NONE;
884}
885
[email protected]310ebd6302011-10-10 19:06:28886void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:29887 if (!webview())
888 return;
889
[email protected]26aa0482009-09-30 16:55:27890 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29891}
892
[email protected]310ebd6302011-10-10 19:06:28893void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:29894 if (!webview())
895 return;
896
[email protected]26aa0482009-09-30 16:55:27897 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29898}
899
[email protected]310ebd6302011-10-10 19:06:28900void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:29901 if (!webview())
902 return;
903
[email protected]26aa0482009-09-30 16:55:27904 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29905}
906
[email protected]310ebd6302011-10-10 19:06:28907void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:29908 if (!webview())
909 return;
910
[email protected]f6b1856b2011-06-29 22:02:53911 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
912 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29913}
914
[email protected]c0cc3092009-09-12 08:27:27915#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:28916void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:35917 if (!webview())
918 return;
919
920 // Since the find pasteboard supports only plain text, this can be simpler
921 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27922 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35923 if (frame->hasSelection()) {
924 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:27925 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:17926 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35927 }
[email protected]a954bf72009-09-12 07:30:35928}
[email protected]c0cc3092009-09-12 08:27:27929#endif
[email protected]a954bf72009-09-12 07:30:35930
[email protected]310ebd6302011-10-10 19:06:28931void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:29932 if (!webview())
933 return;
934
[email protected]26aa0482009-09-30 16:55:27935 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29936}
937
[email protected]44bf7002011-10-16 02:46:15938void RenderViewImpl::OnPasteAndMatchStyle() {
939 if (!webview())
940 return;
941
942 webview()->focusedFrame()->executeCommand(
943 WebString::fromUTF8("PasteAndMatchStyle"));
944}
945
[email protected]310ebd6302011-10-10 19:06:28946void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29947 if (!webview())
948 return;
949
[email protected]1ff7a032010-02-03 02:46:03950 WebFrame* frame = webview()->focusedFrame();
951 if (!frame->hasSelection())
952 frame->selectWordAroundCaret();
953 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29954}
955
[email protected]310ebd6302011-10-10 19:06:28956void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:29957 if (!webview())
958 return;
959
[email protected]26aa0482009-09-30 16:55:27960 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29961}
962
[email protected]310ebd6302011-10-10 19:06:28963void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:29964 if (!webview())
965 return;
966
[email protected]26aa0482009-09-30 16:55:27967 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22968 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29969}
970
[email protected]310ebd6302011-10-10 19:06:28971void RenderViewImpl::OnSelectRange(const gfx::Point& start,
972 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:08973 if (!webview())
974 return;
975
976 handling_select_range_ = true;
977 webview()->focusedFrame()->selectRange(start, end);
978 handling_select_range_ = false;
979}
980
[email protected]310ebd6302011-10-10 19:06:28981void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
982 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:19983 DCHECK(history_length >= 0);
984 DCHECK(history_list_offset_ == history_list_length_ - 1);
985 DCHECK(minimum_page_id >= -1);
986
987 // Generate the new list.
988 std::vector<int32> new_history_page_ids(history_length, -1);
989 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
990 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
991 continue;
992 new_history_page_ids.push_back(history_page_ids_[i]);
993 }
994 new_history_page_ids.swap(history_page_ids_);
995
996 // Update indexes.
997 history_list_length_ = history_page_ids_.size();
998 history_list_offset_ = history_list_length_ - 1;
999}
1000
1001
[email protected]310ebd6302011-10-10 19:06:281002void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291003 if (!webview())
1004 return;
[email protected]26aa0482009-09-30 16:55:271005 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291006}
1007
[email protected]54ca3ca892011-06-07 21:14:541008#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281009void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331010 if (!webview())
1011 return;
1012 if (in_live_resize)
1013 webview()->willStartLiveResize();
1014 else
1015 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541016}
1017#endif
1018
[email protected]310ebd6302011-10-10 19:06:281019void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1020 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091021 WebKit::WebNode node = GetFocusedNode();
1022 if (!node.isNull()) {
1023 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191024 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511025 }
1026}
1027
initial.commit09911bf2008-07-26 23:55:291028///////////////////////////////////////////////////////////////////////////////
1029
1030// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281031void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451032 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291033 DCHECK(ds);
1034
[email protected]726985e22009-06-18 21:09:281035 const WebURLRequest& request = ds->request();
1036 const WebURLRequest& original_request = ds->originalRequest();
1037 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291038
[email protected]007733c2011-11-17 00:34:071039 DocumentState* document_state = DocumentState::FromDataSource(ds);
1040 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291041
1042 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281043 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291044 params.is_post = false;
1045 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071046 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191047 params.socket_address.set_host(response.remoteIPAddress().utf8());
1048 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031049 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091050 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071051 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291052 // SSL state specified in the request takes precedence over the one in the
1053 // response.
1054 // So far this is only intended for error pages that are not expected to be
1055 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281056 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071057 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291058 } else {
[email protected]726985e22009-06-18 21:09:281059 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291060 }
1061
1062 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281063 if (ds->hasUnreachableURL()) {
1064 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291065 } else {
[email protected]726985e22009-06-18 21:09:281066 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291067 }
1068
[email protected]5f9b8712011-11-23 08:55:571069 if (frame->document().baseURL() != params.url)
1070 params.base_url = frame->document().baseURL();
1071
[email protected]726985e22009-06-18 21:09:281072 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241073 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041074 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291075
[email protected]007733c2011-11-17 00:34:071076 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351077 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071078 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291079
1080 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071081 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291082 if (password_form_data)
1083 params.password_form = *password_form_data;
1084
1085 params.gesture = navigation_gesture_;
1086 navigation_gesture_ = NavigationGestureUnknown;
1087
[email protected]0f38dc4552011-02-25 11:24:001088 // Make navigation state a part of the FrameNavigate message so that commited
1089 // entry had it at all times.
1090 const WebHistoryItem& item = frame->currentHistoryItem();
1091 if (!item.isNull()) {
1092 params.content_state = webkit_glue::HistoryItemToString(item);
1093 } else {
1094 params.content_state =
1095 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1096 }
1097
[email protected]dd7daa82009-08-10 05:46:451098 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291099 // Top-level navigation.
1100
[email protected]b75b8292010-10-01 07:28:251101 // Set zoom level, but don't do it for full-page plugin since they don't use
1102 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011103 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541104 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251105 if (webview()->mainFrame()->document().isPluginDocument()) {
1106 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251107 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251108 } else {
1109 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251110 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251111 }
1112
[email protected]f85f0702010-01-30 09:31:011113 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511114 // This zoom level was merely recorded transiently for this load. We can
1115 // erase it now. If at some point we reload this page, the browser will
1116 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011117 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511118 }
1119
[email protected]b75b8292010-10-01 07:28:251120 // Reset the zoom limits in case a plugin had changed them previously. This
1121 // will also call us back which will cause us to send a message to
1122 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251123 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011124 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1125 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251126
initial.commit09911bf2008-07-26 23:55:291127 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551128 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291129
[email protected]daa8c58e2009-06-15 17:21:101130 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581131 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291132 // If the main frame does a load, it should not be reported as a subframe
1133 // navigation. This can occur in the following case:
1134 // 1. You're on a site with frames.
1135 // 2. You do a subframe navigation. This is stored with transition type
1136 // MANUAL_SUBFRAME.
1137 // 3. You navigate to some non-frame site, say, google.com.
1138 // 4. You navigate back to the page from step 2. Since it was initially
1139 // MANUAL_SUBFRAME, it will be that same transition type here.
1140 // We don't want that, because any navigation that changes the toplevel
1141 // frame should be tracked as a toplevel navigation (this allows us to
1142 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581143 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291144 }
1145
initial.commit09911bf2008-07-26 23:55:291146 // If we have a valid consumed client redirect source,
1147 // the page contained a client redirect (meta refresh, document.loc...),
1148 // so we set the referrer and transition to match.
[email protected]445e1042011-12-03 21:03:151149 if (completed_client_redirect_src_.url.is_valid()) {
1150 DCHECK(completed_client_redirect_src_.url == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291151 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581152 params.transition = static_cast<content::PageTransition>(
1153 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291154 } else {
1155 // Bug 654101: the referrer will be empty on https->http transitions. It
1156 // would be nice if we could get the real referrer from somewhere.
[email protected]445e1042011-12-03 21:03:151157 params.referrer = Referrer(GURL(
1158 original_request.httpHeaderField(WebString::fromUTF8("Referer"))),
1159 getReferrerPolicyFromRequest(original_request));
initial.commit09911bf2008-07-26 23:55:291160 }
1161
[email protected]726985e22009-06-18 21:09:281162 string16 method = request.httpMethod();
1163 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291164 params.is_post = true;
1165
[email protected]c2a797d2009-09-21 16:46:321166 // Save some histogram data so we can compute the average memory used per
1167 // page load of the glyphs.
1168 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1169 webkit_glue::GetGlyphPageCount());
1170
[email protected]15cf526b2010-02-12 06:33:491171 // This message needs to be sent before any of allowScripts(),
1172 // allowImages(), allowPlugins() is called for the new page, so that when
1173 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1174 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291175 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1176 } else {
1177 // Subframe navigation: the type depends on whether this navigation
1178 // generated a new session history entry. When they do generate a session
1179 // history entry, it means the user initiated the navigation and we should
1180 // mark it as such. This test checks if this is the first time UpdateURL
1181 // has been called since WillNavigateToURL was called to initiate the load.
1182 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581183 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291184 else
[email protected]2905f742011-10-13 03:51:581185 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291186
initial.commit09911bf2008-07-26 23:55:291187 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1188 }
1189
1190 last_page_id_sent_to_browser_ =
1191 std::max(last_page_id_sent_to_browser_, page_id_);
1192
1193 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101194 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581195 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291196}
1197
1198// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281199void RenderViewImpl::UpdateTitle(WebFrame* frame,
1200 const string16& title,
1201 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461202 // Ignore all but top level navigations.
1203 if (frame->parent())
1204 return;
1205
1206 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1207 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1208 title_direction));
initial.commit09911bf2008-07-26 23:55:291209}
1210
[email protected]310ebd6302011-10-10 19:06:281211void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1212 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291213 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271214 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291215 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301216 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291217 last_encoding_name_ = encoding_name;
1218
[email protected]e38f40152008-09-12 23:08:301219 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291220 }
1221}
1222
[email protected]e15f680732010-11-23 22:30:201223// Sends the last committed session history state to the browser so it will be
1224// saved before we navigate to a new page. This must be called *before* the
1225// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281226void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291227 // If we have a valid page ID at this point, then it corresponds to the page
1228 // we are navigating away from. Otherwise, this is the first navigation, so
1229 // there is no past session history to record.
1230 if (page_id_ == -1)
1231 return;
1232
[email protected]ca948a22009-06-25 19:36:171233 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271234 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171235 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291236 return;
[email protected]ca948a22009-06-25 19:36:171237
1238 Send(new ViewHostMsg_UpdateState(
1239 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291240}
1241
[email protected]310ebd6302011-10-10 19:06:281242void RenderViewImpl::OpenURL(WebFrame* frame,
1243 const GURL& url,
[email protected]445e1042011-12-03 21:03:151244 const Referrer& referrer,
[email protected]310ebd6302011-10-10 19:06:281245 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171246 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581247 routing_id_,
1248 url,
1249 referrer,
1250 NavigationPolicyToDisposition(policy),
1251 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171252}
1253
[email protected]79dbc662009-09-04 05:42:511254// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291255
[email protected]310ebd6302011-10-10 19:06:281256void RenderViewImpl::LoadNavigationErrorPage(
1257 WebFrame* frame,
1258 const WebURLRequest& failed_request,
1259 const WebURLError& error,
1260 const std::string& html,
1261 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581262 std::string alt_html;
1263 const std::string* error_html;
1264
1265 if (!html.empty()) {
1266 error_html = &html;
1267 } else {
1268 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1269 failed_request, error, &alt_html, NULL);
1270 error_html = &alt_html;
1271 }
1272
1273 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361274 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251275 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551276 replace);
initial.commit09911bf2008-07-26 23:55:291277}
1278
[email protected]269f86d2011-12-07 02:43:471279bool RenderViewImpl::RunJavaScriptMessage(ui::JavascriptMessageType type,
[email protected]310ebd6302011-10-10 19:06:281280 const string16& message,
1281 const string16& default_value,
1282 const GURL& frame_url,
1283 string16* result) {
initial.commit09911bf2008-07-26 23:55:291284 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411285 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291286 if (!result)
1287 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291288
[email protected]12636df2009-09-28 22:32:211289 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1290 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291291 return success;
1292}
1293
[email protected]310ebd6302011-10-10 19:06:281294bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571295 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1296 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1297 // it is particularly important that we do not call willEnterModalLoop as
1298 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441299 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1300 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571301
1302 message->EnableMessagePumping(); // Runs a nested message loop.
1303 return Send(message);
1304}
1305
[email protected]48c9cf2d2009-09-16 16:47:521306// WebKit::WebViewClient ------------------------------------------------------
1307
[email protected]310ebd6302011-10-10 19:06:281308WebView* RenderViewImpl::createView(
[email protected]844acf372011-01-14 10:49:271309 WebFrame* creator,
1310 const WebURLRequest& request,
1311 const WebWindowFeatures& features,
1312 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521313 // Check to make sure we aren't overloading on popups.
1314 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1315 return NULL;
1316
[email protected]8ab04652010-06-12 02:47:261317 ViewHostMsg_CreateWindow_Params params;
1318 params.opener_id = routing_id_;
1319 params.user_gesture = creator->isProcessingUserGesture();
1320 params.window_container_type = WindowFeaturesToContainerType(features);
1321 params.session_storage_namespace_id = session_storage_namespace_id_;
1322 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111323 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411324 params.opener_url = creator->document().url();
1325 params.opener_security_origin =
1326 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111327 if (!request.isNull())
1328 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261329
[email protected]48c9cf2d2009-09-16 16:47:521330 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341331 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261332 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521333
[email protected]380244092011-10-07 17:26:271334 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261335 new ViewHostMsg_CreateWindow(params,
1336 &routing_id,
1337 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211338 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521339 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521340
[email protected]310ebd6302011-10-10 19:06:281341 RenderViewImpl* view = RenderViewImpl::Create(
1342 0,
1343 routing_id_,
1344 renderer_preferences_,
1345 webkit_preferences_,
1346 shared_popup_counter_,
1347 routing_id,
1348 cloned_session_storage_namespace_id,
[email protected]74ce1ad2011-12-16 21:51:461349 frame_name,
1350 1);
[email protected]8ab04652010-06-12 02:47:261351 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521352
[email protected]007a848b2009-10-26 15:55:461353 // Record whether the creator frame is trying to suppress the opener field.
1354 view->opener_suppressed_ = opener_suppressed;
1355
[email protected]48c9cf2d2009-09-16 16:47:521356 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411357 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521358 if (!creator_url.is_valid() || !creator_url.IsStandard())
1359 creator_url = GURL();
1360 view->creator_url_ = creator_url;
1361
1362 // Copy over the alternate error page URL so we can have alt error pages in
1363 // the new render view (we don't need the browser to send the URL back down).
1364 view->alternate_error_page_url_ = alternate_error_page_url_;
1365
1366 return view->webview();
1367}
1368
[email protected]310ebd6302011-10-10 19:06:281369WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]380244092011-10-07 17:26:271370 RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521371 return widget->webwidget();
1372}
1373
[email protected]310ebd6302011-10-10 19:06:281374WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441375 // TODO(jcivelli): Remove this deprecated method when its been removed from
1376 // the WebViewClient interface. It's been replaced by
1377 // createExternalPopupMenu.
1378 NOTREACHED();
1379 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521380}
1381
[email protected]310ebd6302011-10-10 19:06:281382WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081383 const WebPopupMenuInfo& popup_menu_info,
1384 WebExternalPopupMenuClient* popup_menu_client) {
1385 DCHECK(!external_popup_menu_.get());
1386 external_popup_menu_.reset(
1387 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1388 return external_popup_menu_.get();
1389}
1390
[email protected]310ebd6302011-10-10 19:06:281391RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521392 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531393 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421394 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411395 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531396 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271397 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391398 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561399 return widget;
[email protected]79c7bed2010-09-14 22:28:391400}
1401
[email protected]310ebd6302011-10-10 19:06:281402WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1403 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341404 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391405 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291406 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1407 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1408 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341409}
1410
[email protected]310ebd6302011-10-10 19:06:281411void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521412 const WebConsoleMessage& message, const WebString& source_name,
1413 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081414 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511415 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081416 case WebConsoleMessage::LevelTip:
1417 log_severity = logging::LOG_VERBOSE;
1418 break;
1419 case WebConsoleMessage::LevelLog:
1420 log_severity = logging::LOG_INFO;
1421 break;
1422 case WebConsoleMessage::LevelWarning:
1423 log_severity = logging::LOG_WARNING;
1424 break;
1425 case WebConsoleMessage::LevelError:
1426 log_severity = logging::LOG_ERROR;
1427 break;
1428 default:
1429 NOTREACHED();
1430 }
1431
[email protected]48c9cf2d2009-09-16 16:47:521432 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081433 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311434 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521435 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311436 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521437}
1438
[email protected]310ebd6302011-10-10 19:06:281439void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421440 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521441}
1442
[email protected]310ebd6302011-10-10 19:06:281443WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511444 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021445}
1446
[email protected]310ebd6302011-10-10 19:06:281447bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121448 const WebString& path,
1449 WebFileChooserCompletion* chooser_completion) {
1450 int id = enumeration_completion_id_++;
1451 enumeration_completions_[id] = chooser_completion;
1452 return Send(new ViewHostMsg_EnumerateDirectory(
1453 routing_id_,
1454 id,
1455 webkit_glue::WebStringToFilePath(path)));
1456}
1457
[email protected]310ebd6302011-10-10 19:06:281458void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521459 if (is_loading_) {
1460 DLOG(WARNING) << "didStartLoading called while loading";
1461 return;
1462 }
1463
1464 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521465
1466 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311467
1468 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521469}
1470
[email protected]310ebd6302011-10-10 19:06:281471void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521472 if (!is_loading_) {
1473 DLOG(WARNING) << "DidStopLoading called while not loading";
1474 return;
1475 }
1476
1477 is_loading_ = false;
1478
1479 // NOTE: For now we're doing the safest thing, and sending out notification
1480 // when done loading. This currently isn't an issue as the favicon is only
1481 // displayed when done loading. Ideally we would send notification when
1482 // finished parsing the head, but webkit doesn't support that yet.
1483 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521484 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1485
[email protected]90109412010-12-15 17:14:241486 if (load_progress_tracker_ != NULL)
1487 load_progress_tracker_->DidStopLoading();
1488
[email protected]93b9d692011-04-13 00:44:311489 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521490}
1491
[email protected]310ebd6302011-10-10 19:06:281492void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1493 double load_progress) {
[email protected]90109412010-12-15 17:14:241494 if (load_progress_tracker_ != NULL)
1495 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1496}
1497
[email protected]310ebd6302011-10-10 19:06:281498bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061499#if defined(OS_MACOSX)
1500 return true;
1501#else
1502 return false;
1503#endif
1504}
1505
[email protected]310ebd6302011-10-10 19:06:281506bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031507#if defined(OS_WIN)
1508 return true;
1509#else
1510 return false;
1511#endif
1512}
1513
[email protected]310ebd6302011-10-10 19:06:281514void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081515 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031516 return;
[email protected]4fb60142011-08-09 02:22:081517 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011518
[email protected]b781ff282011-08-20 06:19:361519 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031520}
1521
[email protected]310ebd6302011-10-10 19:06:281522void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121523 const std::string& name = UTF16ToUTF8(command_name);
1524 if (StartsWithASCII(name, "Move", true) ||
1525 StartsWithASCII(name, "Insert", true) ||
1526 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031527 return;
[email protected]f1a29a02011-10-06 23:08:441528 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031529}
1530
[email protected]310ebd6302011-10-10 19:06:281531bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101532 if (edit_commands_.empty())
1533 return false;
1534
[email protected]26aa0482009-09-30 16:55:271535 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101536 if (!frame)
1537 return false;
1538
1539 EditCommands::iterator it = edit_commands_.begin();
1540 EditCommands::iterator end = edit_commands_.end();
1541
[email protected]507b33ea2009-09-29 03:56:511542 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101543 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331544 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1545 // key (but it's the exception). Once one edit command is not executed, it
1546 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101547 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1548 WebString::fromUTF8(it->value)))
1549 break;
[email protected]507b33ea2009-09-29 03:56:511550 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101551 }
1552
[email protected]507b33ea2009-09-29 03:56:511553 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101554}
1555
[email protected]310ebd6302011-10-10 19:06:281556bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351557 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471558 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351559 // Do not open the file dialog in a hidden RenderView.
1560 if (is_hidden())
1561 return false;
[email protected]8caadeb2011-11-22 02:45:231562 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261563 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231564 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261565 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231566 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501567 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231568 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261569 else
[email protected]8caadeb2011-11-22 02:45:231570 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471571 ipc_params.title = params.title;
1572 ipc_params.default_file_name =
1573 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461574 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1575 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1576 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471577
1578 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461579}
1580
[email protected]269f86d2011-12-07 02:43:471581void RenderViewImpl::runModalAlertDialog(WebFrame* frame,
1582 const WebString& message) {
1583 RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_ALERT,
[email protected]4f5ce842011-05-27 19:34:411584 message,
1585 string16(),
[email protected]b6cb3a842011-06-24 18:28:411586 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521587 NULL);
1588}
1589
[email protected]269f86d2011-12-07 02:43:471590bool RenderViewImpl::runModalConfirmDialog(WebFrame* frame,
1591 const WebString& message) {
1592 return RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
[email protected]4f5ce842011-05-27 19:34:411593 message,
1594 string16(),
[email protected]b6cb3a842011-06-24 18:28:411595 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521596 NULL);
1597}
1598
[email protected]269f86d2011-12-07 02:43:471599bool RenderViewImpl::runModalPromptDialog(WebFrame* frame,
1600 const WebString& message,
1601 const WebString& default_value,
1602 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411603 string16 result;
[email protected]269f86d2011-12-07 02:43:471604 bool ok = RunJavaScriptMessage(ui::JAVASCRIPT_MESSAGE_TYPE_PROMPT,
[email protected]4f5ce842011-05-27 19:34:411605 message,
1606 default_value,
[email protected]b6cb3a842011-06-24 18:28:411607 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521608 &result);
1609 if (ok)
[email protected]4f5ce842011-05-27 19:34:411610 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521611 return ok;
1612}
1613
[email protected]310ebd6302011-10-10 19:06:281614bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521615 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151616 // If we are swapping out, we have already run the beforeunload handler.
1617 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1618 // at all, to avoid running it twice.
1619 if (is_swapped_out_)
1620 return true;
1621
[email protected]48c9cf2d2009-09-16 16:47:521622 bool success = false;
1623 // This is an ignored return value, but is included so we can accept the same
1624 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411625 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211626 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411627 routing_id_, frame->document().url(), message,
1628 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521629 return success;
1630}
1631
[email protected]310ebd6302011-10-10 19:06:281632void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441633 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291634 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371635
1636 // frame is NULL if invoked by BlockedPlugin.
1637 if (frame)
1638 params.frame_id = frame->identifier();
1639
[email protected]db803aae2011-03-05 02:00:421640 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271641 // it. We replace it with an empty GURL so the appropriate items are disabled
1642 // in the context menu.
1643 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1644 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421645 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271646 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101647 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291648 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441649}
1650
[email protected]310ebd6302011-10-10 19:06:281651void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261652 // TODO(darin): Remove once WebKit roll is complete.
1653 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471654}
1655
[email protected]310ebd6302011-10-10 19:06:281656void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261657 // TODO(darin): Remove once WebKit roll is complete.
1658 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471659}
1660
[email protected]310ebd6302011-10-10 19:06:281661void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521662}
1663
[email protected]310ebd6302011-10-10 19:06:281664void RenderViewImpl::UpdateTargetURL(const GURL& url,
1665 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581666 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521667 if (latest_url == target_url_)
1668 return;
[email protected]163f8242009-10-30 20:19:551669
[email protected]48c9cf2d2009-09-16 16:47:521670 // Tell the browser to display a destination link.
1671 if (target_url_status_ == TARGET_INFLIGHT ||
1672 target_url_status_ == TARGET_PENDING) {
1673 // If we have a request in-flight, save the URL to be sent when we
1674 // receive an ACK to the in-flight request. We can happily overwrite
1675 // any existing pending sends.
1676 pending_target_url_ = latest_url;
1677 target_url_status_ = TARGET_PENDING;
1678 } else {
[email protected]c85f0212011-11-04 16:54:411679 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1680 // see |ParamTraits<GURL>|.
1681 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1682 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521683 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1684 target_url_ = latest_url;
1685 target_url_status_ = TARGET_INFLIGHT;
1686 }
1687}
1688
[email protected]310ebd6302011-10-10 19:06:281689void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311690 int delay;
1691 if (send_content_state_immediately_)
1692 delay = 0;
1693 else if (is_hidden())
1694 delay = kDelaySecondsForContentStateSyncHidden;
1695 else
1696 delay = kDelaySecondsForContentStateSync;
1697
1698 if (nav_state_sync_timer_.IsRunning()) {
1699 // The timer is already running. If the delay of the timer maches the amount
1700 // we want to delay by, then return. Otherwise stop the timer so that it
1701 // gets started with the right delay.
1702 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1703 return;
1704 nav_state_sync_timer_.Stop();
1705 }
1706
[email protected]d323a172011-09-02 18:23:021707 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281708 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311709}
1710
[email protected]310ebd6302011-10-10 19:06:281711void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551712 mouse_over_url_ = GURL(url);
1713 UpdateTargetURL(mouse_over_url_, focus_url_);
1714}
1715
[email protected]310ebd6302011-10-10 19:06:281716void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551717 focus_url_ = GURL(url);
1718 UpdateTargetURL(focus_url_, mouse_over_url_);
1719}
1720
[email protected]310ebd6302011-10-10 19:06:281721void RenderViewImpl::startDragging(const WebDragData& data,
1722 WebDragOperationsMask mask,
1723 const WebImage& image,
1724 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411725#if WEBKIT_USING_SKIA
1726 SkBitmap bitmap(image.getSkBitmap());
1727#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331728 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411729#endif
1730
[email protected]59f4f2fa2011-03-23 01:00:551731 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521732 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411733 mask,
1734 bitmap,
1735 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521736}
1737
[email protected]310ebd6302011-10-10 19:06:281738bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451739 return renderer_preferences_.can_accept_load_drops;
1740}
1741
[email protected]310ebd6302011-10-10 19:06:281742void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521743 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1744}
1745
[email protected]310ebd6302011-10-10 19:06:281746void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521747 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1748}
1749
[email protected]310ebd6302011-10-10 19:06:281750void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511751 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071752
[email protected]38b592902011-04-16 02:08:421753 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491754}
1755
[email protected]169d4282011-11-30 19:33:591756void RenderViewImpl::didUpdateLayout() {
1757 // We don't always want to set up a timer, only if we've been put in that
1758 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
1759 // message.
1760 if (!send_preferred_size_changes_ || !webview())
1761 return;
1762
1763 if (check_preferred_size_timer_.IsRunning())
1764 return;
1765 check_preferred_size_timer_.Start(FROM_HERE,
1766 TimeDelta::FromMilliseconds(0), this,
1767 &RenderViewImpl::CheckPreferredSize);
1768}
1769
[email protected]310ebd6302011-10-10 19:06:281770void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521771 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1772}
1773
[email protected]310ebd6302011-10-10 19:06:281774int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001775 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521776}
1777
[email protected]310ebd6302011-10-10 19:06:281778int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001779 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521780}
1781
[email protected]310ebd6302011-10-10 19:06:281782void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321783 const WebAccessibilityObject& obj,
1784 WebAccessibilityNotification notification) {
1785 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1786}
1787
[email protected]310ebd6302011-10-10 19:06:281788void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141789 const WebString& value) {
1790 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1791 key.utf8(),
1792 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261793}
1794
[email protected]79dbc662009-09-04 05:42:511795// WebKit::WebWidgetClient ----------------------------------------------------
1796
[email protected]310ebd6302011-10-10 19:06:281797void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121798 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1799 // we won't have to test for user gesture anymore and we can
1800 // move that code back to render_widget.cc
1801 if (webview() && webview()->mainFrame() &&
1802 webview()->mainFrame()->isProcessingUserGesture()) {
1803 Send(new ViewHostMsg_Focus(routing_id_));
1804 }
1805}
1806
[email protected]310ebd6302011-10-10 19:06:281807void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121808 // TODO(jcivelli): see TODO above in didFocus().
1809 if (webview() && webview()->mainFrame() &&
1810 webview()->mainFrame()->isProcessingUserGesture()) {
1811 Send(new ViewHostMsg_Blur(routing_id_));
1812 }
1813}
1814
initial.commit09911bf2008-07-26 23:55:291815// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281816// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291817// point to dispatch the ShowView message.
1818//
1819// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281820// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291821//
[email protected]310ebd6302011-10-10 19:06:281822void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291823 DCHECK(!did_show_) << "received extraneous Show call";
1824 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1825
1826 if (did_show_)
1827 return;
1828 did_show_ = true;
1829
[email protected]6779aa12011-03-29 17:32:241830 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041831 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041832
[email protected]28295ec2009-10-16 05:34:331833 // Force new windows to a popup if they were not opened with a user gesture.
1834 if (!opened_by_user_gesture_) {
1835 // We exempt background tabs for compat with older versions of Chrome.
1836 // TODO(darin): This seems bogus. These should have a user gesture, so
1837 // we probably don't need this check.
1838 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1839 policy = WebKit::WebNavigationPolicyNewPopup;
1840 }
1841
initial.commit09911bf2008-07-26 23:55:291842 // NOTE: initial_pos_ may still have its default values at this point, but
1843 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1844 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281845 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1846 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291847 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241848 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291849}
1850
[email protected]310ebd6302011-10-10 19:06:281851void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:291852 DCHECK(did_show_) << "should already have shown the view";
1853
[email protected]c1f50aa2010-02-18 03:46:571854 // We must keep WebKit's shared timer running in this case in order to allow
1855 // showModalDialog to function properly.
1856 //
1857 // TODO(darin): WebKit should really be smarter about suppressing events and
1858 // timers so that we do not need to manage the shared timer in such a heavy
1859 // handed manner.
1860 //
[email protected]f1a29a02011-10-06 23:08:441861 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1862 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:571863
[email protected]12636df2009-09-28 22:32:211864 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291865}
1866
[email protected]2b624c562011-10-27 22:58:261867bool RenderViewImpl::enterFullScreen() {
1868 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1869 return true;
1870}
1871
1872void RenderViewImpl::exitFullScreen() {
1873 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1874}
1875
[email protected]3d9689372009-09-10 04:29:171876// WebKit::WebFrameClient -----------------------------------------------------
1877
[email protected]310ebd6302011-10-10 19:06:281878WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
1879 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:551880 WebPlugin* plugin = NULL;
1881 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
1882 this, frame, params, &plugin)) {
1883 return plugin;
1884 }
1885
[email protected]a813c8e2011-10-08 01:34:111886 webkit::WebPluginInfo info;
1887 std::string mime_type;
1888 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
1889 params.mimeType.utf8(), &info, &mime_type);
1890 if (!found)
1891 return NULL;
1892
1893 WebPluginParams params_to_use = params;
1894 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:311895 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:171896}
1897
[email protected]310ebd6302011-10-10 19:06:281898WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:421899 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371900 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421901
[email protected]30447b62009-11-13 01:13:371902 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511903 bool exists = false;
[email protected]30447b62009-11-13 01:13:371904 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511905 ViewHostMsg_CreateWorker_Params params;
1906 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:511907 params.name = name;
1908 params.document_id = document_id;
1909 params.render_view_route_id = routing_id_;
1910 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231911 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371912 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511913 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371914 if (url_mismatch) {
1915 return NULL;
1916 } else {
[email protected]f1a29a02011-10-06 23:08:441917 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:491918 document_id,
[email protected]6de0bcf2010-02-17 22:00:511919 exists,
[email protected]30447b62009-11-13 01:13:371920 route_id,
1921 routing_id_);
1922 }
[email protected]9c00f002009-11-05 22:37:421923}
1924
[email protected]310ebd6302011-10-10 19:06:281925WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:171926 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441927 FOR_EACH_OBSERVER(
1928 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171929
[email protected]bb6fd402011-12-09 02:45:441930 media::MessageLoopFactory* message_loop_factory =
1931 new media::MessageLoopFactoryImpl();
1932 media::FilterCollection* collection = new media::FilterCollection();
1933 RenderMediaLog* render_media_log = new RenderMediaLog();
[email protected]457d8342010-10-23 01:20:371934
[email protected]3d9689372009-09-10 04:29:171935 // Add in any custom filter factories first.
1936 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1937 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1938 // Add the chrome specific audio renderer.
[email protected]f7eb0a392011-07-12 10:19:511939 collection->AddAudioRenderer(new AudioRendererImpl());
[email protected]3d9689372009-09-10 04:29:171940 }
1941
[email protected]e1d69d762011-12-13 05:12:181942#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
1943 // Currently only cros/arm has any HW video decode support in
1944 // GpuVideoDecodeAccelerator so we don't even try to use it on other
1945 // platforms. This is a startup-time optimization. When new VDA
1946 // implementations are added, relax the #if above.
1947 WebKit::WebGraphicsContext3D* wk_context3d = webview()->graphicsContext3D();
1948 if (wk_context3d) {
1949 WebGraphicsContext3DCommandBufferImpl* context3d =
1950 static_cast<WebGraphicsContext3DCommandBufferImpl*>(wk_context3d);
1951 GpuChannelHost* gpu_channel_host =
1952 RenderThreadImpl::current()->EstablishGpuChannelSync(
1953 content::CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
1954 collection->AddVideoDecoder(new media::GpuVideoDecoder(
1955 MessageLoop::current(),
1956 new RendererGpuVideoDecoderFactories(
1957 gpu_channel_host, context3d->context()->AsWeakPtr())));
1958 }
1959#endif
1960
[email protected]bb6fd402011-12-09 02:45:441961 webkit_media::WebMediaPlayerImpl* result_ptr;
1962 if (!content::GetContentClient()->renderer()->OverrideCreateWebMediaPlayer(
1963 this, client, AsWeakPtr(), collection, message_loop_factory,
1964 media_stream_impl_.get(), render_media_log, &result_ptr)) {
1965 result_ptr = new webkit_media::WebMediaPlayerImpl(
1966 client, AsWeakPtr(), collection, message_loop_factory,
1967 media_stream_impl_.get(), render_media_log);
1968 }
1969
1970 DCHECK(result_ptr);
1971 scoped_ptr<webkit_media::WebMediaPlayerImpl> result;
1972 result.reset(result_ptr);
1973
[email protected]79684282010-12-06 21:15:461974 if (!result->Initialize(frame,
[email protected]86b3f4b2011-11-18 23:52:461975 cmd_line->HasSwitch(switches::kSimpleDataSource))) {
[email protected]a8e24d522010-12-01 07:13:581976 return NULL;
1977 }
1978 return result.release();
[email protected]3d9689372009-09-10 04:29:171979}
1980
[email protected]310ebd6302011-10-10 19:06:281981WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:211982 WebFrame* frame, WebApplicationCacheHostClient* client) {
1983 return new RendererWebApplicationCacheHostImpl(
1984 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:441985 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:211986}
1987
[email protected]310ebd6302011-10-10 19:06:281988WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:381989 return &cookie_jar_;
1990}
1991
[email protected]310ebd6302011-10-10 19:06:281992void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511993 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451994}
1995
[email protected]310ebd6302011-10-10 19:06:281996void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511997 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171998}
1999
[email protected]310ebd6302011-10-10 19:06:282000void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:172001 WebFrame* frame, const WebURLRequest& request,
2002 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342003 loadURLExternally(frame, request, policy, WebString());
2004}
2005
[email protected]310ebd6302011-10-10 19:06:282006void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:342007 WebFrame* frame, const WebURLRequest& request,
2008 WebNavigationPolicy policy,
2009 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592010 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2011 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342012 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2013 suggested_name));
[email protected]efce17b2009-09-11 18:04:592014 } else {
[email protected]445e1042011-12-03 21:03:152015 OpenURL(frame, request.url(),
2016 Referrer(referrer, getReferrerPolicyFromRequest(request)), policy);
[email protected]efce17b2009-09-11 18:04:592017 }
[email protected]3d9689372009-09-10 04:29:172018}
2019
[email protected]310ebd6302011-10-10 19:06:282020WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172021 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222022 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152023 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2024 if (is_swapped_out_) {
2025 DCHECK(request.url() == GURL("about:swappedout"));
2026 return default_policy;
2027 }
2028
[email protected]3d9689372009-09-10 04:29:172029 // Webkit is asking whether to navigate to a new URL.
2030 // This is fine normally, except if we're showing UI from one security
2031 // context and they're trying to navigate to a different context.
2032 const GURL& url = request.url();
2033
[email protected]d19ea342011-04-20 20:31:132034 // A content initiated navigation may have originated from a link-click,
2035 // script, drag-n-drop operation, etc.
2036 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:072037 DocumentState::FromDataSource(frame->provisionalDataSource())->
2038 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:132039
[email protected]a8c269a2011-10-25 20:17:222040 // Experimental:
2041 // If --enable-strict-site-isolation is enabled, send all top-level
2042 // navigations to the browser to let it swap processes when crossing site
2043 // boundaries. This is currently expected to break some script calls and
2044 // navigations, such as form submissions.
2045 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:102046 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
2047 !frame->parent() && (is_content_initiated || is_redirect)) {
2048 WebString origin_str = frame->document().securityOrigin().toString();
2049 GURL frame_url(origin_str.utf8().data());
2050 // TODO(cevans): revisit whether this origin check is still necessary once
2051 // crbug.com/101395 is fixed.
2052 if (frame_url.GetOrigin() != url.GetOrigin()) {
[email protected]445e1042011-12-03 21:03:152053 Referrer referrer(
2054 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2055 getReferrerPolicyFromRequest(request));
[email protected]313b80bd2011-11-23 03:49:102056 OpenURL(frame, url, referrer, default_policy);
2057 return WebKit::WebNavigationPolicyIgnore;
2058 }
[email protected]a8c269a2011-10-25 20:17:222059 }
2060
[email protected]3d9689372009-09-10 04:29:172061 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302062 // navigations.
[email protected]d19ea342011-04-20 20:31:132063 if (is_content_initiated &&
2064 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:452065 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]445e1042011-12-03 21:03:152066 Referrer referrer(
2067 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2068 getReferrerPolicyFromRequest(request));
[email protected]a58db8b2010-08-24 01:51:232069 // Reset these counters as the RenderView could be reused for the next
2070 // navigation.
2071 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232072 last_page_id_sent_to_browser_ = -1;
[email protected]ae5184d62011-10-06 19:25:582073 OpenURL(frame, url, referrer, default_policy);
[email protected]61c9f032010-03-31 23:04:192074 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172075 }
2076
[email protected]6101c342010-12-16 22:44:372077 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552078 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572079 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372080 // opening a new window). But we sometimes navigate to about:blank to clear a
2081 // tab, and we want to still allow that.
2082 //
[email protected]8f4da8c2011-02-09 19:49:572083 // Note: we do this only for GET requests because our mechanism for switching
2084 // processes only issues GET requests. In particular, POST requests don't
2085 // work, because this mechanism does not preserve form POST data. If it
2086 // becomes necessary to support process switching for POST requests, we will
2087 // need to send the request's httpBody data up to the browser process, and
2088 // issue a special POST navigation in WebKit (via
2089 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2090 // for examples of how to send the httpBody data.
[email protected]2762a1b2011-12-09 15:25:222091 if (!frame->parent() && is_content_initiated &&
[email protected]6101c342010-12-16 22:44:372092 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2093 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2094 bool send_referrer = false;
2095 bool should_fork =
[email protected]e091df82011-10-11 18:13:212096 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172097 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372098 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112099
[email protected]e48869a2011-04-01 19:56:032100 if (!should_fork) {
2101 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362102 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032103 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362104 frame, url, is_content_initiated, is_initial_navigation,
2105 &send_referrer);
[email protected]6101c342010-12-16 22:44:372106 }
2107
2108 if (should_fork) {
[email protected]445e1042011-12-03 21:03:152109 Referrer referrer(
2110 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))),
2111 getReferrerPolicyFromRequest(request));
2112 OpenURL(
2113 frame, url, send_referrer ? referrer : Referrer(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112114 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2115 }
[email protected]3d9689372009-09-10 04:29:172116 }
2117
[email protected]43763f982011-08-26 18:33:402118 // Use the frame's original request's URL rather than the document's URL for
2119 // this check. For a popup, the document's URL may become the opener window's
2120 // URL if the opener has called document.write. See http://crbug.com/93517.
2121 GURL old_url(frame->dataSource()->request().url());
2122
[email protected]3d9689372009-09-10 04:29:172123 // Detect when a page is "forking" a new tab that can be safely rendered in
2124 // its own process. This is done by sites like Gmail that try to open links
2125 // in new windows without script connections back to the original page. We
2126 // treat such cases as browser navigations (in which we will create a new
2127 // renderer for a cross-site navigation), rather than WebKit navigations.
2128 //
2129 // We use the following heuristic to decide whether to fork a new page in its
2130 // own process:
2131 // The parent page must open a new tab to about:blank, set the new tab's
2132 // window.opener to null, and then redirect the tab to a cross-site URL using
2133 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462134 //
2135 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2136 // (see below).
[email protected]3d9689372009-09-10 04:29:172137 bool is_fork =
2138 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582139 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172140 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522141 historyBackListCount() < 1 &&
2142 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172143 // The parent page must have set the child's window.opener to null before
2144 // redirecting to the desired URL.
2145 frame->opener() == NULL &&
2146 // Must be a top-level frame.
2147 frame->parent() == NULL &&
2148 // Must not have issued the request from this page.
2149 is_content_initiated &&
2150 // Must be targeted at the current tab.
2151 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2152 // Must be a JavaScript navigation, which appears as "other".
2153 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462154
2155 // Recognize if this navigation is from a link with rel=noreferrer and
2156 // target=_blank attributes, in which case the opener will be suppressed. If
2157 // so, it is safe to load cross-site pages in a separate process, so we
2158 // should let the browser handle it.
2159 bool is_noreferrer_and_blank_target =
2160 // Frame should be top level and not yet navigated.
2161 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412162 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462163 historyBackListCount() < 1 &&
2164 historyForwardListCount() < 1 &&
2165 // Links with rel=noreferrer will have no Referer field, and their
2166 // resulting frame will have its window.opener suppressed.
2167 // TODO(creis): should add a request.httpReferrer() method to help avoid
2168 // typos on the unusual spelling of Referer.
2169 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2170 opener_suppressed_ &&
2171 frame->opener() == NULL &&
2172 // Links with target=_blank will have no name.
2173 frame->name().isNull() &&
2174 // Another frame (with a non-empty creator) should have initiated the
2175 // request, targeted at this frame.
2176 !creator_url_.is_empty() &&
2177 is_content_initiated &&
2178 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2179 type == WebKit::WebNavigationTypeOther;
2180
2181 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172182 // Open the URL via the browser, not via WebKit.
[email protected]445e1042011-12-03 21:03:152183 OpenURL(frame, url, Referrer(), default_policy);
[email protected]3d9689372009-09-10 04:29:172184 return WebKit::WebNavigationPolicyIgnore;
2185 }
2186
2187 return default_policy;
2188}
2189
[email protected]310ebd6302011-10-10 19:06:282190bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492191 WebFrame* frame, const WebURLRequest& request) {
2192 // We allow WebKit to think that everything can be handled even though
2193 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342194 return true;
2195}
2196
[email protected]310ebd6302011-10-10 19:06:282197WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492198 WebFrame* frame, const WebURLRequest& request) {
2199 NOTREACHED(); // Since we said we can handle all requests.
2200 return WebURLError();
2201}
2202
[email protected]310ebd6302011-10-10 19:06:282203WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492204 WebFrame* frame, const WebURLRequest& request) {
2205 WebURLError error;
2206 error.domain = WebString::fromUTF8(net::kErrorDomain);
2207 error.reason = net::ERR_ABORTED;
2208 error.unreachableURL = request.url();
2209 return error;
[email protected]7b7a7dc2009-10-19 02:23:342210}
2211
[email protected]310ebd6302011-10-10 19:06:282212void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492213 WebFrame*, const WebURLError&) {
2214 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342215}
2216
[email protected]310ebd6302011-10-10 19:06:282217void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432218 const WebKit::WebFormElement& form) {
2219 // Some login forms have onSubmit handlers that put a hash of the password
2220 // into a hidden field and then clear the password. (Issue 28910.)
2221 // This method gets called before any of those handlers run, so save away
2222 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072223 DocumentState* document_state =
2224 DocumentState::FromDataSource(frame->dataSource());
2225 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432226 PasswordFormDomManager::CreatePasswordForm(form));
2227}
2228
[email protected]310ebd6302011-10-10 19:06:282229void RenderViewImpl::willSubmitForm(WebFrame* frame,
2230 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072231 DocumentState* document_state =
2232 DocumentState::FromDataSource(frame->provisionalDataSource());
2233 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172234
[email protected]2905f742011-10-13 03:51:582235 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2236 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172237
2238 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352239 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072240 document_state->set_searchable_form_url(web_searchable_form_data.url());
2241 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212242 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432243 PasswordForm* password_form_data =
2244 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072245 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432246
[email protected]098c95cb2011-04-28 16:49:012247 // In order to save the password that the user actually typed and not one
2248 // that may have gotten transformed by the site prior to submit, recover it
2249 // from the form contents already stored by |willSendSubmitEvent| into the
2250 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2251 // which is what we're storing into now.)
2252 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072253 DocumentState* old_document_state =
2254 DocumentState::FromDataSource(frame->dataSource());
2255 if (old_document_state) {
2256 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432257 if (old_form_data && old_form_data->action == password_form_data->action)
2258 password_form_data->password_value = old_form_data->password_value;
2259 }
2260 }
[email protected]3d9689372009-09-10 04:29:172261
[email protected]2a5b1732011-04-01 23:55:552262 FOR_EACH_OBSERVER(
2263 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172264}
2265
[email protected]310ebd6302011-10-10 19:06:282266void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172267 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2268 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382269 FOR_EACH_OBSERVER(
2270 RenderViewObserver, observers_,
2271 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172272}
2273
[email protected]310ebd6302011-10-10 19:06:282274void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382275 FOR_EACH_OBSERVER(
2276 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172277}
2278
[email protected]310ebd6302011-10-10 19:06:282279void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172280 WebFrame* frame, const WebURL& from) {
[email protected]445e1042011-12-03 21:03:152281 if (!frame->parent()) {
2282 WebDataSource* ds = frame->provisionalDataSource();
2283 // If there's no provisional data source, it's a reference fragment
2284 // navigation.
2285 completed_client_redirect_src_ = Referrer(
2286 from, ds ? getReferrerPolicyFromRequest(ds->request()) :
2287 frame->referrerPolicy());
2288 }
[email protected]eb0bff942011-04-07 22:08:382289 FOR_EACH_OBSERVER(
2290 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172291}
2292
[email protected]310ebd6302011-10-10 19:06:282293void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072294 DocumentState* document_state = DocumentState::FromDataSource(ds);
2295 if (!document_state) {
2296 document_state = new DocumentState;
2297 ds->setExtraData(document_state);
2298 }
2299
[email protected]3d9689372009-09-10 04:29:172300 // The rest of RenderView assumes that a WebDataSource will always have a
2301 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072302 bool content_initiated = !pending_navigation_params_.get();
2303 if (content_initiated)
2304 document_state->set_navigation_state(
2305 NavigationState::CreateContentInitiated());
2306 else
2307 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512308
[email protected]007733c2011-11-17 00:34:072309 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512310 // navigating from a page that used prefetching using a link on that
2311 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072312 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512313 // this value appropriately.
2314 // TODO(gavinp): catch the important case of navigation in a new
2315 // renderer process.
2316 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302317 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522318 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512319 const GURL referrer(
2320 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2321 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072322 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512323 old_frame->dataSource())->was_prefetcher()) {
2324 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2325 WebDataSource* old_frame_ds = old_frame->dataSource();
2326 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072327 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512328 break;
2329 }
2330 }
2331 }
2332 }
2333 }
2334
[email protected]4c1b6f0b2010-02-07 16:38:182335 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522336 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512337 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182338 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072339 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182340 break;
2341 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072342 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182343 break;
2344 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072345 document_state->set_load_type(
2346 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182347 break;
2348 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072349 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182350 break;
2351 }
2352 }
[email protected]fa7b6b542009-11-03 05:02:302353
[email protected]946a0032011-03-31 18:42:282354 FOR_EACH_OBSERVER(
2355 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172356}
2357
[email protected]007733c2011-11-17 00:34:072358void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2359 DocumentState* document_state) {
2360 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2361
2362 if (document_state->request_time().is_null())
2363 document_state->set_request_time(params.request_time);
2364
2365 // A navigation resulting from loading a javascript URL should not be treated
2366 // as a browser initiated event. Instead, we want it to look as if the page
2367 // initiated any load resulting from JS execution.
2368 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2369 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2370 params.page_id,
2371 params.pending_history_list_offset,
2372 params.transition);
[email protected]4ad5d77d2011-12-03 02:00:482373 navigation_state->set_transferred_request_child_id(
2374 params.transferred_request_child_id);
2375 navigation_state->set_transferred_request_request_id(
2376 params.transferred_request_request_id);
[email protected]007733c2011-11-17 00:34:072377 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2378 // We're doing a load of a page that was restored from the last session.
2379 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2380 // which can result in stale data for pages that are set to expire. We
2381 // explicitly override that by setting the policy here so that as
2382 // necessary we load from the network.
2383 document_state->set_cache_policy_override(
2384 WebURLRequest::UseProtocolCachePolicy);
2385 }
2386 document_state->set_navigation_state(navigation_state);
2387 } else {
2388 document_state->set_navigation_state(
2389 NavigationState::CreateContentInitiated());
2390 }
2391
2392 if (IsReload(params))
2393 document_state->set_load_type(DocumentState::RELOAD);
2394 else if (!params.state.empty())
2395 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2396 else
2397 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2398
2399 pending_navigation_params_.reset();
2400}
2401
[email protected]310ebd6302011-10-10 19:06:282402void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172403 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072404 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172405
[email protected]3d9689372009-09-10 04:29:172406 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072407 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172408 double event_time = ds->triggeringEventTime();
2409 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072410 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172411 }
2412
[email protected]05c8e502010-08-15 15:13:522413 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072414 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522415
[email protected]3d9689372009-09-10 04:29:172416 bool is_top_most = !frame->parent();
2417 if (is_top_most) {
2418 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132419 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172420
2421 // Make sure redirect tracking state is clear for the new load.
[email protected]445e1042011-12-03 21:03:152422 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172423 } else if (frame->parent()->isLoading()) {
2424 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002425 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072426 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582427 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172428 }
2429
[email protected]28685da92011-02-07 21:49:172430 FOR_EACH_OBSERVER(
2431 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2432
[email protected]3d9689372009-09-10 04:29:172433 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592434 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262435 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172436}
2437
[email protected]310ebd6302011-10-10 19:06:282438void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2439 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172440 if (frame->parent())
2441 return;
2442 // Received a redirect on the main frame.
2443 WebDataSource* data_source = frame->provisionalDataSource();
2444 if (!data_source) {
2445 // Should only be invoked when we have a data source.
2446 NOTREACHED();
2447 return;
2448 }
2449 std::vector<GURL> redirects;
2450 GetRedirectChain(data_source, &redirects);
2451 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512452 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592453 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172454 }
2455}
2456
[email protected]310ebd6302011-10-10 19:06:282457void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2458 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172459 // Notify the browser that we failed a provisional load with an error.
2460 //
2461 // Note: It is important this notification occur before DidStopLoading so the
2462 // SSL manager can react to the provisional load failure before being
2463 // notified the load stopped.
2464 //
2465 WebDataSource* ds = frame->provisionalDataSource();
2466 DCHECK(ds);
2467
2468 const WebURLRequest& failed_request = ds->request();
2469
[email protected]28685da92011-02-07 21:49:172470 FOR_EACH_OBSERVER(
2471 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2472
[email protected]3d9689372009-09-10 04:29:172473 bool show_repost_interstitial =
2474 (error.reason == net::ERR_CACHE_MISS &&
2475 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582476
2477 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2478 params.frame_id = frame->identifier();
2479 params.is_main_frame = !frame->parent();
2480 params.error_code = error.reason;
2481 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2482 failed_request,
2483 error,
2484 NULL,
2485 &params.error_description);
2486 params.url = error.unreachableURL;
2487 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172488 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582489 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172490
2491 // Don't display an error page if this is simply a cancelled load. Aside
2492 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2493 if (error.reason == net::ERR_ABORTED)
2494 return;
2495
2496 // Make sure we never show errors in view source mode.
2497 frame->enableViewSourceMode(false);
2498
[email protected]007733c2011-11-17 00:34:072499 DocumentState* document_state = DocumentState::FromDataSource(ds);
2500 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172501
2502 // If this is a failed back/forward/reload navigation, then we need to do a
2503 // 'replace' load. This is necessary to avoid messing up session history.
2504 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2505 // as session history is concerned.
2506 //
2507 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2508 // the page id.
2509 //
2510 bool replace =
2511 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582512 navigation_state->transition_type() ==
2513 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172514
2515 // If we failed on a browser initiated request, then make sure that our error
2516 // page load is regarded as the same browser initiated request.
2517 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072518 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2519 pending_navigation_params_->page_id =
2520 navigation_state->pending_page_id();
2521 pending_navigation_params_->pending_history_list_offset =
2522 navigation_state->pending_history_list_offset();
2523 pending_navigation_params_->transition =
2524 navigation_state->transition_type();
2525 pending_navigation_params_->request_time =
2526 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172527 }
2528
2529 // Provide the user with a more helpful error page?
2530 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2531 return;
2532
2533 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082534 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172535}
2536
[email protected]310ebd6302011-10-10 19:06:282537void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172538 WebFrame* frame, const char* data, size_t data_len,
2539 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072540 DocumentState* document_state =
2541 DocumentState::FromDataSource(frame->dataSource());
2542 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172543}
2544
[email protected]310ebd6302011-10-10 19:06:282545void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2546 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072547 DocumentState* document_state =
2548 DocumentState::FromDataSource(frame->dataSource());
2549 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172550
[email protected]007733c2011-11-17 00:34:072551 if (document_state->commit_load_time().is_null())
2552 document_state->set_commit_load_time(Time::Now());
2553
[email protected]3d9689372009-09-10 04:29:172554 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202555 // When we perform a new navigation, we need to update the last committed
2556 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172557 UpdateSessionHistory(frame);
2558
2559 // We bump our Page ID to correspond with the new session history entry.
2560 page_id_ = next_page_id_++;
2561
[email protected]3cc72b12010-03-18 23:03:002562 // Advance our offset in session history, applying the length limit. There
2563 // is now no forward history.
2564 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102565 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2566 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002567 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032568 history_page_ids_.resize(history_list_length_, -1);
2569 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172570 } else {
2571 // Inspect the navigation_state on this frame to see if the navigation
2572 // corresponds to a session history navigation... Note: |frame| may or
2573 // may not be the toplevel frame, but for the case of capturing session
2574 // history, the first committed frame suffices. We keep track of whether
2575 // we've seen this commit before so that only capture session history once
2576 // per navigation.
2577 //
2578 // Note that we need to check if the page ID changed. In the case of a
2579 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2580 // previous URL and the current page ID, which would be wrong.
2581 if (navigation_state->pending_page_id() != -1 &&
2582 navigation_state->pending_page_id() != page_id_ &&
2583 !navigation_state->request_committed()) {
2584 // This is a successful session history navigation!
2585 UpdateSessionHistory(frame);
2586 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002587
2588 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032589
2590 // If the history list is valid, our list of page IDs should be correct.
2591 DCHECK(history_list_length_ <= 0 ||
2592 history_list_offset_ < 0 ||
2593 history_list_offset_ >= history_list_length_ ||
2594 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172595 }
2596 }
2597
[email protected]28685da92011-02-07 21:49:172598 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2599 DidCommitProvisionalLoad(frame, is_new_navigation));
2600
[email protected]3d9689372009-09-10 04:29:172601 // Remember that we've already processed this request, so we don't update
2602 // the session history again. We do this regardless of whether this is
2603 // a session history navigation, because if we attempted a session history
2604 // navigation without valid HistoryItem state, WebCore will think it is a
2605 // new navigation.
2606 navigation_state->set_request_committed(true);
2607
2608 UpdateURL(frame);
2609
2610 // If this committed load was initiated by a client redirect, we're
2611 // at the last stop now, so clear it.
[email protected]445e1042011-12-03 21:03:152612 completed_client_redirect_src_ = Referrer();
[email protected]3d9689372009-09-10 04:29:172613
2614 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272615 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172616}
2617
[email protected]310ebd6302011-10-10 19:06:282618void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102619 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2620 DidClearWindowObject(frame));
2621
[email protected]b6cb3a842011-06-24 18:28:412622 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212623 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252624 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2625 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272626 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172627 }
[email protected]3d9689372009-09-10 04:29:172628}
2629
[email protected]310ebd6302011-10-10 19:06:282630void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172631 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412632 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252633 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272634 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172635 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2636 }
[email protected]e48869a2011-04-01 19:56:032637
2638 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2639 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172640}
2641
[email protected]310ebd6302011-10-10 19:06:282642void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2643 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462644 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172645
2646 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272647 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172648}
2649
[email protected]310ebd6302011-10-10 19:06:282650void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132651 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2652 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582653}
2654
[email protected]310ebd6302011-10-10 19:06:282655void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172656 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072657 DocumentState* document_state = DocumentState::FromDataSource(ds);
2658 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172659
[email protected]622474d2010-11-04 09:21:082660 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172661
[email protected]28685da92011-02-07 21:49:172662 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2663 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172664
2665 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272666 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172667}
2668
[email protected]310ebd6302011-10-10 19:06:282669void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082670 if (webview()->mainFrame() == frame) {
2671 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2672 page_id_));
2673 }
[email protected]3d9689372009-09-10 04:29:172674}
2675
[email protected]310ebd6302011-10-10 19:06:282676void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]1a55c5be2011-11-29 11:36:312677 WebDataSource* ds = frame->dataSource();
2678 DCHECK(ds);
2679
2680
[email protected]28685da92011-02-07 21:49:172681 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]1a55c5be2011-11-29 11:36:312682
2683 const WebURLRequest& failed_request = ds->request();
2684 string16 error_description;
2685 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2686 failed_request,
2687 error,
2688 NULL,
2689 &error_description);
2690 Send(new ViewHostMsg_DidFailLoadWithError(routing_id_,
2691 frame->identifier(),
2692 failed_request.url(),
2693 !frame->parent(),
2694 error.reason,
2695 error_description));
[email protected]3d9689372009-09-10 04:29:172696}
2697
[email protected]310ebd6302011-10-10 19:06:282698void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172699 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072700 DocumentState* document_state = DocumentState::FromDataSource(ds);
2701 if (document_state->finish_load_time().is_null())
2702 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412703
[email protected]676126f72011-01-15 00:03:512704 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172705
[email protected]1a55c5be2011-11-29 11:36:312706 Send(new ViewHostMsg_DidFinishLoad(routing_id_,
2707 frame->identifier(),
2708 ds->request().url(),
2709 !frame->parent()));
[email protected]3d9689372009-09-10 04:29:172710}
2711
[email protected]310ebd6302011-10-10 19:06:282712void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172713 WebFrame* frame, bool is_new_navigation) {
2714 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072715 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172716 // update the ExtraData on the datasource so that others who read the
2717 // ExtraData will get the new NavigationState. Similarly, if we did not
2718 // initiate this navigation, then we need to take care to reset any pre-
2719 // existing navigation state to a content-initiated navigation state.
2720 // DidCreateDataSource conveniently takes care of this for us.
2721 didCreateDataSource(frame, frame->dataSource());
2722
[email protected]007733c2011-11-17 00:34:072723 DocumentState* document_state =
2724 DocumentState::FromDataSource(frame->dataSource());
2725 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092726 new_state->set_was_within_same_page(true);
2727
[email protected]3d9689372009-09-10 04:29:172728 didCommitProvisionalLoad(frame, is_new_navigation);
2729
[email protected]750fcf872011-08-03 23:10:472730 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2731 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172732}
2733
[email protected]310ebd6302011-10-10 19:06:282734void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312735 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592736}
2737
[email protected]310ebd6302011-10-10 19:06:282738void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172739 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2740 // Ignore
2741}
2742
[email protected]310ebd6302011-10-10 19:06:282743void RenderViewImpl::willSendRequest(WebFrame* frame,
2744 unsigned identifier,
2745 WebURLRequest& request,
2746 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302747 WebFrame* top_frame = frame->top();
2748 if (!top_frame)
2749 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512750 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2751 WebDataSource* top_data_source = top_frame->dataSource();
2752 WebDataSource* data_source =
2753 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222754
[email protected]78d5cfe2011-02-04 08:43:222755 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032756 GURL new_url;
2757 if (content::GetContentClient()->renderer()->WillSendRequest(
2758 frame, request_url, &new_url)) {
2759 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222760 }
2761
[email protected]2905f742011-10-13 03:51:582762 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072763 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2764 NavigationState* navigation_state = document_state->navigation_state();
2765 if (document_state) {
2766 if (document_state->is_cache_policy_override_set())
2767 request.setCachePolicy(document_state->cache_policy_override());
2768 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:302769 }
[email protected]8a3125a712010-08-09 18:58:512770
[email protected]91043a8232011-11-04 16:41:192771 request.setExtraData(
[email protected]537fbe02011-11-24 00:58:062772 new RequestExtraData(frame->referrerPolicy(),
2773 (frame == top_frame),
[email protected]91043a8232011-11-04 16:41:192774 frame->identifier(),
2775 frame->parent() == top_frame,
2776 frame->parent() ? frame->parent()->identifier() : -1,
[email protected]4ad5d77d2011-12-03 02:00:482777 transition_type,
2778 navigation_state->transferred_request_child_id(),
2779 navigation_state->transferred_request_request_id()));
[email protected]d88bf0a2011-08-30 23:55:572780
[email protected]007733c2011-11-17 00:34:072781 DocumentState* top_document_state =
2782 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:572783 // TODO(gavinp): separate out prefetching and prerender field trials
2784 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:072785 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:572786 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2787 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:072788 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512789
[email protected]3d9689372009-09-10 04:29:172790 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132791 request.setHasUserGesture(frame->isProcessingUserGesture());
2792
[email protected]0a8db0d2011-04-13 15:15:402793 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132794 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172795}
2796
[email protected]310ebd6302011-10-10 19:06:282797void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:172798 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492799
[email protected]3d9689372009-09-10 04:29:172800 // Only do this for responses that correspond to a provisional data source
2801 // of the top-most frame. If we have a provisional data source, then we
2802 // can't have any sub-resources yet, so we know that this response must
2803 // correspond to a frame load.
2804 if (!frame->provisionalDataSource() || frame->parent())
2805 return;
2806
2807 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082808 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172809 if (frame->isViewSourceModeEnabled())
2810 return;
2811
[email protected]007733c2011-11-17 00:34:072812 DocumentState* document_state =
2813 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:082814 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532815
[email protected]972ebdff2010-06-10 22:59:072816 // Record page load flags.
[email protected]007733c2011-11-17 00:34:072817 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2818 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
2819 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:572820 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:072821 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
2822 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092823 // Whether or not the http status code actually corresponds to an error is
2824 // only checked when the page is done loading, if |use_error_page| is
2825 // still true.
[email protected]007733c2011-11-17 00:34:072826 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172827}
2828
[email protected]310ebd6302011-10-10 19:06:282829void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:172830 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:072831 DocumentState* document_state =
2832 DocumentState::FromDataSource(frame->dataSource());
2833 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172834 return;
2835
[email protected]7bfc153f2011-09-23 22:00:202836 // Do not show error page when DevTools is attached.
2837 if (devtools_agent_->IsAttached())
2838 return;
2839
[email protected]06333afe2011-02-24 14:55:092840 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:072841 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:082842 if (http_status_code == 404) {
2843 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412844 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172845
[email protected]b6cb3a842011-06-24 18:28:412846 const GURL& error_page_url =
2847 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092848 if (error_page_url.is_valid()) {
2849 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472850 original_error.domain = "http";
2851 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412852 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172853
[email protected]007733c2011-11-17 00:34:072854 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:092855 new AltErrorPageResourceFetcher(
2856 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:082857 base::Bind(&RenderViewImpl::AltErrorPageFinished,
2858 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:092859 return;
2860 }
2861 }
[email protected]3d9689372009-09-10 04:29:172862
[email protected]e6a2ce52011-10-08 01:40:132863 std::string error_domain;
2864 if (content::GetContentClient()->renderer()->HasErrorPage(
2865 http_status_code, &error_domain)) {
2866 WebURLError error;
2867 error.unreachableURL = frame->document().url();
2868 error.domain = WebString::fromUTF8(error_domain);
2869 error.reason = http_status_code;
2870
2871 LoadNavigationErrorPage(
2872 frame, frame->dataSource()->request(), error, std::string(), true);
2873 }
[email protected]3d9689372009-09-10 04:29:172874}
2875
[email protected]310ebd6302011-10-10 19:06:282876void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:172877 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2878 // Ignore
2879}
2880
[email protected]310ebd6302011-10-10 19:06:282881void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:172882 WebFrame* frame, const WebURLRequest& request,
2883 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:002884 // The recipients of this message have no use for data: URLs: they don't
2885 // affect the page's insecure content list and are not in the disk cache. To
2886 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
2887 // filter them out here.
2888 GURL url(request.url());
2889 if (url.SchemeIs("data"))
2890 return;
2891
[email protected]3d9689372009-09-10 04:29:172892 // Let the browser know we loaded a resource from the memory cache. This
2893 // message is needed to display the correct SSL indicators.
2894 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2895 routing_id_,
[email protected]84703292011-10-28 20:44:002896 url,
[email protected]70435962011-08-02 20:13:282897 response.securityInfo(),
2898 request.httpMethod().utf8(),
2899 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172900}
2901
[email protected]310ebd6302011-10-10 19:06:282902void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292903 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2904}
2905
[email protected]310ebd6302011-10-10 19:06:282906void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:022907 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292908 Send(new ViewHostMsg_DidRunInsecureContent(
2909 routing_id_,
[email protected]92771112011-01-20 00:13:022910 origin.toString().utf8(),
2911 target));
[email protected]e3d60e5d2009-09-25 21:08:292912}
2913
[email protected]310ebd6302011-10-10 19:06:282914void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:032915 webkit_glue::WebURLLoaderImpl* loader_impl =
2916 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2917 loader_impl->UpdateRoutingId(routing_id_);
2918}
2919
[email protected]310ebd6302011-10-10 19:06:282920void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172921 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2922}
2923
[email protected]310ebd6302011-10-10 19:06:282924void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
2925 v8::Handle<v8::Context> context,
2926 int world_id) {
[email protected]5bc10932011-09-21 21:03:302927 content::GetContentClient()->renderer()->DidCreateScriptContext(
2928 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282929}
2930
[email protected]310ebd6302011-10-10 19:06:282931void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
2932 v8::Handle<v8::Context> context,
2933 int world_id) {
[email protected]5bc10932011-09-21 21:03:302934 content::GetContentClient()->renderer()->WillReleaseScriptContext(
2935 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282936}
2937
[email protected]310ebd6302011-10-10 19:06:282938void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:072939 // We don't always want to send the change messages over IPC, only if we've
2940 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2941 // message.
2942 if (!send_preferred_size_changes_ || !webview())
2943 return;
2944
[email protected]705243f2010-05-05 19:58:072945 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2946 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532947
2948 // In the presence of zoom, these sizes are still reported as if unzoomed,
2949 // so we need to adjust.
2950 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2951 size.set_width(static_cast<int>(size.width() * zoom_factor));
2952 size.set_height(static_cast<int>(size.height() * zoom_factor));
2953
[email protected]6b5576cb2011-12-05 08:23:002954 if (!size.height())
2955 size.set_height(preferred_size_.height());
2956
[email protected]705243f2010-05-05 19:58:072957 if (size == preferred_size_)
2958 return;
[email protected]c27324b2009-11-19 22:44:292959
[email protected]705243f2010-05-05 19:58:072960 preferred_size_ = size;
2961 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2962 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172963}
2964
[email protected]310ebd6302011-10-10 19:06:282965void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
2966 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:312967 if (webview()->mainFrame() != frame)
2968 return;
2969 WebView* frameView = frame->view();
2970 if (!frameView)
2971 return;
2972
2973 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
2974 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
2975
2976 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
2977 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
2978 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
2979 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
2980
2981 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
2982 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
2983 }
2984}
2985
[email protected]310ebd6302011-10-10 19:06:282986void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:312987 WebSize offset = frame->scrollOffset();
2988 WebSize minimum_offset = frame->minimumScrollOffset();
2989 WebSize maximum_offset = frame->maximumScrollOffset();
2990
2991 bool is_pinned_to_left = offset.width <= minimum_offset.width;
2992 bool is_pinned_to_right = offset.width >= maximum_offset.width;
2993
2994 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
2995 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
2996 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
2997 routing_id_, is_pinned_to_left, is_pinned_to_right));
2998
2999 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
3000 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
3001 }
3002}
3003
[email protected]310ebd6302011-10-10 19:06:283004void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:493005 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:313006
3007 if (webview()->mainFrame() == frame)
3008 UpdateScrollState(frame);
3009}
3010
[email protected]310ebd6302011-10-10 19:06:283011void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:313012 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:493013}
3014
[email protected]310ebd6302011-10-10 19:06:283015void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
3016 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113017 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3018 if (!count)
3019 active_match_ordinal = 0;
3020
3021 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3022 routing_id_,
3023 request_id,
3024 count,
3025 gfx::Rect(),
3026 active_match_ordinal,
3027 final_update);
3028
[email protected]8922e1f2009-10-03 05:01:263029 // If we have a message that has been queued up, then we should just replace
3030 // it. The ACK from the browser will make sure it gets sent when the browser
3031 // wants it.
3032 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263033 queued_find_reply_message_.reset(msg);
3034 } else {
3035 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113036 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263037 }
3038}
3039
[email protected]310ebd6302011-10-10 19:06:283040void RenderViewImpl::reportFindInPageSelection(int request_id,
3041 int active_match_ordinal,
3042 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:263043 // Send the search result over to the browser process.
3044 Send(new ViewHostMsg_Find_Reply(routing_id_,
3045 request_id,
3046 -1,
3047 selection_rect,
3048 active_match_ordinal,
3049 false));
3050}
3051
[email protected]310ebd6302011-10-10 19:06:283052void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:223053 WebFrame* frame,
3054 WebFileSystem::Type type,
3055 long long size,
[email protected]d275d7a2010-11-03 01:34:493056 bool create,
[email protected]2b06a992010-08-21 05:48:223057 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083058 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223059
[email protected]b6cb3a842011-06-24 18:28:413060 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563061 if (origin.isUnique()) {
3062 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:083063 callbacks->didFail(WebKit::WebFileErrorAbort);
3064 return;
3065 }
[email protected]2b06a992010-08-21 05:48:223066
[email protected]c5a272d2010-09-27 18:37:083067 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3068 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493069 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223070}
3071
[email protected]310ebd6302011-10-10 19:06:283072void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:403073 WebFrame* frame,
3074 WebStorageQuotaType type,
3075 WebStorageQuotaCallbacks* callbacks) {
3076 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413077 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563078 if (origin.isUnique()) {
3079 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403080 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3081 return;
3082 }
3083 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533084 GURL(origin.toString()),
3085 static_cast<quota::StorageType>(type),
3086 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403087}
3088
[email protected]310ebd6302011-10-10 19:06:283089void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403090 WebFrame* frame,
3091 WebStorageQuotaType type,
3092 unsigned long long requested_size,
3093 WebStorageQuotaCallbacks* callbacks) {
3094 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413095 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563096 if (origin.isUnique()) {
3097 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403098 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3099 return;
3100 }
3101 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533102 routing_id(), GURL(origin.toString()),
3103 static_cast<quota::StorageType>(type), requested_size,
3104 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403105}
3106
[email protected]8b5af492011-11-28 21:50:583107void RenderViewImpl::registerIntentService(
3108 WebKit::WebFrame* frame, const WebKit::WebIntentServiceInfo& service) {
3109 Send(new IntentsHostMsg_RegisterIntentService(routing_id_,
3110 service.action(),
3111 service.type(),
3112 service.url().spec().utf16(),
3113 service.title(),
3114 service.disposition()));
3115}
3116
3117void RenderViewImpl::dispatchIntent(WebKit::WebFrame* frame,
3118 const WebKit::WebIntent& intent) {
[email protected]678105012011-12-09 04:01:213119 webkit_glue::WebIntentData intent_data(intent);
[email protected]8b5af492011-11-28 21:50:583120 Send(new IntentsHostMsg_WebIntentDispatch(
3121 routing_id_, intent_data, intent.identifier()));
3122}
3123
[email protected]18d5be92011-07-25 18:00:193124// WebKit::WebPageSerializerClient implementation ------------------------------
3125
[email protected]310ebd6302011-10-10 19:06:283126void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193127 const WebURL& frame_url,
3128 const WebCString& data,
3129 WebPageSerializerClient::PageSerializationStatus status) {
3130 Send(new ViewHostMsg_SendSerializedHtmlData(
3131 routing_id(),
3132 frame_url,
3133 data.data(),
3134 static_cast<int32>(status)));
3135}
3136
[email protected]a2ef54c2011-10-10 16:20:313137// content::RenderView implementation ------------------------------------------
3138
[email protected]310ebd6302011-10-10 19:06:283139bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313140 return RenderWidget::Send(message);
3141}
3142
[email protected]310ebd6302011-10-10 19:06:283143int RenderViewImpl::GetRoutingId() const {
[email protected]a2ef54c2011-10-10 16:20:313144 return routing_id_;
3145}
3146
[email protected]310ebd6302011-10-10 19:06:283147int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313148 return page_id_;
3149}
3150
[email protected]310ebd6302011-10-10 19:06:283151gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313152 return size();
3153}
3154
[email protected]310ebd6302011-10-10 19:06:283155gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313156 return host_window();
3157}
3158
[email protected]310ebd6302011-10-10 19:06:283159WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313160 return webkit_preferences_;
3161}
3162
[email protected]310ebd6302011-10-10 19:06:283163WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313164 return webview();
3165}
3166
[email protected]310ebd6302011-10-10 19:06:283167WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313168 if (!webview())
3169 return WebNode();
3170 WebFrame* focused_frame = webview()->focusedFrame();
3171 if (focused_frame) {
3172 WebDocument doc = focused_frame->document();
3173 if (!doc.isNull())
3174 return doc.focusedNode();
3175 }
3176
3177 return WebNode();
3178}
3179
[email protected]310ebd6302011-10-10 19:06:283180WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313181 return context_menu_node_;
3182}
3183
[email protected]310ebd6302011-10-10 19:06:283184bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313185 bool is_editable_node = false;
3186 if (!node.isNull()) {
3187 if (node.isContentEditable()) {
3188 is_editable_node = true;
3189 } else if (node.isElementNode()) {
3190 is_editable_node =
3191 node.toConst<WebElement>().isTextFormControlElement();
3192 }
3193 }
3194 return is_editable_node;
3195}
3196
[email protected]310ebd6302011-10-10 19:06:283197WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313198 WebKit::WebFrame* frame,
3199 const webkit::WebPluginInfo& info,
3200 const WebKit::WebPluginParams& params) {
3201 bool pepper_plugin_was_registered = false;
3202 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3203 pepper_delegate_.CreatePepperPluginModule(info,
3204 &pepper_plugin_was_registered));
3205 if (pepper_plugin_was_registered) {
3206 if (!pepper_module)
3207 return NULL;
3208 return new webkit::ppapi::WebPluginImpl(
3209 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3210 }
3211
3212 return new webkit::npapi::WebPluginImpl(
3213 frame, params, info.path, AsWeakPtr());
3214}
3215
[email protected]310ebd6302011-10-10 19:06:283216void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3217 const string16& jscript,
3218 int id,
3219 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313220 v8::Handle<v8::Value> result;
3221 WebFrame* web_frame = GetChildFrame(frame_xpath);
3222 if (web_frame)
3223 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3224 if (notify_result) {
3225 ListValue list;
3226 if (!result.IsEmpty() && web_frame) {
3227 v8::HandleScope handle_scope;
3228 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3229 v8::Context::Scope context_scope(context);
3230 V8ValueConverterImpl converter;
3231 converter.set_allow_date(true);
3232 converter.set_allow_regexp(true);
3233 list.Set(0, converter.FromV8Value(result, context));
3234 } else {
3235 list.Set(0, Value::CreateNullValue());
3236 }
3237 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3238 }
3239}
3240
[email protected]310ebd6302011-10-10 19:06:283241bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313242 return (!send_preferred_size_changes_ ||
3243 (disable_scrollbars_size_limit_.width() <= width ||
3244 disable_scrollbars_size_limit_.height() <= height));
3245}
3246
[email protected]310ebd6302011-10-10 19:06:283247int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313248 return enabled_bindings_;
3249}
3250
[email protected]310ebd6302011-10-10 19:06:283251void RenderViewImpl::SetEnabledBindings(int enabled_bindings) {
[email protected]a2ef54c2011-10-10 16:20:313252 enabled_bindings_ = enabled_bindings;
3253}
3254
[email protected]310ebd6302011-10-10 19:06:283255bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313256 return send_content_state_immediately_;
3257}
3258
[email protected]310ebd6302011-10-10 19:06:283259float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313260 return filtered_time_per_frame();
3261}
3262
[email protected]310ebd6302011-10-10 19:06:283263void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3264 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313265 showContextMenu(frame, data);
3266}
3267
[email protected]310ebd6302011-10-10 19:06:283268WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313269 return visibilityState();
3270}
3271
[email protected]310ebd6302011-10-10 19:06:283272void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3273 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313274 return runModalAlertDialog(frame, message);
3275}
3276
[email protected]310ebd6302011-10-10 19:06:283277void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313278 WebKit::WebFrame* frame,
3279 const WebKit::WebURLRequest& request,
3280 WebKit::WebNavigationPolicy policy) {
3281 loadURLExternally(frame, request, policy);
3282}
3283
3284// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513285
[email protected]310ebd6302011-10-10 19:06:283286webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533287 const FilePath& file_path,
3288 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593289 if (!PluginChannelHost::IsListening())
3290 return NULL;
3291
[email protected]00c39612010-03-06 02:53:283292 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463293 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323294#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223295 return webkit::npapi::WebPluginDelegateImpl::Create(
3296 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093297#else
[email protected]7398dcc2011-09-06 21:40:323298 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223299 NOTIMPLEMENTED();
3300 return NULL;
[email protected]7b6616f2010-01-14 18:07:553301#endif
[email protected]f103ab72009-09-02 17:10:593302 }
3303
[email protected]4e0616e2010-05-28 14:55:533304 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593305}
3306
[email protected]310ebd6302011-10-10 19:06:283307void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033308#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273309 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593310#endif
3311}
3312
[email protected]310ebd6302011-10-10 19:06:283313void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033314#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273315 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593316#endif
3317 CleanupWindowInPluginMoves(window);
3318}
3319
[email protected]310ebd6302011-10-10 19:06:283320void RenderViewImpl::DidMovePlugin(
3321 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593322 SchedulePluginMove(move);
3323}
3324
[email protected]310ebd6302011-10-10 19:06:283325void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593326 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523327 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593328}
3329
[email protected]310ebd6302011-10-10 19:06:283330void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593331 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523332 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593333}
3334
[email protected]310ebd6302011-10-10 19:06:283335WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513336 return &cookie_jar_;
3337}
3338
[email protected]a9288f52011-11-17 05:18:163339void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073340 Send(new ViewHostMsg_MediaNotification(routing_id_,
3341 reinterpret_cast<int64>(player),
3342 player->hasVideo(),
3343 player->hasAudio(),
3344 true));
3345}
3346
[email protected]a9288f52011-11-17 05:18:163347void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073348 Send(new ViewHostMsg_MediaNotification(routing_id_,
3349 reinterpret_cast<int64>(player),
3350 player->hasVideo(),
3351 player->hasAudio(),
3352 false));
3353}
3354
[email protected]a9288f52011-11-17 05:18:163355void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073356 DidPause(player);
3357}
3358
[email protected]310ebd6302011-10-10 19:06:283359void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293360 if (!webview())
3361 return;
3362
[email protected]26aa0482009-09-30 16:55:273363 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173364 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293365 return;
[email protected]ca948a22009-06-25 19:36:173366
3367 Send(new ViewHostMsg_UpdateState(
3368 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293369}
3370
[email protected]310ebd6302011-10-10 19:06:283371void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363372 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003373 if (!frame)
3374 return;
[email protected]b781ff282011-08-20 06:19:363375
[email protected]b781ff282011-08-20 06:19:363376 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003377 if (!webview()->caretOrSelectionRange(&location, &length))
3378 return;
3379
3380 string16 text;
3381 size_t offset;
3382 ui::Range range(location, location + length);
3383
3384 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3385 // If current focused element is editable, we will send 100 more chars
3386 // before and after selection. It is for input method surrounding text
3387 // feature.
3388 if (location > kExtraCharsBeforeAndAfterSelection)
3389 offset = location - kExtraCharsBeforeAndAfterSelection;
3390 else
3391 offset = 0;
3392 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3393 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3394 if (!webrange.isNull())
3395 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3396 } else {
3397 offset = location;
3398 text = frame->selectionAsText();
[email protected]e8cdf3532011-10-29 00:50:523399 // http://crbug.com/101435
3400 // In some case, frame->selectionAsText() returned text's length is not
3401 // equal to the length returned from webview()->caretOrSelectionRange().
3402 // So we have to set the range according to text.length().
3403 range.set_end(range.start() + text.length());
[email protected]b781ff282011-08-20 06:19:363404 }
3405
[email protected]b781ff282011-08-20 06:19:363406 // Sometimes we get repeated didChangeSelection calls from webkit when
3407 // the selection hasn't actually changed. We don't want to report these
3408 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003409 if (selection_text_offset_ != offset ||
3410 selection_range_ != range ||
3411 selection_text_ != text) {
3412 selection_text_ = text;
3413 selection_text_offset_ = offset;
3414 selection_range_ = range;
3415 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3416 }
[email protected]b781ff282011-08-20 06:19:363417}
3418
[email protected]310ebd6302011-10-10 19:06:283419GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3420 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553421 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293422 // If the URL that failed was secure, then the embedding web page was not
3423 // expecting a network attacker to be able to manipulate its contents. As
3424 // we fetch alternate error pages over HTTP, we would be allowing a network
3425 // attacker to manipulate the contents of the response if we tried to use
3426 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153427 return GURL();
initial.commit09911bf2008-07-26 23:55:293428 }
3429
3430 // Grab the base URL from the browser process.
3431 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153432 return GURL();
initial.commit09911bf2008-07-26 23:55:293433
3434 // Strip query params from the failed URL.
3435 GURL::Replacements remove_params;
3436 remove_params.ClearUsername();
3437 remove_params.ClearPassword();
3438 remove_params.ClearQuery();
3439 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553440 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503441 std::string spec_to_send = url_to_send.spec();
3442 // Notify link doctor of the url truncation by sending of "?" at the end.
3443 if (failed_url.has_query())
3444 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293445
3446 // Construct the query params to send to link doctor.
3447 std::string params(alternate_error_page_url_.query());
3448 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023449 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293450 params.append("&sourceid=chrome");
3451 params.append("&error=");
3452 switch (error_type) {
3453 case DNS_ERROR:
3454 params.append("dnserror");
3455 break;
3456
3457 case HTTP_404:
3458 params.append("http404");
3459 break;
3460
[email protected]5df266ac2008-10-15 19:50:133461 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333462 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133463 break;
3464
initial.commit09911bf2008-07-26 23:55:293465 default:
3466 NOTREACHED() << "unknown ErrorPageType";
3467 }
3468
3469 // OK, build the final url to return.
3470 GURL::Replacements link_doctor_params;
3471 link_doctor_params.SetQueryStr(params);
3472 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3473 return url;
3474}
3475
[email protected]310ebd6302011-10-10 19:06:283476GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593477 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3478 return GURL();
3479 else
3480 return creator_url_;
3481}
3482
[email protected]310ebd6302011-10-10 19:06:283483WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273484 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313485 web_ui_bindings_.reset(new WebUIBindings(
3486 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463487 }
[email protected]c50008512011-02-03 01:17:273488 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463489}
3490
[email protected]310ebd6302011-10-10 19:06:283491WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013492 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493493}
3494
[email protected]310ebd6302011-10-10 19:06:283495void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3496 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273497 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493498
[email protected]872542532011-06-23 00:43:163499 // Check if the plugin still exists in the document.
3500 if (main_frame->document().isPluginDocument() &&
3501 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493502 if (options.findNext) {
3503 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013504 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493505 } else {
[email protected]afdbd142010-07-10 08:01:233506 if (GetWebPluginFromPluginDocument()->startFind(
3507 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493508 } else {
[email protected]e7c58a32010-08-13 19:47:113509 // Send "no results".
3510 Send(new ViewHostMsg_Find_Reply(routing_id_,
3511 request_id,
3512 0,
3513 gfx::Rect(),
3514 0,
3515 true));
[email protected]24a7f3c2010-03-25 08:26:493516 }
3517 }
3518 return;
3519 }
3520
[email protected]b4bb2502009-10-01 22:35:273521 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273522 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293523 WebFrame* search_frame = focused_frame; // start searching focused frame.
3524
3525 bool multi_frame = (frame_after_main != main_frame);
3526
3527 // If we have multiple frames, we don't want to wrap the search within the
3528 // frame, so we check here if we only have main_frame in the chain.
3529 bool wrap_within_frame = !multi_frame;
3530
[email protected]b3f2b912009-04-09 16:18:523531 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293532 bool result = false;
3533
[email protected]7830da3e2009-11-06 16:27:263534 // If something is selected when we start searching it means we cannot just
3535 // increment the current match ordinal; we need to re-generate it.
3536 WebRange current_selection = focused_frame->selectionRange();
3537
initial.commit09911bf2008-07-26 23:55:293538 do {
[email protected]dd7daa82009-08-10 05:46:453539 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593540 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293541
3542 if (!result) {
3543 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223544 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293545
3546 // Find the next frame, but skip the invisible ones.
3547 do {
3548 // What is the next frame to search? (we might be going backwards). Note
3549 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593550 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273551 search_frame->traverseNext(true) :
3552 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453553 } while (!search_frame->hasVisibleContent() &&
3554 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293555
[email protected]884db412008-11-24 23:46:503556 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223557 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293558
3559 // If we have multiple frames and we have wrapped back around to the
3560 // focused frame, we need to search it once more allowing wrap within
3561 // the frame, otherwise it will report 'no match' if the focused frame has
3562 // reported matches, but no frames after the focused_frame contain a
3563 // match for the search word(s).
3564 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453565 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593566 request_id, search_text, options, true, // Force wrapping.
3567 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293568 }
3569 }
3570
[email protected]26aa0482009-09-30 16:55:273571 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293572 } while (!result && search_frame != focused_frame);
3573
[email protected]7830da3e2009-11-06 16:27:263574 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293575 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453576 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293577 } else {
3578 // If nothing is found, set result to "0 of 0", otherwise, set it to
3579 // "-1 of 1" to indicate that we found at least one item, but we don't know
3580 // yet what is active.
3581 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3582 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293583
[email protected]4f3dc372009-02-24 00:10:293584 // If we find no matches then this will be our last status update.
3585 // Otherwise the scoping effort will send more results.
3586 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293587
[email protected]4f3dc372009-02-24 00:10:293588 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403589 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593590 request_id,
[email protected]4f3dc372009-02-24 00:10:293591 match_count,
3592 selection_rect,
3593 ordinal,
3594 final_status_update));
initial.commit09911bf2008-07-26 23:55:293595
initial.commit09911bf2008-07-26 23:55:293596 // Scoping effort begins, starting with the mainframe.
3597 search_frame = main_frame;
3598
[email protected]dd7daa82009-08-10 05:46:453599 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293600
3601 do {
3602 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453603 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293604
3605 // We don't start another scoping effort unless at least one match has
3606 // been found.
3607 if (result) {
3608 // Start new scoping request. If the scoping function determines that it
3609 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453610 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593611 search_text,
3612 options,
initial.commit09911bf2008-07-26 23:55:293613 true); // reset the tickmarks
3614 }
3615
3616 // Iterate to the next frame. The frame will not necessarily scope, for
3617 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273618 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293619 } while (search_frame != main_frame);
3620 }
3621}
3622
[email protected]815dd9872011-11-23 18:40:303623void RenderViewImpl::OnStopFinding(content::StopFindAction action) {
[email protected]24a7f3c2010-03-25 08:26:493624 WebView* view = webview();
3625 if (!view)
3626 return;
3627
3628 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163629 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013630 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493631 return;
3632 }
3633
[email protected]815dd9872011-11-23 18:40:303634 bool clear_selection = action == content::STOP_FIND_ACTION_CLEAR_SELECTION;
[email protected]24a7f3c2010-03-25 08:26:493635 if (clear_selection)
3636 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3637
3638 WebFrame* frame = view->mainFrame();
3639 while (frame) {
3640 frame->stopFinding(clear_selection);
3641 frame = frame->traverseNext(false);
3642 }
3643
[email protected]815dd9872011-11-23 18:40:303644 if (action == content::STOP_FIND_ACTION_ACTIVATE_SELECTION) {
[email protected]24a7f3c2010-03-25 08:26:493645 WebFrame* focused_frame = view->focusedFrame();
3646 if (focused_frame) {
3647 WebDocument doc = focused_frame->document();
3648 if (!doc.isNull()) {
3649 WebNode node = doc.focusedNode();
3650 if (!node.isNull())
3651 node.simulateClick();
3652 }
3653 }
3654 }
3655}
3656
[email protected]310ebd6302011-10-10 19:06:283657void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493658 // Check if there is any queued up request waiting to be sent.
3659 if (queued_find_reply_message_.get()) {
3660 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423661 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493662 }
3663}
3664
[email protected]54087fe2011-10-28 22:02:483665void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513666 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3667 return;
3668
[email protected]258d31122010-05-09 10:59:413669 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103670
[email protected]b75b8292010-10-01 07:28:253671 double old_zoom_level = webview()->zoomLevel();
3672 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483673 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253674 zoom_level = 0;
3675 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3676 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483677 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253678 } else {
3679 // Either the user hit the zoom factor limit and thus the zoom level is now
3680 // not a whole number, or a plugin changed it to a custom value. We want
3681 // to go to the next whole number so that the user can always get back to
3682 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483683 if ((old_zoom_level > 1 && zoom > 0) ||
3684 (old_zoom_level < 1 && zoom < 0)) {
3685 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253686 } else {
3687 // We're going towards 100%, so first go to the next whole number.
3688 zoom_level = static_cast<int>(old_zoom_level);
3689 }
3690 }
[email protected]b75b8292010-10-01 07:28:253691 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413692 zoomLevelChanged();
3693}
3694
3695void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3696 int zoom_center_x, int zoom_center_y) {
3697 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3698 kScalingIncrementForGesture);
3699}
3700
3701void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3702 int zoom_center_x,
3703 int zoom_center_y,
3704 float scaling_increment) {
3705 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3706 return;
3707
[email protected]c514d6372011-08-16 22:54:443708 double old_page_scale_factor = webview()->pageScaleFactor();
3709 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:483710 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:443711 page_scale_factor = 1.0;
3712 } else {
3713 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:413714 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:443715 }
[email protected]47578fa02011-11-02 19:34:413716 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:093717 webview()->setPageScaleFactor(page_scale_factor,
3718 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:413719 }
[email protected]40bd6582009-12-04 23:49:513720}
3721
[email protected]310ebd6302011-10-10 19:06:283722void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173723 webview()->hidePopups();
3724 webview()->setZoomLevel(false, zoom_level);
3725 zoomLevelChanged();
3726}
3727
[email protected]310ebd6302011-10-10 19:06:283728void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3729 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543730 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293731}
3732
[email protected]310ebd6302011-10-10 19:06:283733void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273734 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293735}
3736
[email protected]310ebd6302011-10-10 19:06:283737void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273738 WebString no_encoding;
3739 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183740}
3741
[email protected]310ebd6302011-10-10 19:06:283742WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453743 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273744 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453745
3746 // xpath string can represent a frame deep down the tree (across multiple
3747 // frame DOMs).
3748 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3749 // should break into 2 xpaths
3750 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413751 std::vector<string16> xpaths;
3752 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453753
[email protected]26aa0482009-09-30 16:55:273754 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413755 for (std::vector<string16>::const_iterator i = xpaths.begin();
3756 frame && i != xpaths.end(); ++i) {
3757 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293758 }
3759
[email protected]dd7daa82009-08-10 05:46:453760 return frame;
initial.commit09911bf2008-07-26 23:55:293761}
3762
[email protected]310ebd6302011-10-10 19:06:283763void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
3764 const string16& jscript,
3765 int id,
3766 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:533767 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293768}
3769
[email protected]310ebd6302011-10-10 19:06:283770void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
3771 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413772 WebFrame* frame = GetChildFrame(frame_xpath);
3773 if (!frame)
[email protected]216813952011-05-19 22:21:263774 return;
[email protected]ae461542009-06-19 19:03:413775
[email protected]01cf589c2011-07-28 18:04:033776 frame->document().insertUserStyleSheet(
3777 WebString::fromUTF8(css),
3778 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483779}
3780
[email protected]310ebd6302011-10-10 19:06:283781void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:093782 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293783}
3784
[email protected]310ebd6302011-10-10 19:06:283785void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
3786 const std::string& value) {
[email protected]e091df82011-10-11 18:13:213787 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:273788 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293789}
3790
[email protected]310ebd6302011-10-10 19:06:283791void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
3792 const gfx::Point& client_point,
3793 const gfx::Point& screen_point,
3794 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553795 WebDragOperation operation = webview()->dragTargetDragEnter(
3796 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553797 client_point,
3798 screen_point,
3799 ops);
3800
3801 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3802}
3803
[email protected]310ebd6302011-10-10 19:06:283804void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
3805 const gfx::Point& screen_point,
3806 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553807 WebDragOperation operation = webview()->dragTargetDragOver(
3808 client_point,
3809 screen_point,
3810 ops);
3811
3812 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3813}
3814
[email protected]310ebd6302011-10-10 19:06:283815void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:553816 webview()->dragTargetDragLeave();
3817}
3818
[email protected]310ebd6302011-10-10 19:06:283819void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
3820 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:553821 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573822
3823 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553824}
3825
[email protected]310ebd6302011-10-10 19:06:283826void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3827 const gfx::Point& screen_point,
3828 bool ended,
3829 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033830 if (ended) {
[email protected]26aa0482009-09-30 16:55:273831 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203832 } else {
3833 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033834 }
initial.commit09911bf2008-07-26 23:55:293835}
3836
[email protected]310ebd6302011-10-10 19:06:283837void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273838 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293839}
3840
[email protected]310ebd6302011-10-10 19:06:283841void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593842 webkit_preferences_ = prefs;
3843 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293844}
3845
[email protected]310ebd6302011-10-10 19:06:283846void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:293847 alternate_error_page_url_ = url;
3848}
3849
[email protected]310ebd6302011-10-10 19:06:283850void RenderViewImpl::OnCustomContextMenuAction(
[email protected]b29aa74b2011-01-31 21:41:083851 const webkit_glue::CustomContextMenuContext& custom_context,
3852 unsigned action) {
3853 if (custom_context.is_pepper_menu)
3854 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3855 else
3856 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:583857 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3858 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:333859}
3860
[email protected]310ebd6302011-10-10 19:06:283861void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:513862 int id,
3863 const std::vector<FilePath>& paths) {
3864 if (!enumeration_completions_[id])
3865 return;
3866
3867 WebVector<WebString> ws_file_names(paths.size());
3868 for (size_t i = 0; i < paths.size(); ++i)
3869 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3870
3871 enumeration_completions_[id]->didChooseFile(ws_file_names);
3872 enumeration_completions_.erase(id);
3873}
3874
[email protected]310ebd6302011-10-10 19:06:283875void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363876 // This could happen if we navigated to a different page before the user
3877 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473878 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363879 return;
3880
[email protected]cdaf8d02010-03-30 19:52:473881 WebVector<WebString> ws_file_names(paths.size());
3882 for (size_t i = 0; i < paths.size(); ++i)
3883 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463884
[email protected]cdaf8d02010-03-30 19:52:473885 if (file_chooser_completions_.front()->completion)
3886 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3887 file_chooser_completions_.pop_front();
3888
3889 // If there are more pending file chooser requests, schedule one now.
3890 if (!file_chooser_completions_.empty()) {
3891 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3892 file_chooser_completions_.front()->params));
3893 }
initial.commit09911bf2008-07-26 23:55:293894}
3895
[email protected]244ac1892011-12-02 17:04:473896void RenderViewImpl::OnEnableAutoResize(const gfx::Size& min_size,
3897 const gfx::Size& max_size) {
3898 DCHECK(disable_scrollbars_size_limit_.IsEmpty());
3899 if (!webview())
3900 return;
3901 webview()->enableAutoResizeMode(true, min_size, max_size);
3902}
3903
[email protected]2bf834f2011-11-17 20:02:213904void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:243905 if (send_preferred_size_changes_)
3906 return;
[email protected]9fb325e2010-05-06 18:23:243907 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393908
[email protected]d812fd12011-05-27 23:05:073909 // Start off with an initial preferred size notification (in case
3910 // |didUpdateLayout| was already called).
[email protected]169d4282011-11-30 19:33:593911 didUpdateLayout();
[email protected]0666aef2009-05-13 19:48:083912}
3913
[email protected]310ebd6302011-10-10 19:06:283914void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:103915 const gfx::Size& disable_scrollbar_size_limit) {
3916 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3917}
3918
[email protected]310ebd6302011-10-10 19:06:283919void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:313920 const content::RendererPreferences& renderer_prefs) {
[email protected]d051d9a2011-12-10 02:02:503921 double old_zoom_level = renderer_preferences_.default_zoom_level;
[email protected]80d96fa2009-06-10 22:34:513922 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373923 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133924#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413925 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3926 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463927 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513928 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343929 renderer_prefs.thumb_inactive_color,
3930 renderer_prefs.thumb_active_color,
3931 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323932
[email protected]644d77e2010-01-27 01:03:103933 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323934 webview()->setScrollbarColors(
3935 renderer_prefs.thumb_inactive_color,
3936 renderer_prefs.thumb_active_color,
3937 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103938 webview()->setSelectionColors(
3939 renderer_prefs.active_selection_bg_color,
3940 renderer_prefs.active_selection_fg_color,
3941 renderer_prefs.inactive_selection_bg_color,
3942 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463943 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103944 }
[email protected]7a74e102009-09-03 00:16:563945#endif
[email protected]d051d9a2011-12-10 02:02:503946 // If the zoom level for this page matches the old zoom default, and this
3947 // is not a plugin, update the zoom level to match the new default.
3948 if (webview() && !webview()->mainFrame()->document().isPluginDocument() &&
3949 content::ZoomValuesEqual(webview()->zoomLevel(), old_zoom_level)) {
3950 webview()->setZoomLevel(false, renderer_preferences_.default_zoom_level);
3951 zoomLevelChanged();
3952 }
[email protected]80d96fa2009-06-10 22:34:513953}
3954
[email protected]310ebd6302011-10-10 19:06:283955void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
3956 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:283957 if (webview())
3958 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563959}
3960
[email protected]310ebd6302011-10-10 19:06:283961void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:193962 const GURL& page_url) {
3963 // Prepare list to storage all savable resource links.
3964 std::vector<GURL> resources_list;
3965 std::vector<GURL> referrers_list;
3966 std::vector<GURL> frames_list;
3967 webkit_glue::SavableResourcesResult result(&resources_list,
3968 &referrers_list,
3969 &frames_list);
3970
[email protected]445e1042011-12-03 21:03:153971 // FIXME(rdsmith): When GetAllSavableResourceLinksForCurrentPage starts to
3972 // return referrers, it should also return the referrer policies.
[email protected]18d5be92011-07-25 18:00:193973 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3974 webview(),
3975 page_url,
3976 &result,
[email protected]2a80aee2011-10-07 16:06:033977 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:193978 // If something is wrong when collecting all savable resource links,
3979 // send empty list to embedder(browser) to tell it failed.
3980 referrers_list.clear();
3981 resources_list.clear();
3982 frames_list.clear();
3983 }
3984
3985 // Send result of all savable resource links to embedder.
3986 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3987 resources_list,
3988 referrers_list,
3989 frames_list));
3990}
3991
[email protected]310ebd6302011-10-10 19:06:283992void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:193993 const std::vector<GURL>& links,
3994 const std::vector<FilePath>& local_paths,
3995 const FilePath& local_directory_name) {
3996
3997 // Convert std::vector of GURLs to WebVector<WebURL>
3998 WebVector<WebURL> weburl_links(links);
3999
4000 // Convert std::vector of std::strings to WebVector<WebString>
4001 WebVector<WebString> webstring_paths(local_paths.size());
4002 for (size_t i = 0; i < local_paths.size(); i++)
4003 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4004
4005 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
4006 webstring_paths,
4007 webkit_glue::FilePathToWebString(
4008 local_directory_name));
4009}
4010
[email protected]310ebd6302011-10-10 19:06:284011void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274012 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474013 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294014}
4015
[email protected]310ebd6302011-10-10 19:06:284016void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]992db4c2011-05-12 15:37:154017 if (is_swapped_out_)
4018 return;
4019
4020 // Swap this RenderView out so the tab can navigate to a page rendered by a
4021 // different process. This involves running the unload handler and clearing
4022 // the page. Once WasSwappedOut is called, we also allow this process to exit
4023 // if there are no other active RenderViews in it.
4024
4025 // Send an UpdateState message before we get swapped out.
4026 SyncNavigationState();
4027
4028 // Synchronously run the unload handler before sending the ACK.
4029 webview()->dispatchUnloadEvent();
4030
4031 // Swap out and stop sending any IPC messages that are not ACKs.
4032 SetSwappedOut(true);
4033
4034 // Replace the page with a blank dummy URL. The unload handler will not be
4035 // run a second time, thanks to a check in FrameLoader::stopLoading.
4036 // TODO(creis): Need to add a better way to do this that avoids running the
4037 // beforeunload handler. For now, we just run it a second time silently.
4038 webview()->mainFrame()->loadHTMLString(std::string(),
4039 GURL("about:swappedout"),
4040 GURL("about:swappedout"),
4041 false);
4042
4043 // Just echo back the params in the ACK.
4044 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
4045}
4046
[email protected]310ebd6302011-10-10 19:06:284047void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:374048 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:294049 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4050 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4051 // in the onunload handler from appearing. For now, we're bypassing that and
4052 // calling the FrameLoader's CloseURL method directly. This should be
4053 // revisited to avoid having two ways to close a page. Having a single way
4054 // to close that can run onunload is also useful for fixing
4055 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:274056 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294057
[email protected]992db4c2011-05-12 15:37:154058 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:294059}
4060
[email protected]310ebd6302011-10-10 19:06:284061void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:024062#if defined(USE_AURA)
4063 // Aura doesn't care if we switch themes.
4064#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:164065 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:464066 if (webview())
4067 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:574068#else // defined(OS_WIN)
4069 // TODO(port): we don't support theming on non-Windows platforms yet
4070 NOTIMPLEMENTED();
4071#endif
initial.commit09911bf2008-07-26 23:55:294072}
4073
[email protected]310ebd6302011-10-10 19:06:284074void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:084075 if (decrement_shared_popup_at_destruction_)
4076 shared_popup_counter_->data--;
4077 shared_popup_counter_ = new SharedRenderViewCounter(0);
4078 decrement_shared_popup_at_destruction_ = false;
4079}
4080
[email protected]310ebd6302011-10-10 19:06:284081bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
4082 const WebURLError& error,
4083 bool replace) {
[email protected]15d79e12009-08-02 19:23:454084 // We only show alternate error pages in the main frame. They are
4085 // intended to assist the user when navigating, so there is not much
4086 // value in showing them for failed subframes. Ideally, we would be
4087 // able to use the TYPED transition type for this, but that flag is
4088 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:454089 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:454090 return false;
4091
4092 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374093 // connection failure.
[email protected]15d79e12009-08-02 19:23:454094 int ec = error.reason;
4095 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4096 ec != net::ERR_CONNECTION_FAILED &&
4097 ec != net::ERR_CONNECTION_REFUSED &&
4098 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374099 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454100 return false;
4101
4102 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554103 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454104 if (!error_page_url.is_valid())
4105 return false;
4106
4107 // Load an empty page first so there is an immediate response to the error,
4108 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454109 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364110 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454111 error.unreachableURL,
4112 replace);
4113
4114 // Now, create a fetcher for the error page and associate it with the data
4115 // source we just created via the LoadHTMLString call. That way if another
4116 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074117 DocumentState* document_state =
4118 DocumentState::FromDataSource(frame->provisionalDataSource());
4119 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454120 new AltErrorPageResourceFetcher(
4121 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084122 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4123 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454124 return true;
4125}
4126
[email protected]310ebd6302011-10-10 19:06:284127void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4128 const WebURLError& original_error,
4129 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454130 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094131 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554132 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094133 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454134}
4135
[email protected]310ebd6302011-10-10 19:06:284136void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004137 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474138 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004139}
4140
[email protected]310ebd6302011-10-10 19:06:284141void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094142 const gfx::Rect& resizer_rect,
4143 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104144 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474145 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104146 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204147 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314148 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104149 }
[email protected]dd6afca2011-08-13 03:44:314150 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104151 }
4152
[email protected]ee41e7d22011-10-14 19:34:094153 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004154}
[email protected]0aa477bd2009-03-23 22:21:434155
[email protected]310ebd6302011-10-10 19:06:284156void RenderViewImpl::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014157 // Notify the pepper plugins that we started painting.
4158 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284159}
4160
[email protected]310ebd6302011-10-10 19:06:284161void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284162 // Notify any pepper plugins that we painted. This will call into the plugin,
4163 // and we it may ask to close itself as a result. This will, in turn, modify
4164 // our set, possibly invalidating the iterator. So we iterate on a copy that
4165 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014166 pepper_delegate_.ViewFlushedPaint();
4167
[email protected]00c39612010-03-06 02:53:284168 WebFrame* main_frame = webview()->mainFrame();
4169
4170 // If we have a provisional frame we are between the start and commit stages
4171 // of loading and we don't want to save stats.
4172 if (!main_frame->provisionalDataSource()) {
4173 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074174 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284175
[email protected]05c8e502010-08-15 15:13:524176 // TODO(jar): The following code should all be inside a method, probably in
4177 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284178 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074179 if (document_state->first_paint_time().is_null()) {
4180 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284181 }
[email protected]007733c2011-11-17 00:34:074182 if (document_state->first_paint_after_load_time().is_null() &&
4183 !document_state->finish_load_time().is_null()) {
4184 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284185 }
4186 }
4187}
4188
[email protected]310ebd6302011-10-10 19:06:284189void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084190 RenderWidget::OnSwapBuffersPosted();
4191}
4192
[email protected]310ebd6302011-10-10 19:06:284193void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244194 RenderWidget::OnSwapBuffersComplete();
4195}
4196
[email protected]310ebd6302011-10-10 19:06:284197void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244198 RenderWidget::OnSwapBuffersAborted();
4199}
4200
[email protected]310ebd6302011-10-10 19:06:284201webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154202 const gfx::Rect& paint_bounds,
4203 TransportDIB** dib,
4204 gfx::Rect* location,
4205 gfx::Rect* clip) {
4206 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4207 paint_bounds, dib, location, clip);
4208}
4209
[email protected]310ebd6302011-10-10 19:06:284210gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074211 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434212 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524213}
4214
[email protected]310ebd6302011-10-10 19:06:284215void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164216 if (webview())
[email protected]26aa0482009-09-30 16:55:274217 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164218}
4219
[email protected]310ebd6302011-10-10 19:06:284220void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144221 if (webview())
[email protected]b4bb2502009-10-01 22:35:274222 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144223
4224 SetBackground(background);
4225}
4226
[email protected]310ebd6302011-10-10 19:06:284227void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344228 if (webview())
[email protected]b4bb2502009-10-01 22:35:274229 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264230
4231#if defined(OS_MACOSX)
4232 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4233 for (plugin_it = plugin_delegates_.begin();
4234 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4235 (*plugin_it)->SetWindowFocus(active);
4236 }
4237#endif
[email protected]8c66c5a2009-07-22 17:26:344238}
4239
[email protected]6ce7abc52010-02-02 18:40:144240#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284241void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144242 // Inform plugins that their container has changed visibility.
4243 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4244 for (plugin_it = plugin_delegates_.begin();
4245 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4246 (*plugin_it)->SetContainerVisibility(visible);
4247 }
4248}
[email protected]1e6e3c992010-02-08 15:52:134249
[email protected]310ebd6302011-10-10 19:06:284250void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4251 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134252 // Inform plugins that their window's frame has changed.
4253 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4254 for (plugin_it = plugin_delegates_.begin();
4255 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4256 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4257 }
4258}
[email protected]935d63d2010-10-15 23:31:554259
[email protected]310ebd6302011-10-10 19:06:284260void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4261 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134262 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554263 // applies to it or not, so inform all the delegates.
4264 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4265 for (plugin_it = plugin_delegates_.begin();
4266 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134267 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554268 }
4269}
[email protected]6ce7abc52010-02-02 18:40:144270#endif // OS_MACOSX
4271
[email protected]310ebd6302011-10-10 19:06:284272void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484273 const EditCommands& edit_commands) {
4274 edit_commands_ = edit_commands;
4275}
4276
[email protected]310ebd6302011-10-10 19:06:284277void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594278 // We need to grab a pointer to the doomed WebView before we destroy it.
4279 WebView* doomed = webview();
4280 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494281 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594282}
4283
[email protected]310ebd6302011-10-10 19:06:284284void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484285 edit_commands_.clear();
4286}
4287
[email protected]310ebd6302011-10-10 19:06:284288bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]b993705a2011-10-09 23:00:244289 return pepper_delegate_.HandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374290}
4291
[email protected]310ebd6302011-10-10 19:06:284292void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514293 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064294}
4295
[email protected]310ebd6302011-10-10 19:06:284296void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244297 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4298}
4299
[email protected]310ebd6302011-10-10 19:06:284300void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434301 RenderWidget::OnWasHidden();
4302
[email protected]a6939ca42011-02-18 17:58:074303 if (webview()) {
4304 webview()->settings()->setMinimumTimerInterval(
4305 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444306 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074307 }
4308
4309#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434310 // Inform plugins that their container is no longer visible.
4311 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4312 for (plugin_it = plugin_delegates_.begin();
4313 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4314 (*plugin_it)->SetContainerVisibility(false);
4315 }
[email protected]a6939ca42011-02-18 17:58:074316#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434317}
4318
[email protected]310ebd6302011-10-10 19:06:284319void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434320 RenderWidget::OnWasRestored(needs_repainting);
4321
[email protected]a6939ca42011-02-18 17:58:074322 if (webview()) {
4323 webview()->settings()->setMinimumTimerInterval(
4324 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444325 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074326 }
4327
4328#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434329 // Inform plugins that their container is now visible.
4330 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4331 for (plugin_it = plugin_delegates_.begin();
4332 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4333 (*plugin_it)->SetContainerVisibility(true);
4334 }
[email protected]784ea1ab2010-09-18 00:02:344335#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074336}
[email protected]1e6e3c992010-02-08 15:52:134337
[email protected]310ebd6302011-10-10 19:06:284338bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384339 if (WebWidgetHandlesCompositorScheduling())
4340 return false;
4341
[email protected]65225772011-05-12 21:10:244342 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4343 if (!context)
4344 return false;
4345 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4346 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4347 std::string::npos;
4348}
4349
[email protected]310ebd6302011-10-10 19:06:284350void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134351 RenderWidget::OnSetFocus(enable);
4352
[email protected]7d3c02c2010-05-05 23:10:314353 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074354 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134355 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4356 for (plugin_it = plugin_delegates_.begin();
4357 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344358#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314359 // RenderWidget's call to setFocus can cause the underlying webview's
4360 // activation state to change just like a call to setIsActive.
4361 if (enable)
4362 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344363#endif
[email protected]7d3c02c2010-05-05 23:10:314364 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134365 }
[email protected]589621b2010-09-23 22:01:074366
4367 // Notify all Pepper plugins.
4368 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134369 }
4370}
[email protected]941e4552010-02-01 21:23:434371
[email protected]310ebd6302011-10-10 19:06:284372void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004373 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504374 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574375}
4376
[email protected]73bf95812011-10-12 11:38:324377void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004378 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324379}
4380
[email protected]3f783362011-10-21 22:40:504381void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4382 UpdateSelectionBounds();
4383}
4384
[email protected]73bf95812011-10-12 11:38:324385void RenderViewImpl::PpapiPluginCancelComposition() {
4386 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4387 ui::Range range(ui::Range::InvalidRange());
4388 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4389}
4390
[email protected]310ebd6302011-10-10 19:06:284391void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574392 const string16& text,
4393 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4394 int selection_start,
4395 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324396 if (pepper_delegate_.IsPluginFocused()) {
4397 // When a PPAPI plugin has focus, we bypass WebKit.
4398 pepper_delegate_.OnImeSetComposition(text,
4399 underlines,
4400 selection_start,
4401 selection_end);
4402 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234403#if defined(OS_WIN)
4404 // When a plug-in has focus, we create platform-specific IME data used by
4405 // our IME emulator and send it directly to the focused plug-in, i.e. we
4406 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4407 // instance ID is the same one as the specified ID.)
4408 if (focused_plugin_id_ >= 0) {
4409 std::vector<int> clauses;
4410 std::vector<int> target;
4411 for (size_t i = 0; i < underlines.size(); ++i) {
4412 clauses.push_back(underlines[i].startOffset);
4413 clauses.push_back(underlines[i].endOffset);
4414 if (underlines[i].thick) {
4415 target.clear();
4416 target.push_back(underlines[i].startOffset);
4417 target.push_back(underlines[i].endOffset);
4418 }
4419 }
4420 std::set<WebPluginDelegateProxy*>::iterator it;
4421 for (it = plugin_delegates_.begin();
4422 it != plugin_delegates_.end(); ++it) {
4423 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4424 focused_plugin_id_);
4425 }
4426 return;
4427 }
4428#endif
[email protected]56ea1a62011-05-30 07:05:574429 RenderWidget::OnImeSetComposition(text,
4430 underlines,
4431 selection_start,
4432 selection_end);
4433 }
4434}
4435
[email protected]4de6d1692011-10-12 08:45:444436void RenderViewImpl::OnImeConfirmComposition(
4437 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574438 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324439 // When a PPAPI plugin has focus, we bypass WebKit.
4440 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574441 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234442#if defined(OS_WIN)
4443 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4444 // plug-ins. When we send IME text directly to plug-ins, we should not send
4445 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444446 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234447 if (focused_plugin_id_ >= 0) {
4448 std::set<WebPluginDelegateProxy*>::iterator it;
4449 for (it = plugin_delegates_.begin();
4450 it != plugin_delegates_.end(); ++it) {
4451 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4452 }
4453 return;
4454 }
4455#endif
[email protected]ebd28ac2011-10-13 18:49:054456 if (replacement_range.IsValid() && webview()) {
4457 // Select the text in |replacement_range|, it will then be replaced by
4458 // text added by the call to RenderWidget::OnImeConfirmComposition().
4459 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164460 WebRange webrange = WebRange::fromDocumentRange(
4461 frame, replacement_range.start(), replacement_range.length());
4462 if (!webrange.isNull())
4463 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054464 }
4465 }
[email protected]4de6d1692011-10-12 08:45:444466 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574467 }
4468}
4469
[email protected]310ebd6302011-10-10 19:06:284470ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324471 return pepper_delegate_.IsPluginFocused() ?
4472 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4473}
4474
[email protected]3f783362011-10-21 22:40:504475void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4476 if (pepper_delegate_.IsPluginFocused()) {
4477 // TODO(kinaba) http://crbug.com/101101
4478 // Current Pepper IME API does not handle selection bounds. So we simply
4479 // use the caret position as an empty range for now. It will be updated
4480 // after Pepper API equips features related to surrounding text retrieval.
4481 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4482 *start = caret;
4483 *end = caret;
4484 return;
4485 }
4486 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454487}
4488
[email protected]310ebd6302011-10-10 19:06:284489bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324490 return pepper_delegate_.IsPluginFocused() ?
4491 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574492}
4493
[email protected]e6ae0f6c2011-10-04 10:39:234494#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284495void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234496 if (focused)
4497 focused_plugin_id_ = plugin_id;
4498 else
4499 focused_plugin_id_ = -1;
4500}
4501#endif
4502
[email protected]43f28f832010-02-03 02:28:484503#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284504void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134505 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4506 focused, plugin_id);
4507 Send(msg);
4508}
4509
[email protected]310ebd6302011-10-10 19:06:284510void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134511 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554512 // This message can be sent during event-handling, and needs to be delivered
4513 // within that context.
4514 msg->set_unblock(true);
4515 Send(msg);
4516}
4517
[email protected]310ebd6302011-10-10 19:06:284518gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234519 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484520 gfx::PluginWindowHandle window = NULL;
4521 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234522 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114523 if (window) {
4524 fake_plugin_window_handles_.insert(window);
4525 }
[email protected]43f28f832010-02-03 02:28:484526 return window;
4527}
4528
[email protected]310ebd6302011-10-10 19:06:284529void RenderViewImpl::DestroyFakePluginWindowHandle(
4530 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114531 if (window && fake_plugin_window_handles_.find(window) !=
4532 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484533 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114534 fake_plugin_window_handles_.erase(window);
4535 }
[email protected]43f28f832010-02-03 02:28:484536}
4537
[email protected]310ebd6302011-10-10 19:06:284538void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4539 gfx::PluginWindowHandle window,
4540 int32 width,
4541 int32 height,
4542 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334543 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484544 routing_id(), window, width, height, io_surface_identifier));
4545}
4546
[email protected]310ebd6302011-10-10 19:06:284547void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334548 gfx::PluginWindowHandle window,
4549 int32 width,
4550 int32 height,
4551 TransportDIB::Handle transport_dib) {
4552 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074553 routing_id(), window, width, height, transport_dib));
4554}
4555
[email protected]310ebd6302011-10-10 19:06:284556TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334557 size_t size) {
[email protected]1aef98132010-02-23 18:00:074558 TransportDIB::Handle dib_handle;
4559 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384560 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074561 return dib_handle;
4562 // Return an invalid handle if Send() fails.
4563 return TransportDIB::DefaultHandleValue();
4564}
4565
[email protected]310ebd6302011-10-10 19:06:284566void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4567 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074568 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4569}
4570
[email protected]310ebd6302011-10-10 19:06:284571void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144572 gfx::PluginWindowHandle window, uint64 surface_id) {
4573 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4574 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484575}
4576#endif
[email protected]58c321d2010-02-19 12:11:284577
[email protected]310ebd6302011-10-10 19:06:284578bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234579 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474580 WebFileChooserCompletion* completion) {
4581 static const size_t kMaximumPendingFileChooseRequests = 4;
4582 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4583 // This sanity check prevents too many file choose requests from getting
4584 // queued which could DoS the user. Getting these is most likely a
4585 // programming error (there are many ways to DoS the user so it's not
4586 // considered a "real" security check), either in JS requesting many file
4587 // choosers to pop up, or in a plugin.
4588 //
4589 // TODO(brettw) we might possibly want to require a user gesture to open
4590 // a file picker, which will address this issue in a better way.
4591 return false;
4592 }
4593
4594 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4595 new PendingFileChooser(params, completion)));
4596 if (file_chooser_completions_.size() == 1) {
4597 // Actually show the browse dialog when this is the first request.
4598 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4599 }
4600 return true;
4601}
4602
[email protected]310ebd6302011-10-10 19:06:284603WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514604 if (!geolocation_dispatcher_)
4605 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4606 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254607}
[email protected]61c9f032010-03-31 23:04:194608
[email protected]310ebd6302011-10-10 19:06:284609WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114610 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224611#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514612 if (!speech_input_dispatcher_)
4613 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224614#endif
[email protected]676126f72011-01-15 00:03:514615 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114616}
4617
[email protected]310ebd6302011-10-10 19:06:284618WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514619 if (!device_orientation_dispatcher_)
4620 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4621 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534622}
4623
[email protected]310ebd6302011-10-10 19:06:284624void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4625 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254626 // For now, don't remember plugin zoom values. We don't want to mix them with
4627 // normal web content (i.e. a fixed layout plugin would usually want them
4628 // different).
4629 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4630
[email protected]b75b8292010-10-01 07:28:254631 int minimum_percent = static_cast<int>(
4632 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4633 int maximum_percent = static_cast<int>(
4634 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254635
4636 Send(new ViewHostMsg_UpdateZoomLimits(
4637 routing_id_, minimum_percent, maximum_percent, remember));
4638}
4639
[email protected]310ebd6302011-10-10 19:06:284640void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254641 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084642 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:254643 // Tell the browser which url got zoomed so it can update the menu and the
4644 // saved values if necessary
4645 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084646 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414647 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254648}
4649
[email protected]310ebd6302011-10-10 19:06:284650void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4651 const WebString& base_url,
4652 const WebString& url,
4653 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484654 GURL base(base_url);
4655 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4656 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4657 return;
4658 }
[email protected]f1a29a02011-10-06 23:08:444659 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4660 UTF16ToUTF8(scheme),
4661 absolute_url,
4662 title));
[email protected]a6d36cc2011-02-23 00:39:484663}
4664
[email protected]310ebd6302011-10-10 19:06:284665WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444666 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4667 WebKit::WebPageVisibilityStateHidden :
4668 WebKit::WebPageVisibilityStateVisible;
4669 WebKit::WebPageVisibilityState override_state = current_state;
4670 if (content::GetContentClient()->renderer()->
4671 ShouldOverridePageVisibilityState(this,
4672 &override_state))
4673 return override_state;
4674 return current_state;
[email protected]94dec932011-05-26 20:04:214675}
4676
[email protected]310ebd6302011-10-10 19:06:284677bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194678 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454679 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194680 if (frame->parent() != NULL)
4681 return false;
4682
[email protected]f0a3d0b2010-08-06 22:51:534683 // Navigations initiated within Webkit are not sent out to the external host
4684 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274685 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134686 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534687 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134688 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334689 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534690 return false;
4691
[email protected]2fc22d12010-12-02 23:08:164692 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324693 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014694 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164695 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014696 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324697 // The opener relationship between the new window and the parent allows the
4698 // new window to script the parent and vice versa. This is not allowed if
4699 // the origins of the two domains are different. This can be treated as a
4700 // top level navigation and routed back to the host.
4701 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274702 if (!opener) {
[email protected]86965362011-04-21 18:42:514703 return true;
[email protected]d19ea342011-04-20 20:31:134704 } else {
[email protected]b6cb3a842011-06-24 18:28:414705 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324706 return true;
4707 }
4708 }
[email protected]61c9f032010-03-31 23:04:194709 return false;
4710}
[email protected]2b06a992010-08-21 05:48:224711
[email protected]310ebd6302011-10-10 19:06:284712void RenderViewImpl::OnAsyncFileOpened(
4713 base::PlatformFileError error_code,
4714 IPC::PlatformFileForTransit file_for_transit,
4715 int message_id) {
[email protected]27a9ef32010-09-10 04:06:244716 pepper_delegate_.OnAsyncFileOpened(
4717 error_code,
4718 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4719 message_id);
4720}
[email protected]caf706f2010-10-26 17:54:084721
[email protected]310ebd6302011-10-10 19:06:284722void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:474723 int request_id,
4724 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434725 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474726 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4727 broker_process_handle,
4728 handle);
[email protected]eb415bf0e2011-04-14 02:45:424729}
4730
[email protected]caf706f2010-10-26 17:54:084731#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284732void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154733 if (external_popup_menu_ == NULL) {
4734 // Crash reports from the field indicate that we can be notified with a
4735 // NULL external popup menu (we probably get notified twice).
4736 // If you hit this please file a bug against jcivelli and include the page
4737 // and steps to repro.
4738 NOTREACHED();
4739 return;
4740 }
[email protected]caf706f2010-10-26 17:54:084741 external_popup_menu_->DidSelectItem(selected_index);
4742 external_popup_menu_.reset();
4743}
4744#endif
[email protected]bb461532010-11-26 21:50:234745
[email protected]1b4209f2011-01-07 00:25:404746#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:284747void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:404748 int request_id,
4749 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:494750 const PP_NetAddress_Private& local_addr,
4751 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:404752 pepper_delegate_.OnConnectTcpACK(
4753 request_id,
4754 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4755 local_addr,
4756 remote_addr);
4757}
4758#endif
[email protected]a6097f42011-01-10 08:50:514759
[email protected]310ebd6302011-10-10 19:06:284760void RenderViewImpl::OnContextMenuClosed(
[email protected]b29aa74b2011-01-31 21:41:084761 const webkit_glue::CustomContextMenuContext& custom_context) {
4762 if (custom_context.is_pepper_menu)
4763 pepper_delegate_.OnContextMenuClosed(custom_context);
4764 else
4765 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104766}
[email protected]5a7b15a2011-08-22 22:48:184767
[email protected]310ebd6302011-10-10 19:06:284768void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:184769 if (!webview())
4770 return;
4771 WebFrame* main_frame = webview()->mainFrame();
4772 if (!main_frame)
4773 return;
4774 main_frame->enableViewSourceMode(true);
4775}
[email protected]67bfb83f2011-09-22 03:36:374776
[email protected]310ebd6302011-10-10 19:06:284777void RenderViewImpl::OnLockMouseACK(bool succeeded) {
[email protected]57e02be2011-10-11 19:00:534778 // Mouse Lock removes the system cursor and provides all mouse motion as
4779 // .movementX/Y values on events all sent to a fixed target. This requires
4780 // content to specifically request the mode to be entered.
4781 // Mouse Capture is implicitly given for the duration of a drag event, and
4782 // sends all mouse events to the initial target of the drag.
4783 // If Lock is entered it supercedes any in progress Capture.
4784 if (succeeded)
4785 OnMouseCaptureLost();
4786
[email protected]67bfb83f2011-09-22 03:36:374787 pepper_delegate_.OnLockMouseACK(succeeded);
4788}
4789
[email protected]310ebd6302011-10-10 19:06:284790void RenderViewImpl::OnMouseLockLost() {
[email protected]67bfb83f2011-09-22 03:36:374791 pepper_delegate_.OnMouseLockLost();
4792}
[email protected]c3d45532011-10-07 19:20:404793
[email protected]310ebd6302011-10-10 19:06:284794bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:084795 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:404796}
[email protected]7f3c7af2011-10-20 22:52:514797
[email protected]64d0e192011-12-09 14:44:204798void RenderViewImpl::OnJavaBridgeInit() {
[email protected]7f3c7af2011-10-20 22:52:514799 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:184800#if defined(ENABLE_JAVA_BRIDGE)
[email protected]64d0e192011-12-09 14:44:204801 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this));
[email protected]464750f2011-10-24 23:16:184802#endif
[email protected]7f3c7af2011-10-20 22:52:514803}