blob: 012594724e5e9c40e78a31a48657a470a5eb1e6d [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]c27ae592010-03-18 15:24:41186using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50187using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17188using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28189using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17190using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28191using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28192using WebKit::WebNavigationType;
[email protected]232a5812011-03-04 22:42:08193using WebKit::WebNetworkStateNotifier;
[email protected]79dbc662009-09-04 05:42:51194using WebKit::WebNode;
[email protected]3d9689372009-09-10 04:29:17195using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40196using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49197using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09198using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52199using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59200using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51201using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52202using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40203using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35204using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29205using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17206using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59207using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42208using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02209using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34210using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40211using WebKit::WebStorageQuotaCallbacks;
212using WebKit::WebStorageQuotaError;
213using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28214using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51215using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52216using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28217using WebKit::WebURL;
218using WebKit::WebURLError;
219using WebKit::WebURLRequest;
220using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28221using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03222using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28223using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26224using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43225using WebKit::WebWorker;
226using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26227using appcache::WebApplicationCacheHostImpl;
228using base::Time;
229using base::TimeDelta;
230using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26231using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26232using webkit_glue::PasswordForm;
233using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23234using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26235using webkit_glue::SiteIsolationMetrics;
236using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33237
initial.commit09911bf2008-07-26 23:55:29238//-----------------------------------------------------------------------------
239
[email protected]3354d3e2010-06-10 19:53:02240typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49241static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02242
[email protected]882daa92009-11-05 16:31:31243// Time, in seconds, we delay before sending content state changes (such as form
244// state and scroll position) to the browser. We delay sending changes to avoid
245// spamming the browser.
246// To avoid having tab/session restore require sending a message to get the
247// current content state during tab closing we use a shorter timeout for the
248// foreground renderer. This means there is a small window of time from which
249// content state is modified and not sent to session restore, but this is
250// better than having to wake up all renderers during shutdown.
251static const int kDelaySecondsForContentStateSyncHidden = 5;
252static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29253
[email protected]0aa55312008-10-17 21:53:08254// The maximum number of popups that can be spawned from one page.
255static const int kMaximumNumberOfUnacknowledgedPopups = 25;
256
[email protected]6fdd4182010-10-14 23:59:26257static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35258
[email protected]726985e22009-06-18 21:09:28259static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
260 WebVector<WebURL> urls;
261 ds->redirectChain(urls);
262 result->reserve(urls.size());
263 for (size_t i = 0; i < urls.size(); ++i)
264 result->push_back(urls[i]);
265}
266
[email protected]54ec7f82010-10-21 22:32:51267static bool WebAccessibilityNotificationToViewHostMsg(
268 WebAccessibilityNotification notification,
[email protected]fffaf972011-03-24 01:34:35269 ViewHostMsg_AccessibilityNotification_Type::Value* type) {
[email protected]54ec7f82010-10-21 22:32:51270 switch (notification) {
271 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
[email protected]fffaf972011-03-24 01:34:35272 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51273 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
274 break;
275 case WebKit::WebAccessibilityNotificationChildrenChanged:
[email protected]fffaf972011-03-24 01:34:35276 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51277 NOTIFICATION_TYPE_CHILDREN_CHANGED;
278 break;
279 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
[email protected]fffaf972011-03-24 01:34:35280 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51281 NOTIFICATION_TYPE_FOCUS_CHANGED;
282 break;
283 case WebKit::WebAccessibilityNotificationLoadComplete:
[email protected]fffaf972011-03-24 01:34:35284 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51285 NOTIFICATION_TYPE_LOAD_COMPLETE;
286 break;
287 case WebKit::WebAccessibilityNotificationValueChanged:
[email protected]fffaf972011-03-24 01:34:35288 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51289 NOTIFICATION_TYPE_VALUE_CHANGED;
290 break;
291 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
[email protected]fffaf972011-03-24 01:34:35292 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51293 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
294 break;
295 default:
296 // TODO(ctguil): Support additional webkit notifications.
297 return false;
298 }
299 return true;
300}
301
[email protected]6a8f5112011-05-13 16:38:44302// If |data_source| is non-null and has a NavigationState associated with it,
303// the AltErrorPageResourceFetcher is reset.
304static void StopAltErrorPageFetcher(WebDataSource* data_source) {
305 if (data_source) {
306 NavigationState* state = NavigationState::FromDataSource(data_source);
307 if (state)
308 state->set_alt_error_page_fetcher(NULL);
309 }
310}
311
initial.commit09911bf2008-07-26 23:55:29312///////////////////////////////////////////////////////////////////////////////
313
[email protected]60c42a8c72009-10-09 04:08:59314int32 RenderView::next_page_id_ = 1;
315
[email protected]cdaf8d02010-03-30 19:52:47316struct RenderView::PendingFileChooser {
317 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
318 WebFileChooserCompletion* c)
319 : params(p),
320 completion(c) {
321 }
322 ViewHostMsg_RunFileChooser_Params params;
323 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
324};
325
[email protected]2fab253a2009-08-17 23:00:59326RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51327 gfx::NativeViewId parent_hwnd,
[email protected]c03a6e72011-04-19 21:42:06328 gfx::PluginWindowHandle compositing_surface,
[email protected]676126f72011-01-15 00:03:51329 int32 opener_id,
330 const RendererPreferences& renderer_prefs,
331 const WebPreferences& webkit_prefs,
332 SharedRenderViewCounter* counter,
333 int32 routing_id,
334 int64 session_storage_namespace_id,
335 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12336 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51337 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02338 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09339 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02340 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24341 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21342 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02343 opened_by_user_gesture_(true),
344 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24345 page_id_(-1),
346 last_page_id_sent_to_browser_(-1),
[email protected]3cc72b12010-03-18 23:03:00347 history_list_offset_(-1),
348 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24349 has_unload_listener_(false),
[email protected]3354d3e2010-06-10 19:53:02350 target_url_status_(TARGET_NONE),
[email protected]18ca9a6b2010-06-02 19:05:18351 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]54ec7f82010-10-21 22:32:51352 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02353 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51354 geolocation_dispatcher_(NULL),
355 speech_input_dispatcher_(NULL),
356 device_orientation_dispatcher_(NULL),
[email protected]54ec7f82010-10-21 22:32:51357 accessibility_ack_pending_(false),
[email protected]cae8c8492011-03-03 11:12:18358 p2p_socket_dispatcher_(NULL),
[email protected]5ee0cfd02011-01-18 05:42:22359 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]676126f72011-01-15 00:03:51360 routing_id_ = routing_id;
361 if (opener_id != MSG_ROUTING_NONE)
362 opener_id_ = opener_id;
363
[email protected]11fee2332011-03-29 20:36:35364 webwidget_ = WebView::create(this);
365
[email protected]676126f72011-01-15 00:03:51366 if (counter) {
367 shared_popup_counter_ = counter;
368 shared_popup_counter_->data++;
369 decrement_shared_popup_at_destruction_ = true;
370 } else {
371 shared_popup_counter_ = new SharedRenderViewCounter(0);
372 decrement_shared_popup_at_destruction_ = false;
373 }
374
375 notification_provider_ = new NotificationProvider(this);
376
[email protected]676126f72011-01-15 00:03:51377 render_thread_->AddRoute(routing_id_, this);
378 // Take a reference on behalf of the RenderThread. This will be balanced
379 // when we receive ViewMsg_Close.
380 AddRef();
381
382 // If this is a popup, we must wait for the CreatingNew_ACK message before
383 // completing initialization. Otherwise, we can finish it now.
384 if (opener_id == MSG_ROUTING_NONE) {
385 did_show_ = true;
[email protected]c03a6e72011-04-19 21:42:06386 CompleteInit(parent_hwnd, compositing_surface);
[email protected]676126f72011-01-15 00:03:51387 }
388
[email protected]34c61bd52011-05-02 19:38:33389 g_view_map.Get().insert(std::make_pair(webview(), this));
390 webkit_preferences_.Apply(webview());
391 webview()->initializeMainFrame(this);
392 if (!frame_name.empty())
393 webview()->mainFrame()->setName(frame_name);
394 webview()->settings()->setMinimumTimerInterval(
395 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
396 webkit_glue::kForegroundTabTimerInterval);
397
398 OnSetRendererPrefs(renderer_prefs);
399
[email protected]676126f72011-01-15 00:03:51400 host_window_ = parent_hwnd;
401
402 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]676126f72011-01-15 00:03:51403 if (command_line.HasSwitch(switches::kEnableAccessibility))
404 WebAccessibilityCache::enableAccessibility();
405
406 audio_message_filter_ = new AudioMessageFilter(routing_id_);
407 render_thread_->AddFilter(audio_message_filter_);
408
[email protected]a026daa2011-04-20 15:49:51409#if defined(ENABLE_P2P_APIS)
[email protected]9966325b2011-04-18 05:00:10410 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableP2PApi))
[email protected]cae8c8492011-03-03 11:12:18411 p2p_socket_dispatcher_ = new P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51412#endif
[email protected]cae8c8492011-03-03 11:12:18413
[email protected]e48869a2011-04-01 19:56:03414 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29415}
416
417RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08418 if (decrement_shared_popup_at_destruction_)
419 shared_popup_counter_->data--;
420
[email protected]a1128322009-10-06 18:38:46421 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47422 while (!file_chooser_completions_.empty()) {
423 if (file_chooser_completions_.front()->completion) {
424 file_chooser_completions_.front()->completion->didChooseFile(
425 WebVector<WebString>());
426 }
427 file_chooser_completions_.pop_front();
428 }
[email protected]a1128322009-10-06 18:38:46429
[email protected]83dde542009-09-11 20:59:55430#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11431 // Destroy all fake plugin window handles on the browser side.
432 while (!fake_plugin_window_handles_.empty()) {
433 // Make sure no NULL plugin window handles were inserted into this list.
434 DCHECK(*fake_plugin_window_handles_.begin());
435 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
436 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
437 }
[email protected]83dde542009-09-11 20:59:55438#endif
[email protected]98324892009-09-09 21:16:05439
[email protected]5fb88962009-04-16 19:03:25440 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59441
442#ifndef NDEBUG
443 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49444 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59445 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
446 DCHECK_NE(this, it->second) << "Failed to call Close?";
447#endif
[email protected]676126f72011-01-15 00:03:51448
449 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
450 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59451}
452
453/*static*/
454void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49455 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59456 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
457 if (!visitor->Visit(it->second))
458 return;
459 }
460}
461
462/*static*/
463RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49464 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59465 ViewMap::iterator it = views->find(webview);
466 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29467}
468
469/*static*/
[email protected]0aa55312008-10-17 21:53:08470RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24471 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15472 gfx::NativeViewId parent_hwnd,
[email protected]c03a6e72011-04-19 21:42:06473 gfx::PluginWindowHandle compositing_surface,
[email protected]0aa55312008-10-17 21:53:08474 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51475 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08476 const WebPreferences& webkit_prefs,
477 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34478 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26479 int64 session_storage_namespace_id,
480 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29481 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51482 return new RenderView(
483 render_thread,
484 parent_hwnd,
[email protected]c03a6e72011-04-19 21:42:06485 compositing_surface,
[email protected]676126f72011-01-15 00:03:51486 opener_id,
487 renderer_prefs,
488 webkit_prefs,
489 counter,
490 routing_id,
491 session_storage_namespace_id,
492 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29493}
494
[email protected]bb461532010-11-26 21:50:23495// static
initial.commit09911bf2008-07-26 23:55:29496void RenderView::SetNextPageID(int32 next_page_id) {
497 // This method should only be called during process startup, and the given
498 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05499 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29500 DCHECK(next_page_id >= next_page_id_);
501 next_page_id_ = next_page_id;
502}
503
[email protected]676126f72011-01-15 00:03:51504void RenderView::AddObserver(RenderViewObserver* observer) {
505 observers_.AddObserver(observer);
506}
507
508void RenderView::RemoveObserver(RenderViewObserver* observer) {
509 observer->set_render_view(NULL);
510 observers_.RemoveObserver(observer);
511}
512
[email protected]70eee342010-11-05 01:59:37513bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
514 typedef ViewHostMsg_AccessibilityNotification_Params params;
[email protected]a527a022011-02-10 02:32:36515 if (type == WebKit::WebAccessibilityNotificationChildrenChanged ||
516 type == WebKit::WebAccessibilityNotificationLoadComplete) {
[email protected]70eee342010-11-05 01:59:37517 return true;
518 }
519 return false;
520}
521
[email protected]8a3125a712010-08-09 18:58:51522WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26523 return static_cast<WebKit::WebView*>(webwidget());
524}
525
[email protected]1a3c3cb2010-12-16 21:03:40526void RenderView::SetReportLoadProgressEnabled(bool enabled) {
527 if (!enabled) {
528 load_progress_tracker_.reset(NULL);
529 return;
530 }
531 if (load_progress_tracker_ == NULL)
532 load_progress_tracker_.reset(new LoadProgressTracker(this));
533}
534
[email protected]a3a8fb6d2009-10-22 20:12:51535void RenderView::PluginCrashed(const FilePath& plugin_path) {
536 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29537}
538
[email protected]aad51d1c2010-08-05 08:38:09539WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
540 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50541 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26542 bool found;
[email protected]6fdd4182010-10-14 23:59:26543 std::string mime_type;
544 Send(new ViewHostMsg_GetPluginInfo(
[email protected]c8f73ab2011-01-22 00:05:17545 routing_id_, params.url, frame->top()->url(), params.mimeType.utf8(),
[email protected]8093a542011-05-13 07:29:32546 &found, &info, &mime_type));
[email protected]b83ff222011-01-24 17:37:12547 if (!found || !webkit::npapi::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09548 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45549
[email protected]96dcc1762011-04-04 16:01:09550 bool pepper_plugin_was_registered = false;
[email protected]0bd753682010-12-16 18:15:52551 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]96dcc1762011-04-04 16:01:09552 pepper_delegate_.CreatePepperPlugin(info.path,
553 &pepper_plugin_was_registered));
554 if (pepper_plugin_was_registered) {
555 if (pepper_module)
556 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
557 return NULL;
558 }
[email protected]1a78d9f32010-12-08 06:38:45559 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09560}
561
[email protected]d8fd6fa2010-02-01 15:54:26562void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
563 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30564 // If the renderer is visible, set initial visibility and focus state.
565 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34566#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30567 delegate->SetContainerVisibility(true);
568 if (webview() && webview()->isActive())
569 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34570#endif
[email protected]49232292010-09-03 19:07:30571 }
[email protected]784ea1ab2010-09-18 00:02:34572 // Plugins start assuming the content has focus (so that they work in
573 // environments where RenderView isn't hosting them), so we always have to
574 // set the initial state. See webplugin_delegate_impl.h for details.
575 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26576}
577
578void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
579 plugin_delegates_.erase(delegate);
580}
[email protected]d8fd6fa2010-02-01 15:54:26581
[email protected]a95986a82010-12-24 06:19:28582bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27583 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27584 if (main_frame)
[email protected]38b592902011-04-16 02:08:42585 content::GetContentClient()->SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26586
[email protected]676126f72011-01-15 00:03:51587 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
588 RenderViewObserver* observer;
589 while ((observer = it.GetNext()) != NULL)
590 if (observer->OnMessageReceived(message))
591 return true;
[email protected]b2abac72009-02-26 12:39:28592
[email protected]a95986a82010-12-24 06:19:28593 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29594 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29595 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
596 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56597 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29598 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
599 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
600 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
601 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27602#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35603 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27604#endif
initial.commit09911bf2008-07-26 23:55:29605 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
606 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
607 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
608 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
609 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15610 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29611 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49612 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
613 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17614 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17615 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:54616 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
617 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29618 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18619 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
620 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29621 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48622 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29623 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55624 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
625 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
626 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
627 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
628 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
629 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
630 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45631 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40632 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29633 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:51634 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
635 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:29636 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
637 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
638 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
639 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]600ea402011-04-12 00:01:51640 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
641 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29642 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04643 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15644 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29645 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
646 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08647 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
648 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00649 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16650 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14651 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25652 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
653 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10654 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
655 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51656 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56657 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34658 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14659#if defined(OS_MACOSX)
660 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13661 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13662 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
663 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14664#endif
[email protected]446705872009-09-10 07:22:48665 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33666 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33667 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
668 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:14669 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:36670 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
671 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
672 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:42673 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
674 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:24675 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42676 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
677 OnPpapiBrokerChannelCreated)
[email protected]caf706f2010-10-26 17:54:08678#if defined(OS_MACOSX)
679 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
680#endif
[email protected]521b2482011-01-15 00:10:10681 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]232a5812011-03-04 22:42:08682 IPC_MESSAGE_HANDLER(ViewMsg_NetworkStateChanged, OnNetworkStateChanged)
[email protected]f0557932011-01-25 20:20:51683 // TODO(viettrungluu): Move to a separate message filter.
684#if defined(ENABLE_FLAPPER_HACKS)
685 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
686#endif
687
initial.commit09911bf2008-07-26 23:55:29688 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28689 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29690 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28691 return handled;
initial.commit09911bf2008-07-26 23:55:29692}
693
initial.commit09911bf2008-07-26 23:55:29694void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
695 if (!webview())
696 return;
697
[email protected]992db4c2011-05-12 15:37:15698 // Swap this renderer back in if necessary.
699 if (is_swapped_out_)
700 SetSwappedOut(false);
701
[email protected]3cc72b12010-03-18 23:03:00702 history_list_offset_ = params.current_history_list_offset;
703 history_list_length_ = params.current_history_list_length;
704
[email protected]38b592902011-04-16 02:08:42705 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29706
[email protected]ecbf10d2010-02-18 13:03:29707 bool is_reload =
[email protected]2c5569662011-03-22 20:45:02708 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
709 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:29710
[email protected]26aa0482009-09-30 16:55:27711 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45712 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29713 // We cannot reload if we do not have any history state. This happens, for
714 // example, when recovering from a crash. Our workaround here is a bit of
715 // a hack since it means that reload after a crashed tab does not cause an
716 // end-to-end cache validation.
717 is_reload = false;
718 }
719
[email protected]77f17a82009-05-21 04:42:54720 // A navigation resulting from loading a javascript URL should not be treated
721 // as a browser initiated event. Instead, we want it to look as if the page
722 // initiated any load resulting from JS execution.
723 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30724 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00725 params.page_id,
726 params.pending_history_list_offset,
727 params.transition,
728 params.request_time);
[email protected]2c5569662011-03-22 20:45:02729 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30730 // We're doing a load of a page that was restored from the last session.
731 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
732 // which can result in stale data for pages that are set to expire. We
733 // explicitly override that by setting the policy here so that as
734 // necessary we load from the network.
735 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
736 }
737 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54738 }
initial.commit09911bf2008-07-26 23:55:29739
[email protected]a7ccc4d2010-01-27 08:14:48740 NavigationState* navigation_state = pending_navigation_state_.get();
741
[email protected]48a5c772011-04-18 23:50:50742 if (navigation_state) {
743 // New loads need to reset the error page fetcher. Otherwise if there is an
744 // outstanding error page fetcher it may complete and clobber the current
745 // page load.
746 navigation_state->set_alt_error_page_fetcher(NULL);
747 }
748
[email protected]04d3c6e2009-05-22 17:00:13749 // If we are reloading, then WebKit will use the history state of the current
750 // page, so we should just ignore any given history state. Otherwise, if we
751 // have history state, then we need to navigate to it, which corresponds to a
752 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55753 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48754 if (navigation_state)
755 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29756 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02757 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29758 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55759 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13760 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58761 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48762 if (navigation_state)
763 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45764 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17765 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13766 } else {
767 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28768 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29769
[email protected]e6f546c32009-07-01 17:12:55770 // A session history navigation should have been accompanied by state.
771 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13772
[email protected]dd7daa82009-08-10 05:46:45773 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55774 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13775
[email protected]726985e22009-06-18 21:09:28776 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17777 if (!WebSecurityPolicy::shouldHideReferrer(
778 params.url,
779 WebString::fromUTF8(params.referrer.spec()))) {
780 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
781 WebString::fromUTF8(params.referrer.spec()));
782 }
[email protected]726985e22009-06-18 21:09:28783 }
[email protected]04d3c6e2009-05-22 17:00:13784
[email protected]52c68652010-12-07 17:47:04785 if (!params.extra_headers.empty()) {
786 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
787 params.extra_headers.end(), "\n");
788 i.GetNext(); ) {
789 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
790 WebString::fromUTF8(i.values()));
791 }
792 }
793
[email protected]16e923d2011-04-30 00:41:44794 if (navigation_state)
795 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45796 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50797 }
798
[email protected]77f17a82009-05-21 04:42:54799 // In case LoadRequest failed before DidCreateDataSource was called.
800 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29801}
802
803// Stop loading the current page
804void RenderView::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44805 if (webview()) {
806 WebFrame* main_frame = webview()->mainFrame();
807 // Stop the alt error page fetcher. If we let it continue it may complete
808 // and cause RenderViewHostManager to swap to this RenderView, even though
809 // it may no longer be active.
810 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
811 StopAltErrorPageFetcher(main_frame->dataSource());
812 main_frame->stopLoading();
813 }
initial.commit09911bf2008-07-26 23:55:29814}
815
[email protected]ecbf10d2010-02-18 13:03:29816// Reload current focused frame.
817// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56818void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29819 if (webview() && webview()->focusedFrame()) {
820 // We always obey the cache (ignore_cache=false) here.
821 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
822 // a cache-ignoring reload of the frame.
823 webview()->focusedFrame()->reload(false);
824 }
[email protected]1dda4022010-01-28 18:24:56825}
826
initial.commit09911bf2008-07-26 23:55:29827void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27828 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29829}
830
[email protected]68b1e922009-06-23 16:00:25831void RenderView::OnExecuteEditCommand(const std::string& name,
832 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27833 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25834 return;
835
[email protected]26aa0482009-09-30 16:55:27836 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45837 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25838}
839
initial.commit09911bf2008-07-26 23:55:29840void RenderView::OnUpdateTargetURLAck() {
841 // Check if there is a targeturl waiting to be sent.
842 if (target_url_status_ == TARGET_PENDING) {
843 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
844 pending_target_url_));
845 }
846
847 target_url_status_ = TARGET_NONE;
848}
849
850void RenderView::OnUndo() {
851 if (!webview())
852 return;
853
[email protected]26aa0482009-09-30 16:55:27854 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29855}
856
857void RenderView::OnRedo() {
858 if (!webview())
859 return;
860
[email protected]26aa0482009-09-30 16:55:27861 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29862}
863
864void RenderView::OnCut() {
865 if (!webview())
866 return;
867
[email protected]26aa0482009-09-30 16:55:27868 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29869}
870
871void RenderView::OnCopy() {
872 if (!webview())
873 return;
874
[email protected]26aa0482009-09-30 16:55:27875 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
initial.commit09911bf2008-07-26 23:55:29876}
877
[email protected]c0cc3092009-09-12 08:27:27878#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35879void RenderView::OnCopyToFindPboard() {
880 if (!webview())
881 return;
882
883 // Since the find pasteboard supports only plain text, this can be simpler
884 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27885 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35886 if (frame->hasSelection()) {
887 string16 selection = frame->selectionAsText();
888 RenderThread::current()->Send(
[email protected]7e3589742011-03-10 18:49:17889 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35890 }
[email protected]a954bf72009-09-12 07:30:35891}
[email protected]c0cc3092009-09-12 08:27:27892#endif
[email protected]a954bf72009-09-12 07:30:35893
initial.commit09911bf2008-07-26 23:55:29894void RenderView::OnPaste() {
895 if (!webview())
896 return;
897
[email protected]26aa0482009-09-30 16:55:27898 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29899}
900
[email protected]2a3a7762009-10-19 19:17:32901void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29902 if (!webview())
903 return;
904
[email protected]1ff7a032010-02-03 02:46:03905 WebFrame* frame = webview()->focusedFrame();
906 if (!frame->hasSelection())
907 frame->selectWordAroundCaret();
908 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29909}
910
911void RenderView::OnDelete() {
912 if (!webview())
913 return;
914
[email protected]26aa0482009-09-30 16:55:27915 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29916}
917
918void RenderView::OnSelectAll() {
919 if (!webview())
920 return;
921
[email protected]26aa0482009-09-30 16:55:27922 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22923 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29924}
925
926void RenderView::OnSetInitialFocus(bool reverse) {
927 if (!webview())
928 return;
[email protected]26aa0482009-09-30 16:55:27929 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29930}
931
[email protected]9b66f34bf2010-10-27 20:45:51932void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:09933 WebKit::WebNode node = GetFocusedNode();
934 if (!node.isNull()) {
935 if (IsEditableNode(node))
936 // TODO(varunjain): Change webkit API to scroll a particular node into
937 // view and use that API here instead.
938 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:51939 }
940}
941
initial.commit09911bf2008-07-26 23:55:29942///////////////////////////////////////////////////////////////////////////////
943
944// Tell the embedding application that the URL of the active page has changed
945void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:45946 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:29947 DCHECK(ds);
948
[email protected]726985e22009-06-18 21:09:28949 const WebURLRequest& request = ds->request();
950 const WebURLRequest& original_request = ds->originalRequest();
951 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:29952
[email protected]daa8c58e2009-06-15 17:21:10953 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
954 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:29955
956 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:28957 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:29958 params.is_post = false;
959 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:07960 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:19961 params.socket_address.set_host(response.remoteIPAddress().utf8());
962 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:03963 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:09964 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:55965 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:29966 // SSL state specified in the request takes precedence over the one in the
967 // response.
968 // So far this is only intended for error pages that are not expected to be
969 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:28970 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:55971 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:29972 } else {
[email protected]726985e22009-06-18 21:09:28973 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:29974 }
975
976 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:28977 if (ds->hasUnreachableURL()) {
978 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:29979 } else {
[email protected]726985e22009-06-18 21:09:28980 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:29981 }
982
[email protected]726985e22009-06-18 21:09:28983 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:24984 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:04985 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:29986
[email protected]ce0e250d2009-10-23 21:00:35987 params.searchable_form_url = navigation_state->searchable_form_url();
988 params.searchable_form_encoding =
989 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:29990
991 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:10992 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:29993 if (password_form_data)
994 params.password_form = *password_form_data;
995
996 params.gesture = navigation_gesture_;
997 navigation_gesture_ = NavigationGestureUnknown;
998
[email protected]0f38dc4552011-02-25 11:24:00999 // Make navigation state a part of the FrameNavigate message so that commited
1000 // entry had it at all times.
1001 const WebHistoryItem& item = frame->currentHistoryItem();
1002 if (!item.isNull()) {
1003 params.content_state = webkit_glue::HistoryItemToString(item);
1004 } else {
1005 params.content_state =
1006 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1007 }
1008
[email protected]dd7daa82009-08-10 05:46:451009 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291010 // Top-level navigation.
1011
[email protected]b75b8292010-10-01 07:28:251012 // Set zoom level, but don't do it for full-page plugin since they don't use
1013 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011014 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541015 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251016 if (webview()->mainFrame()->document().isPluginDocument()) {
1017 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251018 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251019 } else {
1020 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251021 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251022 }
1023
[email protected]f85f0702010-01-30 09:31:011024 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511025 // This zoom level was merely recorded transiently for this load. We can
1026 // erase it now. If at some point we reload this page, the browser will
1027 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011028 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511029 }
1030
[email protected]b75b8292010-10-01 07:28:251031 // Reset the zoom limits in case a plugin had changed them previously. This
1032 // will also call us back which will cause us to send a message to
1033 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251034 webview()->zoomLimitsChanged(
1035 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1036 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251037
initial.commit09911bf2008-07-26 23:55:291038 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551039 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291040
[email protected]daa8c58e2009-06-15 17:21:101041 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291042 if (!PageTransition::IsMainFrame(params.transition)) {
1043 // If the main frame does a load, it should not be reported as a subframe
1044 // navigation. This can occur in the following case:
1045 // 1. You're on a site with frames.
1046 // 2. You do a subframe navigation. This is stored with transition type
1047 // MANUAL_SUBFRAME.
1048 // 3. You navigate to some non-frame site, say, google.com.
1049 // 4. You navigate back to the page from step 2. Since it was initially
1050 // MANUAL_SUBFRAME, it will be that same transition type here.
1051 // We don't want that, because any navigation that changes the toplevel
1052 // frame should be tracked as a toplevel navigation (this allows us to
1053 // update the URL bar, etc).
1054 params.transition = PageTransition::LINK;
1055 }
1056
initial.commit09911bf2008-07-26 23:55:291057 // If we have a valid consumed client redirect source,
1058 // the page contained a client redirect (meta refresh, document.loc...),
1059 // so we set the referrer and transition to match.
1060 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041061 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291062 params.referrer = completed_client_redirect_src_;
1063 params.transition = static_cast<PageTransition::Type>(
1064 params.transition | PageTransition::CLIENT_REDIRECT);
1065 } else {
1066 // Bug 654101: the referrer will be empty on https->http transitions. It
1067 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281068 params.referrer = GURL(
1069 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291070 }
1071
[email protected]726985e22009-06-18 21:09:281072 string16 method = request.httpMethod();
1073 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291074 params.is_post = true;
1075
[email protected]c2a797d2009-09-21 16:46:321076 // Save some histogram data so we can compute the average memory used per
1077 // page load of the glyphs.
1078 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1079 webkit_glue::GetGlyphPageCount());
1080
[email protected]15cf526b2010-02-12 06:33:491081 // This message needs to be sent before any of allowScripts(),
1082 // allowImages(), allowPlugins() is called for the new page, so that when
1083 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1084 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291085 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1086 } else {
1087 // Subframe navigation: the type depends on whether this navigation
1088 // generated a new session history entry. When they do generate a session
1089 // history entry, it means the user initiated the navigation and we should
1090 // mark it as such. This test checks if this is the first time UpdateURL
1091 // has been called since WillNavigateToURL was called to initiate the load.
1092 if (page_id_ > last_page_id_sent_to_browser_)
1093 params.transition = PageTransition::MANUAL_SUBFRAME;
1094 else
1095 params.transition = PageTransition::AUTO_SUBFRAME;
1096
initial.commit09911bf2008-07-26 23:55:291097 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1098 }
1099
1100 last_page_id_sent_to_browser_ =
1101 std::max(last_page_id_sent_to_browser_, page_id_);
1102
1103 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101104 // we don't want the transition type to persist. Just clear it.
1105 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501106
[email protected]af15bed2010-08-25 21:12:091107 // Check if the navigation was within the same page, in which case we don't
1108 // want to clear the accessibility cache.
1109 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351110 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141111 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501112 }
initial.commit09911bf2008-07-26 23:55:291113}
1114
1115// Tell the embedding application that the title of the active page has changed
[email protected]6b2f7a82011-04-25 19:30:511116void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291117 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171118 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171119 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171120 routing_id_,
1121 page_id_,
[email protected]6b2f7a82011-04-25 19:30:511122 UTF16ToWideHack(title.length() > content::kMaxTitleChars ?
1123 title.substr(0, content::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171124 }
initial.commit09911bf2008-07-26 23:55:291125}
1126
1127void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401128 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291129 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271130 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291131 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301132 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291133 last_encoding_name_ = encoding_name;
1134
[email protected]e38f40152008-09-12 23:08:301135 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291136 }
1137}
1138
[email protected]e15f680732010-11-23 22:30:201139// Sends the last committed session history state to the browser so it will be
1140// saved before we navigate to a new page. This must be called *before* the
1141// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291142void RenderView::UpdateSessionHistory(WebFrame* frame) {
1143 // If we have a valid page ID at this point, then it corresponds to the page
1144 // we are navigating away from. Otherwise, this is the first navigation, so
1145 // there is no past session history to record.
1146 if (page_id_ == -1)
1147 return;
1148
[email protected]ca948a22009-06-25 19:36:171149 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271150 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171151 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291152 return;
[email protected]ca948a22009-06-25 19:36:171153
1154 Send(new ViewHostMsg_UpdateState(
1155 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291156}
1157
[email protected]3d9689372009-09-10 04:29:171158void RenderView::OpenURL(
1159 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1160 Send(new ViewHostMsg_OpenURL(
1161 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1162}
1163
[email protected]79dbc662009-09-04 05:42:511164// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291165
initial.commit09911bf2008-07-26 23:55:291166void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281167 const WebURLRequest& failed_request,
1168 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291169 const std::string& html,
1170 bool replace) {
[email protected]21d61e52011-03-18 19:08:251171 std::string alt_html = !html.empty() ? html :
1172 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1173 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451174 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361175 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251176 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551177 replace);
initial.commit09911bf2008-07-26 23:55:291178}
1179
initial.commit09911bf2008-07-26 23:55:291180bool RenderView::RunJavaScriptMessage(int type,
1181 const std::wstring& message,
1182 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071183 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291184 std::wstring* result) {
1185 bool success = false;
1186 std::wstring result_temp;
1187 if (!result)
1188 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291189
[email protected]12636df2009-09-28 22:32:211190 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1191 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291192 return success;
1193}
1194
[email protected]c1f50aa2010-02-18 03:46:571195bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1196 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1197 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1198 // it is particularly important that we do not call willEnterModalLoop as
1199 // that would defer resource loads for the dialog itself.
1200 if (RenderThread::current()) // Will be NULL during unit tests.
1201 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1202
1203 message->EnableMessagePumping(); // Runs a nested message loop.
1204 return Send(message);
1205}
1206
[email protected]f103ab72009-09-02 17:10:591207void RenderView::OnMissingPluginStatus(
1208 WebPluginDelegateProxy* delegate,
1209 int status) {
[email protected]6c8afae52009-01-22 02:24:571210#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591211 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291212 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:501213 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591214 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291215 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1216 }
1217 } else {
1218 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1219 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:501220 if (status ==
1221 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:291222 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1223 }
1224 }
[email protected]6c8afae52009-01-22 02:24:571225#else
[email protected]76c3b312010-05-20 21:38:291226 // TODO(port): Implement the infobar that accompanies the default plugin.
1227 // Linux: http://crbug.com/10952
1228 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571229 NOTIMPLEMENTED();
1230#endif
initial.commit09911bf2008-07-26 23:55:291231}
1232
[email protected]48c9cf2d2009-09-16 16:47:521233// WebKit::WebViewClient ------------------------------------------------------
1234
[email protected]844acf372011-01-14 10:49:271235WebView* RenderView::createView(
1236 WebFrame* creator,
1237 const WebURLRequest& request,
1238 const WebWindowFeatures& features,
1239 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521240 // Check to make sure we aren't overloading on popups.
1241 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1242 return NULL;
1243
[email protected]8ab04652010-06-12 02:47:261244 ViewHostMsg_CreateWindow_Params params;
1245 params.opener_id = routing_id_;
1246 params.user_gesture = creator->isProcessingUserGesture();
1247 params.window_container_type = WindowFeaturesToContainerType(features);
1248 params.session_storage_namespace_id = session_storage_namespace_id_;
1249 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111250 params.opener_frame_id = creator->identifier();
1251 params.opener_url = creator->url();
1252 params.opener_security_origin = creator->securityOrigin().toString().utf8();
1253 if (!request.isNull())
1254 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261255
[email protected]48c9cf2d2009-09-16 16:47:521256 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341257 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261258 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521259
[email protected]48c9cf2d2009-09-16 16:47:521260 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261261 new ViewHostMsg_CreateWindow(params,
1262 &routing_id,
1263 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211264 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521265 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521266
[email protected]48c9cf2d2009-09-16 16:47:521267 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421268 0,
[email protected]c03a6e72011-04-19 21:42:061269 gfx::kNullPluginWindow,
[email protected]12636df2009-09-28 22:32:211270 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521271 renderer_preferences_,
1272 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211273 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341274 routing_id,
[email protected]8ab04652010-06-12 02:47:261275 cloned_session_storage_namespace_id,
1276 frame_name);
1277 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521278
[email protected]007a848b2009-10-26 15:55:461279 // Record whether the creator frame is trying to suppress the opener field.
1280 view->opener_suppressed_ = opener_suppressed;
1281
[email protected]48c9cf2d2009-09-16 16:47:521282 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:091283 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521284 if (!creator_url.is_valid() || !creator_url.IsStandard())
1285 creator_url = GURL();
1286 view->creator_url_ = creator_url;
1287
1288 // Copy over the alternate error page URL so we can have alt error pages in
1289 // the new render view (we don't need the browser to send the URL back down).
1290 view->alternate_error_page_url_ = alternate_error_page_url_;
1291
1292 return view->webview();
1293}
1294
[email protected]3e2b375b2010-04-07 17:03:121295WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521296 RenderWidget* widget = RenderWidget::Create(routing_id_,
1297 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121298 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521299 return widget->webwidget();
1300}
1301
1302WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441303 // TODO(jcivelli): Remove this deprecated method when its been removed from
1304 // the WebViewClient interface. It's been replaced by
1305 // createExternalPopupMenu.
1306 NOTREACHED();
1307 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521308}
1309
[email protected]caf706f2010-10-26 17:54:081310WebExternalPopupMenu* RenderView::createExternalPopupMenu(
1311 const WebPopupMenuInfo& popup_menu_info,
1312 WebExternalPopupMenuClient* popup_menu_client) {
1313 DCHECK(!external_popup_menu_.get());
1314 external_popup_menu_.reset(
1315 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1316 return external_popup_menu_.get();
1317}
1318
[email protected]ea192e82011-04-11 19:16:021319RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521320 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531321 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421322 if (webview() && webview()->mainFrame())
[email protected]d91233b7e2011-03-29 20:33:531323 active_url = GURL(webview()->mainFrame()->url());
1324 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
1325 routing_id_, render_thread_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391326 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561327 return widget;
[email protected]79c7bed2010-09-14 22:28:391328}
1329
[email protected]68c50e52010-05-12 11:14:391330WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341331 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391332 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291333 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1334 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1335 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341336}
1337
[email protected]48c9cf2d2009-09-16 16:47:521338void RenderView::didAddMessageToConsole(
1339 const WebConsoleMessage& message, const WebString& source_name,
1340 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081341 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
1342 switch(message.level) {
1343 case WebConsoleMessage::LevelTip:
1344 log_severity = logging::LOG_VERBOSE;
1345 break;
1346 case WebConsoleMessage::LevelLog:
1347 log_severity = logging::LOG_INFO;
1348 break;
1349 case WebConsoleMessage::LevelWarning:
1350 log_severity = logging::LOG_WARNING;
1351 break;
1352 case WebConsoleMessage::LevelError:
1353 log_severity = logging::LOG_ERROR;
1354 break;
1355 default:
1356 NOTREACHED();
1357 }
1358
[email protected]48c9cf2d2009-09-16 16:47:521359 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081360 static_cast<int32>(log_severity),
[email protected]48c9cf2d2009-09-16 16:47:521361 UTF16ToWideHack(message.text),
1362 static_cast<int32>(source_line),
1363 UTF16ToWideHack(source_name)));
1364}
1365
1366void RenderView::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421367 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521368}
1369
[email protected]3354d3e2010-06-10 19:53:021370WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511371 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021372}
1373
[email protected]8a58c1c2011-04-19 18:40:121374bool RenderView::enumerateChosenDirectory(
1375 const WebString& path,
1376 WebFileChooserCompletion* chooser_completion) {
1377 int id = enumeration_completion_id_++;
1378 enumeration_completions_[id] = chooser_completion;
1379 return Send(new ViewHostMsg_EnumerateDirectory(
1380 routing_id_,
1381 id,
1382 webkit_glue::WebStringToFilePath(path)));
1383}
1384
[email protected]48c9cf2d2009-09-16 16:47:521385void RenderView::didStartLoading() {
1386 if (is_loading_) {
1387 DLOG(WARNING) << "didStartLoading called while loading";
1388 return;
1389 }
1390
1391 is_loading_ = true;
1392 // Clear the pointer so that we can assign it only when there is an unknown
1393 // plugin on a page.
1394 first_default_plugin_.reset();
1395
1396 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311397
1398 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521399}
1400
1401void RenderView::didStopLoading() {
1402 if (!is_loading_) {
1403 DLOG(WARNING) << "DidStopLoading called while not loading";
1404 return;
1405 }
1406
1407 is_loading_ = false;
1408
1409 // NOTE: For now we're doing the safest thing, and sending out notification
1410 // when done loading. This currently isn't an issue as the favicon is only
1411 // displayed when done loading. Ideally we would send notification when
1412 // finished parsing the head, but webkit doesn't support that yet.
1413 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521414 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1415
[email protected]90109412010-12-15 17:14:241416 if (load_progress_tracker_ != NULL)
1417 load_progress_tracker_->DidStopLoading();
1418
[email protected]93b9d692011-04-13 00:44:311419 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521420}
1421
[email protected]90109412010-12-15 17:14:241422void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
1423 if (load_progress_tracker_ != NULL)
1424 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1425}
1426
[email protected]f55039a2010-02-17 14:12:061427bool RenderView::isSmartInsertDeleteEnabled() {
1428#if defined(OS_MACOSX)
1429 return true;
1430#else
1431 return false;
1432#endif
1433}
1434
[email protected]04fc9482009-09-18 22:13:031435bool RenderView::isSelectTrailingWhitespaceEnabled() {
1436#if defined(OS_WIN)
1437 return true;
1438#else
1439 return false;
1440#endif
1441}
1442
[email protected]04fc9482009-09-18 22:13:031443void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:421444#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031445 if (!handling_input_event_)
1446 return;
[email protected]d4cff272011-05-02 15:46:011447
1448 if (is_empty_selection) {
1449 last_selection_.clear();
1450 } else {
[email protected]04fc9482009-09-18 22:13:031451 // Sometimes we get repeated didChangeSelection calls from webkit when
1452 // the selection hasn't actually changed. We don't want to report these
1453 // because it will cause us to continually claim the X clipboard.
[email protected]d4cff272011-05-02 15:46:011454 WebFrame* frame = webview()->focusedFrame();
1455 const std::string& this_selection = frame->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031456 if (this_selection == last_selection_)
1457 return;
[email protected]04fc9482009-09-18 22:13:031458 last_selection_ = this_selection;
[email protected]04fc9482009-09-18 22:13:031459 }
[email protected]d4cff272011-05-02 15:46:011460
1461 ui::Range range(ui::Range::InvalidRange());
1462 size_t location, length;
1463 if (webview()->caretOrSelectionRange(&location, &length)) {
1464 range.set_start(location);
1465 range.set_end(location + length);
1466 }
1467 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range));
[email protected]0ff0ff32010-12-21 19:34:421468#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031469}
1470
1471void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121472 const std::string& name = UTF16ToUTF8(command_name);
1473 if (StartsWithASCII(name, "Move", true) ||
1474 StartsWithASCII(name, "Insert", true) ||
1475 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031476 return;
[email protected]9966325b2011-04-18 05:00:101477 webkit_glue::UserMetricsRecordAction(name);
[email protected]04fc9482009-09-18 22:13:031478}
1479
[email protected]54ec7f82010-10-21 22:32:511480void RenderView::SendPendingAccessibilityNotifications() {
1481 if (!accessibility_.get())
1482 return;
1483
1484 if (pending_accessibility_notifications_.empty())
1485 return;
1486
1487 // Send all pending accessibility notifications.
1488 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
1489 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
1490 RendererAccessibilityNotification& notification =
1491 pending_accessibility_notifications_[i];
1492 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
1493 if (!obj.isValid())
1494 continue;
1495
1496 ViewHostMsg_AccessibilityNotification_Params param;
[email protected]a527a022011-02-10 02:32:361497 WebAccessibilityNotificationToViewHostMsg(
1498 pending_accessibility_notifications_[i].type, &param.notification_type);
[email protected]70eee342010-11-05 01:59:371499 param.acc_obj = WebAccessibility(
1500 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:511501 notifications.push_back(param);
1502 }
1503 pending_accessibility_notifications_.clear();
1504 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
1505 accessibility_ack_pending_ = true;
1506}
1507
[email protected]b2528b72009-09-24 06:57:101508bool RenderView::handleCurrentKeyboardEvent() {
1509 if (edit_commands_.empty())
1510 return false;
1511
[email protected]26aa0482009-09-30 16:55:271512 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101513 if (!frame)
1514 return false;
1515
1516 EditCommands::iterator it = edit_commands_.begin();
1517 EditCommands::iterator end = edit_commands_.end();
1518
[email protected]507b33ea2009-09-29 03:56:511519 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101520 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331521 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1522 // key (but it's the exception). Once one edit command is not executed, it
1523 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101524 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1525 WebString::fromUTF8(it->value)))
1526 break;
[email protected]507b33ea2009-09-29 03:56:511527 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101528 }
1529
[email protected]507b33ea2009-09-29 03:56:511530 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101531}
1532
[email protected]a1128322009-10-06 18:38:461533bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351534 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471535 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351536 // Do not open the file dialog in a hidden RenderView.
1537 if (is_hidden())
1538 return false;
[email protected]cdaf8d02010-03-30 19:52:471539 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261540 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361541 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261542 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361543 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]b5977a0c2010-08-24 19:46:261544 else
[email protected]0aed2f52011-03-23 18:06:361545 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471546 ipc_params.title = params.title;
1547 ipc_params.default_file_name =
1548 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591549 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471550
1551 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461552}
1553
[email protected]48c9cf2d2009-09-16 16:47:521554void RenderView::runModalAlertDialog(
1555 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061556 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]48c9cf2d2009-09-16 16:47:521557 UTF16ToWideHack(message),
1558 std::wstring(),
1559 frame->url(),
1560 NULL);
1561}
1562
1563bool RenderView::runModalConfirmDialog(
1564 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061565 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]48c9cf2d2009-09-16 16:47:521566 UTF16ToWideHack(message),
1567 std::wstring(),
1568 frame->url(),
1569 NULL);
1570}
1571
1572bool RenderView::runModalPromptDialog(
1573 WebFrame* frame, const WebString& message, const WebString& default_value,
1574 WebString* actual_value) {
1575 std::wstring result;
[email protected]9dd7e3d72011-01-20 18:27:061576 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]48c9cf2d2009-09-16 16:47:521577 UTF16ToWideHack(message),
1578 UTF16ToWideHack(default_value),
1579 frame->url(),
1580 &result);
1581 if (ok)
1582 actual_value->assign(WideToUTF16Hack(result));
1583 return ok;
1584}
1585
1586bool RenderView::runModalBeforeUnloadDialog(
1587 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151588 // If we are swapping out, we have already run the beforeunload handler.
1589 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1590 // at all, to avoid running it twice.
1591 if (is_swapped_out_)
1592 return true;
1593
[email protected]48c9cf2d2009-09-16 16:47:521594 bool success = false;
1595 // This is an ignored return value, but is included so we can accept the same
1596 // response as RunJavaScriptMessage.
1597 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:211598 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:521599 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:211600 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521601 return success;
1602}
1603
[email protected]79e37442009-10-09 18:17:441604void RenderView::showContextMenu(
1605 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291606 ContextMenuParams params = ContextMenuParams(data);
[email protected]db803aae2011-03-05 02:00:421607 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271608 // it. We replace it with an empty GURL so the appropriate items are disabled
1609 // in the context menu.
1610 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1611 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421612 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271613 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101614 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291615 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441616}
1617
[email protected]52f139e2c2010-06-11 16:56:091618bool RenderView::supportsFullscreen() {
1619 return CommandLine::ForCurrentProcess()->HasSwitch(
1620 switches::kEnableVideoFullscreen);
1621}
1622
1623void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1624 NOTIMPLEMENTED();
1625}
1626
1627void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1628 NOTIMPLEMENTED();
1629}
1630
[email protected]48c9cf2d2009-09-16 16:47:521631void RenderView::setStatusText(const WebString& text) {
1632}
1633
[email protected]163f8242009-10-30 20:19:551634void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581635 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521636 if (latest_url == target_url_)
1637 return;
[email protected]163f8242009-10-30 20:19:551638
[email protected]48c9cf2d2009-09-16 16:47:521639 // Tell the browser to display a destination link.
1640 if (target_url_status_ == TARGET_INFLIGHT ||
1641 target_url_status_ == TARGET_PENDING) {
1642 // If we have a request in-flight, save the URL to be sent when we
1643 // receive an ACK to the in-flight request. We can happily overwrite
1644 // any existing pending sends.
1645 pending_target_url_ = latest_url;
1646 target_url_status_ = TARGET_PENDING;
1647 } else {
1648 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1649 target_url_ = latest_url;
1650 target_url_status_ = TARGET_INFLIGHT;
1651 }
1652}
1653
[email protected]882daa92009-11-05 16:31:311654void RenderView::StartNavStateSyncTimerIfNecessary() {
1655 int delay;
1656 if (send_content_state_immediately_)
1657 delay = 0;
1658 else if (is_hidden())
1659 delay = kDelaySecondsForContentStateSyncHidden;
1660 else
1661 delay = kDelaySecondsForContentStateSync;
1662
1663 if (nav_state_sync_timer_.IsRunning()) {
1664 // The timer is already running. If the delay of the timer maches the amount
1665 // we want to delay by, then return. Otherwise stop the timer so that it
1666 // gets started with the right delay.
1667 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1668 return;
1669 nav_state_sync_timer_.Stop();
1670 }
1671
1672 nav_state_sync_timer_.Start(
1673 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1674}
1675
[email protected]163f8242009-10-30 20:19:551676void RenderView::setMouseOverURL(const WebURL& url) {
1677 mouse_over_url_ = GURL(url);
1678 UpdateTargetURL(mouse_over_url_, focus_url_);
1679}
1680
1681void RenderView::setKeyboardFocusURL(const WebURL& url) {
1682 focus_url_ = GURL(url);
1683 UpdateTargetURL(focus_url_, mouse_over_url_);
1684}
1685
[email protected]48c9cf2d2009-09-16 16:47:521686void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
1687 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
1688 hint));
1689}
1690
[email protected]c27ae592010-03-18 15:24:411691void RenderView::startDragging(const WebDragData& data,
1692 WebDragOperationsMask mask,
1693 const WebImage& image,
1694 const WebPoint& imageOffset) {
1695#if WEBKIT_USING_SKIA
1696 SkBitmap bitmap(image.getSkBitmap());
1697#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331698 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411699#endif
1700
[email protected]59f4f2fa2011-03-23 01:00:551701 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521702 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411703 mask,
1704 bitmap,
1705 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521706}
1707
[email protected]28b92df2009-09-25 17:35:451708bool RenderView::acceptsLoadDrops() {
1709 return renderer_preferences_.can_accept_load_drops;
1710}
1711
[email protected]48c9cf2d2009-09-16 16:47:521712void RenderView::focusNext() {
1713 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1714}
1715
1716void RenderView::focusPrevious() {
1717 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1718}
1719
[email protected]08e9e132010-06-01 16:58:491720void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511721 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071722
1723 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
1724 // TODO(ctguil): Make WebKit send this notification.
1725 // When focus is cleared notify accessibility that the document is focused.
1726 postAccessibilityNotification(
1727 webview()->accessibilityObject(),
1728 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
1729 }
[email protected]13a1e4c3c2011-02-03 21:07:091730
[email protected]38b592902011-04-16 02:08:421731 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491732}
1733
[email protected]48c9cf2d2009-09-16 16:47:521734void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521735 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1736}
1737
1738int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001739 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521740}
1741
1742int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001743 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521744}
1745
[email protected]c4e98902010-06-01 10:20:141746void RenderView::didUpdateInspectorSetting(const WebString& key,
1747 const WebString& value) {
1748 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1749 key.utf8(),
1750 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261751}
1752
[email protected]79dbc662009-09-04 05:42:511753// WebKit::WebWidgetClient ----------------------------------------------------
1754
[email protected]ea42e7782010-08-23 23:58:121755void RenderView::didFocus() {
1756 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1757 // we won't have to test for user gesture anymore and we can
1758 // move that code back to render_widget.cc
1759 if (webview() && webview()->mainFrame() &&
1760 webview()->mainFrame()->isProcessingUserGesture()) {
1761 Send(new ViewHostMsg_Focus(routing_id_));
1762 }
1763}
1764
1765void RenderView::didBlur() {
1766 // TODO(jcivelli): see TODO above in didFocus().
1767 if (webview() && webview()->mainFrame() &&
1768 webview()->mainFrame()->isProcessingUserGesture()) {
1769 Send(new ViewHostMsg_Blur(routing_id_));
1770 }
1771}
1772
initial.commit09911bf2008-07-26 23:55:291773// We are supposed to get a single call to Show for a newly created RenderView
1774// that was created via RenderView::CreateWebView. So, we wait until this
1775// point to dispatch the ShowView message.
1776//
1777// This method provides us with the information about how to display the newly
1778// created RenderView (i.e., as a constrained popup or as a new tab).
1779//
[email protected]4873c7d2009-07-16 06:36:281780void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291781 DCHECK(!did_show_) << "received extraneous Show call";
1782 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1783
1784 if (did_show_)
1785 return;
1786 did_show_ = true;
1787
[email protected]6779aa12011-03-29 17:32:241788 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041789 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041790
[email protected]28295ec2009-10-16 05:34:331791 // Force new windows to a popup if they were not opened with a user gesture.
1792 if (!opened_by_user_gesture_) {
1793 // We exempt background tabs for compat with older versions of Chrome.
1794 // TODO(darin): This seems bogus. These should have a user gesture, so
1795 // we probably don't need this check.
1796 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1797 policy = WebKit::WebNavigationPolicyNewPopup;
1798 }
1799
initial.commit09911bf2008-07-26 23:55:291800 // NOTE: initial_pos_ may still have its default values at this point, but
1801 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1802 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281803 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1804 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291805 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241806 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291807}
1808
[email protected]4873c7d2009-07-16 06:36:281809void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291810 DCHECK(did_show_) << "should already have shown the view";
1811
[email protected]c1f50aa2010-02-18 03:46:571812 // We must keep WebKit's shared timer running in this case in order to allow
1813 // showModalDialog to function properly.
1814 //
1815 // TODO(darin): WebKit should really be smarter about suppressing events and
1816 // timers so that we do not need to manage the shared timer in such a heavy
1817 // handed manner.
1818 //
1819 if (RenderThread::current()) // Will be NULL during unit tests.
1820 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
1821
[email protected]12636df2009-09-28 22:32:211822 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291823}
1824
[email protected]3d9689372009-09-10 04:29:171825// WebKit::WebFrameClient -----------------------------------------------------
1826
[email protected]00152e92010-07-19 11:47:401827WebPlugin* RenderView::createPlugin(WebFrame* frame,
1828 const WebPluginParams& params) {
[email protected]e7c21b812011-03-19 18:03:301829 return content::GetContentClient()->renderer()->CreatePlugin(
[email protected]21d61e52011-03-18 19:08:251830 this, frame, params);
[email protected]3d9689372009-09-10 04:29:171831}
1832
1833WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561834 WebApplicationCacheHostImpl* appcache_host =
1835 WebApplicationCacheHostImpl::FromFrame(frame);
1836 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
1837 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
1838 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171839}
1840
[email protected]9c00f002009-11-05 22:37:421841WebSharedWorker* RenderView::createSharedWorker(
1842 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371843 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421844
[email protected]30447b62009-11-13 01:13:371845 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511846 bool exists = false;
[email protected]30447b62009-11-13 01:13:371847 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511848 ViewHostMsg_CreateWorker_Params params;
1849 params.url = url;
1850 params.is_shared = true;
1851 params.name = name;
1852 params.document_id = document_id;
1853 params.render_view_route_id = routing_id_;
1854 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231855 params.parent_appcache_host_id = 0;
1856 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371857 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511858 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371859 if (url_mismatch) {
1860 return NULL;
1861 } else {
1862 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:491863 document_id,
[email protected]6de0bcf2010-02-17 22:00:511864 exists,
[email protected]30447b62009-11-13 01:13:371865 route_id,
1866 routing_id_);
1867 }
[email protected]9c00f002009-11-05 22:37:421868}
1869
[email protected]3d9689372009-09-10 04:29:171870WebMediaPlayer* RenderView::createMediaPlayer(
1871 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441872 FOR_EACH_OBSERVER(
1873 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171874
[email protected]f78d1dfc2011-01-15 07:09:271875 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1876 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491877 scoped_ptr<media::FilterCollection> collection(
1878 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371879
[email protected]3d9689372009-09-10 04:29:171880 // Add in any custom filter factories first.
1881 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1882 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1883 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:491884 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:171885 }
1886
[email protected]3bb08602010-10-07 21:47:171887 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:121888 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:071889 WebGraphicsContext3DCommandBufferImpl* context =
1890 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
1891 frame->view()->graphicsContext3D());
1892 if (!context)
1893 return NULL;
[email protected]a9a43012010-11-05 01:54:061894
[email protected]5aa6a312010-11-06 00:00:071895 // Add the hardware video decoder factory.
1896 // TODO(hclam): This will cause the renderer process to crash on context
1897 // lost.
1898 bool ret = context->makeContextCurrent();
1899 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:491900 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:071901 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:171902 }
1903
[email protected]457d8342010-10-23 01:20:371904 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:311905 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
1906 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
1907 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:491908 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:311909 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:111910
[email protected]a8e24d522010-12-01 07:13:581911 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:271912 new webkit_glue::WebMediaPlayerImpl(client,
1913 collection.release(),
1914 message_loop_factory.release()));
[email protected]79684282010-12-06 21:15:461915 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:581916 cmd_line->HasSwitch(switches::kSimpleDataSource),
1917 video_renderer)) {
1918 return NULL;
1919 }
1920 return result.release();
[email protected]3d9689372009-09-10 04:29:171921}
1922
[email protected]035545f2010-04-09 13:10:211923WebApplicationCacheHost* RenderView::createApplicationCacheHost(
1924 WebFrame* frame, WebApplicationCacheHostClient* client) {
1925 return new RendererWebApplicationCacheHostImpl(
1926 FromWebView(frame->view()), client,
1927 RenderThread::current()->appcache_dispatcher()->backend_proxy());
1928}
1929
[email protected]8ff181072010-11-29 17:09:381930WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
1931 return &cookie_jar_;
1932}
1933
[email protected]5041f982010-08-11 21:40:451934void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511935 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451936}
1937
[email protected]3d9689372009-09-10 04:29:171938void RenderView::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511939 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171940}
1941
1942void RenderView::loadURLExternally(
1943 WebFrame* frame, const WebURLRequest& request,
1944 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:591945 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1946 if (policy == WebKit::WebNavigationPolicyDownload) {
1947 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
1948 } else {
1949 OpenURL(request.url(), referrer, policy);
1950 }
[email protected]3d9689372009-09-10 04:29:171951}
1952
1953WebNavigationPolicy RenderView::decidePolicyForNavigation(
1954 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221955 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:151956 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
1957 if (is_swapped_out_) {
1958 DCHECK(request.url() == GURL("about:swappedout"));
1959 return default_policy;
1960 }
1961
[email protected]3d9689372009-09-10 04:29:171962 // Webkit is asking whether to navigate to a new URL.
1963 // This is fine normally, except if we're showing UI from one security
1964 // context and they're trying to navigate to a different context.
1965 const GURL& url = request.url();
1966
[email protected]d19ea342011-04-20 20:31:131967 // A content initiated navigation may have originated from a link-click,
1968 // script, drag-n-drop operation, etc.
1969 bool is_content_initiated =
1970 NavigationState::FromDataSource(frame->provisionalDataSource())->
1971 is_content_initiated();
1972
[email protected]3d9689372009-09-10 04:29:171973 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:301974 // navigations.
[email protected]d19ea342011-04-20 20:31:131975 if (is_content_initiated &&
1976 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:451977 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:191978 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:231979 // Reset these counters as the RenderView could be reused for the next
1980 // navigation.
1981 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:231982 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:191983 OpenURL(url, referrer, default_policy);
1984 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:171985 }
1986
[email protected]a6b960ad972010-09-01 19:53:581987 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:171988
[email protected]6101c342010-12-16 22:44:371989 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:551990 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:571991 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:371992 // opening a new window). But we sometimes navigate to about:blank to clear a
1993 // tab, and we want to still allow that.
1994 //
[email protected]8f4da8c2011-02-09 19:49:571995 // Note: we do this only for GET requests because our mechanism for switching
1996 // processes only issues GET requests. In particular, POST requests don't
1997 // work, because this mechanism does not preserve form POST data. If it
1998 // becomes necessary to support process switching for POST requests, we will
1999 // need to send the request's httpBody data up to the browser process, and
2000 // issue a special POST navigation in WebKit (via
2001 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2002 // for examples of how to send the httpBody data.
2003 // Note2: We normally don't do this for browser-initiated navigations, since
2004 // it's pointless to tell the browser about navigations it gave us. But
2005 // we do potentially ask the browser to handle a redirect that was originally
2006 // initiated by the browser. See http://crbug.com/70943
2007 //
2008 // TODO(creis): Move this redirect check to the browser process to avoid
2009 // ping-ponging. See http://crbug.com/72380.
2010 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372011 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2012 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2013 bool send_referrer = false;
2014 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552015 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172016 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372017 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112018
[email protected]e48869a2011-04-01 19:56:032019 if (!should_fork) {
2020 // Give the embedder a chance.
2021 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2022 frame, url, is_content_initiated, &send_referrer);
[email protected]6101c342010-12-16 22:44:372023 }
2024
2025 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112026 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372027 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112028 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2029 }
[email protected]3d9689372009-09-10 04:29:172030 }
2031
2032 // Detect when a page is "forking" a new tab that can be safely rendered in
2033 // its own process. This is done by sites like Gmail that try to open links
2034 // in new windows without script connections back to the original page. We
2035 // treat such cases as browser navigations (in which we will create a new
2036 // renderer for a cross-site navigation), rather than WebKit navigations.
2037 //
2038 // We use the following heuristic to decide whether to fork a new page in its
2039 // own process:
2040 // The parent page must open a new tab to about:blank, set the new tab's
2041 // window.opener to null, and then redirect the tab to a cross-site URL using
2042 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462043 //
2044 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2045 // (see below).
[email protected]3d9689372009-09-10 04:29:172046 bool is_fork =
2047 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582048 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172049 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522050 historyBackListCount() < 1 &&
2051 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172052 // The parent page must have set the child's window.opener to null before
2053 // redirecting to the desired URL.
2054 frame->opener() == NULL &&
2055 // Must be a top-level frame.
2056 frame->parent() == NULL &&
2057 // Must not have issued the request from this page.
2058 is_content_initiated &&
2059 // Must be targeted at the current tab.
2060 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2061 // Must be a JavaScript navigation, which appears as "other".
2062 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462063
2064 // Recognize if this navigation is from a link with rel=noreferrer and
2065 // target=_blank attributes, in which case the opener will be suppressed. If
2066 // so, it is safe to load cross-site pages in a separate process, so we
2067 // should let the browser handle it.
2068 bool is_noreferrer_and_blank_target =
2069 // Frame should be top level and not yet navigated.
2070 frame->parent() == NULL &&
2071 frame->url().isEmpty() &&
2072 historyBackListCount() < 1 &&
2073 historyForwardListCount() < 1 &&
2074 // Links with rel=noreferrer will have no Referer field, and their
2075 // resulting frame will have its window.opener suppressed.
2076 // TODO(creis): should add a request.httpReferrer() method to help avoid
2077 // typos on the unusual spelling of Referer.
2078 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2079 opener_suppressed_ &&
2080 frame->opener() == NULL &&
2081 // Links with target=_blank will have no name.
2082 frame->name().isNull() &&
2083 // Another frame (with a non-empty creator) should have initiated the
2084 // request, targeted at this frame.
2085 !creator_url_.is_empty() &&
2086 is_content_initiated &&
2087 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2088 type == WebKit::WebNavigationTypeOther;
2089
2090 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172091 // Open the URL via the browser, not via WebKit.
2092 OpenURL(url, GURL(), default_policy);
2093 return WebKit::WebNavigationPolicyIgnore;
2094 }
2095
2096 return default_policy;
2097}
2098
[email protected]6069da8c2009-10-20 20:33:492099bool RenderView::canHandleRequest(
2100 WebFrame* frame, const WebURLRequest& request) {
2101 // We allow WebKit to think that everything can be handled even though
2102 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342103 return true;
2104}
2105
[email protected]6069da8c2009-10-20 20:33:492106WebURLError RenderView::cannotHandleRequestError(
2107 WebFrame* frame, const WebURLRequest& request) {
2108 NOTREACHED(); // Since we said we can handle all requests.
2109 return WebURLError();
2110}
2111
2112WebURLError RenderView::cancelledError(
2113 WebFrame* frame, const WebURLRequest& request) {
2114 WebURLError error;
2115 error.domain = WebString::fromUTF8(net::kErrorDomain);
2116 error.reason = net::ERR_ABORTED;
2117 error.unreachableURL = request.url();
2118 return error;
[email protected]7b7a7dc2009-10-19 02:23:342119}
2120
2121void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492122 WebFrame*, const WebURLError&) {
2123 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342124}
2125
[email protected]90eeddb2010-05-06 21:06:432126void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2127 const WebKit::WebFormElement& form) {
2128 // Some login forms have onSubmit handlers that put a hash of the password
2129 // into a hidden field and then clear the password. (Issue 28910.)
2130 // This method gets called before any of those handlers run, so save away
2131 // a copy of the password in case it gets lost.
2132 NavigationState* navigation_state =
2133 NavigationState::FromDataSource(frame->dataSource());
2134 navigation_state->set_password_form_data(
2135 PasswordFormDomManager::CreatePasswordForm(form));
2136}
2137
[email protected]979c28b2009-11-07 01:30:482138void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172139 NavigationState* navigation_state =
2140 NavigationState::FromDataSource(frame->provisionalDataSource());
2141
2142 if (navigation_state->transition_type() == PageTransition::LINK)
2143 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2144
2145 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352146 WebSearchableFormData web_searchable_form_data(form);
2147 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2148 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212149 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432150 PasswordForm* password_form_data =
2151 PasswordFormDomManager::CreatePasswordForm(form);
2152 navigation_state->set_password_form_data(password_form_data);
2153
[email protected]098c95cb2011-04-28 16:49:012154 // In order to save the password that the user actually typed and not one
2155 // that may have gotten transformed by the site prior to submit, recover it
2156 // from the form contents already stored by |willSendSubmitEvent| into the
2157 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2158 // which is what we're storing into now.)
2159 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432160 NavigationState* old_navigation_state =
2161 NavigationState::FromDataSource(frame->dataSource());
2162 if (old_navigation_state) {
2163 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2164 if (old_form_data && old_form_data->action == password_form_data->action)
2165 password_form_data->password_value = old_form_data->password_value;
2166 }
2167 }
[email protected]3d9689372009-09-10 04:29:172168
[email protected]2a5b1732011-04-01 23:55:552169 FOR_EACH_OBSERVER(
2170 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172171}
2172
2173void RenderView::willPerformClientRedirect(
2174 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2175 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382176 FOR_EACH_OBSERVER(
2177 RenderViewObserver, observers_,
2178 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172179}
2180
2181void RenderView::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382182 FOR_EACH_OBSERVER(
2183 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172184}
2185
2186void RenderView::didCompleteClientRedirect(
2187 WebFrame* frame, const WebURL& from) {
2188 if (!frame->parent())
2189 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382190 FOR_EACH_OBSERVER(
2191 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172192}
2193
2194void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2195 // The rest of RenderView assumes that a WebDataSource will always have a
2196 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482197 bool content_initiated = !pending_navigation_state_.get();
2198 NavigationState* state = content_initiated ?
2199 NavigationState::CreateContentInitiated() :
2200 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512201
[email protected]8a3125a712010-08-09 18:58:512202 // NavigationState::referred_by_prefetcher_ is true if we are
2203 // navigating from a page that used prefetching using a link on that
2204 // page. We are early enough in the request process here that we
2205 // can still see the NavigationState of the previous page and set
2206 // this value appropriately.
2207 // TODO(gavinp): catch the important case of navigation in a new
2208 // renderer process.
2209 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302210 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522211 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512212 const GURL referrer(
2213 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2214 if (!referrer.is_empty() &&
2215 NavigationState::FromDataSource(
2216 old_frame->dataSource())->was_prefetcher()) {
2217 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2218 WebDataSource* old_frame_ds = old_frame->dataSource();
2219 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2220 state->set_was_referred_by_prefetcher(true);
2221 break;
2222 }
2223 }
2224 }
2225 }
2226 }
2227
[email protected]4c1b6f0b2010-02-07 16:38:182228 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522229 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512230 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182231 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2232 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2233 break;
2234 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2235 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2236 break;
2237 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2238 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2239 break;
2240 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2241 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2242 break;
2243 }
2244 }
[email protected]fa7b6b542009-11-03 05:02:302245
[email protected]16e923d2011-04-30 00:41:442246 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502247
[email protected]946a0032011-03-31 18:42:282248 FOR_EACH_OBSERVER(
2249 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172250}
2251
2252void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2253 WebDataSource* ds = frame->provisionalDataSource();
2254 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2255
[email protected]3d9689372009-09-10 04:29:172256 // Update the request time if WebKit has better knowledge of it.
2257 if (navigation_state->request_time().is_null()) {
2258 double event_time = ds->triggeringEventTime();
2259 if (event_time != 0.0)
2260 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2261 }
2262
[email protected]05c8e502010-08-15 15:13:522263 // Start time is only set after request time.
2264 navigation_state->set_start_load_time(Time::Now());
2265
[email protected]3d9689372009-09-10 04:29:172266 bool is_top_most = !frame->parent();
2267 if (is_top_most) {
2268 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132269 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172270
2271 // Make sure redirect tracking state is clear for the new load.
2272 completed_client_redirect_src_ = GURL();
2273 } else if (frame->parent()->isLoading()) {
2274 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002275 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172276 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2277 }
2278
[email protected]28685da92011-02-07 21:49:172279 FOR_EACH_OBSERVER(
2280 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2281
[email protected]3d9689372009-09-10 04:29:172282 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:072283 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172284}
2285
2286void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2287 if (frame->parent())
2288 return;
2289 // Received a redirect on the main frame.
2290 WebDataSource* data_source = frame->provisionalDataSource();
2291 if (!data_source) {
2292 // Should only be invoked when we have a data source.
2293 NOTREACHED();
2294 return;
2295 }
2296 std::vector<GURL> redirects;
2297 GetRedirectChain(data_source, &redirects);
2298 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512299 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
2300 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172301 }
2302}
2303
[email protected]40bd6582009-12-04 23:49:512304void RenderView::didFailProvisionalLoad(WebFrame* frame,
2305 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172306 // Notify the browser that we failed a provisional load with an error.
2307 //
2308 // Note: It is important this notification occur before DidStopLoading so the
2309 // SSL manager can react to the provisional load failure before being
2310 // notified the load stopped.
2311 //
2312 WebDataSource* ds = frame->provisionalDataSource();
2313 DCHECK(ds);
2314
2315 const WebURLRequest& failed_request = ds->request();
2316
[email protected]28685da92011-02-07 21:49:172317 FOR_EACH_OBSERVER(
2318 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2319
[email protected]3d9689372009-09-10 04:29:172320 bool show_repost_interstitial =
2321 (error.reason == net::ERR_CACHE_MISS &&
2322 EqualsASCII(failed_request.httpMethod(), "POST"));
2323 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072324 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2325 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172326
2327 // Don't display an error page if this is simply a cancelled load. Aside
2328 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2329 if (error.reason == net::ERR_ABORTED)
2330 return;
2331
2332 // Make sure we never show errors in view source mode.
2333 frame->enableViewSourceMode(false);
2334
2335 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2336
2337 // If this is a failed back/forward/reload navigation, then we need to do a
2338 // 'replace' load. This is necessary to avoid messing up session history.
2339 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2340 // as session history is concerned.
2341 //
2342 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2343 // the page id.
2344 //
2345 bool replace =
2346 navigation_state->pending_page_id() != -1 ||
2347 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2348
2349 // If we failed on a browser initiated request, then make sure that our error
2350 // page load is regarded as the same browser initiated request.
2351 if (!navigation_state->is_content_initiated()) {
2352 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2353 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002354 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172355 navigation_state->transition_type(),
2356 navigation_state->request_time()));
2357 }
2358
2359 // Provide the user with a more helpful error page?
2360 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2361 return;
2362
2363 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082364 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172365}
2366
2367void RenderView::didReceiveDocumentData(
2368 WebFrame* frame, const char* data, size_t data_len,
2369 bool& prevent_default) {
2370 NavigationState* navigation_state =
2371 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092372 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172373}
2374
[email protected]40bd6582009-12-04 23:49:512375void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2376 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172377 NavigationState* navigation_state =
2378 NavigationState::FromDataSource(frame->dataSource());
2379
2380 navigation_state->set_commit_load_time(Time::Now());
2381 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202382 // When we perform a new navigation, we need to update the last committed
2383 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172384 UpdateSessionHistory(frame);
2385
2386 // We bump our Page ID to correspond with the new session history entry.
2387 page_id_ = next_page_id_++;
2388
[email protected]3cc72b12010-03-18 23:03:002389 // Advance our offset in session history, applying the length limit. There
2390 // is now no forward history.
2391 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102392 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2393 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002394 history_list_length_ = history_list_offset_ + 1;
[email protected]3d9689372009-09-10 04:29:172395 } else {
2396 // Inspect the navigation_state on this frame to see if the navigation
2397 // corresponds to a session history navigation... Note: |frame| may or
2398 // may not be the toplevel frame, but for the case of capturing session
2399 // history, the first committed frame suffices. We keep track of whether
2400 // we've seen this commit before so that only capture session history once
2401 // per navigation.
2402 //
2403 // Note that we need to check if the page ID changed. In the case of a
2404 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2405 // previous URL and the current page ID, which would be wrong.
2406 if (navigation_state->pending_page_id() != -1 &&
2407 navigation_state->pending_page_id() != page_id_ &&
2408 !navigation_state->request_committed()) {
2409 // This is a successful session history navigation!
2410 UpdateSessionHistory(frame);
2411 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002412
2413 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:172414 }
2415 }
2416
[email protected]28685da92011-02-07 21:49:172417 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2418 DidCommitProvisionalLoad(frame, is_new_navigation));
2419
[email protected]3d9689372009-09-10 04:29:172420 // Remember that we've already processed this request, so we don't update
2421 // the session history again. We do this regardless of whether this is
2422 // a session history navigation, because if we attempted a session history
2423 // navigation without valid HistoryItem state, WebCore will think it is a
2424 // new navigation.
2425 navigation_state->set_request_committed(true);
2426
2427 UpdateURL(frame);
2428
2429 // If this committed load was initiated by a client redirect, we're
2430 // at the last stop now, so clear it.
2431 completed_client_redirect_src_ = GURL();
2432
2433 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272434 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172435}
2436
2437void RenderView::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102438 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2439 DidClearWindowObject(frame));
2440
[email protected]0d7ae862010-10-01 13:52:452441 GURL frame_url = frame->url();
[email protected]c09163a2011-02-15 00:05:552442 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:252443 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2444 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272445 GetWebUIBindings()->set_message_sender(this);
2446 GetWebUIBindings()->set_routing_id(routing_id_);
2447 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172448 }
[email protected]3d9689372009-09-10 04:29:172449}
2450
2451void RenderView::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172452 // Notify the browser about non-blank documents loading in the top frame.
2453 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:252454 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272455 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172456 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2457 }
[email protected]e48869a2011-04-01 19:56:032458
2459 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2460 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172461}
2462
[email protected]a3bc4d12011-04-20 17:22:212463void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title,
2464 WebTextDirection direction) {
[email protected]6b2f7a82011-04-25 19:30:512465 // TODO: pass direction through various APIs.
2466 // http://code.google.com/p/chromium/issues/detail?id=79903
2467 UpdateTitle(frame, title);
[email protected]3d9689372009-09-10 04:29:172468
2469 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272470 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172471}
2472
[email protected]5019ef12010-04-27 17:26:582473void RenderView::didChangeIcons(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102474 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidChangeIcons(frame));
[email protected]5019ef12010-04-27 17:26:582475}
2476
[email protected]3d9689372009-09-10 04:29:172477void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2478 WebDataSource* ds = frame->dataSource();
2479 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2480 DCHECK(navigation_state);
2481 navigation_state->set_finish_document_load_time(Time::Now());
2482
[email protected]622474d2010-11-04 09:21:082483 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172484
[email protected]28685da92011-02-07 21:49:172485 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2486 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172487
2488 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272489 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172490}
2491
2492void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082493 if (webview()->mainFrame() == frame) {
2494 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2495 page_id_));
2496 }
[email protected]3d9689372009-09-10 04:29:172497}
2498
2499void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172500 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172501}
2502
2503void RenderView::didFinishLoad(WebFrame* frame) {
2504 WebDataSource* ds = frame->dataSource();
2505 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2506 DCHECK(navigation_state);
2507 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412508
[email protected]676126f72011-01-15 00:03:512509 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172510
2511 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172512}
2513
[email protected]ccbe04e2010-03-17 17:58:432514void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172515 WebFrame* frame, bool is_new_navigation) {
2516 // If this was a reference fragment navigation that we initiated, then we
2517 // could end up having a non-null pending navigation state. We just need to
2518 // update the ExtraData on the datasource so that others who read the
2519 // ExtraData will get the new NavigationState. Similarly, if we did not
2520 // initiate this navigation, then we need to take care to reset any pre-
2521 // existing navigation state to a content-initiated navigation state.
2522 // DidCreateDataSource conveniently takes care of this for us.
2523 didCreateDataSource(frame, frame->dataSource());
2524
[email protected]af15bed2010-08-25 21:12:092525 NavigationState* new_state =
2526 NavigationState::FromDataSource(frame->dataSource());
2527 new_state->set_was_within_same_page(true);
2528
[email protected]3d9689372009-09-10 04:29:172529 didCommitProvisionalLoad(frame, is_new_navigation);
2530
[email protected]6b2f7a82011-04-25 19:30:512531 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:172532}
2533
[email protected]476b6f82009-09-10 21:00:592534void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312535 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592536}
2537
[email protected]3d9689372009-09-10 04:29:172538void RenderView::assignIdentifierToRequest(
2539 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2540 // Ignore
2541}
2542
2543void RenderView::willSendRequest(
2544 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2545 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302546 WebFrame* top_frame = frame->top();
2547 if (!top_frame)
2548 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512549 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2550 WebDataSource* top_data_source = top_frame->dataSource();
2551 WebDataSource* data_source =
2552 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222553
[email protected]e48869a2011-04-01 19:56:032554
[email protected]78d5cfe2011-02-04 08:43:222555 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032556 GURL new_url;
2557 if (content::GetContentClient()->renderer()->WillSendRequest(
2558 frame, request_url, &new_url)) {
2559 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222560 }
2561
[email protected]5e369672009-11-03 23:48:302562 if (data_source) {
2563 NavigationState* state = NavigationState::FromDataSource(data_source);
2564 if (state && state->is_cache_policy_override_set())
2565 request.setCachePolicy(state->cache_policy_override());
2566 }
[email protected]8a3125a712010-08-09 18:58:512567
2568 if (top_data_source) {
2569 NavigationState* state = NavigationState::FromDataSource(top_data_source);
2570 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
2571 state->set_was_prefetcher(true);
2572 }
2573
[email protected]3d9689372009-09-10 04:29:172574 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132575 request.setHasUserGesture(frame->isProcessingUserGesture());
2576
[email protected]0a8db0d2011-04-13 15:15:402577 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132578 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:492579
[email protected]85cc78c2010-05-04 18:30:092580 // Temporary metrics, see site_isolation_metrics.h
2581 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:172582}
2583
2584void RenderView::didReceiveResponse(
2585 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492586
[email protected]85cc78c2010-05-04 18:30:092587 // Temporary metrics, see site_isolation_metrics.h
2588 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
2589 identifier,
2590 response);
[email protected]fa0a3432010-03-30 16:53:492591
[email protected]3d9689372009-09-10 04:29:172592 // Only do this for responses that correspond to a provisional data source
2593 // of the top-most frame. If we have a provisional data source, then we
2594 // can't have any sub-resources yet, so we know that this response must
2595 // correspond to a frame load.
2596 if (!frame->provisionalDataSource() || frame->parent())
2597 return;
2598
2599 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082600 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172601 if (frame->isViewSourceModeEnabled())
2602 return;
2603
[email protected]65041fa2010-05-21 06:56:532604 NavigationState* navigation_state =
2605 NavigationState::FromDataSource(frame->provisionalDataSource());
2606 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082607 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532608
[email protected]972ebdff2010-06-10 22:59:072609 // Record page load flags.
2610 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2611 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572612 navigation_state->set_was_alternate_protocol_available(
2613 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072614 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082615 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092616 // Whether or not the http status code actually corresponds to an error is
2617 // only checked when the page is done loading, if |use_error_page| is
2618 // still true.
2619 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172620}
2621
2622void RenderView::didFinishResourceLoad(
2623 WebFrame* frame, unsigned identifier) {
2624 NavigationState* navigation_state =
2625 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092626 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172627 return;
2628
[email protected]06333afe2011-02-24 14:55:092629 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082630 int http_status_code = navigation_state->http_status_code();
2631 if (http_status_code == 404) {
2632 // On 404s, try a remote search page as a fallback.
2633 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:172634
[email protected]3f853a52010-09-13 19:15:082635 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092636 if (error_page_url.is_valid()) {
2637 WebURLError original_error;
2638 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:172639
[email protected]06333afe2011-02-24 14:55:092640 navigation_state->set_alt_error_page_fetcher(
2641 new AltErrorPageResourceFetcher(
2642 error_page_url, frame, original_error,
2643 NewCallback(this, &RenderView::AltErrorPageFinished)));
2644 return;
2645 }
2646 }
[email protected]3d9689372009-09-10 04:29:172647
[email protected]9966325b2011-04-18 05:00:102648 content::GetContentClient()->renderer()->ShowErrorPage(
2649 this, frame, http_status_code);
[email protected]3d9689372009-09-10 04:29:172650}
2651
2652void RenderView::didFailResourceLoad(
2653 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2654 // Ignore
2655}
2656
2657void RenderView::didLoadResourceFromMemoryCache(
2658 WebFrame* frame, const WebURLRequest& request,
2659 const WebURLResponse& response) {
2660 // Let the browser know we loaded a resource from the memory cache. This
2661 // message is needed to display the correct SSL indicators.
2662 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2663 routing_id_,
2664 request.url(),
[email protected]3d9689372009-09-10 04:29:172665 response.securityInfo()));
2666}
2667
[email protected]6069da8c2009-10-20 20:33:492668void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292669 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2670}
2671
[email protected]92771112011-01-20 00:13:022672void RenderView::didRunInsecureContent(
2673 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292674 Send(new ViewHostMsg_DidRunInsecureContent(
2675 routing_id_,
[email protected]92771112011-01-20 00:13:022676 origin.toString().utf8(),
2677 target));
[email protected]e3d60e5d2009-09-25 21:08:292678}
2679
[email protected]3d9689372009-09-10 04:29:172680void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2681 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2682}
2683
[email protected]0c882b282009-10-07 17:01:282684void RenderView::didCreateScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032685 content::GetContentClient()->renderer()->DidCreateScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282686}
2687
2688void RenderView::didDestroyScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032689 content::GetContentClient()->renderer()->DidDestroyScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282690}
2691
2692void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032693 content::GetContentClient()->renderer()->DidCreateIsolatedScriptContext(
2694 frame);
[email protected]0c882b282009-10-07 17:01:282695}
2696
[email protected]fc86daa2010-03-30 23:52:532697void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
2698 WebFrame* target,
2699 bool cross_origin,
2700 const WebString& property_name,
2701 unsigned long long event_id) {
[email protected]6cf19311f2011-04-14 23:06:022702 FOR_EACH_OBSERVER(
2703 RenderViewObserver,
2704 observers_,
2705 LogCrossFramePropertyAccess(
2706 frame, target, cross_origin, property_name, event_id));
[email protected]ab9eabac2010-03-16 16:54:102707}
2708
[email protected]3d9689372009-09-10 04:29:172709void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:142710 CheckPreferredSize();
2711}
2712
2713void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:172714 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:252715 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172716 // message.
[email protected]705243f2010-05-05 19:58:072717 if (!send_preferred_size_changes_ || !webview())
2718 return;
[email protected]dfca5acf2010-03-22 03:28:432719
[email protected]705243f2010-05-05 19:58:072720 // WebCore likes to tell us things have changed even when they haven't, so
2721 // cache the width and height and only send the IPC message when we're sure
2722 // they're different.
2723 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2724 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532725
2726 // In the presence of zoom, these sizes are still reported as if unzoomed,
2727 // so we need to adjust.
2728 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2729 size.set_width(static_cast<int>(size.width() * zoom_factor));
2730 size.set_height(static_cast<int>(size.height() * zoom_factor));
2731
[email protected]705243f2010-05-05 19:58:072732 if (size == preferred_size_)
2733 return;
[email protected]c27324b2009-11-19 22:44:292734
[email protected]705243f2010-05-05 19:58:072735 preferred_size_ = size;
2736 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2737 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172738}
2739
[email protected]143dcd592009-11-06 21:33:492740void RenderView::didChangeScrollOffset(WebFrame* frame) {
2741 StartNavStateSyncTimerIfNecessary();
2742}
2743
[email protected]8922e1f2009-10-03 05:01:262744void RenderView::reportFindInPageMatchCount(int request_id, int count,
2745 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112746 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2747 if (!count)
2748 active_match_ordinal = 0;
2749
2750 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2751 routing_id_,
2752 request_id,
2753 count,
2754 gfx::Rect(),
2755 active_match_ordinal,
2756 final_update);
2757
[email protected]8922e1f2009-10-03 05:01:262758 // If we have a message that has been queued up, then we should just replace
2759 // it. The ACK from the browser will make sure it gets sent when the browser
2760 // wants it.
2761 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262762 queued_find_reply_message_.reset(msg);
2763 } else {
2764 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112765 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262766 }
2767}
2768
2769void RenderView::reportFindInPageSelection(int request_id,
2770 int active_match_ordinal,
2771 const WebRect& selection_rect) {
2772 // Send the search result over to the browser process.
2773 Send(new ViewHostMsg_Find_Reply(routing_id_,
2774 request_id,
2775 -1,
2776 selection_rect,
2777 active_match_ordinal,
2778 false));
2779}
2780
[email protected]2b06a992010-08-21 05:48:222781void RenderView::openFileSystem(
2782 WebFrame* frame,
2783 WebFileSystem::Type type,
2784 long long size,
[email protected]d275d7a2010-11-03 01:34:492785 bool create,
[email protected]2b06a992010-08-21 05:48:222786 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082787 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222788
2789 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082790 if (origin.isEmpty()) {
2791 // Uninitialized document?
2792 callbacks->didFail(WebKit::WebFileErrorAbort);
2793 return;
2794 }
[email protected]2b06a992010-08-21 05:48:222795
[email protected]c5a272d2010-09-27 18:37:082796 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2797 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492798 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222799}
2800
[email protected]10e5cf12011-04-13 04:10:402801void RenderView::queryStorageUsageAndQuota(
2802 WebFrame* frame,
2803 WebStorageQuotaType type,
2804 WebStorageQuotaCallbacks* callbacks) {
2805 DCHECK(frame);
2806 WebSecurityOrigin origin = frame->securityOrigin();
2807 if (origin.isEmpty()) {
2808 // Uninitialized document?
2809 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2810 return;
2811 }
2812 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
2813 GURL(origin.toString()), type, callbacks);
2814}
2815
2816void RenderView::requestStorageQuota(
2817 WebFrame* frame,
2818 WebStorageQuotaType type,
2819 unsigned long long requested_size,
2820 WebStorageQuotaCallbacks* callbacks) {
2821 DCHECK(frame);
2822 WebSecurityOrigin origin = frame->securityOrigin();
2823 if (origin.isEmpty()) {
2824 // Uninitialized document?
2825 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2826 return;
2827 }
2828 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
2829 GURL(origin.toString()), type, requested_size, callbacks);
2830}
2831
[email protected]79dbc662009-09-04 05:42:512832// webkit_glue::WebPluginPageDelegate -----------------------------------------
2833
[email protected]191eb3f72010-12-21 06:27:502834webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:532835 const FilePath& file_path,
2836 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:592837 if (!PluginChannelHost::IsListening())
2838 return NULL;
2839
[email protected]00c39612010-03-06 02:53:282840 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:462841 if (in_process_plugin) {
[email protected]6876dff2010-01-15 19:38:092842#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]e8f7a182011-03-10 00:50:222843 return webkit::npapi::WebPluginDelegateImpl::Create(
2844 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092845#else
[email protected]e8f7a182011-03-10 00:50:222846 NOTIMPLEMENTED();
2847 return NULL;
[email protected]7b6616f2010-01-14 18:07:552848#endif
[email protected]f103ab72009-09-02 17:10:592849 }
2850
[email protected]4e0616e2010-05-28 14:55:532851 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592852}
2853
2854void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032855#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592856 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2857 routing_id(), window));
2858#endif
2859}
2860
2861void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032862#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592863 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2864 routing_id(), window));
2865#endif
2866 CleanupWindowInPluginMoves(window);
2867}
2868
[email protected]191eb3f72010-12-21 06:27:502869void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:592870 SchedulePluginMove(move);
2871}
2872
2873void RenderView::DidStartLoadingForPlugin() {
2874 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522875 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592876}
2877
2878void RenderView::DidStopLoadingForPlugin() {
2879 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522880 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592881}
2882
[email protected]b921cfd22010-02-25 16:57:512883WebCookieJar* RenderView::GetCookieJar() {
2884 return &cookie_jar_;
2885}
2886
initial.commit09911bf2008-07-26 23:55:292887void RenderView::SyncNavigationState() {
2888 if (!webview())
2889 return;
2890
[email protected]26aa0482009-09-30 16:55:272891 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172892 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:292893 return;
[email protected]ca948a22009-06-25 19:36:172894
2895 Send(new ViewHostMsg_UpdateState(
2896 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:292897}
2898
[email protected]7ccddb8c2009-08-04 17:36:552899GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:292900 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:552901 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:292902 // If the URL that failed was secure, then the embedding web page was not
2903 // expecting a network attacker to be able to manipulate its contents. As
2904 // we fetch alternate error pages over HTTP, we would be allowing a network
2905 // attacker to manipulate the contents of the response if we tried to use
2906 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:152907 return GURL();
initial.commit09911bf2008-07-26 23:55:292908 }
2909
2910 // Grab the base URL from the browser process.
2911 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:152912 return GURL();
initial.commit09911bf2008-07-26 23:55:292913
2914 // Strip query params from the failed URL.
2915 GURL::Replacements remove_params;
2916 remove_params.ClearUsername();
2917 remove_params.ClearPassword();
2918 remove_params.ClearQuery();
2919 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:552920 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:502921 std::string spec_to_send = url_to_send.spec();
2922 // Notify link doctor of the url truncation by sending of "?" at the end.
2923 if (failed_url.has_query())
2924 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:292925
2926 // Construct the query params to send to link doctor.
2927 std::string params(alternate_error_page_url_.query());
2928 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:502929 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:292930 params.append("&sourceid=chrome");
2931 params.append("&error=");
2932 switch (error_type) {
2933 case DNS_ERROR:
2934 params.append("dnserror");
2935 break;
2936
2937 case HTTP_404:
2938 params.append("http404");
2939 break;
2940
[email protected]5df266ac2008-10-15 19:50:132941 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:332942 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:132943 break;
2944
initial.commit09911bf2008-07-26 23:55:292945 default:
2946 NOTREACHED() << "unknown ErrorPageType";
2947 }
2948
2949 // OK, build the final url to return.
2950 GURL::Replacements link_doctor_params;
2951 link_doctor_params.SetQueryStr(params);
2952 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
2953 return url;
2954}
2955
[email protected]c50008512011-02-03 01:17:272956WebUIBindings* RenderView::GetWebUIBindings() {
2957 if (!web_ui_bindings_.get()) {
2958 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:462959 }
[email protected]c50008512011-02-03 01:17:272960 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:462961}
2962
[email protected]0fdbf8c2010-07-08 20:33:012963WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
2964 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:492965}
2966
[email protected]6069da8c2009-10-20 20:33:492967void RenderView::OnFind(int request_id, const string16& search_text,
2968 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:272969 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:492970
2971 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:492972 if (options.findNext) {
2973 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:012974 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:492975 } else {
[email protected]afdbd142010-07-10 08:01:232976 if (GetWebPluginFromPluginDocument()->startFind(
2977 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:492978 } else {
[email protected]e7c58a32010-08-13 19:47:112979 // Send "no results".
2980 Send(new ViewHostMsg_Find_Reply(routing_id_,
2981 request_id,
2982 0,
2983 gfx::Rect(),
2984 0,
2985 true));
[email protected]24a7f3c2010-03-25 08:26:492986 }
2987 }
2988 return;
2989 }
2990
[email protected]b4bb2502009-10-01 22:35:272991 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:272992 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:292993 WebFrame* search_frame = focused_frame; // start searching focused frame.
2994
2995 bool multi_frame = (frame_after_main != main_frame);
2996
2997 // If we have multiple frames, we don't want to wrap the search within the
2998 // frame, so we check here if we only have main_frame in the chain.
2999 bool wrap_within_frame = !multi_frame;
3000
[email protected]b3f2b912009-04-09 16:18:523001 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293002 bool result = false;
3003
[email protected]7830da3e2009-11-06 16:27:263004 // If something is selected when we start searching it means we cannot just
3005 // increment the current match ordinal; we need to re-generate it.
3006 WebRange current_selection = focused_frame->selectionRange();
3007
initial.commit09911bf2008-07-26 23:55:293008 do {
[email protected]dd7daa82009-08-10 05:46:453009 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593010 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293011
3012 if (!result) {
3013 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223014 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293015
3016 // Find the next frame, but skip the invisible ones.
3017 do {
3018 // What is the next frame to search? (we might be going backwards). Note
3019 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593020 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273021 search_frame->traverseNext(true) :
3022 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453023 } while (!search_frame->hasVisibleContent() &&
3024 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293025
[email protected]884db412008-11-24 23:46:503026 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223027 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293028
3029 // If we have multiple frames and we have wrapped back around to the
3030 // focused frame, we need to search it once more allowing wrap within
3031 // the frame, otherwise it will report 'no match' if the focused frame has
3032 // reported matches, but no frames after the focused_frame contain a
3033 // match for the search word(s).
3034 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453035 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593036 request_id, search_text, options, true, // Force wrapping.
3037 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293038 }
3039 }
3040
[email protected]26aa0482009-09-30 16:55:273041 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293042 } while (!result && search_frame != focused_frame);
3043
[email protected]7830da3e2009-11-06 16:27:263044 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293045 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453046 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293047 } else {
3048 // If nothing is found, set result to "0 of 0", otherwise, set it to
3049 // "-1 of 1" to indicate that we found at least one item, but we don't know
3050 // yet what is active.
3051 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3052 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293053
[email protected]4f3dc372009-02-24 00:10:293054 // If we find no matches then this will be our last status update.
3055 // Otherwise the scoping effort will send more results.
3056 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293057
[email protected]4f3dc372009-02-24 00:10:293058 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403059 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593060 request_id,
[email protected]4f3dc372009-02-24 00:10:293061 match_count,
3062 selection_rect,
3063 ordinal,
3064 final_status_update));
initial.commit09911bf2008-07-26 23:55:293065
initial.commit09911bf2008-07-26 23:55:293066 // Scoping effort begins, starting with the mainframe.
3067 search_frame = main_frame;
3068
[email protected]dd7daa82009-08-10 05:46:453069 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293070
3071 do {
3072 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453073 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293074
3075 // We don't start another scoping effort unless at least one match has
3076 // been found.
3077 if (result) {
3078 // Start new scoping request. If the scoping function determines that it
3079 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453080 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593081 search_text,
3082 options,
initial.commit09911bf2008-07-26 23:55:293083 true); // reset the tickmarks
3084 }
3085
3086 // Iterate to the next frame. The frame will not necessarily scope, for
3087 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273088 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293089 } while (search_frame != main_frame);
3090 }
3091}
3092
[email protected]24a7f3c2010-03-25 08:26:493093void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3094 WebView* view = webview();
3095 if (!view)
3096 return;
3097
3098 WebDocument doc = view->mainFrame()->document();
3099 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013100 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493101 return;
3102 }
3103
3104 bool clear_selection =
3105 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3106 if (clear_selection)
3107 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3108
3109 WebFrame* frame = view->mainFrame();
3110 while (frame) {
3111 frame->stopFinding(clear_selection);
3112 frame = frame->traverseNext(false);
3113 }
3114
3115 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3116 WebFrame* focused_frame = view->focusedFrame();
3117 if (focused_frame) {
3118 WebDocument doc = focused_frame->document();
3119 if (!doc.isNull()) {
3120 WebNode node = doc.focusedNode();
3121 if (!node.isNull())
3122 node.simulateClick();
3123 }
3124 }
3125 }
3126}
3127
3128void RenderView::OnFindReplyAck() {
3129 // Check if there is any queued up request waiting to be sent.
3130 if (queued_find_reply_message_.get()) {
3131 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423132 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493133 }
3134}
3135
[email protected]0bd753682010-12-16 18:15:523136WebPlugin* RenderView::CreatePepperPlugin(
3137 WebFrame* frame,
3138 const WebPluginParams& params,
3139 const FilePath& path,
3140 webkit::ppapi::PluginModule* pepper_module) {
3141 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:253142 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:093143}
[email protected]00152e92010-07-19 11:47:403144
[email protected]191eb3f72010-12-21 06:27:503145WebPlugin* RenderView::CreateNPAPIPlugin(
3146 WebFrame* frame,
3147 const WebPluginParams& params,
3148 const FilePath& path,
3149 const std::string& mime_type) {
3150 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:083151 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403152}
3153
[email protected]40bd6582009-12-04 23:49:513154void RenderView::OnZoom(PageZoom::Function function) {
3155 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3156 return;
3157
[email protected]258d31122010-05-09 10:59:413158 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523159
[email protected]b75b8292010-10-01 07:28:253160 double old_zoom_level = webview()->zoomLevel();
3161 double zoom_level;
3162 if (function == PageZoom::RESET) {
3163 zoom_level = 0;
3164 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3165 // Previous zoom level is a whole number, so just increment/decrement.
3166 zoom_level = old_zoom_level + function;
3167 } else {
3168 // Either the user hit the zoom factor limit and thus the zoom level is now
3169 // not a whole number, or a plugin changed it to a custom value. We want
3170 // to go to the next whole number so that the user can always get back to
3171 // 100% with the keyboard/menu.
3172 if ((old_zoom_level > 1 && function > 0) ||
3173 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453174 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253175 } else {
3176 // We're going towards 100%, so first go to the next whole number.
3177 zoom_level = static_cast<int>(old_zoom_level);
3178 }
3179 }
[email protected]40bd6582009-12-04 23:49:513180
[email protected]b75b8292010-10-01 07:28:253181 webview()->setZoomLevel(false, zoom_level);
3182 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513183}
3184
[email protected]d0b8d092010-10-25 04:05:173185void RenderView::OnSetZoomLevel(double zoom_level) {
3186 // Don't set zoom level for full-page plugin since they don't use the same
3187 // zoom settings.
3188 if (webview()->mainFrame()->document().isPluginDocument())
3189 return;
3190
3191 webview()->hidePopups();
3192 webview()->setZoomLevel(false, zoom_level);
3193 zoomLevelChanged();
3194}
3195
[email protected]9d797f32010-04-23 07:17:543196void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:253197 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543198 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293199}
3200
[email protected]41fc0322009-09-04 22:23:403201void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273202 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293203}
3204
[email protected]a697f4c2009-09-14 22:30:183205void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273206 WebString no_encoding;
3207 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183208}
3209
[email protected]dd7daa82009-08-10 05:46:453210WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
3211 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273212 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453213
3214 // xpath string can represent a frame deep down the tree (across multiple
3215 // frame DOMs).
3216 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3217 // should break into 2 xpaths
3218 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
3219
[email protected]26aa0482009-09-30 16:55:273220 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453221
3222 std::wstring xpath_remaining = xpath;
3223 while (!xpath_remaining.empty()) {
3224 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
3225 std::wstring xpath_child;
3226 if (delim_pos != std::wstring::npos) {
3227 xpath_child = xpath_remaining.substr(0, delim_pos);
3228 xpath_remaining.erase(0, delim_pos + 1);
3229 } else {
3230 xpath_remaining.swap(xpath_child);
3231 }
3232 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:293233 }
3234
[email protected]dd7daa82009-08-10 05:46:453235 return frame;
initial.commit09911bf2008-07-26 23:55:293236}
3237
[email protected]13a1e4c3c2011-02-03 21:07:093238WebNode RenderView::GetFocusedNode() const {
3239 if (!webview())
3240 return WebNode();
3241 WebFrame* focused_frame = webview()->focusedFrame();
3242 if (focused_frame) {
3243 WebDocument doc = focused_frame->document();
3244 if (!doc.isNull())
3245 return doc.focusedNode();
3246 }
3247
3248 return WebNode();
3249}
3250
[email protected]38b592902011-04-16 02:08:423251bool RenderView::IsEditableNode(const WebNode& node) {
3252 bool is_editable_node = false;
3253 if (!node.isNull()) {
3254 if (node.isContentEditable()) {
3255 is_editable_node = true;
3256 } else if (node.isElementNode()) {
3257 is_editable_node =
3258 node.toConst<WebElement>().isTextFormControlElement();
3259 }
3260 }
3261 return is_editable_node;
3262}
3263
[email protected]882b7b22010-10-05 03:34:533264void RenderView::EvaluateScript(const string16& frame_xpath,
3265 const string16& script,
3266 int id,
3267 bool notify_result) {
3268 v8::Handle<v8::Value> result;
3269 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
3270 if (web_frame)
3271 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
3272 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:293273 ListValue list;
3274 if (web_frame) {
3275 v8::HandleScope handle_scope;
3276 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3277 v8::Context::Scope context_scope(context);
[email protected]b1cf3372011-04-20 21:28:103278 V8ValueConverter converter;
3279 converter.set_allow_date(true);
3280 converter.set_allow_regexp(true);
3281 list.Set(0, converter.FromV8Value(result, context));
[email protected]81f9fe0b2010-12-07 00:35:293282 } else {
3283 list.Set(0, Value::CreateNullValue());
3284 }
3285 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:533286 }
initial.commit09911bf2008-07-26 23:55:293287}
3288
[email protected]1810e132009-03-24 23:35:483289void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083290 const std::string& css,
3291 const std::string& id) {
[email protected]1810e132009-03-24 23:35:483292 WebFrame* web_frame = GetChildFrame(frame_xpath);
3293 if (!web_frame)
3294 return;
3295
[email protected]ffaef0c2009-09-15 17:08:083296 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:483297}
3298
[email protected]882b7b22010-10-05 03:34:533299void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
3300 const string16& jscript,
3301 int id,
3302 bool notify_result) {
3303 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293304}
3305
[email protected]1810e132009-03-24 23:35:483306void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:083307 const std::string& css,
3308 const std::string& id) {
3309 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:413310
3311 // Notify RenderViewHost that css has been inserted into the frame.
3312 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:483313}
3314
[email protected]81e63782009-02-27 19:35:093315void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3316 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293317}
3318
[email protected]d0980792011-02-13 19:41:403319void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:293320 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:553321 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:273322 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293323}
3324
3325void RenderView::OnReservePageIDRange(int size_of_range) {
3326 next_page_id_ += size_of_range + 1;
3327}
3328
[email protected]59f4f2fa2011-03-23 01:00:553329void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
3330 const gfx::Point& client_point,
3331 const gfx::Point& screen_point,
3332 WebDragOperationsMask ops) {
3333 WebDragOperation operation = webview()->dragTargetDragEnter(
3334 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553335 client_point,
3336 screen_point,
3337 ops);
3338
3339 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3340}
3341
3342void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
3343 const gfx::Point& screen_point,
3344 WebDragOperationsMask ops) {
3345 WebDragOperation operation = webview()->dragTargetDragOver(
3346 client_point,
3347 screen_point,
3348 ops);
3349
3350 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3351}
3352
3353void RenderView::OnDragTargetDragLeave() {
3354 webview()->dragTargetDragLeave();
3355}
3356
3357void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3358 const gfx::Point& screen_point) {
3359 webview()->dragTargetDrop(client_point, screen_point);
3360}
3361
[email protected]e80c73b2009-04-07 23:24:583362void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3363 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253364 bool ended,
3365 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033366 if (ended) {
[email protected]26aa0482009-09-30 16:55:273367 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203368 } else {
3369 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033370 }
initial.commit09911bf2008-07-26 23:55:293371}
3372
3373void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273374 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293375}
3376
initial.commit09911bf2008-07-26 23:55:293377void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593378 webkit_preferences_ = prefs;
3379 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293380}
3381
3382void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3383 alternate_error_page_url_ = url;
3384}
3385
[email protected]b29aa74b2011-01-31 21:41:083386void RenderView::OnCustomContextMenuAction(
3387 const webkit_glue::CustomContextMenuContext& custom_context,
3388 unsigned action) {
3389 if (custom_context.is_pepper_menu)
3390 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3391 else
3392 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:333393}
3394
initial.commit09911bf2008-07-26 23:55:293395void RenderView::OnInstallMissingPlugin() {
3396 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593397 if (first_default_plugin_)
3398 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293399}
3400
[email protected]600ea402011-04-12 00:01:513401void RenderView::OnEnumerateDirectoryResponse(
3402 int id,
3403 const std::vector<FilePath>& paths) {
3404 if (!enumeration_completions_[id])
3405 return;
3406
3407 WebVector<WebString> ws_file_names(paths.size());
3408 for (size_t i = 0; i < paths.size(); ++i)
3409 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3410
3411 enumeration_completions_[id]->didChooseFile(ws_file_names);
3412 enumeration_completions_.erase(id);
3413}
3414
[email protected]cdaf8d02010-03-30 19:52:473415void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363416 // This could happen if we navigated to a different page before the user
3417 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473418 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363419 return;
3420
[email protected]cdaf8d02010-03-30 19:52:473421 WebVector<WebString> ws_file_names(paths.size());
3422 for (size_t i = 0; i < paths.size(); ++i)
3423 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463424
[email protected]cdaf8d02010-03-30 19:52:473425 if (file_chooser_completions_.front()->completion)
3426 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3427 file_chooser_completions_.pop_front();
3428
3429 // If there are more pending file chooser requests, schedule one now.
3430 if (!file_chooser_completions_.empty()) {
3431 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3432 file_chooser_completions_.front()->params));
3433 }
initial.commit09911bf2008-07-26 23:55:293434}
3435
[email protected]770dd8b2010-05-24 18:11:393436void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3437 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243438 if (send_preferred_size_changes_)
3439 return;
[email protected]9fb325e2010-05-06 18:23:243440 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393441
3442 // WebKit doesn't send a notification of the effective height of the page
3443 // changes, so poll for it.
3444 // TODO: Add a notification for this to WebKit, remove polling. After that's
3445 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
3446 // http://crbug.com/44850
3447 if (flags & kPreferredSizeHeightThisIsSlow) {
3448 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
3449 &RenderView::CheckPreferredSize);
3450 }
[email protected]0666aef2009-05-13 19:48:083451}
3452
[email protected]cda45c02010-02-25 19:28:103453void RenderView::OnDisableScrollbarsForSmallWindows(
3454 const gfx::Size& disable_scrollbar_size_limit) {
3455 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3456}
3457
[email protected]80d96fa2009-06-10 22:34:513458void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3459 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373460 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133461#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413462 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3463 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463464 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513465 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343466 renderer_prefs.thumb_inactive_color,
3467 renderer_prefs.thumb_active_color,
3468 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323469
[email protected]644d77e2010-01-27 01:03:103470 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323471 webview()->setScrollbarColors(
3472 renderer_prefs.thumb_inactive_color,
3473 renderer_prefs.thumb_active_color,
3474 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103475 webview()->setSelectionColors(
3476 renderer_prefs.active_selection_bg_color,
3477 renderer_prefs.active_selection_fg_color,
3478 renderer_prefs.inactive_selection_bg_color,
3479 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463480 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103481 }
[email protected]7a74e102009-09-03 00:16:563482#endif
[email protected]80d96fa2009-06-10 22:34:513483}
3484
[email protected]952cb702009-10-07 05:50:283485void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3486 const WebMediaPlayerAction& action) {
3487 if (webview())
3488 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563489}
3490
[email protected]dea2d372010-09-25 06:41:143491void RenderView::OnEnableAccessibility() {
3492 if (WebAccessibilityCache::accessibilityEnabled())
3493 return;
[email protected]9f4db512010-05-10 20:21:413494
[email protected]dea2d372010-09-25 06:41:143495 WebAccessibilityCache::enableAccessibility();
3496
3497 if (webview()) {
3498 // It's possible that the webview has already loaded a webpage without
3499 // accessibility being enabled. Initialize the browser's cached
3500 // accessibility tree by sending it a 'load complete' notification.
3501 postAccessibilityNotification(
3502 webview()->accessibilityObject(),
3503 WebKit::WebAccessibilityNotificationLoadComplete);
3504 }
[email protected]266eb6f2008-09-30 23:56:503505}
3506
[email protected]aef92842010-05-21 16:54:363507void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
3508 if (!accessibility_.get())
3509 return;
[email protected]02ea2f312010-09-27 17:03:363510
3511 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3512 WebAccessibilityObject root = webview()->accessibilityObject();
3513 if (!obj.isValid() || !root.isValid())
3514 return;
3515
3516 // By convention, calling SetFocus on the root of the tree should clear the
3517 // current focus. Otherwise set the focus to the new node.
3518 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
3519 webview()->clearFocusedNode();
3520 else
3521 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:363522}
3523
3524void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
3525 if (!accessibility_.get())
3526 return;
[email protected]02ea2f312010-09-27 17:03:363527
3528 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3529 if (!obj.isValid())
3530 return;
3531
3532 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:363533}
3534
[email protected]9892b472010-09-16 00:23:423535void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:513536 DCHECK(accessibility_ack_pending_);
3537 accessibility_ack_pending_ = false;
3538 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:313539}
3540
[email protected]9b18a84f2010-06-10 15:54:043541void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273542 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473543 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293544}
3545
[email protected]992db4c2011-05-12 15:37:153546void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3547 if (is_swapped_out_)
3548 return;
3549
3550 // Swap this RenderView out so the tab can navigate to a page rendered by a
3551 // different process. This involves running the unload handler and clearing
3552 // the page. Once WasSwappedOut is called, we also allow this process to exit
3553 // if there are no other active RenderViews in it.
3554
3555 // Send an UpdateState message before we get swapped out.
3556 SyncNavigationState();
3557
3558 // Synchronously run the unload handler before sending the ACK.
3559 webview()->dispatchUnloadEvent();
3560
3561 // Swap out and stop sending any IPC messages that are not ACKs.
3562 SetSwappedOut(true);
3563
3564 // Replace the page with a blank dummy URL. The unload handler will not be
3565 // run a second time, thanks to a check in FrameLoader::stopLoading.
3566 // TODO(creis): Need to add a better way to do this that avoids running the
3567 // beforeunload handler. For now, we just run it a second time silently.
3568 webview()->mainFrame()->loadHTMLString(std::string(),
3569 GURL("about:swappedout"),
3570 GURL("about:swappedout"),
3571 false);
3572
3573 // Just echo back the params in the ACK.
3574 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3575}
3576
3577void RenderView::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:293578 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3579 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3580 // in the onunload handler from appearing. For now, we're bypassing that and
3581 // calling the FrameLoader's CloseURL method directly. This should be
3582 // revisited to avoid having two ways to close a page. Having a single way
3583 // to close that can run onunload is also useful for fixing
3584 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273585 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293586
[email protected]992db4c2011-05-12 15:37:153587 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293588}
3589
3590void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573591#if defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163592 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463593 if (webview())
3594 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573595#else // defined(OS_WIN)
3596 // TODO(port): we don't support theming on non-Windows platforms yet
3597 NOTIMPLEMENTED();
3598#endif
initial.commit09911bf2008-07-26 23:55:293599}
3600
[email protected]0aa55312008-10-17 21:53:083601void RenderView::OnDisassociateFromPopupCount() {
3602 if (decrement_shared_popup_at_destruction_)
3603 shared_popup_counter_->data--;
3604 shared_popup_counter_ = new SharedRenderViewCounter(0);
3605 decrement_shared_popup_at_destruction_ = false;
3606}
3607
[email protected]15d79e12009-08-02 19:23:453608bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3609 const WebURLError& error,
3610 bool replace) {
3611 // We only show alternate error pages in the main frame. They are
3612 // intended to assist the user when navigating, so there is not much
3613 // value in showing them for failed subframes. Ideally, we would be
3614 // able to use the TYPED transition type for this, but that flag is
3615 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453616 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453617 return false;
3618
3619 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373620 // connection failure.
[email protected]15d79e12009-08-02 19:23:453621 int ec = error.reason;
3622 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3623 ec != net::ERR_CONNECTION_FAILED &&
3624 ec != net::ERR_CONNECTION_REFUSED &&
3625 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373626 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453627 return false;
3628
3629 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553630 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453631 if (!error_page_url.is_valid())
3632 return false;
3633
3634 // Load an empty page first so there is an immediate response to the error,
3635 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453636 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363637 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453638 error.unreachableURL,
3639 replace);
3640
3641 // Now, create a fetcher for the error page and associate it with the data
3642 // source we just created via the LoadHTMLString call. That way if another
3643 // navigation occurs, the fetcher will get destroyed.
3644 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453645 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453646 navigation_state->set_alt_error_page_fetcher(
3647 new AltErrorPageResourceFetcher(
3648 error_page_url, frame, error,
3649 NewCallback(this, &RenderView::AltErrorPageFinished)));
3650 return true;
3651}
3652
[email protected]15d79e12009-08-02 19:23:453653void RenderView::AltErrorPageFinished(WebFrame* frame,
3654 const WebURLError& original_error,
3655 const std::string& html) {
3656 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093657 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553658 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093659 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453660}
3661
[email protected]30f75e62009-02-25 22:01:003662void RenderView::OnMoveOrResizeStarted() {
3663 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473664 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003665}
3666
[email protected]30f75e62009-02-25 22:01:003667void RenderView::OnResize(const gfx::Size& new_size,
3668 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103669 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473670 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103671 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203672 webview()->mainFrame()->setCanHaveScrollbars(
3673 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103674 }
3675 }
3676
[email protected]30f75e62009-02-25 22:01:003677 RenderWidget::OnResize(new_size, resizer_rect);
3678}
[email protected]0aa477bd2009-03-23 22:21:433679
[email protected]00c39612010-03-06 02:53:283680void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013681 // Notify the pepper plugins that we started painting.
3682 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283683}
3684
3685void RenderView::DidFlushPaint() {
3686 // Notify any pepper plugins that we painted. This will call into the plugin,
3687 // and we it may ask to close itself as a result. This will, in turn, modify
3688 // our set, possibly invalidating the iterator. So we iterate on a copy that
3689 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013690 pepper_delegate_.ViewFlushedPaint();
3691
[email protected]00c39612010-03-06 02:53:283692 WebFrame* main_frame = webview()->mainFrame();
3693
3694 // If we have a provisional frame we are between the start and commit stages
3695 // of loading and we don't want to save stats.
3696 if (!main_frame->provisionalDataSource()) {
3697 WebDataSource* ds = main_frame->dataSource();
3698 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3699 DCHECK(navigation_state);
3700
[email protected]05c8e502010-08-15 15:13:523701 // TODO(jar): The following code should all be inside a method, probably in
3702 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283703 Time now = Time::Now();
3704 if (navigation_state->first_paint_time().is_null()) {
3705 navigation_state->set_first_paint_time(now);
3706 }
3707 if (navigation_state->first_paint_after_load_time().is_null() &&
3708 !navigation_state->finish_load_time().is_null()) {
3709 navigation_state->set_first_paint_after_load_time(now);
3710 }
3711 }
3712}
3713
[email protected]65225772011-05-12 21:10:243714void RenderView::OnViewContextSwapBuffersComplete() {
3715 RenderWidget::OnSwapBuffersComplete();
3716}
3717
3718void RenderView::OnViewContextSwapBuffersAborted() {
3719 RenderWidget::OnSwapBuffersAborted();
3720}
3721
[email protected]719b36f2010-12-22 20:36:463722webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:153723 const gfx::Rect& paint_bounds,
3724 TransportDIB** dib,
3725 gfx::Rect* location,
3726 gfx::Rect* clip) {
3727 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
3728 paint_bounds, dib, location, clip);
3729}
3730
[email protected]bcaf2272011-02-15 15:29:433731gfx::Point RenderView::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:523732 WebKit::WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:433733 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523734}
3735
[email protected]05d478752009-04-08 23:38:163736void RenderView::OnClearFocusedNode() {
3737 if (webview())
[email protected]26aa0482009-09-30 16:55:273738 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163739}
3740
[email protected]699ab0d2009-04-23 23:19:143741void RenderView::OnSetBackground(const SkBitmap& background) {
3742 if (webview())
[email protected]b4bb2502009-10-01 22:35:273743 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143744
3745 SetBackground(background);
3746}
3747
[email protected]8c66c5a2009-07-22 17:26:343748void RenderView::OnSetActive(bool active) {
3749 if (webview())
[email protected]b4bb2502009-10-01 22:35:273750 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263751
3752#if defined(OS_MACOSX)
3753 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3754 for (plugin_it = plugin_delegates_.begin();
3755 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3756 (*plugin_it)->SetWindowFocus(active);
3757 }
3758#endif
[email protected]8c66c5a2009-07-22 17:26:343759}
3760
[email protected]6ce7abc52010-02-02 18:40:143761#if defined(OS_MACOSX)
3762void RenderView::OnSetWindowVisibility(bool visible) {
3763 // Inform plugins that their container has changed visibility.
3764 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3765 for (plugin_it = plugin_delegates_.begin();
3766 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3767 (*plugin_it)->SetContainerVisibility(visible);
3768 }
3769}
[email protected]1e6e3c992010-02-08 15:52:133770
[email protected]4d51d5bf2010-07-26 18:48:263771void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
3772 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:133773 // Inform plugins that their window's frame has changed.
3774 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3775 for (plugin_it = plugin_delegates_.begin();
3776 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3777 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3778 }
3779}
[email protected]935d63d2010-10-15 23:31:553780
[email protected]b7f75862011-01-21 21:15:133781void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:553782 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:133783 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:553784 // applies to it or not, so inform all the delegates.
3785 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3786 for (plugin_it = plugin_delegates_.begin();
3787 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:133788 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:553789 }
3790}
[email protected]6ce7abc52010-02-02 18:40:143791#endif // OS_MACOSX
3792
[email protected]9892b472010-09-16 00:23:423793void RenderView::postAccessibilityNotification(
3794 const WebAccessibilityObject& obj,
3795 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:143796 if (!accessibility_.get() && webview()) {
3797 // Load complete should be our first notification sent.
3798 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
3799 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
3800 return;
3801
3802 // Create and initialize our accessibility cache
3803 accessibility_.reset(WebAccessibilityCache::create());
3804 accessibility_->initialize(webview());
3805 }
3806
[email protected]a3fa4f92010-09-30 22:19:333807 if (!accessibility_->isCached(obj)) {
3808 // The browser doesn't know about objects that are not in the cache. Send a
3809 // children change for the first accestor that actually is in the cache.
3810 WebAccessibilityObject parent = obj;
3811 while (parent.isValid() && !accessibility_->isCached(parent))
3812 parent = parent.parentObject();
3813
3814 DCHECK(parent.isValid() && accessibility_->isCached(parent));
3815 if (!parent.isValid())
3816 return;
3817 postAccessibilityNotification(
3818 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
3819
3820 // The parent's children change takes care of the child's children change.
3821 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
3822 return;
3823 }
3824
[email protected]dea2d372010-09-25 06:41:143825 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:513826 RendererAccessibilityNotification acc_notification;
3827 acc_notification.id = accessibility_->addOrGetId(obj);
[email protected]a527a022011-02-10 02:32:363828 acc_notification.type = notification;
[email protected]54ec7f82010-10-21 22:32:513829 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:483830 return;
3831
[email protected]fffaf972011-03-24 01:34:353832 ViewHostMsg_AccessibilityNotification_Type::Value temp;
[email protected]a527a022011-02-10 02:32:363833 if (!WebAccessibilityNotificationToViewHostMsg(notification, &temp))
[email protected]54ec7f82010-10-21 22:32:513834 return;
[email protected]54ec7f82010-10-21 22:32:513835
3836 // Discard duplicate accessibility notifications.
3837 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
3838 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
3839 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:423840 return;
[email protected]54ec7f82010-10-21 22:32:513841 }
[email protected]9892b472010-09-16 00:23:423842 }
[email protected]54ec7f82010-10-21 22:32:513843 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:483844
[email protected]54ec7f82010-10-21 22:32:513845 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
3846 // When no accessibility notifications are in-flight post a task to send
3847 // the notifications to the browser. We use PostTask so that we can queue
3848 // up additional notifications.
3849 MessageLoop::current()->PostTask(
3850 FROM_HERE,
3851 accessibility_method_factory_.NewRunnableMethod(
3852 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:313853 }
[email protected]520cb7d72010-08-31 11:54:313854}
3855
[email protected]446705872009-09-10 07:22:483856void RenderView::OnSetEditCommandsForNextKeyEvent(
3857 const EditCommands& edit_commands) {
3858 edit_commands_ = edit_commands;
3859}
3860
[email protected]60c42a8c72009-10-09 04:08:593861void RenderView::Close() {
3862 // We need to grab a pointer to the doomed WebView before we destroy it.
3863 WebView* doomed = webview();
3864 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:493865 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:593866}
3867
[email protected]446705872009-09-10 07:22:483868void RenderView::DidHandleKeyEvent() {
3869 edit_commands_.clear();
3870}
3871
[email protected]6a8ddba52010-09-05 04:38:063872void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:513873 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:063874}
3875
[email protected]941e4552010-02-01 21:23:433876void RenderView::OnWasHidden() {
3877 RenderWidget::OnWasHidden();
3878
[email protected]a6939ca42011-02-18 17:58:073879 if (webview()) {
3880 webview()->settings()->setMinimumTimerInterval(
3881 webkit_glue::kBackgroundTabTimerInterval);
3882 }
3883
3884#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:433885 // Inform plugins that their container is no longer visible.
3886 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3887 for (plugin_it = plugin_delegates_.begin();
3888 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3889 (*plugin_it)->SetContainerVisibility(false);
3890 }
[email protected]a6939ca42011-02-18 17:58:073891#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:433892}
3893
3894void RenderView::OnWasRestored(bool needs_repainting) {
3895 RenderWidget::OnWasRestored(needs_repainting);
3896
[email protected]a6939ca42011-02-18 17:58:073897 if (webview()) {
3898 webview()->settings()->setMinimumTimerInterval(
3899 webkit_glue::kForegroundTabTimerInterval);
3900 }
3901
3902#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:433903 // Inform plugins that their container is now visible.
3904 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3905 for (plugin_it = plugin_delegates_.begin();
3906 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3907 (*plugin_it)->SetContainerVisibility(true);
3908 }
[email protected]784ea1ab2010-09-18 00:02:343909#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:073910}
[email protected]1e6e3c992010-02-08 15:52:133911
[email protected]65225772011-05-12 21:10:243912bool RenderView::SupportsAsynchronousSwapBuffers() {
3913 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
3914 if (!context)
3915 return false;
3916 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
3917 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
3918 std::string::npos;
3919}
3920
[email protected]1e6e3c992010-02-08 15:52:133921void RenderView::OnSetFocus(bool enable) {
3922 RenderWidget::OnSetFocus(enable);
3923
[email protected]7d3c02c2010-05-05 23:10:313924 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:073925 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:133926 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3927 for (plugin_it = plugin_delegates_.begin();
3928 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:343929#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:313930 // RenderWidget's call to setFocus can cause the underlying webview's
3931 // activation state to change just like a call to setIsActive.
3932 if (enable)
3933 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:343934#endif
[email protected]7d3c02c2010-05-05 23:10:313935 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:133936 }
[email protected]589621b2010-09-23 22:01:073937
3938 // Notify all Pepper plugins.
3939 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:133940 }
3941}
[email protected]941e4552010-02-01 21:23:433942
[email protected]43f28f832010-02-03 02:28:483943#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:133944void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
3945 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
3946 focused, plugin_id);
3947 Send(msg);
3948}
3949
3950void RenderView::StartPluginIme() {
3951 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:553952 // This message can be sent during event-handling, and needs to be delivered
3953 // within that context.
3954 msg->set_unblock(true);
3955 Send(msg);
3956}
3957
[email protected]ea04a4e12010-04-15 00:58:033958gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:233959 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:483960 gfx::PluginWindowHandle window = NULL;
3961 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:233962 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:113963 if (window) {
3964 fake_plugin_window_handles_.insert(window);
3965 }
[email protected]43f28f832010-02-03 02:28:483966 return window;
3967}
3968
3969void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:113970 if (window && fake_plugin_window_handles_.find(window) !=
3971 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:483972 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:113973 fake_plugin_window_handles_.erase(window);
3974 }
[email protected]43f28f832010-02-03 02:28:483975}
3976
[email protected]44ce0b12010-03-12 16:45:333977void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
3978 int32 width,
3979 int32 height,
3980 uint64 io_surface_identifier) {
3981 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:483982 routing_id(), window, width, height, io_surface_identifier));
3983}
3984
[email protected]44ce0b12010-03-12 16:45:333985void RenderView::AcceleratedSurfaceSetTransportDIB(
3986 gfx::PluginWindowHandle window,
3987 int32 width,
3988 int32 height,
3989 TransportDIB::Handle transport_dib) {
3990 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:073991 routing_id(), window, width, height, transport_dib));
3992}
3993
[email protected]44ce0b12010-03-12 16:45:333994TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
3995 size_t size) {
[email protected]1aef98132010-02-23 18:00:073996 TransportDIB::Handle dib_handle;
3997 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:383998 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:073999 return dib_handle;
4000 // Return an invalid handle if Send() fails.
4001 return TransportDIB::DefaultHandleValue();
4002}
4003
[email protected]44ce0b12010-03-12 16:45:334004void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074005 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4006}
4007
[email protected]44ce0b12010-03-12 16:45:334008void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144009 gfx::PluginWindowHandle window, uint64 surface_id) {
4010 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4011 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484012}
4013#endif
[email protected]58c321d2010-02-19 12:11:284014
[email protected]cdaf8d02010-03-30 19:52:474015bool RenderView::ScheduleFileChooser(
4016 const ViewHostMsg_RunFileChooser_Params& params,
4017 WebFileChooserCompletion* completion) {
4018 static const size_t kMaximumPendingFileChooseRequests = 4;
4019 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4020 // This sanity check prevents too many file choose requests from getting
4021 // queued which could DoS the user. Getting these is most likely a
4022 // programming error (there are many ways to DoS the user so it's not
4023 // considered a "real" security check), either in JS requesting many file
4024 // choosers to pop up, or in a plugin.
4025 //
4026 // TODO(brettw) we might possibly want to require a user gesture to open
4027 // a file picker, which will address this issue in a better way.
4028 return false;
4029 }
4030
4031 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4032 new PendingFileChooser(params, completion)));
4033 if (file_chooser_completions_.size() == 1) {
4034 // Actually show the browse dialog when this is the first request.
4035 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4036 }
4037 return true;
4038}
4039
[email protected]0ff0ff32010-12-21 19:34:424040WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514041 if (!geolocation_dispatcher_)
4042 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4043 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254044}
[email protected]61c9f032010-03-31 23:04:194045
[email protected]638694c2010-08-04 22:24:114046WebKit::WebSpeechInputController* RenderView::speechInputController(
4047 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:514048 if (!speech_input_dispatcher_)
4049 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
4050 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114051}
4052
[email protected]57ead352010-08-11 14:42:534053WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514054 if (!device_orientation_dispatcher_)
4055 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4056 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534057}
4058
[email protected]b75b8292010-10-01 07:28:254059void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
4060 // For now, don't remember plugin zoom values. We don't want to mix them with
4061 // normal web content (i.e. a fixed layout plugin would usually want them
4062 // different).
4063 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4064
[email protected]b75b8292010-10-01 07:28:254065 int minimum_percent = static_cast<int>(
4066 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4067 int maximum_percent = static_cast<int>(
4068 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254069
4070 Send(new ViewHostMsg_UpdateZoomLimits(
4071 routing_id_, minimum_percent, maximum_percent, remember));
4072}
4073
4074void RenderView::zoomLevelChanged() {
4075 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4076
[email protected]b75b8292010-10-01 07:28:254077 // Tell the browser which url got zoomed so it can update the menu and the
4078 // saved values if necessary
4079 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:414080 routing_id_, webview()->zoomLevel(), remember,
4081 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:254082}
4083
[email protected]a6d36cc2011-02-23 00:39:484084void RenderView::registerProtocolHandler(const WebString& scheme,
4085 const WebString& base_url,
4086 const WebString& url,
4087 const WebString& title) {
4088 GURL base(base_url);
4089 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4090 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4091 return;
4092 }
4093 RenderThread::current()->Send(
4094 new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4095 UTF16ToUTF8(scheme),
4096 absolute_url,
4097 title));
4098}
4099
[email protected]8079b362010-05-07 18:37:454100bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194101 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454102 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194103 if (frame->parent() != NULL)
4104 return false;
4105
[email protected]f0a3d0b2010-08-06 22:51:534106 // Navigations initiated within Webkit are not sent out to the external host
4107 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274108 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134109 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534110 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134111 // 3. Reloads/form submits/back forward navigations
[email protected]f0a3d0b2010-08-06 22:51:534112 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
4113 return false;
4114
[email protected]2fc22d12010-12-02 23:08:164115 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324116 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014117 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164118 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014119 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324120 // The opener relationship between the new window and the parent allows the
4121 // new window to script the parent and vice versa. This is not allowed if
4122 // the origins of the two domains are different. This can be treated as a
4123 // top level navigation and routed back to the host.
4124 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274125 if (!opener) {
[email protected]86965362011-04-21 18:42:514126 return true;
[email protected]d19ea342011-04-20 20:31:134127 } else {
4128 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324129 return true;
4130 }
4131 }
[email protected]61c9f032010-03-31 23:04:194132 return false;
4133}
[email protected]2b06a992010-08-21 05:48:224134
[email protected]27a9ef32010-09-10 04:06:244135void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
4136 IPC::PlatformFileForTransit file_for_transit,
4137 int message_id) {
4138 pepper_delegate_.OnAsyncFileOpened(
4139 error_code,
4140 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4141 message_id);
4142}
[email protected]caf706f2010-10-26 17:54:084143
[email protected]2b657fd2011-04-18 16:00:474144void RenderView::OnPpapiBrokerChannelCreated(
4145 int request_id,
4146 base::ProcessHandle broker_process_handle,
4147 IPC::ChannelHandle handle) {
4148 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4149 broker_process_handle,
4150 handle);
[email protected]eb415bf0e2011-04-14 02:45:424151}
4152
[email protected]caf706f2010-10-26 17:54:084153#if defined(OS_MACOSX)
4154void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154155 if (external_popup_menu_ == NULL) {
4156 // Crash reports from the field indicate that we can be notified with a
4157 // NULL external popup menu (we probably get notified twice).
4158 // If you hit this please file a bug against jcivelli and include the page
4159 // and steps to repro.
4160 NOTREACHED();
4161 return;
4162 }
[email protected]caf706f2010-10-26 17:54:084163 external_popup_menu_->DidSelectItem(selected_index);
4164 external_popup_menu_.reset();
4165}
4166#endif
[email protected]bb461532010-11-26 21:50:234167
[email protected]1b4209f2011-01-07 00:25:404168#if defined(ENABLE_FLAPPER_HACKS)
4169void RenderView::OnConnectTcpACK(
4170 int request_id,
4171 IPC::PlatformFileForTransit socket_for_transit,
4172 const PP_Flash_NetAddress& local_addr,
4173 const PP_Flash_NetAddress& remote_addr) {
4174 pepper_delegate_.OnConnectTcpACK(
4175 request_id,
4176 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4177 local_addr,
4178 remote_addr);
4179}
4180#endif
[email protected]a6097f42011-01-10 08:50:514181
[email protected]b29aa74b2011-01-31 21:41:084182void RenderView::OnContextMenuClosed(
4183 const webkit_glue::CustomContextMenuContext& custom_context) {
4184 if (custom_context.is_pepper_menu)
4185 pepper_delegate_.OnContextMenuClosed(custom_context);
4186 else
4187 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104188}
[email protected]232a5812011-03-04 22:42:084189
4190void RenderView::OnNetworkStateChanged(bool online) {
4191 WebNetworkStateNotifier::setOnLine(online);
4192}