blob: 804e730a99af9d9ef4169850192040bbbf40f6d1 [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]230b7ef2011-03-16 22:30:1942#include "content/renderer/audio_message_filter.h"
[email protected]21d61e52011-03-18 19:08:2543#include "content/renderer/content_renderer_client.h"
[email protected]230b7ef2011-03-16 22:30:1944#include "content/renderer/device_orientation_dispatcher.h"
[email protected]55722152011-03-22 01:33:5345#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1946#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4047#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]921f1592011-03-18 00:41:0248#include "content/renderer/load_progress_tracker.h"
[email protected]ccc70d8e2011-03-16 20:40:3749#include "content/renderer/media/audio_renderer_impl.h"
[email protected]921f1592011-03-18 00:41:0250#include "content/renderer/navigation_state.h"
[email protected]230b7ef2011-03-16 22:30:1951#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3752#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3553#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0554#include "content/renderer/render_process.h"
[email protected]10e6ab572011-04-14 23:42:0055#include "content/renderer/render_thread.h"
[email protected]60916042011-03-19 00:43:3656#include "content/renderer/render_view_observer.h"
57#include "content/renderer/render_view_visitor.h"
[email protected]2cff0052011-03-18 16:51:4458#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:0159#include "content/renderer/renderer_webapplicationcachehost_impl.h"
60#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1961#include "content/renderer/speech_input_dispatcher.h"
[email protected]b1cf3372011-04-20 21:28:1062#include "content/renderer/v8_value_converter.h"
[email protected]663bd9e2011-03-21 01:07:0163#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3564#include "content/renderer/webplugin_delegate_proxy.h"
65#include "content/renderer/websharedworker_proxy.h"
66#include "content/renderer/webworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4967#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4168#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2769#include "media/base/message_loop_factory_impl.h"
initial.commit09911bf2008-07-26 23:55:2970#include "net/base/escape.h"
71#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0472#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5773#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3774#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
75#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
76#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
77#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3778#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
79#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
80#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
81#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3782#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
83#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
84#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
85#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
86#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
87#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
88#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
89#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
90#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:5791#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]69f110d62011-03-17 19:01:1492#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]232a5812011-03-04 22:42:0893#include "third_party/WebKit/Source/WebKit/chromium/public/WebNetworkStateNotifier.h"
[email protected]8bd0fe62011-01-17 06:44:3794#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]8bd0fe62011-01-17 06:44:3795#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
96#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
97#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
98#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
99#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
100#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
101#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
102#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
103#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
104#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17105#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37106#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40109#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]8bd0fe62011-01-17 06:44:37110#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
111#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
112#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
113#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
114#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
115#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26118#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c4a9e932011-03-05 04:05:55119#include "ui/base/message_box_flags.h"
[email protected]08397d52011-02-05 01:53:38120#include "ui/gfx/native_widget_types.h"
121#include "ui/gfx/point.h"
122#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55123#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04124#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43125#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24126#include "webkit/glue/context_menu.h"
[email protected]b1438212010-04-03 00:30:59127#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24128#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24129#include "webkit/glue/glue_serialize.h"
[email protected]85cc78c2010-05-04 18:30:09130#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26131#include "webkit/glue/password_form_dom_manager.h"
[email protected]85cc78c2010-05-04 18:30:09132#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24133#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29134#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07135#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29136#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17137#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50138#include "webkit/plugins/npapi/default_plugin_shared.h"
139#include "webkit/plugins/npapi/plugin_list.h"
140#include "webkit/plugins/npapi/webplugin_delegate.h"
141#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
142#include "webkit/plugins/npapi/webplugin_impl.h"
143#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52144#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29145
[email protected]6c8afae52009-01-22 02:24:57146#if defined(OS_WIN)
147// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57148// * theming
[email protected]08397d52011-02-05 01:53:38149#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03150#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37151#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51152#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33153#elif defined(OS_MACOSX)
154#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57155#endif
156
[email protected]c7287a92009-11-04 20:06:15157using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42158using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08159using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21160using WebKit::WebApplicationCacheHost;
161using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26162using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41163using WebKit::WebColor;
164using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59165using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44166using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51167using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55168using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28169using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00170using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58171using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25172using WebKit::WebDragOperation;
173using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51174using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51175using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08176using WebKit::WebExternalPopupMenu;
177using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47178using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22179using WebKit::WebFileSystem;
180using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49181using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59182using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48183using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45184using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17185using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13186using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41187using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50188using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17189using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28190using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17191using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28192using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28193using WebKit::WebNavigationType;
[email protected]232a5812011-03-04 22:42:08194using WebKit::WebNetworkStateNotifier;
[email protected]79dbc662009-09-04 05:42:51195using WebKit::WebNode;
[email protected]3d9689372009-09-10 04:29:17196using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40197using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49198using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09199using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52200using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59201using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51202using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52203using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40204using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35205using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29206using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17207using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59208using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42209using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02210using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34211using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40212using WebKit::WebStorageQuotaCallbacks;
213using WebKit::WebStorageQuotaError;
214using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28215using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51216using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52217using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28218using WebKit::WebURL;
219using WebKit::WebURLError;
220using WebKit::WebURLRequest;
221using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28222using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03223using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28224using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26225using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43226using WebKit::WebWorker;
227using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26228using appcache::WebApplicationCacheHostImpl;
229using base::Time;
230using base::TimeDelta;
231using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26232using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26233using webkit_glue::PasswordForm;
234using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23235using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26236using webkit_glue::SiteIsolationMetrics;
237using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33238
initial.commit09911bf2008-07-26 23:55:29239//-----------------------------------------------------------------------------
240
[email protected]3354d3e2010-06-10 19:53:02241typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49242static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02243
[email protected]882daa92009-11-05 16:31:31244// Time, in seconds, we delay before sending content state changes (such as form
245// state and scroll position) to the browser. We delay sending changes to avoid
246// spamming the browser.
247// To avoid having tab/session restore require sending a message to get the
248// current content state during tab closing we use a shorter timeout for the
249// foreground renderer. This means there is a small window of time from which
250// content state is modified and not sent to session restore, but this is
251// better than having to wake up all renderers during shutdown.
252static const int kDelaySecondsForContentStateSyncHidden = 5;
253static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29254
[email protected]0aa55312008-10-17 21:53:08255// The maximum number of popups that can be spawned from one page.
256static const int kMaximumNumberOfUnacknowledgedPopups = 25;
257
[email protected]6fdd4182010-10-14 23:59:26258static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35259
[email protected]726985e22009-06-18 21:09:28260static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
261 WebVector<WebURL> urls;
262 ds->redirectChain(urls);
263 result->reserve(urls.size());
264 for (size_t i = 0; i < urls.size(); ++i)
265 result->push_back(urls[i]);
266}
267
[email protected]54ec7f82010-10-21 22:32:51268static bool WebAccessibilityNotificationToViewHostMsg(
269 WebAccessibilityNotification notification,
[email protected]fffaf972011-03-24 01:34:35270 ViewHostMsg_AccessibilityNotification_Type::Value* type) {
[email protected]54ec7f82010-10-21 22:32:51271 switch (notification) {
272 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
[email protected]fffaf972011-03-24 01:34:35273 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51274 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
275 break;
276 case WebKit::WebAccessibilityNotificationChildrenChanged:
[email protected]fffaf972011-03-24 01:34:35277 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51278 NOTIFICATION_TYPE_CHILDREN_CHANGED;
279 break;
280 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
[email protected]fffaf972011-03-24 01:34:35281 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51282 NOTIFICATION_TYPE_FOCUS_CHANGED;
283 break;
284 case WebKit::WebAccessibilityNotificationLoadComplete:
[email protected]fffaf972011-03-24 01:34:35285 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51286 NOTIFICATION_TYPE_LOAD_COMPLETE;
287 break;
288 case WebKit::WebAccessibilityNotificationValueChanged:
[email protected]fffaf972011-03-24 01:34:35289 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51290 NOTIFICATION_TYPE_VALUE_CHANGED;
291 break;
292 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
[email protected]fffaf972011-03-24 01:34:35293 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51294 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
295 break;
296 default:
297 // TODO(ctguil): Support additional webkit notifications.
298 return false;
299 }
300 return true;
301}
302
[email protected]6a8f5112011-05-13 16:38:44303// If |data_source| is non-null and has a NavigationState associated with it,
304// the AltErrorPageResourceFetcher is reset.
305static void StopAltErrorPageFetcher(WebDataSource* data_source) {
306 if (data_source) {
307 NavigationState* state = NavigationState::FromDataSource(data_source);
308 if (state)
309 state->set_alt_error_page_fetcher(NULL);
310 }
311}
312
initial.commit09911bf2008-07-26 23:55:29313///////////////////////////////////////////////////////////////////////////////
314
[email protected]60c42a8c72009-10-09 04:08:59315int32 RenderView::next_page_id_ = 1;
316
[email protected]cdaf8d02010-03-30 19:52:47317struct RenderView::PendingFileChooser {
318 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
319 WebFileChooserCompletion* c)
320 : params(p),
321 completion(c) {
322 }
323 ViewHostMsg_RunFileChooser_Params params;
324 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
325};
326
[email protected]2fab253a2009-08-17 23:00:59327RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51328 gfx::NativeViewId parent_hwnd,
[email protected]c03a6e72011-04-19 21:42:06329 gfx::PluginWindowHandle compositing_surface,
[email protected]676126f72011-01-15 00:03:51330 int32 opener_id,
331 const RendererPreferences& renderer_prefs,
332 const WebPreferences& webkit_prefs,
333 SharedRenderViewCounter* counter,
334 int32 routing_id,
335 int64 session_storage_namespace_id,
336 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12337 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51338 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02339 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09340 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02341 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24342 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21343 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02344 opened_by_user_gesture_(true),
345 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24346 page_id_(-1),
347 last_page_id_sent_to_browser_(-1),
[email protected]3cc72b12010-03-18 23:03:00348 history_list_offset_(-1),
349 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24350 has_unload_listener_(false),
[email protected]3354d3e2010-06-10 19:53:02351 target_url_status_(TARGET_NONE),
[email protected]18ca9a6b2010-06-02 19:05:18352 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]54ec7f82010-10-21 22:32:51353 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02354 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51355 geolocation_dispatcher_(NULL),
356 speech_input_dispatcher_(NULL),
357 device_orientation_dispatcher_(NULL),
[email protected]54ec7f82010-10-21 22:32:51358 accessibility_ack_pending_(false),
[email protected]cae8c8492011-03-03 11:12:18359 p2p_socket_dispatcher_(NULL),
[email protected]5ee0cfd02011-01-18 05:42:22360 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]676126f72011-01-15 00:03:51361 routing_id_ = routing_id;
362 if (opener_id != MSG_ROUTING_NONE)
363 opener_id_ = opener_id;
364
[email protected]11fee2332011-03-29 20:36:35365 webwidget_ = WebView::create(this);
366
[email protected]676126f72011-01-15 00:03:51367 if (counter) {
368 shared_popup_counter_ = counter;
369 shared_popup_counter_->data++;
370 decrement_shared_popup_at_destruction_ = true;
371 } else {
372 shared_popup_counter_ = new SharedRenderViewCounter(0);
373 decrement_shared_popup_at_destruction_ = false;
374 }
375
376 notification_provider_ = new NotificationProvider(this);
377
[email protected]676126f72011-01-15 00:03:51378 render_thread_->AddRoute(routing_id_, this);
379 // Take a reference on behalf of the RenderThread. This will be balanced
380 // when we receive ViewMsg_Close.
381 AddRef();
382
383 // If this is a popup, we must wait for the CreatingNew_ACK message before
384 // completing initialization. Otherwise, we can finish it now.
385 if (opener_id == MSG_ROUTING_NONE) {
386 did_show_ = true;
[email protected]c03a6e72011-04-19 21:42:06387 CompleteInit(parent_hwnd, compositing_surface);
[email protected]676126f72011-01-15 00:03:51388 }
389
[email protected]34c61bd52011-05-02 19:38:33390 g_view_map.Get().insert(std::make_pair(webview(), this));
391 webkit_preferences_.Apply(webview());
392 webview()->initializeMainFrame(this);
393 if (!frame_name.empty())
394 webview()->mainFrame()->setName(frame_name);
395 webview()->settings()->setMinimumTimerInterval(
396 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
397 webkit_glue::kForegroundTabTimerInterval);
398
399 OnSetRendererPrefs(renderer_prefs);
400
[email protected]676126f72011-01-15 00:03:51401 host_window_ = parent_hwnd;
402
403 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]676126f72011-01-15 00:03:51404 if (command_line.HasSwitch(switches::kEnableAccessibility))
405 WebAccessibilityCache::enableAccessibility();
406
407 audio_message_filter_ = new AudioMessageFilter(routing_id_);
408 render_thread_->AddFilter(audio_message_filter_);
409
[email protected]a026daa2011-04-20 15:49:51410#if defined(ENABLE_P2P_APIS)
[email protected]9966325b2011-04-18 05:00:10411 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableP2PApi))
[email protected]cae8c8492011-03-03 11:12:18412 p2p_socket_dispatcher_ = new P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51413#endif
[email protected]cae8c8492011-03-03 11:12:18414
[email protected]e48869a2011-04-01 19:56:03415 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29416}
417
418RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08419 if (decrement_shared_popup_at_destruction_)
420 shared_popup_counter_->data--;
421
[email protected]a1128322009-10-06 18:38:46422 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47423 while (!file_chooser_completions_.empty()) {
424 if (file_chooser_completions_.front()->completion) {
425 file_chooser_completions_.front()->completion->didChooseFile(
426 WebVector<WebString>());
427 }
428 file_chooser_completions_.pop_front();
429 }
[email protected]a1128322009-10-06 18:38:46430
[email protected]83dde542009-09-11 20:59:55431#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11432 // Destroy all fake plugin window handles on the browser side.
433 while (!fake_plugin_window_handles_.empty()) {
434 // Make sure no NULL plugin window handles were inserted into this list.
435 DCHECK(*fake_plugin_window_handles_.begin());
436 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
437 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
438 }
[email protected]83dde542009-09-11 20:59:55439#endif
[email protected]98324892009-09-09 21:16:05440
[email protected]5fb88962009-04-16 19:03:25441 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59442
443#ifndef NDEBUG
444 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49445 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59446 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
447 DCHECK_NE(this, it->second) << "Failed to call Close?";
448#endif
[email protected]676126f72011-01-15 00:03:51449
450 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
451 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59452}
453
454/*static*/
455void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49456 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59457 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
458 if (!visitor->Visit(it->second))
459 return;
460 }
461}
462
463/*static*/
464RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49465 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59466 ViewMap::iterator it = views->find(webview);
467 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29468}
469
470/*static*/
[email protected]0aa55312008-10-17 21:53:08471RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24472 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15473 gfx::NativeViewId parent_hwnd,
[email protected]c03a6e72011-04-19 21:42:06474 gfx::PluginWindowHandle compositing_surface,
[email protected]0aa55312008-10-17 21:53:08475 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51476 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08477 const WebPreferences& webkit_prefs,
478 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34479 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26480 int64 session_storage_namespace_id,
481 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29482 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51483 return new RenderView(
484 render_thread,
485 parent_hwnd,
[email protected]c03a6e72011-04-19 21:42:06486 compositing_surface,
[email protected]676126f72011-01-15 00:03:51487 opener_id,
488 renderer_prefs,
489 webkit_prefs,
490 counter,
491 routing_id,
492 session_storage_namespace_id,
493 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29494}
495
[email protected]bb461532010-11-26 21:50:23496// static
initial.commit09911bf2008-07-26 23:55:29497void RenderView::SetNextPageID(int32 next_page_id) {
498 // This method should only be called during process startup, and the given
499 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05500 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29501 DCHECK(next_page_id >= next_page_id_);
502 next_page_id_ = next_page_id;
503}
504
[email protected]676126f72011-01-15 00:03:51505void RenderView::AddObserver(RenderViewObserver* observer) {
506 observers_.AddObserver(observer);
507}
508
509void RenderView::RemoveObserver(RenderViewObserver* observer) {
510 observer->set_render_view(NULL);
511 observers_.RemoveObserver(observer);
512}
513
[email protected]70eee342010-11-05 01:59:37514bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
515 typedef ViewHostMsg_AccessibilityNotification_Params params;
[email protected]a527a022011-02-10 02:32:36516 if (type == WebKit::WebAccessibilityNotificationChildrenChanged ||
517 type == WebKit::WebAccessibilityNotificationLoadComplete) {
[email protected]70eee342010-11-05 01:59:37518 return true;
519 }
520 return false;
521}
522
[email protected]8a3125a712010-08-09 18:58:51523WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26524 return static_cast<WebKit::WebView*>(webwidget());
525}
526
[email protected]1a3c3cb2010-12-16 21:03:40527void RenderView::SetReportLoadProgressEnabled(bool enabled) {
528 if (!enabled) {
529 load_progress_tracker_.reset(NULL);
530 return;
531 }
532 if (load_progress_tracker_ == NULL)
533 load_progress_tracker_.reset(new LoadProgressTracker(this));
534}
535
[email protected]a3a8fb6d2009-10-22 20:12:51536void RenderView::PluginCrashed(const FilePath& plugin_path) {
537 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29538}
539
[email protected]aad51d1c2010-08-05 08:38:09540WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
541 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50542 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26543 bool found;
[email protected]6fdd4182010-10-14 23:59:26544 std::string mime_type;
545 Send(new ViewHostMsg_GetPluginInfo(
[email protected]c8f73ab2011-01-22 00:05:17546 routing_id_, params.url, frame->top()->url(), params.mimeType.utf8(),
[email protected]8093a542011-05-13 07:29:32547 &found, &info, &mime_type));
[email protected]b83ff222011-01-24 17:37:12548 if (!found || !webkit::npapi::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09549 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45550
[email protected]96dcc1762011-04-04 16:01:09551 bool pepper_plugin_was_registered = false;
[email protected]0bd753682010-12-16 18:15:52552 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]96dcc1762011-04-04 16:01:09553 pepper_delegate_.CreatePepperPlugin(info.path,
554 &pepper_plugin_was_registered));
555 if (pepper_plugin_was_registered) {
556 if (pepper_module)
557 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
558 return NULL;
559 }
[email protected]1a78d9f32010-12-08 06:38:45560 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09561}
562
[email protected]d8fd6fa2010-02-01 15:54:26563void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
564 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30565 // If the renderer is visible, set initial visibility and focus state.
566 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34567#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30568 delegate->SetContainerVisibility(true);
569 if (webview() && webview()->isActive())
570 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34571#endif
[email protected]49232292010-09-03 19:07:30572 }
[email protected]784ea1ab2010-09-18 00:02:34573 // Plugins start assuming the content has focus (so that they work in
574 // environments where RenderView isn't hosting them), so we always have to
575 // set the initial state. See webplugin_delegate_impl.h for details.
576 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26577}
578
579void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
580 plugin_delegates_.erase(delegate);
581}
[email protected]d8fd6fa2010-02-01 15:54:26582
[email protected]a95986a82010-12-24 06:19:28583bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27584 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27585 if (main_frame)
[email protected]38b592902011-04-16 02:08:42586 content::GetContentClient()->SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26587
[email protected]676126f72011-01-15 00:03:51588 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
589 RenderViewObserver* observer;
590 while ((observer = it.GetNext()) != NULL)
591 if (observer->OnMessageReceived(message))
592 return true;
[email protected]b2abac72009-02-26 12:39:28593
[email protected]a95986a82010-12-24 06:19:28594 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29595 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29596 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
597 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56598 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29599 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
600 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
601 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
602 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27603#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35604 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27605#endif
initial.commit09911bf2008-07-26 23:55:29606 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
607 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
608 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
609 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
610 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15611 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29612 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49613 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
614 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17615 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17616 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:54617 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
618 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29619 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18620 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
621 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29622 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48623 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29624 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55625 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
626 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
627 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
628 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
629 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
630 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
631 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45632 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40633 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29634 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:51635 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
636 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:29637 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
638 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
639 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
640 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]600ea402011-04-12 00:01:51641 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
642 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29643 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04644 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15645 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29646 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
647 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08648 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
649 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00650 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16651 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14652 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25653 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
654 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10655 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
656 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51657 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56658 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34659 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14660#if defined(OS_MACOSX)
661 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13662 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13663 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
664 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14665#endif
[email protected]446705872009-09-10 07:22:48666 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33667 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33668 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
669 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:14670 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:36671 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
672 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
673 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:42674 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
675 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:24676 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42677 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
678 OnPpapiBrokerChannelCreated)
[email protected]caf706f2010-10-26 17:54:08679#if defined(OS_MACOSX)
680 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
681#endif
[email protected]521b2482011-01-15 00:10:10682 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]232a5812011-03-04 22:42:08683 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]f0557932011-01-25 20:20:51684 // TODO(viettrungluu): Move to a separate message filter.
685#if defined(ENABLE_FLAPPER_HACKS)
686 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
687#endif
[email protected]54ca3ca892011-06-07 21:14:54688#if defined(OS_MACOSX)
689 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
690#endif
[email protected]f0557932011-01-25 20:20:51691
initial.commit09911bf2008-07-26 23:55:29692 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28693 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29694 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28695 return handled;
initial.commit09911bf2008-07-26 23:55:29696}
697
initial.commit09911bf2008-07-26 23:55:29698void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
699 if (!webview())
700 return;
701
[email protected]992db4c2011-05-12 15:37:15702 // Swap this renderer back in if necessary.
703 if (is_swapped_out_)
704 SetSwappedOut(false);
705
[email protected]3cc72b12010-03-18 23:03:00706 history_list_offset_ = params.current_history_list_offset;
707 history_list_length_ = params.current_history_list_length;
708
[email protected]38b592902011-04-16 02:08:42709 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29710
[email protected]ecbf10d2010-02-18 13:03:29711 bool is_reload =
[email protected]2c5569662011-03-22 20:45:02712 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
713 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29714
[email protected]26aa0482009-09-30 16:55:27715 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45716 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29717 // We cannot reload if we do not have any history state. This happens, for
718 // example, when recovering from a crash. Our workaround here is a bit of
719 // a hack since it means that reload after a crashed tab does not cause an
720 // end-to-end cache validation.
721 is_reload = false;
722 }
723
[email protected]77f17a82009-05-21 04:42:54724 // A navigation resulting from loading a javascript URL should not be treated
725 // as a browser initiated event. Instead, we want it to look as if the page
726 // initiated any load resulting from JS execution.
727 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30728 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00729 params.page_id,
730 params.pending_history_list_offset,
731 params.transition,
732 params.request_time);
[email protected]2c5569662011-03-22 20:45:02733 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30734 // We're doing a load of a page that was restored from the last session.
735 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
736 // which can result in stale data for pages that are set to expire. We
737 // explicitly override that by setting the policy here so that as
738 // necessary we load from the network.
739 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
740 }
741 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54742 }
initial.commit09911bf2008-07-26 23:55:29743
[email protected]a7ccc4d2010-01-27 08:14:48744 NavigationState* navigation_state = pending_navigation_state_.get();
745
[email protected]48a5c772011-04-18 23:50:50746 if (navigation_state) {
747 // New loads need to reset the error page fetcher. Otherwise if there is an
748 // outstanding error page fetcher it may complete and clobber the current
749 // page load.
750 navigation_state->set_alt_error_page_fetcher(NULL);
751 }
752
[email protected]04d3c6e2009-05-22 17:00:13753 // If we are reloading, then WebKit will use the history state of the current
754 // page, so we should just ignore any given history state. Otherwise, if we
755 // have history state, then we need to navigate to it, which corresponds to a
756 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55757 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48758 if (navigation_state)
759 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29760 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02761 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29762 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55763 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13764 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58765 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48766 if (navigation_state)
767 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45768 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17769 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13770 } else {
771 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28772 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29773
[email protected]e6f546c32009-07-01 17:12:55774 // A session history navigation should have been accompanied by state.
775 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13776
[email protected]dd7daa82009-08-10 05:46:45777 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55778 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13779
[email protected]726985e22009-06-18 21:09:28780 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17781 if (!WebSecurityPolicy::shouldHideReferrer(
782 params.url,
783 WebString::fromUTF8(params.referrer.spec()))) {
784 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
785 WebString::fromUTF8(params.referrer.spec()));
786 }
[email protected]726985e22009-06-18 21:09:28787 }
[email protected]04d3c6e2009-05-22 17:00:13788
[email protected]52c68652010-12-07 17:47:04789 if (!params.extra_headers.empty()) {
790 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
791 params.extra_headers.end(), "\n");
792 i.GetNext(); ) {
793 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
794 WebString::fromUTF8(i.values()));
795 }
796 }
797
[email protected]16e923d2011-04-30 00:41:44798 if (navigation_state)
799 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45800 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50801 }
802
[email protected]77f17a82009-05-21 04:42:54803 // In case LoadRequest failed before DidCreateDataSource was called.
804 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29805}
806
807// Stop loading the current page
808void RenderView::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44809 if (webview()) {
810 WebFrame* main_frame = webview()->mainFrame();
811 // Stop the alt error page fetcher. If we let it continue it may complete
812 // and cause RenderViewHostManager to swap to this RenderView, even though
813 // it may no longer be active.
814 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
815 StopAltErrorPageFetcher(main_frame->dataSource());
816 main_frame->stopLoading();
817 }
initial.commit09911bf2008-07-26 23:55:29818}
819
[email protected]ecbf10d2010-02-18 13:03:29820// Reload current focused frame.
821// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56822void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29823 if (webview() && webview()->focusedFrame()) {
824 // We always obey the cache (ignore_cache=false) here.
825 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
826 // a cache-ignoring reload of the frame.
827 webview()->focusedFrame()->reload(false);
828 }
[email protected]1dda4022010-01-28 18:24:56829}
830
initial.commit09911bf2008-07-26 23:55:29831void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27832 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29833}
834
[email protected]68b1e922009-06-23 16:00:25835void RenderView::OnExecuteEditCommand(const std::string& name,
836 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27837 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25838 return;
839
[email protected]26aa0482009-09-30 16:55:27840 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45841 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25842}
843
initial.commit09911bf2008-07-26 23:55:29844void RenderView::OnUpdateTargetURLAck() {
845 // Check if there is a targeturl waiting to be sent.
846 if (target_url_status_ == TARGET_PENDING) {
847 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
848 pending_target_url_));
849 }
850
851 target_url_status_ = TARGET_NONE;
852}
853
854void RenderView::OnUndo() {
855 if (!webview())
856 return;
857
[email protected]26aa0482009-09-30 16:55:27858 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29859}
860
861void RenderView::OnRedo() {
862 if (!webview())
863 return;
864
[email protected]26aa0482009-09-30 16:55:27865 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29866}
867
868void RenderView::OnCut() {
869 if (!webview())
870 return;
871
[email protected]26aa0482009-09-30 16:55:27872 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29873}
874
875void RenderView::OnCopy() {
876 if (!webview())
877 return;
878
[email protected]26aa0482009-09-30 16:55:27879 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
initial.commit09911bf2008-07-26 23:55:29880}
881
[email protected]c0cc3092009-09-12 08:27:27882#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35883void RenderView::OnCopyToFindPboard() {
884 if (!webview())
885 return;
886
887 // Since the find pasteboard supports only plain text, this can be simpler
888 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27889 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35890 if (frame->hasSelection()) {
891 string16 selection = frame->selectionAsText();
892 RenderThread::current()->Send(
[email protected]7e3589742011-03-10 18:49:17893 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35894 }
[email protected]a954bf72009-09-12 07:30:35895}
[email protected]c0cc3092009-09-12 08:27:27896#endif
[email protected]a954bf72009-09-12 07:30:35897
initial.commit09911bf2008-07-26 23:55:29898void RenderView::OnPaste() {
899 if (!webview())
900 return;
901
[email protected]26aa0482009-09-30 16:55:27902 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29903}
904
[email protected]2a3a7762009-10-19 19:17:32905void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29906 if (!webview())
907 return;
908
[email protected]1ff7a032010-02-03 02:46:03909 WebFrame* frame = webview()->focusedFrame();
910 if (!frame->hasSelection())
911 frame->selectWordAroundCaret();
912 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29913}
914
915void RenderView::OnDelete() {
916 if (!webview())
917 return;
918
[email protected]26aa0482009-09-30 16:55:27919 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29920}
921
922void RenderView::OnSelectAll() {
923 if (!webview())
924 return;
925
[email protected]26aa0482009-09-30 16:55:27926 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22927 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29928}
929
930void RenderView::OnSetInitialFocus(bool reverse) {
931 if (!webview())
932 return;
[email protected]26aa0482009-09-30 16:55:27933 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29934}
935
[email protected]54ca3ca892011-06-07 21:14:54936#if defined(OS_MACOSX)
937void RenderView::OnSetInLiveResize(bool in_live_resize) {
938 if (!webview())
939 return;
940 if (in_live_resize)
941 webview()->willStartLiveResize();
942 else
943 webview()->willEndLiveResize();
944}
945#endif
946
[email protected]9b66f34bf2010-10-27 20:45:51947void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:09948 WebKit::WebNode node = GetFocusedNode();
949 if (!node.isNull()) {
950 if (IsEditableNode(node))
951 // TODO(varunjain): Change webkit API to scroll a particular node into
952 // view and use that API here instead.
953 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:51954 }
955}
956
initial.commit09911bf2008-07-26 23:55:29957///////////////////////////////////////////////////////////////////////////////
958
959// Tell the embedding application that the URL of the active page has changed
960void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45961 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29962 DCHECK(ds);
963
[email protected]726985e22009-06-18 21:09:28964 const WebURLRequest& request = ds->request();
965 const WebURLRequest& original_request = ds->originalRequest();
966 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29967
[email protected]daa8c58e2009-06-15 17:21:10968 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
969 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29970
971 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28972 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29973 params.is_post = false;
974 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:07975 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:19976 params.socket_address.set_host(response.remoteIPAddress().utf8());
977 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:03978 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:09979 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:55980 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29981 // SSL state specified in the request takes precedence over the one in the
982 // response.
983 // So far this is only intended for error pages that are not expected to be
984 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28985 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55986 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29987 } else {
[email protected]726985e22009-06-18 21:09:28988 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29989 }
990
991 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28992 if (ds->hasUnreachableURL()) {
993 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29994 } else {
[email protected]726985e22009-06-18 21:09:28995 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29996 }
997
[email protected]726985e22009-06-18 21:09:28998 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:24999 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041000 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291001
[email protected]ce0e250d2009-10-23 21:00:351002 params.searchable_form_url = navigation_state->searchable_form_url();
1003 params.searchable_form_encoding =
1004 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291005
1006 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101007 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291008 if (password_form_data)
1009 params.password_form = *password_form_data;
1010
1011 params.gesture = navigation_gesture_;
1012 navigation_gesture_ = NavigationGestureUnknown;
1013
[email protected]0f38dc4552011-02-25 11:24:001014 // Make navigation state a part of the FrameNavigate message so that commited
1015 // entry had it at all times.
1016 const WebHistoryItem& item = frame->currentHistoryItem();
1017 if (!item.isNull()) {
1018 params.content_state = webkit_glue::HistoryItemToString(item);
1019 } else {
1020 params.content_state =
1021 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1022 }
1023
[email protected]dd7daa82009-08-10 05:46:451024 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291025 // Top-level navigation.
1026
[email protected]b75b8292010-10-01 07:28:251027 // Set zoom level, but don't do it for full-page plugin since they don't use
1028 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011029 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541030 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251031 if (webview()->mainFrame()->document().isPluginDocument()) {
1032 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251033 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251034 } else {
1035 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251036 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251037 }
1038
[email protected]f85f0702010-01-30 09:31:011039 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511040 // This zoom level was merely recorded transiently for this load. We can
1041 // erase it now. If at some point we reload this page, the browser will
1042 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011043 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511044 }
1045
[email protected]b75b8292010-10-01 07:28:251046 // Reset the zoom limits in case a plugin had changed them previously. This
1047 // will also call us back which will cause us to send a message to
1048 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251049 webview()->zoomLimitsChanged(
1050 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1051 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251052
initial.commit09911bf2008-07-26 23:55:291053 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551054 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291055
[email protected]daa8c58e2009-06-15 17:21:101056 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291057 if (!PageTransition::IsMainFrame(params.transition)) {
1058 // If the main frame does a load, it should not be reported as a subframe
1059 // navigation. This can occur in the following case:
1060 // 1. You're on a site with frames.
1061 // 2. You do a subframe navigation. This is stored with transition type
1062 // MANUAL_SUBFRAME.
1063 // 3. You navigate to some non-frame site, say, google.com.
1064 // 4. You navigate back to the page from step 2. Since it was initially
1065 // MANUAL_SUBFRAME, it will be that same transition type here.
1066 // We don't want that, because any navigation that changes the toplevel
1067 // frame should be tracked as a toplevel navigation (this allows us to
1068 // update the URL bar, etc).
1069 params.transition = PageTransition::LINK;
1070 }
1071
initial.commit09911bf2008-07-26 23:55:291072 // If we have a valid consumed client redirect source,
1073 // the page contained a client redirect (meta refresh, document.loc...),
1074 // so we set the referrer and transition to match.
1075 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041076 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291077 params.referrer = completed_client_redirect_src_;
1078 params.transition = static_cast<PageTransition::Type>(
1079 params.transition | PageTransition::CLIENT_REDIRECT);
1080 } else {
1081 // Bug 654101: the referrer will be empty on https->http transitions. It
1082 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281083 params.referrer = GURL(
1084 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291085 }
1086
[email protected]726985e22009-06-18 21:09:281087 string16 method = request.httpMethod();
1088 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291089 params.is_post = true;
1090
[email protected]c2a797d2009-09-21 16:46:321091 // Save some histogram data so we can compute the average memory used per
1092 // page load of the glyphs.
1093 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1094 webkit_glue::GetGlyphPageCount());
1095
[email protected]15cf526b2010-02-12 06:33:491096 // This message needs to be sent before any of allowScripts(),
1097 // allowImages(), allowPlugins() is called for the new page, so that when
1098 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1099 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291100 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1101 } else {
1102 // Subframe navigation: the type depends on whether this navigation
1103 // generated a new session history entry. When they do generate a session
1104 // history entry, it means the user initiated the navigation and we should
1105 // mark it as such. This test checks if this is the first time UpdateURL
1106 // has been called since WillNavigateToURL was called to initiate the load.
1107 if (page_id_ > last_page_id_sent_to_browser_)
1108 params.transition = PageTransition::MANUAL_SUBFRAME;
1109 else
1110 params.transition = PageTransition::AUTO_SUBFRAME;
1111
initial.commit09911bf2008-07-26 23:55:291112 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1113 }
1114
1115 last_page_id_sent_to_browser_ =
1116 std::max(last_page_id_sent_to_browser_, page_id_);
1117
1118 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101119 // we don't want the transition type to persist. Just clear it.
1120 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501121
[email protected]af15bed2010-08-25 21:12:091122 // Check if the navigation was within the same page, in which case we don't
1123 // want to clear the accessibility cache.
1124 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351125 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141126 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501127 }
initial.commit09911bf2008-07-26 23:55:291128}
1129
1130// Tell the embedding application that the title of the active page has changed
[email protected]6b2f7a82011-04-25 19:30:511131void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291132 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171133 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171134 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171135 routing_id_,
1136 page_id_,
[email protected]6b2f7a82011-04-25 19:30:511137 UTF16ToWideHack(title.length() > content::kMaxTitleChars ?
1138 title.substr(0, content::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171139 }
initial.commit09911bf2008-07-26 23:55:291140}
1141
1142void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401143 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291144 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271145 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291146 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301147 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291148 last_encoding_name_ = encoding_name;
1149
[email protected]e38f40152008-09-12 23:08:301150 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291151 }
1152}
1153
[email protected]e15f680732010-11-23 22:30:201154// Sends the last committed session history state to the browser so it will be
1155// saved before we navigate to a new page. This must be called *before* the
1156// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291157void RenderView::UpdateSessionHistory(WebFrame* frame) {
1158 // If we have a valid page ID at this point, then it corresponds to the page
1159 // we are navigating away from. Otherwise, this is the first navigation, so
1160 // there is no past session history to record.
1161 if (page_id_ == -1)
1162 return;
1163
[email protected]ca948a22009-06-25 19:36:171164 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271165 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171166 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291167 return;
[email protected]ca948a22009-06-25 19:36:171168
1169 Send(new ViewHostMsg_UpdateState(
1170 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291171}
1172
[email protected]3d9689372009-09-10 04:29:171173void RenderView::OpenURL(
1174 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1175 Send(new ViewHostMsg_OpenURL(
1176 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1177}
1178
[email protected]79dbc662009-09-04 05:42:511179// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291180
initial.commit09911bf2008-07-26 23:55:291181void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281182 const WebURLRequest& failed_request,
1183 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291184 const std::string& html,
1185 bool replace) {
[email protected]21d61e52011-03-18 19:08:251186 std::string alt_html = !html.empty() ? html :
1187 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1188 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451189 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361190 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251191 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551192 replace);
initial.commit09911bf2008-07-26 23:55:291193}
1194
initial.commit09911bf2008-07-26 23:55:291195bool RenderView::RunJavaScriptMessage(int type,
[email protected]4f5ce842011-05-27 19:34:411196 const string16& message,
1197 const string16& default_value,
[email protected]a455d3812009-03-05 20:18:071198 const GURL& frame_url,
[email protected]4f5ce842011-05-27 19:34:411199 string16* result) {
initial.commit09911bf2008-07-26 23:55:291200 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411201 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291202 if (!result)
1203 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291204
[email protected]12636df2009-09-28 22:32:211205 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1206 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291207 return success;
1208}
1209
[email protected]c1f50aa2010-02-18 03:46:571210bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1211 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1212 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1213 // it is particularly important that we do not call willEnterModalLoop as
1214 // that would defer resource loads for the dialog itself.
1215 if (RenderThread::current()) // Will be NULL during unit tests.
1216 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1217
1218 message->EnableMessagePumping(); // Runs a nested message loop.
1219 return Send(message);
1220}
1221
[email protected]f103ab72009-09-02 17:10:591222void RenderView::OnMissingPluginStatus(
1223 WebPluginDelegateProxy* delegate,
1224 int status) {
[email protected]6c8afae52009-01-22 02:24:571225#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591226 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291227 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:501228 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591229 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291230 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1231 }
1232 } else {
1233 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1234 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:501235 if (status ==
1236 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:291237 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1238 }
1239 }
[email protected]6c8afae52009-01-22 02:24:571240#else
[email protected]76c3b312010-05-20 21:38:291241 // TODO(port): Implement the infobar that accompanies the default plugin.
1242 // Linux: http://crbug.com/10952
1243 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571244 NOTIMPLEMENTED();
1245#endif
initial.commit09911bf2008-07-26 23:55:291246}
1247
[email protected]48c9cf2d2009-09-16 16:47:521248// WebKit::WebViewClient ------------------------------------------------------
1249
[email protected]844acf372011-01-14 10:49:271250WebView* RenderView::createView(
1251 WebFrame* creator,
1252 const WebURLRequest& request,
1253 const WebWindowFeatures& features,
1254 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521255 // Check to make sure we aren't overloading on popups.
1256 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1257 return NULL;
1258
[email protected]8ab04652010-06-12 02:47:261259 ViewHostMsg_CreateWindow_Params params;
1260 params.opener_id = routing_id_;
1261 params.user_gesture = creator->isProcessingUserGesture();
1262 params.window_container_type = WindowFeaturesToContainerType(features);
1263 params.session_storage_namespace_id = session_storage_namespace_id_;
1264 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111265 params.opener_frame_id = creator->identifier();
1266 params.opener_url = creator->url();
1267 params.opener_security_origin = creator->securityOrigin().toString().utf8();
1268 if (!request.isNull())
1269 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261270
[email protected]48c9cf2d2009-09-16 16:47:521271 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341272 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261273 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521274
[email protected]48c9cf2d2009-09-16 16:47:521275 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261276 new ViewHostMsg_CreateWindow(params,
1277 &routing_id,
1278 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211279 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521280 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521281
[email protected]48c9cf2d2009-09-16 16:47:521282 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421283 0,
[email protected]c03a6e72011-04-19 21:42:061284 gfx::kNullPluginWindow,
[email protected]12636df2009-09-28 22:32:211285 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521286 renderer_preferences_,
1287 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211288 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341289 routing_id,
[email protected]8ab04652010-06-12 02:47:261290 cloned_session_storage_namespace_id,
1291 frame_name);
1292 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521293
[email protected]007a848b2009-10-26 15:55:461294 // Record whether the creator frame is trying to suppress the opener field.
1295 view->opener_suppressed_ = opener_suppressed;
1296
[email protected]48c9cf2d2009-09-16 16:47:521297 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091298 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521299 if (!creator_url.is_valid() || !creator_url.IsStandard())
1300 creator_url = GURL();
1301 view->creator_url_ = creator_url;
1302
1303 // Copy over the alternate error page URL so we can have alt error pages in
1304 // the new render view (we don't need the browser to send the URL back down).
1305 view->alternate_error_page_url_ = alternate_error_page_url_;
1306
1307 return view->webview();
1308}
1309
[email protected]3e2b375b2010-04-07 17:03:121310WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521311 RenderWidget* widget = RenderWidget::Create(routing_id_,
1312 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121313 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521314 return widget->webwidget();
1315}
1316
1317WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441318 // TODO(jcivelli): Remove this deprecated method when its been removed from
1319 // the WebViewClient interface. It's been replaced by
1320 // createExternalPopupMenu.
1321 NOTREACHED();
1322 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521323}
1324
[email protected]caf706f2010-10-26 17:54:081325WebExternalPopupMenu* RenderView::createExternalPopupMenu(
1326 const WebPopupMenuInfo& popup_menu_info,
1327 WebExternalPopupMenuClient* popup_menu_client) {
1328 DCHECK(!external_popup_menu_.get());
1329 external_popup_menu_.reset(
1330 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1331 return external_popup_menu_.get();
1332}
1333
[email protected]ea192e82011-04-11 19:16:021334RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521335 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531336 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421337 if (webview() && webview()->mainFrame())
[email protected]d91233b7e2011-03-29 20:33:531338 active_url = GURL(webview()->mainFrame()->url());
1339 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
1340 routing_id_, render_thread_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391341 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561342 return widget;
[email protected]79c7bed2010-09-14 22:28:391343}
1344
[email protected]68c50e52010-05-12 11:14:391345WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341346 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391347 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291348 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1349 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1350 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341351}
1352
[email protected]48c9cf2d2009-09-16 16:47:521353void RenderView::didAddMessageToConsole(
1354 const WebConsoleMessage& message, const WebString& source_name,
1355 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081356 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
1357 switch(message.level) {
1358 case WebConsoleMessage::LevelTip:
1359 log_severity = logging::LOG_VERBOSE;
1360 break;
1361 case WebConsoleMessage::LevelLog:
1362 log_severity = logging::LOG_INFO;
1363 break;
1364 case WebConsoleMessage::LevelWarning:
1365 log_severity = logging::LOG_WARNING;
1366 break;
1367 case WebConsoleMessage::LevelError:
1368 log_severity = logging::LOG_ERROR;
1369 break;
1370 default:
1371 NOTREACHED();
1372 }
1373
[email protected]48c9cf2d2009-09-16 16:47:521374 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081375 static_cast<int32>(log_severity),
[email protected]48c9cf2d2009-09-16 16:47:521376 UTF16ToWideHack(message.text),
1377 static_cast<int32>(source_line),
1378 UTF16ToWideHack(source_name)));
1379}
1380
1381void RenderView::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421382 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521383}
1384
[email protected]3354d3e2010-06-10 19:53:021385WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511386 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021387}
1388
[email protected]8a58c1c2011-04-19 18:40:121389bool RenderView::enumerateChosenDirectory(
1390 const WebString& path,
1391 WebFileChooserCompletion* chooser_completion) {
1392 int id = enumeration_completion_id_++;
1393 enumeration_completions_[id] = chooser_completion;
1394 return Send(new ViewHostMsg_EnumerateDirectory(
1395 routing_id_,
1396 id,
1397 webkit_glue::WebStringToFilePath(path)));
1398}
1399
[email protected]48c9cf2d2009-09-16 16:47:521400void RenderView::didStartLoading() {
1401 if (is_loading_) {
1402 DLOG(WARNING) << "didStartLoading called while loading";
1403 return;
1404 }
1405
1406 is_loading_ = true;
1407 // Clear the pointer so that we can assign it only when there is an unknown
1408 // plugin on a page.
1409 first_default_plugin_.reset();
1410
1411 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311412
1413 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521414}
1415
1416void RenderView::didStopLoading() {
1417 if (!is_loading_) {
1418 DLOG(WARNING) << "DidStopLoading called while not loading";
1419 return;
1420 }
1421
1422 is_loading_ = false;
1423
1424 // NOTE: For now we're doing the safest thing, and sending out notification
1425 // when done loading. This currently isn't an issue as the favicon is only
1426 // displayed when done loading. Ideally we would send notification when
1427 // finished parsing the head, but webkit doesn't support that yet.
1428 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521429 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1430
[email protected]90109412010-12-15 17:14:241431 if (load_progress_tracker_ != NULL)
1432 load_progress_tracker_->DidStopLoading();
1433
[email protected]93b9d692011-04-13 00:44:311434 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521435}
1436
[email protected]90109412010-12-15 17:14:241437void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
1438 if (load_progress_tracker_ != NULL)
1439 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1440}
1441
[email protected]f55039a2010-02-17 14:12:061442bool RenderView::isSmartInsertDeleteEnabled() {
1443#if defined(OS_MACOSX)
1444 return true;
1445#else
1446 return false;
1447#endif
1448}
1449
[email protected]04fc9482009-09-18 22:13:031450bool RenderView::isSelectTrailingWhitespaceEnabled() {
1451#if defined(OS_WIN)
1452 return true;
1453#else
1454 return false;
1455#endif
1456}
1457
[email protected]04fc9482009-09-18 22:13:031458void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:421459#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031460 if (!handling_input_event_)
1461 return;
[email protected]d4cff272011-05-02 15:46:011462
1463 if (is_empty_selection) {
1464 last_selection_.clear();
1465 } else {
[email protected]04fc9482009-09-18 22:13:031466 // Sometimes we get repeated didChangeSelection calls from webkit when
1467 // the selection hasn't actually changed. We don't want to report these
1468 // because it will cause us to continually claim the X clipboard.
[email protected]d4cff272011-05-02 15:46:011469 WebFrame* frame = webview()->focusedFrame();
1470 const std::string& this_selection = frame->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031471 if (this_selection == last_selection_)
1472 return;
[email protected]04fc9482009-09-18 22:13:031473 last_selection_ = this_selection;
[email protected]04fc9482009-09-18 22:13:031474 }
[email protected]d4cff272011-05-02 15:46:011475
1476 ui::Range range(ui::Range::InvalidRange());
1477 size_t location, length;
1478 if (webview()->caretOrSelectionRange(&location, &length)) {
1479 range.set_start(location);
1480 range.set_end(location + length);
1481 }
1482 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range));
[email protected]0ff0ff32010-12-21 19:34:421483#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031484}
1485
1486void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121487 const std::string& name = UTF16ToUTF8(command_name);
1488 if (StartsWithASCII(name, "Move", true) ||
1489 StartsWithASCII(name, "Insert", true) ||
1490 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031491 return;
[email protected]c2043682011-06-10 22:49:561492 RenderThread::current()->Send(
1493 new ViewHostMsg_UserMetricsRecordAction(name));
[email protected]04fc9482009-09-18 22:13:031494}
1495
[email protected]54ec7f82010-10-21 22:32:511496void RenderView::SendPendingAccessibilityNotifications() {
1497 if (!accessibility_.get())
1498 return;
1499
1500 if (pending_accessibility_notifications_.empty())
1501 return;
1502
1503 // Send all pending accessibility notifications.
1504 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
1505 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
1506 RendererAccessibilityNotification& notification =
1507 pending_accessibility_notifications_[i];
1508 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
1509 if (!obj.isValid())
1510 continue;
1511
1512 ViewHostMsg_AccessibilityNotification_Params param;
[email protected]a527a022011-02-10 02:32:361513 WebAccessibilityNotificationToViewHostMsg(
1514 pending_accessibility_notifications_[i].type, &param.notification_type);
[email protected]70eee342010-11-05 01:59:371515 param.acc_obj = WebAccessibility(
1516 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:511517 notifications.push_back(param);
1518 }
1519 pending_accessibility_notifications_.clear();
1520 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
1521 accessibility_ack_pending_ = true;
1522}
1523
[email protected]b2528b72009-09-24 06:57:101524bool RenderView::handleCurrentKeyboardEvent() {
1525 if (edit_commands_.empty())
1526 return false;
1527
[email protected]26aa0482009-09-30 16:55:271528 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101529 if (!frame)
1530 return false;
1531
1532 EditCommands::iterator it = edit_commands_.begin();
1533 EditCommands::iterator end = edit_commands_.end();
1534
[email protected]507b33ea2009-09-29 03:56:511535 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101536 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331537 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1538 // key (but it's the exception). Once one edit command is not executed, it
1539 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101540 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1541 WebString::fromUTF8(it->value)))
1542 break;
[email protected]507b33ea2009-09-29 03:56:511543 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101544 }
1545
[email protected]507b33ea2009-09-29 03:56:511546 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101547}
1548
[email protected]a1128322009-10-06 18:38:461549bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351550 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471551 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351552 // Do not open the file dialog in a hidden RenderView.
1553 if (is_hidden())
1554 return false;
[email protected]cdaf8d02010-03-30 19:52:471555 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261556 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361557 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261558 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361559 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]b5977a0c2010-08-24 19:46:261560 else
[email protected]0aed2f52011-03-23 18:06:361561 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471562 ipc_params.title = params.title;
1563 ipc_params.default_file_name =
1564 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591565 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471566
1567 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461568}
1569
[email protected]48c9cf2d2009-09-16 16:47:521570void RenderView::runModalAlertDialog(
1571 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061572 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]4f5ce842011-05-27 19:34:411573 message,
1574 string16(),
[email protected]48c9cf2d2009-09-16 16:47:521575 frame->url(),
1576 NULL);
1577}
1578
1579bool RenderView::runModalConfirmDialog(
1580 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061581 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]4f5ce842011-05-27 19:34:411582 message,
1583 string16(),
[email protected]48c9cf2d2009-09-16 16:47:521584 frame->url(),
1585 NULL);
1586}
1587
1588bool RenderView::runModalPromptDialog(
1589 WebFrame* frame, const WebString& message, const WebString& default_value,
1590 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411591 string16 result;
[email protected]9dd7e3d72011-01-20 18:27:061592 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]4f5ce842011-05-27 19:34:411593 message,
1594 default_value,
[email protected]48c9cf2d2009-09-16 16:47:521595 frame->url(),
1596 &result);
1597 if (ok)
[email protected]4f5ce842011-05-27 19:34:411598 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521599 return ok;
1600}
1601
1602bool RenderView::runModalBeforeUnloadDialog(
1603 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151604 // If we are swapping out, we have already run the beforeunload handler.
1605 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1606 // at all, to avoid running it twice.
1607 if (is_swapped_out_)
1608 return true;
1609
[email protected]48c9cf2d2009-09-16 16:47:521610 bool success = false;
1611 // This is an ignored return value, but is included so we can accept the same
1612 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411613 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211614 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]4f5ce842011-05-27 19:34:411615 routing_id_, frame->url(), message, &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521616 return success;
1617}
1618
[email protected]79e37442009-10-09 18:17:441619void RenderView::showContextMenu(
1620 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291621 ContextMenuParams params = ContextMenuParams(data);
[email protected]db803aae2011-03-05 02:00:421622 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271623 // it. We replace it with an empty GURL so the appropriate items are disabled
1624 // in the context menu.
1625 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1626 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421627 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271628 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101629 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291630 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441631}
1632
[email protected]52f139e2c2010-06-11 16:56:091633bool RenderView::supportsFullscreen() {
1634 return CommandLine::ForCurrentProcess()->HasSwitch(
1635 switches::kEnableVideoFullscreen);
1636}
1637
1638void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1639 NOTIMPLEMENTED();
1640}
1641
1642void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1643 NOTIMPLEMENTED();
1644}
1645
[email protected]48c9cf2d2009-09-16 16:47:521646void RenderView::setStatusText(const WebString& text) {
1647}
1648
[email protected]163f8242009-10-30 20:19:551649void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581650 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521651 if (latest_url == target_url_)
1652 return;
[email protected]163f8242009-10-30 20:19:551653
[email protected]48c9cf2d2009-09-16 16:47:521654 // Tell the browser to display a destination link.
1655 if (target_url_status_ == TARGET_INFLIGHT ||
1656 target_url_status_ == TARGET_PENDING) {
1657 // If we have a request in-flight, save the URL to be sent when we
1658 // receive an ACK to the in-flight request. We can happily overwrite
1659 // any existing pending sends.
1660 pending_target_url_ = latest_url;
1661 target_url_status_ = TARGET_PENDING;
1662 } else {
1663 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1664 target_url_ = latest_url;
1665 target_url_status_ = TARGET_INFLIGHT;
1666 }
1667}
1668
[email protected]882daa92009-11-05 16:31:311669void RenderView::StartNavStateSyncTimerIfNecessary() {
1670 int delay;
1671 if (send_content_state_immediately_)
1672 delay = 0;
1673 else if (is_hidden())
1674 delay = kDelaySecondsForContentStateSyncHidden;
1675 else
1676 delay = kDelaySecondsForContentStateSync;
1677
1678 if (nav_state_sync_timer_.IsRunning()) {
1679 // The timer is already running. If the delay of the timer maches the amount
1680 // we want to delay by, then return. Otherwise stop the timer so that it
1681 // gets started with the right delay.
1682 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1683 return;
1684 nav_state_sync_timer_.Stop();
1685 }
1686
1687 nav_state_sync_timer_.Start(
1688 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1689}
1690
[email protected]163f8242009-10-30 20:19:551691void RenderView::setMouseOverURL(const WebURL& url) {
1692 mouse_over_url_ = GURL(url);
1693 UpdateTargetURL(mouse_over_url_, focus_url_);
1694}
1695
1696void RenderView::setKeyboardFocusURL(const WebURL& url) {
1697 focus_url_ = GURL(url);
1698 UpdateTargetURL(focus_url_, mouse_over_url_);
1699}
1700
[email protected]c27ae592010-03-18 15:24:411701void RenderView::startDragging(const WebDragData& data,
1702 WebDragOperationsMask mask,
1703 const WebImage& image,
1704 const WebPoint& imageOffset) {
1705#if WEBKIT_USING_SKIA
1706 SkBitmap bitmap(image.getSkBitmap());
1707#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331708 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411709#endif
1710
[email protected]59f4f2fa2011-03-23 01:00:551711 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521712 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411713 mask,
1714 bitmap,
1715 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521716}
1717
[email protected]28b92df2009-09-25 17:35:451718bool RenderView::acceptsLoadDrops() {
1719 return renderer_preferences_.can_accept_load_drops;
1720}
1721
[email protected]48c9cf2d2009-09-16 16:47:521722void RenderView::focusNext() {
1723 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1724}
1725
1726void RenderView::focusPrevious() {
1727 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1728}
1729
[email protected]08e9e132010-06-01 16:58:491730void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511731 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071732
1733 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
1734 // TODO(ctguil): Make WebKit send this notification.
1735 // When focus is cleared notify accessibility that the document is focused.
1736 postAccessibilityNotification(
1737 webview()->accessibilityObject(),
1738 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
1739 }
[email protected]13a1e4c3c2011-02-03 21:07:091740
[email protected]38b592902011-04-16 02:08:421741 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491742}
1743
[email protected]48c9cf2d2009-09-16 16:47:521744void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521745 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1746}
1747
1748int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001749 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521750}
1751
1752int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001753 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521754}
1755
[email protected]c4e98902010-06-01 10:20:141756void RenderView::didUpdateInspectorSetting(const WebString& key,
1757 const WebString& value) {
1758 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1759 key.utf8(),
1760 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261761}
1762
[email protected]79dbc662009-09-04 05:42:511763// WebKit::WebWidgetClient ----------------------------------------------------
1764
[email protected]ea42e7782010-08-23 23:58:121765void RenderView::didFocus() {
1766 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1767 // we won't have to test for user gesture anymore and we can
1768 // move that code back to render_widget.cc
1769 if (webview() && webview()->mainFrame() &&
1770 webview()->mainFrame()->isProcessingUserGesture()) {
1771 Send(new ViewHostMsg_Focus(routing_id_));
1772 }
1773}
1774
1775void RenderView::didBlur() {
1776 // TODO(jcivelli): see TODO above in didFocus().
1777 if (webview() && webview()->mainFrame() &&
1778 webview()->mainFrame()->isProcessingUserGesture()) {
1779 Send(new ViewHostMsg_Blur(routing_id_));
1780 }
1781}
1782
initial.commit09911bf2008-07-26 23:55:291783// We are supposed to get a single call to Show for a newly created RenderView
1784// that was created via RenderView::CreateWebView. So, we wait until this
1785// point to dispatch the ShowView message.
1786//
1787// This method provides us with the information about how to display the newly
1788// created RenderView (i.e., as a constrained popup or as a new tab).
1789//
[email protected]4873c7d2009-07-16 06:36:281790void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291791 DCHECK(!did_show_) << "received extraneous Show call";
1792 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1793
1794 if (did_show_)
1795 return;
1796 did_show_ = true;
1797
[email protected]6779aa12011-03-29 17:32:241798 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041799 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041800
[email protected]28295ec2009-10-16 05:34:331801 // Force new windows to a popup if they were not opened with a user gesture.
1802 if (!opened_by_user_gesture_) {
1803 // We exempt background tabs for compat with older versions of Chrome.
1804 // TODO(darin): This seems bogus. These should have a user gesture, so
1805 // we probably don't need this check.
1806 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1807 policy = WebKit::WebNavigationPolicyNewPopup;
1808 }
1809
initial.commit09911bf2008-07-26 23:55:291810 // NOTE: initial_pos_ may still have its default values at this point, but
1811 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1812 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281813 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1814 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291815 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241816 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291817}
1818
[email protected]4873c7d2009-07-16 06:36:281819void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291820 DCHECK(did_show_) << "should already have shown the view";
1821
[email protected]c1f50aa2010-02-18 03:46:571822 // We must keep WebKit's shared timer running in this case in order to allow
1823 // showModalDialog to function properly.
1824 //
1825 // TODO(darin): WebKit should really be smarter about suppressing events and
1826 // timers so that we do not need to manage the shared timer in such a heavy
1827 // handed manner.
1828 //
1829 if (RenderThread::current()) // Will be NULL during unit tests.
1830 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
1831
[email protected]12636df2009-09-28 22:32:211832 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291833}
1834
[email protected]3d9689372009-09-10 04:29:171835// WebKit::WebFrameClient -----------------------------------------------------
1836
[email protected]00152e92010-07-19 11:47:401837WebPlugin* RenderView::createPlugin(WebFrame* frame,
1838 const WebPluginParams& params) {
[email protected]e7c21b812011-03-19 18:03:301839 return content::GetContentClient()->renderer()->CreatePlugin(
[email protected]21d61e52011-03-18 19:08:251840 this, frame, params);
[email protected]3d9689372009-09-10 04:29:171841}
1842
1843WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561844 WebApplicationCacheHostImpl* appcache_host =
1845 WebApplicationCacheHostImpl::FromFrame(frame);
1846 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
1847 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
1848 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171849}
1850
[email protected]9c00f002009-11-05 22:37:421851WebSharedWorker* RenderView::createSharedWorker(
1852 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371853 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421854
[email protected]30447b62009-11-13 01:13:371855 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511856 bool exists = false;
[email protected]30447b62009-11-13 01:13:371857 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511858 ViewHostMsg_CreateWorker_Params params;
1859 params.url = url;
1860 params.is_shared = true;
1861 params.name = name;
1862 params.document_id = document_id;
1863 params.render_view_route_id = routing_id_;
1864 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231865 params.parent_appcache_host_id = 0;
1866 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371867 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511868 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371869 if (url_mismatch) {
1870 return NULL;
1871 } else {
1872 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:491873 document_id,
[email protected]6de0bcf2010-02-17 22:00:511874 exists,
[email protected]30447b62009-11-13 01:13:371875 route_id,
1876 routing_id_);
1877 }
[email protected]9c00f002009-11-05 22:37:421878}
1879
[email protected]3d9689372009-09-10 04:29:171880WebMediaPlayer* RenderView::createMediaPlayer(
1881 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441882 FOR_EACH_OBSERVER(
1883 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171884
[email protected]f78d1dfc2011-01-15 07:09:271885 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1886 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491887 scoped_ptr<media::FilterCollection> collection(
1888 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371889
[email protected]3d9689372009-09-10 04:29:171890 // Add in any custom filter factories first.
1891 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1892 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1893 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:491894 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:171895 }
1896
[email protected]457d8342010-10-23 01:20:371897 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:311898 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
1899 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
1900 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:491901 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:311902 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:111903
[email protected]a8e24d522010-12-01 07:13:581904 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:271905 new webkit_glue::WebMediaPlayerImpl(client,
1906 collection.release(),
1907 message_loop_factory.release()));
[email protected]79684282010-12-06 21:15:461908 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:581909 cmd_line->HasSwitch(switches::kSimpleDataSource),
1910 video_renderer)) {
1911 return NULL;
1912 }
1913 return result.release();
[email protected]3d9689372009-09-10 04:29:171914}
1915
[email protected]035545f2010-04-09 13:10:211916WebApplicationCacheHost* RenderView::createApplicationCacheHost(
1917 WebFrame* frame, WebApplicationCacheHostClient* client) {
1918 return new RendererWebApplicationCacheHostImpl(
1919 FromWebView(frame->view()), client,
1920 RenderThread::current()->appcache_dispatcher()->backend_proxy());
1921}
1922
[email protected]8ff181072010-11-29 17:09:381923WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
1924 return &cookie_jar_;
1925}
1926
[email protected]5041f982010-08-11 21:40:451927void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511928 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451929}
1930
[email protected]3d9689372009-09-10 04:29:171931void RenderView::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511932 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171933}
1934
1935void RenderView::loadURLExternally(
1936 WebFrame* frame, const WebURLRequest& request,
1937 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:591938 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1939 if (policy == WebKit::WebNavigationPolicyDownload) {
1940 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1941 } else {
1942 OpenURL(request.url(), referrer, policy);
1943 }
[email protected]3d9689372009-09-10 04:29:171944}
1945
1946WebNavigationPolicy RenderView::decidePolicyForNavigation(
1947 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221948 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:151949 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
1950 if (is_swapped_out_) {
1951 DCHECK(request.url() == GURL("about:swappedout"));
1952 return default_policy;
1953 }
1954
[email protected]3d9689372009-09-10 04:29:171955 // Webkit is asking whether to navigate to a new URL.
1956 // This is fine normally, except if we're showing UI from one security
1957 // context and they're trying to navigate to a different context.
1958 const GURL& url = request.url();
1959
[email protected]d19ea342011-04-20 20:31:131960 // A content initiated navigation may have originated from a link-click,
1961 // script, drag-n-drop operation, etc.
1962 bool is_content_initiated =
1963 NavigationState::FromDataSource(frame->provisionalDataSource())->
1964 is_content_initiated();
1965
[email protected]3d9689372009-09-10 04:29:171966 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:301967 // navigations.
[email protected]d19ea342011-04-20 20:31:131968 if (is_content_initiated &&
1969 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:451970 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:191971 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:231972 // Reset these counters as the RenderView could be reused for the next
1973 // navigation.
1974 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:231975 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:191976 OpenURL(url, referrer, default_policy);
1977 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:171978 }
1979
[email protected]a6b960ad972010-09-01 19:53:581980 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:171981
[email protected]6101c342010-12-16 22:44:371982 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:551983 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:571984 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:371985 // opening a new window). But we sometimes navigate to about:blank to clear a
1986 // tab, and we want to still allow that.
1987 //
[email protected]8f4da8c2011-02-09 19:49:571988 // Note: we do this only for GET requests because our mechanism for switching
1989 // processes only issues GET requests. In particular, POST requests don't
1990 // work, because this mechanism does not preserve form POST data. If it
1991 // becomes necessary to support process switching for POST requests, we will
1992 // need to send the request's httpBody data up to the browser process, and
1993 // issue a special POST navigation in WebKit (via
1994 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
1995 // for examples of how to send the httpBody data.
1996 // Note2: We normally don't do this for browser-initiated navigations, since
1997 // it's pointless to tell the browser about navigations it gave us. But
1998 // we do potentially ask the browser to handle a redirect that was originally
1999 // initiated by the browser. See http://crbug.com/70943
2000 //
2001 // TODO(creis): Move this redirect check to the browser process to avoid
2002 // ping-ponging. See http://crbug.com/72380.
2003 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372004 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2005 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2006 bool send_referrer = false;
2007 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552008 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172009 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372010 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112011
[email protected]e48869a2011-04-01 19:56:032012 if (!should_fork) {
2013 // Give the embedder a chance.
2014 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2015 frame, url, is_content_initiated, &send_referrer);
[email protected]6101c342010-12-16 22:44:372016 }
2017
2018 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112019 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372020 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112021 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2022 }
[email protected]3d9689372009-09-10 04:29:172023 }
2024
2025 // Detect when a page is "forking" a new tab that can be safely rendered in
2026 // its own process. This is done by sites like Gmail that try to open links
2027 // in new windows without script connections back to the original page. We
2028 // treat such cases as browser navigations (in which we will create a new
2029 // renderer for a cross-site navigation), rather than WebKit navigations.
2030 //
2031 // We use the following heuristic to decide whether to fork a new page in its
2032 // own process:
2033 // The parent page must open a new tab to about:blank, set the new tab's
2034 // window.opener to null, and then redirect the tab to a cross-site URL using
2035 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462036 //
2037 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2038 // (see below).
[email protected]3d9689372009-09-10 04:29:172039 bool is_fork =
2040 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582041 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172042 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522043 historyBackListCount() < 1 &&
2044 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172045 // The parent page must have set the child's window.opener to null before
2046 // redirecting to the desired URL.
2047 frame->opener() == NULL &&
2048 // Must be a top-level frame.
2049 frame->parent() == NULL &&
2050 // Must not have issued the request from this page.
2051 is_content_initiated &&
2052 // Must be targeted at the current tab.
2053 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2054 // Must be a JavaScript navigation, which appears as "other".
2055 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462056
2057 // Recognize if this navigation is from a link with rel=noreferrer and
2058 // target=_blank attributes, in which case the opener will be suppressed. If
2059 // so, it is safe to load cross-site pages in a separate process, so we
2060 // should let the browser handle it.
2061 bool is_noreferrer_and_blank_target =
2062 // Frame should be top level and not yet navigated.
2063 frame->parent() == NULL &&
2064 frame->url().isEmpty() &&
2065 historyBackListCount() < 1 &&
2066 historyForwardListCount() < 1 &&
2067 // Links with rel=noreferrer will have no Referer field, and their
2068 // resulting frame will have its window.opener suppressed.
2069 // TODO(creis): should add a request.httpReferrer() method to help avoid
2070 // typos on the unusual spelling of Referer.
2071 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2072 opener_suppressed_ &&
2073 frame->opener() == NULL &&
2074 // Links with target=_blank will have no name.
2075 frame->name().isNull() &&
2076 // Another frame (with a non-empty creator) should have initiated the
2077 // request, targeted at this frame.
2078 !creator_url_.is_empty() &&
2079 is_content_initiated &&
2080 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2081 type == WebKit::WebNavigationTypeOther;
2082
2083 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172084 // Open the URL via the browser, not via WebKit.
2085 OpenURL(url, GURL(), default_policy);
2086 return WebKit::WebNavigationPolicyIgnore;
2087 }
2088
2089 return default_policy;
2090}
2091
[email protected]6069da8c2009-10-20 20:33:492092bool RenderView::canHandleRequest(
2093 WebFrame* frame, const WebURLRequest& request) {
2094 // We allow WebKit to think that everything can be handled even though
2095 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342096 return true;
2097}
2098
[email protected]6069da8c2009-10-20 20:33:492099WebURLError RenderView::cannotHandleRequestError(
2100 WebFrame* frame, const WebURLRequest& request) {
2101 NOTREACHED(); // Since we said we can handle all requests.
2102 return WebURLError();
2103}
2104
2105WebURLError RenderView::cancelledError(
2106 WebFrame* frame, const WebURLRequest& request) {
2107 WebURLError error;
2108 error.domain = WebString::fromUTF8(net::kErrorDomain);
2109 error.reason = net::ERR_ABORTED;
2110 error.unreachableURL = request.url();
2111 return error;
[email protected]7b7a7dc2009-10-19 02:23:342112}
2113
2114void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492115 WebFrame*, const WebURLError&) {
2116 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342117}
2118
[email protected]90eeddb2010-05-06 21:06:432119void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2120 const WebKit::WebFormElement& form) {
2121 // Some login forms have onSubmit handlers that put a hash of the password
2122 // into a hidden field and then clear the password. (Issue 28910.)
2123 // This method gets called before any of those handlers run, so save away
2124 // a copy of the password in case it gets lost.
2125 NavigationState* navigation_state =
2126 NavigationState::FromDataSource(frame->dataSource());
2127 navigation_state->set_password_form_data(
2128 PasswordFormDomManager::CreatePasswordForm(form));
2129}
2130
[email protected]979c28b2009-11-07 01:30:482131void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172132 NavigationState* navigation_state =
2133 NavigationState::FromDataSource(frame->provisionalDataSource());
2134
2135 if (navigation_state->transition_type() == PageTransition::LINK)
2136 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2137
2138 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352139 WebSearchableFormData web_searchable_form_data(form);
2140 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2141 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212142 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432143 PasswordForm* password_form_data =
2144 PasswordFormDomManager::CreatePasswordForm(form);
2145 navigation_state->set_password_form_data(password_form_data);
2146
[email protected]098c95cb2011-04-28 16:49:012147 // In order to save the password that the user actually typed and not one
2148 // that may have gotten transformed by the site prior to submit, recover it
2149 // from the form contents already stored by |willSendSubmitEvent| into the
2150 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2151 // which is what we're storing into now.)
2152 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432153 NavigationState* old_navigation_state =
2154 NavigationState::FromDataSource(frame->dataSource());
2155 if (old_navigation_state) {
2156 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2157 if (old_form_data && old_form_data->action == password_form_data->action)
2158 password_form_data->password_value = old_form_data->password_value;
2159 }
2160 }
[email protected]3d9689372009-09-10 04:29:172161
[email protected]2a5b1732011-04-01 23:55:552162 FOR_EACH_OBSERVER(
2163 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172164}
2165
2166void RenderView::willPerformClientRedirect(
2167 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2168 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382169 FOR_EACH_OBSERVER(
2170 RenderViewObserver, observers_,
2171 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172172}
2173
2174void RenderView::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382175 FOR_EACH_OBSERVER(
2176 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172177}
2178
2179void RenderView::didCompleteClientRedirect(
2180 WebFrame* frame, const WebURL& from) {
2181 if (!frame->parent())
2182 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382183 FOR_EACH_OBSERVER(
2184 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172185}
2186
2187void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2188 // The rest of RenderView assumes that a WebDataSource will always have a
2189 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482190 bool content_initiated = !pending_navigation_state_.get();
2191 NavigationState* state = content_initiated ?
2192 NavigationState::CreateContentInitiated() :
2193 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512194
[email protected]8a3125a712010-08-09 18:58:512195 // NavigationState::referred_by_prefetcher_ is true if we are
2196 // navigating from a page that used prefetching using a link on that
2197 // page. We are early enough in the request process here that we
2198 // can still see the NavigationState of the previous page and set
2199 // this value appropriately.
2200 // TODO(gavinp): catch the important case of navigation in a new
2201 // renderer process.
2202 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302203 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522204 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512205 const GURL referrer(
2206 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2207 if (!referrer.is_empty() &&
2208 NavigationState::FromDataSource(
2209 old_frame->dataSource())->was_prefetcher()) {
2210 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2211 WebDataSource* old_frame_ds = old_frame->dataSource();
2212 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2213 state->set_was_referred_by_prefetcher(true);
2214 break;
2215 }
2216 }
2217 }
2218 }
2219 }
2220
[email protected]4c1b6f0b2010-02-07 16:38:182221 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522222 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512223 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182224 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2225 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2226 break;
2227 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2228 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2229 break;
2230 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2231 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2232 break;
2233 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2234 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2235 break;
2236 }
2237 }
[email protected]fa7b6b542009-11-03 05:02:302238
[email protected]16e923d2011-04-30 00:41:442239 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502240
[email protected]946a0032011-03-31 18:42:282241 FOR_EACH_OBSERVER(
2242 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172243}
2244
2245void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2246 WebDataSource* ds = frame->provisionalDataSource();
2247 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2248
[email protected]3d9689372009-09-10 04:29:172249 // Update the request time if WebKit has better knowledge of it.
2250 if (navigation_state->request_time().is_null()) {
2251 double event_time = ds->triggeringEventTime();
2252 if (event_time != 0.0)
2253 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2254 }
2255
[email protected]05c8e502010-08-15 15:13:522256 // Start time is only set after request time.
2257 navigation_state->set_start_load_time(Time::Now());
2258
[email protected]3d9689372009-09-10 04:29:172259 bool is_top_most = !frame->parent();
2260 if (is_top_most) {
2261 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132262 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172263
2264 // Make sure redirect tracking state is clear for the new load.
2265 completed_client_redirect_src_ = GURL();
2266 } else if (frame->parent()->isLoading()) {
2267 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002268 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172269 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2270 }
2271
[email protected]28685da92011-02-07 21:49:172272 FOR_EACH_OBSERVER(
2273 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2274
[email protected]eacb080b2011-05-22 19:40:262275 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]3d9689372009-09-10 04:29:172276 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]eacb080b2011-05-22 19:40:262277 routing_id_, frame->identifier(), is_top_most, has_opener_set,
2278 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172279}
2280
2281void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2282 if (frame->parent())
2283 return;
2284 // Received a redirect on the main frame.
2285 WebDataSource* data_source = frame->provisionalDataSource();
2286 if (!data_source) {
2287 // Should only be invoked when we have a data source.
2288 NOTREACHED();
2289 return;
2290 }
2291 std::vector<GURL> redirects;
2292 GetRedirectChain(data_source, &redirects);
2293 if (redirects.size() >= 2) {
[email protected]eacb080b2011-05-22 19:40:262294 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]40bd6582009-12-04 23:49:512295 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]eacb080b2011-05-22 19:40:262296 has_opener_set, redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172297 }
2298}
2299
[email protected]40bd6582009-12-04 23:49:512300void RenderView::didFailProvisionalLoad(WebFrame* frame,
2301 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172302 // Notify the browser that we failed a provisional load with an error.
2303 //
2304 // Note: It is important this notification occur before DidStopLoading so the
2305 // SSL manager can react to the provisional load failure before being
2306 // notified the load stopped.
2307 //
2308 WebDataSource* ds = frame->provisionalDataSource();
2309 DCHECK(ds);
2310
2311 const WebURLRequest& failed_request = ds->request();
2312
[email protected]28685da92011-02-07 21:49:172313 FOR_EACH_OBSERVER(
2314 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2315
[email protected]3d9689372009-09-10 04:29:172316 bool show_repost_interstitial =
2317 (error.reason == net::ERR_CACHE_MISS &&
2318 EqualsASCII(failed_request.httpMethod(), "POST"));
2319 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072320 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2321 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172322
2323 // Don't display an error page if this is simply a cancelled load. Aside
2324 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2325 if (error.reason == net::ERR_ABORTED)
2326 return;
2327
2328 // Make sure we never show errors in view source mode.
2329 frame->enableViewSourceMode(false);
2330
2331 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2332
2333 // If this is a failed back/forward/reload navigation, then we need to do a
2334 // 'replace' load. This is necessary to avoid messing up session history.
2335 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2336 // as session history is concerned.
2337 //
2338 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2339 // the page id.
2340 //
2341 bool replace =
2342 navigation_state->pending_page_id() != -1 ||
2343 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2344
2345 // If we failed on a browser initiated request, then make sure that our error
2346 // page load is regarded as the same browser initiated request.
2347 if (!navigation_state->is_content_initiated()) {
2348 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2349 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002350 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172351 navigation_state->transition_type(),
2352 navigation_state->request_time()));
2353 }
2354
2355 // Provide the user with a more helpful error page?
2356 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2357 return;
2358
2359 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082360 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172361}
2362
2363void RenderView::didReceiveDocumentData(
2364 WebFrame* frame, const char* data, size_t data_len,
2365 bool& prevent_default) {
2366 NavigationState* navigation_state =
2367 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092368 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172369}
2370
[email protected]40bd6582009-12-04 23:49:512371void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2372 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172373 NavigationState* navigation_state =
2374 NavigationState::FromDataSource(frame->dataSource());
2375
2376 navigation_state->set_commit_load_time(Time::Now());
2377 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202378 // When we perform a new navigation, we need to update the last committed
2379 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172380 UpdateSessionHistory(frame);
2381
2382 // We bump our Page ID to correspond with the new session history entry.
2383 page_id_ = next_page_id_++;
2384
[email protected]3cc72b12010-03-18 23:03:002385 // Advance our offset in session history, applying the length limit. There
2386 // is now no forward history.
2387 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102388 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2389 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002390 history_list_length_ = history_list_offset_ + 1;
[email protected]3d9689372009-09-10 04:29:172391 } else {
2392 // Inspect the navigation_state on this frame to see if the navigation
2393 // corresponds to a session history navigation... Note: |frame| may or
2394 // may not be the toplevel frame, but for the case of capturing session
2395 // history, the first committed frame suffices. We keep track of whether
2396 // we've seen this commit before so that only capture session history once
2397 // per navigation.
2398 //
2399 // Note that we need to check if the page ID changed. In the case of a
2400 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2401 // previous URL and the current page ID, which would be wrong.
2402 if (navigation_state->pending_page_id() != -1 &&
2403 navigation_state->pending_page_id() != page_id_ &&
2404 !navigation_state->request_committed()) {
2405 // This is a successful session history navigation!
2406 UpdateSessionHistory(frame);
2407 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002408
2409 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172410 }
2411 }
2412
[email protected]28685da92011-02-07 21:49:172413 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2414 DidCommitProvisionalLoad(frame, is_new_navigation));
2415
[email protected]3d9689372009-09-10 04:29:172416 // Remember that we've already processed this request, so we don't update
2417 // the session history again. We do this regardless of whether this is
2418 // a session history navigation, because if we attempted a session history
2419 // navigation without valid HistoryItem state, WebCore will think it is a
2420 // new navigation.
2421 navigation_state->set_request_committed(true);
2422
2423 UpdateURL(frame);
2424
2425 // If this committed load was initiated by a client redirect, we're
2426 // at the last stop now, so clear it.
2427 completed_client_redirect_src_ = GURL();
2428
2429 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272430 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172431}
2432
2433void RenderView::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102434 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2435 DidClearWindowObject(frame));
2436
[email protected]0d7ae862010-10-01 13:52:452437 GURL frame_url = frame->url();
[email protected]c09163a2011-02-15 00:05:552438 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:252439 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2440 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272441 GetWebUIBindings()->set_message_sender(this);
2442 GetWebUIBindings()->set_routing_id(routing_id_);
2443 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172444 }
[email protected]3d9689372009-09-10 04:29:172445}
2446
2447void RenderView::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172448 // Notify the browser about non-blank documents loading in the top frame.
2449 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252450 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272451 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172452 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2453 }
[email protected]e48869a2011-04-01 19:56:032454
2455 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2456 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172457}
2458
[email protected]a3bc4d12011-04-20 17:22:212459void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title,
2460 WebTextDirection direction) {
[email protected]6b2f7a82011-04-25 19:30:512461 // TODO: pass direction through various APIs.
2462 // http://code.google.com/p/chromium/issues/detail?id=79903
2463 UpdateTitle(frame, title);
[email protected]3d9689372009-09-10 04:29:172464
2465 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272466 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172467}
2468
[email protected]42054a252011-05-17 18:02:132469void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
2470 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2471 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582472}
2473
[email protected]3d9689372009-09-10 04:29:172474void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2475 WebDataSource* ds = frame->dataSource();
2476 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2477 DCHECK(navigation_state);
2478 navigation_state->set_finish_document_load_time(Time::Now());
2479
[email protected]622474d2010-11-04 09:21:082480 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172481
[email protected]28685da92011-02-07 21:49:172482 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2483 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172484
2485 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272486 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172487}
2488
2489void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082490 if (webview()->mainFrame() == frame) {
2491 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2492 page_id_));
2493 }
[email protected]3d9689372009-09-10 04:29:172494}
2495
2496void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172497 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172498}
2499
2500void RenderView::didFinishLoad(WebFrame* frame) {
2501 WebDataSource* ds = frame->dataSource();
2502 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2503 DCHECK(navigation_state);
2504 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412505
[email protected]676126f72011-01-15 00:03:512506 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172507
2508 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172509}
2510
[email protected]ccbe04e2010-03-17 17:58:432511void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172512 WebFrame* frame, bool is_new_navigation) {
2513 // If this was a reference fragment navigation that we initiated, then we
2514 // could end up having a non-null pending navigation state. We just need to
2515 // update the ExtraData on the datasource so that others who read the
2516 // ExtraData will get the new NavigationState. Similarly, if we did not
2517 // initiate this navigation, then we need to take care to reset any pre-
2518 // existing navigation state to a content-initiated navigation state.
2519 // DidCreateDataSource conveniently takes care of this for us.
2520 didCreateDataSource(frame, frame->dataSource());
2521
[email protected]af15bed2010-08-25 21:12:092522 NavigationState* new_state =
2523 NavigationState::FromDataSource(frame->dataSource());
2524 new_state->set_was_within_same_page(true);
2525
[email protected]3d9689372009-09-10 04:29:172526 didCommitProvisionalLoad(frame, is_new_navigation);
2527
[email protected]6b2f7a82011-04-25 19:30:512528 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172529}
2530
[email protected]476b6f82009-09-10 21:00:592531void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312532 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592533}
2534
[email protected]3d9689372009-09-10 04:29:172535void RenderView::assignIdentifierToRequest(
2536 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2537 // Ignore
2538}
2539
2540void RenderView::willSendRequest(
2541 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2542 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302543 WebFrame* top_frame = frame->top();
2544 if (!top_frame)
2545 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512546 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2547 WebDataSource* top_data_source = top_frame->dataSource();
2548 WebDataSource* data_source =
2549 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222550
[email protected]e48869a2011-04-01 19:56:032551
[email protected]78d5cfe2011-02-04 08:43:222552 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032553 GURL new_url;
2554 if (content::GetContentClient()->renderer()->WillSendRequest(
2555 frame, request_url, &new_url)) {
2556 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222557 }
2558
[email protected]5e369672009-11-03 23:48:302559 if (data_source) {
2560 NavigationState* state = NavigationState::FromDataSource(data_source);
2561 if (state && state->is_cache_policy_override_set())
2562 request.setCachePolicy(state->cache_policy_override());
2563 }
[email protected]8a3125a712010-08-09 18:58:512564
2565 if (top_data_source) {
2566 NavigationState* state = NavigationState::FromDataSource(top_data_source);
[email protected]61a99dd82011-05-24 19:19:472567 // TODO(gavinp): separate out prefetching and prerender field trials
2568 // if the rel=prerender rel type is sticking around.
2569 if (state && (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2570 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]8a3125a712010-08-09 18:58:512571 state->set_was_prefetcher(true);
2572 }
2573
[email protected]3d9689372009-09-10 04:29:172574 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132575 request.setHasUserGesture(frame->isProcessingUserGesture());
2576
[email protected]0a8db0d2011-04-13 15:15:402577 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132578 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492579
[email protected]85cc78c2010-05-04 18:30:092580 // Temporary metrics, see site_isolation_metrics.h
2581 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:172582}
2583
2584void RenderView::didReceiveResponse(
2585 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492586
[email protected]85cc78c2010-05-04 18:30:092587 // Temporary metrics, see site_isolation_metrics.h
2588 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
2589 identifier,
2590 response);
[email protected]fa0a3432010-03-30 16:53:492591
[email protected]3d9689372009-09-10 04:29:172592 // Only do this for responses that correspond to a provisional data source
2593 // of the top-most frame. If we have a provisional data source, then we
2594 // can't have any sub-resources yet, so we know that this response must
2595 // correspond to a frame load.
2596 if (!frame->provisionalDataSource() || frame->parent())
2597 return;
2598
2599 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082600 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172601 if (frame->isViewSourceModeEnabled())
2602 return;
2603
[email protected]65041fa2010-05-21 06:56:532604 NavigationState* navigation_state =
2605 NavigationState::FromDataSource(frame->provisionalDataSource());
2606 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082607 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532608
[email protected]972ebdff2010-06-10 22:59:072609 // Record page load flags.
2610 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2611 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572612 navigation_state->set_was_alternate_protocol_available(
2613 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072614 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082615 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092616 // Whether or not the http status code actually corresponds to an error is
2617 // only checked when the page is done loading, if |use_error_page| is
2618 // still true.
2619 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172620}
2621
2622void RenderView::didFinishResourceLoad(
2623 WebFrame* frame, unsigned identifier) {
2624 NavigationState* navigation_state =
2625 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092626 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172627 return;
2628
[email protected]06333afe2011-02-24 14:55:092629 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082630 int http_status_code = navigation_state->http_status_code();
2631 if (http_status_code == 404) {
2632 // On 404s, try a remote search page as a fallback.
2633 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:172634
[email protected]3f853a52010-09-13 19:15:082635 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092636 if (error_page_url.is_valid()) {
2637 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472638 original_error.domain = "http";
2639 original_error.reason = 404;
[email protected]06333afe2011-02-24 14:55:092640 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:172641
[email protected]06333afe2011-02-24 14:55:092642 navigation_state->set_alt_error_page_fetcher(
2643 new AltErrorPageResourceFetcher(
2644 error_page_url, frame, original_error,
2645 NewCallback(this, &RenderView::AltErrorPageFinished)));
2646 return;
2647 }
2648 }
[email protected]3d9689372009-09-10 04:29:172649
[email protected]9966325b2011-04-18 05:00:102650 content::GetContentClient()->renderer()->ShowErrorPage(
2651 this, frame, http_status_code);
[email protected]3d9689372009-09-10 04:29:172652}
2653
2654void RenderView::didFailResourceLoad(
2655 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2656 // Ignore
2657}
2658
2659void RenderView::didLoadResourceFromMemoryCache(
2660 WebFrame* frame, const WebURLRequest& request,
2661 const WebURLResponse& response) {
2662 // Let the browser know we loaded a resource from the memory cache. This
2663 // message is needed to display the correct SSL indicators.
2664 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2665 routing_id_,
2666 request.url(),
[email protected]3d9689372009-09-10 04:29:172667 response.securityInfo()));
2668}
2669
[email protected]6069da8c2009-10-20 20:33:492670void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292671 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2672}
2673
[email protected]92771112011-01-20 00:13:022674void RenderView::didRunInsecureContent(
2675 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292676 Send(new ViewHostMsg_DidRunInsecureContent(
2677 routing_id_,
[email protected]92771112011-01-20 00:13:022678 origin.toString().utf8(),
2679 target));
[email protected]e3d60e5d2009-09-25 21:08:292680}
2681
[email protected]3d9689372009-09-10 04:29:172682void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2683 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2684}
2685
[email protected]0c882b282009-10-07 17:01:282686void RenderView::didCreateScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032687 content::GetContentClient()->renderer()->DidCreateScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282688}
2689
2690void RenderView::didDestroyScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032691 content::GetContentClient()->renderer()->DidDestroyScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282692}
2693
2694void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032695 content::GetContentClient()->renderer()->DidCreateIsolatedScriptContext(
2696 frame);
[email protected]0c882b282009-10-07 17:01:282697}
2698
[email protected]fc86daa2010-03-30 23:52:532699void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
2700 WebFrame* target,
2701 bool cross_origin,
2702 const WebString& property_name,
2703 unsigned long long event_id) {
[email protected]6cf19311f2011-04-14 23:06:022704 FOR_EACH_OBSERVER(
2705 RenderViewObserver,
2706 observers_,
2707 LogCrossFramePropertyAccess(
2708 frame, target, cross_origin, property_name, event_id));
[email protected]ab9eabac2010-03-16 16:54:102709}
2710
[email protected]d812fd12011-05-27 23:05:072711void RenderView::didUpdateLayout(WebFrame* frame) {
2712 // We don't always want to set up a timer, only if we've been put in that
2713 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172714 // message.
[email protected]705243f2010-05-05 19:58:072715 if (!send_preferred_size_changes_ || !webview())
2716 return;
[email protected]dfca5acf2010-03-22 03:28:432717
[email protected]d812fd12011-05-27 23:05:072718 if (check_preferred_size_timer_.IsRunning())
2719 return;
2720 check_preferred_size_timer_.Start(TimeDelta::FromMilliseconds(0), this,
2721 &RenderView::CheckPreferredSize);
2722}
2723
2724void RenderView::CheckPreferredSize() {
2725 // We don't always want to send the change messages over IPC, only if we've
2726 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2727 // message.
2728 if (!send_preferred_size_changes_ || !webview())
2729 return;
2730
[email protected]705243f2010-05-05 19:58:072731 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2732 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532733
2734 // In the presence of zoom, these sizes are still reported as if unzoomed,
2735 // so we need to adjust.
2736 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2737 size.set_width(static_cast<int>(size.width() * zoom_factor));
2738 size.set_height(static_cast<int>(size.height() * zoom_factor));
2739
[email protected]705243f2010-05-05 19:58:072740 if (size == preferred_size_)
2741 return;
[email protected]c27324b2009-11-19 22:44:292742
[email protected]705243f2010-05-05 19:58:072743 preferred_size_ = size;
2744 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2745 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172746}
2747
[email protected]143dcd592009-11-06 21:33:492748void RenderView::didChangeScrollOffset(WebFrame* frame) {
2749 StartNavStateSyncTimerIfNecessary();
2750}
2751
[email protected]8922e1f2009-10-03 05:01:262752void RenderView::reportFindInPageMatchCount(int request_id, int count,
2753 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112754 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2755 if (!count)
2756 active_match_ordinal = 0;
2757
2758 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2759 routing_id_,
2760 request_id,
2761 count,
2762 gfx::Rect(),
2763 active_match_ordinal,
2764 final_update);
2765
[email protected]8922e1f2009-10-03 05:01:262766 // If we have a message that has been queued up, then we should just replace
2767 // it. The ACK from the browser will make sure it gets sent when the browser
2768 // wants it.
2769 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262770 queued_find_reply_message_.reset(msg);
2771 } else {
2772 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112773 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262774 }
2775}
2776
2777void RenderView::reportFindInPageSelection(int request_id,
2778 int active_match_ordinal,
2779 const WebRect& selection_rect) {
2780 // Send the search result over to the browser process.
2781 Send(new ViewHostMsg_Find_Reply(routing_id_,
2782 request_id,
2783 -1,
2784 selection_rect,
2785 active_match_ordinal,
2786 false));
2787}
2788
[email protected]2b06a992010-08-21 05:48:222789void RenderView::openFileSystem(
2790 WebFrame* frame,
2791 WebFileSystem::Type type,
2792 long long size,
[email protected]d275d7a2010-11-03 01:34:492793 bool create,
[email protected]2b06a992010-08-21 05:48:222794 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082795 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222796
2797 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082798 if (origin.isEmpty()) {
2799 // Uninitialized document?
2800 callbacks->didFail(WebKit::WebFileErrorAbort);
2801 return;
2802 }
[email protected]2b06a992010-08-21 05:48:222803
[email protected]c5a272d2010-09-27 18:37:082804 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2805 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492806 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222807}
2808
[email protected]10e5cf12011-04-13 04:10:402809void RenderView::queryStorageUsageAndQuota(
2810 WebFrame* frame,
2811 WebStorageQuotaType type,
2812 WebStorageQuotaCallbacks* callbacks) {
2813 DCHECK(frame);
2814 WebSecurityOrigin origin = frame->securityOrigin();
2815 if (origin.isEmpty()) {
2816 // Uninitialized document?
2817 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2818 return;
2819 }
2820 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
2821 GURL(origin.toString()), type, callbacks);
2822}
2823
2824void RenderView::requestStorageQuota(
2825 WebFrame* frame,
2826 WebStorageQuotaType type,
2827 unsigned long long requested_size,
2828 WebStorageQuotaCallbacks* callbacks) {
2829 DCHECK(frame);
2830 WebSecurityOrigin origin = frame->securityOrigin();
2831 if (origin.isEmpty()) {
2832 // Uninitialized document?
2833 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2834 return;
2835 }
2836 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]317f96c92011-05-31 06:53:412837 routing_id(), GURL(origin.toString()), type, requested_size, callbacks);
[email protected]10e5cf12011-04-13 04:10:402838}
2839
[email protected]79dbc662009-09-04 05:42:512840// webkit_glue::WebPluginPageDelegate -----------------------------------------
2841
[email protected]191eb3f72010-12-21 06:27:502842webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:532843 const FilePath& file_path,
2844 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:592845 if (!PluginChannelHost::IsListening())
2846 return NULL;
2847
[email protected]00c39612010-03-06 02:53:282848 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:462849 if (in_process_plugin) {
[email protected]6876dff2010-01-15 19:38:092850#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]e8f7a182011-03-10 00:50:222851 return webkit::npapi::WebPluginDelegateImpl::Create(
2852 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092853#else
[email protected]e8f7a182011-03-10 00:50:222854 NOTIMPLEMENTED();
2855 return NULL;
[email protected]7b6616f2010-01-14 18:07:552856#endif
[email protected]f103ab72009-09-02 17:10:592857 }
2858
[email protected]4e0616e2010-05-28 14:55:532859 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592860}
2861
2862void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032863#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592864 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2865 routing_id(), window));
2866#endif
2867}
2868
2869void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032870#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592871 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2872 routing_id(), window));
2873#endif
2874 CleanupWindowInPluginMoves(window);
2875}
2876
[email protected]191eb3f72010-12-21 06:27:502877void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:592878 SchedulePluginMove(move);
2879}
2880
2881void RenderView::DidStartLoadingForPlugin() {
2882 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522883 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592884}
2885
2886void RenderView::DidStopLoadingForPlugin() {
2887 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522888 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592889}
2890
[email protected]b921cfd22010-02-25 16:57:512891WebCookieJar* RenderView::GetCookieJar() {
2892 return &cookie_jar_;
2893}
2894
initial.commit09911bf2008-07-26 23:55:292895void RenderView::SyncNavigationState() {
2896 if (!webview())
2897 return;
2898
[email protected]26aa0482009-09-30 16:55:272899 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172900 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292901 return;
[email protected]ca948a22009-06-25 19:36:172902
2903 Send(new ViewHostMsg_UpdateState(
2904 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292905}
2906
[email protected]7ccddb8c2009-08-04 17:36:552907GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292908 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552909 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292910 // If the URL that failed was secure, then the embedding web page was not
2911 // expecting a network attacker to be able to manipulate its contents. As
2912 // we fetch alternate error pages over HTTP, we would be allowing a network
2913 // attacker to manipulate the contents of the response if we tried to use
2914 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:152915 return GURL();
initial.commit09911bf2008-07-26 23:55:292916 }
2917
2918 // Grab the base URL from the browser process.
2919 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:152920 return GURL();
initial.commit09911bf2008-07-26 23:55:292921
2922 // Strip query params from the failed URL.
2923 GURL::Replacements remove_params;
2924 remove_params.ClearUsername();
2925 remove_params.ClearPassword();
2926 remove_params.ClearQuery();
2927 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552928 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:502929 std::string spec_to_send = url_to_send.spec();
2930 // Notify link doctor of the url truncation by sending of "?" at the end.
2931 if (failed_url.has_query())
2932 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:292933
2934 // Construct the query params to send to link doctor.
2935 std::string params(alternate_error_page_url_.query());
2936 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:502937 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:292938 params.append("&sourceid=chrome");
2939 params.append("&error=");
2940 switch (error_type) {
2941 case DNS_ERROR:
2942 params.append("dnserror");
2943 break;
2944
2945 case HTTP_404:
2946 params.append("http404");
2947 break;
2948
[email protected]5df266ac2008-10-15 19:50:132949 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332950 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132951 break;
2952
initial.commit09911bf2008-07-26 23:55:292953 default:
2954 NOTREACHED() << "unknown ErrorPageType";
2955 }
2956
2957 // OK, build the final url to return.
2958 GURL::Replacements link_doctor_params;
2959 link_doctor_params.SetQueryStr(params);
2960 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2961 return url;
2962}
2963
[email protected]c50008512011-02-03 01:17:272964WebUIBindings* RenderView::GetWebUIBindings() {
2965 if (!web_ui_bindings_.get()) {
2966 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:462967 }
[email protected]c50008512011-02-03 01:17:272968 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:462969}
2970
[email protected]0fdbf8c2010-07-08 20:33:012971WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
2972 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:492973}
2974
[email protected]6069da8c2009-10-20 20:33:492975void RenderView::OnFind(int request_id, const string16& search_text,
2976 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272977 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:492978
2979 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:492980 if (options.findNext) {
2981 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:012982 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:492983 } else {
[email protected]afdbd142010-07-10 08:01:232984 if (GetWebPluginFromPluginDocument()->startFind(
2985 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:492986 } else {
[email protected]e7c58a32010-08-13 19:47:112987 // Send "no results".
2988 Send(new ViewHostMsg_Find_Reply(routing_id_,
2989 request_id,
2990 0,
2991 gfx::Rect(),
2992 0,
2993 true));
[email protected]24a7f3c2010-03-25 08:26:492994 }
2995 }
2996 return;
2997 }
2998
[email protected]b4bb2502009-10-01 22:35:272999 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273000 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293001 WebFrame* search_frame = focused_frame; // start searching focused frame.
3002
3003 bool multi_frame = (frame_after_main != main_frame);
3004
3005 // If we have multiple frames, we don't want to wrap the search within the
3006 // frame, so we check here if we only have main_frame in the chain.
3007 bool wrap_within_frame = !multi_frame;
3008
[email protected]b3f2b912009-04-09 16:18:523009 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293010 bool result = false;
3011
[email protected]7830da3e2009-11-06 16:27:263012 // If something is selected when we start searching it means we cannot just
3013 // increment the current match ordinal; we need to re-generate it.
3014 WebRange current_selection = focused_frame->selectionRange();
3015
initial.commit09911bf2008-07-26 23:55:293016 do {
[email protected]dd7daa82009-08-10 05:46:453017 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593018 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293019
3020 if (!result) {
3021 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223022 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293023
3024 // Find the next frame, but skip the invisible ones.
3025 do {
3026 // What is the next frame to search? (we might be going backwards). Note
3027 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593028 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273029 search_frame->traverseNext(true) :
3030 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453031 } while (!search_frame->hasVisibleContent() &&
3032 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293033
[email protected]884db412008-11-24 23:46:503034 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223035 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293036
3037 // If we have multiple frames and we have wrapped back around to the
3038 // focused frame, we need to search it once more allowing wrap within
3039 // the frame, otherwise it will report 'no match' if the focused frame has
3040 // reported matches, but no frames after the focused_frame contain a
3041 // match for the search word(s).
3042 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453043 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593044 request_id, search_text, options, true, // Force wrapping.
3045 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293046 }
3047 }
3048
[email protected]26aa0482009-09-30 16:55:273049 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293050 } while (!result && search_frame != focused_frame);
3051
[email protected]7830da3e2009-11-06 16:27:263052 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293053 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453054 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293055 } else {
3056 // If nothing is found, set result to "0 of 0", otherwise, set it to
3057 // "-1 of 1" to indicate that we found at least one item, but we don't know
3058 // yet what is active.
3059 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3060 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293061
[email protected]4f3dc372009-02-24 00:10:293062 // If we find no matches then this will be our last status update.
3063 // Otherwise the scoping effort will send more results.
3064 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293065
[email protected]4f3dc372009-02-24 00:10:293066 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403067 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593068 request_id,
[email protected]4f3dc372009-02-24 00:10:293069 match_count,
3070 selection_rect,
3071 ordinal,
3072 final_status_update));
initial.commit09911bf2008-07-26 23:55:293073
initial.commit09911bf2008-07-26 23:55:293074 // Scoping effort begins, starting with the mainframe.
3075 search_frame = main_frame;
3076
[email protected]dd7daa82009-08-10 05:46:453077 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293078
3079 do {
3080 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453081 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293082
3083 // We don't start another scoping effort unless at least one match has
3084 // been found.
3085 if (result) {
3086 // Start new scoping request. If the scoping function determines that it
3087 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453088 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593089 search_text,
3090 options,
initial.commit09911bf2008-07-26 23:55:293091 true); // reset the tickmarks
3092 }
3093
3094 // Iterate to the next frame. The frame will not necessarily scope, for
3095 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273096 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293097 } while (search_frame != main_frame);
3098 }
3099}
3100
[email protected]24a7f3c2010-03-25 08:26:493101void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3102 WebView* view = webview();
3103 if (!view)
3104 return;
3105
3106 WebDocument doc = view->mainFrame()->document();
3107 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013108 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493109 return;
3110 }
3111
3112 bool clear_selection =
3113 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3114 if (clear_selection)
3115 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3116
3117 WebFrame* frame = view->mainFrame();
3118 while (frame) {
3119 frame->stopFinding(clear_selection);
3120 frame = frame->traverseNext(false);
3121 }
3122
3123 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3124 WebFrame* focused_frame = view->focusedFrame();
3125 if (focused_frame) {
3126 WebDocument doc = focused_frame->document();
3127 if (!doc.isNull()) {
3128 WebNode node = doc.focusedNode();
3129 if (!node.isNull())
3130 node.simulateClick();
3131 }
3132 }
3133 }
3134}
3135
3136void RenderView::OnFindReplyAck() {
3137 // Check if there is any queued up request waiting to be sent.
3138 if (queued_find_reply_message_.get()) {
3139 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423140 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493141 }
3142}
3143
[email protected]0bd753682010-12-16 18:15:523144WebPlugin* RenderView::CreatePepperPlugin(
3145 WebFrame* frame,
3146 const WebPluginParams& params,
3147 const FilePath& path,
3148 webkit::ppapi::PluginModule* pepper_module) {
3149 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:253150 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:093151}
[email protected]00152e92010-07-19 11:47:403152
[email protected]191eb3f72010-12-21 06:27:503153WebPlugin* RenderView::CreateNPAPIPlugin(
3154 WebFrame* frame,
3155 const WebPluginParams& params,
3156 const FilePath& path,
3157 const std::string& mime_type) {
3158 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:083159 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403160}
3161
[email protected]40bd6582009-12-04 23:49:513162void RenderView::OnZoom(PageZoom::Function function) {
3163 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3164 return;
3165
[email protected]258d31122010-05-09 10:59:413166 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523167
[email protected]b75b8292010-10-01 07:28:253168 double old_zoom_level = webview()->zoomLevel();
3169 double zoom_level;
3170 if (function == PageZoom::RESET) {
3171 zoom_level = 0;
3172 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3173 // Previous zoom level is a whole number, so just increment/decrement.
3174 zoom_level = old_zoom_level + function;
3175 } else {
3176 // Either the user hit the zoom factor limit and thus the zoom level is now
3177 // not a whole number, or a plugin changed it to a custom value. We want
3178 // to go to the next whole number so that the user can always get back to
3179 // 100% with the keyboard/menu.
3180 if ((old_zoom_level > 1 && function > 0) ||
3181 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453182 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253183 } else {
3184 // We're going towards 100%, so first go to the next whole number.
3185 zoom_level = static_cast<int>(old_zoom_level);
3186 }
3187 }
[email protected]40bd6582009-12-04 23:49:513188
[email protected]b75b8292010-10-01 07:28:253189 webview()->setZoomLevel(false, zoom_level);
3190 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513191}
3192
[email protected]d0b8d092010-10-25 04:05:173193void RenderView::OnSetZoomLevel(double zoom_level) {
3194 // Don't set zoom level for full-page plugin since they don't use the same
3195 // zoom settings.
3196 if (webview()->mainFrame()->document().isPluginDocument())
3197 return;
3198
3199 webview()->hidePopups();
3200 webview()->setZoomLevel(false, zoom_level);
3201 zoomLevelChanged();
3202}
3203
[email protected]9d797f32010-04-23 07:17:543204void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:253205 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543206 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293207}
3208
[email protected]41fc0322009-09-04 22:23:403209void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273210 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293211}
3212
[email protected]a697f4c2009-09-14 22:30:183213void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273214 WebString no_encoding;
3215 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183216}
3217
[email protected]dd7daa82009-08-10 05:46:453218WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3219 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273220 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453221
3222 // xpath string can represent a frame deep down the tree (across multiple
3223 // frame DOMs).
3224 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3225 // should break into 2 xpaths
3226 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3227
[email protected]26aa0482009-09-30 16:55:273228 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453229
3230 std::wstring xpath_remaining = xpath;
3231 while (!xpath_remaining.empty()) {
3232 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3233 std::wstring xpath_child;
3234 if (delim_pos != std::wstring::npos) {
3235 xpath_child = xpath_remaining.substr(0, delim_pos);
3236 xpath_remaining.erase(0, delim_pos + 1);
3237 } else {
3238 xpath_remaining.swap(xpath_child);
3239 }
3240 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293241 }
3242
[email protected]dd7daa82009-08-10 05:46:453243 return frame;
initial.commit09911bf2008-07-26 23:55:293244}
3245
[email protected]13a1e4c3c2011-02-03 21:07:093246WebNode RenderView::GetFocusedNode() const {
3247 if (!webview())
3248 return WebNode();
3249 WebFrame* focused_frame = webview()->focusedFrame();
3250 if (focused_frame) {
3251 WebDocument doc = focused_frame->document();
3252 if (!doc.isNull())
3253 return doc.focusedNode();
3254 }
3255
3256 return WebNode();
3257}
3258
[email protected]38b592902011-04-16 02:08:423259bool RenderView::IsEditableNode(const WebNode& node) {
3260 bool is_editable_node = false;
3261 if (!node.isNull()) {
3262 if (node.isContentEditable()) {
3263 is_editable_node = true;
3264 } else if (node.isElementNode()) {
3265 is_editable_node =
3266 node.toConst<WebElement>().isTextFormControlElement();
3267 }
3268 }
3269 return is_editable_node;
3270}
3271
[email protected]882b7b22010-10-05 03:34:533272void RenderView::EvaluateScript(const string16& frame_xpath,
3273 const string16& script,
3274 int id,
3275 bool notify_result) {
3276 v8::Handle<v8::Value> result;
3277 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
3278 if (web_frame)
3279 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
3280 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:293281 ListValue list;
3282 if (web_frame) {
3283 v8::HandleScope handle_scope;
3284 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3285 v8::Context::Scope context_scope(context);
[email protected]b1cf3372011-04-20 21:28:103286 V8ValueConverter converter;
3287 converter.set_allow_date(true);
3288 converter.set_allow_regexp(true);
3289 list.Set(0, converter.FromV8Value(result, context));
[email protected]81f9fe0b2010-12-07 00:35:293290 } else {
3291 list.Set(0, Value::CreateNullValue());
3292 }
3293 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:533294 }
initial.commit09911bf2008-07-26 23:55:293295}
3296
[email protected]882b7b22010-10-05 03:34:533297void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
3298 const string16& jscript,
3299 int id,
3300 bool notify_result) {
3301 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293302}
3303
[email protected]1810e132009-03-24 23:35:483304void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083305 const std::string& css,
3306 const std::string& id) {
[email protected]216813952011-05-19 22:21:263307 WebFrame* web_frame = GetChildFrame(frame_xpath);
3308 if (!web_frame)
3309 return;
[email protected]ae461542009-06-19 19:03:413310
[email protected]216813952011-05-19 22:21:263311 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483312}
3313
[email protected]81e63782009-02-27 19:35:093314void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3315 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293316}
3317
[email protected]d0980792011-02-13 19:41:403318void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:293319 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:553320 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:273321 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293322}
3323
3324void RenderView::OnReservePageIDRange(int size_of_range) {
3325 next_page_id_ += size_of_range + 1;
3326}
3327
[email protected]59f4f2fa2011-03-23 01:00:553328void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
3329 const gfx::Point& client_point,
3330 const gfx::Point& screen_point,
3331 WebDragOperationsMask ops) {
3332 WebDragOperation operation = webview()->dragTargetDragEnter(
3333 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553334 client_point,
3335 screen_point,
3336 ops);
3337
3338 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3339}
3340
3341void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
3342 const gfx::Point& screen_point,
3343 WebDragOperationsMask ops) {
3344 WebDragOperation operation = webview()->dragTargetDragOver(
3345 client_point,
3346 screen_point,
3347 ops);
3348
3349 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3350}
3351
3352void RenderView::OnDragTargetDragLeave() {
3353 webview()->dragTargetDragLeave();
3354}
3355
3356void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3357 const gfx::Point& screen_point) {
3358 webview()->dragTargetDrop(client_point, screen_point);
3359}
3360
[email protected]e80c73b2009-04-07 23:24:583361void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3362 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253363 bool ended,
3364 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033365 if (ended) {
[email protected]26aa0482009-09-30 16:55:273366 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203367 } else {
3368 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033369 }
initial.commit09911bf2008-07-26 23:55:293370}
3371
3372void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273373 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293374}
3375
initial.commit09911bf2008-07-26 23:55:293376void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593377 webkit_preferences_ = prefs;
3378 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293379}
3380
3381void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3382 alternate_error_page_url_ = url;
3383}
3384
[email protected]b29aa74b2011-01-31 21:41:083385void RenderView::OnCustomContextMenuAction(
3386 const webkit_glue::CustomContextMenuContext& custom_context,
3387 unsigned action) {
3388 if (custom_context.is_pepper_menu)
3389 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3390 else
3391 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:333392}
3393
initial.commit09911bf2008-07-26 23:55:293394void RenderView::OnInstallMissingPlugin() {
3395 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593396 if (first_default_plugin_)
3397 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293398}
3399
[email protected]600ea402011-04-12 00:01:513400void RenderView::OnEnumerateDirectoryResponse(
3401 int id,
3402 const std::vector<FilePath>& paths) {
3403 if (!enumeration_completions_[id])
3404 return;
3405
3406 WebVector<WebString> ws_file_names(paths.size());
3407 for (size_t i = 0; i < paths.size(); ++i)
3408 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3409
3410 enumeration_completions_[id]->didChooseFile(ws_file_names);
3411 enumeration_completions_.erase(id);
3412}
3413
[email protected]cdaf8d02010-03-30 19:52:473414void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363415 // This could happen if we navigated to a different page before the user
3416 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473417 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363418 return;
3419
[email protected]cdaf8d02010-03-30 19:52:473420 WebVector<WebString> ws_file_names(paths.size());
3421 for (size_t i = 0; i < paths.size(); ++i)
3422 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463423
[email protected]cdaf8d02010-03-30 19:52:473424 if (file_chooser_completions_.front()->completion)
3425 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3426 file_chooser_completions_.pop_front();
3427
3428 // If there are more pending file chooser requests, schedule one now.
3429 if (!file_chooser_completions_.empty()) {
3430 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3431 file_chooser_completions_.front()->params));
3432 }
initial.commit09911bf2008-07-26 23:55:293433}
3434
[email protected]770dd8b2010-05-24 18:11:393435void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3436 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243437 if (send_preferred_size_changes_)
3438 return;
[email protected]9fb325e2010-05-06 18:23:243439 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393440
[email protected]d812fd12011-05-27 23:05:073441 // Start off with an initial preferred size notification (in case
3442 // |didUpdateLayout| was already called).
3443 if (webview())
3444 didUpdateLayout(webview()->mainFrame());
[email protected]0666aef2009-05-13 19:48:083445}
3446
[email protected]cda45c02010-02-25 19:28:103447void RenderView::OnDisableScrollbarsForSmallWindows(
3448 const gfx::Size& disable_scrollbar_size_limit) {
3449 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3450}
3451
[email protected]80d96fa2009-06-10 22:34:513452void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3453 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373454 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133455#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413456 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3457 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463458 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513459 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343460 renderer_prefs.thumb_inactive_color,
3461 renderer_prefs.thumb_active_color,
3462 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323463
[email protected]644d77e2010-01-27 01:03:103464 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323465 webview()->setScrollbarColors(
3466 renderer_prefs.thumb_inactive_color,
3467 renderer_prefs.thumb_active_color,
3468 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103469 webview()->setSelectionColors(
3470 renderer_prefs.active_selection_bg_color,
3471 renderer_prefs.active_selection_fg_color,
3472 renderer_prefs.inactive_selection_bg_color,
3473 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463474 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103475 }
[email protected]7a74e102009-09-03 00:16:563476#endif
[email protected]80d96fa2009-06-10 22:34:513477}
3478
[email protected]952cb702009-10-07 05:50:283479void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3480 const WebMediaPlayerAction& action) {
3481 if (webview())
3482 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563483}
3484
[email protected]dea2d372010-09-25 06:41:143485void RenderView::OnEnableAccessibility() {
3486 if (WebAccessibilityCache::accessibilityEnabled())
3487 return;
[email protected]9f4db512010-05-10 20:21:413488
[email protected]dea2d372010-09-25 06:41:143489 WebAccessibilityCache::enableAccessibility();
3490
3491 if (webview()) {
3492 // It's possible that the webview has already loaded a webpage without
3493 // accessibility being enabled. Initialize the browser's cached
3494 // accessibility tree by sending it a 'load complete' notification.
3495 postAccessibilityNotification(
3496 webview()->accessibilityObject(),
3497 WebKit::WebAccessibilityNotificationLoadComplete);
3498 }
[email protected]266eb6f2008-09-30 23:56:503499}
3500
[email protected]aef92842010-05-21 16:54:363501void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
3502 if (!accessibility_.get())
3503 return;
[email protected]02ea2f312010-09-27 17:03:363504
3505 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3506 WebAccessibilityObject root = webview()->accessibilityObject();
3507 if (!obj.isValid() || !root.isValid())
3508 return;
3509
3510 // By convention, calling SetFocus on the root of the tree should clear the
3511 // current focus. Otherwise set the focus to the new node.
3512 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
3513 webview()->clearFocusedNode();
3514 else
3515 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:363516}
3517
3518void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
3519 if (!accessibility_.get())
3520 return;
[email protected]02ea2f312010-09-27 17:03:363521
3522 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3523 if (!obj.isValid())
3524 return;
3525
3526 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:363527}
3528
[email protected]9892b472010-09-16 00:23:423529void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:513530 DCHECK(accessibility_ack_pending_);
3531 accessibility_ack_pending_ = false;
3532 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:313533}
3534
[email protected]9b18a84f2010-06-10 15:54:043535void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273536 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473537 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293538}
3539
[email protected]992db4c2011-05-12 15:37:153540void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3541 if (is_swapped_out_)
3542 return;
3543
3544 // Swap this RenderView out so the tab can navigate to a page rendered by a
3545 // different process. This involves running the unload handler and clearing
3546 // the page. Once WasSwappedOut is called, we also allow this process to exit
3547 // if there are no other active RenderViews in it.
3548
3549 // Send an UpdateState message before we get swapped out.
3550 SyncNavigationState();
3551
3552 // Synchronously run the unload handler before sending the ACK.
3553 webview()->dispatchUnloadEvent();
3554
3555 // Swap out and stop sending any IPC messages that are not ACKs.
3556 SetSwappedOut(true);
3557
3558 // Replace the page with a blank dummy URL. The unload handler will not be
3559 // run a second time, thanks to a check in FrameLoader::stopLoading.
3560 // TODO(creis): Need to add a better way to do this that avoids running the
3561 // beforeunload handler. For now, we just run it a second time silently.
3562 webview()->mainFrame()->loadHTMLString(std::string(),
3563 GURL("about:swappedout"),
3564 GURL("about:swappedout"),
3565 false);
3566
3567 // Just echo back the params in the ACK.
3568 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3569}
3570
3571void RenderView::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:293572 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3573 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3574 // in the onunload handler from appearing. For now, we're bypassing that and
3575 // calling the FrameLoader's CloseURL method directly. This should be
3576 // revisited to avoid having two ways to close a page. Having a single way
3577 // to close that can run onunload is also useful for fixing
3578 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273579 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293580
[email protected]992db4c2011-05-12 15:37:153581 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293582}
3583
3584void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573585#if defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163586 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463587 if (webview())
3588 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573589#else // defined(OS_WIN)
3590 // TODO(port): we don't support theming on non-Windows platforms yet
3591 NOTIMPLEMENTED();
3592#endif
initial.commit09911bf2008-07-26 23:55:293593}
3594
[email protected]0aa55312008-10-17 21:53:083595void RenderView::OnDisassociateFromPopupCount() {
3596 if (decrement_shared_popup_at_destruction_)
3597 shared_popup_counter_->data--;
3598 shared_popup_counter_ = new SharedRenderViewCounter(0);
3599 decrement_shared_popup_at_destruction_ = false;
3600}
3601
[email protected]15d79e12009-08-02 19:23:453602bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3603 const WebURLError& error,
3604 bool replace) {
3605 // We only show alternate error pages in the main frame. They are
3606 // intended to assist the user when navigating, so there is not much
3607 // value in showing them for failed subframes. Ideally, we would be
3608 // able to use the TYPED transition type for this, but that flag is
3609 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453610 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453611 return false;
3612
3613 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373614 // connection failure.
[email protected]15d79e12009-08-02 19:23:453615 int ec = error.reason;
3616 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3617 ec != net::ERR_CONNECTION_FAILED &&
3618 ec != net::ERR_CONNECTION_REFUSED &&
3619 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373620 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453621 return false;
3622
3623 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553624 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453625 if (!error_page_url.is_valid())
3626 return false;
3627
3628 // Load an empty page first so there is an immediate response to the error,
3629 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453630 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363631 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453632 error.unreachableURL,
3633 replace);
3634
3635 // Now, create a fetcher for the error page and associate it with the data
3636 // source we just created via the LoadHTMLString call. That way if another
3637 // navigation occurs, the fetcher will get destroyed.
3638 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453639 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453640 navigation_state->set_alt_error_page_fetcher(
3641 new AltErrorPageResourceFetcher(
3642 error_page_url, frame, error,
3643 NewCallback(this, &RenderView::AltErrorPageFinished)));
3644 return true;
3645}
3646
[email protected]15d79e12009-08-02 19:23:453647void RenderView::AltErrorPageFinished(WebFrame* frame,
3648 const WebURLError& original_error,
3649 const std::string& html) {
3650 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093651 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553652 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093653 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453654}
3655
[email protected]30f75e62009-02-25 22:01:003656void RenderView::OnMoveOrResizeStarted() {
3657 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473658 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003659}
3660
[email protected]30f75e62009-02-25 22:01:003661void RenderView::OnResize(const gfx::Size& new_size,
3662 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103663 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473664 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103665 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203666 webview()->mainFrame()->setCanHaveScrollbars(
3667 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103668 }
3669 }
3670
[email protected]30f75e62009-02-25 22:01:003671 RenderWidget::OnResize(new_size, resizer_rect);
3672}
[email protected]0aa477bd2009-03-23 22:21:433673
[email protected]00c39612010-03-06 02:53:283674void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013675 // Notify the pepper plugins that we started painting.
3676 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283677}
3678
3679void RenderView::DidFlushPaint() {
3680 // Notify any pepper plugins that we painted. This will call into the plugin,
3681 // and we it may ask to close itself as a result. This will, in turn, modify
3682 // our set, possibly invalidating the iterator. So we iterate on a copy that
3683 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013684 pepper_delegate_.ViewFlushedPaint();
3685
[email protected]00c39612010-03-06 02:53:283686 WebFrame* main_frame = webview()->mainFrame();
3687
3688 // If we have a provisional frame we are between the start and commit stages
3689 // of loading and we don't want to save stats.
3690 if (!main_frame->provisionalDataSource()) {
3691 WebDataSource* ds = main_frame->dataSource();
3692 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3693 DCHECK(navigation_state);
3694
[email protected]05c8e502010-08-15 15:13:523695 // TODO(jar): The following code should all be inside a method, probably in
3696 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283697 Time now = Time::Now();
3698 if (navigation_state->first_paint_time().is_null()) {
3699 navigation_state->set_first_paint_time(now);
3700 }
3701 if (navigation_state->first_paint_after_load_time().is_null() &&
3702 !navigation_state->finish_load_time().is_null()) {
3703 navigation_state->set_first_paint_after_load_time(now);
3704 }
3705 }
3706}
3707
[email protected]65225772011-05-12 21:10:243708void RenderView::OnViewContextSwapBuffersComplete() {
3709 RenderWidget::OnSwapBuffersComplete();
3710}
3711
3712void RenderView::OnViewContextSwapBuffersAborted() {
3713 RenderWidget::OnSwapBuffersAborted();
3714}
3715
[email protected]719b36f2010-12-22 20:36:463716webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:153717 const gfx::Rect& paint_bounds,
3718 TransportDIB** dib,
3719 gfx::Rect* location,
3720 gfx::Rect* clip) {
3721 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
3722 paint_bounds, dib, location, clip);
3723}
3724
[email protected]bcaf2272011-02-15 15:29:433725gfx::Point RenderView::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:073726 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:433727 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523728}
3729
[email protected]05d478752009-04-08 23:38:163730void RenderView::OnClearFocusedNode() {
3731 if (webview())
[email protected]26aa0482009-09-30 16:55:273732 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163733}
3734
[email protected]699ab0d2009-04-23 23:19:143735void RenderView::OnSetBackground(const SkBitmap& background) {
3736 if (webview())
[email protected]b4bb2502009-10-01 22:35:273737 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143738
3739 SetBackground(background);
3740}
3741
[email protected]8c66c5a2009-07-22 17:26:343742void RenderView::OnSetActive(bool active) {
3743 if (webview())
[email protected]b4bb2502009-10-01 22:35:273744 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263745
3746#if defined(OS_MACOSX)
3747 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3748 for (plugin_it = plugin_delegates_.begin();
3749 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3750 (*plugin_it)->SetWindowFocus(active);
3751 }
3752#endif
[email protected]8c66c5a2009-07-22 17:26:343753}
3754
[email protected]6ce7abc52010-02-02 18:40:143755#if defined(OS_MACOSX)
3756void RenderView::OnSetWindowVisibility(bool visible) {
3757 // Inform plugins that their container has changed visibility.
3758 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3759 for (plugin_it = plugin_delegates_.begin();
3760 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3761 (*plugin_it)->SetContainerVisibility(visible);
3762 }
3763}
[email protected]1e6e3c992010-02-08 15:52:133764
[email protected]4d51d5bf2010-07-26 18:48:263765void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
3766 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:133767 // Inform plugins that their window's frame has changed.
3768 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3769 for (plugin_it = plugin_delegates_.begin();
3770 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3771 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3772 }
3773}
[email protected]935d63d2010-10-15 23:31:553774
[email protected]b7f75862011-01-21 21:15:133775void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:553776 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:133777 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:553778 // applies to it or not, so inform all the delegates.
3779 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3780 for (plugin_it = plugin_delegates_.begin();
3781 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:133782 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:553783 }
3784}
[email protected]6ce7abc52010-02-02 18:40:143785#endif // OS_MACOSX
3786
[email protected]9892b472010-09-16 00:23:423787void RenderView::postAccessibilityNotification(
3788 const WebAccessibilityObject& obj,
3789 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:143790 if (!accessibility_.get() && webview()) {
3791 // Load complete should be our first notification sent.
3792 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
3793 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
3794 return;
3795
3796 // Create and initialize our accessibility cache
3797 accessibility_.reset(WebAccessibilityCache::create());
3798 accessibility_->initialize(webview());
3799 }
3800
[email protected]a3fa4f92010-09-30 22:19:333801 if (!accessibility_->isCached(obj)) {
3802 // The browser doesn't know about objects that are not in the cache. Send a
3803 // children change for the first accestor that actually is in the cache.
3804 WebAccessibilityObject parent = obj;
3805 while (parent.isValid() && !accessibility_->isCached(parent))
3806 parent = parent.parentObject();
3807
3808 DCHECK(parent.isValid() && accessibility_->isCached(parent));
3809 if (!parent.isValid())
3810 return;
3811 postAccessibilityNotification(
3812 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
3813
3814 // The parent's children change takes care of the child's children change.
3815 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
3816 return;
3817 }
3818
[email protected]dea2d372010-09-25 06:41:143819 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:513820 RendererAccessibilityNotification acc_notification;
3821 acc_notification.id = accessibility_->addOrGetId(obj);
[email protected]a527a022011-02-10 02:32:363822 acc_notification.type = notification;
[email protected]54ec7f82010-10-21 22:32:513823 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:483824 return;
3825
[email protected]fffaf972011-03-24 01:34:353826 ViewHostMsg_AccessibilityNotification_Type::Value temp;
[email protected]a527a022011-02-10 02:32:363827 if (!WebAccessibilityNotificationToViewHostMsg(notification, &temp))
[email protected]54ec7f82010-10-21 22:32:513828 return;
[email protected]54ec7f82010-10-21 22:32:513829
3830 // Discard duplicate accessibility notifications.
3831 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
3832 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
3833 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:423834 return;
[email protected]54ec7f82010-10-21 22:32:513835 }
[email protected]9892b472010-09-16 00:23:423836 }
[email protected]54ec7f82010-10-21 22:32:513837 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:483838
[email protected]54ec7f82010-10-21 22:32:513839 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
3840 // When no accessibility notifications are in-flight post a task to send
3841 // the notifications to the browser. We use PostTask so that we can queue
3842 // up additional notifications.
3843 MessageLoop::current()->PostTask(
3844 FROM_HERE,
3845 accessibility_method_factory_.NewRunnableMethod(
3846 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:313847 }
[email protected]520cb7d72010-08-31 11:54:313848}
3849
[email protected]446705872009-09-10 07:22:483850void RenderView::OnSetEditCommandsForNextKeyEvent(
3851 const EditCommands& edit_commands) {
3852 edit_commands_ = edit_commands;
3853}
3854
[email protected]60c42a8c72009-10-09 04:08:593855void RenderView::Close() {
3856 // We need to grab a pointer to the doomed WebView before we destroy it.
3857 WebView* doomed = webview();
3858 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:493859 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:593860}
3861
[email protected]446705872009-09-10 07:22:483862void RenderView::DidHandleKeyEvent() {
3863 edit_commands_.clear();
3864}
3865
[email protected]6a8ddba52010-09-05 04:38:063866void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:513867 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:063868}
3869
[email protected]941e4552010-02-01 21:23:433870void RenderView::OnWasHidden() {
3871 RenderWidget::OnWasHidden();
3872
[email protected]a6939ca42011-02-18 17:58:073873 if (webview()) {
3874 webview()->settings()->setMinimumTimerInterval(
3875 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:443876 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073877 }
3878
3879#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:433880 // Inform plugins that their container is no longer visible.
3881 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3882 for (plugin_it = plugin_delegates_.begin();
3883 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3884 (*plugin_it)->SetContainerVisibility(false);
3885 }
[email protected]a6939ca42011-02-18 17:58:073886#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:433887}
3888
3889void RenderView::OnWasRestored(bool needs_repainting) {
3890 RenderWidget::OnWasRestored(needs_repainting);
3891
[email protected]a6939ca42011-02-18 17:58:073892 if (webview()) {
3893 webview()->settings()->setMinimumTimerInterval(
3894 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:443895 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073896 }
3897
3898#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:433899 // Inform plugins that their container is now visible.
3900 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3901 for (plugin_it = plugin_delegates_.begin();
3902 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3903 (*plugin_it)->SetContainerVisibility(true);
3904 }
[email protected]784ea1ab2010-09-18 00:02:343905#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:073906}
[email protected]1e6e3c992010-02-08 15:52:133907
[email protected]65225772011-05-12 21:10:243908bool RenderView::SupportsAsynchronousSwapBuffers() {
3909 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
3910 if (!context)
3911 return false;
3912 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
3913 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
3914 std::string::npos;
3915}
3916
[email protected]1e6e3c992010-02-08 15:52:133917void RenderView::OnSetFocus(bool enable) {
3918 RenderWidget::OnSetFocus(enable);
3919
[email protected]7d3c02c2010-05-05 23:10:313920 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:073921 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:133922 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3923 for (plugin_it = plugin_delegates_.begin();
3924 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:343925#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:313926 // RenderWidget's call to setFocus can cause the underlying webview's
3927 // activation state to change just like a call to setIsActive.
3928 if (enable)
3929 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:343930#endif
[email protected]7d3c02c2010-05-05 23:10:313931 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:133932 }
[email protected]589621b2010-09-23 22:01:073933
3934 // Notify all Pepper plugins.
3935 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:133936 }
3937}
[email protected]941e4552010-02-01 21:23:433938
[email protected]56ea1a62011-05-30 07:05:573939void RenderView::PpapiPluginFocusChanged() {
3940 UpdateInputMethod();
3941}
3942
3943void RenderView::OnImeSetComposition(
3944 const string16& text,
3945 const std::vector<WebKit::WebCompositionUnderline>& underlines,
3946 int selection_start,
3947 int selection_end) {
3948 // Until PPAPI has an interface for handling IME events, we skip sending
3949 // OnImeSetComposition. Otherwise the composition is canceled when a
3950 // non-editable DOM element is focused.
3951 //
3952 // TODO(kinaba) This temporal remedy can be removed after PPAPI is extended
3953 // with an IME handling interface.
3954 if (!pepper_delegate_.IsPluginFocused()) {
3955 RenderWidget::OnImeSetComposition(text,
3956 underlines,
3957 selection_start,
3958 selection_end);
3959 }
3960}
3961
3962void RenderView::OnImeConfirmComposition(const string16& text) {
3963 if (pepper_delegate_.IsPluginFocused()) {
3964 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
3965 // send character events.
3966 for (size_t i = 0; i < text.size(); ++i) {
3967 WebKit::WebKeyboardEvent char_event;
3968 char_event.type = WebKit::WebInputEvent::Char;
3969 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
3970 char_event.modifiers = 0;
3971 char_event.windowsKeyCode = text[i];
3972 char_event.nativeKeyCode = text[i];
3973 char_event.text[0] = text[i];
3974 char_event.unmodifiedText[0] = text[i];
3975 if (webwidget_)
3976 webwidget_->handleInputEvent(char_event);
3977 }
3978 } else {
3979 RenderWidget::OnImeConfirmComposition(text);
3980 }
3981}
3982
3983WebKit::WebTextInputType RenderView::GetTextInputType() {
3984 if (pepper_delegate_.IsPluginFocused()) {
3985 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
3986 // consider all the parts of PPAPI plugins are accepting text inputs.
3987 return WebKit::WebTextInputTypeText;
3988 } else {
3989 return RenderWidget::GetTextInputType();
3990 }
3991}
3992
[email protected]43f28f832010-02-03 02:28:483993#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:133994void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
3995 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
3996 focused, plugin_id);
3997 Send(msg);
3998}
3999
4000void RenderView::StartPluginIme() {
4001 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554002 // This message can be sent during event-handling, and needs to be delivered
4003 // within that context.
4004 msg->set_unblock(true);
4005 Send(msg);
4006}
4007
[email protected]ea04a4e12010-04-15 00:58:034008gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234009 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484010 gfx::PluginWindowHandle window = NULL;
4011 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234012 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114013 if (window) {
4014 fake_plugin_window_handles_.insert(window);
4015 }
[email protected]43f28f832010-02-03 02:28:484016 return window;
4017}
4018
4019void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114020 if (window && fake_plugin_window_handles_.find(window) !=
4021 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484022 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114023 fake_plugin_window_handles_.erase(window);
4024 }
[email protected]43f28f832010-02-03 02:28:484025}
4026
[email protected]44ce0b12010-03-12 16:45:334027void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4028 int32 width,
4029 int32 height,
4030 uint64 io_surface_identifier) {
4031 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484032 routing_id(), window, width, height, io_surface_identifier));
4033}
4034
[email protected]44ce0b12010-03-12 16:45:334035void RenderView::AcceleratedSurfaceSetTransportDIB(
4036 gfx::PluginWindowHandle window,
4037 int32 width,
4038 int32 height,
4039 TransportDIB::Handle transport_dib) {
4040 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074041 routing_id(), window, width, height, transport_dib));
4042}
4043
[email protected]44ce0b12010-03-12 16:45:334044TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4045 size_t size) {
[email protected]1aef98132010-02-23 18:00:074046 TransportDIB::Handle dib_handle;
4047 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384048 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074049 return dib_handle;
4050 // Return an invalid handle if Send() fails.
4051 return TransportDIB::DefaultHandleValue();
4052}
4053
[email protected]44ce0b12010-03-12 16:45:334054void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074055 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4056}
4057
[email protected]44ce0b12010-03-12 16:45:334058void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144059 gfx::PluginWindowHandle window, uint64 surface_id) {
4060 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4061 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484062}
4063#endif
[email protected]58c321d2010-02-19 12:11:284064
[email protected]cdaf8d02010-03-30 19:52:474065bool RenderView::ScheduleFileChooser(
4066 const ViewHostMsg_RunFileChooser_Params& params,
4067 WebFileChooserCompletion* completion) {
4068 static const size_t kMaximumPendingFileChooseRequests = 4;
4069 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4070 // This sanity check prevents too many file choose requests from getting
4071 // queued which could DoS the user. Getting these is most likely a
4072 // programming error (there are many ways to DoS the user so it's not
4073 // considered a "real" security check), either in JS requesting many file
4074 // choosers to pop up, or in a plugin.
4075 //
4076 // TODO(brettw) we might possibly want to require a user gesture to open
4077 // a file picker, which will address this issue in a better way.
4078 return false;
4079 }
4080
4081 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4082 new PendingFileChooser(params, completion)));
4083 if (file_chooser_completions_.size() == 1) {
4084 // Actually show the browse dialog when this is the first request.
4085 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4086 }
4087 return true;
4088}
4089
[email protected]0ff0ff32010-12-21 19:34:424090WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514091 if (!geolocation_dispatcher_)
4092 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4093 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254094}
[email protected]61c9f032010-03-31 23:04:194095
[email protected]638694c2010-08-04 22:24:114096WebKit::WebSpeechInputController* RenderView::speechInputController(
4097 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:514098 if (!speech_input_dispatcher_)
4099 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
4100 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114101}
4102
[email protected]57ead352010-08-11 14:42:534103WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514104 if (!device_orientation_dispatcher_)
4105 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4106 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534107}
4108
[email protected]b75b8292010-10-01 07:28:254109void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
4110 // For now, don't remember plugin zoom values. We don't want to mix them with
4111 // normal web content (i.e. a fixed layout plugin would usually want them
4112 // different).
4113 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4114
[email protected]b75b8292010-10-01 07:28:254115 int minimum_percent = static_cast<int>(
4116 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4117 int maximum_percent = static_cast<int>(
4118 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254119
4120 Send(new ViewHostMsg_UpdateZoomLimits(
4121 routing_id_, minimum_percent, maximum_percent, remember));
4122}
4123
4124void RenderView::zoomLevelChanged() {
4125 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4126
[email protected]b75b8292010-10-01 07:28:254127 // Tell the browser which url got zoomed so it can update the menu and the
4128 // saved values if necessary
4129 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:414130 routing_id_, webview()->zoomLevel(), remember,
4131 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:254132}
4133
[email protected]a6d36cc2011-02-23 00:39:484134void RenderView::registerProtocolHandler(const WebString& scheme,
4135 const WebString& base_url,
4136 const WebString& url,
4137 const WebString& title) {
4138 GURL base(base_url);
4139 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4140 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4141 return;
4142 }
4143 RenderThread::current()->Send(
4144 new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4145 UTF16ToUTF8(scheme),
4146 absolute_url,
4147 title));
4148}
4149
[email protected]94dec932011-05-26 20:04:214150WebKit::WebPageVisibilityState RenderView::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444151 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4152 WebKit::WebPageVisibilityStateHidden :
4153 WebKit::WebPageVisibilityStateVisible;
4154 WebKit::WebPageVisibilityState override_state = current_state;
4155 if (content::GetContentClient()->renderer()->
4156 ShouldOverridePageVisibilityState(this,
4157 &override_state))
4158 return override_state;
4159 return current_state;
[email protected]94dec932011-05-26 20:04:214160}
4161
[email protected]8079b362010-05-07 18:37:454162bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194163 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454164 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194165 if (frame->parent() != NULL)
4166 return false;
4167
[email protected]f0a3d0b2010-08-06 22:51:534168 // Navigations initiated within Webkit are not sent out to the external host
4169 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274170 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134171 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534172 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134173 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334174 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534175 return false;
4176
[email protected]2fc22d12010-12-02 23:08:164177 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324178 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014179 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164180 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014181 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324182 // The opener relationship between the new window and the parent allows the
4183 // new window to script the parent and vice versa. This is not allowed if
4184 // the origins of the two domains are different. This can be treated as a
4185 // top level navigation and routed back to the host.
4186 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274187 if (!opener) {
[email protected]86965362011-04-21 18:42:514188 return true;
[email protected]d19ea342011-04-20 20:31:134189 } else {
4190 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324191 return true;
4192 }
4193 }
[email protected]61c9f032010-03-31 23:04:194194 return false;
4195}
[email protected]2b06a992010-08-21 05:48:224196
[email protected]27a9ef32010-09-10 04:06:244197void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
4198 IPC::PlatformFileForTransit file_for_transit,
4199 int message_id) {
4200 pepper_delegate_.OnAsyncFileOpened(
4201 error_code,
4202 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4203 message_id);
4204}
[email protected]caf706f2010-10-26 17:54:084205
[email protected]2b657fd2011-04-18 16:00:474206void RenderView::OnPpapiBrokerChannelCreated(
4207 int request_id,
4208 base::ProcessHandle broker_process_handle,
4209 IPC::ChannelHandle handle) {
4210 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4211 broker_process_handle,
4212 handle);
[email protected]eb415bf0e2011-04-14 02:45:424213}
4214
[email protected]caf706f2010-10-26 17:54:084215#if defined(OS_MACOSX)
4216void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154217 if (external_popup_menu_ == NULL) {
4218 // Crash reports from the field indicate that we can be notified with a
4219 // NULL external popup menu (we probably get notified twice).
4220 // If you hit this please file a bug against jcivelli and include the page
4221 // and steps to repro.
4222 NOTREACHED();
4223 return;
4224 }
[email protected]caf706f2010-10-26 17:54:084225 external_popup_menu_->DidSelectItem(selected_index);
4226 external_popup_menu_.reset();
4227}
4228#endif
[email protected]bb461532010-11-26 21:50:234229
[email protected]1b4209f2011-01-07 00:25:404230#if defined(ENABLE_FLAPPER_HACKS)
4231void RenderView::OnConnectTcpACK(
4232 int request_id,
4233 IPC::PlatformFileForTransit socket_for_transit,
4234 const PP_Flash_NetAddress& local_addr,
4235 const PP_Flash_NetAddress& remote_addr) {
4236 pepper_delegate_.OnConnectTcpACK(
4237 request_id,
4238 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4239 local_addr,
4240 remote_addr);
4241}
4242#endif
[email protected]a6097f42011-01-10 08:50:514243
[email protected]b29aa74b2011-01-31 21:41:084244void RenderView::OnContextMenuClosed(
4245 const webkit_glue::CustomContextMenuContext& custom_context) {
4246 if (custom_context.is_pepper_menu)
4247 pepper_delegate_.OnContextMenuClosed(custom_context);
4248 else
4249 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104250}
[email protected]232a5812011-03-04 22:42:084251
4252void RenderView::OnNetworkStateChanged(bool online) {
4253 WebNetworkStateNotifier::setOnLine(online);
4254}