blob: d5cedecc75361a1cc01d7992f845905efaf8d6a4 [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]6e24cf12011-03-18 19:57:025#include "content/renderer/render_view.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]b1cf3372011-04-20 21:28:1015#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4916#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2818#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5119#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2920#include "base/string_piece.h"
21#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2822#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2623#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2224#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1025#include "content/common/appcache/appcache_dispatcher.h"
[email protected]9966325b2011-04-18 05:00:1026#include "content/common/bindings_policy.h"
[email protected]127dd582011-03-16 21:32:1027#include "content/common/clipboard_messages.h"
[email protected]db803aae2011-03-05 02:00:4228#include "content/common/content_constants.h"
[email protected]9966325b2011-04-18 05:00:1029#include "content/common/content_switches.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]c3113022011-04-16 03:26:3034#include "content/common/json_value_serializer.h"
[email protected]7f070d42011-03-09 20:25:3235#include "content/common/notification_service.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]9966325b2011-04-18 05:00:1040#include "content/common/url_constants.h"
[email protected]778574e2011-03-21 22:03:5041#include "content/common/view_messages.h"
[email protected]21d61e52011-03-18 19:08:2542#include "content/renderer/content_renderer_client.h"
[email protected]82622452011-07-22 09:57:2043#include "content/renderer/devtools_agent.h"
[email protected]230b7ef2011-03-16 22:30:1944#include "content/renderer/device_orientation_dispatcher.h"
[email protected]8f6a3b852011-07-19 16:48:5645#include "content/renderer/mhtml_generator.h"
[email protected]55722152011-03-22 01:33:5346#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1947#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4048#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]921f1592011-03-18 00:41:0249#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0850#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3751#include "content/renderer/media/audio_renderer_impl.h"
[email protected]ab2c4732011-07-20 19:57:4052#include "content/renderer/media/media_stream_impl.h"
[email protected]921f1592011-03-18 00:41:0253#include "content/renderer/navigation_state.h"
[email protected]230b7ef2011-03-16 22:30:1954#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3755#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3556#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0557#include "content/renderer/render_process.h"
[email protected]10e6ab572011-04-14 23:42:0058#include "content/renderer/render_thread.h"
[email protected]60916042011-03-19 00:43:3659#include "content/renderer/render_view_observer.h"
60#include "content/renderer/render_view_visitor.h"
[email protected]2cff0052011-03-18 16:51:4461#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:0162#include "content/renderer/renderer_webapplicationcachehost_impl.h"
63#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1964#include "content/renderer/speech_input_dispatcher.h"
[email protected]b1cf3372011-04-20 21:28:1065#include "content/renderer/v8_value_converter.h"
[email protected]663bd9e2011-03-21 01:07:0166#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3567#include "content/renderer/webplugin_delegate_proxy.h"
68#include "content/renderer/websharedworker_proxy.h"
69#include "content/renderer/webworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4970#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4171#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2772#include "media/base/message_loop_factory_impl.h"
initial.commit09911bf2008-07-26 23:55:2973#include "net/base/escape.h"
74#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0475#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5776#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3777#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
78#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
79#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
80#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3781#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
82#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
83#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
84#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3785#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
86#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
87#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
88#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
89#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
90#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
91#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
92#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
93#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:5794#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]69f110d62011-03-17 19:01:1495#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:3796#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:1997#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:3798#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
99#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
100#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
101#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
102#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
103#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
104#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
105#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17108#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37109#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
111#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40112#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]8bd0fe62011-01-17 06:44:37113#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
114#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
115#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26121#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c4a9e932011-03-05 04:05:55122#include "ui/base/message_box_flags.h"
[email protected]08397d52011-02-05 01:53:38123#include "ui/gfx/native_widget_types.h"
124#include "ui/gfx/point.h"
125#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55126#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04127#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43128#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24129#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19130#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59131#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24132#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24133#include "webkit/glue/glue_serialize.h"
[email protected]85cc78c2010-05-04 18:30:09134#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26135#include "webkit/glue/password_form_dom_manager.h"
[email protected]418da612011-07-21 19:01:52136#include "webkit/glue/request_extra_data.h"
[email protected]7a4de7a62010-08-17 18:38:24137#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29138#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07139#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29140#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17141#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50142#include "webkit/plugins/npapi/default_plugin_shared.h"
143#include "webkit/plugins/npapi/plugin_list.h"
144#include "webkit/plugins/npapi/webplugin_delegate.h"
145#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
146#include "webkit/plugins/npapi/webplugin_impl.h"
147#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52148#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29149
[email protected]6c8afae52009-01-22 02:24:57150#if defined(OS_WIN)
151// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57152// * theming
[email protected]08397d52011-02-05 01:53:38153#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03154#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37155#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51156#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33157#elif defined(OS_MACOSX)
158#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57159#endif
160
[email protected]c7287a92009-11-04 20:06:15161using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42162using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08163using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21164using WebKit::WebApplicationCacheHost;
165using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26166using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41167using WebKit::WebColor;
168using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59169using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44170using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51171using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55172using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28173using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00174using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58175using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25176using WebKit::WebDragOperation;
177using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51178using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51179using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08180using WebKit::WebExternalPopupMenu;
181using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47182using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22183using WebKit::WebFileSystem;
184using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49185using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59186using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48187using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45188using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17189using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13190using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41191using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50192using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17193using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28194using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17195using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28196using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28197using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51198using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19199using WebKit::WebPageSerializer;
200using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17201using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40202using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49203using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09204using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52205using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59206using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51207using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52208using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40209using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35210using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29211using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17212using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59213using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42214using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02215using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34216using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40217using WebKit::WebStorageQuotaCallbacks;
218using WebKit::WebStorageQuotaError;
219using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28220using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51221using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52222using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28223using WebKit::WebURL;
224using WebKit::WebURLError;
225using WebKit::WebURLRequest;
226using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28227using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03228using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28229using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26230using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43231using WebKit::WebWorker;
232using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26233using appcache::WebApplicationCacheHostImpl;
234using base::Time;
235using base::TimeDelta;
236using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26237using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26238using webkit_glue::PasswordForm;
239using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23240using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26241using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33242
initial.commit09911bf2008-07-26 23:55:29243//-----------------------------------------------------------------------------
244
[email protected]3354d3e2010-06-10 19:53:02245typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49246static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02247
[email protected]882daa92009-11-05 16:31:31248// Time, in seconds, we delay before sending content state changes (such as form
249// state and scroll position) to the browser. We delay sending changes to avoid
250// spamming the browser.
251// To avoid having tab/session restore require sending a message to get the
252// current content state during tab closing we use a shorter timeout for the
253// foreground renderer. This means there is a small window of time from which
254// content state is modified and not sent to session restore, but this is
255// better than having to wake up all renderers during shutdown.
256static const int kDelaySecondsForContentStateSyncHidden = 5;
257static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29258
[email protected]0aa55312008-10-17 21:53:08259// The maximum number of popups that can be spawned from one page.
260static const int kMaximumNumberOfUnacknowledgedPopups = 25;
261
[email protected]6fdd4182010-10-14 23:59:26262static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35263
[email protected]726985e22009-06-18 21:09:28264static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
265 WebVector<WebURL> urls;
266 ds->redirectChain(urls);
267 result->reserve(urls.size());
268 for (size_t i = 0; i < urls.size(); ++i)
269 result->push_back(urls[i]);
270}
271
[email protected]54ec7f82010-10-21 22:32:51272static bool WebAccessibilityNotificationToViewHostMsg(
273 WebAccessibilityNotification notification,
[email protected]fffaf972011-03-24 01:34:35274 ViewHostMsg_AccessibilityNotification_Type::Value* type) {
[email protected]54ec7f82010-10-21 22:32:51275 switch (notification) {
276 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
[email protected]fffaf972011-03-24 01:34:35277 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51278 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
279 break;
280 case WebKit::WebAccessibilityNotificationChildrenChanged:
[email protected]fffaf972011-03-24 01:34:35281 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51282 NOTIFICATION_TYPE_CHILDREN_CHANGED;
283 break;
284 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
[email protected]fffaf972011-03-24 01:34:35285 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51286 NOTIFICATION_TYPE_FOCUS_CHANGED;
287 break;
288 case WebKit::WebAccessibilityNotificationLoadComplete:
[email protected]fffaf972011-03-24 01:34:35289 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51290 NOTIFICATION_TYPE_LOAD_COMPLETE;
291 break;
292 case WebKit::WebAccessibilityNotificationValueChanged:
[email protected]fffaf972011-03-24 01:34:35293 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51294 NOTIFICATION_TYPE_VALUE_CHANGED;
295 break;
296 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
[email protected]fffaf972011-03-24 01:34:35297 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51298 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
299 break;
300 default:
301 // TODO(ctguil): Support additional webkit notifications.
302 return false;
303 }
304 return true;
305}
306
[email protected]6a8f5112011-05-13 16:38:44307// If |data_source| is non-null and has a NavigationState associated with it,
308// the AltErrorPageResourceFetcher is reset.
309static void StopAltErrorPageFetcher(WebDataSource* data_source) {
310 if (data_source) {
311 NavigationState* state = NavigationState::FromDataSource(data_source);
312 if (state)
313 state->set_alt_error_page_fetcher(NULL);
314 }
315}
316
initial.commit09911bf2008-07-26 23:55:29317///////////////////////////////////////////////////////////////////////////////
318
[email protected]60c42a8c72009-10-09 04:08:59319int32 RenderView::next_page_id_ = 1;
320
[email protected]cdaf8d02010-03-30 19:52:47321struct RenderView::PendingFileChooser {
322 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
323 WebFileChooserCompletion* c)
324 : params(p),
325 completion(c) {
326 }
327 ViewHostMsg_RunFileChooser_Params params;
328 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
329};
330
[email protected]2fab253a2009-08-17 23:00:59331RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51332 gfx::NativeViewId parent_hwnd,
333 int32 opener_id,
334 const RendererPreferences& renderer_prefs,
335 const WebPreferences& webkit_prefs,
336 SharedRenderViewCounter* counter,
337 int32 routing_id,
338 int64 session_storage_namespace_id,
339 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12340 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51341 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02342 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09343 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02344 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24345 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21346 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02347 opened_by_user_gesture_(true),
348 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24349 page_id_(-1),
350 last_page_id_sent_to_browser_(-1),
[email protected]3cc72b12010-03-18 23:03:00351 history_list_offset_(-1),
352 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02353 target_url_status_(TARGET_NONE),
[email protected]18ca9a6b2010-06-02 19:05:18354 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]54ec7f82010-10-21 22:32:51355 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02356 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51357 geolocation_dispatcher_(NULL),
358 speech_input_dispatcher_(NULL),
359 device_orientation_dispatcher_(NULL),
[email protected]54ec7f82010-10-21 22:32:51360 accessibility_ack_pending_(false),
[email protected]cae8c8492011-03-03 11:12:18361 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41362 devtools_agent_(NULL),
[email protected]5ee0cfd02011-01-18 05:42:22363 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]676126f72011-01-15 00:03:51364 routing_id_ = routing_id;
365 if (opener_id != MSG_ROUTING_NONE)
366 opener_id_ = opener_id;
367
[email protected]11fee2332011-03-29 20:36:35368 webwidget_ = WebView::create(this);
369
[email protected]676126f72011-01-15 00:03:51370 if (counter) {
371 shared_popup_counter_ = counter;
372 shared_popup_counter_->data++;
373 decrement_shared_popup_at_destruction_ = true;
374 } else {
375 shared_popup_counter_ = new SharedRenderViewCounter(0);
376 decrement_shared_popup_at_destruction_ = false;
377 }
378
379 notification_provider_ = new NotificationProvider(this);
380
[email protected]676126f72011-01-15 00:03:51381 render_thread_->AddRoute(routing_id_, this);
382 // Take a reference on behalf of the RenderThread. This will be balanced
383 // when we receive ViewMsg_Close.
384 AddRef();
385
386 // If this is a popup, we must wait for the CreatingNew_ACK message before
387 // completing initialization. Otherwise, we can finish it now.
388 if (opener_id == MSG_ROUTING_NONE) {
389 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55390 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51391 }
392
[email protected]34c61bd52011-05-02 19:38:33393 g_view_map.Get().insert(std::make_pair(webview(), this));
394 webkit_preferences_.Apply(webview());
395 webview()->initializeMainFrame(this);
396 if (!frame_name.empty())
397 webview()->mainFrame()->setName(frame_name);
398 webview()->settings()->setMinimumTimerInterval(
399 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
400 webkit_glue::kForegroundTabTimerInterval);
401
402 OnSetRendererPrefs(renderer_prefs);
403
[email protected]676126f72011-01-15 00:03:51404 host_window_ = parent_hwnd;
405
406 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]676126f72011-01-15 00:03:51407 if (command_line.HasSwitch(switches::kEnableAccessibility))
408 WebAccessibilityCache::enableAccessibility();
409
[email protected]a026daa2011-04-20 15:49:51410#if defined(ENABLE_P2P_APIS)
[email protected]09b36762011-07-19 01:19:12411 p2p_socket_dispatcher_ = new P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51412#endif
[email protected]cae8c8492011-03-03 11:12:18413
[email protected]8f6a3b852011-07-19 16:48:56414 new MHTMLGenerator(this);
415
[email protected]c5c1d6d2011-07-28 18:42:41416 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20417
[email protected]ab2c4732011-07-20 19:57:40418 if (command_line.HasSwitch(switches::kEnableMediaStream)) {
419 media_stream_impl_ = new MediaStreamImpl(
420 RenderThread::current()->video_capture_impl_manager());
421 }
422
[email protected]e48869a2011-04-01 19:56:03423 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29424}
425
426RenderView::~RenderView() {
[email protected]d466b8a2011-07-15 21:48:03427 history_page_ids_.clear();
428
[email protected]0aa55312008-10-17 21:53:08429 if (decrement_shared_popup_at_destruction_)
430 shared_popup_counter_->data--;
431
[email protected]a1128322009-10-06 18:38:46432 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47433 while (!file_chooser_completions_.empty()) {
434 if (file_chooser_completions_.front()->completion) {
435 file_chooser_completions_.front()->completion->didChooseFile(
436 WebVector<WebString>());
437 }
438 file_chooser_completions_.pop_front();
439 }
[email protected]a1128322009-10-06 18:38:46440
[email protected]83dde542009-09-11 20:59:55441#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11442 // Destroy all fake plugin window handles on the browser side.
443 while (!fake_plugin_window_handles_.empty()) {
444 // Make sure no NULL plugin window handles were inserted into this list.
445 DCHECK(*fake_plugin_window_handles_.begin());
446 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
447 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
448 }
[email protected]83dde542009-09-11 20:59:55449#endif
[email protected]98324892009-09-09 21:16:05450
[email protected]60c42a8c72009-10-09 04:08:59451#ifndef NDEBUG
452 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49453 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59454 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
455 DCHECK_NE(this, it->second) << "Failed to call Close?";
456#endif
[email protected]676126f72011-01-15 00:03:51457
458 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
459 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59460}
461
462/*static*/
463void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49464 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59465 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
466 if (!visitor->Visit(it->second))
467 return;
468 }
469}
470
471/*static*/
472RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49473 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59474 ViewMap::iterator it = views->find(webview);
475 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29476}
477
478/*static*/
[email protected]0aa55312008-10-17 21:53:08479RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24480 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15481 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08482 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51483 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08484 const WebPreferences& webkit_prefs,
485 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34486 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26487 int64 session_storage_namespace_id,
488 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29489 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51490 return new RenderView(
491 render_thread,
492 parent_hwnd,
493 opener_id,
494 renderer_prefs,
495 webkit_prefs,
496 counter,
497 routing_id,
498 session_storage_namespace_id,
499 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29500}
501
[email protected]bb461532010-11-26 21:50:23502// static
initial.commit09911bf2008-07-26 23:55:29503void RenderView::SetNextPageID(int32 next_page_id) {
504 // This method should only be called during process startup, and the given
505 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05506 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29507 DCHECK(next_page_id >= next_page_id_);
508 next_page_id_ = next_page_id;
509}
510
[email protected]676126f72011-01-15 00:03:51511void RenderView::AddObserver(RenderViewObserver* observer) {
512 observers_.AddObserver(observer);
513}
514
515void RenderView::RemoveObserver(RenderViewObserver* observer) {
516 observer->set_render_view(NULL);
517 observers_.RemoveObserver(observer);
518}
519
[email protected]70eee342010-11-05 01:59:37520bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
521 typedef ViewHostMsg_AccessibilityNotification_Params params;
[email protected]a527a022011-02-10 02:32:36522 if (type == WebKit::WebAccessibilityNotificationChildrenChanged ||
523 type == WebKit::WebAccessibilityNotificationLoadComplete) {
[email protected]70eee342010-11-05 01:59:37524 return true;
525 }
526 return false;
527}
528
[email protected]8a3125a712010-08-09 18:58:51529WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26530 return static_cast<WebKit::WebView*>(webwidget());
531}
532
[email protected]1a3c3cb2010-12-16 21:03:40533void RenderView::SetReportLoadProgressEnabled(bool enabled) {
534 if (!enabled) {
535 load_progress_tracker_.reset(NULL);
536 return;
537 }
538 if (load_progress_tracker_ == NULL)
539 load_progress_tracker_.reset(new LoadProgressTracker(this));
540}
541
[email protected]a3a8fb6d2009-10-22 20:12:51542void RenderView::PluginCrashed(const FilePath& plugin_path) {
543 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29544}
545
[email protected]aad51d1c2010-08-05 08:38:09546WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
547 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50548 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26549 bool found;
[email protected]6fdd4182010-10-14 23:59:26550 std::string mime_type;
551 Send(new ViewHostMsg_GetPluginInfo(
[email protected]b6cb3a842011-06-24 18:28:41552 routing_id_, params.url, frame->top()->document().url(),
553 params.mimeType.utf8(), &found, &info, &mime_type));
[email protected]b83ff222011-01-24 17:37:12554 if (!found || !webkit::npapi::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09555 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45556
[email protected]96dcc1762011-04-04 16:01:09557 bool pepper_plugin_was_registered = false;
[email protected]0bd753682010-12-16 18:15:52558 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]96dcc1762011-04-04 16:01:09559 pepper_delegate_.CreatePepperPlugin(info.path,
560 &pepper_plugin_was_registered));
561 if (pepper_plugin_was_registered) {
562 if (pepper_module)
563 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
564 return NULL;
565 }
[email protected]1a78d9f32010-12-08 06:38:45566 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09567}
568
[email protected]d8fd6fa2010-02-01 15:54:26569void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
570 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30571 // If the renderer is visible, set initial visibility and focus state.
572 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34573#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30574 delegate->SetContainerVisibility(true);
575 if (webview() && webview()->isActive())
576 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34577#endif
[email protected]49232292010-09-03 19:07:30578 }
[email protected]784ea1ab2010-09-18 00:02:34579 // Plugins start assuming the content has focus (so that they work in
580 // environments where RenderView isn't hosting them), so we always have to
581 // set the initial state. See webplugin_delegate_impl.h for details.
582 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26583}
584
585void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
586 plugin_delegates_.erase(delegate);
587}
[email protected]d8fd6fa2010-02-01 15:54:26588
[email protected]a95986a82010-12-24 06:19:28589bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27590 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27591 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41592 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26593
[email protected]676126f72011-01-15 00:03:51594 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
595 RenderViewObserver* observer;
596 while ((observer = it.GetNext()) != NULL)
597 if (observer->OnMessageReceived(message))
598 return true;
[email protected]b2abac72009-02-26 12:39:28599
[email protected]a95986a82010-12-24 06:19:28600 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29601 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29602 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
603 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56604 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29605 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
606 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
607 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
608 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27609#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35610 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27611#endif
initial.commit09911bf2008-07-26 23:55:29612 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
613 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
614 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
615 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
616 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15617 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29618 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49619 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
620 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17621 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17622 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:54623 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
624 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29625 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18626 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
627 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29628 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48629 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29630 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55631 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
632 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
633 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
634 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
635 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
636 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
637 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45638 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40639 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29640 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:51641 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
642 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:29643 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
644 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
645 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
646 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]600ea402011-04-12 00:01:51647 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
648 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29649 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04650 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15651 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29652 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
653 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08654 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
655 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00656 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16657 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14658 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25659 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
660 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10661 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
662 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51663 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56664 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34665 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14666#if defined(OS_MACOSX)
667 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13668 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13669 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
670 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14671#endif
[email protected]446705872009-09-10 07:22:48672 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33673 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33674 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
675 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:14676 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:36677 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
678 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
679 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:42680 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
681 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:24682 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42683 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
684 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19685 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
686 OnGetAllSavableResourceLinksForCurrentPage)
687 IPC_MESSAGE_HANDLER(
688 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
689 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08690#if defined(OS_MACOSX)
691 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
692#endif
[email protected]521b2482011-01-15 00:10:10693 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51694 // TODO(viettrungluu): Move to a separate message filter.
695#if defined(ENABLE_FLAPPER_HACKS)
696 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
697#endif
[email protected]54ca3ca892011-06-07 21:14:54698#if defined(OS_MACOSX)
699 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
700#endif
[email protected]08bb1e722011-07-30 19:13:04701 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRemoteAccessClientFirewallTraversal,
702 OnUpdateRemoteAccessClientFirewallTraversal)
initial.commit09911bf2008-07-26 23:55:29703 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28704 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29705 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28706 return handled;
initial.commit09911bf2008-07-26 23:55:29707}
708
initial.commit09911bf2008-07-26 23:55:29709void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
710 if (!webview())
711 return;
712
[email protected]d466b8a2011-07-15 21:48:03713 bool is_reload =
714 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
715 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
716
717 // If this is a stale back/forward (due to a recent navigation the browser
718 // didn't know about), ignore it.
719 if (IsBackForwardToStaleEntry(params, is_reload))
720 return;
721
[email protected]992db4c2011-05-12 15:37:15722 // Swap this renderer back in if necessary.
723 if (is_swapped_out_)
724 SetSwappedOut(false);
725
[email protected]3cc72b12010-03-18 23:03:00726 history_list_offset_ = params.current_history_list_offset;
727 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03728 if (history_list_length_ >= 0)
729 history_page_ids_.resize(history_list_length_, -1);
730 if (params.pending_history_list_offset >= 0 &&
731 params.pending_history_list_offset < history_list_length_)
732 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00733
[email protected]38b592902011-04-16 02:08:42734 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29735
[email protected]26aa0482009-09-30 16:55:27736 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45737 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29738 // We cannot reload if we do not have any history state. This happens, for
739 // example, when recovering from a crash. Our workaround here is a bit of
740 // a hack since it means that reload after a crashed tab does not cause an
741 // end-to-end cache validation.
742 is_reload = false;
743 }
744
[email protected]77f17a82009-05-21 04:42:54745 // A navigation resulting from loading a javascript URL should not be treated
746 // as a browser initiated event. Instead, we want it to look as if the page
747 // initiated any load resulting from JS execution.
748 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30749 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00750 params.page_id,
751 params.pending_history_list_offset,
752 params.transition,
753 params.request_time);
[email protected]2c5569662011-03-22 20:45:02754 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30755 // We're doing a load of a page that was restored from the last session.
756 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
757 // which can result in stale data for pages that are set to expire. We
758 // explicitly override that by setting the policy here so that as
759 // necessary we load from the network.
760 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
761 }
762 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54763 }
initial.commit09911bf2008-07-26 23:55:29764
[email protected]a7ccc4d2010-01-27 08:14:48765 NavigationState* navigation_state = pending_navigation_state_.get();
766
[email protected]48a5c772011-04-18 23:50:50767 if (navigation_state) {
768 // New loads need to reset the error page fetcher. Otherwise if there is an
769 // outstanding error page fetcher it may complete and clobber the current
770 // page load.
771 navigation_state->set_alt_error_page_fetcher(NULL);
772 }
773
[email protected]04d3c6e2009-05-22 17:00:13774 // If we are reloading, then WebKit will use the history state of the current
775 // page, so we should just ignore any given history state. Otherwise, if we
776 // have history state, then we need to navigate to it, which corresponds to a
777 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55778 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48779 if (navigation_state)
780 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29781 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02782 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29783 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55784 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13785 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58786 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48787 if (navigation_state)
788 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45789 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17790 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13791 } else {
792 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28793 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29794
[email protected]e6f546c32009-07-01 17:12:55795 // A session history navigation should have been accompanied by state.
796 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13797
[email protected]dd7daa82009-08-10 05:46:45798 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55799 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13800
[email protected]726985e22009-06-18 21:09:28801 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17802 if (!WebSecurityPolicy::shouldHideReferrer(
803 params.url,
804 WebString::fromUTF8(params.referrer.spec()))) {
805 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
806 WebString::fromUTF8(params.referrer.spec()));
807 }
[email protected]726985e22009-06-18 21:09:28808 }
[email protected]04d3c6e2009-05-22 17:00:13809
[email protected]52c68652010-12-07 17:47:04810 if (!params.extra_headers.empty()) {
811 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
812 params.extra_headers.end(), "\n");
813 i.GetNext(); ) {
814 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
815 WebString::fromUTF8(i.values()));
816 }
817 }
818
[email protected]16e923d2011-04-30 00:41:44819 if (navigation_state)
820 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45821 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50822 }
823
[email protected]77f17a82009-05-21 04:42:54824 // In case LoadRequest failed before DidCreateDataSource was called.
825 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29826}
827
[email protected]d466b8a2011-07-15 21:48:03828bool RenderView::IsBackForwardToStaleEntry(
829 const ViewMsg_Navigate_Params& params,
830 bool is_reload) {
831 // Make sure this isn't a back/forward to an entry we have already cropped
832 // or replaced from our history, before the browser knew about it. If so,
833 // a new navigation has committed in the mean time, and we can ignore this.
834 bool is_back_forward = !is_reload && !params.state.empty();
835
836 // Note: if the history_list_length_ is 0 for a back/forward, we must be
837 // restoring from a previous session. We'll update our state in OnNavigate.
838 if (!is_back_forward || history_list_length_ <= 0)
839 return false;
840
841 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
842
843 // Check for whether the forward history has been cropped due to a recent
844 // navigation the browser didn't know about.
845 if (params.pending_history_list_offset >= history_list_length_)
846 return true;
847
848 // Check for whether this entry has been replaced with a new one.
849 int expected_page_id =
850 history_page_ids_[params.pending_history_list_offset];
851 if (expected_page_id > 0 && params.page_id != expected_page_id)
852 return true;
853
854 return false;
855}
856
initial.commit09911bf2008-07-26 23:55:29857// Stop loading the current page
858void RenderView::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44859 if (webview()) {
860 WebFrame* main_frame = webview()->mainFrame();
861 // Stop the alt error page fetcher. If we let it continue it may complete
862 // and cause RenderViewHostManager to swap to this RenderView, even though
863 // it may no longer be active.
864 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
865 StopAltErrorPageFetcher(main_frame->dataSource());
866 main_frame->stopLoading();
867 }
initial.commit09911bf2008-07-26 23:55:29868}
869
[email protected]ecbf10d2010-02-18 13:03:29870// Reload current focused frame.
871// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56872void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29873 if (webview() && webview()->focusedFrame()) {
874 // We always obey the cache (ignore_cache=false) here.
875 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
876 // a cache-ignoring reload of the frame.
877 webview()->focusedFrame()->reload(false);
878 }
[email protected]1dda4022010-01-28 18:24:56879}
880
initial.commit09911bf2008-07-26 23:55:29881void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27882 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29883}
884
[email protected]68b1e922009-06-23 16:00:25885void RenderView::OnExecuteEditCommand(const std::string& name,
886 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27887 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25888 return;
889
[email protected]26aa0482009-09-30 16:55:27890 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45891 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25892}
893
initial.commit09911bf2008-07-26 23:55:29894void RenderView::OnUpdateTargetURLAck() {
895 // Check if there is a targeturl waiting to be sent.
896 if (target_url_status_ == TARGET_PENDING) {
897 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
898 pending_target_url_));
899 }
900
901 target_url_status_ = TARGET_NONE;
902}
903
904void RenderView::OnUndo() {
905 if (!webview())
906 return;
907
[email protected]26aa0482009-09-30 16:55:27908 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29909}
910
911void RenderView::OnRedo() {
912 if (!webview())
913 return;
914
[email protected]26aa0482009-09-30 16:55:27915 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29916}
917
918void RenderView::OnCut() {
919 if (!webview())
920 return;
921
[email protected]26aa0482009-09-30 16:55:27922 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29923}
924
925void RenderView::OnCopy() {
926 if (!webview())
927 return;
928
[email protected]f6b1856b2011-06-29 22:02:53929 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
930 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29931}
932
[email protected]c0cc3092009-09-12 08:27:27933#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35934void RenderView::OnCopyToFindPboard() {
935 if (!webview())
936 return;
937
938 // Since the find pasteboard supports only plain text, this can be simpler
939 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27940 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35941 if (frame->hasSelection()) {
942 string16 selection = frame->selectionAsText();
943 RenderThread::current()->Send(
[email protected]7e3589742011-03-10 18:49:17944 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35945 }
[email protected]a954bf72009-09-12 07:30:35946}
[email protected]c0cc3092009-09-12 08:27:27947#endif
[email protected]a954bf72009-09-12 07:30:35948
initial.commit09911bf2008-07-26 23:55:29949void RenderView::OnPaste() {
950 if (!webview())
951 return;
952
[email protected]26aa0482009-09-30 16:55:27953 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29954}
955
[email protected]2a3a7762009-10-19 19:17:32956void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29957 if (!webview())
958 return;
959
[email protected]1ff7a032010-02-03 02:46:03960 WebFrame* frame = webview()->focusedFrame();
961 if (!frame->hasSelection())
962 frame->selectWordAroundCaret();
963 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29964}
965
966void RenderView::OnDelete() {
967 if (!webview())
968 return;
969
[email protected]26aa0482009-09-30 16:55:27970 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29971}
972
973void RenderView::OnSelectAll() {
974 if (!webview())
975 return;
976
[email protected]26aa0482009-09-30 16:55:27977 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22978 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29979}
980
981void RenderView::OnSetInitialFocus(bool reverse) {
982 if (!webview())
983 return;
[email protected]26aa0482009-09-30 16:55:27984 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29985}
986
[email protected]54ca3ca892011-06-07 21:14:54987#if defined(OS_MACOSX)
988void RenderView::OnSetInLiveResize(bool in_live_resize) {
989 if (!webview())
990 return;
991 if (in_live_resize)
992 webview()->willStartLiveResize();
993 else
994 webview()->willEndLiveResize();
995}
996#endif
997
[email protected]9b66f34bf2010-10-27 20:45:51998void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:09999 WebKit::WebNode node = GetFocusedNode();
1000 if (!node.isNull()) {
1001 if (IsEditableNode(node))
1002 // TODO(varunjain): Change webkit API to scroll a particular node into
1003 // view and use that API here instead.
1004 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:511005 }
1006}
1007
initial.commit09911bf2008-07-26 23:55:291008///////////////////////////////////////////////////////////////////////////////
1009
1010// Tell the embedding application that the URL of the active page has changed
1011void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451012 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291013 DCHECK(ds);
1014
[email protected]726985e22009-06-18 21:09:281015 const WebURLRequest& request = ds->request();
1016 const WebURLRequest& original_request = ds->originalRequest();
1017 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291018
[email protected]daa8c58e2009-06-15 17:21:101019 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1020 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291021
1022 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281023 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291024 params.is_post = false;
1025 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071026 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191027 params.socket_address.set_host(response.remoteIPAddress().utf8());
1028 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031029 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091030 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551031 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291032 // SSL state specified in the request takes precedence over the one in the
1033 // response.
1034 // So far this is only intended for error pages that are not expected to be
1035 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281036 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551037 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291038 } else {
[email protected]726985e22009-06-18 21:09:281039 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291040 }
1041
1042 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281043 if (ds->hasUnreachableURL()) {
1044 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291045 } else {
[email protected]726985e22009-06-18 21:09:281046 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291047 }
1048
[email protected]726985e22009-06-18 21:09:281049 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241050 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041051 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291052
[email protected]ce0e250d2009-10-23 21:00:351053 params.searchable_form_url = navigation_state->searchable_form_url();
1054 params.searchable_form_encoding =
1055 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291056
1057 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101058 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291059 if (password_form_data)
1060 params.password_form = *password_form_data;
1061
1062 params.gesture = navigation_gesture_;
1063 navigation_gesture_ = NavigationGestureUnknown;
1064
[email protected]0f38dc4552011-02-25 11:24:001065 // Make navigation state a part of the FrameNavigate message so that commited
1066 // entry had it at all times.
1067 const WebHistoryItem& item = frame->currentHistoryItem();
1068 if (!item.isNull()) {
1069 params.content_state = webkit_glue::HistoryItemToString(item);
1070 } else {
1071 params.content_state =
1072 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1073 }
1074
[email protected]dd7daa82009-08-10 05:46:451075 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291076 // Top-level navigation.
1077
[email protected]b75b8292010-10-01 07:28:251078 // Set zoom level, but don't do it for full-page plugin since they don't use
1079 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011080 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541081 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251082 if (webview()->mainFrame()->document().isPluginDocument()) {
1083 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251084 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251085 } else {
1086 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251087 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251088 }
1089
[email protected]f85f0702010-01-30 09:31:011090 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511091 // This zoom level was merely recorded transiently for this load. We can
1092 // erase it now. If at some point we reload this page, the browser will
1093 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011094 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511095 }
1096
[email protected]b75b8292010-10-01 07:28:251097 // Reset the zoom limits in case a plugin had changed them previously. This
1098 // will also call us back which will cause us to send a message to
1099 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251100 webview()->zoomLimitsChanged(
1101 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1102 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251103
initial.commit09911bf2008-07-26 23:55:291104 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551105 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291106
[email protected]daa8c58e2009-06-15 17:21:101107 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291108 if (!PageTransition::IsMainFrame(params.transition)) {
1109 // If the main frame does a load, it should not be reported as a subframe
1110 // navigation. This can occur in the following case:
1111 // 1. You're on a site with frames.
1112 // 2. You do a subframe navigation. This is stored with transition type
1113 // MANUAL_SUBFRAME.
1114 // 3. You navigate to some non-frame site, say, google.com.
1115 // 4. You navigate back to the page from step 2. Since it was initially
1116 // MANUAL_SUBFRAME, it will be that same transition type here.
1117 // We don't want that, because any navigation that changes the toplevel
1118 // frame should be tracked as a toplevel navigation (this allows us to
1119 // update the URL bar, etc).
1120 params.transition = PageTransition::LINK;
1121 }
1122
initial.commit09911bf2008-07-26 23:55:291123 // If we have a valid consumed client redirect source,
1124 // the page contained a client redirect (meta refresh, document.loc...),
1125 // so we set the referrer and transition to match.
1126 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041127 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291128 params.referrer = completed_client_redirect_src_;
1129 params.transition = static_cast<PageTransition::Type>(
1130 params.transition | PageTransition::CLIENT_REDIRECT);
1131 } else {
1132 // Bug 654101: the referrer will be empty on https->http transitions. It
1133 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281134 params.referrer = GURL(
1135 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291136 }
1137
[email protected]726985e22009-06-18 21:09:281138 string16 method = request.httpMethod();
1139 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291140 params.is_post = true;
1141
[email protected]c2a797d2009-09-21 16:46:321142 // Save some histogram data so we can compute the average memory used per
1143 // page load of the glyphs.
1144 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1145 webkit_glue::GetGlyphPageCount());
1146
[email protected]15cf526b2010-02-12 06:33:491147 // This message needs to be sent before any of allowScripts(),
1148 // allowImages(), allowPlugins() is called for the new page, so that when
1149 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1150 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291151 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1152 } else {
1153 // Subframe navigation: the type depends on whether this navigation
1154 // generated a new session history entry. When they do generate a session
1155 // history entry, it means the user initiated the navigation and we should
1156 // mark it as such. This test checks if this is the first time UpdateURL
1157 // has been called since WillNavigateToURL was called to initiate the load.
1158 if (page_id_ > last_page_id_sent_to_browser_)
1159 params.transition = PageTransition::MANUAL_SUBFRAME;
1160 else
1161 params.transition = PageTransition::AUTO_SUBFRAME;
1162
initial.commit09911bf2008-07-26 23:55:291163 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1164 }
1165
1166 last_page_id_sent_to_browser_ =
1167 std::max(last_page_id_sent_to_browser_, page_id_);
1168
1169 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101170 // we don't want the transition type to persist. Just clear it.
1171 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501172
[email protected]af15bed2010-08-25 21:12:091173 // Check if the navigation was within the same page, in which case we don't
1174 // want to clear the accessibility cache.
1175 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351176 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141177 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501178 }
initial.commit09911bf2008-07-26 23:55:291179}
1180
1181// Tell the embedding application that the title of the active page has changed
[email protected]a49e10b2011-08-01 23:57:461182void RenderView::UpdateTitle(WebFrame* frame, const string16& title,
1183 WebTextDirection title_direction) {
1184 // Ignore all but top level navigations.
1185 if (frame->parent())
1186 return;
1187
1188 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1189 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1190 title_direction));
initial.commit09911bf2008-07-26 23:55:291191}
1192
1193void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401194 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291195 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271196 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291197 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301198 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291199 last_encoding_name_ = encoding_name;
1200
[email protected]e38f40152008-09-12 23:08:301201 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291202 }
1203}
1204
[email protected]e15f680732010-11-23 22:30:201205// Sends the last committed session history state to the browser so it will be
1206// saved before we navigate to a new page. This must be called *before* the
1207// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291208void RenderView::UpdateSessionHistory(WebFrame* frame) {
1209 // If we have a valid page ID at this point, then it corresponds to the page
1210 // we are navigating away from. Otherwise, this is the first navigation, so
1211 // there is no past session history to record.
1212 if (page_id_ == -1)
1213 return;
1214
[email protected]ca948a22009-06-25 19:36:171215 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271216 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171217 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291218 return;
[email protected]ca948a22009-06-25 19:36:171219
1220 Send(new ViewHostMsg_UpdateState(
1221 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291222}
1223
[email protected]3d9689372009-09-10 04:29:171224void RenderView::OpenURL(
1225 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1226 Send(new ViewHostMsg_OpenURL(
1227 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1228}
1229
[email protected]79dbc662009-09-04 05:42:511230// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291231
initial.commit09911bf2008-07-26 23:55:291232void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281233 const WebURLRequest& failed_request,
1234 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291235 const std::string& html,
1236 bool replace) {
[email protected]c5c1d6d2011-07-28 18:42:411237
1238 // Do not show alternate error page when DevTools is attached.
1239 if (devtools_agent_->IsAttached())
1240 return;
1241
[email protected]21d61e52011-03-18 19:08:251242 std::string alt_html = !html.empty() ? html :
1243 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1244 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451245 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361246 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251247 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551248 replace);
initial.commit09911bf2008-07-26 23:55:291249}
1250
initial.commit09911bf2008-07-26 23:55:291251bool RenderView::RunJavaScriptMessage(int type,
[email protected]4f5ce842011-05-27 19:34:411252 const string16& message,
1253 const string16& default_value,
[email protected]a455d3812009-03-05 20:18:071254 const GURL& frame_url,
[email protected]4f5ce842011-05-27 19:34:411255 string16* result) {
initial.commit09911bf2008-07-26 23:55:291256 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411257 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291258 if (!result)
1259 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291260
[email protected]12636df2009-09-28 22:32:211261 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1262 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291263 return success;
1264}
1265
[email protected]c1f50aa2010-02-18 03:46:571266bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1267 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1268 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1269 // it is particularly important that we do not call willEnterModalLoop as
1270 // that would defer resource loads for the dialog itself.
1271 if (RenderThread::current()) // Will be NULL during unit tests.
1272 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1273
1274 message->EnableMessagePumping(); // Runs a nested message loop.
1275 return Send(message);
1276}
1277
[email protected]f103ab72009-09-02 17:10:591278void RenderView::OnMissingPluginStatus(
1279 WebPluginDelegateProxy* delegate,
1280 int status) {
[email protected]6c8afae52009-01-22 02:24:571281#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591282 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291283 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:501284 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591285 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291286 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1287 }
1288 } else {
1289 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1290 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:501291 if (status ==
1292 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:291293 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1294 }
1295 }
[email protected]6c8afae52009-01-22 02:24:571296#else
[email protected]76c3b312010-05-20 21:38:291297 // TODO(port): Implement the infobar that accompanies the default plugin.
1298 // Linux: http://crbug.com/10952
1299 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571300 NOTIMPLEMENTED();
1301#endif
initial.commit09911bf2008-07-26 23:55:291302}
1303
[email protected]48c9cf2d2009-09-16 16:47:521304// WebKit::WebViewClient ------------------------------------------------------
1305
[email protected]844acf372011-01-14 10:49:271306WebView* RenderView::createView(
1307 WebFrame* creator,
1308 const WebURLRequest& request,
1309 const WebWindowFeatures& features,
1310 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521311 // Check to make sure we aren't overloading on popups.
1312 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1313 return NULL;
1314
[email protected]8ab04652010-06-12 02:47:261315 ViewHostMsg_CreateWindow_Params params;
1316 params.opener_id = routing_id_;
1317 params.user_gesture = creator->isProcessingUserGesture();
1318 params.window_container_type = WindowFeaturesToContainerType(features);
1319 params.session_storage_namespace_id = session_storage_namespace_id_;
1320 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111321 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411322 params.opener_url = creator->document().url();
1323 params.opener_security_origin =
1324 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111325 if (!request.isNull())
1326 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261327
[email protected]48c9cf2d2009-09-16 16:47:521328 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341329 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261330 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521331
[email protected]48c9cf2d2009-09-16 16:47:521332 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261333 new ViewHostMsg_CreateWindow(params,
1334 &routing_id,
1335 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211336 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521337 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521338
[email protected]48c9cf2d2009-09-16 16:47:521339 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421340 0,
[email protected]12636df2009-09-28 22:32:211341 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521342 renderer_preferences_,
1343 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211344 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341345 routing_id,
[email protected]8ab04652010-06-12 02:47:261346 cloned_session_storage_namespace_id,
1347 frame_name);
1348 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521349
[email protected]007a848b2009-10-26 15:55:461350 // Record whether the creator frame is trying to suppress the opener field.
1351 view->opener_suppressed_ = opener_suppressed;
1352
[email protected]48c9cf2d2009-09-16 16:47:521353 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411354 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521355 if (!creator_url.is_valid() || !creator_url.IsStandard())
1356 creator_url = GURL();
1357 view->creator_url_ = creator_url;
1358
1359 // Copy over the alternate error page URL so we can have alt error pages in
1360 // the new render view (we don't need the browser to send the URL back down).
1361 view->alternate_error_page_url_ = alternate_error_page_url_;
1362
1363 return view->webview();
1364}
1365
[email protected]3e2b375b2010-04-07 17:03:121366WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521367 RenderWidget* widget = RenderWidget::Create(routing_id_,
1368 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121369 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521370 return widget->webwidget();
1371}
1372
1373WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441374 // TODO(jcivelli): Remove this deprecated method when its been removed from
1375 // the WebViewClient interface. It's been replaced by
1376 // createExternalPopupMenu.
1377 NOTREACHED();
1378 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521379}
1380
[email protected]caf706f2010-10-26 17:54:081381WebExternalPopupMenu* RenderView::createExternalPopupMenu(
1382 const WebPopupMenuInfo& popup_menu_info,
1383 WebExternalPopupMenuClient* popup_menu_client) {
1384 DCHECK(!external_popup_menu_.get());
1385 external_popup_menu_.reset(
1386 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1387 return external_popup_menu_.get();
1388}
1389
[email protected]ea192e82011-04-11 19:16:021390RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521391 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531392 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421393 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411394 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531395 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
1396 routing_id_, render_thread_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391397 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561398 return widget;
[email protected]79c7bed2010-09-14 22:28:391399}
1400
[email protected]68c50e52010-05-12 11:14:391401WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341402 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391403 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291404 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1405 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1406 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341407}
1408
[email protected]48c9cf2d2009-09-16 16:47:521409void RenderView::didAddMessageToConsole(
1410 const WebConsoleMessage& message, const WebString& source_name,
1411 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081412 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511413 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081414 case WebConsoleMessage::LevelTip:
1415 log_severity = logging::LOG_VERBOSE;
1416 break;
1417 case WebConsoleMessage::LevelLog:
1418 log_severity = logging::LOG_INFO;
1419 break;
1420 case WebConsoleMessage::LevelWarning:
1421 log_severity = logging::LOG_WARNING;
1422 break;
1423 case WebConsoleMessage::LevelError:
1424 log_severity = logging::LOG_ERROR;
1425 break;
1426 default:
1427 NOTREACHED();
1428 }
1429
[email protected]48c9cf2d2009-09-16 16:47:521430 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081431 static_cast<int32>(log_severity),
[email protected]48c9cf2d2009-09-16 16:47:521432 UTF16ToWideHack(message.text),
1433 static_cast<int32>(source_line),
1434 UTF16ToWideHack(source_name)));
1435}
1436
1437void RenderView::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421438 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521439}
1440
[email protected]3354d3e2010-06-10 19:53:021441WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511442 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021443}
1444
[email protected]8a58c1c2011-04-19 18:40:121445bool RenderView::enumerateChosenDirectory(
1446 const WebString& path,
1447 WebFileChooserCompletion* chooser_completion) {
1448 int id = enumeration_completion_id_++;
1449 enumeration_completions_[id] = chooser_completion;
1450 return Send(new ViewHostMsg_EnumerateDirectory(
1451 routing_id_,
1452 id,
1453 webkit_glue::WebStringToFilePath(path)));
1454}
1455
[email protected]48c9cf2d2009-09-16 16:47:521456void RenderView::didStartLoading() {
1457 if (is_loading_) {
1458 DLOG(WARNING) << "didStartLoading called while loading";
1459 return;
1460 }
1461
1462 is_loading_ = true;
1463 // Clear the pointer so that we can assign it only when there is an unknown
1464 // plugin on a page.
1465 first_default_plugin_.reset();
1466
1467 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311468
1469 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521470}
1471
1472void RenderView::didStopLoading() {
1473 if (!is_loading_) {
1474 DLOG(WARNING) << "DidStopLoading called while not loading";
1475 return;
1476 }
1477
1478 is_loading_ = false;
1479
1480 // NOTE: For now we're doing the safest thing, and sending out notification
1481 // when done loading. This currently isn't an issue as the favicon is only
1482 // displayed when done loading. Ideally we would send notification when
1483 // finished parsing the head, but webkit doesn't support that yet.
1484 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521485 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1486
[email protected]90109412010-12-15 17:14:241487 if (load_progress_tracker_ != NULL)
1488 load_progress_tracker_->DidStopLoading();
1489
[email protected]93b9d692011-04-13 00:44:311490 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521491}
1492
[email protected]90109412010-12-15 17:14:241493void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
1494 if (load_progress_tracker_ != NULL)
1495 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1496}
1497
[email protected]f55039a2010-02-17 14:12:061498bool RenderView::isSmartInsertDeleteEnabled() {
1499#if defined(OS_MACOSX)
1500 return true;
1501#else
1502 return false;
1503#endif
1504}
1505
[email protected]04fc9482009-09-18 22:13:031506bool RenderView::isSelectTrailingWhitespaceEnabled() {
1507#if defined(OS_WIN)
1508 return true;
1509#else
1510 return false;
1511#endif
1512}
1513
[email protected]04fc9482009-09-18 22:13:031514void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:421515#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031516 if (!handling_input_event_)
1517 return;
[email protected]d4cff272011-05-02 15:46:011518
1519 if (is_empty_selection) {
1520 last_selection_.clear();
1521 } else {
[email protected]04fc9482009-09-18 22:13:031522 // Sometimes we get repeated didChangeSelection calls from webkit when
1523 // the selection hasn't actually changed. We don't want to report these
1524 // because it will cause us to continually claim the X clipboard.
[email protected]d4cff272011-05-02 15:46:011525 WebFrame* frame = webview()->focusedFrame();
1526 const std::string& this_selection = frame->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031527 if (this_selection == last_selection_)
1528 return;
[email protected]04fc9482009-09-18 22:13:031529 last_selection_ = this_selection;
[email protected]04fc9482009-09-18 22:13:031530 }
[email protected]d4cff272011-05-02 15:46:011531
1532 ui::Range range(ui::Range::InvalidRange());
1533 size_t location, length;
1534 if (webview()->caretOrSelectionRange(&location, &length)) {
1535 range.set_start(location);
1536 range.set_end(location + length);
1537 }
1538 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range));
[email protected]0ff0ff32010-12-21 19:34:421539#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031540}
1541
1542void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121543 const std::string& name = UTF16ToUTF8(command_name);
1544 if (StartsWithASCII(name, "Move", true) ||
1545 StartsWithASCII(name, "Insert", true) ||
1546 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031547 return;
[email protected]c2043682011-06-10 22:49:561548 RenderThread::current()->Send(
1549 new ViewHostMsg_UserMetricsRecordAction(name));
[email protected]04fc9482009-09-18 22:13:031550}
1551
[email protected]54ec7f82010-10-21 22:32:511552void RenderView::SendPendingAccessibilityNotifications() {
1553 if (!accessibility_.get())
1554 return;
1555
1556 if (pending_accessibility_notifications_.empty())
1557 return;
1558
1559 // Send all pending accessibility notifications.
1560 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
1561 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
1562 RendererAccessibilityNotification& notification =
1563 pending_accessibility_notifications_[i];
1564 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
1565 if (!obj.isValid())
1566 continue;
1567
1568 ViewHostMsg_AccessibilityNotification_Params param;
[email protected]a527a022011-02-10 02:32:361569 WebAccessibilityNotificationToViewHostMsg(
1570 pending_accessibility_notifications_[i].type, &param.notification_type);
[email protected]70eee342010-11-05 01:59:371571 param.acc_obj = WebAccessibility(
1572 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:511573 notifications.push_back(param);
1574 }
1575 pending_accessibility_notifications_.clear();
1576 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
1577 accessibility_ack_pending_ = true;
1578}
1579
[email protected]b2528b72009-09-24 06:57:101580bool RenderView::handleCurrentKeyboardEvent() {
1581 if (edit_commands_.empty())
1582 return false;
1583
[email protected]26aa0482009-09-30 16:55:271584 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101585 if (!frame)
1586 return false;
1587
1588 EditCommands::iterator it = edit_commands_.begin();
1589 EditCommands::iterator end = edit_commands_.end();
1590
[email protected]507b33ea2009-09-29 03:56:511591 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101592 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331593 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1594 // key (but it's the exception). Once one edit command is not executed, it
1595 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101596 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1597 WebString::fromUTF8(it->value)))
1598 break;
[email protected]507b33ea2009-09-29 03:56:511599 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101600 }
1601
[email protected]507b33ea2009-09-29 03:56:511602 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101603}
1604
[email protected]a1128322009-10-06 18:38:461605bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351606 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471607 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351608 // Do not open the file dialog in a hidden RenderView.
1609 if (is_hidden())
1610 return false;
[email protected]cdaf8d02010-03-30 19:52:471611 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261612 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361613 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261614 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361615 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]b5977a0c2010-08-24 19:46:261616 else
[email protected]0aed2f52011-03-23 18:06:361617 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471618 ipc_params.title = params.title;
1619 ipc_params.default_file_name =
1620 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591621 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471622
1623 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461624}
1625
[email protected]48c9cf2d2009-09-16 16:47:521626void RenderView::runModalAlertDialog(
1627 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061628 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]4f5ce842011-05-27 19:34:411629 message,
1630 string16(),
[email protected]b6cb3a842011-06-24 18:28:411631 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521632 NULL);
1633}
1634
1635bool RenderView::runModalConfirmDialog(
1636 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061637 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]4f5ce842011-05-27 19:34:411638 message,
1639 string16(),
[email protected]b6cb3a842011-06-24 18:28:411640 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521641 NULL);
1642}
1643
1644bool RenderView::runModalPromptDialog(
1645 WebFrame* frame, const WebString& message, const WebString& default_value,
1646 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411647 string16 result;
[email protected]9dd7e3d72011-01-20 18:27:061648 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]4f5ce842011-05-27 19:34:411649 message,
1650 default_value,
[email protected]b6cb3a842011-06-24 18:28:411651 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521652 &result);
1653 if (ok)
[email protected]4f5ce842011-05-27 19:34:411654 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521655 return ok;
1656}
1657
1658bool RenderView::runModalBeforeUnloadDialog(
1659 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151660 // If we are swapping out, we have already run the beforeunload handler.
1661 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1662 // at all, to avoid running it twice.
1663 if (is_swapped_out_)
1664 return true;
1665
[email protected]48c9cf2d2009-09-16 16:47:521666 bool success = false;
1667 // This is an ignored return value, but is included so we can accept the same
1668 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411669 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211670 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411671 routing_id_, frame->document().url(), message,
1672 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521673 return success;
1674}
1675
[email protected]79e37442009-10-09 18:17:441676void RenderView::showContextMenu(
1677 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291678 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371679
1680 // frame is NULL if invoked by BlockedPlugin.
1681 if (frame)
1682 params.frame_id = frame->identifier();
1683
[email protected]db803aae2011-03-05 02:00:421684 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271685 // it. We replace it with an empty GURL so the appropriate items are disabled
1686 // in the context menu.
1687 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1688 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421689 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271690 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101691 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291692 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441693}
1694
[email protected]52f139e2c2010-06-11 16:56:091695bool RenderView::supportsFullscreen() {
1696 return CommandLine::ForCurrentProcess()->HasSwitch(
1697 switches::kEnableVideoFullscreen);
1698}
1699
1700void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1701 NOTIMPLEMENTED();
1702}
1703
1704void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1705 NOTIMPLEMENTED();
1706}
1707
[email protected]48c9cf2d2009-09-16 16:47:521708void RenderView::setStatusText(const WebString& text) {
1709}
1710
[email protected]163f8242009-10-30 20:19:551711void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581712 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521713 if (latest_url == target_url_)
1714 return;
[email protected]163f8242009-10-30 20:19:551715
[email protected]48c9cf2d2009-09-16 16:47:521716 // Tell the browser to display a destination link.
1717 if (target_url_status_ == TARGET_INFLIGHT ||
1718 target_url_status_ == TARGET_PENDING) {
1719 // If we have a request in-flight, save the URL to be sent when we
1720 // receive an ACK to the in-flight request. We can happily overwrite
1721 // any existing pending sends.
1722 pending_target_url_ = latest_url;
1723 target_url_status_ = TARGET_PENDING;
1724 } else {
1725 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1726 target_url_ = latest_url;
1727 target_url_status_ = TARGET_INFLIGHT;
1728 }
1729}
1730
[email protected]882daa92009-11-05 16:31:311731void RenderView::StartNavStateSyncTimerIfNecessary() {
1732 int delay;
1733 if (send_content_state_immediately_)
1734 delay = 0;
1735 else if (is_hidden())
1736 delay = kDelaySecondsForContentStateSyncHidden;
1737 else
1738 delay = kDelaySecondsForContentStateSync;
1739
1740 if (nav_state_sync_timer_.IsRunning()) {
1741 // The timer is already running. If the delay of the timer maches the amount
1742 // we want to delay by, then return. Otherwise stop the timer so that it
1743 // gets started with the right delay.
1744 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1745 return;
1746 nav_state_sync_timer_.Stop();
1747 }
1748
1749 nav_state_sync_timer_.Start(
1750 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1751}
1752
[email protected]163f8242009-10-30 20:19:551753void RenderView::setMouseOverURL(const WebURL& url) {
1754 mouse_over_url_ = GURL(url);
1755 UpdateTargetURL(mouse_over_url_, focus_url_);
1756}
1757
1758void RenderView::setKeyboardFocusURL(const WebURL& url) {
1759 focus_url_ = GURL(url);
1760 UpdateTargetURL(focus_url_, mouse_over_url_);
1761}
1762
[email protected]c27ae592010-03-18 15:24:411763void RenderView::startDragging(const WebDragData& data,
1764 WebDragOperationsMask mask,
1765 const WebImage& image,
1766 const WebPoint& imageOffset) {
1767#if WEBKIT_USING_SKIA
1768 SkBitmap bitmap(image.getSkBitmap());
1769#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331770 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411771#endif
1772
[email protected]59f4f2fa2011-03-23 01:00:551773 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521774 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411775 mask,
1776 bitmap,
1777 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521778}
1779
[email protected]28b92df2009-09-25 17:35:451780bool RenderView::acceptsLoadDrops() {
1781 return renderer_preferences_.can_accept_load_drops;
1782}
1783
[email protected]48c9cf2d2009-09-16 16:47:521784void RenderView::focusNext() {
1785 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1786}
1787
1788void RenderView::focusPrevious() {
1789 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1790}
1791
[email protected]08e9e132010-06-01 16:58:491792void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511793 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071794
1795 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
1796 // TODO(ctguil): Make WebKit send this notification.
1797 // When focus is cleared notify accessibility that the document is focused.
1798 postAccessibilityNotification(
1799 webview()->accessibilityObject(),
1800 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
1801 }
[email protected]13a1e4c3c2011-02-03 21:07:091802
[email protected]38b592902011-04-16 02:08:421803 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491804}
1805
[email protected]48c9cf2d2009-09-16 16:47:521806void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521807 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1808}
1809
1810int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001811 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521812}
1813
1814int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001815 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521816}
1817
[email protected]c4e98902010-06-01 10:20:141818void RenderView::didUpdateInspectorSetting(const WebString& key,
1819 const WebString& value) {
1820 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1821 key.utf8(),
1822 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261823}
1824
[email protected]79dbc662009-09-04 05:42:511825// WebKit::WebWidgetClient ----------------------------------------------------
1826
[email protected]ea42e7782010-08-23 23:58:121827void RenderView::didFocus() {
1828 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1829 // we won't have to test for user gesture anymore and we can
1830 // move that code back to render_widget.cc
1831 if (webview() && webview()->mainFrame() &&
1832 webview()->mainFrame()->isProcessingUserGesture()) {
1833 Send(new ViewHostMsg_Focus(routing_id_));
1834 }
1835}
1836
1837void RenderView::didBlur() {
1838 // TODO(jcivelli): see TODO above in didFocus().
1839 if (webview() && webview()->mainFrame() &&
1840 webview()->mainFrame()->isProcessingUserGesture()) {
1841 Send(new ViewHostMsg_Blur(routing_id_));
1842 }
1843}
1844
initial.commit09911bf2008-07-26 23:55:291845// We are supposed to get a single call to Show for a newly created RenderView
1846// that was created via RenderView::CreateWebView. So, we wait until this
1847// point to dispatch the ShowView message.
1848//
1849// This method provides us with the information about how to display the newly
1850// created RenderView (i.e., as a constrained popup or as a new tab).
1851//
[email protected]4873c7d2009-07-16 06:36:281852void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291853 DCHECK(!did_show_) << "received extraneous Show call";
1854 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1855
1856 if (did_show_)
1857 return;
1858 did_show_ = true;
1859
[email protected]6779aa12011-03-29 17:32:241860 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041861 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041862
[email protected]28295ec2009-10-16 05:34:331863 // Force new windows to a popup if they were not opened with a user gesture.
1864 if (!opened_by_user_gesture_) {
1865 // We exempt background tabs for compat with older versions of Chrome.
1866 // TODO(darin): This seems bogus. These should have a user gesture, so
1867 // we probably don't need this check.
1868 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1869 policy = WebKit::WebNavigationPolicyNewPopup;
1870 }
1871
initial.commit09911bf2008-07-26 23:55:291872 // NOTE: initial_pos_ may still have its default values at this point, but
1873 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1874 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281875 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1876 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291877 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241878 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291879}
1880
[email protected]4873c7d2009-07-16 06:36:281881void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291882 DCHECK(did_show_) << "should already have shown the view";
1883
[email protected]c1f50aa2010-02-18 03:46:571884 // We must keep WebKit's shared timer running in this case in order to allow
1885 // showModalDialog to function properly.
1886 //
1887 // TODO(darin): WebKit should really be smarter about suppressing events and
1888 // timers so that we do not need to manage the shared timer in such a heavy
1889 // handed manner.
1890 //
1891 if (RenderThread::current()) // Will be NULL during unit tests.
1892 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
1893
[email protected]12636df2009-09-28 22:32:211894 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291895}
1896
[email protected]3d9689372009-09-10 04:29:171897// WebKit::WebFrameClient -----------------------------------------------------
1898
[email protected]00152e92010-07-19 11:47:401899WebPlugin* RenderView::createPlugin(WebFrame* frame,
1900 const WebPluginParams& params) {
[email protected]e7c21b812011-03-19 18:03:301901 return content::GetContentClient()->renderer()->CreatePlugin(
[email protected]21d61e52011-03-18 19:08:251902 this, frame, params);
[email protected]3d9689372009-09-10 04:29:171903}
1904
1905WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561906 WebApplicationCacheHostImpl* appcache_host =
1907 WebApplicationCacheHostImpl::FromFrame(frame);
1908 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
1909 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
1910 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171911}
1912
[email protected]9c00f002009-11-05 22:37:421913WebSharedWorker* RenderView::createSharedWorker(
1914 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371915 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421916
[email protected]30447b62009-11-13 01:13:371917 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511918 bool exists = false;
[email protected]30447b62009-11-13 01:13:371919 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511920 ViewHostMsg_CreateWorker_Params params;
1921 params.url = url;
1922 params.is_shared = true;
1923 params.name = name;
1924 params.document_id = document_id;
1925 params.render_view_route_id = routing_id_;
1926 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231927 params.parent_appcache_host_id = 0;
1928 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371929 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511930 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371931 if (url_mismatch) {
1932 return NULL;
1933 } else {
1934 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:491935 document_id,
[email protected]6de0bcf2010-02-17 22:00:511936 exists,
[email protected]30447b62009-11-13 01:13:371937 route_id,
1938 routing_id_);
1939 }
[email protected]9c00f002009-11-05 22:37:421940}
1941
[email protected]3d9689372009-09-10 04:29:171942WebMediaPlayer* RenderView::createMediaPlayer(
1943 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441944 FOR_EACH_OBSERVER(
1945 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171946
[email protected]f78d1dfc2011-01-15 07:09:271947 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1948 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491949 scoped_ptr<media::FilterCollection> collection(
1950 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371951
[email protected]3d9689372009-09-10 04:29:171952 // Add in any custom filter factories first.
1953 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1954 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1955 // Add the chrome specific audio renderer.
[email protected]f7eb0a392011-07-12 10:19:511956 collection->AddAudioRenderer(new AudioRendererImpl());
[email protected]3d9689372009-09-10 04:29:171957 }
1958
[email protected]457d8342010-10-23 01:20:371959 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:311960 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
1961 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
1962 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:491963 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:311964 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:111965
[email protected]a8e24d522010-12-01 07:13:581966 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:271967 new webkit_glue::WebMediaPlayerImpl(client,
1968 collection.release(),
[email protected]ab2c4732011-07-20 19:57:401969 message_loop_factory.release(),
1970 media_stream_impl_.get()));
[email protected]79684282010-12-06 21:15:461971 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:581972 cmd_line->HasSwitch(switches::kSimpleDataSource),
1973 video_renderer)) {
1974 return NULL;
1975 }
1976 return result.release();
[email protected]3d9689372009-09-10 04:29:171977}
1978
[email protected]035545f2010-04-09 13:10:211979WebApplicationCacheHost* RenderView::createApplicationCacheHost(
1980 WebFrame* frame, WebApplicationCacheHostClient* client) {
1981 return new RendererWebApplicationCacheHostImpl(
1982 FromWebView(frame->view()), client,
1983 RenderThread::current()->appcache_dispatcher()->backend_proxy());
1984}
1985
[email protected]8ff181072010-11-29 17:09:381986WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
1987 return &cookie_jar_;
1988}
1989
[email protected]5041f982010-08-11 21:40:451990void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511991 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451992}
1993
[email protected]3d9689372009-09-10 04:29:171994void RenderView::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511995 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171996}
1997
1998void RenderView::loadURLExternally(
1999 WebFrame* frame, const WebURLRequest& request,
2000 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342001 loadURLExternally(frame, request, policy, WebString());
2002}
2003
2004void RenderView::loadURLExternally(
2005 WebFrame* frame, const WebURLRequest& request,
2006 WebNavigationPolicy policy,
2007 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592008 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2009 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342010 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2011 suggested_name));
[email protected]efce17b2009-09-11 18:04:592012 } else {
2013 OpenURL(request.url(), referrer, policy);
2014 }
[email protected]3d9689372009-09-10 04:29:172015}
2016
2017WebNavigationPolicy RenderView::decidePolicyForNavigation(
2018 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222019 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152020 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2021 if (is_swapped_out_) {
2022 DCHECK(request.url() == GURL("about:swappedout"));
2023 return default_policy;
2024 }
2025
[email protected]3d9689372009-09-10 04:29:172026 // Webkit is asking whether to navigate to a new URL.
2027 // This is fine normally, except if we're showing UI from one security
2028 // context and they're trying to navigate to a different context.
2029 const GURL& url = request.url();
2030
[email protected]d19ea342011-04-20 20:31:132031 // A content initiated navigation may have originated from a link-click,
2032 // script, drag-n-drop operation, etc.
2033 bool is_content_initiated =
2034 NavigationState::FromDataSource(frame->provisionalDataSource())->
2035 is_content_initiated();
2036
[email protected]3d9689372009-09-10 04:29:172037 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302038 // navigations.
[email protected]d19ea342011-04-20 20:31:132039 if (is_content_initiated &&
2040 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:452041 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192042 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232043 // Reset these counters as the RenderView could be reused for the next
2044 // navigation.
2045 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232046 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192047 OpenURL(url, referrer, default_policy);
2048 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172049 }
2050
[email protected]b6cb3a842011-06-24 18:28:412051 GURL old_url(frame->document().url());
[email protected]3d9689372009-09-10 04:29:172052
[email protected]6101c342010-12-16 22:44:372053 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552054 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572055 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372056 // opening a new window). But we sometimes navigate to about:blank to clear a
2057 // tab, and we want to still allow that.
2058 //
[email protected]8f4da8c2011-02-09 19:49:572059 // Note: we do this only for GET requests because our mechanism for switching
2060 // processes only issues GET requests. In particular, POST requests don't
2061 // work, because this mechanism does not preserve form POST data. If it
2062 // becomes necessary to support process switching for POST requests, we will
2063 // need to send the request's httpBody data up to the browser process, and
2064 // issue a special POST navigation in WebKit (via
2065 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2066 // for examples of how to send the httpBody data.
2067 // Note2: We normally don't do this for browser-initiated navigations, since
2068 // it's pointless to tell the browser about navigations it gave us. But
2069 // we do potentially ask the browser to handle a redirect that was originally
2070 // initiated by the browser. See http://crbug.com/70943
2071 //
2072 // TODO(creis): Move this redirect check to the browser process to avoid
2073 // ping-ponging. See http://crbug.com/72380.
2074 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372075 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2076 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2077 bool send_referrer = false;
2078 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552079 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172080 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372081 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112082
[email protected]e48869a2011-04-01 19:56:032083 if (!should_fork) {
2084 // Give the embedder a chance.
2085 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2086 frame, url, is_content_initiated, &send_referrer);
[email protected]6101c342010-12-16 22:44:372087 }
2088
2089 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112090 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372091 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112092 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2093 }
[email protected]3d9689372009-09-10 04:29:172094 }
2095
2096 // Detect when a page is "forking" a new tab that can be safely rendered in
2097 // its own process. This is done by sites like Gmail that try to open links
2098 // in new windows without script connections back to the original page. We
2099 // treat such cases as browser navigations (in which we will create a new
2100 // renderer for a cross-site navigation), rather than WebKit navigations.
2101 //
2102 // We use the following heuristic to decide whether to fork a new page in its
2103 // own process:
2104 // The parent page must open a new tab to about:blank, set the new tab's
2105 // window.opener to null, and then redirect the tab to a cross-site URL using
2106 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462107 //
2108 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2109 // (see below).
[email protected]3d9689372009-09-10 04:29:172110 bool is_fork =
2111 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582112 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172113 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522114 historyBackListCount() < 1 &&
2115 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172116 // The parent page must have set the child's window.opener to null before
2117 // redirecting to the desired URL.
2118 frame->opener() == NULL &&
2119 // Must be a top-level frame.
2120 frame->parent() == NULL &&
2121 // Must not have issued the request from this page.
2122 is_content_initiated &&
2123 // Must be targeted at the current tab.
2124 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2125 // Must be a JavaScript navigation, which appears as "other".
2126 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462127
2128 // Recognize if this navigation is from a link with rel=noreferrer and
2129 // target=_blank attributes, in which case the opener will be suppressed. If
2130 // so, it is safe to load cross-site pages in a separate process, so we
2131 // should let the browser handle it.
2132 bool is_noreferrer_and_blank_target =
2133 // Frame should be top level and not yet navigated.
2134 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412135 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462136 historyBackListCount() < 1 &&
2137 historyForwardListCount() < 1 &&
2138 // Links with rel=noreferrer will have no Referer field, and their
2139 // resulting frame will have its window.opener suppressed.
2140 // TODO(creis): should add a request.httpReferrer() method to help avoid
2141 // typos on the unusual spelling of Referer.
2142 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2143 opener_suppressed_ &&
2144 frame->opener() == NULL &&
2145 // Links with target=_blank will have no name.
2146 frame->name().isNull() &&
2147 // Another frame (with a non-empty creator) should have initiated the
2148 // request, targeted at this frame.
2149 !creator_url_.is_empty() &&
2150 is_content_initiated &&
2151 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2152 type == WebKit::WebNavigationTypeOther;
2153
2154 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172155 // Open the URL via the browser, not via WebKit.
2156 OpenURL(url, GURL(), default_policy);
2157 return WebKit::WebNavigationPolicyIgnore;
2158 }
2159
2160 return default_policy;
2161}
2162
[email protected]6069da8c2009-10-20 20:33:492163bool RenderView::canHandleRequest(
2164 WebFrame* frame, const WebURLRequest& request) {
2165 // We allow WebKit to think that everything can be handled even though
2166 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342167 return true;
2168}
2169
[email protected]6069da8c2009-10-20 20:33:492170WebURLError RenderView::cannotHandleRequestError(
2171 WebFrame* frame, const WebURLRequest& request) {
2172 NOTREACHED(); // Since we said we can handle all requests.
2173 return WebURLError();
2174}
2175
2176WebURLError RenderView::cancelledError(
2177 WebFrame* frame, const WebURLRequest& request) {
2178 WebURLError error;
2179 error.domain = WebString::fromUTF8(net::kErrorDomain);
2180 error.reason = net::ERR_ABORTED;
2181 error.unreachableURL = request.url();
2182 return error;
[email protected]7b7a7dc2009-10-19 02:23:342183}
2184
2185void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492186 WebFrame*, const WebURLError&) {
2187 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342188}
2189
[email protected]90eeddb2010-05-06 21:06:432190void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2191 const WebKit::WebFormElement& form) {
2192 // Some login forms have onSubmit handlers that put a hash of the password
2193 // into a hidden field and then clear the password. (Issue 28910.)
2194 // This method gets called before any of those handlers run, so save away
2195 // a copy of the password in case it gets lost.
2196 NavigationState* navigation_state =
2197 NavigationState::FromDataSource(frame->dataSource());
2198 navigation_state->set_password_form_data(
2199 PasswordFormDomManager::CreatePasswordForm(form));
2200}
2201
[email protected]979c28b2009-11-07 01:30:482202void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172203 NavigationState* navigation_state =
2204 NavigationState::FromDataSource(frame->provisionalDataSource());
2205
2206 if (navigation_state->transition_type() == PageTransition::LINK)
2207 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2208
2209 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352210 WebSearchableFormData web_searchable_form_data(form);
2211 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2212 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212213 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432214 PasswordForm* password_form_data =
2215 PasswordFormDomManager::CreatePasswordForm(form);
2216 navigation_state->set_password_form_data(password_form_data);
2217
[email protected]098c95cb2011-04-28 16:49:012218 // In order to save the password that the user actually typed and not one
2219 // that may have gotten transformed by the site prior to submit, recover it
2220 // from the form contents already stored by |willSendSubmitEvent| into the
2221 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2222 // which is what we're storing into now.)
2223 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432224 NavigationState* old_navigation_state =
2225 NavigationState::FromDataSource(frame->dataSource());
2226 if (old_navigation_state) {
2227 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2228 if (old_form_data && old_form_data->action == password_form_data->action)
2229 password_form_data->password_value = old_form_data->password_value;
2230 }
2231 }
[email protected]3d9689372009-09-10 04:29:172232
[email protected]2a5b1732011-04-01 23:55:552233 FOR_EACH_OBSERVER(
2234 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172235}
2236
2237void RenderView::willPerformClientRedirect(
2238 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2239 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382240 FOR_EACH_OBSERVER(
2241 RenderViewObserver, observers_,
2242 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172243}
2244
2245void RenderView::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382246 FOR_EACH_OBSERVER(
2247 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172248}
2249
2250void RenderView::didCompleteClientRedirect(
2251 WebFrame* frame, const WebURL& from) {
2252 if (!frame->parent())
2253 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382254 FOR_EACH_OBSERVER(
2255 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172256}
2257
2258void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2259 // The rest of RenderView assumes that a WebDataSource will always have a
2260 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482261 bool content_initiated = !pending_navigation_state_.get();
2262 NavigationState* state = content_initiated ?
2263 NavigationState::CreateContentInitiated() :
2264 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512265
[email protected]8a3125a712010-08-09 18:58:512266 // NavigationState::referred_by_prefetcher_ is true if we are
2267 // navigating from a page that used prefetching using a link on that
2268 // page. We are early enough in the request process here that we
2269 // can still see the NavigationState of the previous page and set
2270 // this value appropriately.
2271 // TODO(gavinp): catch the important case of navigation in a new
2272 // renderer process.
2273 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302274 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522275 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512276 const GURL referrer(
2277 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2278 if (!referrer.is_empty() &&
2279 NavigationState::FromDataSource(
2280 old_frame->dataSource())->was_prefetcher()) {
2281 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2282 WebDataSource* old_frame_ds = old_frame->dataSource();
2283 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2284 state->set_was_referred_by_prefetcher(true);
2285 break;
2286 }
2287 }
2288 }
2289 }
2290 }
2291
[email protected]4c1b6f0b2010-02-07 16:38:182292 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522293 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512294 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182295 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2296 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2297 break;
2298 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2299 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2300 break;
2301 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2302 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2303 break;
2304 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2305 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2306 break;
2307 }
2308 }
[email protected]fa7b6b542009-11-03 05:02:302309
[email protected]16e923d2011-04-30 00:41:442310 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502311
[email protected]946a0032011-03-31 18:42:282312 FOR_EACH_OBSERVER(
2313 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172314}
2315
2316void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2317 WebDataSource* ds = frame->provisionalDataSource();
2318 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2319
[email protected]3d9689372009-09-10 04:29:172320 // Update the request time if WebKit has better knowledge of it.
2321 if (navigation_state->request_time().is_null()) {
2322 double event_time = ds->triggeringEventTime();
2323 if (event_time != 0.0)
2324 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2325 }
2326
[email protected]05c8e502010-08-15 15:13:522327 // Start time is only set after request time.
2328 navigation_state->set_start_load_time(Time::Now());
2329
[email protected]3d9689372009-09-10 04:29:172330 bool is_top_most = !frame->parent();
2331 if (is_top_most) {
2332 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132333 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172334
2335 // Make sure redirect tracking state is clear for the new load.
2336 completed_client_redirect_src_ = GURL();
2337 } else if (frame->parent()->isLoading()) {
2338 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002339 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172340 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2341 }
2342
[email protected]28685da92011-02-07 21:49:172343 FOR_EACH_OBSERVER(
2344 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2345
[email protected]eacb080b2011-05-22 19:40:262346 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]3d9689372009-09-10 04:29:172347 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]eacb080b2011-05-22 19:40:262348 routing_id_, frame->identifier(), is_top_most, has_opener_set,
2349 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172350}
2351
2352void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2353 if (frame->parent())
2354 return;
2355 // Received a redirect on the main frame.
2356 WebDataSource* data_source = frame->provisionalDataSource();
2357 if (!data_source) {
2358 // Should only be invoked when we have a data source.
2359 NOTREACHED();
2360 return;
2361 }
2362 std::vector<GURL> redirects;
2363 GetRedirectChain(data_source, &redirects);
2364 if (redirects.size() >= 2) {
[email protected]eacb080b2011-05-22 19:40:262365 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]40bd6582009-12-04 23:49:512366 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]eacb080b2011-05-22 19:40:262367 has_opener_set, redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172368 }
2369}
2370
[email protected]40bd6582009-12-04 23:49:512371void RenderView::didFailProvisionalLoad(WebFrame* frame,
2372 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172373 // Notify the browser that we failed a provisional load with an error.
2374 //
2375 // Note: It is important this notification occur before DidStopLoading so the
2376 // SSL manager can react to the provisional load failure before being
2377 // notified the load stopped.
2378 //
2379 WebDataSource* ds = frame->provisionalDataSource();
2380 DCHECK(ds);
2381
2382 const WebURLRequest& failed_request = ds->request();
2383
[email protected]28685da92011-02-07 21:49:172384 FOR_EACH_OBSERVER(
2385 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2386
[email protected]3d9689372009-09-10 04:29:172387 bool show_repost_interstitial =
2388 (error.reason == net::ERR_CACHE_MISS &&
2389 EqualsASCII(failed_request.httpMethod(), "POST"));
2390 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072391 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2392 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172393
2394 // Don't display an error page if this is simply a cancelled load. Aside
2395 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2396 if (error.reason == net::ERR_ABORTED)
2397 return;
2398
2399 // Make sure we never show errors in view source mode.
2400 frame->enableViewSourceMode(false);
2401
2402 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2403
2404 // If this is a failed back/forward/reload navigation, then we need to do a
2405 // 'replace' load. This is necessary to avoid messing up session history.
2406 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2407 // as session history is concerned.
2408 //
2409 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2410 // the page id.
2411 //
2412 bool replace =
2413 navigation_state->pending_page_id() != -1 ||
2414 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2415
2416 // If we failed on a browser initiated request, then make sure that our error
2417 // page load is regarded as the same browser initiated request.
2418 if (!navigation_state->is_content_initiated()) {
2419 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2420 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002421 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172422 navigation_state->transition_type(),
2423 navigation_state->request_time()));
2424 }
2425
[email protected]c5c1d6d2011-07-28 18:42:412426 // Do not show alternate error page when DevTools is attached.
2427 if (devtools_agent_->IsAttached())
2428 return;
2429
[email protected]3d9689372009-09-10 04:29:172430 // Provide the user with a more helpful error page?
2431 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2432 return;
2433
2434 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082435 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172436}
2437
2438void RenderView::didReceiveDocumentData(
2439 WebFrame* frame, const char* data, size_t data_len,
2440 bool& prevent_default) {
2441 NavigationState* navigation_state =
2442 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092443 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172444}
2445
[email protected]40bd6582009-12-04 23:49:512446void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2447 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172448 NavigationState* navigation_state =
2449 NavigationState::FromDataSource(frame->dataSource());
2450
2451 navigation_state->set_commit_load_time(Time::Now());
2452 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202453 // When we perform a new navigation, we need to update the last committed
2454 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172455 UpdateSessionHistory(frame);
2456
2457 // We bump our Page ID to correspond with the new session history entry.
2458 page_id_ = next_page_id_++;
2459
[email protected]3cc72b12010-03-18 23:03:002460 // Advance our offset in session history, applying the length limit. There
2461 // is now no forward history.
2462 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102463 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2464 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002465 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032466 history_page_ids_.resize(history_list_length_, -1);
2467 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172468 } else {
2469 // Inspect the navigation_state on this frame to see if the navigation
2470 // corresponds to a session history navigation... Note: |frame| may or
2471 // may not be the toplevel frame, but for the case of capturing session
2472 // history, the first committed frame suffices. We keep track of whether
2473 // we've seen this commit before so that only capture session history once
2474 // per navigation.
2475 //
2476 // Note that we need to check if the page ID changed. In the case of a
2477 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2478 // previous URL and the current page ID, which would be wrong.
2479 if (navigation_state->pending_page_id() != -1 &&
2480 navigation_state->pending_page_id() != page_id_ &&
2481 !navigation_state->request_committed()) {
2482 // This is a successful session history navigation!
2483 UpdateSessionHistory(frame);
2484 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002485
2486 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032487
2488 // If the history list is valid, our list of page IDs should be correct.
2489 DCHECK(history_list_length_ <= 0 ||
2490 history_list_offset_ < 0 ||
2491 history_list_offset_ >= history_list_length_ ||
2492 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172493 }
2494 }
2495
[email protected]28685da92011-02-07 21:49:172496 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2497 DidCommitProvisionalLoad(frame, is_new_navigation));
2498
[email protected]3d9689372009-09-10 04:29:172499 // Remember that we've already processed this request, so we don't update
2500 // the session history again. We do this regardless of whether this is
2501 // a session history navigation, because if we attempted a session history
2502 // navigation without valid HistoryItem state, WebCore will think it is a
2503 // new navigation.
2504 navigation_state->set_request_committed(true);
2505
2506 UpdateURL(frame);
2507
2508 // If this committed load was initiated by a client redirect, we're
2509 // at the last stop now, so clear it.
2510 completed_client_redirect_src_ = GURL();
2511
2512 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272513 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172514}
2515
2516void RenderView::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102517 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2518 DidClearWindowObject(frame));
2519
[email protected]b6cb3a842011-06-24 18:28:412520 GURL frame_url = frame->document().url();
[email protected]c09163a2011-02-15 00:05:552521 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:252522 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2523 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272524 GetWebUIBindings()->set_message_sender(this);
2525 GetWebUIBindings()->set_routing_id(routing_id_);
2526 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172527 }
[email protected]3d9689372009-09-10 04:29:172528}
2529
2530void RenderView::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172531 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412532 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252533 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272534 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172535 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2536 }
[email protected]e48869a2011-04-01 19:56:032537
2538 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2539 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172540}
2541
[email protected]a3bc4d12011-04-20 17:22:212542void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title,
2543 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462544 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172545
2546 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272547 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172548}
2549
[email protected]42054a252011-05-17 18:02:132550void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
2551 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2552 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582553}
2554
[email protected]3d9689372009-09-10 04:29:172555void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2556 WebDataSource* ds = frame->dataSource();
2557 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2558 DCHECK(navigation_state);
2559 navigation_state->set_finish_document_load_time(Time::Now());
2560
[email protected]622474d2010-11-04 09:21:082561 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172562
[email protected]28685da92011-02-07 21:49:172563 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2564 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172565
2566 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272567 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172568}
2569
2570void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082571 if (webview()->mainFrame() == frame) {
2572 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2573 page_id_));
2574 }
[email protected]3d9689372009-09-10 04:29:172575}
2576
2577void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172578 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172579}
2580
2581void RenderView::didFinishLoad(WebFrame* frame) {
2582 WebDataSource* ds = frame->dataSource();
2583 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2584 DCHECK(navigation_state);
2585 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412586
[email protected]676126f72011-01-15 00:03:512587 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172588
2589 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172590}
2591
[email protected]ccbe04e2010-03-17 17:58:432592void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172593 WebFrame* frame, bool is_new_navigation) {
2594 // If this was a reference fragment navigation that we initiated, then we
2595 // could end up having a non-null pending navigation state. We just need to
2596 // update the ExtraData on the datasource so that others who read the
2597 // ExtraData will get the new NavigationState. Similarly, if we did not
2598 // initiate this navigation, then we need to take care to reset any pre-
2599 // existing navigation state to a content-initiated navigation state.
2600 // DidCreateDataSource conveniently takes care of this for us.
2601 didCreateDataSource(frame, frame->dataSource());
2602
[email protected]af15bed2010-08-25 21:12:092603 NavigationState* new_state =
2604 NavigationState::FromDataSource(frame->dataSource());
2605 new_state->set_was_within_same_page(true);
2606
[email protected]3d9689372009-09-10 04:29:172607 didCommitProvisionalLoad(frame, is_new_navigation);
2608
[email protected]a49e10b2011-08-01 23:57:462609 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle(),
2610 frame->view()->mainFrame()->dataSource()->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172611}
2612
[email protected]476b6f82009-09-10 21:00:592613void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312614 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592615}
2616
[email protected]3d9689372009-09-10 04:29:172617void RenderView::assignIdentifierToRequest(
2618 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2619 // Ignore
2620}
2621
2622void RenderView::willSendRequest(
2623 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2624 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302625 WebFrame* top_frame = frame->top();
2626 if (!top_frame)
2627 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512628 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2629 WebDataSource* top_data_source = top_frame->dataSource();
2630 WebDataSource* data_source =
2631 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222632
[email protected]418da612011-07-21 19:01:522633 bool is_top_frame = (frame == top_frame);
2634 request.setExtraData(
2635 new RequestExtraData(is_top_frame, frame->identifier()));
[email protected]e48869a2011-04-01 19:56:032636
[email protected]78d5cfe2011-02-04 08:43:222637 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032638 GURL new_url;
2639 if (content::GetContentClient()->renderer()->WillSendRequest(
2640 frame, request_url, &new_url)) {
2641 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222642 }
2643
[email protected]5e369672009-11-03 23:48:302644 if (data_source) {
2645 NavigationState* state = NavigationState::FromDataSource(data_source);
2646 if (state && state->is_cache_policy_override_set())
2647 request.setCachePolicy(state->cache_policy_override());
2648 }
[email protected]8a3125a712010-08-09 18:58:512649
2650 if (top_data_source) {
2651 NavigationState* state = NavigationState::FromDataSource(top_data_source);
[email protected]61a99dd82011-05-24 19:19:472652 // TODO(gavinp): separate out prefetching and prerender field trials
2653 // if the rel=prerender rel type is sticking around.
2654 if (state && (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2655 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]8a3125a712010-08-09 18:58:512656 state->set_was_prefetcher(true);
2657 }
2658
[email protected]3d9689372009-09-10 04:29:172659 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132660 request.setHasUserGesture(frame->isProcessingUserGesture());
2661
[email protected]0a8db0d2011-04-13 15:15:402662 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132663 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172664}
2665
2666void RenderView::didReceiveResponse(
2667 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492668
[email protected]3d9689372009-09-10 04:29:172669 // Only do this for responses that correspond to a provisional data source
2670 // of the top-most frame. If we have a provisional data source, then we
2671 // can't have any sub-resources yet, so we know that this response must
2672 // correspond to a frame load.
2673 if (!frame->provisionalDataSource() || frame->parent())
2674 return;
2675
2676 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082677 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172678 if (frame->isViewSourceModeEnabled())
2679 return;
2680
[email protected]65041fa2010-05-21 06:56:532681 NavigationState* navigation_state =
2682 NavigationState::FromDataSource(frame->provisionalDataSource());
2683 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082684 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532685
[email protected]972ebdff2010-06-10 22:59:072686 // Record page load flags.
2687 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2688 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572689 navigation_state->set_was_alternate_protocol_available(
2690 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072691 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082692 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092693 // Whether or not the http status code actually corresponds to an error is
2694 // only checked when the page is done loading, if |use_error_page| is
2695 // still true.
2696 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172697}
2698
2699void RenderView::didFinishResourceLoad(
2700 WebFrame* frame, unsigned identifier) {
2701 NavigationState* navigation_state =
2702 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092703 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172704 return;
2705
[email protected]06333afe2011-02-24 14:55:092706 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082707 int http_status_code = navigation_state->http_status_code();
2708 if (http_status_code == 404) {
2709 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412710 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172711
[email protected]b6cb3a842011-06-24 18:28:412712 const GURL& error_page_url =
2713 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092714 if (error_page_url.is_valid()) {
2715 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472716 original_error.domain = "http";
2717 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412718 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172719
[email protected]06333afe2011-02-24 14:55:092720 navigation_state->set_alt_error_page_fetcher(
2721 new AltErrorPageResourceFetcher(
2722 error_page_url, frame, original_error,
2723 NewCallback(this, &RenderView::AltErrorPageFinished)));
2724 return;
2725 }
2726 }
[email protected]3d9689372009-09-10 04:29:172727
[email protected]9966325b2011-04-18 05:00:102728 content::GetContentClient()->renderer()->ShowErrorPage(
2729 this, frame, http_status_code);
[email protected]3d9689372009-09-10 04:29:172730}
2731
2732void RenderView::didFailResourceLoad(
2733 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2734 // Ignore
2735}
2736
2737void RenderView::didLoadResourceFromMemoryCache(
2738 WebFrame* frame, const WebURLRequest& request,
2739 const WebURLResponse& response) {
2740 // Let the browser know we loaded a resource from the memory cache. This
2741 // message is needed to display the correct SSL indicators.
2742 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2743 routing_id_,
2744 request.url(),
[email protected]70435962011-08-02 20:13:282745 response.securityInfo(),
2746 request.httpMethod().utf8(),
2747 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172748}
2749
[email protected]6069da8c2009-10-20 20:33:492750void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292751 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2752}
2753
[email protected]92771112011-01-20 00:13:022754void RenderView::didRunInsecureContent(
2755 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292756 Send(new ViewHostMsg_DidRunInsecureContent(
2757 routing_id_,
[email protected]92771112011-01-20 00:13:022758 origin.toString().utf8(),
2759 target));
[email protected]e3d60e5d2009-09-25 21:08:292760}
2761
[email protected]3d9689372009-09-10 04:29:172762void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2763 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2764}
2765
[email protected]0c882b282009-10-07 17:01:282766void RenderView::didCreateScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032767 content::GetContentClient()->renderer()->DidCreateScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282768}
2769
2770void RenderView::didDestroyScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032771 content::GetContentClient()->renderer()->DidDestroyScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282772}
2773
2774void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032775 content::GetContentClient()->renderer()->DidCreateIsolatedScriptContext(
2776 frame);
[email protected]0c882b282009-10-07 17:01:282777}
2778
[email protected]fc86daa2010-03-30 23:52:532779void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
2780 WebFrame* target,
2781 bool cross_origin,
2782 const WebString& property_name,
2783 unsigned long long event_id) {
[email protected]6cf19311f2011-04-14 23:06:022784 FOR_EACH_OBSERVER(
2785 RenderViewObserver,
2786 observers_,
2787 LogCrossFramePropertyAccess(
2788 frame, target, cross_origin, property_name, event_id));
[email protected]ab9eabac2010-03-16 16:54:102789}
2790
[email protected]d812fd12011-05-27 23:05:072791void RenderView::didUpdateLayout(WebFrame* frame) {
2792 // We don't always want to set up a timer, only if we've been put in that
2793 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172794 // message.
[email protected]705243f2010-05-05 19:58:072795 if (!send_preferred_size_changes_ || !webview())
2796 return;
[email protected]dfca5acf2010-03-22 03:28:432797
[email protected]d812fd12011-05-27 23:05:072798 if (check_preferred_size_timer_.IsRunning())
2799 return;
2800 check_preferred_size_timer_.Start(TimeDelta::FromMilliseconds(0), this,
2801 &RenderView::CheckPreferredSize);
2802}
2803
2804void RenderView::CheckPreferredSize() {
2805 // We don't always want to send the change messages over IPC, only if we've
2806 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2807 // message.
2808 if (!send_preferred_size_changes_ || !webview())
2809 return;
2810
[email protected]705243f2010-05-05 19:58:072811 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2812 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532813
2814 // In the presence of zoom, these sizes are still reported as if unzoomed,
2815 // so we need to adjust.
2816 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2817 size.set_width(static_cast<int>(size.width() * zoom_factor));
2818 size.set_height(static_cast<int>(size.height() * zoom_factor));
2819
[email protected]705243f2010-05-05 19:58:072820 if (size == preferred_size_)
2821 return;
[email protected]c27324b2009-11-19 22:44:292822
[email protected]705243f2010-05-05 19:58:072823 preferred_size_ = size;
2824 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2825 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172826}
2827
[email protected]143dcd592009-11-06 21:33:492828void RenderView::didChangeScrollOffset(WebFrame* frame) {
2829 StartNavStateSyncTimerIfNecessary();
2830}
2831
[email protected]8922e1f2009-10-03 05:01:262832void RenderView::reportFindInPageMatchCount(int request_id, int count,
2833 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112834 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2835 if (!count)
2836 active_match_ordinal = 0;
2837
2838 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2839 routing_id_,
2840 request_id,
2841 count,
2842 gfx::Rect(),
2843 active_match_ordinal,
2844 final_update);
2845
[email protected]8922e1f2009-10-03 05:01:262846 // If we have a message that has been queued up, then we should just replace
2847 // it. The ACK from the browser will make sure it gets sent when the browser
2848 // wants it.
2849 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262850 queued_find_reply_message_.reset(msg);
2851 } else {
2852 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112853 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262854 }
2855}
2856
2857void RenderView::reportFindInPageSelection(int request_id,
2858 int active_match_ordinal,
2859 const WebRect& selection_rect) {
2860 // Send the search result over to the browser process.
2861 Send(new ViewHostMsg_Find_Reply(routing_id_,
2862 request_id,
2863 -1,
2864 selection_rect,
2865 active_match_ordinal,
2866 false));
2867}
2868
[email protected]2b06a992010-08-21 05:48:222869void RenderView::openFileSystem(
2870 WebFrame* frame,
2871 WebFileSystem::Type type,
2872 long long size,
[email protected]d275d7a2010-11-03 01:34:492873 bool create,
[email protected]2b06a992010-08-21 05:48:222874 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082875 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222876
[email protected]b6cb3a842011-06-24 18:28:412877 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082878 if (origin.isEmpty()) {
2879 // Uninitialized document?
2880 callbacks->didFail(WebKit::WebFileErrorAbort);
2881 return;
2882 }
[email protected]2b06a992010-08-21 05:48:222883
[email protected]c5a272d2010-09-27 18:37:082884 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2885 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492886 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222887}
2888
[email protected]10e5cf12011-04-13 04:10:402889void RenderView::queryStorageUsageAndQuota(
2890 WebFrame* frame,
2891 WebStorageQuotaType type,
2892 WebStorageQuotaCallbacks* callbacks) {
2893 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412894 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402895 if (origin.isEmpty()) {
2896 // Uninitialized document?
2897 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2898 return;
2899 }
2900 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:532901 GURL(origin.toString()),
2902 static_cast<quota::StorageType>(type),
2903 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402904}
2905
2906void RenderView::requestStorageQuota(
2907 WebFrame* frame,
2908 WebStorageQuotaType type,
2909 unsigned long long requested_size,
2910 WebStorageQuotaCallbacks* callbacks) {
2911 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412912 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402913 if (origin.isEmpty()) {
2914 // Uninitialized document?
2915 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2916 return;
2917 }
2918 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:532919 routing_id(), GURL(origin.toString()),
2920 static_cast<quota::StorageType>(type), requested_size,
2921 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402922}
2923
[email protected]18d5be92011-07-25 18:00:192924// WebKit::WebPageSerializerClient implementation ------------------------------
2925
2926void RenderView::didSerializeDataForFrame(
2927 const WebURL& frame_url,
2928 const WebCString& data,
2929 WebPageSerializerClient::PageSerializationStatus status) {
2930 Send(new ViewHostMsg_SendSerializedHtmlData(
2931 routing_id(),
2932 frame_url,
2933 data.data(),
2934 static_cast<int32>(status)));
2935}
2936
[email protected]79dbc662009-09-04 05:42:512937// webkit_glue::WebPluginPageDelegate -----------------------------------------
2938
[email protected]191eb3f72010-12-21 06:27:502939webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:532940 const FilePath& file_path,
2941 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:592942 if (!PluginChannelHost::IsListening())
2943 return NULL;
2944
[email protected]00c39612010-03-06 02:53:282945 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:462946 if (in_process_plugin) {
[email protected]6876dff2010-01-15 19:38:092947#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]e8f7a182011-03-10 00:50:222948 return webkit::npapi::WebPluginDelegateImpl::Create(
2949 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092950#else
[email protected]e8f7a182011-03-10 00:50:222951 NOTIMPLEMENTED();
2952 return NULL;
[email protected]7b6616f2010-01-14 18:07:552953#endif
[email protected]f103ab72009-09-02 17:10:592954 }
2955
[email protected]4e0616e2010-05-28 14:55:532956 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592957}
2958
2959void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032960#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592961 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2962 routing_id(), window));
2963#endif
2964}
2965
2966void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032967#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592968 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2969 routing_id(), window));
2970#endif
2971 CleanupWindowInPluginMoves(window);
2972}
2973
[email protected]191eb3f72010-12-21 06:27:502974void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:592975 SchedulePluginMove(move);
2976}
2977
2978void RenderView::DidStartLoadingForPlugin() {
2979 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522980 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592981}
2982
2983void RenderView::DidStopLoadingForPlugin() {
2984 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522985 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592986}
2987
[email protected]b921cfd22010-02-25 16:57:512988WebCookieJar* RenderView::GetCookieJar() {
2989 return &cookie_jar_;
2990}
2991
initial.commit09911bf2008-07-26 23:55:292992void RenderView::SyncNavigationState() {
2993 if (!webview())
2994 return;
2995
[email protected]26aa0482009-09-30 16:55:272996 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172997 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292998 return;
[email protected]ca948a22009-06-25 19:36:172999
3000 Send(new ViewHostMsg_UpdateState(
3001 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293002}
3003
[email protected]7ccddb8c2009-08-04 17:36:553004GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293005 ErrorPageType error_type) {
[email protected]c5c1d6d2011-07-28 18:42:413006
[email protected]7ccddb8c2009-08-04 17:36:553007 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293008 // If the URL that failed was secure, then the embedding web page was not
3009 // expecting a network attacker to be able to manipulate its contents. As
3010 // we fetch alternate error pages over HTTP, we would be allowing a network
3011 // attacker to manipulate the contents of the response if we tried to use
3012 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153013 return GURL();
initial.commit09911bf2008-07-26 23:55:293014 }
3015
[email protected]c5c1d6d2011-07-28 18:42:413016 if (devtools_agent_->IsAttached()) {
3017 // Do not show alternate error page when DevTools is attached.
3018 return GURL();
3019 }
3020
initial.commit09911bf2008-07-26 23:55:293021 // Grab the base URL from the browser process.
3022 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153023 return GURL();
initial.commit09911bf2008-07-26 23:55:293024
3025 // Strip query params from the failed URL.
3026 GURL::Replacements remove_params;
3027 remove_params.ClearUsername();
3028 remove_params.ClearPassword();
3029 remove_params.ClearQuery();
3030 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553031 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503032 std::string spec_to_send = url_to_send.spec();
3033 // Notify link doctor of the url truncation by sending of "?" at the end.
3034 if (failed_url.has_query())
3035 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293036
3037 // Construct the query params to send to link doctor.
3038 std::string params(alternate_error_page_url_.query());
3039 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503040 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293041 params.append("&sourceid=chrome");
3042 params.append("&error=");
3043 switch (error_type) {
3044 case DNS_ERROR:
3045 params.append("dnserror");
3046 break;
3047
3048 case HTTP_404:
3049 params.append("http404");
3050 break;
3051
[email protected]5df266ac2008-10-15 19:50:133052 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333053 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133054 break;
3055
initial.commit09911bf2008-07-26 23:55:293056 default:
3057 NOTREACHED() << "unknown ErrorPageType";
3058 }
3059
3060 // OK, build the final url to return.
3061 GURL::Replacements link_doctor_params;
3062 link_doctor_params.SetQueryStr(params);
3063 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3064 return url;
3065}
3066
[email protected]c50008512011-02-03 01:17:273067WebUIBindings* RenderView::GetWebUIBindings() {
3068 if (!web_ui_bindings_.get()) {
3069 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:463070 }
[email protected]c50008512011-02-03 01:17:273071 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463072}
3073
[email protected]0fdbf8c2010-07-08 20:33:013074WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3075 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493076}
3077
[email protected]6069da8c2009-10-20 20:33:493078void RenderView::OnFind(int request_id, const string16& search_text,
3079 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273080 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493081
[email protected]872542532011-06-23 00:43:163082 // Check if the plugin still exists in the document.
3083 if (main_frame->document().isPluginDocument() &&
3084 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493085 if (options.findNext) {
3086 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013087 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493088 } else {
[email protected]afdbd142010-07-10 08:01:233089 if (GetWebPluginFromPluginDocument()->startFind(
3090 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493091 } else {
[email protected]e7c58a32010-08-13 19:47:113092 // Send "no results".
3093 Send(new ViewHostMsg_Find_Reply(routing_id_,
3094 request_id,
3095 0,
3096 gfx::Rect(),
3097 0,
3098 true));
[email protected]24a7f3c2010-03-25 08:26:493099 }
3100 }
3101 return;
3102 }
3103
[email protected]b4bb2502009-10-01 22:35:273104 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273105 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293106 WebFrame* search_frame = focused_frame; // start searching focused frame.
3107
3108 bool multi_frame = (frame_after_main != main_frame);
3109
3110 // If we have multiple frames, we don't want to wrap the search within the
3111 // frame, so we check here if we only have main_frame in the chain.
3112 bool wrap_within_frame = !multi_frame;
3113
[email protected]b3f2b912009-04-09 16:18:523114 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293115 bool result = false;
3116
[email protected]7830da3e2009-11-06 16:27:263117 // If something is selected when we start searching it means we cannot just
3118 // increment the current match ordinal; we need to re-generate it.
3119 WebRange current_selection = focused_frame->selectionRange();
3120
initial.commit09911bf2008-07-26 23:55:293121 do {
[email protected]dd7daa82009-08-10 05:46:453122 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593123 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293124
3125 if (!result) {
3126 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223127 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293128
3129 // Find the next frame, but skip the invisible ones.
3130 do {
3131 // What is the next frame to search? (we might be going backwards). Note
3132 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593133 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273134 search_frame->traverseNext(true) :
3135 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453136 } while (!search_frame->hasVisibleContent() &&
3137 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293138
[email protected]884db412008-11-24 23:46:503139 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223140 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293141
3142 // If we have multiple frames and we have wrapped back around to the
3143 // focused frame, we need to search it once more allowing wrap within
3144 // the frame, otherwise it will report 'no match' if the focused frame has
3145 // reported matches, but no frames after the focused_frame contain a
3146 // match for the search word(s).
3147 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453148 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593149 request_id, search_text, options, true, // Force wrapping.
3150 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293151 }
3152 }
3153
[email protected]26aa0482009-09-30 16:55:273154 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293155 } while (!result && search_frame != focused_frame);
3156
[email protected]7830da3e2009-11-06 16:27:263157 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293158 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453159 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293160 } else {
3161 // If nothing is found, set result to "0 of 0", otherwise, set it to
3162 // "-1 of 1" to indicate that we found at least one item, but we don't know
3163 // yet what is active.
3164 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3165 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293166
[email protected]4f3dc372009-02-24 00:10:293167 // If we find no matches then this will be our last status update.
3168 // Otherwise the scoping effort will send more results.
3169 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293170
[email protected]4f3dc372009-02-24 00:10:293171 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403172 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593173 request_id,
[email protected]4f3dc372009-02-24 00:10:293174 match_count,
3175 selection_rect,
3176 ordinal,
3177 final_status_update));
initial.commit09911bf2008-07-26 23:55:293178
initial.commit09911bf2008-07-26 23:55:293179 // Scoping effort begins, starting with the mainframe.
3180 search_frame = main_frame;
3181
[email protected]dd7daa82009-08-10 05:46:453182 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293183
3184 do {
3185 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453186 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293187
3188 // We don't start another scoping effort unless at least one match has
3189 // been found.
3190 if (result) {
3191 // Start new scoping request. If the scoping function determines that it
3192 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453193 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593194 search_text,
3195 options,
initial.commit09911bf2008-07-26 23:55:293196 true); // reset the tickmarks
3197 }
3198
3199 // Iterate to the next frame. The frame will not necessarily scope, for
3200 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273201 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293202 } while (search_frame != main_frame);
3203 }
3204}
3205
[email protected]24a7f3c2010-03-25 08:26:493206void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3207 WebView* view = webview();
3208 if (!view)
3209 return;
3210
3211 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163212 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013213 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493214 return;
3215 }
3216
3217 bool clear_selection =
3218 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3219 if (clear_selection)
3220 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3221
3222 WebFrame* frame = view->mainFrame();
3223 while (frame) {
3224 frame->stopFinding(clear_selection);
3225 frame = frame->traverseNext(false);
3226 }
3227
3228 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3229 WebFrame* focused_frame = view->focusedFrame();
3230 if (focused_frame) {
3231 WebDocument doc = focused_frame->document();
3232 if (!doc.isNull()) {
3233 WebNode node = doc.focusedNode();
3234 if (!node.isNull())
3235 node.simulateClick();
3236 }
3237 }
3238 }
3239}
3240
3241void RenderView::OnFindReplyAck() {
3242 // Check if there is any queued up request waiting to be sent.
3243 if (queued_find_reply_message_.get()) {
3244 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423245 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493246 }
3247}
3248
[email protected]0bd753682010-12-16 18:15:523249WebPlugin* RenderView::CreatePepperPlugin(
3250 WebFrame* frame,
3251 const WebPluginParams& params,
3252 const FilePath& path,
3253 webkit::ppapi::PluginModule* pepper_module) {
3254 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:253255 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:093256}
[email protected]00152e92010-07-19 11:47:403257
[email protected]191eb3f72010-12-21 06:27:503258WebPlugin* RenderView::CreateNPAPIPlugin(
3259 WebFrame* frame,
3260 const WebPluginParams& params,
3261 const FilePath& path,
3262 const std::string& mime_type) {
3263 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:083264 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403265}
3266
[email protected]40bd6582009-12-04 23:49:513267void RenderView::OnZoom(PageZoom::Function function) {
3268 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3269 return;
3270
[email protected]258d31122010-05-09 10:59:413271 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523272
[email protected]b75b8292010-10-01 07:28:253273 double old_zoom_level = webview()->zoomLevel();
3274 double zoom_level;
3275 if (function == PageZoom::RESET) {
3276 zoom_level = 0;
3277 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3278 // Previous zoom level is a whole number, so just increment/decrement.
3279 zoom_level = old_zoom_level + function;
3280 } else {
3281 // Either the user hit the zoom factor limit and thus the zoom level is now
3282 // not a whole number, or a plugin changed it to a custom value. We want
3283 // to go to the next whole number so that the user can always get back to
3284 // 100% with the keyboard/menu.
3285 if ((old_zoom_level > 1 && function > 0) ||
3286 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453287 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253288 } else {
3289 // We're going towards 100%, so first go to the next whole number.
3290 zoom_level = static_cast<int>(old_zoom_level);
3291 }
3292 }
[email protected]40bd6582009-12-04 23:49:513293
[email protected]b75b8292010-10-01 07:28:253294 webview()->setZoomLevel(false, zoom_level);
3295 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513296}
3297
[email protected]d0b8d092010-10-25 04:05:173298void RenderView::OnSetZoomLevel(double zoom_level) {
3299 // Don't set zoom level for full-page plugin since they don't use the same
3300 // zoom settings.
3301 if (webview()->mainFrame()->document().isPluginDocument())
3302 return;
3303
3304 webview()->hidePopups();
3305 webview()->setZoomLevel(false, zoom_level);
3306 zoomLevelChanged();
3307}
3308
[email protected]9d797f32010-04-23 07:17:543309void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:253310 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543311 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293312}
3313
[email protected]41fc0322009-09-04 22:23:403314void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273315 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293316}
3317
[email protected]a697f4c2009-09-14 22:30:183318void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273319 WebString no_encoding;
3320 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183321}
3322
[email protected]dd7daa82009-08-10 05:46:453323WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3324 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273325 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453326
3327 // xpath string can represent a frame deep down the tree (across multiple
3328 // frame DOMs).
3329 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3330 // should break into 2 xpaths
3331 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3332
[email protected]26aa0482009-09-30 16:55:273333 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453334
3335 std::wstring xpath_remaining = xpath;
3336 while (!xpath_remaining.empty()) {
3337 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3338 std::wstring xpath_child;
3339 if (delim_pos != std::wstring::npos) {
3340 xpath_child = xpath_remaining.substr(0, delim_pos);
3341 xpath_remaining.erase(0, delim_pos + 1);
3342 } else {
3343 xpath_remaining.swap(xpath_child);
3344 }
3345 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293346 }
3347
[email protected]dd7daa82009-08-10 05:46:453348 return frame;
initial.commit09911bf2008-07-26 23:55:293349}
3350
[email protected]13a1e4c3c2011-02-03 21:07:093351WebNode RenderView::GetFocusedNode() const {
3352 if (!webview())
3353 return WebNode();
3354 WebFrame* focused_frame = webview()->focusedFrame();
3355 if (focused_frame) {
3356 WebDocument doc = focused_frame->document();
3357 if (!doc.isNull())
3358 return doc.focusedNode();
3359 }
3360
3361 return WebNode();
3362}
3363
[email protected]38b592902011-04-16 02:08:423364bool RenderView::IsEditableNode(const WebNode& node) {
3365 bool is_editable_node = false;
3366 if (!node.isNull()) {
3367 if (node.isContentEditable()) {
3368 is_editable_node = true;
3369 } else if (node.isElementNode()) {
3370 is_editable_node =
3371 node.toConst<WebElement>().isTextFormControlElement();
3372 }
3373 }
3374 return is_editable_node;
3375}
3376
[email protected]882b7b22010-10-05 03:34:533377void RenderView::EvaluateScript(const string16& frame_xpath,
3378 const string16& script,
3379 int id,
3380 bool notify_result) {
3381 v8::Handle<v8::Value> result;
3382 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
3383 if (web_frame)
3384 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
3385 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:293386 ListValue list;
[email protected]cd326242011-06-16 01:55:463387 if (!result.IsEmpty() && web_frame) {
[email protected]81f9fe0b2010-12-07 00:35:293388 v8::HandleScope handle_scope;
3389 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3390 v8::Context::Scope context_scope(context);
[email protected]b1cf3372011-04-20 21:28:103391 V8ValueConverter converter;
3392 converter.set_allow_date(true);
3393 converter.set_allow_regexp(true);
3394 list.Set(0, converter.FromV8Value(result, context));
[email protected]81f9fe0b2010-12-07 00:35:293395 } else {
3396 list.Set(0, Value::CreateNullValue());
3397 }
3398 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:533399 }
initial.commit09911bf2008-07-26 23:55:293400}
3401
[email protected]882b7b22010-10-05 03:34:533402void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
3403 const string16& jscript,
3404 int id,
3405 bool notify_result) {
3406 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293407}
3408
[email protected]1810e132009-03-24 23:35:483409void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]01cf589c2011-07-28 18:04:033410 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413411 WebFrame* frame = GetChildFrame(frame_xpath);
3412 if (!frame)
[email protected]216813952011-05-19 22:21:263413 return;
[email protected]ae461542009-06-19 19:03:413414
[email protected]01cf589c2011-07-28 18:04:033415 frame->document().insertUserStyleSheet(
3416 WebString::fromUTF8(css),
3417 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483418}
3419
[email protected]81e63782009-02-27 19:35:093420void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3421 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293422}
3423
[email protected]d0980792011-02-13 19:41:403424void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:293425 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:553426 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:273427 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293428}
3429
3430void RenderView::OnReservePageIDRange(int size_of_range) {
3431 next_page_id_ += size_of_range + 1;
3432}
3433
[email protected]59f4f2fa2011-03-23 01:00:553434void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
3435 const gfx::Point& client_point,
3436 const gfx::Point& screen_point,
3437 WebDragOperationsMask ops) {
3438 WebDragOperation operation = webview()->dragTargetDragEnter(
3439 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553440 client_point,
3441 screen_point,
3442 ops);
3443
3444 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3445}
3446
3447void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
3448 const gfx::Point& screen_point,
3449 WebDragOperationsMask ops) {
3450 WebDragOperation operation = webview()->dragTargetDragOver(
3451 client_point,
3452 screen_point,
3453 ops);
3454
3455 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3456}
3457
3458void RenderView::OnDragTargetDragLeave() {
3459 webview()->dragTargetDragLeave();
3460}
3461
3462void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3463 const gfx::Point& screen_point) {
3464 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573465
3466 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553467}
3468
[email protected]e80c73b2009-04-07 23:24:583469void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3470 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253471 bool ended,
3472 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033473 if (ended) {
[email protected]26aa0482009-09-30 16:55:273474 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203475 } else {
3476 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033477 }
initial.commit09911bf2008-07-26 23:55:293478}
3479
3480void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273481 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293482}
3483
initial.commit09911bf2008-07-26 23:55:293484void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593485 webkit_preferences_ = prefs;
3486 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293487}
3488
[email protected]08bb1e722011-07-30 19:13:043489void RenderView::OnUpdateRemoteAccessClientFirewallTraversal(
3490 const std::string& policy) {
3491 pepper_delegate_.PublishPolicy(policy);
3492}
3493
initial.commit09911bf2008-07-26 23:55:293494void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3495 alternate_error_page_url_ = url;
3496}
3497
[email protected]b29aa74b2011-01-31 21:41:083498void RenderView::OnCustomContextMenuAction(
3499 const webkit_glue::CustomContextMenuContext& custom_context,
3500 unsigned action) {
3501 if (custom_context.is_pepper_menu)
3502 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3503 else
3504 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:333505}
3506
initial.commit09911bf2008-07-26 23:55:293507void RenderView::OnInstallMissingPlugin() {
3508 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593509 if (first_default_plugin_)
3510 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293511}
3512
[email protected]600ea402011-04-12 00:01:513513void RenderView::OnEnumerateDirectoryResponse(
3514 int id,
3515 const std::vector<FilePath>& paths) {
3516 if (!enumeration_completions_[id])
3517 return;
3518
3519 WebVector<WebString> ws_file_names(paths.size());
3520 for (size_t i = 0; i < paths.size(); ++i)
3521 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3522
3523 enumeration_completions_[id]->didChooseFile(ws_file_names);
3524 enumeration_completions_.erase(id);
3525}
3526
[email protected]cdaf8d02010-03-30 19:52:473527void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363528 // This could happen if we navigated to a different page before the user
3529 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473530 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363531 return;
3532
[email protected]cdaf8d02010-03-30 19:52:473533 WebVector<WebString> ws_file_names(paths.size());
3534 for (size_t i = 0; i < paths.size(); ++i)
3535 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463536
[email protected]cdaf8d02010-03-30 19:52:473537 if (file_chooser_completions_.front()->completion)
3538 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3539 file_chooser_completions_.pop_front();
3540
3541 // If there are more pending file chooser requests, schedule one now.
3542 if (!file_chooser_completions_.empty()) {
3543 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3544 file_chooser_completions_.front()->params));
3545 }
initial.commit09911bf2008-07-26 23:55:293546}
3547
[email protected]770dd8b2010-05-24 18:11:393548void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3549 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243550 if (send_preferred_size_changes_)
3551 return;
[email protected]9fb325e2010-05-06 18:23:243552 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393553
[email protected]d812fd12011-05-27 23:05:073554 // Start off with an initial preferred size notification (in case
3555 // |didUpdateLayout| was already called).
3556 if (webview())
3557 didUpdateLayout(webview()->mainFrame());
[email protected]0666aef2009-05-13 19:48:083558}
3559
[email protected]cda45c02010-02-25 19:28:103560void RenderView::OnDisableScrollbarsForSmallWindows(
3561 const gfx::Size& disable_scrollbar_size_limit) {
3562 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3563}
3564
[email protected]80d96fa2009-06-10 22:34:513565void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3566 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373567 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133568#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413569 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3570 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463571 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513572 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343573 renderer_prefs.thumb_inactive_color,
3574 renderer_prefs.thumb_active_color,
3575 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323576
[email protected]644d77e2010-01-27 01:03:103577 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323578 webview()->setScrollbarColors(
3579 renderer_prefs.thumb_inactive_color,
3580 renderer_prefs.thumb_active_color,
3581 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103582 webview()->setSelectionColors(
3583 renderer_prefs.active_selection_bg_color,
3584 renderer_prefs.active_selection_fg_color,
3585 renderer_prefs.inactive_selection_bg_color,
3586 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463587 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103588 }
[email protected]7a74e102009-09-03 00:16:563589#endif
[email protected]80d96fa2009-06-10 22:34:513590}
3591
[email protected]952cb702009-10-07 05:50:283592void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3593 const WebMediaPlayerAction& action) {
3594 if (webview())
3595 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563596}
3597
[email protected]dea2d372010-09-25 06:41:143598void RenderView::OnEnableAccessibility() {
3599 if (WebAccessibilityCache::accessibilityEnabled())
3600 return;
[email protected]9f4db512010-05-10 20:21:413601
[email protected]dea2d372010-09-25 06:41:143602 WebAccessibilityCache::enableAccessibility();
3603
3604 if (webview()) {
3605 // It's possible that the webview has already loaded a webpage without
3606 // accessibility being enabled. Initialize the browser's cached
3607 // accessibility tree by sending it a 'load complete' notification.
3608 postAccessibilityNotification(
3609 webview()->accessibilityObject(),
3610 WebKit::WebAccessibilityNotificationLoadComplete);
3611 }
[email protected]266eb6f2008-09-30 23:56:503612}
3613
[email protected]aef92842010-05-21 16:54:363614void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
3615 if (!accessibility_.get())
3616 return;
[email protected]02ea2f312010-09-27 17:03:363617
3618 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3619 WebAccessibilityObject root = webview()->accessibilityObject();
3620 if (!obj.isValid() || !root.isValid())
3621 return;
3622
3623 // By convention, calling SetFocus on the root of the tree should clear the
3624 // current focus. Otherwise set the focus to the new node.
3625 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
3626 webview()->clearFocusedNode();
3627 else
3628 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:363629}
3630
3631void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
3632 if (!accessibility_.get())
3633 return;
[email protected]02ea2f312010-09-27 17:03:363634
3635 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3636 if (!obj.isValid())
3637 return;
3638
3639 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:363640}
3641
[email protected]9892b472010-09-16 00:23:423642void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:513643 DCHECK(accessibility_ack_pending_);
3644 accessibility_ack_pending_ = false;
3645 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:313646}
3647
[email protected]18d5be92011-07-25 18:00:193648void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3649 const GURL& page_url) {
3650 // Prepare list to storage all savable resource links.
3651 std::vector<GURL> resources_list;
3652 std::vector<GURL> referrers_list;
3653 std::vector<GURL> frames_list;
3654 webkit_glue::SavableResourcesResult result(&resources_list,
3655 &referrers_list,
3656 &frames_list);
3657
3658 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3659 webview(),
3660 page_url,
3661 &result,
3662 chrome::kSavableSchemes)) {
3663 // If something is wrong when collecting all savable resource links,
3664 // send empty list to embedder(browser) to tell it failed.
3665 referrers_list.clear();
3666 resources_list.clear();
3667 frames_list.clear();
3668 }
3669
3670 // Send result of all savable resource links to embedder.
3671 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3672 resources_list,
3673 referrers_list,
3674 frames_list));
3675}
3676
3677void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
3678 const std::vector<GURL>& links,
3679 const std::vector<FilePath>& local_paths,
3680 const FilePath& local_directory_name) {
3681
3682 // Convert std::vector of GURLs to WebVector<WebURL>
3683 WebVector<WebURL> weburl_links(links);
3684
3685 // Convert std::vector of std::strings to WebVector<WebString>
3686 WebVector<WebString> webstring_paths(local_paths.size());
3687 for (size_t i = 0; i < local_paths.size(); i++)
3688 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3689
3690 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
3691 webstring_paths,
3692 webkit_glue::FilePathToWebString(
3693 local_directory_name));
3694}
3695
[email protected]9b18a84f2010-06-10 15:54:043696void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273697 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473698 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293699}
3700
[email protected]992db4c2011-05-12 15:37:153701void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3702 if (is_swapped_out_)
3703 return;
3704
3705 // Swap this RenderView out so the tab can navigate to a page rendered by a
3706 // different process. This involves running the unload handler and clearing
3707 // the page. Once WasSwappedOut is called, we also allow this process to exit
3708 // if there are no other active RenderViews in it.
3709
3710 // Send an UpdateState message before we get swapped out.
3711 SyncNavigationState();
3712
3713 // Synchronously run the unload handler before sending the ACK.
3714 webview()->dispatchUnloadEvent();
3715
3716 // Swap out and stop sending any IPC messages that are not ACKs.
3717 SetSwappedOut(true);
3718
3719 // Replace the page with a blank dummy URL. The unload handler will not be
3720 // run a second time, thanks to a check in FrameLoader::stopLoading.
3721 // TODO(creis): Need to add a better way to do this that avoids running the
3722 // beforeunload handler. For now, we just run it a second time silently.
3723 webview()->mainFrame()->loadHTMLString(std::string(),
3724 GURL("about:swappedout"),
3725 GURL("about:swappedout"),
3726 false);
3727
3728 // Just echo back the params in the ACK.
3729 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3730}
3731
3732void RenderView::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:293733 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3734 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3735 // in the onunload handler from appearing. For now, we're bypassing that and
3736 // calling the FrameLoader's CloseURL method directly. This should be
3737 // revisited to avoid having two ways to close a page. Having a single way
3738 // to close that can run onunload is also useful for fixing
3739 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273740 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293741
[email protected]992db4c2011-05-12 15:37:153742 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293743}
3744
3745void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573746#if defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163747 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463748 if (webview())
3749 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573750#else // defined(OS_WIN)
3751 // TODO(port): we don't support theming on non-Windows platforms yet
3752 NOTIMPLEMENTED();
3753#endif
initial.commit09911bf2008-07-26 23:55:293754}
3755
[email protected]0aa55312008-10-17 21:53:083756void RenderView::OnDisassociateFromPopupCount() {
3757 if (decrement_shared_popup_at_destruction_)
3758 shared_popup_counter_->data--;
3759 shared_popup_counter_ = new SharedRenderViewCounter(0);
3760 decrement_shared_popup_at_destruction_ = false;
3761}
3762
[email protected]15d79e12009-08-02 19:23:453763bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3764 const WebURLError& error,
3765 bool replace) {
3766 // We only show alternate error pages in the main frame. They are
3767 // intended to assist the user when navigating, so there is not much
3768 // value in showing them for failed subframes. Ideally, we would be
3769 // able to use the TYPED transition type for this, but that flag is
3770 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453771 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453772 return false;
3773
3774 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373775 // connection failure.
[email protected]15d79e12009-08-02 19:23:453776 int ec = error.reason;
3777 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3778 ec != net::ERR_CONNECTION_FAILED &&
3779 ec != net::ERR_CONNECTION_REFUSED &&
3780 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373781 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453782 return false;
3783
3784 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553785 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453786 if (!error_page_url.is_valid())
3787 return false;
3788
3789 // Load an empty page first so there is an immediate response to the error,
3790 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453791 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363792 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453793 error.unreachableURL,
3794 replace);
3795
3796 // Now, create a fetcher for the error page and associate it with the data
3797 // source we just created via the LoadHTMLString call. That way if another
3798 // navigation occurs, the fetcher will get destroyed.
3799 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453800 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453801 navigation_state->set_alt_error_page_fetcher(
3802 new AltErrorPageResourceFetcher(
3803 error_page_url, frame, error,
3804 NewCallback(this, &RenderView::AltErrorPageFinished)));
3805 return true;
3806}
3807
[email protected]15d79e12009-08-02 19:23:453808void RenderView::AltErrorPageFinished(WebFrame* frame,
3809 const WebURLError& original_error,
3810 const std::string& html) {
3811 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093812 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553813 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093814 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453815}
3816
[email protected]30f75e62009-02-25 22:01:003817void RenderView::OnMoveOrResizeStarted() {
3818 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473819 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003820}
3821
[email protected]30f75e62009-02-25 22:01:003822void RenderView::OnResize(const gfx::Size& new_size,
3823 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103824 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473825 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103826 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203827 webview()->mainFrame()->setCanHaveScrollbars(
3828 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103829 }
3830 }
3831
[email protected]30f75e62009-02-25 22:01:003832 RenderWidget::OnResize(new_size, resizer_rect);
3833}
[email protected]0aa477bd2009-03-23 22:21:433834
[email protected]00c39612010-03-06 02:53:283835void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013836 // Notify the pepper plugins that we started painting.
3837 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283838}
3839
3840void RenderView::DidFlushPaint() {
3841 // Notify any pepper plugins that we painted. This will call into the plugin,
3842 // and we it may ask to close itself as a result. This will, in turn, modify
3843 // our set, possibly invalidating the iterator. So we iterate on a copy that
3844 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013845 pepper_delegate_.ViewFlushedPaint();
3846
[email protected]00c39612010-03-06 02:53:283847 WebFrame* main_frame = webview()->mainFrame();
3848
3849 // If we have a provisional frame we are between the start and commit stages
3850 // of loading and we don't want to save stats.
3851 if (!main_frame->provisionalDataSource()) {
3852 WebDataSource* ds = main_frame->dataSource();
3853 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3854 DCHECK(navigation_state);
3855
[email protected]05c8e502010-08-15 15:13:523856 // TODO(jar): The following code should all be inside a method, probably in
3857 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283858 Time now = Time::Now();
3859 if (navigation_state->first_paint_time().is_null()) {
3860 navigation_state->set_first_paint_time(now);
3861 }
3862 if (navigation_state->first_paint_after_load_time().is_null() &&
3863 !navigation_state->finish_load_time().is_null()) {
3864 navigation_state->set_first_paint_after_load_time(now);
3865 }
3866 }
3867}
3868
[email protected]37a6f302011-07-11 23:43:083869void RenderView::OnViewContextSwapBuffersPosted() {
3870 RenderWidget::OnSwapBuffersPosted();
3871}
3872
[email protected]65225772011-05-12 21:10:243873void RenderView::OnViewContextSwapBuffersComplete() {
3874 RenderWidget::OnSwapBuffersComplete();
3875}
3876
3877void RenderView::OnViewContextSwapBuffersAborted() {
3878 RenderWidget::OnSwapBuffersAborted();
3879}
3880
[email protected]719b36f2010-12-22 20:36:463881webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:153882 const gfx::Rect& paint_bounds,
3883 TransportDIB** dib,
3884 gfx::Rect* location,
3885 gfx::Rect* clip) {
3886 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
3887 paint_bounds, dib, location, clip);
3888}
3889
[email protected]bcaf2272011-02-15 15:29:433890gfx::Point RenderView::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:073891 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:433892 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523893}
3894
[email protected]05d478752009-04-08 23:38:163895void RenderView::OnClearFocusedNode() {
3896 if (webview())
[email protected]26aa0482009-09-30 16:55:273897 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163898}
3899
[email protected]699ab0d2009-04-23 23:19:143900void RenderView::OnSetBackground(const SkBitmap& background) {
3901 if (webview())
[email protected]b4bb2502009-10-01 22:35:273902 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143903
3904 SetBackground(background);
3905}
3906
[email protected]8c66c5a2009-07-22 17:26:343907void RenderView::OnSetActive(bool active) {
3908 if (webview())
[email protected]b4bb2502009-10-01 22:35:273909 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263910
3911#if defined(OS_MACOSX)
3912 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3913 for (plugin_it = plugin_delegates_.begin();
3914 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3915 (*plugin_it)->SetWindowFocus(active);
3916 }
3917#endif
[email protected]8c66c5a2009-07-22 17:26:343918}
3919
[email protected]6ce7abc52010-02-02 18:40:143920#if defined(OS_MACOSX)
3921void RenderView::OnSetWindowVisibility(bool visible) {
3922 // Inform plugins that their container has changed visibility.
3923 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3924 for (plugin_it = plugin_delegates_.begin();
3925 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3926 (*plugin_it)->SetContainerVisibility(visible);
3927 }
3928}
[email protected]1e6e3c992010-02-08 15:52:133929
[email protected]4d51d5bf2010-07-26 18:48:263930void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
3931 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:133932 // Inform plugins that their window's frame has changed.
3933 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3934 for (plugin_it = plugin_delegates_.begin();
3935 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3936 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3937 }
3938}
[email protected]935d63d2010-10-15 23:31:553939
[email protected]b7f75862011-01-21 21:15:133940void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:553941 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:133942 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:553943 // applies to it or not, so inform all the delegates.
3944 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3945 for (plugin_it = plugin_delegates_.begin();
3946 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:133947 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:553948 }
3949}
[email protected]6ce7abc52010-02-02 18:40:143950#endif // OS_MACOSX
3951
[email protected]9892b472010-09-16 00:23:423952void RenderView::postAccessibilityNotification(
3953 const WebAccessibilityObject& obj,
3954 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:143955 if (!accessibility_.get() && webview()) {
3956 // Load complete should be our first notification sent.
3957 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
3958 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
3959 return;
3960
3961 // Create and initialize our accessibility cache
3962 accessibility_.reset(WebAccessibilityCache::create());
3963 accessibility_->initialize(webview());
3964 }
3965
[email protected]a3fa4f92010-09-30 22:19:333966 if (!accessibility_->isCached(obj)) {
3967 // The browser doesn't know about objects that are not in the cache. Send a
3968 // children change for the first accestor that actually is in the cache.
3969 WebAccessibilityObject parent = obj;
3970 while (parent.isValid() && !accessibility_->isCached(parent))
3971 parent = parent.parentObject();
3972
3973 DCHECK(parent.isValid() && accessibility_->isCached(parent));
3974 if (!parent.isValid())
3975 return;
3976 postAccessibilityNotification(
3977 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
3978
3979 // The parent's children change takes care of the child's children change.
3980 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
3981 return;
3982 }
3983
[email protected]dea2d372010-09-25 06:41:143984 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:513985 RendererAccessibilityNotification acc_notification;
3986 acc_notification.id = accessibility_->addOrGetId(obj);
[email protected]a527a022011-02-10 02:32:363987 acc_notification.type = notification;
[email protected]54ec7f82010-10-21 22:32:513988 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:483989 return;
3990
[email protected]fffaf972011-03-24 01:34:353991 ViewHostMsg_AccessibilityNotification_Type::Value temp;
[email protected]a527a022011-02-10 02:32:363992 if (!WebAccessibilityNotificationToViewHostMsg(notification, &temp))
[email protected]54ec7f82010-10-21 22:32:513993 return;
[email protected]54ec7f82010-10-21 22:32:513994
3995 // Discard duplicate accessibility notifications.
3996 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
3997 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
3998 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:423999 return;
[email protected]54ec7f82010-10-21 22:32:514000 }
[email protected]9892b472010-09-16 00:23:424001 }
[email protected]54ec7f82010-10-21 22:32:514002 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:484003
[email protected]54ec7f82010-10-21 22:32:514004 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
4005 // When no accessibility notifications are in-flight post a task to send
4006 // the notifications to the browser. We use PostTask so that we can queue
4007 // up additional notifications.
4008 MessageLoop::current()->PostTask(
4009 FROM_HERE,
4010 accessibility_method_factory_.NewRunnableMethod(
4011 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:314012 }
[email protected]520cb7d72010-08-31 11:54:314013}
4014
[email protected]446705872009-09-10 07:22:484015void RenderView::OnSetEditCommandsForNextKeyEvent(
4016 const EditCommands& edit_commands) {
4017 edit_commands_ = edit_commands;
4018}
4019
[email protected]60c42a8c72009-10-09 04:08:594020void RenderView::Close() {
4021 // We need to grab a pointer to the doomed WebView before we destroy it.
4022 WebView* doomed = webview();
4023 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494024 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594025}
4026
[email protected]446705872009-09-10 07:22:484027void RenderView::DidHandleKeyEvent() {
4028 edit_commands_.clear();
4029}
4030
[email protected]6a8ddba52010-09-05 04:38:064031void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514032 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064033}
4034
[email protected]941e4552010-02-01 21:23:434035void RenderView::OnWasHidden() {
4036 RenderWidget::OnWasHidden();
4037
[email protected]a6939ca42011-02-18 17:58:074038 if (webview()) {
4039 webview()->settings()->setMinimumTimerInterval(
4040 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444041 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074042 }
4043
4044#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434045 // Inform plugins that their container is no longer visible.
4046 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4047 for (plugin_it = plugin_delegates_.begin();
4048 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4049 (*plugin_it)->SetContainerVisibility(false);
4050 }
[email protected]a6939ca42011-02-18 17:58:074051#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434052}
4053
4054void RenderView::OnWasRestored(bool needs_repainting) {
4055 RenderWidget::OnWasRestored(needs_repainting);
4056
[email protected]a6939ca42011-02-18 17:58:074057 if (webview()) {
4058 webview()->settings()->setMinimumTimerInterval(
4059 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444060 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074061 }
4062
4063#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434064 // Inform plugins that their container is now visible.
4065 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4066 for (plugin_it = plugin_delegates_.begin();
4067 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4068 (*plugin_it)->SetContainerVisibility(true);
4069 }
[email protected]784ea1ab2010-09-18 00:02:344070#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074071}
[email protected]1e6e3c992010-02-08 15:52:134072
[email protected]65225772011-05-12 21:10:244073bool RenderView::SupportsAsynchronousSwapBuffers() {
4074 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4075 if (!context)
4076 return false;
4077 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4078 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4079 std::string::npos;
4080}
4081
[email protected]1e6e3c992010-02-08 15:52:134082void RenderView::OnSetFocus(bool enable) {
4083 RenderWidget::OnSetFocus(enable);
4084
[email protected]7d3c02c2010-05-05 23:10:314085 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074086 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134087 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4088 for (plugin_it = plugin_delegates_.begin();
4089 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344090#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314091 // RenderWidget's call to setFocus can cause the underlying webview's
4092 // activation state to change just like a call to setIsActive.
4093 if (enable)
4094 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344095#endif
[email protected]7d3c02c2010-05-05 23:10:314096 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134097 }
[email protected]589621b2010-09-23 22:01:074098
4099 // Notify all Pepper plugins.
4100 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134101 }
4102}
[email protected]941e4552010-02-01 21:23:434103
[email protected]56ea1a62011-05-30 07:05:574104void RenderView::PpapiPluginFocusChanged() {
4105 UpdateInputMethod();
4106}
4107
[email protected]08bb1e722011-07-30 19:13:044108void RenderView::RequestRemoteAccessClientFirewallTraversal() {
4109 Send(new ViewHostMsg_RequestRemoteAccessClientFirewallTraversal(routing_id_));
4110}
4111
[email protected]56ea1a62011-05-30 07:05:574112void RenderView::OnImeSetComposition(
4113 const string16& text,
4114 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4115 int selection_start,
4116 int selection_end) {
4117 // Until PPAPI has an interface for handling IME events, we skip sending
4118 // OnImeSetComposition. Otherwise the composition is canceled when a
4119 // non-editable DOM element is focused.
4120 //
4121 // TODO(kinaba) This temporal remedy can be removed after PPAPI is extended
4122 // with an IME handling interface.
4123 if (!pepper_delegate_.IsPluginFocused()) {
4124 RenderWidget::OnImeSetComposition(text,
4125 underlines,
4126 selection_start,
4127 selection_end);
4128 }
4129}
4130
4131void RenderView::OnImeConfirmComposition(const string16& text) {
4132 if (pepper_delegate_.IsPluginFocused()) {
4133 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4134 // send character events.
4135 for (size_t i = 0; i < text.size(); ++i) {
4136 WebKit::WebKeyboardEvent char_event;
4137 char_event.type = WebKit::WebInputEvent::Char;
4138 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
4139 char_event.modifiers = 0;
4140 char_event.windowsKeyCode = text[i];
4141 char_event.nativeKeyCode = text[i];
4142 char_event.text[0] = text[i];
4143 char_event.unmodifiedText[0] = text[i];
4144 if (webwidget_)
4145 webwidget_->handleInputEvent(char_event);
4146 }
4147 } else {
4148 RenderWidget::OnImeConfirmComposition(text);
4149 }
4150}
4151
[email protected]ad26ef42011-06-17 07:59:454152ui::TextInputType RenderView::GetTextInputType() {
[email protected]56ea1a62011-05-30 07:05:574153 if (pepper_delegate_.IsPluginFocused()) {
4154 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4155 // consider all the parts of PPAPI plugins are accepting text inputs.
[email protected]ad26ef42011-06-17 07:59:454156 return ui::TEXT_INPUT_TYPE_TEXT;
[email protected]56ea1a62011-05-30 07:05:574157 }
[email protected]ad26ef42011-06-17 07:59:454158 return RenderWidget::GetTextInputType();
4159}
4160
4161bool RenderView::CanComposeInline() {
4162 if (pepper_delegate_.IsPluginFocused()) {
4163 // TODO(kinaba) Until PPAPI has an interface for handling IME events, there
4164 // is no way for the browser to know whether the plugin is capable of
4165 // drawing composition text. We assume plugins are incapable and let the
4166 // browser handle composition display for now.
4167 return false;
4168 }
4169 return true;
[email protected]56ea1a62011-05-30 07:05:574170}
4171
[email protected]43f28f832010-02-03 02:28:484172#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:134173void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
4174 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4175 focused, plugin_id);
4176 Send(msg);
4177}
4178
4179void RenderView::StartPluginIme() {
4180 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554181 // This message can be sent during event-handling, and needs to be delivered
4182 // within that context.
4183 msg->set_unblock(true);
4184 Send(msg);
4185}
4186
[email protected]ea04a4e12010-04-15 00:58:034187gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234188 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484189 gfx::PluginWindowHandle window = NULL;
4190 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234191 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114192 if (window) {
4193 fake_plugin_window_handles_.insert(window);
4194 }
[email protected]43f28f832010-02-03 02:28:484195 return window;
4196}
4197
4198void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114199 if (window && fake_plugin_window_handles_.find(window) !=
4200 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484201 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114202 fake_plugin_window_handles_.erase(window);
4203 }
[email protected]43f28f832010-02-03 02:28:484204}
4205
[email protected]44ce0b12010-03-12 16:45:334206void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4207 int32 width,
4208 int32 height,
4209 uint64 io_surface_identifier) {
4210 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484211 routing_id(), window, width, height, io_surface_identifier));
4212}
4213
[email protected]44ce0b12010-03-12 16:45:334214void RenderView::AcceleratedSurfaceSetTransportDIB(
4215 gfx::PluginWindowHandle window,
4216 int32 width,
4217 int32 height,
4218 TransportDIB::Handle transport_dib) {
4219 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074220 routing_id(), window, width, height, transport_dib));
4221}
4222
[email protected]44ce0b12010-03-12 16:45:334223TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4224 size_t size) {
[email protected]1aef98132010-02-23 18:00:074225 TransportDIB::Handle dib_handle;
4226 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384227 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074228 return dib_handle;
4229 // Return an invalid handle if Send() fails.
4230 return TransportDIB::DefaultHandleValue();
4231}
4232
[email protected]44ce0b12010-03-12 16:45:334233void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074234 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4235}
4236
[email protected]44ce0b12010-03-12 16:45:334237void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144238 gfx::PluginWindowHandle window, uint64 surface_id) {
4239 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4240 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484241}
4242#endif
[email protected]58c321d2010-02-19 12:11:284243
[email protected]cdaf8d02010-03-30 19:52:474244bool RenderView::ScheduleFileChooser(
4245 const ViewHostMsg_RunFileChooser_Params& params,
4246 WebFileChooserCompletion* completion) {
4247 static const size_t kMaximumPendingFileChooseRequests = 4;
4248 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4249 // This sanity check prevents too many file choose requests from getting
4250 // queued which could DoS the user. Getting these is most likely a
4251 // programming error (there are many ways to DoS the user so it's not
4252 // considered a "real" security check), either in JS requesting many file
4253 // choosers to pop up, or in a plugin.
4254 //
4255 // TODO(brettw) we might possibly want to require a user gesture to open
4256 // a file picker, which will address this issue in a better way.
4257 return false;
4258 }
4259
4260 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4261 new PendingFileChooser(params, completion)));
4262 if (file_chooser_completions_.size() == 1) {
4263 // Actually show the browse dialog when this is the first request.
4264 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4265 }
4266 return true;
4267}
4268
[email protected]0ff0ff32010-12-21 19:34:424269WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514270 if (!geolocation_dispatcher_)
4271 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4272 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254273}
[email protected]61c9f032010-03-31 23:04:194274
[email protected]638694c2010-08-04 22:24:114275WebKit::WebSpeechInputController* RenderView::speechInputController(
4276 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:514277 if (!speech_input_dispatcher_)
4278 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
4279 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114280}
4281
[email protected]57ead352010-08-11 14:42:534282WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514283 if (!device_orientation_dispatcher_)
4284 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4285 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534286}
4287
[email protected]b75b8292010-10-01 07:28:254288void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
4289 // For now, don't remember plugin zoom values. We don't want to mix them with
4290 // normal web content (i.e. a fixed layout plugin would usually want them
4291 // different).
4292 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4293
[email protected]b75b8292010-10-01 07:28:254294 int minimum_percent = static_cast<int>(
4295 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4296 int maximum_percent = static_cast<int>(
4297 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254298
4299 Send(new ViewHostMsg_UpdateZoomLimits(
4300 routing_id_, minimum_percent, maximum_percent, remember));
4301}
4302
4303void RenderView::zoomLevelChanged() {
4304 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4305
[email protected]b75b8292010-10-01 07:28:254306 // Tell the browser which url got zoomed so it can update the menu and the
4307 // saved values if necessary
4308 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:414309 routing_id_, webview()->zoomLevel(), remember,
[email protected]b6cb3a842011-06-24 18:28:414310 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254311}
4312
[email protected]a6d36cc2011-02-23 00:39:484313void RenderView::registerProtocolHandler(const WebString& scheme,
4314 const WebString& base_url,
4315 const WebString& url,
4316 const WebString& title) {
4317 GURL base(base_url);
4318 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4319 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4320 return;
4321 }
4322 RenderThread::current()->Send(
4323 new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4324 UTF16ToUTF8(scheme),
4325 absolute_url,
4326 title));
4327}
4328
[email protected]62af76e2011-08-01 02:34:014329void RenderView::registerIntentHandler(const WebString& action,
4330 const WebString& type,
4331 const WebString& href,
4332 const WebString& title) {
4333 RenderThread::current()->Send(
4334 new ViewHostMsg_RegisterIntentHandler(routing_id_,
4335 action,
4336 type,
4337 href,
4338 title));
4339}
4340
[email protected]94dec932011-05-26 20:04:214341WebKit::WebPageVisibilityState RenderView::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444342 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4343 WebKit::WebPageVisibilityStateHidden :
4344 WebKit::WebPageVisibilityStateVisible;
4345 WebKit::WebPageVisibilityState override_state = current_state;
4346 if (content::GetContentClient()->renderer()->
4347 ShouldOverridePageVisibilityState(this,
4348 &override_state))
4349 return override_state;
4350 return current_state;
[email protected]94dec932011-05-26 20:04:214351}
4352
[email protected]8079b362010-05-07 18:37:454353bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194354 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454355 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194356 if (frame->parent() != NULL)
4357 return false;
4358
[email protected]f0a3d0b2010-08-06 22:51:534359 // Navigations initiated within Webkit are not sent out to the external host
4360 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274361 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134362 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534363 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134364 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334365 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534366 return false;
4367
[email protected]2fc22d12010-12-02 23:08:164368 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324369 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014370 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164371 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014372 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324373 // The opener relationship between the new window and the parent allows the
4374 // new window to script the parent and vice versa. This is not allowed if
4375 // the origins of the two domains are different. This can be treated as a
4376 // top level navigation and routed back to the host.
4377 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274378 if (!opener) {
[email protected]86965362011-04-21 18:42:514379 return true;
[email protected]d19ea342011-04-20 20:31:134380 } else {
[email protected]b6cb3a842011-06-24 18:28:414381 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324382 return true;
4383 }
4384 }
[email protected]61c9f032010-03-31 23:04:194385 return false;
4386}
[email protected]2b06a992010-08-21 05:48:224387
[email protected]27a9ef32010-09-10 04:06:244388void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
4389 IPC::PlatformFileForTransit file_for_transit,
4390 int message_id) {
4391 pepper_delegate_.OnAsyncFileOpened(
4392 error_code,
4393 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4394 message_id);
4395}
[email protected]caf706f2010-10-26 17:54:084396
[email protected]2b657fd2011-04-18 16:00:474397void RenderView::OnPpapiBrokerChannelCreated(
4398 int request_id,
4399 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434400 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474401 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4402 broker_process_handle,
4403 handle);
[email protected]eb415bf0e2011-04-14 02:45:424404}
4405
[email protected]caf706f2010-10-26 17:54:084406#if defined(OS_MACOSX)
4407void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154408 if (external_popup_menu_ == NULL) {
4409 // Crash reports from the field indicate that we can be notified with a
4410 // NULL external popup menu (we probably get notified twice).
4411 // If you hit this please file a bug against jcivelli and include the page
4412 // and steps to repro.
4413 NOTREACHED();
4414 return;
4415 }
[email protected]caf706f2010-10-26 17:54:084416 external_popup_menu_->DidSelectItem(selected_index);
4417 external_popup_menu_.reset();
4418}
4419#endif
[email protected]bb461532010-11-26 21:50:234420
[email protected]1b4209f2011-01-07 00:25:404421#if defined(ENABLE_FLAPPER_HACKS)
4422void RenderView::OnConnectTcpACK(
4423 int request_id,
4424 IPC::PlatformFileForTransit socket_for_transit,
4425 const PP_Flash_NetAddress& local_addr,
4426 const PP_Flash_NetAddress& remote_addr) {
4427 pepper_delegate_.OnConnectTcpACK(
4428 request_id,
4429 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4430 local_addr,
4431 remote_addr);
4432}
4433#endif
[email protected]a6097f42011-01-10 08:50:514434
[email protected]b29aa74b2011-01-31 21:41:084435void RenderView::OnContextMenuClosed(
4436 const webkit_glue::CustomContextMenuContext& custom_context) {
4437 if (custom_context.is_pepper_menu)
4438 pepper_delegate_.OnContextMenuClosed(custom_context);
4439 else
4440 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104441}