blob: 0b1a4748ff3b9f5571de30f91f0dcc46113dbd67 [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]921f1592011-03-18 00:41:0247#include "content/renderer/load_progress_tracker.h"
[email protected]ccc70d8e2011-03-16 20:40:3748#include "content/renderer/media/audio_renderer_impl.h"
49#include "content/renderer/media/ipc_video_decoder.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/webgraphicscontext3d_command_buffer_impl.h"
65#include "content/renderer/webplugin_delegate_proxy.h"
66#include "content/renderer/websharedworker_proxy.h"
67#include "content/renderer/webworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4968#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4169#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2770#include "media/base/message_loop_factory_impl.h"
initial.commit09911bf2008-07-26 23:55:2971#include "net/base/escape.h"
72#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0473#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5774#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3775#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
76#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
77#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
78#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3779#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
80#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
81#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
82#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3783#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
84#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
85#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
86#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
87#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
88#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
89#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
90#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
91#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.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
688
initial.commit09911bf2008-07-26 23:55:29689 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28690 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29691 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28692 return handled;
initial.commit09911bf2008-07-26 23:55:29693}
694
initial.commit09911bf2008-07-26 23:55:29695void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
696 if (!webview())
697 return;
698
[email protected]992db4c2011-05-12 15:37:15699 // Swap this renderer back in if necessary.
700 if (is_swapped_out_)
701 SetSwappedOut(false);
702
[email protected]3cc72b12010-03-18 23:03:00703 history_list_offset_ = params.current_history_list_offset;
704 history_list_length_ = params.current_history_list_length;
705
[email protected]38b592902011-04-16 02:08:42706 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29707
[email protected]ecbf10d2010-02-18 13:03:29708 bool is_reload =
[email protected]2c5569662011-03-22 20:45:02709 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
710 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29711
[email protected]26aa0482009-09-30 16:55:27712 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45713 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29714 // We cannot reload if we do not have any history state. This happens, for
715 // example, when recovering from a crash. Our workaround here is a bit of
716 // a hack since it means that reload after a crashed tab does not cause an
717 // end-to-end cache validation.
718 is_reload = false;
719 }
720
[email protected]77f17a82009-05-21 04:42:54721 // A navigation resulting from loading a javascript URL should not be treated
722 // as a browser initiated event. Instead, we want it to look as if the page
723 // initiated any load resulting from JS execution.
724 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30725 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00726 params.page_id,
727 params.pending_history_list_offset,
728 params.transition,
729 params.request_time);
[email protected]2c5569662011-03-22 20:45:02730 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30731 // We're doing a load of a page that was restored from the last session.
732 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
733 // which can result in stale data for pages that are set to expire. We
734 // explicitly override that by setting the policy here so that as
735 // necessary we load from the network.
736 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
737 }
738 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54739 }
initial.commit09911bf2008-07-26 23:55:29740
[email protected]a7ccc4d2010-01-27 08:14:48741 NavigationState* navigation_state = pending_navigation_state_.get();
742
[email protected]48a5c772011-04-18 23:50:50743 if (navigation_state) {
744 // New loads need to reset the error page fetcher. Otherwise if there is an
745 // outstanding error page fetcher it may complete and clobber the current
746 // page load.
747 navigation_state->set_alt_error_page_fetcher(NULL);
748 }
749
[email protected]04d3c6e2009-05-22 17:00:13750 // If we are reloading, then WebKit will use the history state of the current
751 // page, so we should just ignore any given history state. Otherwise, if we
752 // have history state, then we need to navigate to it, which corresponds to a
753 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55754 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48755 if (navigation_state)
756 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29757 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02758 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29759 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55760 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13761 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58762 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48763 if (navigation_state)
764 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45765 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17766 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13767 } else {
768 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28769 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29770
[email protected]e6f546c32009-07-01 17:12:55771 // A session history navigation should have been accompanied by state.
772 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13773
[email protected]dd7daa82009-08-10 05:46:45774 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55775 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13776
[email protected]726985e22009-06-18 21:09:28777 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17778 if (!WebSecurityPolicy::shouldHideReferrer(
779 params.url,
780 WebString::fromUTF8(params.referrer.spec()))) {
781 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
782 WebString::fromUTF8(params.referrer.spec()));
783 }
[email protected]726985e22009-06-18 21:09:28784 }
[email protected]04d3c6e2009-05-22 17:00:13785
[email protected]52c68652010-12-07 17:47:04786 if (!params.extra_headers.empty()) {
787 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
788 params.extra_headers.end(), "\n");
789 i.GetNext(); ) {
790 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
791 WebString::fromUTF8(i.values()));
792 }
793 }
794
[email protected]16e923d2011-04-30 00:41:44795 if (navigation_state)
796 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45797 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50798 }
799
[email protected]77f17a82009-05-21 04:42:54800 // In case LoadRequest failed before DidCreateDataSource was called.
801 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29802}
803
804// Stop loading the current page
805void RenderView::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44806 if (webview()) {
807 WebFrame* main_frame = webview()->mainFrame();
808 // Stop the alt error page fetcher. If we let it continue it may complete
809 // and cause RenderViewHostManager to swap to this RenderView, even though
810 // it may no longer be active.
811 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
812 StopAltErrorPageFetcher(main_frame->dataSource());
813 main_frame->stopLoading();
814 }
initial.commit09911bf2008-07-26 23:55:29815}
816
[email protected]ecbf10d2010-02-18 13:03:29817// Reload current focused frame.
818// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56819void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29820 if (webview() && webview()->focusedFrame()) {
821 // We always obey the cache (ignore_cache=false) here.
822 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
823 // a cache-ignoring reload of the frame.
824 webview()->focusedFrame()->reload(false);
825 }
[email protected]1dda4022010-01-28 18:24:56826}
827
initial.commit09911bf2008-07-26 23:55:29828void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27829 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29830}
831
[email protected]68b1e922009-06-23 16:00:25832void RenderView::OnExecuteEditCommand(const std::string& name,
833 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27834 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25835 return;
836
[email protected]26aa0482009-09-30 16:55:27837 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45838 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25839}
840
initial.commit09911bf2008-07-26 23:55:29841void RenderView::OnUpdateTargetURLAck() {
842 // Check if there is a targeturl waiting to be sent.
843 if (target_url_status_ == TARGET_PENDING) {
844 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
845 pending_target_url_));
846 }
847
848 target_url_status_ = TARGET_NONE;
849}
850
851void RenderView::OnUndo() {
852 if (!webview())
853 return;
854
[email protected]26aa0482009-09-30 16:55:27855 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29856}
857
858void RenderView::OnRedo() {
859 if (!webview())
860 return;
861
[email protected]26aa0482009-09-30 16:55:27862 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29863}
864
865void RenderView::OnCut() {
866 if (!webview())
867 return;
868
[email protected]26aa0482009-09-30 16:55:27869 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29870}
871
872void RenderView::OnCopy() {
873 if (!webview())
874 return;
875
[email protected]26aa0482009-09-30 16:55:27876 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
initial.commit09911bf2008-07-26 23:55:29877}
878
[email protected]c0cc3092009-09-12 08:27:27879#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35880void RenderView::OnCopyToFindPboard() {
881 if (!webview())
882 return;
883
884 // Since the find pasteboard supports only plain text, this can be simpler
885 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27886 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35887 if (frame->hasSelection()) {
888 string16 selection = frame->selectionAsText();
889 RenderThread::current()->Send(
[email protected]7e3589742011-03-10 18:49:17890 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35891 }
[email protected]a954bf72009-09-12 07:30:35892}
[email protected]c0cc3092009-09-12 08:27:27893#endif
[email protected]a954bf72009-09-12 07:30:35894
initial.commit09911bf2008-07-26 23:55:29895void RenderView::OnPaste() {
896 if (!webview())
897 return;
898
[email protected]26aa0482009-09-30 16:55:27899 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29900}
901
[email protected]2a3a7762009-10-19 19:17:32902void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29903 if (!webview())
904 return;
905
[email protected]1ff7a032010-02-03 02:46:03906 WebFrame* frame = webview()->focusedFrame();
907 if (!frame->hasSelection())
908 frame->selectWordAroundCaret();
909 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29910}
911
912void RenderView::OnDelete() {
913 if (!webview())
914 return;
915
[email protected]26aa0482009-09-30 16:55:27916 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29917}
918
919void RenderView::OnSelectAll() {
920 if (!webview())
921 return;
922
[email protected]26aa0482009-09-30 16:55:27923 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22924 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29925}
926
927void RenderView::OnSetInitialFocus(bool reverse) {
928 if (!webview())
929 return;
[email protected]26aa0482009-09-30 16:55:27930 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29931}
932
[email protected]9b66f34bf2010-10-27 20:45:51933void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:09934 WebKit::WebNode node = GetFocusedNode();
935 if (!node.isNull()) {
936 if (IsEditableNode(node))
937 // TODO(varunjain): Change webkit API to scroll a particular node into
938 // view and use that API here instead.
939 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:51940 }
941}
942
initial.commit09911bf2008-07-26 23:55:29943///////////////////////////////////////////////////////////////////////////////
944
945// Tell the embedding application that the URL of the active page has changed
946void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45947 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29948 DCHECK(ds);
949
[email protected]726985e22009-06-18 21:09:28950 const WebURLRequest& request = ds->request();
951 const WebURLRequest& original_request = ds->originalRequest();
952 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29953
[email protected]daa8c58e2009-06-15 17:21:10954 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
955 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29956
957 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28958 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29959 params.is_post = false;
960 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:07961 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:19962 params.socket_address.set_host(response.remoteIPAddress().utf8());
963 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:03964 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:09965 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:55966 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29967 // SSL state specified in the request takes precedence over the one in the
968 // response.
969 // So far this is only intended for error pages that are not expected to be
970 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28971 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55972 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29973 } else {
[email protected]726985e22009-06-18 21:09:28974 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29975 }
976
977 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28978 if (ds->hasUnreachableURL()) {
979 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29980 } else {
[email protected]726985e22009-06-18 21:09:28981 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29982 }
983
[email protected]726985e22009-06-18 21:09:28984 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:24985 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:04986 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:29987
[email protected]ce0e250d2009-10-23 21:00:35988 params.searchable_form_url = navigation_state->searchable_form_url();
989 params.searchable_form_encoding =
990 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:29991
992 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:10993 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:29994 if (password_form_data)
995 params.password_form = *password_form_data;
996
997 params.gesture = navigation_gesture_;
998 navigation_gesture_ = NavigationGestureUnknown;
999
[email protected]0f38dc4552011-02-25 11:24:001000 // Make navigation state a part of the FrameNavigate message so that commited
1001 // entry had it at all times.
1002 const WebHistoryItem& item = frame->currentHistoryItem();
1003 if (!item.isNull()) {
1004 params.content_state = webkit_glue::HistoryItemToString(item);
1005 } else {
1006 params.content_state =
1007 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1008 }
1009
[email protected]dd7daa82009-08-10 05:46:451010 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291011 // Top-level navigation.
1012
[email protected]b75b8292010-10-01 07:28:251013 // Set zoom level, but don't do it for full-page plugin since they don't use
1014 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011015 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541016 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251017 if (webview()->mainFrame()->document().isPluginDocument()) {
1018 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251019 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251020 } else {
1021 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251022 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251023 }
1024
[email protected]f85f0702010-01-30 09:31:011025 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511026 // This zoom level was merely recorded transiently for this load. We can
1027 // erase it now. If at some point we reload this page, the browser will
1028 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011029 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511030 }
1031
[email protected]b75b8292010-10-01 07:28:251032 // Reset the zoom limits in case a plugin had changed them previously. This
1033 // will also call us back which will cause us to send a message to
1034 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251035 webview()->zoomLimitsChanged(
1036 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1037 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251038
initial.commit09911bf2008-07-26 23:55:291039 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551040 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291041
[email protected]daa8c58e2009-06-15 17:21:101042 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291043 if (!PageTransition::IsMainFrame(params.transition)) {
1044 // If the main frame does a load, it should not be reported as a subframe
1045 // navigation. This can occur in the following case:
1046 // 1. You're on a site with frames.
1047 // 2. You do a subframe navigation. This is stored with transition type
1048 // MANUAL_SUBFRAME.
1049 // 3. You navigate to some non-frame site, say, google.com.
1050 // 4. You navigate back to the page from step 2. Since it was initially
1051 // MANUAL_SUBFRAME, it will be that same transition type here.
1052 // We don't want that, because any navigation that changes the toplevel
1053 // frame should be tracked as a toplevel navigation (this allows us to
1054 // update the URL bar, etc).
1055 params.transition = PageTransition::LINK;
1056 }
1057
initial.commit09911bf2008-07-26 23:55:291058 // If we have a valid consumed client redirect source,
1059 // the page contained a client redirect (meta refresh, document.loc...),
1060 // so we set the referrer and transition to match.
1061 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041062 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291063 params.referrer = completed_client_redirect_src_;
1064 params.transition = static_cast<PageTransition::Type>(
1065 params.transition | PageTransition::CLIENT_REDIRECT);
1066 } else {
1067 // Bug 654101: the referrer will be empty on https->http transitions. It
1068 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281069 params.referrer = GURL(
1070 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291071 }
1072
[email protected]726985e22009-06-18 21:09:281073 string16 method = request.httpMethod();
1074 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291075 params.is_post = true;
1076
[email protected]c2a797d2009-09-21 16:46:321077 // Save some histogram data so we can compute the average memory used per
1078 // page load of the glyphs.
1079 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1080 webkit_glue::GetGlyphPageCount());
1081
[email protected]15cf526b2010-02-12 06:33:491082 // This message needs to be sent before any of allowScripts(),
1083 // allowImages(), allowPlugins() is called for the new page, so that when
1084 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1085 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291086 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1087 } else {
1088 // Subframe navigation: the type depends on whether this navigation
1089 // generated a new session history entry. When they do generate a session
1090 // history entry, it means the user initiated the navigation and we should
1091 // mark it as such. This test checks if this is the first time UpdateURL
1092 // has been called since WillNavigateToURL was called to initiate the load.
1093 if (page_id_ > last_page_id_sent_to_browser_)
1094 params.transition = PageTransition::MANUAL_SUBFRAME;
1095 else
1096 params.transition = PageTransition::AUTO_SUBFRAME;
1097
initial.commit09911bf2008-07-26 23:55:291098 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1099 }
1100
1101 last_page_id_sent_to_browser_ =
1102 std::max(last_page_id_sent_to_browser_, page_id_);
1103
1104 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101105 // we don't want the transition type to persist. Just clear it.
1106 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501107
[email protected]af15bed2010-08-25 21:12:091108 // Check if the navigation was within the same page, in which case we don't
1109 // want to clear the accessibility cache.
1110 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351111 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141112 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501113 }
initial.commit09911bf2008-07-26 23:55:291114}
1115
1116// Tell the embedding application that the title of the active page has changed
[email protected]6b2f7a82011-04-25 19:30:511117void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291118 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171119 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171120 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171121 routing_id_,
1122 page_id_,
[email protected]6b2f7a82011-04-25 19:30:511123 UTF16ToWideHack(title.length() > content::kMaxTitleChars ?
1124 title.substr(0, content::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171125 }
initial.commit09911bf2008-07-26 23:55:291126}
1127
1128void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401129 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291130 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271131 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291132 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301133 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291134 last_encoding_name_ = encoding_name;
1135
[email protected]e38f40152008-09-12 23:08:301136 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291137 }
1138}
1139
[email protected]e15f680732010-11-23 22:30:201140// Sends the last committed session history state to the browser so it will be
1141// saved before we navigate to a new page. This must be called *before* the
1142// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291143void RenderView::UpdateSessionHistory(WebFrame* frame) {
1144 // If we have a valid page ID at this point, then it corresponds to the page
1145 // we are navigating away from. Otherwise, this is the first navigation, so
1146 // there is no past session history to record.
1147 if (page_id_ == -1)
1148 return;
1149
[email protected]ca948a22009-06-25 19:36:171150 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271151 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171152 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291153 return;
[email protected]ca948a22009-06-25 19:36:171154
1155 Send(new ViewHostMsg_UpdateState(
1156 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291157}
1158
[email protected]3d9689372009-09-10 04:29:171159void RenderView::OpenURL(
1160 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1161 Send(new ViewHostMsg_OpenURL(
1162 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1163}
1164
[email protected]79dbc662009-09-04 05:42:511165// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291166
initial.commit09911bf2008-07-26 23:55:291167void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281168 const WebURLRequest& failed_request,
1169 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291170 const std::string& html,
1171 bool replace) {
[email protected]21d61e52011-03-18 19:08:251172 std::string alt_html = !html.empty() ? html :
1173 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1174 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451175 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361176 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251177 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551178 replace);
initial.commit09911bf2008-07-26 23:55:291179}
1180
initial.commit09911bf2008-07-26 23:55:291181bool RenderView::RunJavaScriptMessage(int type,
1182 const std::wstring& message,
1183 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071184 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291185 std::wstring* result) {
1186 bool success = false;
1187 std::wstring result_temp;
1188 if (!result)
1189 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291190
[email protected]12636df2009-09-28 22:32:211191 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1192 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291193 return success;
1194}
1195
[email protected]c1f50aa2010-02-18 03:46:571196bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1197 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1198 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1199 // it is particularly important that we do not call willEnterModalLoop as
1200 // that would defer resource loads for the dialog itself.
1201 if (RenderThread::current()) // Will be NULL during unit tests.
1202 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1203
1204 message->EnableMessagePumping(); // Runs a nested message loop.
1205 return Send(message);
1206}
1207
[email protected]f103ab72009-09-02 17:10:591208void RenderView::OnMissingPluginStatus(
1209 WebPluginDelegateProxy* delegate,
1210 int status) {
[email protected]6c8afae52009-01-22 02:24:571211#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591212 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291213 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:501214 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591215 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291216 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1217 }
1218 } else {
1219 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1220 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:501221 if (status ==
1222 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:291223 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1224 }
1225 }
[email protected]6c8afae52009-01-22 02:24:571226#else
[email protected]76c3b312010-05-20 21:38:291227 // TODO(port): Implement the infobar that accompanies the default plugin.
1228 // Linux: http://crbug.com/10952
1229 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571230 NOTIMPLEMENTED();
1231#endif
initial.commit09911bf2008-07-26 23:55:291232}
1233
[email protected]48c9cf2d2009-09-16 16:47:521234// WebKit::WebViewClient ------------------------------------------------------
1235
[email protected]844acf372011-01-14 10:49:271236WebView* RenderView::createView(
1237 WebFrame* creator,
1238 const WebURLRequest& request,
1239 const WebWindowFeatures& features,
1240 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521241 // Check to make sure we aren't overloading on popups.
1242 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1243 return NULL;
1244
[email protected]8ab04652010-06-12 02:47:261245 ViewHostMsg_CreateWindow_Params params;
1246 params.opener_id = routing_id_;
1247 params.user_gesture = creator->isProcessingUserGesture();
1248 params.window_container_type = WindowFeaturesToContainerType(features);
1249 params.session_storage_namespace_id = session_storage_namespace_id_;
1250 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111251 params.opener_frame_id = creator->identifier();
1252 params.opener_url = creator->url();
1253 params.opener_security_origin = creator->securityOrigin().toString().utf8();
1254 if (!request.isNull())
1255 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261256
[email protected]48c9cf2d2009-09-16 16:47:521257 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341258 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261259 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521260
[email protected]48c9cf2d2009-09-16 16:47:521261 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261262 new ViewHostMsg_CreateWindow(params,
1263 &routing_id,
1264 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211265 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521266 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521267
[email protected]48c9cf2d2009-09-16 16:47:521268 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421269 0,
[email protected]c03a6e72011-04-19 21:42:061270 gfx::kNullPluginWindow,
[email protected]12636df2009-09-28 22:32:211271 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521272 renderer_preferences_,
1273 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211274 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341275 routing_id,
[email protected]8ab04652010-06-12 02:47:261276 cloned_session_storage_namespace_id,
1277 frame_name);
1278 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521279
[email protected]007a848b2009-10-26 15:55:461280 // Record whether the creator frame is trying to suppress the opener field.
1281 view->opener_suppressed_ = opener_suppressed;
1282
[email protected]48c9cf2d2009-09-16 16:47:521283 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091284 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521285 if (!creator_url.is_valid() || !creator_url.IsStandard())
1286 creator_url = GURL();
1287 view->creator_url_ = creator_url;
1288
1289 // Copy over the alternate error page URL so we can have alt error pages in
1290 // the new render view (we don't need the browser to send the URL back down).
1291 view->alternate_error_page_url_ = alternate_error_page_url_;
1292
1293 return view->webview();
1294}
1295
[email protected]3e2b375b2010-04-07 17:03:121296WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521297 RenderWidget* widget = RenderWidget::Create(routing_id_,
1298 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121299 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521300 return widget->webwidget();
1301}
1302
1303WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441304 // TODO(jcivelli): Remove this deprecated method when its been removed from
1305 // the WebViewClient interface. It's been replaced by
1306 // createExternalPopupMenu.
1307 NOTREACHED();
1308 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521309}
1310
[email protected]caf706f2010-10-26 17:54:081311WebExternalPopupMenu* RenderView::createExternalPopupMenu(
1312 const WebPopupMenuInfo& popup_menu_info,
1313 WebExternalPopupMenuClient* popup_menu_client) {
1314 DCHECK(!external_popup_menu_.get());
1315 external_popup_menu_.reset(
1316 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1317 return external_popup_menu_.get();
1318}
1319
[email protected]ea192e82011-04-11 19:16:021320RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521321 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531322 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421323 if (webview() && webview()->mainFrame())
[email protected]d91233b7e2011-03-29 20:33:531324 active_url = GURL(webview()->mainFrame()->url());
1325 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
1326 routing_id_, render_thread_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391327 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561328 return widget;
[email protected]79c7bed2010-09-14 22:28:391329}
1330
[email protected]68c50e52010-05-12 11:14:391331WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341332 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391333 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291334 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1335 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1336 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341337}
1338
[email protected]48c9cf2d2009-09-16 16:47:521339void RenderView::didAddMessageToConsole(
1340 const WebConsoleMessage& message, const WebString& source_name,
1341 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081342 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
1343 switch(message.level) {
1344 case WebConsoleMessage::LevelTip:
1345 log_severity = logging::LOG_VERBOSE;
1346 break;
1347 case WebConsoleMessage::LevelLog:
1348 log_severity = logging::LOG_INFO;
1349 break;
1350 case WebConsoleMessage::LevelWarning:
1351 log_severity = logging::LOG_WARNING;
1352 break;
1353 case WebConsoleMessage::LevelError:
1354 log_severity = logging::LOG_ERROR;
1355 break;
1356 default:
1357 NOTREACHED();
1358 }
1359
[email protected]48c9cf2d2009-09-16 16:47:521360 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081361 static_cast<int32>(log_severity),
[email protected]48c9cf2d2009-09-16 16:47:521362 UTF16ToWideHack(message.text),
1363 static_cast<int32>(source_line),
1364 UTF16ToWideHack(source_name)));
1365}
1366
1367void RenderView::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421368 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521369}
1370
[email protected]3354d3e2010-06-10 19:53:021371WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511372 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021373}
1374
[email protected]8a58c1c2011-04-19 18:40:121375bool RenderView::enumerateChosenDirectory(
1376 const WebString& path,
1377 WebFileChooserCompletion* chooser_completion) {
1378 int id = enumeration_completion_id_++;
1379 enumeration_completions_[id] = chooser_completion;
1380 return Send(new ViewHostMsg_EnumerateDirectory(
1381 routing_id_,
1382 id,
1383 webkit_glue::WebStringToFilePath(path)));
1384}
1385
[email protected]48c9cf2d2009-09-16 16:47:521386void RenderView::didStartLoading() {
1387 if (is_loading_) {
1388 DLOG(WARNING) << "didStartLoading called while loading";
1389 return;
1390 }
1391
1392 is_loading_ = true;
1393 // Clear the pointer so that we can assign it only when there is an unknown
1394 // plugin on a page.
1395 first_default_plugin_.reset();
1396
1397 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311398
1399 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521400}
1401
1402void RenderView::didStopLoading() {
1403 if (!is_loading_) {
1404 DLOG(WARNING) << "DidStopLoading called while not loading";
1405 return;
1406 }
1407
1408 is_loading_ = false;
1409
1410 // NOTE: For now we're doing the safest thing, and sending out notification
1411 // when done loading. This currently isn't an issue as the favicon is only
1412 // displayed when done loading. Ideally we would send notification when
1413 // finished parsing the head, but webkit doesn't support that yet.
1414 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521415 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1416
[email protected]90109412010-12-15 17:14:241417 if (load_progress_tracker_ != NULL)
1418 load_progress_tracker_->DidStopLoading();
1419
[email protected]93b9d692011-04-13 00:44:311420 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521421}
1422
[email protected]90109412010-12-15 17:14:241423void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
1424 if (load_progress_tracker_ != NULL)
1425 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1426}
1427
[email protected]f55039a2010-02-17 14:12:061428bool RenderView::isSmartInsertDeleteEnabled() {
1429#if defined(OS_MACOSX)
1430 return true;
1431#else
1432 return false;
1433#endif
1434}
1435
[email protected]04fc9482009-09-18 22:13:031436bool RenderView::isSelectTrailingWhitespaceEnabled() {
1437#if defined(OS_WIN)
1438 return true;
1439#else
1440 return false;
1441#endif
1442}
1443
[email protected]04fc9482009-09-18 22:13:031444void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:421445#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031446 if (!handling_input_event_)
1447 return;
[email protected]d4cff272011-05-02 15:46:011448
1449 if (is_empty_selection) {
1450 last_selection_.clear();
1451 } else {
[email protected]04fc9482009-09-18 22:13:031452 // Sometimes we get repeated didChangeSelection calls from webkit when
1453 // the selection hasn't actually changed. We don't want to report these
1454 // because it will cause us to continually claim the X clipboard.
[email protected]d4cff272011-05-02 15:46:011455 WebFrame* frame = webview()->focusedFrame();
1456 const std::string& this_selection = frame->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031457 if (this_selection == last_selection_)
1458 return;
[email protected]04fc9482009-09-18 22:13:031459 last_selection_ = this_selection;
[email protected]04fc9482009-09-18 22:13:031460 }
[email protected]d4cff272011-05-02 15:46:011461
1462 ui::Range range(ui::Range::InvalidRange());
1463 size_t location, length;
1464 if (webview()->caretOrSelectionRange(&location, &length)) {
1465 range.set_start(location);
1466 range.set_end(location + length);
1467 }
1468 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range));
[email protected]0ff0ff32010-12-21 19:34:421469#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031470}
1471
1472void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121473 const std::string& name = UTF16ToUTF8(command_name);
1474 if (StartsWithASCII(name, "Move", true) ||
1475 StartsWithASCII(name, "Insert", true) ||
1476 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031477 return;
[email protected]9966325b2011-04-18 05:00:101478 webkit_glue::UserMetricsRecordAction(name);
[email protected]04fc9482009-09-18 22:13:031479}
1480
[email protected]54ec7f82010-10-21 22:32:511481void RenderView::SendPendingAccessibilityNotifications() {
1482 if (!accessibility_.get())
1483 return;
1484
1485 if (pending_accessibility_notifications_.empty())
1486 return;
1487
1488 // Send all pending accessibility notifications.
1489 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
1490 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
1491 RendererAccessibilityNotification& notification =
1492 pending_accessibility_notifications_[i];
1493 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
1494 if (!obj.isValid())
1495 continue;
1496
1497 ViewHostMsg_AccessibilityNotification_Params param;
[email protected]a527a022011-02-10 02:32:361498 WebAccessibilityNotificationToViewHostMsg(
1499 pending_accessibility_notifications_[i].type, &param.notification_type);
[email protected]70eee342010-11-05 01:59:371500 param.acc_obj = WebAccessibility(
1501 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:511502 notifications.push_back(param);
1503 }
1504 pending_accessibility_notifications_.clear();
1505 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
1506 accessibility_ack_pending_ = true;
1507}
1508
[email protected]b2528b72009-09-24 06:57:101509bool RenderView::handleCurrentKeyboardEvent() {
1510 if (edit_commands_.empty())
1511 return false;
1512
[email protected]26aa0482009-09-30 16:55:271513 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101514 if (!frame)
1515 return false;
1516
1517 EditCommands::iterator it = edit_commands_.begin();
1518 EditCommands::iterator end = edit_commands_.end();
1519
[email protected]507b33ea2009-09-29 03:56:511520 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101521 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331522 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1523 // key (but it's the exception). Once one edit command is not executed, it
1524 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101525 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1526 WebString::fromUTF8(it->value)))
1527 break;
[email protected]507b33ea2009-09-29 03:56:511528 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101529 }
1530
[email protected]507b33ea2009-09-29 03:56:511531 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101532}
1533
[email protected]a1128322009-10-06 18:38:461534bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351535 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471536 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351537 // Do not open the file dialog in a hidden RenderView.
1538 if (is_hidden())
1539 return false;
[email protected]cdaf8d02010-03-30 19:52:471540 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261541 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361542 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261543 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361544 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]b5977a0c2010-08-24 19:46:261545 else
[email protected]0aed2f52011-03-23 18:06:361546 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471547 ipc_params.title = params.title;
1548 ipc_params.default_file_name =
1549 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591550 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471551
1552 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461553}
1554
[email protected]48c9cf2d2009-09-16 16:47:521555void RenderView::runModalAlertDialog(
1556 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061557 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]48c9cf2d2009-09-16 16:47:521558 UTF16ToWideHack(message),
1559 std::wstring(),
1560 frame->url(),
1561 NULL);
1562}
1563
1564bool RenderView::runModalConfirmDialog(
1565 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061566 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]48c9cf2d2009-09-16 16:47:521567 UTF16ToWideHack(message),
1568 std::wstring(),
1569 frame->url(),
1570 NULL);
1571}
1572
1573bool RenderView::runModalPromptDialog(
1574 WebFrame* frame, const WebString& message, const WebString& default_value,
1575 WebString* actual_value) {
1576 std::wstring result;
[email protected]9dd7e3d72011-01-20 18:27:061577 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]48c9cf2d2009-09-16 16:47:521578 UTF16ToWideHack(message),
1579 UTF16ToWideHack(default_value),
1580 frame->url(),
1581 &result);
1582 if (ok)
1583 actual_value->assign(WideToUTF16Hack(result));
1584 return ok;
1585}
1586
1587bool RenderView::runModalBeforeUnloadDialog(
1588 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151589 // If we are swapping out, we have already run the beforeunload handler.
1590 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1591 // at all, to avoid running it twice.
1592 if (is_swapped_out_)
1593 return true;
1594
[email protected]48c9cf2d2009-09-16 16:47:521595 bool success = false;
1596 // This is an ignored return value, but is included so we can accept the same
1597 // response as RunJavaScriptMessage.
1598 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211599 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521600 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211601 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521602 return success;
1603}
1604
[email protected]79e37442009-10-09 18:17:441605void RenderView::showContextMenu(
1606 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291607 ContextMenuParams params = ContextMenuParams(data);
[email protected]db803aae2011-03-05 02:00:421608 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271609 // it. We replace it with an empty GURL so the appropriate items are disabled
1610 // in the context menu.
1611 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1612 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421613 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271614 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101615 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291616 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441617}
1618
[email protected]52f139e2c2010-06-11 16:56:091619bool RenderView::supportsFullscreen() {
1620 return CommandLine::ForCurrentProcess()->HasSwitch(
1621 switches::kEnableVideoFullscreen);
1622}
1623
1624void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1625 NOTIMPLEMENTED();
1626}
1627
1628void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1629 NOTIMPLEMENTED();
1630}
1631
[email protected]48c9cf2d2009-09-16 16:47:521632void RenderView::setStatusText(const WebString& text) {
1633}
1634
[email protected]163f8242009-10-30 20:19:551635void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581636 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521637 if (latest_url == target_url_)
1638 return;
[email protected]163f8242009-10-30 20:19:551639
[email protected]48c9cf2d2009-09-16 16:47:521640 // Tell the browser to display a destination link.
1641 if (target_url_status_ == TARGET_INFLIGHT ||
1642 target_url_status_ == TARGET_PENDING) {
1643 // If we have a request in-flight, save the URL to be sent when we
1644 // receive an ACK to the in-flight request. We can happily overwrite
1645 // any existing pending sends.
1646 pending_target_url_ = latest_url;
1647 target_url_status_ = TARGET_PENDING;
1648 } else {
1649 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1650 target_url_ = latest_url;
1651 target_url_status_ = TARGET_INFLIGHT;
1652 }
1653}
1654
[email protected]882daa92009-11-05 16:31:311655void RenderView::StartNavStateSyncTimerIfNecessary() {
1656 int delay;
1657 if (send_content_state_immediately_)
1658 delay = 0;
1659 else if (is_hidden())
1660 delay = kDelaySecondsForContentStateSyncHidden;
1661 else
1662 delay = kDelaySecondsForContentStateSync;
1663
1664 if (nav_state_sync_timer_.IsRunning()) {
1665 // The timer is already running. If the delay of the timer maches the amount
1666 // we want to delay by, then return. Otherwise stop the timer so that it
1667 // gets started with the right delay.
1668 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1669 return;
1670 nav_state_sync_timer_.Stop();
1671 }
1672
1673 nav_state_sync_timer_.Start(
1674 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1675}
1676
[email protected]163f8242009-10-30 20:19:551677void RenderView::setMouseOverURL(const WebURL& url) {
1678 mouse_over_url_ = GURL(url);
1679 UpdateTargetURL(mouse_over_url_, focus_url_);
1680}
1681
1682void RenderView::setKeyboardFocusURL(const WebURL& url) {
1683 focus_url_ = GURL(url);
1684 UpdateTargetURL(focus_url_, mouse_over_url_);
1685}
1686
[email protected]48c9cf2d2009-09-16 16:47:521687void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1688 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1689 hint));
1690}
1691
[email protected]c27ae592010-03-18 15:24:411692void RenderView::startDragging(const WebDragData& data,
1693 WebDragOperationsMask mask,
1694 const WebImage& image,
1695 const WebPoint& imageOffset) {
1696#if WEBKIT_USING_SKIA
1697 SkBitmap bitmap(image.getSkBitmap());
1698#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331699 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411700#endif
1701
[email protected]59f4f2fa2011-03-23 01:00:551702 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521703 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411704 mask,
1705 bitmap,
1706 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521707}
1708
[email protected]28b92df2009-09-25 17:35:451709bool RenderView::acceptsLoadDrops() {
1710 return renderer_preferences_.can_accept_load_drops;
1711}
1712
[email protected]48c9cf2d2009-09-16 16:47:521713void RenderView::focusNext() {
1714 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1715}
1716
1717void RenderView::focusPrevious() {
1718 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1719}
1720
[email protected]08e9e132010-06-01 16:58:491721void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511722 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071723
1724 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
1725 // TODO(ctguil): Make WebKit send this notification.
1726 // When focus is cleared notify accessibility that the document is focused.
1727 postAccessibilityNotification(
1728 webview()->accessibilityObject(),
1729 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
1730 }
[email protected]13a1e4c3c2011-02-03 21:07:091731
[email protected]38b592902011-04-16 02:08:421732 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491733}
1734
[email protected]48c9cf2d2009-09-16 16:47:521735void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521736 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1737}
1738
1739int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001740 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521741}
1742
1743int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001744 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521745}
1746
[email protected]c4e98902010-06-01 10:20:141747void RenderView::didUpdateInspectorSetting(const WebString& key,
1748 const WebString& value) {
1749 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1750 key.utf8(),
1751 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261752}
1753
[email protected]79dbc662009-09-04 05:42:511754// WebKit::WebWidgetClient ----------------------------------------------------
1755
[email protected]ea42e7782010-08-23 23:58:121756void RenderView::didFocus() {
1757 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1758 // we won't have to test for user gesture anymore and we can
1759 // move that code back to render_widget.cc
1760 if (webview() && webview()->mainFrame() &&
1761 webview()->mainFrame()->isProcessingUserGesture()) {
1762 Send(new ViewHostMsg_Focus(routing_id_));
1763 }
1764}
1765
1766void RenderView::didBlur() {
1767 // TODO(jcivelli): see TODO above in didFocus().
1768 if (webview() && webview()->mainFrame() &&
1769 webview()->mainFrame()->isProcessingUserGesture()) {
1770 Send(new ViewHostMsg_Blur(routing_id_));
1771 }
1772}
1773
initial.commit09911bf2008-07-26 23:55:291774// We are supposed to get a single call to Show for a newly created RenderView
1775// that was created via RenderView::CreateWebView. So, we wait until this
1776// point to dispatch the ShowView message.
1777//
1778// This method provides us with the information about how to display the newly
1779// created RenderView (i.e., as a constrained popup or as a new tab).
1780//
[email protected]4873c7d2009-07-16 06:36:281781void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291782 DCHECK(!did_show_) << "received extraneous Show call";
1783 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1784
1785 if (did_show_)
1786 return;
1787 did_show_ = true;
1788
[email protected]6779aa12011-03-29 17:32:241789 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041790 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041791
[email protected]28295ec2009-10-16 05:34:331792 // Force new windows to a popup if they were not opened with a user gesture.
1793 if (!opened_by_user_gesture_) {
1794 // We exempt background tabs for compat with older versions of Chrome.
1795 // TODO(darin): This seems bogus. These should have a user gesture, so
1796 // we probably don't need this check.
1797 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1798 policy = WebKit::WebNavigationPolicyNewPopup;
1799 }
1800
initial.commit09911bf2008-07-26 23:55:291801 // NOTE: initial_pos_ may still have its default values at this point, but
1802 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1803 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281804 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1805 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291806 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241807 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291808}
1809
[email protected]4873c7d2009-07-16 06:36:281810void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291811 DCHECK(did_show_) << "should already have shown the view";
1812
[email protected]c1f50aa2010-02-18 03:46:571813 // We must keep WebKit's shared timer running in this case in order to allow
1814 // showModalDialog to function properly.
1815 //
1816 // TODO(darin): WebKit should really be smarter about suppressing events and
1817 // timers so that we do not need to manage the shared timer in such a heavy
1818 // handed manner.
1819 //
1820 if (RenderThread::current()) // Will be NULL during unit tests.
1821 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
1822
[email protected]12636df2009-09-28 22:32:211823 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291824}
1825
[email protected]3d9689372009-09-10 04:29:171826// WebKit::WebFrameClient -----------------------------------------------------
1827
[email protected]00152e92010-07-19 11:47:401828WebPlugin* RenderView::createPlugin(WebFrame* frame,
1829 const WebPluginParams& params) {
[email protected]e7c21b812011-03-19 18:03:301830 return content::GetContentClient()->renderer()->CreatePlugin(
[email protected]21d61e52011-03-18 19:08:251831 this, frame, params);
[email protected]3d9689372009-09-10 04:29:171832}
1833
1834WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561835 WebApplicationCacheHostImpl* appcache_host =
1836 WebApplicationCacheHostImpl::FromFrame(frame);
1837 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
1838 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
1839 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171840}
1841
[email protected]9c00f002009-11-05 22:37:421842WebSharedWorker* RenderView::createSharedWorker(
1843 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371844 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421845
[email protected]30447b62009-11-13 01:13:371846 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511847 bool exists = false;
[email protected]30447b62009-11-13 01:13:371848 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511849 ViewHostMsg_CreateWorker_Params params;
1850 params.url = url;
1851 params.is_shared = true;
1852 params.name = name;
1853 params.document_id = document_id;
1854 params.render_view_route_id = routing_id_;
1855 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231856 params.parent_appcache_host_id = 0;
1857 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371858 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511859 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371860 if (url_mismatch) {
1861 return NULL;
1862 } else {
1863 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:491864 document_id,
[email protected]6de0bcf2010-02-17 22:00:511865 exists,
[email protected]30447b62009-11-13 01:13:371866 route_id,
1867 routing_id_);
1868 }
[email protected]9c00f002009-11-05 22:37:421869}
1870
[email protected]3d9689372009-09-10 04:29:171871WebMediaPlayer* RenderView::createMediaPlayer(
1872 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441873 FOR_EACH_OBSERVER(
1874 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171875
[email protected]f78d1dfc2011-01-15 07:09:271876 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1877 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491878 scoped_ptr<media::FilterCollection> collection(
1879 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371880
[email protected]3d9689372009-09-10 04:29:171881 // Add in any custom filter factories first.
1882 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1883 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1884 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:491885 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:171886 }
1887
[email protected]3bb08602010-10-07 21:47:171888 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:121889 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:071890 WebGraphicsContext3DCommandBufferImpl* context =
1891 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
1892 frame->view()->graphicsContext3D());
1893 if (!context)
1894 return NULL;
[email protected]a9a43012010-11-05 01:54:061895
[email protected]5aa6a312010-11-06 00:00:071896 // Add the hardware video decoder factory.
1897 // TODO(hclam): This will cause the renderer process to crash on context
1898 // lost.
1899 bool ret = context->makeContextCurrent();
1900 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:491901 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:071902 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:171903 }
1904
[email protected]457d8342010-10-23 01:20:371905 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:311906 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
1907 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
1908 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:491909 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:311910 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:111911
[email protected]a8e24d522010-12-01 07:13:581912 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:271913 new webkit_glue::WebMediaPlayerImpl(client,
1914 collection.release(),
1915 message_loop_factory.release()));
[email protected]79684282010-12-06 21:15:461916 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:581917 cmd_line->HasSwitch(switches::kSimpleDataSource),
1918 video_renderer)) {
1919 return NULL;
1920 }
1921 return result.release();
[email protected]3d9689372009-09-10 04:29:171922}
1923
[email protected]035545f2010-04-09 13:10:211924WebApplicationCacheHost* RenderView::createApplicationCacheHost(
1925 WebFrame* frame, WebApplicationCacheHostClient* client) {
1926 return new RendererWebApplicationCacheHostImpl(
1927 FromWebView(frame->view()), client,
1928 RenderThread::current()->appcache_dispatcher()->backend_proxy());
1929}
1930
[email protected]8ff181072010-11-29 17:09:381931WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
1932 return &cookie_jar_;
1933}
1934
[email protected]5041f982010-08-11 21:40:451935void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511936 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451937}
1938
[email protected]3d9689372009-09-10 04:29:171939void RenderView::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511940 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171941}
1942
1943void RenderView::loadURLExternally(
1944 WebFrame* frame, const WebURLRequest& request,
1945 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:591946 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1947 if (policy == WebKit::WebNavigationPolicyDownload) {
1948 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1949 } else {
1950 OpenURL(request.url(), referrer, policy);
1951 }
[email protected]3d9689372009-09-10 04:29:171952}
1953
1954WebNavigationPolicy RenderView::decidePolicyForNavigation(
1955 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221956 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:151957 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
1958 if (is_swapped_out_) {
1959 DCHECK(request.url() == GURL("about:swappedout"));
1960 return default_policy;
1961 }
1962
[email protected]3d9689372009-09-10 04:29:171963 // Webkit is asking whether to navigate to a new URL.
1964 // This is fine normally, except if we're showing UI from one security
1965 // context and they're trying to navigate to a different context.
1966 const GURL& url = request.url();
1967
[email protected]d19ea342011-04-20 20:31:131968 // A content initiated navigation may have originated from a link-click,
1969 // script, drag-n-drop operation, etc.
1970 bool is_content_initiated =
1971 NavigationState::FromDataSource(frame->provisionalDataSource())->
1972 is_content_initiated();
1973
[email protected]3d9689372009-09-10 04:29:171974 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:301975 // navigations.
[email protected]d19ea342011-04-20 20:31:131976 if (is_content_initiated &&
1977 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:451978 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:191979 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:231980 // Reset these counters as the RenderView could be reused for the next
1981 // navigation.
1982 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:231983 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:191984 OpenURL(url, referrer, default_policy);
1985 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:171986 }
1987
[email protected]a6b960ad972010-09-01 19:53:581988 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:171989
[email protected]6101c342010-12-16 22:44:371990 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:551991 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:571992 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:371993 // opening a new window). But we sometimes navigate to about:blank to clear a
1994 // tab, and we want to still allow that.
1995 //
[email protected]8f4da8c2011-02-09 19:49:571996 // Note: we do this only for GET requests because our mechanism for switching
1997 // processes only issues GET requests. In particular, POST requests don't
1998 // work, because this mechanism does not preserve form POST data. If it
1999 // becomes necessary to support process switching for POST requests, we will
2000 // need to send the request's httpBody data up to the browser process, and
2001 // issue a special POST navigation in WebKit (via
2002 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2003 // for examples of how to send the httpBody data.
2004 // Note2: We normally don't do this for browser-initiated navigations, since
2005 // it's pointless to tell the browser about navigations it gave us. But
2006 // we do potentially ask the browser to handle a redirect that was originally
2007 // initiated by the browser. See http://crbug.com/70943
2008 //
2009 // TODO(creis): Move this redirect check to the browser process to avoid
2010 // ping-ponging. See http://crbug.com/72380.
2011 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372012 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2013 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2014 bool send_referrer = false;
2015 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552016 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172017 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372018 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112019
[email protected]e48869a2011-04-01 19:56:032020 if (!should_fork) {
2021 // Give the embedder a chance.
2022 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2023 frame, url, is_content_initiated, &send_referrer);
[email protected]6101c342010-12-16 22:44:372024 }
2025
2026 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112027 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372028 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112029 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2030 }
[email protected]3d9689372009-09-10 04:29:172031 }
2032
2033 // Detect when a page is "forking" a new tab that can be safely rendered in
2034 // its own process. This is done by sites like Gmail that try to open links
2035 // in new windows without script connections back to the original page. We
2036 // treat such cases as browser navigations (in which we will create a new
2037 // renderer for a cross-site navigation), rather than WebKit navigations.
2038 //
2039 // We use the following heuristic to decide whether to fork a new page in its
2040 // own process:
2041 // The parent page must open a new tab to about:blank, set the new tab's
2042 // window.opener to null, and then redirect the tab to a cross-site URL using
2043 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462044 //
2045 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2046 // (see below).
[email protected]3d9689372009-09-10 04:29:172047 bool is_fork =
2048 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582049 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172050 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522051 historyBackListCount() < 1 &&
2052 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172053 // The parent page must have set the child's window.opener to null before
2054 // redirecting to the desired URL.
2055 frame->opener() == NULL &&
2056 // Must be a top-level frame.
2057 frame->parent() == NULL &&
2058 // Must not have issued the request from this page.
2059 is_content_initiated &&
2060 // Must be targeted at the current tab.
2061 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2062 // Must be a JavaScript navigation, which appears as "other".
2063 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462064
2065 // Recognize if this navigation is from a link with rel=noreferrer and
2066 // target=_blank attributes, in which case the opener will be suppressed. If
2067 // so, it is safe to load cross-site pages in a separate process, so we
2068 // should let the browser handle it.
2069 bool is_noreferrer_and_blank_target =
2070 // Frame should be top level and not yet navigated.
2071 frame->parent() == NULL &&
2072 frame->url().isEmpty() &&
2073 historyBackListCount() < 1 &&
2074 historyForwardListCount() < 1 &&
2075 // Links with rel=noreferrer will have no Referer field, and their
2076 // resulting frame will have its window.opener suppressed.
2077 // TODO(creis): should add a request.httpReferrer() method to help avoid
2078 // typos on the unusual spelling of Referer.
2079 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2080 opener_suppressed_ &&
2081 frame->opener() == NULL &&
2082 // Links with target=_blank will have no name.
2083 frame->name().isNull() &&
2084 // Another frame (with a non-empty creator) should have initiated the
2085 // request, targeted at this frame.
2086 !creator_url_.is_empty() &&
2087 is_content_initiated &&
2088 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2089 type == WebKit::WebNavigationTypeOther;
2090
2091 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172092 // Open the URL via the browser, not via WebKit.
2093 OpenURL(url, GURL(), default_policy);
2094 return WebKit::WebNavigationPolicyIgnore;
2095 }
2096
2097 return default_policy;
2098}
2099
[email protected]6069da8c2009-10-20 20:33:492100bool RenderView::canHandleRequest(
2101 WebFrame* frame, const WebURLRequest& request) {
2102 // We allow WebKit to think that everything can be handled even though
2103 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342104 return true;
2105}
2106
[email protected]6069da8c2009-10-20 20:33:492107WebURLError RenderView::cannotHandleRequestError(
2108 WebFrame* frame, const WebURLRequest& request) {
2109 NOTREACHED(); // Since we said we can handle all requests.
2110 return WebURLError();
2111}
2112
2113WebURLError RenderView::cancelledError(
2114 WebFrame* frame, const WebURLRequest& request) {
2115 WebURLError error;
2116 error.domain = WebString::fromUTF8(net::kErrorDomain);
2117 error.reason = net::ERR_ABORTED;
2118 error.unreachableURL = request.url();
2119 return error;
[email protected]7b7a7dc2009-10-19 02:23:342120}
2121
2122void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492123 WebFrame*, const WebURLError&) {
2124 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342125}
2126
[email protected]90eeddb2010-05-06 21:06:432127void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2128 const WebKit::WebFormElement& form) {
2129 // Some login forms have onSubmit handlers that put a hash of the password
2130 // into a hidden field and then clear the password. (Issue 28910.)
2131 // This method gets called before any of those handlers run, so save away
2132 // a copy of the password in case it gets lost.
2133 NavigationState* navigation_state =
2134 NavigationState::FromDataSource(frame->dataSource());
2135 navigation_state->set_password_form_data(
2136 PasswordFormDomManager::CreatePasswordForm(form));
2137}
2138
[email protected]979c28b2009-11-07 01:30:482139void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172140 NavigationState* navigation_state =
2141 NavigationState::FromDataSource(frame->provisionalDataSource());
2142
2143 if (navigation_state->transition_type() == PageTransition::LINK)
2144 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2145
2146 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352147 WebSearchableFormData web_searchable_form_data(form);
2148 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2149 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212150 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432151 PasswordForm* password_form_data =
2152 PasswordFormDomManager::CreatePasswordForm(form);
2153 navigation_state->set_password_form_data(password_form_data);
2154
[email protected]098c95cb2011-04-28 16:49:012155 // In order to save the password that the user actually typed and not one
2156 // that may have gotten transformed by the site prior to submit, recover it
2157 // from the form contents already stored by |willSendSubmitEvent| into the
2158 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2159 // which is what we're storing into now.)
2160 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432161 NavigationState* old_navigation_state =
2162 NavigationState::FromDataSource(frame->dataSource());
2163 if (old_navigation_state) {
2164 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2165 if (old_form_data && old_form_data->action == password_form_data->action)
2166 password_form_data->password_value = old_form_data->password_value;
2167 }
2168 }
[email protected]3d9689372009-09-10 04:29:172169
[email protected]2a5b1732011-04-01 23:55:552170 FOR_EACH_OBSERVER(
2171 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172172}
2173
2174void RenderView::willPerformClientRedirect(
2175 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2176 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382177 FOR_EACH_OBSERVER(
2178 RenderViewObserver, observers_,
2179 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172180}
2181
2182void RenderView::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382183 FOR_EACH_OBSERVER(
2184 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172185}
2186
2187void RenderView::didCompleteClientRedirect(
2188 WebFrame* frame, const WebURL& from) {
2189 if (!frame->parent())
2190 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382191 FOR_EACH_OBSERVER(
2192 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172193}
2194
2195void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2196 // The rest of RenderView assumes that a WebDataSource will always have a
2197 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482198 bool content_initiated = !pending_navigation_state_.get();
2199 NavigationState* state = content_initiated ?
2200 NavigationState::CreateContentInitiated() :
2201 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512202
[email protected]8a3125a712010-08-09 18:58:512203 // NavigationState::referred_by_prefetcher_ is true if we are
2204 // navigating from a page that used prefetching using a link on that
2205 // page. We are early enough in the request process here that we
2206 // can still see the NavigationState of the previous page and set
2207 // this value appropriately.
2208 // TODO(gavinp): catch the important case of navigation in a new
2209 // renderer process.
2210 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302211 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522212 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512213 const GURL referrer(
2214 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2215 if (!referrer.is_empty() &&
2216 NavigationState::FromDataSource(
2217 old_frame->dataSource())->was_prefetcher()) {
2218 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2219 WebDataSource* old_frame_ds = old_frame->dataSource();
2220 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2221 state->set_was_referred_by_prefetcher(true);
2222 break;
2223 }
2224 }
2225 }
2226 }
2227 }
2228
[email protected]4c1b6f0b2010-02-07 16:38:182229 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522230 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512231 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182232 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2233 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2234 break;
2235 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2236 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2237 break;
2238 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2239 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2240 break;
2241 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2242 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2243 break;
2244 }
2245 }
[email protected]fa7b6b542009-11-03 05:02:302246
[email protected]16e923d2011-04-30 00:41:442247 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502248
[email protected]946a0032011-03-31 18:42:282249 FOR_EACH_OBSERVER(
2250 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172251}
2252
2253void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2254 WebDataSource* ds = frame->provisionalDataSource();
2255 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2256
[email protected]3d9689372009-09-10 04:29:172257 // Update the request time if WebKit has better knowledge of it.
2258 if (navigation_state->request_time().is_null()) {
2259 double event_time = ds->triggeringEventTime();
2260 if (event_time != 0.0)
2261 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2262 }
2263
[email protected]05c8e502010-08-15 15:13:522264 // Start time is only set after request time.
2265 navigation_state->set_start_load_time(Time::Now());
2266
[email protected]3d9689372009-09-10 04:29:172267 bool is_top_most = !frame->parent();
2268 if (is_top_most) {
2269 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132270 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172271
2272 // Make sure redirect tracking state is clear for the new load.
2273 completed_client_redirect_src_ = GURL();
2274 } else if (frame->parent()->isLoading()) {
2275 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002276 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172277 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2278 }
2279
[email protected]28685da92011-02-07 21:49:172280 FOR_EACH_OBSERVER(
2281 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2282
[email protected]3d9689372009-09-10 04:29:172283 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]04a3ce32011-05-17 23:36:132284 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172285}
2286
2287void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2288 if (frame->parent())
2289 return;
2290 // Received a redirect on the main frame.
2291 WebDataSource* data_source = frame->provisionalDataSource();
2292 if (!data_source) {
2293 // Should only be invoked when we have a data source.
2294 NOTREACHED();
2295 return;
2296 }
2297 std::vector<GURL> redirects;
2298 GetRedirectChain(data_source, &redirects);
2299 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512300 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]04a3ce32011-05-17 23:36:132301 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172302 }
2303}
2304
[email protected]40bd6582009-12-04 23:49:512305void RenderView::didFailProvisionalLoad(WebFrame* frame,
2306 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172307 // Notify the browser that we failed a provisional load with an error.
2308 //
2309 // Note: It is important this notification occur before DidStopLoading so the
2310 // SSL manager can react to the provisional load failure before being
2311 // notified the load stopped.
2312 //
2313 WebDataSource* ds = frame->provisionalDataSource();
2314 DCHECK(ds);
2315
2316 const WebURLRequest& failed_request = ds->request();
2317
[email protected]28685da92011-02-07 21:49:172318 FOR_EACH_OBSERVER(
2319 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2320
[email protected]3d9689372009-09-10 04:29:172321 bool show_repost_interstitial =
2322 (error.reason == net::ERR_CACHE_MISS &&
2323 EqualsASCII(failed_request.httpMethod(), "POST"));
2324 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072325 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2326 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172327
2328 // Don't display an error page if this is simply a cancelled load. Aside
2329 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2330 if (error.reason == net::ERR_ABORTED)
2331 return;
2332
2333 // Make sure we never show errors in view source mode.
2334 frame->enableViewSourceMode(false);
2335
2336 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2337
2338 // If this is a failed back/forward/reload navigation, then we need to do a
2339 // 'replace' load. This is necessary to avoid messing up session history.
2340 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2341 // as session history is concerned.
2342 //
2343 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2344 // the page id.
2345 //
2346 bool replace =
2347 navigation_state->pending_page_id() != -1 ||
2348 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2349
2350 // If we failed on a browser initiated request, then make sure that our error
2351 // page load is regarded as the same browser initiated request.
2352 if (!navigation_state->is_content_initiated()) {
2353 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2354 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002355 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172356 navigation_state->transition_type(),
2357 navigation_state->request_time()));
2358 }
2359
2360 // Provide the user with a more helpful error page?
2361 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2362 return;
2363
2364 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082365 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172366}
2367
2368void RenderView::didReceiveDocumentData(
2369 WebFrame* frame, const char* data, size_t data_len,
2370 bool& prevent_default) {
2371 NavigationState* navigation_state =
2372 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092373 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172374}
2375
[email protected]40bd6582009-12-04 23:49:512376void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2377 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172378 NavigationState* navigation_state =
2379 NavigationState::FromDataSource(frame->dataSource());
2380
2381 navigation_state->set_commit_load_time(Time::Now());
2382 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202383 // When we perform a new navigation, we need to update the last committed
2384 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172385 UpdateSessionHistory(frame);
2386
2387 // We bump our Page ID to correspond with the new session history entry.
2388 page_id_ = next_page_id_++;
2389
[email protected]3cc72b12010-03-18 23:03:002390 // Advance our offset in session history, applying the length limit. There
2391 // is now no forward history.
2392 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102393 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2394 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002395 history_list_length_ = history_list_offset_ + 1;
[email protected]3d9689372009-09-10 04:29:172396 } else {
2397 // Inspect the navigation_state on this frame to see if the navigation
2398 // corresponds to a session history navigation... Note: |frame| may or
2399 // may not be the toplevel frame, but for the case of capturing session
2400 // history, the first committed frame suffices. We keep track of whether
2401 // we've seen this commit before so that only capture session history once
2402 // per navigation.
2403 //
2404 // Note that we need to check if the page ID changed. In the case of a
2405 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2406 // previous URL and the current page ID, which would be wrong.
2407 if (navigation_state->pending_page_id() != -1 &&
2408 navigation_state->pending_page_id() != page_id_ &&
2409 !navigation_state->request_committed()) {
2410 // This is a successful session history navigation!
2411 UpdateSessionHistory(frame);
2412 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002413
2414 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172415 }
2416 }
2417
[email protected]28685da92011-02-07 21:49:172418 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2419 DidCommitProvisionalLoad(frame, is_new_navigation));
2420
[email protected]3d9689372009-09-10 04:29:172421 // Remember that we've already processed this request, so we don't update
2422 // the session history again. We do this regardless of whether this is
2423 // a session history navigation, because if we attempted a session history
2424 // navigation without valid HistoryItem state, WebCore will think it is a
2425 // new navigation.
2426 navigation_state->set_request_committed(true);
2427
2428 UpdateURL(frame);
2429
2430 // If this committed load was initiated by a client redirect, we're
2431 // at the last stop now, so clear it.
2432 completed_client_redirect_src_ = GURL();
2433
2434 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272435 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172436}
2437
2438void RenderView::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102439 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2440 DidClearWindowObject(frame));
2441
[email protected]0d7ae862010-10-01 13:52:452442 GURL frame_url = frame->url();
[email protected]c09163a2011-02-15 00:05:552443 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:252444 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2445 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272446 GetWebUIBindings()->set_message_sender(this);
2447 GetWebUIBindings()->set_routing_id(routing_id_);
2448 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172449 }
[email protected]3d9689372009-09-10 04:29:172450}
2451
2452void RenderView::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172453 // Notify the browser about non-blank documents loading in the top frame.
2454 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252455 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272456 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172457 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2458 }
[email protected]e48869a2011-04-01 19:56:032459
2460 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2461 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172462}
2463
[email protected]a3bc4d12011-04-20 17:22:212464void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title,
2465 WebTextDirection direction) {
[email protected]6b2f7a82011-04-25 19:30:512466 // TODO: pass direction through various APIs.
2467 // http://code.google.com/p/chromium/issues/detail?id=79903
2468 UpdateTitle(frame, title);
[email protected]3d9689372009-09-10 04:29:172469
2470 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272471 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172472}
2473
[email protected]42054a252011-05-17 18:02:132474void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
2475 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2476 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582477}
2478
[email protected]3d9689372009-09-10 04:29:172479void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2480 WebDataSource* ds = frame->dataSource();
2481 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2482 DCHECK(navigation_state);
2483 navigation_state->set_finish_document_load_time(Time::Now());
2484
[email protected]622474d2010-11-04 09:21:082485 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172486
[email protected]28685da92011-02-07 21:49:172487 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2488 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172489
2490 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272491 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172492}
2493
2494void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082495 if (webview()->mainFrame() == frame) {
2496 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2497 page_id_));
2498 }
[email protected]3d9689372009-09-10 04:29:172499}
2500
2501void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172502 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172503}
2504
2505void RenderView::didFinishLoad(WebFrame* frame) {
2506 WebDataSource* ds = frame->dataSource();
2507 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2508 DCHECK(navigation_state);
2509 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412510
[email protected]676126f72011-01-15 00:03:512511 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172512
2513 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172514}
2515
[email protected]ccbe04e2010-03-17 17:58:432516void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172517 WebFrame* frame, bool is_new_navigation) {
2518 // If this was a reference fragment navigation that we initiated, then we
2519 // could end up having a non-null pending navigation state. We just need to
2520 // update the ExtraData on the datasource so that others who read the
2521 // ExtraData will get the new NavigationState. Similarly, if we did not
2522 // initiate this navigation, then we need to take care to reset any pre-
2523 // existing navigation state to a content-initiated navigation state.
2524 // DidCreateDataSource conveniently takes care of this for us.
2525 didCreateDataSource(frame, frame->dataSource());
2526
[email protected]af15bed2010-08-25 21:12:092527 NavigationState* new_state =
2528 NavigationState::FromDataSource(frame->dataSource());
2529 new_state->set_was_within_same_page(true);
2530
[email protected]3d9689372009-09-10 04:29:172531 didCommitProvisionalLoad(frame, is_new_navigation);
2532
[email protected]6b2f7a82011-04-25 19:30:512533 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172534}
2535
[email protected]476b6f82009-09-10 21:00:592536void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312537 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592538}
2539
[email protected]3d9689372009-09-10 04:29:172540void RenderView::assignIdentifierToRequest(
2541 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2542 // Ignore
2543}
2544
2545void RenderView::willSendRequest(
2546 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2547 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302548 WebFrame* top_frame = frame->top();
2549 if (!top_frame)
2550 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512551 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2552 WebDataSource* top_data_source = top_frame->dataSource();
2553 WebDataSource* data_source =
2554 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222555
[email protected]e48869a2011-04-01 19:56:032556
[email protected]78d5cfe2011-02-04 08:43:222557 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032558 GURL new_url;
2559 if (content::GetContentClient()->renderer()->WillSendRequest(
2560 frame, request_url, &new_url)) {
2561 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222562 }
2563
[email protected]5e369672009-11-03 23:48:302564 if (data_source) {
2565 NavigationState* state = NavigationState::FromDataSource(data_source);
2566 if (state && state->is_cache_policy_override_set())
2567 request.setCachePolicy(state->cache_policy_override());
2568 }
[email protected]8a3125a712010-08-09 18:58:512569
2570 if (top_data_source) {
2571 NavigationState* state = NavigationState::FromDataSource(top_data_source);
2572 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
2573 state->set_was_prefetcher(true);
2574 }
2575
[email protected]3d9689372009-09-10 04:29:172576 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132577 request.setHasUserGesture(frame->isProcessingUserGesture());
2578
[email protected]0a8db0d2011-04-13 15:15:402579 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132580 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492581
[email protected]85cc78c2010-05-04 18:30:092582 // Temporary metrics, see site_isolation_metrics.h
2583 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:172584}
2585
2586void RenderView::didReceiveResponse(
2587 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492588
[email protected]85cc78c2010-05-04 18:30:092589 // Temporary metrics, see site_isolation_metrics.h
2590 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
2591 identifier,
2592 response);
[email protected]fa0a3432010-03-30 16:53:492593
[email protected]3d9689372009-09-10 04:29:172594 // Only do this for responses that correspond to a provisional data source
2595 // of the top-most frame. If we have a provisional data source, then we
2596 // can't have any sub-resources yet, so we know that this response must
2597 // correspond to a frame load.
2598 if (!frame->provisionalDataSource() || frame->parent())
2599 return;
2600
2601 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082602 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172603 if (frame->isViewSourceModeEnabled())
2604 return;
2605
[email protected]65041fa2010-05-21 06:56:532606 NavigationState* navigation_state =
2607 NavigationState::FromDataSource(frame->provisionalDataSource());
2608 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082609 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532610
[email protected]972ebdff2010-06-10 22:59:072611 // Record page load flags.
2612 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2613 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572614 navigation_state->set_was_alternate_protocol_available(
2615 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072616 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082617 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092618 // Whether or not the http status code actually corresponds to an error is
2619 // only checked when the page is done loading, if |use_error_page| is
2620 // still true.
2621 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172622}
2623
2624void RenderView::didFinishResourceLoad(
2625 WebFrame* frame, unsigned identifier) {
2626 NavigationState* navigation_state =
2627 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092628 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172629 return;
2630
[email protected]06333afe2011-02-24 14:55:092631 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082632 int http_status_code = navigation_state->http_status_code();
2633 if (http_status_code == 404) {
2634 // On 404s, try a remote search page as a fallback.
2635 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:172636
[email protected]3f853a52010-09-13 19:15:082637 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092638 if (error_page_url.is_valid()) {
2639 WebURLError original_error;
2640 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]3d9689372009-09-10 04:29:172711void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142712 CheckPreferredSize();
2713}
2714
2715void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172716 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252717 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172718 // message.
[email protected]705243f2010-05-05 19:58:072719 if (!send_preferred_size_changes_ || !webview())
2720 return;
[email protected]dfca5acf2010-03-22 03:28:432721
[email protected]705243f2010-05-05 19:58:072722 // WebCore likes to tell us things have changed even when they haven't, so
2723 // cache the width and height and only send the IPC message when we're sure
2724 // they're different.
2725 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2726 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532727
2728 // In the presence of zoom, these sizes are still reported as if unzoomed,
2729 // so we need to adjust.
2730 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2731 size.set_width(static_cast<int>(size.width() * zoom_factor));
2732 size.set_height(static_cast<int>(size.height() * zoom_factor));
2733
[email protected]705243f2010-05-05 19:58:072734 if (size == preferred_size_)
2735 return;
[email protected]c27324b2009-11-19 22:44:292736
[email protected]705243f2010-05-05 19:58:072737 preferred_size_ = size;
2738 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2739 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172740}
2741
[email protected]143dcd592009-11-06 21:33:492742void RenderView::didChangeScrollOffset(WebFrame* frame) {
2743 StartNavStateSyncTimerIfNecessary();
2744}
2745
[email protected]8922e1f2009-10-03 05:01:262746void RenderView::reportFindInPageMatchCount(int request_id, int count,
2747 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112748 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2749 if (!count)
2750 active_match_ordinal = 0;
2751
2752 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2753 routing_id_,
2754 request_id,
2755 count,
2756 gfx::Rect(),
2757 active_match_ordinal,
2758 final_update);
2759
[email protected]8922e1f2009-10-03 05:01:262760 // If we have a message that has been queued up, then we should just replace
2761 // it. The ACK from the browser will make sure it gets sent when the browser
2762 // wants it.
2763 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262764 queued_find_reply_message_.reset(msg);
2765 } else {
2766 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112767 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262768 }
2769}
2770
2771void RenderView::reportFindInPageSelection(int request_id,
2772 int active_match_ordinal,
2773 const WebRect& selection_rect) {
2774 // Send the search result over to the browser process.
2775 Send(new ViewHostMsg_Find_Reply(routing_id_,
2776 request_id,
2777 -1,
2778 selection_rect,
2779 active_match_ordinal,
2780 false));
2781}
2782
[email protected]2b06a992010-08-21 05:48:222783void RenderView::openFileSystem(
2784 WebFrame* frame,
2785 WebFileSystem::Type type,
2786 long long size,
[email protected]d275d7a2010-11-03 01:34:492787 bool create,
[email protected]2b06a992010-08-21 05:48:222788 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082789 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222790
2791 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082792 if (origin.isEmpty()) {
2793 // Uninitialized document?
2794 callbacks->didFail(WebKit::WebFileErrorAbort);
2795 return;
2796 }
[email protected]2b06a992010-08-21 05:48:222797
[email protected]c5a272d2010-09-27 18:37:082798 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2799 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492800 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222801}
2802
[email protected]10e5cf12011-04-13 04:10:402803void RenderView::queryStorageUsageAndQuota(
2804 WebFrame* frame,
2805 WebStorageQuotaType type,
2806 WebStorageQuotaCallbacks* callbacks) {
2807 DCHECK(frame);
2808 WebSecurityOrigin origin = frame->securityOrigin();
2809 if (origin.isEmpty()) {
2810 // Uninitialized document?
2811 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2812 return;
2813 }
2814 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
2815 GURL(origin.toString()), type, callbacks);
2816}
2817
2818void RenderView::requestStorageQuota(
2819 WebFrame* frame,
2820 WebStorageQuotaType type,
2821 unsigned long long requested_size,
2822 WebStorageQuotaCallbacks* callbacks) {
2823 DCHECK(frame);
2824 WebSecurityOrigin origin = frame->securityOrigin();
2825 if (origin.isEmpty()) {
2826 // Uninitialized document?
2827 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2828 return;
2829 }
2830 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
2831 GURL(origin.toString()), type, requested_size, callbacks);
2832}
2833
[email protected]79dbc662009-09-04 05:42:512834// webkit_glue::WebPluginPageDelegate -----------------------------------------
2835
[email protected]191eb3f72010-12-21 06:27:502836webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:532837 const FilePath& file_path,
2838 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:592839 if (!PluginChannelHost::IsListening())
2840 return NULL;
2841
[email protected]00c39612010-03-06 02:53:282842 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:462843 if (in_process_plugin) {
[email protected]6876dff2010-01-15 19:38:092844#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]e8f7a182011-03-10 00:50:222845 return webkit::npapi::WebPluginDelegateImpl::Create(
2846 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092847#else
[email protected]e8f7a182011-03-10 00:50:222848 NOTIMPLEMENTED();
2849 return NULL;
[email protected]7b6616f2010-01-14 18:07:552850#endif
[email protected]f103ab72009-09-02 17:10:592851 }
2852
[email protected]4e0616e2010-05-28 14:55:532853 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592854}
2855
2856void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032857#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592858 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2859 routing_id(), window));
2860#endif
2861}
2862
2863void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032864#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592865 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2866 routing_id(), window));
2867#endif
2868 CleanupWindowInPluginMoves(window);
2869}
2870
[email protected]191eb3f72010-12-21 06:27:502871void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:592872 SchedulePluginMove(move);
2873}
2874
2875void RenderView::DidStartLoadingForPlugin() {
2876 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522877 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592878}
2879
2880void RenderView::DidStopLoadingForPlugin() {
2881 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522882 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592883}
2884
[email protected]b921cfd22010-02-25 16:57:512885WebCookieJar* RenderView::GetCookieJar() {
2886 return &cookie_jar_;
2887}
2888
initial.commit09911bf2008-07-26 23:55:292889void RenderView::SyncNavigationState() {
2890 if (!webview())
2891 return;
2892
[email protected]26aa0482009-09-30 16:55:272893 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172894 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292895 return;
[email protected]ca948a22009-06-25 19:36:172896
2897 Send(new ViewHostMsg_UpdateState(
2898 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292899}
2900
[email protected]7ccddb8c2009-08-04 17:36:552901GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292902 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552903 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292904 // If the URL that failed was secure, then the embedding web page was not
2905 // expecting a network attacker to be able to manipulate its contents. As
2906 // we fetch alternate error pages over HTTP, we would be allowing a network
2907 // attacker to manipulate the contents of the response if we tried to use
2908 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:152909 return GURL();
initial.commit09911bf2008-07-26 23:55:292910 }
2911
2912 // Grab the base URL from the browser process.
2913 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:152914 return GURL();
initial.commit09911bf2008-07-26 23:55:292915
2916 // Strip query params from the failed URL.
2917 GURL::Replacements remove_params;
2918 remove_params.ClearUsername();
2919 remove_params.ClearPassword();
2920 remove_params.ClearQuery();
2921 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552922 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:502923 std::string spec_to_send = url_to_send.spec();
2924 // Notify link doctor of the url truncation by sending of "?" at the end.
2925 if (failed_url.has_query())
2926 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:292927
2928 // Construct the query params to send to link doctor.
2929 std::string params(alternate_error_page_url_.query());
2930 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:502931 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:292932 params.append("&sourceid=chrome");
2933 params.append("&error=");
2934 switch (error_type) {
2935 case DNS_ERROR:
2936 params.append("dnserror");
2937 break;
2938
2939 case HTTP_404:
2940 params.append("http404");
2941 break;
2942
[email protected]5df266ac2008-10-15 19:50:132943 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332944 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132945 break;
2946
initial.commit09911bf2008-07-26 23:55:292947 default:
2948 NOTREACHED() << "unknown ErrorPageType";
2949 }
2950
2951 // OK, build the final url to return.
2952 GURL::Replacements link_doctor_params;
2953 link_doctor_params.SetQueryStr(params);
2954 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2955 return url;
2956}
2957
[email protected]c50008512011-02-03 01:17:272958WebUIBindings* RenderView::GetWebUIBindings() {
2959 if (!web_ui_bindings_.get()) {
2960 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:462961 }
[email protected]c50008512011-02-03 01:17:272962 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:462963}
2964
[email protected]0fdbf8c2010-07-08 20:33:012965WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
2966 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:492967}
2968
[email protected]6069da8c2009-10-20 20:33:492969void RenderView::OnFind(int request_id, const string16& search_text,
2970 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272971 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:492972
2973 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:492974 if (options.findNext) {
2975 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:012976 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:492977 } else {
[email protected]afdbd142010-07-10 08:01:232978 if (GetWebPluginFromPluginDocument()->startFind(
2979 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:492980 } else {
[email protected]e7c58a32010-08-13 19:47:112981 // Send "no results".
2982 Send(new ViewHostMsg_Find_Reply(routing_id_,
2983 request_id,
2984 0,
2985 gfx::Rect(),
2986 0,
2987 true));
[email protected]24a7f3c2010-03-25 08:26:492988 }
2989 }
2990 return;
2991 }
2992
[email protected]b4bb2502009-10-01 22:35:272993 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272994 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292995 WebFrame* search_frame = focused_frame; // start searching focused frame.
2996
2997 bool multi_frame = (frame_after_main != main_frame);
2998
2999 // If we have multiple frames, we don't want to wrap the search within the
3000 // frame, so we check here if we only have main_frame in the chain.
3001 bool wrap_within_frame = !multi_frame;
3002
[email protected]b3f2b912009-04-09 16:18:523003 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293004 bool result = false;
3005
[email protected]7830da3e2009-11-06 16:27:263006 // If something is selected when we start searching it means we cannot just
3007 // increment the current match ordinal; we need to re-generate it.
3008 WebRange current_selection = focused_frame->selectionRange();
3009
initial.commit09911bf2008-07-26 23:55:293010 do {
[email protected]dd7daa82009-08-10 05:46:453011 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593012 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293013
3014 if (!result) {
3015 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223016 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293017
3018 // Find the next frame, but skip the invisible ones.
3019 do {
3020 // What is the next frame to search? (we might be going backwards). Note
3021 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593022 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273023 search_frame->traverseNext(true) :
3024 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453025 } while (!search_frame->hasVisibleContent() &&
3026 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293027
[email protected]884db412008-11-24 23:46:503028 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223029 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293030
3031 // If we have multiple frames and we have wrapped back around to the
3032 // focused frame, we need to search it once more allowing wrap within
3033 // the frame, otherwise it will report 'no match' if the focused frame has
3034 // reported matches, but no frames after the focused_frame contain a
3035 // match for the search word(s).
3036 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453037 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593038 request_id, search_text, options, true, // Force wrapping.
3039 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293040 }
3041 }
3042
[email protected]26aa0482009-09-30 16:55:273043 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293044 } while (!result && search_frame != focused_frame);
3045
[email protected]7830da3e2009-11-06 16:27:263046 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293047 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453048 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293049 } else {
3050 // If nothing is found, set result to "0 of 0", otherwise, set it to
3051 // "-1 of 1" to indicate that we found at least one item, but we don't know
3052 // yet what is active.
3053 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3054 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293055
[email protected]4f3dc372009-02-24 00:10:293056 // If we find no matches then this will be our last status update.
3057 // Otherwise the scoping effort will send more results.
3058 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293059
[email protected]4f3dc372009-02-24 00:10:293060 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403061 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593062 request_id,
[email protected]4f3dc372009-02-24 00:10:293063 match_count,
3064 selection_rect,
3065 ordinal,
3066 final_status_update));
initial.commit09911bf2008-07-26 23:55:293067
initial.commit09911bf2008-07-26 23:55:293068 // Scoping effort begins, starting with the mainframe.
3069 search_frame = main_frame;
3070
[email protected]dd7daa82009-08-10 05:46:453071 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293072
3073 do {
3074 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453075 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293076
3077 // We don't start another scoping effort unless at least one match has
3078 // been found.
3079 if (result) {
3080 // Start new scoping request. If the scoping function determines that it
3081 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453082 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593083 search_text,
3084 options,
initial.commit09911bf2008-07-26 23:55:293085 true); // reset the tickmarks
3086 }
3087
3088 // Iterate to the next frame. The frame will not necessarily scope, for
3089 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273090 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293091 } while (search_frame != main_frame);
3092 }
3093}
3094
[email protected]24a7f3c2010-03-25 08:26:493095void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3096 WebView* view = webview();
3097 if (!view)
3098 return;
3099
3100 WebDocument doc = view->mainFrame()->document();
3101 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013102 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493103 return;
3104 }
3105
3106 bool clear_selection =
3107 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3108 if (clear_selection)
3109 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3110
3111 WebFrame* frame = view->mainFrame();
3112 while (frame) {
3113 frame->stopFinding(clear_selection);
3114 frame = frame->traverseNext(false);
3115 }
3116
3117 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3118 WebFrame* focused_frame = view->focusedFrame();
3119 if (focused_frame) {
3120 WebDocument doc = focused_frame->document();
3121 if (!doc.isNull()) {
3122 WebNode node = doc.focusedNode();
3123 if (!node.isNull())
3124 node.simulateClick();
3125 }
3126 }
3127 }
3128}
3129
3130void RenderView::OnFindReplyAck() {
3131 // Check if there is any queued up request waiting to be sent.
3132 if (queued_find_reply_message_.get()) {
3133 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423134 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493135 }
3136}
3137
[email protected]0bd753682010-12-16 18:15:523138WebPlugin* RenderView::CreatePepperPlugin(
3139 WebFrame* frame,
3140 const WebPluginParams& params,
3141 const FilePath& path,
3142 webkit::ppapi::PluginModule* pepper_module) {
3143 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:253144 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:093145}
[email protected]00152e92010-07-19 11:47:403146
[email protected]191eb3f72010-12-21 06:27:503147WebPlugin* RenderView::CreateNPAPIPlugin(
3148 WebFrame* frame,
3149 const WebPluginParams& params,
3150 const FilePath& path,
3151 const std::string& mime_type) {
3152 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:083153 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403154}
3155
[email protected]40bd6582009-12-04 23:49:513156void RenderView::OnZoom(PageZoom::Function function) {
3157 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3158 return;
3159
[email protected]258d31122010-05-09 10:59:413160 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523161
[email protected]b75b8292010-10-01 07:28:253162 double old_zoom_level = webview()->zoomLevel();
3163 double zoom_level;
3164 if (function == PageZoom::RESET) {
3165 zoom_level = 0;
3166 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3167 // Previous zoom level is a whole number, so just increment/decrement.
3168 zoom_level = old_zoom_level + function;
3169 } else {
3170 // Either the user hit the zoom factor limit and thus the zoom level is now
3171 // not a whole number, or a plugin changed it to a custom value. We want
3172 // to go to the next whole number so that the user can always get back to
3173 // 100% with the keyboard/menu.
3174 if ((old_zoom_level > 1 && function > 0) ||
3175 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453176 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253177 } else {
3178 // We're going towards 100%, so first go to the next whole number.
3179 zoom_level = static_cast<int>(old_zoom_level);
3180 }
3181 }
[email protected]40bd6582009-12-04 23:49:513182
[email protected]b75b8292010-10-01 07:28:253183 webview()->setZoomLevel(false, zoom_level);
3184 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513185}
3186
[email protected]d0b8d092010-10-25 04:05:173187void RenderView::OnSetZoomLevel(double zoom_level) {
3188 // Don't set zoom level for full-page plugin since they don't use the same
3189 // zoom settings.
3190 if (webview()->mainFrame()->document().isPluginDocument())
3191 return;
3192
3193 webview()->hidePopups();
3194 webview()->setZoomLevel(false, zoom_level);
3195 zoomLevelChanged();
3196}
3197
[email protected]9d797f32010-04-23 07:17:543198void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:253199 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543200 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293201}
3202
[email protected]41fc0322009-09-04 22:23:403203void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273204 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293205}
3206
[email protected]a697f4c2009-09-14 22:30:183207void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273208 WebString no_encoding;
3209 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183210}
3211
[email protected]dd7daa82009-08-10 05:46:453212WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3213 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273214 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453215
3216 // xpath string can represent a frame deep down the tree (across multiple
3217 // frame DOMs).
3218 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3219 // should break into 2 xpaths
3220 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3221
[email protected]26aa0482009-09-30 16:55:273222 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453223
3224 std::wstring xpath_remaining = xpath;
3225 while (!xpath_remaining.empty()) {
3226 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3227 std::wstring xpath_child;
3228 if (delim_pos != std::wstring::npos) {
3229 xpath_child = xpath_remaining.substr(0, delim_pos);
3230 xpath_remaining.erase(0, delim_pos + 1);
3231 } else {
3232 xpath_remaining.swap(xpath_child);
3233 }
3234 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293235 }
3236
[email protected]dd7daa82009-08-10 05:46:453237 return frame;
initial.commit09911bf2008-07-26 23:55:293238}
3239
[email protected]13a1e4c3c2011-02-03 21:07:093240WebNode RenderView::GetFocusedNode() const {
3241 if (!webview())
3242 return WebNode();
3243 WebFrame* focused_frame = webview()->focusedFrame();
3244 if (focused_frame) {
3245 WebDocument doc = focused_frame->document();
3246 if (!doc.isNull())
3247 return doc.focusedNode();
3248 }
3249
3250 return WebNode();
3251}
3252
[email protected]38b592902011-04-16 02:08:423253bool RenderView::IsEditableNode(const WebNode& node) {
3254 bool is_editable_node = false;
3255 if (!node.isNull()) {
3256 if (node.isContentEditable()) {
3257 is_editable_node = true;
3258 } else if (node.isElementNode()) {
3259 is_editable_node =
3260 node.toConst<WebElement>().isTextFormControlElement();
3261 }
3262 }
3263 return is_editable_node;
3264}
3265
[email protected]882b7b22010-10-05 03:34:533266void RenderView::EvaluateScript(const string16& frame_xpath,
3267 const string16& script,
3268 int id,
3269 bool notify_result) {
3270 v8::Handle<v8::Value> result;
3271 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
3272 if (web_frame)
3273 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
3274 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:293275 ListValue list;
3276 if (web_frame) {
3277 v8::HandleScope handle_scope;
3278 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3279 v8::Context::Scope context_scope(context);
[email protected]b1cf3372011-04-20 21:28:103280 V8ValueConverter converter;
3281 converter.set_allow_date(true);
3282 converter.set_allow_regexp(true);
3283 list.Set(0, converter.FromV8Value(result, context));
[email protected]81f9fe0b2010-12-07 00:35:293284 } else {
3285 list.Set(0, Value::CreateNullValue());
3286 }
3287 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:533288 }
initial.commit09911bf2008-07-26 23:55:293289}
3290
[email protected]882b7b22010-10-05 03:34:533291void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
3292 const string16& jscript,
3293 int id,
3294 bool notify_result) {
3295 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293296}
3297
[email protected]1810e132009-03-24 23:35:483298void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083299 const std::string& css,
3300 const std::string& id) {
[email protected]216813952011-05-19 22:21:263301 WebFrame* web_frame = GetChildFrame(frame_xpath);
3302 if (!web_frame)
3303 return;
[email protected]ae461542009-06-19 19:03:413304
[email protected]216813952011-05-19 22:21:263305 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483306}
3307
[email protected]81e63782009-02-27 19:35:093308void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3309 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293310}
3311
[email protected]d0980792011-02-13 19:41:403312void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:293313 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:553314 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:273315 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293316}
3317
3318void RenderView::OnReservePageIDRange(int size_of_range) {
3319 next_page_id_ += size_of_range + 1;
3320}
3321
[email protected]59f4f2fa2011-03-23 01:00:553322void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
3323 const gfx::Point& client_point,
3324 const gfx::Point& screen_point,
3325 WebDragOperationsMask ops) {
3326 WebDragOperation operation = webview()->dragTargetDragEnter(
3327 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553328 client_point,
3329 screen_point,
3330 ops);
3331
3332 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3333}
3334
3335void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
3336 const gfx::Point& screen_point,
3337 WebDragOperationsMask ops) {
3338 WebDragOperation operation = webview()->dragTargetDragOver(
3339 client_point,
3340 screen_point,
3341 ops);
3342
3343 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3344}
3345
3346void RenderView::OnDragTargetDragLeave() {
3347 webview()->dragTargetDragLeave();
3348}
3349
3350void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3351 const gfx::Point& screen_point) {
3352 webview()->dragTargetDrop(client_point, screen_point);
3353}
3354
[email protected]e80c73b2009-04-07 23:24:583355void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3356 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253357 bool ended,
3358 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033359 if (ended) {
[email protected]26aa0482009-09-30 16:55:273360 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203361 } else {
3362 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033363 }
initial.commit09911bf2008-07-26 23:55:293364}
3365
3366void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273367 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293368}
3369
initial.commit09911bf2008-07-26 23:55:293370void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593371 webkit_preferences_ = prefs;
3372 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293373}
3374
3375void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3376 alternate_error_page_url_ = url;
3377}
3378
[email protected]b29aa74b2011-01-31 21:41:083379void RenderView::OnCustomContextMenuAction(
3380 const webkit_glue::CustomContextMenuContext& custom_context,
3381 unsigned action) {
3382 if (custom_context.is_pepper_menu)
3383 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3384 else
3385 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:333386}
3387
initial.commit09911bf2008-07-26 23:55:293388void RenderView::OnInstallMissingPlugin() {
3389 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593390 if (first_default_plugin_)
3391 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293392}
3393
[email protected]600ea402011-04-12 00:01:513394void RenderView::OnEnumerateDirectoryResponse(
3395 int id,
3396 const std::vector<FilePath>& paths) {
3397 if (!enumeration_completions_[id])
3398 return;
3399
3400 WebVector<WebString> ws_file_names(paths.size());
3401 for (size_t i = 0; i < paths.size(); ++i)
3402 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3403
3404 enumeration_completions_[id]->didChooseFile(ws_file_names);
3405 enumeration_completions_.erase(id);
3406}
3407
[email protected]cdaf8d02010-03-30 19:52:473408void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363409 // This could happen if we navigated to a different page before the user
3410 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473411 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363412 return;
3413
[email protected]cdaf8d02010-03-30 19:52:473414 WebVector<WebString> ws_file_names(paths.size());
3415 for (size_t i = 0; i < paths.size(); ++i)
3416 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463417
[email protected]cdaf8d02010-03-30 19:52:473418 if (file_chooser_completions_.front()->completion)
3419 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3420 file_chooser_completions_.pop_front();
3421
3422 // If there are more pending file chooser requests, schedule one now.
3423 if (!file_chooser_completions_.empty()) {
3424 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3425 file_chooser_completions_.front()->params));
3426 }
initial.commit09911bf2008-07-26 23:55:293427}
3428
[email protected]770dd8b2010-05-24 18:11:393429void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3430 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243431 if (send_preferred_size_changes_)
3432 return;
[email protected]9fb325e2010-05-06 18:23:243433 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393434
3435 // WebKit doesn't send a notification of the effective height of the page
3436 // changes, so poll for it.
3437 // TODO: Add a notification for this to WebKit, remove polling. After that's
3438 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
3439 // http://crbug.com/44850
3440 if (flags & kPreferredSizeHeightThisIsSlow) {
3441 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3442 &RenderView::CheckPreferredSize);
3443 }
[email protected]0666aef2009-05-13 19:48:083444}
3445
[email protected]cda45c02010-02-25 19:28:103446void RenderView::OnDisableScrollbarsForSmallWindows(
3447 const gfx::Size& disable_scrollbar_size_limit) {
3448 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3449}
3450
[email protected]80d96fa2009-06-10 22:34:513451void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3452 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373453 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133454#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413455 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3456 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463457 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513458 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343459 renderer_prefs.thumb_inactive_color,
3460 renderer_prefs.thumb_active_color,
3461 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323462
[email protected]644d77e2010-01-27 01:03:103463 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323464 webview()->setScrollbarColors(
3465 renderer_prefs.thumb_inactive_color,
3466 renderer_prefs.thumb_active_color,
3467 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103468 webview()->setSelectionColors(
3469 renderer_prefs.active_selection_bg_color,
3470 renderer_prefs.active_selection_fg_color,
3471 renderer_prefs.inactive_selection_bg_color,
3472 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463473 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103474 }
[email protected]7a74e102009-09-03 00:16:563475#endif
[email protected]80d96fa2009-06-10 22:34:513476}
3477
[email protected]952cb702009-10-07 05:50:283478void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3479 const WebMediaPlayerAction& action) {
3480 if (webview())
3481 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563482}
3483
[email protected]dea2d372010-09-25 06:41:143484void RenderView::OnEnableAccessibility() {
3485 if (WebAccessibilityCache::accessibilityEnabled())
3486 return;
[email protected]9f4db512010-05-10 20:21:413487
[email protected]dea2d372010-09-25 06:41:143488 WebAccessibilityCache::enableAccessibility();
3489
3490 if (webview()) {
3491 // It's possible that the webview has already loaded a webpage without
3492 // accessibility being enabled. Initialize the browser's cached
3493 // accessibility tree by sending it a 'load complete' notification.
3494 postAccessibilityNotification(
3495 webview()->accessibilityObject(),
3496 WebKit::WebAccessibilityNotificationLoadComplete);
3497 }
[email protected]266eb6f2008-09-30 23:56:503498}
3499
[email protected]aef92842010-05-21 16:54:363500void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
3501 if (!accessibility_.get())
3502 return;
[email protected]02ea2f312010-09-27 17:03:363503
3504 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3505 WebAccessibilityObject root = webview()->accessibilityObject();
3506 if (!obj.isValid() || !root.isValid())
3507 return;
3508
3509 // By convention, calling SetFocus on the root of the tree should clear the
3510 // current focus. Otherwise set the focus to the new node.
3511 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
3512 webview()->clearFocusedNode();
3513 else
3514 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:363515}
3516
3517void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
3518 if (!accessibility_.get())
3519 return;
[email protected]02ea2f312010-09-27 17:03:363520
3521 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3522 if (!obj.isValid())
3523 return;
3524
3525 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:363526}
3527
[email protected]9892b472010-09-16 00:23:423528void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:513529 DCHECK(accessibility_ack_pending_);
3530 accessibility_ack_pending_ = false;
3531 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:313532}
3533
[email protected]9b18a84f2010-06-10 15:54:043534void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273535 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473536 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293537}
3538
[email protected]992db4c2011-05-12 15:37:153539void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3540 if (is_swapped_out_)
3541 return;
3542
3543 // Swap this RenderView out so the tab can navigate to a page rendered by a
3544 // different process. This involves running the unload handler and clearing
3545 // the page. Once WasSwappedOut is called, we also allow this process to exit
3546 // if there are no other active RenderViews in it.
3547
3548 // Send an UpdateState message before we get swapped out.
3549 SyncNavigationState();
3550
3551 // Synchronously run the unload handler before sending the ACK.
3552 webview()->dispatchUnloadEvent();
3553
3554 // Swap out and stop sending any IPC messages that are not ACKs.
3555 SetSwappedOut(true);
3556
3557 // Replace the page with a blank dummy URL. The unload handler will not be
3558 // run a second time, thanks to a check in FrameLoader::stopLoading.
3559 // TODO(creis): Need to add a better way to do this that avoids running the
3560 // beforeunload handler. For now, we just run it a second time silently.
3561 webview()->mainFrame()->loadHTMLString(std::string(),
3562 GURL("about:swappedout"),
3563 GURL("about:swappedout"),
3564 false);
3565
3566 // Just echo back the params in the ACK.
3567 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3568}
3569
3570void RenderView::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:293571 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3572 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3573 // in the onunload handler from appearing. For now, we're bypassing that and
3574 // calling the FrameLoader's CloseURL method directly. This should be
3575 // revisited to avoid having two ways to close a page. Having a single way
3576 // to close that can run onunload is also useful for fixing
3577 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273578 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293579
[email protected]992db4c2011-05-12 15:37:153580 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293581}
3582
3583void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573584#if defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163585 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463586 if (webview())
3587 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573588#else // defined(OS_WIN)
3589 // TODO(port): we don't support theming on non-Windows platforms yet
3590 NOTIMPLEMENTED();
3591#endif
initial.commit09911bf2008-07-26 23:55:293592}
3593
[email protected]0aa55312008-10-17 21:53:083594void RenderView::OnDisassociateFromPopupCount() {
3595 if (decrement_shared_popup_at_destruction_)
3596 shared_popup_counter_->data--;
3597 shared_popup_counter_ = new SharedRenderViewCounter(0);
3598 decrement_shared_popup_at_destruction_ = false;
3599}
3600
[email protected]15d79e12009-08-02 19:23:453601bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3602 const WebURLError& error,
3603 bool replace) {
3604 // We only show alternate error pages in the main frame. They are
3605 // intended to assist the user when navigating, so there is not much
3606 // value in showing them for failed subframes. Ideally, we would be
3607 // able to use the TYPED transition type for this, but that flag is
3608 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453609 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453610 return false;
3611
3612 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373613 // connection failure.
[email protected]15d79e12009-08-02 19:23:453614 int ec = error.reason;
3615 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3616 ec != net::ERR_CONNECTION_FAILED &&
3617 ec != net::ERR_CONNECTION_REFUSED &&
3618 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373619 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453620 return false;
3621
3622 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553623 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453624 if (!error_page_url.is_valid())
3625 return false;
3626
3627 // Load an empty page first so there is an immediate response to the error,
3628 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453629 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363630 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453631 error.unreachableURL,
3632 replace);
3633
3634 // Now, create a fetcher for the error page and associate it with the data
3635 // source we just created via the LoadHTMLString call. That way if another
3636 // navigation occurs, the fetcher will get destroyed.
3637 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453638 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453639 navigation_state->set_alt_error_page_fetcher(
3640 new AltErrorPageResourceFetcher(
3641 error_page_url, frame, error,
3642 NewCallback(this, &RenderView::AltErrorPageFinished)));
3643 return true;
3644}
3645
[email protected]15d79e12009-08-02 19:23:453646void RenderView::AltErrorPageFinished(WebFrame* frame,
3647 const WebURLError& original_error,
3648 const std::string& html) {
3649 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093650 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553651 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093652 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453653}
3654
[email protected]30f75e62009-02-25 22:01:003655void RenderView::OnMoveOrResizeStarted() {
3656 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473657 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003658}
3659
[email protected]30f75e62009-02-25 22:01:003660void RenderView::OnResize(const gfx::Size& new_size,
3661 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103662 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473663 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103664 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203665 webview()->mainFrame()->setCanHaveScrollbars(
3666 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103667 }
3668 }
3669
[email protected]30f75e62009-02-25 22:01:003670 RenderWidget::OnResize(new_size, resizer_rect);
3671}
[email protected]0aa477bd2009-03-23 22:21:433672
[email protected]00c39612010-03-06 02:53:283673void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013674 // Notify the pepper plugins that we started painting.
3675 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283676}
3677
3678void RenderView::DidFlushPaint() {
3679 // Notify any pepper plugins that we painted. This will call into the plugin,
3680 // and we it may ask to close itself as a result. This will, in turn, modify
3681 // our set, possibly invalidating the iterator. So we iterate on a copy that
3682 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013683 pepper_delegate_.ViewFlushedPaint();
3684
[email protected]00c39612010-03-06 02:53:283685 WebFrame* main_frame = webview()->mainFrame();
3686
3687 // If we have a provisional frame we are between the start and commit stages
3688 // of loading and we don't want to save stats.
3689 if (!main_frame->provisionalDataSource()) {
3690 WebDataSource* ds = main_frame->dataSource();
3691 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3692 DCHECK(navigation_state);
3693
[email protected]05c8e502010-08-15 15:13:523694 // TODO(jar): The following code should all be inside a method, probably in
3695 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283696 Time now = Time::Now();
3697 if (navigation_state->first_paint_time().is_null()) {
3698 navigation_state->set_first_paint_time(now);
3699 }
3700 if (navigation_state->first_paint_after_load_time().is_null() &&
3701 !navigation_state->finish_load_time().is_null()) {
3702 navigation_state->set_first_paint_after_load_time(now);
3703 }
3704 }
3705}
3706
[email protected]65225772011-05-12 21:10:243707void RenderView::OnViewContextSwapBuffersComplete() {
3708 RenderWidget::OnSwapBuffersComplete();
3709}
3710
3711void RenderView::OnViewContextSwapBuffersAborted() {
3712 RenderWidget::OnSwapBuffersAborted();
3713}
3714
[email protected]719b36f2010-12-22 20:36:463715webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:153716 const gfx::Rect& paint_bounds,
3717 TransportDIB** dib,
3718 gfx::Rect* location,
3719 gfx::Rect* clip) {
3720 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
3721 paint_bounds, dib, location, clip);
3722}
3723
[email protected]bcaf2272011-02-15 15:29:433724gfx::Point RenderView::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:523725 WebKit::WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:433726 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523727}
3728
[email protected]05d478752009-04-08 23:38:163729void RenderView::OnClearFocusedNode() {
3730 if (webview())
[email protected]26aa0482009-09-30 16:55:273731 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163732}
3733
[email protected]699ab0d2009-04-23 23:19:143734void RenderView::OnSetBackground(const SkBitmap& background) {
3735 if (webview())
[email protected]b4bb2502009-10-01 22:35:273736 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143737
3738 SetBackground(background);
3739}
3740
[email protected]8c66c5a2009-07-22 17:26:343741void RenderView::OnSetActive(bool active) {
3742 if (webview())
[email protected]b4bb2502009-10-01 22:35:273743 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263744
3745#if defined(OS_MACOSX)
3746 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3747 for (plugin_it = plugin_delegates_.begin();
3748 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3749 (*plugin_it)->SetWindowFocus(active);
3750 }
3751#endif
[email protected]8c66c5a2009-07-22 17:26:343752}
3753
[email protected]6ce7abc52010-02-02 18:40:143754#if defined(OS_MACOSX)
3755void RenderView::OnSetWindowVisibility(bool visible) {
3756 // Inform plugins that their container has changed visibility.
3757 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3758 for (plugin_it = plugin_delegates_.begin();
3759 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3760 (*plugin_it)->SetContainerVisibility(visible);
3761 }
3762}
[email protected]1e6e3c992010-02-08 15:52:133763
[email protected]4d51d5bf2010-07-26 18:48:263764void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
3765 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:133766 // Inform plugins that their window's frame has changed.
3767 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3768 for (plugin_it = plugin_delegates_.begin();
3769 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3770 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3771 }
3772}
[email protected]935d63d2010-10-15 23:31:553773
[email protected]b7f75862011-01-21 21:15:133774void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:553775 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:133776 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:553777 // applies to it or not, so inform all the delegates.
3778 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3779 for (plugin_it = plugin_delegates_.begin();
3780 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:133781 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:553782 }
3783}
[email protected]6ce7abc52010-02-02 18:40:143784#endif // OS_MACOSX
3785
[email protected]9892b472010-09-16 00:23:423786void RenderView::postAccessibilityNotification(
3787 const WebAccessibilityObject& obj,
3788 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:143789 if (!accessibility_.get() && webview()) {
3790 // Load complete should be our first notification sent.
3791 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
3792 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
3793 return;
3794
3795 // Create and initialize our accessibility cache
3796 accessibility_.reset(WebAccessibilityCache::create());
3797 accessibility_->initialize(webview());
3798 }
3799
[email protected]a3fa4f92010-09-30 22:19:333800 if (!accessibility_->isCached(obj)) {
3801 // The browser doesn't know about objects that are not in the cache. Send a
3802 // children change for the first accestor that actually is in the cache.
3803 WebAccessibilityObject parent = obj;
3804 while (parent.isValid() && !accessibility_->isCached(parent))
3805 parent = parent.parentObject();
3806
3807 DCHECK(parent.isValid() && accessibility_->isCached(parent));
3808 if (!parent.isValid())
3809 return;
3810 postAccessibilityNotification(
3811 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
3812
3813 // The parent's children change takes care of the child's children change.
3814 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
3815 return;
3816 }
3817
[email protected]dea2d372010-09-25 06:41:143818 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:513819 RendererAccessibilityNotification acc_notification;
3820 acc_notification.id = accessibility_->addOrGetId(obj);
[email protected]a527a022011-02-10 02:32:363821 acc_notification.type = notification;
[email protected]54ec7f82010-10-21 22:32:513822 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:483823 return;
3824
[email protected]fffaf972011-03-24 01:34:353825 ViewHostMsg_AccessibilityNotification_Type::Value temp;
[email protected]a527a022011-02-10 02:32:363826 if (!WebAccessibilityNotificationToViewHostMsg(notification, &temp))
[email protected]54ec7f82010-10-21 22:32:513827 return;
[email protected]54ec7f82010-10-21 22:32:513828
3829 // Discard duplicate accessibility notifications.
3830 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
3831 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
3832 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:423833 return;
[email protected]54ec7f82010-10-21 22:32:513834 }
[email protected]9892b472010-09-16 00:23:423835 }
[email protected]54ec7f82010-10-21 22:32:513836 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:483837
[email protected]54ec7f82010-10-21 22:32:513838 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
3839 // When no accessibility notifications are in-flight post a task to send
3840 // the notifications to the browser. We use PostTask so that we can queue
3841 // up additional notifications.
3842 MessageLoop::current()->PostTask(
3843 FROM_HERE,
3844 accessibility_method_factory_.NewRunnableMethod(
3845 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:313846 }
[email protected]520cb7d72010-08-31 11:54:313847}
3848
[email protected]446705872009-09-10 07:22:483849void RenderView::OnSetEditCommandsForNextKeyEvent(
3850 const EditCommands& edit_commands) {
3851 edit_commands_ = edit_commands;
3852}
3853
[email protected]60c42a8c72009-10-09 04:08:593854void RenderView::Close() {
3855 // We need to grab a pointer to the doomed WebView before we destroy it.
3856 WebView* doomed = webview();
3857 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:493858 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:593859}
3860
[email protected]446705872009-09-10 07:22:483861void RenderView::DidHandleKeyEvent() {
3862 edit_commands_.clear();
3863}
3864
[email protected]6a8ddba52010-09-05 04:38:063865void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:513866 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:063867}
3868
[email protected]941e4552010-02-01 21:23:433869void RenderView::OnWasHidden() {
3870 RenderWidget::OnWasHidden();
3871
[email protected]a6939ca42011-02-18 17:58:073872 if (webview()) {
3873 webview()->settings()->setMinimumTimerInterval(
3874 webkit_glue::kBackgroundTabTimerInterval);
3875 }
3876
3877#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:433878 // Inform plugins that their container is no longer visible.
3879 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3880 for (plugin_it = plugin_delegates_.begin();
3881 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3882 (*plugin_it)->SetContainerVisibility(false);
3883 }
[email protected]a6939ca42011-02-18 17:58:073884#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:433885}
3886
3887void RenderView::OnWasRestored(bool needs_repainting) {
3888 RenderWidget::OnWasRestored(needs_repainting);
3889
[email protected]a6939ca42011-02-18 17:58:073890 if (webview()) {
3891 webview()->settings()->setMinimumTimerInterval(
3892 webkit_glue::kForegroundTabTimerInterval);
3893 }
3894
3895#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:433896 // Inform plugins that their container is now visible.
3897 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3898 for (plugin_it = plugin_delegates_.begin();
3899 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3900 (*plugin_it)->SetContainerVisibility(true);
3901 }
[email protected]784ea1ab2010-09-18 00:02:343902#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:073903}
[email protected]1e6e3c992010-02-08 15:52:133904
[email protected]65225772011-05-12 21:10:243905bool RenderView::SupportsAsynchronousSwapBuffers() {
3906 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
3907 if (!context)
3908 return false;
3909 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
3910 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
3911 std::string::npos;
3912}
3913
[email protected]1e6e3c992010-02-08 15:52:133914void RenderView::OnSetFocus(bool enable) {
3915 RenderWidget::OnSetFocus(enable);
3916
[email protected]7d3c02c2010-05-05 23:10:313917 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:073918 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:133919 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3920 for (plugin_it = plugin_delegates_.begin();
3921 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:343922#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:313923 // RenderWidget's call to setFocus can cause the underlying webview's
3924 // activation state to change just like a call to setIsActive.
3925 if (enable)
3926 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:343927#endif
[email protected]7d3c02c2010-05-05 23:10:313928 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:133929 }
[email protected]589621b2010-09-23 22:01:073930
3931 // Notify all Pepper plugins.
3932 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:133933 }
3934}
[email protected]941e4552010-02-01 21:23:433935
[email protected]43f28f832010-02-03 02:28:483936#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:133937void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
3938 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
3939 focused, plugin_id);
3940 Send(msg);
3941}
3942
3943void RenderView::StartPluginIme() {
3944 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:553945 // This message can be sent during event-handling, and needs to be delivered
3946 // within that context.
3947 msg->set_unblock(true);
3948 Send(msg);
3949}
3950
[email protected]ea04a4e12010-04-15 00:58:033951gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:233952 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:483953 gfx::PluginWindowHandle window = NULL;
3954 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:233955 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:113956 if (window) {
3957 fake_plugin_window_handles_.insert(window);
3958 }
[email protected]43f28f832010-02-03 02:28:483959 return window;
3960}
3961
3962void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:113963 if (window && fake_plugin_window_handles_.find(window) !=
3964 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:483965 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:113966 fake_plugin_window_handles_.erase(window);
3967 }
[email protected]43f28f832010-02-03 02:28:483968}
3969
[email protected]44ce0b12010-03-12 16:45:333970void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
3971 int32 width,
3972 int32 height,
3973 uint64 io_surface_identifier) {
3974 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:483975 routing_id(), window, width, height, io_surface_identifier));
3976}
3977
[email protected]44ce0b12010-03-12 16:45:333978void RenderView::AcceleratedSurfaceSetTransportDIB(
3979 gfx::PluginWindowHandle window,
3980 int32 width,
3981 int32 height,
3982 TransportDIB::Handle transport_dib) {
3983 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:073984 routing_id(), window, width, height, transport_dib));
3985}
3986
[email protected]44ce0b12010-03-12 16:45:333987TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
3988 size_t size) {
[email protected]1aef98132010-02-23 18:00:073989 TransportDIB::Handle dib_handle;
3990 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:383991 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:073992 return dib_handle;
3993 // Return an invalid handle if Send() fails.
3994 return TransportDIB::DefaultHandleValue();
3995}
3996
[email protected]44ce0b12010-03-12 16:45:333997void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:073998 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
3999}
4000
[email protected]44ce0b12010-03-12 16:45:334001void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144002 gfx::PluginWindowHandle window, uint64 surface_id) {
4003 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4004 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484005}
4006#endif
[email protected]58c321d2010-02-19 12:11:284007
[email protected]cdaf8d02010-03-30 19:52:474008bool RenderView::ScheduleFileChooser(
4009 const ViewHostMsg_RunFileChooser_Params& params,
4010 WebFileChooserCompletion* completion) {
4011 static const size_t kMaximumPendingFileChooseRequests = 4;
4012 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4013 // This sanity check prevents too many file choose requests from getting
4014 // queued which could DoS the user. Getting these is most likely a
4015 // programming error (there are many ways to DoS the user so it's not
4016 // considered a "real" security check), either in JS requesting many file
4017 // choosers to pop up, or in a plugin.
4018 //
4019 // TODO(brettw) we might possibly want to require a user gesture to open
4020 // a file picker, which will address this issue in a better way.
4021 return false;
4022 }
4023
4024 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4025 new PendingFileChooser(params, completion)));
4026 if (file_chooser_completions_.size() == 1) {
4027 // Actually show the browse dialog when this is the first request.
4028 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4029 }
4030 return true;
4031}
4032
[email protected]0ff0ff32010-12-21 19:34:424033WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514034 if (!geolocation_dispatcher_)
4035 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4036 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254037}
[email protected]61c9f032010-03-31 23:04:194038
[email protected]638694c2010-08-04 22:24:114039WebKit::WebSpeechInputController* RenderView::speechInputController(
4040 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:514041 if (!speech_input_dispatcher_)
4042 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
4043 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114044}
4045
[email protected]57ead352010-08-11 14:42:534046WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514047 if (!device_orientation_dispatcher_)
4048 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4049 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534050}
4051
[email protected]b75b8292010-10-01 07:28:254052void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
4053 // For now, don't remember plugin zoom values. We don't want to mix them with
4054 // normal web content (i.e. a fixed layout plugin would usually want them
4055 // different).
4056 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4057
[email protected]b75b8292010-10-01 07:28:254058 int minimum_percent = static_cast<int>(
4059 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4060 int maximum_percent = static_cast<int>(
4061 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254062
4063 Send(new ViewHostMsg_UpdateZoomLimits(
4064 routing_id_, minimum_percent, maximum_percent, remember));
4065}
4066
4067void RenderView::zoomLevelChanged() {
4068 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4069
[email protected]b75b8292010-10-01 07:28:254070 // Tell the browser which url got zoomed so it can update the menu and the
4071 // saved values if necessary
4072 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:414073 routing_id_, webview()->zoomLevel(), remember,
4074 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:254075}
4076
[email protected]a6d36cc2011-02-23 00:39:484077void RenderView::registerProtocolHandler(const WebString& scheme,
4078 const WebString& base_url,
4079 const WebString& url,
4080 const WebString& title) {
4081 GURL base(base_url);
4082 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4083 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4084 return;
4085 }
4086 RenderThread::current()->Send(
4087 new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4088 UTF16ToUTF8(scheme),
4089 absolute_url,
4090 title));
4091}
4092
[email protected]8079b362010-05-07 18:37:454093bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194094 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454095 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194096 if (frame->parent() != NULL)
4097 return false;
4098
[email protected]f0a3d0b2010-08-06 22:51:534099 // Navigations initiated within Webkit are not sent out to the external host
4100 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274101 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134102 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534103 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134104 // 3. Reloads/form submits/back forward navigations
[email protected]f0a3d0b2010-08-06 22:51:534105 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
4106 return false;
4107
[email protected]2fc22d12010-12-02 23:08:164108 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324109 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014110 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164111 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014112 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324113 // The opener relationship between the new window and the parent allows the
4114 // new window to script the parent and vice versa. This is not allowed if
4115 // the origins of the two domains are different. This can be treated as a
4116 // top level navigation and routed back to the host.
4117 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274118 if (!opener) {
[email protected]86965362011-04-21 18:42:514119 return true;
[email protected]d19ea342011-04-20 20:31:134120 } else {
4121 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324122 return true;
4123 }
4124 }
[email protected]61c9f032010-03-31 23:04:194125 return false;
4126}
[email protected]2b06a992010-08-21 05:48:224127
[email protected]27a9ef32010-09-10 04:06:244128void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
4129 IPC::PlatformFileForTransit file_for_transit,
4130 int message_id) {
4131 pepper_delegate_.OnAsyncFileOpened(
4132 error_code,
4133 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4134 message_id);
4135}
[email protected]caf706f2010-10-26 17:54:084136
[email protected]2b657fd2011-04-18 16:00:474137void RenderView::OnPpapiBrokerChannelCreated(
4138 int request_id,
4139 base::ProcessHandle broker_process_handle,
4140 IPC::ChannelHandle handle) {
4141 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4142 broker_process_handle,
4143 handle);
[email protected]eb415bf0e2011-04-14 02:45:424144}
4145
[email protected]caf706f2010-10-26 17:54:084146#if defined(OS_MACOSX)
4147void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154148 if (external_popup_menu_ == NULL) {
4149 // Crash reports from the field indicate that we can be notified with a
4150 // NULL external popup menu (we probably get notified twice).
4151 // If you hit this please file a bug against jcivelli and include the page
4152 // and steps to repro.
4153 NOTREACHED();
4154 return;
4155 }
[email protected]caf706f2010-10-26 17:54:084156 external_popup_menu_->DidSelectItem(selected_index);
4157 external_popup_menu_.reset();
4158}
4159#endif
[email protected]bb461532010-11-26 21:50:234160
[email protected]1b4209f2011-01-07 00:25:404161#if defined(ENABLE_FLAPPER_HACKS)
4162void RenderView::OnConnectTcpACK(
4163 int request_id,
4164 IPC::PlatformFileForTransit socket_for_transit,
4165 const PP_Flash_NetAddress& local_addr,
4166 const PP_Flash_NetAddress& remote_addr) {
4167 pepper_delegate_.OnConnectTcpACK(
4168 request_id,
4169 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4170 local_addr,
4171 remote_addr);
4172}
4173#endif
[email protected]a6097f42011-01-10 08:50:514174
[email protected]b29aa74b2011-01-31 21:41:084175void RenderView::OnContextMenuClosed(
4176 const webkit_glue::CustomContextMenuContext& custom_context) {
4177 if (custom_context.is_pepper_menu)
4178 pepper_delegate_.OnContextMenuClosed(custom_context);
4179 else
4180 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104181}
[email protected]232a5812011-03-04 22:42:084182
4183void RenderView::OnNetworkStateChanged(bool online) {
4184 WebNetworkStateNotifier::setOnLine(online);
4185}