blob: c855ed038b42d5053c5affa54048968e9b7df133 [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]2041cf342010-02-19 03:15:5912#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5014#include "base/compiler_specific.h"
[email protected]005bab02011-10-07 18:36:0015#include "base/json/json_value_serializer.h"
[email protected]b1cf3372011-04-20 21:28:1016#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4917#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2819#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4122#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2923#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2824#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2625#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2226#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1027#include "content/common/appcache/appcache_dispatcher.h"
[email protected]127dd582011-03-16 21:32:1028#include "content/common/clipboard_messages.h"
[email protected]db803aae2011-03-05 02:00:4229#include "content/common/content_constants.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]60916042011-03-19 00:43:3639#include "content/common/renderer_preferences.h"
[email protected]940895b2011-08-20 00:50:0540#include "content/common/request_extra_data.h"
[email protected]778574e2011-03-21 22:03:5041#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2142#include "content/public/common/bindings_policy.h"
[email protected]c08950d22011-10-13 22:20:2943#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0344#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3445#include "content/public/renderer/content_renderer_client.h"
[email protected]82ddba1c2011-10-04 00:15:3246#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4447#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3648#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1949#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0250#include "content/renderer/devtools_agent.h"
[email protected]55722152011-03-22 01:33:5351#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1952#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4053#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]1ef93132011-09-16 18:33:4754#include "content/renderer/intents_dispatcher.h"
[email protected]7f3c7af2011-10-20 22:52:5155#include "content/renderer/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0256#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0857#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3758#include "content/renderer/media/audio_renderer_impl.h"
[email protected]ab2c4732011-07-20 19:57:4059#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:4060#include "content/renderer/media/render_media_log.h"
[email protected]4a19be92011-09-22 14:25:0261#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1962#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3763#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3564#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0565#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4466#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4467#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3268#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0169#include "content/renderer/renderer_webapplicationcachehost_impl.h"
70#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1971#include "content/renderer/speech_input_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3272#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1973#include "content/renderer/v8_value_converter_impl.h"
[email protected]663bd9e2011-03-21 01:07:0174#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3575#include "content/renderer/webplugin_delegate_proxy.h"
76#include "content/renderer/websharedworker_proxy.h"
77#include "content/renderer/webworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4978#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4179#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2780#include "media/base/message_loop_factory_impl.h"
initial.commit09911bf2008-07-26 23:55:2981#include "net/base/escape.h"
82#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0483#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5784#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3785#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
86#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
87#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3788#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
89#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
90#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
91#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3792#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
93#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
94#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
95#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
96#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
97#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
98#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
99#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
100#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]69f110d62011-03-17 19:01:14102#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37103#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19104#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37105#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
111#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
112#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"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40119#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]8bd0fe62011-01-17 06:44:37120#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26128#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c4a9e932011-03-05 04:05:55129#include "ui/base/message_box_flags.h"
[email protected]08397d52011-02-05 01:53:38130#include "ui/gfx/native_widget_types.h"
131#include "ui/gfx/point.h"
132#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55133#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04134#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43135#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24136#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19137#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59138#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24139#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24140#include "webkit/glue/glue_serialize.h"
[email protected]85cc78c2010-05-04 18:30:09141#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26142#include "webkit/glue/password_form_dom_manager.h"
initial.commit09911bf2008-07-26 23:55:29143#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07144#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29145#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17146#include "webkit/glue/webmediaplayer_impl.h"
[email protected]b00ba702011-08-17 01:41:03147#include "webkit/glue/weburlloader_impl.h"
[email protected]191eb3f72010-12-21 06:27:50148#include "webkit/plugins/npapi/default_plugin_shared.h"
149#include "webkit/plugins/npapi/plugin_list.h"
150#include "webkit/plugins/npapi/webplugin_delegate.h"
151#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
152#include "webkit/plugins/npapi/webplugin_impl.h"
153#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52154#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29155
[email protected]6c8afae52009-01-22 02:24:57156#if defined(OS_WIN)
157// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57158// * theming
[email protected]08397d52011-02-05 01:53:38159#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03160#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37161#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51162#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33163#elif defined(OS_MACOSX)
164#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57165#endif
166
[email protected]9892b472010-09-16 00:23:42167using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08168using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21169using WebKit::WebApplicationCacheHost;
170using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26171using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41172using WebKit::WebColor;
173using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59174using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44175using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51176using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55177using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28178using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00179using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58180using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25181using WebKit::WebDragOperation;
182using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51183using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51184using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08185using WebKit::WebExternalPopupMenu;
186using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47187using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22188using WebKit::WebFileSystem;
189using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49190using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59191using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48192using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45193using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17194using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13195using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41196using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50197using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17198using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28199using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17200using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28201using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28202using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51203using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19204using WebKit::WebPageSerializer;
205using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17206using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40207using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49208using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09209using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52210using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59211using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51212using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52213using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40214using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35215using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29216using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17217using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59218using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42219using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02220using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34221using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40222using WebKit::WebStorageQuotaCallbacks;
223using WebKit::WebStorageQuotaError;
224using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28225using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51226using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52227using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24228using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28229using WebKit::WebURL;
230using WebKit::WebURLError;
231using WebKit::WebURLRequest;
232using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28233using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03234using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28235using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26236using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43237using WebKit::WebWorker;
238using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26239using appcache::WebApplicationCacheHostImpl;
240using base::Time;
241using base::TimeDelta;
[email protected]82ddba1c2011-10-04 00:15:32242using content::NavigationState;
[email protected]380244092011-10-07 17:26:27243using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44244using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36245using content::RenderViewVisitor;
[email protected]8d86f13d2011-10-04 17:01:19246using content::V8ValueConverter;
[email protected]6fdd4182010-10-14 23:59:26247using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26248using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26249using webkit_glue::PasswordForm;
250using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23251using webkit_glue::ResourceFetcher;
[email protected]e1acf6f2008-10-27 20:43:33252
initial.commit09911bf2008-07-26 23:55:29253//-----------------------------------------------------------------------------
254
[email protected]310ebd6302011-10-10 19:06:28255typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]625332e02010-12-14 07:48:49256static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02257
[email protected]882daa92009-11-05 16:31:31258// Time, in seconds, we delay before sending content state changes (such as form
259// state and scroll position) to the browser. We delay sending changes to avoid
260// spamming the browser.
261// To avoid having tab/session restore require sending a message to get the
262// current content state during tab closing we use a shorter timeout for the
263// foreground renderer. This means there is a small window of time from which
264// content state is modified and not sent to session restore, but this is
265// better than having to wake up all renderers during shutdown.
266static const int kDelaySecondsForContentStateSyncHidden = 5;
267static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29268
[email protected]e99ef6f2011-10-16 01:13:00269static const size_t kExtraCharsBeforeAndAfterSelection = 100;
270
[email protected]0aa55312008-10-17 21:53:08271// The maximum number of popups that can be spawned from one page.
272static const int kMaximumNumberOfUnacknowledgedPopups = 25;
273
[email protected]c514d6372011-08-16 22:54:44274static const float kScalingIncrement = 0.1f;
275
[email protected]726985e22009-06-18 21:09:28276static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
277 WebVector<WebURL> urls;
278 ds->redirectChain(urls);
279 result->reserve(urls.size());
280 for (size_t i = 0; i < urls.size(); ++i)
281 result->push_back(urls[i]);
282}
283
[email protected]6a8f5112011-05-13 16:38:44284// If |data_source| is non-null and has a NavigationState associated with it,
285// the AltErrorPageResourceFetcher is reset.
286static void StopAltErrorPageFetcher(WebDataSource* data_source) {
287 if (data_source) {
288 NavigationState* state = NavigationState::FromDataSource(data_source);
289 if (state)
290 state->set_alt_error_page_fetcher(NULL);
291 }
292}
293
initial.commit09911bf2008-07-26 23:55:29294///////////////////////////////////////////////////////////////////////////////
295
[email protected]310ebd6302011-10-10 19:06:28296int32 RenderViewImpl::next_page_id_ = 1;
[email protected]60c42a8c72009-10-09 04:08:59297
[email protected]310ebd6302011-10-10 19:06:28298struct RenderViewImpl::PendingFileChooser {
[email protected]cdaf8d02010-03-30 19:52:47299 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
300 WebFileChooserCompletion* c)
301 : params(p),
302 completion(c) {
303 }
304 ViewHostMsg_RunFileChooser_Params params;
305 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
306};
307
[email protected]310ebd6302011-10-10 19:06:28308RenderViewImpl::RenderViewImpl(gfx::NativeViewId parent_hwnd,
309 int32 opener_id,
310 const RendererPreferences& renderer_prefs,
311 const WebPreferences& webkit_prefs,
312 SharedRenderViewCounter* counter,
313 int32 routing_id,
314 int64 session_storage_namespace_id,
315 const string16& frame_name)
[email protected]380244092011-10-07 17:26:27316 : RenderWidget(WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51317 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02318 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09319 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02320 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24321 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21322 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02323 opened_by_user_gesture_(true),
324 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24325 page_id_(-1),
326 last_page_id_sent_to_browser_(-1),
[email protected]3cc72b12010-03-18 23:03:00327 history_list_offset_(-1),
328 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02329 target_url_status_(TARGET_NONE),
[email protected]dd6afca2011-08-13 03:44:31330 cached_is_main_frame_pinned_to_left_(false),
331 cached_is_main_frame_pinned_to_right_(false),
332 cached_has_main_frame_horizontal_scrollbar_(false),
333 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]18ca9a6b2010-06-02 19:05:18334 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e6ae0f6c2011-10-04 10:39:23335#if defined(OS_WIN)
336 focused_plugin_id_(-1),
337#endif
[email protected]3354d3e2010-06-10 19:53:02338 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51339 geolocation_dispatcher_(NULL),
340 speech_input_dispatcher_(NULL),
341 device_orientation_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18342 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41343 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32344 renderer_accessibility_(NULL),
[email protected]4fb60142011-08-09 02:22:08345 session_storage_namespace_id_(session_storage_namespace_id),
346 handling_select_range_(false) {
[email protected]676126f72011-01-15 00:03:51347 routing_id_ = routing_id;
348 if (opener_id != MSG_ROUTING_NONE)
349 opener_id_ = opener_id;
350
[email protected]11fee2332011-03-29 20:36:35351 webwidget_ = WebView::create(this);
352
[email protected]676126f72011-01-15 00:03:51353 if (counter) {
354 shared_popup_counter_ = counter;
355 shared_popup_counter_->data++;
356 decrement_shared_popup_at_destruction_ = true;
357 } else {
358 shared_popup_counter_ = new SharedRenderViewCounter(0);
359 decrement_shared_popup_at_destruction_ = false;
360 }
361
[email protected]1ef93132011-09-16 18:33:47362 intents_dispatcher_ = new IntentsDispatcher(this);
[email protected]676126f72011-01-15 00:03:51363 notification_provider_ = new NotificationProvider(this);
364
[email protected]380244092011-10-07 17:26:27365 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51366 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47367 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51368 AddRef();
369
370 // If this is a popup, we must wait for the CreatingNew_ACK message before
371 // completing initialization. Otherwise, we can finish it now.
372 if (opener_id == MSG_ROUTING_NONE) {
373 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55374 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51375 }
376
[email protected]34c61bd52011-05-02 19:38:33377 g_view_map.Get().insert(std::make_pair(webview(), this));
378 webkit_preferences_.Apply(webview());
379 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35380 if (!frame_name.empty())
381 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33382 webview()->settings()->setMinimumTimerInterval(
383 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
384 webkit_glue::kForegroundTabTimerInterval);
385
386 OnSetRendererPrefs(renderer_prefs);
387
[email protected]676126f72011-01-15 00:03:51388 host_window_ = parent_hwnd;
389
[email protected]a026daa2011-04-20 15:49:51390#if defined(ENABLE_P2P_APIS)
[email protected]b3f8f9722011-08-25 20:56:07391 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51392#endif
[email protected]cae8c8492011-03-03 11:12:18393
[email protected]8f6a3b852011-07-19 16:48:56394 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32395#if defined(OS_MACOSX)
396 new TextInputClientObserver(this);
397#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56398
[email protected]c5c1d6d2011-07-28 18:42:41399 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20400
[email protected]063afcb2011-09-29 07:54:32401 renderer_accessibility_ = new RendererAccessibility(this);
402
403 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]ab2c4732011-07-20 19:57:40404 if (command_line.HasSwitch(switches::kEnableMediaStream)) {
405 media_stream_impl_ = new MediaStreamImpl(
[email protected]f1a29a02011-10-06 23:08:44406 RenderThreadImpl::current()->video_capture_impl_manager());
[email protected]ab2c4732011-07-20 19:57:40407 }
408
[email protected]e48869a2011-04-01 19:56:03409 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29410}
411
[email protected]310ebd6302011-10-10 19:06:28412RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03413 history_page_ids_.clear();
414
[email protected]0aa55312008-10-17 21:53:08415 if (decrement_shared_popup_at_destruction_)
416 shared_popup_counter_->data--;
417
[email protected]a1128322009-10-06 18:38:46418 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47419 while (!file_chooser_completions_.empty()) {
420 if (file_chooser_completions_.front()->completion) {
421 file_chooser_completions_.front()->completion->didChooseFile(
422 WebVector<WebString>());
423 }
424 file_chooser_completions_.pop_front();
425 }
[email protected]a1128322009-10-06 18:38:46426
[email protected]83dde542009-09-11 20:59:55427#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11428 // Destroy all fake plugin window handles on the browser side.
429 while (!fake_plugin_window_handles_.empty()) {
430 // Make sure no NULL plugin window handles were inserted into this list.
431 DCHECK(*fake_plugin_window_handles_.begin());
432 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
433 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
434 }
[email protected]83dde542009-09-11 20:59:55435#endif
[email protected]98324892009-09-09 21:16:05436
[email protected]60c42a8c72009-10-09 04:08:59437#ifndef NDEBUG
438 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49439 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59440 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
441 DCHECK_NE(this, it->second) << "Failed to call Close?";
442#endif
[email protected]676126f72011-01-15 00:03:51443
[email protected]310ebd6302011-10-10 19:06:28444 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51445 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59446}
447
448/*static*/
[email protected]310ebd6302011-10-10 19:06:28449RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31450 ViewMap* views = g_view_map.Pointer();
451 ViewMap::iterator it = views->find(webview);
452 return it == views->end() ? NULL : it->second;
453}
454
455/*static*/
456content::RenderView*
457 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28458 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31459}
460
461/*static*/
462void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49463 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59464 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
465 if (!visitor->Visit(it->second))
466 return;
467 }
468}
469
470/*static*/
[email protected]310ebd6302011-10-10 19:06:28471RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15472 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08473 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51474 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08475 const WebPreferences& webkit_prefs,
476 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34477 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26478 int64 session_storage_namespace_id,
479 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29480 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28481 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51482 parent_hwnd,
483 opener_id,
484 renderer_prefs,
485 webkit_prefs,
486 counter,
487 routing_id,
488 session_storage_namespace_id,
489 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29490}
491
[email protected]bb461532010-11-26 21:50:23492// static
[email protected]310ebd6302011-10-10 19:06:28493void RenderViewImpl::SetNextPageID(int32 next_page_id) {
initial.commit09911bf2008-07-26 23:55:29494 // This method should only be called during process startup, and the given
495 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05496 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29497 DCHECK(next_page_id >= next_page_id_);
498 next_page_id_ = next_page_id;
499}
500
[email protected]310ebd6302011-10-10 19:06:28501void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51502 observers_.AddObserver(observer);
503}
504
[email protected]310ebd6302011-10-10 19:06:28505void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
506 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51507 observers_.RemoveObserver(observer);
508}
509
[email protected]310ebd6302011-10-10 19:06:28510WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26511 return static_cast<WebKit::WebView*>(webwidget());
512}
513
[email protected]310ebd6302011-10-10 19:06:28514void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40515 if (!enabled) {
516 load_progress_tracker_.reset(NULL);
517 return;
518 }
519 if (load_progress_tracker_ == NULL)
520 load_progress_tracker_.reset(new LoadProgressTracker(this));
521}
522
[email protected]310ebd6302011-10-10 19:06:28523void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51524 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29525}
526
[email protected]310ebd6302011-10-10 19:06:28527void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26528 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30529 // If the renderer is visible, set initial visibility and focus state.
530 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34531#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30532 delegate->SetContainerVisibility(true);
533 if (webview() && webview()->isActive())
534 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34535#endif
[email protected]49232292010-09-03 19:07:30536 }
[email protected]784ea1ab2010-09-18 00:02:34537 // Plugins start assuming the content has focus (so that they work in
538 // environments where RenderView isn't hosting them), so we always have to
539 // set the initial state. See webplugin_delegate_impl.h for details.
540 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26541}
542
[email protected]310ebd6302011-10-10 19:06:28543void RenderViewImpl::UnregisterPluginDelegate(
544 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26545 plugin_delegates_.erase(delegate);
546}
[email protected]d8fd6fa2010-02-01 15:54:26547
[email protected]310ebd6302011-10-10 19:06:28548bool RenderViewImpl::GetPluginInfo(const GURL& url,
549 const GURL& page_url,
550 const std::string& mime_type,
551 webkit::WebPluginInfo* plugin_info,
552 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08553 bool found = false;
554 Send(new ViewHostMsg_GetPluginInfo(
555 routing_id_, url, page_url, mime_type, &found, plugin_info,
556 actual_mime_type));
557 return found;
558}
559
[email protected]310ebd6302011-10-10 19:06:28560bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27561 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27562 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41563 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26564
[email protected]676126f72011-01-15 00:03:51565 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
566 RenderViewObserver* observer;
567 while ((observer = it.GetNext()) != NULL)
568 if (observer->OnMessageReceived(message))
569 return true;
[email protected]b2abac72009-02-26 12:39:28570
[email protected]a95986a82010-12-24 06:19:28571 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40572 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28573 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29574 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
575 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56576 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29577 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
578 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
579 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
580 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27581#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35582 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27583#endif
initial.commit09911bf2008-07-26 23:55:29584 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15585 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29586 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
587 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
588 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08589 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29590 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15591 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29592 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49593 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
594 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17595 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17596 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:54597 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
598 OnSetZoomLevelForLoadingURL)
[email protected]8a5e0ca2011-08-25 06:30:47599 IPC_MESSAGE_HANDLER(ViewMsg_ExitFullscreen, OnExitFullscreen)
initial.commit09911bf2008-07-26 23:55:29600 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18601 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
602 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29603 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48604 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29605 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55606 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
607 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
608 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
609 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
610 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
611 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
612 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45613 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40614 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29615 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19616 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
617 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29618 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
619 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
620 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51621 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
622 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29623 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04624 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15625 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29626 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
627 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08628 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
629 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00630 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16631 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14632 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25633 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
634 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10635 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
636 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51637 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56638 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34639 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14640#if defined(OS_MACOSX)
641 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13642 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13643 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
644 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14645#endif
[email protected]446705872009-09-10 07:22:48646 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33647 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33648 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
649 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24650 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42651 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
652 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19653 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
654 OnGetAllSavableResourceLinksForCurrentPage)
655 IPC_MESSAGE_HANDLER(
656 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
657 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08658#if defined(OS_MACOSX)
659 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
660#endif
[email protected]521b2482011-01-15 00:10:10661 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51662 // TODO(viettrungluu): Move to a separate message filter.
663#if defined(ENABLE_FLAPPER_HACKS)
664 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
665#endif
[email protected]54ca3ca892011-06-07 21:14:54666#if defined(OS_MACOSX)
667 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
668#endif
[email protected]9e1ad4b2011-08-14 16:49:19669 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
670 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18671 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]67bfb83f2011-09-22 03:36:37672 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
673 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
[email protected]7f3c7af2011-10-20 22:52:51674 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19675
initial.commit09911bf2008-07-26 23:55:29676 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28677 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29678 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40679
680 if (!msg_is_ok) {
681 // The message had a handler, but its deserialization failed.
682 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28683 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40684 }
685
[email protected]a95986a82010-12-24 06:19:28686 return handled;
initial.commit09911bf2008-07-26 23:55:29687}
688
[email protected]310ebd6302011-10-10 19:06:28689void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
initial.commit09911bf2008-07-26 23:55:29690 if (!webview())
691 return;
692
[email protected]440a0e52011-09-13 17:38:58693 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
694
[email protected]d466b8a2011-07-15 21:48:03695 bool is_reload =
696 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
697 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
698
699 // If this is a stale back/forward (due to a recent navigation the browser
700 // didn't know about), ignore it.
701 if (IsBackForwardToStaleEntry(params, is_reload))
702 return;
703
[email protected]992db4c2011-05-12 15:37:15704 // Swap this renderer back in if necessary.
705 if (is_swapped_out_)
706 SetSwappedOut(false);
707
[email protected]3cc72b12010-03-18 23:03:00708 history_list_offset_ = params.current_history_list_offset;
709 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03710 if (history_list_length_ >= 0)
711 history_page_ids_.resize(history_list_length_, -1);
712 if (params.pending_history_list_offset >= 0 &&
713 params.pending_history_list_offset < history_list_length_)
714 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00715
[email protected]38b592902011-04-16 02:08:42716 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29717
[email protected]26aa0482009-09-30 16:55:27718 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45719 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29720 // We cannot reload if we do not have any history state. This happens, for
721 // example, when recovering from a crash. Our workaround here is a bit of
722 // a hack since it means that reload after a crashed tab does not cause an
723 // end-to-end cache validation.
724 is_reload = false;
725 }
726
[email protected]77f17a82009-05-21 04:42:54727 // A navigation resulting from loading a javascript URL should not be treated
728 // as a browser initiated event. Instead, we want it to look as if the page
729 // initiated any load resulting from JS execution.
730 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30731 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00732 params.page_id,
733 params.pending_history_list_offset,
734 params.transition,
735 params.request_time);
[email protected]2c5569662011-03-22 20:45:02736 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30737 // We're doing a load of a page that was restored from the last session.
738 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
739 // which can result in stale data for pages that are set to expire. We
740 // explicitly override that by setting the policy here so that as
741 // necessary we load from the network.
742 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
743 }
744 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54745 }
initial.commit09911bf2008-07-26 23:55:29746
[email protected]a7ccc4d2010-01-27 08:14:48747 NavigationState* navigation_state = pending_navigation_state_.get();
748
[email protected]48a5c772011-04-18 23:50:50749 if (navigation_state) {
750 // New loads need to reset the error page fetcher. Otherwise if there is an
751 // outstanding error page fetcher it may complete and clobber the current
752 // page load.
753 navigation_state->set_alt_error_page_fetcher(NULL);
754 }
755
[email protected]04d3c6e2009-05-22 17:00:13756 // If we are reloading, then WebKit will use the history state of the current
757 // page, so we should just ignore any given history state. Otherwise, if we
758 // have history state, then we need to navigate to it, which corresponds to a
759 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55760 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48761 if (navigation_state)
762 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29763 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02764 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29765 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55766 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13767 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58768 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48769 if (navigation_state)
770 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45771 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17772 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13773 } else {
774 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28775 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29776
[email protected]e6f546c32009-07-01 17:12:55777 // A session history navigation should have been accompanied by state.
778 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13779
[email protected]dd7daa82009-08-10 05:46:45780 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55781 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13782
[email protected]726985e22009-06-18 21:09:28783 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17784 if (!WebSecurityPolicy::shouldHideReferrer(
785 params.url,
786 WebString::fromUTF8(params.referrer.spec()))) {
787 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
788 WebString::fromUTF8(params.referrer.spec()));
789 }
[email protected]726985e22009-06-18 21:09:28790 }
[email protected]04d3c6e2009-05-22 17:00:13791
[email protected]52c68652010-12-07 17:47:04792 if (!params.extra_headers.empty()) {
793 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
794 params.extra_headers.end(), "\n");
795 i.GetNext(); ) {
796 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
797 WebString::fromUTF8(i.values()));
798 }
799 }
800
[email protected]16e923d2011-04-30 00:41:44801 if (navigation_state)
802 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45803 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50804 }
805
[email protected]77f17a82009-05-21 04:42:54806 // In case LoadRequest failed before DidCreateDataSource was called.
807 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29808}
809
[email protected]310ebd6302011-10-10 19:06:28810bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03811 const ViewMsg_Navigate_Params& params,
812 bool is_reload) {
813 // Make sure this isn't a back/forward to an entry we have already cropped
814 // or replaced from our history, before the browser knew about it. If so,
815 // a new navigation has committed in the mean time, and we can ignore this.
816 bool is_back_forward = !is_reload && !params.state.empty();
817
818 // Note: if the history_list_length_ is 0 for a back/forward, we must be
819 // restoring from a previous session. We'll update our state in OnNavigate.
820 if (!is_back_forward || history_list_length_ <= 0)
821 return false;
822
823 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
824
825 // Check for whether the forward history has been cropped due to a recent
826 // navigation the browser didn't know about.
827 if (params.pending_history_list_offset >= history_list_length_)
828 return true;
829
830 // Check for whether this entry has been replaced with a new one.
831 int expected_page_id =
832 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44833 if (expected_page_id > 0 && params.page_id != expected_page_id) {
834 if (params.page_id < expected_page_id)
835 return true;
836
837 // Otherwise we've removed an earlier entry and should have shifted all
838 // entries left. For now, it's ok to lazily update the list.
839 // TODO(creis): Notify all live renderers when we remove entries from
840 // the front of the list, so that we don't hit this case.
841 history_page_ids_[params.pending_history_list_offset] = params.page_id;
842 }
[email protected]d466b8a2011-07-15 21:48:03843
844 return false;
845}
846
initial.commit09911bf2008-07-26 23:55:29847// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28848void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44849 if (webview()) {
850 WebFrame* main_frame = webview()->mainFrame();
851 // Stop the alt error page fetcher. If we let it continue it may complete
852 // and cause RenderViewHostManager to swap to this RenderView, even though
853 // it may no longer be active.
854 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
855 StopAltErrorPageFetcher(main_frame->dataSource());
856 main_frame->stopLoading();
857 }
initial.commit09911bf2008-07-26 23:55:29858}
859
[email protected]ecbf10d2010-02-18 13:03:29860// Reload current focused frame.
861// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28862void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29863 if (webview() && webview()->focusedFrame()) {
864 // We always obey the cache (ignore_cache=false) here.
865 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
866 // a cache-ignoring reload of the frame.
867 webview()->focusedFrame()->reload(false);
868 }
[email protected]1dda4022010-01-28 18:24:56869}
870
[email protected]310ebd6302011-10-10 19:06:28871void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27872 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29873}
874
[email protected]310ebd6302011-10-10 19:06:28875void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:25876 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27877 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25878 return;
879
[email protected]26aa0482009-09-30 16:55:27880 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45881 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25882}
883
[email protected]310ebd6302011-10-10 19:06:28884void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:29885 // Check if there is a targeturl waiting to be sent.
886 if (target_url_status_ == TARGET_PENDING) {
887 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
888 pending_target_url_));
889 }
890
891 target_url_status_ = TARGET_NONE;
892}
893
[email protected]310ebd6302011-10-10 19:06:28894void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:29895 if (!webview())
896 return;
897
[email protected]26aa0482009-09-30 16:55:27898 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29899}
900
[email protected]310ebd6302011-10-10 19:06:28901void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:29902 if (!webview())
903 return;
904
[email protected]26aa0482009-09-30 16:55:27905 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29906}
907
[email protected]310ebd6302011-10-10 19:06:28908void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:29909 if (!webview())
910 return;
911
[email protected]26aa0482009-09-30 16:55:27912 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29913}
914
[email protected]310ebd6302011-10-10 19:06:28915void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:29916 if (!webview())
917 return;
918
[email protected]f6b1856b2011-06-29 22:02:53919 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
920 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29921}
922
[email protected]c0cc3092009-09-12 08:27:27923#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:28924void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:35925 if (!webview())
926 return;
927
928 // Since the find pasteboard supports only plain text, this can be simpler
929 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27930 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35931 if (frame->hasSelection()) {
932 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:27933 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:17934 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35935 }
[email protected]a954bf72009-09-12 07:30:35936}
[email protected]c0cc3092009-09-12 08:27:27937#endif
[email protected]a954bf72009-09-12 07:30:35938
[email protected]310ebd6302011-10-10 19:06:28939void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:29940 if (!webview())
941 return;
942
[email protected]26aa0482009-09-30 16:55:27943 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29944}
945
[email protected]44bf7002011-10-16 02:46:15946void RenderViewImpl::OnPasteAndMatchStyle() {
947 if (!webview())
948 return;
949
950 webview()->focusedFrame()->executeCommand(
951 WebString::fromUTF8("PasteAndMatchStyle"));
952}
953
[email protected]310ebd6302011-10-10 19:06:28954void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29955 if (!webview())
956 return;
957
[email protected]1ff7a032010-02-03 02:46:03958 WebFrame* frame = webview()->focusedFrame();
959 if (!frame->hasSelection())
960 frame->selectWordAroundCaret();
961 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29962}
963
[email protected]310ebd6302011-10-10 19:06:28964void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:29965 if (!webview())
966 return;
967
[email protected]26aa0482009-09-30 16:55:27968 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29969}
970
[email protected]310ebd6302011-10-10 19:06:28971void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:29972 if (!webview())
973 return;
974
[email protected]26aa0482009-09-30 16:55:27975 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22976 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29977}
978
[email protected]310ebd6302011-10-10 19:06:28979void RenderViewImpl::OnSelectRange(const gfx::Point& start,
980 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:08981 if (!webview())
982 return;
983
984 handling_select_range_ = true;
985 webview()->focusedFrame()->selectRange(start, end);
986 handling_select_range_ = false;
987}
988
[email protected]310ebd6302011-10-10 19:06:28989void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
990 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:19991 DCHECK(history_length >= 0);
992 DCHECK(history_list_offset_ == history_list_length_ - 1);
993 DCHECK(minimum_page_id >= -1);
994
995 // Generate the new list.
996 std::vector<int32> new_history_page_ids(history_length, -1);
997 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
998 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
999 continue;
1000 new_history_page_ids.push_back(history_page_ids_[i]);
1001 }
1002 new_history_page_ids.swap(history_page_ids_);
1003
1004 // Update indexes.
1005 history_list_length_ = history_page_ids_.size();
1006 history_list_offset_ = history_list_length_ - 1;
1007}
1008
1009
[email protected]310ebd6302011-10-10 19:06:281010void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:291011 if (!webview())
1012 return;
[email protected]26aa0482009-09-30 16:55:271013 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291014}
1015
[email protected]54ca3ca892011-06-07 21:14:541016#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281017void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331018 if (!webview())
1019 return;
1020 if (in_live_resize)
1021 webview()->willStartLiveResize();
1022 else
1023 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541024}
1025#endif
1026
[email protected]310ebd6302011-10-10 19:06:281027void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1028 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091029 WebKit::WebNode node = GetFocusedNode();
1030 if (!node.isNull()) {
1031 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191032 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511033 }
1034}
1035
initial.commit09911bf2008-07-26 23:55:291036///////////////////////////////////////////////////////////////////////////////
1037
1038// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281039void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451040 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291041 DCHECK(ds);
1042
[email protected]726985e22009-06-18 21:09:281043 const WebURLRequest& request = ds->request();
1044 const WebURLRequest& original_request = ds->originalRequest();
1045 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291046
[email protected]daa8c58e2009-06-15 17:21:101047 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1048 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291049
1050 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281051 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291052 params.is_post = false;
1053 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071054 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191055 params.socket_address.set_host(response.remoteIPAddress().utf8());
1056 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031057 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091058 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551059 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291060 // SSL state specified in the request takes precedence over the one in the
1061 // response.
1062 // So far this is only intended for error pages that are not expected to be
1063 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281064 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551065 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291066 } else {
[email protected]726985e22009-06-18 21:09:281067 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291068 }
1069
1070 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281071 if (ds->hasUnreachableURL()) {
1072 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291073 } else {
[email protected]726985e22009-06-18 21:09:281074 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291075 }
1076
[email protected]726985e22009-06-18 21:09:281077 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241078 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041079 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291080
[email protected]ce0e250d2009-10-23 21:00:351081 params.searchable_form_url = navigation_state->searchable_form_url();
1082 params.searchable_form_encoding =
1083 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291084
1085 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101086 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291087 if (password_form_data)
1088 params.password_form = *password_form_data;
1089
1090 params.gesture = navigation_gesture_;
1091 navigation_gesture_ = NavigationGestureUnknown;
1092
[email protected]0f38dc4552011-02-25 11:24:001093 // Make navigation state a part of the FrameNavigate message so that commited
1094 // entry had it at all times.
1095 const WebHistoryItem& item = frame->currentHistoryItem();
1096 if (!item.isNull()) {
1097 params.content_state = webkit_glue::HistoryItemToString(item);
1098 } else {
1099 params.content_state =
1100 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1101 }
1102
[email protected]dd7daa82009-08-10 05:46:451103 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291104 // Top-level navigation.
1105
[email protected]b75b8292010-10-01 07:28:251106 // Set zoom level, but don't do it for full-page plugin since they don't use
1107 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011108 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541109 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251110 if (webview()->mainFrame()->document().isPluginDocument()) {
1111 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251112 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251113 } else {
1114 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251115 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251116 }
1117
[email protected]f85f0702010-01-30 09:31:011118 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511119 // This zoom level was merely recorded transiently for this load. We can
1120 // erase it now. If at some point we reload this page, the browser will
1121 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011122 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511123 }
1124
[email protected]b75b8292010-10-01 07:28:251125 // Reset the zoom limits in case a plugin had changed them previously. This
1126 // will also call us back which will cause us to send a message to
1127 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251128 webview()->zoomLimitsChanged(
1129 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1130 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251131
initial.commit09911bf2008-07-26 23:55:291132 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551133 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291134
[email protected]daa8c58e2009-06-15 17:21:101135 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581136 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291137 // If the main frame does a load, it should not be reported as a subframe
1138 // navigation. This can occur in the following case:
1139 // 1. You're on a site with frames.
1140 // 2. You do a subframe navigation. This is stored with transition type
1141 // MANUAL_SUBFRAME.
1142 // 3. You navigate to some non-frame site, say, google.com.
1143 // 4. You navigate back to the page from step 2. Since it was initially
1144 // MANUAL_SUBFRAME, it will be that same transition type here.
1145 // We don't want that, because any navigation that changes the toplevel
1146 // frame should be tracked as a toplevel navigation (this allows us to
1147 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581148 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291149 }
1150
initial.commit09911bf2008-07-26 23:55:291151 // If we have a valid consumed client redirect source,
1152 // the page contained a client redirect (meta refresh, document.loc...),
1153 // so we set the referrer and transition to match.
1154 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041155 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291156 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581157 params.transition = static_cast<content::PageTransition>(
1158 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291159 } else {
1160 // Bug 654101: the referrer will be empty on https->http transitions. It
1161 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281162 params.referrer = GURL(
1163 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291164 }
1165
[email protected]726985e22009-06-18 21:09:281166 string16 method = request.httpMethod();
1167 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291168 params.is_post = true;
1169
[email protected]c2a797d2009-09-21 16:46:321170 // Save some histogram data so we can compute the average memory used per
1171 // page load of the glyphs.
1172 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1173 webkit_glue::GetGlyphPageCount());
1174
[email protected]15cf526b2010-02-12 06:33:491175 // This message needs to be sent before any of allowScripts(),
1176 // allowImages(), allowPlugins() is called for the new page, so that when
1177 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1178 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291179 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1180 } else {
1181 // Subframe navigation: the type depends on whether this navigation
1182 // generated a new session history entry. When they do generate a session
1183 // history entry, it means the user initiated the navigation and we should
1184 // mark it as such. This test checks if this is the first time UpdateURL
1185 // has been called since WillNavigateToURL was called to initiate the load.
1186 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581187 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291188 else
[email protected]2905f742011-10-13 03:51:581189 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291190
initial.commit09911bf2008-07-26 23:55:291191 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1192 }
1193
1194 last_page_id_sent_to_browser_ =
1195 std::max(last_page_id_sent_to_browser_, page_id_);
1196
1197 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101198 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581199 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291200}
1201
1202// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281203void RenderViewImpl::UpdateTitle(WebFrame* frame,
1204 const string16& title,
1205 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461206 // Ignore all but top level navigations.
1207 if (frame->parent())
1208 return;
1209
1210 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1211 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1212 title_direction));
initial.commit09911bf2008-07-26 23:55:291213}
1214
[email protected]310ebd6302011-10-10 19:06:281215void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1216 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291217 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271218 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291219 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301220 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291221 last_encoding_name_ = encoding_name;
1222
[email protected]e38f40152008-09-12 23:08:301223 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291224 }
1225}
1226
[email protected]e15f680732010-11-23 22:30:201227// Sends the last committed session history state to the browser so it will be
1228// saved before we navigate to a new page. This must be called *before* the
1229// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281230void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291231 // If we have a valid page ID at this point, then it corresponds to the page
1232 // we are navigating away from. Otherwise, this is the first navigation, so
1233 // there is no past session history to record.
1234 if (page_id_ == -1)
1235 return;
1236
[email protected]ca948a22009-06-25 19:36:171237 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271238 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171239 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291240 return;
[email protected]ca948a22009-06-25 19:36:171241
1242 Send(new ViewHostMsg_UpdateState(
1243 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291244}
1245
[email protected]310ebd6302011-10-10 19:06:281246void RenderViewImpl::OpenURL(WebFrame* frame,
1247 const GURL& url,
1248 const GURL& referrer,
1249 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171250 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581251 routing_id_,
1252 url,
1253 referrer,
1254 NavigationPolicyToDisposition(policy),
1255 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171256}
1257
[email protected]79dbc662009-09-04 05:42:511258// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291259
[email protected]310ebd6302011-10-10 19:06:281260void RenderViewImpl::LoadNavigationErrorPage(
1261 WebFrame* frame,
1262 const WebURLRequest& failed_request,
1263 const WebURLError& error,
1264 const std::string& html,
1265 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581266 std::string alt_html;
1267 const std::string* error_html;
1268
1269 if (!html.empty()) {
1270 error_html = &html;
1271 } else {
1272 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1273 failed_request, error, &alt_html, NULL);
1274 error_html = &alt_html;
1275 }
1276
1277 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361278 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251279 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551280 replace);
initial.commit09911bf2008-07-26 23:55:291281}
1282
[email protected]310ebd6302011-10-10 19:06:281283bool RenderViewImpl::RunJavaScriptMessage(int type,
1284 const string16& message,
1285 const string16& default_value,
1286 const GURL& frame_url,
1287 string16* result) {
initial.commit09911bf2008-07-26 23:55:291288 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411289 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291290 if (!result)
1291 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291292
[email protected]12636df2009-09-28 22:32:211293 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1294 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291295 return success;
1296}
1297
[email protected]310ebd6302011-10-10 19:06:281298bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571299 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1300 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1301 // it is particularly important that we do not call willEnterModalLoop as
1302 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441303 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1304 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571305
1306 message->EnableMessagePumping(); // Runs a nested message loop.
1307 return Send(message);
1308}
1309
[email protected]48c9cf2d2009-09-16 16:47:521310// WebKit::WebViewClient ------------------------------------------------------
1311
[email protected]310ebd6302011-10-10 19:06:281312WebView* RenderViewImpl::createView(
[email protected]844acf372011-01-14 10:49:271313 WebFrame* creator,
1314 const WebURLRequest& request,
1315 const WebWindowFeatures& features,
1316 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521317 // Check to make sure we aren't overloading on popups.
1318 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1319 return NULL;
1320
[email protected]8ab04652010-06-12 02:47:261321 ViewHostMsg_CreateWindow_Params params;
1322 params.opener_id = routing_id_;
1323 params.user_gesture = creator->isProcessingUserGesture();
1324 params.window_container_type = WindowFeaturesToContainerType(features);
1325 params.session_storage_namespace_id = session_storage_namespace_id_;
1326 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111327 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411328 params.opener_url = creator->document().url();
1329 params.opener_security_origin =
1330 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111331 if (!request.isNull())
1332 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261333
[email protected]48c9cf2d2009-09-16 16:47:521334 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341335 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261336 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521337
[email protected]380244092011-10-07 17:26:271338 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261339 new ViewHostMsg_CreateWindow(params,
1340 &routing_id,
1341 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211342 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521343 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521344
[email protected]310ebd6302011-10-10 19:06:281345 RenderViewImpl* view = RenderViewImpl::Create(
1346 0,
1347 routing_id_,
1348 renderer_preferences_,
1349 webkit_preferences_,
1350 shared_popup_counter_,
1351 routing_id,
1352 cloned_session_storage_namespace_id,
1353 frame_name);
[email protected]8ab04652010-06-12 02:47:261354 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521355
[email protected]007a848b2009-10-26 15:55:461356 // Record whether the creator frame is trying to suppress the opener field.
1357 view->opener_suppressed_ = opener_suppressed;
1358
[email protected]48c9cf2d2009-09-16 16:47:521359 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411360 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521361 if (!creator_url.is_valid() || !creator_url.IsStandard())
1362 creator_url = GURL();
1363 view->creator_url_ = creator_url;
1364
1365 // Copy over the alternate error page URL so we can have alt error pages in
1366 // the new render view (we don't need the browser to send the URL back down).
1367 view->alternate_error_page_url_ = alternate_error_page_url_;
1368
1369 return view->webview();
1370}
1371
[email protected]310ebd6302011-10-10 19:06:281372WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]380244092011-10-07 17:26:271373 RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521374 return widget->webwidget();
1375}
1376
[email protected]310ebd6302011-10-10 19:06:281377WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441378 // TODO(jcivelli): Remove this deprecated method when its been removed from
1379 // the WebViewClient interface. It's been replaced by
1380 // createExternalPopupMenu.
1381 NOTREACHED();
1382 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521383}
1384
[email protected]310ebd6302011-10-10 19:06:281385WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081386 const WebPopupMenuInfo& popup_menu_info,
1387 WebExternalPopupMenuClient* popup_menu_client) {
1388 DCHECK(!external_popup_menu_.get());
1389 external_popup_menu_.reset(
1390 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1391 return external_popup_menu_.get();
1392}
1393
[email protected]310ebd6302011-10-10 19:06:281394RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521395 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531396 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421397 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411398 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531399 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271400 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391401 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561402 return widget;
[email protected]79c7bed2010-09-14 22:28:391403}
1404
[email protected]310ebd6302011-10-10 19:06:281405WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1406 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341407 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391408 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291409 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1410 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1411 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341412}
1413
[email protected]310ebd6302011-10-10 19:06:281414void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521415 const WebConsoleMessage& message, const WebString& source_name,
1416 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081417 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511418 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081419 case WebConsoleMessage::LevelTip:
1420 log_severity = logging::LOG_VERBOSE;
1421 break;
1422 case WebConsoleMessage::LevelLog:
1423 log_severity = logging::LOG_INFO;
1424 break;
1425 case WebConsoleMessage::LevelWarning:
1426 log_severity = logging::LOG_WARNING;
1427 break;
1428 case WebConsoleMessage::LevelError:
1429 log_severity = logging::LOG_ERROR;
1430 break;
1431 default:
1432 NOTREACHED();
1433 }
1434
[email protected]48c9cf2d2009-09-16 16:47:521435 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081436 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311437 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521438 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311439 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521440}
1441
[email protected]310ebd6302011-10-10 19:06:281442void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421443 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521444}
1445
[email protected]310ebd6302011-10-10 19:06:281446WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511447 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021448}
1449
[email protected]310ebd6302011-10-10 19:06:281450bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121451 const WebString& path,
1452 WebFileChooserCompletion* chooser_completion) {
1453 int id = enumeration_completion_id_++;
1454 enumeration_completions_[id] = chooser_completion;
1455 return Send(new ViewHostMsg_EnumerateDirectory(
1456 routing_id_,
1457 id,
1458 webkit_glue::WebStringToFilePath(path)));
1459}
1460
[email protected]310ebd6302011-10-10 19:06:281461void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521462 if (is_loading_) {
1463 DLOG(WARNING) << "didStartLoading called while loading";
1464 return;
1465 }
1466
1467 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521468
1469 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311470
1471 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521472}
1473
[email protected]310ebd6302011-10-10 19:06:281474void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521475 if (!is_loading_) {
1476 DLOG(WARNING) << "DidStopLoading called while not loading";
1477 return;
1478 }
1479
1480 is_loading_ = false;
1481
1482 // NOTE: For now we're doing the safest thing, and sending out notification
1483 // when done loading. This currently isn't an issue as the favicon is only
1484 // displayed when done loading. Ideally we would send notification when
1485 // finished parsing the head, but webkit doesn't support that yet.
1486 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521487 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1488
[email protected]90109412010-12-15 17:14:241489 if (load_progress_tracker_ != NULL)
1490 load_progress_tracker_->DidStopLoading();
1491
[email protected]93b9d692011-04-13 00:44:311492 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521493}
1494
[email protected]310ebd6302011-10-10 19:06:281495void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1496 double load_progress) {
[email protected]90109412010-12-15 17:14:241497 if (load_progress_tracker_ != NULL)
1498 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1499}
1500
[email protected]310ebd6302011-10-10 19:06:281501bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061502#if defined(OS_MACOSX)
1503 return true;
1504#else
1505 return false;
1506#endif
1507}
1508
[email protected]310ebd6302011-10-10 19:06:281509bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031510#if defined(OS_WIN)
1511 return true;
1512#else
1513 return false;
1514#endif
1515}
1516
[email protected]310ebd6302011-10-10 19:06:281517void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]e99ef6f2011-10-16 01:13:001518 // TODO(penghuang): Enable this on Window to support IME reconversion.
1519 // http://crbug.com/100220
[email protected]0ff0ff32010-12-21 19:34:421520#if defined(OS_POSIX)
[email protected]4fb60142011-08-09 02:22:081521 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031522 return;
[email protected]4fb60142011-08-09 02:22:081523 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011524
[email protected]b781ff282011-08-20 06:19:361525 SyncSelectionIfRequired();
[email protected]0ff0ff32010-12-21 19:34:421526#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031527}
1528
[email protected]310ebd6302011-10-10 19:06:281529void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121530 const std::string& name = UTF16ToUTF8(command_name);
1531 if (StartsWithASCII(name, "Move", true) ||
1532 StartsWithASCII(name, "Insert", true) ||
1533 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031534 return;
[email protected]f1a29a02011-10-06 23:08:441535 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031536}
1537
[email protected]310ebd6302011-10-10 19:06:281538bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101539 if (edit_commands_.empty())
1540 return false;
1541
[email protected]26aa0482009-09-30 16:55:271542 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101543 if (!frame)
1544 return false;
1545
1546 EditCommands::iterator it = edit_commands_.begin();
1547 EditCommands::iterator end = edit_commands_.end();
1548
[email protected]507b33ea2009-09-29 03:56:511549 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101550 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331551 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1552 // key (but it's the exception). Once one edit command is not executed, it
1553 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101554 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1555 WebString::fromUTF8(it->value)))
1556 break;
[email protected]507b33ea2009-09-29 03:56:511557 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101558 }
1559
[email protected]507b33ea2009-09-29 03:56:511560 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101561}
1562
[email protected]310ebd6302011-10-10 19:06:281563bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351564 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471565 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351566 // Do not open the file dialog in a hidden RenderView.
1567 if (is_hidden())
1568 return false;
[email protected]cdaf8d02010-03-30 19:52:471569 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261570 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361571 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261572 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361573 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501574 else if (params.saveAs)
1575 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Save;
[email protected]b5977a0c2010-08-24 19:46:261576 else
[email protected]0aed2f52011-03-23 18:06:361577 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471578 ipc_params.title = params.title;
1579 ipc_params.default_file_name =
1580 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591581 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471582
1583 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461584}
1585
[email protected]310ebd6302011-10-10 19:06:281586void RenderViewImpl::runModalAlertDialog(
[email protected]48c9cf2d2009-09-16 16:47:521587 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061588 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]4f5ce842011-05-27 19:34:411589 message,
1590 string16(),
[email protected]b6cb3a842011-06-24 18:28:411591 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521592 NULL);
1593}
1594
[email protected]310ebd6302011-10-10 19:06:281595bool RenderViewImpl::runModalConfirmDialog(
[email protected]48c9cf2d2009-09-16 16:47:521596 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061597 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]4f5ce842011-05-27 19:34:411598 message,
1599 string16(),
[email protected]b6cb3a842011-06-24 18:28:411600 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521601 NULL);
1602}
1603
[email protected]310ebd6302011-10-10 19:06:281604bool RenderViewImpl::runModalPromptDialog(
[email protected]48c9cf2d2009-09-16 16:47:521605 WebFrame* frame, const WebString& message, const WebString& default_value,
1606 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411607 string16 result;
[email protected]9dd7e3d72011-01-20 18:27:061608 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]4f5ce842011-05-27 19:34:411609 message,
1610 default_value,
[email protected]b6cb3a842011-06-24 18:28:411611 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521612 &result);
1613 if (ok)
[email protected]4f5ce842011-05-27 19:34:411614 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521615 return ok;
1616}
1617
[email protected]310ebd6302011-10-10 19:06:281618bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521619 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151620 // If we are swapping out, we have already run the beforeunload handler.
1621 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1622 // at all, to avoid running it twice.
1623 if (is_swapped_out_)
1624 return true;
1625
[email protected]48c9cf2d2009-09-16 16:47:521626 bool success = false;
1627 // This is an ignored return value, but is included so we can accept the same
1628 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411629 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211630 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411631 routing_id_, frame->document().url(), message,
1632 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521633 return success;
1634}
1635
[email protected]310ebd6302011-10-10 19:06:281636void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441637 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291638 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371639
1640 // frame is NULL if invoked by BlockedPlugin.
1641 if (frame)
1642 params.frame_id = frame->identifier();
1643
[email protected]db803aae2011-03-05 02:00:421644 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271645 // it. We replace it with an empty GURL so the appropriate items are disabled
1646 // in the context menu.
1647 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1648 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421649 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271650 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101651 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291652 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441653}
1654
[email protected]310ebd6302011-10-10 19:06:281655bool RenderViewImpl::supportsFullscreen() {
[email protected]52f139e2c2010-06-11 16:56:091656 return CommandLine::ForCurrentProcess()->HasSwitch(
1657 switches::kEnableVideoFullscreen);
1658}
1659
[email protected]310ebd6302011-10-10 19:06:281660void RenderViewImpl::enterFullscreenForNode(const WebKit::WebNode& node) {
[email protected]52f139e2c2010-06-11 16:56:091661 NOTIMPLEMENTED();
1662}
1663
[email protected]310ebd6302011-10-10 19:06:281664void RenderViewImpl::exitFullscreenForNode(const WebKit::WebNode& node) {
[email protected]52f139e2c2010-06-11 16:56:091665 NOTIMPLEMENTED();
1666}
1667
[email protected]310ebd6302011-10-10 19:06:281668void RenderViewImpl::enterFullscreen() {
[email protected]8a5e0ca2011-08-25 06:30:471669 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1670}
1671
[email protected]310ebd6302011-10-10 19:06:281672void RenderViewImpl::exitFullscreen() {
[email protected]8a5e0ca2011-08-25 06:30:471673 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1674}
1675
[email protected]310ebd6302011-10-10 19:06:281676void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521677}
1678
[email protected]310ebd6302011-10-10 19:06:281679void RenderViewImpl::UpdateTargetURL(const GURL& url,
1680 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581681 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521682 if (latest_url == target_url_)
1683 return;
[email protected]163f8242009-10-30 20:19:551684
[email protected]48c9cf2d2009-09-16 16:47:521685 // Tell the browser to display a destination link.
1686 if (target_url_status_ == TARGET_INFLIGHT ||
1687 target_url_status_ == TARGET_PENDING) {
1688 // If we have a request in-flight, save the URL to be sent when we
1689 // receive an ACK to the in-flight request. We can happily overwrite
1690 // any existing pending sends.
1691 pending_target_url_ = latest_url;
1692 target_url_status_ = TARGET_PENDING;
1693 } else {
1694 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1695 target_url_ = latest_url;
1696 target_url_status_ = TARGET_INFLIGHT;
1697 }
1698}
1699
[email protected]310ebd6302011-10-10 19:06:281700void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311701 int delay;
1702 if (send_content_state_immediately_)
1703 delay = 0;
1704 else if (is_hidden())
1705 delay = kDelaySecondsForContentStateSyncHidden;
1706 else
1707 delay = kDelaySecondsForContentStateSync;
1708
1709 if (nav_state_sync_timer_.IsRunning()) {
1710 // The timer is already running. If the delay of the timer maches the amount
1711 // we want to delay by, then return. Otherwise stop the timer so that it
1712 // gets started with the right delay.
1713 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1714 return;
1715 nav_state_sync_timer_.Stop();
1716 }
1717
[email protected]d323a172011-09-02 18:23:021718 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281719 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311720}
1721
[email protected]310ebd6302011-10-10 19:06:281722void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551723 mouse_over_url_ = GURL(url);
1724 UpdateTargetURL(mouse_over_url_, focus_url_);
1725}
1726
[email protected]310ebd6302011-10-10 19:06:281727void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551728 focus_url_ = GURL(url);
1729 UpdateTargetURL(focus_url_, mouse_over_url_);
1730}
1731
[email protected]310ebd6302011-10-10 19:06:281732void RenderViewImpl::startDragging(const WebDragData& data,
1733 WebDragOperationsMask mask,
1734 const WebImage& image,
1735 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411736#if WEBKIT_USING_SKIA
1737 SkBitmap bitmap(image.getSkBitmap());
1738#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331739 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411740#endif
1741
[email protected]59f4f2fa2011-03-23 01:00:551742 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521743 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411744 mask,
1745 bitmap,
1746 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521747}
1748
[email protected]310ebd6302011-10-10 19:06:281749bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451750 return renderer_preferences_.can_accept_load_drops;
1751}
1752
[email protected]310ebd6302011-10-10 19:06:281753void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521754 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1755}
1756
[email protected]310ebd6302011-10-10 19:06:281757void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521758 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1759}
1760
[email protected]310ebd6302011-10-10 19:06:281761void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511762 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071763
[email protected]38b592902011-04-16 02:08:421764 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491765}
1766
[email protected]310ebd6302011-10-10 19:06:281767void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521768 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1769}
1770
[email protected]310ebd6302011-10-10 19:06:281771int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001772 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521773}
1774
[email protected]310ebd6302011-10-10 19:06:281775int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001776 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521777}
1778
[email protected]310ebd6302011-10-10 19:06:281779void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321780 const WebAccessibilityObject& obj,
1781 WebAccessibilityNotification notification) {
1782 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1783}
1784
[email protected]310ebd6302011-10-10 19:06:281785void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141786 const WebString& value) {
1787 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1788 key.utf8(),
1789 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261790}
1791
[email protected]79dbc662009-09-04 05:42:511792// WebKit::WebWidgetClient ----------------------------------------------------
1793
[email protected]310ebd6302011-10-10 19:06:281794void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121795 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1796 // we won't have to test for user gesture anymore and we can
1797 // move that code back to render_widget.cc
1798 if (webview() && webview()->mainFrame() &&
1799 webview()->mainFrame()->isProcessingUserGesture()) {
1800 Send(new ViewHostMsg_Focus(routing_id_));
1801 }
1802}
1803
[email protected]310ebd6302011-10-10 19:06:281804void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121805 // TODO(jcivelli): see TODO above in didFocus().
1806 if (webview() && webview()->mainFrame() &&
1807 webview()->mainFrame()->isProcessingUserGesture()) {
1808 Send(new ViewHostMsg_Blur(routing_id_));
1809 }
1810}
1811
initial.commit09911bf2008-07-26 23:55:291812// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281813// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291814// point to dispatch the ShowView message.
1815//
1816// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281817// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291818//
[email protected]310ebd6302011-10-10 19:06:281819void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291820 DCHECK(!did_show_) << "received extraneous Show call";
1821 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1822
1823 if (did_show_)
1824 return;
1825 did_show_ = true;
1826
[email protected]6779aa12011-03-29 17:32:241827 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041828 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041829
[email protected]28295ec2009-10-16 05:34:331830 // Force new windows to a popup if they were not opened with a user gesture.
1831 if (!opened_by_user_gesture_) {
1832 // We exempt background tabs for compat with older versions of Chrome.
1833 // TODO(darin): This seems bogus. These should have a user gesture, so
1834 // we probably don't need this check.
1835 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1836 policy = WebKit::WebNavigationPolicyNewPopup;
1837 }
1838
initial.commit09911bf2008-07-26 23:55:291839 // NOTE: initial_pos_ may still have its default values at this point, but
1840 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1841 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281842 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1843 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291844 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241845 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291846}
1847
[email protected]310ebd6302011-10-10 19:06:281848void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:291849 DCHECK(did_show_) << "should already have shown the view";
1850
[email protected]c1f50aa2010-02-18 03:46:571851 // We must keep WebKit's shared timer running in this case in order to allow
1852 // showModalDialog to function properly.
1853 //
1854 // TODO(darin): WebKit should really be smarter about suppressing events and
1855 // timers so that we do not need to manage the shared timer in such a heavy
1856 // handed manner.
1857 //
[email protected]f1a29a02011-10-06 23:08:441858 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1859 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:571860
[email protected]12636df2009-09-28 22:32:211861 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291862}
1863
[email protected]3d9689372009-09-10 04:29:171864// WebKit::WebFrameClient -----------------------------------------------------
1865
[email protected]310ebd6302011-10-10 19:06:281866WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
1867 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:551868 WebPlugin* plugin = NULL;
1869 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
1870 this, frame, params, &plugin)) {
1871 return plugin;
1872 }
1873
[email protected]a813c8e2011-10-08 01:34:111874 webkit::WebPluginInfo info;
1875 std::string mime_type;
1876 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
1877 params.mimeType.utf8(), &info, &mime_type);
1878 if (!found)
1879 return NULL;
1880
1881 WebPluginParams params_to_use = params;
1882 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:311883 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:171884}
1885
[email protected]310ebd6302011-10-10 19:06:281886WebWorker* RenderViewImpl::createWorker(WebFrame* frame,
1887 WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561888 WebApplicationCacheHostImpl* appcache_host =
1889 WebApplicationCacheHostImpl::FromFrame(frame);
1890 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
[email protected]f1a29a02011-10-06 23:08:441891 return new WebWorkerProxy(client, RenderThreadImpl::current(), routing_id_,
[email protected]14396e92010-05-06 20:40:561892 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171893}
1894
[email protected]310ebd6302011-10-10 19:06:281895WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:421896 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371897 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421898
[email protected]30447b62009-11-13 01:13:371899 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511900 bool exists = false;
[email protected]30447b62009-11-13 01:13:371901 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511902 ViewHostMsg_CreateWorker_Params params;
1903 params.url = url;
1904 params.is_shared = true;
1905 params.name = name;
1906 params.document_id = document_id;
1907 params.render_view_route_id = routing_id_;
1908 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231909 params.parent_appcache_host_id = 0;
1910 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371911 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511912 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371913 if (url_mismatch) {
1914 return NULL;
1915 } else {
[email protected]f1a29a02011-10-06 23:08:441916 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:491917 document_id,
[email protected]6de0bcf2010-02-17 22:00:511918 exists,
[email protected]30447b62009-11-13 01:13:371919 route_id,
1920 routing_id_);
1921 }
[email protected]9c00f002009-11-05 22:37:421922}
1923
[email protected]310ebd6302011-10-10 19:06:281924WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:171925 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441926 FOR_EACH_OBSERVER(
1927 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171928
[email protected]f78d1dfc2011-01-15 07:09:271929 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1930 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491931 scoped_ptr<media::FilterCollection> collection(
1932 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371933
[email protected]3d9689372009-09-10 04:29:171934 // Add in any custom filter factories first.
1935 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1936 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1937 // Add the chrome specific audio renderer.
[email protected]f7eb0a392011-07-12 10:19:511938 collection->AddAudioRenderer(new AudioRendererImpl());
[email protected]3d9689372009-09-10 04:29:171939 }
1940
[email protected]457d8342010-10-23 01:20:371941 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:311942 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
1943 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
1944 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:491945 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:311946 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:111947
[email protected]a8e24d522010-12-01 07:13:581948 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:271949 new webkit_glue::WebMediaPlayerImpl(client,
[email protected]baff4512011-10-19 18:21:071950 this,
[email protected]f78d1dfc2011-01-15 07:09:271951 collection.release(),
[email protected]ab2c4732011-07-20 19:57:401952 message_loop_factory.release(),
[email protected]090f7312011-08-05 23:26:401953 media_stream_impl_.get(),
1954 new RenderMediaLog()));
[email protected]79684282010-12-06 21:15:461955 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:581956 cmd_line->HasSwitch(switches::kSimpleDataSource),
1957 video_renderer)) {
1958 return NULL;
1959 }
1960 return result.release();
[email protected]3d9689372009-09-10 04:29:171961}
1962
[email protected]310ebd6302011-10-10 19:06:281963WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:211964 WebFrame* frame, WebApplicationCacheHostClient* client) {
1965 return new RendererWebApplicationCacheHostImpl(
1966 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:441967 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:211968}
1969
[email protected]310ebd6302011-10-10 19:06:281970WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:381971 return &cookie_jar_;
1972}
1973
[email protected]310ebd6302011-10-10 19:06:281974void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511975 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451976}
1977
[email protected]310ebd6302011-10-10 19:06:281978void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511979 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171980}
1981
[email protected]310ebd6302011-10-10 19:06:281982void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:171983 WebFrame* frame, const WebURLRequest& request,
1984 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:341985 loadURLExternally(frame, request, policy, WebString());
1986}
1987
[email protected]310ebd6302011-10-10 19:06:281988void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:341989 WebFrame* frame, const WebURLRequest& request,
1990 WebNavigationPolicy policy,
1991 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:591992 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1993 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:341994 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
1995 suggested_name));
[email protected]efce17b2009-09-11 18:04:591996 } else {
[email protected]ae5184d62011-10-06 19:25:581997 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:591998 }
[email protected]3d9689372009-09-10 04:29:171999}
2000
[email protected]310ebd6302011-10-10 19:06:282001WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:172002 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222003 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152004 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2005 if (is_swapped_out_) {
2006 DCHECK(request.url() == GURL("about:swappedout"));
2007 return default_policy;
2008 }
2009
[email protected]3d9689372009-09-10 04:29:172010 // Webkit is asking whether to navigate to a new URL.
2011 // This is fine normally, except if we're showing UI from one security
2012 // context and they're trying to navigate to a different context.
2013 const GURL& url = request.url();
2014
[email protected]d19ea342011-04-20 20:31:132015 // A content initiated navigation may have originated from a link-click,
2016 // script, drag-n-drop operation, etc.
2017 bool is_content_initiated =
2018 NavigationState::FromDataSource(frame->provisionalDataSource())->
2019 is_content_initiated();
2020
[email protected]3d9689372009-09-10 04:29:172021 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302022 // navigations.
[email protected]d19ea342011-04-20 20:31:132023 if (is_content_initiated &&
2024 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:452025 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192026 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232027 // Reset these counters as the RenderView could be reused for the next
2028 // navigation.
2029 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232030 last_page_id_sent_to_browser_ = -1;
[email protected]ae5184d62011-10-06 19:25:582031 OpenURL(frame, url, referrer, default_policy);
[email protected]61c9f032010-03-31 23:04:192032 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172033 }
2034
[email protected]6101c342010-12-16 22:44:372035 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552036 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572037 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372038 // opening a new window). But we sometimes navigate to about:blank to clear a
2039 // tab, and we want to still allow that.
2040 //
[email protected]8f4da8c2011-02-09 19:49:572041 // Note: we do this only for GET requests because our mechanism for switching
2042 // processes only issues GET requests. In particular, POST requests don't
2043 // work, because this mechanism does not preserve form POST data. If it
2044 // becomes necessary to support process switching for POST requests, we will
2045 // need to send the request's httpBody data up to the browser process, and
2046 // issue a special POST navigation in WebKit (via
2047 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2048 // for examples of how to send the httpBody data.
2049 // Note2: We normally don't do this for browser-initiated navigations, since
2050 // it's pointless to tell the browser about navigations it gave us. But
2051 // we do potentially ask the browser to handle a redirect that was originally
2052 // initiated by the browser. See http://crbug.com/70943
2053 //
2054 // TODO(creis): Move this redirect check to the browser process to avoid
2055 // ping-ponging. See http://crbug.com/72380.
2056 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372057 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2058 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2059 bool send_referrer = false;
2060 bool should_fork =
[email protected]e091df82011-10-11 18:13:212061 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172062 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372063 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112064
[email protected]e48869a2011-04-01 19:56:032065 if (!should_fork) {
2066 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362067 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032068 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362069 frame, url, is_content_initiated, is_initial_navigation,
2070 &send_referrer);
[email protected]6101c342010-12-16 22:44:372071 }
2072
2073 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112074 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]ae5184d62011-10-06 19:25:582075 OpenURL(frame, url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112076 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2077 }
[email protected]3d9689372009-09-10 04:29:172078 }
2079
[email protected]43763f982011-08-26 18:33:402080 // Use the frame's original request's URL rather than the document's URL for
2081 // this check. For a popup, the document's URL may become the opener window's
2082 // URL if the opener has called document.write. See http://crbug.com/93517.
2083 GURL old_url(frame->dataSource()->request().url());
2084
[email protected]3d9689372009-09-10 04:29:172085 // Detect when a page is "forking" a new tab that can be safely rendered in
2086 // its own process. This is done by sites like Gmail that try to open links
2087 // in new windows without script connections back to the original page. We
2088 // treat such cases as browser navigations (in which we will create a new
2089 // renderer for a cross-site navigation), rather than WebKit navigations.
2090 //
2091 // We use the following heuristic to decide whether to fork a new page in its
2092 // own process:
2093 // The parent page must open a new tab to about:blank, set the new tab's
2094 // window.opener to null, and then redirect the tab to a cross-site URL using
2095 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462096 //
2097 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2098 // (see below).
[email protected]3d9689372009-09-10 04:29:172099 bool is_fork =
2100 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582101 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172102 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522103 historyBackListCount() < 1 &&
2104 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172105 // The parent page must have set the child's window.opener to null before
2106 // redirecting to the desired URL.
2107 frame->opener() == NULL &&
2108 // Must be a top-level frame.
2109 frame->parent() == NULL &&
2110 // Must not have issued the request from this page.
2111 is_content_initiated &&
2112 // Must be targeted at the current tab.
2113 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2114 // Must be a JavaScript navigation, which appears as "other".
2115 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462116
2117 // Recognize if this navigation is from a link with rel=noreferrer and
2118 // target=_blank attributes, in which case the opener will be suppressed. If
2119 // so, it is safe to load cross-site pages in a separate process, so we
2120 // should let the browser handle it.
2121 bool is_noreferrer_and_blank_target =
2122 // Frame should be top level and not yet navigated.
2123 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412124 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462125 historyBackListCount() < 1 &&
2126 historyForwardListCount() < 1 &&
2127 // Links with rel=noreferrer will have no Referer field, and their
2128 // resulting frame will have its window.opener suppressed.
2129 // TODO(creis): should add a request.httpReferrer() method to help avoid
2130 // typos on the unusual spelling of Referer.
2131 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2132 opener_suppressed_ &&
2133 frame->opener() == NULL &&
2134 // Links with target=_blank will have no name.
2135 frame->name().isNull() &&
2136 // Another frame (with a non-empty creator) should have initiated the
2137 // request, targeted at this frame.
2138 !creator_url_.is_empty() &&
2139 is_content_initiated &&
2140 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2141 type == WebKit::WebNavigationTypeOther;
2142
2143 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172144 // Open the URL via the browser, not via WebKit.
[email protected]ae5184d62011-10-06 19:25:582145 OpenURL(frame, url, GURL(), default_policy);
[email protected]3d9689372009-09-10 04:29:172146 return WebKit::WebNavigationPolicyIgnore;
2147 }
2148
2149 return default_policy;
2150}
2151
[email protected]310ebd6302011-10-10 19:06:282152bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492153 WebFrame* frame, const WebURLRequest& request) {
2154 // We allow WebKit to think that everything can be handled even though
2155 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342156 return true;
2157}
2158
[email protected]310ebd6302011-10-10 19:06:282159WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492160 WebFrame* frame, const WebURLRequest& request) {
2161 NOTREACHED(); // Since we said we can handle all requests.
2162 return WebURLError();
2163}
2164
[email protected]310ebd6302011-10-10 19:06:282165WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492166 WebFrame* frame, const WebURLRequest& request) {
2167 WebURLError error;
2168 error.domain = WebString::fromUTF8(net::kErrorDomain);
2169 error.reason = net::ERR_ABORTED;
2170 error.unreachableURL = request.url();
2171 return error;
[email protected]7b7a7dc2009-10-19 02:23:342172}
2173
[email protected]310ebd6302011-10-10 19:06:282174void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492175 WebFrame*, const WebURLError&) {
2176 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342177}
2178
[email protected]310ebd6302011-10-10 19:06:282179void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432180 const WebKit::WebFormElement& form) {
2181 // Some login forms have onSubmit handlers that put a hash of the password
2182 // into a hidden field and then clear the password. (Issue 28910.)
2183 // This method gets called before any of those handlers run, so save away
2184 // a copy of the password in case it gets lost.
2185 NavigationState* navigation_state =
2186 NavigationState::FromDataSource(frame->dataSource());
2187 navigation_state->set_password_form_data(
2188 PasswordFormDomManager::CreatePasswordForm(form));
2189}
2190
[email protected]310ebd6302011-10-10 19:06:282191void RenderViewImpl::willSubmitForm(WebFrame* frame,
2192 const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172193 NavigationState* navigation_state =
2194 NavigationState::FromDataSource(frame->provisionalDataSource());
2195
[email protected]2905f742011-10-13 03:51:582196 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2197 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172198
2199 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352200 WebSearchableFormData web_searchable_form_data(form);
2201 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2202 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212203 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432204 PasswordForm* password_form_data =
2205 PasswordFormDomManager::CreatePasswordForm(form);
2206 navigation_state->set_password_form_data(password_form_data);
2207
[email protected]098c95cb2011-04-28 16:49:012208 // In order to save the password that the user actually typed and not one
2209 // that may have gotten transformed by the site prior to submit, recover it
2210 // from the form contents already stored by |willSendSubmitEvent| into the
2211 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2212 // which is what we're storing into now.)
2213 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432214 NavigationState* old_navigation_state =
2215 NavigationState::FromDataSource(frame->dataSource());
2216 if (old_navigation_state) {
2217 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2218 if (old_form_data && old_form_data->action == password_form_data->action)
2219 password_form_data->password_value = old_form_data->password_value;
2220 }
2221 }
[email protected]3d9689372009-09-10 04:29:172222
[email protected]2a5b1732011-04-01 23:55:552223 FOR_EACH_OBSERVER(
2224 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172225}
2226
[email protected]310ebd6302011-10-10 19:06:282227void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172228 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2229 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382230 FOR_EACH_OBSERVER(
2231 RenderViewObserver, observers_,
2232 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172233}
2234
[email protected]310ebd6302011-10-10 19:06:282235void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382236 FOR_EACH_OBSERVER(
2237 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172238}
2239
[email protected]310ebd6302011-10-10 19:06:282240void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172241 WebFrame* frame, const WebURL& from) {
2242 if (!frame->parent())
2243 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382244 FOR_EACH_OBSERVER(
2245 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172246}
2247
[email protected]310ebd6302011-10-10 19:06:282248void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]3d9689372009-09-10 04:29:172249 // The rest of RenderView assumes that a WebDataSource will always have a
2250 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482251 bool content_initiated = !pending_navigation_state_.get();
2252 NavigationState* state = content_initiated ?
2253 NavigationState::CreateContentInitiated() :
2254 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512255
[email protected]8a3125a712010-08-09 18:58:512256 // NavigationState::referred_by_prefetcher_ is true if we are
2257 // navigating from a page that used prefetching using a link on that
2258 // page. We are early enough in the request process here that we
2259 // can still see the NavigationState of the previous page and set
2260 // this value appropriately.
2261 // TODO(gavinp): catch the important case of navigation in a new
2262 // renderer process.
2263 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302264 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522265 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512266 const GURL referrer(
2267 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2268 if (!referrer.is_empty() &&
2269 NavigationState::FromDataSource(
2270 old_frame->dataSource())->was_prefetcher()) {
2271 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2272 WebDataSource* old_frame_ds = old_frame->dataSource();
2273 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2274 state->set_was_referred_by_prefetcher(true);
2275 break;
2276 }
2277 }
2278 }
2279 }
2280 }
2281
[email protected]4c1b6f0b2010-02-07 16:38:182282 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522283 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512284 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182285 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2286 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2287 break;
2288 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2289 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2290 break;
2291 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2292 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2293 break;
2294 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2295 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2296 break;
2297 }
2298 }
[email protected]fa7b6b542009-11-03 05:02:302299
[email protected]16e923d2011-04-30 00:41:442300 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502301
[email protected]946a0032011-03-31 18:42:282302 FOR_EACH_OBSERVER(
2303 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172304}
2305
[email protected]310ebd6302011-10-10 19:06:282306void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172307 WebDataSource* ds = frame->provisionalDataSource();
2308 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2309
[email protected]3d9689372009-09-10 04:29:172310 // Update the request time if WebKit has better knowledge of it.
2311 if (navigation_state->request_time().is_null()) {
2312 double event_time = ds->triggeringEventTime();
2313 if (event_time != 0.0)
2314 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2315 }
2316
[email protected]05c8e502010-08-15 15:13:522317 // Start time is only set after request time.
2318 navigation_state->set_start_load_time(Time::Now());
2319
[email protected]3d9689372009-09-10 04:29:172320 bool is_top_most = !frame->parent();
2321 if (is_top_most) {
2322 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132323 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172324
2325 // Make sure redirect tracking state is clear for the new load.
2326 completed_client_redirect_src_ = GURL();
2327 } else if (frame->parent()->isLoading()) {
2328 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002329 // load an error page. See didFailProvisionalLoad.
[email protected]2905f742011-10-13 03:51:582330 navigation_state->set_transition_type(
2331 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172332 }
2333
[email protected]28685da92011-02-07 21:49:172334 FOR_EACH_OBSERVER(
2335 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2336
[email protected]3d9689372009-09-10 04:29:172337 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592338 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262339 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172340}
2341
[email protected]310ebd6302011-10-10 19:06:282342void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2343 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172344 if (frame->parent())
2345 return;
2346 // Received a redirect on the main frame.
2347 WebDataSource* data_source = frame->provisionalDataSource();
2348 if (!data_source) {
2349 // Should only be invoked when we have a data source.
2350 NOTREACHED();
2351 return;
2352 }
2353 std::vector<GURL> redirects;
2354 GetRedirectChain(data_source, &redirects);
2355 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512356 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592357 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172358 }
2359}
2360
[email protected]310ebd6302011-10-10 19:06:282361void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2362 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172363 // Notify the browser that we failed a provisional load with an error.
2364 //
2365 // Note: It is important this notification occur before DidStopLoading so the
2366 // SSL manager can react to the provisional load failure before being
2367 // notified the load stopped.
2368 //
2369 WebDataSource* ds = frame->provisionalDataSource();
2370 DCHECK(ds);
2371
2372 const WebURLRequest& failed_request = ds->request();
2373
[email protected]28685da92011-02-07 21:49:172374 FOR_EACH_OBSERVER(
2375 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2376
[email protected]3d9689372009-09-10 04:29:172377 bool show_repost_interstitial =
2378 (error.reason == net::ERR_CACHE_MISS &&
2379 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582380
2381 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2382 params.frame_id = frame->identifier();
2383 params.is_main_frame = !frame->parent();
2384 params.error_code = error.reason;
2385 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2386 failed_request,
2387 error,
2388 NULL,
2389 &params.error_description);
2390 params.url = error.unreachableURL;
2391 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172392 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582393 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172394
2395 // Don't display an error page if this is simply a cancelled load. Aside
2396 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2397 if (error.reason == net::ERR_ABORTED)
2398 return;
2399
2400 // Make sure we never show errors in view source mode.
2401 frame->enableViewSourceMode(false);
2402
2403 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2404
2405 // If this is a failed back/forward/reload navigation, then we need to do a
2406 // 'replace' load. This is necessary to avoid messing up session history.
2407 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2408 // as session history is concerned.
2409 //
2410 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2411 // the page id.
2412 //
2413 bool replace =
2414 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582415 navigation_state->transition_type() ==
2416 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172417
2418 // If we failed on a browser initiated request, then make sure that our error
2419 // page load is regarded as the same browser initiated request.
2420 if (!navigation_state->is_content_initiated()) {
2421 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2422 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002423 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172424 navigation_state->transition_type(),
2425 navigation_state->request_time()));
2426 }
2427
2428 // Provide the user with a more helpful error page?
2429 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2430 return;
2431
2432 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082433 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172434}
2435
[email protected]310ebd6302011-10-10 19:06:282436void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172437 WebFrame* frame, const char* data, size_t data_len,
2438 bool& prevent_default) {
2439 NavigationState* navigation_state =
2440 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092441 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172442}
2443
[email protected]310ebd6302011-10-10 19:06:282444void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2445 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172446 NavigationState* navigation_state =
2447 NavigationState::FromDataSource(frame->dataSource());
2448
2449 navigation_state->set_commit_load_time(Time::Now());
2450 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202451 // When we perform a new navigation, we need to update the last committed
2452 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172453 UpdateSessionHistory(frame);
2454
2455 // We bump our Page ID to correspond with the new session history entry.
2456 page_id_ = next_page_id_++;
2457
[email protected]3cc72b12010-03-18 23:03:002458 // Advance our offset in session history, applying the length limit. There
2459 // is now no forward history.
2460 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102461 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2462 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002463 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032464 history_page_ids_.resize(history_list_length_, -1);
2465 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172466 } else {
2467 // Inspect the navigation_state on this frame to see if the navigation
2468 // corresponds to a session history navigation... Note: |frame| may or
2469 // may not be the toplevel frame, but for the case of capturing session
2470 // history, the first committed frame suffices. We keep track of whether
2471 // we've seen this commit before so that only capture session history once
2472 // per navigation.
2473 //
2474 // Note that we need to check if the page ID changed. In the case of a
2475 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2476 // previous URL and the current page ID, which would be wrong.
2477 if (navigation_state->pending_page_id() != -1 &&
2478 navigation_state->pending_page_id() != page_id_ &&
2479 !navigation_state->request_committed()) {
2480 // This is a successful session history navigation!
2481 UpdateSessionHistory(frame);
2482 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002483
2484 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032485
2486 // If the history list is valid, our list of page IDs should be correct.
2487 DCHECK(history_list_length_ <= 0 ||
2488 history_list_offset_ < 0 ||
2489 history_list_offset_ >= history_list_length_ ||
2490 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172491 }
2492 }
2493
[email protected]28685da92011-02-07 21:49:172494 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2495 DidCommitProvisionalLoad(frame, is_new_navigation));
2496
[email protected]3d9689372009-09-10 04:29:172497 // Remember that we've already processed this request, so we don't update
2498 // the session history again. We do this regardless of whether this is
2499 // a session history navigation, because if we attempted a session history
2500 // navigation without valid HistoryItem state, WebCore will think it is a
2501 // new navigation.
2502 navigation_state->set_request_committed(true);
2503
2504 UpdateURL(frame);
2505
2506 // If this committed load was initiated by a client redirect, we're
2507 // at the last stop now, so clear it.
2508 completed_client_redirect_src_ = GURL();
2509
2510 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272511 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172512}
2513
[email protected]310ebd6302011-10-10 19:06:282514void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102515 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2516 DidClearWindowObject(frame));
2517
[email protected]b6cb3a842011-06-24 18:28:412518 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212519 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252520 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2521 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272522 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172523 }
[email protected]3d9689372009-09-10 04:29:172524}
2525
[email protected]310ebd6302011-10-10 19:06:282526void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172527 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412528 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252529 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272530 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172531 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2532 }
[email protected]e48869a2011-04-01 19:56:032533
2534 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2535 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172536}
2537
[email protected]310ebd6302011-10-10 19:06:282538void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2539 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462540 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172541
2542 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272543 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172544}
2545
[email protected]310ebd6302011-10-10 19:06:282546void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132547 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2548 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582549}
2550
[email protected]310ebd6302011-10-10 19:06:282551void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172552 WebDataSource* ds = frame->dataSource();
2553 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2554 DCHECK(navigation_state);
2555 navigation_state->set_finish_document_load_time(Time::Now());
2556
[email protected]622474d2010-11-04 09:21:082557 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172558
[email protected]28685da92011-02-07 21:49:172559 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2560 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172561
2562 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272563 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172564}
2565
[email protected]310ebd6302011-10-10 19:06:282566void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082567 if (webview()->mainFrame() == frame) {
2568 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2569 page_id_));
2570 }
[email protected]3d9689372009-09-10 04:29:172571}
2572
[email protected]310ebd6302011-10-10 19:06:282573void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172574 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172575}
2576
[email protected]310ebd6302011-10-10 19:06:282577void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172578 WebDataSource* ds = frame->dataSource();
2579 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2580 DCHECK(navigation_state);
2581 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412582
[email protected]676126f72011-01-15 00:03:512583 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172584
2585 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172586}
2587
[email protected]310ebd6302011-10-10 19:06:282588void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172589 WebFrame* frame, bool is_new_navigation) {
2590 // If this was a reference fragment navigation that we initiated, then we
2591 // could end up having a non-null pending navigation state. We just need to
2592 // update the ExtraData on the datasource so that others who read the
2593 // ExtraData will get the new NavigationState. Similarly, if we did not
2594 // initiate this navigation, then we need to take care to reset any pre-
2595 // existing navigation state to a content-initiated navigation state.
2596 // DidCreateDataSource conveniently takes care of this for us.
2597 didCreateDataSource(frame, frame->dataSource());
2598
[email protected]af15bed2010-08-25 21:12:092599 NavigationState* new_state =
2600 NavigationState::FromDataSource(frame->dataSource());
2601 new_state->set_was_within_same_page(true);
2602
[email protected]3d9689372009-09-10 04:29:172603 didCommitProvisionalLoad(frame, is_new_navigation);
2604
[email protected]750fcf872011-08-03 23:10:472605 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2606 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172607}
2608
[email protected]310ebd6302011-10-10 19:06:282609void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312610 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592611}
2612
[email protected]310ebd6302011-10-10 19:06:282613void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172614 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2615 // Ignore
2616}
2617
[email protected]310ebd6302011-10-10 19:06:282618void RenderViewImpl::willSendRequest(WebFrame* frame,
2619 unsigned identifier,
2620 WebURLRequest& request,
2621 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302622 WebFrame* top_frame = frame->top();
2623 if (!top_frame)
2624 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512625 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2626 WebDataSource* top_data_source = top_frame->dataSource();
2627 WebDataSource* data_source =
2628 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222629
[email protected]78d5cfe2011-02-04 08:43:222630 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032631 GURL new_url;
2632 if (content::GetContentClient()->renderer()->WillSendRequest(
2633 frame, request_url, &new_url)) {
2634 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222635 }
2636
[email protected]2905f742011-10-13 03:51:582637 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]d88bf0a2011-08-30 23:55:572638 NavigationState* data_state = NavigationState::FromDataSource(data_source);
2639 if (data_state) {
2640 if (data_state->is_cache_policy_override_set())
2641 request.setCachePolicy(data_state->cache_policy_override());
2642 transition_type = data_state->transition_type();
[email protected]5e369672009-11-03 23:48:302643 }
[email protected]8a3125a712010-08-09 18:58:512644
[email protected]d88bf0a2011-08-30 23:55:572645 request.setExtraData(new RequestExtraData((frame == top_frame),
2646 frame->identifier(), transition_type));
2647
2648 NavigationState* top_data_state =
2649 NavigationState::FromDataSource(top_data_source);
2650 // TODO(gavinp): separate out prefetching and prerender field trials
2651 // if the rel=prerender rel type is sticking around.
2652 if (top_data_state &&
2653 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2654 request.targetType() == WebURLRequest::TargetIsPrerender))
2655 top_data_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512656
[email protected]3d9689372009-09-10 04:29:172657 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132658 request.setHasUserGesture(frame->isProcessingUserGesture());
2659
[email protected]0a8db0d2011-04-13 15:15:402660 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132661 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172662}
2663
[email protected]310ebd6302011-10-10 19:06:282664void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:172665 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492666
[email protected]3d9689372009-09-10 04:29:172667 // Only do this for responses that correspond to a provisional data source
2668 // of the top-most frame. If we have a provisional data source, then we
2669 // can't have any sub-resources yet, so we know that this response must
2670 // correspond to a frame load.
2671 if (!frame->provisionalDataSource() || frame->parent())
2672 return;
2673
2674 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082675 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172676 if (frame->isViewSourceModeEnabled())
2677 return;
2678
[email protected]65041fa2010-05-21 06:56:532679 NavigationState* navigation_state =
2680 NavigationState::FromDataSource(frame->provisionalDataSource());
2681 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082682 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532683
[email protected]972ebdff2010-06-10 22:59:072684 // Record page load flags.
2685 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2686 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572687 navigation_state->set_was_alternate_protocol_available(
2688 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072689 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082690 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092691 // Whether or not the http status code actually corresponds to an error is
2692 // only checked when the page is done loading, if |use_error_page| is
2693 // still true.
2694 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172695}
2696
[email protected]310ebd6302011-10-10 19:06:282697void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:172698 WebFrame* frame, unsigned identifier) {
2699 NavigationState* navigation_state =
2700 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092701 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172702 return;
2703
[email protected]7bfc153f2011-09-23 22:00:202704 // Do not show error page when DevTools is attached.
2705 if (devtools_agent_->IsAttached())
2706 return;
2707
[email protected]06333afe2011-02-24 14:55:092708 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082709 int http_status_code = navigation_state->http_status_code();
2710 if (http_status_code == 404) {
2711 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412712 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172713
[email protected]b6cb3a842011-06-24 18:28:412714 const GURL& error_page_url =
2715 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092716 if (error_page_url.is_valid()) {
2717 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472718 original_error.domain = "http";
2719 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412720 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172721
[email protected]06333afe2011-02-24 14:55:092722 navigation_state->set_alt_error_page_fetcher(
2723 new AltErrorPageResourceFetcher(
2724 error_page_url, frame, original_error,
[email protected]310ebd6302011-10-10 19:06:282725 NewCallback(this, &RenderViewImpl::AltErrorPageFinished)));
[email protected]06333afe2011-02-24 14:55:092726 return;
2727 }
2728 }
[email protected]3d9689372009-09-10 04:29:172729
[email protected]e6a2ce52011-10-08 01:40:132730 std::string error_domain;
2731 if (content::GetContentClient()->renderer()->HasErrorPage(
2732 http_status_code, &error_domain)) {
2733 WebURLError error;
2734 error.unreachableURL = frame->document().url();
2735 error.domain = WebString::fromUTF8(error_domain);
2736 error.reason = http_status_code;
2737
2738 LoadNavigationErrorPage(
2739 frame, frame->dataSource()->request(), error, std::string(), true);
2740 }
[email protected]3d9689372009-09-10 04:29:172741}
2742
[email protected]310ebd6302011-10-10 19:06:282743void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:172744 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2745 // Ignore
2746}
2747
[email protected]310ebd6302011-10-10 19:06:282748void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:172749 WebFrame* frame, const WebURLRequest& request,
2750 const WebURLResponse& response) {
2751 // Let the browser know we loaded a resource from the memory cache. This
2752 // message is needed to display the correct SSL indicators.
2753 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2754 routing_id_,
2755 request.url(),
[email protected]70435962011-08-02 20:13:282756 response.securityInfo(),
2757 request.httpMethod().utf8(),
2758 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172759}
2760
[email protected]310ebd6302011-10-10 19:06:282761void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292762 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2763}
2764
[email protected]310ebd6302011-10-10 19:06:282765void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:022766 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292767 Send(new ViewHostMsg_DidRunInsecureContent(
2768 routing_id_,
[email protected]92771112011-01-20 00:13:022769 origin.toString().utf8(),
2770 target));
[email protected]e3d60e5d2009-09-25 21:08:292771}
2772
[email protected]310ebd6302011-10-10 19:06:282773void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:032774 webkit_glue::WebURLLoaderImpl* loader_impl =
2775 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2776 loader_impl->UpdateRoutingId(routing_id_);
2777}
2778
[email protected]310ebd6302011-10-10 19:06:282779void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172780 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2781}
2782
[email protected]310ebd6302011-10-10 19:06:282783void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
2784 v8::Handle<v8::Context> context,
2785 int world_id) {
[email protected]5bc10932011-09-21 21:03:302786 content::GetContentClient()->renderer()->DidCreateScriptContext(
2787 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282788}
2789
[email protected]310ebd6302011-10-10 19:06:282790void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
2791 v8::Handle<v8::Context> context,
2792 int world_id) {
[email protected]5bc10932011-09-21 21:03:302793 content::GetContentClient()->renderer()->WillReleaseScriptContext(
2794 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282795}
2796
[email protected]310ebd6302011-10-10 19:06:282797void RenderViewImpl::didUpdateLayout(WebFrame* frame) {
[email protected]d812fd12011-05-27 23:05:072798 // We don't always want to set up a timer, only if we've been put in that
2799 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172800 // message.
[email protected]705243f2010-05-05 19:58:072801 if (!send_preferred_size_changes_ || !webview())
2802 return;
[email protected]dfca5acf2010-03-22 03:28:432803
[email protected]d812fd12011-05-27 23:05:072804 if (check_preferred_size_timer_.IsRunning())
2805 return;
[email protected]d323a172011-09-02 18:23:022806 check_preferred_size_timer_.Start(FROM_HERE,
2807 TimeDelta::FromMilliseconds(0), this,
[email protected]310ebd6302011-10-10 19:06:282808 &RenderViewImpl::CheckPreferredSize);
[email protected]d812fd12011-05-27 23:05:072809}
2810
[email protected]310ebd6302011-10-10 19:06:282811void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:072812 // We don't always want to send the change messages over IPC, only if we've
2813 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2814 // message.
2815 if (!send_preferred_size_changes_ || !webview())
2816 return;
2817
[email protected]705243f2010-05-05 19:58:072818 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2819 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532820
2821 // In the presence of zoom, these sizes are still reported as if unzoomed,
2822 // so we need to adjust.
2823 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2824 size.set_width(static_cast<int>(size.width() * zoom_factor));
2825 size.set_height(static_cast<int>(size.height() * zoom_factor));
2826
[email protected]705243f2010-05-05 19:58:072827 if (size == preferred_size_)
2828 return;
[email protected]c27324b2009-11-19 22:44:292829
[email protected]705243f2010-05-05 19:58:072830 preferred_size_ = size;
2831 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2832 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172833}
2834
[email protected]310ebd6302011-10-10 19:06:282835void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
2836 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:312837 if (webview()->mainFrame() != frame)
2838 return;
2839 WebView* frameView = frame->view();
2840 if (!frameView)
2841 return;
2842
2843 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
2844 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
2845
2846 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
2847 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
2848 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
2849 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
2850
2851 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
2852 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
2853 }
2854}
2855
[email protected]310ebd6302011-10-10 19:06:282856void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:312857 WebSize offset = frame->scrollOffset();
2858 WebSize minimum_offset = frame->minimumScrollOffset();
2859 WebSize maximum_offset = frame->maximumScrollOffset();
2860
2861 bool is_pinned_to_left = offset.width <= minimum_offset.width;
2862 bool is_pinned_to_right = offset.width >= maximum_offset.width;
2863
2864 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
2865 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
2866 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
2867 routing_id_, is_pinned_to_left, is_pinned_to_right));
2868
2869 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
2870 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
2871 }
2872}
2873
[email protected]310ebd6302011-10-10 19:06:282874void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:492875 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:312876
2877 if (webview()->mainFrame() == frame)
2878 UpdateScrollState(frame);
2879}
2880
[email protected]310ebd6302011-10-10 19:06:282881void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:312882 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:492883}
2884
[email protected]310ebd6302011-10-10 19:06:282885void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
2886 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112887 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2888 if (!count)
2889 active_match_ordinal = 0;
2890
2891 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2892 routing_id_,
2893 request_id,
2894 count,
2895 gfx::Rect(),
2896 active_match_ordinal,
2897 final_update);
2898
[email protected]8922e1f2009-10-03 05:01:262899 // If we have a message that has been queued up, then we should just replace
2900 // it. The ACK from the browser will make sure it gets sent when the browser
2901 // wants it.
2902 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262903 queued_find_reply_message_.reset(msg);
2904 } else {
2905 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112906 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262907 }
2908}
2909
[email protected]310ebd6302011-10-10 19:06:282910void RenderViewImpl::reportFindInPageSelection(int request_id,
2911 int active_match_ordinal,
2912 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:262913 // Send the search result over to the browser process.
2914 Send(new ViewHostMsg_Find_Reply(routing_id_,
2915 request_id,
2916 -1,
2917 selection_rect,
2918 active_match_ordinal,
2919 false));
2920}
2921
[email protected]310ebd6302011-10-10 19:06:282922void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:222923 WebFrame* frame,
2924 WebFileSystem::Type type,
2925 long long size,
[email protected]d275d7a2010-11-03 01:34:492926 bool create,
[email protected]2b06a992010-08-21 05:48:222927 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082928 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222929
[email protected]b6cb3a842011-06-24 18:28:412930 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082931 if (origin.isEmpty()) {
2932 // Uninitialized document?
2933 callbacks->didFail(WebKit::WebFileErrorAbort);
2934 return;
2935 }
[email protected]2b06a992010-08-21 05:48:222936
[email protected]c5a272d2010-09-27 18:37:082937 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2938 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492939 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222940}
2941
[email protected]310ebd6302011-10-10 19:06:282942void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:402943 WebFrame* frame,
2944 WebStorageQuotaType type,
2945 WebStorageQuotaCallbacks* callbacks) {
2946 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412947 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402948 if (origin.isEmpty()) {
2949 // Uninitialized document?
2950 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2951 return;
2952 }
2953 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:532954 GURL(origin.toString()),
2955 static_cast<quota::StorageType>(type),
2956 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402957}
2958
[email protected]310ebd6302011-10-10 19:06:282959void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:402960 WebFrame* frame,
2961 WebStorageQuotaType type,
2962 unsigned long long requested_size,
2963 WebStorageQuotaCallbacks* callbacks) {
2964 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412965 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402966 if (origin.isEmpty()) {
2967 // Uninitialized document?
2968 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2969 return;
2970 }
2971 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:532972 routing_id(), GURL(origin.toString()),
2973 static_cast<quota::StorageType>(type), requested_size,
2974 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402975}
2976
[email protected]18d5be92011-07-25 18:00:192977// WebKit::WebPageSerializerClient implementation ------------------------------
2978
[email protected]310ebd6302011-10-10 19:06:282979void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:192980 const WebURL& frame_url,
2981 const WebCString& data,
2982 WebPageSerializerClient::PageSerializationStatus status) {
2983 Send(new ViewHostMsg_SendSerializedHtmlData(
2984 routing_id(),
2985 frame_url,
2986 data.data(),
2987 static_cast<int32>(status)));
2988}
2989
[email protected]a2ef54c2011-10-10 16:20:312990// content::RenderView implementation ------------------------------------------
2991
[email protected]310ebd6302011-10-10 19:06:282992bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:312993 return RenderWidget::Send(message);
2994}
2995
[email protected]310ebd6302011-10-10 19:06:282996int RenderViewImpl::GetRoutingId() const {
[email protected]a2ef54c2011-10-10 16:20:312997 return routing_id_;
2998}
2999
[email protected]310ebd6302011-10-10 19:06:283000int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313001 return page_id_;
3002}
3003
[email protected]310ebd6302011-10-10 19:06:283004gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313005 return size();
3006}
3007
[email protected]310ebd6302011-10-10 19:06:283008gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313009 return host_window();
3010}
3011
[email protected]310ebd6302011-10-10 19:06:283012WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313013 return webkit_preferences_;
3014}
3015
[email protected]310ebd6302011-10-10 19:06:283016WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313017 return webview();
3018}
3019
[email protected]310ebd6302011-10-10 19:06:283020WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313021 if (!webview())
3022 return WebNode();
3023 WebFrame* focused_frame = webview()->focusedFrame();
3024 if (focused_frame) {
3025 WebDocument doc = focused_frame->document();
3026 if (!doc.isNull())
3027 return doc.focusedNode();
3028 }
3029
3030 return WebNode();
3031}
3032
[email protected]310ebd6302011-10-10 19:06:283033WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313034 return context_menu_node_;
3035}
3036
[email protected]310ebd6302011-10-10 19:06:283037bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313038 bool is_editable_node = false;
3039 if (!node.isNull()) {
3040 if (node.isContentEditable()) {
3041 is_editable_node = true;
3042 } else if (node.isElementNode()) {
3043 is_editable_node =
3044 node.toConst<WebElement>().isTextFormControlElement();
3045 }
3046 }
3047 return is_editable_node;
3048}
3049
[email protected]310ebd6302011-10-10 19:06:283050WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313051 WebKit::WebFrame* frame,
3052 const webkit::WebPluginInfo& info,
3053 const WebKit::WebPluginParams& params) {
3054 bool pepper_plugin_was_registered = false;
3055 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3056 pepper_delegate_.CreatePepperPluginModule(info,
3057 &pepper_plugin_was_registered));
3058 if (pepper_plugin_was_registered) {
3059 if (!pepper_module)
3060 return NULL;
3061 return new webkit::ppapi::WebPluginImpl(
3062 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3063 }
3064
3065 return new webkit::npapi::WebPluginImpl(
3066 frame, params, info.path, AsWeakPtr());
3067}
3068
[email protected]310ebd6302011-10-10 19:06:283069void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3070 const string16& jscript,
3071 int id,
3072 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313073 v8::Handle<v8::Value> result;
3074 WebFrame* web_frame = GetChildFrame(frame_xpath);
3075 if (web_frame)
3076 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3077 if (notify_result) {
3078 ListValue list;
3079 if (!result.IsEmpty() && web_frame) {
3080 v8::HandleScope handle_scope;
3081 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3082 v8::Context::Scope context_scope(context);
3083 V8ValueConverterImpl converter;
3084 converter.set_allow_date(true);
3085 converter.set_allow_regexp(true);
3086 list.Set(0, converter.FromV8Value(result, context));
3087 } else {
3088 list.Set(0, Value::CreateNullValue());
3089 }
3090 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3091 }
3092}
3093
[email protected]310ebd6302011-10-10 19:06:283094bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313095 return (!send_preferred_size_changes_ ||
3096 (disable_scrollbars_size_limit_.width() <= width ||
3097 disable_scrollbars_size_limit_.height() <= height));
3098}
3099
[email protected]310ebd6302011-10-10 19:06:283100int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313101 return enabled_bindings_;
3102}
3103
[email protected]310ebd6302011-10-10 19:06:283104void RenderViewImpl::SetEnabledBindings(int enabled_bindings) {
[email protected]a2ef54c2011-10-10 16:20:313105 enabled_bindings_ = enabled_bindings;
3106}
3107
[email protected]310ebd6302011-10-10 19:06:283108bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313109 return send_content_state_immediately_;
3110}
3111
[email protected]310ebd6302011-10-10 19:06:283112float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313113 return filtered_time_per_frame();
3114}
3115
[email protected]310ebd6302011-10-10 19:06:283116void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3117 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313118 showContextMenu(frame, data);
3119}
3120
[email protected]310ebd6302011-10-10 19:06:283121WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313122 return visibilityState();
3123}
3124
[email protected]310ebd6302011-10-10 19:06:283125void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3126 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313127 return runModalAlertDialog(frame, message);
3128}
3129
[email protected]310ebd6302011-10-10 19:06:283130void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313131 WebKit::WebFrame* frame,
3132 const WebKit::WebURLRequest& request,
3133 WebKit::WebNavigationPolicy policy) {
3134 loadURLExternally(frame, request, policy);
3135}
3136
3137// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513138
[email protected]310ebd6302011-10-10 19:06:283139webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533140 const FilePath& file_path,
3141 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593142 if (!PluginChannelHost::IsListening())
3143 return NULL;
3144
[email protected]00c39612010-03-06 02:53:283145 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463146 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323147#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223148 return webkit::npapi::WebPluginDelegateImpl::Create(
3149 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093150#else
[email protected]7398dcc2011-09-06 21:40:323151 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223152 NOTIMPLEMENTED();
3153 return NULL;
[email protected]7b6616f2010-01-14 18:07:553154#endif
[email protected]f103ab72009-09-02 17:10:593155 }
3156
[email protected]4e0616e2010-05-28 14:55:533157 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593158}
3159
[email protected]310ebd6302011-10-10 19:06:283160void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033161#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273162 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593163#endif
3164}
3165
[email protected]310ebd6302011-10-10 19:06:283166void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033167#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273168 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593169#endif
3170 CleanupWindowInPluginMoves(window);
3171}
3172
[email protected]310ebd6302011-10-10 19:06:283173void RenderViewImpl::DidMovePlugin(
3174 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593175 SchedulePluginMove(move);
3176}
3177
[email protected]310ebd6302011-10-10 19:06:283178void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593179 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523180 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593181}
3182
[email protected]310ebd6302011-10-10 19:06:283183void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593184 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523185 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593186}
3187
[email protected]310ebd6302011-10-10 19:06:283188WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513189 return &cookie_jar_;
3190}
3191
[email protected]baff4512011-10-19 18:21:073192void RenderViewImpl::DidPlay(webkit_glue::WebMediaPlayerImpl* player) {
3193 Send(new ViewHostMsg_MediaNotification(routing_id_,
3194 reinterpret_cast<int64>(player),
3195 player->hasVideo(),
3196 player->hasAudio(),
3197 true));
3198}
3199
3200void RenderViewImpl::DidPause(webkit_glue::WebMediaPlayerImpl* player) {
3201 Send(new ViewHostMsg_MediaNotification(routing_id_,
3202 reinterpret_cast<int64>(player),
3203 player->hasVideo(),
3204 player->hasAudio(),
3205 false));
3206}
3207
3208void RenderViewImpl::PlayerGone(webkit_glue::WebMediaPlayerImpl* player) {
3209 DidPause(player);
3210}
3211
[email protected]310ebd6302011-10-10 19:06:283212void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293213 if (!webview())
3214 return;
3215
[email protected]26aa0482009-09-30 16:55:273216 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173217 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293218 return;
[email protected]ca948a22009-06-25 19:36:173219
3220 Send(new ViewHostMsg_UpdateState(
3221 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293222}
3223
[email protected]310ebd6302011-10-10 19:06:283224void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363225 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003226 if (!frame)
3227 return;
[email protected]b781ff282011-08-20 06:19:363228
[email protected]b781ff282011-08-20 06:19:363229 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003230 if (!webview()->caretOrSelectionRange(&location, &length))
3231 return;
3232
3233 string16 text;
3234 size_t offset;
3235 ui::Range range(location, location + length);
3236
3237 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3238 // If current focused element is editable, we will send 100 more chars
3239 // before and after selection. It is for input method surrounding text
3240 // feature.
3241 if (location > kExtraCharsBeforeAndAfterSelection)
3242 offset = location - kExtraCharsBeforeAndAfterSelection;
3243 else
3244 offset = 0;
3245 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3246 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3247 if (!webrange.isNull())
3248 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3249 } else {
3250 offset = location;
3251 text = frame->selectionAsText();
[email protected]b781ff282011-08-20 06:19:363252 }
3253
[email protected]b781ff282011-08-20 06:19:363254 // Sometimes we get repeated didChangeSelection calls from webkit when
3255 // the selection hasn't actually changed. We don't want to report these
3256 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003257 if (selection_text_offset_ != offset ||
3258 selection_range_ != range ||
3259 selection_text_ != text) {
3260 selection_text_ = text;
3261 selection_text_offset_ = offset;
3262 selection_range_ = range;
3263 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3264 }
[email protected]b781ff282011-08-20 06:19:363265}
3266
[email protected]310ebd6302011-10-10 19:06:283267GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3268 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553269 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293270 // If the URL that failed was secure, then the embedding web page was not
3271 // expecting a network attacker to be able to manipulate its contents. As
3272 // we fetch alternate error pages over HTTP, we would be allowing a network
3273 // attacker to manipulate the contents of the response if we tried to use
3274 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153275 return GURL();
initial.commit09911bf2008-07-26 23:55:293276 }
3277
3278 // Grab the base URL from the browser process.
3279 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153280 return GURL();
initial.commit09911bf2008-07-26 23:55:293281
3282 // Strip query params from the failed URL.
3283 GURL::Replacements remove_params;
3284 remove_params.ClearUsername();
3285 remove_params.ClearPassword();
3286 remove_params.ClearQuery();
3287 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553288 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503289 std::string spec_to_send = url_to_send.spec();
3290 // Notify link doctor of the url truncation by sending of "?" at the end.
3291 if (failed_url.has_query())
3292 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293293
3294 // Construct the query params to send to link doctor.
3295 std::string params(alternate_error_page_url_.query());
3296 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023297 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293298 params.append("&sourceid=chrome");
3299 params.append("&error=");
3300 switch (error_type) {
3301 case DNS_ERROR:
3302 params.append("dnserror");
3303 break;
3304
3305 case HTTP_404:
3306 params.append("http404");
3307 break;
3308
[email protected]5df266ac2008-10-15 19:50:133309 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333310 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133311 break;
3312
initial.commit09911bf2008-07-26 23:55:293313 default:
3314 NOTREACHED() << "unknown ErrorPageType";
3315 }
3316
3317 // OK, build the final url to return.
3318 GURL::Replacements link_doctor_params;
3319 link_doctor_params.SetQueryStr(params);
3320 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3321 return url;
3322}
3323
[email protected]310ebd6302011-10-10 19:06:283324GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593325 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3326 return GURL();
3327 else
3328 return creator_url_;
3329}
3330
[email protected]310ebd6302011-10-10 19:06:283331WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273332 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313333 web_ui_bindings_.reset(new WebUIBindings(
3334 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463335 }
[email protected]c50008512011-02-03 01:17:273336 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463337}
3338
[email protected]310ebd6302011-10-10 19:06:283339WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013340 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493341}
3342
[email protected]310ebd6302011-10-10 19:06:283343void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3344 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273345 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493346
[email protected]872542532011-06-23 00:43:163347 // Check if the plugin still exists in the document.
3348 if (main_frame->document().isPluginDocument() &&
3349 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493350 if (options.findNext) {
3351 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013352 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493353 } else {
[email protected]afdbd142010-07-10 08:01:233354 if (GetWebPluginFromPluginDocument()->startFind(
3355 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493356 } else {
[email protected]e7c58a32010-08-13 19:47:113357 // Send "no results".
3358 Send(new ViewHostMsg_Find_Reply(routing_id_,
3359 request_id,
3360 0,
3361 gfx::Rect(),
3362 0,
3363 true));
[email protected]24a7f3c2010-03-25 08:26:493364 }
3365 }
3366 return;
3367 }
3368
[email protected]b4bb2502009-10-01 22:35:273369 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273370 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293371 WebFrame* search_frame = focused_frame; // start searching focused frame.
3372
3373 bool multi_frame = (frame_after_main != main_frame);
3374
3375 // If we have multiple frames, we don't want to wrap the search within the
3376 // frame, so we check here if we only have main_frame in the chain.
3377 bool wrap_within_frame = !multi_frame;
3378
[email protected]b3f2b912009-04-09 16:18:523379 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293380 bool result = false;
3381
[email protected]7830da3e2009-11-06 16:27:263382 // If something is selected when we start searching it means we cannot just
3383 // increment the current match ordinal; we need to re-generate it.
3384 WebRange current_selection = focused_frame->selectionRange();
3385
initial.commit09911bf2008-07-26 23:55:293386 do {
[email protected]dd7daa82009-08-10 05:46:453387 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593388 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293389
3390 if (!result) {
3391 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223392 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293393
3394 // Find the next frame, but skip the invisible ones.
3395 do {
3396 // What is the next frame to search? (we might be going backwards). Note
3397 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593398 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273399 search_frame->traverseNext(true) :
3400 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453401 } while (!search_frame->hasVisibleContent() &&
3402 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293403
[email protected]884db412008-11-24 23:46:503404 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223405 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293406
3407 // If we have multiple frames and we have wrapped back around to the
3408 // focused frame, we need to search it once more allowing wrap within
3409 // the frame, otherwise it will report 'no match' if the focused frame has
3410 // reported matches, but no frames after the focused_frame contain a
3411 // match for the search word(s).
3412 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453413 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593414 request_id, search_text, options, true, // Force wrapping.
3415 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293416 }
3417 }
3418
[email protected]26aa0482009-09-30 16:55:273419 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293420 } while (!result && search_frame != focused_frame);
3421
[email protected]7830da3e2009-11-06 16:27:263422 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293423 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453424 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293425 } else {
3426 // If nothing is found, set result to "0 of 0", otherwise, set it to
3427 // "-1 of 1" to indicate that we found at least one item, but we don't know
3428 // yet what is active.
3429 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3430 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293431
[email protected]4f3dc372009-02-24 00:10:293432 // If we find no matches then this will be our last status update.
3433 // Otherwise the scoping effort will send more results.
3434 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293435
[email protected]4f3dc372009-02-24 00:10:293436 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403437 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593438 request_id,
[email protected]4f3dc372009-02-24 00:10:293439 match_count,
3440 selection_rect,
3441 ordinal,
3442 final_status_update));
initial.commit09911bf2008-07-26 23:55:293443
initial.commit09911bf2008-07-26 23:55:293444 // Scoping effort begins, starting with the mainframe.
3445 search_frame = main_frame;
3446
[email protected]dd7daa82009-08-10 05:46:453447 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293448
3449 do {
3450 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453451 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293452
3453 // We don't start another scoping effort unless at least one match has
3454 // been found.
3455 if (result) {
3456 // Start new scoping request. If the scoping function determines that it
3457 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453458 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593459 search_text,
3460 options,
initial.commit09911bf2008-07-26 23:55:293461 true); // reset the tickmarks
3462 }
3463
3464 // Iterate to the next frame. The frame will not necessarily scope, for
3465 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273466 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293467 } while (search_frame != main_frame);
3468 }
3469}
3470
[email protected]310ebd6302011-10-10 19:06:283471void RenderViewImpl::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
[email protected]24a7f3c2010-03-25 08:26:493472 WebView* view = webview();
3473 if (!view)
3474 return;
3475
3476 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163477 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013478 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493479 return;
3480 }
3481
3482 bool clear_selection =
3483 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3484 if (clear_selection)
3485 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3486
3487 WebFrame* frame = view->mainFrame();
3488 while (frame) {
3489 frame->stopFinding(clear_selection);
3490 frame = frame->traverseNext(false);
3491 }
3492
3493 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3494 WebFrame* focused_frame = view->focusedFrame();
3495 if (focused_frame) {
3496 WebDocument doc = focused_frame->document();
3497 if (!doc.isNull()) {
3498 WebNode node = doc.focusedNode();
3499 if (!node.isNull())
3500 node.simulateClick();
3501 }
3502 }
3503 }
3504}
3505
[email protected]310ebd6302011-10-10 19:06:283506void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493507 // Check if there is any queued up request waiting to be sent.
3508 if (queued_find_reply_message_.get()) {
3509 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423510 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493511 }
3512}
3513
[email protected]310ebd6302011-10-10 19:06:283514void RenderViewImpl::OnZoom(PageZoom::Function function) {
[email protected]40bd6582009-12-04 23:49:513515 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3516 return;
3517
[email protected]258d31122010-05-09 10:59:413518 webview()->hidePopups();
[email protected]c514d6372011-08-16 22:54:443519#if !defined(TOUCH_UI)
[email protected]b75b8292010-10-01 07:28:253520 double old_zoom_level = webview()->zoomLevel();
3521 double zoom_level;
3522 if (function == PageZoom::RESET) {
3523 zoom_level = 0;
3524 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3525 // Previous zoom level is a whole number, so just increment/decrement.
3526 zoom_level = old_zoom_level + function;
3527 } else {
3528 // Either the user hit the zoom factor limit and thus the zoom level is now
3529 // not a whole number, or a plugin changed it to a custom value. We want
3530 // to go to the next whole number so that the user can always get back to
3531 // 100% with the keyboard/menu.
3532 if ((old_zoom_level > 1 && function > 0) ||
3533 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453534 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253535 } else {
3536 // We're going towards 100%, so first go to the next whole number.
3537 zoom_level = static_cast<int>(old_zoom_level);
3538 }
3539 }
[email protected]b75b8292010-10-01 07:28:253540 webview()->setZoomLevel(false, zoom_level);
[email protected]c514d6372011-08-16 22:54:443541#else
3542 double old_page_scale_factor = webview()->pageScaleFactor();
3543 double page_scale_factor;
3544 if (function == PageZoom::RESET) {
3545 page_scale_factor = 1.0;
3546 } else {
3547 page_scale_factor = old_page_scale_factor +
3548 (function > 0 ? kScalingIncrement : -kScalingIncrement);
3549 }
3550 webview()->scalePage(page_scale_factor, WebPoint(0, 0));
3551#endif
[email protected]b75b8292010-10-01 07:28:253552 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513553}
3554
[email protected]310ebd6302011-10-10 19:06:283555void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173556 // Don't set zoom level for full-page plugin since they don't use the same
3557 // zoom settings.
3558 if (webview()->mainFrame()->document().isPluginDocument())
3559 return;
3560
3561 webview()->hidePopups();
3562 webview()->setZoomLevel(false, zoom_level);
3563 zoomLevelChanged();
3564}
3565
[email protected]310ebd6302011-10-10 19:06:283566void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3567 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543568 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293569}
3570
[email protected]310ebd6302011-10-10 19:06:283571void RenderViewImpl::OnExitFullscreen() {
[email protected]8a5e0ca2011-08-25 06:30:473572 webview()->exitFullscreen();
3573}
3574
[email protected]310ebd6302011-10-10 19:06:283575void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273576 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293577}
3578
[email protected]310ebd6302011-10-10 19:06:283579void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273580 WebString no_encoding;
3581 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183582}
3583
[email protected]310ebd6302011-10-10 19:06:283584WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453585 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273586 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453587
3588 // xpath string can represent a frame deep down the tree (across multiple
3589 // frame DOMs).
3590 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3591 // should break into 2 xpaths
3592 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413593 std::vector<string16> xpaths;
3594 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453595
[email protected]26aa0482009-09-30 16:55:273596 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413597 for (std::vector<string16>::const_iterator i = xpaths.begin();
3598 frame && i != xpaths.end(); ++i) {
3599 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293600 }
3601
[email protected]dd7daa82009-08-10 05:46:453602 return frame;
initial.commit09911bf2008-07-26 23:55:293603}
3604
[email protected]310ebd6302011-10-10 19:06:283605void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
3606 const string16& jscript,
3607 int id,
3608 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:533609 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293610}
3611
[email protected]310ebd6302011-10-10 19:06:283612void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
3613 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413614 WebFrame* frame = GetChildFrame(frame_xpath);
3615 if (!frame)
[email protected]216813952011-05-19 22:21:263616 return;
[email protected]ae461542009-06-19 19:03:413617
[email protected]01cf589c2011-07-28 18:04:033618 frame->document().insertUserStyleSheet(
3619 WebString::fromUTF8(css),
3620 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483621}
3622
[email protected]310ebd6302011-10-10 19:06:283623void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:093624 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293625}
3626
[email protected]310ebd6302011-10-10 19:06:283627void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
3628 const std::string& value) {
[email protected]e091df82011-10-11 18:13:213629 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:273630 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293631}
3632
[email protected]310ebd6302011-10-10 19:06:283633void RenderViewImpl::OnReservePageIDRange(int size_of_range) {
initial.commit09911bf2008-07-26 23:55:293634 next_page_id_ += size_of_range + 1;
3635}
3636
[email protected]310ebd6302011-10-10 19:06:283637void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
3638 const gfx::Point& client_point,
3639 const gfx::Point& screen_point,
3640 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553641 WebDragOperation operation = webview()->dragTargetDragEnter(
3642 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553643 client_point,
3644 screen_point,
3645 ops);
3646
3647 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3648}
3649
[email protected]310ebd6302011-10-10 19:06:283650void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
3651 const gfx::Point& screen_point,
3652 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553653 WebDragOperation operation = webview()->dragTargetDragOver(
3654 client_point,
3655 screen_point,
3656 ops);
3657
3658 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3659}
3660
[email protected]310ebd6302011-10-10 19:06:283661void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:553662 webview()->dragTargetDragLeave();
3663}
3664
[email protected]310ebd6302011-10-10 19:06:283665void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
3666 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:553667 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573668
3669 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553670}
3671
[email protected]310ebd6302011-10-10 19:06:283672void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3673 const gfx::Point& screen_point,
3674 bool ended,
3675 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033676 if (ended) {
[email protected]26aa0482009-09-30 16:55:273677 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203678 } else {
3679 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033680 }
initial.commit09911bf2008-07-26 23:55:293681}
3682
[email protected]310ebd6302011-10-10 19:06:283683void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273684 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293685}
3686
[email protected]310ebd6302011-10-10 19:06:283687void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593688 webkit_preferences_ = prefs;
3689 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293690}
3691
[email protected]310ebd6302011-10-10 19:06:283692void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:293693 alternate_error_page_url_ = url;
3694}
3695
[email protected]310ebd6302011-10-10 19:06:283696void RenderViewImpl::OnCustomContextMenuAction(
[email protected]b29aa74b2011-01-31 21:41:083697 const webkit_glue::CustomContextMenuContext& custom_context,
3698 unsigned action) {
3699 if (custom_context.is_pepper_menu)
3700 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3701 else
3702 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:583703 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3704 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:333705}
3706
[email protected]310ebd6302011-10-10 19:06:283707void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:513708 int id,
3709 const std::vector<FilePath>& paths) {
3710 if (!enumeration_completions_[id])
3711 return;
3712
3713 WebVector<WebString> ws_file_names(paths.size());
3714 for (size_t i = 0; i < paths.size(); ++i)
3715 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3716
3717 enumeration_completions_[id]->didChooseFile(ws_file_names);
3718 enumeration_completions_.erase(id);
3719}
3720
[email protected]310ebd6302011-10-10 19:06:283721void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363722 // This could happen if we navigated to a different page before the user
3723 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473724 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363725 return;
3726
[email protected]cdaf8d02010-03-30 19:52:473727 WebVector<WebString> ws_file_names(paths.size());
3728 for (size_t i = 0; i < paths.size(); ++i)
3729 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463730
[email protected]cdaf8d02010-03-30 19:52:473731 if (file_chooser_completions_.front()->completion)
3732 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3733 file_chooser_completions_.pop_front();
3734
3735 // If there are more pending file chooser requests, schedule one now.
3736 if (!file_chooser_completions_.empty()) {
3737 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3738 file_chooser_completions_.front()->params));
3739 }
initial.commit09911bf2008-07-26 23:55:293740}
3741
[email protected]310ebd6302011-10-10 19:06:283742void RenderViewImpl::OnEnablePreferredSizeChangedMode(int flags) {
[email protected]770dd8b2010-05-24 18:11:393743 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243744 if (send_preferred_size_changes_)
3745 return;
[email protected]9fb325e2010-05-06 18:23:243746 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393747
[email protected]d812fd12011-05-27 23:05:073748 // Start off with an initial preferred size notification (in case
3749 // |didUpdateLayout| was already called).
3750 if (webview())
3751 didUpdateLayout(webview()->mainFrame());
[email protected]0666aef2009-05-13 19:48:083752}
3753
[email protected]310ebd6302011-10-10 19:06:283754void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:103755 const gfx::Size& disable_scrollbar_size_limit) {
3756 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3757}
3758
[email protected]310ebd6302011-10-10 19:06:283759void RenderViewImpl::OnSetRendererPrefs(
3760 const RendererPreferences& renderer_prefs) {
[email protected]80d96fa2009-06-10 22:34:513761 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373762 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133763#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413764 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3765 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463766 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513767 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343768 renderer_prefs.thumb_inactive_color,
3769 renderer_prefs.thumb_active_color,
3770 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323771
[email protected]644d77e2010-01-27 01:03:103772 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323773 webview()->setScrollbarColors(
3774 renderer_prefs.thumb_inactive_color,
3775 renderer_prefs.thumb_active_color,
3776 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103777 webview()->setSelectionColors(
3778 renderer_prefs.active_selection_bg_color,
3779 renderer_prefs.active_selection_fg_color,
3780 renderer_prefs.inactive_selection_bg_color,
3781 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463782 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103783 }
[email protected]7a74e102009-09-03 00:16:563784#endif
[email protected]80d96fa2009-06-10 22:34:513785}
3786
[email protected]310ebd6302011-10-10 19:06:283787void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
3788 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:283789 if (webview())
3790 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563791}
3792
[email protected]310ebd6302011-10-10 19:06:283793void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:193794 const GURL& page_url) {
3795 // Prepare list to storage all savable resource links.
3796 std::vector<GURL> resources_list;
3797 std::vector<GURL> referrers_list;
3798 std::vector<GURL> frames_list;
3799 webkit_glue::SavableResourcesResult result(&resources_list,
3800 &referrers_list,
3801 &frames_list);
3802
3803 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3804 webview(),
3805 page_url,
3806 &result,
[email protected]2a80aee2011-10-07 16:06:033807 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:193808 // If something is wrong when collecting all savable resource links,
3809 // send empty list to embedder(browser) to tell it failed.
3810 referrers_list.clear();
3811 resources_list.clear();
3812 frames_list.clear();
3813 }
3814
3815 // Send result of all savable resource links to embedder.
3816 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3817 resources_list,
3818 referrers_list,
3819 frames_list));
3820}
3821
[email protected]310ebd6302011-10-10 19:06:283822void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:193823 const std::vector<GURL>& links,
3824 const std::vector<FilePath>& local_paths,
3825 const FilePath& local_directory_name) {
3826
3827 // Convert std::vector of GURLs to WebVector<WebURL>
3828 WebVector<WebURL> weburl_links(links);
3829
3830 // Convert std::vector of std::strings to WebVector<WebString>
3831 WebVector<WebString> webstring_paths(local_paths.size());
3832 for (size_t i = 0; i < local_paths.size(); i++)
3833 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3834
3835 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
3836 webstring_paths,
3837 webkit_glue::FilePathToWebString(
3838 local_directory_name));
3839}
3840
[email protected]310ebd6302011-10-10 19:06:283841void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273842 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473843 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293844}
3845
[email protected]310ebd6302011-10-10 19:06:283846void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]992db4c2011-05-12 15:37:153847 if (is_swapped_out_)
3848 return;
3849
3850 // Swap this RenderView out so the tab can navigate to a page rendered by a
3851 // different process. This involves running the unload handler and clearing
3852 // the page. Once WasSwappedOut is called, we also allow this process to exit
3853 // if there are no other active RenderViews in it.
3854
3855 // Send an UpdateState message before we get swapped out.
3856 SyncNavigationState();
3857
3858 // Synchronously run the unload handler before sending the ACK.
3859 webview()->dispatchUnloadEvent();
3860
3861 // Swap out and stop sending any IPC messages that are not ACKs.
3862 SetSwappedOut(true);
3863
3864 // Replace the page with a blank dummy URL. The unload handler will not be
3865 // run a second time, thanks to a check in FrameLoader::stopLoading.
3866 // TODO(creis): Need to add a better way to do this that avoids running the
3867 // beforeunload handler. For now, we just run it a second time silently.
3868 webview()->mainFrame()->loadHTMLString(std::string(),
3869 GURL("about:swappedout"),
3870 GURL("about:swappedout"),
3871 false);
3872
3873 // Just echo back the params in the ACK.
3874 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3875}
3876
[email protected]310ebd6302011-10-10 19:06:283877void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:373878 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:293879 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3880 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3881 // in the onunload handler from appearing. For now, we're bypassing that and
3882 // calling the FrameLoader's CloseURL method directly. This should be
3883 // revisited to avoid having two ways to close a page. Having a single way
3884 // to close that can run onunload is also useful for fixing
3885 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273886 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293887
[email protected]992db4c2011-05-12 15:37:153888 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293889}
3890
[email protected]310ebd6302011-10-10 19:06:283891void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:023892#if defined(USE_AURA)
3893 // Aura doesn't care if we switch themes.
3894#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163895 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463896 if (webview())
3897 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573898#else // defined(OS_WIN)
3899 // TODO(port): we don't support theming on non-Windows platforms yet
3900 NOTIMPLEMENTED();
3901#endif
initial.commit09911bf2008-07-26 23:55:293902}
3903
[email protected]310ebd6302011-10-10 19:06:283904void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:083905 if (decrement_shared_popup_at_destruction_)
3906 shared_popup_counter_->data--;
3907 shared_popup_counter_ = new SharedRenderViewCounter(0);
3908 decrement_shared_popup_at_destruction_ = false;
3909}
3910
[email protected]310ebd6302011-10-10 19:06:283911bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
3912 const WebURLError& error,
3913 bool replace) {
[email protected]15d79e12009-08-02 19:23:453914 // We only show alternate error pages in the main frame. They are
3915 // intended to assist the user when navigating, so there is not much
3916 // value in showing them for failed subframes. Ideally, we would be
3917 // able to use the TYPED transition type for this, but that flag is
3918 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453919 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453920 return false;
3921
3922 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373923 // connection failure.
[email protected]15d79e12009-08-02 19:23:453924 int ec = error.reason;
3925 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3926 ec != net::ERR_CONNECTION_FAILED &&
3927 ec != net::ERR_CONNECTION_REFUSED &&
3928 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373929 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453930 return false;
3931
3932 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553933 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453934 if (!error_page_url.is_valid())
3935 return false;
3936
3937 // Load an empty page first so there is an immediate response to the error,
3938 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453939 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363940 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453941 error.unreachableURL,
3942 replace);
3943
3944 // Now, create a fetcher for the error page and associate it with the data
3945 // source we just created via the LoadHTMLString call. That way if another
3946 // navigation occurs, the fetcher will get destroyed.
3947 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453948 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453949 navigation_state->set_alt_error_page_fetcher(
3950 new AltErrorPageResourceFetcher(
3951 error_page_url, frame, error,
[email protected]310ebd6302011-10-10 19:06:283952 NewCallback(this, &RenderViewImpl::AltErrorPageFinished)));
[email protected]15d79e12009-08-02 19:23:453953 return true;
3954}
3955
[email protected]310ebd6302011-10-10 19:06:283956void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
3957 const WebURLError& original_error,
3958 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:453959 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093960 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553961 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093962 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453963}
3964
[email protected]310ebd6302011-10-10 19:06:283965void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:003966 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473967 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003968}
3969
[email protected]310ebd6302011-10-10 19:06:283970void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:093971 const gfx::Rect& resizer_rect,
3972 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:103973 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473974 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103975 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203976 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:313977 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103978 }
[email protected]dd6afca2011-08-13 03:44:313979 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:103980 }
3981
[email protected]ee41e7d22011-10-14 19:34:093982 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:003983}
[email protected]0aa477bd2009-03-23 22:21:433984
[email protected]310ebd6302011-10-10 19:06:283985void RenderViewImpl::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013986 // Notify the pepper plugins that we started painting.
3987 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283988}
3989
[email protected]310ebd6302011-10-10 19:06:283990void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:283991 // Notify any pepper plugins that we painted. This will call into the plugin,
3992 // and we it may ask to close itself as a result. This will, in turn, modify
3993 // our set, possibly invalidating the iterator. So we iterate on a copy that
3994 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013995 pepper_delegate_.ViewFlushedPaint();
3996
[email protected]00c39612010-03-06 02:53:283997 WebFrame* main_frame = webview()->mainFrame();
3998
3999 // If we have a provisional frame we are between the start and commit stages
4000 // of loading and we don't want to save stats.
4001 if (!main_frame->provisionalDataSource()) {
4002 WebDataSource* ds = main_frame->dataSource();
4003 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
4004 DCHECK(navigation_state);
4005
[email protected]05c8e502010-08-15 15:13:524006 // TODO(jar): The following code should all be inside a method, probably in
4007 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284008 Time now = Time::Now();
4009 if (navigation_state->first_paint_time().is_null()) {
4010 navigation_state->set_first_paint_time(now);
4011 }
4012 if (navigation_state->first_paint_after_load_time().is_null() &&
4013 !navigation_state->finish_load_time().is_null()) {
4014 navigation_state->set_first_paint_after_load_time(now);
4015 }
4016 }
4017}
4018
[email protected]310ebd6302011-10-10 19:06:284019void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084020 RenderWidget::OnSwapBuffersPosted();
4021}
4022
[email protected]310ebd6302011-10-10 19:06:284023void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244024 RenderWidget::OnSwapBuffersComplete();
4025}
4026
[email protected]310ebd6302011-10-10 19:06:284027void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244028 RenderWidget::OnSwapBuffersAborted();
4029}
4030
[email protected]310ebd6302011-10-10 19:06:284031webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154032 const gfx::Rect& paint_bounds,
4033 TransportDIB** dib,
4034 gfx::Rect* location,
4035 gfx::Rect* clip) {
4036 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4037 paint_bounds, dib, location, clip);
4038}
4039
[email protected]310ebd6302011-10-10 19:06:284040gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074041 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434042 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524043}
4044
[email protected]310ebd6302011-10-10 19:06:284045void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164046 if (webview())
[email protected]26aa0482009-09-30 16:55:274047 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164048}
4049
[email protected]310ebd6302011-10-10 19:06:284050void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144051 if (webview())
[email protected]b4bb2502009-10-01 22:35:274052 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144053
4054 SetBackground(background);
4055}
4056
[email protected]310ebd6302011-10-10 19:06:284057void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344058 if (webview())
[email protected]b4bb2502009-10-01 22:35:274059 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264060
4061#if defined(OS_MACOSX)
4062 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4063 for (plugin_it = plugin_delegates_.begin();
4064 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4065 (*plugin_it)->SetWindowFocus(active);
4066 }
4067#endif
[email protected]8c66c5a2009-07-22 17:26:344068}
4069
[email protected]6ce7abc52010-02-02 18:40:144070#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284071void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144072 // Inform plugins that their container has changed visibility.
4073 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4074 for (plugin_it = plugin_delegates_.begin();
4075 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4076 (*plugin_it)->SetContainerVisibility(visible);
4077 }
4078}
[email protected]1e6e3c992010-02-08 15:52:134079
[email protected]310ebd6302011-10-10 19:06:284080void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4081 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134082 // Inform plugins that their window's frame has changed.
4083 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4084 for (plugin_it = plugin_delegates_.begin();
4085 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4086 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4087 }
4088}
[email protected]935d63d2010-10-15 23:31:554089
[email protected]310ebd6302011-10-10 19:06:284090void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4091 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134092 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554093 // applies to it or not, so inform all the delegates.
4094 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4095 for (plugin_it = plugin_delegates_.begin();
4096 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134097 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554098 }
4099}
[email protected]6ce7abc52010-02-02 18:40:144100#endif // OS_MACOSX
4101
[email protected]310ebd6302011-10-10 19:06:284102void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484103 const EditCommands& edit_commands) {
4104 edit_commands_ = edit_commands;
4105}
4106
[email protected]310ebd6302011-10-10 19:06:284107void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594108 // We need to grab a pointer to the doomed WebView before we destroy it.
4109 WebView* doomed = webview();
4110 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494111 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594112}
4113
[email protected]310ebd6302011-10-10 19:06:284114void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484115 edit_commands_.clear();
4116}
4117
[email protected]310ebd6302011-10-10 19:06:284118bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]b993705a2011-10-09 23:00:244119 return pepper_delegate_.HandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374120}
4121
[email protected]310ebd6302011-10-10 19:06:284122void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514123 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064124}
4125
[email protected]310ebd6302011-10-10 19:06:284126void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244127 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4128}
4129
[email protected]310ebd6302011-10-10 19:06:284130void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434131 RenderWidget::OnWasHidden();
4132
[email protected]a6939ca42011-02-18 17:58:074133 if (webview()) {
4134 webview()->settings()->setMinimumTimerInterval(
4135 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444136 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074137 }
4138
4139#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434140 // Inform plugins that their container is no longer visible.
4141 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4142 for (plugin_it = plugin_delegates_.begin();
4143 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4144 (*plugin_it)->SetContainerVisibility(false);
4145 }
[email protected]a6939ca42011-02-18 17:58:074146#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434147}
4148
[email protected]310ebd6302011-10-10 19:06:284149void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434150 RenderWidget::OnWasRestored(needs_repainting);
4151
[email protected]a6939ca42011-02-18 17:58:074152 if (webview()) {
4153 webview()->settings()->setMinimumTimerInterval(
4154 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444155 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074156 }
4157
4158#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434159 // Inform plugins that their container is now visible.
4160 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4161 for (plugin_it = plugin_delegates_.begin();
4162 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4163 (*plugin_it)->SetContainerVisibility(true);
4164 }
[email protected]784ea1ab2010-09-18 00:02:344165#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074166}
[email protected]1e6e3c992010-02-08 15:52:134167
[email protected]310ebd6302011-10-10 19:06:284168bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384169 if (WebWidgetHandlesCompositorScheduling())
4170 return false;
4171
[email protected]65225772011-05-12 21:10:244172 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4173 if (!context)
4174 return false;
4175 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4176 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4177 std::string::npos;
4178}
4179
[email protected]310ebd6302011-10-10 19:06:284180void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134181 RenderWidget::OnSetFocus(enable);
4182
[email protected]7d3c02c2010-05-05 23:10:314183 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074184 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134185 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4186 for (plugin_it = plugin_delegates_.begin();
4187 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344188#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314189 // RenderWidget's call to setFocus can cause the underlying webview's
4190 // activation state to change just like a call to setIsActive.
4191 if (enable)
4192 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344193#endif
[email protected]7d3c02c2010-05-05 23:10:314194 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134195 }
[email protected]589621b2010-09-23 22:01:074196
4197 // Notify all Pepper plugins.
4198 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134199 }
4200}
[email protected]941e4552010-02-01 21:23:434201
[email protected]310ebd6302011-10-10 19:06:284202void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004203 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504204 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574205}
4206
[email protected]73bf95812011-10-12 11:38:324207void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004208 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324209}
4210
[email protected]3f783362011-10-21 22:40:504211void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4212 UpdateSelectionBounds();
4213}
4214
[email protected]73bf95812011-10-12 11:38:324215void RenderViewImpl::PpapiPluginCancelComposition() {
4216 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4217 ui::Range range(ui::Range::InvalidRange());
4218 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4219}
4220
[email protected]310ebd6302011-10-10 19:06:284221void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574222 const string16& text,
4223 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4224 int selection_start,
4225 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324226 if (pepper_delegate_.IsPluginFocused()) {
4227 // When a PPAPI plugin has focus, we bypass WebKit.
4228 pepper_delegate_.OnImeSetComposition(text,
4229 underlines,
4230 selection_start,
4231 selection_end);
4232 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234233#if defined(OS_WIN)
4234 // When a plug-in has focus, we create platform-specific IME data used by
4235 // our IME emulator and send it directly to the focused plug-in, i.e. we
4236 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4237 // instance ID is the same one as the specified ID.)
4238 if (focused_plugin_id_ >= 0) {
4239 std::vector<int> clauses;
4240 std::vector<int> target;
4241 for (size_t i = 0; i < underlines.size(); ++i) {
4242 clauses.push_back(underlines[i].startOffset);
4243 clauses.push_back(underlines[i].endOffset);
4244 if (underlines[i].thick) {
4245 target.clear();
4246 target.push_back(underlines[i].startOffset);
4247 target.push_back(underlines[i].endOffset);
4248 }
4249 }
4250 std::set<WebPluginDelegateProxy*>::iterator it;
4251 for (it = plugin_delegates_.begin();
4252 it != plugin_delegates_.end(); ++it) {
4253 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4254 focused_plugin_id_);
4255 }
4256 return;
4257 }
4258#endif
[email protected]56ea1a62011-05-30 07:05:574259 RenderWidget::OnImeSetComposition(text,
4260 underlines,
4261 selection_start,
4262 selection_end);
4263 }
4264}
4265
[email protected]4de6d1692011-10-12 08:45:444266void RenderViewImpl::OnImeConfirmComposition(
4267 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574268 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324269 // When a PPAPI plugin has focus, we bypass WebKit.
4270 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574271 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234272#if defined(OS_WIN)
4273 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4274 // plug-ins. When we send IME text directly to plug-ins, we should not send
4275 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444276 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234277 if (focused_plugin_id_ >= 0) {
4278 std::set<WebPluginDelegateProxy*>::iterator it;
4279 for (it = plugin_delegates_.begin();
4280 it != plugin_delegates_.end(); ++it) {
4281 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4282 }
4283 return;
4284 }
4285#endif
[email protected]ebd28ac2011-10-13 18:49:054286 if (replacement_range.IsValid() && webview()) {
4287 // Select the text in |replacement_range|, it will then be replaced by
4288 // text added by the call to RenderWidget::OnImeConfirmComposition().
4289 if (WebFrame* frame = webview()->focusedFrame()) {
4290 frame->setSelectionToRange(
4291 WebRange::fromDocumentRange(frame,
4292 replacement_range.start(),
4293 replacement_range.length()));
4294 }
4295 }
[email protected]4de6d1692011-10-12 08:45:444296 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574297 }
4298}
4299
[email protected]310ebd6302011-10-10 19:06:284300ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324301 return pepper_delegate_.IsPluginFocused() ?
4302 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4303}
4304
[email protected]3f783362011-10-21 22:40:504305void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4306 if (pepper_delegate_.IsPluginFocused()) {
4307 // TODO(kinaba) http://crbug.com/101101
4308 // Current Pepper IME API does not handle selection bounds. So we simply
4309 // use the caret position as an empty range for now. It will be updated
4310 // after Pepper API equips features related to surrounding text retrieval.
4311 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4312 *start = caret;
4313 *end = caret;
4314 return;
4315 }
4316 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454317}
4318
[email protected]310ebd6302011-10-10 19:06:284319bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324320 return pepper_delegate_.IsPluginFocused() ?
4321 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574322}
4323
[email protected]e6ae0f6c2011-10-04 10:39:234324#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284325void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234326 if (focused)
4327 focused_plugin_id_ = plugin_id;
4328 else
4329 focused_plugin_id_ = -1;
4330}
4331#endif
4332
[email protected]43f28f832010-02-03 02:28:484333#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284334void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134335 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4336 focused, plugin_id);
4337 Send(msg);
4338}
4339
[email protected]310ebd6302011-10-10 19:06:284340void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134341 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554342 // This message can be sent during event-handling, and needs to be delivered
4343 // within that context.
4344 msg->set_unblock(true);
4345 Send(msg);
4346}
4347
[email protected]310ebd6302011-10-10 19:06:284348gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234349 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484350 gfx::PluginWindowHandle window = NULL;
4351 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234352 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114353 if (window) {
4354 fake_plugin_window_handles_.insert(window);
4355 }
[email protected]43f28f832010-02-03 02:28:484356 return window;
4357}
4358
[email protected]310ebd6302011-10-10 19:06:284359void RenderViewImpl::DestroyFakePluginWindowHandle(
4360 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114361 if (window && fake_plugin_window_handles_.find(window) !=
4362 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484363 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114364 fake_plugin_window_handles_.erase(window);
4365 }
[email protected]43f28f832010-02-03 02:28:484366}
4367
[email protected]310ebd6302011-10-10 19:06:284368void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4369 gfx::PluginWindowHandle window,
4370 int32 width,
4371 int32 height,
4372 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334373 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484374 routing_id(), window, width, height, io_surface_identifier));
4375}
4376
[email protected]310ebd6302011-10-10 19:06:284377void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334378 gfx::PluginWindowHandle window,
4379 int32 width,
4380 int32 height,
4381 TransportDIB::Handle transport_dib) {
4382 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074383 routing_id(), window, width, height, transport_dib));
4384}
4385
[email protected]310ebd6302011-10-10 19:06:284386TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334387 size_t size) {
[email protected]1aef98132010-02-23 18:00:074388 TransportDIB::Handle dib_handle;
4389 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384390 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074391 return dib_handle;
4392 // Return an invalid handle if Send() fails.
4393 return TransportDIB::DefaultHandleValue();
4394}
4395
[email protected]310ebd6302011-10-10 19:06:284396void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4397 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074398 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4399}
4400
[email protected]310ebd6302011-10-10 19:06:284401void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144402 gfx::PluginWindowHandle window, uint64 surface_id) {
4403 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4404 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484405}
4406#endif
[email protected]58c321d2010-02-19 12:11:284407
[email protected]310ebd6302011-10-10 19:06:284408bool RenderViewImpl::ScheduleFileChooser(
[email protected]cdaf8d02010-03-30 19:52:474409 const ViewHostMsg_RunFileChooser_Params& params,
4410 WebFileChooserCompletion* completion) {
4411 static const size_t kMaximumPendingFileChooseRequests = 4;
4412 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4413 // This sanity check prevents too many file choose requests from getting
4414 // queued which could DoS the user. Getting these is most likely a
4415 // programming error (there are many ways to DoS the user so it's not
4416 // considered a "real" security check), either in JS requesting many file
4417 // choosers to pop up, or in a plugin.
4418 //
4419 // TODO(brettw) we might possibly want to require a user gesture to open
4420 // a file picker, which will address this issue in a better way.
4421 return false;
4422 }
4423
4424 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4425 new PendingFileChooser(params, completion)));
4426 if (file_chooser_completions_.size() == 1) {
4427 // Actually show the browse dialog when this is the first request.
4428 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4429 }
4430 return true;
4431}
4432
[email protected]310ebd6302011-10-10 19:06:284433WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514434 if (!geolocation_dispatcher_)
4435 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4436 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254437}
[email protected]61c9f032010-03-31 23:04:194438
[email protected]310ebd6302011-10-10 19:06:284439WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114440 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224441#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514442 if (!speech_input_dispatcher_)
4443 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224444#endif
[email protected]676126f72011-01-15 00:03:514445 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114446}
4447
[email protected]310ebd6302011-10-10 19:06:284448WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514449 if (!device_orientation_dispatcher_)
4450 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4451 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534452}
4453
[email protected]310ebd6302011-10-10 19:06:284454void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4455 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254456 // For now, don't remember plugin zoom values. We don't want to mix them with
4457 // normal web content (i.e. a fixed layout plugin would usually want them
4458 // different).
4459 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4460
[email protected]b75b8292010-10-01 07:28:254461 int minimum_percent = static_cast<int>(
4462 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4463 int maximum_percent = static_cast<int>(
4464 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254465
4466 Send(new ViewHostMsg_UpdateZoomLimits(
4467 routing_id_, minimum_percent, maximum_percent, remember));
4468}
4469
[email protected]310ebd6302011-10-10 19:06:284470void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254471 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084472#if defined(TOUCH_UI)
4473 float zoom_level =
4474 WebView::zoomFactorToZoomLevel(webview()->pageScaleFactor());
4475#else
4476 float zoom_level = webview()->zoomLevel();
4477#endif
[email protected]b75b8292010-10-01 07:28:254478 // Tell the browser which url got zoomed so it can update the menu and the
4479 // saved values if necessary
4480 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084481 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414482 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254483}
4484
[email protected]310ebd6302011-10-10 19:06:284485void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4486 const WebString& base_url,
4487 const WebString& url,
4488 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484489 GURL base(base_url);
4490 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4491 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4492 return;
4493 }
[email protected]f1a29a02011-10-06 23:08:444494 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4495 UTF16ToUTF8(scheme),
4496 absolute_url,
4497 title));
[email protected]a6d36cc2011-02-23 00:39:484498}
4499
[email protected]310ebd6302011-10-10 19:06:284500void RenderViewImpl::registerIntentHandler(const WebString& action,
4501 const WebString& type,
4502 const WebString& href,
4503 const WebString& title) {
[email protected]f1a29a02011-10-06 23:08:444504 Send(new ViewHostMsg_RegisterIntentHandler(routing_id_,
4505 action,
4506 type,
4507 href,
4508 title));
[email protected]62af76e2011-08-01 02:34:014509}
4510
[email protected]310ebd6302011-10-10 19:06:284511WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444512 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4513 WebKit::WebPageVisibilityStateHidden :
4514 WebKit::WebPageVisibilityStateVisible;
4515 WebKit::WebPageVisibilityState override_state = current_state;
4516 if (content::GetContentClient()->renderer()->
4517 ShouldOverridePageVisibilityState(this,
4518 &override_state))
4519 return override_state;
4520 return current_state;
[email protected]94dec932011-05-26 20:04:214521}
4522
[email protected]310ebd6302011-10-10 19:06:284523void RenderViewImpl::startActivity(const WebKit::WebString& action,
4524 const WebKit::WebString& type,
4525 const WebKit::WebString& data,
4526 int intent_id) {
[email protected]ce9751942011-09-21 01:57:244527 webkit_glue::WebIntentData intent_data;
4528 intent_data.action = action;
4529 intent_data.type = type;
4530 intent_data.data = data;
4531 Send(new IntentsHostMsg_WebIntentDispatch(
4532 routing_id_, intent_data, intent_id));
[email protected]e235c7d02011-08-18 22:38:434533}
4534
[email protected]310ebd6302011-10-10 19:06:284535bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194536 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454537 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194538 if (frame->parent() != NULL)
4539 return false;
4540
[email protected]f0a3d0b2010-08-06 22:51:534541 // Navigations initiated within Webkit are not sent out to the external host
4542 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274543 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134544 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534545 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134546 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334547 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534548 return false;
4549
[email protected]2fc22d12010-12-02 23:08:164550 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324551 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014552 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164553 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014554 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324555 // The opener relationship between the new window and the parent allows the
4556 // new window to script the parent and vice versa. This is not allowed if
4557 // the origins of the two domains are different. This can be treated as a
4558 // top level navigation and routed back to the host.
4559 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274560 if (!opener) {
[email protected]86965362011-04-21 18:42:514561 return true;
[email protected]d19ea342011-04-20 20:31:134562 } else {
[email protected]b6cb3a842011-06-24 18:28:414563 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324564 return true;
4565 }
4566 }
[email protected]61c9f032010-03-31 23:04:194567 return false;
4568}
[email protected]2b06a992010-08-21 05:48:224569
[email protected]310ebd6302011-10-10 19:06:284570void RenderViewImpl::OnAsyncFileOpened(
4571 base::PlatformFileError error_code,
4572 IPC::PlatformFileForTransit file_for_transit,
4573 int message_id) {
[email protected]27a9ef32010-09-10 04:06:244574 pepper_delegate_.OnAsyncFileOpened(
4575 error_code,
4576 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4577 message_id);
4578}
[email protected]caf706f2010-10-26 17:54:084579
[email protected]310ebd6302011-10-10 19:06:284580void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:474581 int request_id,
4582 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434583 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474584 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4585 broker_process_handle,
4586 handle);
[email protected]eb415bf0e2011-04-14 02:45:424587}
4588
[email protected]caf706f2010-10-26 17:54:084589#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284590void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154591 if (external_popup_menu_ == NULL) {
4592 // Crash reports from the field indicate that we can be notified with a
4593 // NULL external popup menu (we probably get notified twice).
4594 // If you hit this please file a bug against jcivelli and include the page
4595 // and steps to repro.
4596 NOTREACHED();
4597 return;
4598 }
[email protected]caf706f2010-10-26 17:54:084599 external_popup_menu_->DidSelectItem(selected_index);
4600 external_popup_menu_.reset();
4601}
4602#endif
[email protected]bb461532010-11-26 21:50:234603
[email protected]1b4209f2011-01-07 00:25:404604#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:284605void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:404606 int request_id,
4607 IPC::PlatformFileForTransit socket_for_transit,
4608 const PP_Flash_NetAddress& local_addr,
4609 const PP_Flash_NetAddress& remote_addr) {
4610 pepper_delegate_.OnConnectTcpACK(
4611 request_id,
4612 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4613 local_addr,
4614 remote_addr);
4615}
4616#endif
[email protected]a6097f42011-01-10 08:50:514617
[email protected]310ebd6302011-10-10 19:06:284618void RenderViewImpl::OnContextMenuClosed(
[email protected]b29aa74b2011-01-31 21:41:084619 const webkit_glue::CustomContextMenuContext& custom_context) {
4620 if (custom_context.is_pepper_menu)
4621 pepper_delegate_.OnContextMenuClosed(custom_context);
4622 else
4623 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104624}
[email protected]5a7b15a2011-08-22 22:48:184625
[email protected]310ebd6302011-10-10 19:06:284626void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:184627 if (!webview())
4628 return;
4629 WebFrame* main_frame = webview()->mainFrame();
4630 if (!main_frame)
4631 return;
4632 main_frame->enableViewSourceMode(true);
4633}
[email protected]67bfb83f2011-09-22 03:36:374634
[email protected]310ebd6302011-10-10 19:06:284635void RenderViewImpl::OnLockMouseACK(bool succeeded) {
[email protected]57e02be2011-10-11 19:00:534636 // Mouse Lock removes the system cursor and provides all mouse motion as
4637 // .movementX/Y values on events all sent to a fixed target. This requires
4638 // content to specifically request the mode to be entered.
4639 // Mouse Capture is implicitly given for the duration of a drag event, and
4640 // sends all mouse events to the initial target of the drag.
4641 // If Lock is entered it supercedes any in progress Capture.
4642 if (succeeded)
4643 OnMouseCaptureLost();
4644
[email protected]67bfb83f2011-09-22 03:36:374645 pepper_delegate_.OnLockMouseACK(succeeded);
4646}
4647
[email protected]310ebd6302011-10-10 19:06:284648void RenderViewImpl::OnMouseLockLost() {
[email protected]67bfb83f2011-09-22 03:36:374649 pepper_delegate_.OnMouseLockLost();
4650}
[email protected]c3d45532011-10-07 19:20:404651
[email protected]310ebd6302011-10-10 19:06:284652bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]c3d45532011-10-07 19:20:404653 return webview()->settings()->useThreadedCompositor();
4654}
[email protected]7f3c7af2011-10-20 22:52:514655
4656void RenderViewImpl::OnJavaBridgeInit(
4657 const IPC::ChannelHandle& channel_handle) {
4658 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:184659#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7f3c7af2011-10-20 22:52:514660 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this, channel_handle));
[email protected]464750f2011-10-24 23:16:184661#endif
[email protected]7f3c7af2011-10-20 22:52:514662}