blob: c69bbb445118b05e18999babbfc3a81dbf608fb1 [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"
[email protected]318bf5802011-08-08 17:12:4121#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2823#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2624#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2225#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1026#include "content/common/appcache/appcache_dispatcher.h"
[email protected]9966325b2011-04-18 05:00:1027#include "content/common/bindings_policy.h"
[email protected]127dd582011-03-16 21:32:1028#include "content/common/clipboard_messages.h"
[email protected]db803aae2011-03-05 02:00:4229#include "content/common/content_constants.h"
[email protected]9966325b2011-04-18 05:00:1030#include "content/common/content_switches.h"
[email protected]37666cf2011-03-13 21:51:4231#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5532#include "content/common/drag_messages.h"
[email protected]7ef40ffe12011-03-08 05:05:2833#include "content/common/file_system/file_system_dispatcher.h"
34#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]c3113022011-04-16 03:26:3035#include "content/common/json_value_serializer.h"
[email protected]7f070d42011-03-09 20:25:3236#include "content/common/notification_service.h"
[email protected]127dd582011-03-16 21:32:1037#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0038#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4039#include "content/common/quota_dispatcher.h"
[email protected]60916042011-03-19 00:43:3640#include "content/common/renderer_preferences.h"
[email protected]940895b2011-08-20 00:50:0541#include "content/common/request_extra_data.h"
[email protected]9966325b2011-04-18 05:00:1042#include "content/common/url_constants.h"
[email protected]778574e2011-03-21 22:03:5043#include "content/common/view_messages.h"
[email protected]21d61e52011-03-18 19:08:2544#include "content/renderer/content_renderer_client.h"
[email protected]82622452011-07-22 09:57:2045#include "content/renderer/devtools_agent.h"
[email protected]230b7ef2011-03-16 22:30:1946#include "content/renderer/device_orientation_dispatcher.h"
[email protected]8f6a3b852011-07-19 16:48:5647#include "content/renderer/mhtml_generator.h"
[email protected]55722152011-03-22 01:33:5348#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1949#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4050#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]921f1592011-03-18 00:41:0251#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0852#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3753#include "content/renderer/media/audio_renderer_impl.h"
[email protected]ab2c4732011-07-20 19:57:4054#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:4055#include "content/renderer/media/render_media_log.h"
[email protected]921f1592011-03-18 00:41:0256#include "content/renderer/navigation_state.h"
[email protected]230b7ef2011-03-16 22:30:1957#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3758#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3559#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0560#include "content/renderer/render_process.h"
[email protected]10e6ab572011-04-14 23:42:0061#include "content/renderer/render_thread.h"
[email protected]60916042011-03-19 00:43:3662#include "content/renderer/render_view_observer.h"
63#include "content/renderer/render_view_visitor.h"
[email protected]2cff0052011-03-18 16:51:4464#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:0165#include "content/renderer/renderer_webapplicationcachehost_impl.h"
66#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1967#include "content/renderer/speech_input_dispatcher.h"
[email protected]b1cf3372011-04-20 21:28:1068#include "content/renderer/v8_value_converter.h"
[email protected]663bd9e2011-03-21 01:07:0169#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3570#include "content/renderer/webplugin_delegate_proxy.h"
71#include "content/renderer/websharedworker_proxy.h"
72#include "content/renderer/webworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4973#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4174#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2775#include "media/base/message_loop_factory_impl.h"
initial.commit09911bf2008-07-26 23:55:2976#include "net/base/escape.h"
77#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0478#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5779#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3780#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
81#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
82#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
83#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3784#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
85#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
86#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
87#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3788#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
89#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
90#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
91#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
92#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
93#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
94#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
95#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
96#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:5797#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]69f110d62011-03-17 19:01:1498#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:3799#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19100#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37101#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
102#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
103#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
104#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
105#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17111#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37112#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
113#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
114#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40115#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]8bd0fe62011-01-17 06:44:37116#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26124#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c4a9e932011-03-05 04:05:55125#include "ui/base/message_box_flags.h"
[email protected]08397d52011-02-05 01:53:38126#include "ui/gfx/native_widget_types.h"
127#include "ui/gfx/point.h"
128#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55129#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04130#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43131#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24132#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19133#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59134#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24135#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24136#include "webkit/glue/glue_serialize.h"
[email protected]85cc78c2010-05-04 18:30:09137#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26138#include "webkit/glue/password_form_dom_manager.h"
[email protected]7a4de7a62010-08-17 18:38:24139#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29140#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07141#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29142#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17143#include "webkit/glue/webmediaplayer_impl.h"
[email protected]b00ba702011-08-17 01:41:03144#include "webkit/glue/weburlloader_impl.h"
[email protected]191eb3f72010-12-21 06:27:50145#include "webkit/plugins/npapi/default_plugin_shared.h"
146#include "webkit/plugins/npapi/plugin_list.h"
147#include "webkit/plugins/npapi/webplugin_delegate.h"
148#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
149#include "webkit/plugins/npapi/webplugin_impl.h"
150#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52151#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29152
[email protected]6c8afae52009-01-22 02:24:57153#if defined(OS_WIN)
154// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57155// * theming
[email protected]08397d52011-02-05 01:53:38156#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03157#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37158#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51159#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33160#elif defined(OS_MACOSX)
161#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57162#endif
163
[email protected]c7287a92009-11-04 20:06:15164using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42165using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08166using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21167using WebKit::WebApplicationCacheHost;
168using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26169using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41170using WebKit::WebColor;
171using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59172using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44173using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51174using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55175using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28176using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00177using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58178using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25179using WebKit::WebDragOperation;
180using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51181using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51182using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08183using WebKit::WebExternalPopupMenu;
184using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47185using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22186using WebKit::WebFileSystem;
187using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49188using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59189using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48190using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45191using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17192using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13193using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41194using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50195using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17196using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28197using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17198using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28199using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28200using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51201using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19202using WebKit::WebPageSerializer;
203using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17204using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40205using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49206using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09207using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52208using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59209using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51210using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52211using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40212using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35213using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29214using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17215using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59216using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42217using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02218using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34219using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40220using WebKit::WebStorageQuotaCallbacks;
221using WebKit::WebStorageQuotaError;
222using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28223using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51224using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52225using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28226using WebKit::WebURL;
227using WebKit::WebURLError;
228using WebKit::WebURLRequest;
229using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28230using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03231using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28232using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26233using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43234using WebKit::WebWorker;
235using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26236using appcache::WebApplicationCacheHostImpl;
237using base::Time;
238using base::TimeDelta;
239using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26240using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26241using webkit_glue::PasswordForm;
242using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23243using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26244using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33245
initial.commit09911bf2008-07-26 23:55:29246//-----------------------------------------------------------------------------
247
[email protected]3354d3e2010-06-10 19:53:02248typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49249static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02250
[email protected]882daa92009-11-05 16:31:31251// Time, in seconds, we delay before sending content state changes (such as form
252// state and scroll position) to the browser. We delay sending changes to avoid
253// spamming the browser.
254// To avoid having tab/session restore require sending a message to get the
255// current content state during tab closing we use a shorter timeout for the
256// foreground renderer. This means there is a small window of time from which
257// content state is modified and not sent to session restore, but this is
258// better than having to wake up all renderers during shutdown.
259static const int kDelaySecondsForContentStateSyncHidden = 5;
260static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29261
[email protected]0aa55312008-10-17 21:53:08262// The maximum number of popups that can be spawned from one page.
263static const int kMaximumNumberOfUnacknowledgedPopups = 25;
264
[email protected]c514d6372011-08-16 22:54:44265static const float kScalingIncrement = 0.1f;
266
[email protected]726985e22009-06-18 21:09:28267static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
268 WebVector<WebURL> urls;
269 ds->redirectChain(urls);
270 result->reserve(urls.size());
271 for (size_t i = 0; i < urls.size(); ++i)
272 result->push_back(urls[i]);
273}
274
[email protected]54ec7f82010-10-21 22:32:51275static bool WebAccessibilityNotificationToViewHostMsg(
276 WebAccessibilityNotification notification,
[email protected]fffaf972011-03-24 01:34:35277 ViewHostMsg_AccessibilityNotification_Type::Value* type) {
[email protected]54ec7f82010-10-21 22:32:51278 switch (notification) {
279 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
[email protected]fffaf972011-03-24 01:34:35280 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51281 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
282 break;
283 case WebKit::WebAccessibilityNotificationChildrenChanged:
[email protected]fffaf972011-03-24 01:34:35284 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51285 NOTIFICATION_TYPE_CHILDREN_CHANGED;
286 break;
287 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
[email protected]fffaf972011-03-24 01:34:35288 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51289 NOTIFICATION_TYPE_FOCUS_CHANGED;
290 break;
291 case WebKit::WebAccessibilityNotificationLoadComplete:
[email protected]fffaf972011-03-24 01:34:35292 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51293 NOTIFICATION_TYPE_LOAD_COMPLETE;
294 break;
295 case WebKit::WebAccessibilityNotificationValueChanged:
[email protected]fffaf972011-03-24 01:34:35296 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51297 NOTIFICATION_TYPE_VALUE_CHANGED;
298 break;
299 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
[email protected]fffaf972011-03-24 01:34:35300 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51301 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
302 break;
303 default:
304 // TODO(ctguil): Support additional webkit notifications.
305 return false;
306 }
307 return true;
308}
309
[email protected]6a8f5112011-05-13 16:38:44310// If |data_source| is non-null and has a NavigationState associated with it,
311// the AltErrorPageResourceFetcher is reset.
312static void StopAltErrorPageFetcher(WebDataSource* data_source) {
313 if (data_source) {
314 NavigationState* state = NavigationState::FromDataSource(data_source);
315 if (state)
316 state->set_alt_error_page_fetcher(NULL);
317 }
318}
319
initial.commit09911bf2008-07-26 23:55:29320///////////////////////////////////////////////////////////////////////////////
321
[email protected]60c42a8c72009-10-09 04:08:59322int32 RenderView::next_page_id_ = 1;
323
[email protected]cdaf8d02010-03-30 19:52:47324struct RenderView::PendingFileChooser {
325 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
326 WebFileChooserCompletion* c)
327 : params(p),
328 completion(c) {
329 }
330 ViewHostMsg_RunFileChooser_Params params;
331 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
332};
333
[email protected]2fab253a2009-08-17 23:00:59334RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51335 gfx::NativeViewId parent_hwnd,
336 int32 opener_id,
337 const RendererPreferences& renderer_prefs,
338 const WebPreferences& webkit_prefs,
339 SharedRenderViewCounter* counter,
340 int32 routing_id,
341 int64 session_storage_namespace_id,
342 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12343 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51344 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02345 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09346 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02347 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24348 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21349 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02350 opened_by_user_gesture_(true),
351 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24352 page_id_(-1),
353 last_page_id_sent_to_browser_(-1),
[email protected]3cc72b12010-03-18 23:03:00354 history_list_offset_(-1),
355 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02356 target_url_status_(TARGET_NONE),
[email protected]dd6afca2011-08-13 03:44:31357 cached_is_main_frame_pinned_to_left_(false),
358 cached_is_main_frame_pinned_to_right_(false),
359 cached_has_main_frame_horizontal_scrollbar_(false),
360 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]18ca9a6b2010-06-02 19:05:18361 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]54ec7f82010-10-21 22:32:51362 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02363 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51364 geolocation_dispatcher_(NULL),
365 speech_input_dispatcher_(NULL),
366 device_orientation_dispatcher_(NULL),
[email protected]54ec7f82010-10-21 22:32:51367 accessibility_ack_pending_(false),
[email protected]cae8c8492011-03-03 11:12:18368 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41369 devtools_agent_(NULL),
[email protected]4fb60142011-08-09 02:22:08370 session_storage_namespace_id_(session_storage_namespace_id),
371 handling_select_range_(false) {
[email protected]676126f72011-01-15 00:03:51372 routing_id_ = routing_id;
373 if (opener_id != MSG_ROUTING_NONE)
374 opener_id_ = opener_id;
375
[email protected]11fee2332011-03-29 20:36:35376 webwidget_ = WebView::create(this);
377
[email protected]676126f72011-01-15 00:03:51378 if (counter) {
379 shared_popup_counter_ = counter;
380 shared_popup_counter_->data++;
381 decrement_shared_popup_at_destruction_ = true;
382 } else {
383 shared_popup_counter_ = new SharedRenderViewCounter(0);
384 decrement_shared_popup_at_destruction_ = false;
385 }
386
387 notification_provider_ = new NotificationProvider(this);
388
[email protected]676126f72011-01-15 00:03:51389 render_thread_->AddRoute(routing_id_, this);
390 // Take a reference on behalf of the RenderThread. This will be balanced
391 // when we receive ViewMsg_Close.
392 AddRef();
393
394 // If this is a popup, we must wait for the CreatingNew_ACK message before
395 // completing initialization. Otherwise, we can finish it now.
396 if (opener_id == MSG_ROUTING_NONE) {
397 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55398 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51399 }
400
[email protected]34c61bd52011-05-02 19:38:33401 g_view_map.Get().insert(std::make_pair(webview(), this));
402 webkit_preferences_.Apply(webview());
403 webview()->initializeMainFrame(this);
404 if (!frame_name.empty())
405 webview()->mainFrame()->setName(frame_name);
406 webview()->settings()->setMinimumTimerInterval(
407 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
408 webkit_glue::kForegroundTabTimerInterval);
409
410 OnSetRendererPrefs(renderer_prefs);
411
[email protected]676126f72011-01-15 00:03:51412 host_window_ = parent_hwnd;
413
414 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]676126f72011-01-15 00:03:51415 if (command_line.HasSwitch(switches::kEnableAccessibility))
416 WebAccessibilityCache::enableAccessibility();
417
[email protected]a026daa2011-04-20 15:49:51418#if defined(ENABLE_P2P_APIS)
[email protected]09b36762011-07-19 01:19:12419 p2p_socket_dispatcher_ = new P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51420#endif
[email protected]cae8c8492011-03-03 11:12:18421
[email protected]8f6a3b852011-07-19 16:48:56422 new MHTMLGenerator(this);
423
[email protected]c5c1d6d2011-07-28 18:42:41424 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20425
[email protected]ab2c4732011-07-20 19:57:40426 if (command_line.HasSwitch(switches::kEnableMediaStream)) {
427 media_stream_impl_ = new MediaStreamImpl(
428 RenderThread::current()->video_capture_impl_manager());
429 }
430
[email protected]e48869a2011-04-01 19:56:03431 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29432}
433
434RenderView::~RenderView() {
[email protected]d466b8a2011-07-15 21:48:03435 history_page_ids_.clear();
436
[email protected]0aa55312008-10-17 21:53:08437 if (decrement_shared_popup_at_destruction_)
438 shared_popup_counter_->data--;
439
[email protected]a1128322009-10-06 18:38:46440 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47441 while (!file_chooser_completions_.empty()) {
442 if (file_chooser_completions_.front()->completion) {
443 file_chooser_completions_.front()->completion->didChooseFile(
444 WebVector<WebString>());
445 }
446 file_chooser_completions_.pop_front();
447 }
[email protected]a1128322009-10-06 18:38:46448
[email protected]83dde542009-09-11 20:59:55449#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11450 // Destroy all fake plugin window handles on the browser side.
451 while (!fake_plugin_window_handles_.empty()) {
452 // Make sure no NULL plugin window handles were inserted into this list.
453 DCHECK(*fake_plugin_window_handles_.begin());
454 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
455 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
456 }
[email protected]83dde542009-09-11 20:59:55457#endif
[email protected]98324892009-09-09 21:16:05458
[email protected]60c42a8c72009-10-09 04:08:59459#ifndef NDEBUG
460 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49461 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59462 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
463 DCHECK_NE(this, it->second) << "Failed to call Close?";
464#endif
[email protected]676126f72011-01-15 00:03:51465
466 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
467 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59468}
469
470/*static*/
471void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49472 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59473 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
474 if (!visitor->Visit(it->second))
475 return;
476 }
477}
478
479/*static*/
480RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49481 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59482 ViewMap::iterator it = views->find(webview);
483 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29484}
485
486/*static*/
[email protected]0aa55312008-10-17 21:53:08487RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24488 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15489 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08490 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51491 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08492 const WebPreferences& webkit_prefs,
493 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34494 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26495 int64 session_storage_namespace_id,
496 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29497 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51498 return new RenderView(
499 render_thread,
500 parent_hwnd,
501 opener_id,
502 renderer_prefs,
503 webkit_prefs,
504 counter,
505 routing_id,
506 session_storage_namespace_id,
507 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29508}
509
[email protected]bb461532010-11-26 21:50:23510// static
initial.commit09911bf2008-07-26 23:55:29511void RenderView::SetNextPageID(int32 next_page_id) {
512 // This method should only be called during process startup, and the given
513 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05514 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29515 DCHECK(next_page_id >= next_page_id_);
516 next_page_id_ = next_page_id;
517}
518
[email protected]676126f72011-01-15 00:03:51519void RenderView::AddObserver(RenderViewObserver* observer) {
520 observers_.AddObserver(observer);
521}
522
523void RenderView::RemoveObserver(RenderViewObserver* observer) {
524 observer->set_render_view(NULL);
525 observers_.RemoveObserver(observer);
526}
527
[email protected]70eee342010-11-05 01:59:37528bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
529 typedef ViewHostMsg_AccessibilityNotification_Params params;
[email protected]a527a022011-02-10 02:32:36530 if (type == WebKit::WebAccessibilityNotificationChildrenChanged ||
531 type == WebKit::WebAccessibilityNotificationLoadComplete) {
[email protected]70eee342010-11-05 01:59:37532 return true;
533 }
534 return false;
535}
536
[email protected]8a3125a712010-08-09 18:58:51537WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26538 return static_cast<WebKit::WebView*>(webwidget());
539}
540
[email protected]1a3c3cb2010-12-16 21:03:40541void RenderView::SetReportLoadProgressEnabled(bool enabled) {
542 if (!enabled) {
543 load_progress_tracker_.reset(NULL);
544 return;
545 }
546 if (load_progress_tracker_ == NULL)
547 load_progress_tracker_.reset(new LoadProgressTracker(this));
548}
549
[email protected]a3a8fb6d2009-10-22 20:12:51550void RenderView::PluginCrashed(const FilePath& plugin_path) {
551 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29552}
553
[email protected]aad51d1c2010-08-05 08:38:09554WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
555 const WebPluginParams& params) {
[email protected]91d9f3d2011-08-14 05:24:44556 webkit::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26557 bool found;
[email protected]6fdd4182010-10-14 23:59:26558 std::string mime_type;
559 Send(new ViewHostMsg_GetPluginInfo(
[email protected]b6cb3a842011-06-24 18:28:41560 routing_id_, params.url, frame->top()->document().url(),
561 params.mimeType.utf8(), &found, &info, &mime_type));
[email protected]91d9f3d2011-08-14 05:24:44562 if (!found || !webkit::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09563 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45564
[email protected]96dcc1762011-04-04 16:01:09565 bool pepper_plugin_was_registered = false;
[email protected]0bd753682010-12-16 18:15:52566 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]076117592011-08-17 03:16:41567 pepper_delegate_.CreatePepperPluginModule(info,
568 &pepper_plugin_was_registered));
[email protected]96dcc1762011-04-04 16:01:09569 if (pepper_plugin_was_registered) {
570 if (pepper_module)
571 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
572 return NULL;
573 }
[email protected]1a78d9f32010-12-08 06:38:45574 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09575}
576
[email protected]d8fd6fa2010-02-01 15:54:26577void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
578 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30579 // If the renderer is visible, set initial visibility and focus state.
580 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34581#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30582 delegate->SetContainerVisibility(true);
583 if (webview() && webview()->isActive())
584 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34585#endif
[email protected]49232292010-09-03 19:07:30586 }
[email protected]784ea1ab2010-09-18 00:02:34587 // Plugins start assuming the content has focus (so that they work in
588 // environments where RenderView isn't hosting them), so we always have to
589 // set the initial state. See webplugin_delegate_impl.h for details.
590 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26591}
592
593void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
594 plugin_delegates_.erase(delegate);
595}
[email protected]d8fd6fa2010-02-01 15:54:26596
[email protected]a95986a82010-12-24 06:19:28597bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27598 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27599 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41600 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26601
[email protected]676126f72011-01-15 00:03:51602 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
603 RenderViewObserver* observer;
604 while ((observer = it.GetNext()) != NULL)
605 if (observer->OnMessageReceived(message))
606 return true;
[email protected]b2abac72009-02-26 12:39:28607
[email protected]a95986a82010-12-24 06:19:28608 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29609 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29610 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
611 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56612 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29613 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
614 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
615 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
616 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27617#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35618 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27619#endif
initial.commit09911bf2008-07-26 23:55:29620 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
621 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
622 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
623 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08624 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29625 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15626 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29627 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49628 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
629 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17630 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17631 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:54632 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
633 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29634 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18635 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
636 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29637 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48638 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29639 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55640 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
641 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
642 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
643 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
644 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
645 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
646 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45647 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40648 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29649 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:51650 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
651 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:29652 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
653 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
654 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
655 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]600ea402011-04-12 00:01:51656 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
657 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29658 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04659 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15660 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29661 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
662 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08663 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
664 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00665 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16666 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14667 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25668 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
669 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10670 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
671 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51672 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56673 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34674 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14675#if defined(OS_MACOSX)
676 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13677 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13678 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
679 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14680#endif
[email protected]446705872009-09-10 07:22:48681 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33682 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33683 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
684 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:14685 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:36686 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
687 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
688 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:42689 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
690 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:24691 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42692 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
693 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19694 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
695 OnGetAllSavableResourceLinksForCurrentPage)
696 IPC_MESSAGE_HANDLER(
697 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
698 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08699#if defined(OS_MACOSX)
700 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
701#endif
[email protected]521b2482011-01-15 00:10:10702 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51703 // TODO(viettrungluu): Move to a separate message filter.
704#if defined(ENABLE_FLAPPER_HACKS)
705 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
706#endif
[email protected]54ca3ca892011-06-07 21:14:54707#if defined(OS_MACOSX)
708 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
709#endif
[email protected]08bb1e722011-07-30 19:13:04710 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRemoteAccessClientFirewallTraversal,
711 OnUpdateRemoteAccessClientFirewallTraversal)
[email protected]9e1ad4b2011-08-14 16:49:19712 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
713 OnSetHistoryLengthAndPrune)
714
initial.commit09911bf2008-07-26 23:55:29715 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28716 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29717 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28718 return handled;
initial.commit09911bf2008-07-26 23:55:29719}
720
initial.commit09911bf2008-07-26 23:55:29721void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
722 if (!webview())
723 return;
724
[email protected]d466b8a2011-07-15 21:48:03725 bool is_reload =
726 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
727 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
728
729 // If this is a stale back/forward (due to a recent navigation the browser
730 // didn't know about), ignore it.
731 if (IsBackForwardToStaleEntry(params, is_reload))
732 return;
733
[email protected]992db4c2011-05-12 15:37:15734 // Swap this renderer back in if necessary.
735 if (is_swapped_out_)
736 SetSwappedOut(false);
737
[email protected]3cc72b12010-03-18 23:03:00738 history_list_offset_ = params.current_history_list_offset;
739 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03740 if (history_list_length_ >= 0)
741 history_page_ids_.resize(history_list_length_, -1);
742 if (params.pending_history_list_offset >= 0 &&
743 params.pending_history_list_offset < history_list_length_)
744 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00745
[email protected]38b592902011-04-16 02:08:42746 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29747
[email protected]26aa0482009-09-30 16:55:27748 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45749 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29750 // We cannot reload if we do not have any history state. This happens, for
751 // example, when recovering from a crash. Our workaround here is a bit of
752 // a hack since it means that reload after a crashed tab does not cause an
753 // end-to-end cache validation.
754 is_reload = false;
755 }
756
[email protected]77f17a82009-05-21 04:42:54757 // A navigation resulting from loading a javascript URL should not be treated
758 // as a browser initiated event. Instead, we want it to look as if the page
759 // initiated any load resulting from JS execution.
760 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30761 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00762 params.page_id,
763 params.pending_history_list_offset,
764 params.transition,
765 params.request_time);
[email protected]2c5569662011-03-22 20:45:02766 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30767 // We're doing a load of a page that was restored from the last session.
768 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
769 // which can result in stale data for pages that are set to expire. We
770 // explicitly override that by setting the policy here so that as
771 // necessary we load from the network.
772 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
773 }
774 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54775 }
initial.commit09911bf2008-07-26 23:55:29776
[email protected]a7ccc4d2010-01-27 08:14:48777 NavigationState* navigation_state = pending_navigation_state_.get();
778
[email protected]48a5c772011-04-18 23:50:50779 if (navigation_state) {
780 // New loads need to reset the error page fetcher. Otherwise if there is an
781 // outstanding error page fetcher it may complete and clobber the current
782 // page load.
783 navigation_state->set_alt_error_page_fetcher(NULL);
784 }
785
[email protected]04d3c6e2009-05-22 17:00:13786 // If we are reloading, then WebKit will use the history state of the current
787 // page, so we should just ignore any given history state. Otherwise, if we
788 // have history state, then we need to navigate to it, which corresponds to a
789 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55790 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48791 if (navigation_state)
792 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29793 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02794 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29795 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55796 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13797 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58798 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48799 if (navigation_state)
800 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45801 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17802 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13803 } else {
804 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28805 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29806
[email protected]e6f546c32009-07-01 17:12:55807 // A session history navigation should have been accompanied by state.
808 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13809
[email protected]dd7daa82009-08-10 05:46:45810 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55811 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13812
[email protected]726985e22009-06-18 21:09:28813 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17814 if (!WebSecurityPolicy::shouldHideReferrer(
815 params.url,
816 WebString::fromUTF8(params.referrer.spec()))) {
817 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
818 WebString::fromUTF8(params.referrer.spec()));
819 }
[email protected]726985e22009-06-18 21:09:28820 }
[email protected]04d3c6e2009-05-22 17:00:13821
[email protected]52c68652010-12-07 17:47:04822 if (!params.extra_headers.empty()) {
823 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
824 params.extra_headers.end(), "\n");
825 i.GetNext(); ) {
826 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
827 WebString::fromUTF8(i.values()));
828 }
829 }
830
[email protected]16e923d2011-04-30 00:41:44831 if (navigation_state)
832 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45833 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50834 }
835
[email protected]77f17a82009-05-21 04:42:54836 // In case LoadRequest failed before DidCreateDataSource was called.
837 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29838}
839
[email protected]d466b8a2011-07-15 21:48:03840bool RenderView::IsBackForwardToStaleEntry(
841 const ViewMsg_Navigate_Params& params,
842 bool is_reload) {
843 // Make sure this isn't a back/forward to an entry we have already cropped
844 // or replaced from our history, before the browser knew about it. If so,
845 // a new navigation has committed in the mean time, and we can ignore this.
846 bool is_back_forward = !is_reload && !params.state.empty();
847
848 // Note: if the history_list_length_ is 0 for a back/forward, we must be
849 // restoring from a previous session. We'll update our state in OnNavigate.
850 if (!is_back_forward || history_list_length_ <= 0)
851 return false;
852
853 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
854
855 // Check for whether the forward history has been cropped due to a recent
856 // navigation the browser didn't know about.
857 if (params.pending_history_list_offset >= history_list_length_)
858 return true;
859
860 // Check for whether this entry has been replaced with a new one.
861 int expected_page_id =
862 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44863 if (expected_page_id > 0 && params.page_id != expected_page_id) {
864 if (params.page_id < expected_page_id)
865 return true;
866
867 // Otherwise we've removed an earlier entry and should have shifted all
868 // entries left. For now, it's ok to lazily update the list.
869 // TODO(creis): Notify all live renderers when we remove entries from
870 // the front of the list, so that we don't hit this case.
871 history_page_ids_[params.pending_history_list_offset] = params.page_id;
872 }
[email protected]d466b8a2011-07-15 21:48:03873
874 return false;
875}
876
initial.commit09911bf2008-07-26 23:55:29877// Stop loading the current page
878void RenderView::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44879 if (webview()) {
880 WebFrame* main_frame = webview()->mainFrame();
881 // Stop the alt error page fetcher. If we let it continue it may complete
882 // and cause RenderViewHostManager to swap to this RenderView, even though
883 // it may no longer be active.
884 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
885 StopAltErrorPageFetcher(main_frame->dataSource());
886 main_frame->stopLoading();
887 }
initial.commit09911bf2008-07-26 23:55:29888}
889
[email protected]ecbf10d2010-02-18 13:03:29890// Reload current focused frame.
891// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56892void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29893 if (webview() && webview()->focusedFrame()) {
894 // We always obey the cache (ignore_cache=false) here.
895 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
896 // a cache-ignoring reload of the frame.
897 webview()->focusedFrame()->reload(false);
898 }
[email protected]1dda4022010-01-28 18:24:56899}
900
initial.commit09911bf2008-07-26 23:55:29901void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27902 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29903}
904
[email protected]68b1e922009-06-23 16:00:25905void RenderView::OnExecuteEditCommand(const std::string& name,
906 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27907 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25908 return;
909
[email protected]26aa0482009-09-30 16:55:27910 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45911 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25912}
913
initial.commit09911bf2008-07-26 23:55:29914void RenderView::OnUpdateTargetURLAck() {
915 // Check if there is a targeturl waiting to be sent.
916 if (target_url_status_ == TARGET_PENDING) {
917 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
918 pending_target_url_));
919 }
920
921 target_url_status_ = TARGET_NONE;
922}
923
924void RenderView::OnUndo() {
925 if (!webview())
926 return;
927
[email protected]26aa0482009-09-30 16:55:27928 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29929}
930
931void RenderView::OnRedo() {
932 if (!webview())
933 return;
934
[email protected]26aa0482009-09-30 16:55:27935 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29936}
937
938void RenderView::OnCut() {
939 if (!webview())
940 return;
941
[email protected]26aa0482009-09-30 16:55:27942 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29943}
944
945void RenderView::OnCopy() {
946 if (!webview())
947 return;
948
[email protected]f6b1856b2011-06-29 22:02:53949 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
950 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29951}
952
[email protected]c0cc3092009-09-12 08:27:27953#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35954void RenderView::OnCopyToFindPboard() {
955 if (!webview())
956 return;
957
958 // Since the find pasteboard supports only plain text, this can be simpler
959 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27960 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35961 if (frame->hasSelection()) {
962 string16 selection = frame->selectionAsText();
963 RenderThread::current()->Send(
[email protected]7e3589742011-03-10 18:49:17964 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35965 }
[email protected]a954bf72009-09-12 07:30:35966}
[email protected]c0cc3092009-09-12 08:27:27967#endif
[email protected]a954bf72009-09-12 07:30:35968
initial.commit09911bf2008-07-26 23:55:29969void RenderView::OnPaste() {
970 if (!webview())
971 return;
972
[email protected]26aa0482009-09-30 16:55:27973 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29974}
975
[email protected]2a3a7762009-10-19 19:17:32976void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29977 if (!webview())
978 return;
979
[email protected]1ff7a032010-02-03 02:46:03980 WebFrame* frame = webview()->focusedFrame();
981 if (!frame->hasSelection())
982 frame->selectWordAroundCaret();
983 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29984}
985
986void RenderView::OnDelete() {
987 if (!webview())
988 return;
989
[email protected]26aa0482009-09-30 16:55:27990 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29991}
992
993void RenderView::OnSelectAll() {
994 if (!webview())
995 return;
996
[email protected]26aa0482009-09-30 16:55:27997 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22998 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29999}
1000
[email protected]4fb60142011-08-09 02:22:081001void RenderView::OnSelectRange(const gfx::Point& start, const gfx::Point& end) {
1002 if (!webview())
1003 return;
1004
1005 handling_select_range_ = true;
1006 webview()->focusedFrame()->selectRange(start, end);
1007 handling_select_range_ = false;
1008}
1009
[email protected]9e1ad4b2011-08-14 16:49:191010void RenderView::OnSetHistoryLengthAndPrune(int history_length,
1011 int32 minimum_page_id) {
1012 DCHECK(history_length >= 0);
1013 DCHECK(history_list_offset_ == history_list_length_ - 1);
1014 DCHECK(minimum_page_id >= -1);
1015
1016 // Generate the new list.
1017 std::vector<int32> new_history_page_ids(history_length, -1);
1018 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1019 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1020 continue;
1021 new_history_page_ids.push_back(history_page_ids_[i]);
1022 }
1023 new_history_page_ids.swap(history_page_ids_);
1024
1025 // Update indexes.
1026 history_list_length_ = history_page_ids_.size();
1027 history_list_offset_ = history_list_length_ - 1;
1028}
1029
1030
initial.commit09911bf2008-07-26 23:55:291031void RenderView::OnSetInitialFocus(bool reverse) {
1032 if (!webview())
1033 return;
[email protected]26aa0482009-09-30 16:55:271034 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291035}
1036
[email protected]54ca3ca892011-06-07 21:14:541037#if defined(OS_MACOSX)
1038void RenderView::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331039 if (!webview())
1040 return;
1041 if (in_live_resize)
1042 webview()->willStartLiveResize();
1043 else
1044 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541045}
1046#endif
1047
[email protected]9b66f34bf2010-10-27 20:45:511048void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:091049 WebKit::WebNode node = GetFocusedNode();
1050 if (!node.isNull()) {
1051 if (IsEditableNode(node))
1052 // TODO(varunjain): Change webkit API to scroll a particular node into
1053 // view and use that API here instead.
1054 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:511055 }
1056}
1057
initial.commit09911bf2008-07-26 23:55:291058///////////////////////////////////////////////////////////////////////////////
1059
1060// Tell the embedding application that the URL of the active page has changed
1061void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451062 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291063 DCHECK(ds);
1064
[email protected]726985e22009-06-18 21:09:281065 const WebURLRequest& request = ds->request();
1066 const WebURLRequest& original_request = ds->originalRequest();
1067 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291068
[email protected]daa8c58e2009-06-15 17:21:101069 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1070 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291071
1072 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281073 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291074 params.is_post = false;
1075 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071076 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191077 params.socket_address.set_host(response.remoteIPAddress().utf8());
1078 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031079 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091080 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551081 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291082 // SSL state specified in the request takes precedence over the one in the
1083 // response.
1084 // So far this is only intended for error pages that are not expected to be
1085 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281086 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551087 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291088 } else {
[email protected]726985e22009-06-18 21:09:281089 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291090 }
1091
1092 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281093 if (ds->hasUnreachableURL()) {
1094 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291095 } else {
[email protected]726985e22009-06-18 21:09:281096 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291097 }
1098
[email protected]726985e22009-06-18 21:09:281099 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241100 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041101 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291102
[email protected]ce0e250d2009-10-23 21:00:351103 params.searchable_form_url = navigation_state->searchable_form_url();
1104 params.searchable_form_encoding =
1105 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291106
1107 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101108 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291109 if (password_form_data)
1110 params.password_form = *password_form_data;
1111
1112 params.gesture = navigation_gesture_;
1113 navigation_gesture_ = NavigationGestureUnknown;
1114
[email protected]0f38dc4552011-02-25 11:24:001115 // Make navigation state a part of the FrameNavigate message so that commited
1116 // entry had it at all times.
1117 const WebHistoryItem& item = frame->currentHistoryItem();
1118 if (!item.isNull()) {
1119 params.content_state = webkit_glue::HistoryItemToString(item);
1120 } else {
1121 params.content_state =
1122 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1123 }
1124
[email protected]dd7daa82009-08-10 05:46:451125 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291126 // Top-level navigation.
1127
[email protected]b75b8292010-10-01 07:28:251128 // Set zoom level, but don't do it for full-page plugin since they don't use
1129 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011130 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541131 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251132 if (webview()->mainFrame()->document().isPluginDocument()) {
1133 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251134 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251135 } else {
1136 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251137 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251138 }
1139
[email protected]f85f0702010-01-30 09:31:011140 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511141 // This zoom level was merely recorded transiently for this load. We can
1142 // erase it now. If at some point we reload this page, the browser will
1143 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011144 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511145 }
1146
[email protected]b75b8292010-10-01 07:28:251147 // Reset the zoom limits in case a plugin had changed them previously. This
1148 // will also call us back which will cause us to send a message to
1149 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251150 webview()->zoomLimitsChanged(
1151 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1152 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251153
initial.commit09911bf2008-07-26 23:55:291154 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551155 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291156
[email protected]daa8c58e2009-06-15 17:21:101157 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291158 if (!PageTransition::IsMainFrame(params.transition)) {
1159 // If the main frame does a load, it should not be reported as a subframe
1160 // navigation. This can occur in the following case:
1161 // 1. You're on a site with frames.
1162 // 2. You do a subframe navigation. This is stored with transition type
1163 // MANUAL_SUBFRAME.
1164 // 3. You navigate to some non-frame site, say, google.com.
1165 // 4. You navigate back to the page from step 2. Since it was initially
1166 // MANUAL_SUBFRAME, it will be that same transition type here.
1167 // We don't want that, because any navigation that changes the toplevel
1168 // frame should be tracked as a toplevel navigation (this allows us to
1169 // update the URL bar, etc).
1170 params.transition = PageTransition::LINK;
1171 }
1172
initial.commit09911bf2008-07-26 23:55:291173 // If we have a valid consumed client redirect source,
1174 // the page contained a client redirect (meta refresh, document.loc...),
1175 // so we set the referrer and transition to match.
1176 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041177 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291178 params.referrer = completed_client_redirect_src_;
1179 params.transition = static_cast<PageTransition::Type>(
1180 params.transition | PageTransition::CLIENT_REDIRECT);
1181 } else {
1182 // Bug 654101: the referrer will be empty on https->http transitions. It
1183 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281184 params.referrer = GURL(
1185 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291186 }
1187
[email protected]726985e22009-06-18 21:09:281188 string16 method = request.httpMethod();
1189 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291190 params.is_post = true;
1191
[email protected]c2a797d2009-09-21 16:46:321192 // Save some histogram data so we can compute the average memory used per
1193 // page load of the glyphs.
1194 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1195 webkit_glue::GetGlyphPageCount());
1196
[email protected]15cf526b2010-02-12 06:33:491197 // This message needs to be sent before any of allowScripts(),
1198 // allowImages(), allowPlugins() is called for the new page, so that when
1199 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1200 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291201 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1202 } else {
1203 // Subframe navigation: the type depends on whether this navigation
1204 // generated a new session history entry. When they do generate a session
1205 // history entry, it means the user initiated the navigation and we should
1206 // mark it as such. This test checks if this is the first time UpdateURL
1207 // has been called since WillNavigateToURL was called to initiate the load.
1208 if (page_id_ > last_page_id_sent_to_browser_)
1209 params.transition = PageTransition::MANUAL_SUBFRAME;
1210 else
1211 params.transition = PageTransition::AUTO_SUBFRAME;
1212
initial.commit09911bf2008-07-26 23:55:291213 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1214 }
1215
1216 last_page_id_sent_to_browser_ =
1217 std::max(last_page_id_sent_to_browser_, page_id_);
1218
1219 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101220 // we don't want the transition type to persist. Just clear it.
1221 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501222
[email protected]af15bed2010-08-25 21:12:091223 // Check if the navigation was within the same page, in which case we don't
1224 // want to clear the accessibility cache.
1225 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351226 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141227 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501228 }
initial.commit09911bf2008-07-26 23:55:291229}
1230
1231// Tell the embedding application that the title of the active page has changed
[email protected]750fcf872011-08-03 23:10:471232void RenderView::UpdateTitle(WebFrame* frame,
1233 const string16& title,
[email protected]a49e10b2011-08-01 23:57:461234 WebTextDirection title_direction) {
1235 // Ignore all but top level navigations.
1236 if (frame->parent())
1237 return;
1238
1239 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1240 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1241 title_direction));
initial.commit09911bf2008-07-26 23:55:291242}
1243
1244void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401245 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291246 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271247 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291248 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301249 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291250 last_encoding_name_ = encoding_name;
1251
[email protected]e38f40152008-09-12 23:08:301252 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291253 }
1254}
1255
[email protected]e15f680732010-11-23 22:30:201256// Sends the last committed session history state to the browser so it will be
1257// saved before we navigate to a new page. This must be called *before* the
1258// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291259void RenderView::UpdateSessionHistory(WebFrame* frame) {
1260 // If we have a valid page ID at this point, then it corresponds to the page
1261 // we are navigating away from. Otherwise, this is the first navigation, so
1262 // there is no past session history to record.
1263 if (page_id_ == -1)
1264 return;
1265
[email protected]ca948a22009-06-25 19:36:171266 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271267 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171268 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291269 return;
[email protected]ca948a22009-06-25 19:36:171270
1271 Send(new ViewHostMsg_UpdateState(
1272 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291273}
1274
[email protected]3d9689372009-09-10 04:29:171275void RenderView::OpenURL(
1276 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1277 Send(new ViewHostMsg_OpenURL(
1278 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1279}
1280
[email protected]79dbc662009-09-04 05:42:511281// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291282
initial.commit09911bf2008-07-26 23:55:291283void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281284 const WebURLRequest& failed_request,
1285 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291286 const std::string& html,
1287 bool replace) {
[email protected]c5c1d6d2011-07-28 18:42:411288
1289 // Do not show alternate error page when DevTools is attached.
1290 if (devtools_agent_->IsAttached())
1291 return;
1292
[email protected]21d61e52011-03-18 19:08:251293 std::string alt_html = !html.empty() ? html :
1294 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1295 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451296 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361297 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251298 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551299 replace);
initial.commit09911bf2008-07-26 23:55:291300}
1301
initial.commit09911bf2008-07-26 23:55:291302bool RenderView::RunJavaScriptMessage(int type,
[email protected]4f5ce842011-05-27 19:34:411303 const string16& message,
1304 const string16& default_value,
[email protected]a455d3812009-03-05 20:18:071305 const GURL& frame_url,
[email protected]4f5ce842011-05-27 19:34:411306 string16* result) {
initial.commit09911bf2008-07-26 23:55:291307 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411308 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291309 if (!result)
1310 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291311
[email protected]12636df2009-09-28 22:32:211312 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1313 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291314 return success;
1315}
1316
[email protected]c1f50aa2010-02-18 03:46:571317bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1318 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1319 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1320 // it is particularly important that we do not call willEnterModalLoop as
1321 // that would defer resource loads for the dialog itself.
1322 if (RenderThread::current()) // Will be NULL during unit tests.
1323 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1324
1325 message->EnableMessagePumping(); // Runs a nested message loop.
1326 return Send(message);
1327}
1328
[email protected]f103ab72009-09-02 17:10:591329void RenderView::OnMissingPluginStatus(
1330 WebPluginDelegateProxy* delegate,
1331 int status) {
[email protected]6c8afae52009-01-22 02:24:571332#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591333 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291334 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:501335 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591336 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291337 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1338 }
1339 } else {
1340 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1341 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:501342 if (status ==
1343 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:291344 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1345 }
1346 }
[email protected]6c8afae52009-01-22 02:24:571347#else
[email protected]76c3b312010-05-20 21:38:291348 // TODO(port): Implement the infobar that accompanies the default plugin.
1349 // Linux: http://crbug.com/10952
1350 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571351 NOTIMPLEMENTED();
1352#endif
initial.commit09911bf2008-07-26 23:55:291353}
1354
[email protected]48c9cf2d2009-09-16 16:47:521355// WebKit::WebViewClient ------------------------------------------------------
1356
[email protected]844acf372011-01-14 10:49:271357WebView* RenderView::createView(
1358 WebFrame* creator,
1359 const WebURLRequest& request,
1360 const WebWindowFeatures& features,
1361 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521362 // Check to make sure we aren't overloading on popups.
1363 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1364 return NULL;
1365
[email protected]8ab04652010-06-12 02:47:261366 ViewHostMsg_CreateWindow_Params params;
1367 params.opener_id = routing_id_;
1368 params.user_gesture = creator->isProcessingUserGesture();
1369 params.window_container_type = WindowFeaturesToContainerType(features);
1370 params.session_storage_namespace_id = session_storage_namespace_id_;
1371 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111372 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411373 params.opener_url = creator->document().url();
1374 params.opener_security_origin =
1375 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111376 if (!request.isNull())
1377 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261378
[email protected]48c9cf2d2009-09-16 16:47:521379 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341380 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261381 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521382
[email protected]48c9cf2d2009-09-16 16:47:521383 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261384 new ViewHostMsg_CreateWindow(params,
1385 &routing_id,
1386 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211387 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521388 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521389
[email protected]48c9cf2d2009-09-16 16:47:521390 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421391 0,
[email protected]12636df2009-09-28 22:32:211392 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521393 renderer_preferences_,
1394 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211395 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341396 routing_id,
[email protected]8ab04652010-06-12 02:47:261397 cloned_session_storage_namespace_id,
1398 frame_name);
1399 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521400
[email protected]007a848b2009-10-26 15:55:461401 // Record whether the creator frame is trying to suppress the opener field.
1402 view->opener_suppressed_ = opener_suppressed;
1403
[email protected]48c9cf2d2009-09-16 16:47:521404 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411405 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521406 if (!creator_url.is_valid() || !creator_url.IsStandard())
1407 creator_url = GURL();
1408 view->creator_url_ = creator_url;
1409
1410 // Copy over the alternate error page URL so we can have alt error pages in
1411 // the new render view (we don't need the browser to send the URL back down).
1412 view->alternate_error_page_url_ = alternate_error_page_url_;
1413
1414 return view->webview();
1415}
1416
[email protected]3e2b375b2010-04-07 17:03:121417WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521418 RenderWidget* widget = RenderWidget::Create(routing_id_,
1419 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121420 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521421 return widget->webwidget();
1422}
1423
1424WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441425 // TODO(jcivelli): Remove this deprecated method when its been removed from
1426 // the WebViewClient interface. It's been replaced by
1427 // createExternalPopupMenu.
1428 NOTREACHED();
1429 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521430}
1431
[email protected]caf706f2010-10-26 17:54:081432WebExternalPopupMenu* RenderView::createExternalPopupMenu(
1433 const WebPopupMenuInfo& popup_menu_info,
1434 WebExternalPopupMenuClient* popup_menu_client) {
1435 DCHECK(!external_popup_menu_.get());
1436 external_popup_menu_.reset(
1437 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1438 return external_popup_menu_.get();
1439}
1440
[email protected]ea192e82011-04-11 19:16:021441RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521442 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531443 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421444 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411445 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531446 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
1447 routing_id_, render_thread_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391448 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561449 return widget;
[email protected]79c7bed2010-09-14 22:28:391450}
1451
[email protected]68c50e52010-05-12 11:14:391452WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341453 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391454 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291455 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1456 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1457 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341458}
1459
[email protected]48c9cf2d2009-09-16 16:47:521460void RenderView::didAddMessageToConsole(
1461 const WebConsoleMessage& message, const WebString& source_name,
1462 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081463 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511464 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081465 case WebConsoleMessage::LevelTip:
1466 log_severity = logging::LOG_VERBOSE;
1467 break;
1468 case WebConsoleMessage::LevelLog:
1469 log_severity = logging::LOG_INFO;
1470 break;
1471 case WebConsoleMessage::LevelWarning:
1472 log_severity = logging::LOG_WARNING;
1473 break;
1474 case WebConsoleMessage::LevelError:
1475 log_severity = logging::LOG_ERROR;
1476 break;
1477 default:
1478 NOTREACHED();
1479 }
1480
[email protected]48c9cf2d2009-09-16 16:47:521481 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081482 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311483 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521484 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311485 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521486}
1487
1488void RenderView::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421489 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521490}
1491
[email protected]3354d3e2010-06-10 19:53:021492WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511493 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021494}
1495
[email protected]8a58c1c2011-04-19 18:40:121496bool RenderView::enumerateChosenDirectory(
1497 const WebString& path,
1498 WebFileChooserCompletion* chooser_completion) {
1499 int id = enumeration_completion_id_++;
1500 enumeration_completions_[id] = chooser_completion;
1501 return Send(new ViewHostMsg_EnumerateDirectory(
1502 routing_id_,
1503 id,
1504 webkit_glue::WebStringToFilePath(path)));
1505}
1506
[email protected]48c9cf2d2009-09-16 16:47:521507void RenderView::didStartLoading() {
1508 if (is_loading_) {
1509 DLOG(WARNING) << "didStartLoading called while loading";
1510 return;
1511 }
1512
1513 is_loading_ = true;
1514 // Clear the pointer so that we can assign it only when there is an unknown
1515 // plugin on a page.
1516 first_default_plugin_.reset();
1517
1518 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311519
1520 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521521}
1522
1523void RenderView::didStopLoading() {
1524 if (!is_loading_) {
1525 DLOG(WARNING) << "DidStopLoading called while not loading";
1526 return;
1527 }
1528
1529 is_loading_ = false;
1530
1531 // NOTE: For now we're doing the safest thing, and sending out notification
1532 // when done loading. This currently isn't an issue as the favicon is only
1533 // displayed when done loading. Ideally we would send notification when
1534 // finished parsing the head, but webkit doesn't support that yet.
1535 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521536 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1537
[email protected]90109412010-12-15 17:14:241538 if (load_progress_tracker_ != NULL)
1539 load_progress_tracker_->DidStopLoading();
1540
[email protected]93b9d692011-04-13 00:44:311541 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521542}
1543
[email protected]90109412010-12-15 17:14:241544void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
1545 if (load_progress_tracker_ != NULL)
1546 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1547}
1548
[email protected]f55039a2010-02-17 14:12:061549bool RenderView::isSmartInsertDeleteEnabled() {
1550#if defined(OS_MACOSX)
1551 return true;
1552#else
1553 return false;
1554#endif
1555}
1556
[email protected]04fc9482009-09-18 22:13:031557bool RenderView::isSelectTrailingWhitespaceEnabled() {
1558#if defined(OS_WIN)
1559 return true;
1560#else
1561 return false;
1562#endif
1563}
1564
[email protected]04fc9482009-09-18 22:13:031565void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:421566#if defined(OS_POSIX)
[email protected]4fb60142011-08-09 02:22:081567 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031568 return;
[email protected]4fb60142011-08-09 02:22:081569 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011570
1571 if (is_empty_selection) {
1572 last_selection_.clear();
1573 } else {
[email protected]04fc9482009-09-18 22:13:031574 // Sometimes we get repeated didChangeSelection calls from webkit when
1575 // the selection hasn't actually changed. We don't want to report these
1576 // because it will cause us to continually claim the X clipboard.
[email protected]d4cff272011-05-02 15:46:011577 WebFrame* frame = webview()->focusedFrame();
1578 const std::string& this_selection = frame->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031579 if (this_selection == last_selection_)
1580 return;
[email protected]04fc9482009-09-18 22:13:031581 last_selection_ = this_selection;
[email protected]04fc9482009-09-18 22:13:031582 }
[email protected]d4cff272011-05-02 15:46:011583
1584 ui::Range range(ui::Range::InvalidRange());
1585 size_t location, length;
1586 if (webview()->caretOrSelectionRange(&location, &length)) {
1587 range.set_start(location);
1588 range.set_end(location + length);
1589 }
[email protected]4fb60142011-08-09 02:22:081590
1591 WebKit::WebPoint start, end;
1592 webview()->selectionRange(start, end);
1593
1594 // Webkit gives an offset of 1 between start and end even if there is no
1595 // selection. So we need to check against that.
1596 // TODO(varunjain): remove this check once that is fixed.
1597 gfx::Point p1, p2;
1598 if (std::abs(start.x - end.x) > 1 || std::abs(start.y - end.y) > 1) {
1599 gfx::Point scroll_offset = GetScrollOffset();
1600 p1.SetPoint(start.x + scroll_offset.x(), start.y + scroll_offset.y());
1601 p2.SetPoint(end.x + scroll_offset.x(), end.y + scroll_offset.y());
1602 }
1603 // TODO(varunjain): add other hooks for SelectionChanged.
1604 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range,
1605 p1, p2));
[email protected]0ff0ff32010-12-21 19:34:421606#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031607}
1608
1609void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121610 const std::string& name = UTF16ToUTF8(command_name);
1611 if (StartsWithASCII(name, "Move", true) ||
1612 StartsWithASCII(name, "Insert", true) ||
1613 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031614 return;
[email protected]c2043682011-06-10 22:49:561615 RenderThread::current()->Send(
1616 new ViewHostMsg_UserMetricsRecordAction(name));
[email protected]04fc9482009-09-18 22:13:031617}
1618
[email protected]54ec7f82010-10-21 22:32:511619void RenderView::SendPendingAccessibilityNotifications() {
1620 if (!accessibility_.get())
1621 return;
1622
1623 if (pending_accessibility_notifications_.empty())
1624 return;
1625
1626 // Send all pending accessibility notifications.
1627 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
1628 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
1629 RendererAccessibilityNotification& notification =
1630 pending_accessibility_notifications_[i];
1631 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
1632 if (!obj.isValid())
1633 continue;
1634
1635 ViewHostMsg_AccessibilityNotification_Params param;
[email protected]a527a022011-02-10 02:32:361636 WebAccessibilityNotificationToViewHostMsg(
1637 pending_accessibility_notifications_[i].type, &param.notification_type);
[email protected]70eee342010-11-05 01:59:371638 param.acc_obj = WebAccessibility(
1639 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:511640 notifications.push_back(param);
1641 }
1642 pending_accessibility_notifications_.clear();
1643 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
1644 accessibility_ack_pending_ = true;
1645}
1646
[email protected]b2528b72009-09-24 06:57:101647bool RenderView::handleCurrentKeyboardEvent() {
1648 if (edit_commands_.empty())
1649 return false;
1650
[email protected]26aa0482009-09-30 16:55:271651 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101652 if (!frame)
1653 return false;
1654
1655 EditCommands::iterator it = edit_commands_.begin();
1656 EditCommands::iterator end = edit_commands_.end();
1657
[email protected]507b33ea2009-09-29 03:56:511658 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101659 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331660 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1661 // key (but it's the exception). Once one edit command is not executed, it
1662 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101663 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1664 WebString::fromUTF8(it->value)))
1665 break;
[email protected]507b33ea2009-09-29 03:56:511666 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101667 }
1668
[email protected]507b33ea2009-09-29 03:56:511669 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101670}
1671
[email protected]a1128322009-10-06 18:38:461672bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351673 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471674 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351675 // Do not open the file dialog in a hidden RenderView.
1676 if (is_hidden())
1677 return false;
[email protected]cdaf8d02010-03-30 19:52:471678 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261679 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361680 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261681 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361682 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]b5977a0c2010-08-24 19:46:261683 else
[email protected]0aed2f52011-03-23 18:06:361684 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471685 ipc_params.title = params.title;
1686 ipc_params.default_file_name =
1687 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591688 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471689
1690 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461691}
1692
[email protected]48c9cf2d2009-09-16 16:47:521693void RenderView::runModalAlertDialog(
1694 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061695 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]4f5ce842011-05-27 19:34:411696 message,
1697 string16(),
[email protected]b6cb3a842011-06-24 18:28:411698 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521699 NULL);
1700}
1701
1702bool RenderView::runModalConfirmDialog(
1703 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061704 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]4f5ce842011-05-27 19:34:411705 message,
1706 string16(),
[email protected]b6cb3a842011-06-24 18:28:411707 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521708 NULL);
1709}
1710
1711bool RenderView::runModalPromptDialog(
1712 WebFrame* frame, const WebString& message, const WebString& default_value,
1713 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411714 string16 result;
[email protected]9dd7e3d72011-01-20 18:27:061715 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]4f5ce842011-05-27 19:34:411716 message,
1717 default_value,
[email protected]b6cb3a842011-06-24 18:28:411718 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521719 &result);
1720 if (ok)
[email protected]4f5ce842011-05-27 19:34:411721 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521722 return ok;
1723}
1724
1725bool RenderView::runModalBeforeUnloadDialog(
1726 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151727 // If we are swapping out, we have already run the beforeunload handler.
1728 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1729 // at all, to avoid running it twice.
1730 if (is_swapped_out_)
1731 return true;
1732
[email protected]48c9cf2d2009-09-16 16:47:521733 bool success = false;
1734 // This is an ignored return value, but is included so we can accept the same
1735 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411736 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211737 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411738 routing_id_, frame->document().url(), message,
1739 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521740 return success;
1741}
1742
[email protected]79e37442009-10-09 18:17:441743void RenderView::showContextMenu(
1744 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291745 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371746
1747 // frame is NULL if invoked by BlockedPlugin.
1748 if (frame)
1749 params.frame_id = frame->identifier();
1750
[email protected]db803aae2011-03-05 02:00:421751 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271752 // it. We replace it with an empty GURL so the appropriate items are disabled
1753 // in the context menu.
1754 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1755 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421756 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271757 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101758 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291759 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441760}
1761
[email protected]52f139e2c2010-06-11 16:56:091762bool RenderView::supportsFullscreen() {
1763 return CommandLine::ForCurrentProcess()->HasSwitch(
1764 switches::kEnableVideoFullscreen);
1765}
1766
1767void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1768 NOTIMPLEMENTED();
1769}
1770
1771void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1772 NOTIMPLEMENTED();
1773}
1774
[email protected]48c9cf2d2009-09-16 16:47:521775void RenderView::setStatusText(const WebString& text) {
1776}
1777
[email protected]163f8242009-10-30 20:19:551778void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581779 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521780 if (latest_url == target_url_)
1781 return;
[email protected]163f8242009-10-30 20:19:551782
[email protected]48c9cf2d2009-09-16 16:47:521783 // Tell the browser to display a destination link.
1784 if (target_url_status_ == TARGET_INFLIGHT ||
1785 target_url_status_ == TARGET_PENDING) {
1786 // If we have a request in-flight, save the URL to be sent when we
1787 // receive an ACK to the in-flight request. We can happily overwrite
1788 // any existing pending sends.
1789 pending_target_url_ = latest_url;
1790 target_url_status_ = TARGET_PENDING;
1791 } else {
1792 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1793 target_url_ = latest_url;
1794 target_url_status_ = TARGET_INFLIGHT;
1795 }
1796}
1797
[email protected]882daa92009-11-05 16:31:311798void RenderView::StartNavStateSyncTimerIfNecessary() {
1799 int delay;
1800 if (send_content_state_immediately_)
1801 delay = 0;
1802 else if (is_hidden())
1803 delay = kDelaySecondsForContentStateSyncHidden;
1804 else
1805 delay = kDelaySecondsForContentStateSync;
1806
1807 if (nav_state_sync_timer_.IsRunning()) {
1808 // The timer is already running. If the delay of the timer maches the amount
1809 // we want to delay by, then return. Otherwise stop the timer so that it
1810 // gets started with the right delay.
1811 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1812 return;
1813 nav_state_sync_timer_.Stop();
1814 }
1815
1816 nav_state_sync_timer_.Start(
1817 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1818}
1819
[email protected]163f8242009-10-30 20:19:551820void RenderView::setMouseOverURL(const WebURL& url) {
1821 mouse_over_url_ = GURL(url);
1822 UpdateTargetURL(mouse_over_url_, focus_url_);
1823}
1824
1825void RenderView::setKeyboardFocusURL(const WebURL& url) {
1826 focus_url_ = GURL(url);
1827 UpdateTargetURL(focus_url_, mouse_over_url_);
1828}
1829
[email protected]c27ae592010-03-18 15:24:411830void RenderView::startDragging(const WebDragData& data,
1831 WebDragOperationsMask mask,
1832 const WebImage& image,
1833 const WebPoint& imageOffset) {
1834#if WEBKIT_USING_SKIA
1835 SkBitmap bitmap(image.getSkBitmap());
1836#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331837 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411838#endif
1839
[email protected]59f4f2fa2011-03-23 01:00:551840 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521841 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411842 mask,
1843 bitmap,
1844 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521845}
1846
[email protected]28b92df2009-09-25 17:35:451847bool RenderView::acceptsLoadDrops() {
1848 return renderer_preferences_.can_accept_load_drops;
1849}
1850
[email protected]48c9cf2d2009-09-16 16:47:521851void RenderView::focusNext() {
1852 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1853}
1854
1855void RenderView::focusPrevious() {
1856 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1857}
1858
[email protected]08e9e132010-06-01 16:58:491859void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511860 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071861
1862 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
1863 // TODO(ctguil): Make WebKit send this notification.
1864 // When focus is cleared notify accessibility that the document is focused.
1865 postAccessibilityNotification(
1866 webview()->accessibilityObject(),
1867 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
1868 }
[email protected]13a1e4c3c2011-02-03 21:07:091869
[email protected]38b592902011-04-16 02:08:421870 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491871}
1872
[email protected]48c9cf2d2009-09-16 16:47:521873void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521874 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1875}
1876
1877int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001878 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521879}
1880
1881int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001882 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521883}
1884
[email protected]c4e98902010-06-01 10:20:141885void RenderView::didUpdateInspectorSetting(const WebString& key,
1886 const WebString& value) {
1887 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1888 key.utf8(),
1889 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261890}
1891
[email protected]79dbc662009-09-04 05:42:511892// WebKit::WebWidgetClient ----------------------------------------------------
1893
[email protected]ea42e7782010-08-23 23:58:121894void RenderView::didFocus() {
1895 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1896 // we won't have to test for user gesture anymore and we can
1897 // move that code back to render_widget.cc
1898 if (webview() && webview()->mainFrame() &&
1899 webview()->mainFrame()->isProcessingUserGesture()) {
1900 Send(new ViewHostMsg_Focus(routing_id_));
1901 }
1902}
1903
1904void RenderView::didBlur() {
1905 // TODO(jcivelli): see TODO above in didFocus().
1906 if (webview() && webview()->mainFrame() &&
1907 webview()->mainFrame()->isProcessingUserGesture()) {
1908 Send(new ViewHostMsg_Blur(routing_id_));
1909 }
1910}
1911
initial.commit09911bf2008-07-26 23:55:291912// We are supposed to get a single call to Show for a newly created RenderView
1913// that was created via RenderView::CreateWebView. So, we wait until this
1914// point to dispatch the ShowView message.
1915//
1916// This method provides us with the information about how to display the newly
1917// created RenderView (i.e., as a constrained popup or as a new tab).
1918//
[email protected]4873c7d2009-07-16 06:36:281919void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291920 DCHECK(!did_show_) << "received extraneous Show call";
1921 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1922
1923 if (did_show_)
1924 return;
1925 did_show_ = true;
1926
[email protected]6779aa12011-03-29 17:32:241927 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041928 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041929
[email protected]28295ec2009-10-16 05:34:331930 // Force new windows to a popup if they were not opened with a user gesture.
1931 if (!opened_by_user_gesture_) {
1932 // We exempt background tabs for compat with older versions of Chrome.
1933 // TODO(darin): This seems bogus. These should have a user gesture, so
1934 // we probably don't need this check.
1935 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1936 policy = WebKit::WebNavigationPolicyNewPopup;
1937 }
1938
initial.commit09911bf2008-07-26 23:55:291939 // NOTE: initial_pos_ may still have its default values at this point, but
1940 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1941 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281942 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1943 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291944 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241945 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291946}
1947
[email protected]4873c7d2009-07-16 06:36:281948void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291949 DCHECK(did_show_) << "should already have shown the view";
1950
[email protected]c1f50aa2010-02-18 03:46:571951 // We must keep WebKit's shared timer running in this case in order to allow
1952 // showModalDialog to function properly.
1953 //
1954 // TODO(darin): WebKit should really be smarter about suppressing events and
1955 // timers so that we do not need to manage the shared timer in such a heavy
1956 // handed manner.
1957 //
1958 if (RenderThread::current()) // Will be NULL during unit tests.
1959 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
1960
[email protected]12636df2009-09-28 22:32:211961 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291962}
1963
[email protected]3d9689372009-09-10 04:29:171964// WebKit::WebFrameClient -----------------------------------------------------
1965
[email protected]00152e92010-07-19 11:47:401966WebPlugin* RenderView::createPlugin(WebFrame* frame,
1967 const WebPluginParams& params) {
[email protected]e7c21b812011-03-19 18:03:301968 return content::GetContentClient()->renderer()->CreatePlugin(
[email protected]21d61e52011-03-18 19:08:251969 this, frame, params);
[email protected]3d9689372009-09-10 04:29:171970}
1971
1972WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561973 WebApplicationCacheHostImpl* appcache_host =
1974 WebApplicationCacheHostImpl::FromFrame(frame);
1975 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
1976 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
1977 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171978}
1979
[email protected]9c00f002009-11-05 22:37:421980WebSharedWorker* RenderView::createSharedWorker(
1981 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371982 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421983
[email protected]30447b62009-11-13 01:13:371984 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511985 bool exists = false;
[email protected]30447b62009-11-13 01:13:371986 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511987 ViewHostMsg_CreateWorker_Params params;
1988 params.url = url;
1989 params.is_shared = true;
1990 params.name = name;
1991 params.document_id = document_id;
1992 params.render_view_route_id = routing_id_;
1993 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231994 params.parent_appcache_host_id = 0;
1995 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371996 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511997 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371998 if (url_mismatch) {
1999 return NULL;
2000 } else {
2001 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492002 document_id,
[email protected]6de0bcf2010-02-17 22:00:512003 exists,
[email protected]30447b62009-11-13 01:13:372004 route_id,
2005 routing_id_);
2006 }
[email protected]9c00f002009-11-05 22:37:422007}
2008
[email protected]3d9689372009-09-10 04:29:172009WebMediaPlayer* RenderView::createMediaPlayer(
2010 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:442011 FOR_EACH_OBSERVER(
2012 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:172013
[email protected]f78d1dfc2011-01-15 07:09:272014 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
2015 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:492016 scoped_ptr<media::FilterCollection> collection(
2017 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:372018
[email protected]3d9689372009-09-10 04:29:172019 // Add in any custom filter factories first.
2020 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2021 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2022 // Add the chrome specific audio renderer.
[email protected]f7eb0a392011-07-12 10:19:512023 collection->AddAudioRenderer(new AudioRendererImpl());
[email protected]3d9689372009-09-10 04:29:172024 }
2025
[email protected]457d8342010-10-23 01:20:372026 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:312027 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2028 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
2029 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:492030 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:312031 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:112032
[email protected]a8e24d522010-12-01 07:13:582033 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:272034 new webkit_glue::WebMediaPlayerImpl(client,
2035 collection.release(),
[email protected]ab2c4732011-07-20 19:57:402036 message_loop_factory.release(),
[email protected]090f7312011-08-05 23:26:402037 media_stream_impl_.get(),
2038 new RenderMediaLog()));
[email protected]79684282010-12-06 21:15:462039 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:582040 cmd_line->HasSwitch(switches::kSimpleDataSource),
2041 video_renderer)) {
2042 return NULL;
2043 }
2044 return result.release();
[email protected]3d9689372009-09-10 04:29:172045}
2046
[email protected]035545f2010-04-09 13:10:212047WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2048 WebFrame* frame, WebApplicationCacheHostClient* client) {
2049 return new RendererWebApplicationCacheHostImpl(
2050 FromWebView(frame->view()), client,
2051 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2052}
2053
[email protected]8ff181072010-11-29 17:09:382054WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
2055 return &cookie_jar_;
2056}
2057
[email protected]5041f982010-08-11 21:40:452058void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512059 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452060}
2061
[email protected]3d9689372009-09-10 04:29:172062void RenderView::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512063 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172064}
2065
2066void RenderView::loadURLExternally(
2067 WebFrame* frame, const WebURLRequest& request,
2068 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342069 loadURLExternally(frame, request, policy, WebString());
2070}
2071
2072void RenderView::loadURLExternally(
2073 WebFrame* frame, const WebURLRequest& request,
2074 WebNavigationPolicy policy,
2075 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592076 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2077 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342078 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2079 suggested_name));
[email protected]efce17b2009-09-11 18:04:592080 } else {
2081 OpenURL(request.url(), referrer, policy);
2082 }
[email protected]3d9689372009-09-10 04:29:172083}
2084
2085WebNavigationPolicy RenderView::decidePolicyForNavigation(
2086 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222087 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152088 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2089 if (is_swapped_out_) {
2090 DCHECK(request.url() == GURL("about:swappedout"));
2091 return default_policy;
2092 }
2093
[email protected]3d9689372009-09-10 04:29:172094 // Webkit is asking whether to navigate to a new URL.
2095 // This is fine normally, except if we're showing UI from one security
2096 // context and they're trying to navigate to a different context.
2097 const GURL& url = request.url();
2098
[email protected]d19ea342011-04-20 20:31:132099 // A content initiated navigation may have originated from a link-click,
2100 // script, drag-n-drop operation, etc.
2101 bool is_content_initiated =
2102 NavigationState::FromDataSource(frame->provisionalDataSource())->
2103 is_content_initiated();
2104
[email protected]3d9689372009-09-10 04:29:172105 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302106 // navigations.
[email protected]d19ea342011-04-20 20:31:132107 if (is_content_initiated &&
2108 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:452109 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192110 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232111 // Reset these counters as the RenderView could be reused for the next
2112 // navigation.
2113 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232114 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192115 OpenURL(url, referrer, default_policy);
2116 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172117 }
2118
[email protected]b6cb3a842011-06-24 18:28:412119 GURL old_url(frame->document().url());
[email protected]3d9689372009-09-10 04:29:172120
[email protected]6101c342010-12-16 22:44:372121 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552122 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572123 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372124 // opening a new window). But we sometimes navigate to about:blank to clear a
2125 // tab, and we want to still allow that.
2126 //
[email protected]8f4da8c2011-02-09 19:49:572127 // Note: we do this only for GET requests because our mechanism for switching
2128 // processes only issues GET requests. In particular, POST requests don't
2129 // work, because this mechanism does not preserve form POST data. If it
2130 // becomes necessary to support process switching for POST requests, we will
2131 // need to send the request's httpBody data up to the browser process, and
2132 // issue a special POST navigation in WebKit (via
2133 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2134 // for examples of how to send the httpBody data.
2135 // Note2: We normally don't do this for browser-initiated navigations, since
2136 // it's pointless to tell the browser about navigations it gave us. But
2137 // we do potentially ask the browser to handle a redirect that was originally
2138 // initiated by the browser. See http://crbug.com/70943
2139 //
2140 // TODO(creis): Move this redirect check to the browser process to avoid
2141 // ping-ponging. See http://crbug.com/72380.
2142 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372143 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2144 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2145 bool send_referrer = false;
2146 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552147 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172148 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372149 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112150
[email protected]e48869a2011-04-01 19:56:032151 if (!should_fork) {
2152 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362153 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032154 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362155 frame, url, is_content_initiated, is_initial_navigation,
2156 &send_referrer);
[email protected]6101c342010-12-16 22:44:372157 }
2158
2159 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112160 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372161 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112162 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2163 }
[email protected]3d9689372009-09-10 04:29:172164 }
2165
2166 // Detect when a page is "forking" a new tab that can be safely rendered in
2167 // its own process. This is done by sites like Gmail that try to open links
2168 // in new windows without script connections back to the original page. We
2169 // treat such cases as browser navigations (in which we will create a new
2170 // renderer for a cross-site navigation), rather than WebKit navigations.
2171 //
2172 // We use the following heuristic to decide whether to fork a new page in its
2173 // own process:
2174 // The parent page must open a new tab to about:blank, set the new tab's
2175 // window.opener to null, and then redirect the tab to a cross-site URL using
2176 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462177 //
2178 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2179 // (see below).
[email protected]3d9689372009-09-10 04:29:172180 bool is_fork =
2181 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582182 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172183 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522184 historyBackListCount() < 1 &&
2185 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172186 // The parent page must have set the child's window.opener to null before
2187 // redirecting to the desired URL.
2188 frame->opener() == NULL &&
2189 // Must be a top-level frame.
2190 frame->parent() == NULL &&
2191 // Must not have issued the request from this page.
2192 is_content_initiated &&
2193 // Must be targeted at the current tab.
2194 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2195 // Must be a JavaScript navigation, which appears as "other".
2196 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462197
2198 // Recognize if this navigation is from a link with rel=noreferrer and
2199 // target=_blank attributes, in which case the opener will be suppressed. If
2200 // so, it is safe to load cross-site pages in a separate process, so we
2201 // should let the browser handle it.
2202 bool is_noreferrer_and_blank_target =
2203 // Frame should be top level and not yet navigated.
2204 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412205 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462206 historyBackListCount() < 1 &&
2207 historyForwardListCount() < 1 &&
2208 // Links with rel=noreferrer will have no Referer field, and their
2209 // resulting frame will have its window.opener suppressed.
2210 // TODO(creis): should add a request.httpReferrer() method to help avoid
2211 // typos on the unusual spelling of Referer.
2212 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2213 opener_suppressed_ &&
2214 frame->opener() == NULL &&
2215 // Links with target=_blank will have no name.
2216 frame->name().isNull() &&
2217 // Another frame (with a non-empty creator) should have initiated the
2218 // request, targeted at this frame.
2219 !creator_url_.is_empty() &&
2220 is_content_initiated &&
2221 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2222 type == WebKit::WebNavigationTypeOther;
2223
2224 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172225 // Open the URL via the browser, not via WebKit.
2226 OpenURL(url, GURL(), default_policy);
2227 return WebKit::WebNavigationPolicyIgnore;
2228 }
2229
2230 return default_policy;
2231}
2232
[email protected]6069da8c2009-10-20 20:33:492233bool RenderView::canHandleRequest(
2234 WebFrame* frame, const WebURLRequest& request) {
2235 // We allow WebKit to think that everything can be handled even though
2236 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342237 return true;
2238}
2239
[email protected]6069da8c2009-10-20 20:33:492240WebURLError RenderView::cannotHandleRequestError(
2241 WebFrame* frame, const WebURLRequest& request) {
2242 NOTREACHED(); // Since we said we can handle all requests.
2243 return WebURLError();
2244}
2245
2246WebURLError RenderView::cancelledError(
2247 WebFrame* frame, const WebURLRequest& request) {
2248 WebURLError error;
2249 error.domain = WebString::fromUTF8(net::kErrorDomain);
2250 error.reason = net::ERR_ABORTED;
2251 error.unreachableURL = request.url();
2252 return error;
[email protected]7b7a7dc2009-10-19 02:23:342253}
2254
2255void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492256 WebFrame*, const WebURLError&) {
2257 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342258}
2259
[email protected]90eeddb2010-05-06 21:06:432260void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2261 const WebKit::WebFormElement& form) {
2262 // Some login forms have onSubmit handlers that put a hash of the password
2263 // into a hidden field and then clear the password. (Issue 28910.)
2264 // This method gets called before any of those handlers run, so save away
2265 // a copy of the password in case it gets lost.
2266 NavigationState* navigation_state =
2267 NavigationState::FromDataSource(frame->dataSource());
2268 navigation_state->set_password_form_data(
2269 PasswordFormDomManager::CreatePasswordForm(form));
2270}
2271
[email protected]979c28b2009-11-07 01:30:482272void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172273 NavigationState* navigation_state =
2274 NavigationState::FromDataSource(frame->provisionalDataSource());
2275
2276 if (navigation_state->transition_type() == PageTransition::LINK)
2277 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2278
2279 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352280 WebSearchableFormData web_searchable_form_data(form);
2281 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2282 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212283 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432284 PasswordForm* password_form_data =
2285 PasswordFormDomManager::CreatePasswordForm(form);
2286 navigation_state->set_password_form_data(password_form_data);
2287
[email protected]098c95cb2011-04-28 16:49:012288 // In order to save the password that the user actually typed and not one
2289 // that may have gotten transformed by the site prior to submit, recover it
2290 // from the form contents already stored by |willSendSubmitEvent| into the
2291 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2292 // which is what we're storing into now.)
2293 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432294 NavigationState* old_navigation_state =
2295 NavigationState::FromDataSource(frame->dataSource());
2296 if (old_navigation_state) {
2297 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2298 if (old_form_data && old_form_data->action == password_form_data->action)
2299 password_form_data->password_value = old_form_data->password_value;
2300 }
2301 }
[email protected]3d9689372009-09-10 04:29:172302
[email protected]2a5b1732011-04-01 23:55:552303 FOR_EACH_OBSERVER(
2304 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172305}
2306
2307void RenderView::willPerformClientRedirect(
2308 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2309 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382310 FOR_EACH_OBSERVER(
2311 RenderViewObserver, observers_,
2312 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172313}
2314
2315void RenderView::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382316 FOR_EACH_OBSERVER(
2317 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172318}
2319
2320void RenderView::didCompleteClientRedirect(
2321 WebFrame* frame, const WebURL& from) {
2322 if (!frame->parent())
2323 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382324 FOR_EACH_OBSERVER(
2325 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172326}
2327
2328void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2329 // The rest of RenderView assumes that a WebDataSource will always have a
2330 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482331 bool content_initiated = !pending_navigation_state_.get();
2332 NavigationState* state = content_initiated ?
2333 NavigationState::CreateContentInitiated() :
2334 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512335
[email protected]8a3125a712010-08-09 18:58:512336 // NavigationState::referred_by_prefetcher_ is true if we are
2337 // navigating from a page that used prefetching using a link on that
2338 // page. We are early enough in the request process here that we
2339 // can still see the NavigationState of the previous page and set
2340 // this value appropriately.
2341 // TODO(gavinp): catch the important case of navigation in a new
2342 // renderer process.
2343 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302344 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522345 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512346 const GURL referrer(
2347 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2348 if (!referrer.is_empty() &&
2349 NavigationState::FromDataSource(
2350 old_frame->dataSource())->was_prefetcher()) {
2351 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2352 WebDataSource* old_frame_ds = old_frame->dataSource();
2353 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2354 state->set_was_referred_by_prefetcher(true);
2355 break;
2356 }
2357 }
2358 }
2359 }
2360 }
2361
[email protected]4c1b6f0b2010-02-07 16:38:182362 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522363 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512364 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182365 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2366 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2367 break;
2368 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2369 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2370 break;
2371 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2372 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2373 break;
2374 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2375 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2376 break;
2377 }
2378 }
[email protected]fa7b6b542009-11-03 05:02:302379
[email protected]16e923d2011-04-30 00:41:442380 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502381
[email protected]946a0032011-03-31 18:42:282382 FOR_EACH_OBSERVER(
2383 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172384}
2385
2386void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2387 WebDataSource* ds = frame->provisionalDataSource();
2388 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2389
[email protected]3d9689372009-09-10 04:29:172390 // Update the request time if WebKit has better knowledge of it.
2391 if (navigation_state->request_time().is_null()) {
2392 double event_time = ds->triggeringEventTime();
2393 if (event_time != 0.0)
2394 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2395 }
2396
[email protected]05c8e502010-08-15 15:13:522397 // Start time is only set after request time.
2398 navigation_state->set_start_load_time(Time::Now());
2399
[email protected]3d9689372009-09-10 04:29:172400 bool is_top_most = !frame->parent();
2401 if (is_top_most) {
2402 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132403 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172404
2405 // Make sure redirect tracking state is clear for the new load.
2406 completed_client_redirect_src_ = GURL();
2407 } else if (frame->parent()->isLoading()) {
2408 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002409 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172410 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2411 }
2412
[email protected]28685da92011-02-07 21:49:172413 FOR_EACH_OBSERVER(
2414 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2415
[email protected]eacb080b2011-05-22 19:40:262416 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]3d9689372009-09-10 04:29:172417 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]eacb080b2011-05-22 19:40:262418 routing_id_, frame->identifier(), is_top_most, has_opener_set,
2419 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172420}
2421
2422void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2423 if (frame->parent())
2424 return;
2425 // Received a redirect on the main frame.
2426 WebDataSource* data_source = frame->provisionalDataSource();
2427 if (!data_source) {
2428 // Should only be invoked when we have a data source.
2429 NOTREACHED();
2430 return;
2431 }
2432 std::vector<GURL> redirects;
2433 GetRedirectChain(data_source, &redirects);
2434 if (redirects.size() >= 2) {
[email protected]eacb080b2011-05-22 19:40:262435 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]40bd6582009-12-04 23:49:512436 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]eacb080b2011-05-22 19:40:262437 has_opener_set, redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172438 }
2439}
2440
[email protected]40bd6582009-12-04 23:49:512441void RenderView::didFailProvisionalLoad(WebFrame* frame,
2442 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172443 // Notify the browser that we failed a provisional load with an error.
2444 //
2445 // Note: It is important this notification occur before DidStopLoading so the
2446 // SSL manager can react to the provisional load failure before being
2447 // notified the load stopped.
2448 //
2449 WebDataSource* ds = frame->provisionalDataSource();
2450 DCHECK(ds);
2451
2452 const WebURLRequest& failed_request = ds->request();
2453
[email protected]28685da92011-02-07 21:49:172454 FOR_EACH_OBSERVER(
2455 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2456
[email protected]3d9689372009-09-10 04:29:172457 bool show_repost_interstitial =
2458 (error.reason == net::ERR_CACHE_MISS &&
2459 EqualsASCII(failed_request.httpMethod(), "POST"));
2460 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072461 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2462 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172463
2464 // Don't display an error page if this is simply a cancelled load. Aside
2465 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2466 if (error.reason == net::ERR_ABORTED)
2467 return;
2468
2469 // Make sure we never show errors in view source mode.
2470 frame->enableViewSourceMode(false);
2471
2472 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2473
2474 // If this is a failed back/forward/reload navigation, then we need to do a
2475 // 'replace' load. This is necessary to avoid messing up session history.
2476 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2477 // as session history is concerned.
2478 //
2479 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2480 // the page id.
2481 //
2482 bool replace =
2483 navigation_state->pending_page_id() != -1 ||
2484 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2485
2486 // If we failed on a browser initiated request, then make sure that our error
2487 // page load is regarded as the same browser initiated request.
2488 if (!navigation_state->is_content_initiated()) {
2489 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2490 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002491 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172492 navigation_state->transition_type(),
2493 navigation_state->request_time()));
2494 }
2495
[email protected]c5c1d6d2011-07-28 18:42:412496 // Do not show alternate error page when DevTools is attached.
2497 if (devtools_agent_->IsAttached())
2498 return;
2499
[email protected]3d9689372009-09-10 04:29:172500 // Provide the user with a more helpful error page?
2501 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2502 return;
2503
2504 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082505 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172506}
2507
2508void RenderView::didReceiveDocumentData(
2509 WebFrame* frame, const char* data, size_t data_len,
2510 bool& prevent_default) {
2511 NavigationState* navigation_state =
2512 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092513 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172514}
2515
[email protected]40bd6582009-12-04 23:49:512516void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2517 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172518 NavigationState* navigation_state =
2519 NavigationState::FromDataSource(frame->dataSource());
2520
2521 navigation_state->set_commit_load_time(Time::Now());
2522 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202523 // When we perform a new navigation, we need to update the last committed
2524 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172525 UpdateSessionHistory(frame);
2526
2527 // We bump our Page ID to correspond with the new session history entry.
2528 page_id_ = next_page_id_++;
2529
[email protected]3cc72b12010-03-18 23:03:002530 // Advance our offset in session history, applying the length limit. There
2531 // is now no forward history.
2532 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102533 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2534 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002535 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032536 history_page_ids_.resize(history_list_length_, -1);
2537 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172538 } else {
2539 // Inspect the navigation_state on this frame to see if the navigation
2540 // corresponds to a session history navigation... Note: |frame| may or
2541 // may not be the toplevel frame, but for the case of capturing session
2542 // history, the first committed frame suffices. We keep track of whether
2543 // we've seen this commit before so that only capture session history once
2544 // per navigation.
2545 //
2546 // Note that we need to check if the page ID changed. In the case of a
2547 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2548 // previous URL and the current page ID, which would be wrong.
2549 if (navigation_state->pending_page_id() != -1 &&
2550 navigation_state->pending_page_id() != page_id_ &&
2551 !navigation_state->request_committed()) {
2552 // This is a successful session history navigation!
2553 UpdateSessionHistory(frame);
2554 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002555
2556 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032557
2558 // If the history list is valid, our list of page IDs should be correct.
2559 DCHECK(history_list_length_ <= 0 ||
2560 history_list_offset_ < 0 ||
2561 history_list_offset_ >= history_list_length_ ||
2562 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172563 }
2564 }
2565
[email protected]28685da92011-02-07 21:49:172566 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2567 DidCommitProvisionalLoad(frame, is_new_navigation));
2568
[email protected]3d9689372009-09-10 04:29:172569 // Remember that we've already processed this request, so we don't update
2570 // the session history again. We do this regardless of whether this is
2571 // a session history navigation, because if we attempted a session history
2572 // navigation without valid HistoryItem state, WebCore will think it is a
2573 // new navigation.
2574 navigation_state->set_request_committed(true);
2575
2576 UpdateURL(frame);
2577
2578 // If this committed load was initiated by a client redirect, we're
2579 // at the last stop now, so clear it.
2580 completed_client_redirect_src_ = GURL();
2581
2582 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272583 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172584}
2585
2586void RenderView::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102587 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2588 DidClearWindowObject(frame));
2589
[email protected]b6cb3a842011-06-24 18:28:412590 GURL frame_url = frame->document().url();
[email protected]c09163a2011-02-15 00:05:552591 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:252592 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2593 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272594 GetWebUIBindings()->set_message_sender(this);
2595 GetWebUIBindings()->set_routing_id(routing_id_);
2596 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172597 }
[email protected]3d9689372009-09-10 04:29:172598}
2599
2600void RenderView::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172601 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412602 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252603 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272604 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172605 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2606 }
[email protected]e48869a2011-04-01 19:56:032607
2608 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2609 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172610}
2611
[email protected]a3bc4d12011-04-20 17:22:212612void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title,
2613 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462614 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172615
2616 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272617 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172618}
2619
[email protected]42054a252011-05-17 18:02:132620void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
2621 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2622 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582623}
2624
[email protected]3d9689372009-09-10 04:29:172625void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2626 WebDataSource* ds = frame->dataSource();
2627 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2628 DCHECK(navigation_state);
2629 navigation_state->set_finish_document_load_time(Time::Now());
2630
[email protected]622474d2010-11-04 09:21:082631 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172632
[email protected]28685da92011-02-07 21:49:172633 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2634 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172635
2636 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272637 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172638}
2639
2640void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082641 if (webview()->mainFrame() == frame) {
2642 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2643 page_id_));
2644 }
[email protected]3d9689372009-09-10 04:29:172645}
2646
2647void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172648 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172649}
2650
2651void RenderView::didFinishLoad(WebFrame* frame) {
2652 WebDataSource* ds = frame->dataSource();
2653 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2654 DCHECK(navigation_state);
2655 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412656
[email protected]676126f72011-01-15 00:03:512657 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172658
2659 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172660}
2661
[email protected]ccbe04e2010-03-17 17:58:432662void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172663 WebFrame* frame, bool is_new_navigation) {
2664 // If this was a reference fragment navigation that we initiated, then we
2665 // could end up having a non-null pending navigation state. We just need to
2666 // update the ExtraData on the datasource so that others who read the
2667 // ExtraData will get the new NavigationState. Similarly, if we did not
2668 // initiate this navigation, then we need to take care to reset any pre-
2669 // existing navigation state to a content-initiated navigation state.
2670 // DidCreateDataSource conveniently takes care of this for us.
2671 didCreateDataSource(frame, frame->dataSource());
2672
[email protected]af15bed2010-08-25 21:12:092673 NavigationState* new_state =
2674 NavigationState::FromDataSource(frame->dataSource());
2675 new_state->set_was_within_same_page(true);
2676
[email protected]3d9689372009-09-10 04:29:172677 didCommitProvisionalLoad(frame, is_new_navigation);
2678
[email protected]750fcf872011-08-03 23:10:472679 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2680 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172681}
2682
[email protected]476b6f82009-09-10 21:00:592683void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312684 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592685}
2686
[email protected]3d9689372009-09-10 04:29:172687void RenderView::assignIdentifierToRequest(
2688 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2689 // Ignore
2690}
2691
2692void RenderView::willSendRequest(
2693 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2694 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302695 WebFrame* top_frame = frame->top();
2696 if (!top_frame)
2697 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512698 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2699 WebDataSource* top_data_source = top_frame->dataSource();
2700 WebDataSource* data_source =
2701 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222702
[email protected]418da612011-07-21 19:01:522703 bool is_top_frame = (frame == top_frame);
2704 request.setExtraData(
2705 new RequestExtraData(is_top_frame, frame->identifier()));
[email protected]e48869a2011-04-01 19:56:032706
[email protected]78d5cfe2011-02-04 08:43:222707 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032708 GURL new_url;
2709 if (content::GetContentClient()->renderer()->WillSendRequest(
2710 frame, request_url, &new_url)) {
2711 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222712 }
2713
[email protected]5e369672009-11-03 23:48:302714 if (data_source) {
2715 NavigationState* state = NavigationState::FromDataSource(data_source);
2716 if (state && state->is_cache_policy_override_set())
2717 request.setCachePolicy(state->cache_policy_override());
2718 }
[email protected]8a3125a712010-08-09 18:58:512719
2720 if (top_data_source) {
2721 NavigationState* state = NavigationState::FromDataSource(top_data_source);
[email protected]61a99dd82011-05-24 19:19:472722 // TODO(gavinp): separate out prefetching and prerender field trials
2723 // if the rel=prerender rel type is sticking around.
2724 if (state && (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2725 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]8a3125a712010-08-09 18:58:512726 state->set_was_prefetcher(true);
2727 }
2728
[email protected]3d9689372009-09-10 04:29:172729 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132730 request.setHasUserGesture(frame->isProcessingUserGesture());
2731
[email protected]0a8db0d2011-04-13 15:15:402732 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132733 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172734}
2735
2736void RenderView::didReceiveResponse(
2737 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492738
[email protected]3d9689372009-09-10 04:29:172739 // Only do this for responses that correspond to a provisional data source
2740 // of the top-most frame. If we have a provisional data source, then we
2741 // can't have any sub-resources yet, so we know that this response must
2742 // correspond to a frame load.
2743 if (!frame->provisionalDataSource() || frame->parent())
2744 return;
2745
2746 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082747 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172748 if (frame->isViewSourceModeEnabled())
2749 return;
2750
[email protected]65041fa2010-05-21 06:56:532751 NavigationState* navigation_state =
2752 NavigationState::FromDataSource(frame->provisionalDataSource());
2753 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082754 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532755
[email protected]972ebdff2010-06-10 22:59:072756 // Record page load flags.
2757 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2758 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572759 navigation_state->set_was_alternate_protocol_available(
2760 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072761 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082762 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092763 // Whether or not the http status code actually corresponds to an error is
2764 // only checked when the page is done loading, if |use_error_page| is
2765 // still true.
2766 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172767}
2768
2769void RenderView::didFinishResourceLoad(
2770 WebFrame* frame, unsigned identifier) {
2771 NavigationState* navigation_state =
2772 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092773 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172774 return;
2775
[email protected]06333afe2011-02-24 14:55:092776 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082777 int http_status_code = navigation_state->http_status_code();
2778 if (http_status_code == 404) {
2779 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412780 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172781
[email protected]b6cb3a842011-06-24 18:28:412782 const GURL& error_page_url =
2783 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092784 if (error_page_url.is_valid()) {
2785 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472786 original_error.domain = "http";
2787 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412788 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172789
[email protected]06333afe2011-02-24 14:55:092790 navigation_state->set_alt_error_page_fetcher(
2791 new AltErrorPageResourceFetcher(
2792 error_page_url, frame, original_error,
2793 NewCallback(this, &RenderView::AltErrorPageFinished)));
2794 return;
2795 }
2796 }
[email protected]3d9689372009-09-10 04:29:172797
[email protected]9966325b2011-04-18 05:00:102798 content::GetContentClient()->renderer()->ShowErrorPage(
2799 this, frame, http_status_code);
[email protected]3d9689372009-09-10 04:29:172800}
2801
2802void RenderView::didFailResourceLoad(
2803 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2804 // Ignore
2805}
2806
2807void RenderView::didLoadResourceFromMemoryCache(
2808 WebFrame* frame, const WebURLRequest& request,
2809 const WebURLResponse& response) {
2810 // Let the browser know we loaded a resource from the memory cache. This
2811 // message is needed to display the correct SSL indicators.
2812 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2813 routing_id_,
2814 request.url(),
[email protected]70435962011-08-02 20:13:282815 response.securityInfo(),
2816 request.httpMethod().utf8(),
2817 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172818}
2819
[email protected]6069da8c2009-10-20 20:33:492820void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292821 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2822}
2823
[email protected]92771112011-01-20 00:13:022824void RenderView::didRunInsecureContent(
2825 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292826 Send(new ViewHostMsg_DidRunInsecureContent(
2827 routing_id_,
[email protected]92771112011-01-20 00:13:022828 origin.toString().utf8(),
2829 target));
[email protected]e3d60e5d2009-09-25 21:08:292830}
2831
[email protected]b00ba702011-08-17 01:41:032832void RenderView::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
2833 webkit_glue::WebURLLoaderImpl* loader_impl =
2834 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2835 loader_impl->UpdateRoutingId(routing_id_);
2836}
2837
[email protected]3d9689372009-09-10 04:29:172838void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2839 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2840}
2841
[email protected]0c882b282009-10-07 17:01:282842void RenderView::didCreateScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032843 content::GetContentClient()->renderer()->DidCreateScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282844}
2845
2846void RenderView::didDestroyScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032847 content::GetContentClient()->renderer()->DidDestroyScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282848}
2849
[email protected]5a9ff1d2011-08-17 06:23:302850void RenderView::didCreateIsolatedScriptContext(
2851 WebFrame* frame, int world_id, v8::Handle<v8::Context> context) {
[email protected]e48869a2011-04-01 19:56:032852 content::GetContentClient()->renderer()->DidCreateIsolatedScriptContext(
[email protected]5a9ff1d2011-08-17 06:23:302853 frame, world_id, context);
[email protected]0c882b282009-10-07 17:01:282854}
2855
[email protected]d812fd12011-05-27 23:05:072856void RenderView::didUpdateLayout(WebFrame* frame) {
2857 // We don't always want to set up a timer, only if we've been put in that
2858 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172859 // message.
[email protected]705243f2010-05-05 19:58:072860 if (!send_preferred_size_changes_ || !webview())
2861 return;
[email protected]dfca5acf2010-03-22 03:28:432862
[email protected]d812fd12011-05-27 23:05:072863 if (check_preferred_size_timer_.IsRunning())
2864 return;
2865 check_preferred_size_timer_.Start(TimeDelta::FromMilliseconds(0), this,
2866 &RenderView::CheckPreferredSize);
2867}
2868
2869void RenderView::CheckPreferredSize() {
2870 // We don't always want to send the change messages over IPC, only if we've
2871 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2872 // message.
2873 if (!send_preferred_size_changes_ || !webview())
2874 return;
2875
[email protected]705243f2010-05-05 19:58:072876 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2877 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532878
2879 // In the presence of zoom, these sizes are still reported as if unzoomed,
2880 // so we need to adjust.
2881 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2882 size.set_width(static_cast<int>(size.width() * zoom_factor));
2883 size.set_height(static_cast<int>(size.height() * zoom_factor));
2884
[email protected]705243f2010-05-05 19:58:072885 if (size == preferred_size_)
2886 return;
[email protected]c27324b2009-11-19 22:44:292887
[email protected]705243f2010-05-05 19:58:072888 preferred_size_ = size;
2889 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2890 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172891}
2892
[email protected]dd6afca2011-08-13 03:44:312893void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2894 if (webview()->mainFrame() != frame)
2895 return;
2896 WebView* frameView = frame->view();
2897 if (!frameView)
2898 return;
2899
2900 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
2901 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
2902
2903 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
2904 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
2905 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
2906 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
2907
2908 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
2909 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
2910 }
2911}
2912
2913void RenderView::UpdateScrollState(WebFrame* frame) {
2914 WebSize offset = frame->scrollOffset();
2915 WebSize minimum_offset = frame->minimumScrollOffset();
2916 WebSize maximum_offset = frame->maximumScrollOffset();
2917
2918 bool is_pinned_to_left = offset.width <= minimum_offset.width;
2919 bool is_pinned_to_right = offset.width >= maximum_offset.width;
2920
2921 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
2922 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
2923 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
2924 routing_id_, is_pinned_to_left, is_pinned_to_right));
2925
2926 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
2927 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
2928 }
2929}
2930
[email protected]143dcd592009-11-06 21:33:492931void RenderView::didChangeScrollOffset(WebFrame* frame) {
2932 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:312933
2934 if (webview()->mainFrame() == frame)
2935 UpdateScrollState(frame);
2936}
2937
2938void RenderView::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2939 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:492940}
2941
[email protected]8922e1f2009-10-03 05:01:262942void RenderView::reportFindInPageMatchCount(int request_id, int count,
2943 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112944 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2945 if (!count)
2946 active_match_ordinal = 0;
2947
2948 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2949 routing_id_,
2950 request_id,
2951 count,
2952 gfx::Rect(),
2953 active_match_ordinal,
2954 final_update);
2955
[email protected]8922e1f2009-10-03 05:01:262956 // If we have a message that has been queued up, then we should just replace
2957 // it. The ACK from the browser will make sure it gets sent when the browser
2958 // wants it.
2959 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262960 queued_find_reply_message_.reset(msg);
2961 } else {
2962 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112963 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262964 }
2965}
2966
2967void RenderView::reportFindInPageSelection(int request_id,
2968 int active_match_ordinal,
2969 const WebRect& selection_rect) {
2970 // Send the search result over to the browser process.
2971 Send(new ViewHostMsg_Find_Reply(routing_id_,
2972 request_id,
2973 -1,
2974 selection_rect,
2975 active_match_ordinal,
2976 false));
2977}
2978
[email protected]2b06a992010-08-21 05:48:222979void RenderView::openFileSystem(
2980 WebFrame* frame,
2981 WebFileSystem::Type type,
2982 long long size,
[email protected]d275d7a2010-11-03 01:34:492983 bool create,
[email protected]2b06a992010-08-21 05:48:222984 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082985 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222986
[email protected]b6cb3a842011-06-24 18:28:412987 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082988 if (origin.isEmpty()) {
2989 // Uninitialized document?
2990 callbacks->didFail(WebKit::WebFileErrorAbort);
2991 return;
2992 }
[email protected]2b06a992010-08-21 05:48:222993
[email protected]c5a272d2010-09-27 18:37:082994 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2995 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492996 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222997}
2998
[email protected]10e5cf12011-04-13 04:10:402999void RenderView::queryStorageUsageAndQuota(
3000 WebFrame* frame,
3001 WebStorageQuotaType type,
3002 WebStorageQuotaCallbacks* callbacks) {
3003 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413004 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:403005 if (origin.isEmpty()) {
3006 // Uninitialized document?
3007 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3008 return;
3009 }
3010 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533011 GURL(origin.toString()),
3012 static_cast<quota::StorageType>(type),
3013 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403014}
3015
3016void RenderView::requestStorageQuota(
3017 WebFrame* frame,
3018 WebStorageQuotaType type,
3019 unsigned long long requested_size,
3020 WebStorageQuotaCallbacks* callbacks) {
3021 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413022 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:403023 if (origin.isEmpty()) {
3024 // Uninitialized document?
3025 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3026 return;
3027 }
3028 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533029 routing_id(), GURL(origin.toString()),
3030 static_cast<quota::StorageType>(type), requested_size,
3031 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403032}
3033
[email protected]18d5be92011-07-25 18:00:193034// WebKit::WebPageSerializerClient implementation ------------------------------
3035
3036void RenderView::didSerializeDataForFrame(
3037 const WebURL& frame_url,
3038 const WebCString& data,
3039 WebPageSerializerClient::PageSerializationStatus status) {
3040 Send(new ViewHostMsg_SendSerializedHtmlData(
3041 routing_id(),
3042 frame_url,
3043 data.data(),
3044 static_cast<int32>(status)));
3045}
3046
[email protected]79dbc662009-09-04 05:42:513047// webkit_glue::WebPluginPageDelegate -----------------------------------------
3048
[email protected]191eb3f72010-12-21 06:27:503049webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533050 const FilePath& file_path,
3051 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593052 if (!PluginChannelHost::IsListening())
3053 return NULL;
3054
[email protected]00c39612010-03-06 02:53:283055 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463056 if (in_process_plugin) {
[email protected]6876dff2010-01-15 19:38:093057#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]e8f7a182011-03-10 00:50:223058 return webkit::npapi::WebPluginDelegateImpl::Create(
3059 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093060#else
[email protected]e8f7a182011-03-10 00:50:223061 NOTIMPLEMENTED();
3062 return NULL;
[email protected]7b6616f2010-01-14 18:07:553063#endif
[email protected]f103ab72009-09-02 17:10:593064 }
3065
[email protected]4e0616e2010-05-28 14:55:533066 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593067}
3068
3069void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033070#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593071 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3072 routing_id(), window));
3073#endif
3074}
3075
3076void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033077#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593078 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3079 routing_id(), window));
3080#endif
3081 CleanupWindowInPluginMoves(window);
3082}
3083
[email protected]191eb3f72010-12-21 06:27:503084void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593085 SchedulePluginMove(move);
3086}
3087
3088void RenderView::DidStartLoadingForPlugin() {
3089 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523090 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593091}
3092
3093void RenderView::DidStopLoadingForPlugin() {
3094 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523095 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593096}
3097
[email protected]b921cfd22010-02-25 16:57:513098WebCookieJar* RenderView::GetCookieJar() {
3099 return &cookie_jar_;
3100}
3101
initial.commit09911bf2008-07-26 23:55:293102void RenderView::SyncNavigationState() {
3103 if (!webview())
3104 return;
3105
[email protected]26aa0482009-09-30 16:55:273106 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173107 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293108 return;
[email protected]ca948a22009-06-25 19:36:173109
3110 Send(new ViewHostMsg_UpdateState(
3111 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293112}
3113
[email protected]7ccddb8c2009-08-04 17:36:553114GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293115 ErrorPageType error_type) {
[email protected]c5c1d6d2011-07-28 18:42:413116
[email protected]7ccddb8c2009-08-04 17:36:553117 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293118 // If the URL that failed was secure, then the embedding web page was not
3119 // expecting a network attacker to be able to manipulate its contents. As
3120 // we fetch alternate error pages over HTTP, we would be allowing a network
3121 // attacker to manipulate the contents of the response if we tried to use
3122 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153123 return GURL();
initial.commit09911bf2008-07-26 23:55:293124 }
3125
[email protected]c5c1d6d2011-07-28 18:42:413126 if (devtools_agent_->IsAttached()) {
3127 // Do not show alternate error page when DevTools is attached.
3128 return GURL();
3129 }
3130
initial.commit09911bf2008-07-26 23:55:293131 // Grab the base URL from the browser process.
3132 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153133 return GURL();
initial.commit09911bf2008-07-26 23:55:293134
3135 // Strip query params from the failed URL.
3136 GURL::Replacements remove_params;
3137 remove_params.ClearUsername();
3138 remove_params.ClearPassword();
3139 remove_params.ClearQuery();
3140 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553141 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503142 std::string spec_to_send = url_to_send.spec();
3143 // Notify link doctor of the url truncation by sending of "?" at the end.
3144 if (failed_url.has_query())
3145 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293146
3147 // Construct the query params to send to link doctor.
3148 std::string params(alternate_error_page_url_.query());
3149 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503150 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293151 params.append("&sourceid=chrome");
3152 params.append("&error=");
3153 switch (error_type) {
3154 case DNS_ERROR:
3155 params.append("dnserror");
3156 break;
3157
3158 case HTTP_404:
3159 params.append("http404");
3160 break;
3161
[email protected]5df266ac2008-10-15 19:50:133162 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333163 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133164 break;
3165
initial.commit09911bf2008-07-26 23:55:293166 default:
3167 NOTREACHED() << "unknown ErrorPageType";
3168 }
3169
3170 // OK, build the final url to return.
3171 GURL::Replacements link_doctor_params;
3172 link_doctor_params.SetQueryStr(params);
3173 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3174 return url;
3175}
3176
[email protected]c50008512011-02-03 01:17:273177WebUIBindings* RenderView::GetWebUIBindings() {
3178 if (!web_ui_bindings_.get()) {
3179 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:463180 }
[email protected]c50008512011-02-03 01:17:273181 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463182}
3183
[email protected]0fdbf8c2010-07-08 20:33:013184WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3185 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493186}
3187
[email protected]6069da8c2009-10-20 20:33:493188void RenderView::OnFind(int request_id, const string16& search_text,
3189 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273190 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493191
[email protected]872542532011-06-23 00:43:163192 // Check if the plugin still exists in the document.
3193 if (main_frame->document().isPluginDocument() &&
3194 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493195 if (options.findNext) {
3196 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013197 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493198 } else {
[email protected]afdbd142010-07-10 08:01:233199 if (GetWebPluginFromPluginDocument()->startFind(
3200 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493201 } else {
[email protected]e7c58a32010-08-13 19:47:113202 // Send "no results".
3203 Send(new ViewHostMsg_Find_Reply(routing_id_,
3204 request_id,
3205 0,
3206 gfx::Rect(),
3207 0,
3208 true));
[email protected]24a7f3c2010-03-25 08:26:493209 }
3210 }
3211 return;
3212 }
3213
[email protected]b4bb2502009-10-01 22:35:273214 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273215 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293216 WebFrame* search_frame = focused_frame; // start searching focused frame.
3217
3218 bool multi_frame = (frame_after_main != main_frame);
3219
3220 // If we have multiple frames, we don't want to wrap the search within the
3221 // frame, so we check here if we only have main_frame in the chain.
3222 bool wrap_within_frame = !multi_frame;
3223
[email protected]b3f2b912009-04-09 16:18:523224 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293225 bool result = false;
3226
[email protected]7830da3e2009-11-06 16:27:263227 // If something is selected when we start searching it means we cannot just
3228 // increment the current match ordinal; we need to re-generate it.
3229 WebRange current_selection = focused_frame->selectionRange();
3230
initial.commit09911bf2008-07-26 23:55:293231 do {
[email protected]dd7daa82009-08-10 05:46:453232 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593233 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293234
3235 if (!result) {
3236 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223237 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293238
3239 // Find the next frame, but skip the invisible ones.
3240 do {
3241 // What is the next frame to search? (we might be going backwards). Note
3242 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593243 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273244 search_frame->traverseNext(true) :
3245 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453246 } while (!search_frame->hasVisibleContent() &&
3247 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293248
[email protected]884db412008-11-24 23:46:503249 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223250 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293251
3252 // If we have multiple frames and we have wrapped back around to the
3253 // focused frame, we need to search it once more allowing wrap within
3254 // the frame, otherwise it will report 'no match' if the focused frame has
3255 // reported matches, but no frames after the focused_frame contain a
3256 // match for the search word(s).
3257 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453258 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593259 request_id, search_text, options, true, // Force wrapping.
3260 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293261 }
3262 }
3263
[email protected]26aa0482009-09-30 16:55:273264 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293265 } while (!result && search_frame != focused_frame);
3266
[email protected]7830da3e2009-11-06 16:27:263267 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293268 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453269 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293270 } else {
3271 // If nothing is found, set result to "0 of 0", otherwise, set it to
3272 // "-1 of 1" to indicate that we found at least one item, but we don't know
3273 // yet what is active.
3274 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3275 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293276
[email protected]4f3dc372009-02-24 00:10:293277 // If we find no matches then this will be our last status update.
3278 // Otherwise the scoping effort will send more results.
3279 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293280
[email protected]4f3dc372009-02-24 00:10:293281 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403282 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593283 request_id,
[email protected]4f3dc372009-02-24 00:10:293284 match_count,
3285 selection_rect,
3286 ordinal,
3287 final_status_update));
initial.commit09911bf2008-07-26 23:55:293288
initial.commit09911bf2008-07-26 23:55:293289 // Scoping effort begins, starting with the mainframe.
3290 search_frame = main_frame;
3291
[email protected]dd7daa82009-08-10 05:46:453292 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293293
3294 do {
3295 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453296 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293297
3298 // We don't start another scoping effort unless at least one match has
3299 // been found.
3300 if (result) {
3301 // Start new scoping request. If the scoping function determines that it
3302 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453303 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593304 search_text,
3305 options,
initial.commit09911bf2008-07-26 23:55:293306 true); // reset the tickmarks
3307 }
3308
3309 // Iterate to the next frame. The frame will not necessarily scope, for
3310 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273311 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293312 } while (search_frame != main_frame);
3313 }
3314}
3315
[email protected]24a7f3c2010-03-25 08:26:493316void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3317 WebView* view = webview();
3318 if (!view)
3319 return;
3320
3321 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163322 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013323 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493324 return;
3325 }
3326
3327 bool clear_selection =
3328 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3329 if (clear_selection)
3330 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3331
3332 WebFrame* frame = view->mainFrame();
3333 while (frame) {
3334 frame->stopFinding(clear_selection);
3335 frame = frame->traverseNext(false);
3336 }
3337
3338 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3339 WebFrame* focused_frame = view->focusedFrame();
3340 if (focused_frame) {
3341 WebDocument doc = focused_frame->document();
3342 if (!doc.isNull()) {
3343 WebNode node = doc.focusedNode();
3344 if (!node.isNull())
3345 node.simulateClick();
3346 }
3347 }
3348 }
3349}
3350
3351void RenderView::OnFindReplyAck() {
3352 // Check if there is any queued up request waiting to be sent.
3353 if (queued_find_reply_message_.get()) {
3354 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423355 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493356 }
3357}
3358
[email protected]0bd753682010-12-16 18:15:523359WebPlugin* RenderView::CreatePepperPlugin(
3360 WebFrame* frame,
3361 const WebPluginParams& params,
3362 const FilePath& path,
3363 webkit::ppapi::PluginModule* pepper_module) {
3364 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:253365 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:093366}
[email protected]00152e92010-07-19 11:47:403367
[email protected]191eb3f72010-12-21 06:27:503368WebPlugin* RenderView::CreateNPAPIPlugin(
3369 WebFrame* frame,
3370 const WebPluginParams& params,
3371 const FilePath& path,
3372 const std::string& mime_type) {
3373 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:083374 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403375}
3376
[email protected]40bd6582009-12-04 23:49:513377void RenderView::OnZoom(PageZoom::Function function) {
3378 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3379 return;
3380
[email protected]258d31122010-05-09 10:59:413381 webview()->hidePopups();
[email protected]c514d6372011-08-16 22:54:443382#if !defined(TOUCH_UI)
[email protected]b75b8292010-10-01 07:28:253383 double old_zoom_level = webview()->zoomLevel();
3384 double zoom_level;
3385 if (function == PageZoom::RESET) {
3386 zoom_level = 0;
3387 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3388 // Previous zoom level is a whole number, so just increment/decrement.
3389 zoom_level = old_zoom_level + function;
3390 } else {
3391 // Either the user hit the zoom factor limit and thus the zoom level is now
3392 // not a whole number, or a plugin changed it to a custom value. We want
3393 // to go to the next whole number so that the user can always get back to
3394 // 100% with the keyboard/menu.
3395 if ((old_zoom_level > 1 && function > 0) ||
3396 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453397 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253398 } else {
3399 // We're going towards 100%, so first go to the next whole number.
3400 zoom_level = static_cast<int>(old_zoom_level);
3401 }
3402 }
[email protected]b75b8292010-10-01 07:28:253403 webview()->setZoomLevel(false, zoom_level);
[email protected]c514d6372011-08-16 22:54:443404#else
3405 double old_page_scale_factor = webview()->pageScaleFactor();
3406 double page_scale_factor;
3407 if (function == PageZoom::RESET) {
3408 page_scale_factor = 1.0;
3409 } else {
3410 page_scale_factor = old_page_scale_factor +
3411 (function > 0 ? kScalingIncrement : -kScalingIncrement);
3412 }
3413 webview()->scalePage(page_scale_factor, WebPoint(0, 0));
3414#endif
[email protected]b75b8292010-10-01 07:28:253415 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513416}
3417
[email protected]d0b8d092010-10-25 04:05:173418void RenderView::OnSetZoomLevel(double zoom_level) {
3419 // Don't set zoom level for full-page plugin since they don't use the same
3420 // zoom settings.
3421 if (webview()->mainFrame()->document().isPluginDocument())
3422 return;
3423
3424 webview()->hidePopups();
3425 webview()->setZoomLevel(false, zoom_level);
3426 zoomLevelChanged();
3427}
3428
[email protected]9d797f32010-04-23 07:17:543429void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:253430 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543431 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293432}
3433
[email protected]41fc0322009-09-04 22:23:403434void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273435 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293436}
3437
[email protected]a697f4c2009-09-14 22:30:183438void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273439 WebString no_encoding;
3440 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183441}
3442
[email protected]318bf5802011-08-08 17:12:413443WebFrame* RenderView::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453444 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273445 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453446
3447 // xpath string can represent a frame deep down the tree (across multiple
3448 // frame DOMs).
3449 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3450 // should break into 2 xpaths
3451 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413452 std::vector<string16> xpaths;
3453 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453454
[email protected]26aa0482009-09-30 16:55:273455 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413456 for (std::vector<string16>::const_iterator i = xpaths.begin();
3457 frame && i != xpaths.end(); ++i) {
3458 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293459 }
3460
[email protected]dd7daa82009-08-10 05:46:453461 return frame;
initial.commit09911bf2008-07-26 23:55:293462}
3463
[email protected]13a1e4c3c2011-02-03 21:07:093464WebNode RenderView::GetFocusedNode() const {
3465 if (!webview())
3466 return WebNode();
3467 WebFrame* focused_frame = webview()->focusedFrame();
3468 if (focused_frame) {
3469 WebDocument doc = focused_frame->document();
3470 if (!doc.isNull())
3471 return doc.focusedNode();
3472 }
3473
3474 return WebNode();
3475}
3476
[email protected]38b592902011-04-16 02:08:423477bool RenderView::IsEditableNode(const WebNode& node) {
3478 bool is_editable_node = false;
3479 if (!node.isNull()) {
3480 if (node.isContentEditable()) {
3481 is_editable_node = true;
3482 } else if (node.isElementNode()) {
3483 is_editable_node =
3484 node.toConst<WebElement>().isTextFormControlElement();
3485 }
3486 }
3487 return is_editable_node;
3488}
3489
[email protected]882b7b22010-10-05 03:34:533490void RenderView::EvaluateScript(const string16& frame_xpath,
3491 const string16& script,
3492 int id,
3493 bool notify_result) {
3494 v8::Handle<v8::Value> result;
[email protected]318bf5802011-08-08 17:12:413495 WebFrame* web_frame = GetChildFrame(frame_xpath);
[email protected]882b7b22010-10-05 03:34:533496 if (web_frame)
3497 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
3498 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:293499 ListValue list;
[email protected]cd326242011-06-16 01:55:463500 if (!result.IsEmpty() && web_frame) {
[email protected]81f9fe0b2010-12-07 00:35:293501 v8::HandleScope handle_scope;
3502 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3503 v8::Context::Scope context_scope(context);
[email protected]b1cf3372011-04-20 21:28:103504 V8ValueConverter converter;
3505 converter.set_allow_date(true);
3506 converter.set_allow_regexp(true);
3507 list.Set(0, converter.FromV8Value(result, context));
[email protected]81f9fe0b2010-12-07 00:35:293508 } else {
3509 list.Set(0, Value::CreateNullValue());
3510 }
3511 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:533512 }
initial.commit09911bf2008-07-26 23:55:293513}
3514
[email protected]882b7b22010-10-05 03:34:533515void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
3516 const string16& jscript,
3517 int id,
3518 bool notify_result) {
3519 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293520}
3521
[email protected]318bf5802011-08-08 17:12:413522void RenderView::OnCSSInsertRequest(const string16& frame_xpath,
[email protected]01cf589c2011-07-28 18:04:033523 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413524 WebFrame* frame = GetChildFrame(frame_xpath);
3525 if (!frame)
[email protected]216813952011-05-19 22:21:263526 return;
[email protected]ae461542009-06-19 19:03:413527
[email protected]01cf589c2011-07-28 18:04:033528 frame->document().insertUserStyleSheet(
3529 WebString::fromUTF8(css),
3530 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483531}
3532
[email protected]81e63782009-02-27 19:35:093533void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3534 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293535}
3536
[email protected]d0980792011-02-13 19:41:403537void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:293538 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:553539 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:273540 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293541}
3542
3543void RenderView::OnReservePageIDRange(int size_of_range) {
3544 next_page_id_ += size_of_range + 1;
3545}
3546
[email protected]59f4f2fa2011-03-23 01:00:553547void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
3548 const gfx::Point& client_point,
3549 const gfx::Point& screen_point,
3550 WebDragOperationsMask ops) {
3551 WebDragOperation operation = webview()->dragTargetDragEnter(
3552 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553553 client_point,
3554 screen_point,
3555 ops);
3556
3557 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3558}
3559
3560void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
3561 const gfx::Point& screen_point,
3562 WebDragOperationsMask ops) {
3563 WebDragOperation operation = webview()->dragTargetDragOver(
3564 client_point,
3565 screen_point,
3566 ops);
3567
3568 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3569}
3570
3571void RenderView::OnDragTargetDragLeave() {
3572 webview()->dragTargetDragLeave();
3573}
3574
3575void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3576 const gfx::Point& screen_point) {
3577 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573578
3579 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553580}
3581
[email protected]e80c73b2009-04-07 23:24:583582void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3583 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253584 bool ended,
3585 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033586 if (ended) {
[email protected]26aa0482009-09-30 16:55:273587 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203588 } else {
3589 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033590 }
initial.commit09911bf2008-07-26 23:55:293591}
3592
3593void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273594 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293595}
3596
initial.commit09911bf2008-07-26 23:55:293597void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593598 webkit_preferences_ = prefs;
3599 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293600}
3601
[email protected]08bb1e722011-07-30 19:13:043602void RenderView::OnUpdateRemoteAccessClientFirewallTraversal(
3603 const std::string& policy) {
3604 pepper_delegate_.PublishPolicy(policy);
3605}
3606
initial.commit09911bf2008-07-26 23:55:293607void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3608 alternate_error_page_url_ = url;
3609}
3610
[email protected]b29aa74b2011-01-31 21:41:083611void RenderView::OnCustomContextMenuAction(
3612 const webkit_glue::CustomContextMenuContext& custom_context,
3613 unsigned action) {
3614 if (custom_context.is_pepper_menu)
3615 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3616 else
3617 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:333618}
3619
initial.commit09911bf2008-07-26 23:55:293620void RenderView::OnInstallMissingPlugin() {
3621 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593622 if (first_default_plugin_)
3623 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293624}
3625
[email protected]600ea402011-04-12 00:01:513626void RenderView::OnEnumerateDirectoryResponse(
3627 int id,
3628 const std::vector<FilePath>& paths) {
3629 if (!enumeration_completions_[id])
3630 return;
3631
3632 WebVector<WebString> ws_file_names(paths.size());
3633 for (size_t i = 0; i < paths.size(); ++i)
3634 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3635
3636 enumeration_completions_[id]->didChooseFile(ws_file_names);
3637 enumeration_completions_.erase(id);
3638}
3639
[email protected]cdaf8d02010-03-30 19:52:473640void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363641 // This could happen if we navigated to a different page before the user
3642 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473643 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363644 return;
3645
[email protected]cdaf8d02010-03-30 19:52:473646 WebVector<WebString> ws_file_names(paths.size());
3647 for (size_t i = 0; i < paths.size(); ++i)
3648 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463649
[email protected]cdaf8d02010-03-30 19:52:473650 if (file_chooser_completions_.front()->completion)
3651 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3652 file_chooser_completions_.pop_front();
3653
3654 // If there are more pending file chooser requests, schedule one now.
3655 if (!file_chooser_completions_.empty()) {
3656 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3657 file_chooser_completions_.front()->params));
3658 }
initial.commit09911bf2008-07-26 23:55:293659}
3660
[email protected]770dd8b2010-05-24 18:11:393661void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3662 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243663 if (send_preferred_size_changes_)
3664 return;
[email protected]9fb325e2010-05-06 18:23:243665 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393666
[email protected]d812fd12011-05-27 23:05:073667 // Start off with an initial preferred size notification (in case
3668 // |didUpdateLayout| was already called).
3669 if (webview())
3670 didUpdateLayout(webview()->mainFrame());
[email protected]0666aef2009-05-13 19:48:083671}
3672
[email protected]cda45c02010-02-25 19:28:103673void RenderView::OnDisableScrollbarsForSmallWindows(
3674 const gfx::Size& disable_scrollbar_size_limit) {
3675 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3676}
3677
[email protected]80d96fa2009-06-10 22:34:513678void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3679 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373680 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133681#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413682 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3683 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463684 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513685 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343686 renderer_prefs.thumb_inactive_color,
3687 renderer_prefs.thumb_active_color,
3688 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323689
[email protected]644d77e2010-01-27 01:03:103690 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323691 webview()->setScrollbarColors(
3692 renderer_prefs.thumb_inactive_color,
3693 renderer_prefs.thumb_active_color,
3694 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103695 webview()->setSelectionColors(
3696 renderer_prefs.active_selection_bg_color,
3697 renderer_prefs.active_selection_fg_color,
3698 renderer_prefs.inactive_selection_bg_color,
3699 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463700 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103701 }
[email protected]7a74e102009-09-03 00:16:563702#endif
[email protected]80d96fa2009-06-10 22:34:513703}
3704
[email protected]952cb702009-10-07 05:50:283705void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3706 const WebMediaPlayerAction& action) {
3707 if (webview())
3708 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563709}
3710
[email protected]dea2d372010-09-25 06:41:143711void RenderView::OnEnableAccessibility() {
3712 if (WebAccessibilityCache::accessibilityEnabled())
3713 return;
[email protected]9f4db512010-05-10 20:21:413714
[email protected]dea2d372010-09-25 06:41:143715 WebAccessibilityCache::enableAccessibility();
3716
3717 if (webview()) {
3718 // It's possible that the webview has already loaded a webpage without
3719 // accessibility being enabled. Initialize the browser's cached
3720 // accessibility tree by sending it a 'load complete' notification.
3721 postAccessibilityNotification(
3722 webview()->accessibilityObject(),
3723 WebKit::WebAccessibilityNotificationLoadComplete);
3724 }
[email protected]266eb6f2008-09-30 23:56:503725}
3726
[email protected]aef92842010-05-21 16:54:363727void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
3728 if (!accessibility_.get())
3729 return;
[email protected]02ea2f312010-09-27 17:03:363730
3731 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3732 WebAccessibilityObject root = webview()->accessibilityObject();
3733 if (!obj.isValid() || !root.isValid())
3734 return;
3735
3736 // By convention, calling SetFocus on the root of the tree should clear the
3737 // current focus. Otherwise set the focus to the new node.
3738 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
3739 webview()->clearFocusedNode();
3740 else
3741 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:363742}
3743
3744void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
3745 if (!accessibility_.get())
3746 return;
[email protected]02ea2f312010-09-27 17:03:363747
3748 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3749 if (!obj.isValid())
3750 return;
3751
3752 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:363753}
3754
[email protected]9892b472010-09-16 00:23:423755void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:513756 DCHECK(accessibility_ack_pending_);
3757 accessibility_ack_pending_ = false;
3758 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:313759}
3760
[email protected]18d5be92011-07-25 18:00:193761void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3762 const GURL& page_url) {
3763 // Prepare list to storage all savable resource links.
3764 std::vector<GURL> resources_list;
3765 std::vector<GURL> referrers_list;
3766 std::vector<GURL> frames_list;
3767 webkit_glue::SavableResourcesResult result(&resources_list,
3768 &referrers_list,
3769 &frames_list);
3770
3771 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3772 webview(),
3773 page_url,
3774 &result,
3775 chrome::kSavableSchemes)) {
3776 // If something is wrong when collecting all savable resource links,
3777 // send empty list to embedder(browser) to tell it failed.
3778 referrers_list.clear();
3779 resources_list.clear();
3780 frames_list.clear();
3781 }
3782
3783 // Send result of all savable resource links to embedder.
3784 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3785 resources_list,
3786 referrers_list,
3787 frames_list));
3788}
3789
3790void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
3791 const std::vector<GURL>& links,
3792 const std::vector<FilePath>& local_paths,
3793 const FilePath& local_directory_name) {
3794
3795 // Convert std::vector of GURLs to WebVector<WebURL>
3796 WebVector<WebURL> weburl_links(links);
3797
3798 // Convert std::vector of std::strings to WebVector<WebString>
3799 WebVector<WebString> webstring_paths(local_paths.size());
3800 for (size_t i = 0; i < local_paths.size(); i++)
3801 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3802
3803 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
3804 webstring_paths,
3805 webkit_glue::FilePathToWebString(
3806 local_directory_name));
3807}
3808
[email protected]9b18a84f2010-06-10 15:54:043809void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273810 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473811 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293812}
3813
[email protected]992db4c2011-05-12 15:37:153814void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3815 if (is_swapped_out_)
3816 return;
3817
3818 // Swap this RenderView out so the tab can navigate to a page rendered by a
3819 // different process. This involves running the unload handler and clearing
3820 // the page. Once WasSwappedOut is called, we also allow this process to exit
3821 // if there are no other active RenderViews in it.
3822
3823 // Send an UpdateState message before we get swapped out.
3824 SyncNavigationState();
3825
3826 // Synchronously run the unload handler before sending the ACK.
3827 webview()->dispatchUnloadEvent();
3828
3829 // Swap out and stop sending any IPC messages that are not ACKs.
3830 SetSwappedOut(true);
3831
3832 // Replace the page with a blank dummy URL. The unload handler will not be
3833 // run a second time, thanks to a check in FrameLoader::stopLoading.
3834 // TODO(creis): Need to add a better way to do this that avoids running the
3835 // beforeunload handler. For now, we just run it a second time silently.
3836 webview()->mainFrame()->loadHTMLString(std::string(),
3837 GURL("about:swappedout"),
3838 GURL("about:swappedout"),
3839 false);
3840
3841 // Just echo back the params in the ACK.
3842 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3843}
3844
3845void RenderView::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:293846 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3847 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3848 // in the onunload handler from appearing. For now, we're bypassing that and
3849 // calling the FrameLoader's CloseURL method directly. This should be
3850 // revisited to avoid having two ways to close a page. Having a single way
3851 // to close that can run onunload is also useful for fixing
3852 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273853 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293854
[email protected]992db4c2011-05-12 15:37:153855 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293856}
3857
3858void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573859#if defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163860 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463861 if (webview())
3862 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573863#else // defined(OS_WIN)
3864 // TODO(port): we don't support theming on non-Windows platforms yet
3865 NOTIMPLEMENTED();
3866#endif
initial.commit09911bf2008-07-26 23:55:293867}
3868
[email protected]0aa55312008-10-17 21:53:083869void RenderView::OnDisassociateFromPopupCount() {
3870 if (decrement_shared_popup_at_destruction_)
3871 shared_popup_counter_->data--;
3872 shared_popup_counter_ = new SharedRenderViewCounter(0);
3873 decrement_shared_popup_at_destruction_ = false;
3874}
3875
[email protected]15d79e12009-08-02 19:23:453876bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3877 const WebURLError& error,
3878 bool replace) {
3879 // We only show alternate error pages in the main frame. They are
3880 // intended to assist the user when navigating, so there is not much
3881 // value in showing them for failed subframes. Ideally, we would be
3882 // able to use the TYPED transition type for this, but that flag is
3883 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453884 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453885 return false;
3886
3887 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373888 // connection failure.
[email protected]15d79e12009-08-02 19:23:453889 int ec = error.reason;
3890 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3891 ec != net::ERR_CONNECTION_FAILED &&
3892 ec != net::ERR_CONNECTION_REFUSED &&
3893 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373894 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453895 return false;
3896
3897 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553898 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453899 if (!error_page_url.is_valid())
3900 return false;
3901
3902 // Load an empty page first so there is an immediate response to the error,
3903 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453904 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363905 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453906 error.unreachableURL,
3907 replace);
3908
3909 // Now, create a fetcher for the error page and associate it with the data
3910 // source we just created via the LoadHTMLString call. That way if another
3911 // navigation occurs, the fetcher will get destroyed.
3912 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453913 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453914 navigation_state->set_alt_error_page_fetcher(
3915 new AltErrorPageResourceFetcher(
3916 error_page_url, frame, error,
3917 NewCallback(this, &RenderView::AltErrorPageFinished)));
3918 return true;
3919}
3920
[email protected]15d79e12009-08-02 19:23:453921void RenderView::AltErrorPageFinished(WebFrame* frame,
3922 const WebURLError& original_error,
3923 const std::string& html) {
3924 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093925 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553926 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093927 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453928}
3929
[email protected]30f75e62009-02-25 22:01:003930void RenderView::OnMoveOrResizeStarted() {
3931 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473932 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003933}
3934
[email protected]30f75e62009-02-25 22:01:003935void RenderView::OnResize(const gfx::Size& new_size,
3936 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103937 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473938 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103939 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203940 webview()->mainFrame()->setCanHaveScrollbars(
3941 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103942 }
[email protected]dd6afca2011-08-13 03:44:313943 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:103944 }
3945
[email protected]30f75e62009-02-25 22:01:003946 RenderWidget::OnResize(new_size, resizer_rect);
3947}
[email protected]0aa477bd2009-03-23 22:21:433948
[email protected]00c39612010-03-06 02:53:283949void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013950 // Notify the pepper plugins that we started painting.
3951 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283952}
3953
3954void RenderView::DidFlushPaint() {
3955 // Notify any pepper plugins that we painted. This will call into the plugin,
3956 // and we it may ask to close itself as a result. This will, in turn, modify
3957 // our set, possibly invalidating the iterator. So we iterate on a copy that
3958 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013959 pepper_delegate_.ViewFlushedPaint();
3960
[email protected]00c39612010-03-06 02:53:283961 WebFrame* main_frame = webview()->mainFrame();
3962
3963 // If we have a provisional frame we are between the start and commit stages
3964 // of loading and we don't want to save stats.
3965 if (!main_frame->provisionalDataSource()) {
3966 WebDataSource* ds = main_frame->dataSource();
3967 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3968 DCHECK(navigation_state);
3969
[email protected]05c8e502010-08-15 15:13:523970 // TODO(jar): The following code should all be inside a method, probably in
3971 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283972 Time now = Time::Now();
3973 if (navigation_state->first_paint_time().is_null()) {
3974 navigation_state->set_first_paint_time(now);
3975 }
3976 if (navigation_state->first_paint_after_load_time().is_null() &&
3977 !navigation_state->finish_load_time().is_null()) {
3978 navigation_state->set_first_paint_after_load_time(now);
3979 }
3980 }
3981}
3982
[email protected]37a6f302011-07-11 23:43:083983void RenderView::OnViewContextSwapBuffersPosted() {
3984 RenderWidget::OnSwapBuffersPosted();
3985}
3986
[email protected]65225772011-05-12 21:10:243987void RenderView::OnViewContextSwapBuffersComplete() {
3988 RenderWidget::OnSwapBuffersComplete();
3989}
3990
3991void RenderView::OnViewContextSwapBuffersAborted() {
3992 RenderWidget::OnSwapBuffersAborted();
3993}
3994
[email protected]719b36f2010-12-22 20:36:463995webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:153996 const gfx::Rect& paint_bounds,
3997 TransportDIB** dib,
3998 gfx::Rect* location,
3999 gfx::Rect* clip) {
4000 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4001 paint_bounds, dib, location, clip);
4002}
4003
[email protected]bcaf2272011-02-15 15:29:434004gfx::Point RenderView::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074005 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434006 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524007}
4008
[email protected]05d478752009-04-08 23:38:164009void RenderView::OnClearFocusedNode() {
4010 if (webview())
[email protected]26aa0482009-09-30 16:55:274011 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164012}
4013
[email protected]699ab0d2009-04-23 23:19:144014void RenderView::OnSetBackground(const SkBitmap& background) {
4015 if (webview())
[email protected]b4bb2502009-10-01 22:35:274016 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144017
4018 SetBackground(background);
4019}
4020
[email protected]8c66c5a2009-07-22 17:26:344021void RenderView::OnSetActive(bool active) {
4022 if (webview())
[email protected]b4bb2502009-10-01 22:35:274023 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264024
4025#if defined(OS_MACOSX)
4026 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4027 for (plugin_it = plugin_delegates_.begin();
4028 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4029 (*plugin_it)->SetWindowFocus(active);
4030 }
4031#endif
[email protected]8c66c5a2009-07-22 17:26:344032}
4033
[email protected]6ce7abc52010-02-02 18:40:144034#if defined(OS_MACOSX)
4035void RenderView::OnSetWindowVisibility(bool visible) {
4036 // Inform plugins that their container has changed visibility.
4037 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4038 for (plugin_it = plugin_delegates_.begin();
4039 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4040 (*plugin_it)->SetContainerVisibility(visible);
4041 }
4042}
[email protected]1e6e3c992010-02-08 15:52:134043
[email protected]4d51d5bf2010-07-26 18:48:264044void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
4045 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134046 // Inform plugins that their window's frame has changed.
4047 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4048 for (plugin_it = plugin_delegates_.begin();
4049 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4050 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4051 }
4052}
[email protected]935d63d2010-10-15 23:31:554053
[email protected]b7f75862011-01-21 21:15:134054void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:554055 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134056 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554057 // applies to it or not, so inform all the delegates.
4058 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4059 for (plugin_it = plugin_delegates_.begin();
4060 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134061 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554062 }
4063}
[email protected]6ce7abc52010-02-02 18:40:144064#endif // OS_MACOSX
4065
[email protected]9892b472010-09-16 00:23:424066void RenderView::postAccessibilityNotification(
4067 const WebAccessibilityObject& obj,
4068 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:144069 if (!accessibility_.get() && webview()) {
4070 // Load complete should be our first notification sent.
4071 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
4072 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
4073 return;
4074
4075 // Create and initialize our accessibility cache
4076 accessibility_.reset(WebAccessibilityCache::create());
4077 accessibility_->initialize(webview());
4078 }
4079
[email protected]a3fa4f92010-09-30 22:19:334080 if (!accessibility_->isCached(obj)) {
4081 // The browser doesn't know about objects that are not in the cache. Send a
4082 // children change for the first accestor that actually is in the cache.
4083 WebAccessibilityObject parent = obj;
4084 while (parent.isValid() && !accessibility_->isCached(parent))
4085 parent = parent.parentObject();
4086
4087 DCHECK(parent.isValid() && accessibility_->isCached(parent));
4088 if (!parent.isValid())
4089 return;
4090 postAccessibilityNotification(
4091 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
4092
4093 // The parent's children change takes care of the child's children change.
4094 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
4095 return;
4096 }
4097
[email protected]dea2d372010-09-25 06:41:144098 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:514099 RendererAccessibilityNotification acc_notification;
4100 acc_notification.id = accessibility_->addOrGetId(obj);
[email protected]a527a022011-02-10 02:32:364101 acc_notification.type = notification;
[email protected]54ec7f82010-10-21 22:32:514102 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:484103 return;
4104
[email protected]fffaf972011-03-24 01:34:354105 ViewHostMsg_AccessibilityNotification_Type::Value temp;
[email protected]a527a022011-02-10 02:32:364106 if (!WebAccessibilityNotificationToViewHostMsg(notification, &temp))
[email protected]54ec7f82010-10-21 22:32:514107 return;
[email protected]54ec7f82010-10-21 22:32:514108
4109 // Discard duplicate accessibility notifications.
4110 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
4111 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
4112 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:424113 return;
[email protected]54ec7f82010-10-21 22:32:514114 }
[email protected]9892b472010-09-16 00:23:424115 }
[email protected]54ec7f82010-10-21 22:32:514116 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:484117
[email protected]54ec7f82010-10-21 22:32:514118 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
4119 // When no accessibility notifications are in-flight post a task to send
4120 // the notifications to the browser. We use PostTask so that we can queue
4121 // up additional notifications.
4122 MessageLoop::current()->PostTask(
4123 FROM_HERE,
4124 accessibility_method_factory_.NewRunnableMethod(
4125 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:314126 }
[email protected]520cb7d72010-08-31 11:54:314127}
4128
[email protected]446705872009-09-10 07:22:484129void RenderView::OnSetEditCommandsForNextKeyEvent(
4130 const EditCommands& edit_commands) {
4131 edit_commands_ = edit_commands;
4132}
4133
[email protected]60c42a8c72009-10-09 04:08:594134void RenderView::Close() {
4135 // We need to grab a pointer to the doomed WebView before we destroy it.
4136 WebView* doomed = webview();
4137 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494138 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594139}
4140
[email protected]446705872009-09-10 07:22:484141void RenderView::DidHandleKeyEvent() {
4142 edit_commands_.clear();
4143}
4144
[email protected]6a8ddba52010-09-05 04:38:064145void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514146 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064147}
4148
[email protected]941e4552010-02-01 21:23:434149void RenderView::OnWasHidden() {
4150 RenderWidget::OnWasHidden();
4151
[email protected]a6939ca42011-02-18 17:58:074152 if (webview()) {
4153 webview()->settings()->setMinimumTimerInterval(
4154 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444155 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074156 }
4157
4158#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434159 // Inform plugins that their container is no longer visible.
4160 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4161 for (plugin_it = plugin_delegates_.begin();
4162 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4163 (*plugin_it)->SetContainerVisibility(false);
4164 }
[email protected]a6939ca42011-02-18 17:58:074165#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434166}
4167
4168void RenderView::OnWasRestored(bool needs_repainting) {
4169 RenderWidget::OnWasRestored(needs_repainting);
4170
[email protected]a6939ca42011-02-18 17:58:074171 if (webview()) {
4172 webview()->settings()->setMinimumTimerInterval(
4173 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444174 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074175 }
4176
4177#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434178 // Inform plugins that their container is now visible.
4179 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4180 for (plugin_it = plugin_delegates_.begin();
4181 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4182 (*plugin_it)->SetContainerVisibility(true);
4183 }
[email protected]784ea1ab2010-09-18 00:02:344184#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074185}
[email protected]1e6e3c992010-02-08 15:52:134186
[email protected]65225772011-05-12 21:10:244187bool RenderView::SupportsAsynchronousSwapBuffers() {
4188 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4189 if (!context)
4190 return false;
4191 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4192 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4193 std::string::npos;
4194}
4195
[email protected]1e6e3c992010-02-08 15:52:134196void RenderView::OnSetFocus(bool enable) {
4197 RenderWidget::OnSetFocus(enable);
4198
[email protected]7d3c02c2010-05-05 23:10:314199 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074200 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134201 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4202 for (plugin_it = plugin_delegates_.begin();
4203 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344204#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314205 // RenderWidget's call to setFocus can cause the underlying webview's
4206 // activation state to change just like a call to setIsActive.
4207 if (enable)
4208 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344209#endif
[email protected]7d3c02c2010-05-05 23:10:314210 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134211 }
[email protected]589621b2010-09-23 22:01:074212
4213 // Notify all Pepper plugins.
4214 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134215 }
4216}
[email protected]941e4552010-02-01 21:23:434217
[email protected]56ea1a62011-05-30 07:05:574218void RenderView::PpapiPluginFocusChanged() {
4219 UpdateInputMethod();
4220}
4221
[email protected]08bb1e722011-07-30 19:13:044222void RenderView::RequestRemoteAccessClientFirewallTraversal() {
4223 Send(new ViewHostMsg_RequestRemoteAccessClientFirewallTraversal(routing_id_));
4224}
4225
[email protected]56ea1a62011-05-30 07:05:574226void RenderView::OnImeSetComposition(
4227 const string16& text,
4228 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4229 int selection_start,
4230 int selection_end) {
4231 // Until PPAPI has an interface for handling IME events, we skip sending
4232 // OnImeSetComposition. Otherwise the composition is canceled when a
4233 // non-editable DOM element is focused.
4234 //
4235 // TODO(kinaba) This temporal remedy can be removed after PPAPI is extended
4236 // with an IME handling interface.
4237 if (!pepper_delegate_.IsPluginFocused()) {
4238 RenderWidget::OnImeSetComposition(text,
4239 underlines,
4240 selection_start,
4241 selection_end);
4242 }
4243}
4244
4245void RenderView::OnImeConfirmComposition(const string16& text) {
4246 if (pepper_delegate_.IsPluginFocused()) {
4247 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4248 // send character events.
4249 for (size_t i = 0; i < text.size(); ++i) {
4250 WebKit::WebKeyboardEvent char_event;
4251 char_event.type = WebKit::WebInputEvent::Char;
4252 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
4253 char_event.modifiers = 0;
4254 char_event.windowsKeyCode = text[i];
4255 char_event.nativeKeyCode = text[i];
4256 char_event.text[0] = text[i];
4257 char_event.unmodifiedText[0] = text[i];
4258 if (webwidget_)
4259 webwidget_->handleInputEvent(char_event);
4260 }
4261 } else {
4262 RenderWidget::OnImeConfirmComposition(text);
4263 }
4264}
4265
[email protected]ad26ef42011-06-17 07:59:454266ui::TextInputType RenderView::GetTextInputType() {
[email protected]56ea1a62011-05-30 07:05:574267 if (pepper_delegate_.IsPluginFocused()) {
4268 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4269 // consider all the parts of PPAPI plugins are accepting text inputs.
[email protected]ad26ef42011-06-17 07:59:454270 return ui::TEXT_INPUT_TYPE_TEXT;
[email protected]56ea1a62011-05-30 07:05:574271 }
[email protected]ad26ef42011-06-17 07:59:454272 return RenderWidget::GetTextInputType();
4273}
4274
4275bool RenderView::CanComposeInline() {
4276 if (pepper_delegate_.IsPluginFocused()) {
4277 // TODO(kinaba) Until PPAPI has an interface for handling IME events, there
4278 // is no way for the browser to know whether the plugin is capable of
4279 // drawing composition text. We assume plugins are incapable and let the
4280 // browser handle composition display for now.
4281 return false;
4282 }
4283 return true;
[email protected]56ea1a62011-05-30 07:05:574284}
4285
[email protected]43f28f832010-02-03 02:28:484286#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:134287void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
4288 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4289 focused, plugin_id);
4290 Send(msg);
4291}
4292
4293void RenderView::StartPluginIme() {
4294 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554295 // This message can be sent during event-handling, and needs to be delivered
4296 // within that context.
4297 msg->set_unblock(true);
4298 Send(msg);
4299}
4300
[email protected]ea04a4e12010-04-15 00:58:034301gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234302 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484303 gfx::PluginWindowHandle window = NULL;
4304 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234305 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114306 if (window) {
4307 fake_plugin_window_handles_.insert(window);
4308 }
[email protected]43f28f832010-02-03 02:28:484309 return window;
4310}
4311
4312void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114313 if (window && fake_plugin_window_handles_.find(window) !=
4314 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484315 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114316 fake_plugin_window_handles_.erase(window);
4317 }
[email protected]43f28f832010-02-03 02:28:484318}
4319
[email protected]44ce0b12010-03-12 16:45:334320void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4321 int32 width,
4322 int32 height,
4323 uint64 io_surface_identifier) {
4324 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484325 routing_id(), window, width, height, io_surface_identifier));
4326}
4327
[email protected]44ce0b12010-03-12 16:45:334328void RenderView::AcceleratedSurfaceSetTransportDIB(
4329 gfx::PluginWindowHandle window,
4330 int32 width,
4331 int32 height,
4332 TransportDIB::Handle transport_dib) {
4333 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074334 routing_id(), window, width, height, transport_dib));
4335}
4336
[email protected]44ce0b12010-03-12 16:45:334337TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4338 size_t size) {
[email protected]1aef98132010-02-23 18:00:074339 TransportDIB::Handle dib_handle;
4340 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384341 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074342 return dib_handle;
4343 // Return an invalid handle if Send() fails.
4344 return TransportDIB::DefaultHandleValue();
4345}
4346
[email protected]44ce0b12010-03-12 16:45:334347void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074348 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4349}
4350
[email protected]44ce0b12010-03-12 16:45:334351void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144352 gfx::PluginWindowHandle window, uint64 surface_id) {
4353 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4354 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484355}
4356#endif
[email protected]58c321d2010-02-19 12:11:284357
[email protected]cdaf8d02010-03-30 19:52:474358bool RenderView::ScheduleFileChooser(
4359 const ViewHostMsg_RunFileChooser_Params& params,
4360 WebFileChooserCompletion* completion) {
4361 static const size_t kMaximumPendingFileChooseRequests = 4;
4362 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4363 // This sanity check prevents too many file choose requests from getting
4364 // queued which could DoS the user. Getting these is most likely a
4365 // programming error (there are many ways to DoS the user so it's not
4366 // considered a "real" security check), either in JS requesting many file
4367 // choosers to pop up, or in a plugin.
4368 //
4369 // TODO(brettw) we might possibly want to require a user gesture to open
4370 // a file picker, which will address this issue in a better way.
4371 return false;
4372 }
4373
4374 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4375 new PendingFileChooser(params, completion)));
4376 if (file_chooser_completions_.size() == 1) {
4377 // Actually show the browse dialog when this is the first request.
4378 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4379 }
4380 return true;
4381}
4382
[email protected]0ff0ff32010-12-21 19:34:424383WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514384 if (!geolocation_dispatcher_)
4385 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4386 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254387}
[email protected]61c9f032010-03-31 23:04:194388
[email protected]638694c2010-08-04 22:24:114389WebKit::WebSpeechInputController* RenderView::speechInputController(
4390 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:514391 if (!speech_input_dispatcher_)
4392 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
4393 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114394}
4395
[email protected]57ead352010-08-11 14:42:534396WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514397 if (!device_orientation_dispatcher_)
4398 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4399 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534400}
4401
[email protected]b75b8292010-10-01 07:28:254402void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
4403 // For now, don't remember plugin zoom values. We don't want to mix them with
4404 // normal web content (i.e. a fixed layout plugin would usually want them
4405 // different).
4406 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4407
[email protected]b75b8292010-10-01 07:28:254408 int minimum_percent = static_cast<int>(
4409 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4410 int maximum_percent = static_cast<int>(
4411 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254412
4413 Send(new ViewHostMsg_UpdateZoomLimits(
4414 routing_id_, minimum_percent, maximum_percent, remember));
4415}
4416
4417void RenderView::zoomLevelChanged() {
4418 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4419
[email protected]b75b8292010-10-01 07:28:254420 // Tell the browser which url got zoomed so it can update the menu and the
4421 // saved values if necessary
4422 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:414423 routing_id_, webview()->zoomLevel(), remember,
[email protected]b6cb3a842011-06-24 18:28:414424 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254425}
4426
[email protected]a6d36cc2011-02-23 00:39:484427void RenderView::registerProtocolHandler(const WebString& scheme,
4428 const WebString& base_url,
4429 const WebString& url,
4430 const WebString& title) {
4431 GURL base(base_url);
4432 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4433 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4434 return;
4435 }
4436 RenderThread::current()->Send(
4437 new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4438 UTF16ToUTF8(scheme),
4439 absolute_url,
4440 title));
4441}
4442
[email protected]62af76e2011-08-01 02:34:014443void RenderView::registerIntentHandler(const WebString& action,
4444 const WebString& type,
4445 const WebString& href,
4446 const WebString& title) {
4447 RenderThread::current()->Send(
4448 new ViewHostMsg_RegisterIntentHandler(routing_id_,
4449 action,
4450 type,
4451 href,
4452 title));
4453}
4454
[email protected]94dec932011-05-26 20:04:214455WebKit::WebPageVisibilityState RenderView::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444456 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4457 WebKit::WebPageVisibilityStateHidden :
4458 WebKit::WebPageVisibilityStateVisible;
4459 WebKit::WebPageVisibilityState override_state = current_state;
4460 if (content::GetContentClient()->renderer()->
4461 ShouldOverridePageVisibilityState(this,
4462 &override_state))
4463 return override_state;
4464 return current_state;
[email protected]94dec932011-05-26 20:04:214465}
4466
[email protected]e235c7d02011-08-18 22:38:434467void RenderView::startActivity(const WebKit::WebString& action,
4468 const WebKit::WebString& type,
4469 const WebKit::WebString& data,
4470 int intent_id) {
4471 RenderThread::current()->Send(new ViewHostMsg_WebIntentDispatch(
4472 routing_id_, action, type, data, intent_id));
4473}
4474
[email protected]8079b362010-05-07 18:37:454475bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194476 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454477 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194478 if (frame->parent() != NULL)
4479 return false;
4480
[email protected]f0a3d0b2010-08-06 22:51:534481 // Navigations initiated within Webkit are not sent out to the external host
4482 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274483 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134484 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534485 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134486 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334487 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534488 return false;
4489
[email protected]2fc22d12010-12-02 23:08:164490 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324491 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014492 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164493 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014494 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324495 // The opener relationship between the new window and the parent allows the
4496 // new window to script the parent and vice versa. This is not allowed if
4497 // the origins of the two domains are different. This can be treated as a
4498 // top level navigation and routed back to the host.
4499 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274500 if (!opener) {
[email protected]86965362011-04-21 18:42:514501 return true;
[email protected]d19ea342011-04-20 20:31:134502 } else {
[email protected]b6cb3a842011-06-24 18:28:414503 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324504 return true;
4505 }
4506 }
[email protected]61c9f032010-03-31 23:04:194507 return false;
4508}
[email protected]2b06a992010-08-21 05:48:224509
[email protected]27a9ef32010-09-10 04:06:244510void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
4511 IPC::PlatformFileForTransit file_for_transit,
4512 int message_id) {
4513 pepper_delegate_.OnAsyncFileOpened(
4514 error_code,
4515 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4516 message_id);
4517}
[email protected]caf706f2010-10-26 17:54:084518
[email protected]2b657fd2011-04-18 16:00:474519void RenderView::OnPpapiBrokerChannelCreated(
4520 int request_id,
4521 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434522 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474523 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4524 broker_process_handle,
4525 handle);
[email protected]eb415bf0e2011-04-14 02:45:424526}
4527
[email protected]caf706f2010-10-26 17:54:084528#if defined(OS_MACOSX)
4529void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154530 if (external_popup_menu_ == NULL) {
4531 // Crash reports from the field indicate that we can be notified with a
4532 // NULL external popup menu (we probably get notified twice).
4533 // If you hit this please file a bug against jcivelli and include the page
4534 // and steps to repro.
4535 NOTREACHED();
4536 return;
4537 }
[email protected]caf706f2010-10-26 17:54:084538 external_popup_menu_->DidSelectItem(selected_index);
4539 external_popup_menu_.reset();
4540}
4541#endif
[email protected]bb461532010-11-26 21:50:234542
[email protected]1b4209f2011-01-07 00:25:404543#if defined(ENABLE_FLAPPER_HACKS)
4544void RenderView::OnConnectTcpACK(
4545 int request_id,
4546 IPC::PlatformFileForTransit socket_for_transit,
4547 const PP_Flash_NetAddress& local_addr,
4548 const PP_Flash_NetAddress& remote_addr) {
4549 pepper_delegate_.OnConnectTcpACK(
4550 request_id,
4551 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4552 local_addr,
4553 remote_addr);
4554}
4555#endif
[email protected]a6097f42011-01-10 08:50:514556
[email protected]b29aa74b2011-01-31 21:41:084557void RenderView::OnContextMenuClosed(
4558 const webkit_glue::CustomContextMenuContext& custom_context) {
4559 if (custom_context.is_pepper_menu)
4560 pepper_delegate_.OnContextMenuClosed(custom_context);
4561 else
4562 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104563}