blob: 43e9743965e4083f2bece5f003f0ffd8d7692c62 [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]9966325b2011-04-18 05:00:1041#include "content/common/url_constants.h"
[email protected]778574e2011-03-21 22:03:5042#include "content/common/view_messages.h"
[email protected]21d61e52011-03-18 19:08:2543#include "content/renderer/content_renderer_client.h"
[email protected]82622452011-07-22 09:57:2044#include "content/renderer/devtools_agent.h"
[email protected]230b7ef2011-03-16 22:30:1945#include "content/renderer/device_orientation_dispatcher.h"
[email protected]8f6a3b852011-07-19 16:48:5646#include "content/renderer/mhtml_generator.h"
[email protected]55722152011-03-22 01:33:5347#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1948#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4049#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]921f1592011-03-18 00:41:0250#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0851#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3752#include "content/renderer/media/audio_renderer_impl.h"
[email protected]ab2c4732011-07-20 19:57:4053#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:4054#include "content/renderer/media/render_media_log.h"
[email protected]921f1592011-03-18 00:41:0255#include "content/renderer/navigation_state.h"
[email protected]230b7ef2011-03-16 22:30:1956#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3757#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3558#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0559#include "content/renderer/render_process.h"
[email protected]10e6ab572011-04-14 23:42:0060#include "content/renderer/render_thread.h"
[email protected]60916042011-03-19 00:43:3661#include "content/renderer/render_view_observer.h"
62#include "content/renderer/render_view_visitor.h"
[email protected]2cff0052011-03-18 16:51:4463#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]663bd9e2011-03-21 01:07:0164#include "content/renderer/renderer_webapplicationcachehost_impl.h"
65#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1966#include "content/renderer/speech_input_dispatcher.h"
[email protected]b1cf3372011-04-20 21:28:1067#include "content/renderer/v8_value_converter.h"
[email protected]663bd9e2011-03-21 01:07:0168#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3569#include "content/renderer/webplugin_delegate_proxy.h"
70#include "content/renderer/websharedworker_proxy.h"
71#include "content/renderer/webworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4972#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4173#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2774#include "media/base/message_loop_factory_impl.h"
initial.commit09911bf2008-07-26 23:55:2975#include "net/base/escape.h"
76#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0477#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5778#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3779#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
80#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
81#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
82#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3783#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
84#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
85#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
86#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3787#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
88#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
89#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
90#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
91#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
92#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
93#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
94#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
95#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:5796#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]69f110d62011-03-17 19:01:1497#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:3798#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:1999#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37100#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
101#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
102#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
103#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
104#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
105#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17110#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37111#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
112#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
113#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40114#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]8bd0fe62011-01-17 06:44:37115#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26123#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c4a9e932011-03-05 04:05:55124#include "ui/base/message_box_flags.h"
[email protected]08397d52011-02-05 01:53:38125#include "ui/gfx/native_widget_types.h"
126#include "ui/gfx/point.h"
127#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55128#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04129#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43130#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24131#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19132#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59133#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24134#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24135#include "webkit/glue/glue_serialize.h"
[email protected]85cc78c2010-05-04 18:30:09136#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26137#include "webkit/glue/password_form_dom_manager.h"
[email protected]418da612011-07-21 19:01:52138#include "webkit/glue/request_extra_data.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]191eb3f72010-12-21 06:27:50144#include "webkit/plugins/npapi/default_plugin_shared.h"
145#include "webkit/plugins/npapi/plugin_list.h"
146#include "webkit/plugins/npapi/webplugin_delegate.h"
147#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
148#include "webkit/plugins/npapi/webplugin_impl.h"
149#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52150#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29151
[email protected]6c8afae52009-01-22 02:24:57152#if defined(OS_WIN)
153// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57154// * theming
[email protected]08397d52011-02-05 01:53:38155#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03156#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37157#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51158#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33159#elif defined(OS_MACOSX)
160#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57161#endif
162
[email protected]c7287a92009-11-04 20:06:15163using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42164using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08165using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21166using WebKit::WebApplicationCacheHost;
167using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26168using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41169using WebKit::WebColor;
170using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59171using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44172using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51173using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55174using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28175using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00176using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58177using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25178using WebKit::WebDragOperation;
179using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51180using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51181using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08182using WebKit::WebExternalPopupMenu;
183using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47184using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22185using WebKit::WebFileSystem;
186using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49187using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59188using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48189using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45190using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17191using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13192using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41193using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50194using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17195using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28196using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17197using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28198using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28199using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51200using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19201using WebKit::WebPageSerializer;
202using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17203using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40204using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49205using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09206using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52207using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59208using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51209using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52210using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40211using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35212using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29213using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17214using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59215using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42216using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02217using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34218using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40219using WebKit::WebStorageQuotaCallbacks;
220using WebKit::WebStorageQuotaError;
221using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28222using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51223using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52224using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28225using WebKit::WebURL;
226using WebKit::WebURLError;
227using WebKit::WebURLRequest;
228using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28229using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03230using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28231using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26232using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43233using WebKit::WebWorker;
234using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26235using appcache::WebApplicationCacheHostImpl;
236using base::Time;
237using base::TimeDelta;
238using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26239using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26240using webkit_glue::PasswordForm;
241using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23242using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26243using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33244
initial.commit09911bf2008-07-26 23:55:29245//-----------------------------------------------------------------------------
246
[email protected]3354d3e2010-06-10 19:53:02247typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49248static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02249
[email protected]882daa92009-11-05 16:31:31250// Time, in seconds, we delay before sending content state changes (such as form
251// state and scroll position) to the browser. We delay sending changes to avoid
252// spamming the browser.
253// To avoid having tab/session restore require sending a message to get the
254// current content state during tab closing we use a shorter timeout for the
255// foreground renderer. This means there is a small window of time from which
256// content state is modified and not sent to session restore, but this is
257// better than having to wake up all renderers during shutdown.
258static const int kDelaySecondsForContentStateSyncHidden = 5;
259static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29260
[email protected]0aa55312008-10-17 21:53:08261// The maximum number of popups that can be spawned from one page.
262static const int kMaximumNumberOfUnacknowledgedPopups = 25;
263
[email protected]6fdd4182010-10-14 23:59:26264static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35265
[email protected]726985e22009-06-18 21:09:28266static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
267 WebVector<WebURL> urls;
268 ds->redirectChain(urls);
269 result->reserve(urls.size());
270 for (size_t i = 0; i < urls.size(); ++i)
271 result->push_back(urls[i]);
272}
273
[email protected]54ec7f82010-10-21 22:32:51274static bool WebAccessibilityNotificationToViewHostMsg(
275 WebAccessibilityNotification notification,
[email protected]fffaf972011-03-24 01:34:35276 ViewHostMsg_AccessibilityNotification_Type::Value* type) {
[email protected]54ec7f82010-10-21 22:32:51277 switch (notification) {
278 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
[email protected]fffaf972011-03-24 01:34:35279 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51280 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
281 break;
282 case WebKit::WebAccessibilityNotificationChildrenChanged:
[email protected]fffaf972011-03-24 01:34:35283 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51284 NOTIFICATION_TYPE_CHILDREN_CHANGED;
285 break;
286 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
[email protected]fffaf972011-03-24 01:34:35287 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51288 NOTIFICATION_TYPE_FOCUS_CHANGED;
289 break;
290 case WebKit::WebAccessibilityNotificationLoadComplete:
[email protected]fffaf972011-03-24 01:34:35291 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51292 NOTIFICATION_TYPE_LOAD_COMPLETE;
293 break;
294 case WebKit::WebAccessibilityNotificationValueChanged:
[email protected]fffaf972011-03-24 01:34:35295 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51296 NOTIFICATION_TYPE_VALUE_CHANGED;
297 break;
298 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
[email protected]fffaf972011-03-24 01:34:35299 *type = ViewHostMsg_AccessibilityNotification_Type::
[email protected]54ec7f82010-10-21 22:32:51300 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
301 break;
302 default:
303 // TODO(ctguil): Support additional webkit notifications.
304 return false;
305 }
306 return true;
307}
308
[email protected]6a8f5112011-05-13 16:38:44309// If |data_source| is non-null and has a NavigationState associated with it,
310// the AltErrorPageResourceFetcher is reset.
311static void StopAltErrorPageFetcher(WebDataSource* data_source) {
312 if (data_source) {
313 NavigationState* state = NavigationState::FromDataSource(data_source);
314 if (state)
315 state->set_alt_error_page_fetcher(NULL);
316 }
317}
318
initial.commit09911bf2008-07-26 23:55:29319///////////////////////////////////////////////////////////////////////////////
320
[email protected]60c42a8c72009-10-09 04:08:59321int32 RenderView::next_page_id_ = 1;
322
[email protected]cdaf8d02010-03-30 19:52:47323struct RenderView::PendingFileChooser {
324 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
325 WebFileChooserCompletion* c)
326 : params(p),
327 completion(c) {
328 }
329 ViewHostMsg_RunFileChooser_Params params;
330 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
331};
332
[email protected]2fab253a2009-08-17 23:00:59333RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51334 gfx::NativeViewId parent_hwnd,
335 int32 opener_id,
336 const RendererPreferences& renderer_prefs,
337 const WebPreferences& webkit_prefs,
338 SharedRenderViewCounter* counter,
339 int32 routing_id,
340 int64 session_storage_namespace_id,
341 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12342 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51343 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02344 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09345 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02346 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24347 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21348 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02349 opened_by_user_gesture_(true),
350 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24351 page_id_(-1),
352 last_page_id_sent_to_browser_(-1),
[email protected]3cc72b12010-03-18 23:03:00353 history_list_offset_(-1),
354 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02355 target_url_status_(TARGET_NONE),
[email protected]18ca9a6b2010-06-02 19:05:18356 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]54ec7f82010-10-21 22:32:51357 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02358 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51359 geolocation_dispatcher_(NULL),
360 speech_input_dispatcher_(NULL),
361 device_orientation_dispatcher_(NULL),
[email protected]54ec7f82010-10-21 22:32:51362 accessibility_ack_pending_(false),
[email protected]cae8c8492011-03-03 11:12:18363 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41364 devtools_agent_(NULL),
[email protected]c631b592011-08-06 00:58:55365 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]676126f72011-01-15 00:03:51366 routing_id_ = routing_id;
367 if (opener_id != MSG_ROUTING_NONE)
368 opener_id_ = opener_id;
369
[email protected]11fee2332011-03-29 20:36:35370 webwidget_ = WebView::create(this);
371
[email protected]676126f72011-01-15 00:03:51372 if (counter) {
373 shared_popup_counter_ = counter;
374 shared_popup_counter_->data++;
375 decrement_shared_popup_at_destruction_ = true;
376 } else {
377 shared_popup_counter_ = new SharedRenderViewCounter(0);
378 decrement_shared_popup_at_destruction_ = false;
379 }
380
381 notification_provider_ = new NotificationProvider(this);
382
[email protected]676126f72011-01-15 00:03:51383 render_thread_->AddRoute(routing_id_, this);
384 // Take a reference on behalf of the RenderThread. This will be balanced
385 // when we receive ViewMsg_Close.
386 AddRef();
387
388 // If this is a popup, we must wait for the CreatingNew_ACK message before
389 // completing initialization. Otherwise, we can finish it now.
390 if (opener_id == MSG_ROUTING_NONE) {
391 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55392 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51393 }
394
[email protected]34c61bd52011-05-02 19:38:33395 g_view_map.Get().insert(std::make_pair(webview(), this));
396 webkit_preferences_.Apply(webview());
397 webview()->initializeMainFrame(this);
398 if (!frame_name.empty())
399 webview()->mainFrame()->setName(frame_name);
400 webview()->settings()->setMinimumTimerInterval(
401 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
402 webkit_glue::kForegroundTabTimerInterval);
403
404 OnSetRendererPrefs(renderer_prefs);
405
[email protected]676126f72011-01-15 00:03:51406 host_window_ = parent_hwnd;
407
408 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]676126f72011-01-15 00:03:51409 if (command_line.HasSwitch(switches::kEnableAccessibility))
410 WebAccessibilityCache::enableAccessibility();
411
[email protected]a026daa2011-04-20 15:49:51412#if defined(ENABLE_P2P_APIS)
[email protected]09b36762011-07-19 01:19:12413 p2p_socket_dispatcher_ = new P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51414#endif
[email protected]cae8c8492011-03-03 11:12:18415
[email protected]8f6a3b852011-07-19 16:48:56416 new MHTMLGenerator(this);
417
[email protected]c5c1d6d2011-07-28 18:42:41418 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20419
[email protected]ab2c4732011-07-20 19:57:40420 if (command_line.HasSwitch(switches::kEnableMediaStream)) {
421 media_stream_impl_ = new MediaStreamImpl(
422 RenderThread::current()->video_capture_impl_manager());
423 }
424
[email protected]e48869a2011-04-01 19:56:03425 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29426}
427
428RenderView::~RenderView() {
[email protected]d466b8a2011-07-15 21:48:03429 history_page_ids_.clear();
430
[email protected]0aa55312008-10-17 21:53:08431 if (decrement_shared_popup_at_destruction_)
432 shared_popup_counter_->data--;
433
[email protected]a1128322009-10-06 18:38:46434 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47435 while (!file_chooser_completions_.empty()) {
436 if (file_chooser_completions_.front()->completion) {
437 file_chooser_completions_.front()->completion->didChooseFile(
438 WebVector<WebString>());
439 }
440 file_chooser_completions_.pop_front();
441 }
[email protected]a1128322009-10-06 18:38:46442
[email protected]83dde542009-09-11 20:59:55443#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11444 // Destroy all fake plugin window handles on the browser side.
445 while (!fake_plugin_window_handles_.empty()) {
446 // Make sure no NULL plugin window handles were inserted into this list.
447 DCHECK(*fake_plugin_window_handles_.begin());
448 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
449 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
450 }
[email protected]83dde542009-09-11 20:59:55451#endif
[email protected]98324892009-09-09 21:16:05452
[email protected]60c42a8c72009-10-09 04:08:59453#ifndef NDEBUG
454 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49455 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59456 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
457 DCHECK_NE(this, it->second) << "Failed to call Close?";
458#endif
[email protected]676126f72011-01-15 00:03:51459
460 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
461 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59462}
463
464/*static*/
465void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49466 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59467 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
468 if (!visitor->Visit(it->second))
469 return;
470 }
471}
472
473/*static*/
474RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49475 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59476 ViewMap::iterator it = views->find(webview);
477 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29478}
479
480/*static*/
[email protected]0aa55312008-10-17 21:53:08481RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24482 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15483 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08484 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51485 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08486 const WebPreferences& webkit_prefs,
487 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34488 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26489 int64 session_storage_namespace_id,
490 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29491 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51492 return new RenderView(
493 render_thread,
494 parent_hwnd,
495 opener_id,
496 renderer_prefs,
497 webkit_prefs,
498 counter,
499 routing_id,
500 session_storage_namespace_id,
501 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29502}
503
[email protected]bb461532010-11-26 21:50:23504// static
initial.commit09911bf2008-07-26 23:55:29505void RenderView::SetNextPageID(int32 next_page_id) {
506 // This method should only be called during process startup, and the given
507 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05508 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29509 DCHECK(next_page_id >= next_page_id_);
510 next_page_id_ = next_page_id;
511}
512
[email protected]676126f72011-01-15 00:03:51513void RenderView::AddObserver(RenderViewObserver* observer) {
514 observers_.AddObserver(observer);
515}
516
517void RenderView::RemoveObserver(RenderViewObserver* observer) {
518 observer->set_render_view(NULL);
519 observers_.RemoveObserver(observer);
520}
521
[email protected]70eee342010-11-05 01:59:37522bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
523 typedef ViewHostMsg_AccessibilityNotification_Params params;
[email protected]a527a022011-02-10 02:32:36524 if (type == WebKit::WebAccessibilityNotificationChildrenChanged ||
525 type == WebKit::WebAccessibilityNotificationLoadComplete) {
[email protected]70eee342010-11-05 01:59:37526 return true;
527 }
528 return false;
529}
530
[email protected]8a3125a712010-08-09 18:58:51531WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26532 return static_cast<WebKit::WebView*>(webwidget());
533}
534
[email protected]1a3c3cb2010-12-16 21:03:40535void RenderView::SetReportLoadProgressEnabled(bool enabled) {
536 if (!enabled) {
537 load_progress_tracker_.reset(NULL);
538 return;
539 }
540 if (load_progress_tracker_ == NULL)
541 load_progress_tracker_.reset(new LoadProgressTracker(this));
542}
543
[email protected]a3a8fb6d2009-10-22 20:12:51544void RenderView::PluginCrashed(const FilePath& plugin_path) {
545 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29546}
547
[email protected]aad51d1c2010-08-05 08:38:09548WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
549 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50550 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26551 bool found;
[email protected]6fdd4182010-10-14 23:59:26552 std::string mime_type;
553 Send(new ViewHostMsg_GetPluginInfo(
[email protected]b6cb3a842011-06-24 18:28:41554 routing_id_, params.url, frame->top()->document().url(),
555 params.mimeType.utf8(), &found, &info, &mime_type));
[email protected]b83ff222011-01-24 17:37:12556 if (!found || !webkit::npapi::IsPluginEnabled(info))
[email protected]aad51d1c2010-08-05 08:38:09557 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45558
[email protected]96dcc1762011-04-04 16:01:09559 bool pepper_plugin_was_registered = false;
[email protected]0bd753682010-12-16 18:15:52560 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]96dcc1762011-04-04 16:01:09561 pepper_delegate_.CreatePepperPlugin(info.path,
562 &pepper_plugin_was_registered));
563 if (pepper_plugin_was_registered) {
564 if (pepper_module)
565 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
566 return NULL;
567 }
[email protected]1a78d9f32010-12-08 06:38:45568 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09569}
570
[email protected]d8fd6fa2010-02-01 15:54:26571void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
572 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30573 // If the renderer is visible, set initial visibility and focus state.
574 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34575#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30576 delegate->SetContainerVisibility(true);
577 if (webview() && webview()->isActive())
578 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34579#endif
[email protected]49232292010-09-03 19:07:30580 }
[email protected]784ea1ab2010-09-18 00:02:34581 // Plugins start assuming the content has focus (so that they work in
582 // environments where RenderView isn't hosting them), so we always have to
583 // set the initial state. See webplugin_delegate_impl.h for details.
584 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26585}
586
587void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
588 plugin_delegates_.erase(delegate);
589}
[email protected]d8fd6fa2010-02-01 15:54:26590
[email protected]a95986a82010-12-24 06:19:28591bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27592 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27593 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41594 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26595
[email protected]676126f72011-01-15 00:03:51596 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
597 RenderViewObserver* observer;
598 while ((observer = it.GetNext()) != NULL)
599 if (observer->OnMessageReceived(message))
600 return true;
[email protected]b2abac72009-02-26 12:39:28601
[email protected]a95986a82010-12-24 06:19:28602 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29603 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29604 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
605 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56606 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29607 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
608 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
609 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
610 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27611#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35612 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27613#endif
initial.commit09911bf2008-07-26 23:55:29614 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
615 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
616 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
617 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
618 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15619 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29620 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49621 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
622 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17623 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17624 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:54625 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
626 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:29627 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18628 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
629 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29630 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48631 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29632 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55633 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
634 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
635 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
636 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
637 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
638 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
639 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45640 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40641 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29642 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:51643 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
644 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:29645 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
646 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
647 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
648 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]600ea402011-04-12 00:01:51649 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
650 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29651 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04652 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15653 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29654 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
655 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08656 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
657 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00658 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16659 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14660 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25661 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
662 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10663 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
664 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51665 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56666 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34667 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14668#if defined(OS_MACOSX)
669 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13670 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13671 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
672 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14673#endif
[email protected]446705872009-09-10 07:22:48674 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33675 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33676 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
677 OnCustomContextMenuAction)
[email protected]dea2d372010-09-25 06:41:14678 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:36679 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
680 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
681 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:42682 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
683 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:24684 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42685 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
686 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19687 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
688 OnGetAllSavableResourceLinksForCurrentPage)
689 IPC_MESSAGE_HANDLER(
690 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
691 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08692#if defined(OS_MACOSX)
693 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
694#endif
[email protected]521b2482011-01-15 00:10:10695 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51696 // TODO(viettrungluu): Move to a separate message filter.
697#if defined(ENABLE_FLAPPER_HACKS)
698 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
699#endif
[email protected]54ca3ca892011-06-07 21:14:54700#if defined(OS_MACOSX)
701 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
702#endif
[email protected]08bb1e722011-07-30 19:13:04703 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRemoteAccessClientFirewallTraversal,
704 OnUpdateRemoteAccessClientFirewallTraversal)
initial.commit09911bf2008-07-26 23:55:29705 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28706 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29707 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28708 return handled;
initial.commit09911bf2008-07-26 23:55:29709}
710
initial.commit09911bf2008-07-26 23:55:29711void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
712 if (!webview())
713 return;
714
[email protected]d466b8a2011-07-15 21:48:03715 bool is_reload =
716 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
717 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
718
719 // If this is a stale back/forward (due to a recent navigation the browser
720 // didn't know about), ignore it.
721 if (IsBackForwardToStaleEntry(params, is_reload))
722 return;
723
[email protected]992db4c2011-05-12 15:37:15724 // Swap this renderer back in if necessary.
725 if (is_swapped_out_)
726 SetSwappedOut(false);
727
[email protected]3cc72b12010-03-18 23:03:00728 history_list_offset_ = params.current_history_list_offset;
729 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03730 if (history_list_length_ >= 0)
731 history_page_ids_.resize(history_list_length_, -1);
732 if (params.pending_history_list_offset >= 0 &&
733 params.pending_history_list_offset < history_list_length_)
734 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00735
[email protected]38b592902011-04-16 02:08:42736 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29737
[email protected]26aa0482009-09-30 16:55:27738 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45739 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29740 // We cannot reload if we do not have any history state. This happens, for
741 // example, when recovering from a crash. Our workaround here is a bit of
742 // a hack since it means that reload after a crashed tab does not cause an
743 // end-to-end cache validation.
744 is_reload = false;
745 }
746
[email protected]77f17a82009-05-21 04:42:54747 // A navigation resulting from loading a javascript URL should not be treated
748 // as a browser initiated event. Instead, we want it to look as if the page
749 // initiated any load resulting from JS execution.
750 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30751 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00752 params.page_id,
753 params.pending_history_list_offset,
754 params.transition,
755 params.request_time);
[email protected]2c5569662011-03-22 20:45:02756 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30757 // We're doing a load of a page that was restored from the last session.
758 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
759 // which can result in stale data for pages that are set to expire. We
760 // explicitly override that by setting the policy here so that as
761 // necessary we load from the network.
762 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
763 }
764 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54765 }
initial.commit09911bf2008-07-26 23:55:29766
[email protected]a7ccc4d2010-01-27 08:14:48767 NavigationState* navigation_state = pending_navigation_state_.get();
768
[email protected]48a5c772011-04-18 23:50:50769 if (navigation_state) {
770 // New loads need to reset the error page fetcher. Otherwise if there is an
771 // outstanding error page fetcher it may complete and clobber the current
772 // page load.
773 navigation_state->set_alt_error_page_fetcher(NULL);
774 }
775
[email protected]04d3c6e2009-05-22 17:00:13776 // If we are reloading, then WebKit will use the history state of the current
777 // page, so we should just ignore any given history state. Otherwise, if we
778 // have history state, then we need to navigate to it, which corresponds to a
779 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55780 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48781 if (navigation_state)
782 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29783 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02784 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29785 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55786 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13787 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58788 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48789 if (navigation_state)
790 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45791 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17792 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13793 } else {
794 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28795 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29796
[email protected]e6f546c32009-07-01 17:12:55797 // A session history navigation should have been accompanied by state.
798 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13799
[email protected]dd7daa82009-08-10 05:46:45800 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55801 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13802
[email protected]726985e22009-06-18 21:09:28803 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17804 if (!WebSecurityPolicy::shouldHideReferrer(
805 params.url,
806 WebString::fromUTF8(params.referrer.spec()))) {
807 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
808 WebString::fromUTF8(params.referrer.spec()));
809 }
[email protected]726985e22009-06-18 21:09:28810 }
[email protected]04d3c6e2009-05-22 17:00:13811
[email protected]52c68652010-12-07 17:47:04812 if (!params.extra_headers.empty()) {
813 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
814 params.extra_headers.end(), "\n");
815 i.GetNext(); ) {
816 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
817 WebString::fromUTF8(i.values()));
818 }
819 }
820
[email protected]16e923d2011-04-30 00:41:44821 if (navigation_state)
822 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45823 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50824 }
825
[email protected]77f17a82009-05-21 04:42:54826 // In case LoadRequest failed before DidCreateDataSource was called.
827 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29828}
829
[email protected]d466b8a2011-07-15 21:48:03830bool RenderView::IsBackForwardToStaleEntry(
831 const ViewMsg_Navigate_Params& params,
832 bool is_reload) {
833 // Make sure this isn't a back/forward to an entry we have already cropped
834 // or replaced from our history, before the browser knew about it. If so,
835 // a new navigation has committed in the mean time, and we can ignore this.
836 bool is_back_forward = !is_reload && !params.state.empty();
837
838 // Note: if the history_list_length_ is 0 for a back/forward, we must be
839 // restoring from a previous session. We'll update our state in OnNavigate.
840 if (!is_back_forward || history_list_length_ <= 0)
841 return false;
842
843 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
844
845 // Check for whether the forward history has been cropped due to a recent
846 // navigation the browser didn't know about.
847 if (params.pending_history_list_offset >= history_list_length_)
848 return true;
849
850 // Check for whether this entry has been replaced with a new one.
851 int expected_page_id =
852 history_page_ids_[params.pending_history_list_offset];
853 if (expected_page_id > 0 && params.page_id != expected_page_id)
854 return true;
855
856 return false;
857}
858
initial.commit09911bf2008-07-26 23:55:29859// Stop loading the current page
860void RenderView::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44861 if (webview()) {
862 WebFrame* main_frame = webview()->mainFrame();
863 // Stop the alt error page fetcher. If we let it continue it may complete
864 // and cause RenderViewHostManager to swap to this RenderView, even though
865 // it may no longer be active.
866 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
867 StopAltErrorPageFetcher(main_frame->dataSource());
868 main_frame->stopLoading();
869 }
initial.commit09911bf2008-07-26 23:55:29870}
871
[email protected]ecbf10d2010-02-18 13:03:29872// Reload current focused frame.
873// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56874void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29875 if (webview() && webview()->focusedFrame()) {
876 // We always obey the cache (ignore_cache=false) here.
877 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
878 // a cache-ignoring reload of the frame.
879 webview()->focusedFrame()->reload(false);
880 }
[email protected]1dda4022010-01-28 18:24:56881}
882
initial.commit09911bf2008-07-26 23:55:29883void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27884 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29885}
886
[email protected]68b1e922009-06-23 16:00:25887void RenderView::OnExecuteEditCommand(const std::string& name,
888 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27889 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25890 return;
891
[email protected]26aa0482009-09-30 16:55:27892 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45893 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25894}
895
initial.commit09911bf2008-07-26 23:55:29896void RenderView::OnUpdateTargetURLAck() {
897 // Check if there is a targeturl waiting to be sent.
898 if (target_url_status_ == TARGET_PENDING) {
899 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
900 pending_target_url_));
901 }
902
903 target_url_status_ = TARGET_NONE;
904}
905
906void RenderView::OnUndo() {
907 if (!webview())
908 return;
909
[email protected]26aa0482009-09-30 16:55:27910 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29911}
912
913void RenderView::OnRedo() {
914 if (!webview())
915 return;
916
[email protected]26aa0482009-09-30 16:55:27917 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29918}
919
920void RenderView::OnCut() {
921 if (!webview())
922 return;
923
[email protected]26aa0482009-09-30 16:55:27924 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29925}
926
927void RenderView::OnCopy() {
928 if (!webview())
929 return;
930
[email protected]f6b1856b2011-06-29 22:02:53931 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
932 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29933}
934
[email protected]c0cc3092009-09-12 08:27:27935#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35936void RenderView::OnCopyToFindPboard() {
937 if (!webview())
938 return;
939
940 // Since the find pasteboard supports only plain text, this can be simpler
941 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27942 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35943 if (frame->hasSelection()) {
944 string16 selection = frame->selectionAsText();
945 RenderThread::current()->Send(
[email protected]7e3589742011-03-10 18:49:17946 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35947 }
[email protected]a954bf72009-09-12 07:30:35948}
[email protected]c0cc3092009-09-12 08:27:27949#endif
[email protected]a954bf72009-09-12 07:30:35950
initial.commit09911bf2008-07-26 23:55:29951void RenderView::OnPaste() {
952 if (!webview())
953 return;
954
[email protected]26aa0482009-09-30 16:55:27955 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29956}
957
[email protected]2a3a7762009-10-19 19:17:32958void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29959 if (!webview())
960 return;
961
[email protected]1ff7a032010-02-03 02:46:03962 WebFrame* frame = webview()->focusedFrame();
963 if (!frame->hasSelection())
964 frame->selectWordAroundCaret();
965 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29966}
967
968void RenderView::OnDelete() {
969 if (!webview())
970 return;
971
[email protected]26aa0482009-09-30 16:55:27972 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29973}
974
975void RenderView::OnSelectAll() {
976 if (!webview())
977 return;
978
[email protected]26aa0482009-09-30 16:55:27979 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22980 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29981}
982
983void RenderView::OnSetInitialFocus(bool reverse) {
984 if (!webview())
985 return;
[email protected]26aa0482009-09-30 16:55:27986 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29987}
988
[email protected]54ca3ca892011-06-07 21:14:54989#if defined(OS_MACOSX)
990void RenderView::OnSetInLiveResize(bool in_live_resize) {
991 if (!webview())
992 return;
993 if (in_live_resize)
994 webview()->willStartLiveResize();
995 else
996 webview()->willEndLiveResize();
997}
998#endif
999
[email protected]9b66f34bf2010-10-27 20:45:511000void RenderView::OnScrollFocusedEditableNodeIntoView() {
[email protected]13a1e4c3c2011-02-03 21:07:091001 WebKit::WebNode node = GetFocusedNode();
1002 if (!node.isNull()) {
1003 if (IsEditableNode(node))
1004 // TODO(varunjain): Change webkit API to scroll a particular node into
1005 // view and use that API here instead.
1006 webview()->scrollFocusedNodeIntoView();
[email protected]9b66f34bf2010-10-27 20:45:511007 }
1008}
1009
initial.commit09911bf2008-07-26 23:55:291010///////////////////////////////////////////////////////////////////////////////
1011
1012// Tell the embedding application that the URL of the active page has changed
1013void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451014 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291015 DCHECK(ds);
1016
[email protected]726985e22009-06-18 21:09:281017 const WebURLRequest& request = ds->request();
1018 const WebURLRequest& original_request = ds->originalRequest();
1019 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291020
[email protected]daa8c58e2009-06-15 17:21:101021 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1022 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291023
1024 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281025 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291026 params.is_post = false;
1027 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071028 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191029 params.socket_address.set_host(response.remoteIPAddress().utf8());
1030 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031031 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091032 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551033 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291034 // SSL state specified in the request takes precedence over the one in the
1035 // response.
1036 // So far this is only intended for error pages that are not expected to be
1037 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281038 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551039 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291040 } else {
[email protected]726985e22009-06-18 21:09:281041 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291042 }
1043
1044 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281045 if (ds->hasUnreachableURL()) {
1046 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291047 } else {
[email protected]726985e22009-06-18 21:09:281048 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291049 }
1050
[email protected]726985e22009-06-18 21:09:281051 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241052 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041053 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291054
[email protected]ce0e250d2009-10-23 21:00:351055 params.searchable_form_url = navigation_state->searchable_form_url();
1056 params.searchable_form_encoding =
1057 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291058
1059 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101060 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291061 if (password_form_data)
1062 params.password_form = *password_form_data;
1063
1064 params.gesture = navigation_gesture_;
1065 navigation_gesture_ = NavigationGestureUnknown;
1066
[email protected]0f38dc4552011-02-25 11:24:001067 // Make navigation state a part of the FrameNavigate message so that commited
1068 // entry had it at all times.
1069 const WebHistoryItem& item = frame->currentHistoryItem();
1070 if (!item.isNull()) {
1071 params.content_state = webkit_glue::HistoryItemToString(item);
1072 } else {
1073 params.content_state =
1074 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1075 }
1076
[email protected]dd7daa82009-08-10 05:46:451077 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291078 // Top-level navigation.
1079
[email protected]b75b8292010-10-01 07:28:251080 // Set zoom level, but don't do it for full-page plugin since they don't use
1081 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011082 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541083 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251084 if (webview()->mainFrame()->document().isPluginDocument()) {
1085 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251086 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251087 } else {
1088 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251089 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251090 }
1091
[email protected]f85f0702010-01-30 09:31:011092 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511093 // This zoom level was merely recorded transiently for this load. We can
1094 // erase it now. If at some point we reload this page, the browser will
1095 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011096 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511097 }
1098
[email protected]b75b8292010-10-01 07:28:251099 // Reset the zoom limits in case a plugin had changed them previously. This
1100 // will also call us back which will cause us to send a message to
1101 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251102 webview()->zoomLimitsChanged(
1103 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1104 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251105
initial.commit09911bf2008-07-26 23:55:291106 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551107 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291108
[email protected]daa8c58e2009-06-15 17:21:101109 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291110 if (!PageTransition::IsMainFrame(params.transition)) {
1111 // If the main frame does a load, it should not be reported as a subframe
1112 // navigation. This can occur in the following case:
1113 // 1. You're on a site with frames.
1114 // 2. You do a subframe navigation. This is stored with transition type
1115 // MANUAL_SUBFRAME.
1116 // 3. You navigate to some non-frame site, say, google.com.
1117 // 4. You navigate back to the page from step 2. Since it was initially
1118 // MANUAL_SUBFRAME, it will be that same transition type here.
1119 // We don't want that, because any navigation that changes the toplevel
1120 // frame should be tracked as a toplevel navigation (this allows us to
1121 // update the URL bar, etc).
1122 params.transition = PageTransition::LINK;
1123 }
1124
initial.commit09911bf2008-07-26 23:55:291125 // If we have a valid consumed client redirect source,
1126 // the page contained a client redirect (meta refresh, document.loc...),
1127 // so we set the referrer and transition to match.
1128 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041129 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291130 params.referrer = completed_client_redirect_src_;
1131 params.transition = static_cast<PageTransition::Type>(
1132 params.transition | PageTransition::CLIENT_REDIRECT);
1133 } else {
1134 // Bug 654101: the referrer will be empty on https->http transitions. It
1135 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281136 params.referrer = GURL(
1137 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291138 }
1139
[email protected]726985e22009-06-18 21:09:281140 string16 method = request.httpMethod();
1141 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291142 params.is_post = true;
1143
[email protected]c2a797d2009-09-21 16:46:321144 // Save some histogram data so we can compute the average memory used per
1145 // page load of the glyphs.
1146 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1147 webkit_glue::GetGlyphPageCount());
1148
[email protected]15cf526b2010-02-12 06:33:491149 // This message needs to be sent before any of allowScripts(),
1150 // allowImages(), allowPlugins() is called for the new page, so that when
1151 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1152 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291153 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1154 } else {
1155 // Subframe navigation: the type depends on whether this navigation
1156 // generated a new session history entry. When they do generate a session
1157 // history entry, it means the user initiated the navigation and we should
1158 // mark it as such. This test checks if this is the first time UpdateURL
1159 // has been called since WillNavigateToURL was called to initiate the load.
1160 if (page_id_ > last_page_id_sent_to_browser_)
1161 params.transition = PageTransition::MANUAL_SUBFRAME;
1162 else
1163 params.transition = PageTransition::AUTO_SUBFRAME;
1164
initial.commit09911bf2008-07-26 23:55:291165 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1166 }
1167
1168 last_page_id_sent_to_browser_ =
1169 std::max(last_page_id_sent_to_browser_, page_id_);
1170
1171 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101172 // we don't want the transition type to persist. Just clear it.
1173 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501174
[email protected]af15bed2010-08-25 21:12:091175 // Check if the navigation was within the same page, in which case we don't
1176 // want to clear the accessibility cache.
1177 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351178 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141179 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501180 }
initial.commit09911bf2008-07-26 23:55:291181}
1182
1183// Tell the embedding application that the title of the active page has changed
[email protected]750fcf872011-08-03 23:10:471184void RenderView::UpdateTitle(WebFrame* frame,
1185 const string16& title,
[email protected]a49e10b2011-08-01 23:57:461186 WebTextDirection title_direction) {
1187 // Ignore all but top level navigations.
1188 if (frame->parent())
1189 return;
1190
1191 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1192 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1193 title_direction));
initial.commit09911bf2008-07-26 23:55:291194}
1195
1196void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401197 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291198 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271199 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291200 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301201 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291202 last_encoding_name_ = encoding_name;
1203
[email protected]e38f40152008-09-12 23:08:301204 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291205 }
1206}
1207
[email protected]e15f680732010-11-23 22:30:201208// Sends the last committed session history state to the browser so it will be
1209// saved before we navigate to a new page. This must be called *before* the
1210// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291211void RenderView::UpdateSessionHistory(WebFrame* frame) {
1212 // If we have a valid page ID at this point, then it corresponds to the page
1213 // we are navigating away from. Otherwise, this is the first navigation, so
1214 // there is no past session history to record.
1215 if (page_id_ == -1)
1216 return;
1217
[email protected]ca948a22009-06-25 19:36:171218 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271219 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171220 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291221 return;
[email protected]ca948a22009-06-25 19:36:171222
1223 Send(new ViewHostMsg_UpdateState(
1224 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291225}
1226
[email protected]3d9689372009-09-10 04:29:171227void RenderView::OpenURL(
1228 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1229 Send(new ViewHostMsg_OpenURL(
1230 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1231}
1232
[email protected]79dbc662009-09-04 05:42:511233// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291234
initial.commit09911bf2008-07-26 23:55:291235void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281236 const WebURLRequest& failed_request,
1237 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291238 const std::string& html,
1239 bool replace) {
[email protected]c5c1d6d2011-07-28 18:42:411240
1241 // Do not show alternate error page when DevTools is attached.
1242 if (devtools_agent_->IsAttached())
1243 return;
1244
[email protected]21d61e52011-03-18 19:08:251245 std::string alt_html = !html.empty() ? html :
1246 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1247 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451248 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361249 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251250 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551251 replace);
initial.commit09911bf2008-07-26 23:55:291252}
1253
initial.commit09911bf2008-07-26 23:55:291254bool RenderView::RunJavaScriptMessage(int type,
[email protected]4f5ce842011-05-27 19:34:411255 const string16& message,
1256 const string16& default_value,
[email protected]a455d3812009-03-05 20:18:071257 const GURL& frame_url,
[email protected]4f5ce842011-05-27 19:34:411258 string16* result) {
initial.commit09911bf2008-07-26 23:55:291259 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411260 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291261 if (!result)
1262 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291263
[email protected]12636df2009-09-28 22:32:211264 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1265 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291266 return success;
1267}
1268
[email protected]c1f50aa2010-02-18 03:46:571269bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1270 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1271 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1272 // it is particularly important that we do not call willEnterModalLoop as
1273 // that would defer resource loads for the dialog itself.
1274 if (RenderThread::current()) // Will be NULL during unit tests.
1275 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1276
1277 message->EnableMessagePumping(); // Runs a nested message loop.
1278 return Send(message);
1279}
1280
[email protected]f103ab72009-09-02 17:10:591281void RenderView::OnMissingPluginStatus(
1282 WebPluginDelegateProxy* delegate,
1283 int status) {
[email protected]6c8afae52009-01-22 02:24:571284#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:591285 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:291286 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:501287 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:591288 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:291289 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1290 }
1291 } else {
1292 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
1293 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:501294 if (status ==
1295 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:291296 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
1297 }
1298 }
[email protected]6c8afae52009-01-22 02:24:571299#else
[email protected]76c3b312010-05-20 21:38:291300 // TODO(port): Implement the infobar that accompanies the default plugin.
1301 // Linux: http://crbug.com/10952
1302 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:571303 NOTIMPLEMENTED();
1304#endif
initial.commit09911bf2008-07-26 23:55:291305}
1306
[email protected]48c9cf2d2009-09-16 16:47:521307// WebKit::WebViewClient ------------------------------------------------------
1308
[email protected]844acf372011-01-14 10:49:271309WebView* RenderView::createView(
1310 WebFrame* creator,
1311 const WebURLRequest& request,
1312 const WebWindowFeatures& features,
1313 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521314 // Check to make sure we aren't overloading on popups.
1315 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1316 return NULL;
1317
[email protected]8ab04652010-06-12 02:47:261318 ViewHostMsg_CreateWindow_Params params;
1319 params.opener_id = routing_id_;
1320 params.user_gesture = creator->isProcessingUserGesture();
1321 params.window_container_type = WindowFeaturesToContainerType(features);
1322 params.session_storage_namespace_id = session_storage_namespace_id_;
1323 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111324 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411325 params.opener_url = creator->document().url();
1326 params.opener_security_origin =
1327 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111328 if (!request.isNull())
1329 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261330
[email protected]48c9cf2d2009-09-16 16:47:521331 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341332 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261333 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521334
[email protected]48c9cf2d2009-09-16 16:47:521335 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261336 new ViewHostMsg_CreateWindow(params,
1337 &routing_id,
1338 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211339 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521340 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521341
[email protected]48c9cf2d2009-09-16 16:47:521342 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421343 0,
[email protected]12636df2009-09-28 22:32:211344 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521345 renderer_preferences_,
1346 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211347 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341348 routing_id,
[email protected]8ab04652010-06-12 02:47:261349 cloned_session_storage_namespace_id,
1350 frame_name);
1351 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521352
[email protected]007a848b2009-10-26 15:55:461353 // Record whether the creator frame is trying to suppress the opener field.
1354 view->opener_suppressed_ = opener_suppressed;
1355
[email protected]48c9cf2d2009-09-16 16:47:521356 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411357 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521358 if (!creator_url.is_valid() || !creator_url.IsStandard())
1359 creator_url = GURL();
1360 view->creator_url_ = creator_url;
1361
1362 // Copy over the alternate error page URL so we can have alt error pages in
1363 // the new render view (we don't need the browser to send the URL back down).
1364 view->alternate_error_page_url_ = alternate_error_page_url_;
1365
1366 return view->webview();
1367}
1368
[email protected]3e2b375b2010-04-07 17:03:121369WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521370 RenderWidget* widget = RenderWidget::Create(routing_id_,
1371 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121372 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521373 return widget->webwidget();
1374}
1375
1376WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441377 // TODO(jcivelli): Remove this deprecated method when its been removed from
1378 // the WebViewClient interface. It's been replaced by
1379 // createExternalPopupMenu.
1380 NOTREACHED();
1381 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521382}
1383
[email protected]caf706f2010-10-26 17:54:081384WebExternalPopupMenu* RenderView::createExternalPopupMenu(
1385 const WebPopupMenuInfo& popup_menu_info,
1386 WebExternalPopupMenuClient* popup_menu_client) {
1387 DCHECK(!external_popup_menu_.get());
1388 external_popup_menu_.reset(
1389 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1390 return external_popup_menu_.get();
1391}
1392
[email protected]ea192e82011-04-11 19:16:021393RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521394 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531395 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421396 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411397 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531398 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
1399 routing_id_, render_thread_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391400 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561401 return widget;
[email protected]79c7bed2010-09-14 22:28:391402}
1403
[email protected]68c50e52010-05-12 11:14:391404WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341405 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391406 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291407 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1408 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1409 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341410}
1411
[email protected]48c9cf2d2009-09-16 16:47:521412void RenderView::didAddMessageToConsole(
1413 const WebConsoleMessage& message, const WebString& source_name,
1414 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081415 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511416 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081417 case WebConsoleMessage::LevelTip:
1418 log_severity = logging::LOG_VERBOSE;
1419 break;
1420 case WebConsoleMessage::LevelLog:
1421 log_severity = logging::LOG_INFO;
1422 break;
1423 case WebConsoleMessage::LevelWarning:
1424 log_severity = logging::LOG_WARNING;
1425 break;
1426 case WebConsoleMessage::LevelError:
1427 log_severity = logging::LOG_ERROR;
1428 break;
1429 default:
1430 NOTREACHED();
1431 }
1432
[email protected]48c9cf2d2009-09-16 16:47:521433 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081434 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311435 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521436 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311437 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521438}
1439
1440void RenderView::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421441 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521442}
1443
[email protected]3354d3e2010-06-10 19:53:021444WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511445 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021446}
1447
[email protected]8a58c1c2011-04-19 18:40:121448bool RenderView::enumerateChosenDirectory(
1449 const WebString& path,
1450 WebFileChooserCompletion* chooser_completion) {
1451 int id = enumeration_completion_id_++;
1452 enumeration_completions_[id] = chooser_completion;
1453 return Send(new ViewHostMsg_EnumerateDirectory(
1454 routing_id_,
1455 id,
1456 webkit_glue::WebStringToFilePath(path)));
1457}
1458
[email protected]48c9cf2d2009-09-16 16:47:521459void RenderView::didStartLoading() {
1460 if (is_loading_) {
1461 DLOG(WARNING) << "didStartLoading called while loading";
1462 return;
1463 }
1464
1465 is_loading_ = true;
1466 // Clear the pointer so that we can assign it only when there is an unknown
1467 // plugin on a page.
1468 first_default_plugin_.reset();
1469
1470 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311471
1472 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521473}
1474
1475void RenderView::didStopLoading() {
1476 if (!is_loading_) {
1477 DLOG(WARNING) << "DidStopLoading called while not loading";
1478 return;
1479 }
1480
1481 is_loading_ = false;
1482
1483 // NOTE: For now we're doing the safest thing, and sending out notification
1484 // when done loading. This currently isn't an issue as the favicon is only
1485 // displayed when done loading. Ideally we would send notification when
1486 // finished parsing the head, but webkit doesn't support that yet.
1487 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521488 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1489
[email protected]90109412010-12-15 17:14:241490 if (load_progress_tracker_ != NULL)
1491 load_progress_tracker_->DidStopLoading();
1492
[email protected]93b9d692011-04-13 00:44:311493 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521494}
1495
[email protected]90109412010-12-15 17:14:241496void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
1497 if (load_progress_tracker_ != NULL)
1498 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1499}
1500
[email protected]f55039a2010-02-17 14:12:061501bool RenderView::isSmartInsertDeleteEnabled() {
1502#if defined(OS_MACOSX)
1503 return true;
1504#else
1505 return false;
1506#endif
1507}
1508
[email protected]04fc9482009-09-18 22:13:031509bool RenderView::isSelectTrailingWhitespaceEnabled() {
1510#if defined(OS_WIN)
1511 return true;
1512#else
1513 return false;
1514#endif
1515}
1516
[email protected]04fc9482009-09-18 22:13:031517void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:421518#if defined(OS_POSIX)
[email protected]c631b592011-08-06 00:58:551519 if (!handling_input_event_)
[email protected]04fc9482009-09-18 22:13:031520 return;
[email protected]d4cff272011-05-02 15:46:011521
1522 if (is_empty_selection) {
1523 last_selection_.clear();
1524 } else {
[email protected]04fc9482009-09-18 22:13:031525 // Sometimes we get repeated didChangeSelection calls from webkit when
1526 // the selection hasn't actually changed. We don't want to report these
1527 // because it will cause us to continually claim the X clipboard.
[email protected]d4cff272011-05-02 15:46:011528 WebFrame* frame = webview()->focusedFrame();
1529 const std::string& this_selection = frame->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:031530 if (this_selection == last_selection_)
1531 return;
[email protected]04fc9482009-09-18 22:13:031532 last_selection_ = this_selection;
[email protected]04fc9482009-09-18 22:13:031533 }
[email protected]d4cff272011-05-02 15:46:011534
1535 ui::Range range(ui::Range::InvalidRange());
1536 size_t location, length;
1537 if (webview()->caretOrSelectionRange(&location, &length)) {
1538 range.set_start(location);
1539 range.set_end(location + length);
1540 }
[email protected]c631b592011-08-06 00:58:551541 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range));
[email protected]0ff0ff32010-12-21 19:34:421542#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031543}
1544
1545void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121546 const std::string& name = UTF16ToUTF8(command_name);
1547 if (StartsWithASCII(name, "Move", true) ||
1548 StartsWithASCII(name, "Insert", true) ||
1549 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031550 return;
[email protected]c2043682011-06-10 22:49:561551 RenderThread::current()->Send(
1552 new ViewHostMsg_UserMetricsRecordAction(name));
[email protected]04fc9482009-09-18 22:13:031553}
1554
[email protected]54ec7f82010-10-21 22:32:511555void RenderView::SendPendingAccessibilityNotifications() {
1556 if (!accessibility_.get())
1557 return;
1558
1559 if (pending_accessibility_notifications_.empty())
1560 return;
1561
1562 // Send all pending accessibility notifications.
1563 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
1564 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
1565 RendererAccessibilityNotification& notification =
1566 pending_accessibility_notifications_[i];
1567 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
1568 if (!obj.isValid())
1569 continue;
1570
1571 ViewHostMsg_AccessibilityNotification_Params param;
[email protected]a527a022011-02-10 02:32:361572 WebAccessibilityNotificationToViewHostMsg(
1573 pending_accessibility_notifications_[i].type, &param.notification_type);
[email protected]70eee342010-11-05 01:59:371574 param.acc_obj = WebAccessibility(
1575 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:511576 notifications.push_back(param);
1577 }
1578 pending_accessibility_notifications_.clear();
1579 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
1580 accessibility_ack_pending_ = true;
1581}
1582
[email protected]b2528b72009-09-24 06:57:101583bool RenderView::handleCurrentKeyboardEvent() {
1584 if (edit_commands_.empty())
1585 return false;
1586
[email protected]26aa0482009-09-30 16:55:271587 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101588 if (!frame)
1589 return false;
1590
1591 EditCommands::iterator it = edit_commands_.begin();
1592 EditCommands::iterator end = edit_commands_.end();
1593
[email protected]507b33ea2009-09-29 03:56:511594 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101595 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331596 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1597 // key (but it's the exception). Once one edit command is not executed, it
1598 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101599 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1600 WebString::fromUTF8(it->value)))
1601 break;
[email protected]507b33ea2009-09-29 03:56:511602 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101603 }
1604
[email protected]507b33ea2009-09-29 03:56:511605 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101606}
1607
[email protected]a1128322009-10-06 18:38:461608bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351609 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471610 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351611 // Do not open the file dialog in a hidden RenderView.
1612 if (is_hidden())
1613 return false;
[email protected]cdaf8d02010-03-30 19:52:471614 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261615 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361616 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261617 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361618 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]b5977a0c2010-08-24 19:46:261619 else
[email protected]0aed2f52011-03-23 18:06:361620 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471621 ipc_params.title = params.title;
1622 ipc_params.default_file_name =
1623 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591624 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471625
1626 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461627}
1628
[email protected]48c9cf2d2009-09-16 16:47:521629void RenderView::runModalAlertDialog(
1630 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061631 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]4f5ce842011-05-27 19:34:411632 message,
1633 string16(),
[email protected]b6cb3a842011-06-24 18:28:411634 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521635 NULL);
1636}
1637
1638bool RenderView::runModalConfirmDialog(
1639 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061640 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]4f5ce842011-05-27 19:34:411641 message,
1642 string16(),
[email protected]b6cb3a842011-06-24 18:28:411643 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521644 NULL);
1645}
1646
1647bool RenderView::runModalPromptDialog(
1648 WebFrame* frame, const WebString& message, const WebString& default_value,
1649 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411650 string16 result;
[email protected]9dd7e3d72011-01-20 18:27:061651 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]4f5ce842011-05-27 19:34:411652 message,
1653 default_value,
[email protected]b6cb3a842011-06-24 18:28:411654 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521655 &result);
1656 if (ok)
[email protected]4f5ce842011-05-27 19:34:411657 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521658 return ok;
1659}
1660
1661bool RenderView::runModalBeforeUnloadDialog(
1662 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151663 // If we are swapping out, we have already run the beforeunload handler.
1664 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1665 // at all, to avoid running it twice.
1666 if (is_swapped_out_)
1667 return true;
1668
[email protected]48c9cf2d2009-09-16 16:47:521669 bool success = false;
1670 // This is an ignored return value, but is included so we can accept the same
1671 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411672 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211673 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411674 routing_id_, frame->document().url(), message,
1675 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521676 return success;
1677}
1678
[email protected]79e37442009-10-09 18:17:441679void RenderView::showContextMenu(
1680 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291681 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371682
1683 // frame is NULL if invoked by BlockedPlugin.
1684 if (frame)
1685 params.frame_id = frame->identifier();
1686
[email protected]db803aae2011-03-05 02:00:421687 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271688 // it. We replace it with an empty GURL so the appropriate items are disabled
1689 // in the context menu.
1690 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1691 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421692 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271693 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101694 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291695 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441696}
1697
[email protected]52f139e2c2010-06-11 16:56:091698bool RenderView::supportsFullscreen() {
1699 return CommandLine::ForCurrentProcess()->HasSwitch(
1700 switches::kEnableVideoFullscreen);
1701}
1702
1703void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1704 NOTIMPLEMENTED();
1705}
1706
1707void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1708 NOTIMPLEMENTED();
1709}
1710
[email protected]48c9cf2d2009-09-16 16:47:521711void RenderView::setStatusText(const WebString& text) {
1712}
1713
[email protected]163f8242009-10-30 20:19:551714void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581715 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521716 if (latest_url == target_url_)
1717 return;
[email protected]163f8242009-10-30 20:19:551718
[email protected]48c9cf2d2009-09-16 16:47:521719 // Tell the browser to display a destination link.
1720 if (target_url_status_ == TARGET_INFLIGHT ||
1721 target_url_status_ == TARGET_PENDING) {
1722 // If we have a request in-flight, save the URL to be sent when we
1723 // receive an ACK to the in-flight request. We can happily overwrite
1724 // any existing pending sends.
1725 pending_target_url_ = latest_url;
1726 target_url_status_ = TARGET_PENDING;
1727 } else {
1728 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1729 target_url_ = latest_url;
1730 target_url_status_ = TARGET_INFLIGHT;
1731 }
1732}
1733
[email protected]882daa92009-11-05 16:31:311734void RenderView::StartNavStateSyncTimerIfNecessary() {
1735 int delay;
1736 if (send_content_state_immediately_)
1737 delay = 0;
1738 else if (is_hidden())
1739 delay = kDelaySecondsForContentStateSyncHidden;
1740 else
1741 delay = kDelaySecondsForContentStateSync;
1742
1743 if (nav_state_sync_timer_.IsRunning()) {
1744 // The timer is already running. If the delay of the timer maches the amount
1745 // we want to delay by, then return. Otherwise stop the timer so that it
1746 // gets started with the right delay.
1747 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1748 return;
1749 nav_state_sync_timer_.Stop();
1750 }
1751
1752 nav_state_sync_timer_.Start(
1753 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
1754}
1755
[email protected]163f8242009-10-30 20:19:551756void RenderView::setMouseOverURL(const WebURL& url) {
1757 mouse_over_url_ = GURL(url);
1758 UpdateTargetURL(mouse_over_url_, focus_url_);
1759}
1760
1761void RenderView::setKeyboardFocusURL(const WebURL& url) {
1762 focus_url_ = GURL(url);
1763 UpdateTargetURL(focus_url_, mouse_over_url_);
1764}
1765
[email protected]c27ae592010-03-18 15:24:411766void RenderView::startDragging(const WebDragData& data,
1767 WebDragOperationsMask mask,
1768 const WebImage& image,
1769 const WebPoint& imageOffset) {
1770#if WEBKIT_USING_SKIA
1771 SkBitmap bitmap(image.getSkBitmap());
1772#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331773 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411774#endif
1775
[email protected]59f4f2fa2011-03-23 01:00:551776 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521777 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411778 mask,
1779 bitmap,
1780 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521781}
1782
[email protected]28b92df2009-09-25 17:35:451783bool RenderView::acceptsLoadDrops() {
1784 return renderer_preferences_.can_accept_load_drops;
1785}
1786
[email protected]48c9cf2d2009-09-16 16:47:521787void RenderView::focusNext() {
1788 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1789}
1790
1791void RenderView::focusPrevious() {
1792 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1793}
1794
[email protected]08e9e132010-06-01 16:58:491795void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511796 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071797
1798 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
1799 // TODO(ctguil): Make WebKit send this notification.
1800 // When focus is cleared notify accessibility that the document is focused.
1801 postAccessibilityNotification(
1802 webview()->accessibilityObject(),
1803 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
1804 }
[email protected]13a1e4c3c2011-02-03 21:07:091805
[email protected]38b592902011-04-16 02:08:421806 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491807}
1808
[email protected]48c9cf2d2009-09-16 16:47:521809void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521810 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1811}
1812
1813int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001814 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521815}
1816
1817int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001818 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521819}
1820
[email protected]c4e98902010-06-01 10:20:141821void RenderView::didUpdateInspectorSetting(const WebString& key,
1822 const WebString& value) {
1823 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1824 key.utf8(),
1825 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261826}
1827
[email protected]79dbc662009-09-04 05:42:511828// WebKit::WebWidgetClient ----------------------------------------------------
1829
[email protected]ea42e7782010-08-23 23:58:121830void RenderView::didFocus() {
1831 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1832 // we won't have to test for user gesture anymore and we can
1833 // move that code back to render_widget.cc
1834 if (webview() && webview()->mainFrame() &&
1835 webview()->mainFrame()->isProcessingUserGesture()) {
1836 Send(new ViewHostMsg_Focus(routing_id_));
1837 }
1838}
1839
1840void RenderView::didBlur() {
1841 // TODO(jcivelli): see TODO above in didFocus().
1842 if (webview() && webview()->mainFrame() &&
1843 webview()->mainFrame()->isProcessingUserGesture()) {
1844 Send(new ViewHostMsg_Blur(routing_id_));
1845 }
1846}
1847
initial.commit09911bf2008-07-26 23:55:291848// We are supposed to get a single call to Show for a newly created RenderView
1849// that was created via RenderView::CreateWebView. So, we wait until this
1850// point to dispatch the ShowView message.
1851//
1852// This method provides us with the information about how to display the newly
1853// created RenderView (i.e., as a constrained popup or as a new tab).
1854//
[email protected]4873c7d2009-07-16 06:36:281855void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291856 DCHECK(!did_show_) << "received extraneous Show call";
1857 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1858
1859 if (did_show_)
1860 return;
1861 did_show_ = true;
1862
[email protected]6779aa12011-03-29 17:32:241863 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041864 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041865
[email protected]28295ec2009-10-16 05:34:331866 // Force new windows to a popup if they were not opened with a user gesture.
1867 if (!opened_by_user_gesture_) {
1868 // We exempt background tabs for compat with older versions of Chrome.
1869 // TODO(darin): This seems bogus. These should have a user gesture, so
1870 // we probably don't need this check.
1871 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1872 policy = WebKit::WebNavigationPolicyNewPopup;
1873 }
1874
initial.commit09911bf2008-07-26 23:55:291875 // NOTE: initial_pos_ may still have its default values at this point, but
1876 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1877 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281878 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1879 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291880 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241881 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291882}
1883
[email protected]4873c7d2009-07-16 06:36:281884void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291885 DCHECK(did_show_) << "should already have shown the view";
1886
[email protected]c1f50aa2010-02-18 03:46:571887 // We must keep WebKit's shared timer running in this case in order to allow
1888 // showModalDialog to function properly.
1889 //
1890 // TODO(darin): WebKit should really be smarter about suppressing events and
1891 // timers so that we do not need to manage the shared timer in such a heavy
1892 // handed manner.
1893 //
1894 if (RenderThread::current()) // Will be NULL during unit tests.
1895 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
1896
[email protected]12636df2009-09-28 22:32:211897 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291898}
1899
[email protected]3d9689372009-09-10 04:29:171900// WebKit::WebFrameClient -----------------------------------------------------
1901
[email protected]00152e92010-07-19 11:47:401902WebPlugin* RenderView::createPlugin(WebFrame* frame,
1903 const WebPluginParams& params) {
[email protected]e7c21b812011-03-19 18:03:301904 return content::GetContentClient()->renderer()->CreatePlugin(
[email protected]21d61e52011-03-18 19:08:251905 this, frame, params);
[email protected]3d9689372009-09-10 04:29:171906}
1907
1908WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561909 WebApplicationCacheHostImpl* appcache_host =
1910 WebApplicationCacheHostImpl::FromFrame(frame);
1911 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
1912 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
1913 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171914}
1915
[email protected]9c00f002009-11-05 22:37:421916WebSharedWorker* RenderView::createSharedWorker(
1917 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371918 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421919
[email protected]30447b62009-11-13 01:13:371920 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511921 bool exists = false;
[email protected]30447b62009-11-13 01:13:371922 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511923 ViewHostMsg_CreateWorker_Params params;
1924 params.url = url;
1925 params.is_shared = true;
1926 params.name = name;
1927 params.document_id = document_id;
1928 params.render_view_route_id = routing_id_;
1929 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231930 params.parent_appcache_host_id = 0;
1931 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371932 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511933 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371934 if (url_mismatch) {
1935 return NULL;
1936 } else {
1937 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:491938 document_id,
[email protected]6de0bcf2010-02-17 22:00:511939 exists,
[email protected]30447b62009-11-13 01:13:371940 route_id,
1941 routing_id_);
1942 }
[email protected]9c00f002009-11-05 22:37:421943}
1944
[email protected]3d9689372009-09-10 04:29:171945WebMediaPlayer* RenderView::createMediaPlayer(
1946 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441947 FOR_EACH_OBSERVER(
1948 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171949
[email protected]f78d1dfc2011-01-15 07:09:271950 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1951 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491952 scoped_ptr<media::FilterCollection> collection(
1953 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371954
[email protected]3d9689372009-09-10 04:29:171955 // Add in any custom filter factories first.
1956 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1957 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1958 // Add the chrome specific audio renderer.
[email protected]f7eb0a392011-07-12 10:19:511959 collection->AddAudioRenderer(new AudioRendererImpl());
[email protected]3d9689372009-09-10 04:29:171960 }
1961
[email protected]457d8342010-10-23 01:20:371962 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:311963 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
1964 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
1965 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:491966 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:311967 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:111968
[email protected]a8e24d522010-12-01 07:13:581969 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:271970 new webkit_glue::WebMediaPlayerImpl(client,
1971 collection.release(),
[email protected]ab2c4732011-07-20 19:57:401972 message_loop_factory.release(),
[email protected]090f7312011-08-05 23:26:401973 media_stream_impl_.get(),
1974 new RenderMediaLog()));
[email protected]79684282010-12-06 21:15:461975 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:581976 cmd_line->HasSwitch(switches::kSimpleDataSource),
1977 video_renderer)) {
1978 return NULL;
1979 }
1980 return result.release();
[email protected]3d9689372009-09-10 04:29:171981}
1982
[email protected]035545f2010-04-09 13:10:211983WebApplicationCacheHost* RenderView::createApplicationCacheHost(
1984 WebFrame* frame, WebApplicationCacheHostClient* client) {
1985 return new RendererWebApplicationCacheHostImpl(
1986 FromWebView(frame->view()), client,
1987 RenderThread::current()->appcache_dispatcher()->backend_proxy());
1988}
1989
[email protected]8ff181072010-11-29 17:09:381990WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
1991 return &cookie_jar_;
1992}
1993
[email protected]5041f982010-08-11 21:40:451994void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511995 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451996}
1997
[email protected]3d9689372009-09-10 04:29:171998void RenderView::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511999 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172000}
2001
2002void RenderView::loadURLExternally(
2003 WebFrame* frame, const WebURLRequest& request,
2004 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:342005 loadURLExternally(frame, request, policy, WebString());
2006}
2007
2008void RenderView::loadURLExternally(
2009 WebFrame* frame, const WebURLRequest& request,
2010 WebNavigationPolicy policy,
2011 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:592012 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2013 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:342014 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
2015 suggested_name));
[email protected]efce17b2009-09-11 18:04:592016 } else {
2017 OpenURL(request.url(), referrer, policy);
2018 }
[email protected]3d9689372009-09-10 04:29:172019}
2020
2021WebNavigationPolicy RenderView::decidePolicyForNavigation(
2022 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222023 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:152024 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
2025 if (is_swapped_out_) {
2026 DCHECK(request.url() == GURL("about:swappedout"));
2027 return default_policy;
2028 }
2029
[email protected]3d9689372009-09-10 04:29:172030 // Webkit is asking whether to navigate to a new URL.
2031 // This is fine normally, except if we're showing UI from one security
2032 // context and they're trying to navigate to a different context.
2033 const GURL& url = request.url();
2034
[email protected]d19ea342011-04-20 20:31:132035 // A content initiated navigation may have originated from a link-click,
2036 // script, drag-n-drop operation, etc.
2037 bool is_content_initiated =
2038 NavigationState::FromDataSource(frame->provisionalDataSource())->
2039 is_content_initiated();
2040
[email protected]3d9689372009-09-10 04:29:172041 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302042 // navigations.
[email protected]d19ea342011-04-20 20:31:132043 if (is_content_initiated &&
2044 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:452045 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192046 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232047 // Reset these counters as the RenderView could be reused for the next
2048 // navigation.
2049 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232050 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192051 OpenURL(url, referrer, default_policy);
2052 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172053 }
2054
[email protected]b6cb3a842011-06-24 18:28:412055 GURL old_url(frame->document().url());
[email protected]3d9689372009-09-10 04:29:172056
[email protected]6101c342010-12-16 22:44:372057 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552058 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572059 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372060 // opening a new window). But we sometimes navigate to about:blank to clear a
2061 // tab, and we want to still allow that.
2062 //
[email protected]8f4da8c2011-02-09 19:49:572063 // Note: we do this only for GET requests because our mechanism for switching
2064 // processes only issues GET requests. In particular, POST requests don't
2065 // work, because this mechanism does not preserve form POST data. If it
2066 // becomes necessary to support process switching for POST requests, we will
2067 // need to send the request's httpBody data up to the browser process, and
2068 // issue a special POST navigation in WebKit (via
2069 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2070 // for examples of how to send the httpBody data.
2071 // Note2: We normally don't do this for browser-initiated navigations, since
2072 // it's pointless to tell the browser about navigations it gave us. But
2073 // we do potentially ask the browser to handle a redirect that was originally
2074 // initiated by the browser. See http://crbug.com/70943
2075 //
2076 // TODO(creis): Move this redirect check to the browser process to avoid
2077 // ping-ponging. See http://crbug.com/72380.
2078 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372079 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2080 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2081 bool send_referrer = false;
2082 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552083 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172084 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372085 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112086
[email protected]e48869a2011-04-01 19:56:032087 if (!should_fork) {
2088 // Give the embedder a chance.
2089 should_fork = content::GetContentClient()->renderer()->ShouldFork(
2090 frame, url, is_content_initiated, &send_referrer);
[email protected]6101c342010-12-16 22:44:372091 }
2092
2093 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112094 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372095 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112096 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2097 }
[email protected]3d9689372009-09-10 04:29:172098 }
2099
2100 // Detect when a page is "forking" a new tab that can be safely rendered in
2101 // its own process. This is done by sites like Gmail that try to open links
2102 // in new windows without script connections back to the original page. We
2103 // treat such cases as browser navigations (in which we will create a new
2104 // renderer for a cross-site navigation), rather than WebKit navigations.
2105 //
2106 // We use the following heuristic to decide whether to fork a new page in its
2107 // own process:
2108 // The parent page must open a new tab to about:blank, set the new tab's
2109 // window.opener to null, and then redirect the tab to a cross-site URL using
2110 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462111 //
2112 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2113 // (see below).
[email protected]3d9689372009-09-10 04:29:172114 bool is_fork =
2115 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582116 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172117 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522118 historyBackListCount() < 1 &&
2119 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172120 // The parent page must have set the child's window.opener to null before
2121 // redirecting to the desired URL.
2122 frame->opener() == NULL &&
2123 // Must be a top-level frame.
2124 frame->parent() == NULL &&
2125 // Must not have issued the request from this page.
2126 is_content_initiated &&
2127 // Must be targeted at the current tab.
2128 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2129 // Must be a JavaScript navigation, which appears as "other".
2130 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462131
2132 // Recognize if this navigation is from a link with rel=noreferrer and
2133 // target=_blank attributes, in which case the opener will be suppressed. If
2134 // so, it is safe to load cross-site pages in a separate process, so we
2135 // should let the browser handle it.
2136 bool is_noreferrer_and_blank_target =
2137 // Frame should be top level and not yet navigated.
2138 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412139 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462140 historyBackListCount() < 1 &&
2141 historyForwardListCount() < 1 &&
2142 // Links with rel=noreferrer will have no Referer field, and their
2143 // resulting frame will have its window.opener suppressed.
2144 // TODO(creis): should add a request.httpReferrer() method to help avoid
2145 // typos on the unusual spelling of Referer.
2146 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2147 opener_suppressed_ &&
2148 frame->opener() == NULL &&
2149 // Links with target=_blank will have no name.
2150 frame->name().isNull() &&
2151 // Another frame (with a non-empty creator) should have initiated the
2152 // request, targeted at this frame.
2153 !creator_url_.is_empty() &&
2154 is_content_initiated &&
2155 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2156 type == WebKit::WebNavigationTypeOther;
2157
2158 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172159 // Open the URL via the browser, not via WebKit.
2160 OpenURL(url, GURL(), default_policy);
2161 return WebKit::WebNavigationPolicyIgnore;
2162 }
2163
2164 return default_policy;
2165}
2166
[email protected]6069da8c2009-10-20 20:33:492167bool RenderView::canHandleRequest(
2168 WebFrame* frame, const WebURLRequest& request) {
2169 // We allow WebKit to think that everything can be handled even though
2170 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342171 return true;
2172}
2173
[email protected]6069da8c2009-10-20 20:33:492174WebURLError RenderView::cannotHandleRequestError(
2175 WebFrame* frame, const WebURLRequest& request) {
2176 NOTREACHED(); // Since we said we can handle all requests.
2177 return WebURLError();
2178}
2179
2180WebURLError RenderView::cancelledError(
2181 WebFrame* frame, const WebURLRequest& request) {
2182 WebURLError error;
2183 error.domain = WebString::fromUTF8(net::kErrorDomain);
2184 error.reason = net::ERR_ABORTED;
2185 error.unreachableURL = request.url();
2186 return error;
[email protected]7b7a7dc2009-10-19 02:23:342187}
2188
2189void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492190 WebFrame*, const WebURLError&) {
2191 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342192}
2193
[email protected]90eeddb2010-05-06 21:06:432194void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2195 const WebKit::WebFormElement& form) {
2196 // Some login forms have onSubmit handlers that put a hash of the password
2197 // into a hidden field and then clear the password. (Issue 28910.)
2198 // This method gets called before any of those handlers run, so save away
2199 // a copy of the password in case it gets lost.
2200 NavigationState* navigation_state =
2201 NavigationState::FromDataSource(frame->dataSource());
2202 navigation_state->set_password_form_data(
2203 PasswordFormDomManager::CreatePasswordForm(form));
2204}
2205
[email protected]979c28b2009-11-07 01:30:482206void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172207 NavigationState* navigation_state =
2208 NavigationState::FromDataSource(frame->provisionalDataSource());
2209
2210 if (navigation_state->transition_type() == PageTransition::LINK)
2211 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2212
2213 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352214 WebSearchableFormData web_searchable_form_data(form);
2215 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2216 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212217 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432218 PasswordForm* password_form_data =
2219 PasswordFormDomManager::CreatePasswordForm(form);
2220 navigation_state->set_password_form_data(password_form_data);
2221
[email protected]098c95cb2011-04-28 16:49:012222 // In order to save the password that the user actually typed and not one
2223 // that may have gotten transformed by the site prior to submit, recover it
2224 // from the form contents already stored by |willSendSubmitEvent| into the
2225 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2226 // which is what we're storing into now.)
2227 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432228 NavigationState* old_navigation_state =
2229 NavigationState::FromDataSource(frame->dataSource());
2230 if (old_navigation_state) {
2231 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2232 if (old_form_data && old_form_data->action == password_form_data->action)
2233 password_form_data->password_value = old_form_data->password_value;
2234 }
2235 }
[email protected]3d9689372009-09-10 04:29:172236
[email protected]2a5b1732011-04-01 23:55:552237 FOR_EACH_OBSERVER(
2238 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172239}
2240
2241void RenderView::willPerformClientRedirect(
2242 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2243 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382244 FOR_EACH_OBSERVER(
2245 RenderViewObserver, observers_,
2246 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172247}
2248
2249void RenderView::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382250 FOR_EACH_OBSERVER(
2251 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172252}
2253
2254void RenderView::didCompleteClientRedirect(
2255 WebFrame* frame, const WebURL& from) {
2256 if (!frame->parent())
2257 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382258 FOR_EACH_OBSERVER(
2259 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172260}
2261
2262void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2263 // The rest of RenderView assumes that a WebDataSource will always have a
2264 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482265 bool content_initiated = !pending_navigation_state_.get();
2266 NavigationState* state = content_initiated ?
2267 NavigationState::CreateContentInitiated() :
2268 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512269
[email protected]8a3125a712010-08-09 18:58:512270 // NavigationState::referred_by_prefetcher_ is true if we are
2271 // navigating from a page that used prefetching using a link on that
2272 // page. We are early enough in the request process here that we
2273 // can still see the NavigationState of the previous page and set
2274 // this value appropriately.
2275 // TODO(gavinp): catch the important case of navigation in a new
2276 // renderer process.
2277 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302278 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522279 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512280 const GURL referrer(
2281 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2282 if (!referrer.is_empty() &&
2283 NavigationState::FromDataSource(
2284 old_frame->dataSource())->was_prefetcher()) {
2285 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2286 WebDataSource* old_frame_ds = old_frame->dataSource();
2287 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2288 state->set_was_referred_by_prefetcher(true);
2289 break;
2290 }
2291 }
2292 }
2293 }
2294 }
2295
[email protected]4c1b6f0b2010-02-07 16:38:182296 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522297 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512298 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182299 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2300 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2301 break;
2302 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2303 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2304 break;
2305 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2306 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2307 break;
2308 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2309 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2310 break;
2311 }
2312 }
[email protected]fa7b6b542009-11-03 05:02:302313
[email protected]16e923d2011-04-30 00:41:442314 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502315
[email protected]946a0032011-03-31 18:42:282316 FOR_EACH_OBSERVER(
2317 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172318}
2319
2320void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2321 WebDataSource* ds = frame->provisionalDataSource();
2322 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2323
[email protected]3d9689372009-09-10 04:29:172324 // Update the request time if WebKit has better knowledge of it.
2325 if (navigation_state->request_time().is_null()) {
2326 double event_time = ds->triggeringEventTime();
2327 if (event_time != 0.0)
2328 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2329 }
2330
[email protected]05c8e502010-08-15 15:13:522331 // Start time is only set after request time.
2332 navigation_state->set_start_load_time(Time::Now());
2333
[email protected]3d9689372009-09-10 04:29:172334 bool is_top_most = !frame->parent();
2335 if (is_top_most) {
2336 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132337 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172338
2339 // Make sure redirect tracking state is clear for the new load.
2340 completed_client_redirect_src_ = GURL();
2341 } else if (frame->parent()->isLoading()) {
2342 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002343 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172344 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2345 }
2346
[email protected]28685da92011-02-07 21:49:172347 FOR_EACH_OBSERVER(
2348 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2349
[email protected]eacb080b2011-05-22 19:40:262350 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]3d9689372009-09-10 04:29:172351 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]eacb080b2011-05-22 19:40:262352 routing_id_, frame->identifier(), is_top_most, has_opener_set,
2353 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172354}
2355
2356void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2357 if (frame->parent())
2358 return;
2359 // Received a redirect on the main frame.
2360 WebDataSource* data_source = frame->provisionalDataSource();
2361 if (!data_source) {
2362 // Should only be invoked when we have a data source.
2363 NOTREACHED();
2364 return;
2365 }
2366 std::vector<GURL> redirects;
2367 GetRedirectChain(data_source, &redirects);
2368 if (redirects.size() >= 2) {
[email protected]eacb080b2011-05-22 19:40:262369 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]40bd6582009-12-04 23:49:512370 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]eacb080b2011-05-22 19:40:262371 has_opener_set, redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172372 }
2373}
2374
[email protected]40bd6582009-12-04 23:49:512375void RenderView::didFailProvisionalLoad(WebFrame* frame,
2376 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172377 // Notify the browser that we failed a provisional load with an error.
2378 //
2379 // Note: It is important this notification occur before DidStopLoading so the
2380 // SSL manager can react to the provisional load failure before being
2381 // notified the load stopped.
2382 //
2383 WebDataSource* ds = frame->provisionalDataSource();
2384 DCHECK(ds);
2385
2386 const WebURLRequest& failed_request = ds->request();
2387
[email protected]28685da92011-02-07 21:49:172388 FOR_EACH_OBSERVER(
2389 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2390
[email protected]3d9689372009-09-10 04:29:172391 bool show_repost_interstitial =
2392 (error.reason == net::ERR_CACHE_MISS &&
2393 EqualsASCII(failed_request.httpMethod(), "POST"));
2394 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072395 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2396 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172397
2398 // Don't display an error page if this is simply a cancelled load. Aside
2399 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2400 if (error.reason == net::ERR_ABORTED)
2401 return;
2402
2403 // Make sure we never show errors in view source mode.
2404 frame->enableViewSourceMode(false);
2405
2406 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2407
2408 // If this is a failed back/forward/reload navigation, then we need to do a
2409 // 'replace' load. This is necessary to avoid messing up session history.
2410 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2411 // as session history is concerned.
2412 //
2413 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2414 // the page id.
2415 //
2416 bool replace =
2417 navigation_state->pending_page_id() != -1 ||
2418 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2419
2420 // If we failed on a browser initiated request, then make sure that our error
2421 // page load is regarded as the same browser initiated request.
2422 if (!navigation_state->is_content_initiated()) {
2423 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2424 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002425 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172426 navigation_state->transition_type(),
2427 navigation_state->request_time()));
2428 }
2429
[email protected]c5c1d6d2011-07-28 18:42:412430 // Do not show alternate error page when DevTools is attached.
2431 if (devtools_agent_->IsAttached())
2432 return;
2433
[email protected]3d9689372009-09-10 04:29:172434 // Provide the user with a more helpful error page?
2435 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2436 return;
2437
2438 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082439 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172440}
2441
2442void RenderView::didReceiveDocumentData(
2443 WebFrame* frame, const char* data, size_t data_len,
2444 bool& prevent_default) {
2445 NavigationState* navigation_state =
2446 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092447 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172448}
2449
[email protected]40bd6582009-12-04 23:49:512450void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2451 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172452 NavigationState* navigation_state =
2453 NavigationState::FromDataSource(frame->dataSource());
2454
2455 navigation_state->set_commit_load_time(Time::Now());
2456 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202457 // When we perform a new navigation, we need to update the last committed
2458 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172459 UpdateSessionHistory(frame);
2460
2461 // We bump our Page ID to correspond with the new session history entry.
2462 page_id_ = next_page_id_++;
2463
[email protected]3cc72b12010-03-18 23:03:002464 // Advance our offset in session history, applying the length limit. There
2465 // is now no forward history.
2466 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102467 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2468 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002469 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032470 history_page_ids_.resize(history_list_length_, -1);
2471 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172472 } else {
2473 // Inspect the navigation_state on this frame to see if the navigation
2474 // corresponds to a session history navigation... Note: |frame| may or
2475 // may not be the toplevel frame, but for the case of capturing session
2476 // history, the first committed frame suffices. We keep track of whether
2477 // we've seen this commit before so that only capture session history once
2478 // per navigation.
2479 //
2480 // Note that we need to check if the page ID changed. In the case of a
2481 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2482 // previous URL and the current page ID, which would be wrong.
2483 if (navigation_state->pending_page_id() != -1 &&
2484 navigation_state->pending_page_id() != page_id_ &&
2485 !navigation_state->request_committed()) {
2486 // This is a successful session history navigation!
2487 UpdateSessionHistory(frame);
2488 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002489
2490 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032491
2492 // If the history list is valid, our list of page IDs should be correct.
2493 DCHECK(history_list_length_ <= 0 ||
2494 history_list_offset_ < 0 ||
2495 history_list_offset_ >= history_list_length_ ||
2496 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172497 }
2498 }
2499
[email protected]28685da92011-02-07 21:49:172500 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2501 DidCommitProvisionalLoad(frame, is_new_navigation));
2502
[email protected]3d9689372009-09-10 04:29:172503 // Remember that we've already processed this request, so we don't update
2504 // the session history again. We do this regardless of whether this is
2505 // a session history navigation, because if we attempted a session history
2506 // navigation without valid HistoryItem state, WebCore will think it is a
2507 // new navigation.
2508 navigation_state->set_request_committed(true);
2509
2510 UpdateURL(frame);
2511
2512 // If this committed load was initiated by a client redirect, we're
2513 // at the last stop now, so clear it.
2514 completed_client_redirect_src_ = GURL();
2515
2516 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272517 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172518}
2519
2520void RenderView::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102521 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2522 DidClearWindowObject(frame));
2523
[email protected]b6cb3a842011-06-24 18:28:412524 GURL frame_url = frame->document().url();
[email protected]c09163a2011-02-15 00:05:552525 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:252526 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2527 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272528 GetWebUIBindings()->set_message_sender(this);
2529 GetWebUIBindings()->set_routing_id(routing_id_);
2530 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172531 }
[email protected]3d9689372009-09-10 04:29:172532}
2533
2534void RenderView::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172535 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412536 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252537 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272538 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172539 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2540 }
[email protected]e48869a2011-04-01 19:56:032541
2542 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2543 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172544}
2545
[email protected]a3bc4d12011-04-20 17:22:212546void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title,
2547 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462548 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172549
2550 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272551 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172552}
2553
[email protected]42054a252011-05-17 18:02:132554void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
2555 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2556 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582557}
2558
[email protected]3d9689372009-09-10 04:29:172559void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2560 WebDataSource* ds = frame->dataSource();
2561 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2562 DCHECK(navigation_state);
2563 navigation_state->set_finish_document_load_time(Time::Now());
2564
[email protected]622474d2010-11-04 09:21:082565 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172566
[email protected]28685da92011-02-07 21:49:172567 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2568 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172569
2570 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272571 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172572}
2573
2574void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082575 if (webview()->mainFrame() == frame) {
2576 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2577 page_id_));
2578 }
[email protected]3d9689372009-09-10 04:29:172579}
2580
2581void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172582 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172583}
2584
2585void RenderView::didFinishLoad(WebFrame* frame) {
2586 WebDataSource* ds = frame->dataSource();
2587 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2588 DCHECK(navigation_state);
2589 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412590
[email protected]676126f72011-01-15 00:03:512591 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172592
2593 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172594}
2595
[email protected]ccbe04e2010-03-17 17:58:432596void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172597 WebFrame* frame, bool is_new_navigation) {
2598 // If this was a reference fragment navigation that we initiated, then we
2599 // could end up having a non-null pending navigation state. We just need to
2600 // update the ExtraData on the datasource so that others who read the
2601 // ExtraData will get the new NavigationState. Similarly, if we did not
2602 // initiate this navigation, then we need to take care to reset any pre-
2603 // existing navigation state to a content-initiated navigation state.
2604 // DidCreateDataSource conveniently takes care of this for us.
2605 didCreateDataSource(frame, frame->dataSource());
2606
[email protected]af15bed2010-08-25 21:12:092607 NavigationState* new_state =
2608 NavigationState::FromDataSource(frame->dataSource());
2609 new_state->set_was_within_same_page(true);
2610
[email protected]3d9689372009-09-10 04:29:172611 didCommitProvisionalLoad(frame, is_new_navigation);
2612
[email protected]750fcf872011-08-03 23:10:472613 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2614 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172615}
2616
[email protected]476b6f82009-09-10 21:00:592617void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312618 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592619}
2620
[email protected]3d9689372009-09-10 04:29:172621void RenderView::assignIdentifierToRequest(
2622 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2623 // Ignore
2624}
2625
2626void RenderView::willSendRequest(
2627 WebFrame* frame, unsigned identifier, WebURLRequest& request,
2628 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302629 WebFrame* top_frame = frame->top();
2630 if (!top_frame)
2631 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512632 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2633 WebDataSource* top_data_source = top_frame->dataSource();
2634 WebDataSource* data_source =
2635 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222636
[email protected]418da612011-07-21 19:01:522637 bool is_top_frame = (frame == top_frame);
2638 request.setExtraData(
2639 new RequestExtraData(is_top_frame, frame->identifier()));
[email protected]e48869a2011-04-01 19:56:032640
[email protected]78d5cfe2011-02-04 08:43:222641 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032642 GURL new_url;
2643 if (content::GetContentClient()->renderer()->WillSendRequest(
2644 frame, request_url, &new_url)) {
2645 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222646 }
2647
[email protected]5e369672009-11-03 23:48:302648 if (data_source) {
2649 NavigationState* state = NavigationState::FromDataSource(data_source);
2650 if (state && state->is_cache_policy_override_set())
2651 request.setCachePolicy(state->cache_policy_override());
2652 }
[email protected]8a3125a712010-08-09 18:58:512653
2654 if (top_data_source) {
2655 NavigationState* state = NavigationState::FromDataSource(top_data_source);
[email protected]61a99dd82011-05-24 19:19:472656 // TODO(gavinp): separate out prefetching and prerender field trials
2657 // if the rel=prerender rel type is sticking around.
2658 if (state && (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2659 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]8a3125a712010-08-09 18:58:512660 state->set_was_prefetcher(true);
2661 }
2662
[email protected]3d9689372009-09-10 04:29:172663 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132664 request.setHasUserGesture(frame->isProcessingUserGesture());
2665
[email protected]0a8db0d2011-04-13 15:15:402666 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132667 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172668}
2669
2670void RenderView::didReceiveResponse(
2671 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492672
[email protected]3d9689372009-09-10 04:29:172673 // Only do this for responses that correspond to a provisional data source
2674 // of the top-most frame. If we have a provisional data source, then we
2675 // can't have any sub-resources yet, so we know that this response must
2676 // correspond to a frame load.
2677 if (!frame->provisionalDataSource() || frame->parent())
2678 return;
2679
2680 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082681 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172682 if (frame->isViewSourceModeEnabled())
2683 return;
2684
[email protected]65041fa2010-05-21 06:56:532685 NavigationState* navigation_state =
2686 NavigationState::FromDataSource(frame->provisionalDataSource());
2687 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082688 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532689
[email protected]972ebdff2010-06-10 22:59:072690 // Record page load flags.
2691 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2692 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572693 navigation_state->set_was_alternate_protocol_available(
2694 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072695 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082696 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092697 // Whether or not the http status code actually corresponds to an error is
2698 // only checked when the page is done loading, if |use_error_page| is
2699 // still true.
2700 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172701}
2702
2703void RenderView::didFinishResourceLoad(
2704 WebFrame* frame, unsigned identifier) {
2705 NavigationState* navigation_state =
2706 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092707 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172708 return;
2709
[email protected]06333afe2011-02-24 14:55:092710 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082711 int http_status_code = navigation_state->http_status_code();
2712 if (http_status_code == 404) {
2713 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412714 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172715
[email protected]b6cb3a842011-06-24 18:28:412716 const GURL& error_page_url =
2717 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092718 if (error_page_url.is_valid()) {
2719 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472720 original_error.domain = "http";
2721 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412722 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172723
[email protected]06333afe2011-02-24 14:55:092724 navigation_state->set_alt_error_page_fetcher(
2725 new AltErrorPageResourceFetcher(
2726 error_page_url, frame, original_error,
2727 NewCallback(this, &RenderView::AltErrorPageFinished)));
2728 return;
2729 }
2730 }
[email protected]3d9689372009-09-10 04:29:172731
[email protected]9966325b2011-04-18 05:00:102732 content::GetContentClient()->renderer()->ShowErrorPage(
2733 this, frame, http_status_code);
[email protected]3d9689372009-09-10 04:29:172734}
2735
2736void RenderView::didFailResourceLoad(
2737 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2738 // Ignore
2739}
2740
2741void RenderView::didLoadResourceFromMemoryCache(
2742 WebFrame* frame, const WebURLRequest& request,
2743 const WebURLResponse& response) {
2744 // Let the browser know we loaded a resource from the memory cache. This
2745 // message is needed to display the correct SSL indicators.
2746 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2747 routing_id_,
2748 request.url(),
[email protected]70435962011-08-02 20:13:282749 response.securityInfo(),
2750 request.httpMethod().utf8(),
2751 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172752}
2753
[email protected]6069da8c2009-10-20 20:33:492754void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292755 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2756}
2757
[email protected]92771112011-01-20 00:13:022758void RenderView::didRunInsecureContent(
2759 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292760 Send(new ViewHostMsg_DidRunInsecureContent(
2761 routing_id_,
[email protected]92771112011-01-20 00:13:022762 origin.toString().utf8(),
2763 target));
[email protected]e3d60e5d2009-09-25 21:08:292764}
2765
[email protected]3d9689372009-09-10 04:29:172766void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2767 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2768}
2769
[email protected]0c882b282009-10-07 17:01:282770void RenderView::didCreateScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032771 content::GetContentClient()->renderer()->DidCreateScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282772}
2773
2774void RenderView::didDestroyScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032775 content::GetContentClient()->renderer()->DidDestroyScriptContext(frame);
[email protected]0c882b282009-10-07 17:01:282776}
2777
2778void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
[email protected]e48869a2011-04-01 19:56:032779 content::GetContentClient()->renderer()->DidCreateIsolatedScriptContext(
2780 frame);
[email protected]0c882b282009-10-07 17:01:282781}
2782
[email protected]fc86daa2010-03-30 23:52:532783void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
2784 WebFrame* target,
2785 bool cross_origin,
2786 const WebString& property_name,
2787 unsigned long long event_id) {
[email protected]6cf19311f2011-04-14 23:06:022788 FOR_EACH_OBSERVER(
2789 RenderViewObserver,
2790 observers_,
2791 LogCrossFramePropertyAccess(
2792 frame, target, cross_origin, property_name, event_id));
[email protected]ab9eabac2010-03-16 16:54:102793}
2794
[email protected]d812fd12011-05-27 23:05:072795void RenderView::didUpdateLayout(WebFrame* frame) {
2796 // We don't always want to set up a timer, only if we've been put in that
2797 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172798 // message.
[email protected]705243f2010-05-05 19:58:072799 if (!send_preferred_size_changes_ || !webview())
2800 return;
[email protected]dfca5acf2010-03-22 03:28:432801
[email protected]d812fd12011-05-27 23:05:072802 if (check_preferred_size_timer_.IsRunning())
2803 return;
2804 check_preferred_size_timer_.Start(TimeDelta::FromMilliseconds(0), this,
2805 &RenderView::CheckPreferredSize);
2806}
2807
2808void RenderView::CheckPreferredSize() {
2809 // We don't always want to send the change messages over IPC, only if we've
2810 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2811 // message.
2812 if (!send_preferred_size_changes_ || !webview())
2813 return;
2814
[email protected]705243f2010-05-05 19:58:072815 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2816 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532817
2818 // In the presence of zoom, these sizes are still reported as if unzoomed,
2819 // so we need to adjust.
2820 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2821 size.set_width(static_cast<int>(size.width() * zoom_factor));
2822 size.set_height(static_cast<int>(size.height() * zoom_factor));
2823
[email protected]705243f2010-05-05 19:58:072824 if (size == preferred_size_)
2825 return;
[email protected]c27324b2009-11-19 22:44:292826
[email protected]705243f2010-05-05 19:58:072827 preferred_size_ = size;
2828 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2829 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172830}
2831
[email protected]143dcd592009-11-06 21:33:492832void RenderView::didChangeScrollOffset(WebFrame* frame) {
2833 StartNavStateSyncTimerIfNecessary();
2834}
2835
[email protected]8922e1f2009-10-03 05:01:262836void RenderView::reportFindInPageMatchCount(int request_id, int count,
2837 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112838 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2839 if (!count)
2840 active_match_ordinal = 0;
2841
2842 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2843 routing_id_,
2844 request_id,
2845 count,
2846 gfx::Rect(),
2847 active_match_ordinal,
2848 final_update);
2849
[email protected]8922e1f2009-10-03 05:01:262850 // If we have a message that has been queued up, then we should just replace
2851 // it. The ACK from the browser will make sure it gets sent when the browser
2852 // wants it.
2853 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262854 queued_find_reply_message_.reset(msg);
2855 } else {
2856 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112857 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262858 }
2859}
2860
2861void RenderView::reportFindInPageSelection(int request_id,
2862 int active_match_ordinal,
2863 const WebRect& selection_rect) {
2864 // Send the search result over to the browser process.
2865 Send(new ViewHostMsg_Find_Reply(routing_id_,
2866 request_id,
2867 -1,
2868 selection_rect,
2869 active_match_ordinal,
2870 false));
2871}
2872
[email protected]2b06a992010-08-21 05:48:222873void RenderView::openFileSystem(
2874 WebFrame* frame,
2875 WebFileSystem::Type type,
2876 long long size,
[email protected]d275d7a2010-11-03 01:34:492877 bool create,
[email protected]2b06a992010-08-21 05:48:222878 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082879 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222880
[email protected]b6cb3a842011-06-24 18:28:412881 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082882 if (origin.isEmpty()) {
2883 // Uninitialized document?
2884 callbacks->didFail(WebKit::WebFileErrorAbort);
2885 return;
2886 }
[email protected]2b06a992010-08-21 05:48:222887
[email protected]c5a272d2010-09-27 18:37:082888 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2889 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492890 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222891}
2892
[email protected]10e5cf12011-04-13 04:10:402893void RenderView::queryStorageUsageAndQuota(
2894 WebFrame* frame,
2895 WebStorageQuotaType type,
2896 WebStorageQuotaCallbacks* callbacks) {
2897 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412898 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402899 if (origin.isEmpty()) {
2900 // Uninitialized document?
2901 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2902 return;
2903 }
2904 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:532905 GURL(origin.toString()),
2906 static_cast<quota::StorageType>(type),
2907 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402908}
2909
2910void RenderView::requestStorageQuota(
2911 WebFrame* frame,
2912 WebStorageQuotaType type,
2913 unsigned long long requested_size,
2914 WebStorageQuotaCallbacks* callbacks) {
2915 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412916 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402917 if (origin.isEmpty()) {
2918 // Uninitialized document?
2919 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2920 return;
2921 }
2922 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:532923 routing_id(), GURL(origin.toString()),
2924 static_cast<quota::StorageType>(type), requested_size,
2925 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402926}
2927
[email protected]18d5be92011-07-25 18:00:192928// WebKit::WebPageSerializerClient implementation ------------------------------
2929
2930void RenderView::didSerializeDataForFrame(
2931 const WebURL& frame_url,
2932 const WebCString& data,
2933 WebPageSerializerClient::PageSerializationStatus status) {
2934 Send(new ViewHostMsg_SendSerializedHtmlData(
2935 routing_id(),
2936 frame_url,
2937 data.data(),
2938 static_cast<int32>(status)));
2939}
2940
[email protected]79dbc662009-09-04 05:42:512941// webkit_glue::WebPluginPageDelegate -----------------------------------------
2942
[email protected]191eb3f72010-12-21 06:27:502943webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:532944 const FilePath& file_path,
2945 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:592946 if (!PluginChannelHost::IsListening())
2947 return NULL;
2948
[email protected]00c39612010-03-06 02:53:282949 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:462950 if (in_process_plugin) {
[email protected]6876dff2010-01-15 19:38:092951#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]e8f7a182011-03-10 00:50:222952 return webkit::npapi::WebPluginDelegateImpl::Create(
2953 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092954#else
[email protected]e8f7a182011-03-10 00:50:222955 NOTIMPLEMENTED();
2956 return NULL;
[email protected]7b6616f2010-01-14 18:07:552957#endif
[email protected]f103ab72009-09-02 17:10:592958 }
2959
[email protected]4e0616e2010-05-28 14:55:532960 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592961}
2962
2963void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032964#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592965 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2966 routing_id(), window));
2967#endif
2968}
2969
2970void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032971#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592972 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2973 routing_id(), window));
2974#endif
2975 CleanupWindowInPluginMoves(window);
2976}
2977
[email protected]191eb3f72010-12-21 06:27:502978void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:592979 SchedulePluginMove(move);
2980}
2981
2982void RenderView::DidStartLoadingForPlugin() {
2983 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522984 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592985}
2986
2987void RenderView::DidStopLoadingForPlugin() {
2988 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522989 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592990}
2991
[email protected]b921cfd22010-02-25 16:57:512992WebCookieJar* RenderView::GetCookieJar() {
2993 return &cookie_jar_;
2994}
2995
initial.commit09911bf2008-07-26 23:55:292996void RenderView::SyncNavigationState() {
2997 if (!webview())
2998 return;
2999
[email protected]26aa0482009-09-30 16:55:273000 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173001 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293002 return;
[email protected]ca948a22009-06-25 19:36:173003
3004 Send(new ViewHostMsg_UpdateState(
3005 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293006}
3007
[email protected]7ccddb8c2009-08-04 17:36:553008GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293009 ErrorPageType error_type) {
[email protected]c5c1d6d2011-07-28 18:42:413010
[email protected]7ccddb8c2009-08-04 17:36:553011 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293012 // If the URL that failed was secure, then the embedding web page was not
3013 // expecting a network attacker to be able to manipulate its contents. As
3014 // we fetch alternate error pages over HTTP, we would be allowing a network
3015 // attacker to manipulate the contents of the response if we tried to use
3016 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153017 return GURL();
initial.commit09911bf2008-07-26 23:55:293018 }
3019
[email protected]c5c1d6d2011-07-28 18:42:413020 if (devtools_agent_->IsAttached()) {
3021 // Do not show alternate error page when DevTools is attached.
3022 return GURL();
3023 }
3024
initial.commit09911bf2008-07-26 23:55:293025 // Grab the base URL from the browser process.
3026 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153027 return GURL();
initial.commit09911bf2008-07-26 23:55:293028
3029 // Strip query params from the failed URL.
3030 GURL::Replacements remove_params;
3031 remove_params.ClearUsername();
3032 remove_params.ClearPassword();
3033 remove_params.ClearQuery();
3034 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553035 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503036 std::string spec_to_send = url_to_send.spec();
3037 // Notify link doctor of the url truncation by sending of "?" at the end.
3038 if (failed_url.has_query())
3039 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293040
3041 // Construct the query params to send to link doctor.
3042 std::string params(alternate_error_page_url_.query());
3043 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:503044 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293045 params.append("&sourceid=chrome");
3046 params.append("&error=");
3047 switch (error_type) {
3048 case DNS_ERROR:
3049 params.append("dnserror");
3050 break;
3051
3052 case HTTP_404:
3053 params.append("http404");
3054 break;
3055
[email protected]5df266ac2008-10-15 19:50:133056 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333057 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133058 break;
3059
initial.commit09911bf2008-07-26 23:55:293060 default:
3061 NOTREACHED() << "unknown ErrorPageType";
3062 }
3063
3064 // OK, build the final url to return.
3065 GURL::Replacements link_doctor_params;
3066 link_doctor_params.SetQueryStr(params);
3067 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3068 return url;
3069}
3070
[email protected]c50008512011-02-03 01:17:273071WebUIBindings* RenderView::GetWebUIBindings() {
3072 if (!web_ui_bindings_.get()) {
3073 web_ui_bindings_.reset(new WebUIBindings());
[email protected]c091c2c2010-09-17 19:05:463074 }
[email protected]c50008512011-02-03 01:17:273075 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463076}
3077
[email protected]0fdbf8c2010-07-08 20:33:013078WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3079 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493080}
3081
[email protected]6069da8c2009-10-20 20:33:493082void RenderView::OnFind(int request_id, const string16& search_text,
3083 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273084 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493085
[email protected]872542532011-06-23 00:43:163086 // Check if the plugin still exists in the document.
3087 if (main_frame->document().isPluginDocument() &&
3088 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493089 if (options.findNext) {
3090 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013091 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493092 } else {
[email protected]afdbd142010-07-10 08:01:233093 if (GetWebPluginFromPluginDocument()->startFind(
3094 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493095 } else {
[email protected]e7c58a32010-08-13 19:47:113096 // Send "no results".
3097 Send(new ViewHostMsg_Find_Reply(routing_id_,
3098 request_id,
3099 0,
3100 gfx::Rect(),
3101 0,
3102 true));
[email protected]24a7f3c2010-03-25 08:26:493103 }
3104 }
3105 return;
3106 }
3107
[email protected]b4bb2502009-10-01 22:35:273108 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273109 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293110 WebFrame* search_frame = focused_frame; // start searching focused frame.
3111
3112 bool multi_frame = (frame_after_main != main_frame);
3113
3114 // If we have multiple frames, we don't want to wrap the search within the
3115 // frame, so we check here if we only have main_frame in the chain.
3116 bool wrap_within_frame = !multi_frame;
3117
[email protected]b3f2b912009-04-09 16:18:523118 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293119 bool result = false;
3120
[email protected]7830da3e2009-11-06 16:27:263121 // If something is selected when we start searching it means we cannot just
3122 // increment the current match ordinal; we need to re-generate it.
3123 WebRange current_selection = focused_frame->selectionRange();
3124
initial.commit09911bf2008-07-26 23:55:293125 do {
[email protected]dd7daa82009-08-10 05:46:453126 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593127 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293128
3129 if (!result) {
3130 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223131 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293132
3133 // Find the next frame, but skip the invisible ones.
3134 do {
3135 // What is the next frame to search? (we might be going backwards). Note
3136 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593137 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273138 search_frame->traverseNext(true) :
3139 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453140 } while (!search_frame->hasVisibleContent() &&
3141 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293142
[email protected]884db412008-11-24 23:46:503143 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223144 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293145
3146 // If we have multiple frames and we have wrapped back around to the
3147 // focused frame, we need to search it once more allowing wrap within
3148 // the frame, otherwise it will report 'no match' if the focused frame has
3149 // reported matches, but no frames after the focused_frame contain a
3150 // match for the search word(s).
3151 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453152 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593153 request_id, search_text, options, true, // Force wrapping.
3154 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293155 }
3156 }
3157
[email protected]26aa0482009-09-30 16:55:273158 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293159 } while (!result && search_frame != focused_frame);
3160
[email protected]7830da3e2009-11-06 16:27:263161 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293162 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453163 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293164 } else {
3165 // If nothing is found, set result to "0 of 0", otherwise, set it to
3166 // "-1 of 1" to indicate that we found at least one item, but we don't know
3167 // yet what is active.
3168 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3169 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293170
[email protected]4f3dc372009-02-24 00:10:293171 // If we find no matches then this will be our last status update.
3172 // Otherwise the scoping effort will send more results.
3173 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293174
[email protected]4f3dc372009-02-24 00:10:293175 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403176 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593177 request_id,
[email protected]4f3dc372009-02-24 00:10:293178 match_count,
3179 selection_rect,
3180 ordinal,
3181 final_status_update));
initial.commit09911bf2008-07-26 23:55:293182
initial.commit09911bf2008-07-26 23:55:293183 // Scoping effort begins, starting with the mainframe.
3184 search_frame = main_frame;
3185
[email protected]dd7daa82009-08-10 05:46:453186 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293187
3188 do {
3189 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453190 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293191
3192 // We don't start another scoping effort unless at least one match has
3193 // been found.
3194 if (result) {
3195 // Start new scoping request. If the scoping function determines that it
3196 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453197 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593198 search_text,
3199 options,
initial.commit09911bf2008-07-26 23:55:293200 true); // reset the tickmarks
3201 }
3202
3203 // Iterate to the next frame. The frame will not necessarily scope, for
3204 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273205 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293206 } while (search_frame != main_frame);
3207 }
3208}
3209
[email protected]24a7f3c2010-03-25 08:26:493210void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3211 WebView* view = webview();
3212 if (!view)
3213 return;
3214
3215 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163216 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013217 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493218 return;
3219 }
3220
3221 bool clear_selection =
3222 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3223 if (clear_selection)
3224 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3225
3226 WebFrame* frame = view->mainFrame();
3227 while (frame) {
3228 frame->stopFinding(clear_selection);
3229 frame = frame->traverseNext(false);
3230 }
3231
3232 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3233 WebFrame* focused_frame = view->focusedFrame();
3234 if (focused_frame) {
3235 WebDocument doc = focused_frame->document();
3236 if (!doc.isNull()) {
3237 WebNode node = doc.focusedNode();
3238 if (!node.isNull())
3239 node.simulateClick();
3240 }
3241 }
3242 }
3243}
3244
3245void RenderView::OnFindReplyAck() {
3246 // Check if there is any queued up request waiting to be sent.
3247 if (queued_find_reply_message_.get()) {
3248 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423249 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493250 }
3251}
3252
[email protected]0bd753682010-12-16 18:15:523253WebPlugin* RenderView::CreatePepperPlugin(
3254 WebFrame* frame,
3255 const WebPluginParams& params,
3256 const FilePath& path,
3257 webkit::ppapi::PluginModule* pepper_module) {
3258 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:253259 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:093260}
[email protected]00152e92010-07-19 11:47:403261
[email protected]191eb3f72010-12-21 06:27:503262WebPlugin* RenderView::CreateNPAPIPlugin(
3263 WebFrame* frame,
3264 const WebPluginParams& params,
3265 const FilePath& path,
3266 const std::string& mime_type) {
3267 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:083268 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403269}
3270
[email protected]40bd6582009-12-04 23:49:513271void RenderView::OnZoom(PageZoom::Function function) {
3272 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3273 return;
3274
[email protected]258d31122010-05-09 10:59:413275 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:523276
[email protected]b75b8292010-10-01 07:28:253277 double old_zoom_level = webview()->zoomLevel();
3278 double zoom_level;
3279 if (function == PageZoom::RESET) {
3280 zoom_level = 0;
3281 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3282 // Previous zoom level is a whole number, so just increment/decrement.
3283 zoom_level = old_zoom_level + function;
3284 } else {
3285 // Either the user hit the zoom factor limit and thus the zoom level is now
3286 // not a whole number, or a plugin changed it to a custom value. We want
3287 // to go to the next whole number so that the user can always get back to
3288 // 100% with the keyboard/menu.
3289 if ((old_zoom_level > 1 && function > 0) ||
3290 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453291 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253292 } else {
3293 // We're going towards 100%, so first go to the next whole number.
3294 zoom_level = static_cast<int>(old_zoom_level);
3295 }
3296 }
[email protected]40bd6582009-12-04 23:49:513297
[email protected]b75b8292010-10-01 07:28:253298 webview()->setZoomLevel(false, zoom_level);
3299 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513300}
3301
[email protected]d0b8d092010-10-25 04:05:173302void RenderView::OnSetZoomLevel(double zoom_level) {
3303 // Don't set zoom level for full-page plugin since they don't use the same
3304 // zoom settings.
3305 if (webview()->mainFrame()->document().isPluginDocument())
3306 return;
3307
3308 webview()->hidePopups();
3309 webview()->setZoomLevel(false, zoom_level);
3310 zoomLevelChanged();
3311}
3312
[email protected]9d797f32010-04-23 07:17:543313void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:253314 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543315 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293316}
3317
[email protected]41fc0322009-09-04 22:23:403318void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273319 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293320}
3321
[email protected]a697f4c2009-09-14 22:30:183322void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273323 WebString no_encoding;
3324 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183325}
3326
[email protected]318bf5802011-08-08 17:12:413327WebFrame* RenderView::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453328 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273329 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453330
3331 // xpath string can represent a frame deep down the tree (across multiple
3332 // frame DOMs).
3333 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3334 // should break into 2 xpaths
3335 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413336 std::vector<string16> xpaths;
3337 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453338
[email protected]26aa0482009-09-30 16:55:273339 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413340 for (std::vector<string16>::const_iterator i = xpaths.begin();
3341 frame && i != xpaths.end(); ++i) {
3342 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293343 }
3344
[email protected]dd7daa82009-08-10 05:46:453345 return frame;
initial.commit09911bf2008-07-26 23:55:293346}
3347
[email protected]13a1e4c3c2011-02-03 21:07:093348WebNode RenderView::GetFocusedNode() const {
3349 if (!webview())
3350 return WebNode();
3351 WebFrame* focused_frame = webview()->focusedFrame();
3352 if (focused_frame) {
3353 WebDocument doc = focused_frame->document();
3354 if (!doc.isNull())
3355 return doc.focusedNode();
3356 }
3357
3358 return WebNode();
3359}
3360
[email protected]38b592902011-04-16 02:08:423361bool RenderView::IsEditableNode(const WebNode& node) {
3362 bool is_editable_node = false;
3363 if (!node.isNull()) {
3364 if (node.isContentEditable()) {
3365 is_editable_node = true;
3366 } else if (node.isElementNode()) {
3367 is_editable_node =
3368 node.toConst<WebElement>().isTextFormControlElement();
3369 }
3370 }
3371 return is_editable_node;
3372}
3373
[email protected]882b7b22010-10-05 03:34:533374void RenderView::EvaluateScript(const string16& frame_xpath,
3375 const string16& script,
3376 int id,
3377 bool notify_result) {
3378 v8::Handle<v8::Value> result;
[email protected]318bf5802011-08-08 17:12:413379 WebFrame* web_frame = GetChildFrame(frame_xpath);
[email protected]882b7b22010-10-05 03:34:533380 if (web_frame)
3381 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
3382 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:293383 ListValue list;
[email protected]cd326242011-06-16 01:55:463384 if (!result.IsEmpty() && web_frame) {
[email protected]81f9fe0b2010-12-07 00:35:293385 v8::HandleScope handle_scope;
3386 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3387 v8::Context::Scope context_scope(context);
[email protected]b1cf3372011-04-20 21:28:103388 V8ValueConverter converter;
3389 converter.set_allow_date(true);
3390 converter.set_allow_regexp(true);
3391 list.Set(0, converter.FromV8Value(result, context));
[email protected]81f9fe0b2010-12-07 00:35:293392 } else {
3393 list.Set(0, Value::CreateNullValue());
3394 }
3395 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:533396 }
initial.commit09911bf2008-07-26 23:55:293397}
3398
[email protected]882b7b22010-10-05 03:34:533399void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
3400 const string16& jscript,
3401 int id,
3402 bool notify_result) {
3403 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293404}
3405
[email protected]318bf5802011-08-08 17:12:413406void RenderView::OnCSSInsertRequest(const string16& frame_xpath,
[email protected]01cf589c2011-07-28 18:04:033407 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413408 WebFrame* frame = GetChildFrame(frame_xpath);
3409 if (!frame)
[email protected]216813952011-05-19 22:21:263410 return;
[email protected]ae461542009-06-19 19:03:413411
[email protected]01cf589c2011-07-28 18:04:033412 frame->document().insertUserStyleSheet(
3413 WebString::fromUTF8(css),
3414 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483415}
3416
[email protected]81e63782009-02-27 19:35:093417void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3418 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293419}
3420
[email protected]d0980792011-02-13 19:41:403421void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:293422 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:553423 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:273424 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293425}
3426
3427void RenderView::OnReservePageIDRange(int size_of_range) {
3428 next_page_id_ += size_of_range + 1;
3429}
3430
[email protected]59f4f2fa2011-03-23 01:00:553431void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
3432 const gfx::Point& client_point,
3433 const gfx::Point& screen_point,
3434 WebDragOperationsMask ops) {
3435 WebDragOperation operation = webview()->dragTargetDragEnter(
3436 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553437 client_point,
3438 screen_point,
3439 ops);
3440
3441 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3442}
3443
3444void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
3445 const gfx::Point& screen_point,
3446 WebDragOperationsMask ops) {
3447 WebDragOperation operation = webview()->dragTargetDragOver(
3448 client_point,
3449 screen_point,
3450 ops);
3451
3452 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3453}
3454
3455void RenderView::OnDragTargetDragLeave() {
3456 webview()->dragTargetDragLeave();
3457}
3458
3459void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3460 const gfx::Point& screen_point) {
3461 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573462
3463 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553464}
3465
[email protected]e80c73b2009-04-07 23:24:583466void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3467 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253468 bool ended,
3469 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033470 if (ended) {
[email protected]26aa0482009-09-30 16:55:273471 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203472 } else {
3473 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033474 }
initial.commit09911bf2008-07-26 23:55:293475}
3476
3477void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273478 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293479}
3480
initial.commit09911bf2008-07-26 23:55:293481void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593482 webkit_preferences_ = prefs;
3483 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293484}
3485
[email protected]08bb1e722011-07-30 19:13:043486void RenderView::OnUpdateRemoteAccessClientFirewallTraversal(
3487 const std::string& policy) {
3488 pepper_delegate_.PublishPolicy(policy);
3489}
3490
initial.commit09911bf2008-07-26 23:55:293491void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3492 alternate_error_page_url_ = url;
3493}
3494
[email protected]b29aa74b2011-01-31 21:41:083495void RenderView::OnCustomContextMenuAction(
3496 const webkit_glue::CustomContextMenuContext& custom_context,
3497 unsigned action) {
3498 if (custom_context.is_pepper_menu)
3499 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3500 else
3501 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:333502}
3503
initial.commit09911bf2008-07-26 23:55:293504void RenderView::OnInstallMissingPlugin() {
3505 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:593506 if (first_default_plugin_)
3507 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:293508}
3509
[email protected]600ea402011-04-12 00:01:513510void RenderView::OnEnumerateDirectoryResponse(
3511 int id,
3512 const std::vector<FilePath>& paths) {
3513 if (!enumeration_completions_[id])
3514 return;
3515
3516 WebVector<WebString> ws_file_names(paths.size());
3517 for (size_t i = 0; i < paths.size(); ++i)
3518 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3519
3520 enumeration_completions_[id]->didChooseFile(ws_file_names);
3521 enumeration_completions_.erase(id);
3522}
3523
[email protected]cdaf8d02010-03-30 19:52:473524void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363525 // This could happen if we navigated to a different page before the user
3526 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473527 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363528 return;
3529
[email protected]cdaf8d02010-03-30 19:52:473530 WebVector<WebString> ws_file_names(paths.size());
3531 for (size_t i = 0; i < paths.size(); ++i)
3532 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463533
[email protected]cdaf8d02010-03-30 19:52:473534 if (file_chooser_completions_.front()->completion)
3535 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3536 file_chooser_completions_.pop_front();
3537
3538 // If there are more pending file chooser requests, schedule one now.
3539 if (!file_chooser_completions_.empty()) {
3540 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3541 file_chooser_completions_.front()->params));
3542 }
initial.commit09911bf2008-07-26 23:55:293543}
3544
[email protected]770dd8b2010-05-24 18:11:393545void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3546 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243547 if (send_preferred_size_changes_)
3548 return;
[email protected]9fb325e2010-05-06 18:23:243549 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393550
[email protected]d812fd12011-05-27 23:05:073551 // Start off with an initial preferred size notification (in case
3552 // |didUpdateLayout| was already called).
3553 if (webview())
3554 didUpdateLayout(webview()->mainFrame());
[email protected]0666aef2009-05-13 19:48:083555}
3556
[email protected]cda45c02010-02-25 19:28:103557void RenderView::OnDisableScrollbarsForSmallWindows(
3558 const gfx::Size& disable_scrollbar_size_limit) {
3559 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3560}
3561
[email protected]80d96fa2009-06-10 22:34:513562void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3563 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373564 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133565#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413566 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3567 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463568 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513569 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343570 renderer_prefs.thumb_inactive_color,
3571 renderer_prefs.thumb_active_color,
3572 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323573
[email protected]644d77e2010-01-27 01:03:103574 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323575 webview()->setScrollbarColors(
3576 renderer_prefs.thumb_inactive_color,
3577 renderer_prefs.thumb_active_color,
3578 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103579 webview()->setSelectionColors(
3580 renderer_prefs.active_selection_bg_color,
3581 renderer_prefs.active_selection_fg_color,
3582 renderer_prefs.inactive_selection_bg_color,
3583 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463584 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103585 }
[email protected]7a74e102009-09-03 00:16:563586#endif
[email protected]80d96fa2009-06-10 22:34:513587}
3588
[email protected]952cb702009-10-07 05:50:283589void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3590 const WebMediaPlayerAction& action) {
3591 if (webview())
3592 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563593}
3594
[email protected]dea2d372010-09-25 06:41:143595void RenderView::OnEnableAccessibility() {
3596 if (WebAccessibilityCache::accessibilityEnabled())
3597 return;
[email protected]9f4db512010-05-10 20:21:413598
[email protected]dea2d372010-09-25 06:41:143599 WebAccessibilityCache::enableAccessibility();
3600
3601 if (webview()) {
3602 // It's possible that the webview has already loaded a webpage without
3603 // accessibility being enabled. Initialize the browser's cached
3604 // accessibility tree by sending it a 'load complete' notification.
3605 postAccessibilityNotification(
3606 webview()->accessibilityObject(),
3607 WebKit::WebAccessibilityNotificationLoadComplete);
3608 }
[email protected]266eb6f2008-09-30 23:56:503609}
3610
[email protected]aef92842010-05-21 16:54:363611void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
3612 if (!accessibility_.get())
3613 return;
[email protected]02ea2f312010-09-27 17:03:363614
3615 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3616 WebAccessibilityObject root = webview()->accessibilityObject();
3617 if (!obj.isValid() || !root.isValid())
3618 return;
3619
3620 // By convention, calling SetFocus on the root of the tree should clear the
3621 // current focus. Otherwise set the focus to the new node.
3622 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
3623 webview()->clearFocusedNode();
3624 else
3625 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:363626}
3627
3628void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
3629 if (!accessibility_.get())
3630 return;
[email protected]02ea2f312010-09-27 17:03:363631
3632 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
3633 if (!obj.isValid())
3634 return;
3635
3636 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:363637}
3638
[email protected]9892b472010-09-16 00:23:423639void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:513640 DCHECK(accessibility_ack_pending_);
3641 accessibility_ack_pending_ = false;
3642 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:313643}
3644
[email protected]18d5be92011-07-25 18:00:193645void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3646 const GURL& page_url) {
3647 // Prepare list to storage all savable resource links.
3648 std::vector<GURL> resources_list;
3649 std::vector<GURL> referrers_list;
3650 std::vector<GURL> frames_list;
3651 webkit_glue::SavableResourcesResult result(&resources_list,
3652 &referrers_list,
3653 &frames_list);
3654
3655 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3656 webview(),
3657 page_url,
3658 &result,
3659 chrome::kSavableSchemes)) {
3660 // If something is wrong when collecting all savable resource links,
3661 // send empty list to embedder(browser) to tell it failed.
3662 referrers_list.clear();
3663 resources_list.clear();
3664 frames_list.clear();
3665 }
3666
3667 // Send result of all savable resource links to embedder.
3668 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3669 resources_list,
3670 referrers_list,
3671 frames_list));
3672}
3673
3674void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
3675 const std::vector<GURL>& links,
3676 const std::vector<FilePath>& local_paths,
3677 const FilePath& local_directory_name) {
3678
3679 // Convert std::vector of GURLs to WebVector<WebURL>
3680 WebVector<WebURL> weburl_links(links);
3681
3682 // Convert std::vector of std::strings to WebVector<WebString>
3683 WebVector<WebString> webstring_paths(local_paths.size());
3684 for (size_t i = 0; i < local_paths.size(); i++)
3685 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3686
3687 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
3688 webstring_paths,
3689 webkit_glue::FilePathToWebString(
3690 local_directory_name));
3691}
3692
[email protected]9b18a84f2010-06-10 15:54:043693void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273694 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473695 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293696}
3697
[email protected]992db4c2011-05-12 15:37:153698void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3699 if (is_swapped_out_)
3700 return;
3701
3702 // Swap this RenderView out so the tab can navigate to a page rendered by a
3703 // different process. This involves running the unload handler and clearing
3704 // the page. Once WasSwappedOut is called, we also allow this process to exit
3705 // if there are no other active RenderViews in it.
3706
3707 // Send an UpdateState message before we get swapped out.
3708 SyncNavigationState();
3709
3710 // Synchronously run the unload handler before sending the ACK.
3711 webview()->dispatchUnloadEvent();
3712
3713 // Swap out and stop sending any IPC messages that are not ACKs.
3714 SetSwappedOut(true);
3715
3716 // Replace the page with a blank dummy URL. The unload handler will not be
3717 // run a second time, thanks to a check in FrameLoader::stopLoading.
3718 // TODO(creis): Need to add a better way to do this that avoids running the
3719 // beforeunload handler. For now, we just run it a second time silently.
3720 webview()->mainFrame()->loadHTMLString(std::string(),
3721 GURL("about:swappedout"),
3722 GURL("about:swappedout"),
3723 false);
3724
3725 // Just echo back the params in the ACK.
3726 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3727}
3728
3729void RenderView::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:293730 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3731 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3732 // in the onunload handler from appearing. For now, we're bypassing that and
3733 // calling the FrameLoader's CloseURL method directly. This should be
3734 // revisited to avoid having two ways to close a page. Having a single way
3735 // to close that can run onunload is also useful for fixing
3736 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273737 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293738
[email protected]992db4c2011-05-12 15:37:153739 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293740}
3741
3742void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573743#if defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163744 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463745 if (webview())
3746 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573747#else // defined(OS_WIN)
3748 // TODO(port): we don't support theming on non-Windows platforms yet
3749 NOTIMPLEMENTED();
3750#endif
initial.commit09911bf2008-07-26 23:55:293751}
3752
[email protected]0aa55312008-10-17 21:53:083753void RenderView::OnDisassociateFromPopupCount() {
3754 if (decrement_shared_popup_at_destruction_)
3755 shared_popup_counter_->data--;
3756 shared_popup_counter_ = new SharedRenderViewCounter(0);
3757 decrement_shared_popup_at_destruction_ = false;
3758}
3759
[email protected]15d79e12009-08-02 19:23:453760bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3761 const WebURLError& error,
3762 bool replace) {
3763 // We only show alternate error pages in the main frame. They are
3764 // intended to assist the user when navigating, so there is not much
3765 // value in showing them for failed subframes. Ideally, we would be
3766 // able to use the TYPED transition type for this, but that flag is
3767 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453768 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453769 return false;
3770
3771 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373772 // connection failure.
[email protected]15d79e12009-08-02 19:23:453773 int ec = error.reason;
3774 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3775 ec != net::ERR_CONNECTION_FAILED &&
3776 ec != net::ERR_CONNECTION_REFUSED &&
3777 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373778 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453779 return false;
3780
3781 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553782 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453783 if (!error_page_url.is_valid())
3784 return false;
3785
3786 // Load an empty page first so there is an immediate response to the error,
3787 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453788 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363789 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453790 error.unreachableURL,
3791 replace);
3792
3793 // Now, create a fetcher for the error page and associate it with the data
3794 // source we just created via the LoadHTMLString call. That way if another
3795 // navigation occurs, the fetcher will get destroyed.
3796 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453797 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453798 navigation_state->set_alt_error_page_fetcher(
3799 new AltErrorPageResourceFetcher(
3800 error_page_url, frame, error,
3801 NewCallback(this, &RenderView::AltErrorPageFinished)));
3802 return true;
3803}
3804
[email protected]15d79e12009-08-02 19:23:453805void RenderView::AltErrorPageFinished(WebFrame* frame,
3806 const WebURLError& original_error,
3807 const std::string& html) {
3808 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093809 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553810 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093811 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453812}
3813
[email protected]30f75e62009-02-25 22:01:003814void RenderView::OnMoveOrResizeStarted() {
3815 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473816 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003817}
3818
[email protected]30f75e62009-02-25 22:01:003819void RenderView::OnResize(const gfx::Size& new_size,
3820 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103821 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473822 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103823 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203824 webview()->mainFrame()->setCanHaveScrollbars(
3825 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103826 }
3827 }
3828
[email protected]30f75e62009-02-25 22:01:003829 RenderWidget::OnResize(new_size, resizer_rect);
3830}
[email protected]0aa477bd2009-03-23 22:21:433831
[email protected]00c39612010-03-06 02:53:283832void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013833 // Notify the pepper plugins that we started painting.
3834 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283835}
3836
3837void RenderView::DidFlushPaint() {
3838 // Notify any pepper plugins that we painted. This will call into the plugin,
3839 // and we it may ask to close itself as a result. This will, in turn, modify
3840 // our set, possibly invalidating the iterator. So we iterate on a copy that
3841 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013842 pepper_delegate_.ViewFlushedPaint();
3843
[email protected]00c39612010-03-06 02:53:283844 WebFrame* main_frame = webview()->mainFrame();
3845
3846 // If we have a provisional frame we are between the start and commit stages
3847 // of loading and we don't want to save stats.
3848 if (!main_frame->provisionalDataSource()) {
3849 WebDataSource* ds = main_frame->dataSource();
3850 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3851 DCHECK(navigation_state);
3852
[email protected]05c8e502010-08-15 15:13:523853 // TODO(jar): The following code should all be inside a method, probably in
3854 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283855 Time now = Time::Now();
3856 if (navigation_state->first_paint_time().is_null()) {
3857 navigation_state->set_first_paint_time(now);
3858 }
3859 if (navigation_state->first_paint_after_load_time().is_null() &&
3860 !navigation_state->finish_load_time().is_null()) {
3861 navigation_state->set_first_paint_after_load_time(now);
3862 }
3863 }
3864}
3865
[email protected]37a6f302011-07-11 23:43:083866void RenderView::OnViewContextSwapBuffersPosted() {
3867 RenderWidget::OnSwapBuffersPosted();
3868}
3869
[email protected]65225772011-05-12 21:10:243870void RenderView::OnViewContextSwapBuffersComplete() {
3871 RenderWidget::OnSwapBuffersComplete();
3872}
3873
3874void RenderView::OnViewContextSwapBuffersAborted() {
3875 RenderWidget::OnSwapBuffersAborted();
3876}
3877
[email protected]719b36f2010-12-22 20:36:463878webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:153879 const gfx::Rect& paint_bounds,
3880 TransportDIB** dib,
3881 gfx::Rect* location,
3882 gfx::Rect* clip) {
3883 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
3884 paint_bounds, dib, location, clip);
3885}
3886
[email protected]bcaf2272011-02-15 15:29:433887gfx::Point RenderView::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:073888 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:433889 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523890}
3891
[email protected]05d478752009-04-08 23:38:163892void RenderView::OnClearFocusedNode() {
3893 if (webview())
[email protected]26aa0482009-09-30 16:55:273894 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163895}
3896
[email protected]699ab0d2009-04-23 23:19:143897void RenderView::OnSetBackground(const SkBitmap& background) {
3898 if (webview())
[email protected]b4bb2502009-10-01 22:35:273899 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143900
3901 SetBackground(background);
3902}
3903
[email protected]8c66c5a2009-07-22 17:26:343904void RenderView::OnSetActive(bool active) {
3905 if (webview())
[email protected]b4bb2502009-10-01 22:35:273906 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263907
3908#if defined(OS_MACOSX)
3909 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3910 for (plugin_it = plugin_delegates_.begin();
3911 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3912 (*plugin_it)->SetWindowFocus(active);
3913 }
3914#endif
[email protected]8c66c5a2009-07-22 17:26:343915}
3916
[email protected]6ce7abc52010-02-02 18:40:143917#if defined(OS_MACOSX)
3918void RenderView::OnSetWindowVisibility(bool visible) {
3919 // Inform plugins that their container has changed visibility.
3920 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3921 for (plugin_it = plugin_delegates_.begin();
3922 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3923 (*plugin_it)->SetContainerVisibility(visible);
3924 }
3925}
[email protected]1e6e3c992010-02-08 15:52:133926
[email protected]4d51d5bf2010-07-26 18:48:263927void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
3928 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:133929 // Inform plugins that their window's frame has changed.
3930 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3931 for (plugin_it = plugin_delegates_.begin();
3932 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3933 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3934 }
3935}
[email protected]935d63d2010-10-15 23:31:553936
[email protected]b7f75862011-01-21 21:15:133937void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:553938 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:133939 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:553940 // applies to it or not, so inform all the delegates.
3941 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3942 for (plugin_it = plugin_delegates_.begin();
3943 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:133944 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:553945 }
3946}
[email protected]6ce7abc52010-02-02 18:40:143947#endif // OS_MACOSX
3948
[email protected]9892b472010-09-16 00:23:423949void RenderView::postAccessibilityNotification(
3950 const WebAccessibilityObject& obj,
3951 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:143952 if (!accessibility_.get() && webview()) {
3953 // Load complete should be our first notification sent.
3954 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
3955 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
3956 return;
3957
3958 // Create and initialize our accessibility cache
3959 accessibility_.reset(WebAccessibilityCache::create());
3960 accessibility_->initialize(webview());
3961 }
3962
[email protected]a3fa4f92010-09-30 22:19:333963 if (!accessibility_->isCached(obj)) {
3964 // The browser doesn't know about objects that are not in the cache. Send a
3965 // children change for the first accestor that actually is in the cache.
3966 WebAccessibilityObject parent = obj;
3967 while (parent.isValid() && !accessibility_->isCached(parent))
3968 parent = parent.parentObject();
3969
3970 DCHECK(parent.isValid() && accessibility_->isCached(parent));
3971 if (!parent.isValid())
3972 return;
3973 postAccessibilityNotification(
3974 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
3975
3976 // The parent's children change takes care of the child's children change.
3977 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
3978 return;
3979 }
3980
[email protected]dea2d372010-09-25 06:41:143981 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:513982 RendererAccessibilityNotification acc_notification;
3983 acc_notification.id = accessibility_->addOrGetId(obj);
[email protected]a527a022011-02-10 02:32:363984 acc_notification.type = notification;
[email protected]54ec7f82010-10-21 22:32:513985 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:483986 return;
3987
[email protected]fffaf972011-03-24 01:34:353988 ViewHostMsg_AccessibilityNotification_Type::Value temp;
[email protected]a527a022011-02-10 02:32:363989 if (!WebAccessibilityNotificationToViewHostMsg(notification, &temp))
[email protected]54ec7f82010-10-21 22:32:513990 return;
[email protected]54ec7f82010-10-21 22:32:513991
3992 // Discard duplicate accessibility notifications.
3993 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
3994 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
3995 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:423996 return;
[email protected]54ec7f82010-10-21 22:32:513997 }
[email protected]9892b472010-09-16 00:23:423998 }
[email protected]54ec7f82010-10-21 22:32:513999 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:484000
[email protected]54ec7f82010-10-21 22:32:514001 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
4002 // When no accessibility notifications are in-flight post a task to send
4003 // the notifications to the browser. We use PostTask so that we can queue
4004 // up additional notifications.
4005 MessageLoop::current()->PostTask(
4006 FROM_HERE,
4007 accessibility_method_factory_.NewRunnableMethod(
4008 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:314009 }
[email protected]520cb7d72010-08-31 11:54:314010}
4011
[email protected]446705872009-09-10 07:22:484012void RenderView::OnSetEditCommandsForNextKeyEvent(
4013 const EditCommands& edit_commands) {
4014 edit_commands_ = edit_commands;
4015}
4016
[email protected]60c42a8c72009-10-09 04:08:594017void RenderView::Close() {
4018 // We need to grab a pointer to the doomed WebView before we destroy it.
4019 WebView* doomed = webview();
4020 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494021 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594022}
4023
[email protected]446705872009-09-10 07:22:484024void RenderView::DidHandleKeyEvent() {
4025 edit_commands_.clear();
4026}
4027
[email protected]6a8ddba52010-09-05 04:38:064028void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514029 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064030}
4031
[email protected]941e4552010-02-01 21:23:434032void RenderView::OnWasHidden() {
4033 RenderWidget::OnWasHidden();
4034
[email protected]a6939ca42011-02-18 17:58:074035 if (webview()) {
4036 webview()->settings()->setMinimumTimerInterval(
4037 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444038 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074039 }
4040
4041#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434042 // Inform plugins that their container is no longer visible.
4043 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4044 for (plugin_it = plugin_delegates_.begin();
4045 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4046 (*plugin_it)->SetContainerVisibility(false);
4047 }
[email protected]a6939ca42011-02-18 17:58:074048#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434049}
4050
4051void RenderView::OnWasRestored(bool needs_repainting) {
4052 RenderWidget::OnWasRestored(needs_repainting);
4053
[email protected]a6939ca42011-02-18 17:58:074054 if (webview()) {
4055 webview()->settings()->setMinimumTimerInterval(
4056 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444057 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074058 }
4059
4060#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434061 // Inform plugins that their container is now visible.
4062 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4063 for (plugin_it = plugin_delegates_.begin();
4064 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4065 (*plugin_it)->SetContainerVisibility(true);
4066 }
[email protected]784ea1ab2010-09-18 00:02:344067#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074068}
[email protected]1e6e3c992010-02-08 15:52:134069
[email protected]65225772011-05-12 21:10:244070bool RenderView::SupportsAsynchronousSwapBuffers() {
4071 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4072 if (!context)
4073 return false;
4074 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4075 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4076 std::string::npos;
4077}
4078
[email protected]1e6e3c992010-02-08 15:52:134079void RenderView::OnSetFocus(bool enable) {
4080 RenderWidget::OnSetFocus(enable);
4081
[email protected]7d3c02c2010-05-05 23:10:314082 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074083 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134084 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4085 for (plugin_it = plugin_delegates_.begin();
4086 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344087#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314088 // RenderWidget's call to setFocus can cause the underlying webview's
4089 // activation state to change just like a call to setIsActive.
4090 if (enable)
4091 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344092#endif
[email protected]7d3c02c2010-05-05 23:10:314093 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134094 }
[email protected]589621b2010-09-23 22:01:074095
4096 // Notify all Pepper plugins.
4097 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134098 }
4099}
[email protected]941e4552010-02-01 21:23:434100
[email protected]56ea1a62011-05-30 07:05:574101void RenderView::PpapiPluginFocusChanged() {
4102 UpdateInputMethod();
4103}
4104
[email protected]08bb1e722011-07-30 19:13:044105void RenderView::RequestRemoteAccessClientFirewallTraversal() {
4106 Send(new ViewHostMsg_RequestRemoteAccessClientFirewallTraversal(routing_id_));
4107}
4108
[email protected]56ea1a62011-05-30 07:05:574109void RenderView::OnImeSetComposition(
4110 const string16& text,
4111 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4112 int selection_start,
4113 int selection_end) {
4114 // Until PPAPI has an interface for handling IME events, we skip sending
4115 // OnImeSetComposition. Otherwise the composition is canceled when a
4116 // non-editable DOM element is focused.
4117 //
4118 // TODO(kinaba) This temporal remedy can be removed after PPAPI is extended
4119 // with an IME handling interface.
4120 if (!pepper_delegate_.IsPluginFocused()) {
4121 RenderWidget::OnImeSetComposition(text,
4122 underlines,
4123 selection_start,
4124 selection_end);
4125 }
4126}
4127
4128void RenderView::OnImeConfirmComposition(const string16& text) {
4129 if (pepper_delegate_.IsPluginFocused()) {
4130 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4131 // send character events.
4132 for (size_t i = 0; i < text.size(); ++i) {
4133 WebKit::WebKeyboardEvent char_event;
4134 char_event.type = WebKit::WebInputEvent::Char;
4135 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
4136 char_event.modifiers = 0;
4137 char_event.windowsKeyCode = text[i];
4138 char_event.nativeKeyCode = text[i];
4139 char_event.text[0] = text[i];
4140 char_event.unmodifiedText[0] = text[i];
4141 if (webwidget_)
4142 webwidget_->handleInputEvent(char_event);
4143 }
4144 } else {
4145 RenderWidget::OnImeConfirmComposition(text);
4146 }
4147}
4148
[email protected]ad26ef42011-06-17 07:59:454149ui::TextInputType RenderView::GetTextInputType() {
[email protected]56ea1a62011-05-30 07:05:574150 if (pepper_delegate_.IsPluginFocused()) {
4151 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4152 // consider all the parts of PPAPI plugins are accepting text inputs.
[email protected]ad26ef42011-06-17 07:59:454153 return ui::TEXT_INPUT_TYPE_TEXT;
[email protected]56ea1a62011-05-30 07:05:574154 }
[email protected]ad26ef42011-06-17 07:59:454155 return RenderWidget::GetTextInputType();
4156}
4157
4158bool RenderView::CanComposeInline() {
4159 if (pepper_delegate_.IsPluginFocused()) {
4160 // TODO(kinaba) Until PPAPI has an interface for handling IME events, there
4161 // is no way for the browser to know whether the plugin is capable of
4162 // drawing composition text. We assume plugins are incapable and let the
4163 // browser handle composition display for now.
4164 return false;
4165 }
4166 return true;
[email protected]56ea1a62011-05-30 07:05:574167}
4168
[email protected]43f28f832010-02-03 02:28:484169#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:134170void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
4171 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4172 focused, plugin_id);
4173 Send(msg);
4174}
4175
4176void RenderView::StartPluginIme() {
4177 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554178 // This message can be sent during event-handling, and needs to be delivered
4179 // within that context.
4180 msg->set_unblock(true);
4181 Send(msg);
4182}
4183
[email protected]ea04a4e12010-04-15 00:58:034184gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234185 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484186 gfx::PluginWindowHandle window = NULL;
4187 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234188 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114189 if (window) {
4190 fake_plugin_window_handles_.insert(window);
4191 }
[email protected]43f28f832010-02-03 02:28:484192 return window;
4193}
4194
4195void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114196 if (window && fake_plugin_window_handles_.find(window) !=
4197 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484198 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114199 fake_plugin_window_handles_.erase(window);
4200 }
[email protected]43f28f832010-02-03 02:28:484201}
4202
[email protected]44ce0b12010-03-12 16:45:334203void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4204 int32 width,
4205 int32 height,
4206 uint64 io_surface_identifier) {
4207 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484208 routing_id(), window, width, height, io_surface_identifier));
4209}
4210
[email protected]44ce0b12010-03-12 16:45:334211void RenderView::AcceleratedSurfaceSetTransportDIB(
4212 gfx::PluginWindowHandle window,
4213 int32 width,
4214 int32 height,
4215 TransportDIB::Handle transport_dib) {
4216 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074217 routing_id(), window, width, height, transport_dib));
4218}
4219
[email protected]44ce0b12010-03-12 16:45:334220TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4221 size_t size) {
[email protected]1aef98132010-02-23 18:00:074222 TransportDIB::Handle dib_handle;
4223 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384224 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074225 return dib_handle;
4226 // Return an invalid handle if Send() fails.
4227 return TransportDIB::DefaultHandleValue();
4228}
4229
[email protected]44ce0b12010-03-12 16:45:334230void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074231 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4232}
4233
[email protected]44ce0b12010-03-12 16:45:334234void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144235 gfx::PluginWindowHandle window, uint64 surface_id) {
4236 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4237 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484238}
4239#endif
[email protected]58c321d2010-02-19 12:11:284240
[email protected]cdaf8d02010-03-30 19:52:474241bool RenderView::ScheduleFileChooser(
4242 const ViewHostMsg_RunFileChooser_Params& params,
4243 WebFileChooserCompletion* completion) {
4244 static const size_t kMaximumPendingFileChooseRequests = 4;
4245 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4246 // This sanity check prevents too many file choose requests from getting
4247 // queued which could DoS the user. Getting these is most likely a
4248 // programming error (there are many ways to DoS the user so it's not
4249 // considered a "real" security check), either in JS requesting many file
4250 // choosers to pop up, or in a plugin.
4251 //
4252 // TODO(brettw) we might possibly want to require a user gesture to open
4253 // a file picker, which will address this issue in a better way.
4254 return false;
4255 }
4256
4257 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4258 new PendingFileChooser(params, completion)));
4259 if (file_chooser_completions_.size() == 1) {
4260 // Actually show the browse dialog when this is the first request.
4261 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4262 }
4263 return true;
4264}
4265
[email protected]0ff0ff32010-12-21 19:34:424266WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514267 if (!geolocation_dispatcher_)
4268 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4269 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254270}
[email protected]61c9f032010-03-31 23:04:194271
[email protected]638694c2010-08-04 22:24:114272WebKit::WebSpeechInputController* RenderView::speechInputController(
4273 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:514274 if (!speech_input_dispatcher_)
4275 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
4276 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114277}
4278
[email protected]57ead352010-08-11 14:42:534279WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514280 if (!device_orientation_dispatcher_)
4281 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4282 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534283}
4284
[email protected]b75b8292010-10-01 07:28:254285void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
4286 // For now, don't remember plugin zoom values. We don't want to mix them with
4287 // normal web content (i.e. a fixed layout plugin would usually want them
4288 // different).
4289 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4290
[email protected]b75b8292010-10-01 07:28:254291 int minimum_percent = static_cast<int>(
4292 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4293 int maximum_percent = static_cast<int>(
4294 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254295
4296 Send(new ViewHostMsg_UpdateZoomLimits(
4297 routing_id_, minimum_percent, maximum_percent, remember));
4298}
4299
4300void RenderView::zoomLevelChanged() {
4301 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4302
[email protected]b75b8292010-10-01 07:28:254303 // Tell the browser which url got zoomed so it can update the menu and the
4304 // saved values if necessary
4305 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:414306 routing_id_, webview()->zoomLevel(), remember,
[email protected]b6cb3a842011-06-24 18:28:414307 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254308}
4309
[email protected]a6d36cc2011-02-23 00:39:484310void RenderView::registerProtocolHandler(const WebString& scheme,
4311 const WebString& base_url,
4312 const WebString& url,
4313 const WebString& title) {
4314 GURL base(base_url);
4315 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4316 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4317 return;
4318 }
4319 RenderThread::current()->Send(
4320 new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4321 UTF16ToUTF8(scheme),
4322 absolute_url,
4323 title));
4324}
4325
[email protected]62af76e2011-08-01 02:34:014326void RenderView::registerIntentHandler(const WebString& action,
4327 const WebString& type,
4328 const WebString& href,
4329 const WebString& title) {
4330 RenderThread::current()->Send(
4331 new ViewHostMsg_RegisterIntentHandler(routing_id_,
4332 action,
4333 type,
4334 href,
4335 title));
4336}
4337
[email protected]94dec932011-05-26 20:04:214338WebKit::WebPageVisibilityState RenderView::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444339 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4340 WebKit::WebPageVisibilityStateHidden :
4341 WebKit::WebPageVisibilityStateVisible;
4342 WebKit::WebPageVisibilityState override_state = current_state;
4343 if (content::GetContentClient()->renderer()->
4344 ShouldOverridePageVisibilityState(this,
4345 &override_state))
4346 return override_state;
4347 return current_state;
[email protected]94dec932011-05-26 20:04:214348}
4349
[email protected]8079b362010-05-07 18:37:454350bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194351 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454352 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194353 if (frame->parent() != NULL)
4354 return false;
4355
[email protected]f0a3d0b2010-08-06 22:51:534356 // Navigations initiated within Webkit are not sent out to the external host
4357 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274358 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134359 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534360 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134361 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334362 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534363 return false;
4364
[email protected]2fc22d12010-12-02 23:08:164365 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324366 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014367 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164368 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014369 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324370 // The opener relationship between the new window and the parent allows the
4371 // new window to script the parent and vice versa. This is not allowed if
4372 // the origins of the two domains are different. This can be treated as a
4373 // top level navigation and routed back to the host.
4374 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274375 if (!opener) {
[email protected]86965362011-04-21 18:42:514376 return true;
[email protected]d19ea342011-04-20 20:31:134377 } else {
[email protected]b6cb3a842011-06-24 18:28:414378 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324379 return true;
4380 }
4381 }
[email protected]61c9f032010-03-31 23:04:194382 return false;
4383}
[email protected]2b06a992010-08-21 05:48:224384
[email protected]27a9ef32010-09-10 04:06:244385void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
4386 IPC::PlatformFileForTransit file_for_transit,
4387 int message_id) {
4388 pepper_delegate_.OnAsyncFileOpened(
4389 error_code,
4390 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4391 message_id);
4392}
[email protected]caf706f2010-10-26 17:54:084393
[email protected]2b657fd2011-04-18 16:00:474394void RenderView::OnPpapiBrokerChannelCreated(
4395 int request_id,
4396 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434397 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474398 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4399 broker_process_handle,
4400 handle);
[email protected]eb415bf0e2011-04-14 02:45:424401}
4402
[email protected]caf706f2010-10-26 17:54:084403#if defined(OS_MACOSX)
4404void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154405 if (external_popup_menu_ == NULL) {
4406 // Crash reports from the field indicate that we can be notified with a
4407 // NULL external popup menu (we probably get notified twice).
4408 // If you hit this please file a bug against jcivelli and include the page
4409 // and steps to repro.
4410 NOTREACHED();
4411 return;
4412 }
[email protected]caf706f2010-10-26 17:54:084413 external_popup_menu_->DidSelectItem(selected_index);
4414 external_popup_menu_.reset();
4415}
4416#endif
[email protected]bb461532010-11-26 21:50:234417
[email protected]1b4209f2011-01-07 00:25:404418#if defined(ENABLE_FLAPPER_HACKS)
4419void RenderView::OnConnectTcpACK(
4420 int request_id,
4421 IPC::PlatformFileForTransit socket_for_transit,
4422 const PP_Flash_NetAddress& local_addr,
4423 const PP_Flash_NetAddress& remote_addr) {
4424 pepper_delegate_.OnConnectTcpACK(
4425 request_id,
4426 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4427 local_addr,
4428 remote_addr);
4429}
4430#endif
[email protected]a6097f42011-01-10 08:50:514431
[email protected]b29aa74b2011-01-31 21:41:084432void RenderView::OnContextMenuClosed(
4433 const webkit_glue::CustomContextMenuContext& custom_context) {
4434 if (custom_context.is_pepper_menu)
4435 pepper_delegate_.OnContextMenuClosed(custom_context);
4436 else
4437 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104438}