blob: 5248e3ef1a2cc0c848e1737b6da33f530e7a83b2 [file] [log] [blame]
[email protected]1b4209f2011-01-07 00:25:401// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]6e24cf12011-03-18 19:57:025#include "content/renderer/render_view.h"
initial.commit09911bf2008-07-26 23:55:296
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
initial.commit09911bf2008-07-26 23:55:299#include <string>
10#include <vector>
11
[email protected]2041cf342010-02-19 03:15:5912#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5014#include "base/compiler_specific.h"
[email protected]b1cf3372011-04-20 21:28:1015#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4916#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3817#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2818#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5119#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2920#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4121#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2823#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2624#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2225#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1026#include "content/common/appcache/appcache_dispatcher.h"
[email protected]9966325b2011-04-18 05:00:1027#include "content/common/bindings_policy.h"
[email protected]127dd582011-03-16 21:32:1028#include "content/common/clipboard_messages.h"
[email protected]db803aae2011-03-05 02:00:4229#include "content/common/content_constants.h"
[email protected]9966325b2011-04-18 05:00:1030#include "content/common/content_switches.h"
[email protected]37666cf2011-03-13 21:51:4231#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5532#include "content/common/drag_messages.h"
[email protected]7ef40ffe12011-03-08 05:05:2833#include "content/common/file_system/file_system_dispatcher.h"
34#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]c3113022011-04-16 03:26:3035#include "content/common/json_value_serializer.h"
[email protected]7f070d42011-03-09 20:25:3236#include "content/common/notification_service.h"
[email protected]127dd582011-03-16 21:32:1037#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0038#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4039#include "content/common/quota_dispatcher.h"
[email protected]60916042011-03-19 00:43:3640#include "content/common/renderer_preferences.h"
[email protected]940895b2011-08-20 00:50:0541#include "content/common/request_extra_data.h"
[email protected]9966325b2011-04-18 05:00:1042#include "content/common/url_constants.h"
[email protected]778574e2011-03-21 22:03:5043#include "content/common/view_messages.h"
[email protected]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]10e6ab572011-04-14 23:42:0064#include "content/renderer/render_thread.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]3a034ebb2011-10-03 19:19:44241using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36242using content::RenderViewVisitor;
[email protected]8d86f13d2011-10-04 17:01:19243using content::V8ValueConverter;
[email protected]6fdd4182010-10-14 23:59:26244using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26245using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26246using webkit_glue::PasswordForm;
247using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23248using webkit_glue::ResourceFetcher;
[email protected]e1acf6f2008-10-27 20:43:33249
initial.commit09911bf2008-07-26 23:55:29250//-----------------------------------------------------------------------------
251
[email protected]3354d3e2010-06-10 19:53:02252typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49253static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02254
[email protected]882daa92009-11-05 16:31:31255// Time, in seconds, we delay before sending content state changes (such as form
256// state and scroll position) to the browser. We delay sending changes to avoid
257// spamming the browser.
258// To avoid having tab/session restore require sending a message to get the
259// current content state during tab closing we use a shorter timeout for the
260// foreground renderer. This means there is a small window of time from which
261// content state is modified and not sent to session restore, but this is
262// better than having to wake up all renderers during shutdown.
263static const int kDelaySecondsForContentStateSyncHidden = 5;
264static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29265
[email protected]0aa55312008-10-17 21:53:08266// The maximum number of popups that can be spawned from one page.
267static const int kMaximumNumberOfUnacknowledgedPopups = 25;
268
[email protected]c514d6372011-08-16 22:54:44269static const float kScalingIncrement = 0.1f;
270
[email protected]726985e22009-06-18 21:09:28271static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
272 WebVector<WebURL> urls;
273 ds->redirectChain(urls);
274 result->reserve(urls.size());
275 for (size_t i = 0; i < urls.size(); ++i)
276 result->push_back(urls[i]);
277}
278
[email protected]6a8f5112011-05-13 16:38:44279// If |data_source| is non-null and has a NavigationState associated with it,
280// the AltErrorPageResourceFetcher is reset.
281static void StopAltErrorPageFetcher(WebDataSource* data_source) {
282 if (data_source) {
283 NavigationState* state = NavigationState::FromDataSource(data_source);
284 if (state)
285 state->set_alt_error_page_fetcher(NULL);
286 }
287}
288
initial.commit09911bf2008-07-26 23:55:29289///////////////////////////////////////////////////////////////////////////////
290
[email protected]60c42a8c72009-10-09 04:08:59291int32 RenderView::next_page_id_ = 1;
292
[email protected]cdaf8d02010-03-30 19:52:47293struct RenderView::PendingFileChooser {
294 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
295 WebFileChooserCompletion* c)
296 : params(p),
297 completion(c) {
298 }
299 ViewHostMsg_RunFileChooser_Params params;
300 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
301};
302
[email protected]2fab253a2009-08-17 23:00:59303RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51304 gfx::NativeViewId parent_hwnd,
305 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]3e2b375b2010-04-07 17:03:12312 : RenderWidget(render_thread, 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]676126f72011-01-15 00:03:51361 render_thread_->AddRoute(routing_id_, this);
362 // 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(
402 RenderThread::current()->video_capture_impl_manager());
403 }
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]81a34412009-01-05 19:17:24462 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15463 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08464 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51465 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08466 const WebPreferences& webkit_prefs,
467 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34468 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26469 int64 session_storage_namespace_id,
470 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29471 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51472 return new RenderView(
473 render_thread,
474 parent_hwnd,
475 opener_id,
476 renderer_prefs,
477 webkit_prefs,
478 counter,
479 routing_id,
480 session_storage_namespace_id,
481 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29482}
483
[email protected]bb461532010-11-26 21:50:23484// static
initial.commit09911bf2008-07-26 23:55:29485void RenderView::SetNextPageID(int32 next_page_id) {
486 // This method should only be called during process startup, and the given
487 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05488 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29489 DCHECK(next_page_id >= next_page_id_);
490 next_page_id_ = next_page_id;
491}
492
[email protected]676126f72011-01-15 00:03:51493void RenderView::AddObserver(RenderViewObserver* observer) {
494 observers_.AddObserver(observer);
495}
496
497void RenderView::RemoveObserver(RenderViewObserver* observer) {
498 observer->set_render_view(NULL);
499 observers_.RemoveObserver(observer);
500}
501
[email protected]8a3125a712010-08-09 18:58:51502WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26503 return static_cast<WebKit::WebView*>(webwidget());
504}
505
[email protected]1a3c3cb2010-12-16 21:03:40506void RenderView::SetReportLoadProgressEnabled(bool enabled) {
507 if (!enabled) {
508 load_progress_tracker_.reset(NULL);
509 return;
510 }
511 if (load_progress_tracker_ == NULL)
512 load_progress_tracker_.reset(new LoadProgressTracker(this));
513}
514
[email protected]a3a8fb6d2009-10-22 20:12:51515void RenderView::PluginCrashed(const FilePath& plugin_path) {
516 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29517}
518
[email protected]aad51d1c2010-08-05 08:38:09519WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
520 const WebPluginParams& params) {
[email protected]91d9f3d2011-08-14 05:24:44521 webkit::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26522 std::string mime_type;
[email protected]4a7d6392011-09-19 20:55:08523 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
524 params.mimeType.utf8(), &info, &mime_type);
[email protected]dfba8762011-09-02 12:49:54525 if (!found)
[email protected]aad51d1c2010-08-05 08:38:09526 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45527
[email protected]96dcc1762011-04-04 16:01:09528 bool pepper_plugin_was_registered = false;
[email protected]0bd753682010-12-16 18:15:52529 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]076117592011-08-17 03:16:41530 pepper_delegate_.CreatePepperPluginModule(info,
531 &pepper_plugin_was_registered));
[email protected]96dcc1762011-04-04 16:01:09532 if (pepper_plugin_was_registered) {
533 if (pepper_module)
534 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
535 return NULL;
536 }
[email protected]1a78d9f32010-12-08 06:38:45537 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09538}
539
[email protected]d8fd6fa2010-02-01 15:54:26540void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
541 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30542 // If the renderer is visible, set initial visibility and focus state.
543 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34544#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30545 delegate->SetContainerVisibility(true);
546 if (webview() && webview()->isActive())
547 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34548#endif
[email protected]49232292010-09-03 19:07:30549 }
[email protected]784ea1ab2010-09-18 00:02:34550 // Plugins start assuming the content has focus (so that they work in
551 // environments where RenderView isn't hosting them), so we always have to
552 // set the initial state. See webplugin_delegate_impl.h for details.
553 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26554}
555
556void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
557 plugin_delegates_.erase(delegate);
558}
[email protected]d8fd6fa2010-02-01 15:54:26559
[email protected]4a7d6392011-09-19 20:55:08560bool RenderView::GetPluginInfo(const GURL& url,
561 const GURL& page_url,
562 const std::string& mime_type,
563 webkit::WebPluginInfo* plugin_info,
564 std::string* actual_mime_type) {
565 bool found = false;
566 Send(new ViewHostMsg_GetPluginInfo(
567 routing_id_, url, page_url, mime_type, &found, plugin_info,
568 actual_mime_type));
569 return found;
570}
571
572base::SharedMemoryHandle RenderView::HostAllocateSharedMemoryBuffer(
573 uint32 buffer_size) {
574 base::SharedMemoryHandle mem_handle;
575 Send(new ViewHostMsg_AllocateSharedMemoryBuffer(buffer_size, &mem_handle));
576 return mem_handle;
577}
578
[email protected]a95986a82010-12-24 06:19:28579bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27580 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27581 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41582 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26583
[email protected]676126f72011-01-15 00:03:51584 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
585 RenderViewObserver* observer;
586 while ((observer = it.GetNext()) != NULL)
587 if (observer->OnMessageReceived(message))
588 return true;
[email protected]b2abac72009-02-26 12:39:28589
[email protected]a95986a82010-12-24 06:19:28590 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29591 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
initial.commit09911bf2008-07-26 23:55:29592 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
593 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56594 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29595 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
596 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
597 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
598 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27599#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35600 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27601#endif
initial.commit09911bf2008-07-26 23:55:29602 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
603 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
604 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
605 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08606 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29607 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15608 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29609 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49610 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
611 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17612 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17613 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:54614 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
615 OnSetZoomLevelForLoadingURL)
[email protected]8a5e0ca2011-08-25 06:30:47616 IPC_MESSAGE_HANDLER(ViewMsg_ExitFullscreen, OnExitFullscreen)
initial.commit09911bf2008-07-26 23:55:29617 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18618 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
619 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29620 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48621 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29622 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55623 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
624 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
625 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
626 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
627 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
628 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
629 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45630 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40631 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29632 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19633 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
634 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29635 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
636 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
637 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51638 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
639 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29640 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04641 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15642 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29643 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
644 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08645 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
646 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00647 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16648 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14649 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25650 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
651 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10652 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
653 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51654 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56655 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34656 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14657#if defined(OS_MACOSX)
658 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13659 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13660 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
661 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14662#endif
[email protected]446705872009-09-10 07:22:48663 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33664 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33665 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
666 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24667 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42668 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
669 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19670 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
671 OnGetAllSavableResourceLinksForCurrentPage)
672 IPC_MESSAGE_HANDLER(
673 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
674 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08675#if defined(OS_MACOSX)
676 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
677#endif
[email protected]521b2482011-01-15 00:10:10678 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51679 // TODO(viettrungluu): Move to a separate message filter.
680#if defined(ENABLE_FLAPPER_HACKS)
681 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
682#endif
[email protected]54ca3ca892011-06-07 21:14:54683#if defined(OS_MACOSX)
684 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
685#endif
[email protected]08bb1e722011-07-30 19:13:04686 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRemoteAccessClientFirewallTraversal,
687 OnUpdateRemoteAccessClientFirewallTraversal)
[email protected]9e1ad4b2011-08-14 16:49:19688 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
689 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18690 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]1ef93132011-09-16 18:33:47691 IPC_MESSAGE_HANDLER(IntentsMsg_WebIntentReply, OnWebIntentReply);
[email protected]67bfb83f2011-09-22 03:36:37692 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
693 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
[email protected]9e1ad4b2011-08-14 16:49:19694
initial.commit09911bf2008-07-26 23:55:29695 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28696 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29697 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28698 return handled;
initial.commit09911bf2008-07-26 23:55:29699}
700
initial.commit09911bf2008-07-26 23:55:29701void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
702 if (!webview())
703 return;
704
[email protected]440a0e52011-09-13 17:38:58705 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
706
[email protected]d466b8a2011-07-15 21:48:03707 bool is_reload =
708 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
709 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
710
711 // If this is a stale back/forward (due to a recent navigation the browser
712 // didn't know about), ignore it.
713 if (IsBackForwardToStaleEntry(params, is_reload))
714 return;
715
[email protected]992db4c2011-05-12 15:37:15716 // Swap this renderer back in if necessary.
717 if (is_swapped_out_)
718 SetSwappedOut(false);
719
[email protected]3cc72b12010-03-18 23:03:00720 history_list_offset_ = params.current_history_list_offset;
721 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03722 if (history_list_length_ >= 0)
723 history_page_ids_.resize(history_list_length_, -1);
724 if (params.pending_history_list_offset >= 0 &&
725 params.pending_history_list_offset < history_list_length_)
726 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00727
[email protected]38b592902011-04-16 02:08:42728 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29729
[email protected]26aa0482009-09-30 16:55:27730 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45731 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29732 // We cannot reload if we do not have any history state. This happens, for
733 // example, when recovering from a crash. Our workaround here is a bit of
734 // a hack since it means that reload after a crashed tab does not cause an
735 // end-to-end cache validation.
736 is_reload = false;
737 }
738
[email protected]77f17a82009-05-21 04:42:54739 // A navigation resulting from loading a javascript URL should not be treated
740 // as a browser initiated event. Instead, we want it to look as if the page
741 // initiated any load resulting from JS execution.
742 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30743 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00744 params.page_id,
745 params.pending_history_list_offset,
746 params.transition,
747 params.request_time);
[email protected]2c5569662011-03-22 20:45:02748 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30749 // We're doing a load of a page that was restored from the last session.
750 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
751 // which can result in stale data for pages that are set to expire. We
752 // explicitly override that by setting the policy here so that as
753 // necessary we load from the network.
754 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
755 }
756 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54757 }
initial.commit09911bf2008-07-26 23:55:29758
[email protected]a7ccc4d2010-01-27 08:14:48759 NavigationState* navigation_state = pending_navigation_state_.get();
760
[email protected]48a5c772011-04-18 23:50:50761 if (navigation_state) {
762 // New loads need to reset the error page fetcher. Otherwise if there is an
763 // outstanding error page fetcher it may complete and clobber the current
764 // page load.
765 navigation_state->set_alt_error_page_fetcher(NULL);
766 }
767
[email protected]04d3c6e2009-05-22 17:00:13768 // If we are reloading, then WebKit will use the history state of the current
769 // page, so we should just ignore any given history state. Otherwise, if we
770 // have history state, then we need to navigate to it, which corresponds to a
771 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55772 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48773 if (navigation_state)
774 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29775 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02776 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29777 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55778 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13779 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58780 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48781 if (navigation_state)
782 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45783 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17784 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13785 } else {
786 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28787 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29788
[email protected]e6f546c32009-07-01 17:12:55789 // A session history navigation should have been accompanied by state.
790 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13791
[email protected]dd7daa82009-08-10 05:46:45792 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55793 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13794
[email protected]726985e22009-06-18 21:09:28795 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17796 if (!WebSecurityPolicy::shouldHideReferrer(
797 params.url,
798 WebString::fromUTF8(params.referrer.spec()))) {
799 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
800 WebString::fromUTF8(params.referrer.spec()));
801 }
[email protected]726985e22009-06-18 21:09:28802 }
[email protected]04d3c6e2009-05-22 17:00:13803
[email protected]52c68652010-12-07 17:47:04804 if (!params.extra_headers.empty()) {
805 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
806 params.extra_headers.end(), "\n");
807 i.GetNext(); ) {
808 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
809 WebString::fromUTF8(i.values()));
810 }
811 }
812
[email protected]16e923d2011-04-30 00:41:44813 if (navigation_state)
814 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45815 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50816 }
817
[email protected]77f17a82009-05-21 04:42:54818 // In case LoadRequest failed before DidCreateDataSource was called.
819 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29820}
821
[email protected]d466b8a2011-07-15 21:48:03822bool RenderView::IsBackForwardToStaleEntry(
823 const ViewMsg_Navigate_Params& params,
824 bool is_reload) {
825 // Make sure this isn't a back/forward to an entry we have already cropped
826 // or replaced from our history, before the browser knew about it. If so,
827 // a new navigation has committed in the mean time, and we can ignore this.
828 bool is_back_forward = !is_reload && !params.state.empty();
829
830 // Note: if the history_list_length_ is 0 for a back/forward, we must be
831 // restoring from a previous session. We'll update our state in OnNavigate.
832 if (!is_back_forward || history_list_length_ <= 0)
833 return false;
834
835 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
836
837 // Check for whether the forward history has been cropped due to a recent
838 // navigation the browser didn't know about.
839 if (params.pending_history_list_offset >= history_list_length_)
840 return true;
841
842 // Check for whether this entry has been replaced with a new one.
843 int expected_page_id =
844 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44845 if (expected_page_id > 0 && params.page_id != expected_page_id) {
846 if (params.page_id < expected_page_id)
847 return true;
848
849 // Otherwise we've removed an earlier entry and should have shifted all
850 // entries left. For now, it's ok to lazily update the list.
851 // TODO(creis): Notify all live renderers when we remove entries from
852 // the front of the list, so that we don't hit this case.
853 history_page_ids_[params.pending_history_list_offset] = params.page_id;
854 }
[email protected]d466b8a2011-07-15 21:48:03855
856 return false;
857}
858
initial.commit09911bf2008-07-26 23:55:29859// Stop loading the current page
860void RenderView::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44861 if (webview()) {
862 WebFrame* main_frame = webview()->mainFrame();
863 // Stop the alt error page fetcher. If we let it continue it may complete
864 // and cause RenderViewHostManager to swap to this RenderView, even though
865 // it may no longer be active.
866 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
867 StopAltErrorPageFetcher(main_frame->dataSource());
868 main_frame->stopLoading();
869 }
initial.commit09911bf2008-07-26 23:55:29870}
871
[email protected]ecbf10d2010-02-18 13:03:29872// Reload current focused frame.
873// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56874void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29875 if (webview() && webview()->focusedFrame()) {
876 // We always obey the cache (ignore_cache=false) here.
877 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
878 // a cache-ignoring reload of the frame.
879 webview()->focusedFrame()->reload(false);
880 }
[email protected]1dda4022010-01-28 18:24:56881}
882
initial.commit09911bf2008-07-26 23:55:29883void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27884 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29885}
886
[email protected]68b1e922009-06-23 16:00:25887void RenderView::OnExecuteEditCommand(const std::string& name,
888 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27889 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25890 return;
891
[email protected]26aa0482009-09-30 16:55:27892 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45893 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25894}
895
initial.commit09911bf2008-07-26 23:55:29896void RenderView::OnUpdateTargetURLAck() {
897 // Check if there is a targeturl waiting to be sent.
898 if (target_url_status_ == TARGET_PENDING) {
899 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
900 pending_target_url_));
901 }
902
903 target_url_status_ = TARGET_NONE;
904}
905
906void RenderView::OnUndo() {
907 if (!webview())
908 return;
909
[email protected]26aa0482009-09-30 16:55:27910 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29911}
912
913void RenderView::OnRedo() {
914 if (!webview())
915 return;
916
[email protected]26aa0482009-09-30 16:55:27917 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29918}
919
920void RenderView::OnCut() {
921 if (!webview())
922 return;
923
[email protected]26aa0482009-09-30 16:55:27924 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29925}
926
927void RenderView::OnCopy() {
928 if (!webview())
929 return;
930
[email protected]f6b1856b2011-06-29 22:02:53931 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
932 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29933}
934
[email protected]c0cc3092009-09-12 08:27:27935#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35936void RenderView::OnCopyToFindPboard() {
937 if (!webview())
938 return;
939
940 // Since the find pasteboard supports only plain text, this can be simpler
941 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27942 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35943 if (frame->hasSelection()) {
944 string16 selection = frame->selectionAsText();
945 RenderThread::current()->Send(
[email protected]7e3589742011-03-10 18:49:17946 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35947 }
[email protected]a954bf72009-09-12 07:30:35948}
[email protected]c0cc3092009-09-12 08:27:27949#endif
[email protected]a954bf72009-09-12 07:30:35950
initial.commit09911bf2008-07-26 23:55:29951void RenderView::OnPaste() {
952 if (!webview())
953 return;
954
[email protected]26aa0482009-09-30 16:55:27955 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29956}
957
[email protected]2a3a7762009-10-19 19:17:32958void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29959 if (!webview())
960 return;
961
[email protected]1ff7a032010-02-03 02:46:03962 WebFrame* frame = webview()->focusedFrame();
963 if (!frame->hasSelection())
964 frame->selectWordAroundCaret();
965 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29966}
967
968void RenderView::OnDelete() {
969 if (!webview())
970 return;
971
[email protected]26aa0482009-09-30 16:55:27972 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29973}
974
975void RenderView::OnSelectAll() {
976 if (!webview())
977 return;
978
[email protected]26aa0482009-09-30 16:55:27979 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22980 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29981}
982
[email protected]4fb60142011-08-09 02:22:08983void RenderView::OnSelectRange(const gfx::Point& start, const gfx::Point& end) {
984 if (!webview())
985 return;
986
987 handling_select_range_ = true;
988 webview()->focusedFrame()->selectRange(start, end);
989 handling_select_range_ = false;
990}
991
[email protected]9e1ad4b2011-08-14 16:49:19992void RenderView::OnSetHistoryLengthAndPrune(int history_length,
993 int32 minimum_page_id) {
994 DCHECK(history_length >= 0);
995 DCHECK(history_list_offset_ == history_list_length_ - 1);
996 DCHECK(minimum_page_id >= -1);
997
998 // Generate the new list.
999 std::vector<int32> new_history_page_ids(history_length, -1);
1000 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
1001 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
1002 continue;
1003 new_history_page_ids.push_back(history_page_ids_[i]);
1004 }
1005 new_history_page_ids.swap(history_page_ids_);
1006
1007 // Update indexes.
1008 history_list_length_ = history_page_ids_.size();
1009 history_list_offset_ = history_list_length_ - 1;
1010}
1011
1012
initial.commit09911bf2008-07-26 23:55:291013void RenderView::OnSetInitialFocus(bool reverse) {
1014 if (!webview())
1015 return;
[email protected]26aa0482009-09-30 16:55:271016 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291017}
1018
[email protected]54ca3ca892011-06-07 21:14:541019#if defined(OS_MACOSX)
1020void RenderView::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331021 if (!webview())
1022 return;
1023 if (in_live_resize)
1024 webview()->willStartLiveResize();
1025 else
1026 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541027}
1028#endif
1029
[email protected]333ec8d02011-09-16 18:59:191030void RenderView::OnScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091031 WebKit::WebNode node = GetFocusedNode();
1032 if (!node.isNull()) {
1033 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191034 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511035 }
1036}
1037
initial.commit09911bf2008-07-26 23:55:291038///////////////////////////////////////////////////////////////////////////////
1039
1040// Tell the embedding application that the URL of the active page has changed
1041void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451042 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291043 DCHECK(ds);
1044
[email protected]726985e22009-06-18 21:09:281045 const WebURLRequest& request = ds->request();
1046 const WebURLRequest& original_request = ds->originalRequest();
1047 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291048
[email protected]daa8c58e2009-06-15 17:21:101049 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1050 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291051
1052 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281053 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291054 params.is_post = false;
1055 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071056 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191057 params.socket_address.set_host(response.remoteIPAddress().utf8());
1058 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031059 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091060 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551061 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291062 // SSL state specified in the request takes precedence over the one in the
1063 // response.
1064 // So far this is only intended for error pages that are not expected to be
1065 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281066 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551067 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291068 } else {
[email protected]726985e22009-06-18 21:09:281069 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291070 }
1071
1072 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281073 if (ds->hasUnreachableURL()) {
1074 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291075 } else {
[email protected]726985e22009-06-18 21:09:281076 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291077 }
1078
[email protected]726985e22009-06-18 21:09:281079 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241080 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041081 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291082
[email protected]ce0e250d2009-10-23 21:00:351083 params.searchable_form_url = navigation_state->searchable_form_url();
1084 params.searchable_form_encoding =
1085 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291086
1087 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101088 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291089 if (password_form_data)
1090 params.password_form = *password_form_data;
1091
1092 params.gesture = navigation_gesture_;
1093 navigation_gesture_ = NavigationGestureUnknown;
1094
[email protected]0f38dc4552011-02-25 11:24:001095 // Make navigation state a part of the FrameNavigate message so that commited
1096 // entry had it at all times.
1097 const WebHistoryItem& item = frame->currentHistoryItem();
1098 if (!item.isNull()) {
1099 params.content_state = webkit_glue::HistoryItemToString(item);
1100 } else {
1101 params.content_state =
1102 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1103 }
1104
[email protected]dd7daa82009-08-10 05:46:451105 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291106 // Top-level navigation.
1107
[email protected]b75b8292010-10-01 07:28:251108 // Set zoom level, but don't do it for full-page plugin since they don't use
1109 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011110 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541111 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251112 if (webview()->mainFrame()->document().isPluginDocument()) {
1113 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251114 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251115 } else {
1116 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251117 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251118 }
1119
[email protected]f85f0702010-01-30 09:31:011120 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511121 // This zoom level was merely recorded transiently for this load. We can
1122 // erase it now. If at some point we reload this page, the browser will
1123 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011124 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511125 }
1126
[email protected]b75b8292010-10-01 07:28:251127 // Reset the zoom limits in case a plugin had changed them previously. This
1128 // will also call us back which will cause us to send a message to
1129 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251130 webview()->zoomLimitsChanged(
1131 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1132 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251133
initial.commit09911bf2008-07-26 23:55:291134 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551135 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291136
[email protected]daa8c58e2009-06-15 17:21:101137 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291138 if (!PageTransition::IsMainFrame(params.transition)) {
1139 // If the main frame does a load, it should not be reported as a subframe
1140 // navigation. This can occur in the following case:
1141 // 1. You're on a site with frames.
1142 // 2. You do a subframe navigation. This is stored with transition type
1143 // MANUAL_SUBFRAME.
1144 // 3. You navigate to some non-frame site, say, google.com.
1145 // 4. You navigate back to the page from step 2. Since it was initially
1146 // MANUAL_SUBFRAME, it will be that same transition type here.
1147 // We don't want that, because any navigation that changes the toplevel
1148 // frame should be tracked as a toplevel navigation (this allows us to
1149 // update the URL bar, etc).
1150 params.transition = PageTransition::LINK;
1151 }
1152
initial.commit09911bf2008-07-26 23:55:291153 // If we have a valid consumed client redirect source,
1154 // the page contained a client redirect (meta refresh, document.loc...),
1155 // so we set the referrer and transition to match.
1156 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041157 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291158 params.referrer = completed_client_redirect_src_;
1159 params.transition = static_cast<PageTransition::Type>(
1160 params.transition | PageTransition::CLIENT_REDIRECT);
1161 } else {
1162 // Bug 654101: the referrer will be empty on https->http transitions. It
1163 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281164 params.referrer = GURL(
1165 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291166 }
1167
[email protected]726985e22009-06-18 21:09:281168 string16 method = request.httpMethod();
1169 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291170 params.is_post = true;
1171
[email protected]c2a797d2009-09-21 16:46:321172 // Save some histogram data so we can compute the average memory used per
1173 // page load of the glyphs.
1174 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1175 webkit_glue::GetGlyphPageCount());
1176
[email protected]15cf526b2010-02-12 06:33:491177 // This message needs to be sent before any of allowScripts(),
1178 // allowImages(), allowPlugins() is called for the new page, so that when
1179 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1180 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291181 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1182 } else {
1183 // Subframe navigation: the type depends on whether this navigation
1184 // generated a new session history entry. When they do generate a session
1185 // history entry, it means the user initiated the navigation and we should
1186 // mark it as such. This test checks if this is the first time UpdateURL
1187 // has been called since WillNavigateToURL was called to initiate the load.
1188 if (page_id_ > last_page_id_sent_to_browser_)
1189 params.transition = PageTransition::MANUAL_SUBFRAME;
1190 else
1191 params.transition = PageTransition::AUTO_SUBFRAME;
1192
initial.commit09911bf2008-07-26 23:55:291193 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1194 }
1195
1196 last_page_id_sent_to_browser_ =
1197 std::max(last_page_id_sent_to_browser_, page_id_);
1198
1199 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101200 // we don't want the transition type to persist. Just clear it.
1201 navigation_state->set_transition_type(PageTransition::LINK);
initial.commit09911bf2008-07-26 23:55:291202}
1203
1204// Tell the embedding application that the title of the active page has changed
[email protected]750fcf872011-08-03 23:10:471205void RenderView::UpdateTitle(WebFrame* frame,
1206 const string16& title,
[email protected]a49e10b2011-08-01 23:57:461207 WebTextDirection title_direction) {
1208 // Ignore all but top level navigations.
1209 if (frame->parent())
1210 return;
1211
1212 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1213 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1214 title_direction));
initial.commit09911bf2008-07-26 23:55:291215}
1216
1217void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401218 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291219 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271220 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291221 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301222 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291223 last_encoding_name_ = encoding_name;
1224
[email protected]e38f40152008-09-12 23:08:301225 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291226 }
1227}
1228
[email protected]e15f680732010-11-23 22:30:201229// Sends the last committed session history state to the browser so it will be
1230// saved before we navigate to a new page. This must be called *before* the
1231// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291232void RenderView::UpdateSessionHistory(WebFrame* frame) {
1233 // If we have a valid page ID at this point, then it corresponds to the page
1234 // we are navigating away from. Otherwise, this is the first navigation, so
1235 // there is no past session history to record.
1236 if (page_id_ == -1)
1237 return;
1238
[email protected]ca948a22009-06-25 19:36:171239 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271240 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171241 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291242 return;
[email protected]ca948a22009-06-25 19:36:171243
1244 Send(new ViewHostMsg_UpdateState(
1245 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291246}
1247
[email protected]3d9689372009-09-10 04:29:171248void RenderView::OpenURL(
1249 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1250 Send(new ViewHostMsg_OpenURL(
1251 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1252}
1253
[email protected]79dbc662009-09-04 05:42:511254// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291255
initial.commit09911bf2008-07-26 23:55:291256void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281257 const WebURLRequest& failed_request,
1258 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291259 const std::string& html,
1260 bool replace) {
[email protected]21d61e52011-03-18 19:08:251261 std::string alt_html = !html.empty() ? html :
1262 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1263 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451264 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361265 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251266 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551267 replace);
initial.commit09911bf2008-07-26 23:55:291268}
1269
initial.commit09911bf2008-07-26 23:55:291270bool RenderView::RunJavaScriptMessage(int type,
[email protected]4f5ce842011-05-27 19:34:411271 const string16& message,
1272 const string16& default_value,
[email protected]a455d3812009-03-05 20:18:071273 const GURL& frame_url,
[email protected]4f5ce842011-05-27 19:34:411274 string16* result) {
initial.commit09911bf2008-07-26 23:55:291275 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411276 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291277 if (!result)
1278 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291279
[email protected]12636df2009-09-28 22:32:211280 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1281 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291282 return success;
1283}
1284
[email protected]c1f50aa2010-02-18 03:46:571285bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1286 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1287 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1288 // it is particularly important that we do not call willEnterModalLoop as
1289 // that would defer resource loads for the dialog itself.
1290 if (RenderThread::current()) // Will be NULL during unit tests.
1291 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1292
1293 message->EnableMessagePumping(); // Runs a nested message loop.
1294 return Send(message);
1295}
1296
[email protected]48c9cf2d2009-09-16 16:47:521297// WebKit::WebViewClient ------------------------------------------------------
1298
[email protected]844acf372011-01-14 10:49:271299WebView* RenderView::createView(
1300 WebFrame* creator,
1301 const WebURLRequest& request,
1302 const WebWindowFeatures& features,
1303 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521304 // Check to make sure we aren't overloading on popups.
1305 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1306 return NULL;
1307
[email protected]8ab04652010-06-12 02:47:261308 ViewHostMsg_CreateWindow_Params params;
1309 params.opener_id = routing_id_;
1310 params.user_gesture = creator->isProcessingUserGesture();
1311 params.window_container_type = WindowFeaturesToContainerType(features);
1312 params.session_storage_namespace_id = session_storage_namespace_id_;
1313 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111314 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411315 params.opener_url = creator->document().url();
1316 params.opener_security_origin =
1317 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111318 if (!request.isNull())
1319 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261320
[email protected]48c9cf2d2009-09-16 16:47:521321 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341322 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261323 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521324
[email protected]48c9cf2d2009-09-16 16:47:521325 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:261326 new ViewHostMsg_CreateWindow(params,
1327 &routing_id,
1328 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211329 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521330 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521331
[email protected]48c9cf2d2009-09-16 16:47:521332 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:421333 0,
[email protected]12636df2009-09-28 22:32:211334 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521335 renderer_preferences_,
1336 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211337 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341338 routing_id,
[email protected]8ab04652010-06-12 02:47:261339 cloned_session_storage_namespace_id,
1340 frame_name);
1341 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521342
[email protected]007a848b2009-10-26 15:55:461343 // Record whether the creator frame is trying to suppress the opener field.
1344 view->opener_suppressed_ = opener_suppressed;
1345
[email protected]48c9cf2d2009-09-16 16:47:521346 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411347 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521348 if (!creator_url.is_valid() || !creator_url.IsStandard())
1349 creator_url = GURL();
1350 view->creator_url_ = creator_url;
1351
1352 // Copy over the alternate error page URL so we can have alt error pages in
1353 // the new render view (we don't need the browser to send the URL back down).
1354 view->alternate_error_page_url_ = alternate_error_page_url_;
1355
1356 return view->webview();
1357}
1358
[email protected]3e2b375b2010-04-07 17:03:121359WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:521360 RenderWidget* widget = RenderWidget::Create(routing_id_,
1361 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:121362 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521363 return widget->webwidget();
1364}
1365
1366WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441367 // TODO(jcivelli): Remove this deprecated method when its been removed from
1368 // the WebViewClient interface. It's been replaced by
1369 // createExternalPopupMenu.
1370 NOTREACHED();
1371 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521372}
1373
[email protected]caf706f2010-10-26 17:54:081374WebExternalPopupMenu* RenderView::createExternalPopupMenu(
1375 const WebPopupMenuInfo& popup_menu_info,
1376 WebExternalPopupMenuClient* popup_menu_client) {
1377 DCHECK(!external_popup_menu_.get());
1378 external_popup_menu_.reset(
1379 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1380 return external_popup_menu_.get();
1381}
1382
[email protected]ea192e82011-04-11 19:16:021383RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521384 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531385 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421386 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411387 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531388 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
1389 routing_id_, render_thread_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391390 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561391 return widget;
[email protected]79c7bed2010-09-14 22:28:391392}
1393
[email protected]68c50e52010-05-12 11:14:391394WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341395 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391396 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291397 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1398 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1399 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341400}
1401
[email protected]48c9cf2d2009-09-16 16:47:521402void RenderView::didAddMessageToConsole(
1403 const WebConsoleMessage& message, const WebString& source_name,
1404 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081405 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511406 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081407 case WebConsoleMessage::LevelTip:
1408 log_severity = logging::LOG_VERBOSE;
1409 break;
1410 case WebConsoleMessage::LevelLog:
1411 log_severity = logging::LOG_INFO;
1412 break;
1413 case WebConsoleMessage::LevelWarning:
1414 log_severity = logging::LOG_WARNING;
1415 break;
1416 case WebConsoleMessage::LevelError:
1417 log_severity = logging::LOG_ERROR;
1418 break;
1419 default:
1420 NOTREACHED();
1421 }
1422
[email protected]48c9cf2d2009-09-16 16:47:521423 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081424 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311425 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521426 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311427 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521428}
1429
1430void RenderView::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421431 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521432}
1433
[email protected]3354d3e2010-06-10 19:53:021434WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511435 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021436}
1437
[email protected]8a58c1c2011-04-19 18:40:121438bool RenderView::enumerateChosenDirectory(
1439 const WebString& path,
1440 WebFileChooserCompletion* chooser_completion) {
1441 int id = enumeration_completion_id_++;
1442 enumeration_completions_[id] = chooser_completion;
1443 return Send(new ViewHostMsg_EnumerateDirectory(
1444 routing_id_,
1445 id,
1446 webkit_glue::WebStringToFilePath(path)));
1447}
1448
[email protected]48c9cf2d2009-09-16 16:47:521449void RenderView::didStartLoading() {
1450 if (is_loading_) {
1451 DLOG(WARNING) << "didStartLoading called while loading";
1452 return;
1453 }
1454
1455 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521456
1457 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311458
1459 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521460}
1461
1462void RenderView::didStopLoading() {
1463 if (!is_loading_) {
1464 DLOG(WARNING) << "DidStopLoading called while not loading";
1465 return;
1466 }
1467
1468 is_loading_ = false;
1469
1470 // NOTE: For now we're doing the safest thing, and sending out notification
1471 // when done loading. This currently isn't an issue as the favicon is only
1472 // displayed when done loading. Ideally we would send notification when
1473 // finished parsing the head, but webkit doesn't support that yet.
1474 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521475 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1476
[email protected]90109412010-12-15 17:14:241477 if (load_progress_tracker_ != NULL)
1478 load_progress_tracker_->DidStopLoading();
1479
[email protected]93b9d692011-04-13 00:44:311480 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521481}
1482
[email protected]90109412010-12-15 17:14:241483void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
1484 if (load_progress_tracker_ != NULL)
1485 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1486}
1487
[email protected]f55039a2010-02-17 14:12:061488bool RenderView::isSmartInsertDeleteEnabled() {
1489#if defined(OS_MACOSX)
1490 return true;
1491#else
1492 return false;
1493#endif
1494}
1495
[email protected]04fc9482009-09-18 22:13:031496bool RenderView::isSelectTrailingWhitespaceEnabled() {
1497#if defined(OS_WIN)
1498 return true;
1499#else
1500 return false;
1501#endif
1502}
1503
[email protected]04fc9482009-09-18 22:13:031504void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:421505#if defined(OS_POSIX)
[email protected]4fb60142011-08-09 02:22:081506 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031507 return;
[email protected]4fb60142011-08-09 02:22:081508 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011509
[email protected]b781ff282011-08-20 06:19:361510 SyncSelectionIfRequired();
[email protected]0ff0ff32010-12-21 19:34:421511#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031512}
1513
1514void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121515 const std::string& name = UTF16ToUTF8(command_name);
1516 if (StartsWithASCII(name, "Move", true) ||
1517 StartsWithASCII(name, "Insert", true) ||
1518 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031519 return;
[email protected]4a7d6392011-09-19 20:55:081520 RenderThread::RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031521}
1522
[email protected]b2528b72009-09-24 06:57:101523bool RenderView::handleCurrentKeyboardEvent() {
1524 if (edit_commands_.empty())
1525 return false;
1526
[email protected]26aa0482009-09-30 16:55:271527 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101528 if (!frame)
1529 return false;
1530
1531 EditCommands::iterator it = edit_commands_.begin();
1532 EditCommands::iterator end = edit_commands_.end();
1533
[email protected]507b33ea2009-09-29 03:56:511534 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101535 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331536 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1537 // key (but it's the exception). Once one edit command is not executed, it
1538 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101539 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1540 WebString::fromUTF8(it->value)))
1541 break;
[email protected]507b33ea2009-09-29 03:56:511542 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101543 }
1544
[email protected]507b33ea2009-09-29 03:56:511545 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101546}
1547
[email protected]a1128322009-10-06 18:38:461548bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351549 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471550 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351551 // Do not open the file dialog in a hidden RenderView.
1552 if (is_hidden())
1553 return false;
[email protected]cdaf8d02010-03-30 19:52:471554 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261555 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361556 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261557 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361558 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]b5977a0c2010-08-24 19:46:261559 else
[email protected]0aed2f52011-03-23 18:06:361560 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471561 ipc_params.title = params.title;
1562 ipc_params.default_file_name =
1563 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591564 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471565
1566 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461567}
1568
[email protected]48c9cf2d2009-09-16 16:47:521569void RenderView::runModalAlertDialog(
1570 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061571 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]4f5ce842011-05-27 19:34:411572 message,
1573 string16(),
[email protected]b6cb3a842011-06-24 18:28:411574 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521575 NULL);
1576}
1577
1578bool RenderView::runModalConfirmDialog(
1579 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061580 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]4f5ce842011-05-27 19:34:411581 message,
1582 string16(),
[email protected]b6cb3a842011-06-24 18:28:411583 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521584 NULL);
1585}
1586
1587bool RenderView::runModalPromptDialog(
1588 WebFrame* frame, const WebString& message, const WebString& default_value,
1589 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411590 string16 result;
[email protected]9dd7e3d72011-01-20 18:27:061591 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]4f5ce842011-05-27 19:34:411592 message,
1593 default_value,
[email protected]b6cb3a842011-06-24 18:28:411594 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521595 &result);
1596 if (ok)
[email protected]4f5ce842011-05-27 19:34:411597 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521598 return ok;
1599}
1600
1601bool RenderView::runModalBeforeUnloadDialog(
1602 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151603 // If we are swapping out, we have already run the beforeunload handler.
1604 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1605 // at all, to avoid running it twice.
1606 if (is_swapped_out_)
1607 return true;
1608
[email protected]48c9cf2d2009-09-16 16:47:521609 bool success = false;
1610 // This is an ignored return value, but is included so we can accept the same
1611 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411612 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211613 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411614 routing_id_, frame->document().url(), message,
1615 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521616 return success;
1617}
1618
[email protected]79e37442009-10-09 18:17:441619void RenderView::showContextMenu(
1620 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291621 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371622
1623 // frame is NULL if invoked by BlockedPlugin.
1624 if (frame)
1625 params.frame_id = frame->identifier();
1626
[email protected]db803aae2011-03-05 02:00:421627 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271628 // it. We replace it with an empty GURL so the appropriate items are disabled
1629 // in the context menu.
1630 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1631 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421632 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271633 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101634 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291635 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441636}
1637
[email protected]52f139e2c2010-06-11 16:56:091638bool RenderView::supportsFullscreen() {
1639 return CommandLine::ForCurrentProcess()->HasSwitch(
1640 switches::kEnableVideoFullscreen);
1641}
1642
1643void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1644 NOTIMPLEMENTED();
1645}
1646
1647void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1648 NOTIMPLEMENTED();
1649}
1650
[email protected]8a5e0ca2011-08-25 06:30:471651void RenderView::enterFullscreen() {
1652 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1653}
1654
1655void RenderView::exitFullscreen() {
1656 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1657}
1658
[email protected]48c9cf2d2009-09-16 16:47:521659void RenderView::setStatusText(const WebString& text) {
1660}
1661
[email protected]163f8242009-10-30 20:19:551662void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581663 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521664 if (latest_url == target_url_)
1665 return;
[email protected]163f8242009-10-30 20:19:551666
[email protected]48c9cf2d2009-09-16 16:47:521667 // Tell the browser to display a destination link.
1668 if (target_url_status_ == TARGET_INFLIGHT ||
1669 target_url_status_ == TARGET_PENDING) {
1670 // If we have a request in-flight, save the URL to be sent when we
1671 // receive an ACK to the in-flight request. We can happily overwrite
1672 // any existing pending sends.
1673 pending_target_url_ = latest_url;
1674 target_url_status_ = TARGET_PENDING;
1675 } else {
1676 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1677 target_url_ = latest_url;
1678 target_url_status_ = TARGET_INFLIGHT;
1679 }
1680}
1681
[email protected]882daa92009-11-05 16:31:311682void RenderView::StartNavStateSyncTimerIfNecessary() {
1683 int delay;
1684 if (send_content_state_immediately_)
1685 delay = 0;
1686 else if (is_hidden())
1687 delay = kDelaySecondsForContentStateSyncHidden;
1688 else
1689 delay = kDelaySecondsForContentStateSync;
1690
1691 if (nav_state_sync_timer_.IsRunning()) {
1692 // The timer is already running. If the delay of the timer maches the amount
1693 // we want to delay by, then return. Otherwise stop the timer so that it
1694 // gets started with the right delay.
1695 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1696 return;
1697 nav_state_sync_timer_.Stop();
1698 }
1699
[email protected]d323a172011-09-02 18:23:021700 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1701 &RenderView::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311702}
1703
[email protected]163f8242009-10-30 20:19:551704void RenderView::setMouseOverURL(const WebURL& url) {
1705 mouse_over_url_ = GURL(url);
1706 UpdateTargetURL(mouse_over_url_, focus_url_);
1707}
1708
1709void RenderView::setKeyboardFocusURL(const WebURL& url) {
1710 focus_url_ = GURL(url);
1711 UpdateTargetURL(focus_url_, mouse_over_url_);
1712}
1713
[email protected]c27ae592010-03-18 15:24:411714void RenderView::startDragging(const WebDragData& data,
1715 WebDragOperationsMask mask,
1716 const WebImage& image,
1717 const WebPoint& imageOffset) {
1718#if WEBKIT_USING_SKIA
1719 SkBitmap bitmap(image.getSkBitmap());
1720#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331721 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411722#endif
1723
[email protected]59f4f2fa2011-03-23 01:00:551724 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521725 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411726 mask,
1727 bitmap,
1728 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521729}
1730
[email protected]28b92df2009-09-25 17:35:451731bool RenderView::acceptsLoadDrops() {
1732 return renderer_preferences_.can_accept_load_drops;
1733}
1734
[email protected]48c9cf2d2009-09-16 16:47:521735void RenderView::focusNext() {
1736 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1737}
1738
1739void RenderView::focusPrevious() {
1740 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1741}
1742
[email protected]08e9e132010-06-01 16:58:491743void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511744 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071745
[email protected]38b592902011-04-16 02:08:421746 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491747}
1748
[email protected]48c9cf2d2009-09-16 16:47:521749void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521750 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1751}
1752
1753int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001754 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521755}
1756
1757int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001758 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521759}
1760
[email protected]063afcb2011-09-29 07:54:321761void RenderView::postAccessibilityNotification(
1762 const WebAccessibilityObject& obj,
1763 WebAccessibilityNotification notification) {
1764 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1765}
1766
[email protected]c4e98902010-06-01 10:20:141767void RenderView::didUpdateInspectorSetting(const WebString& key,
1768 const WebString& value) {
1769 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1770 key.utf8(),
1771 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261772}
1773
[email protected]79dbc662009-09-04 05:42:511774// WebKit::WebWidgetClient ----------------------------------------------------
1775
[email protected]ea42e7782010-08-23 23:58:121776void RenderView::didFocus() {
1777 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1778 // we won't have to test for user gesture anymore and we can
1779 // move that code back to render_widget.cc
1780 if (webview() && webview()->mainFrame() &&
1781 webview()->mainFrame()->isProcessingUserGesture()) {
1782 Send(new ViewHostMsg_Focus(routing_id_));
1783 }
1784}
1785
1786void RenderView::didBlur() {
1787 // TODO(jcivelli): see TODO above in didFocus().
1788 if (webview() && webview()->mainFrame() &&
1789 webview()->mainFrame()->isProcessingUserGesture()) {
1790 Send(new ViewHostMsg_Blur(routing_id_));
1791 }
1792}
1793
initial.commit09911bf2008-07-26 23:55:291794// We are supposed to get a single call to Show for a newly created RenderView
1795// that was created via RenderView::CreateWebView. So, we wait until this
1796// point to dispatch the ShowView message.
1797//
1798// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281799// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291800//
[email protected]4873c7d2009-07-16 06:36:281801void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291802 DCHECK(!did_show_) << "received extraneous Show call";
1803 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1804
1805 if (did_show_)
1806 return;
1807 did_show_ = true;
1808
[email protected]6779aa12011-03-29 17:32:241809 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041810 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041811
[email protected]28295ec2009-10-16 05:34:331812 // Force new windows to a popup if they were not opened with a user gesture.
1813 if (!opened_by_user_gesture_) {
1814 // We exempt background tabs for compat with older versions of Chrome.
1815 // TODO(darin): This seems bogus. These should have a user gesture, so
1816 // we probably don't need this check.
1817 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1818 policy = WebKit::WebNavigationPolicyNewPopup;
1819 }
1820
initial.commit09911bf2008-07-26 23:55:291821 // NOTE: initial_pos_ may still have its default values at this point, but
1822 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1823 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281824 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1825 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291826 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241827 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291828}
1829
[email protected]4873c7d2009-07-16 06:36:281830void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291831 DCHECK(did_show_) << "should already have shown the view";
1832
[email protected]c1f50aa2010-02-18 03:46:571833 // We must keep WebKit's shared timer running in this case in order to allow
1834 // showModalDialog to function properly.
1835 //
1836 // TODO(darin): WebKit should really be smarter about suppressing events and
1837 // timers so that we do not need to manage the shared timer in such a heavy
1838 // handed manner.
1839 //
1840 if (RenderThread::current()) // Will be NULL during unit tests.
1841 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
1842
[email protected]12636df2009-09-28 22:32:211843 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291844}
1845
[email protected]3d9689372009-09-10 04:29:171846// WebKit::WebFrameClient -----------------------------------------------------
1847
[email protected]00152e92010-07-19 11:47:401848WebPlugin* RenderView::createPlugin(WebFrame* frame,
1849 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:551850 WebPlugin* plugin = NULL;
1851 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
1852 this, frame, params, &plugin)) {
1853 return plugin;
1854 }
1855
1856 return CreatePluginNoCheck(frame, params);
[email protected]3d9689372009-09-10 04:29:171857}
1858
1859WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561860 WebApplicationCacheHostImpl* appcache_host =
1861 WebApplicationCacheHostImpl::FromFrame(frame);
1862 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
1863 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
1864 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171865}
1866
[email protected]9c00f002009-11-05 22:37:421867WebSharedWorker* RenderView::createSharedWorker(
1868 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371869 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421870
[email protected]30447b62009-11-13 01:13:371871 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511872 bool exists = false;
[email protected]30447b62009-11-13 01:13:371873 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511874 ViewHostMsg_CreateWorker_Params params;
1875 params.url = url;
1876 params.is_shared = true;
1877 params.name = name;
1878 params.document_id = document_id;
1879 params.render_view_route_id = routing_id_;
1880 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231881 params.parent_appcache_host_id = 0;
1882 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371883 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511884 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371885 if (url_mismatch) {
1886 return NULL;
1887 } else {
1888 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:491889 document_id,
[email protected]6de0bcf2010-02-17 22:00:511890 exists,
[email protected]30447b62009-11-13 01:13:371891 route_id,
1892 routing_id_);
1893 }
[email protected]9c00f002009-11-05 22:37:421894}
1895
[email protected]3d9689372009-09-10 04:29:171896WebMediaPlayer* RenderView::createMediaPlayer(
1897 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441898 FOR_EACH_OBSERVER(
1899 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171900
[email protected]f78d1dfc2011-01-15 07:09:271901 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1902 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491903 scoped_ptr<media::FilterCollection> collection(
1904 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371905
[email protected]3d9689372009-09-10 04:29:171906 // Add in any custom filter factories first.
1907 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1908 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1909 // Add the chrome specific audio renderer.
[email protected]f7eb0a392011-07-12 10:19:511910 collection->AddAudioRenderer(new AudioRendererImpl());
[email protected]3d9689372009-09-10 04:29:171911 }
1912
[email protected]457d8342010-10-23 01:20:371913 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:311914 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
1915 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
1916 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:491917 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:311918 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:111919
[email protected]a8e24d522010-12-01 07:13:581920 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:271921 new webkit_glue::WebMediaPlayerImpl(client,
1922 collection.release(),
[email protected]ab2c4732011-07-20 19:57:401923 message_loop_factory.release(),
[email protected]090f7312011-08-05 23:26:401924 media_stream_impl_.get(),
1925 new RenderMediaLog()));
[email protected]79684282010-12-06 21:15:461926 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:581927 cmd_line->HasSwitch(switches::kSimpleDataSource),
1928 video_renderer)) {
1929 return NULL;
1930 }
1931 return result.release();
[email protected]3d9689372009-09-10 04:29:171932}
1933
[email protected]035545f2010-04-09 13:10:211934WebApplicationCacheHost* RenderView::createApplicationCacheHost(
1935 WebFrame* frame, WebApplicationCacheHostClient* client) {
1936 return new RendererWebApplicationCacheHostImpl(
1937 FromWebView(frame->view()), client,
1938 RenderThread::current()->appcache_dispatcher()->backend_proxy());
1939}
1940
[email protected]8ff181072010-11-29 17:09:381941WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
1942 return &cookie_jar_;
1943}
1944
[email protected]5041f982010-08-11 21:40:451945void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511946 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451947}
1948
[email protected]3d9689372009-09-10 04:29:171949void RenderView::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511950 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171951}
1952
1953void RenderView::loadURLExternally(
1954 WebFrame* frame, const WebURLRequest& request,
1955 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:341956 loadURLExternally(frame, request, policy, WebString());
1957}
1958
1959void RenderView::loadURLExternally(
1960 WebFrame* frame, const WebURLRequest& request,
1961 WebNavigationPolicy policy,
1962 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:591963 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1964 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:341965 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
1966 suggested_name));
[email protected]efce17b2009-09-11 18:04:591967 } else {
1968 OpenURL(request.url(), referrer, policy);
1969 }
[email protected]3d9689372009-09-10 04:29:171970}
1971
1972WebNavigationPolicy RenderView::decidePolicyForNavigation(
1973 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221974 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:151975 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
1976 if (is_swapped_out_) {
1977 DCHECK(request.url() == GURL("about:swappedout"));
1978 return default_policy;
1979 }
1980
[email protected]3d9689372009-09-10 04:29:171981 // Webkit is asking whether to navigate to a new URL.
1982 // This is fine normally, except if we're showing UI from one security
1983 // context and they're trying to navigate to a different context.
1984 const GURL& url = request.url();
1985
[email protected]d19ea342011-04-20 20:31:131986 // A content initiated navigation may have originated from a link-click,
1987 // script, drag-n-drop operation, etc.
1988 bool is_content_initiated =
1989 NavigationState::FromDataSource(frame->provisionalDataSource())->
1990 is_content_initiated();
1991
[email protected]3d9689372009-09-10 04:29:171992 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:301993 // navigations.
[email protected]d19ea342011-04-20 20:31:131994 if (is_content_initiated &&
1995 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:451996 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:191997 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:231998 // Reset these counters as the RenderView could be reused for the next
1999 // navigation.
2000 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232001 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192002 OpenURL(url, referrer, default_policy);
2003 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172004 }
2005
[email protected]6101c342010-12-16 22:44:372006 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552007 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572008 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372009 // opening a new window). But we sometimes navigate to about:blank to clear a
2010 // tab, and we want to still allow that.
2011 //
[email protected]8f4da8c2011-02-09 19:49:572012 // Note: we do this only for GET requests because our mechanism for switching
2013 // processes only issues GET requests. In particular, POST requests don't
2014 // work, because this mechanism does not preserve form POST data. If it
2015 // becomes necessary to support process switching for POST requests, we will
2016 // need to send the request's httpBody data up to the browser process, and
2017 // issue a special POST navigation in WebKit (via
2018 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2019 // for examples of how to send the httpBody data.
2020 // Note2: We normally don't do this for browser-initiated navigations, since
2021 // it's pointless to tell the browser about navigations it gave us. But
2022 // we do potentially ask the browser to handle a redirect that was originally
2023 // initiated by the browser. See http://crbug.com/70943
2024 //
2025 // TODO(creis): Move this redirect check to the browser process to avoid
2026 // ping-ponging. See http://crbug.com/72380.
2027 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372028 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2029 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2030 bool send_referrer = false;
2031 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552032 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172033 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372034 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112035
[email protected]e48869a2011-04-01 19:56:032036 if (!should_fork) {
2037 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362038 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032039 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362040 frame, url, is_content_initiated, is_initial_navigation,
2041 &send_referrer);
[email protected]6101c342010-12-16 22:44:372042 }
2043
2044 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112045 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372046 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112047 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2048 }
[email protected]3d9689372009-09-10 04:29:172049 }
2050
[email protected]43763f982011-08-26 18:33:402051 // Use the frame's original request's URL rather than the document's URL for
2052 // this check. For a popup, the document's URL may become the opener window's
2053 // URL if the opener has called document.write. See http://crbug.com/93517.
2054 GURL old_url(frame->dataSource()->request().url());
2055
[email protected]3d9689372009-09-10 04:29:172056 // Detect when a page is "forking" a new tab that can be safely rendered in
2057 // its own process. This is done by sites like Gmail that try to open links
2058 // in new windows without script connections back to the original page. We
2059 // treat such cases as browser navigations (in which we will create a new
2060 // renderer for a cross-site navigation), rather than WebKit navigations.
2061 //
2062 // We use the following heuristic to decide whether to fork a new page in its
2063 // own process:
2064 // The parent page must open a new tab to about:blank, set the new tab's
2065 // window.opener to null, and then redirect the tab to a cross-site URL using
2066 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462067 //
2068 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2069 // (see below).
[email protected]3d9689372009-09-10 04:29:172070 bool is_fork =
2071 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582072 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172073 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522074 historyBackListCount() < 1 &&
2075 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172076 // The parent page must have set the child's window.opener to null before
2077 // redirecting to the desired URL.
2078 frame->opener() == NULL &&
2079 // Must be a top-level frame.
2080 frame->parent() == NULL &&
2081 // Must not have issued the request from this page.
2082 is_content_initiated &&
2083 // Must be targeted at the current tab.
2084 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2085 // Must be a JavaScript navigation, which appears as "other".
2086 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462087
2088 // Recognize if this navigation is from a link with rel=noreferrer and
2089 // target=_blank attributes, in which case the opener will be suppressed. If
2090 // so, it is safe to load cross-site pages in a separate process, so we
2091 // should let the browser handle it.
2092 bool is_noreferrer_and_blank_target =
2093 // Frame should be top level and not yet navigated.
2094 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412095 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462096 historyBackListCount() < 1 &&
2097 historyForwardListCount() < 1 &&
2098 // Links with rel=noreferrer will have no Referer field, and their
2099 // resulting frame will have its window.opener suppressed.
2100 // TODO(creis): should add a request.httpReferrer() method to help avoid
2101 // typos on the unusual spelling of Referer.
2102 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2103 opener_suppressed_ &&
2104 frame->opener() == NULL &&
2105 // Links with target=_blank will have no name.
2106 frame->name().isNull() &&
2107 // Another frame (with a non-empty creator) should have initiated the
2108 // request, targeted at this frame.
2109 !creator_url_.is_empty() &&
2110 is_content_initiated &&
2111 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2112 type == WebKit::WebNavigationTypeOther;
2113
2114 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172115 // Open the URL via the browser, not via WebKit.
2116 OpenURL(url, GURL(), default_policy);
2117 return WebKit::WebNavigationPolicyIgnore;
2118 }
2119
2120 return default_policy;
2121}
2122
[email protected]6069da8c2009-10-20 20:33:492123bool RenderView::canHandleRequest(
2124 WebFrame* frame, const WebURLRequest& request) {
2125 // We allow WebKit to think that everything can be handled even though
2126 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342127 return true;
2128}
2129
[email protected]6069da8c2009-10-20 20:33:492130WebURLError RenderView::cannotHandleRequestError(
2131 WebFrame* frame, const WebURLRequest& request) {
2132 NOTREACHED(); // Since we said we can handle all requests.
2133 return WebURLError();
2134}
2135
2136WebURLError RenderView::cancelledError(
2137 WebFrame* frame, const WebURLRequest& request) {
2138 WebURLError error;
2139 error.domain = WebString::fromUTF8(net::kErrorDomain);
2140 error.reason = net::ERR_ABORTED;
2141 error.unreachableURL = request.url();
2142 return error;
[email protected]7b7a7dc2009-10-19 02:23:342143}
2144
2145void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492146 WebFrame*, const WebURLError&) {
2147 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342148}
2149
[email protected]90eeddb2010-05-06 21:06:432150void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2151 const WebKit::WebFormElement& form) {
2152 // Some login forms have onSubmit handlers that put a hash of the password
2153 // into a hidden field and then clear the password. (Issue 28910.)
2154 // This method gets called before any of those handlers run, so save away
2155 // a copy of the password in case it gets lost.
2156 NavigationState* navigation_state =
2157 NavigationState::FromDataSource(frame->dataSource());
2158 navigation_state->set_password_form_data(
2159 PasswordFormDomManager::CreatePasswordForm(form));
2160}
2161
[email protected]979c28b2009-11-07 01:30:482162void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172163 NavigationState* navigation_state =
2164 NavigationState::FromDataSource(frame->provisionalDataSource());
2165
2166 if (navigation_state->transition_type() == PageTransition::LINK)
2167 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2168
2169 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352170 WebSearchableFormData web_searchable_form_data(form);
2171 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2172 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212173 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432174 PasswordForm* password_form_data =
2175 PasswordFormDomManager::CreatePasswordForm(form);
2176 navigation_state->set_password_form_data(password_form_data);
2177
[email protected]098c95cb2011-04-28 16:49:012178 // In order to save the password that the user actually typed and not one
2179 // that may have gotten transformed by the site prior to submit, recover it
2180 // from the form contents already stored by |willSendSubmitEvent| into the
2181 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2182 // which is what we're storing into now.)
2183 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432184 NavigationState* old_navigation_state =
2185 NavigationState::FromDataSource(frame->dataSource());
2186 if (old_navigation_state) {
2187 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2188 if (old_form_data && old_form_data->action == password_form_data->action)
2189 password_form_data->password_value = old_form_data->password_value;
2190 }
2191 }
[email protected]3d9689372009-09-10 04:29:172192
[email protected]2a5b1732011-04-01 23:55:552193 FOR_EACH_OBSERVER(
2194 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172195}
2196
2197void RenderView::willPerformClientRedirect(
2198 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2199 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382200 FOR_EACH_OBSERVER(
2201 RenderViewObserver, observers_,
2202 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172203}
2204
2205void RenderView::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382206 FOR_EACH_OBSERVER(
2207 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172208}
2209
2210void RenderView::didCompleteClientRedirect(
2211 WebFrame* frame, const WebURL& from) {
2212 if (!frame->parent())
2213 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382214 FOR_EACH_OBSERVER(
2215 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172216}
2217
2218void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2219 // The rest of RenderView assumes that a WebDataSource will always have a
2220 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482221 bool content_initiated = !pending_navigation_state_.get();
2222 NavigationState* state = content_initiated ?
2223 NavigationState::CreateContentInitiated() :
2224 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512225
[email protected]8a3125a712010-08-09 18:58:512226 // NavigationState::referred_by_prefetcher_ is true if we are
2227 // navigating from a page that used prefetching using a link on that
2228 // page. We are early enough in the request process here that we
2229 // can still see the NavigationState of the previous page and set
2230 // this value appropriately.
2231 // TODO(gavinp): catch the important case of navigation in a new
2232 // renderer process.
2233 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302234 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522235 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512236 const GURL referrer(
2237 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2238 if (!referrer.is_empty() &&
2239 NavigationState::FromDataSource(
2240 old_frame->dataSource())->was_prefetcher()) {
2241 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2242 WebDataSource* old_frame_ds = old_frame->dataSource();
2243 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2244 state->set_was_referred_by_prefetcher(true);
2245 break;
2246 }
2247 }
2248 }
2249 }
2250 }
2251
[email protected]4c1b6f0b2010-02-07 16:38:182252 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522253 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512254 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182255 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2256 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2257 break;
2258 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2259 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2260 break;
2261 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2262 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2263 break;
2264 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2265 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2266 break;
2267 }
2268 }
[email protected]fa7b6b542009-11-03 05:02:302269
[email protected]16e923d2011-04-30 00:41:442270 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502271
[email protected]946a0032011-03-31 18:42:282272 FOR_EACH_OBSERVER(
2273 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172274}
2275
2276void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2277 WebDataSource* ds = frame->provisionalDataSource();
2278 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2279
[email protected]3d9689372009-09-10 04:29:172280 // Update the request time if WebKit has better knowledge of it.
2281 if (navigation_state->request_time().is_null()) {
2282 double event_time = ds->triggeringEventTime();
2283 if (event_time != 0.0)
2284 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2285 }
2286
[email protected]05c8e502010-08-15 15:13:522287 // Start time is only set after request time.
2288 navigation_state->set_start_load_time(Time::Now());
2289
[email protected]3d9689372009-09-10 04:29:172290 bool is_top_most = !frame->parent();
2291 if (is_top_most) {
2292 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132293 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172294
2295 // Make sure redirect tracking state is clear for the new load.
2296 completed_client_redirect_src_ = GURL();
2297 } else if (frame->parent()->isLoading()) {
2298 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002299 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172300 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2301 }
2302
[email protected]28685da92011-02-07 21:49:172303 FOR_EACH_OBSERVER(
2304 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2305
[email protected]eacb080b2011-05-22 19:40:262306 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]3d9689372009-09-10 04:29:172307 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]eacb080b2011-05-22 19:40:262308 routing_id_, frame->identifier(), is_top_most, has_opener_set,
2309 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172310}
2311
2312void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2313 if (frame->parent())
2314 return;
2315 // Received a redirect on the main frame.
2316 WebDataSource* data_source = frame->provisionalDataSource();
2317 if (!data_source) {
2318 // Should only be invoked when we have a data source.
2319 NOTREACHED();
2320 return;
2321 }
2322 std::vector<GURL> redirects;
2323 GetRedirectChain(data_source, &redirects);
2324 if (redirects.size() >= 2) {
[email protected]eacb080b2011-05-22 19:40:262325 bool has_opener_set = opener_id_ != MSG_ROUTING_NONE;
[email protected]40bd6582009-12-04 23:49:512326 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]eacb080b2011-05-22 19:40:262327 has_opener_set, redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172328 }
2329}
2330
[email protected]40bd6582009-12-04 23:49:512331void RenderView::didFailProvisionalLoad(WebFrame* frame,
2332 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172333 // Notify the browser that we failed a provisional load with an error.
2334 //
2335 // Note: It is important this notification occur before DidStopLoading so the
2336 // SSL manager can react to the provisional load failure before being
2337 // notified the load stopped.
2338 //
2339 WebDataSource* ds = frame->provisionalDataSource();
2340 DCHECK(ds);
2341
2342 const WebURLRequest& failed_request = ds->request();
2343
[email protected]28685da92011-02-07 21:49:172344 FOR_EACH_OBSERVER(
2345 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2346
[email protected]3d9689372009-09-10 04:29:172347 bool show_repost_interstitial =
2348 (error.reason == net::ERR_CACHE_MISS &&
2349 EqualsASCII(failed_request.httpMethod(), "POST"));
2350 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072351 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2352 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172353
2354 // Don't display an error page if this is simply a cancelled load. Aside
2355 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2356 if (error.reason == net::ERR_ABORTED)
2357 return;
2358
2359 // Make sure we never show errors in view source mode.
2360 frame->enableViewSourceMode(false);
2361
2362 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2363
2364 // If this is a failed back/forward/reload navigation, then we need to do a
2365 // 'replace' load. This is necessary to avoid messing up session history.
2366 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2367 // as session history is concerned.
2368 //
2369 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2370 // the page id.
2371 //
2372 bool replace =
2373 navigation_state->pending_page_id() != -1 ||
2374 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2375
2376 // If we failed on a browser initiated request, then make sure that our error
2377 // page load is regarded as the same browser initiated request.
2378 if (!navigation_state->is_content_initiated()) {
2379 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2380 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002381 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172382 navigation_state->transition_type(),
2383 navigation_state->request_time()));
2384 }
2385
2386 // Provide the user with a more helpful error page?
2387 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2388 return;
2389
2390 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082391 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172392}
2393
2394void RenderView::didReceiveDocumentData(
2395 WebFrame* frame, const char* data, size_t data_len,
2396 bool& prevent_default) {
2397 NavigationState* navigation_state =
2398 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092399 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172400}
2401
[email protected]40bd6582009-12-04 23:49:512402void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2403 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172404 NavigationState* navigation_state =
2405 NavigationState::FromDataSource(frame->dataSource());
2406
2407 navigation_state->set_commit_load_time(Time::Now());
2408 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202409 // When we perform a new navigation, we need to update the last committed
2410 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172411 UpdateSessionHistory(frame);
2412
2413 // We bump our Page ID to correspond with the new session history entry.
2414 page_id_ = next_page_id_++;
2415
[email protected]3cc72b12010-03-18 23:03:002416 // Advance our offset in session history, applying the length limit. There
2417 // is now no forward history.
2418 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102419 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2420 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002421 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032422 history_page_ids_.resize(history_list_length_, -1);
2423 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172424 } else {
2425 // Inspect the navigation_state on this frame to see if the navigation
2426 // corresponds to a session history navigation... Note: |frame| may or
2427 // may not be the toplevel frame, but for the case of capturing session
2428 // history, the first committed frame suffices. We keep track of whether
2429 // we've seen this commit before so that only capture session history once
2430 // per navigation.
2431 //
2432 // Note that we need to check if the page ID changed. In the case of a
2433 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2434 // previous URL and the current page ID, which would be wrong.
2435 if (navigation_state->pending_page_id() != -1 &&
2436 navigation_state->pending_page_id() != page_id_ &&
2437 !navigation_state->request_committed()) {
2438 // This is a successful session history navigation!
2439 UpdateSessionHistory(frame);
2440 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002441
2442 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032443
2444 // If the history list is valid, our list of page IDs should be correct.
2445 DCHECK(history_list_length_ <= 0 ||
2446 history_list_offset_ < 0 ||
2447 history_list_offset_ >= history_list_length_ ||
2448 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172449 }
2450 }
2451
[email protected]28685da92011-02-07 21:49:172452 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2453 DidCommitProvisionalLoad(frame, is_new_navigation));
2454
[email protected]3d9689372009-09-10 04:29:172455 // Remember that we've already processed this request, so we don't update
2456 // the session history again. We do this regardless of whether this is
2457 // a session history navigation, because if we attempted a session history
2458 // navigation without valid HistoryItem state, WebCore will think it is a
2459 // new navigation.
2460 navigation_state->set_request_committed(true);
2461
2462 UpdateURL(frame);
2463
2464 // If this committed load was initiated by a client redirect, we're
2465 // at the last stop now, so clear it.
2466 completed_client_redirect_src_ = GURL();
2467
2468 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272469 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172470}
2471
2472void RenderView::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102473 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2474 DidClearWindowObject(frame));
2475
[email protected]b6cb3a842011-06-24 18:28:412476 GURL frame_url = frame->document().url();
[email protected]c09163a2011-02-15 00:05:552477 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:252478 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2479 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272480 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172481 }
[email protected]3d9689372009-09-10 04:29:172482}
2483
2484void RenderView::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172485 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412486 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252487 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272488 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172489 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2490 }
[email protected]e48869a2011-04-01 19:56:032491
2492 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2493 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172494}
2495
[email protected]a3bc4d12011-04-20 17:22:212496void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title,
2497 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462498 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172499
2500 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272501 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172502}
2503
[email protected]42054a252011-05-17 18:02:132504void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
2505 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2506 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582507}
2508
[email protected]3d9689372009-09-10 04:29:172509void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2510 WebDataSource* ds = frame->dataSource();
2511 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2512 DCHECK(navigation_state);
2513 navigation_state->set_finish_document_load_time(Time::Now());
2514
[email protected]622474d2010-11-04 09:21:082515 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172516
[email protected]28685da92011-02-07 21:49:172517 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2518 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172519
2520 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272521 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172522}
2523
2524void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082525 if (webview()->mainFrame() == frame) {
2526 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2527 page_id_));
2528 }
[email protected]3d9689372009-09-10 04:29:172529}
2530
2531void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172532 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172533}
2534
2535void RenderView::didFinishLoad(WebFrame* frame) {
2536 WebDataSource* ds = frame->dataSource();
2537 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2538 DCHECK(navigation_state);
2539 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412540
[email protected]676126f72011-01-15 00:03:512541 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172542
2543 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172544}
2545
[email protected]ccbe04e2010-03-17 17:58:432546void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172547 WebFrame* frame, bool is_new_navigation) {
2548 // If this was a reference fragment navigation that we initiated, then we
2549 // could end up having a non-null pending navigation state. We just need to
2550 // update the ExtraData on the datasource so that others who read the
2551 // ExtraData will get the new NavigationState. Similarly, if we did not
2552 // initiate this navigation, then we need to take care to reset any pre-
2553 // existing navigation state to a content-initiated navigation state.
2554 // DidCreateDataSource conveniently takes care of this for us.
2555 didCreateDataSource(frame, frame->dataSource());
2556
[email protected]af15bed2010-08-25 21:12:092557 NavigationState* new_state =
2558 NavigationState::FromDataSource(frame->dataSource());
2559 new_state->set_was_within_same_page(true);
2560
[email protected]3d9689372009-09-10 04:29:172561 didCommitProvisionalLoad(frame, is_new_navigation);
2562
[email protected]750fcf872011-08-03 23:10:472563 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2564 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172565}
2566
[email protected]476b6f82009-09-10 21:00:592567void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312568 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592569}
2570
[email protected]3d9689372009-09-10 04:29:172571void RenderView::assignIdentifierToRequest(
2572 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2573 // Ignore
2574}
2575
[email protected]d88bf0a2011-08-30 23:55:572576void RenderView::willSendRequest(WebFrame* frame,
2577 unsigned identifier,
2578 WebURLRequest& request,
2579 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302580 WebFrame* top_frame = frame->top();
2581 if (!top_frame)
2582 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512583 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2584 WebDataSource* top_data_source = top_frame->dataSource();
2585 WebDataSource* data_source =
2586 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222587
[email protected]78d5cfe2011-02-04 08:43:222588 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032589 GURL new_url;
2590 if (content::GetContentClient()->renderer()->WillSendRequest(
2591 frame, request_url, &new_url)) {
2592 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222593 }
2594
[email protected]d88bf0a2011-08-30 23:55:572595 PageTransition::Type transition_type = PageTransition::LINK;
2596 NavigationState* data_state = NavigationState::FromDataSource(data_source);
2597 if (data_state) {
2598 if (data_state->is_cache_policy_override_set())
2599 request.setCachePolicy(data_state->cache_policy_override());
2600 transition_type = data_state->transition_type();
[email protected]5e369672009-11-03 23:48:302601 }
[email protected]8a3125a712010-08-09 18:58:512602
[email protected]d88bf0a2011-08-30 23:55:572603 request.setExtraData(new RequestExtraData((frame == top_frame),
2604 frame->identifier(), transition_type));
2605
2606 NavigationState* top_data_state =
2607 NavigationState::FromDataSource(top_data_source);
2608 // TODO(gavinp): separate out prefetching and prerender field trials
2609 // if the rel=prerender rel type is sticking around.
2610 if (top_data_state &&
2611 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2612 request.targetType() == WebURLRequest::TargetIsPrerender))
2613 top_data_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512614
[email protected]3d9689372009-09-10 04:29:172615 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132616 request.setHasUserGesture(frame->isProcessingUserGesture());
2617
[email protected]0a8db0d2011-04-13 15:15:402618 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132619 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172620}
2621
2622void RenderView::didReceiveResponse(
2623 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492624
[email protected]3d9689372009-09-10 04:29:172625 // Only do this for responses that correspond to a provisional data source
2626 // of the top-most frame. If we have a provisional data source, then we
2627 // can't have any sub-resources yet, so we know that this response must
2628 // correspond to a frame load.
2629 if (!frame->provisionalDataSource() || frame->parent())
2630 return;
2631
2632 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082633 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172634 if (frame->isViewSourceModeEnabled())
2635 return;
2636
[email protected]65041fa2010-05-21 06:56:532637 NavigationState* navigation_state =
2638 NavigationState::FromDataSource(frame->provisionalDataSource());
2639 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082640 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532641
[email protected]972ebdff2010-06-10 22:59:072642 // Record page load flags.
2643 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2644 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572645 navigation_state->set_was_alternate_protocol_available(
2646 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072647 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082648 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092649 // Whether or not the http status code actually corresponds to an error is
2650 // only checked when the page is done loading, if |use_error_page| is
2651 // still true.
2652 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172653}
2654
2655void RenderView::didFinishResourceLoad(
2656 WebFrame* frame, unsigned identifier) {
2657 NavigationState* navigation_state =
2658 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092659 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172660 return;
2661
[email protected]7bfc153f2011-09-23 22:00:202662 // Do not show error page when DevTools is attached.
2663 if (devtools_agent_->IsAttached())
2664 return;
2665
[email protected]06333afe2011-02-24 14:55:092666 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082667 int http_status_code = navigation_state->http_status_code();
2668 if (http_status_code == 404) {
2669 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412670 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172671
[email protected]b6cb3a842011-06-24 18:28:412672 const GURL& error_page_url =
2673 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092674 if (error_page_url.is_valid()) {
2675 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472676 original_error.domain = "http";
2677 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412678 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172679
[email protected]06333afe2011-02-24 14:55:092680 navigation_state->set_alt_error_page_fetcher(
2681 new AltErrorPageResourceFetcher(
2682 error_page_url, frame, original_error,
2683 NewCallback(this, &RenderView::AltErrorPageFinished)));
2684 return;
2685 }
2686 }
[email protected]3d9689372009-09-10 04:29:172687
[email protected]9966325b2011-04-18 05:00:102688 content::GetContentClient()->renderer()->ShowErrorPage(
2689 this, frame, http_status_code);
[email protected]3d9689372009-09-10 04:29:172690}
2691
2692void RenderView::didFailResourceLoad(
2693 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2694 // Ignore
2695}
2696
2697void RenderView::didLoadResourceFromMemoryCache(
2698 WebFrame* frame, const WebURLRequest& request,
2699 const WebURLResponse& response) {
2700 // Let the browser know we loaded a resource from the memory cache. This
2701 // message is needed to display the correct SSL indicators.
2702 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2703 routing_id_,
2704 request.url(),
[email protected]70435962011-08-02 20:13:282705 response.securityInfo(),
2706 request.httpMethod().utf8(),
2707 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172708}
2709
[email protected]6069da8c2009-10-20 20:33:492710void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292711 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2712}
2713
[email protected]92771112011-01-20 00:13:022714void RenderView::didRunInsecureContent(
2715 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292716 Send(new ViewHostMsg_DidRunInsecureContent(
2717 routing_id_,
[email protected]92771112011-01-20 00:13:022718 origin.toString().utf8(),
2719 target));
[email protected]e3d60e5d2009-09-25 21:08:292720}
2721
[email protected]b00ba702011-08-17 01:41:032722void RenderView::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
2723 webkit_glue::WebURLLoaderImpl* loader_impl =
2724 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2725 loader_impl->UpdateRoutingId(routing_id_);
2726}
2727
[email protected]3d9689372009-09-10 04:29:172728void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2729 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2730}
2731
[email protected]5bc10932011-09-21 21:03:302732void RenderView::didCreateScriptContext(WebFrame* frame,
2733 v8::Handle<v8::Context> context,
2734 int world_id) {
2735 content::GetContentClient()->renderer()->DidCreateScriptContext(
2736 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282737}
2738
[email protected]5bc10932011-09-21 21:03:302739void RenderView::willReleaseScriptContext(WebFrame* frame,
2740 v8::Handle<v8::Context> context,
2741 int world_id) {
2742 content::GetContentClient()->renderer()->WillReleaseScriptContext(
2743 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282744}
2745
[email protected]d812fd12011-05-27 23:05:072746void RenderView::didUpdateLayout(WebFrame* frame) {
2747 // We don't always want to set up a timer, only if we've been put in that
2748 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172749 // message.
[email protected]705243f2010-05-05 19:58:072750 if (!send_preferred_size_changes_ || !webview())
2751 return;
[email protected]dfca5acf2010-03-22 03:28:432752
[email protected]d812fd12011-05-27 23:05:072753 if (check_preferred_size_timer_.IsRunning())
2754 return;
[email protected]d323a172011-09-02 18:23:022755 check_preferred_size_timer_.Start(FROM_HERE,
2756 TimeDelta::FromMilliseconds(0), this,
[email protected]d812fd12011-05-27 23:05:072757 &RenderView::CheckPreferredSize);
2758}
2759
2760void RenderView::CheckPreferredSize() {
2761 // We don't always want to send the change messages over IPC, only if we've
2762 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2763 // message.
2764 if (!send_preferred_size_changes_ || !webview())
2765 return;
2766
[email protected]705243f2010-05-05 19:58:072767 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2768 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532769
2770 // In the presence of zoom, these sizes are still reported as if unzoomed,
2771 // so we need to adjust.
2772 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2773 size.set_width(static_cast<int>(size.width() * zoom_factor));
2774 size.set_height(static_cast<int>(size.height() * zoom_factor));
2775
[email protected]705243f2010-05-05 19:58:072776 if (size == preferred_size_)
2777 return;
[email protected]c27324b2009-11-19 22:44:292778
[email protected]705243f2010-05-05 19:58:072779 preferred_size_ = size;
2780 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2781 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172782}
2783
[email protected]dd6afca2011-08-13 03:44:312784void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2785 if (webview()->mainFrame() != frame)
2786 return;
2787 WebView* frameView = frame->view();
2788 if (!frameView)
2789 return;
2790
2791 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
2792 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
2793
2794 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
2795 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
2796 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
2797 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
2798
2799 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
2800 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
2801 }
2802}
2803
2804void RenderView::UpdateScrollState(WebFrame* frame) {
2805 WebSize offset = frame->scrollOffset();
2806 WebSize minimum_offset = frame->minimumScrollOffset();
2807 WebSize maximum_offset = frame->maximumScrollOffset();
2808
2809 bool is_pinned_to_left = offset.width <= minimum_offset.width;
2810 bool is_pinned_to_right = offset.width >= maximum_offset.width;
2811
2812 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
2813 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
2814 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
2815 routing_id_, is_pinned_to_left, is_pinned_to_right));
2816
2817 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
2818 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
2819 }
2820}
2821
[email protected]143dcd592009-11-06 21:33:492822void RenderView::didChangeScrollOffset(WebFrame* frame) {
2823 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:312824
2825 if (webview()->mainFrame() == frame)
2826 UpdateScrollState(frame);
2827}
2828
2829void RenderView::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2830 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:492831}
2832
[email protected]8922e1f2009-10-03 05:01:262833void RenderView::reportFindInPageMatchCount(int request_id, int count,
2834 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112835 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2836 if (!count)
2837 active_match_ordinal = 0;
2838
2839 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2840 routing_id_,
2841 request_id,
2842 count,
2843 gfx::Rect(),
2844 active_match_ordinal,
2845 final_update);
2846
[email protected]8922e1f2009-10-03 05:01:262847 // If we have a message that has been queued up, then we should just replace
2848 // it. The ACK from the browser will make sure it gets sent when the browser
2849 // wants it.
2850 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262851 queued_find_reply_message_.reset(msg);
2852 } else {
2853 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112854 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262855 }
2856}
2857
2858void RenderView::reportFindInPageSelection(int request_id,
2859 int active_match_ordinal,
2860 const WebRect& selection_rect) {
2861 // Send the search result over to the browser process.
2862 Send(new ViewHostMsg_Find_Reply(routing_id_,
2863 request_id,
2864 -1,
2865 selection_rect,
2866 active_match_ordinal,
2867 false));
2868}
2869
[email protected]2b06a992010-08-21 05:48:222870void RenderView::openFileSystem(
2871 WebFrame* frame,
2872 WebFileSystem::Type type,
2873 long long size,
[email protected]d275d7a2010-11-03 01:34:492874 bool create,
[email protected]2b06a992010-08-21 05:48:222875 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082876 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222877
[email protected]b6cb3a842011-06-24 18:28:412878 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082879 if (origin.isEmpty()) {
2880 // Uninitialized document?
2881 callbacks->didFail(WebKit::WebFileErrorAbort);
2882 return;
2883 }
[email protected]2b06a992010-08-21 05:48:222884
[email protected]c5a272d2010-09-27 18:37:082885 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2886 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492887 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222888}
2889
[email protected]10e5cf12011-04-13 04:10:402890void RenderView::queryStorageUsageAndQuota(
2891 WebFrame* frame,
2892 WebStorageQuotaType type,
2893 WebStorageQuotaCallbacks* callbacks) {
2894 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412895 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402896 if (origin.isEmpty()) {
2897 // Uninitialized document?
2898 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2899 return;
2900 }
2901 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:532902 GURL(origin.toString()),
2903 static_cast<quota::StorageType>(type),
2904 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402905}
2906
2907void RenderView::requestStorageQuota(
2908 WebFrame* frame,
2909 WebStorageQuotaType type,
2910 unsigned long long requested_size,
2911 WebStorageQuotaCallbacks* callbacks) {
2912 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412913 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402914 if (origin.isEmpty()) {
2915 // Uninitialized document?
2916 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2917 return;
2918 }
2919 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:532920 routing_id(), GURL(origin.toString()),
2921 static_cast<quota::StorageType>(type), requested_size,
2922 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402923}
2924
[email protected]18d5be92011-07-25 18:00:192925// WebKit::WebPageSerializerClient implementation ------------------------------
2926
2927void RenderView::didSerializeDataForFrame(
2928 const WebURL& frame_url,
2929 const WebCString& data,
2930 WebPageSerializerClient::PageSerializationStatus status) {
2931 Send(new ViewHostMsg_SendSerializedHtmlData(
2932 routing_id(),
2933 frame_url,
2934 data.data(),
2935 static_cast<int32>(status)));
2936}
2937
[email protected]79dbc662009-09-04 05:42:512938// webkit_glue::WebPluginPageDelegate -----------------------------------------
2939
[email protected]191eb3f72010-12-21 06:27:502940webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:532941 const FilePath& file_path,
2942 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:592943 if (!PluginChannelHost::IsListening())
2944 return NULL;
2945
[email protected]00c39612010-03-06 02:53:282946 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:462947 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:322948#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:222949 return webkit::npapi::WebPluginDelegateImpl::Create(
2950 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:092951#else
[email protected]7398dcc2011-09-06 21:40:322952 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:222953 NOTIMPLEMENTED();
2954 return NULL;
[email protected]7b6616f2010-01-14 18:07:552955#endif
[email protected]f103ab72009-09-02 17:10:592956 }
2957
[email protected]4e0616e2010-05-28 14:55:532958 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:592959}
2960
2961void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032962#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592963 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
2964 routing_id(), window));
2965#endif
2966}
2967
2968void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:032969#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:592970 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
2971 routing_id(), window));
2972#endif
2973 CleanupWindowInPluginMoves(window);
2974}
2975
[email protected]191eb3f72010-12-21 06:27:502976void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:592977 SchedulePluginMove(move);
2978}
2979
2980void RenderView::DidStartLoadingForPlugin() {
2981 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522982 didStartLoading();
[email protected]f103ab72009-09-02 17:10:592983}
2984
2985void RenderView::DidStopLoadingForPlugin() {
2986 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:522987 didStopLoading();
[email protected]f103ab72009-09-02 17:10:592988}
2989
[email protected]b921cfd22010-02-25 16:57:512990WebCookieJar* RenderView::GetCookieJar() {
2991 return &cookie_jar_;
2992}
2993
initial.commit09911bf2008-07-26 23:55:292994void RenderView::SyncNavigationState() {
2995 if (!webview())
2996 return;
2997
[email protected]26aa0482009-09-30 16:55:272998 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:172999 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293000 return;
[email protected]ca948a22009-06-25 19:36:173001
3002 Send(new ViewHostMsg_UpdateState(
3003 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293004}
3005
[email protected]b781ff282011-08-20 06:19:363006void RenderView::SyncSelectionIfRequired() {
3007 WebFrame* frame = webview()->focusedFrame();
3008 const std::string& text = frame->selectionAsText().utf8();
3009
3010 ui::Range range(ui::Range::InvalidRange());
3011 size_t location, length;
3012 if (webview()->caretOrSelectionRange(&location, &length)) {
3013 range.set_start(location);
3014 range.set_end(location + length);
3015 }
3016
3017 WebPoint start, end;
3018 webview()->selectionRange(start, end);
3019
3020 RenderViewSelection this_selection(text, range, start, end);
3021
3022 // Sometimes we get repeated didChangeSelection calls from webkit when
3023 // the selection hasn't actually changed. We don't want to report these
3024 // because it will cause us to continually claim the X clipboard.
3025 if (this_selection.Equals(last_selection_))
3026 return;
3027 last_selection_ = this_selection;
3028
3029 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, range,
3030 start, end));
3031}
3032
[email protected]7ccddb8c2009-08-04 17:36:553033GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293034 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553035 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293036 // If the URL that failed was secure, then the embedding web page was not
3037 // expecting a network attacker to be able to manipulate its contents. As
3038 // we fetch alternate error pages over HTTP, we would be allowing a network
3039 // attacker to manipulate the contents of the response if we tried to use
3040 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153041 return GURL();
initial.commit09911bf2008-07-26 23:55:293042 }
3043
3044 // Grab the base URL from the browser process.
3045 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153046 return GURL();
initial.commit09911bf2008-07-26 23:55:293047
3048 // Strip query params from the failed URL.
3049 GURL::Replacements remove_params;
3050 remove_params.ClearUsername();
3051 remove_params.ClearPassword();
3052 remove_params.ClearQuery();
3053 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553054 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503055 std::string spec_to_send = url_to_send.spec();
3056 // Notify link doctor of the url truncation by sending of "?" at the end.
3057 if (failed_url.has_query())
3058 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293059
3060 // Construct the query params to send to link doctor.
3061 std::string params(alternate_error_page_url_.query());
3062 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023063 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293064 params.append("&sourceid=chrome");
3065 params.append("&error=");
3066 switch (error_type) {
3067 case DNS_ERROR:
3068 params.append("dnserror");
3069 break;
3070
3071 case HTTP_404:
3072 params.append("http404");
3073 break;
3074
[email protected]5df266ac2008-10-15 19:50:133075 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333076 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133077 break;
3078
initial.commit09911bf2008-07-26 23:55:293079 default:
3080 NOTREACHED() << "unknown ErrorPageType";
3081 }
3082
3083 // OK, build the final url to return.
3084 GURL::Replacements link_doctor_params;
3085 link_doctor_params.SetQueryStr(params);
3086 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3087 return url;
3088}
3089
[email protected]c50008512011-02-03 01:17:273090WebUIBindings* RenderView::GetWebUIBindings() {
3091 if (!web_ui_bindings_.get()) {
[email protected]c6b7ef32011-10-04 22:21:443092 web_ui_bindings_.reset(new WebUIBindings(this, routing_id_));
[email protected]c091c2c2010-09-17 19:05:463093 }
[email protected]c50008512011-02-03 01:17:273094 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463095}
3096
[email protected]0fdbf8c2010-07-08 20:33:013097WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3098 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493099}
3100
[email protected]6069da8c2009-10-20 20:33:493101void RenderView::OnFind(int request_id, const string16& search_text,
3102 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273103 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493104
[email protected]872542532011-06-23 00:43:163105 // Check if the plugin still exists in the document.
3106 if (main_frame->document().isPluginDocument() &&
3107 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493108 if (options.findNext) {
3109 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013110 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493111 } else {
[email protected]afdbd142010-07-10 08:01:233112 if (GetWebPluginFromPluginDocument()->startFind(
3113 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493114 } else {
[email protected]e7c58a32010-08-13 19:47:113115 // Send "no results".
3116 Send(new ViewHostMsg_Find_Reply(routing_id_,
3117 request_id,
3118 0,
3119 gfx::Rect(),
3120 0,
3121 true));
[email protected]24a7f3c2010-03-25 08:26:493122 }
3123 }
3124 return;
3125 }
3126
[email protected]b4bb2502009-10-01 22:35:273127 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273128 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293129 WebFrame* search_frame = focused_frame; // start searching focused frame.
3130
3131 bool multi_frame = (frame_after_main != main_frame);
3132
3133 // If we have multiple frames, we don't want to wrap the search within the
3134 // frame, so we check here if we only have main_frame in the chain.
3135 bool wrap_within_frame = !multi_frame;
3136
[email protected]b3f2b912009-04-09 16:18:523137 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293138 bool result = false;
3139
[email protected]7830da3e2009-11-06 16:27:263140 // If something is selected when we start searching it means we cannot just
3141 // increment the current match ordinal; we need to re-generate it.
3142 WebRange current_selection = focused_frame->selectionRange();
3143
initial.commit09911bf2008-07-26 23:55:293144 do {
[email protected]dd7daa82009-08-10 05:46:453145 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593146 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293147
3148 if (!result) {
3149 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223150 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293151
3152 // Find the next frame, but skip the invisible ones.
3153 do {
3154 // What is the next frame to search? (we might be going backwards). Note
3155 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593156 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273157 search_frame->traverseNext(true) :
3158 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453159 } while (!search_frame->hasVisibleContent() &&
3160 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293161
[email protected]884db412008-11-24 23:46:503162 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223163 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293164
3165 // If we have multiple frames and we have wrapped back around to the
3166 // focused frame, we need to search it once more allowing wrap within
3167 // the frame, otherwise it will report 'no match' if the focused frame has
3168 // reported matches, but no frames after the focused_frame contain a
3169 // match for the search word(s).
3170 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453171 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593172 request_id, search_text, options, true, // Force wrapping.
3173 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293174 }
3175 }
3176
[email protected]26aa0482009-09-30 16:55:273177 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293178 } while (!result && search_frame != focused_frame);
3179
[email protected]7830da3e2009-11-06 16:27:263180 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293181 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453182 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293183 } else {
3184 // If nothing is found, set result to "0 of 0", otherwise, set it to
3185 // "-1 of 1" to indicate that we found at least one item, but we don't know
3186 // yet what is active.
3187 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3188 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293189
[email protected]4f3dc372009-02-24 00:10:293190 // If we find no matches then this will be our last status update.
3191 // Otherwise the scoping effort will send more results.
3192 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293193
[email protected]4f3dc372009-02-24 00:10:293194 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403195 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593196 request_id,
[email protected]4f3dc372009-02-24 00:10:293197 match_count,
3198 selection_rect,
3199 ordinal,
3200 final_status_update));
initial.commit09911bf2008-07-26 23:55:293201
initial.commit09911bf2008-07-26 23:55:293202 // Scoping effort begins, starting with the mainframe.
3203 search_frame = main_frame;
3204
[email protected]dd7daa82009-08-10 05:46:453205 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293206
3207 do {
3208 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453209 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293210
3211 // We don't start another scoping effort unless at least one match has
3212 // been found.
3213 if (result) {
3214 // Start new scoping request. If the scoping function determines that it
3215 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453216 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593217 search_text,
3218 options,
initial.commit09911bf2008-07-26 23:55:293219 true); // reset the tickmarks
3220 }
3221
3222 // Iterate to the next frame. The frame will not necessarily scope, for
3223 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273224 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293225 } while (search_frame != main_frame);
3226 }
3227}
3228
[email protected]24a7f3c2010-03-25 08:26:493229void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3230 WebView* view = webview();
3231 if (!view)
3232 return;
3233
3234 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163235 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013236 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493237 return;
3238 }
3239
3240 bool clear_selection =
3241 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3242 if (clear_selection)
3243 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3244
3245 WebFrame* frame = view->mainFrame();
3246 while (frame) {
3247 frame->stopFinding(clear_selection);
3248 frame = frame->traverseNext(false);
3249 }
3250
3251 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3252 WebFrame* focused_frame = view->focusedFrame();
3253 if (focused_frame) {
3254 WebDocument doc = focused_frame->document();
3255 if (!doc.isNull()) {
3256 WebNode node = doc.focusedNode();
3257 if (!node.isNull())
3258 node.simulateClick();
3259 }
3260 }
3261 }
3262}
3263
3264void RenderView::OnFindReplyAck() {
3265 // Check if there is any queued up request waiting to be sent.
3266 if (queued_find_reply_message_.get()) {
3267 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423268 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493269 }
3270}
3271
[email protected]0bd753682010-12-16 18:15:523272WebPlugin* RenderView::CreatePepperPlugin(
3273 WebFrame* frame,
3274 const WebPluginParams& params,
3275 const FilePath& path,
3276 webkit::ppapi::PluginModule* pepper_module) {
3277 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:253278 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:093279}
[email protected]00152e92010-07-19 11:47:403280
[email protected]191eb3f72010-12-21 06:27:503281WebPlugin* RenderView::CreateNPAPIPlugin(
3282 WebFrame* frame,
3283 const WebPluginParams& params,
3284 const FilePath& path,
3285 const std::string& mime_type) {
3286 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:083287 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:403288}
3289
[email protected]40bd6582009-12-04 23:49:513290void RenderView::OnZoom(PageZoom::Function function) {
3291 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3292 return;
3293
[email protected]258d31122010-05-09 10:59:413294 webview()->hidePopups();
[email protected]c514d6372011-08-16 22:54:443295#if !defined(TOUCH_UI)
[email protected]b75b8292010-10-01 07:28:253296 double old_zoom_level = webview()->zoomLevel();
3297 double zoom_level;
3298 if (function == PageZoom::RESET) {
3299 zoom_level = 0;
3300 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3301 // Previous zoom level is a whole number, so just increment/decrement.
3302 zoom_level = old_zoom_level + function;
3303 } else {
3304 // Either the user hit the zoom factor limit and thus the zoom level is now
3305 // not a whole number, or a plugin changed it to a custom value. We want
3306 // to go to the next whole number so that the user can always get back to
3307 // 100% with the keyboard/menu.
3308 if ((old_zoom_level > 1 && function > 0) ||
3309 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453310 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253311 } else {
3312 // We're going towards 100%, so first go to the next whole number.
3313 zoom_level = static_cast<int>(old_zoom_level);
3314 }
3315 }
[email protected]b75b8292010-10-01 07:28:253316 webview()->setZoomLevel(false, zoom_level);
[email protected]c514d6372011-08-16 22:54:443317#else
3318 double old_page_scale_factor = webview()->pageScaleFactor();
3319 double page_scale_factor;
3320 if (function == PageZoom::RESET) {
3321 page_scale_factor = 1.0;
3322 } else {
3323 page_scale_factor = old_page_scale_factor +
3324 (function > 0 ? kScalingIncrement : -kScalingIncrement);
3325 }
3326 webview()->scalePage(page_scale_factor, WebPoint(0, 0));
3327#endif
[email protected]b75b8292010-10-01 07:28:253328 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513329}
3330
[email protected]d0b8d092010-10-25 04:05:173331void RenderView::OnSetZoomLevel(double zoom_level) {
3332 // Don't set zoom level for full-page plugin since they don't use the same
3333 // zoom settings.
3334 if (webview()->mainFrame()->document().isPluginDocument())
3335 return;
3336
3337 webview()->hidePopups();
3338 webview()->setZoomLevel(false, zoom_level);
3339 zoomLevelChanged();
3340}
3341
[email protected]9d797f32010-04-23 07:17:543342void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:253343 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543344 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293345}
3346
[email protected]8a5e0ca2011-08-25 06:30:473347void RenderView::OnExitFullscreen() {
3348 webview()->exitFullscreen();
3349}
3350
[email protected]41fc0322009-09-04 22:23:403351void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273352 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293353}
3354
[email protected]a697f4c2009-09-14 22:30:183355void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273356 WebString no_encoding;
3357 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183358}
3359
[email protected]318bf5802011-08-08 17:12:413360WebFrame* RenderView::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453361 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273362 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453363
3364 // xpath string can represent a frame deep down the tree (across multiple
3365 // frame DOMs).
3366 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3367 // should break into 2 xpaths
3368 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413369 std::vector<string16> xpaths;
3370 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453371
[email protected]26aa0482009-09-30 16:55:273372 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413373 for (std::vector<string16>::const_iterator i = xpaths.begin();
3374 frame && i != xpaths.end(); ++i) {
3375 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293376 }
3377
[email protected]dd7daa82009-08-10 05:46:453378 return frame;
initial.commit09911bf2008-07-26 23:55:293379}
3380
[email protected]13a1e4c3c2011-02-03 21:07:093381WebNode RenderView::GetFocusedNode() const {
3382 if (!webview())
3383 return WebNode();
3384 WebFrame* focused_frame = webview()->focusedFrame();
3385 if (focused_frame) {
3386 WebDocument doc = focused_frame->document();
3387 if (!doc.isNull())
3388 return doc.focusedNode();
3389 }
3390
3391 return WebNode();
3392}
3393
[email protected]38b592902011-04-16 02:08:423394bool RenderView::IsEditableNode(const WebNode& node) {
3395 bool is_editable_node = false;
3396 if (!node.isNull()) {
3397 if (node.isContentEditable()) {
3398 is_editable_node = true;
3399 } else if (node.isElementNode()) {
3400 is_editable_node =
3401 node.toConst<WebElement>().isTextFormControlElement();
3402 }
3403 }
3404 return is_editable_node;
3405}
3406
[email protected]882b7b22010-10-05 03:34:533407void RenderView::EvaluateScript(const string16& frame_xpath,
3408 const string16& script,
3409 int id,
3410 bool notify_result) {
3411 v8::Handle<v8::Value> result;
[email protected]318bf5802011-08-08 17:12:413412 WebFrame* web_frame = GetChildFrame(frame_xpath);
[email protected]882b7b22010-10-05 03:34:533413 if (web_frame)
3414 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
3415 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:293416 ListValue list;
[email protected]cd326242011-06-16 01:55:463417 if (!result.IsEmpty() && web_frame) {
[email protected]81f9fe0b2010-12-07 00:35:293418 v8::HandleScope handle_scope;
3419 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3420 v8::Context::Scope context_scope(context);
[email protected]8d86f13d2011-10-04 17:01:193421 V8ValueConverterImpl converter;
[email protected]b1cf3372011-04-20 21:28:103422 converter.set_allow_date(true);
3423 converter.set_allow_regexp(true);
3424 list.Set(0, converter.FromV8Value(result, context));
[email protected]81f9fe0b2010-12-07 00:35:293425 } else {
3426 list.Set(0, Value::CreateNullValue());
3427 }
3428 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:533429 }
initial.commit09911bf2008-07-26 23:55:293430}
3431
[email protected]882b7b22010-10-05 03:34:533432void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
3433 const string16& jscript,
3434 int id,
3435 bool notify_result) {
3436 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293437}
3438
[email protected]318bf5802011-08-08 17:12:413439void RenderView::OnCSSInsertRequest(const string16& frame_xpath,
[email protected]01cf589c2011-07-28 18:04:033440 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413441 WebFrame* frame = GetChildFrame(frame_xpath);
3442 if (!frame)
[email protected]216813952011-05-19 22:21:263443 return;
[email protected]ae461542009-06-19 19:03:413444
[email protected]01cf589c2011-07-28 18:04:033445 frame->document().insertUserStyleSheet(
3446 WebString::fromUTF8(css),
3447 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483448}
3449
[email protected]81e63782009-02-27 19:35:093450void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3451 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293452}
3453
[email protected]d0980792011-02-13 19:41:403454void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:293455 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:553456 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:273457 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293458}
3459
3460void RenderView::OnReservePageIDRange(int size_of_range) {
3461 next_page_id_ += size_of_range + 1;
3462}
3463
[email protected]59f4f2fa2011-03-23 01:00:553464void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
3465 const gfx::Point& client_point,
3466 const gfx::Point& screen_point,
3467 WebDragOperationsMask ops) {
3468 WebDragOperation operation = webview()->dragTargetDragEnter(
3469 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553470 client_point,
3471 screen_point,
3472 ops);
3473
3474 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3475}
3476
3477void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
3478 const gfx::Point& screen_point,
3479 WebDragOperationsMask ops) {
3480 WebDragOperation operation = webview()->dragTargetDragOver(
3481 client_point,
3482 screen_point,
3483 ops);
3484
3485 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3486}
3487
3488void RenderView::OnDragTargetDragLeave() {
3489 webview()->dragTargetDragLeave();
3490}
3491
3492void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3493 const gfx::Point& screen_point) {
3494 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573495
3496 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553497}
3498
[email protected]e80c73b2009-04-07 23:24:583499void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3500 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253501 bool ended,
3502 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033503 if (ended) {
[email protected]26aa0482009-09-30 16:55:273504 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203505 } else {
3506 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033507 }
initial.commit09911bf2008-07-26 23:55:293508}
3509
3510void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273511 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293512}
3513
initial.commit09911bf2008-07-26 23:55:293514void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593515 webkit_preferences_ = prefs;
3516 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293517}
3518
[email protected]08bb1e722011-07-30 19:13:043519void RenderView::OnUpdateRemoteAccessClientFirewallTraversal(
3520 const std::string& policy) {
3521 pepper_delegate_.PublishPolicy(policy);
3522}
3523
initial.commit09911bf2008-07-26 23:55:293524void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3525 alternate_error_page_url_ = url;
3526}
3527
[email protected]b29aa74b2011-01-31 21:41:083528void RenderView::OnCustomContextMenuAction(
3529 const webkit_glue::CustomContextMenuContext& custom_context,
3530 unsigned action) {
3531 if (custom_context.is_pepper_menu)
3532 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3533 else
3534 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:583535 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3536 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:333537}
3538
[email protected]600ea402011-04-12 00:01:513539void RenderView::OnEnumerateDirectoryResponse(
3540 int id,
3541 const std::vector<FilePath>& paths) {
3542 if (!enumeration_completions_[id])
3543 return;
3544
3545 WebVector<WebString> ws_file_names(paths.size());
3546 for (size_t i = 0; i < paths.size(); ++i)
3547 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3548
3549 enumeration_completions_[id]->didChooseFile(ws_file_names);
3550 enumeration_completions_.erase(id);
3551}
3552
[email protected]cdaf8d02010-03-30 19:52:473553void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363554 // This could happen if we navigated to a different page before the user
3555 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473556 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363557 return;
3558
[email protected]cdaf8d02010-03-30 19:52:473559 WebVector<WebString> ws_file_names(paths.size());
3560 for (size_t i = 0; i < paths.size(); ++i)
3561 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463562
[email protected]cdaf8d02010-03-30 19:52:473563 if (file_chooser_completions_.front()->completion)
3564 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3565 file_chooser_completions_.pop_front();
3566
3567 // If there are more pending file chooser requests, schedule one now.
3568 if (!file_chooser_completions_.empty()) {
3569 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3570 file_chooser_completions_.front()->params));
3571 }
initial.commit09911bf2008-07-26 23:55:293572}
3573
[email protected]770dd8b2010-05-24 18:11:393574void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3575 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243576 if (send_preferred_size_changes_)
3577 return;
[email protected]9fb325e2010-05-06 18:23:243578 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393579
[email protected]d812fd12011-05-27 23:05:073580 // Start off with an initial preferred size notification (in case
3581 // |didUpdateLayout| was already called).
3582 if (webview())
3583 didUpdateLayout(webview()->mainFrame());
[email protected]0666aef2009-05-13 19:48:083584}
3585
[email protected]cda45c02010-02-25 19:28:103586void RenderView::OnDisableScrollbarsForSmallWindows(
3587 const gfx::Size& disable_scrollbar_size_limit) {
3588 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3589}
3590
[email protected]80d96fa2009-06-10 22:34:513591void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3592 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373593 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133594#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413595 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3596 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463597 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513598 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343599 renderer_prefs.thumb_inactive_color,
3600 renderer_prefs.thumb_active_color,
3601 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323602
[email protected]644d77e2010-01-27 01:03:103603 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323604 webview()->setScrollbarColors(
3605 renderer_prefs.thumb_inactive_color,
3606 renderer_prefs.thumb_active_color,
3607 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103608 webview()->setSelectionColors(
3609 renderer_prefs.active_selection_bg_color,
3610 renderer_prefs.active_selection_fg_color,
3611 renderer_prefs.inactive_selection_bg_color,
3612 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463613 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103614 }
[email protected]7a74e102009-09-03 00:16:563615#endif
[email protected]80d96fa2009-06-10 22:34:513616}
3617
[email protected]952cb702009-10-07 05:50:283618void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3619 const WebMediaPlayerAction& action) {
3620 if (webview())
3621 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563622}
3623
[email protected]18d5be92011-07-25 18:00:193624void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3625 const GURL& page_url) {
3626 // Prepare list to storage all savable resource links.
3627 std::vector<GURL> resources_list;
3628 std::vector<GURL> referrers_list;
3629 std::vector<GURL> frames_list;
3630 webkit_glue::SavableResourcesResult result(&resources_list,
3631 &referrers_list,
3632 &frames_list);
3633
3634 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3635 webview(),
3636 page_url,
3637 &result,
3638 chrome::kSavableSchemes)) {
3639 // If something is wrong when collecting all savable resource links,
3640 // send empty list to embedder(browser) to tell it failed.
3641 referrers_list.clear();
3642 resources_list.clear();
3643 frames_list.clear();
3644 }
3645
3646 // Send result of all savable resource links to embedder.
3647 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3648 resources_list,
3649 referrers_list,
3650 frames_list));
3651}
3652
3653void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
3654 const std::vector<GURL>& links,
3655 const std::vector<FilePath>& local_paths,
3656 const FilePath& local_directory_name) {
3657
3658 // Convert std::vector of GURLs to WebVector<WebURL>
3659 WebVector<WebURL> weburl_links(links);
3660
3661 // Convert std::vector of std::strings to WebVector<WebString>
3662 WebVector<WebString> webstring_paths(local_paths.size());
3663 for (size_t i = 0; i < local_paths.size(); i++)
3664 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3665
3666 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
3667 webstring_paths,
3668 webkit_glue::FilePathToWebString(
3669 local_directory_name));
3670}
3671
[email protected]9b18a84f2010-06-10 15:54:043672void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273673 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473674 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293675}
3676
[email protected]992db4c2011-05-12 15:37:153677void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3678 if (is_swapped_out_)
3679 return;
3680
3681 // Swap this RenderView out so the tab can navigate to a page rendered by a
3682 // different process. This involves running the unload handler and clearing
3683 // the page. Once WasSwappedOut is called, we also allow this process to exit
3684 // if there are no other active RenderViews in it.
3685
3686 // Send an UpdateState message before we get swapped out.
3687 SyncNavigationState();
3688
3689 // Synchronously run the unload handler before sending the ACK.
3690 webview()->dispatchUnloadEvent();
3691
3692 // Swap out and stop sending any IPC messages that are not ACKs.
3693 SetSwappedOut(true);
3694
3695 // Replace the page with a blank dummy URL. The unload handler will not be
3696 // run a second time, thanks to a check in FrameLoader::stopLoading.
3697 // TODO(creis): Need to add a better way to do this that avoids running the
3698 // beforeunload handler. For now, we just run it a second time silently.
3699 webview()->mainFrame()->loadHTMLString(std::string(),
3700 GURL("about:swappedout"),
3701 GURL("about:swappedout"),
3702 false);
3703
3704 // Just echo back the params in the ACK.
3705 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3706}
3707
3708void RenderView::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:293709 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3710 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3711 // in the onunload handler from appearing. For now, we're bypassing that and
3712 // calling the FrameLoader's CloseURL method directly. This should be
3713 // revisited to avoid having two ways to close a page. Having a single way
3714 // to close that can run onunload is also useful for fixing
3715 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273716 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293717
[email protected]992db4c2011-05-12 15:37:153718 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293719}
3720
3721void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573722#if defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163723 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463724 if (webview())
3725 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573726#else // defined(OS_WIN)
3727 // TODO(port): we don't support theming on non-Windows platforms yet
3728 NOTIMPLEMENTED();
3729#endif
initial.commit09911bf2008-07-26 23:55:293730}
3731
[email protected]0aa55312008-10-17 21:53:083732void RenderView::OnDisassociateFromPopupCount() {
3733 if (decrement_shared_popup_at_destruction_)
3734 shared_popup_counter_->data--;
3735 shared_popup_counter_ = new SharedRenderViewCounter(0);
3736 decrement_shared_popup_at_destruction_ = false;
3737}
3738
[email protected]15d79e12009-08-02 19:23:453739bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3740 const WebURLError& error,
3741 bool replace) {
3742 // We only show alternate error pages in the main frame. They are
3743 // intended to assist the user when navigating, so there is not much
3744 // value in showing them for failed subframes. Ideally, we would be
3745 // able to use the TYPED transition type for this, but that flag is
3746 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453747 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453748 return false;
3749
3750 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373751 // connection failure.
[email protected]15d79e12009-08-02 19:23:453752 int ec = error.reason;
3753 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3754 ec != net::ERR_CONNECTION_FAILED &&
3755 ec != net::ERR_CONNECTION_REFUSED &&
3756 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373757 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453758 return false;
3759
3760 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553761 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453762 if (!error_page_url.is_valid())
3763 return false;
3764
3765 // Load an empty page first so there is an immediate response to the error,
3766 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453767 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363768 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453769 error.unreachableURL,
3770 replace);
3771
3772 // Now, create a fetcher for the error page and associate it with the data
3773 // source we just created via the LoadHTMLString call. That way if another
3774 // navigation occurs, the fetcher will get destroyed.
3775 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453776 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453777 navigation_state->set_alt_error_page_fetcher(
3778 new AltErrorPageResourceFetcher(
3779 error_page_url, frame, error,
3780 NewCallback(this, &RenderView::AltErrorPageFinished)));
3781 return true;
3782}
3783
[email protected]15d79e12009-08-02 19:23:453784void RenderView::AltErrorPageFinished(WebFrame* frame,
3785 const WebURLError& original_error,
3786 const std::string& html) {
3787 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093788 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553789 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093790 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453791}
3792
[email protected]30f75e62009-02-25 22:01:003793void RenderView::OnMoveOrResizeStarted() {
3794 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473795 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003796}
3797
[email protected]30f75e62009-02-25 22:01:003798void RenderView::OnResize(const gfx::Size& new_size,
3799 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103800 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473801 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103802 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203803 webview()->mainFrame()->setCanHaveScrollbars(
3804 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103805 }
[email protected]dd6afca2011-08-13 03:44:313806 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:103807 }
3808
[email protected]30f75e62009-02-25 22:01:003809 RenderWidget::OnResize(new_size, resizer_rect);
3810}
[email protected]0aa477bd2009-03-23 22:21:433811
[email protected]00c39612010-03-06 02:53:283812void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013813 // Notify the pepper plugins that we started painting.
3814 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283815}
3816
3817void RenderView::DidFlushPaint() {
3818 // Notify any pepper plugins that we painted. This will call into the plugin,
3819 // and we it may ask to close itself as a result. This will, in turn, modify
3820 // our set, possibly invalidating the iterator. So we iterate on a copy that
3821 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013822 pepper_delegate_.ViewFlushedPaint();
3823
[email protected]00c39612010-03-06 02:53:283824 WebFrame* main_frame = webview()->mainFrame();
3825
3826 // If we have a provisional frame we are between the start and commit stages
3827 // of loading and we don't want to save stats.
3828 if (!main_frame->provisionalDataSource()) {
3829 WebDataSource* ds = main_frame->dataSource();
3830 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3831 DCHECK(navigation_state);
3832
[email protected]05c8e502010-08-15 15:13:523833 // TODO(jar): The following code should all be inside a method, probably in
3834 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283835 Time now = Time::Now();
3836 if (navigation_state->first_paint_time().is_null()) {
3837 navigation_state->set_first_paint_time(now);
3838 }
3839 if (navigation_state->first_paint_after_load_time().is_null() &&
3840 !navigation_state->finish_load_time().is_null()) {
3841 navigation_state->set_first_paint_after_load_time(now);
3842 }
3843 }
[email protected]b781ff282011-08-20 06:19:363844
3845#if defined(TOUCH_UI)
3846 SyncSelectionIfRequired();
3847#endif
[email protected]00c39612010-03-06 02:53:283848}
3849
[email protected]37a6f302011-07-11 23:43:083850void RenderView::OnViewContextSwapBuffersPosted() {
3851 RenderWidget::OnSwapBuffersPosted();
3852}
3853
[email protected]65225772011-05-12 21:10:243854void RenderView::OnViewContextSwapBuffersComplete() {
3855 RenderWidget::OnSwapBuffersComplete();
3856}
3857
3858void RenderView::OnViewContextSwapBuffersAborted() {
3859 RenderWidget::OnSwapBuffersAborted();
3860}
3861
[email protected]719b36f2010-12-22 20:36:463862webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:153863 const gfx::Rect& paint_bounds,
3864 TransportDIB** dib,
3865 gfx::Rect* location,
3866 gfx::Rect* clip) {
3867 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
3868 paint_bounds, dib, location, clip);
3869}
3870
[email protected]bcaf2272011-02-15 15:29:433871gfx::Point RenderView::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:073872 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:433873 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523874}
3875
[email protected]05d478752009-04-08 23:38:163876void RenderView::OnClearFocusedNode() {
3877 if (webview())
[email protected]26aa0482009-09-30 16:55:273878 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163879}
3880
[email protected]699ab0d2009-04-23 23:19:143881void RenderView::OnSetBackground(const SkBitmap& background) {
3882 if (webview())
[email protected]b4bb2502009-10-01 22:35:273883 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143884
3885 SetBackground(background);
3886}
3887
[email protected]8c66c5a2009-07-22 17:26:343888void RenderView::OnSetActive(bool active) {
3889 if (webview())
[email protected]b4bb2502009-10-01 22:35:273890 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263891
3892#if defined(OS_MACOSX)
3893 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3894 for (plugin_it = plugin_delegates_.begin();
3895 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3896 (*plugin_it)->SetWindowFocus(active);
3897 }
3898#endif
[email protected]8c66c5a2009-07-22 17:26:343899}
3900
[email protected]6ce7abc52010-02-02 18:40:143901#if defined(OS_MACOSX)
3902void RenderView::OnSetWindowVisibility(bool visible) {
3903 // Inform plugins that their container has changed visibility.
3904 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3905 for (plugin_it = plugin_delegates_.begin();
3906 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3907 (*plugin_it)->SetContainerVisibility(visible);
3908 }
3909}
[email protected]1e6e3c992010-02-08 15:52:133910
[email protected]4d51d5bf2010-07-26 18:48:263911void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
3912 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:133913 // Inform plugins that their window's frame has changed.
3914 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3915 for (plugin_it = plugin_delegates_.begin();
3916 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3917 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
3918 }
3919}
[email protected]935d63d2010-10-15 23:31:553920
[email protected]b7f75862011-01-21 21:15:133921void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:553922 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:133923 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:553924 // applies to it or not, so inform all the delegates.
3925 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3926 for (plugin_it = plugin_delegates_.begin();
3927 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:133928 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:553929 }
3930}
[email protected]6ce7abc52010-02-02 18:40:143931#endif // OS_MACOSX
3932
[email protected]446705872009-09-10 07:22:483933void RenderView::OnSetEditCommandsForNextKeyEvent(
3934 const EditCommands& edit_commands) {
3935 edit_commands_ = edit_commands;
3936}
3937
[email protected]60c42a8c72009-10-09 04:08:593938void RenderView::Close() {
3939 // We need to grab a pointer to the doomed WebView before we destroy it.
3940 WebView* doomed = webview();
3941 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:493942 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:593943}
3944
[email protected]446705872009-09-10 07:22:483945void RenderView::DidHandleKeyEvent() {
3946 edit_commands_.clear();
3947}
3948
[email protected]67bfb83f2011-09-22 03:36:373949bool RenderView::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
3950 return pepper_delegate_.DispatchLockedMouseEvent(event);
3951}
3952
[email protected]6a8ddba52010-09-05 04:38:063953void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:513954 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:063955}
3956
[email protected]2d0f2e92011-10-03 09:02:243957void RenderView::DidHandleTouchEvent(const WebTouchEvent& event) {
3958 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
3959}
3960
[email protected]941e4552010-02-01 21:23:433961void RenderView::OnWasHidden() {
3962 RenderWidget::OnWasHidden();
3963
[email protected]a6939ca42011-02-18 17:58:073964 if (webview()) {
3965 webview()->settings()->setMinimumTimerInterval(
3966 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:443967 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073968 }
3969
3970#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:433971 // Inform plugins that their container is no longer visible.
3972 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3973 for (plugin_it = plugin_delegates_.begin();
3974 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3975 (*plugin_it)->SetContainerVisibility(false);
3976 }
[email protected]a6939ca42011-02-18 17:58:073977#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:433978}
3979
3980void RenderView::OnWasRestored(bool needs_repainting) {
3981 RenderWidget::OnWasRestored(needs_repainting);
3982
[email protected]a6939ca42011-02-18 17:58:073983 if (webview()) {
3984 webview()->settings()->setMinimumTimerInterval(
3985 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:443986 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:073987 }
3988
3989#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:433990 // Inform plugins that their container is now visible.
3991 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3992 for (plugin_it = plugin_delegates_.begin();
3993 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3994 (*plugin_it)->SetContainerVisibility(true);
3995 }
[email protected]784ea1ab2010-09-18 00:02:343996#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:073997}
[email protected]1e6e3c992010-02-08 15:52:133998
[email protected]65225772011-05-12 21:10:243999bool RenderView::SupportsAsynchronousSwapBuffers() {
4000 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4001 if (!context)
4002 return false;
4003 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4004 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4005 std::string::npos;
4006}
4007
[email protected]1e6e3c992010-02-08 15:52:134008void RenderView::OnSetFocus(bool enable) {
4009 RenderWidget::OnSetFocus(enable);
4010
[email protected]7d3c02c2010-05-05 23:10:314011 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074012 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134013 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4014 for (plugin_it = plugin_delegates_.begin();
4015 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344016#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314017 // RenderWidget's call to setFocus can cause the underlying webview's
4018 // activation state to change just like a call to setIsActive.
4019 if (enable)
4020 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344021#endif
[email protected]7d3c02c2010-05-05 23:10:314022 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134023 }
[email protected]589621b2010-09-23 22:01:074024
4025 // Notify all Pepper plugins.
4026 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134027 }
4028}
[email protected]941e4552010-02-01 21:23:434029
[email protected]56ea1a62011-05-30 07:05:574030void RenderView::PpapiPluginFocusChanged() {
4031 UpdateInputMethod();
4032}
4033
[email protected]08bb1e722011-07-30 19:13:044034void RenderView::RequestRemoteAccessClientFirewallTraversal() {
4035 Send(new ViewHostMsg_RequestRemoteAccessClientFirewallTraversal(routing_id_));
4036}
4037
[email protected]56ea1a62011-05-30 07:05:574038void RenderView::OnImeSetComposition(
4039 const string16& text,
4040 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4041 int selection_start,
4042 int selection_end) {
4043 // Until PPAPI has an interface for handling IME events, we skip sending
4044 // OnImeSetComposition. Otherwise the composition is canceled when a
4045 // non-editable DOM element is focused.
4046 //
4047 // TODO(kinaba) This temporal remedy can be removed after PPAPI is extended
4048 // with an IME handling interface.
4049 if (!pepper_delegate_.IsPluginFocused()) {
[email protected]e6ae0f6c2011-10-04 10:39:234050#if defined(OS_WIN)
4051 // When a plug-in has focus, we create platform-specific IME data used by
4052 // our IME emulator and send it directly to the focused plug-in, i.e. we
4053 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4054 // instance ID is the same one as the specified ID.)
4055 if (focused_plugin_id_ >= 0) {
4056 std::vector<int> clauses;
4057 std::vector<int> target;
4058 for (size_t i = 0; i < underlines.size(); ++i) {
4059 clauses.push_back(underlines[i].startOffset);
4060 clauses.push_back(underlines[i].endOffset);
4061 if (underlines[i].thick) {
4062 target.clear();
4063 target.push_back(underlines[i].startOffset);
4064 target.push_back(underlines[i].endOffset);
4065 }
4066 }
4067 std::set<WebPluginDelegateProxy*>::iterator it;
4068 for (it = plugin_delegates_.begin();
4069 it != plugin_delegates_.end(); ++it) {
4070 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4071 focused_plugin_id_);
4072 }
4073 return;
4074 }
4075#endif
[email protected]56ea1a62011-05-30 07:05:574076 RenderWidget::OnImeSetComposition(text,
4077 underlines,
4078 selection_start,
4079 selection_end);
4080 }
4081}
4082
4083void RenderView::OnImeConfirmComposition(const string16& text) {
4084 if (pepper_delegate_.IsPluginFocused()) {
4085 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4086 // send character events.
4087 for (size_t i = 0; i < text.size(); ++i) {
4088 WebKit::WebKeyboardEvent char_event;
4089 char_event.type = WebKit::WebInputEvent::Char;
4090 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
4091 char_event.modifiers = 0;
4092 char_event.windowsKeyCode = text[i];
4093 char_event.nativeKeyCode = text[i];
4094 char_event.text[0] = text[i];
4095 char_event.unmodifiedText[0] = text[i];
4096 if (webwidget_)
4097 webwidget_->handleInputEvent(char_event);
4098 }
4099 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234100#if defined(OS_WIN)
4101 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4102 // plug-ins. When we send IME text directly to plug-ins, we should not send
4103 // it to WebKit to prevent WebKit from controlling IMEs.
4104 if (focused_plugin_id_ >= 0) {
4105 std::set<WebPluginDelegateProxy*>::iterator it;
4106 for (it = plugin_delegates_.begin();
4107 it != plugin_delegates_.end(); ++it) {
4108 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4109 }
4110 return;
4111 }
4112#endif
[email protected]56ea1a62011-05-30 07:05:574113 RenderWidget::OnImeConfirmComposition(text);
4114 }
4115}
4116
[email protected]ad26ef42011-06-17 07:59:454117ui::TextInputType RenderView::GetTextInputType() {
[email protected]56ea1a62011-05-30 07:05:574118 if (pepper_delegate_.IsPluginFocused()) {
[email protected]7f81cc72011-09-07 18:19:314119#if !defined(TOUCH_UI)
[email protected]56ea1a62011-05-30 07:05:574120 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4121 // consider all the parts of PPAPI plugins are accepting text inputs.
[email protected]ad26ef42011-06-17 07:59:454122 return ui::TEXT_INPUT_TYPE_TEXT;
[email protected]7f81cc72011-09-07 18:19:314123#else
4124 // Disable keyboard input in flash for touch ui until PPAPI can support IME
4125 // events.
4126 return ui::TEXT_INPUT_TYPE_NONE;
4127#endif
[email protected]56ea1a62011-05-30 07:05:574128 }
[email protected]ad26ef42011-06-17 07:59:454129 return RenderWidget::GetTextInputType();
4130}
4131
4132bool RenderView::CanComposeInline() {
4133 if (pepper_delegate_.IsPluginFocused()) {
4134 // TODO(kinaba) Until PPAPI has an interface for handling IME events, there
4135 // is no way for the browser to know whether the plugin is capable of
4136 // drawing composition text. We assume plugins are incapable and let the
4137 // browser handle composition display for now.
4138 return false;
4139 }
4140 return true;
[email protected]56ea1a62011-05-30 07:05:574141}
4142
[email protected]e6ae0f6c2011-10-04 10:39:234143#if defined(OS_WIN)
4144void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
4145 if (focused)
4146 focused_plugin_id_ = plugin_id;
4147 else
4148 focused_plugin_id_ = -1;
4149}
4150#endif
4151
[email protected]43f28f832010-02-03 02:28:484152#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:134153void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
4154 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4155 focused, plugin_id);
4156 Send(msg);
4157}
4158
4159void RenderView::StartPluginIme() {
4160 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554161 // This message can be sent during event-handling, and needs to be delivered
4162 // within that context.
4163 msg->set_unblock(true);
4164 Send(msg);
4165}
4166
[email protected]ea04a4e12010-04-15 00:58:034167gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234168 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484169 gfx::PluginWindowHandle window = NULL;
4170 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234171 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114172 if (window) {
4173 fake_plugin_window_handles_.insert(window);
4174 }
[email protected]43f28f832010-02-03 02:28:484175 return window;
4176}
4177
4178void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114179 if (window && fake_plugin_window_handles_.find(window) !=
4180 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484181 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114182 fake_plugin_window_handles_.erase(window);
4183 }
[email protected]43f28f832010-02-03 02:28:484184}
4185
[email protected]44ce0b12010-03-12 16:45:334186void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4187 int32 width,
4188 int32 height,
4189 uint64 io_surface_identifier) {
4190 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484191 routing_id(), window, width, height, io_surface_identifier));
4192}
4193
[email protected]44ce0b12010-03-12 16:45:334194void RenderView::AcceleratedSurfaceSetTransportDIB(
4195 gfx::PluginWindowHandle window,
4196 int32 width,
4197 int32 height,
4198 TransportDIB::Handle transport_dib) {
4199 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074200 routing_id(), window, width, height, transport_dib));
4201}
4202
[email protected]44ce0b12010-03-12 16:45:334203TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4204 size_t size) {
[email protected]1aef98132010-02-23 18:00:074205 TransportDIB::Handle dib_handle;
4206 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384207 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074208 return dib_handle;
4209 // Return an invalid handle if Send() fails.
4210 return TransportDIB::DefaultHandleValue();
4211}
4212
[email protected]44ce0b12010-03-12 16:45:334213void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074214 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4215}
4216
[email protected]44ce0b12010-03-12 16:45:334217void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144218 gfx::PluginWindowHandle window, uint64 surface_id) {
4219 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4220 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484221}
4222#endif
[email protected]58c321d2010-02-19 12:11:284223
[email protected]cdaf8d02010-03-30 19:52:474224bool RenderView::ScheduleFileChooser(
4225 const ViewHostMsg_RunFileChooser_Params& params,
4226 WebFileChooserCompletion* completion) {
4227 static const size_t kMaximumPendingFileChooseRequests = 4;
4228 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4229 // This sanity check prevents too many file choose requests from getting
4230 // queued which could DoS the user. Getting these is most likely a
4231 // programming error (there are many ways to DoS the user so it's not
4232 // considered a "real" security check), either in JS requesting many file
4233 // choosers to pop up, or in a plugin.
4234 //
4235 // TODO(brettw) we might possibly want to require a user gesture to open
4236 // a file picker, which will address this issue in a better way.
4237 return false;
4238 }
4239
4240 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4241 new PendingFileChooser(params, completion)));
4242 if (file_chooser_completions_.size() == 1) {
4243 // Actually show the browse dialog when this is the first request.
4244 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4245 }
4246 return true;
4247}
4248
[email protected]0ff0ff32010-12-21 19:34:424249WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514250 if (!geolocation_dispatcher_)
4251 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4252 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254253}
[email protected]61c9f032010-03-31 23:04:194254
[email protected]638694c2010-08-04 22:24:114255WebKit::WebSpeechInputController* RenderView::speechInputController(
4256 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:514257 if (!speech_input_dispatcher_)
4258 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
4259 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114260}
4261
[email protected]57ead352010-08-11 14:42:534262WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514263 if (!device_orientation_dispatcher_)
4264 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4265 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534266}
4267
[email protected]b75b8292010-10-01 07:28:254268void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
4269 // For now, don't remember plugin zoom values. We don't want to mix them with
4270 // normal web content (i.e. a fixed layout plugin would usually want them
4271 // different).
4272 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4273
[email protected]b75b8292010-10-01 07:28:254274 int minimum_percent = static_cast<int>(
4275 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4276 int maximum_percent = static_cast<int>(
4277 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254278
4279 Send(new ViewHostMsg_UpdateZoomLimits(
4280 routing_id_, minimum_percent, maximum_percent, remember));
4281}
4282
4283void RenderView::zoomLevelChanged() {
4284 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084285#if defined(TOUCH_UI)
4286 float zoom_level =
4287 WebView::zoomFactorToZoomLevel(webview()->pageScaleFactor());
4288#else
4289 float zoom_level = webview()->zoomLevel();
4290#endif
[email protected]b75b8292010-10-01 07:28:254291 // Tell the browser which url got zoomed so it can update the menu and the
4292 // saved values if necessary
4293 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084294 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414295 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254296}
4297
[email protected]a6d36cc2011-02-23 00:39:484298void RenderView::registerProtocolHandler(const WebString& scheme,
4299 const WebString& base_url,
4300 const WebString& url,
4301 const WebString& title) {
4302 GURL base(base_url);
4303 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4304 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4305 return;
4306 }
4307 RenderThread::current()->Send(
4308 new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4309 UTF16ToUTF8(scheme),
4310 absolute_url,
4311 title));
4312}
4313
[email protected]62af76e2011-08-01 02:34:014314void RenderView::registerIntentHandler(const WebString& action,
4315 const WebString& type,
4316 const WebString& href,
4317 const WebString& title) {
4318 RenderThread::current()->Send(
4319 new ViewHostMsg_RegisterIntentHandler(routing_id_,
4320 action,
4321 type,
4322 href,
4323 title));
4324}
4325
[email protected]94dec932011-05-26 20:04:214326WebKit::WebPageVisibilityState RenderView::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444327 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4328 WebKit::WebPageVisibilityStateHidden :
4329 WebKit::WebPageVisibilityStateVisible;
4330 WebKit::WebPageVisibilityState override_state = current_state;
4331 if (content::GetContentClient()->renderer()->
4332 ShouldOverridePageVisibilityState(this,
4333 &override_state))
4334 return override_state;
4335 return current_state;
[email protected]94dec932011-05-26 20:04:214336}
4337
[email protected]e235c7d02011-08-18 22:38:434338void RenderView::startActivity(const WebKit::WebString& action,
4339 const WebKit::WebString& type,
4340 const WebKit::WebString& data,
4341 int intent_id) {
[email protected]ce9751942011-09-21 01:57:244342 webkit_glue::WebIntentData intent_data;
4343 intent_data.action = action;
4344 intent_data.type = type;
4345 intent_data.data = data;
4346 Send(new IntentsHostMsg_WebIntentDispatch(
4347 routing_id_, intent_data, intent_id));
[email protected]e235c7d02011-08-18 22:38:434348}
4349
[email protected]1ef93132011-09-16 18:33:474350void RenderView::OnWebIntentReply(
4351 IntentsMsg_WebIntentReply_Type::Value reply_type,
4352 const WebKit::WebString& data,
4353 int intent_id) {
4354 // TODO(gbillock): Implement once the webkit side lands.
4355 LOG(INFO) << "RenderView got reply to intent type " << reply_type;
4356}
4357
[email protected]8079b362010-05-07 18:37:454358bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194359 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454360 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194361 if (frame->parent() != NULL)
4362 return false;
4363
[email protected]f0a3d0b2010-08-06 22:51:534364 // Navigations initiated within Webkit are not sent out to the external host
4365 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274366 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134367 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534368 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134369 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334370 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534371 return false;
4372
[email protected]2fc22d12010-12-02 23:08:164373 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324374 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014375 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164376 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014377 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324378 // The opener relationship between the new window and the parent allows the
4379 // new window to script the parent and vice versa. This is not allowed if
4380 // the origins of the two domains are different. This can be treated as a
4381 // top level navigation and routed back to the host.
4382 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274383 if (!opener) {
[email protected]86965362011-04-21 18:42:514384 return true;
[email protected]d19ea342011-04-20 20:31:134385 } else {
[email protected]b6cb3a842011-06-24 18:28:414386 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324387 return true;
4388 }
4389 }
[email protected]61c9f032010-03-31 23:04:194390 return false;
4391}
[email protected]2b06a992010-08-21 05:48:224392
[email protected]27a9ef32010-09-10 04:06:244393void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
4394 IPC::PlatformFileForTransit file_for_transit,
4395 int message_id) {
4396 pepper_delegate_.OnAsyncFileOpened(
4397 error_code,
4398 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4399 message_id);
4400}
[email protected]caf706f2010-10-26 17:54:084401
[email protected]2b657fd2011-04-18 16:00:474402void RenderView::OnPpapiBrokerChannelCreated(
4403 int request_id,
4404 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434405 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474406 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4407 broker_process_handle,
4408 handle);
[email protected]eb415bf0e2011-04-14 02:45:424409}
4410
[email protected]caf706f2010-10-26 17:54:084411#if defined(OS_MACOSX)
4412void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154413 if (external_popup_menu_ == NULL) {
4414 // Crash reports from the field indicate that we can be notified with a
4415 // NULL external popup menu (we probably get notified twice).
4416 // If you hit this please file a bug against jcivelli and include the page
4417 // and steps to repro.
4418 NOTREACHED();
4419 return;
4420 }
[email protected]caf706f2010-10-26 17:54:084421 external_popup_menu_->DidSelectItem(selected_index);
4422 external_popup_menu_.reset();
4423}
4424#endif
[email protected]bb461532010-11-26 21:50:234425
[email protected]1b4209f2011-01-07 00:25:404426#if defined(ENABLE_FLAPPER_HACKS)
4427void RenderView::OnConnectTcpACK(
4428 int request_id,
4429 IPC::PlatformFileForTransit socket_for_transit,
4430 const PP_Flash_NetAddress& local_addr,
4431 const PP_Flash_NetAddress& remote_addr) {
4432 pepper_delegate_.OnConnectTcpACK(
4433 request_id,
4434 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4435 local_addr,
4436 remote_addr);
4437}
4438#endif
[email protected]a6097f42011-01-10 08:50:514439
[email protected]b29aa74b2011-01-31 21:41:084440void RenderView::OnContextMenuClosed(
4441 const webkit_glue::CustomContextMenuContext& custom_context) {
4442 if (custom_context.is_pepper_menu)
4443 pepper_delegate_.OnContextMenuClosed(custom_context);
4444 else
4445 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104446}
[email protected]5a7b15a2011-08-22 22:48:184447
4448void RenderView::OnEnableViewSourceMode() {
4449 if (!webview())
4450 return;
4451 WebFrame* main_frame = webview()->mainFrame();
4452 if (!main_frame)
4453 return;
4454 main_frame->enableViewSourceMode(true);
4455}
[email protected]67bfb83f2011-09-22 03:36:374456
4457void RenderView::OnLockMouseACK(bool succeeded) {
4458 pepper_delegate_.OnLockMouseACK(succeeded);
4459}
4460
4461void RenderView::OnMouseLockLost() {
4462 pepper_delegate_.OnMouseLockLost();
4463}
4464