blob: e482ac4fe255f68befd99dea8346ea5340a821d7 [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]005bab02011-10-07 18:36:0015#include "base/json/json_value_serializer.h"
[email protected]b1cf3372011-04-20 21:28:1016#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4917#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2819#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4122#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2923#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2824#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2625#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2226#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1027#include "content/common/appcache/appcache_dispatcher.h"
[email protected]9966325b2011-04-18 05:00:1028#include "content/common/bindings_policy.h"
[email protected]127dd582011-03-16 21:32:1029#include "content/common/clipboard_messages.h"
[email protected]db803aae2011-03-05 02:00:4230#include "content/common/content_constants.h"
[email protected]9966325b2011-04-18 05:00:1031#include "content/common/content_switches.h"
[email protected]37666cf2011-03-13 21:51:4232#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5533#include "content/common/drag_messages.h"
[email protected]7ef40ffe12011-03-08 05:05:2834#include "content/common/file_system/file_system_dispatcher.h"
35#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]7f070d42011-03-09 20:25:3236#include "content/common/notification_service.h"
[email protected]127dd582011-03-16 21:32:1037#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0038#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4039#include "content/common/quota_dispatcher.h"
[email protected]60916042011-03-19 00:43:3640#include "content/common/renderer_preferences.h"
[email protected]940895b2011-08-20 00:50:0541#include "content/common/request_extra_data.h"
[email protected]9966325b2011-04-18 05:00:1042#include "content/common/url_constants.h"
[email protected]778574e2011-03-21 22:03:5043#include "content/common/view_messages.h"
[email protected]d344114c2011-10-01 01:24:3444#include "content/public/renderer/content_renderer_client.h"
[email protected]82ddba1c2011-10-04 00:15:3245#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4446#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3647#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1948#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0249#include "content/renderer/devtools_agent.h"
[email protected]55722152011-03-22 01:33:5350#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1951#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4052#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]1ef93132011-09-16 18:33:4753#include "content/renderer/intents_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0254#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0855#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3756#include "content/renderer/media/audio_renderer_impl.h"
[email protected]ab2c4732011-07-20 19:57:4057#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:4058#include "content/renderer/media/render_media_log.h"
[email protected]4a19be92011-09-22 14:25:0259#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1960#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3761#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3562#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0563#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4464#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4465#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3266#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0167#include "content/renderer/renderer_webapplicationcachehost_impl.h"
68#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1969#include "content/renderer/speech_input_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3270#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1971#include "content/renderer/v8_value_converter_impl.h"
[email protected]663bd9e2011-03-21 01:07:0172#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3573#include "content/renderer/webplugin_delegate_proxy.h"
74#include "content/renderer/websharedworker_proxy.h"
75#include "content/renderer/webworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4976#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4177#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2778#include "media/base/message_loop_factory_impl.h"
initial.commit09911bf2008-07-26 23:55:2979#include "net/base/escape.h"
80#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0481#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5782#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3783#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
84#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
85#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3786#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
87#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
88#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
89#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3790#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
91#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
92#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
93#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
94#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
95#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
96#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
97#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
98#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:5799#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]69f110d62011-03-17 19:01:14100#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37101#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19102#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37103#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
104#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
105#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
111#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
112#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17113#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37114#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
115#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40117#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]8bd0fe62011-01-17 06:44:37118#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26126#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c4a9e932011-03-05 04:05:55127#include "ui/base/message_box_flags.h"
[email protected]08397d52011-02-05 01:53:38128#include "ui/gfx/native_widget_types.h"
129#include "ui/gfx/point.h"
130#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55131#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04132#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43133#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24134#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19135#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59136#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24137#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24138#include "webkit/glue/glue_serialize.h"
[email protected]85cc78c2010-05-04 18:30:09139#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26140#include "webkit/glue/password_form_dom_manager.h"
initial.commit09911bf2008-07-26 23:55:29141#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07142#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29143#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17144#include "webkit/glue/webmediaplayer_impl.h"
[email protected]b00ba702011-08-17 01:41:03145#include "webkit/glue/weburlloader_impl.h"
[email protected]191eb3f72010-12-21 06:27:50146#include "webkit/plugins/npapi/default_plugin_shared.h"
147#include "webkit/plugins/npapi/plugin_list.h"
148#include "webkit/plugins/npapi/webplugin_delegate.h"
149#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
150#include "webkit/plugins/npapi/webplugin_impl.h"
151#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52152#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29153
[email protected]6c8afae52009-01-22 02:24:57154#if defined(OS_WIN)
155// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57156// * theming
[email protected]08397d52011-02-05 01:53:38157#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03158#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37159#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51160#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33161#elif defined(OS_MACOSX)
162#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57163#endif
164
[email protected]9892b472010-09-16 00:23:42165using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08166using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21167using WebKit::WebApplicationCacheHost;
168using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26169using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41170using WebKit::WebColor;
171using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59172using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44173using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51174using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55175using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28176using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00177using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58178using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25179using WebKit::WebDragOperation;
180using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51181using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51182using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08183using WebKit::WebExternalPopupMenu;
184using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47185using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22186using WebKit::WebFileSystem;
187using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49188using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59189using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48190using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45191using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17192using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13193using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41194using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50195using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17196using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28197using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17198using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28199using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28200using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51201using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19202using WebKit::WebPageSerializer;
203using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17204using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40205using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49206using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09207using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52208using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59209using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51210using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52211using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40212using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35213using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29214using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17215using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59216using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42217using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02218using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34219using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40220using WebKit::WebStorageQuotaCallbacks;
221using WebKit::WebStorageQuotaError;
222using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28223using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51224using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52225using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24226using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28227using WebKit::WebURL;
228using WebKit::WebURLError;
229using WebKit::WebURLRequest;
230using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28231using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03232using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28233using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26234using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43235using WebKit::WebWorker;
236using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26237using appcache::WebApplicationCacheHostImpl;
238using base::Time;
239using base::TimeDelta;
[email protected]82ddba1c2011-10-04 00:15:32240using content::NavigationState;
[email protected]380244092011-10-07 17:26:27241using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44242using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36243using content::RenderViewVisitor;
[email protected]8d86f13d2011-10-04 17:01:19244using content::V8ValueConverter;
[email protected]6fdd4182010-10-14 23:59:26245using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26246using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26247using webkit_glue::PasswordForm;
248using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23249using webkit_glue::ResourceFetcher;
[email protected]e1acf6f2008-10-27 20:43:33250
initial.commit09911bf2008-07-26 23:55:29251//-----------------------------------------------------------------------------
252
[email protected]3354d3e2010-06-10 19:53:02253typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49254static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02255
[email protected]882daa92009-11-05 16:31:31256// Time, in seconds, we delay before sending content state changes (such as form
257// state and scroll position) to the browser. We delay sending changes to avoid
258// spamming the browser.
259// To avoid having tab/session restore require sending a message to get the
260// current content state during tab closing we use a shorter timeout for the
261// foreground renderer. This means there is a small window of time from which
262// content state is modified and not sent to session restore, but this is
263// better than having to wake up all renderers during shutdown.
264static const int kDelaySecondsForContentStateSyncHidden = 5;
265static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29266
[email protected]0aa55312008-10-17 21:53:08267// The maximum number of popups that can be spawned from one page.
268static const int kMaximumNumberOfUnacknowledgedPopups = 25;
269
[email protected]c514d6372011-08-16 22:54:44270static const float kScalingIncrement = 0.1f;
271
[email protected]726985e22009-06-18 21:09:28272static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
273 WebVector<WebURL> urls;
274 ds->redirectChain(urls);
275 result->reserve(urls.size());
276 for (size_t i = 0; i < urls.size(); ++i)
277 result->push_back(urls[i]);
278}
279
[email protected]6a8f5112011-05-13 16:38:44280// If |data_source| is non-null and has a NavigationState associated with it,
281// the AltErrorPageResourceFetcher is reset.
282static void StopAltErrorPageFetcher(WebDataSource* data_source) {
283 if (data_source) {
284 NavigationState* state = NavigationState::FromDataSource(data_source);
285 if (state)
286 state->set_alt_error_page_fetcher(NULL);
287 }
288}
289
initial.commit09911bf2008-07-26 23:55:29290///////////////////////////////////////////////////////////////////////////////
291
[email protected]60c42a8c72009-10-09 04:08:59292int32 RenderView::next_page_id_ = 1;
293
[email protected]cdaf8d02010-03-30 19:52:47294struct RenderView::PendingFileChooser {
295 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
296 WebFileChooserCompletion* c)
297 : params(p),
298 completion(c) {
299 }
300 ViewHostMsg_RunFileChooser_Params params;
301 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
302};
303
[email protected]380244092011-10-07 17:26:27304RenderView::RenderView(gfx::NativeViewId parent_hwnd,
[email protected]676126f72011-01-15 00:03:51305 int32 opener_id,
306 const RendererPreferences& renderer_prefs,
307 const WebPreferences& webkit_prefs,
308 SharedRenderViewCounter* counter,
309 int32 routing_id,
310 int64 session_storage_namespace_id,
311 const string16& frame_name)
[email protected]380244092011-10-07 17:26:27312 : RenderWidget(WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51313 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02314 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09315 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02316 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24317 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21318 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02319 opened_by_user_gesture_(true),
320 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24321 page_id_(-1),
322 last_page_id_sent_to_browser_(-1),
[email protected]3cc72b12010-03-18 23:03:00323 history_list_offset_(-1),
324 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02325 target_url_status_(TARGET_NONE),
[email protected]dd6afca2011-08-13 03:44:31326 cached_is_main_frame_pinned_to_left_(false),
327 cached_is_main_frame_pinned_to_right_(false),
328 cached_has_main_frame_horizontal_scrollbar_(false),
329 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]18ca9a6b2010-06-02 19:05:18330 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e6ae0f6c2011-10-04 10:39:23331#if defined(OS_WIN)
332 focused_plugin_id_(-1),
333#endif
[email protected]3354d3e2010-06-10 19:53:02334 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51335 geolocation_dispatcher_(NULL),
336 speech_input_dispatcher_(NULL),
337 device_orientation_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18338 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41339 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32340 renderer_accessibility_(NULL),
[email protected]4fb60142011-08-09 02:22:08341 session_storage_namespace_id_(session_storage_namespace_id),
342 handling_select_range_(false) {
[email protected]676126f72011-01-15 00:03:51343 routing_id_ = routing_id;
344 if (opener_id != MSG_ROUTING_NONE)
345 opener_id_ = opener_id;
346
[email protected]11fee2332011-03-29 20:36:35347 webwidget_ = WebView::create(this);
348
[email protected]676126f72011-01-15 00:03:51349 if (counter) {
350 shared_popup_counter_ = counter;
351 shared_popup_counter_->data++;
352 decrement_shared_popup_at_destruction_ = true;
353 } else {
354 shared_popup_counter_ = new SharedRenderViewCounter(0);
355 decrement_shared_popup_at_destruction_ = false;
356 }
357
[email protected]1ef93132011-09-16 18:33:47358 intents_dispatcher_ = new IntentsDispatcher(this);
[email protected]676126f72011-01-15 00:03:51359 notification_provider_ = new NotificationProvider(this);
360
[email protected]380244092011-10-07 17:26:27361 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51362 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47363 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51364 AddRef();
365
366 // If this is a popup, we must wait for the CreatingNew_ACK message before
367 // completing initialization. Otherwise, we can finish it now.
368 if (opener_id == MSG_ROUTING_NONE) {
369 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55370 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51371 }
372
[email protected]34c61bd52011-05-02 19:38:33373 g_view_map.Get().insert(std::make_pair(webview(), this));
374 webkit_preferences_.Apply(webview());
375 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35376 if (!frame_name.empty())
377 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33378 webview()->settings()->setMinimumTimerInterval(
379 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
380 webkit_glue::kForegroundTabTimerInterval);
381
382 OnSetRendererPrefs(renderer_prefs);
383
[email protected]676126f72011-01-15 00:03:51384 host_window_ = parent_hwnd;
385
[email protected]a026daa2011-04-20 15:49:51386#if defined(ENABLE_P2P_APIS)
[email protected]b3f8f9722011-08-25 20:56:07387 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51388#endif
[email protected]cae8c8492011-03-03 11:12:18389
[email protected]8f6a3b852011-07-19 16:48:56390 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32391#if defined(OS_MACOSX)
392 new TextInputClientObserver(this);
393#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56394
[email protected]c5c1d6d2011-07-28 18:42:41395 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20396
[email protected]063afcb2011-09-29 07:54:32397 renderer_accessibility_ = new RendererAccessibility(this);
398
399 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]ab2c4732011-07-20 19:57:40400 if (command_line.HasSwitch(switches::kEnableMediaStream)) {
401 media_stream_impl_ = new MediaStreamImpl(
[email protected]f1a29a02011-10-06 23:08:44402 RenderThreadImpl::current()->video_capture_impl_manager());
[email protected]ab2c4732011-07-20 19:57:40403 }
404
[email protected]e48869a2011-04-01 19:56:03405 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29406}
407
408RenderView::~RenderView() {
[email protected]d466b8a2011-07-15 21:48:03409 history_page_ids_.clear();
410
[email protected]0aa55312008-10-17 21:53:08411 if (decrement_shared_popup_at_destruction_)
412 shared_popup_counter_->data--;
413
[email protected]a1128322009-10-06 18:38:46414 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47415 while (!file_chooser_completions_.empty()) {
416 if (file_chooser_completions_.front()->completion) {
417 file_chooser_completions_.front()->completion->didChooseFile(
418 WebVector<WebString>());
419 }
420 file_chooser_completions_.pop_front();
421 }
[email protected]a1128322009-10-06 18:38:46422
[email protected]83dde542009-09-11 20:59:55423#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11424 // Destroy all fake plugin window handles on the browser side.
425 while (!fake_plugin_window_handles_.empty()) {
426 // Make sure no NULL plugin window handles were inserted into this list.
427 DCHECK(*fake_plugin_window_handles_.begin());
428 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
429 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
430 }
[email protected]83dde542009-09-11 20:59:55431#endif
[email protected]98324892009-09-09 21:16:05432
[email protected]60c42a8c72009-10-09 04:08:59433#ifndef NDEBUG
434 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49435 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59436 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
437 DCHECK_NE(this, it->second) << "Failed to call Close?";
438#endif
[email protected]676126f72011-01-15 00:03:51439
440 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
441 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59442}
443
444/*static*/
445void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49446 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59447 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
448 if (!visitor->Visit(it->second))
449 return;
450 }
451}
452
453/*static*/
454RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49455 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59456 ViewMap::iterator it = views->find(webview);
457 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29458}
459
460/*static*/
[email protected]0aa55312008-10-17 21:53:08461RenderView* RenderView::Create(
[email protected]18bcc3c2009-01-27 21:39:15462 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08463 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51464 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08465 const WebPreferences& webkit_prefs,
466 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34467 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26468 int64 session_storage_namespace_id,
469 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29470 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51471 return new RenderView(
[email protected]676126f72011-01-15 00:03:51472 parent_hwnd,
473 opener_id,
474 renderer_prefs,
475 webkit_prefs,
476 counter,
477 routing_id,
478 session_storage_namespace_id,
479 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29480}
481
[email protected]bb461532010-11-26 21:50:23482// static
initial.commit09911bf2008-07-26 23:55:29483void RenderView::SetNextPageID(int32 next_page_id) {
484 // This method should only be called during process startup, and the given
485 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05486 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29487 DCHECK(next_page_id >= next_page_id_);
488 next_page_id_ = next_page_id;
489}
490
[email protected]676126f72011-01-15 00:03:51491void RenderView::AddObserver(RenderViewObserver* observer) {
492 observers_.AddObserver(observer);
493}
494
495void RenderView::RemoveObserver(RenderViewObserver* observer) {
496 observer->set_render_view(NULL);
497 observers_.RemoveObserver(observer);
498}
499
[email protected]8a3125a712010-08-09 18:58:51500WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26501 return static_cast<WebKit::WebView*>(webwidget());
502}
503
[email protected]1a3c3cb2010-12-16 21:03:40504void RenderView::SetReportLoadProgressEnabled(bool enabled) {
505 if (!enabled) {
506 load_progress_tracker_.reset(NULL);
507 return;
508 }
509 if (load_progress_tracker_ == NULL)
510 load_progress_tracker_.reset(new LoadProgressTracker(this));
511}
512
[email protected]a3a8fb6d2009-10-22 20:12:51513void RenderView::PluginCrashed(const FilePath& plugin_path) {
514 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29515}
516
[email protected]aad51d1c2010-08-05 08:38:09517WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
518 const WebPluginParams& params) {
[email protected]91d9f3d2011-08-14 05:24:44519 webkit::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26520 std::string mime_type;
[email protected]4a7d6392011-09-19 20:55:08521 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
522 params.mimeType.utf8(), &info, &mime_type);
[email protected]dfba8762011-09-02 12:49:54523 if (!found)
[email protected]aad51d1c2010-08-05 08:38:09524 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45525
[email protected]96dcc1762011-04-04 16:01:09526 bool pepper_plugin_was_registered = false;
[email protected]0bd753682010-12-16 18:15:52527 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]076117592011-08-17 03:16:41528 pepper_delegate_.CreatePepperPluginModule(info,
529 &pepper_plugin_was_registered));
[email protected]96dcc1762011-04-04 16:01:09530 if (pepper_plugin_was_registered) {
531 if (pepper_module)
532 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
533 return NULL;
534 }
[email protected]1a78d9f32010-12-08 06:38:45535 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09536}
537
[email protected]d8fd6fa2010-02-01 15:54:26538void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
539 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30540 // If the renderer is visible, set initial visibility and focus state.
541 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34542#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30543 delegate->SetContainerVisibility(true);
544 if (webview() && webview()->isActive())
545 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34546#endif
[email protected]49232292010-09-03 19:07:30547 }
[email protected]784ea1ab2010-09-18 00:02:34548 // Plugins start assuming the content has focus (so that they work in
549 // environments where RenderView isn't hosting them), so we always have to
550 // set the initial state. See webplugin_delegate_impl.h for details.
551 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26552}
553
554void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
555 plugin_delegates_.erase(delegate);
556}
[email protected]d8fd6fa2010-02-01 15:54:26557
[email protected]4a7d6392011-09-19 20:55:08558bool RenderView::GetPluginInfo(const GURL& url,
559 const GURL& page_url,
560 const std::string& mime_type,
561 webkit::WebPluginInfo* plugin_info,
562 std::string* actual_mime_type) {
563 bool found = false;
564 Send(new ViewHostMsg_GetPluginInfo(
565 routing_id_, url, page_url, mime_type, &found, plugin_info,
566 actual_mime_type));
567 return found;
568}
569
570base::SharedMemoryHandle RenderView::HostAllocateSharedMemoryBuffer(
571 uint32 buffer_size) {
572 base::SharedMemoryHandle mem_handle;
573 Send(new ViewHostMsg_AllocateSharedMemoryBuffer(buffer_size, &mem_handle));
574 return mem_handle;
575}
576
[email protected]a95986a82010-12-24 06:19:28577bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27578 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27579 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41580 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26581
[email protected]676126f72011-01-15 00:03:51582 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
583 RenderViewObserver* observer;
584 while ((observer = it.GetNext()) != NULL)
585 if (observer->OnMessageReceived(message))
586 return true;
[email protected]b2abac72009-02-26 12:39:28587
[email protected]a95986a82010-12-24 06:19:28588 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40589 bool msg_is_ok = true;
590 IPC_BEGIN_MESSAGE_MAP_EX(RenderView, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29591 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
592 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56593 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29594 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
595 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
596 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
597 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27598#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35599 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27600#endif
initial.commit09911bf2008-07-26 23:55:29601 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
602 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
603 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
604 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08605 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29606 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15607 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29608 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49609 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
610 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17611 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17612 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:54613 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
614 OnSetZoomLevelForLoadingURL)
[email protected]8a5e0ca2011-08-25 06:30:47615 IPC_MESSAGE_HANDLER(ViewMsg_ExitFullscreen, OnExitFullscreen)
initial.commit09911bf2008-07-26 23:55:29616 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18617 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
618 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29619 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48620 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29621 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55622 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
623 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
624 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
625 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
626 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
627 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
628 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45629 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40630 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29631 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19632 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
633 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29634 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
635 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
636 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51637 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
638 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29639 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04640 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15641 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29642 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
643 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08644 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
645 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00646 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16647 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14648 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25649 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
650 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10651 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
652 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51653 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56654 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34655 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14656#if defined(OS_MACOSX)
657 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13658 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13659 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
660 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14661#endif
[email protected]446705872009-09-10 07:22:48662 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33663 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33664 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
665 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24666 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42667 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
668 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19669 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
670 OnGetAllSavableResourceLinksForCurrentPage)
671 IPC_MESSAGE_HANDLER(
672 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
673 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08674#if defined(OS_MACOSX)
675 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
676#endif
[email protected]521b2482011-01-15 00:10:10677 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51678 // TODO(viettrungluu): Move to a separate message filter.
679#if defined(ENABLE_FLAPPER_HACKS)
680 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
681#endif
[email protected]54ca3ca892011-06-07 21:14:54682#if defined(OS_MACOSX)
683 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
684#endif
[email protected]08bb1e722011-07-30 19:13:04685 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRemoteAccessClientFirewallTraversal,
686 OnUpdateRemoteAccessClientFirewallTraversal)
[email protected]9e1ad4b2011-08-14 16:49:19687 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
688 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18689 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]67bfb83f2011-09-22 03:36:37690 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
691 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
[email protected]9e1ad4b2011-08-14 16:49:19692
initial.commit09911bf2008-07-26 23:55:29693 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28694 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29695 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40696
697 if (!msg_is_ok) {
698 // The message had a handler, but its deserialization failed.
699 // Kill the renderer to avoid potential spoofing attacks.
700 CHECK(false) << "Unable to deserialize message in RenderView.";
701 }
702
[email protected]a95986a82010-12-24 06:19:28703 return handled;
initial.commit09911bf2008-07-26 23:55:29704}
705
initial.commit09911bf2008-07-26 23:55:29706void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
707 if (!webview())
708 return;
709
[email protected]440a0e52011-09-13 17:38:58710 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
711
[email protected]d466b8a2011-07-15 21:48:03712 bool is_reload =
713 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
714 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
715
716 // If this is a stale back/forward (due to a recent navigation the browser
717 // didn't know about), ignore it.
718 if (IsBackForwardToStaleEntry(params, is_reload))
719 return;
720
[email protected]992db4c2011-05-12 15:37:15721 // Swap this renderer back in if necessary.
722 if (is_swapped_out_)
723 SetSwappedOut(false);
724
[email protected]3cc72b12010-03-18 23:03:00725 history_list_offset_ = params.current_history_list_offset;
726 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03727 if (history_list_length_ >= 0)
728 history_page_ids_.resize(history_list_length_, -1);
729 if (params.pending_history_list_offset >= 0 &&
730 params.pending_history_list_offset < history_list_length_)
731 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00732
[email protected]38b592902011-04-16 02:08:42733 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29734
[email protected]26aa0482009-09-30 16:55:27735 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45736 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29737 // We cannot reload if we do not have any history state. This happens, for
738 // example, when recovering from a crash. Our workaround here is a bit of
739 // a hack since it means that reload after a crashed tab does not cause an
740 // end-to-end cache validation.
741 is_reload = false;
742 }
743
[email protected]77f17a82009-05-21 04:42:54744 // A navigation resulting from loading a javascript URL should not be treated
745 // as a browser initiated event. Instead, we want it to look as if the page
746 // initiated any load resulting from JS execution.
747 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30748 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00749 params.page_id,
750 params.pending_history_list_offset,
751 params.transition,
752 params.request_time);
[email protected]2c5569662011-03-22 20:45:02753 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30754 // We're doing a load of a page that was restored from the last session.
755 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
756 // which can result in stale data for pages that are set to expire. We
757 // explicitly override that by setting the policy here so that as
758 // necessary we load from the network.
759 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
760 }
761 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54762 }
initial.commit09911bf2008-07-26 23:55:29763
[email protected]a7ccc4d2010-01-27 08:14:48764 NavigationState* navigation_state = pending_navigation_state_.get();
765
[email protected]48a5c772011-04-18 23:50:50766 if (navigation_state) {
767 // New loads need to reset the error page fetcher. Otherwise if there is an
768 // outstanding error page fetcher it may complete and clobber the current
769 // page load.
770 navigation_state->set_alt_error_page_fetcher(NULL);
771 }
772
[email protected]04d3c6e2009-05-22 17:00:13773 // If we are reloading, then WebKit will use the history state of the current
774 // page, so we should just ignore any given history state. Otherwise, if we
775 // have history state, then we need to navigate to it, which corresponds to a
776 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55777 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48778 if (navigation_state)
779 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29780 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02781 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29782 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55783 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13784 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58785 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48786 if (navigation_state)
787 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45788 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17789 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13790 } else {
791 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28792 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29793
[email protected]e6f546c32009-07-01 17:12:55794 // A session history navigation should have been accompanied by state.
795 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13796
[email protected]dd7daa82009-08-10 05:46:45797 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55798 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13799
[email protected]726985e22009-06-18 21:09:28800 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17801 if (!WebSecurityPolicy::shouldHideReferrer(
802 params.url,
803 WebString::fromUTF8(params.referrer.spec()))) {
804 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
805 WebString::fromUTF8(params.referrer.spec()));
806 }
[email protected]726985e22009-06-18 21:09:28807 }
[email protected]04d3c6e2009-05-22 17:00:13808
[email protected]52c68652010-12-07 17:47:04809 if (!params.extra_headers.empty()) {
810 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
811 params.extra_headers.end(), "\n");
812 i.GetNext(); ) {
813 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
814 WebString::fromUTF8(i.values()));
815 }
816 }
817
[email protected]16e923d2011-04-30 00:41:44818 if (navigation_state)
819 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45820 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50821 }
822
[email protected]77f17a82009-05-21 04:42:54823 // In case LoadRequest failed before DidCreateDataSource was called.
824 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29825}
826
[email protected]d466b8a2011-07-15 21:48:03827bool RenderView::IsBackForwardToStaleEntry(
828 const ViewMsg_Navigate_Params& params,
829 bool is_reload) {
830 // Make sure this isn't a back/forward to an entry we have already cropped
831 // or replaced from our history, before the browser knew about it. If so,
832 // a new navigation has committed in the mean time, and we can ignore this.
833 bool is_back_forward = !is_reload && !params.state.empty();
834
835 // Note: if the history_list_length_ is 0 for a back/forward, we must be
836 // restoring from a previous session. We'll update our state in OnNavigate.
837 if (!is_back_forward || history_list_length_ <= 0)
838 return false;
839
840 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
841
842 // Check for whether the forward history has been cropped due to a recent
843 // navigation the browser didn't know about.
844 if (params.pending_history_list_offset >= history_list_length_)
845 return true;
846
847 // Check for whether this entry has been replaced with a new one.
848 int expected_page_id =
849 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44850 if (expected_page_id > 0 && params.page_id != expected_page_id) {
851 if (params.page_id < expected_page_id)
852 return true;
853
854 // Otherwise we've removed an earlier entry and should have shifted all
855 // entries left. For now, it's ok to lazily update the list.
856 // TODO(creis): Notify all live renderers when we remove entries from
857 // the front of the list, so that we don't hit this case.
858 history_page_ids_[params.pending_history_list_offset] = params.page_id;
859 }
[email protected]d466b8a2011-07-15 21:48:03860
861 return false;
862}
863
initial.commit09911bf2008-07-26 23:55:29864// Stop loading the current page
865void RenderView::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44866 if (webview()) {
867 WebFrame* main_frame = webview()->mainFrame();
868 // Stop the alt error page fetcher. If we let it continue it may complete
869 // and cause RenderViewHostManager to swap to this RenderView, even though
870 // it may no longer be active.
871 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
872 StopAltErrorPageFetcher(main_frame->dataSource());
873 main_frame->stopLoading();
874 }
initial.commit09911bf2008-07-26 23:55:29875}
876
[email protected]ecbf10d2010-02-18 13:03:29877// Reload current focused frame.
878// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56879void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29880 if (webview() && webview()->focusedFrame()) {
881 // We always obey the cache (ignore_cache=false) here.
882 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
883 // a cache-ignoring reload of the frame.
884 webview()->focusedFrame()->reload(false);
885 }
[email protected]1dda4022010-01-28 18:24:56886}
887
initial.commit09911bf2008-07-26 23:55:29888void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27889 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29890}
891
[email protected]68b1e922009-06-23 16:00:25892void RenderView::OnExecuteEditCommand(const std::string& name,
893 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27894 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25895 return;
896
[email protected]26aa0482009-09-30 16:55:27897 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45898 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25899}
900
initial.commit09911bf2008-07-26 23:55:29901void RenderView::OnUpdateTargetURLAck() {
902 // Check if there is a targeturl waiting to be sent.
903 if (target_url_status_ == TARGET_PENDING) {
904 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
905 pending_target_url_));
906 }
907
908 target_url_status_ = TARGET_NONE;
909}
910
911void RenderView::OnUndo() {
912 if (!webview())
913 return;
914
[email protected]26aa0482009-09-30 16:55:27915 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29916}
917
918void RenderView::OnRedo() {
919 if (!webview())
920 return;
921
[email protected]26aa0482009-09-30 16:55:27922 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29923}
924
925void RenderView::OnCut() {
926 if (!webview())
927 return;
928
[email protected]26aa0482009-09-30 16:55:27929 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29930}
931
932void RenderView::OnCopy() {
933 if (!webview())
934 return;
935
[email protected]f6b1856b2011-06-29 22:02:53936 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
937 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29938}
939
[email protected]c0cc3092009-09-12 08:27:27940#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35941void RenderView::OnCopyToFindPboard() {
942 if (!webview())
943 return;
944
945 // Since the find pasteboard supports only plain text, this can be simpler
946 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27947 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35948 if (frame->hasSelection()) {
949 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:27950 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:17951 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35952 }
[email protected]a954bf72009-09-12 07:30:35953}
[email protected]c0cc3092009-09-12 08:27:27954#endif
[email protected]a954bf72009-09-12 07:30:35955
initial.commit09911bf2008-07-26 23:55:29956void RenderView::OnPaste() {
957 if (!webview())
958 return;
959
[email protected]26aa0482009-09-30 16:55:27960 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29961}
962
[email protected]2a3a7762009-10-19 19:17:32963void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29964 if (!webview())
965 return;
966
[email protected]1ff7a032010-02-03 02:46:03967 WebFrame* frame = webview()->focusedFrame();
968 if (!frame->hasSelection())
969 frame->selectWordAroundCaret();
970 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29971}
972
973void RenderView::OnDelete() {
974 if (!webview())
975 return;
976
[email protected]26aa0482009-09-30 16:55:27977 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29978}
979
980void RenderView::OnSelectAll() {
981 if (!webview())
982 return;
983
[email protected]26aa0482009-09-30 16:55:27984 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22985 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29986}
987
[email protected]4fb60142011-08-09 02:22:08988void RenderView::OnSelectRange(const gfx::Point& start, const gfx::Point& end) {
989 if (!webview())
990 return;
991
992 handling_select_range_ = true;
993 webview()->focusedFrame()->selectRange(start, end);
994 handling_select_range_ = false;
995}
996
[email protected]9e1ad4b2011-08-14 16:49:19997void RenderView::OnSetHistoryLengthAndPrune(int history_length,
998 int32 minimum_page_id) {
999 DCHECK(history_length >= 0);
1000 DCHECK(history_list_offset_ == history_list_length_ - 1);
1001 DCHECK(minimum_page_id >= -1);
1002
1003 // Generate the new list.
1004 std::vector<int32> new_history_page_ids(history_length, -1);
1005 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1006 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1007 continue;
1008 new_history_page_ids.push_back(history_page_ids_[i]);
1009 }
1010 new_history_page_ids.swap(history_page_ids_);
1011
1012 // Update indexes.
1013 history_list_length_ = history_page_ids_.size();
1014 history_list_offset_ = history_list_length_ - 1;
1015}
1016
1017
initial.commit09911bf2008-07-26 23:55:291018void RenderView::OnSetInitialFocus(bool reverse) {
1019 if (!webview())
1020 return;
[email protected]26aa0482009-09-30 16:55:271021 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291022}
1023
[email protected]54ca3ca892011-06-07 21:14:541024#if defined(OS_MACOSX)
1025void RenderView::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331026 if (!webview())
1027 return;
1028 if (in_live_resize)
1029 webview()->willStartLiveResize();
1030 else
1031 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541032}
1033#endif
1034
[email protected]333ec8d02011-09-16 18:59:191035void RenderView::OnScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091036 WebKit::WebNode node = GetFocusedNode();
1037 if (!node.isNull()) {
1038 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191039 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511040 }
1041}
1042
initial.commit09911bf2008-07-26 23:55:291043///////////////////////////////////////////////////////////////////////////////
1044
1045// Tell the embedding application that the URL of the active page has changed
1046void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451047 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291048 DCHECK(ds);
1049
[email protected]726985e22009-06-18 21:09:281050 const WebURLRequest& request = ds->request();
1051 const WebURLRequest& original_request = ds->originalRequest();
1052 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291053
[email protected]daa8c58e2009-06-15 17:21:101054 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1055 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291056
1057 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281058 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291059 params.is_post = false;
1060 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071061 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191062 params.socket_address.set_host(response.remoteIPAddress().utf8());
1063 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031064 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091065 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551066 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291067 // SSL state specified in the request takes precedence over the one in the
1068 // response.
1069 // So far this is only intended for error pages that are not expected to be
1070 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281071 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551072 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291073 } else {
[email protected]726985e22009-06-18 21:09:281074 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291075 }
1076
1077 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281078 if (ds->hasUnreachableURL()) {
1079 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291080 } else {
[email protected]726985e22009-06-18 21:09:281081 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291082 }
1083
[email protected]726985e22009-06-18 21:09:281084 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241085 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041086 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291087
[email protected]ce0e250d2009-10-23 21:00:351088 params.searchable_form_url = navigation_state->searchable_form_url();
1089 params.searchable_form_encoding =
1090 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291091
1092 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101093 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291094 if (password_form_data)
1095 params.password_form = *password_form_data;
1096
1097 params.gesture = navigation_gesture_;
1098 navigation_gesture_ = NavigationGestureUnknown;
1099
[email protected]0f38dc4552011-02-25 11:24:001100 // Make navigation state a part of the FrameNavigate message so that commited
1101 // entry had it at all times.
1102 const WebHistoryItem& item = frame->currentHistoryItem();
1103 if (!item.isNull()) {
1104 params.content_state = webkit_glue::HistoryItemToString(item);
1105 } else {
1106 params.content_state =
1107 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1108 }
1109
[email protected]dd7daa82009-08-10 05:46:451110 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291111 // Top-level navigation.
1112
[email protected]b75b8292010-10-01 07:28:251113 // Set zoom level, but don't do it for full-page plugin since they don't use
1114 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011115 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541116 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251117 if (webview()->mainFrame()->document().isPluginDocument()) {
1118 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251119 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251120 } else {
1121 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251122 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251123 }
1124
[email protected]f85f0702010-01-30 09:31:011125 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511126 // This zoom level was merely recorded transiently for this load. We can
1127 // erase it now. If at some point we reload this page, the browser will
1128 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011129 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511130 }
1131
[email protected]b75b8292010-10-01 07:28:251132 // Reset the zoom limits in case a plugin had changed them previously. This
1133 // will also call us back which will cause us to send a message to
1134 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251135 webview()->zoomLimitsChanged(
1136 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1137 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251138
initial.commit09911bf2008-07-26 23:55:291139 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551140 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291141
[email protected]daa8c58e2009-06-15 17:21:101142 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291143 if (!PageTransition::IsMainFrame(params.transition)) {
1144 // If the main frame does a load, it should not be reported as a subframe
1145 // navigation. This can occur in the following case:
1146 // 1. You're on a site with frames.
1147 // 2. You do a subframe navigation. This is stored with transition type
1148 // MANUAL_SUBFRAME.
1149 // 3. You navigate to some non-frame site, say, google.com.
1150 // 4. You navigate back to the page from step 2. Since it was initially
1151 // MANUAL_SUBFRAME, it will be that same transition type here.
1152 // We don't want that, because any navigation that changes the toplevel
1153 // frame should be tracked as a toplevel navigation (this allows us to
1154 // update the URL bar, etc).
1155 params.transition = PageTransition::LINK;
1156 }
1157
initial.commit09911bf2008-07-26 23:55:291158 // If we have a valid consumed client redirect source,
1159 // the page contained a client redirect (meta refresh, document.loc...),
1160 // so we set the referrer and transition to match.
1161 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041162 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291163 params.referrer = completed_client_redirect_src_;
1164 params.transition = static_cast<PageTransition::Type>(
1165 params.transition | PageTransition::CLIENT_REDIRECT);
1166 } else {
1167 // Bug 654101: the referrer will be empty on https->http transitions. It
1168 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281169 params.referrer = GURL(
1170 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291171 }
1172
[email protected]726985e22009-06-18 21:09:281173 string16 method = request.httpMethod();
1174 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291175 params.is_post = true;
1176
[email protected]c2a797d2009-09-21 16:46:321177 // Save some histogram data so we can compute the average memory used per
1178 // page load of the glyphs.
1179 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1180 webkit_glue::GetGlyphPageCount());
1181
[email protected]15cf526b2010-02-12 06:33:491182 // This message needs to be sent before any of allowScripts(),
1183 // allowImages(), allowPlugins() is called for the new page, so that when
1184 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1185 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291186 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1187 } else {
1188 // Subframe navigation: the type depends on whether this navigation
1189 // generated a new session history entry. When they do generate a session
1190 // history entry, it means the user initiated the navigation and we should
1191 // mark it as such. This test checks if this is the first time UpdateURL
1192 // has been called since WillNavigateToURL was called to initiate the load.
1193 if (page_id_ > last_page_id_sent_to_browser_)
1194 params.transition = PageTransition::MANUAL_SUBFRAME;
1195 else
1196 params.transition = PageTransition::AUTO_SUBFRAME;
1197
initial.commit09911bf2008-07-26 23:55:291198 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1199 }
1200
1201 last_page_id_sent_to_browser_ =
1202 std::max(last_page_id_sent_to_browser_, page_id_);
1203
1204 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101205 // we don't want the transition type to persist. Just clear it.
1206 navigation_state->set_transition_type(PageTransition::LINK);
initial.commit09911bf2008-07-26 23:55:291207}
1208
1209// Tell the embedding application that the title of the active page has changed
[email protected]750fcf872011-08-03 23:10:471210void RenderView::UpdateTitle(WebFrame* frame,
1211 const string16& title,
[email protected]a49e10b2011-08-01 23:57:461212 WebTextDirection title_direction) {
1213 // Ignore all but top level navigations.
1214 if (frame->parent())
1215 return;
1216
1217 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1218 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1219 title_direction));
initial.commit09911bf2008-07-26 23:55:291220}
1221
1222void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401223 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291224 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271225 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291226 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301227 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291228 last_encoding_name_ = encoding_name;
1229
[email protected]e38f40152008-09-12 23:08:301230 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291231 }
1232}
1233
[email protected]e15f680732010-11-23 22:30:201234// Sends the last committed session history state to the browser so it will be
1235// saved before we navigate to a new page. This must be called *before* the
1236// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291237void RenderView::UpdateSessionHistory(WebFrame* frame) {
1238 // If we have a valid page ID at this point, then it corresponds to the page
1239 // we are navigating away from. Otherwise, this is the first navigation, so
1240 // there is no past session history to record.
1241 if (page_id_ == -1)
1242 return;
1243
[email protected]ca948a22009-06-25 19:36:171244 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271245 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171246 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291247 return;
[email protected]ca948a22009-06-25 19:36:171248
1249 Send(new ViewHostMsg_UpdateState(
1250 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291251}
1252
[email protected]ae5184d62011-10-06 19:25:581253void RenderView::OpenURL(WebFrame* frame,
1254 const GURL& url,
1255 const GURL& referrer,
1256 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171257 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581258 routing_id_,
1259 url,
1260 referrer,
1261 NavigationPolicyToDisposition(policy),
1262 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171263}
1264
[email protected]79dbc662009-09-04 05:42:511265// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291266
initial.commit09911bf2008-07-26 23:55:291267void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281268 const WebURLRequest& failed_request,
1269 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291270 const std::string& html,
1271 bool replace) {
[email protected]21d61e52011-03-18 19:08:251272 std::string alt_html = !html.empty() ? html :
1273 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1274 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451275 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361276 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251277 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551278 replace);
initial.commit09911bf2008-07-26 23:55:291279}
1280
initial.commit09911bf2008-07-26 23:55:291281bool RenderView::RunJavaScriptMessage(int type,
[email protected]4f5ce842011-05-27 19:34:411282 const string16& message,
1283 const string16& default_value,
[email protected]a455d3812009-03-05 20:18:071284 const GURL& frame_url,
[email protected]4f5ce842011-05-27 19:34:411285 string16* result) {
initial.commit09911bf2008-07-26 23:55:291286 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411287 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291288 if (!result)
1289 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291290
[email protected]12636df2009-09-28 22:32:211291 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1292 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291293 return success;
1294}
1295
[email protected]c1f50aa2010-02-18 03:46:571296bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1297 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1298 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1299 // it is particularly important that we do not call willEnterModalLoop as
1300 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441301 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1302 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571303
1304 message->EnableMessagePumping(); // Runs a nested message loop.
1305 return Send(message);
1306}
1307
[email protected]48c9cf2d2009-09-16 16:47:521308// WebKit::WebViewClient ------------------------------------------------------
1309
[email protected]844acf372011-01-14 10:49:271310WebView* RenderView::createView(
1311 WebFrame* creator,
1312 const WebURLRequest& request,
1313 const WebWindowFeatures& features,
1314 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521315 // Check to make sure we aren't overloading on popups.
1316 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1317 return NULL;
1318
[email protected]8ab04652010-06-12 02:47:261319 ViewHostMsg_CreateWindow_Params params;
1320 params.opener_id = routing_id_;
1321 params.user_gesture = creator->isProcessingUserGesture();
1322 params.window_container_type = WindowFeaturesToContainerType(features);
1323 params.session_storage_namespace_id = session_storage_namespace_id_;
1324 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111325 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411326 params.opener_url = creator->document().url();
1327 params.opener_security_origin =
1328 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111329 if (!request.isNull())
1330 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261331
[email protected]48c9cf2d2009-09-16 16:47:521332 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341333 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261334 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521335
[email protected]380244092011-10-07 17:26:271336 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261337 new ViewHostMsg_CreateWindow(params,
1338 &routing_id,
1339 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211340 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521341 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521342
[email protected]380244092011-10-07 17:26:271343 RenderView* view = RenderView::Create(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]380244092011-10-07 17:26:271370 RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521371 return widget->webwidget();
1372}
1373
1374WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441375 // TODO(jcivelli): Remove this deprecated method when its been removed from
1376 // the WebViewClient interface. It's been replaced by
1377 // createExternalPopupMenu.
1378 NOTREACHED();
1379 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521380}
1381
[email protected]caf706f2010-10-26 17:54:081382WebExternalPopupMenu* RenderView::createExternalPopupMenu(
1383 const WebPopupMenuInfo& popup_menu_info,
1384 WebExternalPopupMenuClient* popup_menu_client) {
1385 DCHECK(!external_popup_menu_.get());
1386 external_popup_menu_.reset(
1387 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1388 return external_popup_menu_.get();
1389}
1390
[email protected]ea192e82011-04-11 19:16:021391RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521392 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531393 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421394 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411395 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531396 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271397 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391398 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561399 return widget;
[email protected]79c7bed2010-09-14 22:28:391400}
1401
[email protected]68c50e52010-05-12 11:14:391402WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341403 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391404 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291405 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1406 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1407 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341408}
1409
[email protected]48c9cf2d2009-09-16 16:47:521410void RenderView::didAddMessageToConsole(
1411 const WebConsoleMessage& message, const WebString& source_name,
1412 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081413 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511414 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081415 case WebConsoleMessage::LevelTip:
1416 log_severity = logging::LOG_VERBOSE;
1417 break;
1418 case WebConsoleMessage::LevelLog:
1419 log_severity = logging::LOG_INFO;
1420 break;
1421 case WebConsoleMessage::LevelWarning:
1422 log_severity = logging::LOG_WARNING;
1423 break;
1424 case WebConsoleMessage::LevelError:
1425 log_severity = logging::LOG_ERROR;
1426 break;
1427 default:
1428 NOTREACHED();
1429 }
1430
[email protected]48c9cf2d2009-09-16 16:47:521431 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081432 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311433 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521434 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311435 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521436}
1437
1438void RenderView::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421439 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521440}
1441
[email protected]3354d3e2010-06-10 19:53:021442WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511443 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021444}
1445
[email protected]8a58c1c2011-04-19 18:40:121446bool RenderView::enumerateChosenDirectory(
1447 const WebString& path,
1448 WebFileChooserCompletion* chooser_completion) {
1449 int id = enumeration_completion_id_++;
1450 enumeration_completions_[id] = chooser_completion;
1451 return Send(new ViewHostMsg_EnumerateDirectory(
1452 routing_id_,
1453 id,
1454 webkit_glue::WebStringToFilePath(path)));
1455}
1456
[email protected]48c9cf2d2009-09-16 16:47:521457void RenderView::didStartLoading() {
1458 if (is_loading_) {
1459 DLOG(WARNING) << "didStartLoading called while loading";
1460 return;
1461 }
1462
1463 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521464
1465 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311466
1467 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521468}
1469
1470void RenderView::didStopLoading() {
1471 if (!is_loading_) {
1472 DLOG(WARNING) << "DidStopLoading called while not loading";
1473 return;
1474 }
1475
1476 is_loading_ = false;
1477
1478 // NOTE: For now we're doing the safest thing, and sending out notification
1479 // when done loading. This currently isn't an issue as the favicon is only
1480 // displayed when done loading. Ideally we would send notification when
1481 // finished parsing the head, but webkit doesn't support that yet.
1482 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521483 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1484
[email protected]90109412010-12-15 17:14:241485 if (load_progress_tracker_ != NULL)
1486 load_progress_tracker_->DidStopLoading();
1487
[email protected]93b9d692011-04-13 00:44:311488 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521489}
1490
[email protected]90109412010-12-15 17:14:241491void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
1492 if (load_progress_tracker_ != NULL)
1493 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1494}
1495
[email protected]f55039a2010-02-17 14:12:061496bool RenderView::isSmartInsertDeleteEnabled() {
1497#if defined(OS_MACOSX)
1498 return true;
1499#else
1500 return false;
1501#endif
1502}
1503
[email protected]04fc9482009-09-18 22:13:031504bool RenderView::isSelectTrailingWhitespaceEnabled() {
1505#if defined(OS_WIN)
1506 return true;
1507#else
1508 return false;
1509#endif
1510}
1511
[email protected]04fc9482009-09-18 22:13:031512void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:421513#if defined(OS_POSIX)
[email protected]4fb60142011-08-09 02:22:081514 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031515 return;
[email protected]4fb60142011-08-09 02:22:081516 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011517
[email protected]b781ff282011-08-20 06:19:361518 SyncSelectionIfRequired();
[email protected]0ff0ff32010-12-21 19:34:421519#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031520}
1521
1522void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121523 const std::string& name = UTF16ToUTF8(command_name);
1524 if (StartsWithASCII(name, "Move", true) ||
1525 StartsWithASCII(name, "Insert", true) ||
1526 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031527 return;
[email protected]f1a29a02011-10-06 23:08:441528 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031529}
1530
[email protected]b2528b72009-09-24 06:57:101531bool RenderView::handleCurrentKeyboardEvent() {
1532 if (edit_commands_.empty())
1533 return false;
1534
[email protected]26aa0482009-09-30 16:55:271535 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101536 if (!frame)
1537 return false;
1538
1539 EditCommands::iterator it = edit_commands_.begin();
1540 EditCommands::iterator end = edit_commands_.end();
1541
[email protected]507b33ea2009-09-29 03:56:511542 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101543 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331544 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1545 // key (but it's the exception). Once one edit command is not executed, it
1546 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101547 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1548 WebString::fromUTF8(it->value)))
1549 break;
[email protected]507b33ea2009-09-29 03:56:511550 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101551 }
1552
[email protected]507b33ea2009-09-29 03:56:511553 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101554}
1555
[email protected]a1128322009-10-06 18:38:461556bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351557 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471558 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351559 // Do not open the file dialog in a hidden RenderView.
1560 if (is_hidden())
1561 return false;
[email protected]cdaf8d02010-03-30 19:52:471562 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261563 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361564 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261565 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361566 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]b5977a0c2010-08-24 19:46:261567 else
[email protected]0aed2f52011-03-23 18:06:361568 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471569 ipc_params.title = params.title;
1570 ipc_params.default_file_name =
1571 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591572 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471573
1574 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461575}
1576
[email protected]48c9cf2d2009-09-16 16:47:521577void RenderView::runModalAlertDialog(
1578 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061579 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]4f5ce842011-05-27 19:34:411580 message,
1581 string16(),
[email protected]b6cb3a842011-06-24 18:28:411582 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521583 NULL);
1584}
1585
1586bool RenderView::runModalConfirmDialog(
1587 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061588 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]4f5ce842011-05-27 19:34:411589 message,
1590 string16(),
[email protected]b6cb3a842011-06-24 18:28:411591 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521592 NULL);
1593}
1594
1595bool RenderView::runModalPromptDialog(
1596 WebFrame* frame, const WebString& message, const WebString& default_value,
1597 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411598 string16 result;
[email protected]9dd7e3d72011-01-20 18:27:061599 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]4f5ce842011-05-27 19:34:411600 message,
1601 default_value,
[email protected]b6cb3a842011-06-24 18:28:411602 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521603 &result);
1604 if (ok)
[email protected]4f5ce842011-05-27 19:34:411605 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521606 return ok;
1607}
1608
1609bool RenderView::runModalBeforeUnloadDialog(
1610 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151611 // If we are swapping out, we have already run the beforeunload handler.
1612 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1613 // at all, to avoid running it twice.
1614 if (is_swapped_out_)
1615 return true;
1616
[email protected]48c9cf2d2009-09-16 16:47:521617 bool success = false;
1618 // This is an ignored return value, but is included so we can accept the same
1619 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411620 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211621 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411622 routing_id_, frame->document().url(), message,
1623 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521624 return success;
1625}
1626
[email protected]79e37442009-10-09 18:17:441627void RenderView::showContextMenu(
1628 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291629 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371630
1631 // frame is NULL if invoked by BlockedPlugin.
1632 if (frame)
1633 params.frame_id = frame->identifier();
1634
[email protected]db803aae2011-03-05 02:00:421635 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271636 // it. We replace it with an empty GURL so the appropriate items are disabled
1637 // in the context menu.
1638 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1639 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421640 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271641 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101642 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291643 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441644}
1645
[email protected]52f139e2c2010-06-11 16:56:091646bool RenderView::supportsFullscreen() {
1647 return CommandLine::ForCurrentProcess()->HasSwitch(
1648 switches::kEnableVideoFullscreen);
1649}
1650
1651void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1652 NOTIMPLEMENTED();
1653}
1654
1655void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1656 NOTIMPLEMENTED();
1657}
1658
[email protected]8a5e0ca2011-08-25 06:30:471659void RenderView::enterFullscreen() {
1660 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1661}
1662
1663void RenderView::exitFullscreen() {
1664 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1665}
1666
[email protected]48c9cf2d2009-09-16 16:47:521667void RenderView::setStatusText(const WebString& text) {
1668}
1669
[email protected]163f8242009-10-30 20:19:551670void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581671 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521672 if (latest_url == target_url_)
1673 return;
[email protected]163f8242009-10-30 20:19:551674
[email protected]48c9cf2d2009-09-16 16:47:521675 // Tell the browser to display a destination link.
1676 if (target_url_status_ == TARGET_INFLIGHT ||
1677 target_url_status_ == TARGET_PENDING) {
1678 // If we have a request in-flight, save the URL to be sent when we
1679 // receive an ACK to the in-flight request. We can happily overwrite
1680 // any existing pending sends.
1681 pending_target_url_ = latest_url;
1682 target_url_status_ = TARGET_PENDING;
1683 } else {
1684 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1685 target_url_ = latest_url;
1686 target_url_status_ = TARGET_INFLIGHT;
1687 }
1688}
1689
[email protected]882daa92009-11-05 16:31:311690void RenderView::StartNavStateSyncTimerIfNecessary() {
1691 int delay;
1692 if (send_content_state_immediately_)
1693 delay = 0;
1694 else if (is_hidden())
1695 delay = kDelaySecondsForContentStateSyncHidden;
1696 else
1697 delay = kDelaySecondsForContentStateSync;
1698
1699 if (nav_state_sync_timer_.IsRunning()) {
1700 // The timer is already running. If the delay of the timer maches the amount
1701 // we want to delay by, then return. Otherwise stop the timer so that it
1702 // gets started with the right delay.
1703 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1704 return;
1705 nav_state_sync_timer_.Stop();
1706 }
1707
[email protected]d323a172011-09-02 18:23:021708 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1709 &RenderView::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311710}
1711
[email protected]163f8242009-10-30 20:19:551712void RenderView::setMouseOverURL(const WebURL& url) {
1713 mouse_over_url_ = GURL(url);
1714 UpdateTargetURL(mouse_over_url_, focus_url_);
1715}
1716
1717void RenderView::setKeyboardFocusURL(const WebURL& url) {
1718 focus_url_ = GURL(url);
1719 UpdateTargetURL(focus_url_, mouse_over_url_);
1720}
1721
[email protected]c27ae592010-03-18 15:24:411722void RenderView::startDragging(const WebDragData& data,
1723 WebDragOperationsMask mask,
1724 const WebImage& image,
1725 const WebPoint& imageOffset) {
1726#if WEBKIT_USING_SKIA
1727 SkBitmap bitmap(image.getSkBitmap());
1728#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331729 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411730#endif
1731
[email protected]59f4f2fa2011-03-23 01:00:551732 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521733 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411734 mask,
1735 bitmap,
1736 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521737}
1738
[email protected]28b92df2009-09-25 17:35:451739bool RenderView::acceptsLoadDrops() {
1740 return renderer_preferences_.can_accept_load_drops;
1741}
1742
[email protected]48c9cf2d2009-09-16 16:47:521743void RenderView::focusNext() {
1744 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1745}
1746
1747void RenderView::focusPrevious() {
1748 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1749}
1750
[email protected]08e9e132010-06-01 16:58:491751void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511752 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071753
[email protected]38b592902011-04-16 02:08:421754 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491755}
1756
[email protected]48c9cf2d2009-09-16 16:47:521757void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521758 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1759}
1760
1761int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001762 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521763}
1764
1765int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001766 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521767}
1768
[email protected]063afcb2011-09-29 07:54:321769void RenderView::postAccessibilityNotification(
1770 const WebAccessibilityObject& obj,
1771 WebAccessibilityNotification notification) {
1772 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1773}
1774
[email protected]c4e98902010-06-01 10:20:141775void RenderView::didUpdateInspectorSetting(const WebString& key,
1776 const WebString& value) {
1777 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1778 key.utf8(),
1779 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261780}
1781
[email protected]79dbc662009-09-04 05:42:511782// WebKit::WebWidgetClient ----------------------------------------------------
1783
[email protected]ea42e7782010-08-23 23:58:121784void RenderView::didFocus() {
1785 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1786 // we won't have to test for user gesture anymore and we can
1787 // move that code back to render_widget.cc
1788 if (webview() && webview()->mainFrame() &&
1789 webview()->mainFrame()->isProcessingUserGesture()) {
1790 Send(new ViewHostMsg_Focus(routing_id_));
1791 }
1792}
1793
1794void RenderView::didBlur() {
1795 // TODO(jcivelli): see TODO above in didFocus().
1796 if (webview() && webview()->mainFrame() &&
1797 webview()->mainFrame()->isProcessingUserGesture()) {
1798 Send(new ViewHostMsg_Blur(routing_id_));
1799 }
1800}
1801
initial.commit09911bf2008-07-26 23:55:291802// We are supposed to get a single call to Show for a newly created RenderView
1803// that was created via RenderView::CreateWebView. So, we wait until this
1804// point to dispatch the ShowView message.
1805//
1806// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281807// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291808//
[email protected]4873c7d2009-07-16 06:36:281809void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291810 DCHECK(!did_show_) << "received extraneous Show call";
1811 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1812
1813 if (did_show_)
1814 return;
1815 did_show_ = true;
1816
[email protected]6779aa12011-03-29 17:32:241817 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041818 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041819
[email protected]28295ec2009-10-16 05:34:331820 // Force new windows to a popup if they were not opened with a user gesture.
1821 if (!opened_by_user_gesture_) {
1822 // We exempt background tabs for compat with older versions of Chrome.
1823 // TODO(darin): This seems bogus. These should have a user gesture, so
1824 // we probably don't need this check.
1825 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1826 policy = WebKit::WebNavigationPolicyNewPopup;
1827 }
1828
initial.commit09911bf2008-07-26 23:55:291829 // NOTE: initial_pos_ may still have its default values at this point, but
1830 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1831 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281832 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1833 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291834 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241835 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291836}
1837
[email protected]4873c7d2009-07-16 06:36:281838void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291839 DCHECK(did_show_) << "should already have shown the view";
1840
[email protected]c1f50aa2010-02-18 03:46:571841 // We must keep WebKit's shared timer running in this case in order to allow
1842 // showModalDialog to function properly.
1843 //
1844 // TODO(darin): WebKit should really be smarter about suppressing events and
1845 // timers so that we do not need to manage the shared timer in such a heavy
1846 // handed manner.
1847 //
[email protected]f1a29a02011-10-06 23:08:441848 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1849 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:571850
[email protected]12636df2009-09-28 22:32:211851 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291852}
1853
[email protected]3d9689372009-09-10 04:29:171854// WebKit::WebFrameClient -----------------------------------------------------
1855
[email protected]00152e92010-07-19 11:47:401856WebPlugin* RenderView::createPlugin(WebFrame* frame,
1857 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:551858 WebPlugin* plugin = NULL;
1859 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
1860 this, frame, params, &plugin)) {
1861 return plugin;
1862 }
1863
1864 return CreatePluginNoCheck(frame, params);
[email protected]3d9689372009-09-10 04:29:171865}
1866
1867WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561868 WebApplicationCacheHostImpl* appcache_host =
1869 WebApplicationCacheHostImpl::FromFrame(frame);
1870 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
[email protected]f1a29a02011-10-06 23:08:441871 return new WebWorkerProxy(client, RenderThreadImpl::current(), routing_id_,
[email protected]14396e92010-05-06 20:40:561872 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171873}
1874
[email protected]9c00f002009-11-05 22:37:421875WebSharedWorker* RenderView::createSharedWorker(
1876 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371877 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421878
[email protected]30447b62009-11-13 01:13:371879 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511880 bool exists = false;
[email protected]30447b62009-11-13 01:13:371881 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511882 ViewHostMsg_CreateWorker_Params params;
1883 params.url = url;
1884 params.is_shared = true;
1885 params.name = name;
1886 params.document_id = document_id;
1887 params.render_view_route_id = routing_id_;
1888 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231889 params.parent_appcache_host_id = 0;
1890 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371891 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511892 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371893 if (url_mismatch) {
1894 return NULL;
1895 } else {
[email protected]f1a29a02011-10-06 23:08:441896 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:491897 document_id,
[email protected]6de0bcf2010-02-17 22:00:511898 exists,
[email protected]30447b62009-11-13 01:13:371899 route_id,
1900 routing_id_);
1901 }
[email protected]9c00f002009-11-05 22:37:421902}
1903
[email protected]3d9689372009-09-10 04:29:171904WebMediaPlayer* RenderView::createMediaPlayer(
1905 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441906 FOR_EACH_OBSERVER(
1907 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171908
[email protected]f78d1dfc2011-01-15 07:09:271909 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1910 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491911 scoped_ptr<media::FilterCollection> collection(
1912 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371913
[email protected]3d9689372009-09-10 04:29:171914 // Add in any custom filter factories first.
1915 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1916 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1917 // Add the chrome specific audio renderer.
[email protected]f7eb0a392011-07-12 10:19:511918 collection->AddAudioRenderer(new AudioRendererImpl());
[email protected]3d9689372009-09-10 04:29:171919 }
1920
[email protected]457d8342010-10-23 01:20:371921 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:311922 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
1923 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
1924 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:491925 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:311926 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:111927
[email protected]a8e24d522010-12-01 07:13:581928 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:271929 new webkit_glue::WebMediaPlayerImpl(client,
1930 collection.release(),
[email protected]ab2c4732011-07-20 19:57:401931 message_loop_factory.release(),
[email protected]090f7312011-08-05 23:26:401932 media_stream_impl_.get(),
1933 new RenderMediaLog()));
[email protected]79684282010-12-06 21:15:461934 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:581935 cmd_line->HasSwitch(switches::kSimpleDataSource),
1936 video_renderer)) {
1937 return NULL;
1938 }
1939 return result.release();
[email protected]3d9689372009-09-10 04:29:171940}
1941
[email protected]035545f2010-04-09 13:10:211942WebApplicationCacheHost* RenderView::createApplicationCacheHost(
1943 WebFrame* frame, WebApplicationCacheHostClient* client) {
1944 return new RendererWebApplicationCacheHostImpl(
1945 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:441946 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:211947}
1948
[email protected]8ff181072010-11-29 17:09:381949WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
1950 return &cookie_jar_;
1951}
1952
[email protected]5041f982010-08-11 21:40:451953void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511954 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451955}
1956
[email protected]3d9689372009-09-10 04:29:171957void RenderView::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511958 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171959}
1960
1961void RenderView::loadURLExternally(
1962 WebFrame* frame, const WebURLRequest& request,
1963 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:341964 loadURLExternally(frame, request, policy, WebString());
1965}
1966
1967void RenderView::loadURLExternally(
1968 WebFrame* frame, const WebURLRequest& request,
1969 WebNavigationPolicy policy,
1970 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:591971 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1972 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:341973 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
1974 suggested_name));
[email protected]efce17b2009-09-11 18:04:591975 } else {
[email protected]ae5184d62011-10-06 19:25:581976 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:591977 }
[email protected]3d9689372009-09-10 04:29:171978}
1979
1980WebNavigationPolicy RenderView::decidePolicyForNavigation(
1981 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221982 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:151983 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
1984 if (is_swapped_out_) {
1985 DCHECK(request.url() == GURL("about:swappedout"));
1986 return default_policy;
1987 }
1988
[email protected]3d9689372009-09-10 04:29:171989 // Webkit is asking whether to navigate to a new URL.
1990 // This is fine normally, except if we're showing UI from one security
1991 // context and they're trying to navigate to a different context.
1992 const GURL& url = request.url();
1993
[email protected]d19ea342011-04-20 20:31:131994 // A content initiated navigation may have originated from a link-click,
1995 // script, drag-n-drop operation, etc.
1996 bool is_content_initiated =
1997 NavigationState::FromDataSource(frame->provisionalDataSource())->
1998 is_content_initiated();
1999
[email protected]3d9689372009-09-10 04:29:172000 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302001 // navigations.
[email protected]d19ea342011-04-20 20:31:132002 if (is_content_initiated &&
2003 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:452004 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192005 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232006 // Reset these counters as the RenderView could be reused for the next
2007 // navigation.
2008 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232009 last_page_id_sent_to_browser_ = -1;
[email protected]ae5184d62011-10-06 19:25:582010 OpenURL(frame, url, referrer, default_policy);
[email protected]61c9f032010-03-31 23:04:192011 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172012 }
2013
[email protected]6101c342010-12-16 22:44:372014 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552015 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572016 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372017 // opening a new window). But we sometimes navigate to about:blank to clear a
2018 // tab, and we want to still allow that.
2019 //
[email protected]8f4da8c2011-02-09 19:49:572020 // Note: we do this only for GET requests because our mechanism for switching
2021 // processes only issues GET requests. In particular, POST requests don't
2022 // work, because this mechanism does not preserve form POST data. If it
2023 // becomes necessary to support process switching for POST requests, we will
2024 // need to send the request's httpBody data up to the browser process, and
2025 // issue a special POST navigation in WebKit (via
2026 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2027 // for examples of how to send the httpBody data.
2028 // Note2: We normally don't do this for browser-initiated navigations, since
2029 // it's pointless to tell the browser about navigations it gave us. But
2030 // we do potentially ask the browser to handle a redirect that was originally
2031 // initiated by the browser. See http://crbug.com/70943
2032 //
2033 // TODO(creis): Move this redirect check to the browser process to avoid
2034 // ping-ponging. See http://crbug.com/72380.
2035 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372036 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2037 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2038 bool send_referrer = false;
2039 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552040 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172041 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372042 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112043
[email protected]e48869a2011-04-01 19:56:032044 if (!should_fork) {
2045 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362046 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032047 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362048 frame, url, is_content_initiated, is_initial_navigation,
2049 &send_referrer);
[email protected]6101c342010-12-16 22:44:372050 }
2051
2052 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112053 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]ae5184d62011-10-06 19:25:582054 OpenURL(frame, url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112055 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2056 }
[email protected]3d9689372009-09-10 04:29:172057 }
2058
[email protected]43763f982011-08-26 18:33:402059 // Use the frame's original request's URL rather than the document's URL for
2060 // this check. For a popup, the document's URL may become the opener window's
2061 // URL if the opener has called document.write. See http://crbug.com/93517.
2062 GURL old_url(frame->dataSource()->request().url());
2063
[email protected]3d9689372009-09-10 04:29:172064 // Detect when a page is "forking" a new tab that can be safely rendered in
2065 // its own process. This is done by sites like Gmail that try to open links
2066 // in new windows without script connections back to the original page. We
2067 // treat such cases as browser navigations (in which we will create a new
2068 // renderer for a cross-site navigation), rather than WebKit navigations.
2069 //
2070 // We use the following heuristic to decide whether to fork a new page in its
2071 // own process:
2072 // The parent page must open a new tab to about:blank, set the new tab's
2073 // window.opener to null, and then redirect the tab to a cross-site URL using
2074 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462075 //
2076 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2077 // (see below).
[email protected]3d9689372009-09-10 04:29:172078 bool is_fork =
2079 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582080 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172081 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522082 historyBackListCount() < 1 &&
2083 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172084 // The parent page must have set the child's window.opener to null before
2085 // redirecting to the desired URL.
2086 frame->opener() == NULL &&
2087 // Must be a top-level frame.
2088 frame->parent() == NULL &&
2089 // Must not have issued the request from this page.
2090 is_content_initiated &&
2091 // Must be targeted at the current tab.
2092 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2093 // Must be a JavaScript navigation, which appears as "other".
2094 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462095
2096 // Recognize if this navigation is from a link with rel=noreferrer and
2097 // target=_blank attributes, in which case the opener will be suppressed. If
2098 // so, it is safe to load cross-site pages in a separate process, so we
2099 // should let the browser handle it.
2100 bool is_noreferrer_and_blank_target =
2101 // Frame should be top level and not yet navigated.
2102 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412103 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462104 historyBackListCount() < 1 &&
2105 historyForwardListCount() < 1 &&
2106 // Links with rel=noreferrer will have no Referer field, and their
2107 // resulting frame will have its window.opener suppressed.
2108 // TODO(creis): should add a request.httpReferrer() method to help avoid
2109 // typos on the unusual spelling of Referer.
2110 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2111 opener_suppressed_ &&
2112 frame->opener() == NULL &&
2113 // Links with target=_blank will have no name.
2114 frame->name().isNull() &&
2115 // Another frame (with a non-empty creator) should have initiated the
2116 // request, targeted at this frame.
2117 !creator_url_.is_empty() &&
2118 is_content_initiated &&
2119 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2120 type == WebKit::WebNavigationTypeOther;
2121
2122 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172123 // Open the URL via the browser, not via WebKit.
[email protected]ae5184d62011-10-06 19:25:582124 OpenURL(frame, url, GURL(), default_policy);
[email protected]3d9689372009-09-10 04:29:172125 return WebKit::WebNavigationPolicyIgnore;
2126 }
2127
2128 return default_policy;
2129}
2130
[email protected]6069da8c2009-10-20 20:33:492131bool RenderView::canHandleRequest(
2132 WebFrame* frame, const WebURLRequest& request) {
2133 // We allow WebKit to think that everything can be handled even though
2134 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342135 return true;
2136}
2137
[email protected]6069da8c2009-10-20 20:33:492138WebURLError RenderView::cannotHandleRequestError(
2139 WebFrame* frame, const WebURLRequest& request) {
2140 NOTREACHED(); // Since we said we can handle all requests.
2141 return WebURLError();
2142}
2143
2144WebURLError RenderView::cancelledError(
2145 WebFrame* frame, const WebURLRequest& request) {
2146 WebURLError error;
2147 error.domain = WebString::fromUTF8(net::kErrorDomain);
2148 error.reason = net::ERR_ABORTED;
2149 error.unreachableURL = request.url();
2150 return error;
[email protected]7b7a7dc2009-10-19 02:23:342151}
2152
2153void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492154 WebFrame*, const WebURLError&) {
2155 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342156}
2157
[email protected]90eeddb2010-05-06 21:06:432158void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2159 const WebKit::WebFormElement& form) {
2160 // Some login forms have onSubmit handlers that put a hash of the password
2161 // into a hidden field and then clear the password. (Issue 28910.)
2162 // This method gets called before any of those handlers run, so save away
2163 // a copy of the password in case it gets lost.
2164 NavigationState* navigation_state =
2165 NavigationState::FromDataSource(frame->dataSource());
2166 navigation_state->set_password_form_data(
2167 PasswordFormDomManager::CreatePasswordForm(form));
2168}
2169
[email protected]979c28b2009-11-07 01:30:482170void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172171 NavigationState* navigation_state =
2172 NavigationState::FromDataSource(frame->provisionalDataSource());
2173
2174 if (navigation_state->transition_type() == PageTransition::LINK)
2175 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2176
2177 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352178 WebSearchableFormData web_searchable_form_data(form);
2179 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2180 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212181 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432182 PasswordForm* password_form_data =
2183 PasswordFormDomManager::CreatePasswordForm(form);
2184 navigation_state->set_password_form_data(password_form_data);
2185
[email protected]098c95cb2011-04-28 16:49:012186 // In order to save the password that the user actually typed and not one
2187 // that may have gotten transformed by the site prior to submit, recover it
2188 // from the form contents already stored by |willSendSubmitEvent| into the
2189 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2190 // which is what we're storing into now.)
2191 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432192 NavigationState* old_navigation_state =
2193 NavigationState::FromDataSource(frame->dataSource());
2194 if (old_navigation_state) {
2195 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2196 if (old_form_data && old_form_data->action == password_form_data->action)
2197 password_form_data->password_value = old_form_data->password_value;
2198 }
2199 }
[email protected]3d9689372009-09-10 04:29:172200
[email protected]2a5b1732011-04-01 23:55:552201 FOR_EACH_OBSERVER(
2202 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172203}
2204
2205void RenderView::willPerformClientRedirect(
2206 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2207 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382208 FOR_EACH_OBSERVER(
2209 RenderViewObserver, observers_,
2210 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172211}
2212
2213void RenderView::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382214 FOR_EACH_OBSERVER(
2215 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172216}
2217
2218void RenderView::didCompleteClientRedirect(
2219 WebFrame* frame, const WebURL& from) {
2220 if (!frame->parent())
2221 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382222 FOR_EACH_OBSERVER(
2223 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172224}
2225
2226void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2227 // The rest of RenderView assumes that a WebDataSource will always have a
2228 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482229 bool content_initiated = !pending_navigation_state_.get();
2230 NavigationState* state = content_initiated ?
2231 NavigationState::CreateContentInitiated() :
2232 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512233
[email protected]8a3125a712010-08-09 18:58:512234 // NavigationState::referred_by_prefetcher_ is true if we are
2235 // navigating from a page that used prefetching using a link on that
2236 // page. We are early enough in the request process here that we
2237 // can still see the NavigationState of the previous page and set
2238 // this value appropriately.
2239 // TODO(gavinp): catch the important case of navigation in a new
2240 // renderer process.
2241 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302242 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522243 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512244 const GURL referrer(
2245 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2246 if (!referrer.is_empty() &&
2247 NavigationState::FromDataSource(
2248 old_frame->dataSource())->was_prefetcher()) {
2249 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2250 WebDataSource* old_frame_ds = old_frame->dataSource();
2251 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2252 state->set_was_referred_by_prefetcher(true);
2253 break;
2254 }
2255 }
2256 }
2257 }
2258 }
2259
[email protected]4c1b6f0b2010-02-07 16:38:182260 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522261 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512262 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182263 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2264 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2265 break;
2266 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2267 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2268 break;
2269 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2270 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2271 break;
2272 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2273 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2274 break;
2275 }
2276 }
[email protected]fa7b6b542009-11-03 05:02:302277
[email protected]16e923d2011-04-30 00:41:442278 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502279
[email protected]946a0032011-03-31 18:42:282280 FOR_EACH_OBSERVER(
2281 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172282}
2283
2284void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2285 WebDataSource* ds = frame->provisionalDataSource();
2286 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2287
[email protected]3d9689372009-09-10 04:29:172288 // Update the request time if WebKit has better knowledge of it.
2289 if (navigation_state->request_time().is_null()) {
2290 double event_time = ds->triggeringEventTime();
2291 if (event_time != 0.0)
2292 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2293 }
2294
[email protected]05c8e502010-08-15 15:13:522295 // Start time is only set after request time.
2296 navigation_state->set_start_load_time(Time::Now());
2297
[email protected]3d9689372009-09-10 04:29:172298 bool is_top_most = !frame->parent();
2299 if (is_top_most) {
2300 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132301 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172302
2303 // Make sure redirect tracking state is clear for the new load.
2304 completed_client_redirect_src_ = GURL();
2305 } else if (frame->parent()->isLoading()) {
2306 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002307 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172308 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2309 }
2310
[email protected]28685da92011-02-07 21:49:172311 FOR_EACH_OBSERVER(
2312 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2313
[email protected]3d9689372009-09-10 04:29:172314 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592315 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262316 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172317}
2318
2319void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2320 if (frame->parent())
2321 return;
2322 // Received a redirect on the main frame.
2323 WebDataSource* data_source = frame->provisionalDataSource();
2324 if (!data_source) {
2325 // Should only be invoked when we have a data source.
2326 NOTREACHED();
2327 return;
2328 }
2329 std::vector<GURL> redirects;
2330 GetRedirectChain(data_source, &redirects);
2331 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512332 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592333 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172334 }
2335}
2336
[email protected]40bd6582009-12-04 23:49:512337void RenderView::didFailProvisionalLoad(WebFrame* frame,
2338 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172339 // Notify the browser that we failed a provisional load with an error.
2340 //
2341 // Note: It is important this notification occur before DidStopLoading so the
2342 // SSL manager can react to the provisional load failure before being
2343 // notified the load stopped.
2344 //
2345 WebDataSource* ds = frame->provisionalDataSource();
2346 DCHECK(ds);
2347
2348 const WebURLRequest& failed_request = ds->request();
2349
[email protected]28685da92011-02-07 21:49:172350 FOR_EACH_OBSERVER(
2351 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2352
[email protected]3d9689372009-09-10 04:29:172353 bool show_repost_interstitial =
2354 (error.reason == net::ERR_CACHE_MISS &&
2355 EqualsASCII(failed_request.httpMethod(), "POST"));
2356 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072357 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2358 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172359
2360 // Don't display an error page if this is simply a cancelled load. Aside
2361 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2362 if (error.reason == net::ERR_ABORTED)
2363 return;
2364
2365 // Make sure we never show errors in view source mode.
2366 frame->enableViewSourceMode(false);
2367
2368 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2369
2370 // If this is a failed back/forward/reload navigation, then we need to do a
2371 // 'replace' load. This is necessary to avoid messing up session history.
2372 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2373 // as session history is concerned.
2374 //
2375 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2376 // the page id.
2377 //
2378 bool replace =
2379 navigation_state->pending_page_id() != -1 ||
2380 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2381
2382 // If we failed on a browser initiated request, then make sure that our error
2383 // page load is regarded as the same browser initiated request.
2384 if (!navigation_state->is_content_initiated()) {
2385 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2386 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002387 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172388 navigation_state->transition_type(),
2389 navigation_state->request_time()));
2390 }
2391
2392 // Provide the user with a more helpful error page?
2393 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2394 return;
2395
2396 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082397 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172398}
2399
2400void RenderView::didReceiveDocumentData(
2401 WebFrame* frame, const char* data, size_t data_len,
2402 bool& prevent_default) {
2403 NavigationState* navigation_state =
2404 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092405 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172406}
2407
[email protected]40bd6582009-12-04 23:49:512408void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2409 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172410 NavigationState* navigation_state =
2411 NavigationState::FromDataSource(frame->dataSource());
2412
2413 navigation_state->set_commit_load_time(Time::Now());
2414 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202415 // When we perform a new navigation, we need to update the last committed
2416 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172417 UpdateSessionHistory(frame);
2418
2419 // We bump our Page ID to correspond with the new session history entry.
2420 page_id_ = next_page_id_++;
2421
[email protected]3cc72b12010-03-18 23:03:002422 // Advance our offset in session history, applying the length limit. There
2423 // is now no forward history.
2424 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102425 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2426 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002427 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032428 history_page_ids_.resize(history_list_length_, -1);
2429 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172430 } else {
2431 // Inspect the navigation_state on this frame to see if the navigation
2432 // corresponds to a session history navigation... Note: |frame| may or
2433 // may not be the toplevel frame, but for the case of capturing session
2434 // history, the first committed frame suffices. We keep track of whether
2435 // we've seen this commit before so that only capture session history once
2436 // per navigation.
2437 //
2438 // Note that we need to check if the page ID changed. In the case of a
2439 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2440 // previous URL and the current page ID, which would be wrong.
2441 if (navigation_state->pending_page_id() != -1 &&
2442 navigation_state->pending_page_id() != page_id_ &&
2443 !navigation_state->request_committed()) {
2444 // This is a successful session history navigation!
2445 UpdateSessionHistory(frame);
2446 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002447
2448 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032449
2450 // If the history list is valid, our list of page IDs should be correct.
2451 DCHECK(history_list_length_ <= 0 ||
2452 history_list_offset_ < 0 ||
2453 history_list_offset_ >= history_list_length_ ||
2454 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172455 }
2456 }
2457
[email protected]28685da92011-02-07 21:49:172458 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2459 DidCommitProvisionalLoad(frame, is_new_navigation));
2460
[email protected]3d9689372009-09-10 04:29:172461 // Remember that we've already processed this request, so we don't update
2462 // the session history again. We do this regardless of whether this is
2463 // a session history navigation, because if we attempted a session history
2464 // navigation without valid HistoryItem state, WebCore will think it is a
2465 // new navigation.
2466 navigation_state->set_request_committed(true);
2467
2468 UpdateURL(frame);
2469
2470 // If this committed load was initiated by a client redirect, we're
2471 // at the last stop now, so clear it.
2472 completed_client_redirect_src_ = GURL();
2473
2474 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272475 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172476}
2477
2478void RenderView::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102479 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2480 DidClearWindowObject(frame));
2481
[email protected]b6cb3a842011-06-24 18:28:412482 GURL frame_url = frame->document().url();
[email protected]c09163a2011-02-15 00:05:552483 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:252484 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2485 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272486 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172487 }
[email protected]3d9689372009-09-10 04:29:172488}
2489
2490void RenderView::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172491 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412492 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252493 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272494 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172495 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2496 }
[email protected]e48869a2011-04-01 19:56:032497
2498 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2499 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172500}
2501
[email protected]a3bc4d12011-04-20 17:22:212502void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title,
2503 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462504 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172505
2506 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272507 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172508}
2509
[email protected]42054a252011-05-17 18:02:132510void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
2511 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2512 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582513}
2514
[email protected]3d9689372009-09-10 04:29:172515void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2516 WebDataSource* ds = frame->dataSource();
2517 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2518 DCHECK(navigation_state);
2519 navigation_state->set_finish_document_load_time(Time::Now());
2520
[email protected]622474d2010-11-04 09:21:082521 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172522
[email protected]28685da92011-02-07 21:49:172523 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2524 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172525
2526 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272527 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172528}
2529
2530void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082531 if (webview()->mainFrame() == frame) {
2532 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2533 page_id_));
2534 }
[email protected]3d9689372009-09-10 04:29:172535}
2536
2537void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172538 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172539}
2540
2541void RenderView::didFinishLoad(WebFrame* frame) {
2542 WebDataSource* ds = frame->dataSource();
2543 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2544 DCHECK(navigation_state);
2545 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412546
[email protected]676126f72011-01-15 00:03:512547 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172548
2549 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172550}
2551
[email protected]ccbe04e2010-03-17 17:58:432552void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172553 WebFrame* frame, bool is_new_navigation) {
2554 // If this was a reference fragment navigation that we initiated, then we
2555 // could end up having a non-null pending navigation state. We just need to
2556 // update the ExtraData on the datasource so that others who read the
2557 // ExtraData will get the new NavigationState. Similarly, if we did not
2558 // initiate this navigation, then we need to take care to reset any pre-
2559 // existing navigation state to a content-initiated navigation state.
2560 // DidCreateDataSource conveniently takes care of this for us.
2561 didCreateDataSource(frame, frame->dataSource());
2562
[email protected]af15bed2010-08-25 21:12:092563 NavigationState* new_state =
2564 NavigationState::FromDataSource(frame->dataSource());
2565 new_state->set_was_within_same_page(true);
2566
[email protected]3d9689372009-09-10 04:29:172567 didCommitProvisionalLoad(frame, is_new_navigation);
2568
[email protected]750fcf872011-08-03 23:10:472569 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2570 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172571}
2572
[email protected]476b6f82009-09-10 21:00:592573void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312574 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592575}
2576
[email protected]3d9689372009-09-10 04:29:172577void RenderView::assignIdentifierToRequest(
2578 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2579 // Ignore
2580}
2581
[email protected]d88bf0a2011-08-30 23:55:572582void RenderView::willSendRequest(WebFrame* frame,
2583 unsigned identifier,
2584 WebURLRequest& request,
2585 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302586 WebFrame* top_frame = frame->top();
2587 if (!top_frame)
2588 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512589 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2590 WebDataSource* top_data_source = top_frame->dataSource();
2591 WebDataSource* data_source =
2592 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222593
[email protected]78d5cfe2011-02-04 08:43:222594 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032595 GURL new_url;
2596 if (content::GetContentClient()->renderer()->WillSendRequest(
2597 frame, request_url, &new_url)) {
2598 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222599 }
2600
[email protected]d88bf0a2011-08-30 23:55:572601 PageTransition::Type transition_type = PageTransition::LINK;
2602 NavigationState* data_state = NavigationState::FromDataSource(data_source);
2603 if (data_state) {
2604 if (data_state->is_cache_policy_override_set())
2605 request.setCachePolicy(data_state->cache_policy_override());
2606 transition_type = data_state->transition_type();
[email protected]5e369672009-11-03 23:48:302607 }
[email protected]8a3125a712010-08-09 18:58:512608
[email protected]d88bf0a2011-08-30 23:55:572609 request.setExtraData(new RequestExtraData((frame == top_frame),
2610 frame->identifier(), transition_type));
2611
2612 NavigationState* top_data_state =
2613 NavigationState::FromDataSource(top_data_source);
2614 // TODO(gavinp): separate out prefetching and prerender field trials
2615 // if the rel=prerender rel type is sticking around.
2616 if (top_data_state &&
2617 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2618 request.targetType() == WebURLRequest::TargetIsPrerender))
2619 top_data_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512620
[email protected]3d9689372009-09-10 04:29:172621 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132622 request.setHasUserGesture(frame->isProcessingUserGesture());
2623
[email protected]0a8db0d2011-04-13 15:15:402624 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132625 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172626}
2627
2628void RenderView::didReceiveResponse(
2629 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492630
[email protected]3d9689372009-09-10 04:29:172631 // Only do this for responses that correspond to a provisional data source
2632 // of the top-most frame. If we have a provisional data source, then we
2633 // can't have any sub-resources yet, so we know that this response must
2634 // correspond to a frame load.
2635 if (!frame->provisionalDataSource() || frame->parent())
2636 return;
2637
2638 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082639 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172640 if (frame->isViewSourceModeEnabled())
2641 return;
2642
[email protected]65041fa2010-05-21 06:56:532643 NavigationState* navigation_state =
2644 NavigationState::FromDataSource(frame->provisionalDataSource());
2645 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082646 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532647
[email protected]972ebdff2010-06-10 22:59:072648 // Record page load flags.
2649 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2650 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572651 navigation_state->set_was_alternate_protocol_available(
2652 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072653 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082654 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092655 // Whether or not the http status code actually corresponds to an error is
2656 // only checked when the page is done loading, if |use_error_page| is
2657 // still true.
2658 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172659}
2660
2661void RenderView::didFinishResourceLoad(
2662 WebFrame* frame, unsigned identifier) {
2663 NavigationState* navigation_state =
2664 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092665 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172666 return;
2667
[email protected]7bfc153f2011-09-23 22:00:202668 // Do not show error page when DevTools is attached.
2669 if (devtools_agent_->IsAttached())
2670 return;
2671
[email protected]06333afe2011-02-24 14:55:092672 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082673 int http_status_code = navigation_state->http_status_code();
2674 if (http_status_code == 404) {
2675 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412676 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172677
[email protected]b6cb3a842011-06-24 18:28:412678 const GURL& error_page_url =
2679 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092680 if (error_page_url.is_valid()) {
2681 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472682 original_error.domain = "http";
2683 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412684 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172685
[email protected]06333afe2011-02-24 14:55:092686 navigation_state->set_alt_error_page_fetcher(
2687 new AltErrorPageResourceFetcher(
2688 error_page_url, frame, original_error,
2689 NewCallback(this, &RenderView::AltErrorPageFinished)));
2690 return;
2691 }
2692 }
[email protected]3d9689372009-09-10 04:29:172693
[email protected]9966325b2011-04-18 05:00:102694 content::GetContentClient()->renderer()->ShowErrorPage(
2695 this, frame, http_status_code);
[email protected]3d9689372009-09-10 04:29:172696}
2697
2698void RenderView::didFailResourceLoad(
2699 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2700 // Ignore
2701}
2702
2703void RenderView::didLoadResourceFromMemoryCache(
2704 WebFrame* frame, const WebURLRequest& request,
2705 const WebURLResponse& response) {
2706 // Let the browser know we loaded a resource from the memory cache. This
2707 // message is needed to display the correct SSL indicators.
2708 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2709 routing_id_,
2710 request.url(),
[email protected]70435962011-08-02 20:13:282711 response.securityInfo(),
2712 request.httpMethod().utf8(),
2713 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172714}
2715
[email protected]6069da8c2009-10-20 20:33:492716void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292717 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2718}
2719
[email protected]92771112011-01-20 00:13:022720void RenderView::didRunInsecureContent(
2721 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292722 Send(new ViewHostMsg_DidRunInsecureContent(
2723 routing_id_,
[email protected]92771112011-01-20 00:13:022724 origin.toString().utf8(),
2725 target));
[email protected]e3d60e5d2009-09-25 21:08:292726}
2727
[email protected]b00ba702011-08-17 01:41:032728void RenderView::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
2729 webkit_glue::WebURLLoaderImpl* loader_impl =
2730 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2731 loader_impl->UpdateRoutingId(routing_id_);
2732}
2733
[email protected]3d9689372009-09-10 04:29:172734void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2735 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2736}
2737
[email protected]5bc10932011-09-21 21:03:302738void RenderView::didCreateScriptContext(WebFrame* frame,
2739 v8::Handle<v8::Context> context,
2740 int world_id) {
2741 content::GetContentClient()->renderer()->DidCreateScriptContext(
2742 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282743}
2744
[email protected]5bc10932011-09-21 21:03:302745void RenderView::willReleaseScriptContext(WebFrame* frame,
2746 v8::Handle<v8::Context> context,
2747 int world_id) {
2748 content::GetContentClient()->renderer()->WillReleaseScriptContext(
2749 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282750}
2751
[email protected]d812fd12011-05-27 23:05:072752void RenderView::didUpdateLayout(WebFrame* frame) {
2753 // We don't always want to set up a timer, only if we've been put in that
2754 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172755 // message.
[email protected]705243f2010-05-05 19:58:072756 if (!send_preferred_size_changes_ || !webview())
2757 return;
[email protected]dfca5acf2010-03-22 03:28:432758
[email protected]d812fd12011-05-27 23:05:072759 if (check_preferred_size_timer_.IsRunning())
2760 return;
[email protected]d323a172011-09-02 18:23:022761 check_preferred_size_timer_.Start(FROM_HERE,
2762 TimeDelta::FromMilliseconds(0), this,
[email protected]d812fd12011-05-27 23:05:072763 &RenderView::CheckPreferredSize);
2764}
2765
2766void RenderView::CheckPreferredSize() {
2767 // We don't always want to send the change messages over IPC, only if we've
2768 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2769 // message.
2770 if (!send_preferred_size_changes_ || !webview())
2771 return;
2772
[email protected]705243f2010-05-05 19:58:072773 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2774 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532775
2776 // In the presence of zoom, these sizes are still reported as if unzoomed,
2777 // so we need to adjust.
2778 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2779 size.set_width(static_cast<int>(size.width() * zoom_factor));
2780 size.set_height(static_cast<int>(size.height() * zoom_factor));
2781
[email protected]705243f2010-05-05 19:58:072782 if (size == preferred_size_)
2783 return;
[email protected]c27324b2009-11-19 22:44:292784
[email protected]705243f2010-05-05 19:58:072785 preferred_size_ = size;
2786 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2787 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172788}
2789
[email protected]dd6afca2011-08-13 03:44:312790void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2791 if (webview()->mainFrame() != frame)
2792 return;
2793 WebView* frameView = frame->view();
2794 if (!frameView)
2795 return;
2796
2797 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
2798 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
2799
2800 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
2801 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
2802 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
2803 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
2804
2805 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
2806 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
2807 }
2808}
2809
2810void RenderView::UpdateScrollState(WebFrame* frame) {
2811 WebSize offset = frame->scrollOffset();
2812 WebSize minimum_offset = frame->minimumScrollOffset();
2813 WebSize maximum_offset = frame->maximumScrollOffset();
2814
2815 bool is_pinned_to_left = offset.width <= minimum_offset.width;
2816 bool is_pinned_to_right = offset.width >= maximum_offset.width;
2817
2818 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
2819 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
2820 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
2821 routing_id_, is_pinned_to_left, is_pinned_to_right));
2822
2823 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
2824 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
2825 }
2826}
2827
[email protected]143dcd592009-11-06 21:33:492828void RenderView::didChangeScrollOffset(WebFrame* frame) {
2829 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:312830
2831 if (webview()->mainFrame() == frame)
2832 UpdateScrollState(frame);
2833}
2834
2835void RenderView::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2836 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:492837}
2838
[email protected]8922e1f2009-10-03 05:01:262839void RenderView::reportFindInPageMatchCount(int request_id, int count,
2840 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112841 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2842 if (!count)
2843 active_match_ordinal = 0;
2844
2845 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2846 routing_id_,
2847 request_id,
2848 count,
2849 gfx::Rect(),
2850 active_match_ordinal,
2851 final_update);
2852
[email protected]8922e1f2009-10-03 05:01:262853 // If we have a message that has been queued up, then we should just replace
2854 // it. The ACK from the browser will make sure it gets sent when the browser
2855 // wants it.
2856 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262857 queued_find_reply_message_.reset(msg);
2858 } else {
2859 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112860 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262861 }
2862}
2863
2864void RenderView::reportFindInPageSelection(int request_id,
2865 int active_match_ordinal,
2866 const WebRect& selection_rect) {
2867 // Send the search result over to the browser process.
2868 Send(new ViewHostMsg_Find_Reply(routing_id_,
2869 request_id,
2870 -1,
2871 selection_rect,
2872 active_match_ordinal,
2873 false));
2874}
2875
[email protected]2b06a992010-08-21 05:48:222876void RenderView::openFileSystem(
2877 WebFrame* frame,
2878 WebFileSystem::Type type,
2879 long long size,
[email protected]d275d7a2010-11-03 01:34:492880 bool create,
[email protected]2b06a992010-08-21 05:48:222881 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082882 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222883
[email protected]b6cb3a842011-06-24 18:28:412884 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082885 if (origin.isEmpty()) {
2886 // Uninitialized document?
2887 callbacks->didFail(WebKit::WebFileErrorAbort);
2888 return;
2889 }
[email protected]2b06a992010-08-21 05:48:222890
[email protected]c5a272d2010-09-27 18:37:082891 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2892 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492893 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222894}
2895
[email protected]10e5cf12011-04-13 04:10:402896void RenderView::queryStorageUsageAndQuota(
2897 WebFrame* frame,
2898 WebStorageQuotaType type,
2899 WebStorageQuotaCallbacks* callbacks) {
2900 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412901 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402902 if (origin.isEmpty()) {
2903 // Uninitialized document?
2904 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2905 return;
2906 }
2907 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:532908 GURL(origin.toString()),
2909 static_cast<quota::StorageType>(type),
2910 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402911}
2912
2913void RenderView::requestStorageQuota(
2914 WebFrame* frame,
2915 WebStorageQuotaType type,
2916 unsigned long long requested_size,
2917 WebStorageQuotaCallbacks* callbacks) {
2918 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412919 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402920 if (origin.isEmpty()) {
2921 // Uninitialized document?
2922 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2923 return;
2924 }
2925 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:532926 routing_id(), GURL(origin.toString()),
2927 static_cast<quota::StorageType>(type), requested_size,
2928 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402929}
2930
[email protected]18d5be92011-07-25 18:00:192931// WebKit::WebPageSerializerClient implementation ------------------------------
2932
2933void RenderView::didSerializeDataForFrame(
2934 const WebURL& frame_url,
2935 const WebCString& data,
2936 WebPageSerializerClient::PageSerializationStatus status) {
2937 Send(new ViewHostMsg_SendSerializedHtmlData(
2938 routing_id(),
2939 frame_url,
2940 data.data(),
2941 static_cast<int32>(status)));
2942}
2943
[email protected]79dbc662009-09-04 05:42:512944// webkit_glue::WebPluginPageDelegate -----------------------------------------
2945
[email protected]191eb3f72010-12-21 06:27:502946webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:532947 const FilePath& file_path,
2948 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:592949 if (!PluginChannelHost::IsListening())
2950 return NULL;
2951
[email protected]00c39612010-03-06 02:53:282952 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:462953 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:322954#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:222955 return webkit::npapi::WebPluginDelegateImpl::Create(
2956 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092957#else
[email protected]7398dcc2011-09-06 21:40:322958 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:222959 NOTIMPLEMENTED();
2960 return NULL;
[email protected]7b6616f2010-01-14 18:07:552961#endif
[email protected]f103ab72009-09-02 17:10:592962 }
2963
[email protected]4e0616e2010-05-28 14:55:532964 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592965}
2966
2967void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032968#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:272969 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:592970#endif
2971}
2972
2973void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032974#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:272975 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:592976#endif
2977 CleanupWindowInPluginMoves(window);
2978}
2979
[email protected]191eb3f72010-12-21 06:27:502980void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:592981 SchedulePluginMove(move);
2982}
2983
2984void RenderView::DidStartLoadingForPlugin() {
2985 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522986 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592987}
2988
2989void RenderView::DidStopLoadingForPlugin() {
2990 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522991 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592992}
2993
[email protected]b921cfd22010-02-25 16:57:512994WebCookieJar* RenderView::GetCookieJar() {
2995 return &cookie_jar_;
2996}
2997
initial.commit09911bf2008-07-26 23:55:292998void RenderView::SyncNavigationState() {
2999 if (!webview())
3000 return;
3001
[email protected]26aa0482009-09-30 16:55:273002 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173003 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293004 return;
[email protected]ca948a22009-06-25 19:36:173005
3006 Send(new ViewHostMsg_UpdateState(
3007 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293008}
3009
[email protected]b781ff282011-08-20 06:19:363010void RenderView::SyncSelectionIfRequired() {
3011 WebFrame* frame = webview()->focusedFrame();
3012 const std::string& text = frame->selectionAsText().utf8();
3013
3014 ui::Range range(ui::Range::InvalidRange());
3015 size_t location, length;
3016 if (webview()->caretOrSelectionRange(&location, &length)) {
3017 range.set_start(location);
3018 range.set_end(location + length);
3019 }
3020
3021 WebPoint start, end;
3022 webview()->selectionRange(start, end);
3023
3024 RenderViewSelection this_selection(text, range, start, end);
3025
3026 // Sometimes we get repeated didChangeSelection calls from webkit when
3027 // the selection hasn't actually changed. We don't want to report these
3028 // because it will cause us to continually claim the X clipboard.
3029 if (this_selection.Equals(last_selection_))
3030 return;
3031 last_selection_ = this_selection;
3032
3033 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, range,
3034 start, end));
3035}
3036
[email protected]7ccddb8c2009-08-04 17:36:553037GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293038 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553039 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293040 // If the URL that failed was secure, then the embedding web page was not
3041 // expecting a network attacker to be able to manipulate its contents. As
3042 // we fetch alternate error pages over HTTP, we would be allowing a network
3043 // attacker to manipulate the contents of the response if we tried to use
3044 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153045 return GURL();
initial.commit09911bf2008-07-26 23:55:293046 }
3047
3048 // Grab the base URL from the browser process.
3049 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153050 return GURL();
initial.commit09911bf2008-07-26 23:55:293051
3052 // Strip query params from the failed URL.
3053 GURL::Replacements remove_params;
3054 remove_params.ClearUsername();
3055 remove_params.ClearPassword();
3056 remove_params.ClearQuery();
3057 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553058 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503059 std::string spec_to_send = url_to_send.spec();
3060 // Notify link doctor of the url truncation by sending of "?" at the end.
3061 if (failed_url.has_query())
3062 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293063
3064 // Construct the query params to send to link doctor.
3065 std::string params(alternate_error_page_url_.query());
3066 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023067 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293068 params.append("&sourceid=chrome");
3069 params.append("&error=");
3070 switch (error_type) {
3071 case DNS_ERROR:
3072 params.append("dnserror");
3073 break;
3074
3075 case HTTP_404:
3076 params.append("http404");
3077 break;
3078
[email protected]5df266ac2008-10-15 19:50:133079 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333080 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133081 break;
3082
initial.commit09911bf2008-07-26 23:55:293083 default:
3084 NOTREACHED() << "unknown ErrorPageType";
3085 }
3086
3087 // OK, build the final url to return.
3088 GURL::Replacements link_doctor_params;
3089 link_doctor_params.SetQueryStr(params);
3090 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3091 return url;
3092}
3093
[email protected]57b9396c2011-10-07 19:11:593094GURL RenderView::GetOpenerUrl() const {
3095 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3096 return GURL();
3097 else
3098 return creator_url_;
3099}
3100
[email protected]c50008512011-02-03 01:17:273101WebUIBindings* RenderView::GetWebUIBindings() {
3102 if (!web_ui_bindings_.get()) {
[email protected]c6b7ef32011-10-04 22:21:443103 web_ui_bindings_.reset(new WebUIBindings(this, routing_id_));
[email protected]c091c2c2010-09-17 19:05:463104 }
[email protected]c50008512011-02-03 01:17:273105 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463106}
3107
[email protected]0fdbf8c2010-07-08 20:33:013108WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3109 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493110}
3111
[email protected]6069da8c2009-10-20 20:33:493112void RenderView::OnFind(int request_id, const string16& search_text,
3113 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273114 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493115
[email protected]872542532011-06-23 00:43:163116 // Check if the plugin still exists in the document.
3117 if (main_frame->document().isPluginDocument() &&
3118 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493119 if (options.findNext) {
3120 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013121 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493122 } else {
[email protected]afdbd142010-07-10 08:01:233123 if (GetWebPluginFromPluginDocument()->startFind(
3124 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493125 } else {
[email protected]e7c58a32010-08-13 19:47:113126 // Send "no results".
3127 Send(new ViewHostMsg_Find_Reply(routing_id_,
3128 request_id,
3129 0,
3130 gfx::Rect(),
3131 0,
3132 true));
[email protected]24a7f3c2010-03-25 08:26:493133 }
3134 }
3135 return;
3136 }
3137
[email protected]b4bb2502009-10-01 22:35:273138 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273139 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293140 WebFrame* search_frame = focused_frame; // start searching focused frame.
3141
3142 bool multi_frame = (frame_after_main != main_frame);
3143
3144 // If we have multiple frames, we don't want to wrap the search within the
3145 // frame, so we check here if we only have main_frame in the chain.
3146 bool wrap_within_frame = !multi_frame;
3147
[email protected]b3f2b912009-04-09 16:18:523148 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293149 bool result = false;
3150
[email protected]7830da3e2009-11-06 16:27:263151 // If something is selected when we start searching it means we cannot just
3152 // increment the current match ordinal; we need to re-generate it.
3153 WebRange current_selection = focused_frame->selectionRange();
3154
initial.commit09911bf2008-07-26 23:55:293155 do {
[email protected]dd7daa82009-08-10 05:46:453156 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593157 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293158
3159 if (!result) {
3160 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223161 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293162
3163 // Find the next frame, but skip the invisible ones.
3164 do {
3165 // What is the next frame to search? (we might be going backwards). Note
3166 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593167 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273168 search_frame->traverseNext(true) :
3169 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453170 } while (!search_frame->hasVisibleContent() &&
3171 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293172
[email protected]884db412008-11-24 23:46:503173 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223174 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293175
3176 // If we have multiple frames and we have wrapped back around to the
3177 // focused frame, we need to search it once more allowing wrap within
3178 // the frame, otherwise it will report 'no match' if the focused frame has
3179 // reported matches, but no frames after the focused_frame contain a
3180 // match for the search word(s).
3181 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453182 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593183 request_id, search_text, options, true, // Force wrapping.
3184 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293185 }
3186 }
3187
[email protected]26aa0482009-09-30 16:55:273188 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293189 } while (!result && search_frame != focused_frame);
3190
[email protected]7830da3e2009-11-06 16:27:263191 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293192 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453193 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293194 } else {
3195 // If nothing is found, set result to "0 of 0", otherwise, set it to
3196 // "-1 of 1" to indicate that we found at least one item, but we don't know
3197 // yet what is active.
3198 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3199 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293200
[email protected]4f3dc372009-02-24 00:10:293201 // If we find no matches then this will be our last status update.
3202 // Otherwise the scoping effort will send more results.
3203 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293204
[email protected]4f3dc372009-02-24 00:10:293205 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403206 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593207 request_id,
[email protected]4f3dc372009-02-24 00:10:293208 match_count,
3209 selection_rect,
3210 ordinal,
3211 final_status_update));
initial.commit09911bf2008-07-26 23:55:293212
initial.commit09911bf2008-07-26 23:55:293213 // Scoping effort begins, starting with the mainframe.
3214 search_frame = main_frame;
3215
[email protected]dd7daa82009-08-10 05:46:453216 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293217
3218 do {
3219 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453220 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293221
3222 // We don't start another scoping effort unless at least one match has
3223 // been found.
3224 if (result) {
3225 // Start new scoping request. If the scoping function determines that it
3226 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453227 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593228 search_text,
3229 options,
initial.commit09911bf2008-07-26 23:55:293230 true); // reset the tickmarks
3231 }
3232
3233 // Iterate to the next frame. The frame will not necessarily scope, for
3234 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273235 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293236 } while (search_frame != main_frame);
3237 }
3238}
3239
[email protected]24a7f3c2010-03-25 08:26:493240void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3241 WebView* view = webview();
3242 if (!view)
3243 return;
3244
3245 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163246 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013247 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493248 return;
3249 }
3250
3251 bool clear_selection =
3252 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3253 if (clear_selection)
3254 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3255
3256 WebFrame* frame = view->mainFrame();
3257 while (frame) {
3258 frame->stopFinding(clear_selection);
3259 frame = frame->traverseNext(false);
3260 }
3261
3262 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3263 WebFrame* focused_frame = view->focusedFrame();
3264 if (focused_frame) {
3265 WebDocument doc = focused_frame->document();
3266 if (!doc.isNull()) {
3267 WebNode node = doc.focusedNode();
3268 if (!node.isNull())
3269 node.simulateClick();
3270 }
3271 }
3272 }
3273}
3274
3275void RenderView::OnFindReplyAck() {
3276 // Check if there is any queued up request waiting to be sent.
3277 if (queued_find_reply_message_.get()) {
3278 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423279 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493280 }
3281}
3282
[email protected]0bd753682010-12-16 18:15:523283WebPlugin* RenderView::CreatePepperPlugin(
3284 WebFrame* frame,
3285 const WebPluginParams& params,
3286 const FilePath& path,
3287 webkit::ppapi::PluginModule* pepper_module) {
3288 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:253289 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:093290}
[email protected]00152e92010-07-19 11:47:403291
[email protected]191eb3f72010-12-21 06:27:503292WebPlugin* RenderView::CreateNPAPIPlugin(
3293 WebFrame* frame,
3294 const WebPluginParams& params,
3295 const FilePath& path,
3296 const std::string& mime_type) {
3297 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:083298 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403299}
3300
[email protected]40bd6582009-12-04 23:49:513301void RenderView::OnZoom(PageZoom::Function function) {
3302 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3303 return;
3304
[email protected]258d31122010-05-09 10:59:413305 webview()->hidePopups();
[email protected]c514d6372011-08-16 22:54:443306#if !defined(TOUCH_UI)
[email protected]b75b8292010-10-01 07:28:253307 double old_zoom_level = webview()->zoomLevel();
3308 double zoom_level;
3309 if (function == PageZoom::RESET) {
3310 zoom_level = 0;
3311 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3312 // Previous zoom level is a whole number, so just increment/decrement.
3313 zoom_level = old_zoom_level + function;
3314 } else {
3315 // Either the user hit the zoom factor limit and thus the zoom level is now
3316 // not a whole number, or a plugin changed it to a custom value. We want
3317 // to go to the next whole number so that the user can always get back to
3318 // 100% with the keyboard/menu.
3319 if ((old_zoom_level > 1 && function > 0) ||
3320 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453321 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253322 } else {
3323 // We're going towards 100%, so first go to the next whole number.
3324 zoom_level = static_cast<int>(old_zoom_level);
3325 }
3326 }
[email protected]b75b8292010-10-01 07:28:253327 webview()->setZoomLevel(false, zoom_level);
[email protected]c514d6372011-08-16 22:54:443328#else
3329 double old_page_scale_factor = webview()->pageScaleFactor();
3330 double page_scale_factor;
3331 if (function == PageZoom::RESET) {
3332 page_scale_factor = 1.0;
3333 } else {
3334 page_scale_factor = old_page_scale_factor +
3335 (function > 0 ? kScalingIncrement : -kScalingIncrement);
3336 }
3337 webview()->scalePage(page_scale_factor, WebPoint(0, 0));
3338#endif
[email protected]b75b8292010-10-01 07:28:253339 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513340}
3341
[email protected]d0b8d092010-10-25 04:05:173342void RenderView::OnSetZoomLevel(double zoom_level) {
3343 // Don't set zoom level for full-page plugin since they don't use the same
3344 // zoom settings.
3345 if (webview()->mainFrame()->document().isPluginDocument())
3346 return;
3347
3348 webview()->hidePopups();
3349 webview()->setZoomLevel(false, zoom_level);
3350 zoomLevelChanged();
3351}
3352
[email protected]9d797f32010-04-23 07:17:543353void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:253354 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543355 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293356}
3357
[email protected]8a5e0ca2011-08-25 06:30:473358void RenderView::OnExitFullscreen() {
3359 webview()->exitFullscreen();
3360}
3361
[email protected]41fc0322009-09-04 22:23:403362void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273363 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293364}
3365
[email protected]a697f4c2009-09-14 22:30:183366void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273367 WebString no_encoding;
3368 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183369}
3370
[email protected]318bf5802011-08-08 17:12:413371WebFrame* RenderView::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453372 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273373 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453374
3375 // xpath string can represent a frame deep down the tree (across multiple
3376 // frame DOMs).
3377 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3378 // should break into 2 xpaths
3379 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413380 std::vector<string16> xpaths;
3381 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453382
[email protected]26aa0482009-09-30 16:55:273383 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413384 for (std::vector<string16>::const_iterator i = xpaths.begin();
3385 frame && i != xpaths.end(); ++i) {
3386 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293387 }
3388
[email protected]dd7daa82009-08-10 05:46:453389 return frame;
initial.commit09911bf2008-07-26 23:55:293390}
3391
[email protected]13a1e4c3c2011-02-03 21:07:093392WebNode RenderView::GetFocusedNode() const {
3393 if (!webview())
3394 return WebNode();
3395 WebFrame* focused_frame = webview()->focusedFrame();
3396 if (focused_frame) {
3397 WebDocument doc = focused_frame->document();
3398 if (!doc.isNull())
3399 return doc.focusedNode();
3400 }
3401
3402 return WebNode();
3403}
3404
[email protected]38b592902011-04-16 02:08:423405bool RenderView::IsEditableNode(const WebNode& node) {
3406 bool is_editable_node = false;
3407 if (!node.isNull()) {
3408 if (node.isContentEditable()) {
3409 is_editable_node = true;
3410 } else if (node.isElementNode()) {
3411 is_editable_node =
3412 node.toConst<WebElement>().isTextFormControlElement();
3413 }
3414 }
3415 return is_editable_node;
3416}
3417
[email protected]882b7b22010-10-05 03:34:533418void RenderView::EvaluateScript(const string16& frame_xpath,
3419 const string16& script,
3420 int id,
3421 bool notify_result) {
3422 v8::Handle<v8::Value> result;
[email protected]318bf5802011-08-08 17:12:413423 WebFrame* web_frame = GetChildFrame(frame_xpath);
[email protected]882b7b22010-10-05 03:34:533424 if (web_frame)
3425 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
3426 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:293427 ListValue list;
[email protected]cd326242011-06-16 01:55:463428 if (!result.IsEmpty() && web_frame) {
[email protected]81f9fe0b2010-12-07 00:35:293429 v8::HandleScope handle_scope;
3430 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3431 v8::Context::Scope context_scope(context);
[email protected]8d86f13d2011-10-04 17:01:193432 V8ValueConverterImpl converter;
[email protected]b1cf3372011-04-20 21:28:103433 converter.set_allow_date(true);
3434 converter.set_allow_regexp(true);
3435 list.Set(0, converter.FromV8Value(result, context));
[email protected]81f9fe0b2010-12-07 00:35:293436 } else {
3437 list.Set(0, Value::CreateNullValue());
3438 }
3439 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:533440 }
initial.commit09911bf2008-07-26 23:55:293441}
3442
[email protected]882b7b22010-10-05 03:34:533443void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
3444 const string16& jscript,
3445 int id,
3446 bool notify_result) {
3447 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293448}
3449
[email protected]318bf5802011-08-08 17:12:413450void RenderView::OnCSSInsertRequest(const string16& frame_xpath,
[email protected]01cf589c2011-07-28 18:04:033451 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413452 WebFrame* frame = GetChildFrame(frame_xpath);
3453 if (!frame)
[email protected]216813952011-05-19 22:21:263454 return;
[email protected]ae461542009-06-19 19:03:413455
[email protected]01cf589c2011-07-28 18:04:033456 frame->document().insertUserStyleSheet(
3457 WebString::fromUTF8(css),
3458 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483459}
3460
[email protected]81e63782009-02-27 19:35:093461void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3462 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293463}
3464
[email protected]d0980792011-02-13 19:41:403465void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:293466 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:553467 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:273468 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293469}
3470
3471void RenderView::OnReservePageIDRange(int size_of_range) {
3472 next_page_id_ += size_of_range + 1;
3473}
3474
[email protected]59f4f2fa2011-03-23 01:00:553475void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
3476 const gfx::Point& client_point,
3477 const gfx::Point& screen_point,
3478 WebDragOperationsMask ops) {
3479 WebDragOperation operation = webview()->dragTargetDragEnter(
3480 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553481 client_point,
3482 screen_point,
3483 ops);
3484
3485 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3486}
3487
3488void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
3489 const gfx::Point& screen_point,
3490 WebDragOperationsMask ops) {
3491 WebDragOperation operation = webview()->dragTargetDragOver(
3492 client_point,
3493 screen_point,
3494 ops);
3495
3496 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3497}
3498
3499void RenderView::OnDragTargetDragLeave() {
3500 webview()->dragTargetDragLeave();
3501}
3502
3503void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3504 const gfx::Point& screen_point) {
3505 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573506
3507 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553508}
3509
[email protected]e80c73b2009-04-07 23:24:583510void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3511 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253512 bool ended,
3513 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033514 if (ended) {
[email protected]26aa0482009-09-30 16:55:273515 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203516 } else {
3517 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033518 }
initial.commit09911bf2008-07-26 23:55:293519}
3520
3521void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273522 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293523}
3524
initial.commit09911bf2008-07-26 23:55:293525void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593526 webkit_preferences_ = prefs;
3527 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293528}
3529
[email protected]08bb1e722011-07-30 19:13:043530void RenderView::OnUpdateRemoteAccessClientFirewallTraversal(
3531 const std::string& policy) {
3532 pepper_delegate_.PublishPolicy(policy);
3533}
3534
initial.commit09911bf2008-07-26 23:55:293535void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3536 alternate_error_page_url_ = url;
3537}
3538
[email protected]b29aa74b2011-01-31 21:41:083539void RenderView::OnCustomContextMenuAction(
3540 const webkit_glue::CustomContextMenuContext& custom_context,
3541 unsigned action) {
3542 if (custom_context.is_pepper_menu)
3543 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3544 else
3545 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:583546 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3547 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:333548}
3549
[email protected]600ea402011-04-12 00:01:513550void RenderView::OnEnumerateDirectoryResponse(
3551 int id,
3552 const std::vector<FilePath>& paths) {
3553 if (!enumeration_completions_[id])
3554 return;
3555
3556 WebVector<WebString> ws_file_names(paths.size());
3557 for (size_t i = 0; i < paths.size(); ++i)
3558 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3559
3560 enumeration_completions_[id]->didChooseFile(ws_file_names);
3561 enumeration_completions_.erase(id);
3562}
3563
[email protected]cdaf8d02010-03-30 19:52:473564void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363565 // This could happen if we navigated to a different page before the user
3566 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473567 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363568 return;
3569
[email protected]cdaf8d02010-03-30 19:52:473570 WebVector<WebString> ws_file_names(paths.size());
3571 for (size_t i = 0; i < paths.size(); ++i)
3572 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463573
[email protected]cdaf8d02010-03-30 19:52:473574 if (file_chooser_completions_.front()->completion)
3575 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3576 file_chooser_completions_.pop_front();
3577
3578 // If there are more pending file chooser requests, schedule one now.
3579 if (!file_chooser_completions_.empty()) {
3580 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3581 file_chooser_completions_.front()->params));
3582 }
initial.commit09911bf2008-07-26 23:55:293583}
3584
[email protected]770dd8b2010-05-24 18:11:393585void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3586 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243587 if (send_preferred_size_changes_)
3588 return;
[email protected]9fb325e2010-05-06 18:23:243589 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393590
[email protected]d812fd12011-05-27 23:05:073591 // Start off with an initial preferred size notification (in case
3592 // |didUpdateLayout| was already called).
3593 if (webview())
3594 didUpdateLayout(webview()->mainFrame());
[email protected]0666aef2009-05-13 19:48:083595}
3596
[email protected]cda45c02010-02-25 19:28:103597void RenderView::OnDisableScrollbarsForSmallWindows(
3598 const gfx::Size& disable_scrollbar_size_limit) {
3599 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3600}
3601
[email protected]80d96fa2009-06-10 22:34:513602void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3603 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373604 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133605#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413606 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3607 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463608 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513609 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343610 renderer_prefs.thumb_inactive_color,
3611 renderer_prefs.thumb_active_color,
3612 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323613
[email protected]644d77e2010-01-27 01:03:103614 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323615 webview()->setScrollbarColors(
3616 renderer_prefs.thumb_inactive_color,
3617 renderer_prefs.thumb_active_color,
3618 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103619 webview()->setSelectionColors(
3620 renderer_prefs.active_selection_bg_color,
3621 renderer_prefs.active_selection_fg_color,
3622 renderer_prefs.inactive_selection_bg_color,
3623 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463624 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103625 }
[email protected]7a74e102009-09-03 00:16:563626#endif
[email protected]80d96fa2009-06-10 22:34:513627}
3628
[email protected]952cb702009-10-07 05:50:283629void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3630 const WebMediaPlayerAction& action) {
3631 if (webview())
3632 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563633}
3634
[email protected]18d5be92011-07-25 18:00:193635void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3636 const GURL& page_url) {
3637 // Prepare list to storage all savable resource links.
3638 std::vector<GURL> resources_list;
3639 std::vector<GURL> referrers_list;
3640 std::vector<GURL> frames_list;
3641 webkit_glue::SavableResourcesResult result(&resources_list,
3642 &referrers_list,
3643 &frames_list);
3644
3645 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3646 webview(),
3647 page_url,
3648 &result,
[email protected]2a80aee2011-10-07 16:06:033649 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:193650 // If something is wrong when collecting all savable resource links,
3651 // send empty list to embedder(browser) to tell it failed.
3652 referrers_list.clear();
3653 resources_list.clear();
3654 frames_list.clear();
3655 }
3656
3657 // Send result of all savable resource links to embedder.
3658 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3659 resources_list,
3660 referrers_list,
3661 frames_list));
3662}
3663
3664void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
3665 const std::vector<GURL>& links,
3666 const std::vector<FilePath>& local_paths,
3667 const FilePath& local_directory_name) {
3668
3669 // Convert std::vector of GURLs to WebVector<WebURL>
3670 WebVector<WebURL> weburl_links(links);
3671
3672 // Convert std::vector of std::strings to WebVector<WebString>
3673 WebVector<WebString> webstring_paths(local_paths.size());
3674 for (size_t i = 0; i < local_paths.size(); i++)
3675 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3676
3677 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
3678 webstring_paths,
3679 webkit_glue::FilePathToWebString(
3680 local_directory_name));
3681}
3682
[email protected]9b18a84f2010-06-10 15:54:043683void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273684 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473685 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293686}
3687
[email protected]992db4c2011-05-12 15:37:153688void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3689 if (is_swapped_out_)
3690 return;
3691
3692 // Swap this RenderView out so the tab can navigate to a page rendered by a
3693 // different process. This involves running the unload handler and clearing
3694 // the page. Once WasSwappedOut is called, we also allow this process to exit
3695 // if there are no other active RenderViews in it.
3696
3697 // Send an UpdateState message before we get swapped out.
3698 SyncNavigationState();
3699
3700 // Synchronously run the unload handler before sending the ACK.
3701 webview()->dispatchUnloadEvent();
3702
3703 // Swap out and stop sending any IPC messages that are not ACKs.
3704 SetSwappedOut(true);
3705
3706 // Replace the page with a blank dummy URL. The unload handler will not be
3707 // run a second time, thanks to a check in FrameLoader::stopLoading.
3708 // TODO(creis): Need to add a better way to do this that avoids running the
3709 // beforeunload handler. For now, we just run it a second time silently.
3710 webview()->mainFrame()->loadHTMLString(std::string(),
3711 GURL("about:swappedout"),
3712 GURL("about:swappedout"),
3713 false);
3714
3715 // Just echo back the params in the ACK.
3716 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3717}
3718
3719void RenderView::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:293720 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3721 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3722 // in the onunload handler from appearing. For now, we're bypassing that and
3723 // calling the FrameLoader's CloseURL method directly. This should be
3724 // revisited to avoid having two ways to close a page. Having a single way
3725 // to close that can run onunload is also useful for fixing
3726 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273727 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293728
[email protected]992db4c2011-05-12 15:37:153729 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293730}
3731
3732void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573733#if defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163734 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463735 if (webview())
3736 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573737#else // defined(OS_WIN)
3738 // TODO(port): we don't support theming on non-Windows platforms yet
3739 NOTIMPLEMENTED();
3740#endif
initial.commit09911bf2008-07-26 23:55:293741}
3742
[email protected]0aa55312008-10-17 21:53:083743void RenderView::OnDisassociateFromPopupCount() {
3744 if (decrement_shared_popup_at_destruction_)
3745 shared_popup_counter_->data--;
3746 shared_popup_counter_ = new SharedRenderViewCounter(0);
3747 decrement_shared_popup_at_destruction_ = false;
3748}
3749
[email protected]15d79e12009-08-02 19:23:453750bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3751 const WebURLError& error,
3752 bool replace) {
3753 // We only show alternate error pages in the main frame. They are
3754 // intended to assist the user when navigating, so there is not much
3755 // value in showing them for failed subframes. Ideally, we would be
3756 // able to use the TYPED transition type for this, but that flag is
3757 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453758 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453759 return false;
3760
3761 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373762 // connection failure.
[email protected]15d79e12009-08-02 19:23:453763 int ec = error.reason;
3764 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3765 ec != net::ERR_CONNECTION_FAILED &&
3766 ec != net::ERR_CONNECTION_REFUSED &&
3767 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373768 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453769 return false;
3770
3771 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553772 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453773 if (!error_page_url.is_valid())
3774 return false;
3775
3776 // Load an empty page first so there is an immediate response to the error,
3777 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453778 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363779 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453780 error.unreachableURL,
3781 replace);
3782
3783 // Now, create a fetcher for the error page and associate it with the data
3784 // source we just created via the LoadHTMLString call. That way if another
3785 // navigation occurs, the fetcher will get destroyed.
3786 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453787 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453788 navigation_state->set_alt_error_page_fetcher(
3789 new AltErrorPageResourceFetcher(
3790 error_page_url, frame, error,
3791 NewCallback(this, &RenderView::AltErrorPageFinished)));
3792 return true;
3793}
3794
[email protected]15d79e12009-08-02 19:23:453795void RenderView::AltErrorPageFinished(WebFrame* frame,
3796 const WebURLError& original_error,
3797 const std::string& html) {
3798 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093799 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553800 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093801 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453802}
3803
[email protected]30f75e62009-02-25 22:01:003804void RenderView::OnMoveOrResizeStarted() {
3805 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473806 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003807}
3808
[email protected]30f75e62009-02-25 22:01:003809void RenderView::OnResize(const gfx::Size& new_size,
3810 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103811 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473812 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103813 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203814 webview()->mainFrame()->setCanHaveScrollbars(
3815 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103816 }
[email protected]dd6afca2011-08-13 03:44:313817 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:103818 }
3819
[email protected]30f75e62009-02-25 22:01:003820 RenderWidget::OnResize(new_size, resizer_rect);
3821}
[email protected]0aa477bd2009-03-23 22:21:433822
[email protected]00c39612010-03-06 02:53:283823void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013824 // Notify the pepper plugins that we started painting.
3825 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283826}
3827
3828void RenderView::DidFlushPaint() {
3829 // Notify any pepper plugins that we painted. This will call into the plugin,
3830 // and we it may ask to close itself as a result. This will, in turn, modify
3831 // our set, possibly invalidating the iterator. So we iterate on a copy that
3832 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013833 pepper_delegate_.ViewFlushedPaint();
3834
[email protected]00c39612010-03-06 02:53:283835 WebFrame* main_frame = webview()->mainFrame();
3836
3837 // If we have a provisional frame we are between the start and commit stages
3838 // of loading and we don't want to save stats.
3839 if (!main_frame->provisionalDataSource()) {
3840 WebDataSource* ds = main_frame->dataSource();
3841 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3842 DCHECK(navigation_state);
3843
[email protected]05c8e502010-08-15 15:13:523844 // TODO(jar): The following code should all be inside a method, probably in
3845 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283846 Time now = Time::Now();
3847 if (navigation_state->first_paint_time().is_null()) {
3848 navigation_state->set_first_paint_time(now);
3849 }
3850 if (navigation_state->first_paint_after_load_time().is_null() &&
3851 !navigation_state->finish_load_time().is_null()) {
3852 navigation_state->set_first_paint_after_load_time(now);
3853 }
3854 }
[email protected]b781ff282011-08-20 06:19:363855
3856#if defined(TOUCH_UI)
3857 SyncSelectionIfRequired();
3858#endif
[email protected]00c39612010-03-06 02:53:283859}
3860
[email protected]37a6f302011-07-11 23:43:083861void RenderView::OnViewContextSwapBuffersPosted() {
3862 RenderWidget::OnSwapBuffersPosted();
3863}
3864
[email protected]65225772011-05-12 21:10:243865void RenderView::OnViewContextSwapBuffersComplete() {
3866 RenderWidget::OnSwapBuffersComplete();
3867}
3868
3869void RenderView::OnViewContextSwapBuffersAborted() {
3870 RenderWidget::OnSwapBuffersAborted();
3871}
3872
[email protected]719b36f2010-12-22 20:36:463873webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:153874 const gfx::Rect& paint_bounds,
3875 TransportDIB** dib,
3876 gfx::Rect* location,
3877 gfx::Rect* clip) {
3878 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
3879 paint_bounds, dib, location, clip);
3880}
3881
[email protected]bcaf2272011-02-15 15:29:433882gfx::Point RenderView::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:073883 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:433884 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523885}
3886
[email protected]05d478752009-04-08 23:38:163887void RenderView::OnClearFocusedNode() {
3888 if (webview())
[email protected]26aa0482009-09-30 16:55:273889 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163890}
3891
[email protected]699ab0d2009-04-23 23:19:143892void RenderView::OnSetBackground(const SkBitmap& background) {
3893 if (webview())
[email protected]b4bb2502009-10-01 22:35:273894 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143895
3896 SetBackground(background);
3897}
3898
[email protected]8c66c5a2009-07-22 17:26:343899void RenderView::OnSetActive(bool active) {
3900 if (webview())
[email protected]b4bb2502009-10-01 22:35:273901 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263902
3903#if defined(OS_MACOSX)
3904 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3905 for (plugin_it = plugin_delegates_.begin();
3906 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3907 (*plugin_it)->SetWindowFocus(active);
3908 }
3909#endif
[email protected]8c66c5a2009-07-22 17:26:343910}
3911
[email protected]6ce7abc52010-02-02 18:40:143912#if defined(OS_MACOSX)
3913void RenderView::OnSetWindowVisibility(bool visible) {
3914 // Inform plugins that their container has changed visibility.
3915 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3916 for (plugin_it = plugin_delegates_.begin();
3917 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3918 (*plugin_it)->SetContainerVisibility(visible);
3919 }
3920}
[email protected]1e6e3c992010-02-08 15:52:133921
[email protected]4d51d5bf2010-07-26 18:48:263922void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
3923 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:133924 // Inform plugins that their window's frame has changed.
3925 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3926 for (plugin_it = plugin_delegates_.begin();
3927 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3928 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3929 }
3930}
[email protected]935d63d2010-10-15 23:31:553931
[email protected]b7f75862011-01-21 21:15:133932void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:553933 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:133934 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:553935 // applies to it or not, so inform all the delegates.
3936 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3937 for (plugin_it = plugin_delegates_.begin();
3938 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:133939 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:553940 }
3941}
[email protected]6ce7abc52010-02-02 18:40:143942#endif // OS_MACOSX
3943
[email protected]446705872009-09-10 07:22:483944void RenderView::OnSetEditCommandsForNextKeyEvent(
3945 const EditCommands& edit_commands) {
3946 edit_commands_ = edit_commands;
3947}
3948
[email protected]60c42a8c72009-10-09 04:08:593949void RenderView::Close() {
3950 // We need to grab a pointer to the doomed WebView before we destroy it.
3951 WebView* doomed = webview();
3952 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:493953 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:593954}
3955
[email protected]446705872009-09-10 07:22:483956void RenderView::DidHandleKeyEvent() {
3957 edit_commands_.clear();
3958}
3959
[email protected]67bfb83f2011-09-22 03:36:373960bool RenderView::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
3961 return pepper_delegate_.DispatchLockedMouseEvent(event);
3962}
3963
[email protected]6a8ddba52010-09-05 04:38:063964void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:513965 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:063966}
3967
[email protected]2d0f2e92011-10-03 09:02:243968void RenderView::DidHandleTouchEvent(const WebTouchEvent& event) {
3969 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
3970}
3971
[email protected]941e4552010-02-01 21:23:433972void RenderView::OnWasHidden() {
3973 RenderWidget::OnWasHidden();
3974
[email protected]a6939ca42011-02-18 17:58:073975 if (webview()) {
3976 webview()->settings()->setMinimumTimerInterval(
3977 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:443978 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073979 }
3980
3981#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:433982 // Inform plugins that their container is no longer visible.
3983 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3984 for (plugin_it = plugin_delegates_.begin();
3985 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3986 (*plugin_it)->SetContainerVisibility(false);
3987 }
[email protected]a6939ca42011-02-18 17:58:073988#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:433989}
3990
3991void RenderView::OnWasRestored(bool needs_repainting) {
3992 RenderWidget::OnWasRestored(needs_repainting);
3993
[email protected]a6939ca42011-02-18 17:58:073994 if (webview()) {
3995 webview()->settings()->setMinimumTimerInterval(
3996 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:443997 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073998 }
3999
4000#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434001 // Inform plugins that their container is now visible.
4002 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4003 for (plugin_it = plugin_delegates_.begin();
4004 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4005 (*plugin_it)->SetContainerVisibility(true);
4006 }
[email protected]784ea1ab2010-09-18 00:02:344007#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074008}
[email protected]1e6e3c992010-02-08 15:52:134009
[email protected]65225772011-05-12 21:10:244010bool RenderView::SupportsAsynchronousSwapBuffers() {
4011 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4012 if (!context)
4013 return false;
4014 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4015 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4016 std::string::npos;
4017}
4018
[email protected]1e6e3c992010-02-08 15:52:134019void RenderView::OnSetFocus(bool enable) {
4020 RenderWidget::OnSetFocus(enable);
4021
[email protected]7d3c02c2010-05-05 23:10:314022 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074023 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134024 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4025 for (plugin_it = plugin_delegates_.begin();
4026 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344027#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314028 // RenderWidget's call to setFocus can cause the underlying webview's
4029 // activation state to change just like a call to setIsActive.
4030 if (enable)
4031 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344032#endif
[email protected]7d3c02c2010-05-05 23:10:314033 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134034 }
[email protected]589621b2010-09-23 22:01:074035
4036 // Notify all Pepper plugins.
4037 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134038 }
4039}
[email protected]941e4552010-02-01 21:23:434040
[email protected]56ea1a62011-05-30 07:05:574041void RenderView::PpapiPluginFocusChanged() {
4042 UpdateInputMethod();
4043}
4044
[email protected]08bb1e722011-07-30 19:13:044045void RenderView::RequestRemoteAccessClientFirewallTraversal() {
4046 Send(new ViewHostMsg_RequestRemoteAccessClientFirewallTraversal(routing_id_));
4047}
4048
[email protected]56ea1a62011-05-30 07:05:574049void RenderView::OnImeSetComposition(
4050 const string16& text,
4051 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4052 int selection_start,
4053 int selection_end) {
4054 // Until PPAPI has an interface for handling IME events, we skip sending
4055 // OnImeSetComposition. Otherwise the composition is canceled when a
4056 // non-editable DOM element is focused.
4057 //
4058 // TODO(kinaba) This temporal remedy can be removed after PPAPI is extended
4059 // with an IME handling interface.
4060 if (!pepper_delegate_.IsPluginFocused()) {
[email protected]e6ae0f6c2011-10-04 10:39:234061#if defined(OS_WIN)
4062 // When a plug-in has focus, we create platform-specific IME data used by
4063 // our IME emulator and send it directly to the focused plug-in, i.e. we
4064 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4065 // instance ID is the same one as the specified ID.)
4066 if (focused_plugin_id_ >= 0) {
4067 std::vector<int> clauses;
4068 std::vector<int> target;
4069 for (size_t i = 0; i < underlines.size(); ++i) {
4070 clauses.push_back(underlines[i].startOffset);
4071 clauses.push_back(underlines[i].endOffset);
4072 if (underlines[i].thick) {
4073 target.clear();
4074 target.push_back(underlines[i].startOffset);
4075 target.push_back(underlines[i].endOffset);
4076 }
4077 }
4078 std::set<WebPluginDelegateProxy*>::iterator it;
4079 for (it = plugin_delegates_.begin();
4080 it != plugin_delegates_.end(); ++it) {
4081 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4082 focused_plugin_id_);
4083 }
4084 return;
4085 }
4086#endif
[email protected]56ea1a62011-05-30 07:05:574087 RenderWidget::OnImeSetComposition(text,
4088 underlines,
4089 selection_start,
4090 selection_end);
4091 }
4092}
4093
4094void RenderView::OnImeConfirmComposition(const string16& text) {
4095 if (pepper_delegate_.IsPluginFocused()) {
4096 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4097 // send character events.
4098 for (size_t i = 0; i < text.size(); ++i) {
4099 WebKit::WebKeyboardEvent char_event;
4100 char_event.type = WebKit::WebInputEvent::Char;
4101 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
4102 char_event.modifiers = 0;
4103 char_event.windowsKeyCode = text[i];
4104 char_event.nativeKeyCode = text[i];
4105 char_event.text[0] = text[i];
4106 char_event.unmodifiedText[0] = text[i];
4107 if (webwidget_)
4108 webwidget_->handleInputEvent(char_event);
4109 }
4110 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234111#if defined(OS_WIN)
4112 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4113 // plug-ins. When we send IME text directly to plug-ins, we should not send
4114 // it to WebKit to prevent WebKit from controlling IMEs.
4115 if (focused_plugin_id_ >= 0) {
4116 std::set<WebPluginDelegateProxy*>::iterator it;
4117 for (it = plugin_delegates_.begin();
4118 it != plugin_delegates_.end(); ++it) {
4119 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4120 }
4121 return;
4122 }
4123#endif
[email protected]56ea1a62011-05-30 07:05:574124 RenderWidget::OnImeConfirmComposition(text);
4125 }
4126}
4127
[email protected]ad26ef42011-06-17 07:59:454128ui::TextInputType RenderView::GetTextInputType() {
[email protected]56ea1a62011-05-30 07:05:574129 if (pepper_delegate_.IsPluginFocused()) {
[email protected]7f81cc72011-09-07 18:19:314130#if !defined(TOUCH_UI)
[email protected]56ea1a62011-05-30 07:05:574131 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4132 // consider all the parts of PPAPI plugins are accepting text inputs.
[email protected]ad26ef42011-06-17 07:59:454133 return ui::TEXT_INPUT_TYPE_TEXT;
[email protected]7f81cc72011-09-07 18:19:314134#else
4135 // Disable keyboard input in flash for touch ui until PPAPI can support IME
4136 // events.
4137 return ui::TEXT_INPUT_TYPE_NONE;
4138#endif
[email protected]56ea1a62011-05-30 07:05:574139 }
[email protected]ad26ef42011-06-17 07:59:454140 return RenderWidget::GetTextInputType();
4141}
4142
4143bool RenderView::CanComposeInline() {
4144 if (pepper_delegate_.IsPluginFocused()) {
4145 // TODO(kinaba) Until PPAPI has an interface for handling IME events, there
4146 // is no way for the browser to know whether the plugin is capable of
4147 // drawing composition text. We assume plugins are incapable and let the
4148 // browser handle composition display for now.
4149 return false;
4150 }
4151 return true;
[email protected]56ea1a62011-05-30 07:05:574152}
4153
[email protected]e6ae0f6c2011-10-04 10:39:234154#if defined(OS_WIN)
4155void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
4156 if (focused)
4157 focused_plugin_id_ = plugin_id;
4158 else
4159 focused_plugin_id_ = -1;
4160}
4161#endif
4162
[email protected]43f28f832010-02-03 02:28:484163#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:134164void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
4165 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4166 focused, plugin_id);
4167 Send(msg);
4168}
4169
4170void RenderView::StartPluginIme() {
4171 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554172 // This message can be sent during event-handling, and needs to be delivered
4173 // within that context.
4174 msg->set_unblock(true);
4175 Send(msg);
4176}
4177
[email protected]ea04a4e12010-04-15 00:58:034178gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234179 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484180 gfx::PluginWindowHandle window = NULL;
4181 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234182 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114183 if (window) {
4184 fake_plugin_window_handles_.insert(window);
4185 }
[email protected]43f28f832010-02-03 02:28:484186 return window;
4187}
4188
4189void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114190 if (window && fake_plugin_window_handles_.find(window) !=
4191 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484192 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114193 fake_plugin_window_handles_.erase(window);
4194 }
[email protected]43f28f832010-02-03 02:28:484195}
4196
[email protected]44ce0b12010-03-12 16:45:334197void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4198 int32 width,
4199 int32 height,
4200 uint64 io_surface_identifier) {
4201 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484202 routing_id(), window, width, height, io_surface_identifier));
4203}
4204
[email protected]44ce0b12010-03-12 16:45:334205void RenderView::AcceleratedSurfaceSetTransportDIB(
4206 gfx::PluginWindowHandle window,
4207 int32 width,
4208 int32 height,
4209 TransportDIB::Handle transport_dib) {
4210 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074211 routing_id(), window, width, height, transport_dib));
4212}
4213
[email protected]44ce0b12010-03-12 16:45:334214TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4215 size_t size) {
[email protected]1aef98132010-02-23 18:00:074216 TransportDIB::Handle dib_handle;
4217 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384218 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074219 return dib_handle;
4220 // Return an invalid handle if Send() fails.
4221 return TransportDIB::DefaultHandleValue();
4222}
4223
[email protected]44ce0b12010-03-12 16:45:334224void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074225 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4226}
4227
[email protected]44ce0b12010-03-12 16:45:334228void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144229 gfx::PluginWindowHandle window, uint64 surface_id) {
4230 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4231 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484232}
4233#endif
[email protected]58c321d2010-02-19 12:11:284234
[email protected]cdaf8d02010-03-30 19:52:474235bool RenderView::ScheduleFileChooser(
4236 const ViewHostMsg_RunFileChooser_Params& params,
4237 WebFileChooserCompletion* completion) {
4238 static const size_t kMaximumPendingFileChooseRequests = 4;
4239 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4240 // This sanity check prevents too many file choose requests from getting
4241 // queued which could DoS the user. Getting these is most likely a
4242 // programming error (there are many ways to DoS the user so it's not
4243 // considered a "real" security check), either in JS requesting many file
4244 // choosers to pop up, or in a plugin.
4245 //
4246 // TODO(brettw) we might possibly want to require a user gesture to open
4247 // a file picker, which will address this issue in a better way.
4248 return false;
4249 }
4250
4251 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4252 new PendingFileChooser(params, completion)));
4253 if (file_chooser_completions_.size() == 1) {
4254 // Actually show the browse dialog when this is the first request.
4255 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4256 }
4257 return true;
4258}
4259
[email protected]0ff0ff32010-12-21 19:34:424260WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514261 if (!geolocation_dispatcher_)
4262 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4263 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254264}
[email protected]61c9f032010-03-31 23:04:194265
[email protected]638694c2010-08-04 22:24:114266WebKit::WebSpeechInputController* RenderView::speechInputController(
4267 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:514268 if (!speech_input_dispatcher_)
4269 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
4270 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114271}
4272
[email protected]57ead352010-08-11 14:42:534273WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514274 if (!device_orientation_dispatcher_)
4275 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4276 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534277}
4278
[email protected]b75b8292010-10-01 07:28:254279void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
4280 // For now, don't remember plugin zoom values. We don't want to mix them with
4281 // normal web content (i.e. a fixed layout plugin would usually want them
4282 // different).
4283 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4284
[email protected]b75b8292010-10-01 07:28:254285 int minimum_percent = static_cast<int>(
4286 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4287 int maximum_percent = static_cast<int>(
4288 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254289
4290 Send(new ViewHostMsg_UpdateZoomLimits(
4291 routing_id_, minimum_percent, maximum_percent, remember));
4292}
4293
4294void RenderView::zoomLevelChanged() {
4295 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084296#if defined(TOUCH_UI)
4297 float zoom_level =
4298 WebView::zoomFactorToZoomLevel(webview()->pageScaleFactor());
4299#else
4300 float zoom_level = webview()->zoomLevel();
4301#endif
[email protected]b75b8292010-10-01 07:28:254302 // Tell the browser which url got zoomed so it can update the menu and the
4303 // saved values if necessary
4304 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084305 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414306 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254307}
4308
[email protected]a6d36cc2011-02-23 00:39:484309void RenderView::registerProtocolHandler(const WebString& scheme,
4310 const WebString& base_url,
4311 const WebString& url,
4312 const WebString& title) {
4313 GURL base(base_url);
4314 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4315 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4316 return;
4317 }
[email protected]f1a29a02011-10-06 23:08:444318 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4319 UTF16ToUTF8(scheme),
4320 absolute_url,
4321 title));
[email protected]a6d36cc2011-02-23 00:39:484322}
4323
[email protected]62af76e2011-08-01 02:34:014324void RenderView::registerIntentHandler(const WebString& action,
4325 const WebString& type,
4326 const WebString& href,
4327 const WebString& title) {
[email protected]f1a29a02011-10-06 23:08:444328 Send(new ViewHostMsg_RegisterIntentHandler(routing_id_,
4329 action,
4330 type,
4331 href,
4332 title));
[email protected]62af76e2011-08-01 02:34:014333}
4334
[email protected]94dec932011-05-26 20:04:214335WebKit::WebPageVisibilityState RenderView::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444336 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4337 WebKit::WebPageVisibilityStateHidden :
4338 WebKit::WebPageVisibilityStateVisible;
4339 WebKit::WebPageVisibilityState override_state = current_state;
4340 if (content::GetContentClient()->renderer()->
4341 ShouldOverridePageVisibilityState(this,
4342 &override_state))
4343 return override_state;
4344 return current_state;
[email protected]94dec932011-05-26 20:04:214345}
4346
[email protected]e235c7d02011-08-18 22:38:434347void RenderView::startActivity(const WebKit::WebString& action,
4348 const WebKit::WebString& type,
4349 const WebKit::WebString& data,
4350 int intent_id) {
[email protected]ce9751942011-09-21 01:57:244351 webkit_glue::WebIntentData intent_data;
4352 intent_data.action = action;
4353 intent_data.type = type;
4354 intent_data.data = data;
4355 Send(new IntentsHostMsg_WebIntentDispatch(
4356 routing_id_, intent_data, intent_id));
[email protected]e235c7d02011-08-18 22:38:434357}
4358
[email protected]8079b362010-05-07 18:37:454359bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194360 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454361 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194362 if (frame->parent() != NULL)
4363 return false;
4364
[email protected]f0a3d0b2010-08-06 22:51:534365 // Navigations initiated within Webkit are not sent out to the external host
4366 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274367 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134368 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534369 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134370 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334371 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534372 return false;
4373
[email protected]2fc22d12010-12-02 23:08:164374 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324375 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014376 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164377 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014378 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324379 // The opener relationship between the new window and the parent allows the
4380 // new window to script the parent and vice versa. This is not allowed if
4381 // the origins of the two domains are different. This can be treated as a
4382 // top level navigation and routed back to the host.
4383 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274384 if (!opener) {
[email protected]86965362011-04-21 18:42:514385 return true;
[email protected]d19ea342011-04-20 20:31:134386 } else {
[email protected]b6cb3a842011-06-24 18:28:414387 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324388 return true;
4389 }
4390 }
[email protected]61c9f032010-03-31 23:04:194391 return false;
4392}
[email protected]2b06a992010-08-21 05:48:224393
[email protected]27a9ef32010-09-10 04:06:244394void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
4395 IPC::PlatformFileForTransit file_for_transit,
4396 int message_id) {
4397 pepper_delegate_.OnAsyncFileOpened(
4398 error_code,
4399 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4400 message_id);
4401}
[email protected]caf706f2010-10-26 17:54:084402
[email protected]2b657fd2011-04-18 16:00:474403void RenderView::OnPpapiBrokerChannelCreated(
4404 int request_id,
4405 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434406 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474407 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4408 broker_process_handle,
4409 handle);
[email protected]eb415bf0e2011-04-14 02:45:424410}
4411
[email protected]caf706f2010-10-26 17:54:084412#if defined(OS_MACOSX)
4413void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154414 if (external_popup_menu_ == NULL) {
4415 // Crash reports from the field indicate that we can be notified with a
4416 // NULL external popup menu (we probably get notified twice).
4417 // If you hit this please file a bug against jcivelli and include the page
4418 // and steps to repro.
4419 NOTREACHED();
4420 return;
4421 }
[email protected]caf706f2010-10-26 17:54:084422 external_popup_menu_->DidSelectItem(selected_index);
4423 external_popup_menu_.reset();
4424}
4425#endif
[email protected]bb461532010-11-26 21:50:234426
[email protected]1b4209f2011-01-07 00:25:404427#if defined(ENABLE_FLAPPER_HACKS)
4428void RenderView::OnConnectTcpACK(
4429 int request_id,
4430 IPC::PlatformFileForTransit socket_for_transit,
4431 const PP_Flash_NetAddress& local_addr,
4432 const PP_Flash_NetAddress& remote_addr) {
4433 pepper_delegate_.OnConnectTcpACK(
4434 request_id,
4435 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4436 local_addr,
4437 remote_addr);
4438}
4439#endif
[email protected]a6097f42011-01-10 08:50:514440
[email protected]b29aa74b2011-01-31 21:41:084441void RenderView::OnContextMenuClosed(
4442 const webkit_glue::CustomContextMenuContext& custom_context) {
4443 if (custom_context.is_pepper_menu)
4444 pepper_delegate_.OnContextMenuClosed(custom_context);
4445 else
4446 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104447}
[email protected]5a7b15a2011-08-22 22:48:184448
4449void RenderView::OnEnableViewSourceMode() {
4450 if (!webview())
4451 return;
4452 WebFrame* main_frame = webview()->mainFrame();
4453 if (!main_frame)
4454 return;
4455 main_frame->enableViewSourceMode(true);
4456}
[email protected]67bfb83f2011-09-22 03:36:374457
4458void RenderView::OnLockMouseACK(bool succeeded) {
4459 pepper_delegate_.OnLockMouseACK(succeeded);
4460}
4461
4462void RenderView::OnMouseLockLost() {
4463 pepper_delegate_.OnMouseLockLost();
4464}
[email protected]c3d45532011-10-07 19:20:404465
4466bool RenderView::WebWidgetHandlesCompositorScheduling() const {
4467 return webview()->settings()->useThreadedCompositor();
4468}