blob: 53d0e97de3f97d450be0b2f8061fb9e29775ad5e [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]310ebd6302011-10-10 19:06:285#include "content/renderer/render_view_impl.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]6e806822011-11-19 01:51:0812#include "base/bind.h"
13#include "base/bind_helpers.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5015#include "base/compiler_specific.h"
[email protected]005bab02011-10-07 18:36:0016#include "base/json/json_value_serializer.h"
[email protected]b1cf3372011-04-20 21:28:1017#include "base/json/json_writer.h"
[email protected]625332e02010-12-14 07:48:4918#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3819#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2820#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5121#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2922#include "base/string_piece.h"
[email protected]318bf5802011-08-08 17:12:4123#include "base/string_split.h"
initial.commit09911bf2008-07-26 23:55:2924#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2825#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2626#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2227#include "base/utf_string_conversions.h"
[email protected]e93e04e2011-03-14 00:27:1028#include "content/common/appcache/appcache_dispatcher.h"
[email protected]127dd582011-03-16 21:32:1029#include "content/common/clipboard_messages.h"
[email protected]37666cf2011-03-13 21:51:4230#include "content/common/database_messages.h"
[email protected]59f4f2fa2011-03-23 01:00:5531#include "content/common/drag_messages.h"
[email protected]7ef40ffe12011-03-08 05:05:2832#include "content/common/file_system/file_system_dispatcher.h"
33#include "content/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]a2ef54c2011-10-10 16:20:3134#include "content/common/intents_messages.h"
[email protected]7f3c7af2011-10-20 22:52:5135#include "content/common/java_bridge_messages.h"
[email protected]127dd582011-03-16 21:32:1036#include "content/common/pepper_messages.h"
[email protected]cebc3dc2011-04-18 17:15:0037#include "content/common/pepper_plugin_registry.h"
[email protected]10e5cf12011-04-13 04:10:4038#include "content/common/quota_dispatcher.h"
[email protected]940895b2011-08-20 00:50:0539#include "content/common/request_extra_data.h"
[email protected]778574e2011-03-21 22:03:5040#include "content/common/view_messages.h"
[email protected]e091df82011-10-11 18:13:2141#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4842#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2943#include "content/public/common/content_switches.h"
[email protected]8caadeb2011-11-22 02:45:2344#include "content/public/common/file_chooser_params.h"
[email protected]a1d29162011-10-14 17:14:0345#include "content/public/common/url_constants.h"
[email protected]d344114c2011-10-01 01:24:3446#include "content/public/renderer/content_renderer_client.h"
[email protected]007733c2011-11-17 00:34:0747#include "content/public/renderer/document_state.h"
[email protected]82ddba1c2011-10-04 00:15:3248#include "content/public/renderer/navigation_state.h"
[email protected]3a034ebb2011-10-03 19:19:4449#include "content/public/renderer/render_view_observer.h"
[email protected]64ffa0442011-10-03 22:08:3650#include "content/public/renderer/render_view_visitor.h"
[email protected]230b7ef2011-03-16 22:30:1951#include "content/renderer/device_orientation_dispatcher.h"
[email protected]4a19be92011-09-22 14:25:0252#include "content/renderer/devtools_agent.h"
[email protected]55722152011-03-22 01:33:5353#include "content/renderer/external_popup_menu.h"
[email protected]230b7ef2011-03-16 22:30:1954#include "content/renderer/geolocation_dispatcher.h"
[email protected]a03a2222011-05-25 21:26:4055#include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
[email protected]1ef93132011-09-16 18:33:4756#include "content/renderer/intents_dispatcher.h"
[email protected]07161902011-11-11 09:57:4257#include "content/renderer/java/java_bridge_dispatcher.h"
[email protected]921f1592011-03-18 00:41:0258#include "content/renderer/load_progress_tracker.h"
[email protected]25803d152011-06-14 01:18:0859#include "content/renderer/media/audio_message_filter.h"
[email protected]ccc70d8e2011-03-16 20:40:3760#include "content/renderer/media/audio_renderer_impl.h"
[email protected]ab2c4732011-07-20 19:57:4061#include "content/renderer/media/media_stream_impl.h"
[email protected]090f7312011-08-05 23:26:4062#include "content/renderer/media/render_media_log.h"
[email protected]4a19be92011-09-22 14:25:0263#include "content/renderer/mhtml_generator.h"
[email protected]230b7ef2011-03-16 22:30:1964#include "content/renderer/notification_provider.h"
[email protected]ccc70d8e2011-03-16 20:40:3765#include "content/renderer/p2p/socket_dispatcher.h"
[email protected]6f516082011-03-17 19:15:3566#include "content/renderer/plugin_channel_host.h"
[email protected]8704f89b2011-04-15 00:30:0567#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4468#include "content/renderer/render_thread_impl.h"
[email protected]2cff0052011-03-18 16:51:4469#include "content/renderer/render_widget_fullscreen_pepper.h"
[email protected]063afcb2011-09-29 07:54:3270#include "content/renderer/renderer_accessibility.h"
[email protected]663bd9e2011-03-21 01:07:0171#include "content/renderer/renderer_webapplicationcachehost_impl.h"
72#include "content/renderer/renderer_webstoragenamespace_impl.h"
[email protected]230b7ef2011-03-16 22:30:1973#include "content/renderer/speech_input_dispatcher.h"
[email protected]86a7d3c2011-09-12 16:45:3274#include "content/renderer/text_input_client_observer.h"
[email protected]8d86f13d2011-10-04 17:01:1975#include "content/renderer/v8_value_converter_impl.h"
[email protected]663bd9e2011-03-21 01:07:0176#include "content/renderer/web_ui_bindings.h"
[email protected]6f516082011-03-17 19:15:3577#include "content/renderer/webplugin_delegate_proxy.h"
78#include "content/renderer/websharedworker_proxy.h"
[email protected]f8db8132010-12-03 00:27:4979#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:4180#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:2781#include "media/base/message_loop_factory_impl.h"
initial.commit09911bf2008-07-26 23:55:2982#include "net/base/escape.h"
83#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:0484#include "net/http/http_util.h"
[email protected]9d9f1bb2011-02-23 22:10:5785#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]8bd0fe62011-01-17 06:44:3786#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
87#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
88#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
[email protected]8bd0fe62011-01-17 06:44:3789#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
90#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
91#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
92#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
[email protected]8bd0fe62011-01-17 06:44:3793#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
94#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
95#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
96#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
97#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
98#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
99#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
100#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
101#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
[email protected]56ea1a62011-05-30 07:05:57102#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
[email protected]69f110d62011-03-17 19:01:14103#include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h"
[email protected]8bd0fe62011-01-17 06:44:37104#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
[email protected]18d5be92011-07-25 18:00:19105#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
[email protected]8bd0fe62011-01-17 06:44:37106#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
107#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
108#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
109#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
110#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
111#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
112#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
113#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
114#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
115#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
[email protected]20dc3cad2011-04-20 17:27:17116#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
[email protected]8bd0fe62011-01-17 06:44:37117#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
[email protected]10e5cf12011-04-13 04:10:40120#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h"
[email protected]8bd0fe62011-01-17 06:44:37121#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26129#include "third_party/skia/include/core/SkBitmap.h"
[email protected]c4a9e932011-03-05 04:05:55130#include "ui/base/message_box_flags.h"
[email protected]08397d52011-02-05 01:53:38131#include "ui/gfx/native_widget_types.h"
132#include "ui/gfx/point.h"
133#include "ui/gfx/rect.h"
[email protected]c4a9e932011-03-05 04:05:55134#include "v8/include/v8.h"
[email protected]80f584d92010-01-21 03:59:04135#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43136#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24137#include "webkit/glue/context_menu.h"
[email protected]18d5be92011-07-25 18:00:19138#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59139#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24140#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24141#include "webkit/glue/glue_serialize.h"
[email protected]4d51d5bf2010-07-26 18:48:26142#include "webkit/glue/password_form_dom_manager.h"
initial.commit09911bf2008-07-26 23:55:29143#include "webkit/glue/webdropdata.h"
[email protected]a6939ca42011-02-18 17:58:07144#include "webkit/glue/webkit_constants.h"
initial.commit09911bf2008-07-26 23:55:29145#include "webkit/glue/webkit_glue.h"
[email protected]b00ba702011-08-17 01:41:03146#include "webkit/glue/weburlloader_impl.h"
[email protected]a9288f52011-11-17 05:18:16147#include "webkit/media/video_renderer_impl.h"
148#include "webkit/media/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50149#include "webkit/plugins/npapi/default_plugin_shared.h"
150#include "webkit/plugins/npapi/plugin_list.h"
151#include "webkit/plugins/npapi/webplugin_delegate.h"
152#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
153#include "webkit/plugins/npapi/webplugin_impl.h"
154#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52155#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29156
[email protected]6c8afae52009-01-22 02:24:57157#if defined(OS_WIN)
158// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57159// * theming
[email protected]08397d52011-02-05 01:53:38160#include "ui/gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03161#elif defined(USE_X11)
[email protected]8bd0fe62011-01-17 06:44:37162#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]42e5c862011-04-07 22:13:51163#include "ui/gfx/native_theme.h"
[email protected]78043bdd2010-04-05 18:45:33164#elif defined(OS_MACOSX)
165#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57166#endif
167
[email protected]9892b472010-09-16 00:23:42168using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08169using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21170using WebKit::WebApplicationCacheHost;
171using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26172using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41173using WebKit::WebColor;
174using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59175using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44176using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51177using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55178using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28179using WebKit::WebDataSource;
[email protected]5bc8fe92010-03-11 18:19:00180using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58181using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25182using WebKit::WebDragOperation;
183using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51184using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51185using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08186using WebKit::WebExternalPopupMenu;
187using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47188using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22189using WebKit::WebFileSystem;
190using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49191using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59192using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48193using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45194using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17195using WebKit::WebHistoryItem;
[email protected]42054a252011-05-17 18:02:13196using WebKit::WebIconURL;
[email protected]c27ae592010-03-18 15:24:41197using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50198using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17199using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28200using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17201using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28202using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28203using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51204using WebKit::WebNode;
[email protected]18d5be92011-07-25 18:00:19205using WebKit::WebPageSerializer;
206using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17207using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40208using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49209using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09210using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52211using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59212using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51213using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52214using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40215using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35216using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29217using WebKit::WebSecurityOrigin;
[email protected]20dc3cad2011-04-20 17:27:17218using WebKit::WebSecurityPolicy;
[email protected]2fab253a2009-08-17 23:00:59219using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42220using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02221using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34222using WebKit::WebStorageNamespace;
[email protected]10e5cf12011-04-13 04:10:40223using WebKit::WebStorageQuotaCallbacks;
224using WebKit::WebStorageQuotaError;
225using WebKit::WebStorageQuotaType;
[email protected]726985e22009-06-18 21:09:28226using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51227using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52228using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:24229using WebKit::WebTouchEvent;
[email protected]726985e22009-06-18 21:09:28230using WebKit::WebURL;
231using WebKit::WebURLError;
232using WebKit::WebURLRequest;
233using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28234using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03235using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28236using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26237using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43238using WebKit::WebWorker;
239using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26240using appcache::WebApplicationCacheHostImpl;
241using base::Time;
242using base::TimeDelta;
[email protected]007733c2011-11-17 00:34:07243using content::DocumentState;
[email protected]82ddba1c2011-10-04 00:15:32244using content::NavigationState;
[email protected]380244092011-10-07 17:26:27245using content::RenderThread;
[email protected]3a034ebb2011-10-03 19:19:44246using content::RenderViewObserver;
[email protected]64ffa0442011-10-03 22:08:36247using content::RenderViewVisitor;
[email protected]8d86f13d2011-10-04 17:01:19248using content::V8ValueConverter;
[email protected]6fdd4182010-10-14 23:59:26249using webkit_glue::AltErrorPageResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26250using webkit_glue::FormField;
[email protected]6fdd4182010-10-14 23:59:26251using webkit_glue::PasswordForm;
252using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23253using webkit_glue::ResourceFetcher;
[email protected]e1acf6f2008-10-27 20:43:33254
initial.commit09911bf2008-07-26 23:55:29255//-----------------------------------------------------------------------------
256
[email protected]310ebd6302011-10-10 19:06:28257typedef std::map<WebKit::WebView*, RenderViewImpl*> ViewMap;
[email protected]6de0fd1d2011-11-15 13:31:49258static base::LazyInstance<ViewMap> g_view_map = LAZY_INSTANCE_INITIALIZER;
[email protected]3354d3e2010-06-10 19:53:02259
[email protected]882daa92009-11-05 16:31:31260// Time, in seconds, we delay before sending content state changes (such as form
261// state and scroll position) to the browser. We delay sending changes to avoid
262// spamming the browser.
263// To avoid having tab/session restore require sending a message to get the
264// current content state during tab closing we use a shorter timeout for the
265// foreground renderer. This means there is a small window of time from which
266// content state is modified and not sent to session restore, but this is
267// better than having to wake up all renderers during shutdown.
268static const int kDelaySecondsForContentStateSyncHidden = 5;
269static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29270
[email protected]e99ef6f2011-10-16 01:13:00271static const size_t kExtraCharsBeforeAndAfterSelection = 100;
272
[email protected]0aa55312008-10-17 21:53:08273// The maximum number of popups that can be spawned from one page.
274static const int kMaximumNumberOfUnacknowledgedPopups = 25;
275
[email protected]c514d6372011-08-16 22:54:44276static const float kScalingIncrement = 0.1f;
277
[email protected]47578fa02011-11-02 19:34:41278static const float kScalingIncrementForGesture = 0.01f;
279
[email protected]726985e22009-06-18 21:09:28280static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
281 WebVector<WebURL> urls;
282 ds->redirectChain(urls);
283 result->reserve(urls.size());
284 for (size_t i = 0; i < urls.size(); ++i)
285 result->push_back(urls[i]);
286}
287
[email protected]007733c2011-11-17 00:34:07288// If |data_source| is non-null and has a DocumentState associated with it,
[email protected]6a8f5112011-05-13 16:38:44289// the AltErrorPageResourceFetcher is reset.
290static void StopAltErrorPageFetcher(WebDataSource* data_source) {
291 if (data_source) {
[email protected]007733c2011-11-17 00:34:07292 DocumentState* document_state = DocumentState::FromDataSource(data_source);
293 if (document_state)
294 document_state->set_alt_error_page_fetcher(NULL);
[email protected]6a8f5112011-05-13 16:38:44295 }
296}
297
[email protected]007733c2011-11-17 00:34:07298static bool IsReload(const ViewMsg_Navigate_Params& params) {
299 return
300 params.navigation_type == ViewMsg_Navigate_Type::RELOAD ||
301 params.navigation_type == ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
302}
303
initial.commit09911bf2008-07-26 23:55:29304///////////////////////////////////////////////////////////////////////////////
305
[email protected]310ebd6302011-10-10 19:06:28306int32 RenderViewImpl::next_page_id_ = 1;
[email protected]60c42a8c72009-10-09 04:08:59307
[email protected]310ebd6302011-10-10 19:06:28308struct RenderViewImpl::PendingFileChooser {
[email protected]8caadeb2011-11-22 02:45:23309 PendingFileChooser(const content::FileChooserParams& p,
[email protected]cdaf8d02010-03-30 19:52:47310 WebFileChooserCompletion* c)
311 : params(p),
312 completion(c) {
313 }
[email protected]8caadeb2011-11-22 02:45:23314 content::FileChooserParams params;
[email protected]cdaf8d02010-03-30 19:52:47315 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
316};
317
[email protected]daf82f82011-10-31 22:35:31318RenderViewImpl::RenderViewImpl(
319 gfx::NativeViewId parent_hwnd,
320 int32 opener_id,
321 const content::RendererPreferences& renderer_prefs,
322 const WebPreferences& webkit_prefs,
323 SharedRenderViewCounter* counter,
324 int32 routing_id,
325 int64 session_storage_namespace_id,
326 const string16& frame_name)
[email protected]380244092011-10-07 17:26:27327 : RenderWidget(WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51328 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02329 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09330 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02331 send_preferred_size_changes_(false),
[email protected]81a34412009-01-05 19:17:24332 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21333 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02334 opened_by_user_gesture_(true),
335 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24336 page_id_(-1),
337 last_page_id_sent_to_browser_(-1),
[email protected]3cc72b12010-03-18 23:03:00338 history_list_offset_(-1),
339 history_list_length_(0),
[email protected]3354d3e2010-06-10 19:53:02340 target_url_status_(TARGET_NONE),
[email protected]bbef1d32011-10-25 14:36:55341 selection_text_offset_(0),
[email protected]dd6afca2011-08-13 03:44:31342 cached_is_main_frame_pinned_to_left_(false),
343 cached_is_main_frame_pinned_to_right_(false),
344 cached_has_main_frame_horizontal_scrollbar_(false),
345 cached_has_main_frame_vertical_scrollbar_(false),
[email protected]18ca9a6b2010-06-02 19:05:18346 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e6ae0f6c2011-10-04 10:39:23347#if defined(OS_WIN)
348 focused_plugin_id_(-1),
349#endif
[email protected]3354d3e2010-06-10 19:53:02350 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51351 geolocation_dispatcher_(NULL),
352 speech_input_dispatcher_(NULL),
353 device_orientation_dispatcher_(NULL),
[email protected]cae8c8492011-03-03 11:12:18354 p2p_socket_dispatcher_(NULL),
[email protected]c5c1d6d2011-07-28 18:42:41355 devtools_agent_(NULL),
[email protected]063afcb2011-09-29 07:54:32356 renderer_accessibility_(NULL),
[email protected]4fb60142011-08-09 02:22:08357 session_storage_namespace_id_(session_storage_namespace_id),
358 handling_select_range_(false) {
[email protected]676126f72011-01-15 00:03:51359 routing_id_ = routing_id;
360 if (opener_id != MSG_ROUTING_NONE)
361 opener_id_ = opener_id;
362
[email protected]11fee2332011-03-29 20:36:35363 webwidget_ = WebView::create(this);
364
[email protected]676126f72011-01-15 00:03:51365 if (counter) {
366 shared_popup_counter_ = counter;
367 shared_popup_counter_->data++;
368 decrement_shared_popup_at_destruction_ = true;
369 } else {
370 shared_popup_counter_ = new SharedRenderViewCounter(0);
371 decrement_shared_popup_at_destruction_ = false;
372 }
373
[email protected]1ef93132011-09-16 18:33:47374 intents_dispatcher_ = new IntentsDispatcher(this);
[email protected]7cce3232011-10-28 10:41:57375
376#if defined(ENABLE_NOTIFICATIONS)
[email protected]676126f72011-01-15 00:03:51377 notification_provider_ = new NotificationProvider(this);
[email protected]7cce3232011-10-28 10:41:57378#else
379 notification_provider_ = NULL;
380#endif
[email protected]676126f72011-01-15 00:03:51381
[email protected]380244092011-10-07 17:26:27382 RenderThread::Get()->AddRoute(routing_id_, this);
[email protected]676126f72011-01-15 00:03:51383 // Take a reference on behalf of the RenderThread. This will be balanced
[email protected]8a5e0ca2011-08-25 06:30:47384 // when we receive ViewMsg_ClosePage.
[email protected]676126f72011-01-15 00:03:51385 AddRef();
386
387 // If this is a popup, we must wait for the CreatingNew_ACK message before
388 // completing initialization. Otherwise, we can finish it now.
389 if (opener_id == MSG_ROUTING_NONE) {
390 did_show_ = true;
[email protected]2d7c8552011-06-27 19:21:55391 CompleteInit(parent_hwnd);
[email protected]676126f72011-01-15 00:03:51392 }
393
[email protected]34c61bd52011-05-02 19:38:33394 g_view_map.Get().insert(std::make_pair(webview(), this));
395 webkit_preferences_.Apply(webview());
396 webview()->initializeMainFrame(this);
[email protected]2024c922011-09-02 23:34:35397 if (!frame_name.empty())
398 webview()->mainFrame()->setName(frame_name);
[email protected]34c61bd52011-05-02 19:38:33399 webview()->settings()->setMinimumTimerInterval(
400 is_hidden() ? webkit_glue::kBackgroundTabTimerInterval :
401 webkit_glue::kForegroundTabTimerInterval);
402
403 OnSetRendererPrefs(renderer_prefs);
404
[email protected]676126f72011-01-15 00:03:51405 host_window_ = parent_hwnd;
406
[email protected]a026daa2011-04-20 15:49:51407#if defined(ENABLE_P2P_APIS)
[email protected]b3f8f9722011-08-25 20:56:07408 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(this);
[email protected]a026daa2011-04-20 15:49:51409#endif
[email protected]cae8c8492011-03-03 11:12:18410
[email protected]8f6a3b852011-07-19 16:48:56411 new MHTMLGenerator(this);
[email protected]86a7d3c2011-09-12 16:45:32412#if defined(OS_MACOSX)
413 new TextInputClientObserver(this);
414#endif // defined(OS_MACOSX)
[email protected]8f6a3b852011-07-19 16:48:56415
[email protected]c5c1d6d2011-07-28 18:42:41416 devtools_agent_ = new DevToolsAgent(this);
[email protected]82622452011-07-22 09:57:20417
[email protected]063afcb2011-09-29 07:54:32418 renderer_accessibility_ = new RendererAccessibility(this);
419
420 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]ab2c4732011-07-20 19:57:40421 if (command_line.HasSwitch(switches::kEnableMediaStream)) {
422 media_stream_impl_ = new MediaStreamImpl(
[email protected]f1a29a02011-10-06 23:08:44423 RenderThreadImpl::current()->video_capture_impl_manager());
[email protected]ab2c4732011-07-20 19:57:40424 }
425
[email protected]e48869a2011-04-01 19:56:03426 content::GetContentClient()->renderer()->RenderViewCreated(this);
initial.commit09911bf2008-07-26 23:55:29427}
428
[email protected]310ebd6302011-10-10 19:06:28429RenderViewImpl::~RenderViewImpl() {
[email protected]d466b8a2011-07-15 21:48:03430 history_page_ids_.clear();
431
[email protected]0aa55312008-10-17 21:53:08432 if (decrement_shared_popup_at_destruction_)
433 shared_popup_counter_->data--;
434
[email protected]a1128322009-10-06 18:38:46435 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47436 while (!file_chooser_completions_.empty()) {
437 if (file_chooser_completions_.front()->completion) {
438 file_chooser_completions_.front()->completion->didChooseFile(
439 WebVector<WebString>());
440 }
441 file_chooser_completions_.pop_front();
442 }
[email protected]a1128322009-10-06 18:38:46443
[email protected]83dde542009-09-11 20:59:55444#if defined(OS_MACOSX)
[email protected]c36a9b62010-10-14 00:41:11445 // Destroy all fake plugin window handles on the browser side.
446 while (!fake_plugin_window_handles_.empty()) {
447 // Make sure no NULL plugin window handles were inserted into this list.
448 DCHECK(*fake_plugin_window_handles_.begin());
449 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
450 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
451 }
[email protected]83dde542009-09-11 20:59:55452#endif
[email protected]98324892009-09-09 21:16:05453
[email protected]60c42a8c72009-10-09 04:08:59454#ifndef NDEBUG
455 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49456 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59457 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
458 DCHECK_NE(this, it->second) << "Failed to call Close?";
459#endif
[email protected]676126f72011-01-15 00:03:51460
[email protected]310ebd6302011-10-10 19:06:28461 FOR_EACH_OBSERVER(RenderViewObserver, observers_, RenderViewGone());
[email protected]676126f72011-01-15 00:03:51462 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59463}
464
465/*static*/
[email protected]310ebd6302011-10-10 19:06:28466RenderViewImpl* RenderViewImpl::FromWebView(WebView* webview) {
[email protected]a2ef54c2011-10-10 16:20:31467 ViewMap* views = g_view_map.Pointer();
468 ViewMap::iterator it = views->find(webview);
469 return it == views->end() ? NULL : it->second;
470}
471
472/*static*/
473content::RenderView*
474 content::RenderView::FromWebView(WebKit::WebView* webview) {
[email protected]310ebd6302011-10-10 19:06:28475 return RenderViewImpl::FromWebView(webview);
[email protected]a2ef54c2011-10-10 16:20:31476}
477
478/*static*/
479void content::RenderView::ForEach(content::RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49480 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59481 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
482 if (!visitor->Visit(it->second))
483 return;
484 }
485}
486
487/*static*/
[email protected]310ebd6302011-10-10 19:06:28488RenderViewImpl* RenderViewImpl::Create(
[email protected]18bcc3c2009-01-27 21:39:15489 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08490 int32 opener_id,
[email protected]daf82f82011-10-31 22:35:31491 const content::RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08492 const WebPreferences& webkit_prefs,
493 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34494 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26495 int64 session_storage_namespace_id,
496 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29497 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]310ebd6302011-10-10 19:06:28498 return new RenderViewImpl(
[email protected]676126f72011-01-15 00:03:51499 parent_hwnd,
500 opener_id,
501 renderer_prefs,
502 webkit_prefs,
503 counter,
504 routing_id,
505 session_storage_namespace_id,
506 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29507}
508
[email protected]bb461532010-11-26 21:50:23509// static
[email protected]310ebd6302011-10-10 19:06:28510void RenderViewImpl::SetNextPageID(int32 next_page_id) {
[email protected]ae195eca72011-11-17 21:18:38511 // This method is called on startup or when the browser knows it needs to
512 // inflate the page_id when re-using the process. The renderer may have
513 // incremented this just as the browser was sending the message, but we
514 // only care that next_page_id_ is at least as large as next_page_id.
515 if (next_page_id > next_page_id_)
516 next_page_id_ = next_page_id;
initial.commit09911bf2008-07-26 23:55:29517}
518
[email protected]310ebd6302011-10-10 19:06:28519void RenderViewImpl::AddObserver(RenderViewObserver* observer) {
[email protected]676126f72011-01-15 00:03:51520 observers_.AddObserver(observer);
521}
522
[email protected]310ebd6302011-10-10 19:06:28523void RenderViewImpl::RemoveObserver(RenderViewObserver* observer) {
524 observer->RenderViewGone();
[email protected]676126f72011-01-15 00:03:51525 observers_.RemoveObserver(observer);
526}
527
[email protected]310ebd6302011-10-10 19:06:28528WebKit::WebView* RenderViewImpl::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26529 return static_cast<WebKit::WebView*>(webwidget());
530}
531
[email protected]310ebd6302011-10-10 19:06:28532void RenderViewImpl::SetReportLoadProgressEnabled(bool enabled) {
[email protected]1a3c3cb2010-12-16 21:03:40533 if (!enabled) {
534 load_progress_tracker_.reset(NULL);
535 return;
536 }
537 if (load_progress_tracker_ == NULL)
538 load_progress_tracker_.reset(new LoadProgressTracker(this));
539}
540
[email protected]310ebd6302011-10-10 19:06:28541void RenderViewImpl::PluginCrashed(const FilePath& plugin_path) {
[email protected]a3a8fb6d2009-10-22 20:12:51542 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29543}
544
[email protected]310ebd6302011-10-10 19:06:28545void RenderViewImpl::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26546 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30547 // If the renderer is visible, set initial visibility and focus state.
548 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34549#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30550 delegate->SetContainerVisibility(true);
551 if (webview() && webview()->isActive())
552 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34553#endif
[email protected]49232292010-09-03 19:07:30554 }
[email protected]784ea1ab2010-09-18 00:02:34555 // Plugins start assuming the content has focus (so that they work in
556 // environments where RenderView isn't hosting them), so we always have to
557 // set the initial state. See webplugin_delegate_impl.h for details.
558 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26559}
560
[email protected]310ebd6302011-10-10 19:06:28561void RenderViewImpl::UnregisterPluginDelegate(
562 WebPluginDelegateProxy* delegate) {
[email protected]d8fd6fa2010-02-01 15:54:26563 plugin_delegates_.erase(delegate);
564}
[email protected]d8fd6fa2010-02-01 15:54:26565
[email protected]310ebd6302011-10-10 19:06:28566bool RenderViewImpl::GetPluginInfo(const GURL& url,
567 const GURL& page_url,
568 const std::string& mime_type,
569 webkit::WebPluginInfo* plugin_info,
570 std::string* actual_mime_type) {
[email protected]4a7d6392011-09-19 20:55:08571 bool found = false;
572 Send(new ViewHostMsg_GetPluginInfo(
573 routing_id_, url, page_url, mime_type, &found, plugin_info,
574 actual_mime_type));
575 return found;
576}
577
[email protected]310ebd6302011-10-10 19:06:28578bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27579 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27580 if (main_frame)
[email protected]b6cb3a842011-06-24 18:28:41581 content::GetContentClient()->SetActiveURL(main_frame->document().url());
[email protected]f8b6b6f2009-03-10 16:48:26582
[email protected]676126f72011-01-15 00:03:51583 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
584 RenderViewObserver* observer;
585 while ((observer = it.GetNext()) != NULL)
586 if (observer->OnMessageReceived(message))
587 return true;
[email protected]b2abac72009-02-26 12:39:28588
[email protected]a95986a82010-12-24 06:19:28589 bool handled = true;
[email protected]ffc906f2011-10-04 22:55:40590 bool msg_is_ok = true;
[email protected]310ebd6302011-10-10 19:06:28591 IPC_BEGIN_MESSAGE_MAP_EX(RenderViewImpl, message, msg_is_ok)
initial.commit09911bf2008-07-26 23:55:29592 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
593 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56594 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29595 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
596 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
597 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
598 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27599#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35600 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27601#endif
initial.commit09911bf2008-07-26 23:55:29602 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
[email protected]44bf7002011-10-16 02:46:15603 IPC_MESSAGE_HANDLER(ViewMsg_PasteAndMatchStyle, OnPasteAndMatchStyle)
initial.commit09911bf2008-07-26 23:55:29604 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
605 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
606 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
[email protected]4fb60142011-08-09 02:22:08607 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
initial.commit09911bf2008-07-26 23:55:29608 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15609 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29610 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49611 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
612 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17613 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]d0b8d092010-10-25 04:05:17614 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]47578fa02011-11-02 19:34:41615 IPC_MESSAGE_HANDLER(ViewMsg_ZoomFactor, OnZoomFactor)
[email protected]9d797f32010-04-23 07:17:54616 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
617 OnSetZoomLevelForLoadingURL)
[email protected]8a5e0ca2011-08-25 06:30:47618 IPC_MESSAGE_HANDLER(ViewMsg_ExitFullscreen, OnExitFullscreen)
initial.commit09911bf2008-07-26 23:55:29619 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:18620 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
621 OnResetPageEncodingToDefault)
initial.commit09911bf2008-07-26 23:55:29622 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:48623 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:29624 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
[email protected]59f4f2fa2011-03-23 01:00:55625 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter)
626 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver)
627 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave)
628 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop)
629 IPC_MESSAGE_HANDLER(DragMsg_SourceEndedOrMoved, OnDragSourceEndedOrMoved)
630 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded,
631 OnDragSourceSystemDragEnded)
[email protected]18cb2572008-08-21 20:34:45632 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
[email protected]d0980792011-02-13 19:41:40633 IPC_MESSAGE_HANDLER(ViewMsg_SetWebUIProperty, OnSetWebUIProperty)
initial.commit09911bf2008-07-26 23:55:29634 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]333ec8d02011-09-16 18:59:19635 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoRect,
636 OnScrollFocusedEditableNodeIntoRect)
initial.commit09911bf2008-07-26 23:55:29637 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
638 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
639 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
[email protected]600ea402011-04-12 00:01:51640 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse,
641 OnEnumerateDirectoryResponse)
initial.commit09911bf2008-07-26 23:55:29642 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
[email protected]9b18a84f2010-06-10 15:54:04643 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
[email protected]992db4c2011-05-12 15:37:15644 IPC_MESSAGE_HANDLER(ViewMsg_SwapOut, OnSwapOut)
initial.commit09911bf2008-07-26 23:55:29645 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
646 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]0aa55312008-10-17 21:53:08647 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
648 OnDisassociateFromPopupCount)
[email protected]30f75e62009-02-25 22:01:00649 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]05d478752009-04-08 23:38:16650 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:14651 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:25652 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
653 OnEnablePreferredSizeChangedMode)
[email protected]cda45c02010-02-25 19:28:10654 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
655 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:51656 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]581b87eb2009-07-23 23:06:56657 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:34658 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:14659#if defined(OS_MACOSX)
660 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:13661 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:13662 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
663 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:14664#endif
[email protected]446705872009-09-10 07:22:48665 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:33666 OnSetEditCommandsForNextKeyEvent)
[email protected]a0c7153e2009-12-09 14:36:33667 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
668 OnCustomContextMenuAction)
[email protected]27a9ef32010-09-10 04:06:24669 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]eb415bf0e2011-04-14 02:45:42670 IPC_MESSAGE_HANDLER(ViewMsg_PpapiBrokerChannelCreated,
671 OnPpapiBrokerChannelCreated)
[email protected]18d5be92011-07-25 18:00:19672 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
673 OnGetAllSavableResourceLinksForCurrentPage)
674 IPC_MESSAGE_HANDLER(
675 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
676 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
[email protected]caf706f2010-10-26 17:54:08677#if defined(OS_MACOSX)
678 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
679#endif
[email protected]521b2482011-01-15 00:10:10680 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]f0557932011-01-25 20:20:51681 // TODO(viettrungluu): Move to a separate message filter.
682#if defined(ENABLE_FLAPPER_HACKS)
683 IPC_MESSAGE_HANDLER(PepperMsg_ConnectTcpACK, OnConnectTcpACK)
684#endif
[email protected]54ca3ca892011-06-07 21:14:54685#if defined(OS_MACOSX)
686 IPC_MESSAGE_HANDLER(ViewMsg_SetInLiveResize, OnSetInLiveResize)
687#endif
[email protected]9e1ad4b2011-08-14 16:49:19688 IPC_MESSAGE_HANDLER(ViewMsg_SetHistoryLengthAndPrune,
689 OnSetHistoryLengthAndPrune)
[email protected]5a7b15a2011-08-22 22:48:18690 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
[email protected]67bfb83f2011-09-22 03:36:37691 IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
692 IPC_MESSAGE_HANDLER(ViewMsg_MouseLockLost, OnMouseLockLost)
[email protected]7f3c7af2011-10-20 22:52:51693 IPC_MESSAGE_HANDLER(JavaBridgeMsg_Init, OnJavaBridgeInit)
[email protected]9e1ad4b2011-08-14 16:49:19694
initial.commit09911bf2008-07-26 23:55:29695 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:28696 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:29697 IPC_END_MESSAGE_MAP()
[email protected]ffc906f2011-10-04 22:55:40698
699 if (!msg_is_ok) {
700 // The message had a handler, but its deserialization failed.
701 // Kill the renderer to avoid potential spoofing attacks.
[email protected]310ebd6302011-10-10 19:06:28702 CHECK(false) << "Unable to deserialize message in RenderViewImpl.";
[email protected]ffc906f2011-10-04 22:55:40703 }
704
[email protected]a95986a82010-12-24 06:19:28705 return handled;
initial.commit09911bf2008-07-26 23:55:29706}
707
[email protected]310ebd6302011-10-10 19:06:28708void RenderViewImpl::OnNavigate(const ViewMsg_Navigate_Params& params) {
initial.commit09911bf2008-07-26 23:55:29709 if (!webview())
710 return;
711
[email protected]440a0e52011-09-13 17:38:58712 FOR_EACH_OBSERVER(RenderViewObserver, observers_, Navigate(params.url));
713
[email protected]007733c2011-11-17 00:34:07714 bool is_reload = IsReload(params);
[email protected]d466b8a2011-07-15 21:48:03715
716 // If this is a stale back/forward (due to a recent navigation the browser
717 // didn't know about), ignore it.
718 if (IsBackForwardToStaleEntry(params, is_reload))
719 return;
720
[email protected]992db4c2011-05-12 15:37:15721 // Swap this renderer back in if necessary.
722 if (is_swapped_out_)
723 SetSwappedOut(false);
724
[email protected]3cc72b12010-03-18 23:03:00725 history_list_offset_ = params.current_history_list_offset;
726 history_list_length_ = params.current_history_list_length;
[email protected]d466b8a2011-07-15 21:48:03727 if (history_list_length_ >= 0)
728 history_page_ids_.resize(history_list_length_, -1);
729 if (params.pending_history_list_offset >= 0 &&
730 params.pending_history_list_offset < history_list_length_)
731 history_page_ids_[params.pending_history_list_offset] = params.page_id;
[email protected]3cc72b12010-03-18 23:03:00732
[email protected]38b592902011-04-16 02:08:42733 content::GetContentClient()->SetActiveURL(params.url);
initial.commit09911bf2008-07-26 23:55:29734
[email protected]26aa0482009-09-30 16:55:27735 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:45736 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:29737 // We cannot reload if we do not have any history state. This happens, for
738 // example, when recovering from a crash. Our workaround here is a bit of
739 // a hack since it means that reload after a crashed tab does not cause an
740 // end-to-end cache validation.
741 is_reload = false;
742 }
743
[email protected]007733c2011-11-17 00:34:07744 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
745 *pending_navigation_params_.get() = params;
[email protected]48a5c772011-04-18 23:50:50746
[email protected]04d3c6e2009-05-22 17:00:13747 // If we are reloading, then WebKit will use the history state of the current
748 // page, so we should just ignore any given history state. Otherwise, if we
749 // have history state, then we need to navigate to it, which corresponds to a
750 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:55751 if (is_reload) {
[email protected]ecbf10d2010-02-18 13:03:29752 bool ignore_cache = (params.navigation_type ==
[email protected]2c5569662011-03-22 20:45:02753 ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
[email protected]ecbf10d2010-02-18 13:03:29754 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:55755 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:13756 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:58757 DCHECK_NE(params.page_id, -1);
[email protected]dd7daa82009-08-10 05:46:45758 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:17759 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:13760 } else {
761 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:28762 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:29763
[email protected]e6f546c32009-07-01 17:12:55764 // A session history navigation should have been accompanied by state.
765 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:13766
[email protected]dd7daa82009-08-10 05:46:45767 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:55768 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:13769
[email protected]726985e22009-06-18 21:09:28770 if (params.referrer.is_valid()) {
[email protected]20dc3cad2011-04-20 17:27:17771 if (!WebSecurityPolicy::shouldHideReferrer(
772 params.url,
773 WebString::fromUTF8(params.referrer.spec()))) {
774 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
775 WebString::fromUTF8(params.referrer.spec()));
776 }
[email protected]726985e22009-06-18 21:09:28777 }
[email protected]04d3c6e2009-05-22 17:00:13778
[email protected]52c68652010-12-07 17:47:04779 if (!params.extra_headers.empty()) {
780 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
781 params.extra_headers.end(), "\n");
782 i.GetNext(); ) {
783 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
784 WebString::fromUTF8(i.values()));
785 }
786 }
787
[email protected]dd7daa82009-08-10 05:46:45788 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:50789 }
790
[email protected]77f17a82009-05-21 04:42:54791 // In case LoadRequest failed before DidCreateDataSource was called.
[email protected]007733c2011-11-17 00:34:07792 pending_navigation_params_.reset();
initial.commit09911bf2008-07-26 23:55:29793}
794
[email protected]310ebd6302011-10-10 19:06:28795bool RenderViewImpl::IsBackForwardToStaleEntry(
[email protected]d466b8a2011-07-15 21:48:03796 const ViewMsg_Navigate_Params& params,
797 bool is_reload) {
798 // Make sure this isn't a back/forward to an entry we have already cropped
799 // or replaced from our history, before the browser knew about it. If so,
800 // a new navigation has committed in the mean time, and we can ignore this.
801 bool is_back_forward = !is_reload && !params.state.empty();
802
803 // Note: if the history_list_length_ is 0 for a back/forward, we must be
804 // restoring from a previous session. We'll update our state in OnNavigate.
805 if (!is_back_forward || history_list_length_ <= 0)
806 return false;
807
808 DCHECK_EQ(static_cast<int>(history_page_ids_.size()), history_list_length_);
809
810 // Check for whether the forward history has been cropped due to a recent
811 // navigation the browser didn't know about.
812 if (params.pending_history_list_offset >= history_list_length_)
813 return true;
814
815 // Check for whether this entry has been replaced with a new one.
816 int expected_page_id =
817 history_page_ids_[params.pending_history_list_offset];
[email protected]9978b8f02011-08-13 16:17:44818 if (expected_page_id > 0 && params.page_id != expected_page_id) {
819 if (params.page_id < expected_page_id)
820 return true;
821
822 // Otherwise we've removed an earlier entry and should have shifted all
823 // entries left. For now, it's ok to lazily update the list.
824 // TODO(creis): Notify all live renderers when we remove entries from
825 // the front of the list, so that we don't hit this case.
826 history_page_ids_[params.pending_history_list_offset] = params.page_id;
827 }
[email protected]d466b8a2011-07-15 21:48:03828
829 return false;
830}
831
initial.commit09911bf2008-07-26 23:55:29832// Stop loading the current page
[email protected]310ebd6302011-10-10 19:06:28833void RenderViewImpl::OnStop() {
[email protected]6a8f5112011-05-13 16:38:44834 if (webview()) {
835 WebFrame* main_frame = webview()->mainFrame();
836 // Stop the alt error page fetcher. If we let it continue it may complete
837 // and cause RenderViewHostManager to swap to this RenderView, even though
838 // it may no longer be active.
839 StopAltErrorPageFetcher(main_frame->provisionalDataSource());
840 StopAltErrorPageFetcher(main_frame->dataSource());
841 main_frame->stopLoading();
842 }
initial.commit09911bf2008-07-26 23:55:29843}
844
[email protected]ecbf10d2010-02-18 13:03:29845// Reload current focused frame.
846// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]310ebd6302011-10-10 19:06:28847void RenderViewImpl::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:29848 if (webview() && webview()->focusedFrame()) {
849 // We always obey the cache (ignore_cache=false) here.
850 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
851 // a cache-ignoring reload of the frame.
852 webview()->focusedFrame()->reload(false);
853 }
[email protected]1dda4022010-01-28 18:24:56854}
855
[email protected]310ebd6302011-10-10 19:06:28856void RenderViewImpl::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:27857 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:29858}
859
[email protected]310ebd6302011-10-10 19:06:28860void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
[email protected]68b1e922009-06-23 16:00:25861 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:27862 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:25863 return;
864
[email protected]26aa0482009-09-30 16:55:27865 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:45866 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:25867}
868
[email protected]310ebd6302011-10-10 19:06:28869void RenderViewImpl::OnUpdateTargetURLAck() {
initial.commit09911bf2008-07-26 23:55:29870 // Check if there is a targeturl waiting to be sent.
871 if (target_url_status_ == TARGET_PENDING) {
872 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
873 pending_target_url_));
874 }
875
876 target_url_status_ = TARGET_NONE;
877}
878
[email protected]310ebd6302011-10-10 19:06:28879void RenderViewImpl::OnUndo() {
initial.commit09911bf2008-07-26 23:55:29880 if (!webview())
881 return;
882
[email protected]26aa0482009-09-30 16:55:27883 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
initial.commit09911bf2008-07-26 23:55:29884}
885
[email protected]310ebd6302011-10-10 19:06:28886void RenderViewImpl::OnRedo() {
initial.commit09911bf2008-07-26 23:55:29887 if (!webview())
888 return;
889
[email protected]26aa0482009-09-30 16:55:27890 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
initial.commit09911bf2008-07-26 23:55:29891}
892
[email protected]310ebd6302011-10-10 19:06:28893void RenderViewImpl::OnCut() {
initial.commit09911bf2008-07-26 23:55:29894 if (!webview())
895 return;
896
[email protected]26aa0482009-09-30 16:55:27897 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
initial.commit09911bf2008-07-26 23:55:29898}
899
[email protected]310ebd6302011-10-10 19:06:28900void RenderViewImpl::OnCopy() {
initial.commit09911bf2008-07-26 23:55:29901 if (!webview())
902 return;
903
[email protected]f6b1856b2011-06-29 22:02:53904 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
905 context_menu_node_);
initial.commit09911bf2008-07-26 23:55:29906}
907
[email protected]c0cc3092009-09-12 08:27:27908#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:28909void RenderViewImpl::OnCopyToFindPboard() {
[email protected]a954bf72009-09-12 07:30:35910 if (!webview())
911 return;
912
913 // Since the find pasteboard supports only plain text, this can be simpler
914 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:27915 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:35916 if (frame->hasSelection()) {
917 string16 selection = frame->selectionAsText();
[email protected]380244092011-10-07 17:26:27918 RenderThread::Get()->Send(
[email protected]7e3589742011-03-10 18:49:17919 new ClipboardHostMsg_FindPboardWriteStringAsync(selection));
[email protected]a954bf72009-09-12 07:30:35920 }
[email protected]a954bf72009-09-12 07:30:35921}
[email protected]c0cc3092009-09-12 08:27:27922#endif
[email protected]a954bf72009-09-12 07:30:35923
[email protected]310ebd6302011-10-10 19:06:28924void RenderViewImpl::OnPaste() {
initial.commit09911bf2008-07-26 23:55:29925 if (!webview())
926 return;
927
[email protected]26aa0482009-09-30 16:55:27928 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
initial.commit09911bf2008-07-26 23:55:29929}
930
[email protected]44bf7002011-10-16 02:46:15931void RenderViewImpl::OnPasteAndMatchStyle() {
932 if (!webview())
933 return;
934
935 webview()->focusedFrame()->executeCommand(
936 WebString::fromUTF8("PasteAndMatchStyle"));
937}
938
[email protected]310ebd6302011-10-10 19:06:28939void RenderViewImpl::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:29940 if (!webview())
941 return;
942
[email protected]1ff7a032010-02-03 02:46:03943 WebFrame* frame = webview()->focusedFrame();
944 if (!frame->hasSelection())
945 frame->selectWordAroundCaret();
946 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:29947}
948
[email protected]310ebd6302011-10-10 19:06:28949void RenderViewImpl::OnDelete() {
initial.commit09911bf2008-07-26 23:55:29950 if (!webview())
951 return;
952
[email protected]26aa0482009-09-30 16:55:27953 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
initial.commit09911bf2008-07-26 23:55:29954}
955
[email protected]310ebd6302011-10-10 19:06:28956void RenderViewImpl::OnSelectAll() {
initial.commit09911bf2008-07-26 23:55:29957 if (!webview())
958 return;
959
[email protected]26aa0482009-09-30 16:55:27960 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:22961 WebString::fromUTF8("SelectAll"));
initial.commit09911bf2008-07-26 23:55:29962}
963
[email protected]310ebd6302011-10-10 19:06:28964void RenderViewImpl::OnSelectRange(const gfx::Point& start,
965 const gfx::Point& end) {
[email protected]4fb60142011-08-09 02:22:08966 if (!webview())
967 return;
968
969 handling_select_range_ = true;
970 webview()->focusedFrame()->selectRange(start, end);
971 handling_select_range_ = false;
972}
973
[email protected]310ebd6302011-10-10 19:06:28974void RenderViewImpl::OnSetHistoryLengthAndPrune(int history_length,
975 int32 minimum_page_id) {
[email protected]9e1ad4b2011-08-14 16:49:19976 DCHECK(history_length >= 0);
977 DCHECK(history_list_offset_ == history_list_length_ - 1);
978 DCHECK(minimum_page_id >= -1);
979
980 // Generate the new list.
981 std::vector<int32> new_history_page_ids(history_length, -1);
982 for (size_t i = 0; i < history_page_ids_.size(); ++i) {
983 if (minimum_page_id >= 0 && history_page_ids_[i] < minimum_page_id)
984 continue;
985 new_history_page_ids.push_back(history_page_ids_[i]);
986 }
987 new_history_page_ids.swap(history_page_ids_);
988
989 // Update indexes.
990 history_list_length_ = history_page_ids_.size();
991 history_list_offset_ = history_list_length_ - 1;
992}
993
994
[email protected]310ebd6302011-10-10 19:06:28995void RenderViewImpl::OnSetInitialFocus(bool reverse) {
initial.commit09911bf2008-07-26 23:55:29996 if (!webview())
997 return;
[email protected]26aa0482009-09-30 16:55:27998 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:29999}
1000
[email protected]54ca3ca892011-06-07 21:14:541001#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:281002void RenderViewImpl::OnSetInLiveResize(bool in_live_resize) {
[email protected]4274b3e2011-08-09 19:09:331003 if (!webview())
1004 return;
1005 if (in_live_resize)
1006 webview()->willStartLiveResize();
1007 else
1008 webview()->willEndLiveResize();
[email protected]54ca3ca892011-06-07 21:14:541009}
1010#endif
1011
[email protected]310ebd6302011-10-10 19:06:281012void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1013 const gfx::Rect& rect) {
[email protected]13a1e4c3c2011-02-03 21:07:091014 WebKit::WebNode node = GetFocusedNode();
1015 if (!node.isNull()) {
1016 if (IsEditableNode(node))
[email protected]333ec8d02011-09-16 18:59:191017 webview()->scrollFocusedNodeIntoRect(rect);
[email protected]9b66f34bf2010-10-27 20:45:511018 }
1019}
1020
initial.commit09911bf2008-07-26 23:55:291021///////////////////////////////////////////////////////////////////////////////
1022
1023// Tell the embedding application that the URL of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281024void RenderViewImpl::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451025 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291026 DCHECK(ds);
1027
[email protected]726985e22009-06-18 21:09:281028 const WebURLRequest& request = ds->request();
1029 const WebURLRequest& original_request = ds->originalRequest();
1030 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291031
[email protected]007733c2011-11-17 00:34:071032 DocumentState* document_state = DocumentState::FromDataSource(ds);
1033 NavigationState* navigation_state = document_state->navigation_state();
initial.commit09911bf2008-07-26 23:55:291034
1035 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281036 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291037 params.is_post = false;
1038 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071039 params.frame_id = frame->identifier();
[email protected]6d81b482011-02-22 19:47:191040 params.socket_address.set_host(response.remoteIPAddress().utf8());
1041 params.socket_address.set_port(response.remotePort());
[email protected]b9a7c6d42011-02-25 02:13:031042 params.was_fetched_via_proxy = response.wasFetchedViaProxy();
[email protected]af15bed2010-08-25 21:12:091043 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]007733c2011-11-17 00:34:071044 if (!document_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291045 // SSL state specified in the request takes precedence over the one in the
1046 // response.
1047 // So far this is only intended for error pages that are not expected to be
1048 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281049 DCHECK(response.securityInfo().isEmpty());
[email protected]007733c2011-11-17 00:34:071050 params.security_info = document_state->security_info();
initial.commit09911bf2008-07-26 23:55:291051 } else {
[email protected]726985e22009-06-18 21:09:281052 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291053 }
1054
1055 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281056 if (ds->hasUnreachableURL()) {
1057 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291058 } else {
[email protected]726985e22009-06-18 21:09:281059 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291060 }
1061
[email protected]726985e22009-06-18 21:09:281062 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241063 params.should_update_history = !ds->hasUnreachableURL() &&
[email protected]b7df1b72011-02-10 00:08:041064 !response.isMultipartPayload() && (response.httpStatusCode() != 404);
initial.commit09911bf2008-07-26 23:55:291065
[email protected]007733c2011-11-17 00:34:071066 params.searchable_form_url = document_state->searchable_form_url();
[email protected]ce0e250d2009-10-23 21:00:351067 params.searchable_form_encoding =
[email protected]007733c2011-11-17 00:34:071068 document_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291069
1070 const PasswordForm* password_form_data =
[email protected]007733c2011-11-17 00:34:071071 document_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291072 if (password_form_data)
1073 params.password_form = *password_form_data;
1074
1075 params.gesture = navigation_gesture_;
1076 navigation_gesture_ = NavigationGestureUnknown;
1077
[email protected]0f38dc4552011-02-25 11:24:001078 // Make navigation state a part of the FrameNavigate message so that commited
1079 // entry had it at all times.
1080 const WebHistoryItem& item = frame->currentHistoryItem();
1081 if (!item.isNull()) {
1082 params.content_state = webkit_glue::HistoryItemToString(item);
1083 } else {
1084 params.content_state =
1085 webkit_glue::CreateHistoryStateForURL(GURL(request.url()));
1086 }
1087
[email protected]dd7daa82009-08-10 05:46:451088 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291089 // Top-level navigation.
1090
[email protected]b75b8292010-10-01 07:28:251091 // Set zoom level, but don't do it for full-page plugin since they don't use
1092 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011093 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541094 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251095 if (webview()->mainFrame()->document().isPluginDocument()) {
1096 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251097 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251098 } else {
1099 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251100 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251101 }
1102
[email protected]f85f0702010-01-30 09:31:011103 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511104 // This zoom level was merely recorded transiently for this load. We can
1105 // erase it now. If at some point we reload this page, the browser will
1106 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011107 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511108 }
1109
[email protected]b75b8292010-10-01 07:28:251110 // Reset the zoom limits in case a plugin had changed them previously. This
1111 // will also call us back which will cause us to send a message to
1112 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251113 webview()->zoomLimitsChanged(
[email protected]0f083402011-11-22 02:59:011114 WebView::zoomFactorToZoomLevel(content::kMinimumZoomFactor),
1115 WebView::zoomFactorToZoomLevel(content::kMaximumZoomFactor));
[email protected]b75b8292010-10-01 07:28:251116
initial.commit09911bf2008-07-26 23:55:291117 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551118 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291119
[email protected]daa8c58e2009-06-15 17:21:101120 params.transition = navigation_state->transition_type();
[email protected]2905f742011-10-13 03:51:581121 if (!content::PageTransitionIsMainFrame(params.transition)) {
initial.commit09911bf2008-07-26 23:55:291122 // If the main frame does a load, it should not be reported as a subframe
1123 // navigation. This can occur in the following case:
1124 // 1. You're on a site with frames.
1125 // 2. You do a subframe navigation. This is stored with transition type
1126 // MANUAL_SUBFRAME.
1127 // 3. You navigate to some non-frame site, say, google.com.
1128 // 4. You navigate back to the page from step 2. Since it was initially
1129 // MANUAL_SUBFRAME, it will be that same transition type here.
1130 // We don't want that, because any navigation that changes the toplevel
1131 // frame should be tracked as a toplevel navigation (this allows us to
1132 // update the URL bar, etc).
[email protected]2905f742011-10-13 03:51:581133 params.transition = content::PAGE_TRANSITION_LINK;
initial.commit09911bf2008-07-26 23:55:291134 }
1135
initial.commit09911bf2008-07-26 23:55:291136 // If we have a valid consumed client redirect source,
1137 // the page contained a client redirect (meta refresh, document.loc...),
1138 // so we set the referrer and transition to match.
1139 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041140 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291141 params.referrer = completed_client_redirect_src_;
[email protected]2905f742011-10-13 03:51:581142 params.transition = static_cast<content::PageTransition>(
1143 params.transition | content::PAGE_TRANSITION_CLIENT_REDIRECT);
initial.commit09911bf2008-07-26 23:55:291144 } else {
1145 // Bug 654101: the referrer will be empty on https->http transitions. It
1146 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281147 params.referrer = GURL(
1148 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291149 }
1150
[email protected]726985e22009-06-18 21:09:281151 string16 method = request.httpMethod();
1152 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291153 params.is_post = true;
1154
[email protected]c2a797d2009-09-21 16:46:321155 // Save some histogram data so we can compute the average memory used per
1156 // page load of the glyphs.
1157 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1158 webkit_glue::GetGlyphPageCount());
1159
[email protected]15cf526b2010-02-12 06:33:491160 // This message needs to be sent before any of allowScripts(),
1161 // allowImages(), allowPlugins() is called for the new page, so that when
1162 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1163 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291164 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1165 } else {
1166 // Subframe navigation: the type depends on whether this navigation
1167 // generated a new session history entry. When they do generate a session
1168 // history entry, it means the user initiated the navigation and we should
1169 // mark it as such. This test checks if this is the first time UpdateURL
1170 // has been called since WillNavigateToURL was called to initiate the load.
1171 if (page_id_ > last_page_id_sent_to_browser_)
[email protected]2905f742011-10-13 03:51:581172 params.transition = content::PAGE_TRANSITION_MANUAL_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291173 else
[email protected]2905f742011-10-13 03:51:581174 params.transition = content::PAGE_TRANSITION_AUTO_SUBFRAME;
initial.commit09911bf2008-07-26 23:55:291175
initial.commit09911bf2008-07-26 23:55:291176 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1177 }
1178
1179 last_page_id_sent_to_browser_ =
1180 std::max(last_page_id_sent_to_browser_, page_id_);
1181
1182 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101183 // we don't want the transition type to persist. Just clear it.
[email protected]2905f742011-10-13 03:51:581184 navigation_state->set_transition_type(content::PAGE_TRANSITION_LINK);
initial.commit09911bf2008-07-26 23:55:291185}
1186
1187// Tell the embedding application that the title of the active page has changed
[email protected]310ebd6302011-10-10 19:06:281188void RenderViewImpl::UpdateTitle(WebFrame* frame,
1189 const string16& title,
1190 WebTextDirection title_direction) {
[email protected]a49e10b2011-08-01 23:57:461191 // Ignore all but top level navigations.
1192 if (frame->parent())
1193 return;
1194
1195 string16 shortened_title = title.substr(0, content::kMaxTitleChars);
1196 Send(new ViewHostMsg_UpdateTitle(routing_id_, page_id_, shortened_title,
1197 title_direction));
initial.commit09911bf2008-07-26 23:55:291198}
1199
[email protected]310ebd6302011-10-10 19:06:281200void RenderViewImpl::UpdateEncoding(WebFrame* frame,
1201 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291202 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271203 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291204 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301205 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291206 last_encoding_name_ = encoding_name;
1207
[email protected]e38f40152008-09-12 23:08:301208 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291209 }
1210}
1211
[email protected]e15f680732010-11-23 22:30:201212// Sends the last committed session history state to the browser so it will be
1213// saved before we navigate to a new page. This must be called *before* the
1214// page ID has been updated so we know what it was.
[email protected]310ebd6302011-10-10 19:06:281215void RenderViewImpl::UpdateSessionHistory(WebFrame* frame) {
initial.commit09911bf2008-07-26 23:55:291216 // If we have a valid page ID at this point, then it corresponds to the page
1217 // we are navigating away from. Otherwise, this is the first navigation, so
1218 // there is no past session history to record.
1219 if (page_id_ == -1)
1220 return;
1221
[email protected]ca948a22009-06-25 19:36:171222 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271223 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171224 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291225 return;
[email protected]ca948a22009-06-25 19:36:171226
1227 Send(new ViewHostMsg_UpdateState(
1228 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291229}
1230
[email protected]310ebd6302011-10-10 19:06:281231void RenderViewImpl::OpenURL(WebFrame* frame,
1232 const GURL& url,
1233 const GURL& referrer,
1234 WebNavigationPolicy policy) {
[email protected]3d9689372009-09-10 04:29:171235 Send(new ViewHostMsg_OpenURL(
[email protected]ae5184d62011-10-06 19:25:581236 routing_id_,
1237 url,
1238 referrer,
1239 NavigationPolicyToDisposition(policy),
1240 frame->identifier()));
[email protected]3d9689372009-09-10 04:29:171241}
1242
[email protected]79dbc662009-09-04 05:42:511243// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291244
[email protected]310ebd6302011-10-10 19:06:281245void RenderViewImpl::LoadNavigationErrorPage(
1246 WebFrame* frame,
1247 const WebURLRequest& failed_request,
1248 const WebURLError& error,
1249 const std::string& html,
1250 bool replace) {
[email protected]d7b175e2011-10-11 15:31:581251 std::string alt_html;
1252 const std::string* error_html;
1253
1254 if (!html.empty()) {
1255 error_html = &html;
1256 } else {
1257 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
1258 failed_request, error, &alt_html, NULL);
1259 error_html = &alt_html;
1260 }
1261
1262 frame->loadHTMLString(*error_html,
[email protected]144143c2010-10-28 08:17:361263 GURL(chrome::kUnreachableWebDataURL),
[email protected]21d61e52011-03-18 19:08:251264 error.unreachableURL,
[email protected]e6f546c32009-07-01 17:12:551265 replace);
initial.commit09911bf2008-07-26 23:55:291266}
1267
[email protected]310ebd6302011-10-10 19:06:281268bool RenderViewImpl::RunJavaScriptMessage(int type,
1269 const string16& message,
1270 const string16& default_value,
1271 const GURL& frame_url,
1272 string16* result) {
initial.commit09911bf2008-07-26 23:55:291273 bool success = false;
[email protected]4f5ce842011-05-27 19:34:411274 string16 result_temp;
initial.commit09911bf2008-07-26 23:55:291275 if (!result)
1276 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291277
[email protected]12636df2009-09-28 22:32:211278 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1279 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291280 return success;
1281}
1282
[email protected]310ebd6302011-10-10 19:06:281283bool RenderViewImpl::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
[email protected]c1f50aa2010-02-18 03:46:571284 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1285 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1286 // it is particularly important that we do not call willEnterModalLoop as
1287 // that would defer resource loads for the dialog itself.
[email protected]f1a29a02011-10-06 23:08:441288 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1289 RenderThreadImpl::current()->DoNotNotifyWebKitOfModalLoop();
[email protected]c1f50aa2010-02-18 03:46:571290
1291 message->EnableMessagePumping(); // Runs a nested message loop.
1292 return Send(message);
1293}
1294
[email protected]48c9cf2d2009-09-16 16:47:521295// WebKit::WebViewClient ------------------------------------------------------
1296
[email protected]310ebd6302011-10-10 19:06:281297WebView* RenderViewImpl::createView(
[email protected]844acf372011-01-14 10:49:271298 WebFrame* creator,
1299 const WebURLRequest& request,
1300 const WebWindowFeatures& features,
1301 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:521302 // Check to make sure we aren't overloading on popups.
1303 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
1304 return NULL;
1305
[email protected]8ab04652010-06-12 02:47:261306 ViewHostMsg_CreateWindow_Params params;
1307 params.opener_id = routing_id_;
1308 params.user_gesture = creator->isProcessingUserGesture();
1309 params.window_container_type = WindowFeaturesToContainerType(features);
1310 params.session_storage_namespace_id = session_storage_namespace_id_;
1311 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:111312 params.opener_frame_id = creator->identifier();
[email protected]b6cb3a842011-06-24 18:28:411313 params.opener_url = creator->document().url();
1314 params.opener_security_origin =
1315 creator->document().securityOrigin().toString().utf8();
[email protected]41e65502011-01-21 09:29:111316 if (!request.isNull())
1317 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:261318
[email protected]48c9cf2d2009-09-16 16:47:521319 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:341320 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:261321 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:521322
[email protected]380244092011-10-07 17:26:271323 RenderThread::Get()->Send(
[email protected]8ab04652010-06-12 02:47:261324 new ViewHostMsg_CreateWindow(params,
1325 &routing_id,
1326 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:211327 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:521328 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521329
[email protected]310ebd6302011-10-10 19:06:281330 RenderViewImpl* view = RenderViewImpl::Create(
1331 0,
1332 routing_id_,
1333 renderer_preferences_,
1334 webkit_preferences_,
1335 shared_popup_counter_,
1336 routing_id,
1337 cloned_session_storage_namespace_id,
1338 frame_name);
[email protected]8ab04652010-06-12 02:47:261339 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:521340
[email protected]007a848b2009-10-26 15:55:461341 // Record whether the creator frame is trying to suppress the opener field.
1342 view->opener_suppressed_ = opener_suppressed;
1343
[email protected]48c9cf2d2009-09-16 16:47:521344 // Record the security origin of the creator.
[email protected]b6cb3a842011-06-24 18:28:411345 GURL creator_url(creator->document().securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:521346 if (!creator_url.is_valid() || !creator_url.IsStandard())
1347 creator_url = GURL();
1348 view->creator_url_ = creator_url;
1349
1350 // Copy over the alternate error page URL so we can have alt error pages in
1351 // the new render view (we don't need the browser to send the URL back down).
1352 view->alternate_error_page_url_ = alternate_error_page_url_;
1353
1354 return view->webview();
1355}
1356
[email protected]310ebd6302011-10-10 19:06:281357WebWidget* RenderViewImpl::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]380244092011-10-07 17:26:271358 RenderWidget* widget = RenderWidget::Create(routing_id_, popup_type);
[email protected]48c9cf2d2009-09-16 16:47:521359 return widget->webwidget();
1360}
1361
[email protected]310ebd6302011-10-10 19:06:281362WebWidget* RenderViewImpl::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:441363 // TODO(jcivelli): Remove this deprecated method when its been removed from
1364 // the WebViewClient interface. It's been replaced by
1365 // createExternalPopupMenu.
1366 NOTREACHED();
1367 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:521368}
1369
[email protected]310ebd6302011-10-10 19:06:281370WebExternalPopupMenu* RenderViewImpl::createExternalPopupMenu(
[email protected]caf706f2010-10-26 17:54:081371 const WebPopupMenuInfo& popup_menu_info,
1372 WebExternalPopupMenuClient* popup_menu_client) {
1373 DCHECK(!external_popup_menu_.get());
1374 external_popup_menu_.reset(
1375 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
1376 return external_popup_menu_.get();
1377}
1378
[email protected]310ebd6302011-10-10 19:06:281379RenderWidgetFullscreenPepper* RenderViewImpl::CreatePepperFullscreenContainer(
[email protected]0bd753682010-12-16 18:15:521380 webkit::ppapi::PluginInstance* plugin) {
[email protected]d91233b7e2011-03-29 20:33:531381 GURL active_url;
[email protected]d91ddfc2011-04-07 18:33:421382 if (webview() && webview()->mainFrame())
[email protected]b6cb3a842011-06-24 18:28:411383 active_url = GURL(webview()->mainFrame()->document().url());
[email protected]d91233b7e2011-03-29 20:33:531384 RenderWidgetFullscreenPepper* widget = RenderWidgetFullscreenPepper::Create(
[email protected]380244092011-10-07 17:26:271385 routing_id_, plugin, active_url);
[email protected]79c7bed2010-09-14 22:28:391386 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:561387 return widget;
[email protected]79c7bed2010-09-14 22:28:391388}
1389
[email protected]310ebd6302011-10-10 19:06:281390WebStorageNamespace* RenderViewImpl::createSessionStorageNamespace(
1391 unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:341392 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:391393 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:291394 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
1395 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
1396 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:341397}
1398
[email protected]310ebd6302011-10-10 19:06:281399void RenderViewImpl::didAddMessageToConsole(
[email protected]48c9cf2d2009-09-16 16:47:521400 const WebConsoleMessage& message, const WebString& source_name,
1401 unsigned source_line) {
[email protected]d09df4b2011-04-11 19:01:081402 logging::LogSeverity log_severity = logging::LOG_VERBOSE;
[email protected]f7eb0a392011-07-12 10:19:511403 switch (message.level) {
[email protected]d09df4b2011-04-11 19:01:081404 case WebConsoleMessage::LevelTip:
1405 log_severity = logging::LOG_VERBOSE;
1406 break;
1407 case WebConsoleMessage::LevelLog:
1408 log_severity = logging::LOG_INFO;
1409 break;
1410 case WebConsoleMessage::LevelWarning:
1411 log_severity = logging::LOG_WARNING;
1412 break;
1413 case WebConsoleMessage::LevelError:
1414 log_severity = logging::LOG_ERROR;
1415 break;
1416 default:
1417 NOTREACHED();
1418 }
1419
[email protected]48c9cf2d2009-09-16 16:47:521420 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
[email protected]d09df4b2011-04-11 19:01:081421 static_cast<int32>(log_severity),
[email protected]aa21d2a2011-08-08 23:56:311422 message.text,
[email protected]48c9cf2d2009-09-16 16:47:521423 static_cast<int32>(source_line),
[email protected]aa21d2a2011-08-08 23:56:311424 source_name));
[email protected]48c9cf2d2009-09-16 16:47:521425}
1426
[email protected]310ebd6302011-10-10 19:06:281427void RenderViewImpl::printPage(WebFrame* frame) {
[email protected]d91ddfc2011-04-07 18:33:421428 FOR_EACH_OBSERVER(RenderViewObserver, observers_, PrintPage(frame));
[email protected]48c9cf2d2009-09-16 16:47:521429}
1430
[email protected]310ebd6302011-10-10 19:06:281431WebKit::WebNotificationPresenter* RenderViewImpl::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:511432 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:021433}
1434
[email protected]310ebd6302011-10-10 19:06:281435bool RenderViewImpl::enumerateChosenDirectory(
[email protected]8a58c1c2011-04-19 18:40:121436 const WebString& path,
1437 WebFileChooserCompletion* chooser_completion) {
1438 int id = enumeration_completion_id_++;
1439 enumeration_completions_[id] = chooser_completion;
1440 return Send(new ViewHostMsg_EnumerateDirectory(
1441 routing_id_,
1442 id,
1443 webkit_glue::WebStringToFilePath(path)));
1444}
1445
[email protected]310ebd6302011-10-10 19:06:281446void RenderViewImpl::didStartLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521447 if (is_loading_) {
1448 DLOG(WARNING) << "didStartLoading called while loading";
1449 return;
1450 }
1451
1452 is_loading_ = true;
[email protected]48c9cf2d2009-09-16 16:47:521453
1454 Send(new ViewHostMsg_DidStartLoading(routing_id_));
[email protected]93b9d692011-04-13 00:44:311455
1456 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStartLoading());
[email protected]48c9cf2d2009-09-16 16:47:521457}
1458
[email protected]310ebd6302011-10-10 19:06:281459void RenderViewImpl::didStopLoading() {
[email protected]48c9cf2d2009-09-16 16:47:521460 if (!is_loading_) {
1461 DLOG(WARNING) << "DidStopLoading called while not loading";
1462 return;
1463 }
1464
1465 is_loading_ = false;
1466
1467 // NOTE: For now we're doing the safest thing, and sending out notification
1468 // when done loading. This currently isn't an issue as the favicon is only
1469 // displayed when done loading. Ideally we would send notification when
1470 // finished parsing the head, but webkit doesn't support that yet.
1471 // The feed discovery code would also benefit from access to the head.
[email protected]48c9cf2d2009-09-16 16:47:521472 Send(new ViewHostMsg_DidStopLoading(routing_id_));
1473
[email protected]90109412010-12-15 17:14:241474 if (load_progress_tracker_ != NULL)
1475 load_progress_tracker_->DidStopLoading();
1476
[email protected]93b9d692011-04-13 00:44:311477 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidStopLoading());
[email protected]48c9cf2d2009-09-16 16:47:521478}
1479
[email protected]310ebd6302011-10-10 19:06:281480void RenderViewImpl::didChangeLoadProgress(WebFrame* frame,
1481 double load_progress) {
[email protected]90109412010-12-15 17:14:241482 if (load_progress_tracker_ != NULL)
1483 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
1484}
1485
[email protected]310ebd6302011-10-10 19:06:281486bool RenderViewImpl::isSmartInsertDeleteEnabled() {
[email protected]f55039a2010-02-17 14:12:061487#if defined(OS_MACOSX)
1488 return true;
1489#else
1490 return false;
1491#endif
1492}
1493
[email protected]310ebd6302011-10-10 19:06:281494bool RenderViewImpl::isSelectTrailingWhitespaceEnabled() {
[email protected]04fc9482009-09-18 22:13:031495#if defined(OS_WIN)
1496 return true;
1497#else
1498 return false;
1499#endif
1500}
1501
[email protected]310ebd6302011-10-10 19:06:281502void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
[email protected]4fb60142011-08-09 02:22:081503 if (!handling_input_event_ && !handling_select_range_)
[email protected]04fc9482009-09-18 22:13:031504 return;
[email protected]4fb60142011-08-09 02:22:081505 handling_select_range_ = false;
[email protected]d4cff272011-05-02 15:46:011506
[email protected]b781ff282011-08-20 06:19:361507 SyncSelectionIfRequired();
[email protected]04fc9482009-09-18 22:13:031508}
1509
[email protected]310ebd6302011-10-10 19:06:281510void RenderViewImpl::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:121511 const std::string& name = UTF16ToUTF8(command_name);
1512 if (StartsWithASCII(name, "Move", true) ||
1513 StartsWithASCII(name, "Insert", true) ||
1514 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:031515 return;
[email protected]f1a29a02011-10-06 23:08:441516 RenderThreadImpl::current()->RecordUserMetrics(name);
[email protected]04fc9482009-09-18 22:13:031517}
1518
[email protected]310ebd6302011-10-10 19:06:281519bool RenderViewImpl::handleCurrentKeyboardEvent() {
[email protected]b2528b72009-09-24 06:57:101520 if (edit_commands_.empty())
1521 return false;
1522
[email protected]26aa0482009-09-30 16:55:271523 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:101524 if (!frame)
1525 return false;
1526
1527 EditCommands::iterator it = edit_commands_.begin();
1528 EditCommands::iterator end = edit_commands_.end();
1529
[email protected]507b33ea2009-09-29 03:56:511530 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:101531 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:331532 // In gtk and cocoa, it's possible to bind multiple edit commands to one
1533 // key (but it's the exception). Once one edit command is not executed, it
1534 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:101535 if (!frame->executeCommand(WebString::fromUTF8(it->name),
1536 WebString::fromUTF8(it->value)))
1537 break;
[email protected]507b33ea2009-09-29 03:56:511538 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:101539 }
1540
[email protected]507b33ea2009-09-29 03:56:511541 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:101542}
1543
[email protected]310ebd6302011-10-10 19:06:281544bool RenderViewImpl::runFileChooser(
[email protected]01178b52010-01-15 06:59:351545 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:471546 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:351547 // Do not open the file dialog in a hidden RenderView.
1548 if (is_hidden())
1549 return false;
[email protected]8caadeb2011-11-22 02:45:231550 content::FileChooserParams ipc_params;
[email protected]b5977a0c2010-08-24 19:46:261551 if (params.directory)
[email protected]8caadeb2011-11-22 02:45:231552 ipc_params.mode = content::FileChooserParams::OpenFolder;
[email protected]b5977a0c2010-08-24 19:46:261553 else if (params.multiSelect)
[email protected]8caadeb2011-11-22 02:45:231554 ipc_params.mode = content::FileChooserParams::OpenMultiple;
[email protected]459fba82011-10-13 02:48:501555 else if (params.saveAs)
[email protected]8caadeb2011-11-22 02:45:231556 ipc_params.mode = content::FileChooserParams::Save;
[email protected]b5977a0c2010-08-24 19:46:261557 else
[email protected]8caadeb2011-11-22 02:45:231558 ipc_params.mode = content::FileChooserParams::Open;
[email protected]cdaf8d02010-03-30 19:52:471559 ipc_params.title = params.title;
1560 ipc_params.default_file_name =
1561 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]3314c2b12011-11-02 08:05:461562 ipc_params.accept_types.reserve(params.acceptMIMETypes.size());
1563 for (size_t i = 0; i < params.acceptMIMETypes.size(); ++i)
1564 ipc_params.accept_types.push_back(params.acceptMIMETypes[i]);
[email protected]cdaf8d02010-03-30 19:52:471565
1566 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:461567}
1568
[email protected]310ebd6302011-10-10 19:06:281569void RenderViewImpl::runModalAlertDialog(
[email protected]48c9cf2d2009-09-16 16:47:521570 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061571 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]4f5ce842011-05-27 19:34:411572 message,
1573 string16(),
[email protected]b6cb3a842011-06-24 18:28:411574 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521575 NULL);
1576}
1577
[email protected]310ebd6302011-10-10 19:06:281578bool RenderViewImpl::runModalConfirmDialog(
[email protected]48c9cf2d2009-09-16 16:47:521579 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:061580 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]4f5ce842011-05-27 19:34:411581 message,
1582 string16(),
[email protected]b6cb3a842011-06-24 18:28:411583 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521584 NULL);
1585}
1586
[email protected]310ebd6302011-10-10 19:06:281587bool RenderViewImpl::runModalPromptDialog(
[email protected]48c9cf2d2009-09-16 16:47:521588 WebFrame* frame, const WebString& message, const WebString& default_value,
1589 WebString* actual_value) {
[email protected]4f5ce842011-05-27 19:34:411590 string16 result;
[email protected]9dd7e3d72011-01-20 18:27:061591 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]4f5ce842011-05-27 19:34:411592 message,
1593 default_value,
[email protected]b6cb3a842011-06-24 18:28:411594 frame->document().url(),
[email protected]48c9cf2d2009-09-16 16:47:521595 &result);
1596 if (ok)
[email protected]4f5ce842011-05-27 19:34:411597 actual_value->assign(result);
[email protected]48c9cf2d2009-09-16 16:47:521598 return ok;
1599}
1600
[email protected]310ebd6302011-10-10 19:06:281601bool RenderViewImpl::runModalBeforeUnloadDialog(
[email protected]48c9cf2d2009-09-16 16:47:521602 WebFrame* frame, const WebString& message) {
[email protected]992db4c2011-05-12 15:37:151603 // If we are swapping out, we have already run the beforeunload handler.
1604 // TODO(creis): Fix OnSwapOut to clear the frame without running beforeunload
1605 // at all, to avoid running it twice.
1606 if (is_swapped_out_)
1607 return true;
1608
[email protected]48c9cf2d2009-09-16 16:47:521609 bool success = false;
1610 // This is an ignored return value, but is included so we can accept the same
1611 // response as RunJavaScriptMessage.
[email protected]4f5ce842011-05-27 19:34:411612 string16 ignored_result;
[email protected]12636df2009-09-28 22:32:211613 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]b6cb3a842011-06-24 18:28:411614 routing_id_, frame->document().url(), message,
1615 &success, &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:521616 return success;
1617}
1618
[email protected]310ebd6302011-10-10 19:06:281619void RenderViewImpl::showContextMenu(
[email protected]79e37442009-10-09 18:17:441620 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:291621 ContextMenuParams params = ContextMenuParams(data);
[email protected]7fcd9b72011-07-27 16:52:371622
1623 // frame is NULL if invoked by BlockedPlugin.
1624 if (frame)
1625 params.frame_id = frame->identifier();
1626
[email protected]db803aae2011-03-05 02:00:421627 // Serializing a GURL longer than content::kMaxURLChars will fail, so don't do
[email protected]216932c2010-08-26 21:44:271628 // it. We replace it with an empty GURL so the appropriate items are disabled
1629 // in the context menu.
1630 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
1631 // data encoded images. We should have a way to save them.
[email protected]db803aae2011-03-05 02:00:421632 if (params.src_url.spec().size() > content::kMaxURLChars)
[email protected]216932c2010-08-26 21:44:271633 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:101634 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:291635 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:441636}
1637
[email protected]310ebd6302011-10-10 19:06:281638void RenderViewImpl::enterFullscreen() {
[email protected]2b624c562011-10-27 22:58:261639 // TODO(darin): Remove once WebKit roll is complete.
1640 enterFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471641}
1642
[email protected]310ebd6302011-10-10 19:06:281643void RenderViewImpl::exitFullscreen() {
[email protected]2b624c562011-10-27 22:58:261644 // TODO(darin): Remove once WebKit roll is complete.
1645 exitFullScreen();
[email protected]8a5e0ca2011-08-25 06:30:471646}
1647
[email protected]310ebd6302011-10-10 19:06:281648void RenderViewImpl::setStatusText(const WebString& text) {
[email protected]48c9cf2d2009-09-16 16:47:521649}
1650
[email protected]310ebd6302011-10-10 19:06:281651void RenderViewImpl::UpdateTargetURL(const GURL& url,
1652 const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:581653 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:521654 if (latest_url == target_url_)
1655 return;
[email protected]163f8242009-10-30 20:19:551656
[email protected]48c9cf2d2009-09-16 16:47:521657 // Tell the browser to display a destination link.
1658 if (target_url_status_ == TARGET_INFLIGHT ||
1659 target_url_status_ == TARGET_PENDING) {
1660 // If we have a request in-flight, save the URL to be sent when we
1661 // receive an ACK to the in-flight request. We can happily overwrite
1662 // any existing pending sends.
1663 pending_target_url_ = latest_url;
1664 target_url_status_ = TARGET_PENDING;
1665 } else {
[email protected]c85f0212011-11-04 16:54:411666 // URLs larger than |content::kMaxURLChars| cannot be sent through IPC -
1667 // see |ParamTraits<GURL>|.
1668 if (latest_url.possibly_invalid_spec().size() > content::kMaxURLChars)
1669 latest_url = GURL();
[email protected]48c9cf2d2009-09-16 16:47:521670 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
1671 target_url_ = latest_url;
1672 target_url_status_ = TARGET_INFLIGHT;
1673 }
1674}
1675
[email protected]310ebd6302011-10-10 19:06:281676void RenderViewImpl::StartNavStateSyncTimerIfNecessary() {
[email protected]882daa92009-11-05 16:31:311677 int delay;
1678 if (send_content_state_immediately_)
1679 delay = 0;
1680 else if (is_hidden())
1681 delay = kDelaySecondsForContentStateSyncHidden;
1682 else
1683 delay = kDelaySecondsForContentStateSync;
1684
1685 if (nav_state_sync_timer_.IsRunning()) {
1686 // The timer is already running. If the delay of the timer maches the amount
1687 // we want to delay by, then return. Otherwise stop the timer so that it
1688 // gets started with the right delay.
1689 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
1690 return;
1691 nav_state_sync_timer_.Stop();
1692 }
1693
[email protected]d323a172011-09-02 18:23:021694 nav_state_sync_timer_.Start(FROM_HERE, TimeDelta::FromSeconds(delay), this,
[email protected]310ebd6302011-10-10 19:06:281695 &RenderViewImpl::SyncNavigationState);
[email protected]882daa92009-11-05 16:31:311696}
1697
[email protected]310ebd6302011-10-10 19:06:281698void RenderViewImpl::setMouseOverURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551699 mouse_over_url_ = GURL(url);
1700 UpdateTargetURL(mouse_over_url_, focus_url_);
1701}
1702
[email protected]310ebd6302011-10-10 19:06:281703void RenderViewImpl::setKeyboardFocusURL(const WebURL& url) {
[email protected]163f8242009-10-30 20:19:551704 focus_url_ = GURL(url);
1705 UpdateTargetURL(focus_url_, mouse_over_url_);
1706}
1707
[email protected]310ebd6302011-10-10 19:06:281708void RenderViewImpl::startDragging(const WebDragData& data,
1709 WebDragOperationsMask mask,
1710 const WebImage& image,
1711 const WebPoint& imageOffset) {
[email protected]c27ae592010-03-18 15:24:411712#if WEBKIT_USING_SKIA
1713 SkBitmap bitmap(image.getSkBitmap());
1714#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:331715 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:411716#endif
1717
[email protected]59f4f2fa2011-03-23 01:00:551718 Send(new DragHostMsg_StartDragging(routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:521719 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:411720 mask,
1721 bitmap,
1722 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:521723}
1724
[email protected]310ebd6302011-10-10 19:06:281725bool RenderViewImpl::acceptsLoadDrops() {
[email protected]28b92df2009-09-25 17:35:451726 return renderer_preferences_.can_accept_load_drops;
1727}
1728
[email protected]310ebd6302011-10-10 19:06:281729void RenderViewImpl::focusNext() {
[email protected]48c9cf2d2009-09-16 16:47:521730 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
1731}
1732
[email protected]310ebd6302011-10-10 19:06:281733void RenderViewImpl::focusPrevious() {
[email protected]48c9cf2d2009-09-16 16:47:521734 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
1735}
1736
[email protected]310ebd6302011-10-10 19:06:281737void RenderViewImpl::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:511738 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:071739
[email protected]38b592902011-04-16 02:08:421740 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FocusedNodeChanged(node));
[email protected]08e9e132010-06-01 16:58:491741}
1742
[email protected]310ebd6302011-10-10 19:06:281743void RenderViewImpl::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:521744 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
1745}
1746
[email protected]310ebd6302011-10-10 19:06:281747int RenderViewImpl::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:001748 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:521749}
1750
[email protected]310ebd6302011-10-10 19:06:281751int RenderViewImpl::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:001752 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:521753}
1754
[email protected]310ebd6302011-10-10 19:06:281755void RenderViewImpl::postAccessibilityNotification(
[email protected]063afcb2011-09-29 07:54:321756 const WebAccessibilityObject& obj,
1757 WebAccessibilityNotification notification) {
1758 renderer_accessibility_->PostAccessibilityNotification(obj, notification);
1759}
1760
[email protected]310ebd6302011-10-10 19:06:281761void RenderViewImpl::didUpdateInspectorSetting(const WebString& key,
[email protected]c4e98902010-06-01 10:20:141762 const WebString& value) {
1763 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
1764 key.utf8(),
1765 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:261766}
1767
[email protected]79dbc662009-09-04 05:42:511768// WebKit::WebWidgetClient ----------------------------------------------------
1769
[email protected]310ebd6302011-10-10 19:06:281770void RenderViewImpl::didFocus() {
[email protected]ea42e7782010-08-23 23:58:121771 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
1772 // we won't have to test for user gesture anymore and we can
1773 // move that code back to render_widget.cc
1774 if (webview() && webview()->mainFrame() &&
1775 webview()->mainFrame()->isProcessingUserGesture()) {
1776 Send(new ViewHostMsg_Focus(routing_id_));
1777 }
1778}
1779
[email protected]310ebd6302011-10-10 19:06:281780void RenderViewImpl::didBlur() {
[email protected]ea42e7782010-08-23 23:58:121781 // TODO(jcivelli): see TODO above in didFocus().
1782 if (webview() && webview()->mainFrame() &&
1783 webview()->mainFrame()->isProcessingUserGesture()) {
1784 Send(new ViewHostMsg_Blur(routing_id_));
1785 }
1786}
1787
initial.commit09911bf2008-07-26 23:55:291788// We are supposed to get a single call to Show for a newly created RenderView
[email protected]310ebd6302011-10-10 19:06:281789// that was created via RenderViewImpl::CreateWebView. So, we wait until this
initial.commit09911bf2008-07-26 23:55:291790// point to dispatch the ShowView message.
1791//
1792// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281793// created RenderView (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291794//
[email protected]310ebd6302011-10-10 19:06:281795void RenderViewImpl::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:291796 DCHECK(!did_show_) << "received extraneous Show call";
1797 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1798
1799 if (did_show_)
1800 return;
1801 did_show_ = true;
1802
[email protected]6779aa12011-03-29 17:32:241803 if (content::GetContentClient()->renderer()->AllowPopup(creator_url_))
[email protected]4026ce1e2010-09-14 19:35:041804 opened_by_user_gesture_ = true;
[email protected]4026ce1e2010-09-14 19:35:041805
[email protected]28295ec2009-10-16 05:34:331806 // Force new windows to a popup if they were not opened with a user gesture.
1807 if (!opened_by_user_gesture_) {
1808 // We exempt background tabs for compat with older versions of Chrome.
1809 // TODO(darin): This seems bogus. These should have a user gesture, so
1810 // we probably don't need this check.
1811 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
1812 policy = WebKit::WebNavigationPolicyNewPopup;
1813 }
1814
initial.commit09911bf2008-07-26 23:55:291815 // NOTE: initial_pos_ may still have its default values at this point, but
1816 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
1817 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:281818 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
1819 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:291820 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:241821 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291822}
1823
[email protected]310ebd6302011-10-10 19:06:281824void RenderViewImpl::runModal() {
initial.commit09911bf2008-07-26 23:55:291825 DCHECK(did_show_) << "should already have shown the view";
1826
[email protected]c1f50aa2010-02-18 03:46:571827 // We must keep WebKit's shared timer running in this case in order to allow
1828 // showModalDialog to function properly.
1829 //
1830 // TODO(darin): WebKit should really be smarter about suppressing events and
1831 // timers so that we do not need to manage the shared timer in such a heavy
1832 // handed manner.
1833 //
[email protected]f1a29a02011-10-06 23:08:441834 if (RenderThreadImpl::current()) // Will be NULL during unit tests.
1835 RenderThreadImpl::current()->DoNotSuspendWebKitSharedTimer();
[email protected]c1f50aa2010-02-18 03:46:571836
[email protected]12636df2009-09-28 22:32:211837 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:291838}
1839
[email protected]2b624c562011-10-27 22:58:261840bool RenderViewImpl::enterFullScreen() {
1841 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, true));
1842 return true;
1843}
1844
1845void RenderViewImpl::exitFullScreen() {
1846 Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false));
1847}
1848
[email protected]3d9689372009-09-10 04:29:171849// WebKit::WebFrameClient -----------------------------------------------------
1850
[email protected]310ebd6302011-10-10 19:06:281851WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame,
1852 const WebPluginParams& params) {
[email protected]eaacd1f2011-09-23 02:32:551853 WebPlugin* plugin = NULL;
1854 if (content::GetContentClient()->renderer()->OverrideCreatePlugin(
1855 this, frame, params, &plugin)) {
1856 return plugin;
1857 }
1858
[email protected]a813c8e2011-10-08 01:34:111859 webkit::WebPluginInfo info;
1860 std::string mime_type;
1861 bool found = GetPluginInfo(params.url, frame->top()->document().url(),
1862 params.mimeType.utf8(), &info, &mime_type);
1863 if (!found)
1864 return NULL;
1865
1866 WebPluginParams params_to_use = params;
1867 params_to_use.mimeType = WebString::fromUTF8(mime_type);
[email protected]a2ef54c2011-10-10 16:20:311868 return CreatePlugin(frame, info, params_to_use);
[email protected]3d9689372009-09-10 04:29:171869}
1870
[email protected]310ebd6302011-10-10 19:06:281871WebSharedWorker* RenderViewImpl::createSharedWorker(
[email protected]9c00f002009-11-05 22:37:421872 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:371873 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:421874
[email protected]30447b62009-11-13 01:13:371875 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:511876 bool exists = false;
[email protected]30447b62009-11-13 01:13:371877 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:511878 ViewHostMsg_CreateWorker_Params params;
1879 params.url = url;
[email protected]6de0bcf2010-02-17 22:00:511880 params.name = name;
1881 params.document_id = document_id;
1882 params.render_view_route_id = routing_id_;
1883 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:231884 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:371885 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:511886 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:371887 if (url_mismatch) {
1888 return NULL;
1889 } else {
[email protected]f1a29a02011-10-06 23:08:441890 return new WebSharedWorkerProxy(RenderThreadImpl::current(),
[email protected]0791d3a2010-01-28 01:28:491891 document_id,
[email protected]6de0bcf2010-02-17 22:00:511892 exists,
[email protected]30447b62009-11-13 01:13:371893 route_id,
1894 routing_id_);
1895 }
[email protected]9c00f002009-11-05 22:37:421896}
1897
[email protected]310ebd6302011-10-10 19:06:281898WebMediaPlayer* RenderViewImpl::createMediaPlayer(
[email protected]3d9689372009-09-10 04:29:171899 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]16e923d2011-04-30 00:41:441900 FOR_EACH_OBSERVER(
1901 RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
[email protected]7198402c2011-04-11 12:15:171902
[email protected]f78d1dfc2011-01-15 07:09:271903 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
1904 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:491905 scoped_ptr<media::FilterCollection> collection(
1906 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:371907
[email protected]3d9689372009-09-10 04:29:171908 // Add in any custom filter factories first.
1909 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
1910 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
1911 // Add the chrome specific audio renderer.
[email protected]f7eb0a392011-07-12 10:19:511912 collection->AddAudioRenderer(new AudioRendererImpl());
[email protected]3d9689372009-09-10 04:29:171913 }
1914
[email protected]a9288f52011-11-17 05:18:161915 scoped_ptr<webkit_media::WebMediaPlayerImpl> result(
1916 new webkit_media::WebMediaPlayerImpl(client,
[email protected]b8976652011-10-26 23:46:551917 AsWeakPtr(),
[email protected]f78d1dfc2011-01-15 07:09:271918 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]86b3f4b2011-11-18 23:52:461923 cmd_line->HasSwitch(switches::kSimpleDataSource))) {
[email protected]a8e24d522010-12-01 07:13:581924 return NULL;
1925 }
1926 return result.release();
[email protected]3d9689372009-09-10 04:29:171927}
1928
[email protected]310ebd6302011-10-10 19:06:281929WebApplicationCacheHost* RenderViewImpl::createApplicationCacheHost(
[email protected]035545f2010-04-09 13:10:211930 WebFrame* frame, WebApplicationCacheHostClient* client) {
1931 return new RendererWebApplicationCacheHostImpl(
1932 FromWebView(frame->view()), client,
[email protected]f1a29a02011-10-06 23:08:441933 RenderThreadImpl::current()->appcache_dispatcher()->backend_proxy());
[email protected]035545f2010-04-09 13:10:211934}
1935
[email protected]310ebd6302011-10-10 19:06:281936WebCookieJar* RenderViewImpl::cookieJar(WebFrame* frame) {
[email protected]8ff181072010-11-29 17:09:381937 return &cookie_jar_;
1938}
1939
[email protected]310ebd6302011-10-10 19:06:281940void RenderViewImpl::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511941 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:451942}
1943
[email protected]310ebd6302011-10-10 19:06:281944void RenderViewImpl::willClose(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:511945 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:171946}
1947
[email protected]310ebd6302011-10-10 19:06:281948void RenderViewImpl::loadURLExternally(
[email protected]3d9689372009-09-10 04:29:171949 WebFrame* frame, const WebURLRequest& request,
1950 WebNavigationPolicy policy) {
[email protected]0622875ab2011-07-27 12:10:341951 loadURLExternally(frame, request, policy, WebString());
1952}
1953
[email protected]310ebd6302011-10-10 19:06:281954void RenderViewImpl::loadURLExternally(
[email protected]0622875ab2011-07-27 12:10:341955 WebFrame* frame, const WebURLRequest& request,
1956 WebNavigationPolicy policy,
1957 const WebString& suggested_name) {
[email protected]efce17b2009-09-11 18:04:591958 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
1959 if (policy == WebKit::WebNavigationPolicyDownload) {
[email protected]0622875ab2011-07-27 12:10:341960 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer,
1961 suggested_name));
[email protected]efce17b2009-09-11 18:04:591962 } else {
[email protected]ae5184d62011-10-06 19:25:581963 OpenURL(frame, request.url(), referrer, policy);
[email protected]efce17b2009-09-11 18:04:591964 }
[email protected]3d9689372009-09-10 04:29:171965}
1966
[email protected]310ebd6302011-10-10 19:06:281967WebNavigationPolicy RenderViewImpl::decidePolicyForNavigation(
[email protected]3d9689372009-09-10 04:29:171968 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:221969 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]992db4c2011-05-12 15:37:151970 // TODO(creis): Remove this when we fix OnSwapOut to not need a navigation.
1971 if (is_swapped_out_) {
1972 DCHECK(request.url() == GURL("about:swappedout"));
1973 return default_policy;
1974 }
1975
[email protected]3d9689372009-09-10 04:29:171976 // Webkit is asking whether to navigate to a new URL.
1977 // This is fine normally, except if we're showing UI from one security
1978 // context and they're trying to navigate to a different context.
1979 const GURL& url = request.url();
1980
[email protected]d19ea342011-04-20 20:31:131981 // A content initiated navigation may have originated from a link-click,
1982 // script, drag-n-drop operation, etc.
1983 bool is_content_initiated =
[email protected]007733c2011-11-17 00:34:071984 DocumentState::FromDataSource(frame->provisionalDataSource())->
1985 navigation_state()->is_content_initiated();
[email protected]d19ea342011-04-20 20:31:131986
[email protected]a8c269a2011-10-25 20:17:221987 // Experimental:
1988 // If --enable-strict-site-isolation is enabled, send all top-level
1989 // navigations to the browser to let it swap processes when crossing site
1990 // boundaries. This is currently expected to break some script calls and
1991 // navigations, such as form submissions.
1992 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]313b80bd2011-11-23 03:49:101993 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) &&
1994 !frame->parent() && (is_content_initiated || is_redirect)) {
1995 WebString origin_str = frame->document().securityOrigin().toString();
1996 GURL frame_url(origin_str.utf8().data());
1997 // TODO(cevans): revisit whether this origin check is still necessary once
1998 // crbug.com/101395 is fixed.
1999 if (frame_url.GetOrigin() != url.GetOrigin()) {
2000 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2001 OpenURL(frame, url, referrer, default_policy);
2002 return WebKit::WebNavigationPolicyIgnore;
2003 }
[email protected]a8c269a2011-10-25 20:17:222004 }
2005
[email protected]3d9689372009-09-10 04:29:172006 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302007 // navigations.
[email protected]d19ea342011-04-20 20:31:132008 if (is_content_initiated &&
2009 renderer_preferences_.browser_handles_top_level_requests &&
[email protected]8079b362010-05-07 18:37:452010 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192011 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232012 // Reset these counters as the RenderView could be reused for the next
2013 // navigation.
2014 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232015 last_page_id_sent_to_browser_ = -1;
[email protected]ae5184d62011-10-06 19:25:582016 OpenURL(frame, url, referrer, default_policy);
[email protected]61c9f032010-03-31 23:04:192017 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172018 }
2019
[email protected]6101c342010-12-16 22:44:372020 // Detect when we're crossing a permission-based boundary (e.g. into or out of
[email protected]c39f9bf2011-02-12 00:43:552021 // an extension or app origin, leaving a WebUI page, etc). We only care about
[email protected]8f4da8c2011-02-09 19:49:572022 // top-level navigations within the current tab (as opposed to, for example,
[email protected]6101c342010-12-16 22:44:372023 // opening a new window). But we sometimes navigate to about:blank to clear a
2024 // tab, and we want to still allow that.
2025 //
[email protected]8f4da8c2011-02-09 19:49:572026 // Note: we do this only for GET requests because our mechanism for switching
2027 // processes only issues GET requests. In particular, POST requests don't
2028 // work, because this mechanism does not preserve form POST data. If it
2029 // becomes necessary to support process switching for POST requests, we will
2030 // need to send the request's httpBody data up to the browser process, and
2031 // issue a special POST navigation in WebKit (via
2032 // FrameLoader::loadFrameRequest). See ResourceDispatcher and WebURLLoaderImpl
2033 // for examples of how to send the httpBody data.
2034 // Note2: We normally don't do this for browser-initiated navigations, since
2035 // it's pointless to tell the browser about navigations it gave us. But
2036 // we do potentially ask the browser to handle a redirect that was originally
2037 // initiated by the browser. See http://crbug.com/70943
2038 //
2039 // TODO(creis): Move this redirect check to the browser process to avoid
2040 // ping-ponging. See http://crbug.com/72380.
2041 if (!frame->parent() && (is_content_initiated || is_redirect) &&
[email protected]6101c342010-12-16 22:44:372042 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2043 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2044 bool send_referrer = false;
2045 bool should_fork =
[email protected]e091df82011-10-11 18:13:212046 (enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]3d9689372009-09-10 04:29:172047 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372048 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112049
[email protected]e48869a2011-04-01 19:56:032050 if (!should_fork) {
2051 // Give the embedder a chance.
[email protected]d55c2382011-08-18 23:10:362052 bool is_initial_navigation = page_id_ == -1;
[email protected]e48869a2011-04-01 19:56:032053 should_fork = content::GetContentClient()->renderer()->ShouldFork(
[email protected]d55c2382011-08-18 23:10:362054 frame, url, is_content_initiated, is_initial_navigation,
2055 &send_referrer);
[email protected]6101c342010-12-16 22:44:372056 }
2057
2058 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112059 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]ae5184d62011-10-06 19:25:582060 OpenURL(frame, url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112061 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2062 }
[email protected]3d9689372009-09-10 04:29:172063 }
2064
[email protected]43763f982011-08-26 18:33:402065 // Use the frame's original request's URL rather than the document's URL for
2066 // this check. For a popup, the document's URL may become the opener window's
2067 // URL if the opener has called document.write. See http://crbug.com/93517.
2068 GURL old_url(frame->dataSource()->request().url());
2069
[email protected]3d9689372009-09-10 04:29:172070 // Detect when a page is "forking" a new tab that can be safely rendered in
2071 // its own process. This is done by sites like Gmail that try to open links
2072 // in new windows without script connections back to the original page. We
2073 // treat such cases as browser navigations (in which we will create a new
2074 // renderer for a cross-site navigation), rather than WebKit navigations.
2075 //
2076 // We use the following heuristic to decide whether to fork a new page in its
2077 // own process:
2078 // The parent page must open a new tab to about:blank, set the new tab's
2079 // window.opener to null, and then redirect the tab to a cross-site URL using
2080 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462081 //
2082 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2083 // (see below).
[email protected]3d9689372009-09-10 04:29:172084 bool is_fork =
2085 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582086 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172087 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522088 historyBackListCount() < 1 &&
2089 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:172090 // The parent page must have set the child's window.opener to null before
2091 // redirecting to the desired URL.
2092 frame->opener() == NULL &&
2093 // Must be a top-level frame.
2094 frame->parent() == NULL &&
2095 // Must not have issued the request from this page.
2096 is_content_initiated &&
2097 // Must be targeted at the current tab.
2098 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2099 // Must be a JavaScript navigation, which appears as "other".
2100 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:462101
2102 // Recognize if this navigation is from a link with rel=noreferrer and
2103 // target=_blank attributes, in which case the opener will be suppressed. If
2104 // so, it is safe to load cross-site pages in a separate process, so we
2105 // should let the browser handle it.
2106 bool is_noreferrer_and_blank_target =
2107 // Frame should be top level and not yet navigated.
2108 frame->parent() == NULL &&
[email protected]b6cb3a842011-06-24 18:28:412109 frame->document().url().isEmpty() &&
[email protected]007a848b2009-10-26 15:55:462110 historyBackListCount() < 1 &&
2111 historyForwardListCount() < 1 &&
2112 // Links with rel=noreferrer will have no Referer field, and their
2113 // resulting frame will have its window.opener suppressed.
2114 // TODO(creis): should add a request.httpReferrer() method to help avoid
2115 // typos on the unusual spelling of Referer.
2116 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
2117 opener_suppressed_ &&
2118 frame->opener() == NULL &&
2119 // Links with target=_blank will have no name.
2120 frame->name().isNull() &&
2121 // Another frame (with a non-empty creator) should have initiated the
2122 // request, targeted at this frame.
2123 !creator_url_.is_empty() &&
2124 is_content_initiated &&
2125 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2126 type == WebKit::WebNavigationTypeOther;
2127
2128 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:172129 // Open the URL via the browser, not via WebKit.
[email protected]ae5184d62011-10-06 19:25:582130 OpenURL(frame, url, GURL(), default_policy);
[email protected]3d9689372009-09-10 04:29:172131 return WebKit::WebNavigationPolicyIgnore;
2132 }
2133
2134 return default_policy;
2135}
2136
[email protected]310ebd6302011-10-10 19:06:282137bool RenderViewImpl::canHandleRequest(
[email protected]6069da8c2009-10-20 20:33:492138 WebFrame* frame, const WebURLRequest& request) {
2139 // We allow WebKit to think that everything can be handled even though
2140 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:342141 return true;
2142}
2143
[email protected]310ebd6302011-10-10 19:06:282144WebURLError RenderViewImpl::cannotHandleRequestError(
[email protected]6069da8c2009-10-20 20:33:492145 WebFrame* frame, const WebURLRequest& request) {
2146 NOTREACHED(); // Since we said we can handle all requests.
2147 return WebURLError();
2148}
2149
[email protected]310ebd6302011-10-10 19:06:282150WebURLError RenderViewImpl::cancelledError(
[email protected]6069da8c2009-10-20 20:33:492151 WebFrame* frame, const WebURLRequest& request) {
2152 WebURLError error;
2153 error.domain = WebString::fromUTF8(net::kErrorDomain);
2154 error.reason = net::ERR_ABORTED;
2155 error.unreachableURL = request.url();
2156 return error;
[email protected]7b7a7dc2009-10-19 02:23:342157}
2158
[email protected]310ebd6302011-10-10 19:06:282159void RenderViewImpl::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:492160 WebFrame*, const WebURLError&) {
2161 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:342162}
2163
[email protected]310ebd6302011-10-10 19:06:282164void RenderViewImpl::willSendSubmitEvent(WebKit::WebFrame* frame,
[email protected]90eeddb2010-05-06 21:06:432165 const WebKit::WebFormElement& form) {
2166 // Some login forms have onSubmit handlers that put a hash of the password
2167 // into a hidden field and then clear the password. (Issue 28910.)
2168 // This method gets called before any of those handlers run, so save away
2169 // a copy of the password in case it gets lost.
[email protected]007733c2011-11-17 00:34:072170 DocumentState* document_state =
2171 DocumentState::FromDataSource(frame->dataSource());
2172 document_state->set_password_form_data(
[email protected]90eeddb2010-05-06 21:06:432173 PasswordFormDomManager::CreatePasswordForm(form));
2174}
2175
[email protected]310ebd6302011-10-10 19:06:282176void RenderViewImpl::willSubmitForm(WebFrame* frame,
2177 const WebFormElement& form) {
[email protected]007733c2011-11-17 00:34:072178 DocumentState* document_state =
2179 DocumentState::FromDataSource(frame->provisionalDataSource());
2180 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172181
[email protected]2905f742011-10-13 03:51:582182 if (navigation_state->transition_type() == content::PAGE_TRANSITION_LINK)
2183 navigation_state->set_transition_type(content::PAGE_TRANSITION_FORM_SUBMIT);
[email protected]3d9689372009-09-10 04:29:172184
2185 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:352186 WebSearchableFormData web_searchable_form_data(form);
[email protected]007733c2011-11-17 00:34:072187 document_state->set_searchable_form_url(web_searchable_form_data.url());
2188 document_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:212189 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:432190 PasswordForm* password_form_data =
2191 PasswordFormDomManager::CreatePasswordForm(form);
[email protected]007733c2011-11-17 00:34:072192 document_state->set_password_form_data(password_form_data);
[email protected]90eeddb2010-05-06 21:06:432193
[email protected]098c95cb2011-04-28 16:49:012194 // In order to save the password that the user actually typed and not one
2195 // that may have gotten transformed by the site prior to submit, recover it
2196 // from the form contents already stored by |willSendSubmitEvent| into the
2197 // dataSource's NavigationState (as opposed to the provisionalDataSource's,
2198 // which is what we're storing into now.)
2199 if (password_form_data) {
[email protected]007733c2011-11-17 00:34:072200 DocumentState* old_document_state =
2201 DocumentState::FromDataSource(frame->dataSource());
2202 if (old_document_state) {
2203 PasswordForm* old_form_data = old_document_state->password_form_data();
[email protected]90eeddb2010-05-06 21:06:432204 if (old_form_data && old_form_data->action == password_form_data->action)
2205 password_form_data->password_value = old_form_data->password_value;
2206 }
2207 }
[email protected]3d9689372009-09-10 04:29:172208
[email protected]2a5b1732011-04-01 23:55:552209 FOR_EACH_OBSERVER(
2210 RenderViewObserver, observers_, WillSubmitForm(frame, form));
[email protected]3d9689372009-09-10 04:29:172211}
2212
[email protected]310ebd6302011-10-10 19:06:282213void RenderViewImpl::willPerformClientRedirect(
[email protected]3d9689372009-09-10 04:29:172214 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
2215 double fire_time) {
[email protected]eb0bff942011-04-07 22:08:382216 FOR_EACH_OBSERVER(
2217 RenderViewObserver, observers_,
2218 WillPerformClientRedirect(frame, from, to, interval, fire_time));
[email protected]3d9689372009-09-10 04:29:172219}
2220
[email protected]310ebd6302011-10-10 19:06:282221void RenderViewImpl::didCancelClientRedirect(WebFrame* frame) {
[email protected]eb0bff942011-04-07 22:08:382222 FOR_EACH_OBSERVER(
2223 RenderViewObserver, observers_, DidCancelClientRedirect(frame));
[email protected]3d9689372009-09-10 04:29:172224}
2225
[email protected]310ebd6302011-10-10 19:06:282226void RenderViewImpl::didCompleteClientRedirect(
[email protected]3d9689372009-09-10 04:29:172227 WebFrame* frame, const WebURL& from) {
2228 if (!frame->parent())
2229 completed_client_redirect_src_ = from;
[email protected]eb0bff942011-04-07 22:08:382230 FOR_EACH_OBSERVER(
2231 RenderViewObserver, observers_, DidCompleteClientRedirect(frame, from));
[email protected]3d9689372009-09-10 04:29:172232}
2233
[email protected]310ebd6302011-10-10 19:06:282234void RenderViewImpl::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]007733c2011-11-17 00:34:072235 DocumentState* document_state = DocumentState::FromDataSource(ds);
2236 if (!document_state) {
2237 document_state = new DocumentState;
2238 ds->setExtraData(document_state);
2239 }
2240
[email protected]3d9689372009-09-10 04:29:172241 // The rest of RenderView assumes that a WebDataSource will always have a
2242 // non-null NavigationState.
[email protected]007733c2011-11-17 00:34:072243 bool content_initiated = !pending_navigation_params_.get();
2244 if (content_initiated)
2245 document_state->set_navigation_state(
2246 NavigationState::CreateContentInitiated());
2247 else
2248 PopulateStateFromPendingNavigationParams(document_state);
[email protected]8a3125a712010-08-09 18:58:512249
[email protected]007733c2011-11-17 00:34:072250 // DocumentState::referred_by_prefetcher_ is true if we are
[email protected]8a3125a712010-08-09 18:58:512251 // navigating from a page that used prefetching using a link on that
2252 // page. We are early enough in the request process here that we
[email protected]007733c2011-11-17 00:34:072253 // can still see the DocumentState of the previous page and set
[email protected]8a3125a712010-08-09 18:58:512254 // this value appropriately.
2255 // TODO(gavinp): catch the important case of navigation in a new
2256 // renderer process.
2257 if (webview()) {
[email protected]e47aec52010-08-12 00:50:302258 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:522259 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:512260 const GURL referrer(
2261 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
2262 if (!referrer.is_empty() &&
[email protected]007733c2011-11-17 00:34:072263 DocumentState::FromDataSource(
[email protected]8a3125a712010-08-09 18:58:512264 old_frame->dataSource())->was_prefetcher()) {
2265 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
2266 WebDataSource* old_frame_ds = old_frame->dataSource();
2267 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
[email protected]007733c2011-11-17 00:34:072268 document_state->set_was_referred_by_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512269 break;
2270 }
2271 }
2272 }
2273 }
2274 }
2275
[email protected]4c1b6f0b2010-02-07 16:38:182276 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:522277 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:512278 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:182279 case WebURLRequest::UseProtocolCachePolicy: // normal load.
[email protected]007733c2011-11-17 00:34:072280 document_state->set_load_type(DocumentState::LINK_LOAD_NORMAL);
[email protected]4c1b6f0b2010-02-07 16:38:182281 break;
2282 case WebURLRequest::ReloadIgnoringCacheData: // reload.
[email protected]007733c2011-11-17 00:34:072283 document_state->set_load_type(DocumentState::LINK_LOAD_RELOAD);
[email protected]4c1b6f0b2010-02-07 16:38:182284 break;
2285 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
[email protected]007733c2011-11-17 00:34:072286 document_state->set_load_type(
2287 DocumentState::LINK_LOAD_CACHE_STALE_OK);
[email protected]4c1b6f0b2010-02-07 16:38:182288 break;
2289 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
[email protected]007733c2011-11-17 00:34:072290 document_state->set_load_type(DocumentState::LINK_LOAD_CACHE_ONLY);
[email protected]4c1b6f0b2010-02-07 16:38:182291 break;
2292 }
2293 }
[email protected]fa7b6b542009-11-03 05:02:302294
[email protected]946a0032011-03-31 18:42:282295 FOR_EACH_OBSERVER(
2296 RenderViewObserver, observers_, DidCreateDataSource(frame, ds));
[email protected]3d9689372009-09-10 04:29:172297}
2298
[email protected]007733c2011-11-17 00:34:072299void RenderViewImpl::PopulateStateFromPendingNavigationParams(
2300 DocumentState* document_state) {
2301 const ViewMsg_Navigate_Params& params = *pending_navigation_params_.get();
2302
2303 if (document_state->request_time().is_null())
2304 document_state->set_request_time(params.request_time);
2305
2306 // A navigation resulting from loading a javascript URL should not be treated
2307 // as a browser initiated event. Instead, we want it to look as if the page
2308 // initiated any load resulting from JS execution.
2309 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
2310 NavigationState* navigation_state = NavigationState::CreateBrowserInitiated(
2311 params.page_id,
2312 params.pending_history_list_offset,
2313 params.transition);
2314 if (params.navigation_type == ViewMsg_Navigate_Type::RESTORE) {
2315 // We're doing a load of a page that was restored from the last session.
2316 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
2317 // which can result in stale data for pages that are set to expire. We
2318 // explicitly override that by setting the policy here so that as
2319 // necessary we load from the network.
2320 document_state->set_cache_policy_override(
2321 WebURLRequest::UseProtocolCachePolicy);
2322 }
2323 document_state->set_navigation_state(navigation_state);
2324 } else {
2325 document_state->set_navigation_state(
2326 NavigationState::CreateContentInitiated());
2327 }
2328
2329 if (IsReload(params))
2330 document_state->set_load_type(DocumentState::RELOAD);
2331 else if (!params.state.empty())
2332 document_state->set_load_type(DocumentState::HISTORY_LOAD);
2333 else
2334 document_state->set_load_type(DocumentState::NORMAL_LOAD);
2335
2336 pending_navigation_params_.reset();
2337}
2338
[email protected]310ebd6302011-10-10 19:06:282339void RenderViewImpl::didStartProvisionalLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172340 WebDataSource* ds = frame->provisionalDataSource();
[email protected]007733c2011-11-17 00:34:072341 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]3d9689372009-09-10 04:29:172342
[email protected]3d9689372009-09-10 04:29:172343 // Update the request time if WebKit has better knowledge of it.
[email protected]007733c2011-11-17 00:34:072344 if (document_state->request_time().is_null()) {
[email protected]3d9689372009-09-10 04:29:172345 double event_time = ds->triggeringEventTime();
2346 if (event_time != 0.0)
[email protected]007733c2011-11-17 00:34:072347 document_state->set_request_time(Time::FromDoubleT(event_time));
[email protected]3d9689372009-09-10 04:29:172348 }
2349
[email protected]05c8e502010-08-15 15:13:522350 // Start time is only set after request time.
[email protected]007733c2011-11-17 00:34:072351 document_state->set_start_load_time(Time::Now());
[email protected]05c8e502010-08-15 15:13:522352
[email protected]3d9689372009-09-10 04:29:172353 bool is_top_most = !frame->parent();
2354 if (is_top_most) {
2355 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:132356 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:172357
2358 // Make sure redirect tracking state is clear for the new load.
2359 completed_client_redirect_src_ = GURL();
2360 } else if (frame->parent()->isLoading()) {
2361 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:002362 // load an error page. See didFailProvisionalLoad.
[email protected]007733c2011-11-17 00:34:072363 document_state->navigation_state()->set_transition_type(
[email protected]2905f742011-10-13 03:51:582364 content::PAGE_TRANSITION_AUTO_SUBFRAME);
[email protected]3d9689372009-09-10 04:29:172365 }
2366
[email protected]28685da92011-02-07 21:49:172367 FOR_EACH_OBSERVER(
2368 RenderViewObserver, observers_, DidStartProvisionalLoad(frame));
2369
[email protected]3d9689372009-09-10 04:29:172370 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]57b9396c2011-10-07 19:11:592371 routing_id_, frame->identifier(), is_top_most, GetOpenerUrl(),
[email protected]eacb080b2011-05-22 19:40:262372 ds->request().url()));
[email protected]3d9689372009-09-10 04:29:172373}
2374
[email protected]310ebd6302011-10-10 19:06:282375void RenderViewImpl::didReceiveServerRedirectForProvisionalLoad(
2376 WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172377 if (frame->parent())
2378 return;
2379 // Received a redirect on the main frame.
2380 WebDataSource* data_source = frame->provisionalDataSource();
2381 if (!data_source) {
2382 // Should only be invoked when we have a data source.
2383 NOTREACHED();
2384 return;
2385 }
2386 std::vector<GURL> redirects;
2387 GetRedirectChain(data_source, &redirects);
2388 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:512389 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
[email protected]57b9396c2011-10-07 19:11:592390 GetOpenerUrl(), redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:172391 }
2392}
2393
[email protected]310ebd6302011-10-10 19:06:282394void RenderViewImpl::didFailProvisionalLoad(WebFrame* frame,
2395 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:172396 // Notify the browser that we failed a provisional load with an error.
2397 //
2398 // Note: It is important this notification occur before DidStopLoading so the
2399 // SSL manager can react to the provisional load failure before being
2400 // notified the load stopped.
2401 //
2402 WebDataSource* ds = frame->provisionalDataSource();
2403 DCHECK(ds);
2404
2405 const WebURLRequest& failed_request = ds->request();
2406
[email protected]28685da92011-02-07 21:49:172407 FOR_EACH_OBSERVER(
2408 RenderViewObserver, observers_, DidFailProvisionalLoad(frame, error));
2409
[email protected]3d9689372009-09-10 04:29:172410 bool show_repost_interstitial =
2411 (error.reason == net::ERR_CACHE_MISS &&
2412 EqualsASCII(failed_request.httpMethod(), "POST"));
[email protected]d7b175e2011-10-11 15:31:582413
2414 ViewHostMsg_DidFailProvisionalLoadWithError_Params params;
2415 params.frame_id = frame->identifier();
2416 params.is_main_frame = !frame->parent();
2417 params.error_code = error.reason;
2418 content::GetContentClient()->renderer()->GetNavigationErrorStrings(
2419 failed_request,
2420 error,
2421 NULL,
2422 &params.error_description);
2423 params.url = error.unreachableURL;
2424 params.showing_repost_interstitial = show_repost_interstitial;
[email protected]3d9689372009-09-10 04:29:172425 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:582426 routing_id_, params));
[email protected]3d9689372009-09-10 04:29:172427
2428 // Don't display an error page if this is simply a cancelled load. Aside
2429 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2430 if (error.reason == net::ERR_ABORTED)
2431 return;
2432
2433 // Make sure we never show errors in view source mode.
2434 frame->enableViewSourceMode(false);
2435
[email protected]007733c2011-11-17 00:34:072436 DocumentState* document_state = DocumentState::FromDataSource(ds);
2437 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172438
2439 // If this is a failed back/forward/reload navigation, then we need to do a
2440 // 'replace' load. This is necessary to avoid messing up session history.
2441 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
2442 // as session history is concerned.
2443 //
2444 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
2445 // the page id.
2446 //
2447 bool replace =
2448 navigation_state->pending_page_id() != -1 ||
[email protected]2905f742011-10-13 03:51:582449 navigation_state->transition_type() ==
2450 content::PAGE_TRANSITION_AUTO_SUBFRAME;
[email protected]3d9689372009-09-10 04:29:172451
2452 // If we failed on a browser initiated request, then make sure that our error
2453 // page load is regarded as the same browser initiated request.
2454 if (!navigation_state->is_content_initiated()) {
[email protected]007733c2011-11-17 00:34:072455 pending_navigation_params_.reset(new ViewMsg_Navigate_Params);
2456 pending_navigation_params_->page_id =
2457 navigation_state->pending_page_id();
2458 pending_navigation_params_->pending_history_list_offset =
2459 navigation_state->pending_history_list_offset();
2460 pending_navigation_params_->transition =
2461 navigation_state->transition_type();
2462 pending_navigation_params_->request_time =
2463 document_state->request_time();
[email protected]3d9689372009-09-10 04:29:172464 }
2465
2466 // Provide the user with a more helpful error page?
2467 if (MaybeLoadAlternateErrorPage(frame, error, replace))
2468 return;
2469
2470 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:082471 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:172472}
2473
[email protected]310ebd6302011-10-10 19:06:282474void RenderViewImpl::didReceiveDocumentData(
[email protected]3d9689372009-09-10 04:29:172475 WebFrame* frame, const char* data, size_t data_len,
2476 bool& prevent_default) {
[email protected]007733c2011-11-17 00:34:072477 DocumentState* document_state =
2478 DocumentState::FromDataSource(frame->dataSource());
2479 document_state->set_use_error_page(false);
[email protected]3d9689372009-09-10 04:29:172480}
2481
[email protected]310ebd6302011-10-10 19:06:282482void RenderViewImpl::didCommitProvisionalLoad(WebFrame* frame,
2483 bool is_new_navigation) {
[email protected]007733c2011-11-17 00:34:072484 DocumentState* document_state =
2485 DocumentState::FromDataSource(frame->dataSource());
2486 NavigationState* navigation_state = document_state->navigation_state();
[email protected]3d9689372009-09-10 04:29:172487
[email protected]007733c2011-11-17 00:34:072488 if (document_state->commit_load_time().is_null())
2489 document_state->set_commit_load_time(Time::Now());
2490
[email protected]3d9689372009-09-10 04:29:172491 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:202492 // When we perform a new navigation, we need to update the last committed
2493 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:172494 UpdateSessionHistory(frame);
2495
2496 // We bump our Page ID to correspond with the new session history entry.
2497 page_id_ = next_page_id_++;
2498
[email protected]3cc72b12010-03-18 23:03:002499 // Advance our offset in session history, applying the length limit. There
2500 // is now no forward history.
2501 history_list_offset_++;
[email protected]9966325b2011-04-18 05:00:102502 if (history_list_offset_ >= content::kMaxSessionHistoryEntries)
2503 history_list_offset_ = content::kMaxSessionHistoryEntries - 1;
[email protected]3cc72b12010-03-18 23:03:002504 history_list_length_ = history_list_offset_ + 1;
[email protected]d466b8a2011-07-15 21:48:032505 history_page_ids_.resize(history_list_length_, -1);
2506 history_page_ids_[history_list_offset_] = page_id_;
[email protected]3d9689372009-09-10 04:29:172507 } else {
2508 // Inspect the navigation_state on this frame to see if the navigation
2509 // corresponds to a session history navigation... Note: |frame| may or
2510 // may not be the toplevel frame, but for the case of capturing session
2511 // history, the first committed frame suffices. We keep track of whether
2512 // we've seen this commit before so that only capture session history once
2513 // per navigation.
2514 //
2515 // Note that we need to check if the page ID changed. In the case of a
2516 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2517 // previous URL and the current page ID, which would be wrong.
2518 if (navigation_state->pending_page_id() != -1 &&
2519 navigation_state->pending_page_id() != page_id_ &&
2520 !navigation_state->request_committed()) {
2521 // This is a successful session history navigation!
2522 UpdateSessionHistory(frame);
2523 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:002524
2525 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]d466b8a2011-07-15 21:48:032526
2527 // If the history list is valid, our list of page IDs should be correct.
2528 DCHECK(history_list_length_ <= 0 ||
2529 history_list_offset_ < 0 ||
2530 history_list_offset_ >= history_list_length_ ||
2531 history_page_ids_[history_list_offset_] == page_id_);
[email protected]3d9689372009-09-10 04:29:172532 }
2533 }
2534
[email protected]28685da92011-02-07 21:49:172535 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2536 DidCommitProvisionalLoad(frame, is_new_navigation));
2537
[email protected]3d9689372009-09-10 04:29:172538 // Remember that we've already processed this request, so we don't update
2539 // the session history again. We do this regardless of whether this is
2540 // a session history navigation, because if we attempted a session history
2541 // navigation without valid HistoryItem state, WebCore will think it is a
2542 // new navigation.
2543 navigation_state->set_request_committed(true);
2544
2545 UpdateURL(frame);
2546
2547 // If this committed load was initiated by a client redirect, we're
2548 // at the last stop now, so clear it.
2549 completed_client_redirect_src_ = GURL();
2550
2551 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272552 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172553}
2554
[email protected]310ebd6302011-10-10 19:06:282555void RenderViewImpl::didClearWindowObject(WebFrame* frame) {
[email protected]9966325b2011-04-18 05:00:102556 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2557 DidClearWindowObject(frame));
2558
[email protected]b6cb3a842011-06-24 18:28:412559 GURL frame_url = frame->document().url();
[email protected]e091df82011-10-11 18:13:212560 if ((enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI) &&
[email protected]bfa83eb82010-10-06 08:41:252561 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
2562 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c50008512011-02-03 01:17:272563 GetWebUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:172564 }
[email protected]3d9689372009-09-10 04:29:172565}
2566
[email protected]310ebd6302011-10-10 19:06:282567void RenderViewImpl::didCreateDocumentElement(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172568 // Notify the browser about non-blank documents loading in the top frame.
[email protected]b6cb3a842011-06-24 18:28:412569 GURL url = frame->document().url();
[email protected]e0d481582009-09-15 21:06:252570 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:272571 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:172572 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
2573 }
[email protected]e48869a2011-04-01 19:56:032574
2575 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2576 DidCreateDocumentElement(frame));
[email protected]3d9689372009-09-10 04:29:172577}
2578
[email protected]310ebd6302011-10-10 19:06:282579void RenderViewImpl::didReceiveTitle(WebFrame* frame, const WebString& title,
2580 WebTextDirection direction) {
[email protected]a49e10b2011-08-01 23:57:462581 UpdateTitle(frame, title, direction);
[email protected]3d9689372009-09-10 04:29:172582
2583 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272584 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172585}
2586
[email protected]310ebd6302011-10-10 19:06:282587void RenderViewImpl::didChangeIcon(WebFrame* frame, WebIconURL::Type type) {
[email protected]42054a252011-05-17 18:02:132588 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2589 DidChangeIcon(frame, type));
[email protected]5019ef12010-04-27 17:26:582590}
2591
[email protected]310ebd6302011-10-10 19:06:282592void RenderViewImpl::didFinishDocumentLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172593 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072594 DocumentState* document_state = DocumentState::FromDataSource(ds);
2595 document_state->set_finish_document_load_time(Time::Now());
[email protected]3d9689372009-09-10 04:29:172596
[email protected]622474d2010-11-04 09:21:082597 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172598
[email protected]28685da92011-02-07 21:49:172599 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
2600 DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:172601
2602 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:272603 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:172604}
2605
[email protected]310ebd6302011-10-10 19:06:282606void RenderViewImpl::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:082607 if (webview()->mainFrame() == frame) {
2608 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
2609 page_id_));
2610 }
[email protected]3d9689372009-09-10 04:29:172611}
2612
[email protected]310ebd6302011-10-10 19:06:282613void RenderViewImpl::didFailLoad(WebFrame* frame, const WebURLError& error) {
[email protected]28685da92011-02-07 21:49:172614 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFailLoad(frame, error));
[email protected]3d9689372009-09-10 04:29:172615}
2616
[email protected]310ebd6302011-10-10 19:06:282617void RenderViewImpl::didFinishLoad(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172618 WebDataSource* ds = frame->dataSource();
[email protected]007733c2011-11-17 00:34:072619 DocumentState* document_state = DocumentState::FromDataSource(ds);
2620 if (document_state->finish_load_time().is_null())
2621 document_state->set_finish_load_time(Time::Now());
[email protected]4d44a1c2010-04-28 19:20:412622
[email protected]676126f72011-01-15 00:03:512623 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:172624
2625 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:172626}
2627
[email protected]310ebd6302011-10-10 19:06:282628void RenderViewImpl::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:172629 WebFrame* frame, bool is_new_navigation) {
2630 // If this was a reference fragment navigation that we initiated, then we
[email protected]007733c2011-11-17 00:34:072631 // could end up having a non-null pending navigation params. We just need to
[email protected]3d9689372009-09-10 04:29:172632 // update the ExtraData on the datasource so that others who read the
2633 // ExtraData will get the new NavigationState. Similarly, if we did not
2634 // initiate this navigation, then we need to take care to reset any pre-
2635 // existing navigation state to a content-initiated navigation state.
2636 // DidCreateDataSource conveniently takes care of this for us.
2637 didCreateDataSource(frame, frame->dataSource());
2638
[email protected]007733c2011-11-17 00:34:072639 DocumentState* document_state =
2640 DocumentState::FromDataSource(frame->dataSource());
2641 NavigationState* new_state = document_state->navigation_state();
[email protected]af15bed2010-08-25 21:12:092642 new_state->set_was_within_same_page(true);
2643
[email protected]3d9689372009-09-10 04:29:172644 didCommitProvisionalLoad(frame, is_new_navigation);
2645
[email protected]750fcf872011-08-03 23:10:472646 WebDataSource* datasource = frame->view()->mainFrame()->dataSource();
2647 UpdateTitle(frame, datasource->pageTitle(), datasource->pageTitleDirection());
[email protected]3d9689372009-09-10 04:29:172648}
2649
[email protected]310ebd6302011-10-10 19:06:282650void RenderViewImpl::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:312651 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:592652}
2653
[email protected]310ebd6302011-10-10 19:06:282654void RenderViewImpl::assignIdentifierToRequest(
[email protected]3d9689372009-09-10 04:29:172655 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
2656 // Ignore
2657}
2658
[email protected]310ebd6302011-10-10 19:06:282659void RenderViewImpl::willSendRequest(WebFrame* frame,
2660 unsigned identifier,
2661 WebURLRequest& request,
2662 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:302663 WebFrame* top_frame = frame->top();
2664 if (!top_frame)
2665 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:512666 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
2667 WebDataSource* top_data_source = top_frame->dataSource();
2668 WebDataSource* data_source =
2669 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]78d5cfe2011-02-04 08:43:222670
[email protected]78d5cfe2011-02-04 08:43:222671 GURL request_url(request.url());
[email protected]e48869a2011-04-01 19:56:032672 GURL new_url;
2673 if (content::GetContentClient()->renderer()->WillSendRequest(
2674 frame, request_url, &new_url)) {
2675 request.setURL(WebURL(new_url));
[email protected]78d5cfe2011-02-04 08:43:222676 }
2677
[email protected]2905f742011-10-13 03:51:582678 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]007733c2011-11-17 00:34:072679 DocumentState* document_state = DocumentState::FromDataSource(data_source);
2680 NavigationState* navigation_state = document_state->navigation_state();
2681 if (document_state) {
2682 if (document_state->is_cache_policy_override_set())
2683 request.setCachePolicy(document_state->cache_policy_override());
2684 transition_type = navigation_state->transition_type();
[email protected]5e369672009-11-03 23:48:302685 }
[email protected]8a3125a712010-08-09 18:58:512686
[email protected]91043a8232011-11-04 16:41:192687 request.setExtraData(
2688 new RequestExtraData((frame == top_frame),
2689 frame->identifier(),
2690 frame->parent() == top_frame,
2691 frame->parent() ? frame->parent()->identifier() : -1,
2692 transition_type));
[email protected]d88bf0a2011-08-30 23:55:572693
[email protected]007733c2011-11-17 00:34:072694 DocumentState* top_document_state =
2695 DocumentState::FromDataSource(top_data_source);
[email protected]d88bf0a2011-08-30 23:55:572696 // TODO(gavinp): separate out prefetching and prerender field trials
2697 // if the rel=prerender rel type is sticking around.
[email protected]007733c2011-11-17 00:34:072698 if (top_document_state &&
[email protected]d88bf0a2011-08-30 23:55:572699 (request.targetType() == WebURLRequest::TargetIsPrefetch ||
2700 request.targetType() == WebURLRequest::TargetIsPrerender))
[email protected]007733c2011-11-17 00:34:072701 top_document_state->set_was_prefetcher(true);
[email protected]8a3125a712010-08-09 18:58:512702
[email protected]3d9689372009-09-10 04:29:172703 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:132704 request.setHasUserGesture(frame->isProcessingUserGesture());
2705
[email protected]0a8db0d2011-04-13 15:15:402706 if (!renderer_preferences_.enable_referrers)
[email protected]7deade42010-03-05 09:33:132707 request.clearHTTPHeaderField("Referer");
[email protected]3d9689372009-09-10 04:29:172708}
2709
[email protected]310ebd6302011-10-10 19:06:282710void RenderViewImpl::didReceiveResponse(
[email protected]3d9689372009-09-10 04:29:172711 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:492712
[email protected]3d9689372009-09-10 04:29:172713 // Only do this for responses that correspond to a provisional data source
2714 // of the top-most frame. If we have a provisional data source, then we
2715 // can't have any sub-resources yet, so we know that this response must
2716 // correspond to a frame load.
2717 if (!frame->provisionalDataSource() || frame->parent())
2718 return;
2719
2720 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:082721 // the server's error page.
[email protected]3d9689372009-09-10 04:29:172722 if (frame->isViewSourceModeEnabled())
2723 return;
2724
[email protected]007733c2011-11-17 00:34:072725 DocumentState* document_state =
2726 DocumentState::FromDataSource(frame->provisionalDataSource());
[email protected]3f853a52010-09-13 19:15:082727 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:532728
[email protected]972ebdff2010-06-10 22:59:072729 // Record page load flags.
[email protected]007733c2011-11-17 00:34:072730 document_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
2731 document_state->set_was_npn_negotiated(response.wasNpnNegotiated());
2732 document_state->set_was_alternate_protocol_available(
[email protected]193b0b892010-06-26 03:57:572733 response.wasAlternateProtocolAvailable());
[email protected]007733c2011-11-17 00:34:072734 document_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
2735 document_state->set_http_status_code(http_status_code);
[email protected]06333afe2011-02-24 14:55:092736 // Whether or not the http status code actually corresponds to an error is
2737 // only checked when the page is done loading, if |use_error_page| is
2738 // still true.
[email protected]007733c2011-11-17 00:34:072739 document_state->set_use_error_page(true);
[email protected]3d9689372009-09-10 04:29:172740}
2741
[email protected]310ebd6302011-10-10 19:06:282742void RenderViewImpl::didFinishResourceLoad(
[email protected]3d9689372009-09-10 04:29:172743 WebFrame* frame, unsigned identifier) {
[email protected]007733c2011-11-17 00:34:072744 DocumentState* document_state =
2745 DocumentState::FromDataSource(frame->dataSource());
2746 if (!document_state->use_error_page())
[email protected]3d9689372009-09-10 04:29:172747 return;
2748
[email protected]7bfc153f2011-09-23 22:00:202749 // Do not show error page when DevTools is attached.
2750 if (devtools_agent_->IsAttached())
2751 return;
2752
[email protected]06333afe2011-02-24 14:55:092753 // Display error page, if appropriate.
[email protected]007733c2011-11-17 00:34:072754 int http_status_code = document_state->http_status_code();
[email protected]3f853a52010-09-13 19:15:082755 if (http_status_code == 404) {
2756 // On 404s, try a remote search page as a fallback.
[email protected]b6cb3a842011-06-24 18:28:412757 const GURL& document_url = frame->document().url();
[email protected]3d9689372009-09-10 04:29:172758
[email protected]b6cb3a842011-06-24 18:28:412759 const GURL& error_page_url =
2760 GetAlternateErrorPageURL(document_url, HTTP_404);
[email protected]06333afe2011-02-24 14:55:092761 if (error_page_url.is_valid()) {
2762 WebURLError original_error;
[email protected]2e9706c2011-06-09 16:49:472763 original_error.domain = "http";
2764 original_error.reason = 404;
[email protected]b6cb3a842011-06-24 18:28:412765 original_error.unreachableURL = document_url;
[email protected]3d9689372009-09-10 04:29:172766
[email protected]007733c2011-11-17 00:34:072767 document_state->set_alt_error_page_fetcher(
[email protected]06333afe2011-02-24 14:55:092768 new AltErrorPageResourceFetcher(
2769 error_page_url, frame, original_error,
[email protected]6e806822011-11-19 01:51:082770 base::Bind(&RenderViewImpl::AltErrorPageFinished,
2771 base::Unretained(this))));
[email protected]06333afe2011-02-24 14:55:092772 return;
2773 }
2774 }
[email protected]3d9689372009-09-10 04:29:172775
[email protected]e6a2ce52011-10-08 01:40:132776 std::string error_domain;
2777 if (content::GetContentClient()->renderer()->HasErrorPage(
2778 http_status_code, &error_domain)) {
2779 WebURLError error;
2780 error.unreachableURL = frame->document().url();
2781 error.domain = WebString::fromUTF8(error_domain);
2782 error.reason = http_status_code;
2783
2784 LoadNavigationErrorPage(
2785 frame, frame->dataSource()->request(), error, std::string(), true);
2786 }
[email protected]3d9689372009-09-10 04:29:172787}
2788
[email protected]310ebd6302011-10-10 19:06:282789void RenderViewImpl::didFailResourceLoad(
[email protected]3d9689372009-09-10 04:29:172790 WebFrame* frame, unsigned identifier, const WebURLError& error) {
2791 // Ignore
2792}
2793
[email protected]310ebd6302011-10-10 19:06:282794void RenderViewImpl::didLoadResourceFromMemoryCache(
[email protected]3d9689372009-09-10 04:29:172795 WebFrame* frame, const WebURLRequest& request,
2796 const WebURLResponse& response) {
[email protected]84703292011-10-28 20:44:002797 // The recipients of this message have no use for data: URLs: they don't
2798 // affect the page's insecure content list and are not in the disk cache. To
2799 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
2800 // filter them out here.
2801 GURL url(request.url());
2802 if (url.SchemeIs("data"))
2803 return;
2804
[email protected]3d9689372009-09-10 04:29:172805 // Let the browser know we loaded a resource from the memory cache. This
2806 // message is needed to display the correct SSL indicators.
2807 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
2808 routing_id_,
[email protected]84703292011-10-28 20:44:002809 url,
[email protected]70435962011-08-02 20:13:282810 response.securityInfo(),
2811 request.httpMethod().utf8(),
2812 ResourceType::FromTargetType(request.targetType())));
[email protected]3d9689372009-09-10 04:29:172813}
2814
[email protected]310ebd6302011-10-10 19:06:282815void RenderViewImpl::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:292816 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
2817}
2818
[email protected]310ebd6302011-10-10 19:06:282819void RenderViewImpl::didRunInsecureContent(
[email protected]92771112011-01-20 00:13:022820 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:292821 Send(new ViewHostMsg_DidRunInsecureContent(
2822 routing_id_,
[email protected]92771112011-01-20 00:13:022823 origin.toString().utf8(),
2824 target));
[email protected]e3d60e5d2009-09-25 21:08:292825}
2826
[email protected]310ebd6302011-10-10 19:06:282827void RenderViewImpl::didAdoptURLLoader(WebKit::WebURLLoader* loader) {
[email protected]b00ba702011-08-17 01:41:032828 webkit_glue::WebURLLoaderImpl* loader_impl =
2829 static_cast<webkit_glue::WebURLLoaderImpl*>(loader);
2830 loader_impl->UpdateRoutingId(routing_id_);
2831}
2832
[email protected]310ebd6302011-10-10 19:06:282833void RenderViewImpl::didExhaustMemoryAvailableForScript(WebFrame* frame) {
[email protected]3d9689372009-09-10 04:29:172834 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
2835}
2836
[email protected]310ebd6302011-10-10 19:06:282837void RenderViewImpl::didCreateScriptContext(WebFrame* frame,
2838 v8::Handle<v8::Context> context,
2839 int world_id) {
[email protected]5bc10932011-09-21 21:03:302840 content::GetContentClient()->renderer()->DidCreateScriptContext(
2841 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282842}
2843
[email protected]310ebd6302011-10-10 19:06:282844void RenderViewImpl::willReleaseScriptContext(WebFrame* frame,
2845 v8::Handle<v8::Context> context,
2846 int world_id) {
[email protected]5bc10932011-09-21 21:03:302847 content::GetContentClient()->renderer()->WillReleaseScriptContext(
2848 frame, context, world_id);
[email protected]0c882b282009-10-07 17:01:282849}
2850
[email protected]310ebd6302011-10-10 19:06:282851void RenderViewImpl::didUpdateLayout(WebFrame* frame) {
[email protected]d812fd12011-05-27 23:05:072852 // We don't always want to set up a timer, only if we've been put in that
2853 // mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:172854 // message.
[email protected]705243f2010-05-05 19:58:072855 if (!send_preferred_size_changes_ || !webview())
2856 return;
[email protected]dfca5acf2010-03-22 03:28:432857
[email protected]d812fd12011-05-27 23:05:072858 if (check_preferred_size_timer_.IsRunning())
2859 return;
[email protected]d323a172011-09-02 18:23:022860 check_preferred_size_timer_.Start(FROM_HERE,
2861 TimeDelta::FromMilliseconds(0), this,
[email protected]310ebd6302011-10-10 19:06:282862 &RenderViewImpl::CheckPreferredSize);
[email protected]d812fd12011-05-27 23:05:072863}
2864
[email protected]310ebd6302011-10-10 19:06:282865void RenderViewImpl::CheckPreferredSize() {
[email protected]d812fd12011-05-27 23:05:072866 // We don't always want to send the change messages over IPC, only if we've
2867 // been put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
2868 // message.
2869 if (!send_preferred_size_changes_ || !webview())
2870 return;
2871
[email protected]705243f2010-05-05 19:58:072872 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
2873 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:532874
2875 // In the presence of zoom, these sizes are still reported as if unzoomed,
2876 // so we need to adjust.
2877 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
2878 size.set_width(static_cast<int>(size.width() * zoom_factor));
2879 size.set_height(static_cast<int>(size.height() * zoom_factor));
2880
[email protected]705243f2010-05-05 19:58:072881 if (size == preferred_size_)
2882 return;
[email protected]c27324b2009-11-19 22:44:292883
[email protected]705243f2010-05-05 19:58:072884 preferred_size_ = size;
2885 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
2886 preferred_size_));
[email protected]3d9689372009-09-10 04:29:172887}
2888
[email protected]310ebd6302011-10-10 19:06:282889void RenderViewImpl::didChangeContentsSize(WebFrame* frame,
2890 const WebSize& size) {
[email protected]dd6afca2011-08-13 03:44:312891 if (webview()->mainFrame() != frame)
2892 return;
2893 WebView* frameView = frame->view();
2894 if (!frameView)
2895 return;
2896
2897 bool has_horizontal_scrollbar = frame->hasHorizontalScrollbar();
2898 bool has_vertical_scrollbar = frame->hasVerticalScrollbar();
2899
2900 if (has_horizontal_scrollbar != cached_has_main_frame_horizontal_scrollbar_ ||
2901 has_vertical_scrollbar != cached_has_main_frame_vertical_scrollbar_) {
2902 Send(new ViewHostMsg_DidChangeScrollbarsForMainFrame(
2903 routing_id_, has_horizontal_scrollbar, has_vertical_scrollbar));
2904
2905 cached_has_main_frame_horizontal_scrollbar_ = has_horizontal_scrollbar;
2906 cached_has_main_frame_vertical_scrollbar_ = has_vertical_scrollbar;
2907 }
2908}
2909
[email protected]310ebd6302011-10-10 19:06:282910void RenderViewImpl::UpdateScrollState(WebFrame* frame) {
[email protected]dd6afca2011-08-13 03:44:312911 WebSize offset = frame->scrollOffset();
2912 WebSize minimum_offset = frame->minimumScrollOffset();
2913 WebSize maximum_offset = frame->maximumScrollOffset();
2914
2915 bool is_pinned_to_left = offset.width <= minimum_offset.width;
2916 bool is_pinned_to_right = offset.width >= maximum_offset.width;
2917
2918 if (is_pinned_to_left != cached_is_main_frame_pinned_to_left_ ||
2919 is_pinned_to_right != cached_is_main_frame_pinned_to_right_) {
2920 Send(new ViewHostMsg_DidChangeScrollOffsetPinningForMainFrame(
2921 routing_id_, is_pinned_to_left, is_pinned_to_right));
2922
2923 cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
2924 cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
2925 }
2926}
2927
[email protected]310ebd6302011-10-10 19:06:282928void RenderViewImpl::didChangeScrollOffset(WebFrame* frame) {
[email protected]143dcd592009-11-06 21:33:492929 StartNavStateSyncTimerIfNecessary();
[email protected]dd6afca2011-08-13 03:44:312930
2931 if (webview()->mainFrame() == frame)
2932 UpdateScrollState(frame);
2933}
2934
[email protected]310ebd6302011-10-10 19:06:282935void RenderViewImpl::numberOfWheelEventHandlersChanged(unsigned num_handlers) {
[email protected]dd6afca2011-08-13 03:44:312936 Send(new ViewHostMsg_DidChangeNumWheelEvents(routing_id_, num_handlers));
[email protected]143dcd592009-11-06 21:33:492937}
2938
[email protected]310ebd6302011-10-10 19:06:282939void RenderViewImpl::reportFindInPageMatchCount(int request_id, int count,
2940 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:112941 int active_match_ordinal = -1; // -1 = don't update active match ordinal
2942 if (!count)
2943 active_match_ordinal = 0;
2944
2945 IPC::Message* msg = new ViewHostMsg_Find_Reply(
2946 routing_id_,
2947 request_id,
2948 count,
2949 gfx::Rect(),
2950 active_match_ordinal,
2951 final_update);
2952
[email protected]8922e1f2009-10-03 05:01:262953 // If we have a message that has been queued up, then we should just replace
2954 // it. The ACK from the browser will make sure it gets sent when the browser
2955 // wants it.
2956 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:262957 queued_find_reply_message_.reset(msg);
2958 } else {
2959 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:112960 Send(msg);
[email protected]8922e1f2009-10-03 05:01:262961 }
2962}
2963
[email protected]310ebd6302011-10-10 19:06:282964void RenderViewImpl::reportFindInPageSelection(int request_id,
2965 int active_match_ordinal,
2966 const WebRect& selection_rect) {
[email protected]8922e1f2009-10-03 05:01:262967 // Send the search result over to the browser process.
2968 Send(new ViewHostMsg_Find_Reply(routing_id_,
2969 request_id,
2970 -1,
2971 selection_rect,
2972 active_match_ordinal,
2973 false));
2974}
2975
[email protected]310ebd6302011-10-10 19:06:282976void RenderViewImpl::openFileSystem(
[email protected]2b06a992010-08-21 05:48:222977 WebFrame* frame,
2978 WebFileSystem::Type type,
2979 long long size,
[email protected]d275d7a2010-11-03 01:34:492980 bool create,
[email protected]2b06a992010-08-21 05:48:222981 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:082982 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:222983
[email protected]b6cb3a842011-06-24 18:28:412984 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:562985 if (origin.isUnique()) {
2986 // Unique origins cannot store persistent state.
[email protected]c5a272d2010-09-27 18:37:082987 callbacks->didFail(WebKit::WebFileErrorAbort);
2988 return;
2989 }
[email protected]2b06a992010-08-21 05:48:222990
[email protected]c5a272d2010-09-27 18:37:082991 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
2992 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:492993 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:222994}
2995
[email protected]310ebd6302011-10-10 19:06:282996void RenderViewImpl::queryStorageUsageAndQuota(
[email protected]10e5cf12011-04-13 04:10:402997 WebFrame* frame,
2998 WebStorageQuotaType type,
2999 WebStorageQuotaCallbacks* callbacks) {
3000 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413001 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563002 if (origin.isUnique()) {
3003 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403004 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3005 return;
3006 }
3007 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
[email protected]666bcc5c2011-07-29 06:25:533008 GURL(origin.toString()),
3009 static_cast<quota::StorageType>(type),
3010 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403011}
3012
[email protected]310ebd6302011-10-10 19:06:283013void RenderViewImpl::requestStorageQuota(
[email protected]10e5cf12011-04-13 04:10:403014 WebFrame* frame,
3015 WebStorageQuotaType type,
3016 unsigned long long requested_size,
3017 WebStorageQuotaCallbacks* callbacks) {
3018 DCHECK(frame);
[email protected]b6cb3a842011-06-24 18:28:413019 WebSecurityOrigin origin = frame->document().securityOrigin();
[email protected]753ab8c82011-11-21 20:25:563020 if (origin.isUnique()) {
3021 // Unique origins cannot store persistent state.
[email protected]10e5cf12011-04-13 04:10:403022 callbacks->didFail(WebKit::WebStorageQuotaErrorAbort);
3023 return;
3024 }
3025 ChildThread::current()->quota_dispatcher()->RequestStorageQuota(
[email protected]666bcc5c2011-07-29 06:25:533026 routing_id(), GURL(origin.toString()),
3027 static_cast<quota::StorageType>(type), requested_size,
3028 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper(callbacks));
[email protected]10e5cf12011-04-13 04:10:403029}
3030
[email protected]18d5be92011-07-25 18:00:193031// WebKit::WebPageSerializerClient implementation ------------------------------
3032
[email protected]310ebd6302011-10-10 19:06:283033void RenderViewImpl::didSerializeDataForFrame(
[email protected]18d5be92011-07-25 18:00:193034 const WebURL& frame_url,
3035 const WebCString& data,
3036 WebPageSerializerClient::PageSerializationStatus status) {
3037 Send(new ViewHostMsg_SendSerializedHtmlData(
3038 routing_id(),
3039 frame_url,
3040 data.data(),
3041 static_cast<int32>(status)));
3042}
3043
[email protected]a2ef54c2011-10-10 16:20:313044// content::RenderView implementation ------------------------------------------
3045
[email protected]310ebd6302011-10-10 19:06:283046bool RenderViewImpl::Send(IPC::Message* message) {
[email protected]a2ef54c2011-10-10 16:20:313047 return RenderWidget::Send(message);
3048}
3049
[email protected]310ebd6302011-10-10 19:06:283050int RenderViewImpl::GetRoutingId() const {
[email protected]a2ef54c2011-10-10 16:20:313051 return routing_id_;
3052}
3053
[email protected]310ebd6302011-10-10 19:06:283054int RenderViewImpl::GetPageId() {
[email protected]a2ef54c2011-10-10 16:20:313055 return page_id_;
3056}
3057
[email protected]310ebd6302011-10-10 19:06:283058gfx::Size RenderViewImpl::GetSize() {
[email protected]a2ef54c2011-10-10 16:20:313059 return size();
3060}
3061
[email protected]310ebd6302011-10-10 19:06:283062gfx::NativeViewId RenderViewImpl::GetHostWindow() {
[email protected]a2ef54c2011-10-10 16:20:313063 return host_window();
3064}
3065
[email protected]310ebd6302011-10-10 19:06:283066WebPreferences& RenderViewImpl::GetWebkitPreferences() {
[email protected]a2ef54c2011-10-10 16:20:313067 return webkit_preferences_;
3068}
3069
[email protected]310ebd6302011-10-10 19:06:283070WebKit::WebView* RenderViewImpl::GetWebView() {
[email protected]a2ef54c2011-10-10 16:20:313071 return webview();
3072}
3073
[email protected]310ebd6302011-10-10 19:06:283074WebKit::WebNode RenderViewImpl::GetFocusedNode() const {
[email protected]a2ef54c2011-10-10 16:20:313075 if (!webview())
3076 return WebNode();
3077 WebFrame* focused_frame = webview()->focusedFrame();
3078 if (focused_frame) {
3079 WebDocument doc = focused_frame->document();
3080 if (!doc.isNull())
3081 return doc.focusedNode();
3082 }
3083
3084 return WebNode();
3085}
3086
[email protected]310ebd6302011-10-10 19:06:283087WebKit::WebNode RenderViewImpl::GetContextMenuNode() const {
[email protected]a2ef54c2011-10-10 16:20:313088 return context_menu_node_;
3089}
3090
[email protected]310ebd6302011-10-10 19:06:283091bool RenderViewImpl::IsEditableNode(const WebKit::WebNode& node) {
[email protected]a2ef54c2011-10-10 16:20:313092 bool is_editable_node = false;
3093 if (!node.isNull()) {
3094 if (node.isContentEditable()) {
3095 is_editable_node = true;
3096 } else if (node.isElementNode()) {
3097 is_editable_node =
3098 node.toConst<WebElement>().isTextFormControlElement();
3099 }
3100 }
3101 return is_editable_node;
3102}
3103
[email protected]310ebd6302011-10-10 19:06:283104WebKit::WebPlugin* RenderViewImpl::CreatePlugin(
[email protected]a2ef54c2011-10-10 16:20:313105 WebKit::WebFrame* frame,
3106 const webkit::WebPluginInfo& info,
3107 const WebKit::WebPluginParams& params) {
3108 bool pepper_plugin_was_registered = false;
3109 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
3110 pepper_delegate_.CreatePepperPluginModule(info,
3111 &pepper_plugin_was_registered));
3112 if (pepper_plugin_was_registered) {
3113 if (!pepper_module)
3114 return NULL;
3115 return new webkit::ppapi::WebPluginImpl(
3116 pepper_module.get(), params, pepper_delegate_.AsWeakPtr());
3117 }
3118
3119 return new webkit::npapi::WebPluginImpl(
3120 frame, params, info.path, AsWeakPtr());
3121}
3122
[email protected]310ebd6302011-10-10 19:06:283123void RenderViewImpl::EvaluateScript(const string16& frame_xpath,
3124 const string16& jscript,
3125 int id,
3126 bool notify_result) {
[email protected]a2ef54c2011-10-10 16:20:313127 v8::Handle<v8::Value> result;
3128 WebFrame* web_frame = GetChildFrame(frame_xpath);
3129 if (web_frame)
3130 result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
3131 if (notify_result) {
3132 ListValue list;
3133 if (!result.IsEmpty() && web_frame) {
3134 v8::HandleScope handle_scope;
3135 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
3136 v8::Context::Scope context_scope(context);
3137 V8ValueConverterImpl converter;
3138 converter.set_allow_date(true);
3139 converter.set_allow_regexp(true);
3140 list.Set(0, converter.FromV8Value(result, context));
3141 } else {
3142 list.Set(0, Value::CreateNullValue());
3143 }
3144 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
3145 }
3146}
3147
[email protected]310ebd6302011-10-10 19:06:283148bool RenderViewImpl::ShouldDisplayScrollbars(int width, int height) const {
[email protected]a2ef54c2011-10-10 16:20:313149 return (!send_preferred_size_changes_ ||
3150 (disable_scrollbars_size_limit_.width() <= width ||
3151 disable_scrollbars_size_limit_.height() <= height));
3152}
3153
[email protected]310ebd6302011-10-10 19:06:283154int RenderViewImpl::GetEnabledBindings() {
[email protected]a2ef54c2011-10-10 16:20:313155 return enabled_bindings_;
3156}
3157
[email protected]310ebd6302011-10-10 19:06:283158void RenderViewImpl::SetEnabledBindings(int enabled_bindings) {
[email protected]a2ef54c2011-10-10 16:20:313159 enabled_bindings_ = enabled_bindings;
3160}
3161
[email protected]310ebd6302011-10-10 19:06:283162bool RenderViewImpl::GetContentStateImmediately() {
[email protected]a2ef54c2011-10-10 16:20:313163 return send_content_state_immediately_;
3164}
3165
[email protected]310ebd6302011-10-10 19:06:283166float RenderViewImpl::GetFilteredTimePerFrame() {
[email protected]a2ef54c2011-10-10 16:20:313167 return filtered_time_per_frame();
3168}
3169
[email protected]310ebd6302011-10-10 19:06:283170void RenderViewImpl::ShowContextMenu(WebKit::WebFrame* frame,
3171 const WebKit::WebContextMenuData& data) {
[email protected]a2ef54c2011-10-10 16:20:313172 showContextMenu(frame, data);
3173}
3174
[email protected]310ebd6302011-10-10 19:06:283175WebKit::WebPageVisibilityState RenderViewImpl::GetVisibilityState() const {
[email protected]a2ef54c2011-10-10 16:20:313176 return visibilityState();
3177}
3178
[email protected]310ebd6302011-10-10 19:06:283179void RenderViewImpl::RunModalAlertDialog(WebKit::WebFrame* frame,
3180 const WebKit::WebString& message) {
[email protected]a2ef54c2011-10-10 16:20:313181 return runModalAlertDialog(frame, message);
3182}
3183
[email protected]310ebd6302011-10-10 19:06:283184void RenderViewImpl::LoadURLExternally(
[email protected]a2ef54c2011-10-10 16:20:313185 WebKit::WebFrame* frame,
3186 const WebKit::WebURLRequest& request,
3187 WebKit::WebNavigationPolicy policy) {
3188 loadURLExternally(frame, request, policy);
3189}
3190
3191// webkit_glue::WebPluginPageDelegate ------------------------------------------
[email protected]79dbc662009-09-04 05:42:513192
[email protected]310ebd6302011-10-10 19:06:283193webkit::npapi::WebPluginDelegate* RenderViewImpl::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533194 const FilePath& file_path,
3195 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593196 if (!PluginChannelHost::IsListening())
3197 return NULL;
3198
[email protected]00c39612010-03-06 02:53:283199 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d032f492009-09-29 00:33:463200 if (in_process_plugin) {
[email protected]7398dcc2011-09-06 21:40:323201#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]e8f7a182011-03-10 00:50:223202 return webkit::npapi::WebPluginDelegateImpl::Create(
3203 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093204#else
[email protected]7398dcc2011-09-06 21:40:323205 // In-proc plugins aren't supported on non-Windows.
[email protected]e8f7a182011-03-10 00:50:223206 NOTIMPLEMENTED();
3207 return NULL;
[email protected]7b6616f2010-01-14 18:07:553208#endif
[email protected]f103ab72009-09-02 17:10:593209 }
3210
[email protected]4e0616e2010-05-28 14:55:533211 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593212}
3213
[email protected]310ebd6302011-10-10 19:06:283214void RenderViewImpl::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033215#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273216 Send(new ViewHostMsg_CreatePluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593217#endif
3218}
3219
[email protected]310ebd6302011-10-10 19:06:283220void RenderViewImpl::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033221#if defined(USE_X11)
[email protected]380244092011-10-07 17:26:273222 Send(new ViewHostMsg_DestroyPluginContainer(routing_id(), window));
[email protected]f103ab72009-09-02 17:10:593223#endif
3224 CleanupWindowInPluginMoves(window);
3225}
3226
[email protected]310ebd6302011-10-10 19:06:283227void RenderViewImpl::DidMovePlugin(
3228 const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593229 SchedulePluginMove(move);
3230}
3231
[email protected]310ebd6302011-10-10 19:06:283232void RenderViewImpl::DidStartLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593233 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523234 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593235}
3236
[email protected]310ebd6302011-10-10 19:06:283237void RenderViewImpl::DidStopLoadingForPlugin() {
[email protected]f103ab72009-09-02 17:10:593238 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523239 didStopLoading();
[email protected]f103ab72009-09-02 17:10:593240}
3241
[email protected]310ebd6302011-10-10 19:06:283242WebCookieJar* RenderViewImpl::GetCookieJar() {
[email protected]b921cfd22010-02-25 16:57:513243 return &cookie_jar_;
3244}
3245
[email protected]a9288f52011-11-17 05:18:163246void RenderViewImpl::DidPlay(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073247 Send(new ViewHostMsg_MediaNotification(routing_id_,
3248 reinterpret_cast<int64>(player),
3249 player->hasVideo(),
3250 player->hasAudio(),
3251 true));
3252}
3253
[email protected]a9288f52011-11-17 05:18:163254void RenderViewImpl::DidPause(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073255 Send(new ViewHostMsg_MediaNotification(routing_id_,
3256 reinterpret_cast<int64>(player),
3257 player->hasVideo(),
3258 player->hasAudio(),
3259 false));
3260}
3261
[email protected]a9288f52011-11-17 05:18:163262void RenderViewImpl::PlayerGone(webkit_media::WebMediaPlayerImpl* player) {
[email protected]baff4512011-10-19 18:21:073263 DidPause(player);
3264}
3265
[email protected]310ebd6302011-10-10 19:06:283266void RenderViewImpl::SyncNavigationState() {
initial.commit09911bf2008-07-26 23:55:293267 if (!webview())
3268 return;
3269
[email protected]26aa0482009-09-30 16:55:273270 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:173271 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:293272 return;
[email protected]ca948a22009-06-25 19:36:173273
3274 Send(new ViewHostMsg_UpdateState(
3275 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:293276}
3277
[email protected]310ebd6302011-10-10 19:06:283278void RenderViewImpl::SyncSelectionIfRequired() {
[email protected]b781ff282011-08-20 06:19:363279 WebFrame* frame = webview()->focusedFrame();
[email protected]e99ef6f2011-10-16 01:13:003280 if (!frame)
3281 return;
[email protected]b781ff282011-08-20 06:19:363282
[email protected]b781ff282011-08-20 06:19:363283 size_t location, length;
[email protected]e99ef6f2011-10-16 01:13:003284 if (!webview()->caretOrSelectionRange(&location, &length))
3285 return;
3286
3287 string16 text;
3288 size_t offset;
3289 ui::Range range(location, location + length);
3290
3291 if (webview()->textInputType() != WebKit::WebTextInputTypeNone) {
3292 // If current focused element is editable, we will send 100 more chars
3293 // before and after selection. It is for input method surrounding text
3294 // feature.
3295 if (location > kExtraCharsBeforeAndAfterSelection)
3296 offset = location - kExtraCharsBeforeAndAfterSelection;
3297 else
3298 offset = 0;
3299 length = location + length - offset + kExtraCharsBeforeAndAfterSelection;
3300 WebRange webrange = WebRange::fromDocumentRange(frame, offset, length);
3301 if (!webrange.isNull())
3302 text = WebRange::fromDocumentRange(frame, offset, length).toPlainText();
3303 } else {
3304 offset = location;
3305 text = frame->selectionAsText();
[email protected]e8cdf3532011-10-29 00:50:523306 // http://crbug.com/101435
3307 // In some case, frame->selectionAsText() returned text's length is not
3308 // equal to the length returned from webview()->caretOrSelectionRange().
3309 // So we have to set the range according to text.length().
3310 range.set_end(range.start() + text.length());
[email protected]b781ff282011-08-20 06:19:363311 }
3312
[email protected]b781ff282011-08-20 06:19:363313 // Sometimes we get repeated didChangeSelection calls from webkit when
3314 // the selection hasn't actually changed. We don't want to report these
3315 // because it will cause us to continually claim the X clipboard.
[email protected]e99ef6f2011-10-16 01:13:003316 if (selection_text_offset_ != offset ||
3317 selection_range_ != range ||
3318 selection_text_ != text) {
3319 selection_text_ = text;
3320 selection_text_offset_ = offset;
3321 selection_range_ = range;
3322 Send(new ViewHostMsg_SelectionChanged(routing_id_, text, offset, range));
3323 }
[email protected]b781ff282011-08-20 06:19:363324}
3325
[email protected]310ebd6302011-10-10 19:06:283326GURL RenderViewImpl::GetAlternateErrorPageURL(const GURL& failed_url,
3327 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:553328 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:293329 // If the URL that failed was secure, then the embedding web page was not
3330 // expecting a network attacker to be able to manipulate its contents. As
3331 // we fetch alternate error pages over HTTP, we would be allowing a network
3332 // attacker to manipulate the contents of the response if we tried to use
3333 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:153334 return GURL();
initial.commit09911bf2008-07-26 23:55:293335 }
3336
3337 // Grab the base URL from the browser process.
3338 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:153339 return GURL();
initial.commit09911bf2008-07-26 23:55:293340
3341 // Strip query params from the failed URL.
3342 GURL::Replacements remove_params;
3343 remove_params.ClearUsername();
3344 remove_params.ClearPassword();
3345 remove_params.ClearQuery();
3346 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:553347 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:503348 std::string spec_to_send = url_to_send.spec();
3349 // Notify link doctor of the url truncation by sending of "?" at the end.
3350 if (failed_url.has_query())
3351 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:293352
3353 // Construct the query params to send to link doctor.
3354 std::string params(alternate_error_page_url_.query());
3355 params.append("&url=");
[email protected]4a19be92011-09-22 14:25:023356 params.append(net::EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:293357 params.append("&sourceid=chrome");
3358 params.append("&error=");
3359 switch (error_type) {
3360 case DNS_ERROR:
3361 params.append("dnserror");
3362 break;
3363
3364 case HTTP_404:
3365 params.append("http404");
3366 break;
3367
[email protected]5df266ac2008-10-15 19:50:133368 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:333369 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:133370 break;
3371
initial.commit09911bf2008-07-26 23:55:293372 default:
3373 NOTREACHED() << "unknown ErrorPageType";
3374 }
3375
3376 // OK, build the final url to return.
3377 GURL::Replacements link_doctor_params;
3378 link_doctor_params.SetQueryStr(params);
3379 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
3380 return url;
3381}
3382
[email protected]310ebd6302011-10-10 19:06:283383GURL RenderViewImpl::GetOpenerUrl() const {
[email protected]57b9396c2011-10-07 19:11:593384 if (opener_id_ == MSG_ROUTING_NONE || opener_suppressed_)
3385 return GURL();
3386 else
3387 return creator_url_;
3388}
3389
[email protected]310ebd6302011-10-10 19:06:283390WebUIBindings* RenderViewImpl::GetWebUIBindings() {
[email protected]c50008512011-02-03 01:17:273391 if (!web_ui_bindings_.get()) {
[email protected]a2ef54c2011-10-10 16:20:313392 web_ui_bindings_.reset(new WebUIBindings(
3393 static_cast<content::RenderView*>(this), routing_id_));
[email protected]c091c2c2010-09-17 19:05:463394 }
[email protected]c50008512011-02-03 01:17:273395 return web_ui_bindings_.get();
[email protected]c091c2c2010-09-17 19:05:463396}
3397
[email protected]310ebd6302011-10-10 19:06:283398WebKit::WebPlugin* RenderViewImpl::GetWebPluginFromPluginDocument() {
[email protected]0fdbf8c2010-07-08 20:33:013399 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:493400}
3401
[email protected]310ebd6302011-10-10 19:06:283402void RenderViewImpl::OnFind(int request_id, const string16& search_text,
3403 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:273404 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:493405
[email protected]872542532011-06-23 00:43:163406 // Check if the plugin still exists in the document.
3407 if (main_frame->document().isPluginDocument() &&
3408 GetWebPluginFromPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:493409 if (options.findNext) {
3410 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:013411 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:493412 } else {
[email protected]afdbd142010-07-10 08:01:233413 if (GetWebPluginFromPluginDocument()->startFind(
3414 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:493415 } else {
[email protected]e7c58a32010-08-13 19:47:113416 // Send "no results".
3417 Send(new ViewHostMsg_Find_Reply(routing_id_,
3418 request_id,
3419 0,
3420 gfx::Rect(),
3421 0,
3422 true));
[email protected]24a7f3c2010-03-25 08:26:493423 }
3424 }
3425 return;
3426 }
3427
[email protected]b4bb2502009-10-01 22:35:273428 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:273429 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:293430 WebFrame* search_frame = focused_frame; // start searching focused frame.
3431
3432 bool multi_frame = (frame_after_main != main_frame);
3433
3434 // If we have multiple frames, we don't want to wrap the search within the
3435 // frame, so we check here if we only have main_frame in the chain.
3436 bool wrap_within_frame = !multi_frame;
3437
[email protected]b3f2b912009-04-09 16:18:523438 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:293439 bool result = false;
3440
[email protected]7830da3e2009-11-06 16:27:263441 // If something is selected when we start searching it means we cannot just
3442 // increment the current match ordinal; we need to re-generate it.
3443 WebRange current_selection = focused_frame->selectionRange();
3444
initial.commit09911bf2008-07-26 23:55:293445 do {
[email protected]dd7daa82009-08-10 05:46:453446 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593447 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:293448
3449 if (!result) {
3450 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:223451 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293452
3453 // Find the next frame, but skip the invisible ones.
3454 do {
3455 // What is the next frame to search? (we might be going backwards). Note
3456 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:593457 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:273458 search_frame->traverseNext(true) :
3459 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:453460 } while (!search_frame->hasVisibleContent() &&
3461 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:293462
[email protected]884db412008-11-24 23:46:503463 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:223464 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:293465
3466 // If we have multiple frames and we have wrapped back around to the
3467 // focused frame, we need to search it once more allowing wrap within
3468 // the frame, otherwise it will report 'no match' if the focused frame has
3469 // reported matches, but no frames after the focused_frame contain a
3470 // match for the search word(s).
3471 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:453472 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:593473 request_id, search_text, options, true, // Force wrapping.
3474 &selection_rect);
initial.commit09911bf2008-07-26 23:55:293475 }
3476 }
3477
[email protected]26aa0482009-09-30 16:55:273478 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:293479 } while (!result && search_frame != focused_frame);
3480
[email protected]7830da3e2009-11-06 16:27:263481 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:293482 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:453483 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:293484 } else {
3485 // If nothing is found, set result to "0 of 0", otherwise, set it to
3486 // "-1 of 1" to indicate that we found at least one item, but we don't know
3487 // yet what is active.
3488 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
3489 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:293490
[email protected]4f3dc372009-02-24 00:10:293491 // If we find no matches then this will be our last status update.
3492 // Otherwise the scoping effort will send more results.
3493 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:293494
[email protected]4f3dc372009-02-24 00:10:293495 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:403496 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:593497 request_id,
[email protected]4f3dc372009-02-24 00:10:293498 match_count,
3499 selection_rect,
3500 ordinal,
3501 final_status_update));
initial.commit09911bf2008-07-26 23:55:293502
initial.commit09911bf2008-07-26 23:55:293503 // Scoping effort begins, starting with the mainframe.
3504 search_frame = main_frame;
3505
[email protected]dd7daa82009-08-10 05:46:453506 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:293507
3508 do {
3509 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:453510 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:293511
3512 // We don't start another scoping effort unless at least one match has
3513 // been found.
3514 if (result) {
3515 // Start new scoping request. If the scoping function determines that it
3516 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:453517 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:593518 search_text,
3519 options,
initial.commit09911bf2008-07-26 23:55:293520 true); // reset the tickmarks
3521 }
3522
3523 // Iterate to the next frame. The frame will not necessarily scope, for
3524 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:273525 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:293526 } while (search_frame != main_frame);
3527 }
3528}
3529
[email protected]310ebd6302011-10-10 19:06:283530void RenderViewImpl::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
[email protected]24a7f3c2010-03-25 08:26:493531 WebView* view = webview();
3532 if (!view)
3533 return;
3534
3535 WebDocument doc = view->mainFrame()->document();
[email protected]872542532011-06-23 00:43:163536 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:013537 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:493538 return;
3539 }
3540
3541 bool clear_selection =
3542 params.action == ViewMsg_StopFinding_Params::kClearSelection;
3543 if (clear_selection)
3544 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
3545
3546 WebFrame* frame = view->mainFrame();
3547 while (frame) {
3548 frame->stopFinding(clear_selection);
3549 frame = frame->traverseNext(false);
3550 }
3551
3552 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
3553 WebFrame* focused_frame = view->focusedFrame();
3554 if (focused_frame) {
3555 WebDocument doc = focused_frame->document();
3556 if (!doc.isNull()) {
3557 WebNode node = doc.focusedNode();
3558 if (!node.isNull())
3559 node.simulateClick();
3560 }
3561 }
3562 }
3563}
3564
[email protected]310ebd6302011-10-10 19:06:283565void RenderViewImpl::OnFindReplyAck() {
[email protected]24a7f3c2010-03-25 08:26:493566 // Check if there is any queued up request waiting to be sent.
3567 if (queued_find_reply_message_.get()) {
3568 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:423569 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:493570 }
3571}
3572
[email protected]54087fe2011-10-28 22:02:483573void RenderViewImpl::OnZoom(content::PageZoom zoom) {
[email protected]40bd6582009-12-04 23:49:513574 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3575 return;
3576
[email protected]258d31122010-05-09 10:59:413577 webview()->hidePopups();
[email protected]854ab5462011-11-22 20:48:103578
[email protected]b75b8292010-10-01 07:28:253579 double old_zoom_level = webview()->zoomLevel();
3580 double zoom_level;
[email protected]54087fe2011-10-28 22:02:483581 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]b75b8292010-10-01 07:28:253582 zoom_level = 0;
3583 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
3584 // Previous zoom level is a whole number, so just increment/decrement.
[email protected]54087fe2011-10-28 22:02:483585 zoom_level = old_zoom_level + zoom;
[email protected]b75b8292010-10-01 07:28:253586 } else {
3587 // Either the user hit the zoom factor limit and thus the zoom level is now
3588 // not a whole number, or a plugin changed it to a custom value. We want
3589 // to go to the next whole number so that the user can always get back to
3590 // 100% with the keyboard/menu.
[email protected]54087fe2011-10-28 22:02:483591 if ((old_zoom_level > 1 && zoom > 0) ||
3592 (old_zoom_level < 1 && zoom < 0)) {
3593 zoom_level = static_cast<int>(old_zoom_level + zoom);
[email protected]b75b8292010-10-01 07:28:253594 } else {
3595 // We're going towards 100%, so first go to the next whole number.
3596 zoom_level = static_cast<int>(old_zoom_level);
3597 }
3598 }
[email protected]b75b8292010-10-01 07:28:253599 webview()->setZoomLevel(false, zoom_level);
[email protected]47578fa02011-11-02 19:34:413600 zoomLevelChanged();
3601}
3602
3603void RenderViewImpl::OnZoomFactor(content::PageZoom zoom,
3604 int zoom_center_x, int zoom_center_y) {
3605 ZoomFactorHelper(zoom, zoom_center_x, zoom_center_y,
3606 kScalingIncrementForGesture);
3607}
3608
3609void RenderViewImpl::ZoomFactorHelper(content::PageZoom zoom,
3610 int zoom_center_x,
3611 int zoom_center_y,
3612 float scaling_increment) {
3613 if (!webview()) // Not sure if this can happen, but no harm in being safe.
3614 return;
3615
[email protected]c514d6372011-08-16 22:54:443616 double old_page_scale_factor = webview()->pageScaleFactor();
3617 double page_scale_factor;
[email protected]54087fe2011-10-28 22:02:483618 if (zoom == content::PAGE_ZOOM_RESET) {
[email protected]c514d6372011-08-16 22:54:443619 page_scale_factor = 1.0;
3620 } else {
3621 page_scale_factor = old_page_scale_factor +
[email protected]47578fa02011-11-02 19:34:413622 (zoom > 0 ? scaling_increment : -scaling_increment);
[email protected]c514d6372011-08-16 22:54:443623 }
[email protected]47578fa02011-11-02 19:34:413624 if (page_scale_factor > 0) {
[email protected]85191362011-11-08 18:53:093625 webview()->setPageScaleFactor(page_scale_factor,
3626 WebPoint(zoom_center_x, zoom_center_y));
[email protected]47578fa02011-11-02 19:34:413627 }
[email protected]40bd6582009-12-04 23:49:513628}
3629
[email protected]310ebd6302011-10-10 19:06:283630void RenderViewImpl::OnSetZoomLevel(double zoom_level) {
[email protected]d0b8d092010-10-25 04:05:173631 // Don't set zoom level for full-page plugin since they don't use the same
3632 // zoom settings.
3633 if (webview()->mainFrame()->document().isPluginDocument())
3634 return;
3635
3636 webview()->hidePopups();
3637 webview()->setZoomLevel(false, zoom_level);
3638 zoomLevelChanged();
3639}
3640
[email protected]310ebd6302011-10-10 19:06:283641void RenderViewImpl::OnSetZoomLevelForLoadingURL(const GURL& url,
3642 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:543643 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:293644}
3645
[email protected]310ebd6302011-10-10 19:06:283646void RenderViewImpl::OnExitFullscreen() {
[email protected]2b624c562011-10-27 22:58:263647 // TODO(darin): Remove this IPC once WebKit has been updated.
3648#ifndef WEBKIT_HAS_NEW_FULLSCREEN_API
[email protected]8a5e0ca2011-08-25 06:30:473649 webview()->exitFullscreen();
[email protected]2b624c562011-10-27 22:58:263650#endif
[email protected]8a5e0ca2011-08-25 06:30:473651}
3652
[email protected]310ebd6302011-10-10 19:06:283653void RenderViewImpl::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:273654 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:293655}
3656
[email protected]310ebd6302011-10-10 19:06:283657void RenderViewImpl::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:273658 WebString no_encoding;
3659 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:183660}
3661
[email protected]310ebd6302011-10-10 19:06:283662WebFrame* RenderViewImpl::GetChildFrame(const string16& xpath) const {
[email protected]dd7daa82009-08-10 05:46:453663 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:273664 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:453665
3666 // xpath string can represent a frame deep down the tree (across multiple
3667 // frame DOMs).
3668 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
3669 // should break into 2 xpaths
3670 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
[email protected]318bf5802011-08-08 17:12:413671 std::vector<string16> xpaths;
3672 base::SplitString(xpath, '\n', &xpaths);
[email protected]dd7daa82009-08-10 05:46:453673
[email protected]26aa0482009-09-30 16:55:273674 WebFrame* frame = webview()->mainFrame();
[email protected]318bf5802011-08-08 17:12:413675 for (std::vector<string16>::const_iterator i = xpaths.begin();
3676 frame && i != xpaths.end(); ++i) {
3677 frame = frame->findChildByExpression(*i);
initial.commit09911bf2008-07-26 23:55:293678 }
3679
[email protected]dd7daa82009-08-10 05:46:453680 return frame;
initial.commit09911bf2008-07-26 23:55:293681}
3682
[email protected]310ebd6302011-10-10 19:06:283683void RenderViewImpl::OnScriptEvalRequest(const string16& frame_xpath,
3684 const string16& jscript,
3685 int id,
3686 bool notify_result) {
[email protected]882b7b22010-10-05 03:34:533687 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:293688}
3689
[email protected]310ebd6302011-10-10 19:06:283690void RenderViewImpl::OnCSSInsertRequest(const string16& frame_xpath,
3691 const std::string& css) {
[email protected]b6cb3a842011-06-24 18:28:413692 WebFrame* frame = GetChildFrame(frame_xpath);
3693 if (!frame)
[email protected]216813952011-05-19 22:21:263694 return;
[email protected]ae461542009-06-19 19:03:413695
[email protected]01cf589c2011-07-28 18:04:033696 frame->document().insertUserStyleSheet(
3697 WebString::fromUTF8(css),
3698 WebDocument::UserStyleAuthorLevel);
[email protected]1810e132009-03-24 23:35:483699}
3700
[email protected]310ebd6302011-10-10 19:06:283701void RenderViewImpl::OnAllowBindings(int enabled_bindings_flags) {
[email protected]81e63782009-02-27 19:35:093702 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:293703}
3704
[email protected]310ebd6302011-10-10 19:06:283705void RenderViewImpl::OnSetWebUIProperty(const std::string& name,
3706 const std::string& value) {
[email protected]e091df82011-10-11 18:13:213707 DCHECK(enabled_bindings_ & content::BINDINGS_POLICY_WEB_UI);
[email protected]c50008512011-02-03 01:17:273708 GetWebUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:293709}
3710
[email protected]310ebd6302011-10-10 19:06:283711void RenderViewImpl::OnReservePageIDRange(int size_of_range) {
initial.commit09911bf2008-07-26 23:55:293712 next_page_id_ += size_of_range + 1;
3713}
3714
[email protected]310ebd6302011-10-10 19:06:283715void RenderViewImpl::OnDragTargetDragEnter(const WebDropData& drop_data,
3716 const gfx::Point& client_point,
3717 const gfx::Point& screen_point,
3718 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553719 WebDragOperation operation = webview()->dragTargetDragEnter(
3720 drop_data.ToDragData(),
[email protected]59f4f2fa2011-03-23 01:00:553721 client_point,
3722 screen_point,
3723 ops);
3724
3725 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3726}
3727
[email protected]310ebd6302011-10-10 19:06:283728void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point,
3729 const gfx::Point& screen_point,
3730 WebDragOperationsMask ops) {
[email protected]59f4f2fa2011-03-23 01:00:553731 WebDragOperation operation = webview()->dragTargetDragOver(
3732 client_point,
3733 screen_point,
3734 ops);
3735
3736 Send(new DragHostMsg_UpdateDragCursor(routing_id_, operation));
3737}
3738
[email protected]310ebd6302011-10-10 19:06:283739void RenderViewImpl::OnDragTargetDragLeave() {
[email protected]59f4f2fa2011-03-23 01:00:553740 webview()->dragTargetDragLeave();
3741}
3742
[email protected]310ebd6302011-10-10 19:06:283743void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point,
3744 const gfx::Point& screen_point) {
[email protected]59f4f2fa2011-03-23 01:00:553745 webview()->dragTargetDrop(client_point, screen_point);
[email protected]fcad49452011-06-28 17:11:573746
3747 Send(new DragHostMsg_TargetDrop_ACK(routing_id_));
[email protected]59f4f2fa2011-03-23 01:00:553748}
3749
[email protected]310ebd6302011-10-10 19:06:283750void RenderViewImpl::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
3751 const gfx::Point& screen_point,
3752 bool ended,
3753 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:033754 if (ended) {
[email protected]26aa0482009-09-30 16:55:273755 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:203756 } else {
3757 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:033758 }
initial.commit09911bf2008-07-26 23:55:293759}
3760
[email protected]310ebd6302011-10-10 19:06:283761void RenderViewImpl::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:273762 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:293763}
3764
[email protected]310ebd6302011-10-10 19:06:283765void RenderViewImpl::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:593766 webkit_preferences_ = prefs;
3767 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:293768}
3769
[email protected]310ebd6302011-10-10 19:06:283770void RenderViewImpl::OnSetAltErrorPageURL(const GURL& url) {
initial.commit09911bf2008-07-26 23:55:293771 alternate_error_page_url_ = url;
3772}
3773
[email protected]310ebd6302011-10-10 19:06:283774void RenderViewImpl::OnCustomContextMenuAction(
[email protected]b29aa74b2011-01-31 21:41:083775 const webkit_glue::CustomContextMenuContext& custom_context,
3776 unsigned action) {
3777 if (custom_context.is_pepper_menu)
3778 pepper_delegate_.OnCustomContextMenuAction(custom_context, action);
3779 else
3780 webview()->performCustomContextMenuAction(action);
[email protected]440a0e52011-09-13 17:38:583781 FOR_EACH_OBSERVER(RenderViewObserver, observers_,
3782 ContextMenuAction(action));
[email protected]a0c7153e2009-12-09 14:36:333783}
3784
[email protected]310ebd6302011-10-10 19:06:283785void RenderViewImpl::OnEnumerateDirectoryResponse(
[email protected]600ea402011-04-12 00:01:513786 int id,
3787 const std::vector<FilePath>& paths) {
3788 if (!enumeration_completions_[id])
3789 return;
3790
3791 WebVector<WebString> ws_file_names(paths.size());
3792 for (size_t i = 0; i < paths.size(); ++i)
3793 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
3794
3795 enumeration_completions_[id]->didChooseFile(ws_file_names);
3796 enumeration_completions_.erase(id);
3797}
3798
[email protected]310ebd6302011-10-10 19:06:283799void RenderViewImpl::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:363800 // This could happen if we navigated to a different page before the user
3801 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:473802 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:363803 return;
3804
[email protected]cdaf8d02010-03-30 19:52:473805 WebVector<WebString> ws_file_names(paths.size());
3806 for (size_t i = 0; i < paths.size(); ++i)
3807 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:463808
[email protected]cdaf8d02010-03-30 19:52:473809 if (file_chooser_completions_.front()->completion)
3810 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
3811 file_chooser_completions_.pop_front();
3812
3813 // If there are more pending file chooser requests, schedule one now.
3814 if (!file_chooser_completions_.empty()) {
3815 Send(new ViewHostMsg_RunFileChooser(routing_id_,
3816 file_chooser_completions_.front()->params));
3817 }
initial.commit09911bf2008-07-26 23:55:293818}
3819
[email protected]2bf834f2011-11-17 20:02:213820void RenderViewImpl::OnEnablePreferredSizeChangedMode() {
[email protected]9fb325e2010-05-06 18:23:243821 if (send_preferred_size_changes_)
3822 return;
[email protected]9fb325e2010-05-06 18:23:243823 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:393824
[email protected]d812fd12011-05-27 23:05:073825 // Start off with an initial preferred size notification (in case
3826 // |didUpdateLayout| was already called).
3827 if (webview())
3828 didUpdateLayout(webview()->mainFrame());
[email protected]0666aef2009-05-13 19:48:083829}
3830
[email protected]310ebd6302011-10-10 19:06:283831void RenderViewImpl::OnDisableScrollbarsForSmallWindows(
[email protected]cda45c02010-02-25 19:28:103832 const gfx::Size& disable_scrollbar_size_limit) {
3833 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
3834}
3835
[email protected]310ebd6302011-10-10 19:06:283836void RenderViewImpl::OnSetRendererPrefs(
[email protected]daf82f82011-10-31 22:35:313837 const content::RendererPreferences& renderer_prefs) {
[email protected]80d96fa2009-06-10 22:34:513838 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:373839 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:133840#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:413841 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
3842 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:463843 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]42e5c862011-04-07 22:13:513844 gfx::NativeTheme::instance()->SetScrollbarColors(
[email protected]8d1b864d12010-10-10 00:04:343845 renderer_prefs.thumb_inactive_color,
3846 renderer_prefs.thumb_active_color,
3847 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:323848
[email protected]644d77e2010-01-27 01:03:103849 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:323850 webview()->setScrollbarColors(
3851 renderer_prefs.thumb_inactive_color,
3852 renderer_prefs.thumb_active_color,
3853 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:103854 webview()->setSelectionColors(
3855 renderer_prefs.active_selection_bg_color,
3856 renderer_prefs.active_selection_fg_color,
3857 renderer_prefs.inactive_selection_bg_color,
3858 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:463859 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:103860 }
[email protected]7a74e102009-09-03 00:16:563861#endif
[email protected]80d96fa2009-06-10 22:34:513862}
3863
[email protected]310ebd6302011-10-10 19:06:283864void RenderViewImpl::OnMediaPlayerActionAt(const gfx::Point& location,
3865 const WebMediaPlayerAction& action) {
[email protected]952cb702009-10-07 05:50:283866 if (webview())
3867 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:563868}
3869
[email protected]310ebd6302011-10-10 19:06:283870void RenderViewImpl::OnGetAllSavableResourceLinksForCurrentPage(
[email protected]18d5be92011-07-25 18:00:193871 const GURL& page_url) {
3872 // Prepare list to storage all savable resource links.
3873 std::vector<GURL> resources_list;
3874 std::vector<GURL> referrers_list;
3875 std::vector<GURL> frames_list;
3876 webkit_glue::SavableResourcesResult result(&resources_list,
3877 &referrers_list,
3878 &frames_list);
3879
3880 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
3881 webview(),
3882 page_url,
3883 &result,
[email protected]2a80aee2011-10-07 16:06:033884 chrome::GetSavableSchemes())) {
[email protected]18d5be92011-07-25 18:00:193885 // If something is wrong when collecting all savable resource links,
3886 // send empty list to embedder(browser) to tell it failed.
3887 referrers_list.clear();
3888 resources_list.clear();
3889 frames_list.clear();
3890 }
3891
3892 // Send result of all savable resource links to embedder.
3893 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id(),
3894 resources_list,
3895 referrers_list,
3896 frames_list));
3897}
3898
[email protected]310ebd6302011-10-10 19:06:283899void RenderViewImpl::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]18d5be92011-07-25 18:00:193900 const std::vector<GURL>& links,
3901 const std::vector<FilePath>& local_paths,
3902 const FilePath& local_directory_name) {
3903
3904 // Convert std::vector of GURLs to WebVector<WebURL>
3905 WebVector<WebURL> weburl_links(links);
3906
3907 // Convert std::vector of std::strings to WebVector<WebString>
3908 WebVector<WebString> webstring_paths(local_paths.size());
3909 for (size_t i = 0; i < local_paths.size(); i++)
3910 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
3911
3912 WebPageSerializer::serialize(webview()->mainFrame(), true, this, weburl_links,
3913 webstring_paths,
3914 webkit_glue::FilePathToWebString(
3915 local_directory_name));
3916}
3917
[email protected]310ebd6302011-10-10 19:06:283918void RenderViewImpl::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:273919 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:473920 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:293921}
3922
[email protected]310ebd6302011-10-10 19:06:283923void RenderViewImpl::OnSwapOut(const ViewMsg_SwapOut_Params& params) {
[email protected]992db4c2011-05-12 15:37:153924 if (is_swapped_out_)
3925 return;
3926
3927 // Swap this RenderView out so the tab can navigate to a page rendered by a
3928 // different process. This involves running the unload handler and clearing
3929 // the page. Once WasSwappedOut is called, we also allow this process to exit
3930 // if there are no other active RenderViews in it.
3931
3932 // Send an UpdateState message before we get swapped out.
3933 SyncNavigationState();
3934
3935 // Synchronously run the unload handler before sending the ACK.
3936 webview()->dispatchUnloadEvent();
3937
3938 // Swap out and stop sending any IPC messages that are not ACKs.
3939 SetSwappedOut(true);
3940
3941 // Replace the page with a blank dummy URL. The unload handler will not be
3942 // run a second time, thanks to a check in FrameLoader::stopLoading.
3943 // TODO(creis): Need to add a better way to do this that avoids running the
3944 // beforeunload handler. For now, we just run it a second time silently.
3945 webview()->mainFrame()->loadHTMLString(std::string(),
3946 GURL("about:swappedout"),
3947 GURL("about:swappedout"),
3948 false);
3949
3950 // Just echo back the params in the ACK.
3951 Send(new ViewHostMsg_SwapOut_ACK(routing_id_, params));
3952}
3953
[email protected]310ebd6302011-10-10 19:06:283954void RenderViewImpl::OnClosePage() {
[email protected]77fc9b92011-10-15 16:20:373955 FOR_EACH_OBSERVER(RenderViewObserver, observers_, ClosePage());
initial.commit09911bf2008-07-26 23:55:293956 // TODO(creis): We'd rather use webview()->Close() here, but that currently
3957 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
3958 // in the onunload handler from appearing. For now, we're bypassing that and
3959 // calling the FrameLoader's CloseURL method directly. This should be
3960 // revisited to avoid having two ways to close a page. Having a single way
3961 // to close that can run onunload is also useful for fixing
3962 // http://b/issue?id=753080.
[email protected]26aa0482009-09-30 16:55:273963 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:293964
[email protected]992db4c2011-05-12 15:37:153965 Send(new ViewHostMsg_ClosePage_ACK(routing_id_));
initial.commit09911bf2008-07-26 23:55:293966}
3967
[email protected]310ebd6302011-10-10 19:06:283968void RenderViewImpl::OnThemeChanged() {
[email protected]e8d6b9f2011-10-10 22:21:023969#if defined(USE_AURA)
3970 // Aura doesn't care if we switch themes.
3971#elif defined(OS_WIN)
[email protected]c6d942212011-03-30 19:02:163972 gfx::NativeThemeWin::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:463973 if (webview())
3974 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:573975#else // defined(OS_WIN)
3976 // TODO(port): we don't support theming on non-Windows platforms yet
3977 NOTIMPLEMENTED();
3978#endif
initial.commit09911bf2008-07-26 23:55:293979}
3980
[email protected]310ebd6302011-10-10 19:06:283981void RenderViewImpl::OnDisassociateFromPopupCount() {
[email protected]0aa55312008-10-17 21:53:083982 if (decrement_shared_popup_at_destruction_)
3983 shared_popup_counter_->data--;
3984 shared_popup_counter_ = new SharedRenderViewCounter(0);
3985 decrement_shared_popup_at_destruction_ = false;
3986}
3987
[email protected]310ebd6302011-10-10 19:06:283988bool RenderViewImpl::MaybeLoadAlternateErrorPage(WebFrame* frame,
3989 const WebURLError& error,
3990 bool replace) {
[email protected]15d79e12009-08-02 19:23:453991 // We only show alternate error pages in the main frame. They are
3992 // intended to assist the user when navigating, so there is not much
3993 // value in showing them for failed subframes. Ideally, we would be
3994 // able to use the TYPED transition type for this, but that flag is
3995 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:453996 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:453997 return false;
3998
3999 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:374000 // connection failure.
[email protected]15d79e12009-08-02 19:23:454001 int ec = error.reason;
4002 if (ec != net::ERR_NAME_NOT_RESOLVED &&
4003 ec != net::ERR_CONNECTION_FAILED &&
4004 ec != net::ERR_CONNECTION_REFUSED &&
4005 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:374006 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:454007 return false;
4008
4009 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:554010 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:454011 if (!error_page_url.is_valid())
4012 return false;
4013
4014 // Load an empty page first so there is an immediate response to the error,
4015 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:454016 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:364017 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:454018 error.unreachableURL,
4019 replace);
4020
4021 // Now, create a fetcher for the error page and associate it with the data
4022 // source we just created via the LoadHTMLString call. That way if another
4023 // navigation occurs, the fetcher will get destroyed.
[email protected]007733c2011-11-17 00:34:074024 DocumentState* document_state =
4025 DocumentState::FromDataSource(frame->provisionalDataSource());
4026 document_state->set_alt_error_page_fetcher(
[email protected]15d79e12009-08-02 19:23:454027 new AltErrorPageResourceFetcher(
4028 error_page_url, frame, error,
[email protected]6e806822011-11-19 01:51:084029 base::Bind(&RenderViewImpl::AltErrorPageFinished,
4030 base::Unretained(this))));
[email protected]15d79e12009-08-02 19:23:454031 return true;
4032}
4033
[email protected]310ebd6302011-10-10 19:06:284034void RenderViewImpl::AltErrorPageFinished(WebFrame* frame,
4035 const WebURLError& original_error,
4036 const std::string& html) {
[email protected]15d79e12009-08-02 19:23:454037 // Here, we replace the blank page we loaded previously.
[email protected]06333afe2011-02-24 14:55:094038 // If we failed to download the alternate error page, LoadNavigationErrorPage
[email protected]7ccddb8c2009-08-04 17:36:554039 // will simply display a default error page.
[email protected]06333afe2011-02-24 14:55:094040 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
[email protected]15d79e12009-08-02 19:23:454041}
4042
[email protected]310ebd6302011-10-10 19:06:284043void RenderViewImpl::OnMoveOrResizeStarted() {
[email protected]30f75e62009-02-25 22:01:004044 if (webview())
[email protected]a72a1fa2010-05-03 22:18:474045 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:004046}
4047
[email protected]310ebd6302011-10-10 19:06:284048void RenderViewImpl::OnResize(const gfx::Size& new_size,
[email protected]ee41e7d22011-10-14 19:34:094049 const gfx::Rect& resizer_rect,
4050 bool is_fullscreen) {
[email protected]cda45c02010-02-25 19:28:104051 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:474052 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:104053 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:204054 webview()->mainFrame()->setCanHaveScrollbars(
[email protected]a2ef54c2011-10-10 16:20:314055 ShouldDisplayScrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:104056 }
[email protected]dd6afca2011-08-13 03:44:314057 UpdateScrollState(webview()->mainFrame());
[email protected]cda45c02010-02-25 19:28:104058 }
4059
[email protected]ee41e7d22011-10-14 19:34:094060 RenderWidget::OnResize(new_size, resizer_rect, is_fullscreen);
[email protected]30f75e62009-02-25 22:01:004061}
[email protected]0aa477bd2009-03-23 22:21:434062
[email protected]310ebd6302011-10-10 19:06:284063void RenderViewImpl::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:014064 // Notify the pepper plugins that we started painting.
4065 pepper_delegate_.ViewInitiatedPaint();
[email protected]00c39612010-03-06 02:53:284066}
4067
[email protected]310ebd6302011-10-10 19:06:284068void RenderViewImpl::DidFlushPaint() {
[email protected]00c39612010-03-06 02:53:284069 // Notify any pepper plugins that we painted. This will call into the plugin,
4070 // and we it may ask to close itself as a result. This will, in turn, modify
4071 // our set, possibly invalidating the iterator. So we iterate on a copy that
4072 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:014073 pepper_delegate_.ViewFlushedPaint();
4074
[email protected]00c39612010-03-06 02:53:284075 WebFrame* main_frame = webview()->mainFrame();
4076
4077 // If we have a provisional frame we are between the start and commit stages
4078 // of loading and we don't want to save stats.
4079 if (!main_frame->provisionalDataSource()) {
4080 WebDataSource* ds = main_frame->dataSource();
[email protected]007733c2011-11-17 00:34:074081 DocumentState* document_state = DocumentState::FromDataSource(ds);
[email protected]00c39612010-03-06 02:53:284082
[email protected]05c8e502010-08-15 15:13:524083 // TODO(jar): The following code should all be inside a method, probably in
4084 // NavigatorState.
[email protected]00c39612010-03-06 02:53:284085 Time now = Time::Now();
[email protected]007733c2011-11-17 00:34:074086 if (document_state->first_paint_time().is_null()) {
4087 document_state->set_first_paint_time(now);
[email protected]00c39612010-03-06 02:53:284088 }
[email protected]007733c2011-11-17 00:34:074089 if (document_state->first_paint_after_load_time().is_null() &&
4090 !document_state->finish_load_time().is_null()) {
4091 document_state->set_first_paint_after_load_time(now);
[email protected]00c39612010-03-06 02:53:284092 }
4093 }
4094}
4095
[email protected]310ebd6302011-10-10 19:06:284096void RenderViewImpl::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:084097 RenderWidget::OnSwapBuffersPosted();
4098}
4099
[email protected]310ebd6302011-10-10 19:06:284100void RenderViewImpl::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:244101 RenderWidget::OnSwapBuffersComplete();
4102}
4103
[email protected]310ebd6302011-10-10 19:06:284104void RenderViewImpl::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:244105 RenderWidget::OnSwapBuffersAborted();
4106}
4107
[email protected]310ebd6302011-10-10 19:06:284108webkit::ppapi::PluginInstance* RenderViewImpl::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:154109 const gfx::Rect& paint_bounds,
4110 TransportDIB** dib,
4111 gfx::Rect* location,
4112 gfx::Rect* clip) {
4113 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
4114 paint_bounds, dib, location, clip);
4115}
4116
[email protected]310ebd6302011-10-10 19:06:284117gfx::Point RenderViewImpl::GetScrollOffset() {
[email protected]d812fd12011-05-27 23:05:074118 WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
[email protected]bcaf2272011-02-15 15:29:434119 return gfx::Point(scroll_offset.width, scroll_offset.height);
[email protected]d54169e92011-01-21 09:19:524120}
4121
[email protected]310ebd6302011-10-10 19:06:284122void RenderViewImpl::OnClearFocusedNode() {
[email protected]05d478752009-04-08 23:38:164123 if (webview())
[email protected]26aa0482009-09-30 16:55:274124 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:164125}
4126
[email protected]310ebd6302011-10-10 19:06:284127void RenderViewImpl::OnSetBackground(const SkBitmap& background) {
[email protected]699ab0d2009-04-23 23:19:144128 if (webview())
[email protected]b4bb2502009-10-01 22:35:274129 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:144130
4131 SetBackground(background);
4132}
4133
[email protected]310ebd6302011-10-10 19:06:284134void RenderViewImpl::OnSetActive(bool active) {
[email protected]8c66c5a2009-07-22 17:26:344135 if (webview())
[email protected]b4bb2502009-10-01 22:35:274136 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:264137
4138#if defined(OS_MACOSX)
4139 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4140 for (plugin_it = plugin_delegates_.begin();
4141 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4142 (*plugin_it)->SetWindowFocus(active);
4143 }
4144#endif
[email protected]8c66c5a2009-07-22 17:26:344145}
4146
[email protected]6ce7abc52010-02-02 18:40:144147#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284148void RenderViewImpl::OnSetWindowVisibility(bool visible) {
[email protected]6ce7abc52010-02-02 18:40:144149 // Inform plugins that their container has changed visibility.
4150 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4151 for (plugin_it = plugin_delegates_.begin();
4152 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4153 (*plugin_it)->SetContainerVisibility(visible);
4154 }
4155}
[email protected]1e6e3c992010-02-08 15:52:134156
[email protected]310ebd6302011-10-10 19:06:284157void RenderViewImpl::OnWindowFrameChanged(const gfx::Rect& window_frame,
4158 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:134159 // Inform plugins that their window's frame has changed.
4160 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4161 for (plugin_it = plugin_delegates_.begin();
4162 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4163 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
4164 }
4165}
[email protected]935d63d2010-10-15 23:31:554166
[email protected]310ebd6302011-10-10 19:06:284167void RenderViewImpl::OnPluginImeCompositionCompleted(const string16& text,
4168 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134169 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:554170 // applies to it or not, so inform all the delegates.
4171 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4172 for (plugin_it = plugin_delegates_.begin();
4173 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:134174 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:554175 }
4176}
[email protected]6ce7abc52010-02-02 18:40:144177#endif // OS_MACOSX
4178
[email protected]310ebd6302011-10-10 19:06:284179void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
[email protected]446705872009-09-10 07:22:484180 const EditCommands& edit_commands) {
4181 edit_commands_ = edit_commands;
4182}
4183
[email protected]310ebd6302011-10-10 19:06:284184void RenderViewImpl::Close() {
[email protected]60c42a8c72009-10-09 04:08:594185 // We need to grab a pointer to the doomed WebView before we destroy it.
4186 WebView* doomed = webview();
4187 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:494188 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:594189}
4190
[email protected]310ebd6302011-10-10 19:06:284191void RenderViewImpl::DidHandleKeyEvent() {
[email protected]446705872009-09-10 07:22:484192 edit_commands_.clear();
4193}
4194
[email protected]310ebd6302011-10-10 19:06:284195bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]b993705a2011-10-09 23:00:244196 return pepper_delegate_.HandleMouseEvent(event);
[email protected]67bfb83f2011-09-22 03:36:374197}
4198
[email protected]310ebd6302011-10-10 19:06:284199void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:514200 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:064201}
4202
[email protected]310ebd6302011-10-10 19:06:284203void RenderViewImpl::DidHandleTouchEvent(const WebTouchEvent& event) {
[email protected]2d0f2e92011-10-03 09:02:244204 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleTouchEvent(event));
4205}
4206
[email protected]310ebd6302011-10-10 19:06:284207void RenderViewImpl::OnWasHidden() {
[email protected]941e4552010-02-01 21:23:434208 RenderWidget::OnWasHidden();
4209
[email protected]a6939ca42011-02-18 17:58:074210 if (webview()) {
4211 webview()->settings()->setMinimumTimerInterval(
4212 webkit_glue::kBackgroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444213 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074214 }
4215
4216#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434217 // Inform plugins that their container is no longer visible.
4218 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4219 for (plugin_it = plugin_delegates_.begin();
4220 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4221 (*plugin_it)->SetContainerVisibility(false);
4222 }
[email protected]a6939ca42011-02-18 17:58:074223#endif // OS_MACOSX
[email protected]941e4552010-02-01 21:23:434224}
4225
[email protected]310ebd6302011-10-10 19:06:284226void RenderViewImpl::OnWasRestored(bool needs_repainting) {
[email protected]941e4552010-02-01 21:23:434227 RenderWidget::OnWasRestored(needs_repainting);
4228
[email protected]a6939ca42011-02-18 17:58:074229 if (webview()) {
4230 webview()->settings()->setMinimumTimerInterval(
4231 webkit_glue::kForegroundTabTimerInterval);
[email protected]f59203a2011-06-07 10:01:444232 webview()->setVisibilityState(visibilityState(), false);
[email protected]a6939ca42011-02-18 17:58:074233 }
4234
4235#if defined(OS_MACOSX)
[email protected]941e4552010-02-01 21:23:434236 // Inform plugins that their container is now visible.
4237 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4238 for (plugin_it = plugin_delegates_.begin();
4239 plugin_it != plugin_delegates_.end(); ++plugin_it) {
4240 (*plugin_it)->SetContainerVisibility(true);
4241 }
[email protected]784ea1ab2010-09-18 00:02:344242#endif // OS_MACOSX
[email protected]a6939ca42011-02-18 17:58:074243}
[email protected]1e6e3c992010-02-08 15:52:134244
[email protected]310ebd6302011-10-10 19:06:284245bool RenderViewImpl::SupportsAsynchronousSwapBuffers() {
[email protected]555e75d2011-10-08 01:23:384246 if (WebWidgetHandlesCompositorScheduling())
4247 return false;
4248
[email protected]65225772011-05-12 21:10:244249 WebKit::WebGraphicsContext3D* context = webview()->graphicsContext3D();
4250 if (!context)
4251 return false;
4252 std::string extensions(context->getRequestableExtensionsCHROMIUM().utf8());
4253 return extensions.find("GL_CHROMIUM_swapbuffers_complete_callback") !=
4254 std::string::npos;
4255}
4256
[email protected]310ebd6302011-10-10 19:06:284257void RenderViewImpl::OnSetFocus(bool enable) {
[email protected]1e6e3c992010-02-08 15:52:134258 RenderWidget::OnSetFocus(enable);
4259
[email protected]7d3c02c2010-05-05 23:10:314260 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:074261 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:134262 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
4263 for (plugin_it = plugin_delegates_.begin();
4264 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:344265#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:314266 // RenderWidget's call to setFocus can cause the underlying webview's
4267 // activation state to change just like a call to setIsActive.
4268 if (enable)
4269 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:344270#endif
[email protected]7d3c02c2010-05-05 23:10:314271 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134272 }
[email protected]589621b2010-09-23 22:01:074273
4274 // Notify all Pepper plugins.
4275 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:134276 }
4277}
[email protected]941e4552010-02-01 21:23:434278
[email protected]310ebd6302011-10-10 19:06:284279void RenderViewImpl::PpapiPluginFocusChanged() {
[email protected]e99ef6f2011-10-16 01:13:004280 UpdateTextInputState();
[email protected]3f783362011-10-21 22:40:504281 UpdateSelectionBounds();
[email protected]56ea1a62011-05-30 07:05:574282}
4283
[email protected]73bf95812011-10-12 11:38:324284void RenderViewImpl::PpapiPluginTextInputTypeChanged() {
[email protected]e99ef6f2011-10-16 01:13:004285 UpdateTextInputState();
[email protected]73bf95812011-10-12 11:38:324286}
4287
[email protected]3f783362011-10-21 22:40:504288void RenderViewImpl::PpapiPluginCaretPositionChanged() {
4289 UpdateSelectionBounds();
4290}
4291
[email protected]73bf95812011-10-12 11:38:324292void RenderViewImpl::PpapiPluginCancelComposition() {
4293 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
4294 ui::Range range(ui::Range::InvalidRange());
4295 Send(new ViewHostMsg_ImeCompositionRangeChanged(routing_id(), range));
4296}
4297
[email protected]310ebd6302011-10-10 19:06:284298void RenderViewImpl::OnImeSetComposition(
[email protected]56ea1a62011-05-30 07:05:574299 const string16& text,
4300 const std::vector<WebKit::WebCompositionUnderline>& underlines,
4301 int selection_start,
4302 int selection_end) {
[email protected]73bf95812011-10-12 11:38:324303 if (pepper_delegate_.IsPluginFocused()) {
4304 // When a PPAPI plugin has focus, we bypass WebKit.
4305 pepper_delegate_.OnImeSetComposition(text,
4306 underlines,
4307 selection_start,
4308 selection_end);
4309 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234310#if defined(OS_WIN)
4311 // When a plug-in has focus, we create platform-specific IME data used by
4312 // our IME emulator and send it directly to the focused plug-in, i.e. we
4313 // bypass WebKit. (WebPluginDelegate dispatches this IME data only when its
4314 // instance ID is the same one as the specified ID.)
4315 if (focused_plugin_id_ >= 0) {
4316 std::vector<int> clauses;
4317 std::vector<int> target;
4318 for (size_t i = 0; i < underlines.size(); ++i) {
4319 clauses.push_back(underlines[i].startOffset);
4320 clauses.push_back(underlines[i].endOffset);
4321 if (underlines[i].thick) {
4322 target.clear();
4323 target.push_back(underlines[i].startOffset);
4324 target.push_back(underlines[i].endOffset);
4325 }
4326 }
4327 std::set<WebPluginDelegateProxy*>::iterator it;
4328 for (it = plugin_delegates_.begin();
4329 it != plugin_delegates_.end(); ++it) {
4330 (*it)->ImeCompositionUpdated(text, clauses, target, selection_end,
4331 focused_plugin_id_);
4332 }
4333 return;
4334 }
4335#endif
[email protected]56ea1a62011-05-30 07:05:574336 RenderWidget::OnImeSetComposition(text,
4337 underlines,
4338 selection_start,
4339 selection_end);
4340 }
4341}
4342
[email protected]4de6d1692011-10-12 08:45:444343void RenderViewImpl::OnImeConfirmComposition(
4344 const string16& text, const ui::Range& replacement_range) {
[email protected]56ea1a62011-05-30 07:05:574345 if (pepper_delegate_.IsPluginFocused()) {
[email protected]73bf95812011-10-12 11:38:324346 // When a PPAPI plugin has focus, we bypass WebKit.
4347 pepper_delegate_.OnImeConfirmComposition(text);
[email protected]56ea1a62011-05-30 07:05:574348 } else {
[email protected]e6ae0f6c2011-10-04 10:39:234349#if defined(OS_WIN)
4350 // Same as OnImeSetComposition(), we send the text from IMEs directly to
4351 // plug-ins. When we send IME text directly to plug-ins, we should not send
4352 // it to WebKit to prevent WebKit from controlling IMEs.
[email protected]4de6d1692011-10-12 08:45:444353 // TODO(thakis): Honor |replacement_range| for plugins?
[email protected]e6ae0f6c2011-10-04 10:39:234354 if (focused_plugin_id_ >= 0) {
4355 std::set<WebPluginDelegateProxy*>::iterator it;
4356 for (it = plugin_delegates_.begin();
4357 it != plugin_delegates_.end(); ++it) {
4358 (*it)->ImeCompositionCompleted(text, focused_plugin_id_);
4359 }
4360 return;
4361 }
4362#endif
[email protected]ebd28ac2011-10-13 18:49:054363 if (replacement_range.IsValid() && webview()) {
4364 // Select the text in |replacement_range|, it will then be replaced by
4365 // text added by the call to RenderWidget::OnImeConfirmComposition().
4366 if (WebFrame* frame = webview()->focusedFrame()) {
[email protected]4bacb822011-11-02 15:10:164367 WebRange webrange = WebRange::fromDocumentRange(
4368 frame, replacement_range.start(), replacement_range.length());
4369 if (!webrange.isNull())
4370 frame->setSelectionToRange(webrange);
[email protected]ebd28ac2011-10-13 18:49:054371 }
4372 }
[email protected]4de6d1692011-10-12 08:45:444373 RenderWidget::OnImeConfirmComposition(text, replacement_range);
[email protected]56ea1a62011-05-30 07:05:574374 }
4375}
4376
[email protected]310ebd6302011-10-10 19:06:284377ui::TextInputType RenderViewImpl::GetTextInputType() {
[email protected]73bf95812011-10-12 11:38:324378 return pepper_delegate_.IsPluginFocused() ?
4379 pepper_delegate_.GetTextInputType() : RenderWidget::GetTextInputType();
4380}
4381
[email protected]3f783362011-10-21 22:40:504382void RenderViewImpl::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) {
4383 if (pepper_delegate_.IsPluginFocused()) {
4384 // TODO(kinaba) http://crbug.com/101101
4385 // Current Pepper IME API does not handle selection bounds. So we simply
4386 // use the caret position as an empty range for now. It will be updated
4387 // after Pepper API equips features related to surrounding text retrieval.
4388 gfx::Rect caret = pepper_delegate_.GetCaretBounds();
4389 *start = caret;
4390 *end = caret;
4391 return;
4392 }
4393 RenderWidget::GetSelectionBounds(start, end);
[email protected]ad26ef42011-06-17 07:59:454394}
4395
[email protected]310ebd6302011-10-10 19:06:284396bool RenderViewImpl::CanComposeInline() {
[email protected]73bf95812011-10-12 11:38:324397 return pepper_delegate_.IsPluginFocused() ?
4398 pepper_delegate_.CanComposeInline() : true;
[email protected]56ea1a62011-05-30 07:05:574399}
4400
[email protected]e6ae0f6c2011-10-04 10:39:234401#if defined(OS_WIN)
[email protected]310ebd6302011-10-10 19:06:284402void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]e6ae0f6c2011-10-04 10:39:234403 if (focused)
4404 focused_plugin_id_ = plugin_id;
4405 else
4406 focused_plugin_id_ = -1;
4407}
4408#endif
4409
[email protected]43f28f832010-02-03 02:28:484410#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284411void RenderViewImpl::PluginFocusChanged(bool focused, int plugin_id) {
[email protected]b7f75862011-01-21 21:15:134412 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
4413 focused, plugin_id);
4414 Send(msg);
4415}
4416
[email protected]310ebd6302011-10-10 19:06:284417void RenderViewImpl::StartPluginIme() {
[email protected]b7f75862011-01-21 21:15:134418 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:554419 // This message can be sent during event-handling, and needs to be delivered
4420 // within that context.
4421 msg->set_unblock(true);
4422 Send(msg);
4423}
4424
[email protected]310ebd6302011-10-10 19:06:284425gfx::PluginWindowHandle RenderViewImpl::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234426 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:484427 gfx::PluginWindowHandle window = NULL;
4428 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:234429 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:114430 if (window) {
4431 fake_plugin_window_handles_.insert(window);
4432 }
[email protected]43f28f832010-02-03 02:28:484433 return window;
4434}
4435
[email protected]310ebd6302011-10-10 19:06:284436void RenderViewImpl::DestroyFakePluginWindowHandle(
4437 gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:114438 if (window && fake_plugin_window_handles_.find(window) !=
4439 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:484440 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:114441 fake_plugin_window_handles_.erase(window);
4442 }
[email protected]43f28f832010-02-03 02:28:484443}
4444
[email protected]310ebd6302011-10-10 19:06:284445void RenderViewImpl::AcceleratedSurfaceSetIOSurface(
4446 gfx::PluginWindowHandle window,
4447 int32 width,
4448 int32 height,
4449 uint64 io_surface_identifier) {
[email protected]44ce0b12010-03-12 16:45:334450 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:484451 routing_id(), window, width, height, io_surface_identifier));
4452}
4453
[email protected]310ebd6302011-10-10 19:06:284454void RenderViewImpl::AcceleratedSurfaceSetTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334455 gfx::PluginWindowHandle window,
4456 int32 width,
4457 int32 height,
4458 TransportDIB::Handle transport_dib) {
4459 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:074460 routing_id(), window, width, height, transport_dib));
4461}
4462
[email protected]310ebd6302011-10-10 19:06:284463TransportDIB::Handle RenderViewImpl::AcceleratedSurfaceAllocTransportDIB(
[email protected]44ce0b12010-03-12 16:45:334464 size_t size) {
[email protected]1aef98132010-02-23 18:00:074465 TransportDIB::Handle dib_handle;
4466 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:384467 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:074468 return dib_handle;
4469 // Return an invalid handle if Send() fails.
4470 return TransportDIB::DefaultHandleValue();
4471}
4472
[email protected]310ebd6302011-10-10 19:06:284473void RenderViewImpl::AcceleratedSurfaceFreeTransportDIB(
4474 TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:074475 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
4476}
4477
[email protected]310ebd6302011-10-10 19:06:284478void RenderViewImpl::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:144479 gfx::PluginWindowHandle window, uint64 surface_id) {
4480 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
4481 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:484482}
4483#endif
[email protected]58c321d2010-02-19 12:11:284484
[email protected]310ebd6302011-10-10 19:06:284485bool RenderViewImpl::ScheduleFileChooser(
[email protected]8caadeb2011-11-22 02:45:234486 const content::FileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:474487 WebFileChooserCompletion* completion) {
4488 static const size_t kMaximumPendingFileChooseRequests = 4;
4489 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
4490 // This sanity check prevents too many file choose requests from getting
4491 // queued which could DoS the user. Getting these is most likely a
4492 // programming error (there are many ways to DoS the user so it's not
4493 // considered a "real" security check), either in JS requesting many file
4494 // choosers to pop up, or in a plugin.
4495 //
4496 // TODO(brettw) we might possibly want to require a user gesture to open
4497 // a file picker, which will address this issue in a better way.
4498 return false;
4499 }
4500
4501 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
4502 new PendingFileChooser(params, completion)));
4503 if (file_chooser_completions_.size() == 1) {
4504 // Actually show the browse dialog when this is the first request.
4505 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
4506 }
4507 return true;
4508}
4509
[email protected]310ebd6302011-10-10 19:06:284510WebKit::WebGeolocationClient* RenderViewImpl::geolocationClient() {
[email protected]676126f72011-01-15 00:03:514511 if (!geolocation_dispatcher_)
4512 geolocation_dispatcher_ = new GeolocationDispatcher(this);
4513 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:254514}
[email protected]61c9f032010-03-31 23:04:194515
[email protected]310ebd6302011-10-10 19:06:284516WebKit::WebSpeechInputController* RenderViewImpl::speechInputController(
[email protected]638694c2010-08-04 22:24:114517 WebKit::WebSpeechInputListener* listener) {
[email protected]9eb100e2011-10-14 05:08:224518#if defined(ENABLE_INPUT_SPEECH)
[email protected]676126f72011-01-15 00:03:514519 if (!speech_input_dispatcher_)
4520 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
[email protected]9eb100e2011-10-14 05:08:224521#endif
[email protected]676126f72011-01-15 00:03:514522 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:114523}
4524
[email protected]310ebd6302011-10-10 19:06:284525WebKit::WebDeviceOrientationClient* RenderViewImpl::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:514526 if (!device_orientation_dispatcher_)
4527 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
4528 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:534529}
4530
[email protected]310ebd6302011-10-10 19:06:284531void RenderViewImpl::zoomLimitsChanged(double minimum_level,
4532 double maximum_level) {
[email protected]b75b8292010-10-01 07:28:254533 // For now, don't remember plugin zoom values. We don't want to mix them with
4534 // normal web content (i.e. a fixed layout plugin would usually want them
4535 // different).
4536 bool remember = !webview()->mainFrame()->document().isPluginDocument();
4537
[email protected]b75b8292010-10-01 07:28:254538 int minimum_percent = static_cast<int>(
4539 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
4540 int maximum_percent = static_cast<int>(
4541 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:254542
4543 Send(new ViewHostMsg_UpdateZoomLimits(
4544 routing_id_, minimum_percent, maximum_percent, remember));
4545}
4546
[email protected]310ebd6302011-10-10 19:06:284547void RenderViewImpl::zoomLevelChanged() {
[email protected]b75b8292010-10-01 07:28:254548 bool remember = !webview()->mainFrame()->document().isPluginDocument();
[email protected]ba51d3b2011-08-24 19:53:084549 float zoom_level = webview()->zoomLevel();
[email protected]b75b8292010-10-01 07:28:254550 // Tell the browser which url got zoomed so it can update the menu and the
4551 // saved values if necessary
4552 Send(new ViewHostMsg_DidZoomURL(
[email protected]ba51d3b2011-08-24 19:53:084553 routing_id_, zoom_level, remember,
[email protected]b6cb3a842011-06-24 18:28:414554 GURL(webview()->mainFrame()->document().url())));
[email protected]b75b8292010-10-01 07:28:254555}
4556
[email protected]310ebd6302011-10-10 19:06:284557void RenderViewImpl::registerProtocolHandler(const WebString& scheme,
4558 const WebString& base_url,
4559 const WebString& url,
4560 const WebString& title) {
[email protected]a6d36cc2011-02-23 00:39:484561 GURL base(base_url);
4562 GURL absolute_url = base.Resolve(UTF16ToUTF8(url));
4563 if (base.GetOrigin() != absolute_url.GetOrigin()) {
4564 return;
4565 }
[email protected]f1a29a02011-10-06 23:08:444566 Send(new ViewHostMsg_RegisterProtocolHandler(routing_id_,
4567 UTF16ToUTF8(scheme),
4568 absolute_url,
4569 title));
[email protected]a6d36cc2011-02-23 00:39:484570}
4571
[email protected]310ebd6302011-10-10 19:06:284572void RenderViewImpl::registerIntentHandler(const WebString& action,
4573 const WebString& type,
4574 const WebString& href,
[email protected]63c239322011-10-31 23:56:304575 const WebString& title,
4576 const WebString& disposition) {
4577 Send(new IntentsHostMsg_RegisterIntentHandler(routing_id_,
[email protected]f1a29a02011-10-06 23:08:444578 action,
4579 type,
4580 href,
[email protected]63c239322011-10-31 23:56:304581 title,
4582 disposition));
[email protected]62af76e2011-08-01 02:34:014583}
4584
[email protected]310ebd6302011-10-10 19:06:284585WebKit::WebPageVisibilityState RenderViewImpl::visibilityState() const {
[email protected]f59203a2011-06-07 10:01:444586 WebKit::WebPageVisibilityState current_state = is_hidden() ?
4587 WebKit::WebPageVisibilityStateHidden :
4588 WebKit::WebPageVisibilityStateVisible;
4589 WebKit::WebPageVisibilityState override_state = current_state;
4590 if (content::GetContentClient()->renderer()->
4591 ShouldOverridePageVisibilityState(this,
4592 &override_state))
4593 return override_state;
4594 return current_state;
[email protected]94dec932011-05-26 20:04:214595}
4596
[email protected]310ebd6302011-10-10 19:06:284597void RenderViewImpl::startActivity(const WebKit::WebString& action,
4598 const WebKit::WebString& type,
4599 const WebKit::WebString& data,
4600 int intent_id) {
[email protected]ce9751942011-09-21 01:57:244601 webkit_glue::WebIntentData intent_data;
4602 intent_data.action = action;
4603 intent_data.type = type;
4604 intent_data.data = data;
4605 Send(new IntentsHostMsg_WebIntentDispatch(
4606 routing_id_, intent_data, intent_id));
[email protected]e235c7d02011-08-18 22:38:434607}
4608
[email protected]310ebd6302011-10-10 19:06:284609bool RenderViewImpl::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:194610 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:454611 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:194612 if (frame->parent() != NULL)
4613 return false;
4614
[email protected]f0a3d0b2010-08-06 22:51:534615 // Navigations initiated within Webkit are not sent out to the external host
4616 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:274617 // 1. The url scheme is not http/https
[email protected]d19ea342011-04-20 20:31:134618 // 2. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:534619 // opener relationship is maintained.
[email protected]d19ea342011-04-20 20:31:134620 // 3. Reloads/form submits/back forward navigations
[email protected]abbfaec2011-05-23 23:57:334621 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme))
[email protected]f0a3d0b2010-08-06 22:51:534622 return false;
4623
[email protected]2fc22d12010-12-02 23:08:164624 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:324625 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:014626 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:164627 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:014628 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:324629 // The opener relationship between the new window and the parent allows the
4630 // new window to script the parent and vice versa. This is not allowed if
4631 // the origins of the two domains are different. This can be treated as a
4632 // top level navigation and routed back to the host.
4633 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:274634 if (!opener) {
[email protected]86965362011-04-21 18:42:514635 return true;
[email protected]d19ea342011-04-20 20:31:134636 } else {
[email protected]b6cb3a842011-06-24 18:28:414637 if (url.GetOrigin() != GURL(opener->document().url()).GetOrigin())
[email protected]d0ed50d2010-06-22 01:01:324638 return true;
4639 }
4640 }
[email protected]61c9f032010-03-31 23:04:194641 return false;
4642}
[email protected]2b06a992010-08-21 05:48:224643
[email protected]310ebd6302011-10-10 19:06:284644void RenderViewImpl::OnAsyncFileOpened(
4645 base::PlatformFileError error_code,
4646 IPC::PlatformFileForTransit file_for_transit,
4647 int message_id) {
[email protected]27a9ef32010-09-10 04:06:244648 pepper_delegate_.OnAsyncFileOpened(
4649 error_code,
4650 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
4651 message_id);
4652}
[email protected]caf706f2010-10-26 17:54:084653
[email protected]310ebd6302011-10-10 19:06:284654void RenderViewImpl::OnPpapiBrokerChannelCreated(
[email protected]2b657fd2011-04-18 16:00:474655 int request_id,
4656 base::ProcessHandle broker_process_handle,
[email protected]d54305072011-06-22 20:58:434657 const IPC::ChannelHandle& handle) {
[email protected]2b657fd2011-04-18 16:00:474658 pepper_delegate_.OnPpapiBrokerChannelCreated(request_id,
4659 broker_process_handle,
4660 handle);
[email protected]eb415bf0e2011-04-14 02:45:424661}
4662
[email protected]caf706f2010-10-26 17:54:084663#if defined(OS_MACOSX)
[email protected]310ebd6302011-10-10 19:06:284664void RenderViewImpl::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:154665 if (external_popup_menu_ == NULL) {
4666 // Crash reports from the field indicate that we can be notified with a
4667 // NULL external popup menu (we probably get notified twice).
4668 // If you hit this please file a bug against jcivelli and include the page
4669 // and steps to repro.
4670 NOTREACHED();
4671 return;
4672 }
[email protected]caf706f2010-10-26 17:54:084673 external_popup_menu_->DidSelectItem(selected_index);
4674 external_popup_menu_.reset();
4675}
4676#endif
[email protected]bb461532010-11-26 21:50:234677
[email protected]1b4209f2011-01-07 00:25:404678#if defined(ENABLE_FLAPPER_HACKS)
[email protected]310ebd6302011-10-10 19:06:284679void RenderViewImpl::OnConnectTcpACK(
[email protected]1b4209f2011-01-07 00:25:404680 int request_id,
4681 IPC::PlatformFileForTransit socket_for_transit,
[email protected]5a2b68f2011-11-10 00:00:494682 const PP_NetAddress_Private& local_addr,
4683 const PP_NetAddress_Private& remote_addr) {
[email protected]1b4209f2011-01-07 00:25:404684 pepper_delegate_.OnConnectTcpACK(
4685 request_id,
4686 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
4687 local_addr,
4688 remote_addr);
4689}
4690#endif
[email protected]a6097f42011-01-10 08:50:514691
[email protected]310ebd6302011-10-10 19:06:284692void RenderViewImpl::OnContextMenuClosed(
[email protected]b29aa74b2011-01-31 21:41:084693 const webkit_glue::CustomContextMenuContext& custom_context) {
4694 if (custom_context.is_pepper_menu)
4695 pepper_delegate_.OnContextMenuClosed(custom_context);
4696 else
4697 context_menu_node_.reset();
[email protected]521b2482011-01-15 00:10:104698}
[email protected]5a7b15a2011-08-22 22:48:184699
[email protected]310ebd6302011-10-10 19:06:284700void RenderViewImpl::OnEnableViewSourceMode() {
[email protected]5a7b15a2011-08-22 22:48:184701 if (!webview())
4702 return;
4703 WebFrame* main_frame = webview()->mainFrame();
4704 if (!main_frame)
4705 return;
4706 main_frame->enableViewSourceMode(true);
4707}
[email protected]67bfb83f2011-09-22 03:36:374708
[email protected]310ebd6302011-10-10 19:06:284709void RenderViewImpl::OnLockMouseACK(bool succeeded) {
[email protected]57e02be2011-10-11 19:00:534710 // Mouse Lock removes the system cursor and provides all mouse motion as
4711 // .movementX/Y values on events all sent to a fixed target. This requires
4712 // content to specifically request the mode to be entered.
4713 // Mouse Capture is implicitly given for the duration of a drag event, and
4714 // sends all mouse events to the initial target of the drag.
4715 // If Lock is entered it supercedes any in progress Capture.
4716 if (succeeded)
4717 OnMouseCaptureLost();
4718
[email protected]67bfb83f2011-09-22 03:36:374719 pepper_delegate_.OnLockMouseACK(succeeded);
4720}
4721
[email protected]310ebd6302011-10-10 19:06:284722void RenderViewImpl::OnMouseLockLost() {
[email protected]67bfb83f2011-09-22 03:36:374723 pepper_delegate_.OnMouseLockLost();
4724}
[email protected]c3d45532011-10-07 19:20:404725
[email protected]310ebd6302011-10-10 19:06:284726bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const {
[email protected]ab21f2c2011-11-19 00:50:084727 return !!RenderThreadImpl::current()->compositor_thread();
[email protected]c3d45532011-10-07 19:20:404728}
[email protected]7f3c7af2011-10-20 22:52:514729
4730void RenderViewImpl::OnJavaBridgeInit(
4731 const IPC::ChannelHandle& channel_handle) {
4732 DCHECK(!java_bridge_dispatcher_.get());
[email protected]464750f2011-10-24 23:16:184733#if defined(ENABLE_JAVA_BRIDGE)
[email protected]7f3c7af2011-10-20 22:52:514734 java_bridge_dispatcher_.reset(new JavaBridgeDispatcher(this, channel_handle));
[email protected]464750f2011-10-24 23:16:184735#endif
[email protected]7f3c7af2011-10-20 22:52:514736}