blob: 2eb4b1936934aa130c5569c1988ec1694c75bc4a [file] [log] [blame]
[email protected]1b4209f2011-01-07 00:25:401// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]6e24cf12011-03-18 19:57:025#include "content/renderer/render_view.h"
initial.commit09911bf2008-07-26 23:55:296
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
initial.commit09911bf2008-07-26 23:55:299#include <string>
10#include <vector>
11
[email protected]2041cf342010-02-19 03:15:5912#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5014#include "base/compiler_specific.h"
[email protected]005bab02011-10-07 18:36:0015#include "base/json/json_value_serializer.h"
[email protected]b1cf3372011-04-20 21:28:1016#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4917#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2819#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5120#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2921#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4122#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2923#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2824#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2625#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2226#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1027#include "content/common/appcache/appcache_dispatcher.h"
[email protected]9966325b2011-04-18 05:00:1028#include "content/common/bindings_policy.h"
[email protected]127dd582011-03-16 21:32:1029#include "content/common/clipboard_messages.h"
[email protected]db803aae2011-03-05 02:00:4230#include "content/common/content_constants.h"
[email protected]9966325b2011-04-18 05:00:1031#include "content/common/content_switches.h"
[email protected]37666cf2011-03-13 21:51:4232#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5533#include "content/common/drag_messages.h"
[email protected]7ef40ffe12011-03-08 05:05:2834#include "content/common/file_system/file_system_dispatcher.h"
35#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]a2ef54c2011-10-10 16:20:3136#include "content/common/intents_messages.h"
[email protected]7f070d42011-03-09 20:25:3237#include "content/common/notification_service.h"
[email protected]127dd582011-03-16 21:32:1038#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0039#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4040#include "content/common/quota_dispatcher.h"
[email protected]60916042011-03-19 00:43:3641#include "content/common/renderer_preferences.h"
[email protected]940895b2011-08-20 00:50:0542#include "content/common/request_extra_data.h"
[email protected]9966325b2011-04-18 05:00:1043#include "content/common/url_constants.h"
[email protected]778574e2011-03-21 22:03:5044#include "content/common/view_messages.h"
[email protected]d344114c2011-10-01 01:24:3445#include "content/public/renderer/content_renderer_client.h"
[email protected]82ddba1c2011-10-04 00:15:3246#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4447#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3648#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1949#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0250#include "content/renderer/devtools_agent.h"
[email protected]55722152011-03-22 01:33:5351#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1952#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4053#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]1ef93132011-09-16 18:33:4754#include "content/renderer/intents_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0255#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0856#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3757#include "content/renderer/media/audio_renderer_impl.h"
[email protected]ab2c4732011-07-20 19:57:4058#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:4059#include "content/renderer/media/render_media_log.h"
[email protected]4a19be92011-09-22 14:25:0260#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1961#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3762#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3563#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0564#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4465#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4466#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3267#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0168#include "content/renderer/renderer_webapplicationcachehost_impl.h"
69#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1970#include "content/renderer/speech_input_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3271#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1972#include "content/renderer/v8_value_converter_impl.h"
[email protected]663bd9e2011-03-21 01:07:0173#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3574#include "content/renderer/webplugin_delegate_proxy.h"
75#include "content/renderer/websharedworker_proxy.h"
76#include "content/renderer/webworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4977#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4178#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2779#include "media/base/message_loop_factory_impl.h"
initial.commit09911bf2008-07-26 23:55:2980#include "net/base/escape.h"
81#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0482#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5783#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3784#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
85#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
86#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3787#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
88#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
89#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
90#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3791#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
92#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
93#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
94#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
95#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
96#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
97#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
98#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
99#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57100#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]69f110d62011-03-17 19:01:14101#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37102#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19103#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37104#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
105#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
106#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
111#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
112#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
113#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17114#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37115#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40118#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]8bd0fe62011-01-17 06:44:37119#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26127#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c4a9e932011-03-05 04:05:55128#include "ui/base/message_box_flags.h"
[email protected]08397d52011-02-05 01:53:38129#include "ui/gfx/native_widget_types.h"
130#include "ui/gfx/point.h"
131#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55132#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04133#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43134#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24135#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19136#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59137#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24138#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24139#include "webkit/glue/glue_serialize.h"
[email protected]85cc78c2010-05-04 18:30:09140#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26141#include "webkit/glue/password_form_dom_manager.h"
initial.commit09911bf2008-07-26 23:55:29142#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07143#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29144#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17145#include "webkit/glue/webmediaplayer_impl.h"
[email protected]b00ba702011-08-17 01:41:03146#include "webkit/glue/weburlloader_impl.h"
[email protected]191eb3f72010-12-21 06:27:50147#include "webkit/plugins/npapi/default_plugin_shared.h"
148#include "webkit/plugins/npapi/plugin_list.h"
149#include "webkit/plugins/npapi/webplugin_delegate.h"
150#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
151#include "webkit/plugins/npapi/webplugin_impl.h"
152#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52153#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29154
[email protected]6c8afae52009-01-22 02:24:57155#if defined(OS_WIN)
156// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57157// * theming
[email protected]08397d52011-02-05 01:53:38158#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03159#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37160#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51161#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33162#elif defined(OS_MACOSX)
163#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57164#endif
165
[email protected]9892b472010-09-16 00:23:42166using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08167using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21168using WebKit::WebApplicationCacheHost;
169using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26170using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41171using WebKit::WebColor;
172using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59173using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44174using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51175using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55176using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28177using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00178using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58179using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25180using WebKit::WebDragOperation;
181using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51182using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51183using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08184using WebKit::WebExternalPopupMenu;
185using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47186using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22187using WebKit::WebFileSystem;
188using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49189using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59190using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48191using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45192using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17193using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13194using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41195using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50196using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17197using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28198using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17199using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28200using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28201using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51202using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19203using WebKit::WebPageSerializer;
204using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17205using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40206using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49207using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09208using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52209using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59210using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51211using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52212using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40213using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35214using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29215using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17216using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59217using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42218using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02219using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34220using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40221using WebKit::WebStorageQuotaCallbacks;
222using WebKit::WebStorageQuotaError;
223using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28224using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51225using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52226using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24227using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28228using WebKit::WebURL;
229using WebKit::WebURLError;
230using WebKit::WebURLRequest;
231using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28232using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03233using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28234using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26235using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43236using WebKit::WebWorker;
237using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26238using appcache::WebApplicationCacheHostImpl;
239using base::Time;
240using base::TimeDelta;
[email protected]82ddba1c2011-10-04 00:15:32241using content::NavigationState;
[email protected]380244092011-10-07 17:26:27242using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44243using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36244using content::RenderViewVisitor;
[email protected]8d86f13d2011-10-04 17:01:19245using content::V8ValueConverter;
[email protected]6fdd4182010-10-14 23:59:26246using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26247using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26248using webkit_glue::PasswordForm;
249using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23250using webkit_glue::ResourceFetcher;
[email protected]e1acf6f2008-10-27 20:43:33251
initial.commit09911bf2008-07-26 23:55:29252//-----------------------------------------------------------------------------
253
[email protected]3354d3e2010-06-10 19:53:02254typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49255static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02256
[email protected]882daa92009-11-05 16:31:31257// Time, in seconds, we delay before sending content state changes (such as form
258// state and scroll position) to the browser. We delay sending changes to avoid
259// spamming the browser.
260// To avoid having tab/session restore require sending a message to get the
261// current content state during tab closing we use a shorter timeout for the
262// foreground renderer. This means there is a small window of time from which
263// content state is modified and not sent to session restore, but this is
264// better than having to wake up all renderers during shutdown.
265static const int kDelaySecondsForContentStateSyncHidden = 5;
266static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29267
[email protected]0aa55312008-10-17 21:53:08268// The maximum number of popups that can be spawned from one page.
269static const int kMaximumNumberOfUnacknowledgedPopups = 25;
270
[email protected]c514d6372011-08-16 22:54:44271static const float kScalingIncrement = 0.1f;
272
[email protected]726985e22009-06-18 21:09:28273static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
274 WebVector<WebURL> urls;
275 ds->redirectChain(urls);
276 result->reserve(urls.size());
277 for (size_t i = 0; i < urls.size(); ++i)
278 result->push_back(urls[i]);
279}
280
[email protected]6a8f5112011-05-13 16:38:44281// If |data_source| is non-null and has a NavigationState associated with it,
282// the AltErrorPageResourceFetcher is reset.
283static void StopAltErrorPageFetcher(WebDataSource* data_source) {
284 if (data_source) {
285 NavigationState* state = NavigationState::FromDataSource(data_source);
286 if (state)
287 state->set_alt_error_page_fetcher(NULL);
288 }
289}
290
initial.commit09911bf2008-07-26 23:55:29291///////////////////////////////////////////////////////////////////////////////
292
[email protected]60c42a8c72009-10-09 04:08:59293int32 RenderView::next_page_id_ = 1;
294
[email protected]cdaf8d02010-03-30 19:52:47295struct RenderView::PendingFileChooser {
296 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
297 WebFileChooserCompletion* c)
298 : params(p),
299 completion(c) {
300 }
301 ViewHostMsg_RunFileChooser_Params params;
302 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
303};
304
[email protected]380244092011-10-07 17:26:27305RenderView::RenderView(gfx::NativeViewId parent_hwnd,
[email protected]676126f72011-01-15 00:03:51306 int32 opener_id,
307 const RendererPreferences& renderer_prefs,
308 const WebPreferences& webkit_prefs,
309 SharedRenderViewCounter* counter,
310 int32 routing_id,
311 int64 session_storage_namespace_id,
312 const string16& frame_name)
[email protected]380244092011-10-07 17:26:27313 : RenderWidget(WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51314 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02315 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09316 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02317 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24318 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21319 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02320 opened_by_user_gesture_(true),
321 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24322 page_id_(-1),
323 last_page_id_sent_to_browser_(-1),
[email protected]3cc72b12010-03-18 23:03:00324 history_list_offset_(-1),
325 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02326 target_url_status_(TARGET_NONE),
[email protected]dd6afca2011-08-13 03:44:31327 cached_is_main_frame_pinned_to_left_(false),
328 cached_is_main_frame_pinned_to_right_(false),
329 cached_has_main_frame_horizontal_scrollbar_(false),
330 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]18ca9a6b2010-06-02 19:05:18331 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e6ae0f6c2011-10-04 10:39:23332#if defined(OS_WIN)
333 focused_plugin_id_(-1),
334#endif
[email protected]3354d3e2010-06-10 19:53:02335 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51336 geolocation_dispatcher_(NULL),
337 speech_input_dispatcher_(NULL),
338 device_orientation_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18339 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41340 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32341 renderer_accessibility_(NULL),
[email protected]4fb60142011-08-09 02:22:08342 session_storage_namespace_id_(session_storage_namespace_id),
343 handling_select_range_(false) {
[email protected]676126f72011-01-15 00:03:51344 routing_id_ = routing_id;
345 if (opener_id != MSG_ROUTING_NONE)
346 opener_id_ = opener_id;
347
[email protected]11fee2332011-03-29 20:36:35348 webwidget_ = WebView::create(this);
349
[email protected]676126f72011-01-15 00:03:51350 if (counter) {
351 shared_popup_counter_ = counter;
352 shared_popup_counter_->data++;
353 decrement_shared_popup_at_destruction_ = true;
354 } else {
355 shared_popup_counter_ = new SharedRenderViewCounter(0);
356 decrement_shared_popup_at_destruction_ = false;
357 }
358
[email protected]1ef93132011-09-16 18:33:47359 intents_dispatcher_ = new IntentsDispatcher(this);
[email protected]676126f72011-01-15 00:03:51360 notification_provider_ = new NotificationProvider(this);
361
[email protected]380244092011-10-07 17:26:27362 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51363 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47364 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51365 AddRef();
366
367 // If this is a popup, we must wait for the CreatingNew_ACK message before
368 // completing initialization. Otherwise, we can finish it now.
369 if (opener_id == MSG_ROUTING_NONE) {
370 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55371 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51372 }
373
[email protected]34c61bd52011-05-02 19:38:33374 g_view_map.Get().insert(std::make_pair(webview(), this));
375 webkit_preferences_.Apply(webview());
376 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35377 if (!frame_name.empty())
378 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33379 webview()->settings()->setMinimumTimerInterval(
380 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
381 webkit_glue::kForegroundTabTimerInterval);
382
383 OnSetRendererPrefs(renderer_prefs);
384
[email protected]676126f72011-01-15 00:03:51385 host_window_ = parent_hwnd;
386
[email protected]a026daa2011-04-20 15:49:51387#if defined(ENABLE_P2P_APIS)
[email protected]b3f8f9722011-08-25 20:56:07388 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51389#endif
[email protected]cae8c8492011-03-03 11:12:18390
[email protected]8f6a3b852011-07-19 16:48:56391 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32392#if defined(OS_MACOSX)
393 new TextInputClientObserver(this);
394#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56395
[email protected]c5c1d6d2011-07-28 18:42:41396 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20397
[email protected]063afcb2011-09-29 07:54:32398 renderer_accessibility_ = new RendererAccessibility(this);
399
400 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]ab2c4732011-07-20 19:57:40401 if (command_line.HasSwitch(switches::kEnableMediaStream)) {
402 media_stream_impl_ = new MediaStreamImpl(
[email protected]f1a29a02011-10-06 23:08:44403 RenderThreadImpl::current()->video_capture_impl_manager());
[email protected]ab2c4732011-07-20 19:57:40404 }
405
[email protected]e48869a2011-04-01 19:56:03406 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29407}
408
409RenderView::~RenderView() {
[email protected]d466b8a2011-07-15 21:48:03410 history_page_ids_.clear();
411
[email protected]0aa55312008-10-17 21:53:08412 if (decrement_shared_popup_at_destruction_)
413 shared_popup_counter_->data--;
414
[email protected]a1128322009-10-06 18:38:46415 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47416 while (!file_chooser_completions_.empty()) {
417 if (file_chooser_completions_.front()->completion) {
418 file_chooser_completions_.front()->completion->didChooseFile(
419 WebVector<WebString>());
420 }
421 file_chooser_completions_.pop_front();
422 }
[email protected]a1128322009-10-06 18:38:46423
[email protected]83dde542009-09-11 20:59:55424#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11425 // Destroy all fake plugin window handles on the browser side.
426 while (!fake_plugin_window_handles_.empty()) {
427 // Make sure no NULL plugin window handles were inserted into this list.
428 DCHECK(*fake_plugin_window_handles_.begin());
429 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
430 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
431 }
[email protected]83dde542009-09-11 20:59:55432#endif
[email protected]98324892009-09-09 21:16:05433
[email protected]60c42a8c72009-10-09 04:08:59434#ifndef NDEBUG
435 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49436 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59437 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
438 DCHECK_NE(this, it->second) << "Failed to call Close?";
439#endif
[email protected]676126f72011-01-15 00:03:51440
441 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
442 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59443}
444
445/*static*/
[email protected]a2ef54c2011-10-10 16:20:31446RenderView* RenderView::FromWebView(WebView* webview) {
447 ViewMap* views = g_view_map.Pointer();
448 ViewMap::iterator it = views->find(webview);
449 return it == views->end() ? NULL : it->second;
450}
451
452/*static*/
453content::RenderView*
454 content::RenderView::FromWebView(WebKit::WebView* webview) {
455 return ::RenderView::FromWebView(webview);
456}
457
458/*static*/
459void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49460 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59461 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
462 if (!visitor->Visit(it->second))
463 return;
464 }
465}
466
467/*static*/
[email protected]0aa55312008-10-17 21:53:08468RenderView* RenderView::Create(
[email protected]18bcc3c2009-01-27 21:39:15469 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08470 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51471 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08472 const WebPreferences& webkit_prefs,
473 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34474 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26475 int64 session_storage_namespace_id,
476 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29477 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51478 return new RenderView(
[email protected]676126f72011-01-15 00:03:51479 parent_hwnd,
480 opener_id,
481 renderer_prefs,
482 webkit_prefs,
483 counter,
484 routing_id,
485 session_storage_namespace_id,
486 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29487}
488
[email protected]bb461532010-11-26 21:50:23489// static
initial.commit09911bf2008-07-26 23:55:29490void RenderView::SetNextPageID(int32 next_page_id) {
491 // This method should only be called during process startup, and the given
492 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05493 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29494 DCHECK(next_page_id >= next_page_id_);
495 next_page_id_ = next_page_id;
496}
497
[email protected]676126f72011-01-15 00:03:51498void RenderView::AddObserver(RenderViewObserver* observer) {
499 observers_.AddObserver(observer);
500}
501
502void RenderView::RemoveObserver(RenderViewObserver* observer) {
503 observer->set_render_view(NULL);
504 observers_.RemoveObserver(observer);
505}
506
[email protected]8a3125a712010-08-09 18:58:51507WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26508 return static_cast<WebKit::WebView*>(webwidget());
509}
510
[email protected]1a3c3cb2010-12-16 21:03:40511void RenderView::SetReportLoadProgressEnabled(bool enabled) {
512 if (!enabled) {
513 load_progress_tracker_.reset(NULL);
514 return;
515 }
516 if (load_progress_tracker_ == NULL)
517 load_progress_tracker_.reset(new LoadProgressTracker(this));
518}
519
[email protected]a3a8fb6d2009-10-22 20:12:51520void RenderView::PluginCrashed(const FilePath& plugin_path) {
521 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29522}
523
[email protected]d8fd6fa2010-02-01 15:54:26524void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
525 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30526 // If the renderer is visible, set initial visibility and focus state.
527 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34528#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30529 delegate->SetContainerVisibility(true);
530 if (webview() && webview()->isActive())
531 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34532#endif
[email protected]49232292010-09-03 19:07:30533 }
[email protected]784ea1ab2010-09-18 00:02:34534 // Plugins start assuming the content has focus (so that they work in
535 // environments where RenderView isn't hosting them), so we always have to
536 // set the initial state. See webplugin_delegate_impl.h for details.
537 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26538}
539
540void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
541 plugin_delegates_.erase(delegate);
542}
[email protected]d8fd6fa2010-02-01 15:54:26543
[email protected]4a7d6392011-09-19 20:55:08544bool RenderView::GetPluginInfo(const GURL& url,
545 const GURL& page_url,
546 const std::string& mime_type,
547 webkit::WebPluginInfo* plugin_info,
548 std::string* actual_mime_type) {
549 bool found = false;
550 Send(new ViewHostMsg_GetPluginInfo(
551 routing_id_, url, page_url, mime_type, &found, plugin_info,
552 actual_mime_type));
553 return found;
554}
555
[email protected]a95986a82010-12-24 06:19:28556bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27557 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27558 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41559 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26560
[email protected]676126f72011-01-15 00:03:51561 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
562 RenderViewObserver* observer;
563 while ((observer = it.GetNext()) != NULL)
564 if (observer->OnMessageReceived(message))
565 return true;
[email protected]b2abac72009-02-26 12:39:28566
[email protected]a95986a82010-12-24 06:19:28567 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40568 bool msg_is_ok = true;
569 IPC_BEGIN_MESSAGE_MAP_EX(RenderView, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29570 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
571 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56572 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29573 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
574 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
575 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
576 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27577#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35578 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27579#endif
initial.commit09911bf2008-07-26 23:55:29580 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
581 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
582 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
583 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08584 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29585 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15586 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29587 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49588 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
589 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17590 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17591 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:54592 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
593 OnSetZoomLevelForLoadingURL)
[email protected]8a5e0ca2011-08-25 06:30:47594 IPC_MESSAGE_HANDLER(ViewMsg_ExitFullscreen, OnExitFullscreen)
initial.commit09911bf2008-07-26 23:55:29595 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18596 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
597 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29598 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48599 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29600 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55601 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
602 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
603 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
604 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
605 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
606 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
607 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45608 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40609 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29610 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19611 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
612 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29613 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
614 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
615 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51616 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
617 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29618 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04619 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15620 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29621 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
622 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08623 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
624 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00625 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16626 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14627 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25628 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
629 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10630 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
631 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51632 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56633 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34634 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14635#if defined(OS_MACOSX)
636 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13637 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13638 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
639 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14640#endif
[email protected]446705872009-09-10 07:22:48641 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33642 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33643 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
644 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24645 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42646 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
647 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19648 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
649 OnGetAllSavableResourceLinksForCurrentPage)
650 IPC_MESSAGE_HANDLER(
651 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
652 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08653#if defined(OS_MACOSX)
654 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
655#endif
[email protected]521b2482011-01-15 00:10:10656 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51657 // TODO(viettrungluu): Move to a separate message filter.
658#if defined(ENABLE_FLAPPER_HACKS)
659 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
660#endif
[email protected]54ca3ca892011-06-07 21:14:54661#if defined(OS_MACOSX)
662 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
663#endif
[email protected]08bb1e722011-07-30 19:13:04664 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRemoteAccessClientFirewallTraversal,
665 OnUpdateRemoteAccessClientFirewallTraversal)
[email protected]9e1ad4b2011-08-14 16:49:19666 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
667 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18668 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]67bfb83f2011-09-22 03:36:37669 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
670 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
[email protected]9e1ad4b2011-08-14 16:49:19671
initial.commit09911bf2008-07-26 23:55:29672 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28673 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29674 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40675
676 if (!msg_is_ok) {
677 // The message had a handler, but its deserialization failed.
678 // Kill the renderer to avoid potential spoofing attacks.
679 CHECK(false) << "Unable to deserialize message in RenderView.";
680 }
681
[email protected]a95986a82010-12-24 06:19:28682 return handled;
initial.commit09911bf2008-07-26 23:55:29683}
684
initial.commit09911bf2008-07-26 23:55:29685void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
686 if (!webview())
687 return;
688
[email protected]440a0e52011-09-13 17:38:58689 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
690
[email protected]d466b8a2011-07-15 21:48:03691 bool is_reload =
692 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
693 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
694
695 // If this is a stale back/forward (due to a recent navigation the browser
696 // didn't know about), ignore it.
697 if (IsBackForwardToStaleEntry(params, is_reload))
698 return;
699
[email protected]992db4c2011-05-12 15:37:15700 // Swap this renderer back in if necessary.
701 if (is_swapped_out_)
702 SetSwappedOut(false);
703
[email protected]3cc72b12010-03-18 23:03:00704 history_list_offset_ = params.current_history_list_offset;
705 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03706 if (history_list_length_ >= 0)
707 history_page_ids_.resize(history_list_length_, -1);
708 if (params.pending_history_list_offset >= 0 &&
709 params.pending_history_list_offset < history_list_length_)
710 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00711
[email protected]38b592902011-04-16 02:08:42712 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29713
[email protected]26aa0482009-09-30 16:55:27714 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45715 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29716 // We cannot reload if we do not have any history state. This happens, for
717 // example, when recovering from a crash. Our workaround here is a bit of
718 // a hack since it means that reload after a crashed tab does not cause an
719 // end-to-end cache validation.
720 is_reload = false;
721 }
722
[email protected]77f17a82009-05-21 04:42:54723 // A navigation resulting from loading a javascript URL should not be treated
724 // as a browser initiated event. Instead, we want it to look as if the page
725 // initiated any load resulting from JS execution.
726 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:30727 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:00728 params.page_id,
729 params.pending_history_list_offset,
730 params.transition,
731 params.request_time);
[email protected]2c5569662011-03-22 20:45:02732 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
[email protected]5e369672009-11-03 23:48:30733 // We're doing a load of a page that was restored from the last session.
734 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
735 // which can result in stale data for pages that are set to expire. We
736 // explicitly override that by setting the policy here so that as
737 // necessary we load from the network.
738 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
739 }
740 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:54741 }
initial.commit09911bf2008-07-26 23:55:29742
[email protected]a7ccc4d2010-01-27 08:14:48743 NavigationState* navigation_state = pending_navigation_state_.get();
744
[email protected]48a5c772011-04-18 23:50:50745 if (navigation_state) {
746 // New loads need to reset the error page fetcher. Otherwise if there is an
747 // outstanding error page fetcher it may complete and clobber the current
748 // page load.
749 navigation_state->set_alt_error_page_fetcher(NULL);
750 }
751
[email protected]04d3c6e2009-05-22 17:00:13752 // If we are reloading, then WebKit will use the history state of the current
753 // page, so we should just ignore any given history state. Otherwise, if we
754 // have history state, then we need to navigate to it, which corresponds to a
755 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55756 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:48757 if (navigation_state)
758 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:29759 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02760 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29761 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55762 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13763 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58764 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:48765 if (navigation_state)
766 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:45767 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17768 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13769 } else {
770 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28771 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29772
[email protected]e6f546c32009-07-01 17:12:55773 // A session history navigation should have been accompanied by state.
774 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13775
[email protected]dd7daa82009-08-10 05:46:45776 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55777 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13778
[email protected]726985e22009-06-18 21:09:28779 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17780 if (!WebSecurityPolicy::shouldHideReferrer(
781 params.url,
782 WebString::fromUTF8(params.referrer.spec()))) {
783 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
784 WebString::fromUTF8(params.referrer.spec()));
785 }
[email protected]726985e22009-06-18 21:09:28786 }
[email protected]04d3c6e2009-05-22 17:00:13787
[email protected]52c68652010-12-07 17:47:04788 if (!params.extra_headers.empty()) {
789 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
790 params.extra_headers.end(), "\n");
791 i.GetNext(); ) {
792 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
793 WebString::fromUTF8(i.values()));
794 }
795 }
796
[email protected]16e923d2011-04-30 00:41:44797 if (navigation_state)
798 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
[email protected]dd7daa82009-08-10 05:46:45799 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50800 }
801
[email protected]77f17a82009-05-21 04:42:54802 // In case LoadRequest failed before DidCreateDataSource was called.
803 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:29804}
805
[email protected]d466b8a2011-07-15 21:48:03806bool RenderView::IsBackForwardToStaleEntry(
807 const ViewMsg_Navigate_Params& params,
808 bool is_reload) {
809 // Make sure this isn't a back/forward to an entry we have already cropped
810 // or replaced from our history, before the browser knew about it. If so,
811 // a new navigation has committed in the mean time, and we can ignore this.
812 bool is_back_forward = !is_reload && !params.state.empty();
813
814 // Note: if the history_list_length_ is 0 for a back/forward, we must be
815 // restoring from a previous session. We'll update our state in OnNavigate.
816 if (!is_back_forward || history_list_length_ <= 0)
817 return false;
818
819 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
820
821 // Check for whether the forward history has been cropped due to a recent
822 // navigation the browser didn't know about.
823 if (params.pending_history_list_offset >= history_list_length_)
824 return true;
825
826 // Check for whether this entry has been replaced with a new one.
827 int expected_page_id =
828 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44829 if (expected_page_id > 0 && params.page_id != expected_page_id) {
830 if (params.page_id < expected_page_id)
831 return true;
832
833 // Otherwise we've removed an earlier entry and should have shifted all
834 // entries left. For now, it's ok to lazily update the list.
835 // TODO(creis): Notify all live renderers when we remove entries from
836 // the front of the list, so that we don't hit this case.
837 history_page_ids_[params.pending_history_list_offset] = params.page_id;
838 }
[email protected]d466b8a2011-07-15 21:48:03839
840 return false;
841}
842
initial.commit09911bf2008-07-26 23:55:29843// Stop loading the current page
844void RenderView::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44845 if (webview()) {
846 WebFrame* main_frame = webview()->mainFrame();
847 // Stop the alt error page fetcher. If we let it continue it may complete
848 // and cause RenderViewHostManager to swap to this RenderView, even though
849 // it may no longer be active.
850 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
851 StopAltErrorPageFetcher(main_frame->dataSource());
852 main_frame->stopLoading();
853 }
initial.commit09911bf2008-07-26 23:55:29854}
855
[email protected]ecbf10d2010-02-18 13:03:29856// Reload current focused frame.
857// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:56858void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29859 if (webview() && webview()->focusedFrame()) {
860 // We always obey the cache (ignore_cache=false) here.
861 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
862 // a cache-ignoring reload of the frame.
863 webview()->focusedFrame()->reload(false);
864 }
[email protected]1dda4022010-01-28 18:24:56865}
866
initial.commit09911bf2008-07-26 23:55:29867void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27868 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29869}
870
[email protected]68b1e922009-06-23 16:00:25871void RenderView::OnExecuteEditCommand(const std::string& name,
872 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27873 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25874 return;
875
[email protected]26aa0482009-09-30 16:55:27876 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45877 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25878}
879
initial.commit09911bf2008-07-26 23:55:29880void RenderView::OnUpdateTargetURLAck() {
881 // Check if there is a targeturl waiting to be sent.
882 if (target_url_status_ == TARGET_PENDING) {
883 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
884 pending_target_url_));
885 }
886
887 target_url_status_ = TARGET_NONE;
888}
889
890void RenderView::OnUndo() {
891 if (!webview())
892 return;
893
[email protected]26aa0482009-09-30 16:55:27894 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29895}
896
897void RenderView::OnRedo() {
898 if (!webview())
899 return;
900
[email protected]26aa0482009-09-30 16:55:27901 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29902}
903
904void RenderView::OnCut() {
905 if (!webview())
906 return;
907
[email protected]26aa0482009-09-30 16:55:27908 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29909}
910
911void RenderView::OnCopy() {
912 if (!webview())
913 return;
914
[email protected]f6b1856b2011-06-29 22:02:53915 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
916 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29917}
918
[email protected]c0cc3092009-09-12 08:27:27919#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35920void RenderView::OnCopyToFindPboard() {
921 if (!webview())
922 return;
923
924 // Since the find pasteboard supports only plain text, this can be simpler
925 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27926 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35927 if (frame->hasSelection()) {
928 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:27929 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:17930 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35931 }
[email protected]a954bf72009-09-12 07:30:35932}
[email protected]c0cc3092009-09-12 08:27:27933#endif
[email protected]a954bf72009-09-12 07:30:35934
initial.commit09911bf2008-07-26 23:55:29935void RenderView::OnPaste() {
936 if (!webview())
937 return;
938
[email protected]26aa0482009-09-30 16:55:27939 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29940}
941
[email protected]2a3a7762009-10-19 19:17:32942void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29943 if (!webview())
944 return;
945
[email protected]1ff7a032010-02-03 02:46:03946 WebFrame* frame = webview()->focusedFrame();
947 if (!frame->hasSelection())
948 frame->selectWordAroundCaret();
949 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29950}
951
952void RenderView::OnDelete() {
953 if (!webview())
954 return;
955
[email protected]26aa0482009-09-30 16:55:27956 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29957}
958
959void RenderView::OnSelectAll() {
960 if (!webview())
961 return;
962
[email protected]26aa0482009-09-30 16:55:27963 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22964 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29965}
966
[email protected]4fb60142011-08-09 02:22:08967void RenderView::OnSelectRange(const gfx::Point& start, const gfx::Point& end) {
968 if (!webview())
969 return;
970
971 handling_select_range_ = true;
972 webview()->focusedFrame()->selectRange(start, end);
973 handling_select_range_ = false;
974}
975
[email protected]9e1ad4b2011-08-14 16:49:19976void RenderView::OnSetHistoryLengthAndPrune(int history_length,
977 int32 minimum_page_id) {
978 DCHECK(history_length >= 0);
979 DCHECK(history_list_offset_ == history_list_length_ - 1);
980 DCHECK(minimum_page_id >= -1);
981
982 // Generate the new list.
983 std::vector<int32> new_history_page_ids(history_length, -1);
984 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
985 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
986 continue;
987 new_history_page_ids.push_back(history_page_ids_[i]);
988 }
989 new_history_page_ids.swap(history_page_ids_);
990
991 // Update indexes.
992 history_list_length_ = history_page_ids_.size();
993 history_list_offset_ = history_list_length_ - 1;
994}
995
996
initial.commit09911bf2008-07-26 23:55:29997void RenderView::OnSetInitialFocus(bool reverse) {
998 if (!webview())
999 return;
[email protected]26aa0482009-09-30 16:55:271000 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291001}
1002
[email protected]54ca3ca892011-06-07 21:14:541003#if defined(OS_MACOSX)
1004void RenderView::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331005 if (!webview())
1006 return;
1007 if (in_live_resize)
1008 webview()->willStartLiveResize();
1009 else
1010 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541011}
1012#endif
1013
[email protected]333ec8d02011-09-16 18:59:191014void RenderView::OnScrollFocusedEditableNodeIntoRect(const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091015 WebKit::WebNode node = GetFocusedNode();
1016 if (!node.isNull()) {
1017 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191018 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511019 }
1020}
1021
initial.commit09911bf2008-07-26 23:55:291022///////////////////////////////////////////////////////////////////////////////
1023
1024// Tell the embedding application that the URL of the active page has changed
1025void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451026 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291027 DCHECK(ds);
1028
[email protected]726985e22009-06-18 21:09:281029 const WebURLRequest& request = ds->request();
1030 const WebURLRequest& original_request = ds->originalRequest();
1031 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291032
[email protected]daa8c58e2009-06-15 17:21:101033 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1034 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291035
1036 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281037 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291038 params.is_post = false;
1039 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071040 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191041 params.socket_address.set_host(response.remoteIPAddress().utf8());
1042 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031043 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091044 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551045 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291046 // SSL state specified in the request takes precedence over the one in the
1047 // response.
1048 // So far this is only intended for error pages that are not expected to be
1049 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281050 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551051 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291052 } else {
[email protected]726985e22009-06-18 21:09:281053 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291054 }
1055
1056 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281057 if (ds->hasUnreachableURL()) {
1058 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291059 } else {
[email protected]726985e22009-06-18 21:09:281060 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291061 }
1062
[email protected]726985e22009-06-18 21:09:281063 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241064 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041065 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291066
[email protected]ce0e250d2009-10-23 21:00:351067 params.searchable_form_url = navigation_state->searchable_form_url();
1068 params.searchable_form_encoding =
1069 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291070
1071 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101072 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291073 if (password_form_data)
1074 params.password_form = *password_form_data;
1075
1076 params.gesture = navigation_gesture_;
1077 navigation_gesture_ = NavigationGestureUnknown;
1078
[email protected]0f38dc4552011-02-25 11:24:001079 // Make navigation state a part of the FrameNavigate message so that commited
1080 // entry had it at all times.
1081 const WebHistoryItem& item = frame->currentHistoryItem();
1082 if (!item.isNull()) {
1083 params.content_state = webkit_glue::HistoryItemToString(item);
1084 } else {
1085 params.content_state =
1086 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1087 }
1088
[email protected]dd7daa82009-08-10 05:46:451089 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291090 // Top-level navigation.
1091
[email protected]b75b8292010-10-01 07:28:251092 // Set zoom level, but don't do it for full-page plugin since they don't use
1093 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011094 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541095 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251096 if (webview()->mainFrame()->document().isPluginDocument()) {
1097 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251098 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251099 } else {
1100 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251101 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251102 }
1103
[email protected]f85f0702010-01-30 09:31:011104 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511105 // This zoom level was merely recorded transiently for this load. We can
1106 // erase it now. If at some point we reload this page, the browser will
1107 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011108 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511109 }
1110
[email protected]b75b8292010-10-01 07:28:251111 // Reset the zoom limits in case a plugin had changed them previously. This
1112 // will also call us back which will cause us to send a message to
1113 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251114 webview()->zoomLimitsChanged(
1115 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1116 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251117
initial.commit09911bf2008-07-26 23:55:291118 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551119 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291120
[email protected]daa8c58e2009-06-15 17:21:101121 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291122 if (!PageTransition::IsMainFrame(params.transition)) {
1123 // If the main frame does a load, it should not be reported as a subframe
1124 // navigation. This can occur in the following case:
1125 // 1. You're on a site with frames.
1126 // 2. You do a subframe navigation. This is stored with transition type
1127 // MANUAL_SUBFRAME.
1128 // 3. You navigate to some non-frame site, say, google.com.
1129 // 4. You navigate back to the page from step 2. Since it was initially
1130 // MANUAL_SUBFRAME, it will be that same transition type here.
1131 // We don't want that, because any navigation that changes the toplevel
1132 // frame should be tracked as a toplevel navigation (this allows us to
1133 // update the URL bar, etc).
1134 params.transition = PageTransition::LINK;
1135 }
1136
initial.commit09911bf2008-07-26 23:55:291137 // If we have a valid consumed client redirect source,
1138 // the page contained a client redirect (meta refresh, document.loc...),
1139 // so we set the referrer and transition to match.
1140 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041141 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291142 params.referrer = completed_client_redirect_src_;
1143 params.transition = static_cast<PageTransition::Type>(
1144 params.transition | PageTransition::CLIENT_REDIRECT);
1145 } else {
1146 // Bug 654101: the referrer will be empty on https->http transitions. It
1147 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281148 params.referrer = GURL(
1149 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291150 }
1151
[email protected]726985e22009-06-18 21:09:281152 string16 method = request.httpMethod();
1153 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291154 params.is_post = true;
1155
[email protected]c2a797d2009-09-21 16:46:321156 // Save some histogram data so we can compute the average memory used per
1157 // page load of the glyphs.
1158 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1159 webkit_glue::GetGlyphPageCount());
1160
[email protected]15cf526b2010-02-12 06:33:491161 // This message needs to be sent before any of allowScripts(),
1162 // allowImages(), allowPlugins() is called for the new page, so that when
1163 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1164 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291165 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1166 } else {
1167 // Subframe navigation: the type depends on whether this navigation
1168 // generated a new session history entry. When they do generate a session
1169 // history entry, it means the user initiated the navigation and we should
1170 // mark it as such. This test checks if this is the first time UpdateURL
1171 // has been called since WillNavigateToURL was called to initiate the load.
1172 if (page_id_ > last_page_id_sent_to_browser_)
1173 params.transition = PageTransition::MANUAL_SUBFRAME;
1174 else
1175 params.transition = PageTransition::AUTO_SUBFRAME;
1176
initial.commit09911bf2008-07-26 23:55:291177 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1178 }
1179
1180 last_page_id_sent_to_browser_ =
1181 std::max(last_page_id_sent_to_browser_, page_id_);
1182
1183 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101184 // we don't want the transition type to persist. Just clear it.
1185 navigation_state->set_transition_type(PageTransition::LINK);
initial.commit09911bf2008-07-26 23:55:291186}
1187
1188// Tell the embedding application that the title of the active page has changed
[email protected]750fcf872011-08-03 23:10:471189void RenderView::UpdateTitle(WebFrame* frame,
1190 const string16& title,
[email protected]a49e10b2011-08-01 23:57:461191 WebTextDirection title_direction) {
1192 // Ignore all but top level navigations.
1193 if (frame->parent())
1194 return;
1195
1196 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1197 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1198 title_direction));
initial.commit09911bf2008-07-26 23:55:291199}
1200
1201void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401202 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291203 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271204 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291205 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301206 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291207 last_encoding_name_ = encoding_name;
1208
[email protected]e38f40152008-09-12 23:08:301209 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291210 }
1211}
1212
[email protected]e15f680732010-11-23 22:30:201213// Sends the last committed session history state to the browser so it will be
1214// saved before we navigate to a new page. This must be called *before* the
1215// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291216void RenderView::UpdateSessionHistory(WebFrame* frame) {
1217 // If we have a valid page ID at this point, then it corresponds to the page
1218 // we are navigating away from. Otherwise, this is the first navigation, so
1219 // there is no past session history to record.
1220 if (page_id_ == -1)
1221 return;
1222
[email protected]ca948a22009-06-25 19:36:171223 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271224 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171225 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291226 return;
[email protected]ca948a22009-06-25 19:36:171227
1228 Send(new ViewHostMsg_UpdateState(
1229 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291230}
1231
[email protected]ae5184d62011-10-06 19:25:581232void RenderView::OpenURL(WebFrame* frame,
1233 const GURL& url,
1234 const GURL& referrer,
1235 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171236 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581237 routing_id_,
1238 url,
1239 referrer,
1240 NavigationPolicyToDisposition(policy),
1241 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171242}
1243
[email protected]79dbc662009-09-04 05:42:511244// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291245
initial.commit09911bf2008-07-26 23:55:291246void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281247 const WebURLRequest& failed_request,
1248 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291249 const std::string& html,
1250 bool replace) {
[email protected]21d61e52011-03-18 19:08:251251 std::string alt_html = !html.empty() ? html :
1252 content::GetContentClient()->renderer()->GetNavigationErrorHtml(
1253 failed_request, error);
[email protected]dd7daa82009-08-10 05:46:451254 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361255 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251256 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551257 replace);
initial.commit09911bf2008-07-26 23:55:291258}
1259
initial.commit09911bf2008-07-26 23:55:291260bool RenderView::RunJavaScriptMessage(int type,
[email protected]4f5ce842011-05-27 19:34:411261 const string16& message,
1262 const string16& default_value,
[email protected]a455d3812009-03-05 20:18:071263 const GURL& frame_url,
[email protected]4f5ce842011-05-27 19:34:411264 string16* result) {
initial.commit09911bf2008-07-26 23:55:291265 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411266 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291267 if (!result)
1268 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291269
[email protected]12636df2009-09-28 22:32:211270 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1271 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291272 return success;
1273}
1274
[email protected]c1f50aa2010-02-18 03:46:571275bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1276 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1277 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1278 // it is particularly important that we do not call willEnterModalLoop as
1279 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441280 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1281 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571282
1283 message->EnableMessagePumping(); // Runs a nested message loop.
1284 return Send(message);
1285}
1286
[email protected]48c9cf2d2009-09-16 16:47:521287// WebKit::WebViewClient ------------------------------------------------------
1288
[email protected]844acf372011-01-14 10:49:271289WebView* RenderView::createView(
1290 WebFrame* creator,
1291 const WebURLRequest& request,
1292 const WebWindowFeatures& features,
1293 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521294 // Check to make sure we aren't overloading on popups.
1295 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1296 return NULL;
1297
[email protected]8ab04652010-06-12 02:47:261298 ViewHostMsg_CreateWindow_Params params;
1299 params.opener_id = routing_id_;
1300 params.user_gesture = creator->isProcessingUserGesture();
1301 params.window_container_type = WindowFeaturesToContainerType(features);
1302 params.session_storage_namespace_id = session_storage_namespace_id_;
1303 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111304 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411305 params.opener_url = creator->document().url();
1306 params.opener_security_origin =
1307 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111308 if (!request.isNull())
1309 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261310
[email protected]48c9cf2d2009-09-16 16:47:521311 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341312 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261313 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521314
[email protected]380244092011-10-07 17:26:271315 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261316 new ViewHostMsg_CreateWindow(params,
1317 &routing_id,
1318 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211319 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521320 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521321
[email protected]380244092011-10-07 17:26:271322 RenderView* view = RenderView::Create(0,
[email protected]12636df2009-09-28 22:32:211323 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521324 renderer_preferences_,
1325 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:211326 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:341327 routing_id,
[email protected]8ab04652010-06-12 02:47:261328 cloned_session_storage_namespace_id,
1329 frame_name);
1330 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521331
[email protected]007a848b2009-10-26 15:55:461332 // Record whether the creator frame is trying to suppress the opener field.
1333 view->opener_suppressed_ = opener_suppressed;
1334
[email protected]48c9cf2d2009-09-16 16:47:521335 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411336 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521337 if (!creator_url.is_valid() || !creator_url.IsStandard())
1338 creator_url = GURL();
1339 view->creator_url_ = creator_url;
1340
1341 // Copy over the alternate error page URL so we can have alt error pages in
1342 // the new render view (we don't need the browser to send the URL back down).
1343 view->alternate_error_page_url_ = alternate_error_page_url_;
1344
1345 return view->webview();
1346}
1347
[email protected]3e2b375b2010-04-07 17:03:121348WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]380244092011-10-07 17:26:271349 RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521350 return widget->webwidget();
1351}
1352
1353WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441354 // TODO(jcivelli): Remove this deprecated method when its been removed from
1355 // the WebViewClient interface. It's been replaced by
1356 // createExternalPopupMenu.
1357 NOTREACHED();
1358 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521359}
1360
[email protected]caf706f2010-10-26 17:54:081361WebExternalPopupMenu* RenderView::createExternalPopupMenu(
1362 const WebPopupMenuInfo& popup_menu_info,
1363 WebExternalPopupMenuClient* popup_menu_client) {
1364 DCHECK(!external_popup_menu_.get());
1365 external_popup_menu_.reset(
1366 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1367 return external_popup_menu_.get();
1368}
1369
[email protected]ea192e82011-04-11 19:16:021370RenderWidgetFullscreenPepper* RenderView::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521371 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531372 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421373 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411374 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531375 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271376 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391377 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561378 return widget;
[email protected]79c7bed2010-09-14 22:28:391379}
1380
[email protected]68c50e52010-05-12 11:14:391381WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341382 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391383 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291384 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1385 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1386 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341387}
1388
[email protected]48c9cf2d2009-09-16 16:47:521389void RenderView::didAddMessageToConsole(
1390 const WebConsoleMessage& message, const WebString& source_name,
1391 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081392 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511393 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081394 case WebConsoleMessage::LevelTip:
1395 log_severity = logging::LOG_VERBOSE;
1396 break;
1397 case WebConsoleMessage::LevelLog:
1398 log_severity = logging::LOG_INFO;
1399 break;
1400 case WebConsoleMessage::LevelWarning:
1401 log_severity = logging::LOG_WARNING;
1402 break;
1403 case WebConsoleMessage::LevelError:
1404 log_severity = logging::LOG_ERROR;
1405 break;
1406 default:
1407 NOTREACHED();
1408 }
1409
[email protected]48c9cf2d2009-09-16 16:47:521410 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081411 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311412 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521413 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311414 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521415}
1416
1417void RenderView::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421418 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521419}
1420
[email protected]3354d3e2010-06-10 19:53:021421WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511422 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021423}
1424
[email protected]8a58c1c2011-04-19 18:40:121425bool RenderView::enumerateChosenDirectory(
1426 const WebString& path,
1427 WebFileChooserCompletion* chooser_completion) {
1428 int id = enumeration_completion_id_++;
1429 enumeration_completions_[id] = chooser_completion;
1430 return Send(new ViewHostMsg_EnumerateDirectory(
1431 routing_id_,
1432 id,
1433 webkit_glue::WebStringToFilePath(path)));
1434}
1435
[email protected]48c9cf2d2009-09-16 16:47:521436void RenderView::didStartLoading() {
1437 if (is_loading_) {
1438 DLOG(WARNING) << "didStartLoading called while loading";
1439 return;
1440 }
1441
1442 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521443
1444 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311445
1446 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521447}
1448
1449void RenderView::didStopLoading() {
1450 if (!is_loading_) {
1451 DLOG(WARNING) << "DidStopLoading called while not loading";
1452 return;
1453 }
1454
1455 is_loading_ = false;
1456
1457 // NOTE: For now we're doing the safest thing, and sending out notification
1458 // when done loading. This currently isn't an issue as the favicon is only
1459 // displayed when done loading. Ideally we would send notification when
1460 // finished parsing the head, but webkit doesn't support that yet.
1461 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521462 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1463
[email protected]90109412010-12-15 17:14:241464 if (load_progress_tracker_ != NULL)
1465 load_progress_tracker_->DidStopLoading();
1466
[email protected]93b9d692011-04-13 00:44:311467 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521468}
1469
[email protected]90109412010-12-15 17:14:241470void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
1471 if (load_progress_tracker_ != NULL)
1472 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1473}
1474
[email protected]f55039a2010-02-17 14:12:061475bool RenderView::isSmartInsertDeleteEnabled() {
1476#if defined(OS_MACOSX)
1477 return true;
1478#else
1479 return false;
1480#endif
1481}
1482
[email protected]04fc9482009-09-18 22:13:031483bool RenderView::isSelectTrailingWhitespaceEnabled() {
1484#if defined(OS_WIN)
1485 return true;
1486#else
1487 return false;
1488#endif
1489}
1490
[email protected]04fc9482009-09-18 22:13:031491void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:421492#if defined(OS_POSIX)
[email protected]4fb60142011-08-09 02:22:081493 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031494 return;
[email protected]4fb60142011-08-09 02:22:081495 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011496
[email protected]b781ff282011-08-20 06:19:361497 SyncSelectionIfRequired();
[email protected]0ff0ff32010-12-21 19:34:421498#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:031499}
1500
1501void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121502 const std::string& name = UTF16ToUTF8(command_name);
1503 if (StartsWithASCII(name, "Move", true) ||
1504 StartsWithASCII(name, "Insert", true) ||
1505 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031506 return;
[email protected]f1a29a02011-10-06 23:08:441507 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031508}
1509
[email protected]b2528b72009-09-24 06:57:101510bool RenderView::handleCurrentKeyboardEvent() {
1511 if (edit_commands_.empty())
1512 return false;
1513
[email protected]26aa0482009-09-30 16:55:271514 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101515 if (!frame)
1516 return false;
1517
1518 EditCommands::iterator it = edit_commands_.begin();
1519 EditCommands::iterator end = edit_commands_.end();
1520
[email protected]507b33ea2009-09-29 03:56:511521 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101522 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331523 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1524 // key (but it's the exception). Once one edit command is not executed, it
1525 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101526 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1527 WebString::fromUTF8(it->value)))
1528 break;
[email protected]507b33ea2009-09-29 03:56:511529 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101530 }
1531
[email protected]507b33ea2009-09-29 03:56:511532 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101533}
1534
[email protected]a1128322009-10-06 18:38:461535bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:351536 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471537 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351538 // Do not open the file dialog in a hidden RenderView.
1539 if (is_hidden())
1540 return false;
[email protected]cdaf8d02010-03-30 19:52:471541 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261542 if (params.directory)
[email protected]0aed2f52011-03-23 18:06:361543 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261544 else if (params.multiSelect)
[email protected]0aed2f52011-03-23 18:06:361545 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::OpenMultiple;
[email protected]b5977a0c2010-08-24 19:46:261546 else
[email protected]0aed2f52011-03-23 18:06:361547 ipc_params.mode = ViewHostMsg_RunFileChooser_Mode::Open;
[email protected]cdaf8d02010-03-30 19:52:471548 ipc_params.title = params.title;
1549 ipc_params.default_file_name =
1550 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:591551 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:471552
1553 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461554}
1555
[email protected]48c9cf2d2009-09-16 16:47:521556void RenderView::runModalAlertDialog(
1557 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061558 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]4f5ce842011-05-27 19:34:411559 message,
1560 string16(),
[email protected]b6cb3a842011-06-24 18:28:411561 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521562 NULL);
1563}
1564
1565bool RenderView::runModalConfirmDialog(
1566 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061567 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]4f5ce842011-05-27 19:34:411568 message,
1569 string16(),
[email protected]b6cb3a842011-06-24 18:28:411570 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521571 NULL);
1572}
1573
1574bool RenderView::runModalPromptDialog(
1575 WebFrame* frame, const WebString& message, const WebString& default_value,
1576 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411577 string16 result;
[email protected]9dd7e3d72011-01-20 18:27:061578 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]4f5ce842011-05-27 19:34:411579 message,
1580 default_value,
[email protected]b6cb3a842011-06-24 18:28:411581 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521582 &result);
1583 if (ok)
[email protected]4f5ce842011-05-27 19:34:411584 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521585 return ok;
1586}
1587
1588bool RenderView::runModalBeforeUnloadDialog(
1589 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151590 // If we are swapping out, we have already run the beforeunload handler.
1591 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1592 // at all, to avoid running it twice.
1593 if (is_swapped_out_)
1594 return true;
1595
[email protected]48c9cf2d2009-09-16 16:47:521596 bool success = false;
1597 // This is an ignored return value, but is included so we can accept the same
1598 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411599 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211600 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411601 routing_id_, frame->document().url(), message,
1602 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521603 return success;
1604}
1605
[email protected]79e37442009-10-09 18:17:441606void RenderView::showContextMenu(
1607 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291608 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371609
1610 // frame is NULL if invoked by BlockedPlugin.
1611 if (frame)
1612 params.frame_id = frame->identifier();
1613
[email protected]db803aae2011-03-05 02:00:421614 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271615 // it. We replace it with an empty GURL so the appropriate items are disabled
1616 // in the context menu.
1617 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1618 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421619 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271620 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101621 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291622 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441623}
1624
[email protected]52f139e2c2010-06-11 16:56:091625bool RenderView::supportsFullscreen() {
1626 return CommandLine::ForCurrentProcess()->HasSwitch(
1627 switches::kEnableVideoFullscreen);
1628}
1629
1630void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
1631 NOTIMPLEMENTED();
1632}
1633
1634void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
1635 NOTIMPLEMENTED();
1636}
1637
[email protected]8a5e0ca2011-08-25 06:30:471638void RenderView::enterFullscreen() {
1639 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1640}
1641
1642void RenderView::exitFullscreen() {
1643 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1644}
1645
[email protected]48c9cf2d2009-09-16 16:47:521646void RenderView::setStatusText(const WebString& text) {
1647}
1648
[email protected]163f8242009-10-30 20:19:551649void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581650 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521651 if (latest_url == target_url_)
1652 return;
[email protected]163f8242009-10-30 20:19:551653
[email protected]48c9cf2d2009-09-16 16:47:521654 // Tell the browser to display a destination link.
1655 if (target_url_status_ == TARGET_INFLIGHT ||
1656 target_url_status_ == TARGET_PENDING) {
1657 // If we have a request in-flight, save the URL to be sent when we
1658 // receive an ACK to the in-flight request. We can happily overwrite
1659 // any existing pending sends.
1660 pending_target_url_ = latest_url;
1661 target_url_status_ = TARGET_PENDING;
1662 } else {
1663 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1664 target_url_ = latest_url;
1665 target_url_status_ = TARGET_INFLIGHT;
1666 }
1667}
1668
[email protected]882daa92009-11-05 16:31:311669void RenderView::StartNavStateSyncTimerIfNecessary() {
1670 int delay;
1671 if (send_content_state_immediately_)
1672 delay = 0;
1673 else if (is_hidden())
1674 delay = kDelaySecondsForContentStateSyncHidden;
1675 else
1676 delay = kDelaySecondsForContentStateSync;
1677
1678 if (nav_state_sync_timer_.IsRunning()) {
1679 // The timer is already running. If the delay of the timer maches the amount
1680 // we want to delay by, then return. Otherwise stop the timer so that it
1681 // gets started with the right delay.
1682 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1683 return;
1684 nav_state_sync_timer_.Stop();
1685 }
1686
[email protected]d323a172011-09-02 18:23:021687 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
1688 &RenderView::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311689}
1690
[email protected]163f8242009-10-30 20:19:551691void RenderView::setMouseOverURL(const WebURL& url) {
1692 mouse_over_url_ = GURL(url);
1693 UpdateTargetURL(mouse_over_url_, focus_url_);
1694}
1695
1696void RenderView::setKeyboardFocusURL(const WebURL& url) {
1697 focus_url_ = GURL(url);
1698 UpdateTargetURL(focus_url_, mouse_over_url_);
1699}
1700
[email protected]c27ae592010-03-18 15:24:411701void RenderView::startDragging(const WebDragData& data,
1702 WebDragOperationsMask mask,
1703 const WebImage& image,
1704 const WebPoint& imageOffset) {
1705#if WEBKIT_USING_SKIA
1706 SkBitmap bitmap(image.getSkBitmap());
1707#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331708 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411709#endif
1710
[email protected]59f4f2fa2011-03-23 01:00:551711 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521712 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411713 mask,
1714 bitmap,
1715 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521716}
1717
[email protected]28b92df2009-09-25 17:35:451718bool RenderView::acceptsLoadDrops() {
1719 return renderer_preferences_.can_accept_load_drops;
1720}
1721
[email protected]48c9cf2d2009-09-16 16:47:521722void RenderView::focusNext() {
1723 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1724}
1725
1726void RenderView::focusPrevious() {
1727 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1728}
1729
[email protected]08e9e132010-06-01 16:58:491730void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511731 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071732
[email protected]38b592902011-04-16 02:08:421733 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491734}
1735
[email protected]48c9cf2d2009-09-16 16:47:521736void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521737 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1738}
1739
1740int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001741 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521742}
1743
1744int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001745 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521746}
1747
[email protected]063afcb2011-09-29 07:54:321748void RenderView::postAccessibilityNotification(
1749 const WebAccessibilityObject& obj,
1750 WebAccessibilityNotification notification) {
1751 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1752}
1753
[email protected]c4e98902010-06-01 10:20:141754void RenderView::didUpdateInspectorSetting(const WebString& key,
1755 const WebString& value) {
1756 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1757 key.utf8(),
1758 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261759}
1760
[email protected]79dbc662009-09-04 05:42:511761// WebKit::WebWidgetClient ----------------------------------------------------
1762
[email protected]ea42e7782010-08-23 23:58:121763void RenderView::didFocus() {
1764 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1765 // we won't have to test for user gesture anymore and we can
1766 // move that code back to render_widget.cc
1767 if (webview() && webview()->mainFrame() &&
1768 webview()->mainFrame()->isProcessingUserGesture()) {
1769 Send(new ViewHostMsg_Focus(routing_id_));
1770 }
1771}
1772
1773void RenderView::didBlur() {
1774 // TODO(jcivelli): see TODO above in didFocus().
1775 if (webview() && webview()->mainFrame() &&
1776 webview()->mainFrame()->isProcessingUserGesture()) {
1777 Send(new ViewHostMsg_Blur(routing_id_));
1778 }
1779}
1780
initial.commit09911bf2008-07-26 23:55:291781// We are supposed to get a single call to Show for a newly created RenderView
1782// that was created via RenderView::CreateWebView. So, we wait until this
1783// point to dispatch the ShowView message.
1784//
1785// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281786// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291787//
[email protected]4873c7d2009-07-16 06:36:281788void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291789 DCHECK(!did_show_) << "received extraneous Show call";
1790 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1791
1792 if (did_show_)
1793 return;
1794 did_show_ = true;
1795
[email protected]6779aa12011-03-29 17:32:241796 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041797 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041798
[email protected]28295ec2009-10-16 05:34:331799 // Force new windows to a popup if they were not opened with a user gesture.
1800 if (!opened_by_user_gesture_) {
1801 // We exempt background tabs for compat with older versions of Chrome.
1802 // TODO(darin): This seems bogus. These should have a user gesture, so
1803 // we probably don't need this check.
1804 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1805 policy = WebKit::WebNavigationPolicyNewPopup;
1806 }
1807
initial.commit09911bf2008-07-26 23:55:291808 // NOTE: initial_pos_ may still have its default values at this point, but
1809 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1810 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281811 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1812 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291813 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241814 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291815}
1816
[email protected]4873c7d2009-07-16 06:36:281817void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:291818 DCHECK(did_show_) << "should already have shown the view";
1819
[email protected]c1f50aa2010-02-18 03:46:571820 // We must keep WebKit's shared timer running in this case in order to allow
1821 // showModalDialog to function properly.
1822 //
1823 // TODO(darin): WebKit should really be smarter about suppressing events and
1824 // timers so that we do not need to manage the shared timer in such a heavy
1825 // handed manner.
1826 //
[email protected]f1a29a02011-10-06 23:08:441827 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1828 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:571829
[email protected]12636df2009-09-28 22:32:211830 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291831}
1832
[email protected]3d9689372009-09-10 04:29:171833// WebKit::WebFrameClient -----------------------------------------------------
1834
[email protected]00152e92010-07-19 11:47:401835WebPlugin* RenderView::createPlugin(WebFrame* frame,
1836 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:551837 WebPlugin* plugin = NULL;
1838 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
1839 this, frame, params, &plugin)) {
1840 return plugin;
1841 }
1842
[email protected]a813c8e2011-10-08 01:34:111843 webkit::WebPluginInfo info;
1844 std::string mime_type;
1845 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
1846 params.mimeType.utf8(), &info, &mime_type);
1847 if (!found)
1848 return NULL;
1849
1850 WebPluginParams params_to_use = params;
1851 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:311852 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:171853}
1854
1855WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:561856 WebApplicationCacheHostImpl* appcache_host =
1857 WebApplicationCacheHostImpl::FromFrame(frame);
1858 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
[email protected]f1a29a02011-10-06 23:08:441859 return new WebWorkerProxy(client, RenderThreadImpl::current(), routing_id_,
[email protected]14396e92010-05-06 20:40:561860 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:171861}
1862
[email protected]9c00f002009-11-05 22:37:421863WebSharedWorker* RenderView::createSharedWorker(
1864 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371865 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421866
[email protected]30447b62009-11-13 01:13:371867 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511868 bool exists = false;
[email protected]30447b62009-11-13 01:13:371869 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511870 ViewHostMsg_CreateWorker_Params params;
1871 params.url = url;
1872 params.is_shared = true;
1873 params.name = name;
1874 params.document_id = document_id;
1875 params.render_view_route_id = routing_id_;
1876 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231877 params.parent_appcache_host_id = 0;
1878 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371879 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511880 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371881 if (url_mismatch) {
1882 return NULL;
1883 } else {
[email protected]f1a29a02011-10-06 23:08:441884 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:491885 document_id,
[email protected]6de0bcf2010-02-17 22:00:511886 exists,
[email protected]30447b62009-11-13 01:13:371887 route_id,
1888 routing_id_);
1889 }
[email protected]9c00f002009-11-05 22:37:421890}
1891
[email protected]3d9689372009-09-10 04:29:171892WebMediaPlayer* RenderView::createMediaPlayer(
1893 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441894 FOR_EACH_OBSERVER(
1895 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171896
[email protected]f78d1dfc2011-01-15 07:09:271897 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1898 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491899 scoped_ptr<media::FilterCollection> collection(
1900 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371901
[email protected]3d9689372009-09-10 04:29:171902 // Add in any custom filter factories first.
1903 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1904 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1905 // Add the chrome specific audio renderer.
[email protected]f7eb0a392011-07-12 10:19:511906 collection->AddAudioRenderer(new AudioRendererImpl());
[email protected]3d9689372009-09-10 04:29:171907 }
1908
[email protected]457d8342010-10-23 01:20:371909 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:311910 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
1911 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
1912 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:491913 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:311914 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:111915
[email protected]a8e24d522010-12-01 07:13:581916 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:271917 new webkit_glue::WebMediaPlayerImpl(client,
1918 collection.release(),
[email protected]ab2c4732011-07-20 19:57:401919 message_loop_factory.release(),
[email protected]090f7312011-08-05 23:26:401920 media_stream_impl_.get(),
1921 new RenderMediaLog()));
[email protected]79684282010-12-06 21:15:461922 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:581923 cmd_line->HasSwitch(switches::kSimpleDataSource),
1924 video_renderer)) {
1925 return NULL;
1926 }
1927 return result.release();
[email protected]3d9689372009-09-10 04:29:171928}
1929
[email protected]035545f2010-04-09 13:10:211930WebApplicationCacheHost* RenderView::createApplicationCacheHost(
1931 WebFrame* frame, WebApplicationCacheHostClient* client) {
1932 return new RendererWebApplicationCacheHostImpl(
1933 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:441934 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:211935}
1936
[email protected]8ff181072010-11-29 17:09:381937WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
1938 return &cookie_jar_;
1939}
1940
[email protected]5041f982010-08-11 21:40:451941void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511942 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451943}
1944
[email protected]3d9689372009-09-10 04:29:171945void RenderView::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511946 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171947}
1948
1949void RenderView::loadURLExternally(
1950 WebFrame* frame, const WebURLRequest& request,
1951 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:341952 loadURLExternally(frame, request, policy, WebString());
1953}
1954
1955void RenderView::loadURLExternally(
1956 WebFrame* frame, const WebURLRequest& request,
1957 WebNavigationPolicy policy,
1958 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:591959 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1960 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:341961 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
1962 suggested_name));
[email protected]efce17b2009-09-11 18:04:591963 } else {
[email protected]ae5184d62011-10-06 19:25:581964 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:591965 }
[email protected]3d9689372009-09-10 04:29:171966}
1967
1968WebNavigationPolicy RenderView::decidePolicyForNavigation(
1969 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221970 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:151971 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
1972 if (is_swapped_out_) {
1973 DCHECK(request.url() == GURL("about:swappedout"));
1974 return default_policy;
1975 }
1976
[email protected]3d9689372009-09-10 04:29:171977 // Webkit is asking whether to navigate to a new URL.
1978 // This is fine normally, except if we're showing UI from one security
1979 // context and they're trying to navigate to a different context.
1980 const GURL& url = request.url();
1981
[email protected]d19ea342011-04-20 20:31:131982 // A content initiated navigation may have originated from a link-click,
1983 // script, drag-n-drop operation, etc.
1984 bool is_content_initiated =
1985 NavigationState::FromDataSource(frame->provisionalDataSource())->
1986 is_content_initiated();
1987
[email protected]3d9689372009-09-10 04:29:171988 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:301989 // navigations.
[email protected]d19ea342011-04-20 20:31:131990 if (is_content_initiated &&
1991 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:451992 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:191993 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:231994 // Reset these counters as the RenderView could be reused for the next
1995 // navigation.
1996 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:231997 last_page_id_sent_to_browser_ = -1;
[email protected]ae5184d62011-10-06 19:25:581998 OpenURL(frame, url, referrer, default_policy);
[email protected]61c9f032010-03-31 23:04:191999 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172000 }
2001
[email protected]6101c342010-12-16 22:44:372002 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552003 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572004 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372005 // opening a new window). But we sometimes navigate to about:blank to clear a
2006 // tab, and we want to still allow that.
2007 //
[email protected]8f4da8c2011-02-09 19:49:572008 // Note: we do this only for GET requests because our mechanism for switching
2009 // processes only issues GET requests. In particular, POST requests don't
2010 // work, because this mechanism does not preserve form POST data. If it
2011 // becomes necessary to support process switching for POST requests, we will
2012 // need to send the request's httpBody data up to the browser process, and
2013 // issue a special POST navigation in WebKit (via
2014 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2015 // for examples of how to send the httpBody data.
2016 // Note2: We normally don't do this for browser-initiated navigations, since
2017 // it's pointless to tell the browser about navigations it gave us. But
2018 // we do potentially ask the browser to handle a redirect that was originally
2019 // initiated by the browser. See http://crbug.com/70943
2020 //
2021 // TODO(creis): Move this redirect check to the browser process to avoid
2022 // ping-ponging. See http://crbug.com/72380.
2023 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372024 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2025 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2026 bool send_referrer = false;
2027 bool should_fork =
[email protected]c09163a2011-02-15 00:05:552028 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172029 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372030 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112031
[email protected]e48869a2011-04-01 19:56:032032 if (!should_fork) {
2033 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362034 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032035 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362036 frame, url, is_content_initiated, is_initial_navigation,
2037 &send_referrer);
[email protected]6101c342010-12-16 22:44:372038 }
2039
2040 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112041 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]ae5184d62011-10-06 19:25:582042 OpenURL(frame, url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112043 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2044 }
[email protected]3d9689372009-09-10 04:29:172045 }
2046
[email protected]43763f982011-08-26 18:33:402047 // Use the frame's original request's URL rather than the document's URL for
2048 // this check. For a popup, the document's URL may become the opener window's
2049 // URL if the opener has called document.write. See http://crbug.com/93517.
2050 GURL old_url(frame->dataSource()->request().url());
2051
[email protected]3d9689372009-09-10 04:29:172052 // Detect when a page is "forking" a new tab that can be safely rendered in
2053 // its own process. This is done by sites like Gmail that try to open links
2054 // in new windows without script connections back to the original page. We
2055 // treat such cases as browser navigations (in which we will create a new
2056 // renderer for a cross-site navigation), rather than WebKit navigations.
2057 //
2058 // We use the following heuristic to decide whether to fork a new page in its
2059 // own process:
2060 // The parent page must open a new tab to about:blank, set the new tab's
2061 // window.opener to null, and then redirect the tab to a cross-site URL using
2062 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462063 //
2064 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2065 // (see below).
[email protected]3d9689372009-09-10 04:29:172066 bool is_fork =
2067 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582068 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172069 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522070 historyBackListCount() < 1 &&
2071 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172072 // The parent page must have set the child's window.opener to null before
2073 // redirecting to the desired URL.
2074 frame->opener() == NULL &&
2075 // Must be a top-level frame.
2076 frame->parent() == NULL &&
2077 // Must not have issued the request from this page.
2078 is_content_initiated &&
2079 // Must be targeted at the current tab.
2080 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2081 // Must be a JavaScript navigation, which appears as "other".
2082 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462083
2084 // Recognize if this navigation is from a link with rel=noreferrer and
2085 // target=_blank attributes, in which case the opener will be suppressed. If
2086 // so, it is safe to load cross-site pages in a separate process, so we
2087 // should let the browser handle it.
2088 bool is_noreferrer_and_blank_target =
2089 // Frame should be top level and not yet navigated.
2090 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412091 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462092 historyBackListCount() < 1 &&
2093 historyForwardListCount() < 1 &&
2094 // Links with rel=noreferrer will have no Referer field, and their
2095 // resulting frame will have its window.opener suppressed.
2096 // TODO(creis): should add a request.httpReferrer() method to help avoid
2097 // typos on the unusual spelling of Referer.
2098 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2099 opener_suppressed_ &&
2100 frame->opener() == NULL &&
2101 // Links with target=_blank will have no name.
2102 frame->name().isNull() &&
2103 // Another frame (with a non-empty creator) should have initiated the
2104 // request, targeted at this frame.
2105 !creator_url_.is_empty() &&
2106 is_content_initiated &&
2107 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2108 type == WebKit::WebNavigationTypeOther;
2109
2110 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172111 // Open the URL via the browser, not via WebKit.
[email protected]ae5184d62011-10-06 19:25:582112 OpenURL(frame, url, GURL(), default_policy);
[email protected]3d9689372009-09-10 04:29:172113 return WebKit::WebNavigationPolicyIgnore;
2114 }
2115
2116 return default_policy;
2117}
2118
[email protected]6069da8c2009-10-20 20:33:492119bool RenderView::canHandleRequest(
2120 WebFrame* frame, const WebURLRequest& request) {
2121 // We allow WebKit to think that everything can be handled even though
2122 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342123 return true;
2124}
2125
[email protected]6069da8c2009-10-20 20:33:492126WebURLError RenderView::cannotHandleRequestError(
2127 WebFrame* frame, const WebURLRequest& request) {
2128 NOTREACHED(); // Since we said we can handle all requests.
2129 return WebURLError();
2130}
2131
2132WebURLError RenderView::cancelledError(
2133 WebFrame* frame, const WebURLRequest& request) {
2134 WebURLError error;
2135 error.domain = WebString::fromUTF8(net::kErrorDomain);
2136 error.reason = net::ERR_ABORTED;
2137 error.unreachableURL = request.url();
2138 return error;
[email protected]7b7a7dc2009-10-19 02:23:342139}
2140
2141void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492142 WebFrame*, const WebURLError&) {
2143 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342144}
2145
[email protected]90eeddb2010-05-06 21:06:432146void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
2147 const WebKit::WebFormElement& form) {
2148 // Some login forms have onSubmit handlers that put a hash of the password
2149 // into a hidden field and then clear the password. (Issue 28910.)
2150 // This method gets called before any of those handlers run, so save away
2151 // a copy of the password in case it gets lost.
2152 NavigationState* navigation_state =
2153 NavigationState::FromDataSource(frame->dataSource());
2154 navigation_state->set_password_form_data(
2155 PasswordFormDomManager::CreatePasswordForm(form));
2156}
2157
[email protected]979c28b2009-11-07 01:30:482158void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:172159 NavigationState* navigation_state =
2160 NavigationState::FromDataSource(frame->provisionalDataSource());
2161
2162 if (navigation_state->transition_type() == PageTransition::LINK)
2163 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
2164
2165 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352166 WebSearchableFormData web_searchable_form_data(form);
2167 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
2168 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212169 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432170 PasswordForm* password_form_data =
2171 PasswordFormDomManager::CreatePasswordForm(form);
2172 navigation_state->set_password_form_data(password_form_data);
2173
[email protected]098c95cb2011-04-28 16:49:012174 // In order to save the password that the user actually typed and not one
2175 // that may have gotten transformed by the site prior to submit, recover it
2176 // from the form contents already stored by |willSendSubmitEvent| into the
2177 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2178 // which is what we're storing into now.)
2179 if (password_form_data) {
[email protected]90eeddb2010-05-06 21:06:432180 NavigationState* old_navigation_state =
2181 NavigationState::FromDataSource(frame->dataSource());
2182 if (old_navigation_state) {
2183 PasswordForm* old_form_data = old_navigation_state->password_form_data();
2184 if (old_form_data && old_form_data->action == password_form_data->action)
2185 password_form_data->password_value = old_form_data->password_value;
2186 }
2187 }
[email protected]3d9689372009-09-10 04:29:172188
[email protected]2a5b1732011-04-01 23:55:552189 FOR_EACH_OBSERVER(
2190 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172191}
2192
2193void RenderView::willPerformClientRedirect(
2194 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2195 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382196 FOR_EACH_OBSERVER(
2197 RenderViewObserver, observers_,
2198 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172199}
2200
2201void RenderView::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382202 FOR_EACH_OBSERVER(
2203 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172204}
2205
2206void RenderView::didCompleteClientRedirect(
2207 WebFrame* frame, const WebURL& from) {
2208 if (!frame->parent())
2209 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382210 FOR_EACH_OBSERVER(
2211 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172212}
2213
2214void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
2215 // The rest of RenderView assumes that a WebDataSource will always have a
2216 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:482217 bool content_initiated = !pending_navigation_state_.get();
2218 NavigationState* state = content_initiated ?
2219 NavigationState::CreateContentInitiated() :
2220 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:512221
[email protected]8a3125a712010-08-09 18:58:512222 // NavigationState::referred_by_prefetcher_ is true if we are
2223 // navigating from a page that used prefetching using a link on that
2224 // page. We are early enough in the request process here that we
2225 // can still see the NavigationState of the previous page and set
2226 // this value appropriately.
2227 // TODO(gavinp): catch the important case of navigation in a new
2228 // renderer process.
2229 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302230 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522231 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512232 const GURL referrer(
2233 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2234 if (!referrer.is_empty() &&
2235 NavigationState::FromDataSource(
2236 old_frame->dataSource())->was_prefetcher()) {
2237 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2238 WebDataSource* old_frame_ds = old_frame->dataSource();
2239 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
2240 state->set_was_referred_by_prefetcher(true);
2241 break;
2242 }
2243 }
2244 }
2245 }
2246 }
2247
[email protected]4c1b6f0b2010-02-07 16:38:182248 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522249 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512250 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182251 case WebURLRequest::UseProtocolCachePolicy: // normal load.
2252 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
2253 break;
2254 case WebURLRequest::ReloadIgnoringCacheData: // reload.
2255 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
2256 break;
2257 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
2258 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
2259 break;
2260 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
2261 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
2262 break;
2263 }
2264 }
[email protected]fa7b6b542009-11-03 05:02:302265
[email protected]16e923d2011-04-30 00:41:442266 ds->setExtraData(state);
[email protected]11f595b22011-04-11 14:48:502267
[email protected]946a0032011-03-31 18:42:282268 FOR_EACH_OBSERVER(
2269 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172270}
2271
2272void RenderView::didStartProvisionalLoad(WebFrame* frame) {
2273 WebDataSource* ds = frame->provisionalDataSource();
2274 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2275
[email protected]3d9689372009-09-10 04:29:172276 // Update the request time if WebKit has better knowledge of it.
2277 if (navigation_state->request_time().is_null()) {
2278 double event_time = ds->triggeringEventTime();
2279 if (event_time != 0.0)
2280 navigation_state->set_request_time(Time::FromDoubleT(event_time));
2281 }
2282
[email protected]05c8e502010-08-15 15:13:522283 // Start time is only set after request time.
2284 navigation_state->set_start_load_time(Time::Now());
2285
[email protected]3d9689372009-09-10 04:29:172286 bool is_top_most = !frame->parent();
2287 if (is_top_most) {
2288 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132289 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172290
2291 // Make sure redirect tracking state is clear for the new load.
2292 completed_client_redirect_src_ = GURL();
2293 } else if (frame->parent()->isLoading()) {
2294 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002295 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:172296 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
2297 }
2298
[email protected]28685da92011-02-07 21:49:172299 FOR_EACH_OBSERVER(
2300 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2301
[email protected]3d9689372009-09-10 04:29:172302 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592303 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262304 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172305}
2306
2307void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
2308 if (frame->parent())
2309 return;
2310 // Received a redirect on the main frame.
2311 WebDataSource* data_source = frame->provisionalDataSource();
2312 if (!data_source) {
2313 // Should only be invoked when we have a data source.
2314 NOTREACHED();
2315 return;
2316 }
2317 std::vector<GURL> redirects;
2318 GetRedirectChain(data_source, &redirects);
2319 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512320 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592321 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172322 }
2323}
2324
[email protected]40bd6582009-12-04 23:49:512325void RenderView::didFailProvisionalLoad(WebFrame* frame,
2326 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172327 // Notify the browser that we failed a provisional load with an error.
2328 //
2329 // Note: It is important this notification occur before DidStopLoading so the
2330 // SSL manager can react to the provisional load failure before being
2331 // notified the load stopped.
2332 //
2333 WebDataSource* ds = frame->provisionalDataSource();
2334 DCHECK(ds);
2335
2336 const WebURLRequest& failed_request = ds->request();
2337
[email protected]28685da92011-02-07 21:49:172338 FOR_EACH_OBSERVER(
2339 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2340
[email protected]3d9689372009-09-10 04:29:172341 bool show_repost_interstitial =
2342 (error.reason == net::ERR_CACHE_MISS &&
2343 EqualsASCII(failed_request.httpMethod(), "POST"));
2344 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:072345 routing_id_, frame->identifier(), !frame->parent(), error.reason,
2346 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:172347
2348 // Don't display an error page if this is simply a cancelled load. Aside
2349 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2350 if (error.reason == net::ERR_ABORTED)
2351 return;
2352
2353 // Make sure we never show errors in view source mode.
2354 frame->enableViewSourceMode(false);
2355
2356 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2357
2358 // If this is a failed back/forward/reload navigation, then we need to do a
2359 // 'replace' load. This is necessary to avoid messing up session history.
2360 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2361 // as session history is concerned.
2362 //
2363 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2364 // the page id.
2365 //
2366 bool replace =
2367 navigation_state->pending_page_id() != -1 ||
2368 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
2369
2370 // If we failed on a browser initiated request, then make sure that our error
2371 // page load is regarded as the same browser initiated request.
2372 if (!navigation_state->is_content_initiated()) {
2373 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
2374 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:002375 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:172376 navigation_state->transition_type(),
2377 navigation_state->request_time()));
2378 }
2379
2380 // Provide the user with a more helpful error page?
2381 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2382 return;
2383
2384 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082385 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172386}
2387
2388void RenderView::didReceiveDocumentData(
2389 WebFrame* frame, const char* data, size_t data_len,
2390 bool& prevent_default) {
2391 NavigationState* navigation_state =
2392 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092393 navigation_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172394}
2395
[email protected]40bd6582009-12-04 23:49:512396void RenderView::didCommitProvisionalLoad(WebFrame* frame,
2397 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:172398 NavigationState* navigation_state =
2399 NavigationState::FromDataSource(frame->dataSource());
2400
2401 navigation_state->set_commit_load_time(Time::Now());
2402 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202403 // When we perform a new navigation, we need to update the last committed
2404 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172405 UpdateSessionHistory(frame);
2406
2407 // We bump our Page ID to correspond with the new session history entry.
2408 page_id_ = next_page_id_++;
2409
[email protected]3cc72b12010-03-18 23:03:002410 // Advance our offset in session history, applying the length limit. There
2411 // is now no forward history.
2412 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102413 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2414 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002415 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032416 history_page_ids_.resize(history_list_length_, -1);
2417 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172418 } else {
2419 // Inspect the navigation_state on this frame to see if the navigation
2420 // corresponds to a session history navigation... Note: |frame| may or
2421 // may not be the toplevel frame, but for the case of capturing session
2422 // history, the first committed frame suffices. We keep track of whether
2423 // we've seen this commit before so that only capture session history once
2424 // per navigation.
2425 //
2426 // Note that we need to check if the page ID changed. In the case of a
2427 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2428 // previous URL and the current page ID, which would be wrong.
2429 if (navigation_state->pending_page_id() != -1 &&
2430 navigation_state->pending_page_id() != page_id_ &&
2431 !navigation_state->request_committed()) {
2432 // This is a successful session history navigation!
2433 UpdateSessionHistory(frame);
2434 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002435
2436 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032437
2438 // If the history list is valid, our list of page IDs should be correct.
2439 DCHECK(history_list_length_ <= 0 ||
2440 history_list_offset_ < 0 ||
2441 history_list_offset_ >= history_list_length_ ||
2442 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172443 }
2444 }
2445
[email protected]28685da92011-02-07 21:49:172446 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2447 DidCommitProvisionalLoad(frame, is_new_navigation));
2448
[email protected]3d9689372009-09-10 04:29:172449 // Remember that we've already processed this request, so we don't update
2450 // the session history again. We do this regardless of whether this is
2451 // a session history navigation, because if we attempted a session history
2452 // navigation without valid HistoryItem state, WebCore will think it is a
2453 // new navigation.
2454 navigation_state->set_request_committed(true);
2455
2456 UpdateURL(frame);
2457
2458 // If this committed load was initiated by a client redirect, we're
2459 // at the last stop now, so clear it.
2460 completed_client_redirect_src_ = GURL();
2461
2462 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272463 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172464}
2465
2466void RenderView::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102467 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2468 DidClearWindowObject(frame));
2469
[email protected]b6cb3a842011-06-24 18:28:412470 GURL frame_url = frame->document().url();
[email protected]c09163a2011-02-15 00:05:552471 if (BindingsPolicy::is_web_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:252472 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2473 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272474 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172475 }
[email protected]3d9689372009-09-10 04:29:172476}
2477
2478void RenderView::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172479 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412480 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252481 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272482 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172483 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2484 }
[email protected]e48869a2011-04-01 19:56:032485
2486 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2487 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172488}
2489
[email protected]a3bc4d12011-04-20 17:22:212490void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title,
2491 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462492 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172493
2494 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272495 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172496}
2497
[email protected]42054a252011-05-17 18:02:132498void RenderView::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
2499 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2500 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582501}
2502
[email protected]3d9689372009-09-10 04:29:172503void RenderView::didFinishDocumentLoad(WebFrame* frame) {
2504 WebDataSource* ds = frame->dataSource();
2505 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2506 DCHECK(navigation_state);
2507 navigation_state->set_finish_document_load_time(Time::Now());
2508
[email protected]622474d2010-11-04 09:21:082509 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172510
[email protected]28685da92011-02-07 21:49:172511 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2512 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172513
2514 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272515 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172516}
2517
2518void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082519 if (webview()->mainFrame() == frame) {
2520 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2521 page_id_));
2522 }
[email protected]3d9689372009-09-10 04:29:172523}
2524
2525void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172526 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172527}
2528
2529void RenderView::didFinishLoad(WebFrame* frame) {
2530 WebDataSource* ds = frame->dataSource();
2531 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2532 DCHECK(navigation_state);
2533 navigation_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412534
[email protected]676126f72011-01-15 00:03:512535 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172536
2537 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172538}
2539
[email protected]ccbe04e2010-03-17 17:58:432540void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172541 WebFrame* frame, bool is_new_navigation) {
2542 // If this was a reference fragment navigation that we initiated, then we
2543 // could end up having a non-null pending navigation state. We just need to
2544 // update the ExtraData on the datasource so that others who read the
2545 // ExtraData will get the new NavigationState. Similarly, if we did not
2546 // initiate this navigation, then we need to take care to reset any pre-
2547 // existing navigation state to a content-initiated navigation state.
2548 // DidCreateDataSource conveniently takes care of this for us.
2549 didCreateDataSource(frame, frame->dataSource());
2550
[email protected]af15bed2010-08-25 21:12:092551 NavigationState* new_state =
2552 NavigationState::FromDataSource(frame->dataSource());
2553 new_state->set_was_within_same_page(true);
2554
[email protected]3d9689372009-09-10 04:29:172555 didCommitProvisionalLoad(frame, is_new_navigation);
2556
[email protected]750fcf872011-08-03 23:10:472557 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2558 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172559}
2560
[email protected]476b6f82009-09-10 21:00:592561void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312562 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592563}
2564
[email protected]3d9689372009-09-10 04:29:172565void RenderView::assignIdentifierToRequest(
2566 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2567 // Ignore
2568}
2569
[email protected]d88bf0a2011-08-30 23:55:572570void RenderView::willSendRequest(WebFrame* frame,
2571 unsigned identifier,
2572 WebURLRequest& request,
2573 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302574 WebFrame* top_frame = frame->top();
2575 if (!top_frame)
2576 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512577 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2578 WebDataSource* top_data_source = top_frame->dataSource();
2579 WebDataSource* data_source =
2580 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222581
[email protected]78d5cfe2011-02-04 08:43:222582 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032583 GURL new_url;
2584 if (content::GetContentClient()->renderer()->WillSendRequest(
2585 frame, request_url, &new_url)) {
2586 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222587 }
2588
[email protected]d88bf0a2011-08-30 23:55:572589 PageTransition::Type transition_type = PageTransition::LINK;
2590 NavigationState* data_state = NavigationState::FromDataSource(data_source);
2591 if (data_state) {
2592 if (data_state->is_cache_policy_override_set())
2593 request.setCachePolicy(data_state->cache_policy_override());
2594 transition_type = data_state->transition_type();
[email protected]5e369672009-11-03 23:48:302595 }
[email protected]8a3125a712010-08-09 18:58:512596
[email protected]d88bf0a2011-08-30 23:55:572597 request.setExtraData(new RequestExtraData((frame == top_frame),
2598 frame->identifier(), transition_type));
2599
2600 NavigationState* top_data_state =
2601 NavigationState::FromDataSource(top_data_source);
2602 // TODO(gavinp): separate out prefetching and prerender field trials
2603 // if the rel=prerender rel type is sticking around.
2604 if (top_data_state &&
2605 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2606 request.targetType() == WebURLRequest::TargetIsPrerender))
2607 top_data_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512608
[email protected]3d9689372009-09-10 04:29:172609 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132610 request.setHasUserGesture(frame->isProcessingUserGesture());
2611
[email protected]0a8db0d2011-04-13 15:15:402612 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132613 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172614}
2615
2616void RenderView::didReceiveResponse(
2617 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492618
[email protected]3d9689372009-09-10 04:29:172619 // Only do this for responses that correspond to a provisional data source
2620 // of the top-most frame. If we have a provisional data source, then we
2621 // can't have any sub-resources yet, so we know that this response must
2622 // correspond to a frame load.
2623 if (!frame->provisionalDataSource() || frame->parent())
2624 return;
2625
2626 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082627 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172628 if (frame->isViewSourceModeEnabled())
2629 return;
2630
[email protected]65041fa2010-05-21 06:56:532631 NavigationState* navigation_state =
2632 NavigationState::FromDataSource(frame->provisionalDataSource());
2633 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:082634 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532635
[email protected]972ebdff2010-06-10 22:59:072636 // Record page load flags.
2637 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2638 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:572639 navigation_state->set_was_alternate_protocol_available(
2640 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:072641 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:082642 navigation_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092643 // Whether or not the http status code actually corresponds to an error is
2644 // only checked when the page is done loading, if |use_error_page| is
2645 // still true.
2646 navigation_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172647}
2648
2649void RenderView::didFinishResourceLoad(
2650 WebFrame* frame, unsigned identifier) {
2651 NavigationState* navigation_state =
2652 NavigationState::FromDataSource(frame->dataSource());
[email protected]06333afe2011-02-24 14:55:092653 if (!navigation_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172654 return;
2655
[email protected]7bfc153f2011-09-23 22:00:202656 // Do not show error page when DevTools is attached.
2657 if (devtools_agent_->IsAttached())
2658 return;
2659
[email protected]06333afe2011-02-24 14:55:092660 // Display error page, if appropriate.
[email protected]3f853a52010-09-13 19:15:082661 int http_status_code = navigation_state->http_status_code();
2662 if (http_status_code == 404) {
2663 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412664 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172665
[email protected]b6cb3a842011-06-24 18:28:412666 const GURL& error_page_url =
2667 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092668 if (error_page_url.is_valid()) {
2669 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472670 original_error.domain = "http";
2671 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412672 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172673
[email protected]06333afe2011-02-24 14:55:092674 navigation_state->set_alt_error_page_fetcher(
2675 new AltErrorPageResourceFetcher(
2676 error_page_url, frame, original_error,
2677 NewCallback(this, &RenderView::AltErrorPageFinished)));
2678 return;
2679 }
2680 }
[email protected]3d9689372009-09-10 04:29:172681
[email protected]e6a2ce52011-10-08 01:40:132682 std::string error_domain;
2683 if (content::GetContentClient()->renderer()->HasErrorPage(
2684 http_status_code, &error_domain)) {
2685 WebURLError error;
2686 error.unreachableURL = frame->document().url();
2687 error.domain = WebString::fromUTF8(error_domain);
2688 error.reason = http_status_code;
2689
2690 LoadNavigationErrorPage(
2691 frame, frame->dataSource()->request(), error, std::string(), true);
2692 }
[email protected]3d9689372009-09-10 04:29:172693}
2694
2695void RenderView::didFailResourceLoad(
2696 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2697 // Ignore
2698}
2699
2700void RenderView::didLoadResourceFromMemoryCache(
2701 WebFrame* frame, const WebURLRequest& request,
2702 const WebURLResponse& response) {
2703 // Let the browser know we loaded a resource from the memory cache. This
2704 // message is needed to display the correct SSL indicators.
2705 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2706 routing_id_,
2707 request.url(),
[email protected]70435962011-08-02 20:13:282708 response.securityInfo(),
2709 request.httpMethod().utf8(),
2710 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172711}
2712
[email protected]6069da8c2009-10-20 20:33:492713void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292714 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2715}
2716
[email protected]92771112011-01-20 00:13:022717void RenderView::didRunInsecureContent(
2718 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292719 Send(new ViewHostMsg_DidRunInsecureContent(
2720 routing_id_,
[email protected]92771112011-01-20 00:13:022721 origin.toString().utf8(),
2722 target));
[email protected]e3d60e5d2009-09-25 21:08:292723}
2724
[email protected]b00ba702011-08-17 01:41:032725void RenderView::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
2726 webkit_glue::WebURLLoaderImpl* loader_impl =
2727 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2728 loader_impl->UpdateRoutingId(routing_id_);
2729}
2730
[email protected]3d9689372009-09-10 04:29:172731void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
2732 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2733}
2734
[email protected]5bc10932011-09-21 21:03:302735void RenderView::didCreateScriptContext(WebFrame* frame,
2736 v8::Handle<v8::Context> context,
2737 int world_id) {
2738 content::GetContentClient()->renderer()->DidCreateScriptContext(
2739 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282740}
2741
[email protected]5bc10932011-09-21 21:03:302742void RenderView::willReleaseScriptContext(WebFrame* frame,
2743 v8::Handle<v8::Context> context,
2744 int world_id) {
2745 content::GetContentClient()->renderer()->WillReleaseScriptContext(
2746 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282747}
2748
[email protected]d812fd12011-05-27 23:05:072749void RenderView::didUpdateLayout(WebFrame* frame) {
2750 // We don't always want to set up a timer, only if we've been put in that
2751 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172752 // message.
[email protected]705243f2010-05-05 19:58:072753 if (!send_preferred_size_changes_ || !webview())
2754 return;
[email protected]dfca5acf2010-03-22 03:28:432755
[email protected]d812fd12011-05-27 23:05:072756 if (check_preferred_size_timer_.IsRunning())
2757 return;
[email protected]d323a172011-09-02 18:23:022758 check_preferred_size_timer_.Start(FROM_HERE,
2759 TimeDelta::FromMilliseconds(0), this,
[email protected]d812fd12011-05-27 23:05:072760 &RenderView::CheckPreferredSize);
2761}
2762
2763void RenderView::CheckPreferredSize() {
2764 // We don't always want to send the change messages over IPC, only if we've
2765 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2766 // message.
2767 if (!send_preferred_size_changes_ || !webview())
2768 return;
2769
[email protected]705243f2010-05-05 19:58:072770 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2771 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532772
2773 // In the presence of zoom, these sizes are still reported as if unzoomed,
2774 // so we need to adjust.
2775 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2776 size.set_width(static_cast<int>(size.width() * zoom_factor));
2777 size.set_height(static_cast<int>(size.height() * zoom_factor));
2778
[email protected]705243f2010-05-05 19:58:072779 if (size == preferred_size_)
2780 return;
[email protected]c27324b2009-11-19 22:44:292781
[email protected]705243f2010-05-05 19:58:072782 preferred_size_ = size;
2783 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2784 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172785}
2786
[email protected]dd6afca2011-08-13 03:44:312787void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
2788 if (webview()->mainFrame() != frame)
2789 return;
2790 WebView* frameView = frame->view();
2791 if (!frameView)
2792 return;
2793
2794 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
2795 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
2796
2797 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
2798 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
2799 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
2800 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
2801
2802 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
2803 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
2804 }
2805}
2806
2807void RenderView::UpdateScrollState(WebFrame* frame) {
2808 WebSize offset = frame->scrollOffset();
2809 WebSize minimum_offset = frame->minimumScrollOffset();
2810 WebSize maximum_offset = frame->maximumScrollOffset();
2811
2812 bool is_pinned_to_left = offset.width <= minimum_offset.width;
2813 bool is_pinned_to_right = offset.width >= maximum_offset.width;
2814
2815 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
2816 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
2817 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
2818 routing_id_, is_pinned_to_left, is_pinned_to_right));
2819
2820 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
2821 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
2822 }
2823}
2824
[email protected]143dcd592009-11-06 21:33:492825void RenderView::didChangeScrollOffset(WebFrame* frame) {
2826 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:312827
2828 if (webview()->mainFrame() == frame)
2829 UpdateScrollState(frame);
2830}
2831
2832void RenderView::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
2833 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:492834}
2835
[email protected]8922e1f2009-10-03 05:01:262836void RenderView::reportFindInPageMatchCount(int request_id, int count,
2837 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112838 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2839 if (!count)
2840 active_match_ordinal = 0;
2841
2842 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2843 routing_id_,
2844 request_id,
2845 count,
2846 gfx::Rect(),
2847 active_match_ordinal,
2848 final_update);
2849
[email protected]8922e1f2009-10-03 05:01:262850 // If we have a message that has been queued up, then we should just replace
2851 // it. The ACK from the browser will make sure it gets sent when the browser
2852 // wants it.
2853 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262854 queued_find_reply_message_.reset(msg);
2855 } else {
2856 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112857 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262858 }
2859}
2860
2861void RenderView::reportFindInPageSelection(int request_id,
2862 int active_match_ordinal,
2863 const WebRect& selection_rect) {
2864 // Send the search result over to the browser process.
2865 Send(new ViewHostMsg_Find_Reply(routing_id_,
2866 request_id,
2867 -1,
2868 selection_rect,
2869 active_match_ordinal,
2870 false));
2871}
2872
[email protected]2b06a992010-08-21 05:48:222873void RenderView::openFileSystem(
2874 WebFrame* frame,
2875 WebFileSystem::Type type,
2876 long long size,
[email protected]d275d7a2010-11-03 01:34:492877 bool create,
[email protected]2b06a992010-08-21 05:48:222878 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082879 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222880
[email protected]b6cb3a842011-06-24 18:28:412881 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]c5a272d2010-09-27 18:37:082882 if (origin.isEmpty()) {
2883 // Uninitialized document?
2884 callbacks->didFail(WebKit::WebFileErrorAbort);
2885 return;
2886 }
[email protected]2b06a992010-08-21 05:48:222887
[email protected]c5a272d2010-09-27 18:37:082888 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2889 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492890 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222891}
2892
[email protected]10e5cf12011-04-13 04:10:402893void RenderView::queryStorageUsageAndQuota(
2894 WebFrame* frame,
2895 WebStorageQuotaType type,
2896 WebStorageQuotaCallbacks* callbacks) {
2897 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412898 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402899 if (origin.isEmpty()) {
2900 // Uninitialized document?
2901 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2902 return;
2903 }
2904 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:532905 GURL(origin.toString()),
2906 static_cast<quota::StorageType>(type),
2907 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402908}
2909
2910void RenderView::requestStorageQuota(
2911 WebFrame* frame,
2912 WebStorageQuotaType type,
2913 unsigned long long requested_size,
2914 WebStorageQuotaCallbacks* callbacks) {
2915 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:412916 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]10e5cf12011-04-13 04:10:402917 if (origin.isEmpty()) {
2918 // Uninitialized document?
2919 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
2920 return;
2921 }
2922 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:532923 routing_id(), GURL(origin.toString()),
2924 static_cast<quota::StorageType>(type), requested_size,
2925 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:402926}
2927
[email protected]18d5be92011-07-25 18:00:192928// WebKit::WebPageSerializerClient implementation ------------------------------
2929
2930void RenderView::didSerializeDataForFrame(
2931 const WebURL& frame_url,
2932 const WebCString& data,
2933 WebPageSerializerClient::PageSerializationStatus status) {
2934 Send(new ViewHostMsg_SendSerializedHtmlData(
2935 routing_id(),
2936 frame_url,
2937 data.data(),
2938 static_cast<int32>(status)));
2939}
2940
[email protected]a2ef54c2011-10-10 16:20:312941// content::RenderView implementation ------------------------------------------
2942
2943bool RenderView::Send(IPC::Message* message) {
2944 return RenderWidget::Send(message);
2945}
2946
2947int RenderView::GetRoutingId() const {
2948 return routing_id_;
2949}
2950
2951int RenderView::GetPageId() {
2952 return page_id_;
2953}
2954
2955gfx::Size RenderView::GetSize() {
2956 return size();
2957}
2958
2959gfx::NativeViewId RenderView::GetHostWindow() {
2960 return host_window();
2961}
2962
2963WebPreferences& RenderView::GetWebkitPreferences() {
2964 return webkit_preferences_;
2965}
2966
2967WebKit::WebView* RenderView::GetWebView() {
2968 return webview();
2969}
2970
2971WebKit::WebNode RenderView::GetFocusedNode() const {
2972 if (!webview())
2973 return WebNode();
2974 WebFrame* focused_frame = webview()->focusedFrame();
2975 if (focused_frame) {
2976 WebDocument doc = focused_frame->document();
2977 if (!doc.isNull())
2978 return doc.focusedNode();
2979 }
2980
2981 return WebNode();
2982}
2983
2984WebKit::WebNode RenderView::GetContextMenuNode() const {
2985 return context_menu_node_;
2986}
2987
2988bool RenderView::IsEditableNode(const WebKit::WebNode& node) {
2989 bool is_editable_node = false;
2990 if (!node.isNull()) {
2991 if (node.isContentEditable()) {
2992 is_editable_node = true;
2993 } else if (node.isElementNode()) {
2994 is_editable_node =
2995 node.toConst<WebElement>().isTextFormControlElement();
2996 }
2997 }
2998 return is_editable_node;
2999}
3000
3001WebKit::WebPlugin* RenderView::CreatePlugin(
3002 WebKit::WebFrame* frame,
3003 const webkit::WebPluginInfo& info,
3004 const WebKit::WebPluginParams& params) {
3005 bool pepper_plugin_was_registered = false;
3006 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3007 pepper_delegate_.CreatePepperPluginModule(info,
3008 &pepper_plugin_was_registered));
3009 if (pepper_plugin_was_registered) {
3010 if (!pepper_module)
3011 return NULL;
3012 return new webkit::ppapi::WebPluginImpl(
3013 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3014 }
3015
3016 return new webkit::npapi::WebPluginImpl(
3017 frame, params, info.path, AsWeakPtr());
3018}
3019
3020void RenderView::EvaluateScript(const string16& frame_xpath,
3021 const string16& jscript,
3022 int id,
3023 bool notify_result) {
3024 v8::Handle<v8::Value> result;
3025 WebFrame* web_frame = GetChildFrame(frame_xpath);
3026 if (web_frame)
3027 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3028 if (notify_result) {
3029 ListValue list;
3030 if (!result.IsEmpty() && web_frame) {
3031 v8::HandleScope handle_scope;
3032 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3033 v8::Context::Scope context_scope(context);
3034 V8ValueConverterImpl converter;
3035 converter.set_allow_date(true);
3036 converter.set_allow_regexp(true);
3037 list.Set(0, converter.FromV8Value(result, context));
3038 } else {
3039 list.Set(0, Value::CreateNullValue());
3040 }
3041 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3042 }
3043}
3044
3045bool RenderView::ShouldDisplayScrollbars(int width, int height) const {
3046 return (!send_preferred_size_changes_ ||
3047 (disable_scrollbars_size_limit_.width() <= width ||
3048 disable_scrollbars_size_limit_.height() <= height));
3049}
3050
3051int RenderView::GetEnabledBindings() {
3052 return enabled_bindings_;
3053}
3054
3055void RenderView::SetEnabledBindings(int enabled_bindings) {
3056 enabled_bindings_ = enabled_bindings;
3057}
3058
3059bool RenderView::GetContentStateImmediately() {
3060 return send_content_state_immediately_;
3061}
3062
3063float RenderView::GetFilteredTimePerFrame() {
3064 return filtered_time_per_frame();
3065}
3066
3067void RenderView::ShowContextMenu(WebKit::WebFrame* frame,
3068 const WebKit::WebContextMenuData& data) {
3069 showContextMenu(frame, data);
3070}
3071
3072WebKit::WebPageVisibilityState RenderView::GetVisibilityState() const {
3073 return visibilityState();
3074}
3075
3076void RenderView::RunModalAlertDialog(WebKit::WebFrame* frame,
3077 const WebKit::WebString& message) {
3078 return runModalAlertDialog(frame, message);
3079}
3080
3081void RenderView::LoadURLExternally(
3082 WebKit::WebFrame* frame,
3083 const WebKit::WebURLRequest& request,
3084 WebKit::WebNavigationPolicy policy) {
3085 loadURLExternally(frame, request, policy);
3086}
3087
3088// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513089
[email protected]191eb3f72010-12-21 06:27:503090webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533091 const FilePath& file_path,
3092 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593093 if (!PluginChannelHost::IsListening())
3094 return NULL;
3095
[email protected]00c39612010-03-06 02:53:283096 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463097 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323098#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223099 return webkit::npapi::WebPluginDelegateImpl::Create(
3100 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093101#else
[email protected]7398dcc2011-09-06 21:40:323102 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223103 NOTIMPLEMENTED();
3104 return NULL;
[email protected]7b6616f2010-01-14 18:07:553105#endif
[email protected]f103ab72009-09-02 17:10:593106 }
3107
[email protected]4e0616e2010-05-28 14:55:533108 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593109}
3110
3111void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033112#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273113 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593114#endif
3115}
3116
3117void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033118#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273119 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593120#endif
3121 CleanupWindowInPluginMoves(window);
3122}
3123
[email protected]191eb3f72010-12-21 06:27:503124void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593125 SchedulePluginMove(move);
3126}
3127
3128void RenderView::DidStartLoadingForPlugin() {
3129 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523130 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593131}
3132
3133void RenderView::DidStopLoadingForPlugin() {
3134 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523135 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593136}
3137
[email protected]b921cfd22010-02-25 16:57:513138WebCookieJar* RenderView::GetCookieJar() {
3139 return &cookie_jar_;
3140}
3141
initial.commit09911bf2008-07-26 23:55:293142void RenderView::SyncNavigationState() {
3143 if (!webview())
3144 return;
3145
[email protected]26aa0482009-09-30 16:55:273146 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173147 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293148 return;
[email protected]ca948a22009-06-25 19:36:173149
3150 Send(new ViewHostMsg_UpdateState(
3151 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293152}
3153
[email protected]b781ff282011-08-20 06:19:363154void RenderView::SyncSelectionIfRequired() {
3155 WebFrame* frame = webview()->focusedFrame();
3156 const std::string& text = frame->selectionAsText().utf8();
3157
3158 ui::Range range(ui::Range::InvalidRange());
3159 size_t location, length;
3160 if (webview()->caretOrSelectionRange(&location, &length)) {
3161 range.set_start(location);
3162 range.set_end(location + length);
3163 }
3164
3165 WebPoint start, end;
3166 webview()->selectionRange(start, end);
3167
3168 RenderViewSelection this_selection(text, range, start, end);
3169
3170 // Sometimes we get repeated didChangeSelection calls from webkit when
3171 // the selection hasn't actually changed. We don't want to report these
3172 // because it will cause us to continually claim the X clipboard.
3173 if (this_selection.Equals(last_selection_))
3174 return;
3175 last_selection_ = this_selection;
3176
3177 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, range,
3178 start, end));
3179}
3180
[email protected]7ccddb8c2009-08-04 17:36:553181GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:293182 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553183 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293184 // If the URL that failed was secure, then the embedding web page was not
3185 // expecting a network attacker to be able to manipulate its contents. As
3186 // we fetch alternate error pages over HTTP, we would be allowing a network
3187 // attacker to manipulate the contents of the response if we tried to use
3188 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153189 return GURL();
initial.commit09911bf2008-07-26 23:55:293190 }
3191
3192 // Grab the base URL from the browser process.
3193 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153194 return GURL();
initial.commit09911bf2008-07-26 23:55:293195
3196 // Strip query params from the failed URL.
3197 GURL::Replacements remove_params;
3198 remove_params.ClearUsername();
3199 remove_params.ClearPassword();
3200 remove_params.ClearQuery();
3201 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553202 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503203 std::string spec_to_send = url_to_send.spec();
3204 // Notify link doctor of the url truncation by sending of "?" at the end.
3205 if (failed_url.has_query())
3206 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293207
3208 // Construct the query params to send to link doctor.
3209 std::string params(alternate_error_page_url_.query());
3210 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023211 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293212 params.append("&sourceid=chrome");
3213 params.append("&error=");
3214 switch (error_type) {
3215 case DNS_ERROR:
3216 params.append("dnserror");
3217 break;
3218
3219 case HTTP_404:
3220 params.append("http404");
3221 break;
3222
[email protected]5df266ac2008-10-15 19:50:133223 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333224 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133225 break;
3226
initial.commit09911bf2008-07-26 23:55:293227 default:
3228 NOTREACHED() << "unknown ErrorPageType";
3229 }
3230
3231 // OK, build the final url to return.
3232 GURL::Replacements link_doctor_params;
3233 link_doctor_params.SetQueryStr(params);
3234 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3235 return url;
3236}
3237
[email protected]57b9396c2011-10-07 19:11:593238GURL RenderView::GetOpenerUrl() const {
3239 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3240 return GURL();
3241 else
3242 return creator_url_;
3243}
3244
[email protected]c50008512011-02-03 01:17:273245WebUIBindings* RenderView::GetWebUIBindings() {
3246 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313247 web_ui_bindings_.reset(new WebUIBindings(
3248 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463249 }
[email protected]c50008512011-02-03 01:17:273250 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463251}
3252
[email protected]0fdbf8c2010-07-08 20:33:013253WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
3254 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493255}
3256
[email protected]6069da8c2009-10-20 20:33:493257void RenderView::OnFind(int request_id, const string16& search_text,
3258 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273259 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493260
[email protected]872542532011-06-23 00:43:163261 // Check if the plugin still exists in the document.
3262 if (main_frame->document().isPluginDocument() &&
3263 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493264 if (options.findNext) {
3265 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013266 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493267 } else {
[email protected]afdbd142010-07-10 08:01:233268 if (GetWebPluginFromPluginDocument()->startFind(
3269 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493270 } else {
[email protected]e7c58a32010-08-13 19:47:113271 // Send "no results".
3272 Send(new ViewHostMsg_Find_Reply(routing_id_,
3273 request_id,
3274 0,
3275 gfx::Rect(),
3276 0,
3277 true));
[email protected]24a7f3c2010-03-25 08:26:493278 }
3279 }
3280 return;
3281 }
3282
[email protected]b4bb2502009-10-01 22:35:273283 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273284 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293285 WebFrame* search_frame = focused_frame; // start searching focused frame.
3286
3287 bool multi_frame = (frame_after_main != main_frame);
3288
3289 // If we have multiple frames, we don't want to wrap the search within the
3290 // frame, so we check here if we only have main_frame in the chain.
3291 bool wrap_within_frame = !multi_frame;
3292
[email protected]b3f2b912009-04-09 16:18:523293 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293294 bool result = false;
3295
[email protected]7830da3e2009-11-06 16:27:263296 // If something is selected when we start searching it means we cannot just
3297 // increment the current match ordinal; we need to re-generate it.
3298 WebRange current_selection = focused_frame->selectionRange();
3299
initial.commit09911bf2008-07-26 23:55:293300 do {
[email protected]dd7daa82009-08-10 05:46:453301 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593302 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293303
3304 if (!result) {
3305 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223306 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293307
3308 // Find the next frame, but skip the invisible ones.
3309 do {
3310 // What is the next frame to search? (we might be going backwards). Note
3311 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593312 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273313 search_frame->traverseNext(true) :
3314 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453315 } while (!search_frame->hasVisibleContent() &&
3316 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293317
[email protected]884db412008-11-24 23:46:503318 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223319 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293320
3321 // If we have multiple frames and we have wrapped back around to the
3322 // focused frame, we need to search it once more allowing wrap within
3323 // the frame, otherwise it will report 'no match' if the focused frame has
3324 // reported matches, but no frames after the focused_frame contain a
3325 // match for the search word(s).
3326 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453327 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593328 request_id, search_text, options, true, // Force wrapping.
3329 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293330 }
3331 }
3332
[email protected]26aa0482009-09-30 16:55:273333 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293334 } while (!result && search_frame != focused_frame);
3335
[email protected]7830da3e2009-11-06 16:27:263336 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293337 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453338 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293339 } else {
3340 // If nothing is found, set result to "0 of 0", otherwise, set it to
3341 // "-1 of 1" to indicate that we found at least one item, but we don't know
3342 // yet what is active.
3343 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3344 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293345
[email protected]4f3dc372009-02-24 00:10:293346 // If we find no matches then this will be our last status update.
3347 // Otherwise the scoping effort will send more results.
3348 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293349
[email protected]4f3dc372009-02-24 00:10:293350 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403351 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593352 request_id,
[email protected]4f3dc372009-02-24 00:10:293353 match_count,
3354 selection_rect,
3355 ordinal,
3356 final_status_update));
initial.commit09911bf2008-07-26 23:55:293357
initial.commit09911bf2008-07-26 23:55:293358 // Scoping effort begins, starting with the mainframe.
3359 search_frame = main_frame;
3360
[email protected]dd7daa82009-08-10 05:46:453361 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293362
3363 do {
3364 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453365 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293366
3367 // We don't start another scoping effort unless at least one match has
3368 // been found.
3369 if (result) {
3370 // Start new scoping request. If the scoping function determines that it
3371 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453372 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593373 search_text,
3374 options,
initial.commit09911bf2008-07-26 23:55:293375 true); // reset the tickmarks
3376 }
3377
3378 // Iterate to the next frame. The frame will not necessarily scope, for
3379 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273380 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293381 } while (search_frame != main_frame);
3382 }
3383}
3384
[email protected]24a7f3c2010-03-25 08:26:493385void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
3386 WebView* view = webview();
3387 if (!view)
3388 return;
3389
3390 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163391 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013392 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493393 return;
3394 }
3395
3396 bool clear_selection =
3397 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3398 if (clear_selection)
3399 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3400
3401 WebFrame* frame = view->mainFrame();
3402 while (frame) {
3403 frame->stopFinding(clear_selection);
3404 frame = frame->traverseNext(false);
3405 }
3406
3407 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3408 WebFrame* focused_frame = view->focusedFrame();
3409 if (focused_frame) {
3410 WebDocument doc = focused_frame->document();
3411 if (!doc.isNull()) {
3412 WebNode node = doc.focusedNode();
3413 if (!node.isNull())
3414 node.simulateClick();
3415 }
3416 }
3417 }
3418}
3419
3420void RenderView::OnFindReplyAck() {
3421 // Check if there is any queued up request waiting to be sent.
3422 if (queued_find_reply_message_.get()) {
3423 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423424 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493425 }
3426}
3427
[email protected]40bd6582009-12-04 23:49:513428void RenderView::OnZoom(PageZoom::Function function) {
3429 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3430 return;
3431
[email protected]258d31122010-05-09 10:59:413432 webview()->hidePopups();
[email protected]c514d6372011-08-16 22:54:443433#if !defined(TOUCH_UI)
[email protected]b75b8292010-10-01 07:28:253434 double old_zoom_level = webview()->zoomLevel();
3435 double zoom_level;
3436 if (function == PageZoom::RESET) {
3437 zoom_level = 0;
3438 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3439 // Previous zoom level is a whole number, so just increment/decrement.
3440 zoom_level = old_zoom_level + function;
3441 } else {
3442 // Either the user hit the zoom factor limit and thus the zoom level is now
3443 // not a whole number, or a plugin changed it to a custom value. We want
3444 // to go to the next whole number so that the user can always get back to
3445 // 100% with the keyboard/menu.
3446 if ((old_zoom_level > 1 && function > 0) ||
3447 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:453448 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:253449 } else {
3450 // We're going towards 100%, so first go to the next whole number.
3451 zoom_level = static_cast<int>(old_zoom_level);
3452 }
3453 }
[email protected]b75b8292010-10-01 07:28:253454 webview()->setZoomLevel(false, zoom_level);
[email protected]c514d6372011-08-16 22:54:443455#else
3456 double old_page_scale_factor = webview()->pageScaleFactor();
3457 double page_scale_factor;
3458 if (function == PageZoom::RESET) {
3459 page_scale_factor = 1.0;
3460 } else {
3461 page_scale_factor = old_page_scale_factor +
3462 (function > 0 ? kScalingIncrement : -kScalingIncrement);
3463 }
3464 webview()->scalePage(page_scale_factor, WebPoint(0, 0));
3465#endif
[email protected]b75b8292010-10-01 07:28:253466 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:513467}
3468
[email protected]d0b8d092010-10-25 04:05:173469void RenderView::OnSetZoomLevel(double zoom_level) {
3470 // Don't set zoom level for full-page plugin since they don't use the same
3471 // zoom settings.
3472 if (webview()->mainFrame()->document().isPluginDocument())
3473 return;
3474
3475 webview()->hidePopups();
3476 webview()->setZoomLevel(false, zoom_level);
3477 zoomLevelChanged();
3478}
3479
[email protected]9d797f32010-04-23 07:17:543480void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:253481 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543482 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293483}
3484
[email protected]8a5e0ca2011-08-25 06:30:473485void RenderView::OnExitFullscreen() {
3486 webview()->exitFullscreen();
3487}
3488
[email protected]41fc0322009-09-04 22:23:403489void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273490 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293491}
3492
[email protected]a697f4c2009-09-14 22:30:183493void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273494 WebString no_encoding;
3495 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183496}
3497
[email protected]318bf5802011-08-08 17:12:413498WebFrame* RenderView::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453499 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273500 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453501
3502 // xpath string can represent a frame deep down the tree (across multiple
3503 // frame DOMs).
3504 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3505 // should break into 2 xpaths
3506 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413507 std::vector<string16> xpaths;
3508 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453509
[email protected]26aa0482009-09-30 16:55:273510 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413511 for (std::vector<string16>::const_iterator i = xpaths.begin();
3512 frame && i != xpaths.end(); ++i) {
3513 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293514 }
3515
[email protected]dd7daa82009-08-10 05:46:453516 return frame;
initial.commit09911bf2008-07-26 23:55:293517}
3518
[email protected]882b7b22010-10-05 03:34:533519void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
3520 const string16& jscript,
3521 int id,
3522 bool notify_result) {
3523 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293524}
3525
[email protected]318bf5802011-08-08 17:12:413526void RenderView::OnCSSInsertRequest(const string16& frame_xpath,
[email protected]01cf589c2011-07-28 18:04:033527 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413528 WebFrame* frame = GetChildFrame(frame_xpath);
3529 if (!frame)
[email protected]216813952011-05-19 22:21:263530 return;
[email protected]ae461542009-06-19 19:03:413531
[email protected]01cf589c2011-07-28 18:04:033532 frame->document().insertUserStyleSheet(
3533 WebString::fromUTF8(css),
3534 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483535}
3536
[email protected]81e63782009-02-27 19:35:093537void RenderView::OnAllowBindings(int enabled_bindings_flags) {
3538 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293539}
3540
[email protected]d0980792011-02-13 19:41:403541void RenderView::OnSetWebUIProperty(const std::string& name,
initial.commit09911bf2008-07-26 23:55:293542 const std::string& value) {
[email protected]c09163a2011-02-15 00:05:553543 DCHECK(BindingsPolicy::is_web_ui_enabled(enabled_bindings_));
[email protected]c50008512011-02-03 01:17:273544 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293545}
3546
3547void RenderView::OnReservePageIDRange(int size_of_range) {
3548 next_page_id_ += size_of_range + 1;
3549}
3550
[email protected]59f4f2fa2011-03-23 01:00:553551void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
3552 const gfx::Point& client_point,
3553 const gfx::Point& screen_point,
3554 WebDragOperationsMask ops) {
3555 WebDragOperation operation = webview()->dragTargetDragEnter(
3556 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553557 client_point,
3558 screen_point,
3559 ops);
3560
3561 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3562}
3563
3564void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
3565 const gfx::Point& screen_point,
3566 WebDragOperationsMask ops) {
3567 WebDragOperation operation = webview()->dragTargetDragOver(
3568 client_point,
3569 screen_point,
3570 ops);
3571
3572 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3573}
3574
3575void RenderView::OnDragTargetDragLeave() {
3576 webview()->dragTargetDragLeave();
3577}
3578
3579void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
3580 const gfx::Point& screen_point) {
3581 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573582
3583 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553584}
3585
[email protected]e80c73b2009-04-07 23:24:583586void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3587 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:253588 bool ended,
3589 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033590 if (ended) {
[email protected]26aa0482009-09-30 16:55:273591 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203592 } else {
3593 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033594 }
initial.commit09911bf2008-07-26 23:55:293595}
3596
3597void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273598 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293599}
3600
initial.commit09911bf2008-07-26 23:55:293601void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593602 webkit_preferences_ = prefs;
3603 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293604}
3605
[email protected]08bb1e722011-07-30 19:13:043606void RenderView::OnUpdateRemoteAccessClientFirewallTraversal(
3607 const std::string& policy) {
3608 pepper_delegate_.PublishPolicy(policy);
3609}
3610
initial.commit09911bf2008-07-26 23:55:293611void RenderView::OnSetAltErrorPageURL(const GURL& url) {
3612 alternate_error_page_url_ = url;
3613}
3614
[email protected]b29aa74b2011-01-31 21:41:083615void RenderView::OnCustomContextMenuAction(
3616 const webkit_glue::CustomContextMenuContext& custom_context,
3617 unsigned action) {
3618 if (custom_context.is_pepper_menu)
3619 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3620 else
3621 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:583622 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3623 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:333624}
3625
[email protected]600ea402011-04-12 00:01:513626void RenderView::OnEnumerateDirectoryResponse(
3627 int id,
3628 const std::vector<FilePath>& paths) {
3629 if (!enumeration_completions_[id])
3630 return;
3631
3632 WebVector<WebString> ws_file_names(paths.size());
3633 for (size_t i = 0; i < paths.size(); ++i)
3634 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3635
3636 enumeration_completions_[id]->didChooseFile(ws_file_names);
3637 enumeration_completions_.erase(id);
3638}
3639
[email protected]cdaf8d02010-03-30 19:52:473640void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363641 // This could happen if we navigated to a different page before the user
3642 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473643 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363644 return;
3645
[email protected]cdaf8d02010-03-30 19:52:473646 WebVector<WebString> ws_file_names(paths.size());
3647 for (size_t i = 0; i < paths.size(); ++i)
3648 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463649
[email protected]cdaf8d02010-03-30 19:52:473650 if (file_chooser_completions_.front()->completion)
3651 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3652 file_chooser_completions_.pop_front();
3653
3654 // If there are more pending file chooser requests, schedule one now.
3655 if (!file_chooser_completions_.empty()) {
3656 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3657 file_chooser_completions_.front()->params));
3658 }
initial.commit09911bf2008-07-26 23:55:293659}
3660
[email protected]770dd8b2010-05-24 18:11:393661void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
3662 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:243663 if (send_preferred_size_changes_)
3664 return;
[email protected]9fb325e2010-05-06 18:23:243665 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393666
[email protected]d812fd12011-05-27 23:05:073667 // Start off with an initial preferred size notification (in case
3668 // |didUpdateLayout| was already called).
3669 if (webview())
3670 didUpdateLayout(webview()->mainFrame());
[email protected]0666aef2009-05-13 19:48:083671}
3672
[email protected]cda45c02010-02-25 19:28:103673void RenderView::OnDisableScrollbarsForSmallWindows(
3674 const gfx::Size& disable_scrollbar_size_limit) {
3675 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3676}
3677
[email protected]80d96fa2009-06-10 22:34:513678void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
3679 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373680 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133681#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413682 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3683 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463684 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513685 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343686 renderer_prefs.thumb_inactive_color,
3687 renderer_prefs.thumb_active_color,
3688 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323689
[email protected]644d77e2010-01-27 01:03:103690 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323691 webview()->setScrollbarColors(
3692 renderer_prefs.thumb_inactive_color,
3693 renderer_prefs.thumb_active_color,
3694 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103695 webview()->setSelectionColors(
3696 renderer_prefs.active_selection_bg_color,
3697 renderer_prefs.active_selection_fg_color,
3698 renderer_prefs.inactive_selection_bg_color,
3699 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463700 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103701 }
[email protected]7a74e102009-09-03 00:16:563702#endif
[email protected]80d96fa2009-06-10 22:34:513703}
3704
[email protected]952cb702009-10-07 05:50:283705void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
3706 const WebMediaPlayerAction& action) {
3707 if (webview())
3708 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563709}
3710
[email protected]18d5be92011-07-25 18:00:193711void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
3712 const GURL& page_url) {
3713 // Prepare list to storage all savable resource links.
3714 std::vector<GURL> resources_list;
3715 std::vector<GURL> referrers_list;
3716 std::vector<GURL> frames_list;
3717 webkit_glue::SavableResourcesResult result(&resources_list,
3718 &referrers_list,
3719 &frames_list);
3720
3721 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3722 webview(),
3723 page_url,
3724 &result,
[email protected]2a80aee2011-10-07 16:06:033725 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:193726 // If something is wrong when collecting all savable resource links,
3727 // send empty list to embedder(browser) to tell it failed.
3728 referrers_list.clear();
3729 resources_list.clear();
3730 frames_list.clear();
3731 }
3732
3733 // Send result of all savable resource links to embedder.
3734 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3735 resources_list,
3736 referrers_list,
3737 frames_list));
3738}
3739
3740void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
3741 const std::vector<GURL>& links,
3742 const std::vector<FilePath>& local_paths,
3743 const FilePath& local_directory_name) {
3744
3745 // Convert std::vector of GURLs to WebVector<WebURL>
3746 WebVector<WebURL> weburl_links(links);
3747
3748 // Convert std::vector of std::strings to WebVector<WebString>
3749 WebVector<WebString> webstring_paths(local_paths.size());
3750 for (size_t i = 0; i < local_paths.size(); i++)
3751 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3752
3753 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
3754 webstring_paths,
3755 webkit_glue::FilePathToWebString(
3756 local_directory_name));
3757}
3758
[email protected]9b18a84f2010-06-10 15:54:043759void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273760 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473761 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293762}
3763
[email protected]992db4c2011-05-12 15:37:153764void RenderView::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
3765 if (is_swapped_out_)
3766 return;
3767
3768 // Swap this RenderView out so the tab can navigate to a page rendered by a
3769 // different process. This involves running the unload handler and clearing
3770 // the page. Once WasSwappedOut is called, we also allow this process to exit
3771 // if there are no other active RenderViews in it.
3772
3773 // Send an UpdateState message before we get swapped out.
3774 SyncNavigationState();
3775
3776 // Synchronously run the unload handler before sending the ACK.
3777 webview()->dispatchUnloadEvent();
3778
3779 // Swap out and stop sending any IPC messages that are not ACKs.
3780 SetSwappedOut(true);
3781
3782 // Replace the page with a blank dummy URL. The unload handler will not be
3783 // run a second time, thanks to a check in FrameLoader::stopLoading.
3784 // TODO(creis): Need to add a better way to do this that avoids running the
3785 // beforeunload handler. For now, we just run it a second time silently.
3786 webview()->mainFrame()->loadHTMLString(std::string(),
3787 GURL("about:swappedout"),
3788 GURL("about:swappedout"),
3789 false);
3790
3791 // Just echo back the params in the ACK.
3792 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3793}
3794
3795void RenderView::OnClosePage() {
initial.commit09911bf2008-07-26 23:55:293796 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3797 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3798 // in the onunload handler from appearing. For now, we're bypassing that and
3799 // calling the FrameLoader's CloseURL method directly. This should be
3800 // revisited to avoid having two ways to close a page. Having a single way
3801 // to close that can run onunload is also useful for fixing
3802 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273803 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293804
[email protected]992db4c2011-05-12 15:37:153805 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293806}
3807
3808void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:573809#if defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163810 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463811 if (webview())
3812 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573813#else // defined(OS_WIN)
3814 // TODO(port): we don't support theming on non-Windows platforms yet
3815 NOTIMPLEMENTED();
3816#endif
initial.commit09911bf2008-07-26 23:55:293817}
3818
[email protected]0aa55312008-10-17 21:53:083819void RenderView::OnDisassociateFromPopupCount() {
3820 if (decrement_shared_popup_at_destruction_)
3821 shared_popup_counter_->data--;
3822 shared_popup_counter_ = new SharedRenderViewCounter(0);
3823 decrement_shared_popup_at_destruction_ = false;
3824}
3825
[email protected]15d79e12009-08-02 19:23:453826bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
3827 const WebURLError& error,
3828 bool replace) {
3829 // We only show alternate error pages in the main frame. They are
3830 // intended to assist the user when navigating, so there is not much
3831 // value in showing them for failed subframes. Ideally, we would be
3832 // able to use the TYPED transition type for this, but that flag is
3833 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453834 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453835 return false;
3836
3837 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:373838 // connection failure.
[email protected]15d79e12009-08-02 19:23:453839 int ec = error.reason;
3840 if (ec != net::ERR_NAME_NOT_RESOLVED &&
3841 ec != net::ERR_CONNECTION_FAILED &&
3842 ec != net::ERR_CONNECTION_REFUSED &&
3843 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:373844 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:453845 return false;
3846
3847 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:553848 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:453849 if (!error_page_url.is_valid())
3850 return false;
3851
3852 // Load an empty page first so there is an immediate response to the error,
3853 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:453854 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:363855 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:453856 error.unreachableURL,
3857 replace);
3858
3859 // Now, create a fetcher for the error page and associate it with the data
3860 // source we just created via the LoadHTMLString call. That way if another
3861 // navigation occurs, the fetcher will get destroyed.
3862 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:453863 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:453864 navigation_state->set_alt_error_page_fetcher(
3865 new AltErrorPageResourceFetcher(
3866 error_page_url, frame, error,
3867 NewCallback(this, &RenderView::AltErrorPageFinished)));
3868 return true;
3869}
3870
[email protected]15d79e12009-08-02 19:23:453871void RenderView::AltErrorPageFinished(WebFrame* frame,
3872 const WebURLError& original_error,
3873 const std::string& html) {
3874 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:093875 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:553876 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:093877 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:453878}
3879
[email protected]30f75e62009-02-25 22:01:003880void RenderView::OnMoveOrResizeStarted() {
3881 if (webview())
[email protected]a72a1fa2010-05-03 22:18:473882 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:003883}
3884
[email protected]30f75e62009-02-25 22:01:003885void RenderView::OnResize(const gfx::Size& new_size,
3886 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:103887 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:473888 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:103889 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:203890 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:313891 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:103892 }
[email protected]dd6afca2011-08-13 03:44:313893 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:103894 }
3895
[email protected]30f75e62009-02-25 22:01:003896 RenderWidget::OnResize(new_size, resizer_rect);
3897}
[email protected]0aa477bd2009-03-23 22:21:433898
[email protected]00c39612010-03-06 02:53:283899void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:013900 // Notify the pepper plugins that we started painting.
3901 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:283902}
3903
3904void RenderView::DidFlushPaint() {
3905 // Notify any pepper plugins that we painted. This will call into the plugin,
3906 // and we it may ask to close itself as a result. This will, in turn, modify
3907 // our set, possibly invalidating the iterator. So we iterate on a copy that
3908 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:013909 pepper_delegate_.ViewFlushedPaint();
3910
[email protected]00c39612010-03-06 02:53:283911 WebFrame* main_frame = webview()->mainFrame();
3912
3913 // If we have a provisional frame we are between the start and commit stages
3914 // of loading and we don't want to save stats.
3915 if (!main_frame->provisionalDataSource()) {
3916 WebDataSource* ds = main_frame->dataSource();
3917 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3918 DCHECK(navigation_state);
3919
[email protected]05c8e502010-08-15 15:13:523920 // TODO(jar): The following code should all be inside a method, probably in
3921 // NavigatorState.
[email protected]00c39612010-03-06 02:53:283922 Time now = Time::Now();
3923 if (navigation_state->first_paint_time().is_null()) {
3924 navigation_state->set_first_paint_time(now);
3925 }
3926 if (navigation_state->first_paint_after_load_time().is_null() &&
3927 !navigation_state->finish_load_time().is_null()) {
3928 navigation_state->set_first_paint_after_load_time(now);
3929 }
3930 }
[email protected]b781ff282011-08-20 06:19:363931
3932#if defined(TOUCH_UI)
3933 SyncSelectionIfRequired();
3934#endif
[email protected]00c39612010-03-06 02:53:283935}
3936
[email protected]37a6f302011-07-11 23:43:083937void RenderView::OnViewContextSwapBuffersPosted() {
3938 RenderWidget::OnSwapBuffersPosted();
3939}
3940
[email protected]65225772011-05-12 21:10:243941void RenderView::OnViewContextSwapBuffersComplete() {
3942 RenderWidget::OnSwapBuffersComplete();
3943}
3944
3945void RenderView::OnViewContextSwapBuffersAborted() {
3946 RenderWidget::OnSwapBuffersAborted();
3947}
3948
[email protected]719b36f2010-12-22 20:36:463949webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:153950 const gfx::Rect& paint_bounds,
3951 TransportDIB** dib,
3952 gfx::Rect* location,
3953 gfx::Rect* clip) {
3954 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
3955 paint_bounds, dib, location, clip);
3956}
3957
[email protected]bcaf2272011-02-15 15:29:433958gfx::Point RenderView::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:073959 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:433960 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:523961}
3962
[email protected]05d478752009-04-08 23:38:163963void RenderView::OnClearFocusedNode() {
3964 if (webview())
[email protected]26aa0482009-09-30 16:55:273965 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:163966}
3967
[email protected]699ab0d2009-04-23 23:19:143968void RenderView::OnSetBackground(const SkBitmap& background) {
3969 if (webview())
[email protected]b4bb2502009-10-01 22:35:273970 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:143971
3972 SetBackground(background);
3973}
3974
[email protected]8c66c5a2009-07-22 17:26:343975void RenderView::OnSetActive(bool active) {
3976 if (webview())
[email protected]b4bb2502009-10-01 22:35:273977 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:263978
3979#if defined(OS_MACOSX)
3980 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
3981 for (plugin_it = plugin_delegates_.begin();
3982 plugin_it != plugin_delegates_.end(); ++plugin_it) {
3983 (*plugin_it)->SetWindowFocus(active);
3984 }
3985#endif
[email protected]8c66c5a2009-07-22 17:26:343986}
3987
[email protected]6ce7abc52010-02-02 18:40:143988#if defined(OS_MACOSX)
3989void RenderView::OnSetWindowVisibility(bool visible) {
3990 // Inform plugins that their container has changed visibility.
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(visible);
3995 }
3996}
[email protected]1e6e3c992010-02-08 15:52:133997
[email protected]4d51d5bf2010-07-26 18:48:263998void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
3999 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134000 // Inform plugins that their window's frame has changed.
4001 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4002 for (plugin_it = plugin_delegates_.begin();
4003 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4004 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4005 }
4006}
[email protected]935d63d2010-10-15 23:31:554007
[email protected]b7f75862011-01-21 21:15:134008void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:554009 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134010 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554011 // applies to it or not, so inform all the delegates.
4012 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4013 for (plugin_it = plugin_delegates_.begin();
4014 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134015 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554016 }
4017}
[email protected]6ce7abc52010-02-02 18:40:144018#endif // OS_MACOSX
4019
[email protected]446705872009-09-10 07:22:484020void RenderView::OnSetEditCommandsForNextKeyEvent(
4021 const EditCommands& edit_commands) {
4022 edit_commands_ = edit_commands;
4023}
4024
[email protected]60c42a8c72009-10-09 04:08:594025void RenderView::Close() {
4026 // We need to grab a pointer to the doomed WebView before we destroy it.
4027 WebView* doomed = webview();
4028 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494029 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594030}
4031
[email protected]446705872009-09-10 07:22:484032void RenderView::DidHandleKeyEvent() {
4033 edit_commands_.clear();
4034}
4035
[email protected]67bfb83f2011-09-22 03:36:374036bool RenderView::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]b993705a2011-10-09 23:00:244037 return pepper_delegate_.HandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374038}
4039
[email protected]6a8ddba52010-09-05 04:38:064040void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514041 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064042}
4043
[email protected]2d0f2e92011-10-03 09:02:244044void RenderView::DidHandleTouchEvent(const WebTouchEvent& event) {
4045 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4046}
4047
[email protected]941e4552010-02-01 21:23:434048void RenderView::OnWasHidden() {
4049 RenderWidget::OnWasHidden();
4050
[email protected]a6939ca42011-02-18 17:58:074051 if (webview()) {
4052 webview()->settings()->setMinimumTimerInterval(
4053 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444054 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074055 }
4056
4057#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434058 // Inform plugins that their container is no longer visible.
4059 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4060 for (plugin_it = plugin_delegates_.begin();
4061 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4062 (*plugin_it)->SetContainerVisibility(false);
4063 }
[email protected]a6939ca42011-02-18 17:58:074064#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434065}
4066
4067void RenderView::OnWasRestored(bool needs_repainting) {
4068 RenderWidget::OnWasRestored(needs_repainting);
4069
[email protected]a6939ca42011-02-18 17:58:074070 if (webview()) {
4071 webview()->settings()->setMinimumTimerInterval(
4072 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444073 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074074 }
4075
4076#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434077 // Inform plugins that their container is now visible.
4078 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4079 for (plugin_it = plugin_delegates_.begin();
4080 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4081 (*plugin_it)->SetContainerVisibility(true);
4082 }
[email protected]784ea1ab2010-09-18 00:02:344083#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074084}
[email protected]1e6e3c992010-02-08 15:52:134085
[email protected]65225772011-05-12 21:10:244086bool RenderView::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384087 if (WebWidgetHandlesCompositorScheduling())
4088 return false;
4089
[email protected]65225772011-05-12 21:10:244090 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4091 if (!context)
4092 return false;
4093 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4094 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4095 std::string::npos;
4096}
4097
[email protected]1e6e3c992010-02-08 15:52:134098void RenderView::OnSetFocus(bool enable) {
4099 RenderWidget::OnSetFocus(enable);
4100
[email protected]7d3c02c2010-05-05 23:10:314101 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074102 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134103 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4104 for (plugin_it = plugin_delegates_.begin();
4105 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344106#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314107 // RenderWidget's call to setFocus can cause the underlying webview's
4108 // activation state to change just like a call to setIsActive.
4109 if (enable)
4110 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344111#endif
[email protected]7d3c02c2010-05-05 23:10:314112 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134113 }
[email protected]589621b2010-09-23 22:01:074114
4115 // Notify all Pepper plugins.
4116 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134117 }
4118}
[email protected]941e4552010-02-01 21:23:434119
[email protected]56ea1a62011-05-30 07:05:574120void RenderView::PpapiPluginFocusChanged() {
4121 UpdateInputMethod();
4122}
4123
[email protected]08bb1e722011-07-30 19:13:044124void RenderView::RequestRemoteAccessClientFirewallTraversal() {
4125 Send(new ViewHostMsg_RequestRemoteAccessClientFirewallTraversal(routing_id_));
4126}
4127
[email protected]56ea1a62011-05-30 07:05:574128void RenderView::OnImeSetComposition(
4129 const string16& text,
4130 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4131 int selection_start,
4132 int selection_end) {
4133 // Until PPAPI has an interface for handling IME events, we skip sending
4134 // OnImeSetComposition. Otherwise the composition is canceled when a
4135 // non-editable DOM element is focused.
4136 //
4137 // TODO(kinaba) This temporal remedy can be removed after PPAPI is extended
4138 // with an IME handling interface.
4139 if (!pepper_delegate_.IsPluginFocused()) {
[email protected]e6ae0f6c2011-10-04 10:39:234140#if defined(OS_WIN)
4141 // When a plug-in has focus, we create platform-specific IME data used by
4142 // our IME emulator and send it directly to the focused plug-in, i.e. we
4143 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4144 // instance ID is the same one as the specified ID.)
4145 if (focused_plugin_id_ >= 0) {
4146 std::vector<int> clauses;
4147 std::vector<int> target;
4148 for (size_t i = 0; i < underlines.size(); ++i) {
4149 clauses.push_back(underlines[i].startOffset);
4150 clauses.push_back(underlines[i].endOffset);
4151 if (underlines[i].thick) {
4152 target.clear();
4153 target.push_back(underlines[i].startOffset);
4154 target.push_back(underlines[i].endOffset);
4155 }
4156 }
4157 std::set<WebPluginDelegateProxy*>::iterator it;
4158 for (it = plugin_delegates_.begin();
4159 it != plugin_delegates_.end(); ++it) {
4160 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4161 focused_plugin_id_);
4162 }
4163 return;
4164 }
4165#endif
[email protected]56ea1a62011-05-30 07:05:574166 RenderWidget::OnImeSetComposition(text,
4167 underlines,
4168 selection_start,
4169 selection_end);
4170 }
4171}
4172
4173void RenderView::OnImeConfirmComposition(const string16& text) {
4174 if (pepper_delegate_.IsPluginFocused()) {
4175 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4176 // send character events.
4177 for (size_t i = 0; i < text.size(); ++i) {
4178 WebKit::WebKeyboardEvent char_event;
4179 char_event.type = WebKit::WebInputEvent::Char;
4180 char_event.timeStampSeconds = base::Time::Now().ToDoubleT();
4181 char_event.modifiers = 0;
4182 char_event.windowsKeyCode = text[i];
4183 char_event.nativeKeyCode = text[i];
4184 char_event.text[0] = text[i];
4185 char_event.unmodifiedText[0] = text[i];
4186 if (webwidget_)
4187 webwidget_->handleInputEvent(char_event);
4188 }
4189 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234190#if defined(OS_WIN)
4191 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4192 // plug-ins. When we send IME text directly to plug-ins, we should not send
4193 // it to WebKit to prevent WebKit from controlling IMEs.
4194 if (focused_plugin_id_ >= 0) {
4195 std::set<WebPluginDelegateProxy*>::iterator it;
4196 for (it = plugin_delegates_.begin();
4197 it != plugin_delegates_.end(); ++it) {
4198 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4199 }
4200 return;
4201 }
4202#endif
[email protected]56ea1a62011-05-30 07:05:574203 RenderWidget::OnImeConfirmComposition(text);
4204 }
4205}
4206
[email protected]ad26ef42011-06-17 07:59:454207ui::TextInputType RenderView::GetTextInputType() {
[email protected]56ea1a62011-05-30 07:05:574208 if (pepper_delegate_.IsPluginFocused()) {
[email protected]7f81cc72011-09-07 18:19:314209#if !defined(TOUCH_UI)
[email protected]56ea1a62011-05-30 07:05:574210 // TODO(kinaba) Until PPAPI has an interface for handling IME events, we
4211 // consider all the parts of PPAPI plugins are accepting text inputs.
[email protected]ad26ef42011-06-17 07:59:454212 return ui::TEXT_INPUT_TYPE_TEXT;
[email protected]7f81cc72011-09-07 18:19:314213#else
4214 // Disable keyboard input in flash for touch ui until PPAPI can support IME
4215 // events.
4216 return ui::TEXT_INPUT_TYPE_NONE;
4217#endif
[email protected]56ea1a62011-05-30 07:05:574218 }
[email protected]ad26ef42011-06-17 07:59:454219 return RenderWidget::GetTextInputType();
4220}
4221
4222bool RenderView::CanComposeInline() {
4223 if (pepper_delegate_.IsPluginFocused()) {
4224 // TODO(kinaba) Until PPAPI has an interface for handling IME events, there
4225 // is no way for the browser to know whether the plugin is capable of
4226 // drawing composition text. We assume plugins are incapable and let the
4227 // browser handle composition display for now.
4228 return false;
4229 }
4230 return true;
[email protected]56ea1a62011-05-30 07:05:574231}
4232
[email protected]e6ae0f6c2011-10-04 10:39:234233#if defined(OS_WIN)
4234void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
4235 if (focused)
4236 focused_plugin_id_ = plugin_id;
4237 else
4238 focused_plugin_id_ = -1;
4239}
4240#endif
4241
[email protected]43f28f832010-02-03 02:28:484242#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:134243void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
4244 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4245 focused, plugin_id);
4246 Send(msg);
4247}
4248
4249void RenderView::StartPluginIme() {
4250 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554251 // This message can be sent during event-handling, and needs to be delivered
4252 // within that context.
4253 msg->set_unblock(true);
4254 Send(msg);
4255}
4256
[email protected]ea04a4e12010-04-15 00:58:034257gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234258 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484259 gfx::PluginWindowHandle window = NULL;
4260 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234261 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114262 if (window) {
4263 fake_plugin_window_handles_.insert(window);
4264 }
[email protected]43f28f832010-02-03 02:28:484265 return window;
4266}
4267
4268void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114269 if (window && fake_plugin_window_handles_.find(window) !=
4270 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484271 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114272 fake_plugin_window_handles_.erase(window);
4273 }
[email protected]43f28f832010-02-03 02:28:484274}
4275
[email protected]44ce0b12010-03-12 16:45:334276void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
4277 int32 width,
4278 int32 height,
4279 uint64 io_surface_identifier) {
4280 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484281 routing_id(), window, width, height, io_surface_identifier));
4282}
4283
[email protected]44ce0b12010-03-12 16:45:334284void RenderView::AcceleratedSurfaceSetTransportDIB(
4285 gfx::PluginWindowHandle window,
4286 int32 width,
4287 int32 height,
4288 TransportDIB::Handle transport_dib) {
4289 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074290 routing_id(), window, width, height, transport_dib));
4291}
4292
[email protected]44ce0b12010-03-12 16:45:334293TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
4294 size_t size) {
[email protected]1aef98132010-02-23 18:00:074295 TransportDIB::Handle dib_handle;
4296 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384297 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074298 return dib_handle;
4299 // Return an invalid handle if Send() fails.
4300 return TransportDIB::DefaultHandleValue();
4301}
4302
[email protected]44ce0b12010-03-12 16:45:334303void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074304 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4305}
4306
[email protected]44ce0b12010-03-12 16:45:334307void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144308 gfx::PluginWindowHandle window, uint64 surface_id) {
4309 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4310 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484311}
4312#endif
[email protected]58c321d2010-02-19 12:11:284313
[email protected]cdaf8d02010-03-30 19:52:474314bool RenderView::ScheduleFileChooser(
4315 const ViewHostMsg_RunFileChooser_Params& params,
4316 WebFileChooserCompletion* completion) {
4317 static const size_t kMaximumPendingFileChooseRequests = 4;
4318 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4319 // This sanity check prevents too many file choose requests from getting
4320 // queued which could DoS the user. Getting these is most likely a
4321 // programming error (there are many ways to DoS the user so it's not
4322 // considered a "real" security check), either in JS requesting many file
4323 // choosers to pop up, or in a plugin.
4324 //
4325 // TODO(brettw) we might possibly want to require a user gesture to open
4326 // a file picker, which will address this issue in a better way.
4327 return false;
4328 }
4329
4330 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4331 new PendingFileChooser(params, completion)));
4332 if (file_chooser_completions_.size() == 1) {
4333 // Actually show the browse dialog when this is the first request.
4334 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4335 }
4336 return true;
4337}
4338
[email protected]0ff0ff32010-12-21 19:34:424339WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514340 if (!geolocation_dispatcher_)
4341 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4342 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254343}
[email protected]61c9f032010-03-31 23:04:194344
[email protected]638694c2010-08-04 22:24:114345WebKit::WebSpeechInputController* RenderView::speechInputController(
4346 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:514347 if (!speech_input_dispatcher_)
4348 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
4349 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114350}
4351
[email protected]57ead352010-08-11 14:42:534352WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514353 if (!device_orientation_dispatcher_)
4354 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4355 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534356}
4357
[email protected]b75b8292010-10-01 07:28:254358void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
4359 // For now, don't remember plugin zoom values. We don't want to mix them with
4360 // normal web content (i.e. a fixed layout plugin would usually want them
4361 // different).
4362 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4363
[email protected]b75b8292010-10-01 07:28:254364 int minimum_percent = static_cast<int>(
4365 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4366 int maximum_percent = static_cast<int>(
4367 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254368
4369 Send(new ViewHostMsg_UpdateZoomLimits(
4370 routing_id_, minimum_percent, maximum_percent, remember));
4371}
4372
4373void RenderView::zoomLevelChanged() {
4374 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084375#if defined(TOUCH_UI)
4376 float zoom_level =
4377 WebView::zoomFactorToZoomLevel(webview()->pageScaleFactor());
4378#else
4379 float zoom_level = webview()->zoomLevel();
4380#endif
[email protected]b75b8292010-10-01 07:28:254381 // Tell the browser which url got zoomed so it can update the menu and the
4382 // saved values if necessary
4383 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084384 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414385 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254386}
4387
[email protected]a6d36cc2011-02-23 00:39:484388void RenderView::registerProtocolHandler(const WebString& scheme,
4389 const WebString& base_url,
4390 const WebString& url,
4391 const WebString& title) {
4392 GURL base(base_url);
4393 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4394 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4395 return;
4396 }
[email protected]f1a29a02011-10-06 23:08:444397 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4398 UTF16ToUTF8(scheme),
4399 absolute_url,
4400 title));
[email protected]a6d36cc2011-02-23 00:39:484401}
4402
[email protected]62af76e2011-08-01 02:34:014403void RenderView::registerIntentHandler(const WebString& action,
4404 const WebString& type,
4405 const WebString& href,
4406 const WebString& title) {
[email protected]f1a29a02011-10-06 23:08:444407 Send(new ViewHostMsg_RegisterIntentHandler(routing_id_,
4408 action,
4409 type,
4410 href,
4411 title));
[email protected]62af76e2011-08-01 02:34:014412}
4413
[email protected]94dec932011-05-26 20:04:214414WebKit::WebPageVisibilityState RenderView::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444415 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4416 WebKit::WebPageVisibilityStateHidden :
4417 WebKit::WebPageVisibilityStateVisible;
4418 WebKit::WebPageVisibilityState override_state = current_state;
4419 if (content::GetContentClient()->renderer()->
4420 ShouldOverridePageVisibilityState(this,
4421 &override_state))
4422 return override_state;
4423 return current_state;
[email protected]94dec932011-05-26 20:04:214424}
4425
[email protected]e235c7d02011-08-18 22:38:434426void RenderView::startActivity(const WebKit::WebString& action,
4427 const WebKit::WebString& type,
4428 const WebKit::WebString& data,
4429 int intent_id) {
[email protected]ce9751942011-09-21 01:57:244430 webkit_glue::WebIntentData intent_data;
4431 intent_data.action = action;
4432 intent_data.type = type;
4433 intent_data.data = data;
4434 Send(new IntentsHostMsg_WebIntentDispatch(
4435 routing_id_, intent_data, intent_id));
[email protected]e235c7d02011-08-18 22:38:434436}
4437
[email protected]8079b362010-05-07 18:37:454438bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194439 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454440 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194441 if (frame->parent() != NULL)
4442 return false;
4443
[email protected]f0a3d0b2010-08-06 22:51:534444 // Navigations initiated within Webkit are not sent out to the external host
4445 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274446 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134447 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534448 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134449 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334450 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534451 return false;
4452
[email protected]2fc22d12010-12-02 23:08:164453 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324454 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014455 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164456 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014457 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324458 // The opener relationship between the new window and the parent allows the
4459 // new window to script the parent and vice versa. This is not allowed if
4460 // the origins of the two domains are different. This can be treated as a
4461 // top level navigation and routed back to the host.
4462 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274463 if (!opener) {
[email protected]86965362011-04-21 18:42:514464 return true;
[email protected]d19ea342011-04-20 20:31:134465 } else {
[email protected]b6cb3a842011-06-24 18:28:414466 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324467 return true;
4468 }
4469 }
[email protected]61c9f032010-03-31 23:04:194470 return false;
4471}
[email protected]2b06a992010-08-21 05:48:224472
[email protected]27a9ef32010-09-10 04:06:244473void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
4474 IPC::PlatformFileForTransit file_for_transit,
4475 int message_id) {
4476 pepper_delegate_.OnAsyncFileOpened(
4477 error_code,
4478 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4479 message_id);
4480}
[email protected]caf706f2010-10-26 17:54:084481
[email protected]2b657fd2011-04-18 16:00:474482void RenderView::OnPpapiBrokerChannelCreated(
4483 int request_id,
4484 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434485 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474486 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4487 broker_process_handle,
4488 handle);
[email protected]eb415bf0e2011-04-14 02:45:424489}
4490
[email protected]caf706f2010-10-26 17:54:084491#if defined(OS_MACOSX)
4492void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154493 if (external_popup_menu_ == NULL) {
4494 // Crash reports from the field indicate that we can be notified with a
4495 // NULL external popup menu (we probably get notified twice).
4496 // If you hit this please file a bug against jcivelli and include the page
4497 // and steps to repro.
4498 NOTREACHED();
4499 return;
4500 }
[email protected]caf706f2010-10-26 17:54:084501 external_popup_menu_->DidSelectItem(selected_index);
4502 external_popup_menu_.reset();
4503}
4504#endif
[email protected]bb461532010-11-26 21:50:234505
[email protected]1b4209f2011-01-07 00:25:404506#if defined(ENABLE_FLAPPER_HACKS)
4507void RenderView::OnConnectTcpACK(
4508 int request_id,
4509 IPC::PlatformFileForTransit socket_for_transit,
4510 const PP_Flash_NetAddress& local_addr,
4511 const PP_Flash_NetAddress& remote_addr) {
4512 pepper_delegate_.OnConnectTcpACK(
4513 request_id,
4514 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4515 local_addr,
4516 remote_addr);
4517}
4518#endif
[email protected]a6097f42011-01-10 08:50:514519
[email protected]b29aa74b2011-01-31 21:41:084520void RenderView::OnContextMenuClosed(
4521 const webkit_glue::CustomContextMenuContext& custom_context) {
4522 if (custom_context.is_pepper_menu)
4523 pepper_delegate_.OnContextMenuClosed(custom_context);
4524 else
4525 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104526}
[email protected]5a7b15a2011-08-22 22:48:184527
4528void RenderView::OnEnableViewSourceMode() {
4529 if (!webview())
4530 return;
4531 WebFrame* main_frame = webview()->mainFrame();
4532 if (!main_frame)
4533 return;
4534 main_frame->enableViewSourceMode(true);
4535}
[email protected]67bfb83f2011-09-22 03:36:374536
4537void RenderView::OnLockMouseACK(bool succeeded) {
4538 pepper_delegate_.OnLockMouseACK(succeeded);
4539}
4540
4541void RenderView::OnMouseLockLost() {
4542 pepper_delegate_.OnMouseLockLost();
4543}
[email protected]c3d45532011-10-07 19:20:404544
4545bool RenderView::WebWidgetHandlesCompositorScheduling() const {
4546 return webview()->settings()->useThreadedCompositor();
4547}