blob: d8adaaa5279182cfccf03a98883ea44e374f7c3f [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
5#include "chrome/renderer/render_view.h"
6
7#include <algorithm>
[email protected]b75b8292010-10-01 07:28:258#include <cmath>
initial.commit09911bf2008-07-26 23:55:299#include <string>
10#include <vector>
11
[email protected]2041cf342010-02-19 03:15:5912#include "base/callback.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/command_line.h"
[email protected]bb063b72009-03-27 23:18:5014#include "base/compiler_specific.h"
[email protected]625332e02010-12-14 07:48:4915#include "base/lazy_instance.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/histogram.h"
[email protected]7bf795d92010-05-22 00:14:2817#include "base/path_service.h"
[email protected]8380c092009-06-25 17:45:5118#include "base/process_util.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/string_piece.h"
20#include "base/string_util.h"
[email protected]55126132010-08-19 14:53:2821#include "base/sys_string_conversions.h"
[email protected]6fdd4182010-10-14 23:59:2622#include "base/time.h"
[email protected]be1ce6a72010-08-03 14:35:2223#include "base/utf_string_conversions.h"
[email protected]6c8afae52009-01-22 02:24:5724#include "build/build_config.h"
[email protected]035545f2010-04-09 13:10:2125#include "chrome/common/appcache/appcache_dispatcher.h"
[email protected]81e63782009-02-27 19:35:0926#include "chrome/common/bindings_policy.h"
[email protected]ef916272009-07-08 21:40:5527#include "chrome/common/child_process_logging.h"
[email protected]f0af6a72009-05-30 05:25:1728#include "chrome/common/chrome_constants.h"
[email protected]7bf795d92010-05-22 00:14:2829#include "chrome/common/chrome_paths.h"
30#include "chrome/common/chrome_switches.h"
[email protected]26a9acf2010-12-13 19:35:0531#include "chrome/common/database_messages.h"
[email protected]a0cf04a2010-06-23 03:29:5532#include "chrome/common/extensions/extension.h"
[email protected]c5a272d2010-09-27 18:37:0833#include "chrome/common/file_system/file_system_dispatcher.h"
34#include "chrome/common/file_system/webfilesystem_callback_dispatcher.h"
[email protected]bb461532010-11-26 21:50:2335#include "chrome/common/json_value_serializer.h"
initial.commit09911bf2008-07-26 23:55:2936#include "chrome/common/jstemplate_builder.h"
[email protected]97c5c592010-08-03 08:22:2137#include "chrome/common/notification_service.h"
[email protected]630e26b2008-10-14 22:55:1738#include "chrome/common/page_zoom.h"
[email protected]4e0616e2010-05-28 14:55:5339#include "chrome/common/pepper_plugin_registry.h"
[email protected]e09ba552009-02-05 03:26:2940#include "chrome/common/render_messages.h"
[email protected]9b6f40e2009-06-11 15:54:2641#include "chrome/common/renderer_preferences.h"
initial.commit09911bf2008-07-26 23:55:2942#include "chrome/common/thumbnail_score.h"
[email protected]6de74452009-02-25 18:04:5943#include "chrome/common/url_constants.h"
[email protected]38789d82010-11-17 06:03:4444#include "chrome/common/web_apps.h"
[email protected]534c66c2010-04-28 22:53:1145#include "chrome/common/window_container_type.h"
initial.commit09911bf2008-07-26 23:55:2946#include "chrome/renderer/about_handler.h"
[email protected]5fb88962009-04-16 19:03:2547#include "chrome/renderer/audio_message_filter.h"
[email protected]6a8ddba52010-09-05 04:38:0648#include "chrome/renderer/autofill_helper.h"
[email protected]2f979172010-09-16 21:54:0349#include "chrome/renderer/automation/dom_automation_controller.h"
[email protected]00152e92010-07-19 11:47:4050#include "chrome/renderer/blocked_plugin.h"
[email protected]57ead352010-08-11 14:42:5351#include "chrome/renderer/device_orientation_dispatcher.h"
[email protected]e4ac5df2009-03-17 15:33:1152#include "chrome/renderer/devtools_agent.h"
53#include "chrome/renderer/devtools_client.h"
[email protected]2f979172010-09-16 21:54:0354#include "chrome/renderer/dom_ui_bindings.h"
[email protected]912256b32009-09-18 09:47:3555#include "chrome/renderer/extension_groups.h"
[email protected]4026ce1e2010-09-14 19:35:0456#include "chrome/renderer/extensions/bindings_utils.h"
[email protected]f816c012009-06-26 21:48:3257#include "chrome/renderer/extensions/event_bindings.h"
[email protected]0f6053962009-07-09 19:26:3558#include "chrome/renderer/extensions/extension_process_bindings.h"
[email protected]6fdd4182010-10-14 23:59:2659#include "chrome/renderer/extensions/extension_renderer_info.h"
[email protected]7120f132009-07-20 21:05:3760#include "chrome/renderer/extensions/renderer_extension_bindings.h"
[email protected]2f979172010-09-16 21:54:0361#include "chrome/renderer/external_host_bindings.h"
[email protected]caf706f2010-10-26 17:54:0862#include "chrome/renderer/external_popup_menu.h"
[email protected]ffd0abd2010-12-14 17:45:5063#include "chrome/renderer/geolocation_dispatcher.h"
[email protected]3bb08602010-10-07 21:47:1764#include "chrome/renderer/ggl/ggl.h"
[email protected]90109412010-12-15 17:14:2465#include "chrome/renderer/load_progress_tracker.h"
initial.commit09911bf2008-07-26 23:55:2966#include "chrome/renderer/localized_error.h"
[email protected]6f56d482009-02-20 05:02:5667#include "chrome/renderer/media/audio_renderer_impl.h"
[email protected]ee68378a2010-08-10 01:05:4168#include "chrome/renderer/media/ipc_video_decoder.h"
[email protected]ed3fb032009-06-16 19:50:5669#include "chrome/renderer/navigation_state.h"
[email protected]90e908552009-10-05 01:40:1270#include "chrome/renderer/notification_provider.h"
[email protected]6a8ddba52010-09-05 04:38:0671#include "chrome/renderer/page_click_tracker.h"
[email protected]a5a65ac2010-11-05 18:14:3672#include "chrome/renderer/page_load_histograms.h"
[email protected]6a8ddba52010-09-05 04:38:0673#include "chrome/renderer/password_autocomplete_manager.h"
[email protected]8beff0762009-09-29 02:18:3074#include "chrome/renderer/plugin_channel_host.h"
[email protected]d81c1e52009-06-03 22:09:5075#include "chrome/renderer/print_web_view_helper.h"
[email protected]39008c02009-02-11 23:59:2576#include "chrome/renderer/render_process.h"
[email protected]00c39612010-03-06 02:53:2877#include "chrome/renderer/render_thread.h"
[email protected]676126f72011-01-15 00:03:5178#include "chrome/renderer/render_view_observer.h"
[email protected]4d51d5bf2010-07-26 18:48:2679#include "chrome/renderer/render_view_visitor.h"
[email protected]484955942010-08-19 16:13:1880#include "chrome/renderer/render_widget_fullscreen.h"
[email protected]79c7bed2010-09-14 22:28:3981#include "chrome/renderer/render_widget_fullscreen_pepper.h"
[email protected]035545f2010-04-09 13:10:2182#include "chrome/renderer/renderer_webapplicationcachehost_impl.h"
[email protected]bd92c3a2010-01-13 05:02:3483#include "chrome/renderer/renderer_webstoragenamespace_impl.h"
[email protected]3ead1322010-11-19 20:01:0084#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
[email protected]ce833282010-11-04 15:48:3985#include "chrome/renderer/searchbox_extension.h"
[email protected]638694c2010-08-04 22:24:1186#include "chrome/renderer/speech_input_dispatcher.h"
[email protected]85c55dc2009-11-06 03:05:4687#include "chrome/renderer/spellchecker/spellcheck.h"
[email protected]25e18f82010-10-27 16:38:4388#include "chrome/renderer/user_script_idle_scheduler.h"
[email protected]0938d3c2009-01-09 20:37:3589#include "chrome/renderer/user_script_slave.h"
initial.commit09911bf2008-07-26 23:55:2990#include "chrome/renderer/visitedlink_slave.h"
[email protected]5aa6a312010-11-06 00:00:0791#include "chrome/renderer/webgraphicscontext3d_command_buffer_impl.h"
[email protected]d439ba072009-10-17 22:32:2992#include "chrome/renderer/webplugin_delegate_pepper.h"
[email protected]ba4b17f2009-02-11 21:32:2993#include "chrome/renderer/webplugin_delegate_proxy.h"
[email protected]9c00f002009-11-05 22:37:4294#include "chrome/renderer/websharedworker_proxy.h"
[email protected]eb47a132009-03-04 00:39:5695#include "chrome/renderer/webworker_proxy.h"
[email protected]cd818412010-03-19 03:23:1596#include "gfx/color_utils.h"
97#include "gfx/favicon_size.h"
[email protected]5c7293a2010-03-17 06:40:5798#include "gfx/native_widget_types.h"
[email protected]4d51d5bf2010-07-26 18:48:2699#include "gfx/point.h"
100#include "gfx/rect.h"
[email protected]82afe4b2010-11-12 20:36:22101#include "gfx/skbitmap_operations.h"
[email protected]34ac8f32009-02-22 23:03:27102#include "grit/generated_resources.h"
103#include "grit/renderer_resources.h"
[email protected]f8db8132010-12-03 00:27:49104#include "media/base/filter_collection.h"
[email protected]ee68378a2010-08-10 01:05:41105#include "media/base/media_switches.h"
[email protected]f78d1dfc2011-01-15 07:09:27106#include "media/base/message_loop_factory_impl.h"
[email protected]f11ca0732009-04-11 00:09:34107#include "net/base/data_url.h"
initial.commit09911bf2008-07-26 23:55:29108#include "net/base/escape.h"
109#include "net/base/net_errors.h"
[email protected]52c68652010-12-07 17:47:04110#include "net/http/http_util.h"
[email protected]1b4209f2011-01-07 00:25:40111#include "ppapi/c/private/ppb_flash.h"
[email protected]c399a8a2008-11-22 19:38:00112#include "skia/ext/bitmap_platform_device.h"
[email protected]83c9e6552008-12-03 16:22:10113#include "skia/ext/image_operations.h"
[email protected]8bd0fe62011-01-17 06:44:37114#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache.h"
115#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
116#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
117#include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h"
118#include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
119#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
120#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
121#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
122#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.h"
123#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h"
124#include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystemCallbacks.h"
125#include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h"
126#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h"
127#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h"
128#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
129#include "third_party/WebKit/Source/WebKit/chromium/public/WebGraphicsContext3D.h"
130#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
131#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
132#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
133#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
134#include "third_party/WebKit/Source/WebKit/chromium/public/WebNodeList.h"
135#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageSerializer.h"
136#include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h"
137#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
138#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginDocument.h"
139#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginParams.h"
140#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
141#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
142#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
143#include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h"
144#include "third_party/WebKit/Source/WebKit/chromium/public/WebSearchableFormData.h"
145#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
146#include "third_party/WebKit/Source/WebKit/chromium/public/WebSettings.h"
147#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
148#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h"
149#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
150#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
151#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h"
152#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
153#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
154#include "third_party/WebKit/Source/WebKit/chromium/public/WebVector.h"
155#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
156#include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h"
[email protected]6fdd4182010-10-14 23:59:26157#include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h"
158#include "third_party/skia/include/core/SkBitmap.h"
[email protected]9dd7e3d72011-01-20 18:27:06159#include "ui/base/message_box_flags.h"
[email protected]c051a1b2011-01-21 23:30:17160#include "ui/base/l10n/l10n_util.h"
[email protected]42ce29d2011-01-20 23:19:46161#include "ui/base/resource/resource_bundle.h"
[email protected]882b7b22010-10-05 03:34:53162#include "v8/include/v8.h"
[email protected]a6097f42011-01-10 08:50:51163#include "v8/include/v8-testing.h"
[email protected]80f584d92010-01-21 03:59:04164#include "webkit/appcache/web_application_cache_host_impl.h"
[email protected]25e18f82010-10-27 16:38:43165#include "webkit/glue/alt_error_page_resource_fetcher.h"
[email protected]7a4de7a62010-08-17 18:38:24166#include "webkit/glue/context_menu.h"
initial.commit09911bf2008-07-26 23:55:29167#include "webkit/glue/dom_operations.h"
[email protected]b1438212010-04-03 00:30:59168#include "webkit/glue/form_data.h"
[email protected]95056b582010-02-18 01:29:24169#include "webkit/glue/form_field.h"
[email protected]95056b582010-02-18 01:29:24170#include "webkit/glue/glue_serialize.h"
[email protected]f11ca0732009-04-11 00:09:34171#include "webkit/glue/image_decoder.h"
[email protected]4d51d5bf2010-07-26 18:48:26172#include "webkit/glue/image_resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09173#include "webkit/glue/media/video_renderer_impl.h"
[email protected]4d51d5bf2010-07-26 18:48:26174#include "webkit/glue/password_form_dom_manager.h"
[email protected]bb461532010-11-26 21:50:23175#include "webkit/glue/resource_fetcher.h"
[email protected]85cc78c2010-05-04 18:30:09176#include "webkit/glue/site_isolation_metrics.h"
[email protected]7a4de7a62010-08-17 18:38:24177#include "webkit/glue/webaccessibility.h"
initial.commit09911bf2008-07-26 23:55:29178#include "webkit/glue/webdropdata.h"
initial.commit09911bf2008-07-26 23:55:29179#include "webkit/glue/webkit_glue.h"
[email protected]add51772009-06-11 18:25:17180#include "webkit/glue/webmediaplayer_impl.h"
[email protected]191eb3f72010-12-21 06:27:50181#include "webkit/plugins/npapi/default_plugin_shared.h"
182#include "webkit/plugins/npapi/plugin_list.h"
183#include "webkit/plugins/npapi/webplugin_delegate.h"
184#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
185#include "webkit/plugins/npapi/webplugin_impl.h"
186#include "webkit/plugins/npapi/webview_plugin.h"
[email protected]0bd753682010-12-16 18:15:52187#include "webkit/plugins/ppapi/ppapi_webplugin_impl.h"
initial.commit09911bf2008-07-26 23:55:29188
[email protected]6c8afae52009-01-22 02:24:57189#if defined(OS_WIN)
190// TODO(port): these files are currently Windows only because they concern:
[email protected]6c8afae52009-01-22 02:24:57191// * theming
[email protected]cd818412010-03-19 03:23:15192#include "gfx/native_theme_win.h"
[email protected]6981f7f2010-03-09 00:53:03193#elif defined(USE_X11)
[email protected]8d1b864d12010-10-10 00:04:34194#include "gfx/native_theme_linux.h"
[email protected]8bd0fe62011-01-17 06:44:37195#include "third_party/WebKit/Source/WebKit/chromium/public/linux/WebRenderTheme.h"
[email protected]78043bdd2010-04-05 18:45:33196#elif defined(OS_MACOSX)
197#include "skia/ext/skia_utils_mac.h"
[email protected]6c8afae52009-01-22 02:24:57198#endif
199
[email protected]c7287a92009-11-04 20:06:15200using WebKit::WebAccessibilityCache;
[email protected]9892b472010-09-16 00:23:42201using WebKit::WebAccessibilityNotification;
[email protected]cc0445f2009-10-13 16:09:08202using WebKit::WebAccessibilityObject;
[email protected]035545f2010-04-09 13:10:21203using WebKit::WebApplicationCacheHost;
204using WebKit::WebApplicationCacheHostClient;
[email protected]6fdd4182010-10-14 23:59:26205using WebKit::WebCString;
[email protected]1c83eb42009-09-11 21:08:41206using WebKit::WebColor;
207using WebKit::WebColorName;
[email protected]0dea3ea2009-03-31 23:30:59208using WebKit::WebConsoleMessage;
[email protected]79e37442009-10-09 18:17:44209using WebKit::WebContextMenuData;
[email protected]b921cfd22010-02-25 16:57:51210using WebKit::WebCookieJar;
[email protected]e6f546c32009-07-01 17:12:55211using WebKit::WebData;
[email protected]726985e22009-06-18 21:09:28212using WebKit::WebDataSource;
[email protected]2661b332009-11-03 18:42:29213using WebKit::WebDevToolsAgent;
[email protected]5bc8fe92010-03-11 18:19:00214using WebKit::WebDocument;
[email protected]e80c73b2009-04-07 23:24:58215using WebKit::WebDragData;
[email protected]1d9f4132009-09-08 17:29:25216using WebKit::WebDragOperation;
217using WebKit::WebDragOperationsMask;
[email protected]79dbc662009-09-04 05:42:51218using WebKit::WebEditingAction;
[email protected]9b66f34bf2010-10-27 20:45:51219using WebKit::WebElement;
[email protected]caf706f2010-10-26 17:54:08220using WebKit::WebExternalPopupMenu;
221using WebKit::WebExternalPopupMenuClient;
[email protected]cdaf8d02010-03-30 19:52:47222using WebKit::WebFileChooserCompletion;
[email protected]2b06a992010-08-21 05:48:22223using WebKit::WebFileSystem;
224using WebKit::WebFileSystemCallbacks;
[email protected]6069da8c2009-10-20 20:33:49225using WebKit::WebFindOptions;
[email protected]b1438212010-04-03 00:30:59226using WebKit::WebFormControlElement;
[email protected]979c28b2009-11-07 01:30:48227using WebKit::WebFormElement;
[email protected]dd7daa82009-08-10 05:46:45228using WebKit::WebFrame;
[email protected]ca948a22009-06-25 19:36:17229using WebKit::WebHistoryItem;
[email protected]c27ae592010-03-18 15:24:41230using WebKit::WebImage;
[email protected]e6efd022010-03-31 09:34:50231using WebKit::WebInputElement;
[email protected]3d9689372009-09-10 04:29:17232using WebKit::WebMediaPlayer;
[email protected]952cb702009-10-07 05:50:28233using WebKit::WebMediaPlayerAction;
[email protected]3d9689372009-09-10 04:29:17234using WebKit::WebMediaPlayerClient;
[email protected]4873c7d2009-07-16 06:36:28235using WebKit::WebNavigationPolicy;
[email protected]726985e22009-06-18 21:09:28236using WebKit::WebNavigationType;
[email protected]79dbc662009-09-04 05:42:51237using WebKit::WebNode;
[email protected]d9ec5c0f2009-12-23 11:55:07238using WebKit::WebPageSerializer;
239using WebKit::WebPageSerializerClient;
[email protected]3d9689372009-09-10 04:29:17240using WebKit::WebPlugin;
[email protected]00152e92010-07-19 11:47:40241using WebKit::WebPluginContainer;
[email protected]24a7f3c2010-03-25 08:26:49242using WebKit::WebPluginDocument;
[email protected]aad51d1c2010-08-05 08:38:09243using WebKit::WebPluginParams;
[email protected]48c9cf2d2009-09-16 16:47:52244using WebKit::WebPoint;
[email protected]88efb7ec2009-07-14 16:32:59245using WebKit::WebPopupMenuInfo;
[email protected]79dbc662009-09-04 05:42:51246using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:52247using WebKit::WebRect;
[email protected]4f999132009-03-31 18:08:40248using WebKit::WebScriptSource;
[email protected]ce0e250d2009-10-23 21:00:35249using WebKit::WebSearchableFormData;
[email protected]e3d60e5d2009-09-25 21:08:29250using WebKit::WebSecurityOrigin;
[email protected]2fab253a2009-08-17 23:00:59251using WebKit::WebSettings;
[email protected]9c00f002009-11-05 22:37:42252using WebKit::WebSharedWorker;
[email protected]8649fb32009-06-26 17:51:02253using WebKit::WebSize;
[email protected]bd92c3a2010-01-13 05:02:34254using WebKit::WebStorageNamespace;
[email protected]726985e22009-06-18 21:09:28255using WebKit::WebString;
[email protected]79dbc662009-09-04 05:42:51256using WebKit::WebTextAffinity;
[email protected]de570ef2009-07-29 18:27:52257using WebKit::WebTextDirection;
[email protected]726985e22009-06-18 21:09:28258using WebKit::WebURL;
259using WebKit::WebURLError;
260using WebKit::WebURLRequest;
261using WebKit::WebURLResponse;
[email protected]4873c7d2009-07-16 06:36:28262using WebKit::WebVector;
[email protected]50ae00ef2009-10-19 05:11:03263using WebKit::WebView;
[email protected]4873c7d2009-07-16 06:36:28264using WebKit::WebWidget;
[email protected]6fdd4182010-10-14 23:59:26265using WebKit::WebWindowFeatures;
[email protected]27ba8532009-04-24 20:22:43266using WebKit::WebWorker;
267using WebKit::WebWorkerClient;
[email protected]6fdd4182010-10-14 23:59:26268using appcache::WebApplicationCacheHostImpl;
269using base::Time;
270using base::TimeDelta;
271using webkit_glue::AltErrorPageResourceFetcher;
272using webkit_glue::FormData;
273using webkit_glue::FormField;
274using webkit_glue::ImageResourceFetcher;
275using webkit_glue::PasswordForm;
276using webkit_glue::PasswordFormDomManager;
[email protected]bb461532010-11-26 21:50:23277using webkit_glue::ResourceFetcher;
[email protected]6fdd4182010-10-14 23:59:26278using webkit_glue::SiteIsolationMetrics;
279using webkit_glue::WebAccessibility;
[email protected]e1acf6f2008-10-27 20:43:33280
initial.commit09911bf2008-07-26 23:55:29281//-----------------------------------------------------------------------------
282
[email protected]3354d3e2010-06-10 19:53:02283typedef std::map<WebKit::WebView*, RenderView*> ViewMap;
[email protected]625332e02010-12-14 07:48:49284static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED);
[email protected]3354d3e2010-06-10 19:53:02285
initial.commit09911bf2008-07-26 23:55:29286// define to write the time necessary for thumbnail/DOM text retrieval,
287// respectively, into the system debug log
initial.commit09911bf2008-07-26 23:55:29288// #define TIME_TEXT_RETRIEVAL
289
290// maximum number of characters in the document to index, any text beyond this
291// point will be clipped
[email protected]6c8afae52009-01-22 02:24:57292static const size_t kMaxIndexChars = 65535;
initial.commit09911bf2008-07-26 23:55:29293
294// Size of the thumbnails that we'll generate
[email protected]8b4f4892009-09-04 21:52:37295static const int kThumbnailWidth = 212;
296static const int kThumbnailHeight = 132;
initial.commit09911bf2008-07-26 23:55:29297
298// Delay in milliseconds that we'll wait before capturing the page contents
299// and thumbnail.
300static const int kDelayForCaptureMs = 500;
301
302// Typically, we capture the page data once the page is loaded.
303// Sometimes, the page never finishes to load, preventing the page capture
304// To workaround this problem, we always perform a capture after the following
305// delay.
306static const int kDelayForForcedCaptureMs = 6000;
307
[email protected]882daa92009-11-05 16:31:31308// Time, in seconds, we delay before sending content state changes (such as form
309// state and scroll position) to the browser. We delay sending changes to avoid
310// spamming the browser.
311// To avoid having tab/session restore require sending a message to get the
312// current content state during tab closing we use a shorter timeout for the
313// foreground renderer. This means there is a small window of time from which
314// content state is modified and not sent to session restore, but this is
315// better than having to wake up all renderers during shutdown.
316static const int kDelaySecondsForContentStateSyncHidden = 5;
317static const int kDelaySecondsForContentStateSync = 1;
initial.commit09911bf2008-07-26 23:55:29318
[email protected]0aa55312008-10-17 21:53:08319// The maximum number of popups that can be spawned from one page.
320static const int kMaximumNumberOfUnacknowledgedPopups = 25;
321
[email protected]6fdd4182010-10-14 23:59:26322static const char kBackForwardNavigationScheme[] = "history";
[email protected]50b691c2008-10-31 19:08:35323
[email protected]726985e22009-06-18 21:09:28324static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
325 WebVector<WebURL> urls;
326 ds->redirectChain(urls);
327 result->reserve(urls.size());
328 for (size_t i = 0; i < urls.size(); ++i)
329 result->push_back(urls[i]);
330}
331
[email protected]30507922010-01-15 16:48:23332static bool PaintViewIntoCanvas(WebView* view,
333 skia::PlatformCanvas& canvas) {
334 view->layout();
335 const WebSize& size = view->size();
336
337 if (!canvas.initialize(size.width, size.height, true))
338 return false;
339
340 view->paint(webkit_glue::ToWebCanvas(&canvas),
341 WebRect(0, 0, size.width, size.height));
342 // TODO: Add a way to snapshot the whole page, not just the currently
343 // visible part.
344
345 return true;
346}
347
348// Calculates how "boring" a thumbnail is. The boring score is the
349// 0,1 ranged percentage of pixels that are the most common
350// luma. Higher boring scores indicate that a higher percentage of a
351// bitmap are all the same brightness.
352static double CalculateBoringScore(SkBitmap* bitmap) {
353 int histogram[256] = {0};
354 color_utils::BuildLumaHistogram(bitmap, histogram);
355
356 int color_count = *std::max_element(histogram, histogram + 256);
357 int pixel_count = bitmap->width() * bitmap->height();
358 return static_cast<double>(color_count) / pixel_count;
359}
360
[email protected]12bc8472010-04-15 07:29:40361// True if |frame| contains content that is white-listed for content settings.
362static bool IsWhitelistedForContentSettings(WebFrame* frame) {
363 WebSecurityOrigin origin = frame->securityOrigin();
364 if (origin.isEmpty())
365 return false; // Uninitialized document?
366
367 if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme))
368 return true; // Browser UI elements should still work.
369
370 // If the scheme is ftp: or file:, an empty file name indicates a directory
371 // listing, which requires JavaScript to function properly.
372 GURL frame_url = frame->url();
373 const char* kDirProtocols[] = { "ftp", "file" };
374 for (size_t i = 0; i < arraysize(kDirProtocols); ++i) {
375 if (EqualsASCII(origin.protocol(), kDirProtocols[i])) {
376 return frame_url.SchemeIs(kDirProtocols[i]) &&
377 frame_url.ExtractFileName().empty();
378 }
379 }
380
381 return false;
382}
383
[email protected]3a8eecb2010-04-22 23:56:30384// Returns true if the frame is navigating to an URL either into or out of an
385// extension app's extent.
[email protected]08e94b82010-12-15 22:51:04386// TODO(creis): Temporary workaround for crbug.com/65953: Only return true if
387// we would enter an extension app's extent from a non-app. We avoid swapping
388// processes to exit an app for now, since we do not yet restore context (such
389// as window.opener) if the window navigates back.
390static bool CrossesIntoExtensionExtent(WebFrame* frame, const GURL& new_url) {
[email protected]3a8eecb2010-04-22 23:56:30391 // If the URL is still empty, this is a window.open navigation. Check the
392 // opener's URL.
393 GURL old_url(frame->url());
394 if (old_url.is_empty() && frame->opener())
395 old_url = frame->opener()->url();
396
[email protected]08e94b82010-12-15 22:51:04397 return !ExtensionRendererInfo::InSameExtent(old_url, new_url) &&
398 !ExtensionRendererInfo::GetByURL(old_url);
[email protected]3a8eecb2010-04-22 23:56:30399}
400
[email protected]3354d3e2010-06-10 19:53:02401// Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
402// if it failed.
[email protected]e5106202010-06-11 21:12:36403static std::string DetermineTextLanguage(const string16& text) {
[email protected]655f97c32010-07-22 21:24:17404 std::string language = chrome::kUnknownLanguageCode;
[email protected]3354d3e2010-06-10 19:53:02405 int num_languages = 0;
[email protected]a95586882010-08-02 18:40:08406 int text_bytes = 0;
[email protected]3354d3e2010-06-10 19:53:02407 bool is_reliable = false;
[email protected]3354d3e2010-06-10 19:53:02408 Language cld_language =
[email protected]e5106202010-06-11 21:12:36409 DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
[email protected]a95586882010-08-02 18:40:08410 &num_languages, NULL, &text_bytes);
411 // We don't trust the result if the CLD reports that the detection is not
412 // reliable, or if the actual text used to detect the language was less than
413 // 100 bytes (short texts can often lead to wrong results).
414 if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES &&
[email protected]3354d3e2010-06-10 19:53:02415 cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) {
416 // We should not use LanguageCode_ISO_639_1 because it does not cover all
417 // the languages CLD can detect. As a result, it'll return the invalid
418 // language code for tradtional Chinese among others.
419 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
420 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
421 // for Simplified Chinese.
422 language = LanguageCodeWithDialects(cld_language);
423 }
424 return language;
425}
426
[email protected]9b66f34bf2010-10-27 20:45:51427// Returns true if the parameter node is a textfield, text area or a content
428// editable div.
429static bool IsEditableNode(const WebNode& node) {
430 bool is_editable_node = false;
431 if (!node.isNull()) {
432 if (node.isContentEditable()) {
433 is_editable_node = true;
434 } else if (node.isElementNode()) {
435 is_editable_node =
436 node.toConst<WebElement>().isTextFormControlElement();
437 }
438 }
439 return is_editable_node;
440}
441
[email protected]54ec7f82010-10-21 22:32:51442static bool WebAccessibilityNotificationToViewHostMsg(
443 WebAccessibilityNotification notification,
444 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) {
445 switch (notification) {
446 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
447 *type = ViewHostMsg_AccessibilityNotification_Params::
448 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
449 break;
450 case WebKit::WebAccessibilityNotificationChildrenChanged:
451 *type = ViewHostMsg_AccessibilityNotification_Params::
452 NOTIFICATION_TYPE_CHILDREN_CHANGED;
453 break;
454 case WebKit::WebAccessibilityNotificationFocusedUIElementChanged:
455 *type = ViewHostMsg_AccessibilityNotification_Params::
456 NOTIFICATION_TYPE_FOCUS_CHANGED;
457 break;
458 case WebKit::WebAccessibilityNotificationLoadComplete:
459 *type = ViewHostMsg_AccessibilityNotification_Params::
460 NOTIFICATION_TYPE_LOAD_COMPLETE;
461 break;
462 case WebKit::WebAccessibilityNotificationValueChanged:
463 *type = ViewHostMsg_AccessibilityNotification_Params::
464 NOTIFICATION_TYPE_VALUE_CHANGED;
465 break;
466 case WebKit::WebAccessibilityNotificationSelectedTextChanged:
467 *type = ViewHostMsg_AccessibilityNotification_Params::
468 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED;
469 break;
470 default:
471 // TODO(ctguil): Support additional webkit notifications.
472 return false;
473 }
474 return true;
475}
476
[email protected]81f9fe0b2010-12-07 00:35:29477// Conversion for the incoming value. The map isn't perfect; v8 has Uint32,
478// and int64 which don't fit as Value::TYPE_INTEGER, so we let them fall into
479// being TYPE_REALs. Dates are converted to a string (which can then be parsed
480// into a base::Time), as are regexps. Arrays are converted into lists,
481// recursively. We don't deal with binary objects or functions - they become
482// null values.
483static Value* ConvertV8Value(const v8::Handle<v8::Value>& v8value) {
484 if (v8value->IsBoolean()) {
485 return Value::CreateBooleanValue(v8value->BooleanValue());
486 } else if (v8value->IsInt32()) {
487 return Value::CreateIntegerValue(v8value->Int32Value());
488 } else if (v8value->IsNumber()) {
489 return Value::CreateRealValue(v8value->NumberValue());
490 } else if (v8value->IsString()) {
491 return Value::CreateStringValue(*v8::String::Utf8Value(v8value));
492 } else if (v8value->IsDate()) {
493 v8::Date* date = v8::Date::Cast(*v8value);
494 return Value::CreateRealValue(date->NumberValue() / 1000.0);
495 } else if (v8value->IsRegExp()) {
496 return Value::CreateStringValue(
497 *v8::String::Utf8Value(v8value->ToString()));
498 } else if (v8value->IsArray()) {
499 v8::Array* array = v8::Array::Cast(*v8value);
500 uint32_t length = array->Length();
501 scoped_ptr<ListValue> list(new ListValue);
502 for (uint32_t i = 0 ; i < length ; ++i) {
503 list->Set(i, ConvertV8Value(array->Get(i)));
504 }
505 return list.release();
506 }
507 return Value::CreateNullValue();
508}
509
initial.commit09911bf2008-07-26 23:55:29510///////////////////////////////////////////////////////////////////////////////
511
[email protected]60c42a8c72009-10-09 04:08:59512int32 RenderView::next_page_id_ = 1;
513
[email protected]cdaf8d02010-03-30 19:52:47514struct RenderView::PendingFileChooser {
515 PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p,
516 WebFileChooserCompletion* c)
517 : params(p),
518 completion(c) {
519 }
520 ViewHostMsg_RunFileChooser_Params params;
521 WebFileChooserCompletion* completion; // MAY BE NULL to skip callback.
522};
523
[email protected]2fab253a2009-08-17 23:00:59524RenderView::RenderView(RenderThreadBase* render_thread,
[email protected]676126f72011-01-15 00:03:51525 gfx::NativeViewId parent_hwnd,
526 int32 opener_id,
527 const RendererPreferences& renderer_prefs,
528 const WebPreferences& webkit_prefs,
529 SharedRenderViewCounter* counter,
530 int32 routing_id,
531 int64 session_storage_namespace_id,
532 const string16& frame_name)
[email protected]3e2b375b2010-04-07 17:03:12533 : RenderWidget(render_thread, WebKit::WebPopupTypeNone),
[email protected]676126f72011-01-15 00:03:51534 webkit_preferences_(webkit_prefs),
[email protected]3354d3e2010-06-10 19:53:02535 send_content_state_immediately_(false),
[email protected]81e63782009-02-27 19:35:09536 enabled_bindings_(0),
[email protected]3354d3e2010-06-10 19:53:02537 send_preferred_size_changes_(false),
538 script_can_close_(true),
[email protected]81a34412009-01-05 19:17:24539 is_loading_(false),
[email protected]e75cb49e2009-01-05 23:13:21540 navigation_gesture_(NavigationGestureUnknown),
[email protected]3354d3e2010-06-10 19:53:02541 opened_by_user_gesture_(true),
542 opener_suppressed_(false),
[email protected]81a34412009-01-05 19:17:24543 page_id_(-1),
544 last_page_id_sent_to_browser_(-1),
545 last_indexed_page_id_(-1),
[email protected]3cc72b12010-03-18 23:03:00546 history_list_offset_(-1),
547 history_list_length_(0),
[email protected]81a34412009-01-05 19:17:24548 has_unload_listener_(false),
[email protected]83dde542009-09-11 20:59:55549#if defined(OS_MACOSX)
550 has_document_tag_(false),
551#endif
[email protected]98324892009-09-09 21:16:05552 document_tag_(0),
[email protected]3354d3e2010-06-10 19:53:02553 target_url_status_(TARGET_NONE),
554 spelling_panel_visible_(false),
555 view_type_(ViewType::INVALID),
556 browser_window_id_(-1),
[email protected]18ca9a6b2010-06-02 19:05:18557 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
[email protected]e47aec52010-08-12 00:50:30558 ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)),
[email protected]54ec7f82010-10-21 22:32:51559 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
[email protected]3354d3e2010-06-10 19:53:02560 ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)),
561 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
[email protected]676126f72011-01-15 00:03:51562 devtools_client_(NULL),
563 geolocation_dispatcher_(NULL),
564 speech_input_dispatcher_(NULL),
565 device_orientation_dispatcher_(NULL),
[email protected]54ec7f82010-10-21 22:32:51566 accessibility_ack_pending_(false),
[email protected]bb461532010-11-26 21:50:23567 pending_app_icon_requests_(0),
[email protected]5ee0cfd02011-01-18 05:42:22568 session_storage_namespace_id_(session_storage_namespace_id) {
[email protected]8de12d942010-11-17 20:42:44569#if defined(OS_MACOSX)
570 // On Mac, the select popups are rendered by the browser.
571 // Note that we don't do this in RenderMain otherwise this would not be called
572 // in single-process mode.
573 WebKit::WebView::setUseExternalPopupMenus(true);
574#endif
[email protected]676126f72011-01-15 00:03:51575
[email protected]71b0d5d2010-02-15 05:43:07576 ClearBlockedContentSettings();
[email protected]3ead1322010-11-19 20:01:00577 if (CommandLine::ForCurrentProcess()->HasSwitch(
578 switches::kEnableClientSidePhishingDetection)) {
579 phishing_delegate_.reset(
580 new safe_browsing::PhishingClassifierDelegate(this, NULL));
581 RenderThread* thread = RenderThread::current();
582 if (thread && thread->phishing_scorer()) {
583 phishing_delegate_->SetPhishingScorer(thread->phishing_scorer());
584 }
585 }
[email protected]676126f72011-01-15 00:03:51586
587 routing_id_ = routing_id;
588 if (opener_id != MSG_ROUTING_NONE)
589 opener_id_ = opener_id;
590
591 if (counter) {
592 shared_popup_counter_ = counter;
593 shared_popup_counter_->data++;
594 decrement_shared_popup_at_destruction_ = true;
595 } else {
596 shared_popup_counter_ = new SharedRenderViewCounter(0);
597 decrement_shared_popup_at_destruction_ = false;
598 }
599
600 notification_provider_ = new NotificationProvider(this);
601
602 devtools_agent_ = new DevToolsAgent(this);
603 PasswordAutocompleteManager* password_autocomplete_manager =
604 new PasswordAutocompleteManager(this);
605 AutoFillHelper* autofill_helper = new AutoFillHelper(
606 this, password_autocomplete_manager);
607
608 webwidget_ = WebView::create(this, devtools_agent_, autofill_helper);
609 g_view_map.Get().insert(std::make_pair(webview(), this));
610 webkit_preferences_.Apply(webview());
611 webview()->initializeMainFrame(this);
612 if (!frame_name.empty())
613 webview()->mainFrame()->setName(frame_name);
614
615 OnSetRendererPrefs(renderer_prefs);
616
617 render_thread_->AddRoute(routing_id_, this);
618 // Take a reference on behalf of the RenderThread. This will be balanced
619 // when we receive ViewMsg_Close.
620 AddRef();
621
622 // If this is a popup, we must wait for the CreatingNew_ACK message before
623 // completing initialization. Otherwise, we can finish it now.
624 if (opener_id == MSG_ROUTING_NONE) {
625 did_show_ = true;
626 CompleteInit(parent_hwnd);
627 }
628
629 host_window_ = parent_hwnd;
630
631 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
632 if (command_line.HasSwitch(switches::kDomAutomationController))
633 enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION;
634 if (command_line.HasSwitch(switches::kEnableAccessibility))
635 WebAccessibilityCache::enableAccessibility();
636
637 audio_message_filter_ = new AudioMessageFilter(routing_id_);
638 render_thread_->AddFilter(audio_message_filter_);
639
640 PageClickTracker* page_click_tracker = new PageClickTracker(this);
641 // Note that the order of insertion of the listeners is important.
642 // The password_autocomplete_manager takes the first shot at processing the
643 // notification and can stop the propagation.
644 page_click_tracker->AddListener(password_autocomplete_manager);
645 page_click_tracker->AddListener(autofill_helper);
initial.commit09911bf2008-07-26 23:55:29646}
647
648RenderView::~RenderView() {
[email protected]0aa55312008-10-17 21:53:08649 if (decrement_shared_popup_at_destruction_)
650 shared_popup_counter_->data--;
651
[email protected]a1128322009-10-06 18:38:46652 // If file chooser is still waiting for answer, dispatch empty answer.
[email protected]cdaf8d02010-03-30 19:52:47653 while (!file_chooser_completions_.empty()) {
654 if (file_chooser_completions_.front()->completion) {
655 file_chooser_completions_.front()->completion->didChooseFile(
656 WebVector<WebString>());
657 }
658 file_chooser_completions_.pop_front();
659 }
[email protected]a1128322009-10-06 18:38:46660
[email protected]83dde542009-09-11 20:59:55661#if defined(OS_MACOSX)
[email protected]98324892009-09-09 21:16:05662 // Tell the spellchecker that the document is closed.
[email protected]83dde542009-09-11 20:59:55663 if (has_document_tag_)
664 Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_));
[email protected]c36a9b62010-10-14 00:41:11665
666 // Destroy all fake plugin window handles on the browser side.
667 while (!fake_plugin_window_handles_.empty()) {
668 // Make sure no NULL plugin window handles were inserted into this list.
669 DCHECK(*fake_plugin_window_handles_.begin());
670 // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_.
671 DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin());
672 }
[email protected]83dde542009-09-11 20:59:55673#endif
[email protected]98324892009-09-09 21:16:05674
[email protected]5fb88962009-04-16 19:03:25675 render_thread_->RemoveFilter(audio_message_filter_);
[email protected]60c42a8c72009-10-09 04:08:59676
[email protected]3ead1322010-11-19 20:01:00677 // Tell the PhishingClassifierDelegate that the view is going away.
678 if (phishing_delegate_.get())
679 phishing_delegate_->CancelPendingClassification();
680
[email protected]60c42a8c72009-10-09 04:08:59681#ifndef NDEBUG
682 // Make sure we are no longer referenced by the ViewMap.
[email protected]625332e02010-12-14 07:48:49683 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59684 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it)
685 DCHECK_NE(this, it->second) << "Failed to call Close?";
686#endif
[email protected]676126f72011-01-15 00:03:51687
688 FOR_EACH_OBSERVER(RenderViewObserver, observers_, set_render_view(NULL));
689 FOR_EACH_OBSERVER(RenderViewObserver, observers_, OnDestruct());
[email protected]60c42a8c72009-10-09 04:08:59690}
691
692/*static*/
693void RenderView::ForEach(RenderViewVisitor* visitor) {
[email protected]625332e02010-12-14 07:48:49694 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59695 for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) {
696 if (!visitor->Visit(it->second))
697 return;
698 }
699}
700
701/*static*/
702RenderView* RenderView::FromWebView(WebView* webview) {
[email protected]625332e02010-12-14 07:48:49703 ViewMap* views = g_view_map.Pointer();
[email protected]60c42a8c72009-10-09 04:08:59704 ViewMap::iterator it = views->find(webview);
705 return it == views->end() ? NULL : it->second;
initial.commit09911bf2008-07-26 23:55:29706}
707
708/*static*/
[email protected]0aa55312008-10-17 21:53:08709RenderView* RenderView::Create(
[email protected]81a34412009-01-05 19:17:24710 RenderThreadBase* render_thread,
[email protected]18bcc3c2009-01-27 21:39:15711 gfx::NativeViewId parent_hwnd,
[email protected]0aa55312008-10-17 21:53:08712 int32 opener_id,
[email protected]80d96fa2009-06-10 22:34:51713 const RendererPreferences& renderer_prefs,
[email protected]0aa55312008-10-17 21:53:08714 const WebPreferences& webkit_prefs,
715 SharedRenderViewCounter* counter,
[email protected]4e6419c2010-01-15 04:50:34716 int32 routing_id,
[email protected]8ab04652010-06-12 02:47:26717 int64 session_storage_namespace_id,
718 const string16& frame_name) {
initial.commit09911bf2008-07-26 23:55:29719 DCHECK(routing_id != MSG_ROUTING_NONE);
[email protected]676126f72011-01-15 00:03:51720 return new RenderView(
721 render_thread,
722 parent_hwnd,
723 opener_id,
724 renderer_prefs,
725 webkit_prefs,
726 counter,
727 routing_id,
728 session_storage_namespace_id,
729 frame_name); // adds reference
initial.commit09911bf2008-07-26 23:55:29730}
731
[email protected]bb461532010-11-26 21:50:23732// static
initial.commit09911bf2008-07-26 23:55:29733void RenderView::SetNextPageID(int32 next_page_id) {
734 // This method should only be called during process startup, and the given
735 // page id had better not exceed our current next page id!
[email protected]4646f292009-05-20 03:49:05736 DCHECK_EQ(next_page_id_, 1);
initial.commit09911bf2008-07-26 23:55:29737 DCHECK(next_page_id >= next_page_id_);
738 next_page_id_ = next_page_id;
739}
740
[email protected]676126f72011-01-15 00:03:51741void RenderView::AddObserver(RenderViewObserver* observer) {
742 observers_.AddObserver(observer);
743}
744
745void RenderView::RemoveObserver(RenderViewObserver* observer) {
746 observer->set_render_view(NULL);
747 observers_.RemoveObserver(observer);
748}
749
[email protected]70eee342010-11-05 01:59:37750bool RenderView::RendererAccessibilityNotification::ShouldIncludeChildren() {
751 typedef ViewHostMsg_AccessibilityNotification_Params params;
752 if (type == params::NOTIFICATION_TYPE_CHILDREN_CHANGED ||
753 type == params::NOTIFICATION_TYPE_LOAD_COMPLETE) {
754 return true;
755 }
756 return false;
757}
758
[email protected]8a3125a712010-08-09 18:58:51759WebKit::WebView* RenderView::webview() const {
[email protected]4d51d5bf2010-07-26 18:48:26760 return static_cast<WebKit::WebView*>(webwidget());
761}
762
[email protected]afe3a1672009-11-17 19:04:12763void RenderView::UserMetricsRecordAction(const std::string& action) {
[email protected]15d04ae2010-10-30 01:04:50764 Send(new ViewHostMsg_UserMetricsRecordAction(action));
[email protected]1dbafaf72009-09-23 19:43:56765}
766
[email protected]bb461532010-11-26 21:50:23767bool RenderView::InstallWebApplicationUsingDefinitionFile(WebFrame* frame,
768 string16* error) {
769 // There is an issue of drive-by installs with the below implementation. A web
770 // site could force a user to install an app by timing the dialog to come up
771 // just before the user clicks.
772 //
773 // We do show a success UI that allows users to uninstall, but it seems that
774 // we might still want to put up an infobar before showing the install dialog.
775 //
776 // TODO(aa): Figure out this issue before removing the kEnableCrxlessWebApps
777 // switch.
778 if (!CommandLine::ForCurrentProcess()->HasSwitch(
779 switches::kEnableCrxlessWebApps)) {
780 *error = ASCIIToUTF16("CRX-less web apps aren't enabled.");
781 return false;
782 }
783
784 if (frame != frame->top()) {
785 *error = ASCIIToUTF16("Applications can only be installed from the top "
786 "frame.");
787 return false;
788 }
789
790 if (pending_app_info_.get()) {
791 *error = ASCIIToUTF16("An application install is already in progress.");
792 return false;
793 }
794
795 pending_app_info_.reset(new WebApplicationInfo());
796 if (!web_apps::ParseWebAppFromWebDocument(frame, pending_app_info_.get(),
797 error)) {
798 return false;
799 }
800
801 if (!pending_app_info_->manifest_url.is_valid()) {
802 *error = ASCIIToUTF16("Web application definition not found or invalid.");
803 return false;
804 }
805
806 app_definition_fetcher_.reset(new ResourceFetcher(
807 pending_app_info_->manifest_url, webview()->mainFrame(),
808 NewCallback(this, &RenderView::DidDownloadApplicationDefinition)));
809 return true;
810}
811
[email protected]1a3c3cb2010-12-16 21:03:40812void RenderView::SetReportLoadProgressEnabled(bool enabled) {
813 if (!enabled) {
814 load_progress_tracker_.reset(NULL);
815 return;
816 }
817 if (load_progress_tracker_ == NULL)
818 load_progress_tracker_.reset(new LoadProgressTracker(this));
819}
820
[email protected]bb461532010-11-26 21:50:23821void RenderView::DidDownloadApplicationDefinition(
822 const WebKit::WebURLResponse& response,
823 const std::string& data) {
824 scoped_ptr<WebApplicationInfo> app_info(
825 pending_app_info_.release());
826
827 JSONStringValueSerializer serializer(data);
828 int error_code = 0;
829 std::string error_message;
830 scoped_ptr<Value> result(serializer.Deserialize(&error_code, &error_message));
831 if (!result.get()) {
832 AddErrorToRootConsole(UTF8ToUTF16(error_message));
833 return;
834 }
835
836 string16 error_message_16;
837 if (!web_apps::ParseWebAppFromDefinitionFile(result.get(), app_info.get(),
838 &error_message_16)) {
839 AddErrorToRootConsole(error_message_16);
840 return;
841 }
842
843 if (!app_info->icons.empty()) {
844 pending_app_info_.reset(app_info.release());
845 pending_app_icon_requests_ =
846 static_cast<int>(pending_app_info_->icons.size());
847 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
848 app_icon_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
849 new ImageResourceFetcher(
850 pending_app_info_->icons[i].url,
851 webview()->mainFrame(),
852 static_cast<int>(i),
853 pending_app_info_->icons[i].width,
854 NewCallback(this, &RenderView::DidDownloadApplicationIcon))));
855 }
856 } else {
857 Send(new ViewHostMsg_InstallApplication(routing_id_, *app_info));
858 }
859}
860
861void RenderView::DidDownloadApplicationIcon(ImageResourceFetcher* fetcher,
862 const SkBitmap& image) {
863 pending_app_info_->icons[fetcher->id()].data = image;
864
865 // Remove the image fetcher from our pending list. We're in the callback from
866 // ImageResourceFetcher, best to delay deletion.
867 for (ImageResourceFetcherList::iterator iter = app_icon_fetchers_.begin();
868 iter != app_icon_fetchers_.end(); ++iter) {
869 if (iter->get() == fetcher) {
870 iter->release();
871 app_icon_fetchers_.erase(iter);
872 break;
873 }
874 }
875
876 // We're in the callback from the ImageResourceFetcher, best to delay
877 // deletion.
878 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
879
880 if (--pending_app_icon_requests_ > 0)
881 return;
882
883 // There is a maximum size of IPC on OS X and Linux that we have run into in
884 // some situations. We're not sure what it is, but our hypothesis is in the
885 // neighborhood of 1 MB.
886 //
887 // To be on the safe side, we give ourselves 128 KB for just the image data.
888 // This should be more than enough for 128, 48, and 16 px 32-bit icons. If we
889 // want to start allowing larger icons (see bug 63406), we'll have to either
890 // experiment mor ewith this and find the real limit, or else come up with
891 // some alternative way to transmit the icon data to the browser process.
892 //
893 // See also: bug 63729.
[email protected]678a7d72011-01-05 20:37:32894 const size_t kMaxIconSize = 1024 * 128;
895 size_t actual_icon_size = 0;
[email protected]bb461532010-11-26 21:50:23896 for (size_t i = 0; i < pending_app_info_->icons.size(); ++i) {
[email protected]678a7d72011-01-05 20:37:32897 size_t current_size = pending_app_info_->icons[i].data.getSize();
898 if (current_size > kMaxIconSize - actual_icon_size) {
899 AddErrorToRootConsole(ASCIIToUTF16(
[email protected]bb461532010-11-26 21:50:23900 "Icons are too large. Maximum total size for app icons is 128 KB."));
[email protected]678a7d72011-01-05 20:37:32901 return;
902 }
903 actual_icon_size += current_size;
[email protected]bb461532010-11-26 21:50:23904 }
905
906 Send(new ViewHostMsg_InstallApplication(routing_id_, *pending_app_info_));
907 pending_app_info_.reset(NULL);
908}
909
[email protected]a3a8fb6d2009-10-22 20:12:51910void RenderView::PluginCrashed(const FilePath& plugin_path) {
911 Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path));
initial.commit09911bf2008-07-26 23:55:29912}
913
[email protected]aad51d1c2010-08-05 08:38:09914WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame,
915 const WebPluginParams& params) {
[email protected]191eb3f72010-12-21 06:27:50916 webkit::npapi::WebPluginInfo info;
[email protected]6fdd4182010-10-14 23:59:26917 bool found;
918 ContentSetting setting;
919 std::string mime_type;
920 Send(new ViewHostMsg_GetPluginInfo(
[email protected]c8f73ab2011-01-22 00:05:17921 routing_id_, params.url, frame->top()->url(), params.mimeType.utf8(),
922 &found, &info, &setting, &mime_type));
[email protected]6fdd4182010-10-14 23:59:26923 if (!found || !info.enabled)
[email protected]aad51d1c2010-08-05 08:38:09924 return NULL;
[email protected]1a78d9f32010-12-08 06:38:45925
[email protected]0bd753682010-12-16 18:15:52926 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:45927 pepper_delegate_.CreatePepperPlugin(info.path));
[email protected]aad51d1c2010-08-05 08:38:09928 if (pepper_module)
[email protected]6fdd4182010-10-14 23:59:26929 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]1a78d9f32010-12-08 06:38:45930 return CreateNPAPIPlugin(frame, params, info.path, mime_type);
[email protected]aad51d1c2010-08-05 08:38:09931}
932
[email protected]d8fd6fa2010-02-01 15:54:26933void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) {
934 plugin_delegates_.insert(delegate);
[email protected]49232292010-09-03 19:07:30935 // If the renderer is visible, set initial visibility and focus state.
936 if (!is_hidden()) {
[email protected]784ea1ab2010-09-18 00:02:34937#if defined(OS_MACOSX)
[email protected]49232292010-09-03 19:07:30938 delegate->SetContainerVisibility(true);
939 if (webview() && webview()->isActive())
940 delegate->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:34941#endif
[email protected]49232292010-09-03 19:07:30942 }
[email protected]784ea1ab2010-09-18 00:02:34943 // Plugins start assuming the content has focus (so that they work in
944 // environments where RenderView isn't hosting them), so we always have to
945 // set the initial state. See webplugin_delegate_impl.h for details.
946 delegate->SetContentAreaFocus(has_focus());
[email protected]d8fd6fa2010-02-01 15:54:26947}
948
949void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) {
950 plugin_delegates_.erase(delegate);
951}
[email protected]d8fd6fa2010-02-01 15:54:26952
[email protected]a95986a82010-12-24 06:19:28953bool RenderView::OnMessageReceived(const IPC::Message& message) {
[email protected]26aa0482009-09-30 16:55:27954 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]a9f607e2009-10-23 19:59:27955 if (main_frame)
956 child_process_logging::SetActiveURL(main_frame->url());
[email protected]f8b6b6f2009-03-10 16:48:26957
[email protected]676126f72011-01-15 00:03:51958 ObserverListBase<RenderViewObserver>::Iterator it(observers_);
959 RenderViewObserver* observer;
960 while ((observer = it.GetNext()) != NULL)
961 if (observer->OnMessageReceived(message))
962 return true;
[email protected]b2abac72009-02-26 12:39:28963
[email protected]a95986a82010-12-24 06:19:28964 bool handled = true;
initial.commit09911bf2008-07-26 23:55:29965 IPC_BEGIN_MESSAGE_MAP(RenderView, message)
[email protected]9b18a84f2010-06-10 15:54:04966 IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail)
967 IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot)
initial.commit09911bf2008-07-26 23:55:29968 IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages)
[email protected]82270452009-06-19 15:58:01969 IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone)
[email protected]521b2482011-01-15 00:10:10970 IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview)
971 IPC_MESSAGE_HANDLER(ViewMsg_PrintNodeUnderContextMenu,
972 OnPrintNodeUnderContextMenu)
initial.commit09911bf2008-07-26 23:55:29973 IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate)
974 IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop)
[email protected]1dda4022010-01-28 18:24:56975 IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame)
initial.commit09911bf2008-07-26 23:55:29976 IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo)
977 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
978 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
979 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
[email protected]c0cc3092009-09-12 08:27:27980#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35981 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
[email protected]c0cc3092009-09-12 08:27:27982#endif
initial.commit09911bf2008-07-26 23:55:29983 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
984 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
[email protected]98324892009-09-09 21:16:05985 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel)
986 IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling,
987 OnAdvanceToNextMisspelling)
[email protected]bbbd545c2008-12-15 20:18:04988 IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck)
initial.commit09911bf2008-07-26 23:55:29989 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
990 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
991 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
[email protected]4b59ae602009-06-23 20:58:15992 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
initial.commit09911bf2008-07-26 23:55:29993 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
[email protected]24a7f3c2010-03-25 08:26:49994 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
995 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
[email protected]630e26b2008-10-14 22:55:17996 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
[email protected]9d797f32010-04-23 07:17:54997 IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
998 OnSetContentSettingsForLoadingURL)
[email protected]d0b8d092010-10-25 04:05:17999 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
[email protected]9d797f32010-04-23 07:17:541000 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
1001 OnSetZoomLevelForLoadingURL)
initial.commit09911bf2008-07-26 23:55:291002 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
[email protected]a697f4c2009-09-14 22:30:181003 IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
1004 OnResetPageEncodingToDefault)
[email protected]b2abac72009-02-26 12:39:281005 IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient)
[email protected]bf5c2ff392009-07-08 16:24:331006 IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon)
initial.commit09911bf2008-07-26 23:55:291007 IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest)
[email protected]1810e132009-03-24 23:35:481008 IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest)
initial.commit09911bf2008-07-26 23:55:291009 IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole)
initial.commit09911bf2008-07-26 23:55:291010 IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange)
initial.commit09911bf2008-07-26 23:55:291011 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter)
1012 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
1013 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
1014 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
[email protected]18cb2572008-08-21 20:34:451015 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
initial.commit09911bf2008-07-26 23:55:291016 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
[email protected]266eb6f2008-09-30 23:56:501017 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
1018 OnDragSourceEndedOrMoved)
initial.commit09911bf2008-07-26 23:55:291019 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
1020 OnDragSourceSystemDragEnded)
1021 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
[email protected]9b66f34bf2010-10-27 20:45:511022 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
1023 OnScrollFocusedEditableNodeIntoView)
initial.commit09911bf2008-07-26 23:55:291024 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
1025 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
1026 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
1027 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
[email protected]90dba072011-01-20 20:10:201028 IPC_MESSAGE_HANDLER(ViewMsg_DisplayPrerenderedPage,
1029 OnDisplayPrerenderedPage)
initial.commit09911bf2008-07-26 23:55:291030 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
1031 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
initial.commit09911bf2008-07-26 23:55:291032 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
1033 OnGetAllSavableResourceLinksForCurrentPage)
[email protected]f09c7182009-03-10 12:54:041034 IPC_MESSAGE_HANDLER(
1035 ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks,
1036 OnGetSerializedHtmlDataForCurrentPageWithLocalLinks)
initial.commit09911bf2008-07-26 23:55:291037 IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo)
[email protected]9b18a84f2010-06-10 15:54:041038 IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose)
initial.commit09911bf2008-07-26 23:55:291039 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
1040 IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged)
[email protected]18cb2572008-08-21 20:34:451041 IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost,
[email protected]9b18a84f2010-06-10 15:54:041042 OnHandleMessageFromExternalHost)
[email protected]0aa55312008-10-17 21:53:081043 IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
1044 OnDisassociateFromPopupCount)
[email protected]e8345242010-05-06 03:00:401045 IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose,
1046 OnAllowScriptToClose)
[email protected]30f75e62009-02-25 22:01:001047 IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
[email protected]309d7a282009-03-24 09:18:271048 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse)
[email protected]7120f132009-07-20 21:05:371049 IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke,
1050 OnExtensionMessageInvoke)
[email protected]05d478752009-04-08 23:38:161051 IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode)
[email protected]699ab0d2009-04-23 23:19:141052 IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground)
[email protected]ab32b16c2009-10-16 14:57:251053 IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode,
1054 OnEnablePreferredSizeChangedMode)
[email protected]ce833282010-11-04 15:48:391055 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxChange, OnSearchBoxChange)
1056 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxSubmit, OnSearchBoxSubmit)
1057 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxCancel, OnSearchBoxCancel)
1058 IPC_MESSAGE_HANDLER(ViewMsg_SearchBoxResize, OnSearchBoxResize)
1059 IPC_MESSAGE_HANDLER(ViewMsg_DetermineIfPageSupportsInstant,
1060 OnDetermineIfPageSupportsInstant)
[email protected]cda45c02010-02-25 19:28:101061 IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows,
1062 OnDisableScrollbarsForSmallWindows)
[email protected]80d96fa2009-06-10 22:34:511063 IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
[email protected]7b291f92009-08-14 05:43:531064 IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId,
1065 OnUpdateBrowserWindowId)
1066 IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType,
1067 OnNotifyRendererViewType)
[email protected]581b87eb2009-07-23 23:06:561068 IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt)
[email protected]8c66c5a2009-07-22 17:26:341069 IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
[email protected]6ce7abc52010-02-02 18:40:141070#if defined(OS_MACOSX)
1071 IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility)
[email protected]1e6e3c992010-02-08 15:52:131072 IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged)
[email protected]b7f75862011-01-21 21:15:131073 IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionCompleted,
1074 OnPluginImeCompositionCompleted)
[email protected]6ce7abc52010-02-02 18:40:141075#endif
[email protected]446705872009-09-10 07:22:481076 IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent,
[email protected]a0c7153e2009-12-09 14:36:331077 OnSetEditCommandsForNextKeyEvent)
[email protected]912256b32009-09-18 09:47:351078 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode,
1079 OnExecuteCode)
[email protected]a0c7153e2009-12-09 14:36:331080 IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction,
1081 OnCustomContextMenuAction)
[email protected]d4a00a72010-01-29 01:44:421082 IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage)
[email protected]85d252e2010-04-06 22:21:021083 IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation)
[email protected]dea2d372010-09-25 06:41:141084 IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility)
[email protected]aef92842010-05-21 16:54:361085 IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus)
1086 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction,
1087 OnAccessibilityDoDefaultAction)
[email protected]9892b472010-09-16 00:23:421088 IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK,
1089 OnAccessibilityNotificationsAck)
[email protected]27a9ef32010-09-10 04:06:241090 IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened)
[email protected]1b4209f2011-01-07 00:25:401091#if defined(ENABLE_FLAPPER_HACKS)
1092 IPC_MESSAGE_HANDLER(ViewMsg_PepperConnectTcpACK, OnConnectTcpACK)
1093#endif
[email protected]caf706f2010-10-26 17:54:081094#if defined(OS_MACOSX)
1095 IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1096#endif
[email protected]a6097f42011-01-10 08:50:511097 IPC_MESSAGE_HANDLER(ViewMsg_JavaScriptStressTestControl,
1098 OnJavaScriptStressTestControl)
[email protected]521b2482011-01-15 00:10:101099 IPC_MESSAGE_HANDLER(ViewMsg_ContextMenuClosed, OnContextMenuClosed)
[email protected]634a6f92008-12-01 21:39:311100
initial.commit09911bf2008-07-26 23:55:291101 // Have the super handle all other messages.
[email protected]a95986a82010-12-24 06:19:281102 IPC_MESSAGE_UNHANDLED(handled = RenderWidget::OnMessageReceived(message))
initial.commit09911bf2008-07-26 23:55:291103 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:281104 return handled;
initial.commit09911bf2008-07-26 23:55:291105}
1106
[email protected]9b18a84f2010-06-10 15:54:041107void RenderView::OnCaptureThumbnail() {
[email protected]26aa0482009-09-30 16:55:271108 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291109 if (!main_frame)
1110 return;
1111
1112 // get the URL for this page
[email protected]dd7daa82009-08-10 05:46:451113 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291114 if (url.is_empty())
1115 return;
1116
1117 if (size_.IsEmpty())
1118 return; // Don't create an empty thumbnail!
1119
1120 ThumbnailScore score;
1121 SkBitmap thumbnail;
[email protected]8649fb32009-06-26 17:51:021122 if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight,
[email protected]b6e4bec2008-11-12 01:17:151123 &thumbnail, &score))
1124 return;
1125
initial.commit09911bf2008-07-26 23:55:291126 // send the thumbnail message to the browser process
[email protected]674741932009-02-04 23:44:461127 Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail));
initial.commit09911bf2008-07-26 23:55:291128}
1129
[email protected]9b18a84f2010-06-10 15:54:041130void RenderView::OnCaptureSnapshot() {
[email protected]30507922010-01-15 16:48:231131 SkBitmap snapshot;
1132 bool error = false;
1133
1134 WebFrame* main_frame = webview()->mainFrame();
1135 if (!main_frame)
1136 error = true;
1137
1138 if (!error && !CaptureSnapshot(webview(), &snapshot))
1139 error = true;
1140
1141 DCHECK(error == snapshot.empty()) <<
1142 "Snapshot should be empty on error, non-empty otherwise.";
1143
1144 // Send the snapshot to the browser process.
1145 Send(new ViewHostMsg_Snapshot(routing_id_, snapshot));
1146}
1147
[email protected]068637222009-01-29 16:58:071148void RenderView::OnPrintPages() {
[email protected]c7a827e2011-01-21 00:27:011149 OnPrint(false);
initial.commit09911bf2008-07-26 23:55:291150}
1151
[email protected]82270452009-06-19 15:58:011152void RenderView::OnPrintingDone(int document_cookie, bool success) {
1153 // Ignoring document cookie here since only one print job can be outstanding
1154 // per renderer and document_cookie is 0 when printing is successful.
1155 DCHECK(print_helper_.get());
1156 if (print_helper_.get() != NULL) {
1157 print_helper_->DidFinishPrinting(success);
1158 }
1159}
1160
[email protected]212a49d2010-10-25 18:23:471161void RenderView::OnPrintPreview() {
[email protected]c7a827e2011-01-21 00:27:011162 OnPrint(true);
[email protected]212a49d2010-10-25 18:23:471163}
1164
[email protected]521b2482011-01-15 00:10:101165void RenderView::OnPrintNodeUnderContextMenu() {
1166 if (context_menu_node_.isNull()) {
1167 NOTREACHED();
1168 return;
1169 }
1170
1171 // Make a copy of the node, since we will do a sync call to the browser and
1172 // during that time OnContextMenuClosed might reset context_menu_node_.
1173 WebNode context_menu_node(context_menu_node_);
1174 GetPrintWebViewHelper()->PrintNode(&context_menu_node, false, false);
1175}
1176
initial.commit09911bf2008-07-26 23:55:291177void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) {
1178 if (load_id != page_id_)
1179 return; // this capture call is no longer relevant due to navigation
1180 if (load_id == last_indexed_page_id_)
1181 return; // we already indexed this page
1182
1183 if (!webview())
1184 return;
1185
[email protected]26aa0482009-09-30 16:55:271186 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:291187 if (!main_frame)
1188 return;
1189
1190 // Don't index/capture pages that are in view source mode.
[email protected]dd7daa82009-08-10 05:46:451191 if (main_frame->isViewSourceModeEnabled())
initial.commit09911bf2008-07-26 23:55:291192 return;
1193
1194 // Don't index/capture pages that failed to load. This only checks the top
1195 // level frame so the thumbnail may contain a frame that failed to load.
[email protected]dd7daa82009-08-10 05:46:451196 WebDataSource* ds = main_frame->dataSource();
[email protected]726985e22009-06-18 21:09:281197 if (ds && ds->hasUnreachableURL())
initial.commit09911bf2008-07-26 23:55:291198 return;
1199
1200 if (!preliminary_capture)
1201 last_indexed_page_id_ = load_id;
1202
[email protected]a8a81292010-01-21 00:32:451203 // Get the URL for this page.
[email protected]dd7daa82009-08-10 05:46:451204 GURL url(main_frame->url());
initial.commit09911bf2008-07-26 23:55:291205 if (url.is_empty())
1206 return;
1207
[email protected]a8a81292010-01-21 00:32:451208 // Retrieve the frame's full text.
[email protected]e5106202010-06-11 21:12:361209 string16 contents;
initial.commit09911bf2008-07-26 23:55:291210 CaptureText(main_frame, &contents);
1211 if (contents.size()) {
[email protected]1c57b7b2010-07-12 17:38:101212 WebKit::WebDocument document = main_frame->document();
[email protected]5ddfd63e2010-09-01 15:48:371213 // If the page explicitly specifies a language, use it, otherwise we'll
1214 // determine it based on the text content using the CLD.
1215 std::string language =
1216 TranslateHelper::GetPageLanguageFromMetaTag(&document);
1217 if (language.empty()) {
1218 base::TimeTicks begin_time = base::TimeTicks::Now();
1219 language = DetermineTextLanguage(contents);
1220 UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection",
1221 base::TimeTicks::Now() - begin_time);
1222 }
[email protected]a8a81292010-01-21 00:32:451223 // Send the text to the browser for indexing (the browser might decide not
1224 // to index, if the URL is HTTPS for instance) and language discovery.
[email protected]5ddfd63e2010-09-01 15:48:371225 Send(new ViewHostMsg_PageContents(
1226 routing_id_, url, load_id, contents, language,
1227 TranslateHelper::IsPageTranslatable(&document)));
[email protected]5c4266922009-07-10 16:41:271228 }
1229
[email protected]d54169e92011-01-21 09:19:521230 // Generate the thumbnail here if the in-browser thumbnailing isn't
1231 // enabled. TODO(satorux): Remove this and related code once
1232 // crbug.com/65936 is complete.
1233 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1234 switches::kEnableInBrowserThumbnailing)) {
1235 OnCaptureThumbnail();
1236 }
[email protected]3ead1322010-11-19 20:01:001237
1238 if (phishing_delegate_.get())
1239 phishing_delegate_->FinishedLoad(&contents);
initial.commit09911bf2008-07-26 23:55:291240}
1241
[email protected]e5106202010-06-11 21:12:361242void RenderView::CaptureText(WebFrame* frame, string16* contents) {
initial.commit09911bf2008-07-26 23:55:291243 contents->clear();
1244 if (!frame)
1245 return;
1246
1247#ifdef TIME_TEXT_RETRIEVAL
1248 double begin = time_util::GetHighResolutionTimeNow();
1249#endif
1250
1251 // get the contents of the frame
[email protected]e5106202010-06-11 21:12:361252 *contents = frame->contentAsText(kMaxIndexChars);
initial.commit09911bf2008-07-26 23:55:291253
1254#ifdef TIME_TEXT_RETRIEVAL
1255 double end = time_util::GetHighResolutionTimeNow();
1256 char buf[128];
1257 sprintf_s(buf, "%d chars retrieved for indexing in %gms\n",
1258 contents.size(), (end - begin)*1000);
1259 OutputDebugStringA(buf);
1260#endif
1261
1262 // When the contents are clipped to the maximum, we don't want to have a
1263 // partial word indexed at the end that might have been clipped. Therefore,
1264 // terminate the string at the last space to ensure no words are clipped.
1265 if (contents->size() == kMaxIndexChars) {
[email protected]e5106202010-06-11 21:12:361266 size_t last_space_index = contents->find_last_of(kWhitespaceUTF16);
initial.commit09911bf2008-07-26 23:55:291267 if (last_space_index == std::wstring::npos)
1268 return; // don't index if we got a huge block of text with no spaces
1269 contents->resize(last_space_index);
1270 }
1271}
1272
[email protected]8649fb32009-06-26 17:51:021273bool RenderView::CaptureThumbnail(WebView* view,
initial.commit09911bf2008-07-26 23:55:291274 int w,
1275 int h,
1276 SkBitmap* thumbnail,
1277 ThumbnailScore* score) {
[email protected]30507922010-01-15 16:48:231278 base::TimeTicks beginning_time = base::TimeTicks::Now();
[email protected]b6e4bec2008-11-12 01:17:151279
[email protected]8649fb32009-06-26 17:51:021280 skia::PlatformCanvas canvas;
[email protected]30507922010-01-15 16:48:231281
1282 // Paint |view| into |canvas|.
1283 if (!PaintViewIntoCanvas(view, canvas))
[email protected]8649fb32009-06-26 17:51:021284 return false;
[email protected]8649fb32009-06-26 17:51:021285
1286 skia::BitmapPlatformDevice& device =
1287 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1288
1289 const SkBitmap& src_bmp = device.accessBitmap(false);
initial.commit09911bf2008-07-26 23:55:291290
[email protected]cab34d6a2009-09-24 01:14:521291 SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) };
initial.commit09911bf2008-07-26 23:55:291292 float dest_aspect = dest_rect.width() / dest_rect.height();
1293
1294 // Get the src rect so that we can preserve the aspect ratio while filling
1295 // the destination.
1296 SkIRect src_rect;
1297 if (src_bmp.width() < dest_rect.width() ||
1298 src_bmp.height() < dest_rect.height()) {
1299 // Source image is smaller: we clip the part of source image within the
1300 // dest rect, and then stretch it to fill the dest rect. We don't respect
1301 // the aspect ratio in this case.
1302 src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()),
1303 static_cast<S16CPU>(dest_rect.height()));
1304 score->good_clipping = false;
1305 } else {
1306 float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height();
1307 if (src_aspect > dest_aspect) {
1308 // Wider than tall, clip horizontally: we center the smaller thumbnail in
1309 // the wider screen.
1310 S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect);
1311 S16CPU x_offset = (src_bmp.width() - new_width) / 2;
1312 src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height());
1313 score->good_clipping = false;
1314 } else {
1315 src_rect.set(0, 0, src_bmp.width(),
1316 static_cast<S16CPU>(src_bmp.width() / dest_aspect));
1317 score->good_clipping = true;
1318 }
1319 }
1320
[email protected]26aa0482009-09-30 16:55:271321 score->at_top = (view->mainFrame()->scrollOffset().height == 0);
initial.commit09911bf2008-07-26 23:55:291322
1323 SkBitmap subset;
[email protected]8649fb32009-06-26 17:51:021324 device.accessBitmap(false).extractSubset(&subset, src_rect);
initial.commit09911bf2008-07-26 23:55:291325
[email protected]82afe4b2010-11-12 20:36:221326 // First do a fast downsample by powers of two to get close to the final size.
1327 SkBitmap downsampled_subset =
1328 SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h);
1329
1330 // Do a high-quality resize from the downscaled size to the final size.
[email protected]465b34b72008-12-12 20:19:141331 *thumbnail = skia::ImageOperations::Resize(
[email protected]82afe4b2010-11-12 20:36:221332 downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h);
initial.commit09911bf2008-07-26 23:55:291333
1334 score->boring_score = CalculateBoringScore(thumbnail);
1335
[email protected]30507922010-01-15 16:48:231336 HISTOGRAM_TIMES("Renderer4.Thumbnail",
1337 base::TimeTicks::Now() - beginning_time);
[email protected]82afe4b2010-11-12 20:36:221338
[email protected]b6e4bec2008-11-12 01:17:151339 return true;
initial.commit09911bf2008-07-26 23:55:291340}
1341
[email protected]30507922010-01-15 16:48:231342bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) {
1343 base::TimeTicks beginning_time = base::TimeTicks::Now();
initial.commit09911bf2008-07-26 23:55:291344
[email protected]30507922010-01-15 16:48:231345 skia::PlatformCanvas canvas;
1346 if (!PaintViewIntoCanvas(view, canvas))
1347 return false;
1348
1349 skia::BitmapPlatformDevice& device =
1350 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice());
1351
1352 const SkBitmap& bitmap = device.accessBitmap(false);
1353 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1354 return false;
1355
1356 HISTOGRAM_TIMES("Renderer4.Snapshot",
1357 base::TimeTicks::Now() - beginning_time);
1358 return true;
initial.commit09911bf2008-07-26 23:55:291359}
1360
1361void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) {
1362 if (!webview())
1363 return;
1364
[email protected]3cc72b12010-03-18 23:03:001365 history_list_offset_ = params.current_history_list_offset;
1366 history_list_length_ = params.current_history_list_length;
1367
[email protected]a9f607e2009-10-23 19:59:271368 child_process_logging::SetActiveURL(params.url);
[email protected]f8b6b6f2009-03-10 16:48:261369
initial.commit09911bf2008-07-26 23:55:291370 AboutHandler::MaybeHandle(params.url);
1371
[email protected]ecbf10d2010-02-18 13:03:291372 bool is_reload =
1373 params.navigation_type == ViewMsg_Navigate_Params::RELOAD ||
1374 params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
initial.commit09911bf2008-07-26 23:55:291375
[email protected]26aa0482009-09-30 16:55:271376 WebFrame* main_frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:451377 if (is_reload && main_frame->currentHistoryItem().isNull()) {
initial.commit09911bf2008-07-26 23:55:291378 // We cannot reload if we do not have any history state. This happens, for
1379 // example, when recovering from a crash. Our workaround here is a bit of
1380 // a hack since it means that reload after a crashed tab does not cause an
1381 // end-to-end cache validation.
1382 is_reload = false;
1383 }
1384
[email protected]77f17a82009-05-21 04:42:541385 // A navigation resulting from loading a javascript URL should not be treated
1386 // as a browser initiated event. Instead, we want it to look as if the page
1387 // initiated any load resulting from JS execution.
1388 if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) {
[email protected]5e369672009-11-03 23:48:301389 NavigationState* state = NavigationState::CreateBrowserInitiated(
[email protected]3cc72b12010-03-18 23:03:001390 params.page_id,
1391 params.pending_history_list_offset,
1392 params.transition,
1393 params.request_time);
[email protected]5e369672009-11-03 23:48:301394 if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) {
1395 // We're doing a load of a page that was restored from the last session.
1396 // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE)
1397 // which can result in stale data for pages that are set to expire. We
1398 // explicitly override that by setting the policy here so that as
1399 // necessary we load from the network.
1400 state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy);
1401 }
1402 pending_navigation_state_.reset(state);
[email protected]77f17a82009-05-21 04:42:541403 }
initial.commit09911bf2008-07-26 23:55:291404
[email protected]a7ccc4d2010-01-27 08:14:481405 NavigationState* navigation_state = pending_navigation_state_.get();
1406
[email protected]04d3c6e2009-05-22 17:00:131407 // If we are reloading, then WebKit will use the history state of the current
1408 // page, so we should just ignore any given history state. Otherwise, if we
1409 // have history state, then we need to navigate to it, which corresponds to a
1410 // back/forward navigation event.
[email protected]e6f546c32009-07-01 17:12:551411 if (is_reload) {
[email protected]a7ccc4d2010-01-27 08:14:481412 if (navigation_state)
1413 navigation_state->set_load_type(NavigationState::RELOAD);
[email protected]ecbf10d2010-02-18 13:03:291414 bool ignore_cache = (params.navigation_type ==
1415 ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE);
1416 main_frame->reload(ignore_cache);
[email protected]e6f546c32009-07-01 17:12:551417 } else if (!params.state.empty()) {
[email protected]04d3c6e2009-05-22 17:00:131418 // We must know the page ID of the page we are navigating back to.
[email protected]f929f2f22009-06-12 16:56:581419 DCHECK_NE(params.page_id, -1);
[email protected]a7ccc4d2010-01-27 08:14:481420 if (navigation_state)
1421 navigation_state->set_load_type(NavigationState::HISTORY_LOAD);
[email protected]dd7daa82009-08-10 05:46:451422 main_frame->loadHistoryItem(
[email protected]ca948a22009-06-25 19:36:171423 webkit_glue::HistoryItemFromString(params.state));
[email protected]04d3c6e2009-05-22 17:00:131424 } else {
1425 // Navigate to the given URL.
[email protected]726985e22009-06-18 21:09:281426 WebURLRequest request(params.url);
initial.commit09911bf2008-07-26 23:55:291427
[email protected]e6f546c32009-07-01 17:12:551428 // A session history navigation should have been accompanied by state.
1429 DCHECK_EQ(params.page_id, -1);
[email protected]04d3c6e2009-05-22 17:00:131430
[email protected]dd7daa82009-08-10 05:46:451431 if (main_frame->isViewSourceModeEnabled())
[email protected]e6f546c32009-07-01 17:12:551432 request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad);
[email protected]04d3c6e2009-05-22 17:00:131433
[email protected]726985e22009-06-18 21:09:281434 if (params.referrer.is_valid()) {
1435 request.setHTTPHeaderField(WebString::fromUTF8("Referer"),
1436 WebString::fromUTF8(params.referrer.spec()));
1437 }
[email protected]04d3c6e2009-05-22 17:00:131438
[email protected]52c68652010-12-07 17:47:041439 if (!params.extra_headers.empty()) {
1440 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1441 params.extra_headers.end(), "\n");
1442 i.GetNext(); ) {
1443 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
1444 WebString::fromUTF8(i.values()));
1445 }
1446 }
1447
[email protected]90dba072011-01-20 20:10:201448 if (navigation_state) {
1449 if (params.navigation_type != ViewMsg_Navigate_Params::PRERENDER) {
1450 navigation_state->set_load_type(NavigationState::NORMAL_LOAD);
1451 } else {
1452 navigation_state->set_load_type(NavigationState::PRERENDER_LOAD);
1453 navigation_state->set_is_prerendering(true);
1454 }
1455 }
[email protected]dd7daa82009-08-10 05:46:451456 main_frame->loadRequest(request);
[email protected]c0588052008-10-27 23:01:501457 }
1458
[email protected]77f17a82009-05-21 04:42:541459 // In case LoadRequest failed before DidCreateDataSource was called.
1460 pending_navigation_state_.reset();
initial.commit09911bf2008-07-26 23:55:291461}
1462
1463// Stop loading the current page
1464void RenderView::OnStop() {
1465 if (webview())
[email protected]b4bb2502009-10-01 22:35:271466 webview()->mainFrame()->stopLoading();
initial.commit09911bf2008-07-26 23:55:291467}
1468
[email protected]ecbf10d2010-02-18 13:03:291469// Reload current focused frame.
1470// E.g. called by right-clicking on the frame and picking "reload this frame".
[email protected]1dda4022010-01-28 18:24:561471void RenderView::OnReloadFrame() {
[email protected]ecbf10d2010-02-18 13:03:291472 if (webview() && webview()->focusedFrame()) {
1473 // We always obey the cache (ignore_cache=false) here.
1474 // TODO(evanm): perhaps we could allow shift-clicking the menu item to do
1475 // a cache-ignoring reload of the frame.
1476 webview()->focusedFrame()->reload(false);
1477 }
[email protected]1dda4022010-01-28 18:24:561478}
1479
initial.commit09911bf2008-07-26 23:55:291480void RenderView::OnCopyImageAt(int x, int y) {
[email protected]26aa0482009-09-30 16:55:271481 webview()->copyImageAt(WebPoint(x, y));
initial.commit09911bf2008-07-26 23:55:291482}
1483
[email protected]68b1e922009-06-23 16:00:251484void RenderView::OnExecuteEditCommand(const std::string& name,
1485 const std::string& value) {
[email protected]26aa0482009-09-30 16:55:271486 if (!webview() || !webview()->focusedFrame())
[email protected]68b1e922009-06-23 16:00:251487 return;
1488
[email protected]26aa0482009-09-30 16:55:271489 webview()->focusedFrame()->executeCommand(
[email protected]dd7daa82009-08-10 05:46:451490 WebString::fromUTF8(name), WebString::fromUTF8(value));
[email protected]68b1e922009-06-23 16:00:251491}
1492
[email protected]b2abac72009-02-26 12:39:281493void RenderView::OnSetupDevToolsClient() {
[email protected]676126f72011-01-15 00:03:511494 DCHECK(!devtools_client_);
1495 devtools_client_ = new DevToolsClient(this);
[email protected]b2abac72009-02-26 12:39:281496}
1497
initial.commit09911bf2008-07-26 23:55:291498void RenderView::OnUpdateTargetURLAck() {
1499 // Check if there is a targeturl waiting to be sent.
1500 if (target_url_status_ == TARGET_PENDING) {
1501 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_,
1502 pending_target_url_));
1503 }
1504
1505 target_url_status_ = TARGET_NONE;
1506}
1507
1508void RenderView::OnUndo() {
1509 if (!webview())
1510 return;
1511
[email protected]26aa0482009-09-30 16:55:271512 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"));
[email protected]afe3a1672009-11-17 19:04:121513 UserMetricsRecordAction("Undo");
initial.commit09911bf2008-07-26 23:55:291514}
1515
1516void RenderView::OnRedo() {
1517 if (!webview())
1518 return;
1519
[email protected]26aa0482009-09-30 16:55:271520 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"));
[email protected]afe3a1672009-11-17 19:04:121521 UserMetricsRecordAction("Redo");
initial.commit09911bf2008-07-26 23:55:291522}
1523
1524void RenderView::OnCut() {
1525 if (!webview())
1526 return;
1527
[email protected]26aa0482009-09-30 16:55:271528 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"));
[email protected]afe3a1672009-11-17 19:04:121529 UserMetricsRecordAction("Cut");
initial.commit09911bf2008-07-26 23:55:291530}
1531
1532void RenderView::OnCopy() {
1533 if (!webview())
1534 return;
1535
[email protected]26aa0482009-09-30 16:55:271536 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"));
[email protected]afe3a1672009-11-17 19:04:121537 UserMetricsRecordAction("Copy");
initial.commit09911bf2008-07-26 23:55:291538}
1539
[email protected]c0cc3092009-09-12 08:27:271540#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:351541void RenderView::OnCopyToFindPboard() {
1542 if (!webview())
1543 return;
1544
1545 // Since the find pasteboard supports only plain text, this can be simpler
1546 // than the |OnCopy()| case.
[email protected]26aa0482009-09-30 16:55:271547 WebFrame* frame = webview()->focusedFrame();
[email protected]a954bf72009-09-12 07:30:351548 if (frame->hasSelection()) {
1549 string16 selection = frame->selectionAsText();
1550 RenderThread::current()->Send(
1551 new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection));
1552 }
1553
[email protected]afe3a1672009-11-17 19:04:121554 UserMetricsRecordAction("CopyToFindPboard");
[email protected]a954bf72009-09-12 07:30:351555}
[email protected]c0cc3092009-09-12 08:27:271556#endif
[email protected]a954bf72009-09-12 07:30:351557
initial.commit09911bf2008-07-26 23:55:291558void RenderView::OnPaste() {
1559 if (!webview())
1560 return;
1561
[email protected]26aa0482009-09-30 16:55:271562 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"));
[email protected]afe3a1672009-11-17 19:04:121563 UserMetricsRecordAction("Paste");
initial.commit09911bf2008-07-26 23:55:291564}
1565
[email protected]2a3a7762009-10-19 19:17:321566void RenderView::OnReplace(const string16& text) {
initial.commit09911bf2008-07-26 23:55:291567 if (!webview())
1568 return;
1569
[email protected]1ff7a032010-02-03 02:46:031570 WebFrame* frame = webview()->focusedFrame();
1571 if (!frame->hasSelection())
1572 frame->selectWordAroundCaret();
1573 frame->replaceSelection(text);
initial.commit09911bf2008-07-26 23:55:291574}
1575
[email protected]98324892009-09-09 21:16:051576void RenderView::OnAdvanceToNextMisspelling() {
1577 if (!webview())
1578 return;
[email protected]26aa0482009-09-30 16:55:271579 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051580 WebString::fromUTF8("AdvanceToNextMisspelling"));
1581}
1582
1583void RenderView::OnToggleSpellPanel(bool is_currently_visible) {
1584 if (!webview())
1585 return;
1586 // We need to tell the webView whether the spelling panel is visible or not so
1587 // that it won't need to make ipc calls later.
[email protected]8922e1f2009-10-03 05:01:261588 spelling_panel_visible_ = is_currently_visible;
[email protected]26aa0482009-09-30 16:55:271589 webview()->focusedFrame()->executeCommand(
[email protected]98324892009-09-09 21:16:051590 WebString::fromUTF8("ToggleSpellPanel"));
1591}
1592
[email protected]bbbd545c2008-12-15 20:18:041593void RenderView::OnToggleSpellCheck() {
1594 if (!webview())
1595 return;
1596
[email protected]26aa0482009-09-30 16:55:271597 WebFrame* frame = webview()->focusedFrame();
[email protected]dd7daa82009-08-10 05:46:451598 frame->enableContinuousSpellChecking(
1599 !frame->isContinuousSpellCheckingEnabled());
[email protected]bbbd545c2008-12-15 20:18:041600}
1601
initial.commit09911bf2008-07-26 23:55:291602void RenderView::OnDelete() {
1603 if (!webview())
1604 return;
1605
[email protected]26aa0482009-09-30 16:55:271606 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"));
[email protected]afe3a1672009-11-17 19:04:121607 UserMetricsRecordAction("DeleteSelection");
initial.commit09911bf2008-07-26 23:55:291608}
1609
1610void RenderView::OnSelectAll() {
1611 if (!webview())
1612 return;
1613
[email protected]26aa0482009-09-30 16:55:271614 webview()->focusedFrame()->executeCommand(
[email protected]a100d76bb2009-08-14 17:50:221615 WebString::fromUTF8("SelectAll"));
[email protected]afe3a1672009-11-17 19:04:121616 UserMetricsRecordAction("SelectAll");
initial.commit09911bf2008-07-26 23:55:291617}
1618
1619void RenderView::OnSetInitialFocus(bool reverse) {
1620 if (!webview())
1621 return;
[email protected]26aa0482009-09-30 16:55:271622 webview()->setInitialFocus(reverse);
initial.commit09911bf2008-07-26 23:55:291623}
1624
[email protected]9b66f34bf2010-10-27 20:45:511625void RenderView::OnScrollFocusedEditableNodeIntoView() {
1626 if (!webview())
1627 return;
1628 WebFrame* focused_frame = webview()->focusedFrame();
1629 if (focused_frame) {
1630 WebDocument doc = focused_frame->document();
1631 if (!doc.isNull()) {
1632 WebNode node = doc.focusedNode();
1633 if (IsEditableNode(node))
1634 // TODO(varunjain): Change webkit API to scroll a particular node into
1635 // view and use that API here instead.
1636 webview()->scrollFocusedNodeIntoView();
1637 }
1638 }
1639}
1640
initial.commit09911bf2008-07-26 23:55:291641///////////////////////////////////////////////////////////////////////////////
1642
[email protected]433819d2010-01-30 20:20:011643void RenderView::SetContentSettings(const ContentSettings& settings) {
1644 current_content_settings_ = settings;
[email protected]f85f0702010-01-30 09:31:011645}
1646
initial.commit09911bf2008-07-26 23:55:291647// Tell the embedding application that the URL of the active page has changed
1648void RenderView::UpdateURL(WebFrame* frame) {
[email protected]dd7daa82009-08-10 05:46:451649 WebDataSource* ds = frame->dataSource();
initial.commit09911bf2008-07-26 23:55:291650 DCHECK(ds);
1651
[email protected]726985e22009-06-18 21:09:281652 const WebURLRequest& request = ds->request();
1653 const WebURLRequest& original_request = ds->originalRequest();
1654 const WebURLResponse& response = ds->response();
initial.commit09911bf2008-07-26 23:55:291655
[email protected]daa8c58e2009-06-15 17:21:101656 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
1657 DCHECK(navigation_state);
initial.commit09911bf2008-07-26 23:55:291658
1659 ViewHostMsg_FrameNavigate_Params params;
[email protected]726985e22009-06-18 21:09:281660 params.http_status_code = response.httpStatusCode();
initial.commit09911bf2008-07-26 23:55:291661 params.is_post = false;
1662 params.page_id = page_id_;
[email protected]dabb0d12010-10-05 12:50:071663 params.frame_id = frame->identifier();
[email protected]726985e22009-06-18 21:09:281664 params.is_content_filtered = response.isContentFiltered();
[email protected]af15bed2010-08-25 21:12:091665 params.was_within_same_page = navigation_state->was_within_same_page();
[email protected]e6f546c32009-07-01 17:12:551666 if (!navigation_state->security_info().empty()) {
initial.commit09911bf2008-07-26 23:55:291667 // SSL state specified in the request takes precedence over the one in the
1668 // response.
1669 // So far this is only intended for error pages that are not expected to be
1670 // over ssl, so we should not get any clash.
[email protected]726985e22009-06-18 21:09:281671 DCHECK(response.securityInfo().isEmpty());
[email protected]e6f546c32009-07-01 17:12:551672 params.security_info = navigation_state->security_info();
initial.commit09911bf2008-07-26 23:55:291673 } else {
[email protected]726985e22009-06-18 21:09:281674 params.security_info = response.securityInfo();
initial.commit09911bf2008-07-26 23:55:291675 }
1676
1677 // Set the URL to be displayed in the browser UI to the user.
[email protected]726985e22009-06-18 21:09:281678 if (ds->hasUnreachableURL()) {
1679 params.url = ds->unreachableURL();
initial.commit09911bf2008-07-26 23:55:291680 } else {
[email protected]726985e22009-06-18 21:09:281681 params.url = request.url();
initial.commit09911bf2008-07-26 23:55:291682 }
1683
[email protected]726985e22009-06-18 21:09:281684 GetRedirectChain(ds, &params.redirects);
[email protected]d94dc1e2010-03-04 09:29:241685 params.should_update_history = !ds->hasUnreachableURL() &&
1686 !response.isMultipartPayload();
initial.commit09911bf2008-07-26 23:55:291687
[email protected]ce0e250d2009-10-23 21:00:351688 params.searchable_form_url = navigation_state->searchable_form_url();
1689 params.searchable_form_encoding =
1690 navigation_state->searchable_form_encoding();
initial.commit09911bf2008-07-26 23:55:291691
1692 const PasswordForm* password_form_data =
[email protected]daa8c58e2009-06-15 17:21:101693 navigation_state->password_form_data();
initial.commit09911bf2008-07-26 23:55:291694 if (password_form_data)
1695 params.password_form = *password_form_data;
1696
1697 params.gesture = navigation_gesture_;
1698 navigation_gesture_ = NavigationGestureUnknown;
1699
[email protected]dd7daa82009-08-10 05:46:451700 if (!frame->parent()) {
initial.commit09911bf2008-07-26 23:55:291701 // Top-level navigation.
1702
[email protected]71b0d5d2010-02-15 05:43:071703 // Clear "block" flags for the new page. This needs to happen before any of
1704 // allowScripts(), allowImages(), allowPlugins() is called for the new page
1705 // so that these functions can correctly detect that a piece of content
1706 // flipped from "not blocked" to "blocked".
1707 ClearBlockedContentSettings();
1708
[email protected]62d2a112010-04-07 00:53:021709 // Set content settings. Default them from the parent window if one exists.
1710 // This makes sure about:blank windows work as expected.
[email protected]f85f0702010-01-30 09:31:011711 HostContentSettings::iterator host_content_settings =
[email protected]9d797f32010-04-23 07:17:541712 host_content_settings_.find(GURL(request.url()));
[email protected]f85f0702010-01-30 09:31:011713 if (host_content_settings != host_content_settings_.end()) {
[email protected]433819d2010-01-30 20:20:011714 SetContentSettings(host_content_settings->second);
[email protected]f85f0702010-01-30 09:31:011715
1716 // These content settings were merely recorded transiently for this load.
1717 // We can erase them now. If at some point we reload this page, the
1718 // browser will send us new, up-to-date content settings.
1719 host_content_settings_.erase(host_content_settings);
[email protected]3a387ae2010-04-08 01:58:401720 } else if (frame->opener()) {
[email protected]8128cdd02010-07-21 20:40:101721 // The opener's view is not guaranteed to be non-null (it could be
1722 // detached from its page but not yet destructed).
1723 if (WebView* opener_view = frame->opener()->view()) {
1724 RenderView* opener = FromWebView(opener_view);
1725 SetContentSettings(opener->current_content_settings_);
1726 }
[email protected]f85f0702010-01-30 09:31:011727 }
1728
[email protected]b75b8292010-10-01 07:28:251729 // Set zoom level, but don't do it for full-page plugin since they don't use
1730 // the same zoom settings.
[email protected]f85f0702010-01-30 09:31:011731 HostZoomLevels::iterator host_zoom =
[email protected]9d797f32010-04-23 07:17:541732 host_zoom_levels_.find(GURL(request.url()));
[email protected]b75b8292010-10-01 07:28:251733 if (webview()->mainFrame()->document().isPluginDocument()) {
1734 // Reset the zoom levels for plugins.
[email protected]b75b8292010-10-01 07:28:251735 webview()->setZoomLevel(false, 0);
[email protected]b75b8292010-10-01 07:28:251736 } else {
1737 if (host_zoom != host_zoom_levels_.end())
[email protected]b75b8292010-10-01 07:28:251738 webview()->setZoomLevel(false, host_zoom->second);
[email protected]b75b8292010-10-01 07:28:251739 }
1740
[email protected]f85f0702010-01-30 09:31:011741 if (host_zoom != host_zoom_levels_.end()) {
[email protected]40bd6582009-12-04 23:49:511742 // This zoom level was merely recorded transiently for this load. We can
1743 // erase it now. If at some point we reload this page, the browser will
1744 // send us a new, up-to-date zoom level.
[email protected]f85f0702010-01-30 09:31:011745 host_zoom_levels_.erase(host_zoom);
[email protected]40bd6582009-12-04 23:49:511746 }
1747
[email protected]b75b8292010-10-01 07:28:251748 // Reset the zoom limits in case a plugin had changed them previously. This
1749 // will also call us back which will cause us to send a message to
1750 // update TabContents.
[email protected]b75b8292010-10-01 07:28:251751 webview()->zoomLimitsChanged(
1752 WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier),
1753 WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier));
[email protected]b75b8292010-10-01 07:28:251754
initial.commit09911bf2008-07-26 23:55:291755 // Update contents MIME type for main frame.
[email protected]9c5645b2009-08-11 03:37:551756 params.contents_mime_type = ds->response().mimeType().utf8();
initial.commit09911bf2008-07-26 23:55:291757
[email protected]daa8c58e2009-06-15 17:21:101758 params.transition = navigation_state->transition_type();
initial.commit09911bf2008-07-26 23:55:291759 if (!PageTransition::IsMainFrame(params.transition)) {
1760 // If the main frame does a load, it should not be reported as a subframe
1761 // navigation. This can occur in the following case:
1762 // 1. You're on a site with frames.
1763 // 2. You do a subframe navigation. This is stored with transition type
1764 // MANUAL_SUBFRAME.
1765 // 3. You navigate to some non-frame site, say, google.com.
1766 // 4. You navigate back to the page from step 2. Since it was initially
1767 // MANUAL_SUBFRAME, it will be that same transition type here.
1768 // We don't want that, because any navigation that changes the toplevel
1769 // frame should be tracked as a toplevel navigation (this allows us to
1770 // update the URL bar, etc).
1771 params.transition = PageTransition::LINK;
1772 }
1773
initial.commit09911bf2008-07-26 23:55:291774 // If we have a valid consumed client redirect source,
1775 // the page contained a client redirect (meta refresh, document.loc...),
1776 // so we set the referrer and transition to match.
1777 if (completed_client_redirect_src_.is_valid()) {
[email protected]77e09a92008-08-01 18:11:041778 DCHECK(completed_client_redirect_src_ == params.redirects[0]);
initial.commit09911bf2008-07-26 23:55:291779 params.referrer = completed_client_redirect_src_;
1780 params.transition = static_cast<PageTransition::Type>(
1781 params.transition | PageTransition::CLIENT_REDIRECT);
1782 } else {
1783 // Bug 654101: the referrer will be empty on https->http transitions. It
1784 // would be nice if we could get the real referrer from somewhere.
[email protected]726985e22009-06-18 21:09:281785 params.referrer = GURL(
1786 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
initial.commit09911bf2008-07-26 23:55:291787 }
1788
[email protected]726985e22009-06-18 21:09:281789 string16 method = request.httpMethod();
1790 if (EqualsASCII(method, "POST"))
initial.commit09911bf2008-07-26 23:55:291791 params.is_post = true;
1792
[email protected]c2a797d2009-09-21 16:46:321793 // Save some histogram data so we can compute the average memory used per
1794 // page load of the glyphs.
1795 UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad",
1796 webkit_glue::GetGlyphPageCount());
1797
[email protected]15cf526b2010-02-12 06:33:491798 // This message needs to be sent before any of allowScripts(),
1799 // allowImages(), allowPlugins() is called for the new page, so that when
1800 // these functions send a ViewHostMsg_ContentBlocked message, it arrives
1801 // after the ViewHostMsg_FrameNavigate message.
initial.commit09911bf2008-07-26 23:55:291802 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1803 } else {
1804 // Subframe navigation: the type depends on whether this navigation
1805 // generated a new session history entry. When they do generate a session
1806 // history entry, it means the user initiated the navigation and we should
1807 // mark it as such. This test checks if this is the first time UpdateURL
1808 // has been called since WillNavigateToURL was called to initiate the load.
1809 if (page_id_ > last_page_id_sent_to_browser_)
1810 params.transition = PageTransition::MANUAL_SUBFRAME;
1811 else
1812 params.transition = PageTransition::AUTO_SUBFRAME;
1813
initial.commit09911bf2008-07-26 23:55:291814 Send(new ViewHostMsg_FrameNavigate(routing_id_, params));
1815 }
1816
1817 last_page_id_sent_to_browser_ =
1818 std::max(last_page_id_sent_to_browser_, page_id_);
1819
1820 // If we end up reusing this WebRequest (for example, due to a #ref click),
[email protected]daa8c58e2009-06-15 17:21:101821 // we don't want the transition type to persist. Just clear it.
1822 navigation_state->set_transition_type(PageTransition::LINK);
[email protected]266eb6f2008-09-30 23:56:501823
[email protected]af15bed2010-08-25 21:12:091824 // Check if the navigation was within the same page, in which case we don't
1825 // want to clear the accessibility cache.
1826 if (accessibility_.get() && !navigation_state->was_within_same_page()) {
[email protected]17455962010-02-24 01:39:351827 accessibility_.reset();
[email protected]dea2d372010-09-25 06:41:141828 pending_accessibility_notifications_.clear();
[email protected]266eb6f2008-09-30 23:56:501829 }
initial.commit09911bf2008-07-26 23:55:291830}
1831
1832// Tell the embedding application that the title of the active page has changed
[email protected]3d9689372009-09-10 04:29:171833void RenderView::UpdateTitle(WebFrame* frame, const string16& title) {
initial.commit09911bf2008-07-26 23:55:291834 // Ignore all but top level navigations...
[email protected]3d9689372009-09-10 04:29:171835 if (!frame->parent()) {
[email protected]f0af6a72009-05-30 05:25:171836 Send(new ViewHostMsg_UpdateTitle(
[email protected]3d9689372009-09-10 04:29:171837 routing_id_,
1838 page_id_,
1839 UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ?
1840 title.substr(0, chrome::kMaxTitleChars) : title)));
[email protected]f0af6a72009-05-30 05:25:171841 }
initial.commit09911bf2008-07-26 23:55:291842}
1843
1844void RenderView::UpdateEncoding(WebFrame* frame,
[email protected]41fc0322009-09-04 22:23:401845 const std::string& encoding_name) {
initial.commit09911bf2008-07-26 23:55:291846 // Only update main frame's encoding_name.
[email protected]26aa0482009-09-30 16:55:271847 if (webview()->mainFrame() == frame &&
initial.commit09911bf2008-07-26 23:55:291848 last_encoding_name_ != encoding_name) {
[email protected]e38f40152008-09-12 23:08:301849 // Save the encoding name for later comparing.
initial.commit09911bf2008-07-26 23:55:291850 last_encoding_name_ = encoding_name;
1851
[email protected]e38f40152008-09-12 23:08:301852 Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_));
initial.commit09911bf2008-07-26 23:55:291853 }
1854}
1855
[email protected]e15f680732010-11-23 22:30:201856// Sends the last committed session history state to the browser so it will be
1857// saved before we navigate to a new page. This must be called *before* the
1858// page ID has been updated so we know what it was.
initial.commit09911bf2008-07-26 23:55:291859void RenderView::UpdateSessionHistory(WebFrame* frame) {
1860 // If we have a valid page ID at this point, then it corresponds to the page
1861 // we are navigating away from. Otherwise, this is the first navigation, so
1862 // there is no past session history to record.
1863 if (page_id_ == -1)
1864 return;
1865
[email protected]ca948a22009-06-25 19:36:171866 const WebHistoryItem& item =
[email protected]26aa0482009-09-30 16:55:271867 webview()->mainFrame()->previousHistoryItem();
[email protected]ca948a22009-06-25 19:36:171868 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:291869 return;
[email protected]ca948a22009-06-25 19:36:171870
1871 Send(new ViewHostMsg_UpdateState(
1872 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:291873}
1874
[email protected]3d9689372009-09-10 04:29:171875void RenderView::OpenURL(
1876 const GURL& url, const GURL& referrer, WebNavigationPolicy policy) {
1877 Send(new ViewHostMsg_OpenURL(
1878 routing_id_, url, referrer, NavigationPolicyToDisposition(policy)));
1879}
1880
[email protected]79dbc662009-09-04 05:42:511881// WebViewDelegate ------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291882
initial.commit09911bf2008-07-26 23:55:291883void RenderView::LoadNavigationErrorPage(WebFrame* frame,
[email protected]726985e22009-06-18 21:09:281884 const WebURLRequest& failed_request,
1885 const WebURLError& error,
initial.commit09911bf2008-07-26 23:55:291886 const std::string& html,
1887 bool replace) {
[email protected]726985e22009-06-18 21:09:281888 GURL failed_url = error.unreachableURL;
initial.commit09911bf2008-07-26 23:55:291889 std::string alt_html;
[email protected]07b493512010-08-27 15:39:291890 ExtensionRendererInfo* extension = NULL;
initial.commit09911bf2008-07-26 23:55:291891 if (html.empty()) {
1892 // Use a local error page.
1893 int resource_id;
1894 DictionaryValue error_strings;
[email protected]5351dbc2010-08-27 15:22:111895
[email protected]81654282010-10-04 17:08:061896 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
[email protected]5351dbc2010-08-27 15:22:111897 extension = ExtensionRendererInfo::GetByURL(failed_url);
1898 if (extension) {
[email protected]3f853a52010-09-13 19:15:081899 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1900 &error_strings);
[email protected]5351dbc2010-08-27 15:22:111901
1902 // TODO(erikkay): Should we use a different template for different
1903 // error messages?
1904 resource_id = IDR_ERROR_APP_HTML;
initial.commit09911bf2008-07-26 23:55:291905 } else {
[email protected]3f853a52010-09-13 19:15:081906 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1907 error.reason == net::ERR_CACHE_MISS &&
[email protected]5351dbc2010-08-27 15:22:111908 EqualsASCII(failed_request.httpMethod(), "POST")) {
[email protected]3f853a52010-09-13 19:15:081909 LocalizedError::GetFormRepostStrings(failed_url, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111910 } else {
[email protected]3f853a52010-09-13 19:15:081911 LocalizedError::GetStrings(error, &error_strings);
[email protected]5351dbc2010-08-27 15:22:111912 }
[email protected]75891fe2010-11-20 15:55:181913 resource_id = IDR_NET_ERROR_HTML;
initial.commit09911bf2008-07-26 23:55:291914 }
initial.commit09911bf2008-07-26 23:55:291915
1916 alt_html = GetAltHTMLForTemplate(error_strings, resource_id);
1917 } else {
1918 alt_html = html;
1919 }
1920
[email protected]dd7daa82009-08-10 05:46:451921 frame->loadHTMLString(alt_html,
[email protected]144143c2010-10-28 08:17:361922 GURL(chrome::kUnreachableWebDataURL),
[email protected]e6f546c32009-07-01 17:12:551923 failed_url,
1924 replace);
initial.commit09911bf2008-07-26 23:55:291925}
1926
[email protected]7ccddb8c2009-08-04 17:36:551927void RenderView::BindDOMAutomationController(WebFrame* frame) {
[email protected]2f979172010-09-16 21:54:031928 if (!dom_automation_controller_.get()) {
1929 dom_automation_controller_.reset(new DomAutomationController());
1930 }
1931 dom_automation_controller_->set_message_sender(this);
1932 dom_automation_controller_->set_routing_id(routing_id_);
1933 dom_automation_controller_->BindToJavascript(frame,
[email protected]906690b2010-12-03 18:11:251934 "domAutomationController");
initial.commit09911bf2008-07-26 23:55:291935}
1936
initial.commit09911bf2008-07-26 23:55:291937bool RenderView::RunJavaScriptMessage(int type,
1938 const std::wstring& message,
1939 const std::wstring& default_value,
[email protected]a455d3812009-03-05 20:18:071940 const GURL& frame_url,
initial.commit09911bf2008-07-26 23:55:291941 std::wstring* result) {
1942 bool success = false;
1943 std::wstring result_temp;
1944 if (!result)
1945 result = &result_temp;
initial.commit09911bf2008-07-26 23:55:291946
[email protected]12636df2009-09-28 22:32:211947 SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage(
1948 routing_id_, message, default_value, frame_url, type, &success, result));
initial.commit09911bf2008-07-26 23:55:291949 return success;
1950}
1951
[email protected]c1f50aa2010-02-18 03:46:571952bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) {
1953 // Before WebKit asks us to show an alert (etc.), it takes care of doing the
1954 // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog
1955 // it is particularly important that we do not call willEnterModalLoop as
1956 // that would defer resource loads for the dialog itself.
1957 if (RenderThread::current()) // Will be NULL during unit tests.
1958 RenderThread::current()->DoNotNotifyWebKitOfModalLoop();
1959
1960 message->EnableMessagePumping(); // Runs a nested message loop.
1961 return Send(message);
1962}
1963
[email protected]2de7e002010-10-11 22:58:201964void RenderView::AddGURLSearchProvider(
1965 const GURL& osd_url,
1966 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
initial.commit09911bf2008-07-26 23:55:291967 if (!osd_url.is_empty())
1968 Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url,
[email protected]2de7e002010-10-11 22:58:201969 provider_type));
initial.commit09911bf2008-07-26 23:55:291970}
1971
[email protected]e8345242010-05-06 03:00:401972void RenderView::OnAllowScriptToClose(bool script_can_close) {
1973 script_can_close_ = script_can_close;
[email protected]634a6f92008-12-01 21:39:311974}
1975
initial.commit09911bf2008-07-26 23:55:291976uint32 RenderView::GetCPBrowsingContext() {
1977 uint32 context = 0;
1978 Send(new ViewHostMsg_GetCPBrowsingContext(&context));
1979 return context;
1980}
1981
[email protected]2de7e002010-10-11 22:58:201982void RenderView::AddSearchProvider(
1983 const std::string& url,
1984 const ViewHostMsg_PageHasOSDD_Type& provider_type) {
1985 if (provider_type.type ==
1986 ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER &&
1987 !webview()->mainFrame()->isProcessingUserGesture())
1988 return;
1989
1990 AddGURLSearchProvider(GURL(url), provider_type);
initial.commit09911bf2008-07-26 23:55:291991}
1992
[email protected]155f35e2010-07-17 00:30:181993ViewHostMsg_GetSearchProviderInstallState_Params
[email protected]52ded452010-08-23 22:01:251994RenderView::GetSearchProviderInstallState(WebFrame* frame,
1995 const std::string& url) {
[email protected]155f35e2010-07-17 00:30:181996 GURL inquiry_url = GURL(url);
1997 if (inquiry_url.is_empty())
1998 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
[email protected]52ded452010-08-23 22:01:251999
[email protected]155f35e2010-07-17 00:30:182000 ViewHostMsg_GetSearchProviderInstallState_Params install;
2001 Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
[email protected]52ded452010-08-23 22:01:252002 frame->url(),
[email protected]155f35e2010-07-17 00:30:182003 inquiry_url,
2004 &install));
2005 return install;
2006}
2007
[email protected]f103ab72009-09-02 17:10:592008void RenderView::OnMissingPluginStatus(
2009 WebPluginDelegateProxy* delegate,
2010 int status) {
[email protected]6c8afae52009-01-22 02:24:572011#if defined(OS_WIN)
[email protected]f103ab72009-09-02 17:10:592012 if (!first_default_plugin_) {
initial.commit09911bf2008-07-26 23:55:292013 // Show the InfoBar for the first available plugin.
[email protected]191eb3f72010-12-21 06:27:502014 if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) {
[email protected]f103ab72009-09-02 17:10:592015 first_default_plugin_ = delegate->AsWeakPtr();
initial.commit09911bf2008-07-26 23:55:292016 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2017 }
2018 } else {
2019 // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar)
2020 // to start the download/install.
[email protected]191eb3f72010-12-21 06:27:502021 if (status ==
2022 webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) {
initial.commit09911bf2008-07-26 23:55:292023 Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status));
2024 }
2025 }
[email protected]6c8afae52009-01-22 02:24:572026#else
[email protected]76c3b312010-05-20 21:38:292027 // TODO(port): Implement the infobar that accompanies the default plugin.
2028 // Linux: http://crbug.com/10952
2029 // Mac: http://crbug.com/17392
[email protected]6c8afae52009-01-22 02:24:572030 NOTIMPLEMENTED();
2031#endif
initial.commit09911bf2008-07-26 23:55:292032}
2033
[email protected]48c9cf2d2009-09-16 16:47:522034// WebKit::WebViewClient ------------------------------------------------------
2035
[email protected]844acf372011-01-14 10:49:272036WebView* RenderView::createView(
2037 WebFrame* creator,
2038 const WebURLRequest& request,
2039 const WebWindowFeatures& features,
2040 const WebString& frame_name) {
[email protected]48c9cf2d2009-09-16 16:47:522041 // Check to make sure we aren't overloading on popups.
2042 if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
2043 return NULL;
2044
2045 // This window can't be closed from a window.close() call until we receive a
2046 // message from the Browser process explicitly allowing it.
[email protected]e8345242010-05-06 03:00:402047 script_can_close_ = false;
[email protected]48c9cf2d2009-09-16 16:47:522048
[email protected]8ab04652010-06-12 02:47:262049 ViewHostMsg_CreateWindow_Params params;
2050 params.opener_id = routing_id_;
2051 params.user_gesture = creator->isProcessingUserGesture();
2052 params.window_container_type = WindowFeaturesToContainerType(features);
2053 params.session_storage_namespace_id = session_storage_namespace_id_;
2054 params.frame_name = frame_name;
[email protected]41e65502011-01-21 09:29:112055 params.opener_frame_id = creator->identifier();
2056 params.opener_url = creator->url();
2057 params.opener_security_origin = creator->securityOrigin().toString().utf8();
2058 if (!request.isNull())
2059 params.target_url = request.url();
[email protected]8ab04652010-06-12 02:47:262060
[email protected]48c9cf2d2009-09-16 16:47:522061 int32 routing_id = MSG_ROUTING_NONE;
[email protected]4e6419c2010-01-15 04:50:342062 int64 cloned_session_storage_namespace_id;
[email protected]8ab04652010-06-12 02:47:262063 bool opener_suppressed = creator->willSuppressOpenerInNewFrame();
[email protected]48c9cf2d2009-09-16 16:47:522064
[email protected]48c9cf2d2009-09-16 16:47:522065 render_thread_->Send(
[email protected]8ab04652010-06-12 02:47:262066 new ViewHostMsg_CreateWindow(params,
2067 &routing_id,
2068 &cloned_session_storage_namespace_id));
[email protected]12636df2009-09-28 22:32:212069 if (routing_id == MSG_ROUTING_NONE)
[email protected]48c9cf2d2009-09-16 16:47:522070 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522071
[email protected]48c9cf2d2009-09-16 16:47:522072 RenderView* view = RenderView::Create(render_thread_,
[email protected]659f73fa2009-10-13 13:43:422073 0,
[email protected]12636df2009-09-28 22:32:212074 routing_id_,
[email protected]48c9cf2d2009-09-16 16:47:522075 renderer_preferences_,
2076 webkit_preferences_,
[email protected]12636df2009-09-28 22:32:212077 shared_popup_counter_,
[email protected]4e6419c2010-01-15 04:50:342078 routing_id,
[email protected]8ab04652010-06-12 02:47:262079 cloned_session_storage_namespace_id,
2080 frame_name);
2081 view->opened_by_user_gesture_ = params.user_gesture;
[email protected]48c9cf2d2009-09-16 16:47:522082
[email protected]007a848b2009-10-26 15:55:462083 // Record whether the creator frame is trying to suppress the opener field.
2084 view->opener_suppressed_ = opener_suppressed;
2085
[email protected]48c9cf2d2009-09-16 16:47:522086 // Record the security origin of the creator.
[email protected]91733b62009-09-18 06:21:092087 GURL creator_url(creator->securityOrigin().toString().utf8());
[email protected]48c9cf2d2009-09-16 16:47:522088 if (!creator_url.is_valid() || !creator_url.IsStandard())
2089 creator_url = GURL();
2090 view->creator_url_ = creator_url;
2091
2092 // Copy over the alternate error page URL so we can have alt error pages in
2093 // the new render view (we don't need the browser to send the URL back down).
2094 view->alternate_error_page_url_ = alternate_error_page_url_;
2095
2096 return view->webview();
2097}
2098
[email protected]3e2b375b2010-04-07 17:03:122099WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) {
[email protected]48c9cf2d2009-09-16 16:47:522100 RenderWidget* widget = RenderWidget::Create(routing_id_,
2101 render_thread_,
[email protected]3e2b375b2010-04-07 17:03:122102 popup_type);
[email protected]48c9cf2d2009-09-16 16:47:522103 return widget->webwidget();
2104}
2105
2106WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) {
[email protected]8de12d942010-11-17 20:42:442107 // TODO(jcivelli): Remove this deprecated method when its been removed from
2108 // the WebViewClient interface. It's been replaced by
2109 // createExternalPopupMenu.
2110 NOTREACHED();
2111 return NULL;
[email protected]48c9cf2d2009-09-16 16:47:522112}
2113
[email protected]caf706f2010-10-26 17:54:082114WebExternalPopupMenu* RenderView::createExternalPopupMenu(
2115 const WebPopupMenuInfo& popup_menu_info,
2116 WebExternalPopupMenuClient* popup_menu_client) {
2117 DCHECK(!external_popup_menu_.get());
2118 external_popup_menu_.reset(
2119 new ExternalPopupMenu(this, popup_menu_info, popup_menu_client));
2120 return external_popup_menu_.get();
2121}
2122
[email protected]484955942010-08-19 16:13:182123WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) {
2124 RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_,
2125 render_thread_,
2126 popup_type);
2127 return widget->webwidget();
2128}
2129
[email protected]0bd753682010-12-16 18:15:522130webkit::ppapi::FullscreenContainer*
2131RenderView::CreatePepperFullscreenContainer(
2132 webkit::ppapi::PluginInstance* plugin) {
[email protected]79c7bed2010-09-14 22:28:392133 RenderWidgetFullscreenPepper* widget =
2134 RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin);
2135 widget->show(WebKit::WebNavigationPolicyIgnore);
[email protected]92abcb832011-01-06 20:39:562136 return widget;
[email protected]79c7bed2010-09-14 22:28:392137}
2138
[email protected]68c50e52010-05-12 11:14:392139WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) {
[email protected]bd92c3a2010-01-13 05:02:342140 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess))
[email protected]68c50e52010-05-12 11:14:392141 return WebStorageNamespace::createSessionStorageNamespace(quota);
[email protected]59afea12010-01-20 04:48:292142 CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId);
2143 return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION,
2144 session_storage_namespace_id_);
[email protected]bd92c3a2010-01-13 05:02:342145}
2146
[email protected]48c9cf2d2009-09-16 16:47:522147void RenderView::didAddMessageToConsole(
2148 const WebConsoleMessage& message, const WebString& source_name,
2149 unsigned source_line) {
2150 Send(new ViewHostMsg_AddMessageToConsole(routing_id_,
2151 UTF16ToWideHack(message.text),
2152 static_cast<int32>(source_line),
2153 UTF16ToWideHack(source_name)));
2154}
2155
2156void RenderView::printPage(WebFrame* frame) {
[email protected]71a14262009-09-22 20:02:582157 DCHECK(frame);
[email protected]212a49d2010-10-25 18:23:472158 if (CommandLine::ForCurrentProcess()->HasSwitch(
2159 switches::kEnablePrintPreview)) {
2160 Print(frame, true, true);
2161 } else {
2162 Print(frame, true, false);
2163 }
[email protected]48c9cf2d2009-09-16 16:47:522164}
2165
[email protected]3354d3e2010-06-10 19:53:022166WebKit::WebNotificationPresenter* RenderView::notificationPresenter() {
[email protected]676126f72011-01-15 00:03:512167 return notification_provider_;
[email protected]3354d3e2010-06-10 19:53:022168}
2169
[email protected]48c9cf2d2009-09-16 16:47:522170void RenderView::didStartLoading() {
2171 if (is_loading_) {
2172 DLOG(WARNING) << "didStartLoading called while loading";
2173 return;
2174 }
2175
2176 is_loading_ = true;
2177 // Clear the pointer so that we can assign it only when there is an unknown
2178 // plugin on a page.
2179 first_default_plugin_.reset();
2180
2181 Send(new ViewHostMsg_DidStartLoading(routing_id_));
2182}
2183
2184void RenderView::didStopLoading() {
2185 if (!is_loading_) {
2186 DLOG(WARNING) << "DidStopLoading called while not loading";
2187 return;
2188 }
2189
2190 is_loading_ = false;
2191
2192 // NOTE: For now we're doing the safest thing, and sending out notification
2193 // when done loading. This currently isn't an issue as the favicon is only
2194 // displayed when done loading. Ideally we would send notification when
2195 // finished parsing the head, but webkit doesn't support that yet.
2196 // The feed discovery code would also benefit from access to the head.
[email protected]26aa0482009-09-30 16:55:272197 GURL favicon_url(webview()->mainFrame()->favIconURL());
[email protected]48c9cf2d2009-09-16 16:47:522198 if (!favicon_url.is_empty())
2199 Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url));
2200
[email protected]26aa0482009-09-30 16:55:272201 AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(),
[email protected]2de7e002010-10-11 22:58:202202 ViewHostMsg_PageHasOSDD_Type::Autodetected());
[email protected]48c9cf2d2009-09-16 16:47:522203
2204 Send(new ViewHostMsg_DidStopLoading(routing_id_));
2205
[email protected]90109412010-12-15 17:14:242206 if (load_progress_tracker_ != NULL)
2207 load_progress_tracker_->DidStopLoading();
2208
[email protected]f9f4841b2010-03-20 05:41:422209 MessageLoop::current()->PostDelayedTask(
2210 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:302211 page_info_method_factory_.NewRunnableMethod(
2212 &RenderView::CapturePageInfo, page_id_, false),
[email protected]5ddfd63e2010-09-01 15:48:372213 send_content_state_immediately_ ? 0 : kDelayForCaptureMs);
[email protected]48c9cf2d2009-09-16 16:47:522214}
2215
[email protected]90109412010-12-15 17:14:242216void RenderView::didChangeLoadProgress(WebFrame* frame, double load_progress) {
2217 if (load_progress_tracker_ != NULL)
2218 load_progress_tracker_->DidChangeLoadProgress(frame, load_progress);
2219}
2220
[email protected]f55039a2010-02-17 14:12:062221bool RenderView::isSmartInsertDeleteEnabled() {
2222#if defined(OS_MACOSX)
2223 return true;
2224#else
2225 return false;
2226#endif
2227}
2228
[email protected]04fc9482009-09-18 22:13:032229bool RenderView::isSelectTrailingWhitespaceEnabled() {
2230#if defined(OS_WIN)
2231 return true;
2232#else
2233 return false;
2234#endif
2235}
2236
[email protected]04fc9482009-09-18 22:13:032237void RenderView::didChangeSelection(bool is_empty_selection) {
[email protected]0ff0ff32010-12-21 19:34:422238#if defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032239 if (!handling_input_event_)
2240 return;
2241 // TODO(estade): investigate incremental updates to the selection so that we
2242 // don't send the entire selection over IPC every time.
2243 if (!is_empty_selection) {
2244 // Sometimes we get repeated didChangeSelection calls from webkit when
2245 // the selection hasn't actually changed. We don't want to report these
2246 // because it will cause us to continually claim the X clipboard.
2247 const std::string& this_selection =
[email protected]26aa0482009-09-30 16:55:272248 webview()->focusedFrame()->selectionAsText().utf8();
[email protected]04fc9482009-09-18 22:13:032249 if (this_selection == last_selection_)
2250 return;
2251
2252 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2253 this_selection));
2254 last_selection_ = this_selection;
2255 } else {
2256 last_selection_.clear();
[email protected]eef99c22010-08-17 05:55:162257 Send(new ViewHostMsg_SelectionChanged(routing_id_,
2258 last_selection_));
[email protected]04fc9482009-09-18 22:13:032259 }
[email protected]0ff0ff32010-12-21 19:34:422260#endif // defined(OS_POSIX)
[email protected]04fc9482009-09-18 22:13:032261}
2262
2263void RenderView::didExecuteCommand(const WebString& command_name) {
[email protected]afe3a1672009-11-17 19:04:122264 const std::string& name = UTF16ToUTF8(command_name);
2265 if (StartsWithASCII(name, "Move", true) ||
2266 StartsWithASCII(name, "Insert", true) ||
2267 StartsWithASCII(name, "Delete", true))
[email protected]04fc9482009-09-18 22:13:032268 return;
2269 UserMetricsRecordAction(name);
2270}
2271
[email protected]54ec7f82010-10-21 22:32:512272void RenderView::SendPendingAccessibilityNotifications() {
2273 if (!accessibility_.get())
2274 return;
2275
2276 if (pending_accessibility_notifications_.empty())
2277 return;
2278
2279 // Send all pending accessibility notifications.
2280 std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications;
2281 for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) {
2282 RendererAccessibilityNotification& notification =
2283 pending_accessibility_notifications_[i];
2284 WebAccessibilityObject obj = accessibility_->getObjectById(notification.id);
2285 if (!obj.isValid())
2286 continue;
2287
2288 ViewHostMsg_AccessibilityNotification_Params param;
2289 param.notification_type = pending_accessibility_notifications_[i].type;
[email protected]70eee342010-11-05 01:59:372290 param.acc_obj = WebAccessibility(
2291 obj, accessibility_.get(), notification.ShouldIncludeChildren());
[email protected]54ec7f82010-10-21 22:32:512292 notifications.push_back(param);
2293 }
2294 pending_accessibility_notifications_.clear();
2295 Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications));
2296 accessibility_ack_pending_ = true;
2297}
2298
[email protected]b2528b72009-09-24 06:57:102299bool RenderView::handleCurrentKeyboardEvent() {
2300 if (edit_commands_.empty())
2301 return false;
2302
[email protected]26aa0482009-09-30 16:55:272303 WebFrame* frame = webview()->focusedFrame();
[email protected]b2528b72009-09-24 06:57:102304 if (!frame)
2305 return false;
2306
2307 EditCommands::iterator it = edit_commands_.begin();
2308 EditCommands::iterator end = edit_commands_.end();
2309
[email protected]507b33ea2009-09-29 03:56:512310 bool did_execute_command = false;
[email protected]b2528b72009-09-24 06:57:102311 for (; it != end; ++it) {
[email protected]e6e15012009-09-30 14:59:332312 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2313 // key (but it's the exception). Once one edit command is not executed, it
2314 // seems safest to not execute the rest.
[email protected]b2528b72009-09-24 06:57:102315 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2316 WebString::fromUTF8(it->value)))
2317 break;
[email protected]507b33ea2009-09-29 03:56:512318 did_execute_command = true;
[email protected]b2528b72009-09-24 06:57:102319 }
2320
[email protected]507b33ea2009-09-29 03:56:512321 return did_execute_command;
[email protected]b2528b72009-09-24 06:57:102322}
2323
[email protected]2a3a7762009-10-19 19:17:322324void RenderView::spellCheck(const WebString& text,
2325 int& misspelled_offset,
2326 int& misspelled_length) {
[email protected]1dbafaf72009-09-23 19:43:562327 EnsureDocumentTag();
[email protected]85c55dc2009-11-06 03:05:462328
[email protected]85c55dc2009-11-06 03:05:462329 string16 word(text);
[email protected]cb6037d2009-11-16 22:55:172330 RenderThread* thread = RenderThread::current();
2331 // Will be NULL during unit tests.
2332 if (thread) {
[email protected]c27324b2009-11-19 22:44:292333 thread->spellchecker()->SpellCheckWord(
[email protected]cb6037d2009-11-16 22:55:172334 word.c_str(), word.size(), document_tag_,
2335 &misspelled_offset, &misspelled_length, NULL);
2336 }
[email protected]1dbafaf72009-09-23 19:43:562337}
2338
2339WebString RenderView::autoCorrectWord(const WebKit::WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322340 string16 autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562341 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]b86c8c12009-10-05 22:01:262342 if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) {
[email protected]1dbafaf72009-09-23 19:43:562343 EnsureDocumentTag();
[email protected]cb6037d2009-11-16 22:55:172344 RenderThread* thread = RenderThread::current();
2345 // Will be NULL during unit tests.
2346 if (thread) {
2347 autocorrect_word =
[email protected]c27324b2009-11-19 22:44:292348 thread->spellchecker()->GetAutoCorrectionWord(
[email protected]cb6037d2009-11-16 22:55:172349 word, document_tag_);
2350 }
[email protected]1dbafaf72009-09-23 19:43:562351 }
[email protected]2a3a7762009-10-19 19:17:322352 return autocorrect_word;
[email protected]1dbafaf72009-09-23 19:43:562353}
2354
[email protected]c49085c72009-10-02 16:28:562355void RenderView::showSpellingUI(bool show) {
2356 Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show));
2357}
2358
[email protected]8922e1f2009-10-03 05:01:262359bool RenderView::isShowingSpellingUI() {
2360 return spelling_panel_visible_;
2361}
2362
[email protected]1dbafaf72009-09-23 19:43:562363void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) {
[email protected]2a3a7762009-10-19 19:17:322364 Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_,
2365 word));
[email protected]1dbafaf72009-09-23 19:43:562366}
2367
[email protected]a1128322009-10-06 18:38:462368bool RenderView::runFileChooser(
[email protected]01178b52010-01-15 06:59:352369 const WebKit::WebFileChooserParams& params,
[email protected]cdaf8d02010-03-30 19:52:472370 WebFileChooserCompletion* chooser_completion) {
[email protected]7ef03e02010-10-23 11:58:352371 // Do not open the file dialog in a hidden RenderView.
2372 if (is_hidden())
2373 return false;
[email protected]cdaf8d02010-03-30 19:52:472374 ViewHostMsg_RunFileChooser_Params ipc_params;
[email protected]b5977a0c2010-08-24 19:46:262375 if (params.directory)
2376 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder;
2377 else if (params.multiSelect)
2378 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple;
2379 else
2380 ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open;
[email protected]cdaf8d02010-03-30 19:52:472381 ipc_params.title = params.title;
2382 ipc_params.default_file_name =
2383 webkit_glue::WebStringToFilePath(params.initialValue);
[email protected]099949132010-09-08 20:24:592384 ipc_params.accept_types = params.acceptTypes;
[email protected]cdaf8d02010-03-30 19:52:472385
2386 return ScheduleFileChooser(ipc_params, chooser_completion);
[email protected]a1128322009-10-06 18:38:462387}
2388
[email protected]48c9cf2d2009-09-16 16:47:522389void RenderView::runModalAlertDialog(
2390 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062391 RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptAlert,
[email protected]48c9cf2d2009-09-16 16:47:522392 UTF16ToWideHack(message),
2393 std::wstring(),
2394 frame->url(),
2395 NULL);
2396}
2397
2398bool RenderView::runModalConfirmDialog(
2399 WebFrame* frame, const WebString& message) {
[email protected]9dd7e3d72011-01-20 18:27:062400 return RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptConfirm,
[email protected]48c9cf2d2009-09-16 16:47:522401 UTF16ToWideHack(message),
2402 std::wstring(),
2403 frame->url(),
2404 NULL);
2405}
2406
2407bool RenderView::runModalPromptDialog(
2408 WebFrame* frame, const WebString& message, const WebString& default_value,
2409 WebString* actual_value) {
2410 std::wstring result;
[email protected]9dd7e3d72011-01-20 18:27:062411 bool ok = RunJavaScriptMessage(ui::MessageBoxFlags::kIsJavascriptPrompt,
[email protected]48c9cf2d2009-09-16 16:47:522412 UTF16ToWideHack(message),
2413 UTF16ToWideHack(default_value),
2414 frame->url(),
2415 &result);
2416 if (ok)
2417 actual_value->assign(WideToUTF16Hack(result));
2418 return ok;
2419}
2420
2421bool RenderView::runModalBeforeUnloadDialog(
2422 WebFrame* frame, const WebString& message) {
2423 bool success = false;
2424 // This is an ignored return value, but is included so we can accept the same
2425 // response as RunJavaScriptMessage.
2426 std::wstring ignored_result;
[email protected]12636df2009-09-28 22:32:212427 SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm(
[email protected]48c9cf2d2009-09-16 16:47:522428 routing_id_, frame->url(), UTF16ToWideHack(message), &success,
[email protected]12636df2009-09-28 22:32:212429 &ignored_result));
[email protected]48c9cf2d2009-09-16 16:47:522430 return success;
2431}
2432
[email protected]79e37442009-10-09 18:17:442433void RenderView::showContextMenu(
2434 WebFrame* frame, const WebContextMenuData& data) {
[email protected]c27324b2009-11-19 22:44:292435 ContextMenuParams params = ContextMenuParams(data);
2436 if (!params.misspelled_word.empty() && RenderThread::current()) {
2437 int misspelled_offset, misspelled_length;
[email protected]c76a36a2010-01-26 22:44:042438 bool spelled_right = RenderThread::current()->spellchecker()->
2439 SpellCheckWord(
2440 params.misspelled_word.c_str(), params.misspelled_word.size(),
2441 document_tag_,
2442 &misspelled_offset, &misspelled_length,
2443 &params.dictionary_suggestions);
2444 if (spelled_right)
[email protected]c27324b2009-11-19 22:44:292445 params.misspelled_word.clear();
2446 }
[email protected]216932c2010-08-26 21:44:272447 // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do
2448 // it. We replace it with an empty GURL so the appropriate items are disabled
2449 // in the context menu.
2450 // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large
2451 // data encoded images. We should have a way to save them.
2452 if (params.src_url.spec().size() > chrome::kMaxURLChars)
2453 params.src_url = GURL();
[email protected]521b2482011-01-15 00:10:102454 context_menu_node_ = data.node;
[email protected]c27324b2009-11-19 22:44:292455 Send(new ViewHostMsg_ContextMenu(routing_id_, params));
[email protected]79e37442009-10-09 18:17:442456}
2457
[email protected]52f139e2c2010-06-11 16:56:092458bool RenderView::supportsFullscreen() {
2459 return CommandLine::ForCurrentProcess()->HasSwitch(
2460 switches::kEnableVideoFullscreen);
2461}
2462
2463void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) {
2464 NOTIMPLEMENTED();
2465}
2466
2467void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) {
2468 NOTIMPLEMENTED();
2469}
2470
[email protected]48c9cf2d2009-09-16 16:47:522471void RenderView::setStatusText(const WebString& text) {
2472}
2473
[email protected]163f8242009-10-30 20:19:552474void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) {
[email protected]aa6b90b32010-04-26 15:49:582475 GURL latest_url = url.is_empty() ? fallback_url : url;
[email protected]48c9cf2d2009-09-16 16:47:522476 if (latest_url == target_url_)
2477 return;
[email protected]163f8242009-10-30 20:19:552478
[email protected]48c9cf2d2009-09-16 16:47:522479 // Tell the browser to display a destination link.
2480 if (target_url_status_ == TARGET_INFLIGHT ||
2481 target_url_status_ == TARGET_PENDING) {
2482 // If we have a request in-flight, save the URL to be sent when we
2483 // receive an ACK to the in-flight request. We can happily overwrite
2484 // any existing pending sends.
2485 pending_target_url_ = latest_url;
2486 target_url_status_ = TARGET_PENDING;
2487 } else {
2488 Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url));
2489 target_url_ = latest_url;
2490 target_url_status_ = TARGET_INFLIGHT;
2491 }
2492}
2493
[email protected]882daa92009-11-05 16:31:312494void RenderView::StartNavStateSyncTimerIfNecessary() {
2495 int delay;
2496 if (send_content_state_immediately_)
2497 delay = 0;
2498 else if (is_hidden())
2499 delay = kDelaySecondsForContentStateSyncHidden;
2500 else
2501 delay = kDelaySecondsForContentStateSync;
2502
2503 if (nav_state_sync_timer_.IsRunning()) {
2504 // The timer is already running. If the delay of the timer maches the amount
2505 // we want to delay by, then return. Otherwise stop the timer so that it
2506 // gets started with the right delay.
2507 if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay)
2508 return;
2509 nav_state_sync_timer_.Stop();
2510 }
2511
2512 nav_state_sync_timer_.Start(
2513 TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState);
2514}
2515
[email protected]163f8242009-10-30 20:19:552516void RenderView::setMouseOverURL(const WebURL& url) {
2517 mouse_over_url_ = GURL(url);
2518 UpdateTargetURL(mouse_over_url_, focus_url_);
2519}
2520
2521void RenderView::setKeyboardFocusURL(const WebURL& url) {
2522 focus_url_ = GURL(url);
2523 UpdateTargetURL(focus_url_, mouse_over_url_);
2524}
2525
[email protected]48c9cf2d2009-09-16 16:47:522526void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) {
2527 Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text),
2528 hint));
2529}
2530
[email protected]c27ae592010-03-18 15:24:412531void RenderView::startDragging(const WebDragData& data,
2532 WebDragOperationsMask mask,
2533 const WebImage& image,
2534 const WebPoint& imageOffset) {
2535#if WEBKIT_USING_SKIA
2536 SkBitmap bitmap(image.getSkBitmap());
2537#elif WEBKIT_USING_CG
[email protected]78043bdd2010-04-05 18:45:332538 SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef());
[email protected]c27ae592010-03-18 15:24:412539#endif
2540
[email protected]48c9cf2d2009-09-16 16:47:522541 Send(new ViewHostMsg_StartDragging(routing_id_,
2542 WebDropData(data),
[email protected]c27ae592010-03-18 15:24:412543 mask,
2544 bitmap,
2545 imageOffset));
[email protected]48c9cf2d2009-09-16 16:47:522546}
2547
[email protected]28b92df2009-09-25 17:35:452548bool RenderView::acceptsLoadDrops() {
2549 return renderer_preferences_.can_accept_load_drops;
2550}
2551
[email protected]48c9cf2d2009-09-16 16:47:522552void RenderView::focusNext() {
2553 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2554}
2555
2556void RenderView::focusPrevious() {
2557 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2558}
2559
[email protected]08e9e132010-06-01 16:58:492560void RenderView::focusedNodeChanged(const WebNode& node) {
[email protected]9b66f34bf2010-10-27 20:45:512561 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
[email protected]a4b103b2010-10-05 18:46:072562
2563 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2564 // TODO(ctguil): Make WebKit send this notification.
2565 // When focus is cleared notify accessibility that the document is focused.
2566 postAccessibilityNotification(
2567 webview()->accessibilityObject(),
2568 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2569 }
[email protected]08e9e132010-06-01 16:58:492570}
2571
[email protected]48c9cf2d2009-09-16 16:47:522572void RenderView::navigateBackForwardSoon(int offset) {
[email protected]48c9cf2d2009-09-16 16:47:522573 Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset));
2574}
2575
2576int RenderView::historyBackListCount() {
[email protected]3cc72b12010-03-18 23:03:002577 return history_list_offset_ < 0 ? 0 : history_list_offset_;
[email protected]48c9cf2d2009-09-16 16:47:522578}
2579
2580int RenderView::historyForwardListCount() {
[email protected]3cc72b12010-03-18 23:03:002581 return history_list_length_ - historyBackListCount() - 1;
[email protected]48c9cf2d2009-09-16 16:47:522582}
2583
[email protected]c4e98902010-06-01 10:20:142584void RenderView::didUpdateInspectorSetting(const WebString& key,
2585 const WebString& value) {
2586 Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_,
2587 key.utf8(),
2588 value.utf8()));
[email protected]8922e1f2009-10-03 05:01:262589}
2590
[email protected]79dbc662009-09-04 05:42:512591// WebKit::WebWidgetClient ----------------------------------------------------
2592
[email protected]ea42e7782010-08-23 23:58:122593void RenderView::didFocus() {
2594 // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed
2595 // we won't have to test for user gesture anymore and we can
2596 // move that code back to render_widget.cc
2597 if (webview() && webview()->mainFrame() &&
2598 webview()->mainFrame()->isProcessingUserGesture()) {
2599 Send(new ViewHostMsg_Focus(routing_id_));
2600 }
2601}
2602
2603void RenderView::didBlur() {
2604 // TODO(jcivelli): see TODO above in didFocus().
2605 if (webview() && webview()->mainFrame() &&
2606 webview()->mainFrame()->isProcessingUserGesture()) {
2607 Send(new ViewHostMsg_Blur(routing_id_));
2608 }
2609}
2610
initial.commit09911bf2008-07-26 23:55:292611// We are supposed to get a single call to Show for a newly created RenderView
2612// that was created via RenderView::CreateWebView. So, we wait until this
2613// point to dispatch the ShowView message.
2614//
2615// This method provides us with the information about how to display the newly
2616// created RenderView (i.e., as a constrained popup or as a new tab).
2617//
[email protected]4873c7d2009-07-16 06:36:282618void RenderView::show(WebNavigationPolicy policy) {
initial.commit09911bf2008-07-26 23:55:292619 DCHECK(!did_show_) << "received extraneous Show call";
2620 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2621
2622 if (did_show_)
2623 return;
2624 did_show_ = true;
2625
[email protected]4026ce1e2010-09-14 19:35:042626 // Extensions and apps always allowed to create unrequested popups. The second
2627 // check is necessary to include content scripts.
2628 if (ExtensionRendererInfo::GetByURL(creator_url_) ||
2629 bindings_utils::GetInfoForCurrentContext()) {
2630 opened_by_user_gesture_ = true;
2631 }
2632
[email protected]28295ec2009-10-16 05:34:332633 // Force new windows to a popup if they were not opened with a user gesture.
2634 if (!opened_by_user_gesture_) {
2635 // We exempt background tabs for compat with older versions of Chrome.
2636 // TODO(darin): This seems bogus. These should have a user gesture, so
2637 // we probably don't need this check.
2638 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
2639 policy = WebKit::WebNavigationPolicyNewPopup;
2640 }
2641
initial.commit09911bf2008-07-26 23:55:292642 // NOTE: initial_pos_ may still have its default values at this point, but
2643 // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the
2644 // browser process will impose a default position otherwise.
[email protected]4873c7d2009-07-16 06:36:282645 Send(new ViewHostMsg_ShowView(opener_id_, routing_id_,
2646 NavigationPolicyToDisposition(policy), initial_pos_,
[email protected]7e7414ae2010-01-26 20:19:292647 opened_by_user_gesture_));
[email protected]2533ce12009-05-09 00:02:242648 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:292649}
2650
[email protected]4873c7d2009-07-16 06:36:282651void RenderView::closeWidgetSoon() {
[email protected]7faa53862010-06-16 00:09:132652 // Cancel pending translations so that the translate_helper_ does not attempt
2653 // to access the WebView.
2654 translate_helper_.CancelPendingTranslation();
2655
[email protected]3ead1322010-11-19 20:01:002656 // Same for the phishing classifier.
2657 if (phishing_delegate_.get())
2658 phishing_delegate_->CancelPendingClassification();
2659
[email protected]e8345242010-05-06 03:00:402660 if (script_can_close_)
[email protected]4873c7d2009-07-16 06:36:282661 RenderWidget::closeWidgetSoon();
[email protected]634a6f92008-12-01 21:39:312662}
2663
[email protected]4873c7d2009-07-16 06:36:282664void RenderView::runModal() {
initial.commit09911bf2008-07-26 23:55:292665 DCHECK(did_show_) << "should already have shown the view";
2666
[email protected]c1f50aa2010-02-18 03:46:572667 // We must keep WebKit's shared timer running in this case in order to allow
2668 // showModalDialog to function properly.
2669 //
2670 // TODO(darin): WebKit should really be smarter about suppressing events and
2671 // timers so that we do not need to manage the shared timer in such a heavy
2672 // handed manner.
2673 //
2674 if (RenderThread::current()) // Will be NULL during unit tests.
2675 RenderThread::current()->DoNotSuspendWebKitSharedTimer();
2676
[email protected]12636df2009-09-28 22:32:212677 SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_));
initial.commit09911bf2008-07-26 23:55:292678}
2679
[email protected]3d9689372009-09-10 04:29:172680// WebKit::WebFrameClient -----------------------------------------------------
2681
[email protected]00152e92010-07-19 11:47:402682WebPlugin* RenderView::createPlugin(WebFrame* frame,
2683 const WebPluginParams& params) {
[email protected]6fdd4182010-10-14 23:59:262684 bool found = false;
[email protected]414508d2010-11-02 10:45:392685 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
[email protected]55126132010-08-19 14:53:282686 CommandLine* cmd = CommandLine::ForCurrentProcess();
[email protected]191eb3f72010-12-21 06:27:502687 webkit::npapi::WebPluginInfo info;
[email protected]7a13e792010-08-03 08:18:242688 GURL url(params.url);
[email protected]6fdd4182010-10-14 23:59:262689 std::string actual_mime_type;
[email protected]c8f73ab2011-01-22 00:05:172690 Send(new ViewHostMsg_GetPluginInfo(routing_id_,
2691 url,
[email protected]6fdd4182010-10-14 23:59:262692 frame->top()->url(),
2693 params.mimeType.utf8(),
2694 &found,
2695 &info,
[email protected]44fda5c2010-11-02 10:50:542696 &plugin_setting,
[email protected]6fdd4182010-10-14 23:59:262697 &actual_mime_type));
[email protected]7a13e792010-08-03 08:18:242698
[email protected]6fdd4182010-10-14 23:59:262699 if (!found)
[email protected]0cdafff2010-07-26 09:54:372700 return NULL;
[email protected]414508d2010-11-02 10:45:392701 DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
[email protected]4e0616e2010-05-28 14:55:532702
[email protected]191eb3f72010-12-21 06:27:502703 const webkit::npapi::PluginGroup* group =
2704 webkit::npapi::PluginList::Singleton()->GetPluginGroup(info);
[email protected]79ce1032010-12-07 13:29:412705 DCHECK(group != NULL);
[email protected]851b1eb2010-08-09 13:32:292706
[email protected]6e74a3b2010-12-21 22:27:542707 if (group->IsVulnerable() &&
2708 !cmd->HasSwitch(switches::kAllowOutdatedPlugins)) {
[email protected]3c2826852010-12-16 19:09:142709 Send(new ViewHostMsg_BlockedOutdatedPlugin(routing_id_,
2710 group->GetGroupName(),
2711 GURL(group->GetUpdateURL())));
2712 return CreatePluginPlaceholder(frame,
2713 params,
2714 *group,
[email protected]2e34ab3f2010-12-17 05:47:372715 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202716 IDS_PLUGIN_OUTDATED,
2717 false);
[email protected]851b1eb2010-08-09 13:32:292718 }
[email protected]6e74a3b2010-12-21 22:27:542719
[email protected]3c2826852010-12-16 19:09:142720 if (!info.enabled)
2721 return NULL;
[email protected]851b1eb2010-08-09 13:32:292722
[email protected]414508d2010-11-02 10:45:392723 ContentSetting host_setting =
2724 current_content_settings_.settings[CONTENT_SETTINGS_TYPE_PLUGINS];
[email protected]191eb3f72010-12-21 06:27:502725 if (info.path.value() == webkit::npapi::kDefaultPluginLibraryName ||
[email protected]414508d2010-11-02 10:45:392726 plugin_setting == CONTENT_SETTING_ALLOW ||
2727 host_setting == CONTENT_SETTING_ALLOW) {
[email protected]90dba072011-01-20 20:10:202728 // Delay loading plugins if prerendering.
2729 WebDataSource* ds = frame->dataSource();
2730 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
2731 if (navigation_state->is_prerendering()) {
2732 return CreatePluginPlaceholder(frame,
2733 params,
2734 *group,
2735 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
2736 IDS_PLUGIN_LOAD,
2737 true);
2738 }
2739
[email protected]0bd753682010-12-16 18:15:522740 scoped_refptr<webkit::ppapi::PluginModule> pepper_module(
[email protected]1a78d9f32010-12-08 06:38:452741 pepper_delegate_.CreatePepperPlugin(info.path));
2742 if (pepper_module)
2743 return CreatePepperPlugin(frame, params, info.path, pepper_module.get());
[email protected]6fdd4182010-10-14 23:59:262744 return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type);
[email protected]0cdafff2010-07-26 09:54:372745 }
[email protected]fc61e222010-10-11 15:42:142746 std::string resource;
2747 if (cmd->HasSwitch(switches::kEnableResourceContentSettings))
2748 resource = group->identifier();
2749 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource);
[email protected]414508d2010-11-02 10:45:392750 if (plugin_setting == CONTENT_SETTING_ASK) {
[email protected]3c2826852010-12-16 19:09:142751 return CreatePluginPlaceholder(frame,
2752 params,
2753 *group,
[email protected]2e34ab3f2010-12-17 05:47:372754 IDR_CLICK_TO_PLAY_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202755 IDS_PLUGIN_LOAD,
2756 false);
[email protected]fc61e222010-10-11 15:42:142757 } else {
[email protected]3c2826852010-12-16 19:09:142758 return CreatePluginPlaceholder(frame,
2759 params,
2760 *group,
[email protected]2e34ab3f2010-12-17 05:47:372761 IDR_BLOCKED_PLUGIN_HTML,
[email protected]90dba072011-01-20 20:10:202762 IDS_PLUGIN_BLOCKED,
2763 false);
[email protected]fc61e222010-10-11 15:42:142764 }
[email protected]3d9689372009-09-10 04:29:172765}
2766
2767WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) {
[email protected]14396e92010-05-06 20:40:562768 WebApplicationCacheHostImpl* appcache_host =
2769 WebApplicationCacheHostImpl::FromFrame(frame);
2770 int appcache_host_id = appcache_host ? appcache_host->host_id() : 0;
2771 return new WebWorkerProxy(client, RenderThread::current(), routing_id_,
2772 appcache_host_id);
[email protected]3d9689372009-09-10 04:29:172773}
2774
[email protected]9c00f002009-11-05 22:37:422775WebSharedWorker* RenderView::createSharedWorker(
2776 WebFrame* frame, const WebURL& url, const WebString& name,
[email protected]30447b62009-11-13 01:13:372777 unsigned long long document_id) {
[email protected]9c00f002009-11-05 22:37:422778
[email protected]30447b62009-11-13 01:13:372779 int route_id = MSG_ROUTING_NONE;
[email protected]6de0bcf2010-02-17 22:00:512780 bool exists = false;
[email protected]30447b62009-11-13 01:13:372781 bool url_mismatch = false;
[email protected]6de0bcf2010-02-17 22:00:512782 ViewHostMsg_CreateWorker_Params params;
2783 params.url = url;
2784 params.is_shared = true;
2785 params.name = name;
2786 params.document_id = document_id;
2787 params.render_view_route_id = routing_id_;
2788 params.route_id = MSG_ROUTING_NONE;
[email protected]f9bc9c02010-05-24 19:19:232789 params.parent_appcache_host_id = 0;
2790 params.script_resource_appcache_id = 0;
[email protected]30447b62009-11-13 01:13:372791 Send(new ViewHostMsg_LookupSharedWorker(
[email protected]6de0bcf2010-02-17 22:00:512792 params, &exists, &route_id, &url_mismatch));
[email protected]30447b62009-11-13 01:13:372793 if (url_mismatch) {
2794 return NULL;
2795 } else {
2796 return new WebSharedWorkerProxy(RenderThread::current(),
[email protected]0791d3a2010-01-28 01:28:492797 document_id,
[email protected]6de0bcf2010-02-17 22:00:512798 exists,
[email protected]30447b62009-11-13 01:13:372799 route_id,
2800 routing_id_);
2801 }
[email protected]9c00f002009-11-05 22:37:422802}
2803
[email protected]3d9689372009-09-10 04:29:172804WebMediaPlayer* RenderView::createMediaPlayer(
2805 WebFrame* frame, WebMediaPlayerClient* client) {
[email protected]f78d1dfc2011-01-15 07:09:272806 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
2807 new media::MessageLoopFactoryImpl());
[email protected]f8db8132010-12-03 00:27:492808 scoped_ptr<media::FilterCollection> collection(
2809 new media::FilterCollection());
[email protected]457d8342010-10-23 01:20:372810
[email protected]3d9689372009-09-10 04:29:172811 // Add in any custom filter factories first.
2812 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
2813 if (!cmd_line->HasSwitch(switches::kDisableAudio)) {
2814 // Add the chrome specific audio renderer.
[email protected]b7ba5b52010-11-15 22:04:492815 collection->AddAudioRenderer(new AudioRendererImpl(audio_message_filter()));
[email protected]3d9689372009-09-10 04:29:172816 }
2817
[email protected]3bb08602010-10-07 21:47:172818 if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) &&
[email protected]11c4c812010-10-22 19:50:122819 !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) {
[email protected]5aa6a312010-11-06 00:00:072820 WebGraphicsContext3DCommandBufferImpl* context =
2821 static_cast<WebGraphicsContext3DCommandBufferImpl*>(
2822 frame->view()->graphicsContext3D());
2823 if (!context)
2824 return NULL;
[email protected]a9a43012010-11-05 01:54:062825
[email protected]5aa6a312010-11-06 00:00:072826 // Add the hardware video decoder factory.
2827 // TODO(hclam): This will cause the renderer process to crash on context
2828 // lost.
2829 bool ret = context->makeContextCurrent();
2830 CHECK(ret) << "Failed to switch context";
[email protected]b7ba5b52010-11-15 22:04:492831 collection->AddVideoDecoder(new IpcVideoDecoder(
[email protected]5aa6a312010-11-06 00:00:072832 MessageLoop::current(), context->context()));
[email protected]3bb08602010-10-07 21:47:172833 }
2834
[email protected]457d8342010-10-23 01:20:372835 scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer;
[email protected]77128dec2010-11-08 17:05:312836 bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging);
2837 scoped_refptr<webkit_glue::VideoRendererImpl> renderer(
2838 new webkit_glue::VideoRendererImpl(pts_logging));
[email protected]b7ba5b52010-11-15 22:04:492839 collection->AddVideoRenderer(renderer);
[email protected]77128dec2010-11-08 17:05:312840 video_renderer = renderer;
[email protected]8400e032010-02-26 18:50:112841
[email protected]a8e24d522010-12-01 07:13:582842 scoped_ptr<webkit_glue::WebMediaPlayerImpl> result(
[email protected]f78d1dfc2011-01-15 07:09:272843 new webkit_glue::WebMediaPlayerImpl(client,
2844 collection.release(),
2845 message_loop_factory.release()));
[email protected]79684282010-12-06 21:15:462846 if (!result->Initialize(frame,
[email protected]a8e24d522010-12-01 07:13:582847 cmd_line->HasSwitch(switches::kSimpleDataSource),
2848 video_renderer)) {
2849 return NULL;
2850 }
2851 return result.release();
[email protected]3d9689372009-09-10 04:29:172852}
2853
[email protected]035545f2010-04-09 13:10:212854WebApplicationCacheHost* RenderView::createApplicationCacheHost(
2855 WebFrame* frame, WebApplicationCacheHostClient* client) {
2856 return new RendererWebApplicationCacheHostImpl(
2857 FromWebView(frame->view()), client,
2858 RenderThread::current()->appcache_dispatcher()->backend_proxy());
2859}
2860
[email protected]8ff181072010-11-29 17:09:382861WebCookieJar* RenderView::cookieJar(WebFrame* frame) {
2862 return &cookie_jar_;
2863}
2864
[email protected]5041f982010-08-11 21:40:452865void RenderView::frameDetached(WebFrame* frame) {
[email protected]676126f72011-01-15 00:03:512866 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameDetached(frame));
[email protected]5041f982010-08-11 21:40:452867}
2868
[email protected]3d9689372009-09-10 04:29:172869void RenderView::willClose(WebFrame* frame) {
[email protected]fa7b6b542009-11-03 05:02:302870 WebDataSource* ds = frame->dataSource();
2871 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
[email protected]05c8e502010-08-15 15:13:522872
[email protected]a5a65ac2010-11-05 18:14:362873 page_load_histograms_.Dump(frame);
[email protected]fa7b6b542009-11-03 05:02:302874 navigation_state->user_script_idle_scheduler()->Cancel();
[email protected]f3ce0a32011-01-11 08:18:182875
[email protected]676126f72011-01-15 00:03:512876 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameWillClose(frame));
[email protected]3d9689372009-09-10 04:29:172877}
2878
[email protected]684e4a42010-01-30 06:44:112879bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:402880 if (enabled_per_settings &&
2881 AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES))
2882 return true;
2883
2884 if (IsWhitelistedForContentSettings(frame))
2885 return true;
2886
[email protected]55126132010-08-19 14:53:282887 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string());
[email protected]12bc8472010-04-15 07:29:402888 return false; // Other protocols fall through here.
[email protected]684e4a42010-01-30 06:44:112889}
2890
[email protected]d5f9e4f2010-07-28 08:31:302891bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) {
[email protected]3627b06d2010-11-12 16:36:162892 return WebFrameClient::allowPlugins(frame, enabled_per_settings);
[email protected]d5f9e4f2010-07-28 08:31:302893}
2894
2895
[email protected]3d9689372009-09-10 04:29:172896void RenderView::loadURLExternally(
2897 WebFrame* frame, const WebURLRequest& request,
2898 WebNavigationPolicy policy) {
[email protected]efce17b2009-09-11 18:04:592899 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2900 if (policy == WebKit::WebNavigationPolicyDownload) {
2901 Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer));
2902 } else {
2903 OpenURL(request.url(), referrer, policy);
2904 }
[email protected]3d9689372009-09-10 04:29:172905}
2906
2907WebNavigationPolicy RenderView::decidePolicyForNavigation(
2908 WebFrame* frame, const WebURLRequest& request, WebNavigationType type,
[email protected]65b95cd2009-10-09 05:10:222909 const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) {
[email protected]3d9689372009-09-10 04:29:172910 // Webkit is asking whether to navigate to a new URL.
2911 // This is fine normally, except if we're showing UI from one security
2912 // context and they're trying to navigate to a different context.
2913 const GURL& url = request.url();
2914
2915 // If the browser is interested, then give it a chance to look at top level
[email protected]3a8eecb2010-04-22 23:56:302916 // navigations.
[email protected]8079b362010-05-07 18:37:452917 if (renderer_preferences_.browser_handles_top_level_requests &&
2918 IsNonLocalTopLevelNavigation(url, frame, type)) {
[email protected]61c9f032010-03-31 23:04:192919 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]a58db8b2010-08-24 01:51:232920 // Reset these counters as the RenderView could be reused for the next
2921 // navigation.
2922 page_id_ = -1;
[email protected]a58db8b2010-08-24 01:51:232923 last_page_id_sent_to_browser_ = -1;
[email protected]61c9f032010-03-31 23:04:192924 OpenURL(url, referrer, default_policy);
2925 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
[email protected]3d9689372009-09-10 04:29:172926 }
2927
2928 // A content initiated navigation may have originated from a link-click,
2929 // script, drag-n-drop operation, etc.
2930 bool is_content_initiated =
2931 NavigationState::FromDataSource(frame->provisionalDataSource())->
2932 is_content_initiated();
[email protected]a6b960ad972010-09-01 19:53:582933 GURL old_url(frame->url());
[email protected]3d9689372009-09-10 04:29:172934
[email protected]6101c342010-12-16 22:44:372935 // Detect when we're crossing a permission-based boundary (e.g. into or out of
2936 // an extension or app origin, leaving a DOMUI page, etc). We only care about
2937 // top-level navigations withing the current tab (as opposed to, for example,
2938 // opening a new window). But we sometimes navigate to about:blank to clear a
2939 // tab, and we want to still allow that.
2940 //
2941 // Note: we do this only for GET requests because we our mechanism for
2942 // switching processes only issues GET requests. In particular, POST
2943 // requests don't work, because this mechanism does not preserve form POST
2944 // data. If it becomes necessary to support process switching for POST
2945 // requests, we will need to send the request's httpBody data up to the
2946 // browser process, and issue a special POST navigation in WebKit (via
2947 // FrameLoader::loadFrameRequest). See ResourceDispatcher and
2948 // WebURLLoaderImpl for examples of how to send the httpBody data.
2949 if (!frame->parent() && is_content_initiated &&
2950 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
2951 request.httpMethod() == "GET" && !url.SchemeIs(chrome::kAboutScheme)) {
2952 bool send_referrer = false;
2953 bool should_fork =
2954 BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) ||
[email protected]3d9689372009-09-10 04:29:172955 frame->isViewSourceModeEnabled() ||
[email protected]6101c342010-12-16 22:44:372956 url.SchemeIs(chrome::kViewSourceScheme);
[email protected]5351dbc2010-08-27 15:22:112957
2958 // If the navigation would cross an app extent boundary, we also need
2959 // to defer to the browser to ensure process isolation.
2960 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2961 // which means that things like the back button won't trigger it. Is that
2962 // OK?
[email protected]08e94b82010-12-15 22:51:042963 // TODO(creis): For now, we only swap processes to enter an app and not
2964 // exit it, since we currently lose context (e.g., window.opener) if the
2965 // window navigates back. See crbug.com/65953.
[email protected]6101c342010-12-16 22:44:372966 if (!should_fork && CrossesIntoExtensionExtent(frame, url)) {
[email protected]5351dbc2010-08-27 15:22:112967 // Include the referrer in this case since we're going from a hosted web
2968 // page. (the packaged case is handled previously by the extension
2969 // navigation test)
[email protected]6101c342010-12-16 22:44:372970 should_fork = true;
2971 send_referrer = true;
2972 }
2973
2974 if (should_fork) {
[email protected]5351dbc2010-08-27 15:22:112975 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
[email protected]6101c342010-12-16 22:44:372976 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
[email protected]5351dbc2010-08-27 15:22:112977 return WebKit::WebNavigationPolicyIgnore; // Suppress the load here.
2978 }
[email protected]3d9689372009-09-10 04:29:172979 }
2980
2981 // Detect when a page is "forking" a new tab that can be safely rendered in
2982 // its own process. This is done by sites like Gmail that try to open links
2983 // in new windows without script connections back to the original page. We
2984 // treat such cases as browser navigations (in which we will create a new
2985 // renderer for a cross-site navigation), rather than WebKit navigations.
2986 //
2987 // We use the following heuristic to decide whether to fork a new page in its
2988 // own process:
2989 // The parent page must open a new tab to about:blank, set the new tab's
2990 // window.opener to null, and then redirect the tab to a cross-site URL using
2991 // JavaScript.
[email protected]007a848b2009-10-26 15:55:462992 //
2993 // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer
2994 // (see below).
[email protected]3d9689372009-09-10 04:29:172995 bool is_fork =
2996 // Must start from a tab showing about:blank, which is later redirected.
[email protected]a6b960ad972010-09-01 19:53:582997 old_url == GURL(chrome::kAboutBlankURL) &&
[email protected]3d9689372009-09-10 04:29:172998 // Must be the first real navigation of the tab.
[email protected]48c9cf2d2009-09-16 16:47:522999 historyBackListCount() < 1 &&
3000 historyForwardListCount() < 1 &&
[email protected]3d9689372009-09-10 04:29:173001 // The parent page must have set the child's window.opener to null before
3002 // redirecting to the desired URL.
3003 frame->opener() == NULL &&
3004 // Must be a top-level frame.
3005 frame->parent() == NULL &&
3006 // Must not have issued the request from this page.
3007 is_content_initiated &&
3008 // Must be targeted at the current tab.
3009 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3010 // Must be a JavaScript navigation, which appears as "other".
3011 type == WebKit::WebNavigationTypeOther;
[email protected]007a848b2009-10-26 15:55:463012
3013 // Recognize if this navigation is from a link with rel=noreferrer and
3014 // target=_blank attributes, in which case the opener will be suppressed. If
3015 // so, it is safe to load cross-site pages in a separate process, so we
3016 // should let the browser handle it.
3017 bool is_noreferrer_and_blank_target =
3018 // Frame should be top level and not yet navigated.
3019 frame->parent() == NULL &&
3020 frame->url().isEmpty() &&
3021 historyBackListCount() < 1 &&
3022 historyForwardListCount() < 1 &&
3023 // Links with rel=noreferrer will have no Referer field, and their
3024 // resulting frame will have its window.opener suppressed.
3025 // TODO(creis): should add a request.httpReferrer() method to help avoid
3026 // typos on the unusual spelling of Referer.
3027 request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() &&
3028 opener_suppressed_ &&
3029 frame->opener() == NULL &&
3030 // Links with target=_blank will have no name.
3031 frame->name().isNull() &&
3032 // Another frame (with a non-empty creator) should have initiated the
3033 // request, targeted at this frame.
3034 !creator_url_.is_empty() &&
3035 is_content_initiated &&
3036 default_policy == WebKit::WebNavigationPolicyCurrentTab &&
3037 type == WebKit::WebNavigationTypeOther;
3038
3039 if (is_fork || is_noreferrer_and_blank_target) {
[email protected]3d9689372009-09-10 04:29:173040 // Open the URL via the browser, not via WebKit.
3041 OpenURL(url, GURL(), default_policy);
3042 return WebKit::WebNavigationPolicyIgnore;
3043 }
3044
3045 return default_policy;
3046}
3047
[email protected]6069da8c2009-10-20 20:33:493048bool RenderView::canHandleRequest(
3049 WebFrame* frame, const WebURLRequest& request) {
3050 // We allow WebKit to think that everything can be handled even though
3051 // browser-side we limit what we load.
[email protected]7b7a7dc2009-10-19 02:23:343052 return true;
3053}
3054
[email protected]6069da8c2009-10-20 20:33:493055WebURLError RenderView::cannotHandleRequestError(
3056 WebFrame* frame, const WebURLRequest& request) {
3057 NOTREACHED(); // Since we said we can handle all requests.
3058 return WebURLError();
3059}
3060
3061WebURLError RenderView::cancelledError(
3062 WebFrame* frame, const WebURLRequest& request) {
3063 WebURLError error;
3064 error.domain = WebString::fromUTF8(net::kErrorDomain);
3065 error.reason = net::ERR_ABORTED;
3066 error.unreachableURL = request.url();
3067 return error;
[email protected]7b7a7dc2009-10-19 02:23:343068}
3069
3070void RenderView::unableToImplementPolicyWithError(
[email protected]6069da8c2009-10-20 20:33:493071 WebFrame*, const WebURLError&) {
3072 NOTREACHED(); // Since we said we can handle all requests.
[email protected]7b7a7dc2009-10-19 02:23:343073}
3074
[email protected]90eeddb2010-05-06 21:06:433075void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame,
3076 const WebKit::WebFormElement& form) {
3077 // Some login forms have onSubmit handlers that put a hash of the password
3078 // into a hidden field and then clear the password. (Issue 28910.)
3079 // This method gets called before any of those handlers run, so save away
3080 // a copy of the password in case it gets lost.
3081 NavigationState* navigation_state =
3082 NavigationState::FromDataSource(frame->dataSource());
3083 navigation_state->set_password_form_data(
3084 PasswordFormDomManager::CreatePasswordForm(form));
3085}
3086
[email protected]979c28b2009-11-07 01:30:483087void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) {
[email protected]3d9689372009-09-10 04:29:173088 NavigationState* navigation_state =
3089 NavigationState::FromDataSource(frame->provisionalDataSource());
3090
3091 if (navigation_state->transition_type() == PageTransition::LINK)
3092 navigation_state->set_transition_type(PageTransition::FORM_SUBMIT);
3093
3094 // Save these to be processed when the ensuing navigation is committed.
[email protected]ce0e250d2009-10-23 21:00:353095 WebSearchableFormData web_searchable_form_data(form);
3096 navigation_state->set_searchable_form_url(web_searchable_form_data.url());
3097 navigation_state->set_searchable_form_encoding(
[email protected]b7910b3a2010-01-13 18:33:213098 web_searchable_form_data.encoding().utf8());
[email protected]90eeddb2010-05-06 21:06:433099 PasswordForm* password_form_data =
3100 PasswordFormDomManager::CreatePasswordForm(form);
3101 navigation_state->set_password_form_data(password_form_data);
3102
3103 // If the password has been cleared, recover it from the form contents already
3104 // stored by willSendSubmitEvent into the dataSource's NavigationState (as
3105 // opposed to the provisionalDataSource's, which is what we're storing into
3106 // now.)
3107 if (password_form_data && password_form_data->password_value.empty()) {
3108 NavigationState* old_navigation_state =
3109 NavigationState::FromDataSource(frame->dataSource());
3110 if (old_navigation_state) {
3111 PasswordForm* old_form_data = old_navigation_state->password_form_data();
3112 if (old_form_data && old_form_data->action == password_form_data->action)
3113 password_form_data->password_value = old_form_data->password_value;
3114 }
3115 }
[email protected]3d9689372009-09-10 04:29:173116
[email protected]b1438212010-04-03 00:30:593117 FormData form_data;
[email protected]b715f7f2010-04-05 22:01:043118 if (FormManager::WebFormElementToFormData(
[email protected]5af80432010-11-01 01:25:223119 form,
3120 FormManager::REQUIRE_AUTOCOMPLETE,
[email protected]18ecd002010-11-16 19:29:553121 static_cast<FormManager::ExtractMask>(FormManager::EXTRACT_VALUE |
3122 FormManager::EXTRACT_OPTION_TEXT),
[email protected]5af80432010-11-01 01:25:223123 &form_data)) {
[email protected]b1438212010-04-03 00:30:593124 Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data));
[email protected]5af80432010-11-01 01:25:223125 }
[email protected]3d9689372009-09-10 04:29:173126}
3127
3128void RenderView::willPerformClientRedirect(
3129 WebFrame* frame, const WebURL& from, const WebURL& to, double interval,
3130 double fire_time) {
3131 // Ignore
3132}
3133
3134void RenderView::didCancelClientRedirect(WebFrame* frame) {
3135 // Ignore
3136}
3137
3138void RenderView::didCompleteClientRedirect(
3139 WebFrame* frame, const WebURL& from) {
3140 if (!frame->parent())
3141 completed_client_redirect_src_ = from;
3142}
3143
3144void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) {
[email protected]bb461532010-11-26 21:50:233145 // If there are any app-related fetches in progress, they can be cancelled now
3146 // since we have navigated away from the page that created them.
3147 if (!frame->parent()) {
3148 app_icon_fetchers_.clear();
3149 app_definition_fetcher_.reset(NULL);
3150 }
3151
[email protected]3d9689372009-09-10 04:29:173152 // The rest of RenderView assumes that a WebDataSource will always have a
3153 // non-null NavigationState.
[email protected]a7ccc4d2010-01-27 08:14:483154 bool content_initiated = !pending_navigation_state_.get();
3155 NavigationState* state = content_initiated ?
3156 NavigationState::CreateContentInitiated() :
3157 pending_navigation_state_.release();
[email protected]8a3125a712010-08-09 18:58:513158
[email protected]8a3125a712010-08-09 18:58:513159 // NavigationState::referred_by_prefetcher_ is true if we are
3160 // navigating from a page that used prefetching using a link on that
3161 // page. We are early enough in the request process here that we
3162 // can still see the NavigationState of the previous page and set
3163 // this value appropriately.
3164 // TODO(gavinp): catch the important case of navigation in a new
3165 // renderer process.
3166 if (webview()) {
[email protected]e47aec52010-08-12 00:50:303167 if (WebFrame* old_frame = webview()->mainFrame()) {
[email protected]05c8e502010-08-15 15:13:523168 const WebURLRequest& original_request = ds->originalRequest();
[email protected]8a3125a712010-08-09 18:58:513169 const GURL referrer(
3170 original_request.httpHeaderField(WebString::fromUTF8("Referer")));
3171 if (!referrer.is_empty() &&
3172 NavigationState::FromDataSource(
3173 old_frame->dataSource())->was_prefetcher()) {
3174 for (;old_frame;old_frame = old_frame->traverseNext(false)) {
3175 WebDataSource* old_frame_ds = old_frame->dataSource();
3176 if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) {
3177 state->set_was_referred_by_prefetcher(true);
3178 break;
3179 }
3180 }
3181 }
3182 }
3183 }
3184
[email protected]4c1b6f0b2010-02-07 16:38:183185 if (content_initiated) {
[email protected]05c8e502010-08-15 15:13:523186 const WebURLRequest& request = ds->request();
[email protected]8a3125a712010-08-09 18:58:513187 switch (request.cachePolicy()) {
[email protected]4c1b6f0b2010-02-07 16:38:183188 case WebURLRequest::UseProtocolCachePolicy: // normal load.
3189 state->set_load_type(NavigationState::LINK_LOAD_NORMAL);
3190 break;
3191 case WebURLRequest::ReloadIgnoringCacheData: // reload.
3192 state->set_load_type(NavigationState::LINK_LOAD_RELOAD);
3193 break;
3194 case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data.
3195 state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK);
3196 break;
3197 case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post.
3198 state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY);
3199 break;
3200 }
3201 }
[email protected]fa7b6b542009-11-03 05:02:303202
[email protected]5792d932011-01-18 20:33:293203 // If this datasource already has a UserScriptIdleScheduler, reuse that one.
3204 // This is for navigations within a page (didNavigateWithinPage). See
3205 // http://code.google.com/p/chromium/issues/detail?id=64093
3206 NavigationState* old_state = NavigationState::FromDataSource(ds);
3207 if (old_state && old_state->user_script_idle_scheduler()) {
3208 state->swap_user_script_idle_scheduler(old_state);
3209 } else {
3210 state->set_user_script_idle_scheduler(
3211 new UserScriptIdleScheduler(this, frame));
3212 }
[email protected]fa7b6b542009-11-03 05:02:303213 ds->setExtraData(state);
[email protected]3d9689372009-09-10 04:29:173214}
3215
3216void RenderView::didStartProvisionalLoad(WebFrame* frame) {
3217 WebDataSource* ds = frame->provisionalDataSource();
3218 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3219
[email protected]3d9689372009-09-10 04:29:173220 // Update the request time if WebKit has better knowledge of it.
3221 if (navigation_state->request_time().is_null()) {
3222 double event_time = ds->triggeringEventTime();
3223 if (event_time != 0.0)
3224 navigation_state->set_request_time(Time::FromDoubleT(event_time));
3225 }
3226
[email protected]05c8e502010-08-15 15:13:523227 // Start time is only set after request time.
3228 navigation_state->set_start_load_time(Time::Now());
3229
[email protected]3d9689372009-09-10 04:29:173230 bool is_top_most = !frame->parent();
3231 if (is_top_most) {
3232 navigation_gesture_ = frame->isProcessingUserGesture() ?
[email protected]cd448092010-12-06 23:49:133233 NavigationGestureUser : NavigationGestureAuto;
[email protected]3d9689372009-09-10 04:29:173234
3235 // Make sure redirect tracking state is clear for the new load.
3236 completed_client_redirect_src_ = GURL();
3237 } else if (frame->parent()->isLoading()) {
3238 // Take note of AUTO_SUBFRAME loads here, so that we can know how to
[email protected]4fb66842009-12-04 21:41:003239 // load an error page. See didFailProvisionalLoad.
[email protected]3d9689372009-09-10 04:29:173240 navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME);
3241 }
3242
3243 Send(new ViewHostMsg_DidStartProvisionalLoadForFrame(
[email protected]dabb0d12010-10-05 12:50:073244 routing_id_, frame->identifier(), is_top_most, ds->request().url()));
[email protected]3d9689372009-09-10 04:29:173245}
3246
3247void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) {
3248 if (frame->parent())
3249 return;
3250 // Received a redirect on the main frame.
3251 WebDataSource* data_source = frame->provisionalDataSource();
3252 if (!data_source) {
3253 // Should only be invoked when we have a data source.
3254 NOTREACHED();
3255 return;
3256 }
3257 std::vector<GURL> redirects;
3258 GetRedirectChain(data_source, &redirects);
3259 if (redirects.size() >= 2) {
[email protected]40bd6582009-12-04 23:49:513260 Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_,
3261 redirects[redirects.size() - 2], redirects.back()));
[email protected]3d9689372009-09-10 04:29:173262 }
3263}
3264
[email protected]40bd6582009-12-04 23:49:513265void RenderView::didFailProvisionalLoad(WebFrame* frame,
3266 const WebURLError& error) {
[email protected]3d9689372009-09-10 04:29:173267 // Notify the browser that we failed a provisional load with an error.
3268 //
3269 // Note: It is important this notification occur before DidStopLoading so the
3270 // SSL manager can react to the provisional load failure before being
3271 // notified the load stopped.
3272 //
3273 WebDataSource* ds = frame->provisionalDataSource();
3274 DCHECK(ds);
3275
3276 const WebURLRequest& failed_request = ds->request();
3277
3278 bool show_repost_interstitial =
3279 (error.reason == net::ERR_CACHE_MISS &&
3280 EqualsASCII(failed_request.httpMethod(), "POST"));
3281 Send(new ViewHostMsg_DidFailProvisionalLoadWithError(
[email protected]dabb0d12010-10-05 12:50:073282 routing_id_, frame->identifier(), !frame->parent(), error.reason,
3283 error.unreachableURL, show_repost_interstitial));
[email protected]3d9689372009-09-10 04:29:173284
3285 // Don't display an error page if this is simply a cancelled load. Aside
3286 // from being dumb, WebCore doesn't expect it and it will cause a crash.
3287 if (error.reason == net::ERR_ABORTED)
3288 return;
3289
3290 // Make sure we never show errors in view source mode.
3291 frame->enableViewSourceMode(false);
3292
3293 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3294
3295 // If this is a failed back/forward/reload navigation, then we need to do a
3296 // 'replace' load. This is necessary to avoid messing up session history.
3297 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
3298 // as session history is concerned.
3299 //
3300 // AUTO_SUBFRAME loads should always be treated as loads that do not advance
3301 // the page id.
3302 //
3303 bool replace =
3304 navigation_state->pending_page_id() != -1 ||
3305 navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME;
3306
3307 // If we failed on a browser initiated request, then make sure that our error
3308 // page load is regarded as the same browser initiated request.
3309 if (!navigation_state->is_content_initiated()) {
3310 pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated(
3311 navigation_state->pending_page_id(),
[email protected]3cc72b12010-03-18 23:03:003312 navigation_state->pending_history_list_offset(),
[email protected]3d9689372009-09-10 04:29:173313 navigation_state->transition_type(),
3314 navigation_state->request_time()));
3315 }
3316
3317 // Provide the user with a more helpful error page?
3318 if (MaybeLoadAlternateErrorPage(frame, error, replace))
3319 return;
3320
3321 // Fallback to a local error page.
[email protected]3f853a52010-09-13 19:15:083322 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
[email protected]3d9689372009-09-10 04:29:173323}
3324
3325void RenderView::didReceiveDocumentData(
3326 WebFrame* frame, const char* data, size_t data_len,
3327 bool& prevent_default) {
3328 NavigationState* navigation_state =
3329 NavigationState::FromDataSource(frame->dataSource());
3330 if (!navigation_state->postpone_loading_data())
3331 return;
3332
3333 // We're going to call commitDocumentData ourselves...
3334 prevent_default = true;
3335
[email protected]3f853a52010-09-13 19:15:083336 // Continue buffering the response data for the original error page. If it
3337 // grows too large, then we'll just let it through. For any error other than
3338 // a 404, "too large" means any data at all.
[email protected]3d9689372009-09-10 04:29:173339 navigation_state->append_postponed_data(data, data_len);
[email protected]3f853a52010-09-13 19:15:083340 if (navigation_state->postponed_data().size() >= 512 ||
3341 navigation_state->http_status_code() != 404) {
[email protected]3d9689372009-09-10 04:29:173342 navigation_state->set_postpone_loading_data(false);
3343 frame->commitDocumentData(navigation_state->postponed_data().data(),
3344 navigation_state->postponed_data().size());
3345 navigation_state->clear_postponed_data();
3346 }
3347}
3348
[email protected]40bd6582009-12-04 23:49:513349void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3350 bool is_new_navigation) {
[email protected]3d9689372009-09-10 04:29:173351 NavigationState* navigation_state =
3352 NavigationState::FromDataSource(frame->dataSource());
3353
3354 navigation_state->set_commit_load_time(Time::Now());
3355 if (is_new_navigation) {
[email protected]e15f680732010-11-23 22:30:203356 // When we perform a new navigation, we need to update the last committed
3357 // session history entry with state for the page we are leaving.
[email protected]3d9689372009-09-10 04:29:173358 UpdateSessionHistory(frame);
3359
3360 // We bump our Page ID to correspond with the new session history entry.
3361 page_id_ = next_page_id_++;
3362
[email protected]d64b07b2010-04-20 22:14:063363 // Any pending translation is now obsolete.
3364 translate_helper_.CancelPendingTranslation();
3365
[email protected]3ead1322010-11-19 20:01:003366 // Let the phishing classifier decide whether to cancel classification.
3367 if (phishing_delegate_.get())
3368 phishing_delegate_->CommittedLoadInFrame(frame);
3369
[email protected]3cc72b12010-03-18 23:03:003370 // Advance our offset in session history, applying the length limit. There
3371 // is now no forward history.
3372 history_list_offset_++;
3373 if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries)
3374 history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1;
3375 history_list_length_ = history_list_offset_ + 1;
3376
[email protected]f9f4841b2010-03-20 05:41:423377 MessageLoop::current()->PostDelayedTask(
3378 FROM_HERE,
[email protected]e47aec52010-08-12 00:50:303379 page_info_method_factory_.NewRunnableMethod(
3380 &RenderView::CapturePageInfo, page_id_, true),
[email protected]3d9689372009-09-10 04:29:173381 kDelayForForcedCaptureMs);
3382 } else {
3383 // Inspect the navigation_state on this frame to see if the navigation
3384 // corresponds to a session history navigation... Note: |frame| may or
3385 // may not be the toplevel frame, but for the case of capturing session
3386 // history, the first committed frame suffices. We keep track of whether
3387 // we've seen this commit before so that only capture session history once
3388 // per navigation.
3389 //
3390 // Note that we need to check if the page ID changed. In the case of a
3391 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
3392 // previous URL and the current page ID, which would be wrong.
3393 if (navigation_state->pending_page_id() != -1 &&
3394 navigation_state->pending_page_id() != page_id_ &&
3395 !navigation_state->request_committed()) {
3396 // This is a successful session history navigation!
3397 UpdateSessionHistory(frame);
3398 page_id_ = navigation_state->pending_page_id();
[email protected]3cc72b12010-03-18 23:03:003399
3400 history_list_offset_ = navigation_state->pending_history_list_offset();
[email protected]3d9689372009-09-10 04:29:173401 }
3402 }
3403
3404 // Remember that we've already processed this request, so we don't update
3405 // the session history again. We do this regardless of whether this is
3406 // a session history navigation, because if we attempted a session history
3407 // navigation without valid HistoryItem state, WebCore will think it is a
3408 // new navigation.
3409 navigation_state->set_request_committed(true);
3410
3411 UpdateURL(frame);
3412
3413 // If this committed load was initiated by a client redirect, we're
3414 // at the last stop now, so clear it.
3415 completed_client_redirect_src_ = GURL();
3416
3417 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273418 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173419}
3420
3421void RenderView::didClearWindowObject(WebFrame* frame) {
3422 if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_))
3423 BindDOMAutomationController(frame);
[email protected]0d7ae862010-10-01 13:52:453424 GURL frame_url = frame->url();
3425 if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) &&
[email protected]bfa83eb82010-10-06 08:41:253426 (frame_url.SchemeIs(chrome::kChromeUIScheme) ||
[email protected]731ae512010-10-15 18:20:173427 frame_url.SchemeIs(chrome::kGearsScheme) ||
[email protected]bfa83eb82010-10-06 08:41:253428 frame_url.SchemeIs(chrome::kDataScheme))) {
[email protected]c091c2c2010-09-17 19:05:463429 GetDOMUIBindings()->set_message_sender(this);
3430 GetDOMUIBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253431 GetDOMUIBindings()->BindToJavascript(frame, "chrome");
[email protected]3d9689372009-09-10 04:29:173432 }
3433 if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) {
[email protected]c091c2c2010-09-17 19:05:463434 GetExternalHostBindings()->set_message_sender(this);
3435 GetExternalHostBindings()->set_routing_id(routing_id_);
[email protected]906690b2010-12-03 18:11:253436 GetExternalHostBindings()->BindToJavascript(frame, "externalHost");
[email protected]3d9689372009-09-10 04:29:173437 }
3438}
3439
3440void RenderView::didCreateDocumentElement(WebFrame* frame) {
3441 if (RenderThread::current()) { // Will be NULL during unit tests.
3442 RenderThread::current()->user_script_slave()->InjectScripts(
3443 frame, UserScript::DOCUMENT_START);
3444 }
3445
3446 // Notify the browser about non-blank documents loading in the top frame.
3447 GURL url = frame->url();
[email protected]e0d481582009-09-15 21:06:253448 if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) {
[email protected]26aa0482009-09-30 16:55:273449 if (frame == webview()->mainFrame())
[email protected]3d9689372009-09-10 04:29:173450 Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_));
3451 }
3452}
3453
3454void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) {
3455 UpdateTitle(frame, title);
3456
3457 // Also check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273458 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173459}
3460
[email protected]5019ef12010-04-27 17:26:583461void RenderView::didChangeIcons(WebFrame* frame) {
3462 if (!frame->parent()) {
3463 Send(new ViewHostMsg_UpdateFavIconURL(
3464 routing_id_,
3465 page_id_,
3466 frame->favIconURL()));
3467 }
3468}
3469
[email protected]3d9689372009-09-10 04:29:173470void RenderView::didFinishDocumentLoad(WebFrame* frame) {
3471 WebDataSource* ds = frame->dataSource();
3472 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3473 DCHECK(navigation_state);
3474 navigation_state->set_finish_document_load_time(Time::Now());
3475
[email protected]622474d2010-11-04 09:21:083476 Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173477
[email protected]676126f72011-01-15 00:03:513478 FOR_EACH_OBSERVER(
3479 RenderViewObserver, observers_, DidFinishDocumentLoad(frame));
[email protected]3d9689372009-09-10 04:29:173480
3481 // Check whether we have new encoding name.
[email protected]26aa0482009-09-30 16:55:273482 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
[email protected]3d9689372009-09-10 04:29:173483
3484 if (RenderThread::current()) { // Will be NULL during unit tests.
3485 RenderThread::current()->user_script_slave()->InjectScripts(
3486 frame, UserScript::DOCUMENT_END);
3487 }
[email protected]fa7b6b542009-11-03 05:02:303488
[email protected]41f16632010-10-20 01:21:323489 // InjectScripts() can end up creating a new NavigationState if it triggers a
3490 // fragment navigation, so we need to re-fetch it here.
3491 navigation_state = NavigationState::FromDataSource(ds);
[email protected]fa7b6b542009-11-03 05:02:303492 navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad();
3493}
3494
3495void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) {
3496 if (RenderThread::current()) { // Will be NULL during unit tests.
3497 RenderThread::current()->user_script_slave()->InjectScripts(
3498 frame, UserScript::DOCUMENT_IDLE);
3499 }
3500
3501 WebFrame* main_frame = webview()->mainFrame();
3502 if (frame == main_frame) {
3503 while (!pending_code_execution_queue_.empty()) {
[email protected]61f5a7b2009-12-22 22:21:203504 linked_ptr<ViewMsg_ExecuteCode_Params>& params =
[email protected]fa7b6b542009-11-03 05:02:303505 pending_code_execution_queue_.front();
[email protected]61f5a7b2009-12-22 22:21:203506 ExecuteCodeImpl(main_frame, *params);
[email protected]fa7b6b542009-11-03 05:02:303507 pending_code_execution_queue_.pop();
3508 }
3509 }
[email protected]3d9689372009-09-10 04:29:173510}
3511
3512void RenderView::didHandleOnloadEvents(WebFrame* frame) {
[email protected]25497492010-09-11 15:15:083513 if (webview()->mainFrame() == frame) {
3514 Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_,
3515 page_id_));
3516 }
[email protected]3d9689372009-09-10 04:29:173517}
3518
3519void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) {
3520 // Ignore
3521}
3522
3523void RenderView::didFinishLoad(WebFrame* frame) {
3524 WebDataSource* ds = frame->dataSource();
3525 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
3526 DCHECK(navigation_state);
3527 navigation_state->set_finish_load_time(Time::Now());
[email protected]fa7b6b542009-11-03 05:02:303528 navigation_state->user_script_idle_scheduler()->DidFinishLoad();
[email protected]4d44a1c2010-04-28 19:20:413529
[email protected]676126f72011-01-15 00:03:513530 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidFinishLoad(frame));
[email protected]fdd94a02010-11-05 08:07:173531
3532 Send(new ViewHostMsg_DidFinishLoad(routing_id_, frame->identifier()));
[email protected]3d9689372009-09-10 04:29:173533}
3534
[email protected]ccbe04e2010-03-17 17:58:433535void RenderView::didNavigateWithinPage(
[email protected]3d9689372009-09-10 04:29:173536 WebFrame* frame, bool is_new_navigation) {
3537 // If this was a reference fragment navigation that we initiated, then we
3538 // could end up having a non-null pending navigation state. We just need to
3539 // update the ExtraData on the datasource so that others who read the
3540 // ExtraData will get the new NavigationState. Similarly, if we did not
3541 // initiate this navigation, then we need to take care to reset any pre-
3542 // existing navigation state to a content-initiated navigation state.
3543 // DidCreateDataSource conveniently takes care of this for us.
3544 didCreateDataSource(frame, frame->dataSource());
3545
[email protected]af15bed2010-08-25 21:12:093546 NavigationState* new_state =
3547 NavigationState::FromDataSource(frame->dataSource());
3548 new_state->set_was_within_same_page(true);
3549
[email protected]3d9689372009-09-10 04:29:173550 didCommitProvisionalLoad(frame, is_new_navigation);
3551
[email protected]26aa0482009-09-30 16:55:273552 UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle());
[email protected]3d9689372009-09-10 04:29:173553}
3554
[email protected]476b6f82009-09-10 21:00:593555void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) {
[email protected]882daa92009-11-05 16:31:313556 StartNavStateSyncTimerIfNecessary();
[email protected]476b6f82009-09-10 21:00:593557}
3558
[email protected]3d9689372009-09-10 04:29:173559void RenderView::assignIdentifierToRequest(
3560 WebFrame* frame, unsigned identifier, const WebURLRequest& request) {
3561 // Ignore
3562}
3563
3564void RenderView::willSendRequest(
3565 WebFrame* frame, unsigned identifier, WebURLRequest& request,
3566 const WebURLResponse& redirect_response) {
[email protected]5e369672009-11-03 23:48:303567 WebFrame* top_frame = frame->top();
3568 if (!top_frame)
3569 top_frame = frame;
[email protected]8a3125a712010-08-09 18:58:513570 WebDataSource* provisional_data_source = top_frame->provisionalDataSource();
3571 WebDataSource* top_data_source = top_frame->dataSource();
3572 WebDataSource* data_source =
3573 provisional_data_source ? provisional_data_source : top_data_source;
[email protected]5e369672009-11-03 23:48:303574 if (data_source) {
3575 NavigationState* state = NavigationState::FromDataSource(data_source);
3576 if (state && state->is_cache_policy_override_set())
3577 request.setCachePolicy(state->cache_policy_override());
3578 }
[email protected]8a3125a712010-08-09 18:58:513579
3580 if (top_data_source) {
3581 NavigationState* state = NavigationState::FromDataSource(top_data_source);
3582 if (state && request.targetType() == WebURLRequest::TargetIsPrefetch)
3583 state->set_was_prefetcher(true);
3584 }
3585
[email protected]3d9689372009-09-10 04:29:173586 request.setRequestorID(routing_id_);
[email protected]cd448092010-12-06 23:49:133587 request.setHasUserGesture(frame->isProcessingUserGesture());
3588
[email protected]c5bbc2452010-03-08 08:33:503589 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers))
[email protected]7deade42010-03-05 09:33:133590 request.clearHTTPHeaderField("Referer");
[email protected]fa0a3432010-03-30 16:53:493591
[email protected]85cc78c2010-05-04 18:30:093592 // Temporary metrics, see site_isolation_metrics.h
3593 SiteIsolationMetrics::AddRequest(identifier, request.targetType());
[email protected]3d9689372009-09-10 04:29:173594}
3595
3596void RenderView::didReceiveResponse(
3597 WebFrame* frame, unsigned identifier, const WebURLResponse& response) {
[email protected]fa0a3432010-03-30 16:53:493598
[email protected]85cc78c2010-05-04 18:30:093599 // Temporary metrics, see site_isolation_metrics.h
3600 SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame,
3601 identifier,
3602 response);
[email protected]fa0a3432010-03-30 16:53:493603
[email protected]3d9689372009-09-10 04:29:173604 // Only do this for responses that correspond to a provisional data source
3605 // of the top-most frame. If we have a provisional data source, then we
3606 // can't have any sub-resources yet, so we know that this response must
3607 // correspond to a frame load.
3608 if (!frame->provisionalDataSource() || frame->parent())
3609 return;
3610
3611 // If we are in view source mode, then just let the user see the source of
[email protected]3f853a52010-09-13 19:15:083612 // the server's error page.
[email protected]3d9689372009-09-10 04:29:173613 if (frame->isViewSourceModeEnabled())
3614 return;
3615
[email protected]65041fa2010-05-21 06:56:533616 NavigationState* navigation_state =
3617 NavigationState::FromDataSource(frame->provisionalDataSource());
3618 CHECK(navigation_state);
[email protected]3f853a52010-09-13 19:15:083619 int http_status_code = response.httpStatusCode();
[email protected]65041fa2010-05-21 06:56:533620
[email protected]972ebdff2010-06-10 22:59:073621 // Record page load flags.
3622 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3623 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
[email protected]193b0b892010-06-26 03:57:573624 navigation_state->set_was_alternate_protocol_available(
3625 response.wasAlternateProtocolAvailable());
[email protected]972ebdff2010-06-10 22:59:073626 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
[email protected]3f853a52010-09-13 19:15:083627 navigation_state->set_http_status_code(http_status_code);
[email protected]65041fa2010-05-21 06:56:533628
[email protected]f48013be2010-01-14 22:07:453629 // Consider loading an alternate error page for 404 responses.
[email protected]3f853a52010-09-13 19:15:083630 if (http_status_code == 404) {
3631 // Can we even load an alternate error page for this URL?
3632 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3633 return;
3634 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3635 http_status_code)) {
3636 // If no corresponding error strings for a particular status code, just
3637 // render any received data, regardless of whether or not the status code
3638 // indicates an error.
[email protected]f48013be2010-01-14 22:07:453639 return;
[email protected]3f853a52010-09-13 19:15:083640 }
[email protected]3d9689372009-09-10 04:29:173641
[email protected]3d9689372009-09-10 04:29:173642 navigation_state->set_postpone_loading_data(true);
3643 navigation_state->clear_postponed_data();
3644}
3645
3646void RenderView::didFinishResourceLoad(
3647 WebFrame* frame, unsigned identifier) {
3648 NavigationState* navigation_state =
3649 NavigationState::FromDataSource(frame->dataSource());
3650 if (!navigation_state->postpone_loading_data())
3651 return;
3652
[email protected]3f853a52010-09-13 19:15:083653 // The server returned an error and the content was < 512 bytes (which we
[email protected]3d9689372009-09-10 04:29:173654 // suppressed). Go ahead and fetch the alternate page content.
[email protected]3f853a52010-09-13 19:15:083655 int http_status_code = navigation_state->http_status_code();
3656 if (http_status_code == 404) {
3657 // On 404s, try a remote search page as a fallback.
3658 const GURL& frame_url = frame->url();
[email protected]3d9689372009-09-10 04:29:173659
[email protected]3f853a52010-09-13 19:15:083660 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3661 DCHECK(error_page_url.is_valid());
[email protected]3d9689372009-09-10 04:29:173662
[email protected]3f853a52010-09-13 19:15:083663 WebURLError original_error;
3664 original_error.unreachableURL = frame_url;
[email protected]3d9689372009-09-10 04:29:173665
[email protected]3f853a52010-09-13 19:15:083666 navigation_state->set_alt_error_page_fetcher(
3667 new AltErrorPageResourceFetcher(
3668 error_page_url, frame, original_error,
3669 NewCallback(this, &RenderView::AltErrorPageFinished)));
3670 } else {
3671 // On other errors, use an internal error page.
3672 WebURLError error;
3673 error.unreachableURL = frame->url();
3674 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3675 error.reason = http_status_code;
[email protected]3d9689372009-09-10 04:29:173676
[email protected]3f853a52010-09-13 19:15:083677 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3678 std::string(), true);
3679 }
[email protected]3d9689372009-09-10 04:29:173680}
3681
3682void RenderView::didFailResourceLoad(
3683 WebFrame* frame, unsigned identifier, const WebURLError& error) {
3684 // Ignore
3685}
3686
3687void RenderView::didLoadResourceFromMemoryCache(
3688 WebFrame* frame, const WebURLRequest& request,
3689 const WebURLResponse& response) {
3690 // Let the browser know we loaded a resource from the memory cache. This
3691 // message is needed to display the correct SSL indicators.
3692 Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(
3693 routing_id_,
3694 request.url(),
[email protected]91733b62009-09-18 06:21:093695 frame->securityOrigin().toString().utf8(),
3696 frame->top()->securityOrigin().toString().utf8(),
[email protected]3d9689372009-09-10 04:29:173697 response.securityInfo()));
3698}
3699
[email protected]6069da8c2009-10-20 20:33:493700void RenderView::didDisplayInsecureContent(WebFrame* frame) {
[email protected]e3d60e5d2009-09-25 21:08:293701 Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_));
3702}
3703
[email protected]92771112011-01-20 00:13:023704// We have two didRunInsecureContent's with the same name. That's because
3705// we're in the process of adding an argument and one of them will be correct.
3706// Once the WebKit change is in, the first should be removed.
[email protected]e3d60e5d2009-09-25 21:08:293707void RenderView::didRunInsecureContent(
3708 WebFrame* frame, const WebSecurityOrigin& origin) {
[email protected]92771112011-01-20 00:13:023709 didRunInsecureContent(frame, origin, GURL());
3710}
3711
3712void RenderView::didRunInsecureContent(
3713 WebFrame* frame, const WebSecurityOrigin& origin, const WebURL& target) {
[email protected]e3d60e5d2009-09-25 21:08:293714 Send(new ViewHostMsg_DidRunInsecureContent(
3715 routing_id_,
[email protected]92771112011-01-20 00:13:023716 origin.toString().utf8(),
3717 target));
[email protected]e3d60e5d2009-09-25 21:08:293718}
3719
[email protected]7ea093ba2009-11-03 05:54:593720bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) {
[email protected]12bc8472010-04-15 07:29:403721 if (enabled_per_settings &&
3722 AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT))
3723 return true;
[email protected]7ea093ba2009-11-03 05:54:593724
[email protected]12bc8472010-04-15 07:29:403725 if (IsWhitelistedForContentSettings(frame))
3726 return true;
[email protected]7ea093ba2009-11-03 05:54:593727
3728 return false; // Other protocols fall through here.
3729}
3730
[email protected]0a1a45432010-03-31 08:09:453731bool RenderView::allowDatabase(
3732 WebFrame* frame, const WebString& name, const WebString& display_name,
3733 unsigned long estimated_size) {
3734 WebSecurityOrigin origin = frame->securityOrigin();
3735 if (origin.isEmpty())
3736 return false; // Uninitialized document?
3737
3738 bool result;
[email protected]26a9acf2010-12-13 19:35:053739 if (!Send(new DatabaseHostMsg_Allow(routing_id_,
[email protected]0a1a45432010-03-31 08:09:453740 origin.toString().utf8(), name, display_name, estimated_size, &result)))
3741 return false;
[email protected]9fb83e82010-07-02 18:24:553742 Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_,
3743 GURL(origin.toString().utf8()),
3744 name,
3745 display_name,
3746 estimated_size,
3747 !result));
[email protected]0a1a45432010-03-31 08:09:453748 return result;
3749}
[email protected]8934a3b2010-02-25 00:34:003750void RenderView::didNotAllowScript(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283751 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string());
[email protected]8934a3b2010-02-25 00:34:003752}
3753
[email protected]c21f1d52010-03-04 03:19:433754void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) {
[email protected]55126132010-08-19 14:53:283755 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string());
[email protected]c21f1d52010-03-04 03:19:433756}
3757
[email protected]3d9689372009-09-10 04:29:173758void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) {
3759 Send(new ViewHostMsg_JSOutOfMemory(routing_id_));
3760}
3761
[email protected]0c882b282009-10-07 17:01:283762void RenderView::didCreateScriptContext(WebFrame* frame) {
3763 EventBindings::HandleContextCreated(frame, false);
3764}
3765
3766void RenderView::didDestroyScriptContext(WebFrame* frame) {
3767 EventBindings::HandleContextDestroyed(frame);
3768}
3769
3770void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) {
3771 EventBindings::HandleContextCreated(frame, true);
3772}
3773
[email protected]af7eb3fb2010-09-23 21:31:063774bool RenderView::allowScriptExtension(WebFrame* frame,
3775 const WebString& extension_name,
3776 int extension_group) {
3777 // NULL in unit tests.
3778 if (!RenderThread::current())
3779 return true;
3780
3781 // Note: we prefer the provisional URL here instead of the document URL
3782 // because we might be currently loading an URL into a blank page.
3783 // See http://code.google.com/p/chromium/issues/detail?id=10924
3784 WebDataSource* ds = frame->provisionalDataSource();
3785 if (!ds)
3786 ds = frame->dataSource();
3787 return RenderThread::current()->AllowScriptExtension(
3788 extension_name.utf8(), ds->request().url(), extension_group);
3789}
3790
[email protected]fc86daa2010-03-30 23:52:533791void RenderView::logCrossFramePropertyAccess(WebFrame* frame,
3792 WebFrame* target,
3793 bool cross_origin,
3794 const WebString& property_name,
3795 unsigned long long event_id) {
[email protected]ab9eabac2010-03-16 16:54:103796 // TODO(johnnyg): track the individual properties and repeat event_ids.
[email protected]a5a65ac2010-11-05 18:14:363797 page_load_histograms_.IncrementCrossFramePropertyAccess(cross_origin);
[email protected]ab9eabac2010-03-16 16:54:103798}
3799
[email protected]3d9689372009-09-10 04:29:173800void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) {
[email protected]d8a179c2010-01-31 00:58:143801 CheckPreferredSize();
3802}
3803
3804void RenderView::CheckPreferredSize() {
[email protected]3d9689372009-09-10 04:29:173805 // We don't always want to send the change messages over IPC, only if we've
[email protected]ab32b16c2009-10-16 14:57:253806 // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode|
[email protected]3d9689372009-09-10 04:29:173807 // message.
[email protected]705243f2010-05-05 19:58:073808 if (!send_preferred_size_changes_ || !webview())
3809 return;
[email protected]dfca5acf2010-03-22 03:28:433810
[email protected]705243f2010-05-05 19:58:073811 // WebCore likes to tell us things have changed even when they haven't, so
3812 // cache the width and height and only send the IPC message when we're sure
3813 // they're different.
3814 gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(),
3815 webview()->mainFrame()->documentElementScrollHeight());
[email protected]8205d742010-10-22 23:51:533816
3817 // In the presence of zoom, these sizes are still reported as if unzoomed,
3818 // so we need to adjust.
3819 double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel());
3820 size.set_width(static_cast<int>(size.width() * zoom_factor));
3821 size.set_height(static_cast<int>(size.height() * zoom_factor));
3822
[email protected]705243f2010-05-05 19:58:073823 if (size == preferred_size_)
3824 return;
[email protected]c27324b2009-11-19 22:44:293825
[email protected]705243f2010-05-05 19:58:073826 preferred_size_ = size;
3827 Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_,
3828 preferred_size_));
[email protected]3d9689372009-09-10 04:29:173829}
3830
[email protected]143dcd592009-11-06 21:33:493831void RenderView::didChangeScrollOffset(WebFrame* frame) {
3832 StartNavStateSyncTimerIfNecessary();
3833}
3834
[email protected]8922e1f2009-10-03 05:01:263835void RenderView::reportFindInPageMatchCount(int request_id, int count,
3836 bool final_update) {
[email protected]e7c58a32010-08-13 19:47:113837 int active_match_ordinal = -1; // -1 = don't update active match ordinal
3838 if (!count)
3839 active_match_ordinal = 0;
3840
3841 IPC::Message* msg = new ViewHostMsg_Find_Reply(
3842 routing_id_,
3843 request_id,
3844 count,
3845 gfx::Rect(),
3846 active_match_ordinal,
3847 final_update);
3848
[email protected]8922e1f2009-10-03 05:01:263849 // If we have a message that has been queued up, then we should just replace
3850 // it. The ACK from the browser will make sure it gets sent when the browser
3851 // wants it.
3852 if (queued_find_reply_message_.get()) {
[email protected]8922e1f2009-10-03 05:01:263853 queued_find_reply_message_.reset(msg);
3854 } else {
3855 // Send the search result over to the browser process.
[email protected]e7c58a32010-08-13 19:47:113856 Send(msg);
[email protected]8922e1f2009-10-03 05:01:263857 }
3858}
3859
3860void RenderView::reportFindInPageSelection(int request_id,
3861 int active_match_ordinal,
3862 const WebRect& selection_rect) {
3863 // Send the search result over to the browser process.
3864 Send(new ViewHostMsg_Find_Reply(routing_id_,
3865 request_id,
3866 -1,
3867 selection_rect,
3868 active_match_ordinal,
3869 false));
3870}
3871
[email protected]2b06a992010-08-21 05:48:223872void RenderView::openFileSystem(
3873 WebFrame* frame,
3874 WebFileSystem::Type type,
3875 long long size,
[email protected]d275d7a2010-11-03 01:34:493876 bool create,
[email protected]2b06a992010-08-21 05:48:223877 WebFileSystemCallbacks* callbacks) {
[email protected]c5a272d2010-09-27 18:37:083878 DCHECK(callbacks);
[email protected]2b06a992010-08-21 05:48:223879
3880 WebSecurityOrigin origin = frame->securityOrigin();
[email protected]c5a272d2010-09-27 18:37:083881 if (origin.isEmpty()) {
3882 // Uninitialized document?
3883 callbacks->didFail(WebKit::WebFileErrorAbort);
3884 return;
3885 }
[email protected]2b06a992010-08-21 05:48:223886
[email protected]c5a272d2010-09-27 18:37:083887 ChildThread::current()->file_system_dispatcher()->OpenFileSystem(
3888 GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type),
[email protected]d275d7a2010-11-03 01:34:493889 size, create, new WebFileSystemCallbackDispatcher(callbacks));
[email protected]2b06a992010-08-21 05:48:223890}
3891
[email protected]79dbc662009-09-04 05:42:513892// webkit_glue::WebPluginPageDelegate -----------------------------------------
3893
[email protected]191eb3f72010-12-21 06:27:503894webkit::npapi::WebPluginDelegate* RenderView::CreatePluginDelegate(
[email protected]4e0616e2010-05-28 14:55:533895 const FilePath& file_path,
3896 const std::string& mime_type) {
[email protected]f103ab72009-09-02 17:10:593897 if (!PluginChannelHost::IsListening())
3898 return NULL;
3899
[email protected]d2139662009-12-10 03:21:143900 bool use_pepper_host = false;
[email protected]00c39612010-03-06 02:53:283901 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins();
[email protected]d2139662009-12-10 03:21:143902 // Check for trusted Pepper plugins.
[email protected]26e8d5e2009-10-13 02:47:163903 const char kPepperPrefix[] = "pepper-";
[email protected]4e0616e2010-05-28 14:55:533904 if (StartsWithASCII(mime_type, kPepperPrefix, true)) {
[email protected]d2139662009-12-10 03:21:143905 if (CommandLine::ForCurrentProcess()->
3906 HasSwitch(switches::kInternalPepper)) {
3907 in_process_plugin = true;
3908 use_pepper_host = true;
3909 } else {
3910 // In process Pepper plugins must be explicitly enabled.
3911 return NULL;
3912 }
[email protected]4e0616e2010-05-28 14:55:533913 } else {
3914 FilePath internal_pdf_path;
3915 PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path);
3916 if (file_path == internal_pdf_path) {
3917 in_process_plugin = true;
3918 use_pepper_host = true;
3919 }
[email protected]26e8d5e2009-10-13 02:47:163920 }
[email protected]4e0616e2010-05-28 14:55:533921
[email protected]d2139662009-12-10 03:21:143922 // Check for Native Client modules.
[email protected]5cad70a82010-09-03 22:14:113923 if (mime_type == "application/x-nacl-srpc" &&
3924 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
[email protected]8f05f7f2010-07-30 23:12:433925 // NaCl is only permitted when we're in an extension/application with the
3926 // appropriate permission, or when explicitly enabled on the command line.
3927
[email protected]8f05f7f2010-07-30 23:12:433928 GURL main_frame_url(webview()->mainFrame()->url());
[email protected]5351dbc2010-08-27 15:22:113929 ExtensionRendererInfo* extension =
3930 ExtensionRendererInfo::GetByURL(main_frame_url);
3931 bool in_ext = extension != NULL;
[email protected]8f05f7f2010-07-30 23:12:433932 bool explicit_enable =
3933 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3934
3935 if (in_ext) {
[email protected]5cad70a82010-09-03 22:14:113936 // TODO(cbiffle): NaCl is back to experimental for M7.
[email protected]5351dbc2010-08-27 15:22:113937 if (ExtensionProcessBindings::HasPermission(extension->id(),
[email protected]5cad70a82010-09-03 22:14:113938 Extension::kExperimentalPermission)) {
[email protected]8f05f7f2010-07-30 23:12:433939 in_process_plugin = true;
3940 use_pepper_host = true;
3941 } else {
3942 // Disable NaCl for apps lacking the permission, even with the flag.
3943 return NULL;
3944 }
3945 } else if (explicit_enable) {
[email protected]d032f492009-09-29 00:33:463946 in_process_plugin = true;
[email protected]d2139662009-12-10 03:21:143947 use_pepper_host = true;
[email protected]d032f492009-09-29 00:33:463948 }
3949 }
[email protected]4e0616e2010-05-28 14:55:533950
[email protected]d032f492009-09-29 00:33:463951 if (in_process_plugin) {
[email protected]d2139662009-12-10 03:21:143952 if (use_pepper_host) {
[email protected]00c39612010-03-06 02:53:283953 WebPluginDelegatePepper* pepper_plugin =
[email protected]4e0616e2010-05-28 14:55:533954 WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr());
[email protected]b7d7ed52010-07-20 00:12:333955 if (!pepper_plugin)
3956 return NULL;
3957
[email protected]53900d52010-06-16 04:25:013958 current_oldstyle_pepper_plugins_.insert(pepper_plugin);
[email protected]00c39612010-03-06 02:53:283959 return pepper_plugin;
[email protected]d2139662009-12-10 03:21:143960 } else {
[email protected]6876dff2010-01-15 19:38:093961#if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac.
[email protected]191eb3f72010-12-21 06:27:503962 return webkit::npapi::WebPluginDelegateImpl::Create(
[email protected]4e0616e2010-05-28 14:55:533963 file_path, mime_type, gfx::NativeViewFromId(host_window_));
[email protected]6876dff2010-01-15 19:38:093964#else
[email protected]596b2c42010-01-14 20:40:433965 NOTIMPLEMENTED();
3966 return NULL;
[email protected]7b6616f2010-01-14 18:07:553967#endif
[email protected]6876dff2010-01-15 19:38:093968 }
[email protected]f103ab72009-09-02 17:10:593969 }
3970
[email protected]4e0616e2010-05-28 14:55:533971 return new WebPluginDelegateProxy(mime_type, AsWeakPtr());
[email protected]f103ab72009-09-02 17:10:593972}
3973
3974void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033975#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593976 RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer(
3977 routing_id(), window));
3978#endif
3979}
3980
3981void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) {
[email protected]6981f7f2010-03-09 00:53:033982#if defined(USE_X11)
[email protected]f103ab72009-09-02 17:10:593983 RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer(
3984 routing_id(), window));
3985#endif
3986 CleanupWindowInPluginMoves(window);
3987}
3988
[email protected]191eb3f72010-12-21 06:27:503989void RenderView::DidMovePlugin(const webkit::npapi::WebPluginGeometry& move) {
[email protected]f103ab72009-09-02 17:10:593990 SchedulePluginMove(move);
3991}
3992
3993void RenderView::DidStartLoadingForPlugin() {
3994 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:523995 didStartLoading();
[email protected]f103ab72009-09-02 17:10:593996}
3997
3998void RenderView::DidStopLoadingForPlugin() {
3999 // TODO(darin): Make is_loading_ be a counter!
[email protected]48c9cf2d2009-09-16 16:47:524000 didStopLoading();
[email protected]f103ab72009-09-02 17:10:594001}
4002
4003void RenderView::ShowModalHTMLDialogForPlugin(
4004 const GURL& url,
4005 const gfx::Size& size,
4006 const std::string& json_arguments,
4007 std::string* json_retval) {
[email protected]12636df2009-09-28 22:32:214008 SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog(
[email protected]f103ab72009-09-02 17:10:594009 routing_id_, url, size.width(), size.height(), json_arguments,
[email protected]12636df2009-09-28 22:32:214010 json_retval));
[email protected]f103ab72009-09-02 17:10:594011}
4012
[email protected]b921cfd22010-02-25 16:57:514013WebCookieJar* RenderView::GetCookieJar() {
4014 return &cookie_jar_;
4015}
4016
initial.commit09911bf2008-07-26 23:55:294017void RenderView::SyncNavigationState() {
4018 if (!webview())
4019 return;
4020
[email protected]26aa0482009-09-30 16:55:274021 const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem();
[email protected]ca948a22009-06-25 19:36:174022 if (item.isNull())
initial.commit09911bf2008-07-26 23:55:294023 return;
[email protected]ca948a22009-06-25 19:36:174024
4025 Send(new ViewHostMsg_UpdateState(
4026 routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
initial.commit09911bf2008-07-26 23:55:294027}
4028
[email protected]b0950a72009-09-29 23:16:174029bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) {
4030 // Make sure webview was not shut down.
4031 if (!webview())
4032 return false;
4033 // Create an image resource fetcher and assign it with a call back object.
[email protected]bb461532010-11-26 21:50:234034 image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
4035 new ImageResourceFetcher(
4036 image_url, webview()->mainFrame(), id, image_size,
4037 NewCallback(this, &RenderView::DidDownloadImage))));
[email protected]b0950a72009-09-29 23:16:174038 return true;
4039}
4040
4041void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher,
initial.commit09911bf2008-07-26 23:55:294042 const SkBitmap& image) {
[email protected]b0950a72009-09-29 23:16:174043 // Notify requester of image download status.
[email protected]51bd36612009-10-20 22:49:474044 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_,
4045 fetcher->id(),
4046 fetcher->image_url(),
4047 image.isNull(),
4048 image));
[email protected]bb461532010-11-26 21:50:234049
4050 // Remove the image fetcher from our pending list. We're in the callback from
4051 // ImageResourceFetcher, best to delay deletion.
4052 for (ImageResourceFetcherList::iterator iter = image_fetchers_.begin();
4053 iter != image_fetchers_.end(); ++iter) {
4054 if (iter->get() == fetcher) {
4055 iter->release();
4056 image_fetchers_.erase(iter);
4057 break;
4058 }
4059 }
[email protected]b0950a72009-09-29 23:16:174060 MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher);
initial.commit09911bf2008-07-26 23:55:294061}
4062
[email protected]bf5c2ff392009-07-08 16:24:334063void RenderView::OnDownloadFavIcon(int id,
4064 const GURL& image_url,
4065 int image_size) {
[email protected]f11ca0732009-04-11 00:09:344066 bool data_image_failed = false;
4067 if (image_url.SchemeIs("data")) {
4068 SkBitmap data_image = ImageFromDataUrl(image_url);
4069 data_image_failed = data_image.empty();
4070 if (!data_image_failed) {
[email protected]bf5c2ff392009-07-08 16:24:334071 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false,
4072 data_image));
[email protected]f11ca0732009-04-11 00:09:344073 }
4074 }
4075
[email protected]bf5c2ff392009-07-08 16:24:334076 if (data_image_failed ||
[email protected]b0950a72009-09-29 23:16:174077 !DownloadImage(id, image_url, image_size)) {
[email protected]bf5c2ff392009-07-08 16:24:334078 Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true,
4079 SkBitmap()));
4080 }
initial.commit09911bf2008-07-26 23:55:294081}
4082
[email protected]f11ca0732009-04-11 00:09:344083SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const {
4084 std::string mime_type, char_set, data;
4085 if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) {
4086 // Decode the favicon using WebKit's image decoder.
4087 webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize));
4088 const unsigned char* src_data =
4089 reinterpret_cast<const unsigned char*>(&data[0]);
4090
4091 return decoder.Decode(src_data, data.size());
4092 }
4093 return SkBitmap();
4094}
4095
initial.commit09911bf2008-07-26 23:55:294096void RenderView::OnGetApplicationInfo(int page_id) {
[email protected]38789d82010-11-17 06:03:444097 WebApplicationInfo app_info;
4098 if (page_id == page_id_) {
4099 string16 error;
4100 web_apps::ParseWebAppFromWebDocument(webview()->mainFrame(), &app_info,
4101 &error);
4102 }
initial.commit09911bf2008-07-26 23:55:294103
4104 // Prune out any data URLs in the set of icons. The browser process expects
4105 // any icon with a data URL to have originated from a favicon. We don't want
4106 // to decode arbitrary data URLs in the browser process. See
4107 // http://b/issue?id=1162972
4108 for (size_t i = 0; i < app_info.icons.size(); ++i) {
[email protected]6de74452009-02-25 18:04:594109 if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) {
initial.commit09911bf2008-07-26 23:55:294110 app_info.icons.erase(app_info.icons.begin() + i);
4111 --i;
4112 }
4113 }
4114
4115 Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info));
4116}
4117
[email protected]7ccddb8c2009-08-04 17:36:554118GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url,
initial.commit09911bf2008-07-26 23:55:294119 ErrorPageType error_type) {
[email protected]7ccddb8c2009-08-04 17:36:554120 if (failed_url.SchemeIsSecure()) {
initial.commit09911bf2008-07-26 23:55:294121 // If the URL that failed was secure, then the embedding web page was not
4122 // expecting a network attacker to be able to manipulate its contents. As
4123 // we fetch alternate error pages over HTTP, we would be allowing a network
4124 // attacker to manipulate the contents of the response if we tried to use
4125 // the link doctor here.
[email protected]810a52ef2010-01-08 01:22:154126 return GURL();
initial.commit09911bf2008-07-26 23:55:294127 }
4128
4129 // Grab the base URL from the browser process.
4130 if (!alternate_error_page_url_.is_valid())
[email protected]810a52ef2010-01-08 01:22:154131 return GURL();
initial.commit09911bf2008-07-26 23:55:294132
4133 // Strip query params from the failed URL.
4134 GURL::Replacements remove_params;
4135 remove_params.ClearUsername();
4136 remove_params.ClearPassword();
4137 remove_params.ClearQuery();
4138 remove_params.ClearRef();
[email protected]7ccddb8c2009-08-04 17:36:554139 const GURL url_to_send = failed_url.ReplaceComponents(remove_params);
[email protected]6fd28f642010-03-15 17:15:504140 std::string spec_to_send = url_to_send.spec();
4141 // Notify link doctor of the url truncation by sending of "?" at the end.
4142 if (failed_url.has_query())
4143 spec_to_send.append("?");
initial.commit09911bf2008-07-26 23:55:294144
4145 // Construct the query params to send to link doctor.
4146 std::string params(alternate_error_page_url_.query());
4147 params.append("&url=");
[email protected]6fd28f642010-03-15 17:15:504148 params.append(EscapeQueryParamValue(spec_to_send, true));
initial.commit09911bf2008-07-26 23:55:294149 params.append("&sourceid=chrome");
4150 params.append("&error=");
4151 switch (error_type) {
4152 case DNS_ERROR:
4153 params.append("dnserror");
4154 break;
4155
4156 case HTTP_404:
4157 params.append("http404");
4158 break;
4159
[email protected]5df266ac2008-10-15 19:50:134160 case CONNECTION_ERROR:
[email protected]e1f934b2009-01-26 20:41:334161 params.append("connectionfailure");
[email protected]5df266ac2008-10-15 19:50:134162 break;
4163
initial.commit09911bf2008-07-26 23:55:294164 default:
4165 NOTREACHED() << "unknown ErrorPageType";
4166 }
4167
4168 // OK, build the final url to return.
4169 GURL::Replacements link_doctor_params;
4170 link_doctor_params.SetQueryStr(params);
4171 GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params);
4172 return url;
4173}
4174
[email protected]c091c2c2010-09-17 19:05:464175DOMUIBindings* RenderView::GetDOMUIBindings() {
4176 if (!dom_ui_bindings_.get()) {
4177 dom_ui_bindings_.reset(new DOMUIBindings());
4178 }
4179 return dom_ui_bindings_.get();
4180}
4181
4182ExternalHostBindings* RenderView::GetExternalHostBindings() {
4183 if (!external_host_bindings_.get()) {
4184 external_host_bindings_.reset(new ExternalHostBindings());
4185 }
4186 return external_host_bindings_.get();
4187}
4188
[email protected]0fdbf8c2010-07-08 20:33:014189WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() {
4190 return webview()->mainFrame()->document().to<WebPluginDocument>().plugin();
[email protected]24a7f3c2010-03-25 08:26:494191}
4192
[email protected]6069da8c2009-10-20 20:33:494193void RenderView::OnFind(int request_id, const string16& search_text,
4194 const WebFindOptions& options) {
[email protected]26aa0482009-09-30 16:55:274195 WebFrame* main_frame = webview()->mainFrame();
[email protected]24a7f3c2010-03-25 08:26:494196
4197 if (main_frame->document().isPluginDocument()) {
[email protected]24a7f3c2010-03-25 08:26:494198 if (options.findNext) {
4199 // Just navigate back/forward.
[email protected]0fdbf8c2010-07-08 20:33:014200 GetWebPluginFromPluginDocument()->selectFindResult(options.forward);
[email protected]24a7f3c2010-03-25 08:26:494201 } else {
[email protected]afdbd142010-07-10 08:01:234202 if (GetWebPluginFromPluginDocument()->startFind(
4203 search_text, options.matchCase, request_id)) {
[email protected]24a7f3c2010-03-25 08:26:494204 } else {
[email protected]e7c58a32010-08-13 19:47:114205 // Send "no results".
4206 Send(new ViewHostMsg_Find_Reply(routing_id_,
4207 request_id,
4208 0,
4209 gfx::Rect(),
4210 0,
4211 true));
[email protected]24a7f3c2010-03-25 08:26:494212 }
4213 }
4214 return;
4215 }
4216
[email protected]b4bb2502009-10-01 22:35:274217 WebFrame* frame_after_main = main_frame->traverseNext(true);
[email protected]26aa0482009-09-30 16:55:274218 WebFrame* focused_frame = webview()->focusedFrame();
initial.commit09911bf2008-07-26 23:55:294219 WebFrame* search_frame = focused_frame; // start searching focused frame.
4220
4221 bool multi_frame = (frame_after_main != main_frame);
4222
4223 // If we have multiple frames, we don't want to wrap the search within the
4224 // frame, so we check here if we only have main_frame in the chain.
4225 bool wrap_within_frame = !multi_frame;
4226
[email protected]b3f2b912009-04-09 16:18:524227 WebRect selection_rect;
initial.commit09911bf2008-07-26 23:55:294228 bool result = false;
4229
[email protected]7830da3e2009-11-06 16:27:264230 // If something is selected when we start searching it means we cannot just
4231 // increment the current match ordinal; we need to re-generate it.
4232 WebRange current_selection = focused_frame->selectionRange();
4233
initial.commit09911bf2008-07-26 23:55:294234 do {
[email protected]dd7daa82009-08-10 05:46:454235 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594236 request_id, search_text, options, wrap_within_frame, &selection_rect);
initial.commit09911bf2008-07-26 23:55:294237
4238 if (!result) {
4239 // don't leave text selected as you move to the next frame.
[email protected]a100d76bb2009-08-14 17:50:224240 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294241
4242 // Find the next frame, but skip the invisible ones.
4243 do {
4244 // What is the next frame to search? (we might be going backwards). Note
4245 // that we specify wrap=true so that search_frame never becomes NULL.
[email protected]7ea066a2009-04-06 20:21:594246 search_frame = options.forward ?
[email protected]b4bb2502009-10-01 22:35:274247 search_frame->traverseNext(true) :
4248 search_frame->traversePrevious(true);
[email protected]dd7daa82009-08-10 05:46:454249 } while (!search_frame->hasVisibleContent() &&
4250 search_frame != focused_frame);
initial.commit09911bf2008-07-26 23:55:294251
[email protected]884db412008-11-24 23:46:504252 // Make sure selection doesn't affect the search operation in new frame.
[email protected]a100d76bb2009-08-14 17:50:224253 search_frame->executeCommand(WebString::fromUTF8("Unselect"));
initial.commit09911bf2008-07-26 23:55:294254
4255 // If we have multiple frames and we have wrapped back around to the
4256 // focused frame, we need to search it once more allowing wrap within
4257 // the frame, otherwise it will report 'no match' if the focused frame has
4258 // reported matches, but no frames after the focused_frame contain a
4259 // match for the search word(s).
4260 if (multi_frame && search_frame == focused_frame) {
[email protected]dd7daa82009-08-10 05:46:454261 result = search_frame->find(
[email protected]7ea066a2009-04-06 20:21:594262 request_id, search_text, options, true, // Force wrapping.
4263 &selection_rect);
initial.commit09911bf2008-07-26 23:55:294264 }
4265 }
4266
[email protected]26aa0482009-09-30 16:55:274267 webview()->setFocusedFrame(search_frame);
initial.commit09911bf2008-07-26 23:55:294268 } while (!result && search_frame != focused_frame);
4269
[email protected]7830da3e2009-11-06 16:27:264270 if (options.findNext && current_selection.isNull()) {
[email protected]4f3dc372009-02-24 00:10:294271 // Force the main_frame to report the actual count.
[email protected]dd7daa82009-08-10 05:46:454272 main_frame->increaseMatchCount(0, request_id);
[email protected]4f3dc372009-02-24 00:10:294273 } else {
4274 // If nothing is found, set result to "0 of 0", otherwise, set it to
4275 // "-1 of 1" to indicate that we found at least one item, but we don't know
4276 // yet what is active.
4277 int ordinal = result ? -1 : 0; // -1 here means, we might know more later.
4278 int match_count = result ? 1 : 0; // 1 here means possibly more coming.
initial.commit09911bf2008-07-26 23:55:294279
[email protected]4f3dc372009-02-24 00:10:294280 // If we find no matches then this will be our last status update.
4281 // Otherwise the scoping effort will send more results.
4282 bool final_status_update = !result;
initial.commit09911bf2008-07-26 23:55:294283
[email protected]4f3dc372009-02-24 00:10:294284 // Send the search result over to the browser process.
[email protected]4f999132009-03-31 18:08:404285 Send(new ViewHostMsg_Find_Reply(routing_id_,
[email protected]7ea066a2009-04-06 20:21:594286 request_id,
[email protected]4f3dc372009-02-24 00:10:294287 match_count,
4288 selection_rect,
4289 ordinal,
4290 final_status_update));
initial.commit09911bf2008-07-26 23:55:294291
initial.commit09911bf2008-07-26 23:55:294292 // Scoping effort begins, starting with the mainframe.
4293 search_frame = main_frame;
4294
[email protected]dd7daa82009-08-10 05:46:454295 main_frame->resetMatchCount();
initial.commit09911bf2008-07-26 23:55:294296
4297 do {
4298 // Cancel all old scoping requests before starting a new one.
[email protected]dd7daa82009-08-10 05:46:454299 search_frame->cancelPendingScopingEffort();
initial.commit09911bf2008-07-26 23:55:294300
4301 // We don't start another scoping effort unless at least one match has
4302 // been found.
4303 if (result) {
4304 // Start new scoping request. If the scoping function determines that it
4305 // needs to scope, it will defer until later.
[email protected]dd7daa82009-08-10 05:46:454306 search_frame->scopeStringMatches(request_id,
[email protected]7ea066a2009-04-06 20:21:594307 search_text,
4308 options,
initial.commit09911bf2008-07-26 23:55:294309 true); // reset the tickmarks
4310 }
4311
4312 // Iterate to the next frame. The frame will not necessarily scope, for
4313 // example if it is not visible.
[email protected]b4bb2502009-10-01 22:35:274314 search_frame = search_frame->traverseNext(true);
initial.commit09911bf2008-07-26 23:55:294315 } while (search_frame != main_frame);
4316 }
4317}
4318
[email protected]24a7f3c2010-03-25 08:26:494319void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) {
4320 WebView* view = webview();
4321 if (!view)
4322 return;
4323
4324 WebDocument doc = view->mainFrame()->document();
4325 if (doc.isPluginDocument()) {
[email protected]0fdbf8c2010-07-08 20:33:014326 GetWebPluginFromPluginDocument()->stopFind();
[email protected]24a7f3c2010-03-25 08:26:494327 return;
4328 }
4329
4330 bool clear_selection =
4331 params.action == ViewMsg_StopFinding_Params::kClearSelection;
4332 if (clear_selection)
4333 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"));
4334
4335 WebFrame* frame = view->mainFrame();
4336 while (frame) {
4337 frame->stopFinding(clear_selection);
4338 frame = frame->traverseNext(false);
4339 }
4340
4341 if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) {
4342 WebFrame* focused_frame = view->focusedFrame();
4343 if (focused_frame) {
4344 WebDocument doc = focused_frame->document();
4345 if (!doc.isNull()) {
4346 WebNode node = doc.focusedNode();
4347 if (!node.isNull())
4348 node.simulateClick();
4349 }
4350 }
4351 }
4352}
4353
4354void RenderView::OnFindReplyAck() {
4355 // Check if there is any queued up request waiting to be sent.
4356 if (queued_find_reply_message_.get()) {
4357 // Send the search result over to the browser process.
[email protected]d22d8732010-05-04 19:24:424358 Send(queued_find_reply_message_.release());
[email protected]24a7f3c2010-03-25 08:26:494359 }
4360}
4361
[email protected]8934a3b2010-02-25 00:34:004362bool RenderView::AllowContentType(ContentSettingsType settings_type) {
[email protected]0de80162010-02-03 04:52:354363 // CONTENT_SETTING_ASK is only valid for cookies.
[email protected]8934a3b2010-02-25 00:34:004364 return current_content_settings_.settings[settings_type] !=
4365 CONTENT_SETTING_BLOCK;
4366}
4367
[email protected]55126132010-08-19 14:53:284368void RenderView::DidBlockContentType(ContentSettingsType settings_type,
4369 const std::string& resource_identifier) {
[email protected]8934a3b2010-02-25 00:34:004370 if (!content_blocked_[settings_type]) {
4371 content_blocked_[settings_type] = true;
[email protected]55126132010-08-19 14:53:284372 Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type,
4373 resource_identifier));
[email protected]0de80162010-02-03 04:52:354374 }
[email protected]0de80162010-02-03 04:52:354375}
4376
[email protected]71b0d5d2010-02-15 05:43:074377void RenderView::ClearBlockedContentSettings() {
4378 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
4379 content_blocked_[i] = false;
4380}
4381
[email protected]0bd753682010-12-16 18:15:524382WebPlugin* RenderView::CreatePepperPlugin(
4383 WebFrame* frame,
4384 const WebPluginParams& params,
4385 const FilePath& path,
4386 webkit::ppapi::PluginModule* pepper_module) {
4387 return new webkit::ppapi::WebPluginImpl(
[email protected]b75b8292010-10-01 07:28:254388 pepper_module, params, pepper_delegate_.AsWeakPtr());
[email protected]aad51d1c2010-08-05 08:38:094389}
[email protected]00152e92010-07-19 11:47:404390
[email protected]191eb3f72010-12-21 06:27:504391WebPlugin* RenderView::CreateNPAPIPlugin(
4392 WebFrame* frame,
4393 const WebPluginParams& params,
4394 const FilePath& path,
4395 const std::string& mime_type) {
4396 return new webkit::npapi::WebPluginImpl(
[email protected]20a793e2010-10-12 06:50:084397 frame, params, path, mime_type, AsWeakPtr());
[email protected]00152e92010-07-19 11:47:404398}
4399
[email protected]3c2826852010-12-16 19:09:144400WebPlugin* RenderView::CreatePluginPlaceholder(
[email protected]57b66d02010-09-30 11:24:514401 WebFrame* frame,
4402 const WebPluginParams& params,
[email protected]191eb3f72010-12-21 06:27:504403 const webkit::npapi::PluginGroup& group,
[email protected]3c2826852010-12-16 19:09:144404 int resource_id,
[email protected]90dba072011-01-20 20:10:204405 int message_id,
4406 bool is_blocked_for_prerendering) {
[email protected]3c2826852010-12-16 19:09:144407 // |blocked_plugin| will delete itself when the WebViewPlugin
4408 // is destroyed.
4409 BlockedPlugin* blocked_plugin =
4410 new BlockedPlugin(this,
4411 frame,
4412 group,
4413 params,
4414 webkit_preferences_,
4415 resource_id,
[email protected]2e34ab3f2010-12-17 05:47:374416 l10n_util::GetStringFUTF16(message_id,
[email protected]90dba072011-01-20 20:10:204417 group.GetGroupName()),
4418 is_blocked_for_prerendering);
[email protected]3c2826852010-12-16 19:09:144419 return blocked_plugin->plugin();
[email protected]57b66d02010-09-30 11:24:514420}
4421
[email protected]40bd6582009-12-04 23:49:514422void RenderView::OnZoom(PageZoom::Function function) {
4423 if (!webview()) // Not sure if this can happen, but no harm in being safe.
4424 return;
4425
[email protected]258d31122010-05-09 10:59:414426 webview()->hidePopups();
[email protected]b03794d2010-03-26 19:57:524427
[email protected]b75b8292010-10-01 07:28:254428 double old_zoom_level = webview()->zoomLevel();
4429 double zoom_level;
4430 if (function == PageZoom::RESET) {
4431 zoom_level = 0;
4432 } else if (static_cast<int>(old_zoom_level) == old_zoom_level) {
4433 // Previous zoom level is a whole number, so just increment/decrement.
4434 zoom_level = old_zoom_level + function;
4435 } else {
4436 // Either the user hit the zoom factor limit and thus the zoom level is now
4437 // not a whole number, or a plugin changed it to a custom value. We want
4438 // to go to the next whole number so that the user can always get back to
4439 // 100% with the keyboard/menu.
4440 if ((old_zoom_level > 1 && function > 0) ||
4441 (old_zoom_level < 1 && function < 0)) {
[email protected]3209e7112010-10-01 23:53:454442 zoom_level = static_cast<int>(old_zoom_level + function);
[email protected]b75b8292010-10-01 07:28:254443 } else {
4444 // We're going towards 100%, so first go to the next whole number.
4445 zoom_level = static_cast<int>(old_zoom_level);
4446 }
4447 }
[email protected]40bd6582009-12-04 23:49:514448
[email protected]b75b8292010-10-01 07:28:254449 webview()->setZoomLevel(false, zoom_level);
4450 zoomLevelChanged();
[email protected]40bd6582009-12-04 23:49:514451}
4452
[email protected]d0b8d092010-10-25 04:05:174453void RenderView::OnSetZoomLevel(double zoom_level) {
4454 // Don't set zoom level for full-page plugin since they don't use the same
4455 // zoom settings.
4456 if (webview()->mainFrame()->document().isPluginDocument())
4457 return;
4458
4459 webview()->hidePopups();
4460 webview()->setZoomLevel(false, zoom_level);
4461 zoomLevelChanged();
4462}
4463
[email protected]9d797f32010-04-23 07:17:544464void RenderView::OnSetContentSettingsForLoadingURL(
4465 const GURL& url,
[email protected]f85f0702010-01-30 09:31:014466 const ContentSettings& content_settings) {
[email protected]9d797f32010-04-23 07:17:544467 host_content_settings_[url] = content_settings;
[email protected]f85f0702010-01-30 09:31:014468}
4469
[email protected]9d797f32010-04-23 07:17:544470void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
[email protected]b75b8292010-10-01 07:28:254471 double zoom_level) {
[email protected]9d797f32010-04-23 07:17:544472 host_zoom_levels_[url] = zoom_level;
initial.commit09911bf2008-07-26 23:55:294473}
4474
[email protected]41fc0322009-09-04 22:23:404475void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
[email protected]26aa0482009-09-30 16:55:274476 webview()->setPageEncoding(WebString::fromUTF8(encoding_name));
initial.commit09911bf2008-07-26 23:55:294477}
4478
[email protected]a697f4c2009-09-14 22:30:184479void RenderView::OnResetPageEncodingToDefault() {
[email protected]26aa0482009-09-30 16:55:274480 WebString no_encoding;
4481 webview()->setPageEncoding(no_encoding);
[email protected]a697f4c2009-09-14 22:30:184482}
4483
[email protected]20ad2692009-11-20 18:27:204484bool RenderView::GetAllChildFrames(
4485 WebFrame* parent_frame,
4486 std::vector<WebFrame*>* frames_vector) const {
4487 if (!parent_frame)
4488 return false;
4489 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame;
4490 child_frame = child_frame->nextSibling()) {
4491 frames_vector->push_back(child_frame);
4492 GetAllChildFrames(child_frame, frames_vector);
4493 }
4494 return true;
4495}
4496
[email protected]dd7daa82009-08-10 05:46:454497WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const {
4498 if (xpath.empty())
[email protected]26aa0482009-09-30 16:55:274499 return webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454500
4501 // xpath string can represent a frame deep down the tree (across multiple
4502 // frame DOMs).
4503 // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0]
4504 // should break into 2 xpaths
4505 // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0]
4506
[email protected]26aa0482009-09-30 16:55:274507 WebFrame* frame = webview()->mainFrame();
[email protected]dd7daa82009-08-10 05:46:454508
4509 std::wstring xpath_remaining = xpath;
4510 while (!xpath_remaining.empty()) {
4511 std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n');
4512 std::wstring xpath_child;
4513 if (delim_pos != std::wstring::npos) {
4514 xpath_child = xpath_remaining.substr(0, delim_pos);
4515 xpath_remaining.erase(0, delim_pos + 1);
4516 } else {
4517 xpath_remaining.swap(xpath_child);
4518 }
4519 frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child));
initial.commit09911bf2008-07-26 23:55:294520 }
4521
[email protected]dd7daa82009-08-10 05:46:454522 return frame;
initial.commit09911bf2008-07-26 23:55:294523}
4524
[email protected]ce833282010-11-04 15:48:394525void RenderView::SetSuggestions(const std::vector<std::string>& suggestions) {
4526 // Explicitly allow empty vector to be sent to the browser.
4527 Send(new ViewHostMsg_SetSuggestions(routing_id_, page_id_, suggestions));
[email protected]15d9c0c2010-09-10 22:36:264528}
4529
[email protected]882b7b22010-10-05 03:34:534530void RenderView::EvaluateScript(const string16& frame_xpath,
4531 const string16& script,
4532 int id,
4533 bool notify_result) {
4534 v8::Handle<v8::Value> result;
4535 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
4536 if (web_frame)
4537 result = web_frame->executeScriptAndReturnValue(WebScriptSource(script));
4538 if (notify_result) {
[email protected]81f9fe0b2010-12-07 00:35:294539 ListValue list;
4540 if (web_frame) {
4541 v8::HandleScope handle_scope;
4542 v8::Local<v8::Context> context = web_frame->mainWorldScriptContext();
4543 v8::Context::Scope context_scope(context);
4544 list.Set(0, ConvertV8Value(result));
4545 } else {
4546 list.Set(0, Value::CreateNullValue());
4547 }
4548 Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, list));
[email protected]882b7b22010-10-05 03:34:534549 }
initial.commit09911bf2008-07-26 23:55:294550}
4551
[email protected]1810e132009-03-24 23:35:484552void RenderView::InsertCSS(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084553 const std::string& css,
4554 const std::string& id) {
[email protected]1810e132009-03-24 23:35:484555 WebFrame* web_frame = GetChildFrame(frame_xpath);
4556 if (!web_frame)
4557 return;
4558
[email protected]ffaef0c2009-09-15 17:08:084559 web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id));
[email protected]1810e132009-03-24 23:35:484560}
4561
[email protected]00c39612010-03-06 02:53:284562void RenderView::OnPepperPluginDestroy(
4563 WebPluginDelegatePepper* pepper_plugin) {
4564 std::set<WebPluginDelegatePepper*>::iterator found_pepper =
[email protected]53900d52010-06-16 04:25:014565 current_oldstyle_pepper_plugins_.find(pepper_plugin);
4566 if (found_pepper == current_oldstyle_pepper_plugins_.end()) {
[email protected]00c39612010-03-06 02:53:284567 NOTREACHED();
4568 return;
4569 }
[email protected]53900d52010-06-16 04:25:014570 current_oldstyle_pepper_plugins_.erase(found_pepper);
[email protected]cdaf8d02010-03-30 19:52:474571
4572 // The plugin could have been destroyed while it was waiting for a file
4573 // choose callback, so check all pending completion callbacks and NULL them.
4574 for (std::deque< linked_ptr<PendingFileChooser> >::iterator i =
4575 file_chooser_completions_.begin();
4576 i != file_chooser_completions_.end(); /* nothing */) {
4577 if ((*i)->completion == pepper_plugin) {
4578 // We NULL the first one instead of deleting it because the plugin might
4579 // be the one waiting for a file choose callback. If the callback later
4580 // comes, we don't want to send the result to the next callback in line.
4581 if (i == file_chooser_completions_.begin())
4582 (*i)->completion = NULL;
4583 else
4584 i = file_chooser_completions_.erase(i);
4585 } else {
4586 ++i;
4587 }
4588 }
[email protected]00c39612010-03-06 02:53:284589}
4590
[email protected]882b7b22010-10-05 03:34:534591void RenderView::OnScriptEvalRequest(const string16& frame_xpath,
4592 const string16& jscript,
4593 int id,
4594 bool notify_result) {
4595 EvaluateScript(frame_xpath, jscript, id, notify_result);
initial.commit09911bf2008-07-26 23:55:294596}
4597
[email protected]1810e132009-03-24 23:35:484598void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath,
[email protected]ffaef0c2009-09-15 17:08:084599 const std::string& css,
4600 const std::string& id) {
4601 InsertCSS(frame_xpath, css, id);
[email protected]ae461542009-06-19 19:03:414602
4603 // Notify RenderViewHost that css has been inserted into the frame.
4604 Send(new ViewHostMsg_OnCSSInserted(routing_id_));
[email protected]1810e132009-03-24 23:35:484605}
4606
[email protected]7ea066a2009-04-06 20:21:594607void RenderView::OnAddMessageToConsole(
4608 const string16& frame_xpath,
4609 const string16& message,
4610 const WebConsoleMessage::Level& level) {
4611 WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath));
[email protected]0dea3ea2009-03-31 23:30:594612 if (web_frame)
[email protected]dd7daa82009-08-10 05:46:454613 web_frame->addMessageToConsole(WebConsoleMessage(level, message));
initial.commit09911bf2008-07-26 23:55:294614}
4615
[email protected]81e63782009-02-27 19:35:094616void RenderView::OnAllowBindings(int enabled_bindings_flags) {
4617 enabled_bindings_ |= enabled_bindings_flags;
initial.commit09911bf2008-07-26 23:55:294618}
4619
4620void RenderView::OnSetDOMUIProperty(const std::string& name,
4621 const std::string& value) {
[email protected]81e63782009-02-27 19:35:094622 DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_));
[email protected]c091c2c2010-09-17 19:05:464623 GetDOMUIBindings()->SetProperty(name, value);
initial.commit09911bf2008-07-26 23:55:294624}
4625
4626void RenderView::OnReservePageIDRange(int size_of_range) {
4627 next_page_id_ += size_of_range + 1;
4628}
4629
[email protected]e80c73b2009-04-07 23:24:584630void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point,
4631 const gfx::Point& screen_point,
[email protected]1d9f4132009-09-08 17:29:254632 bool ended,
4633 WebDragOperation op) {
[email protected]5f9ae6c2009-07-08 02:38:034634 if (ended) {
[email protected]26aa0482009-09-30 16:55:274635 webview()->dragSourceEndedAt(client_point, screen_point, op);
[email protected]daec5d62010-06-04 09:14:204636 } else {
4637 webview()->dragSourceMovedTo(client_point, screen_point, op);
[email protected]5f9ae6c2009-07-08 02:38:034638 }
initial.commit09911bf2008-07-26 23:55:294639}
4640
4641void RenderView::OnDragSourceSystemDragEnded() {
[email protected]26aa0482009-09-30 16:55:274642 webview()->dragSourceSystemDragEnded();
initial.commit09911bf2008-07-26 23:55:294643}
4644
initial.commit09911bf2008-07-26 23:55:294645void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data,
[email protected]e80c73b2009-04-07 23:24:584646 const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254647 const gfx::Point& screen_point,
4648 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274649 WebDragOperation operation = webview()->dragTargetDragEnter(
[email protected]e80c73b2009-04-07 23:24:584650 drop_data.ToDragData(),
4651 drop_data.identity,
4652 client_point,
[email protected]1d9f4132009-09-08 17:29:254653 screen_point,
4654 ops);
initial.commit09911bf2008-07-26 23:55:294655
[email protected]1d9f4132009-09-08 17:29:254656 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294657}
4658
[email protected]e80c73b2009-04-07 23:24:584659void RenderView::OnDragTargetDragOver(const gfx::Point& client_point,
[email protected]1d9f4132009-09-08 17:29:254660 const gfx::Point& screen_point,
4661 WebDragOperationsMask ops) {
[email protected]26aa0482009-09-30 16:55:274662 WebDragOperation operation = webview()->dragTargetDragOver(
[email protected]1d9f4132009-09-08 17:29:254663 client_point,
4664 screen_point,
4665 ops);
initial.commit09911bf2008-07-26 23:55:294666
[email protected]1d9f4132009-09-08 17:29:254667 Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation));
initial.commit09911bf2008-07-26 23:55:294668}
4669
4670void RenderView::OnDragTargetDragLeave() {
[email protected]26aa0482009-09-30 16:55:274671 webview()->dragTargetDragLeave();
initial.commit09911bf2008-07-26 23:55:294672}
4673
[email protected]e80c73b2009-04-07 23:24:584674void RenderView::OnDragTargetDrop(const gfx::Point& client_point,
4675 const gfx::Point& screen_point) {
[email protected]26aa0482009-09-30 16:55:274676 webview()->dragTargetDrop(client_point, screen_point);
initial.commit09911bf2008-07-26 23:55:294677}
4678
4679void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) {
[email protected]2fab253a2009-08-17 23:00:594680 webkit_preferences_ = prefs;
4681 webkit_preferences_.Apply(webview());
initial.commit09911bf2008-07-26 23:55:294682}
4683
4684void RenderView::OnSetAltErrorPageURL(const GURL& url) {
4685 alternate_error_page_url_ = url;
4686}
4687
[email protected]a0c7153e2009-12-09 14:36:334688void RenderView::OnCustomContextMenuAction(unsigned action) {
[email protected]5ee0cfd02011-01-18 05:42:224689 webview()->performCustomContextMenuAction(action);
[email protected]a0c7153e2009-12-09 14:36:334690}
4691
[email protected]d4a00a72010-01-29 01:44:424692void RenderView::OnTranslatePage(int page_id,
[email protected]85d252e2010-04-06 22:21:024693 const std::string& translate_script,
[email protected]d4a00a72010-01-29 01:44:424694 const std::string& source_lang,
4695 const std::string& target_lang) {
[email protected]85d252e2010-04-06 22:21:024696 translate_helper_.TranslatePage(page_id, source_lang, target_lang,
4697 translate_script);
[email protected]d4a00a72010-01-29 01:44:424698}
4699
[email protected]85d252e2010-04-06 22:21:024700void RenderView::OnRevertTranslation(int page_id) {
4701 translate_helper_.RevertTranslation(page_id);
[email protected]0bedb8a2010-01-14 19:36:324702}
4703
initial.commit09911bf2008-07-26 23:55:294704void RenderView::OnInstallMissingPlugin() {
4705 // This could happen when the first default plugin is deleted.
[email protected]f103ab72009-09-02 17:10:594706 if (first_default_plugin_)
4707 first_default_plugin_->InstallMissingPlugin();
initial.commit09911bf2008-07-26 23:55:294708}
4709
[email protected]90dba072011-01-20 20:10:204710void RenderView::OnDisplayPrerenderedPage() {
4711 NavigationState* navigation_state = pending_navigation_state_.get();
4712 if (!navigation_state) {
4713 WebDataSource* ds = webview()->mainFrame()->dataSource();
4714 navigation_state = NavigationState::FromDataSource(ds);
4715 }
4716
4717 DCHECK(navigation_state->is_prerendering());
4718 navigation_state->set_is_prerendering(false);
4719}
4720
[email protected]cdaf8d02010-03-30 19:52:474721void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) {
[email protected]8029f5672009-03-20 22:33:364722 // This could happen if we navigated to a different page before the user
4723 // closed the chooser.
[email protected]cdaf8d02010-03-30 19:52:474724 if (file_chooser_completions_.empty())
[email protected]8029f5672009-03-20 22:33:364725 return;
4726
[email protected]cdaf8d02010-03-30 19:52:474727 WebVector<WebString> ws_file_names(paths.size());
4728 for (size_t i = 0; i < paths.size(); ++i)
4729 ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]);
[email protected]a1128322009-10-06 18:38:464730
[email protected]cdaf8d02010-03-30 19:52:474731 if (file_chooser_completions_.front()->completion)
4732 file_chooser_completions_.front()->completion->didChooseFile(ws_file_names);
4733 file_chooser_completions_.pop_front();
4734
4735 // If there are more pending file chooser requests, schedule one now.
4736 if (!file_chooser_completions_.empty()) {
4737 Send(new ViewHostMsg_RunFileChooser(routing_id_,
4738 file_chooser_completions_.front()->params));
4739 }
initial.commit09911bf2008-07-26 23:55:294740}
4741
4742void RenderView::OnEnableViewSourceMode() {
4743 if (!webview())
4744 return;
[email protected]26aa0482009-09-30 16:55:274745 WebFrame* main_frame = webview()->mainFrame();
initial.commit09911bf2008-07-26 23:55:294746 if (!main_frame)
4747 return;
4748
[email protected]dd7daa82009-08-10 05:46:454749 main_frame->enableViewSourceMode(true);
initial.commit09911bf2008-07-26 23:55:294750}
4751
[email protected]770dd8b2010-05-24 18:11:394752void RenderView::OnEnablePreferredSizeChangedMode(int flags) {
4753 DCHECK(flags != kPreferredSizeNothing);
[email protected]9fb325e2010-05-06 18:23:244754 if (send_preferred_size_changes_)
4755 return;
[email protected]9fb325e2010-05-06 18:23:244756 send_preferred_size_changes_ = true;
[email protected]770dd8b2010-05-24 18:11:394757
4758 // WebKit doesn't send a notification of the effective height of the page
4759 // changes, so poll for it.
4760 // TODO: Add a notification for this to WebKit, remove polling. After that's
4761 // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight.
4762 // http://crbug.com/44850
4763 if (flags & kPreferredSizeHeightThisIsSlow) {
4764 preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this,
4765 &RenderView::CheckPreferredSize);
4766 }
[email protected]0666aef2009-05-13 19:48:084767}
4768
[email protected]ce833282010-11-04 15:48:394769void RenderView::OnSearchBoxChange(const string16& value,
[email protected]368ef4c2010-11-08 21:58:464770 bool verbatim,
[email protected]ce833282010-11-04 15:48:394771 int selection_start,
4772 int selection_end) {
4773 search_box_.value = value;
[email protected]368ef4c2010-11-08 21:58:464774 search_box_.verbatim = verbatim;
[email protected]ce833282010-11-04 15:48:394775 search_box_.selection_start = selection_start;
4776 search_box_.selection_end = selection_end;
4777 if (!webview() || !webview()->mainFrame())
4778 return;
4779 extensions_v8::SearchBoxExtension::DispatchChange(webview()->mainFrame());
4780}
4781
4782void RenderView::OnSearchBoxSubmit(const string16& value, bool verbatim) {
4783 search_box_.value = value;
4784 search_box_.verbatim = verbatim;
4785 if (!webview() || !webview()->mainFrame())
4786 return;
4787 extensions_v8::SearchBoxExtension::DispatchSubmit(webview()->mainFrame());
4788}
4789
4790void RenderView::OnSearchBoxCancel() {
4791 search_box_.verbatim = false;
4792 if (!webview() || !webview()->mainFrame())
4793 return;
4794 extensions_v8::SearchBoxExtension::DispatchCancel(webview()->mainFrame());
4795}
4796
4797void RenderView::OnSearchBoxResize(const gfx::Rect& bounds) {
4798 search_box_.x = bounds.x();
4799 search_box_.y = bounds.y();
4800 search_box_.width = bounds.width();
4801 search_box_.height = bounds.height();
4802 if (!webview() || !webview()->mainFrame())
4803 return;
4804 extensions_v8::SearchBoxExtension::DispatchResize(webview()->mainFrame());
4805}
4806
[email protected]57ad7b8c2010-11-18 19:13:494807void RenderView::OnDetermineIfPageSupportsInstant(const string16& value,
[email protected]0d5ab152011-01-14 23:09:044808 bool verbatim,
4809 int selection_start,
4810 int selection_end) {
[email protected]ce833282010-11-04 15:48:394811 search_box_.value = value;
[email protected]57ad7b8c2010-11-18 19:13:494812 search_box_.verbatim = verbatim;
[email protected]0d5ab152011-01-14 23:09:044813 search_box_.selection_start = selection_start;
4814 search_box_.selection_end = selection_end;
[email protected]ce833282010-11-04 15:48:394815 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
4816 webview()->mainFrame());
4817 Send(new ViewHostMsg_InstantSupportDetermined(routing_id_, page_id_, result));
4818}
4819
[email protected]cda45c02010-02-25 19:28:104820void RenderView::OnDisableScrollbarsForSmallWindows(
4821 const gfx::Size& disable_scrollbar_size_limit) {
4822 disable_scrollbars_size_limit_ = disable_scrollbar_size_limit;
4823}
4824
[email protected]80d96fa2009-06-10 22:34:514825void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) {
4826 renderer_preferences_ = renderer_prefs;
[email protected]6e282c92009-07-24 01:19:374827 UpdateFontRenderingFromRendererPrefs();
[email protected]0dd6f9b52010-10-14 16:39:134828#if defined(TOOLKIT_USES_GTK)
[email protected]1c83eb42009-09-11 21:08:414829 WebColorName name = WebKit::WebColorWebkitFocusRingColor;
4830 WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1);
[email protected]39cd64ed2010-02-05 02:18:464831 WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval);
[email protected]8d1b864d12010-10-10 00:04:344832 gfx::NativeThemeLinux::instance()->SetScrollbarColors(
4833 renderer_prefs.thumb_inactive_color,
4834 renderer_prefs.thumb_active_color,
4835 renderer_prefs.track_color);
[email protected]93623c5d2009-12-10 21:40:324836
[email protected]644d77e2010-01-27 01:03:104837 if (webview()) {
[email protected]93623c5d2009-12-10 21:40:324838 webview()->setScrollbarColors(
4839 renderer_prefs.thumb_inactive_color,
4840 renderer_prefs.thumb_active_color,
4841 renderer_prefs.track_color);
[email protected]644d77e2010-01-27 01:03:104842 webview()->setSelectionColors(
4843 renderer_prefs.active_selection_bg_color,
4844 renderer_prefs.active_selection_fg_color,
4845 renderer_prefs.inactive_selection_bg_color,
4846 renderer_prefs.inactive_selection_fg_color);
[email protected]f98d7e3c2010-09-13 22:30:464847 webview()->themeChanged();
[email protected]644d77e2010-01-27 01:03:104848 }
[email protected]7a74e102009-09-03 00:16:564849#endif
[email protected]80d96fa2009-06-10 22:34:514850}
4851
[email protected]952cb702009-10-07 05:50:284852void RenderView::OnMediaPlayerActionAt(const gfx::Point& location,
4853 const WebMediaPlayerAction& action) {
4854 if (webview())
4855 webview()->performMediaPlayerAction(action, location);
[email protected]581b87eb2009-07-23 23:06:564856}
4857
[email protected]7b291f92009-08-14 05:43:534858void RenderView::OnNotifyRendererViewType(ViewType::Type type) {
4859 view_type_ = type;
4860}
4861
4862void RenderView::OnUpdateBrowserWindowId(int window_id) {
4863 browser_window_id_ = window_id;
4864}
4865
[email protected]dea2d372010-09-25 06:41:144866void RenderView::OnEnableAccessibility() {
4867 if (WebAccessibilityCache::accessibilityEnabled())
4868 return;
[email protected]9f4db512010-05-10 20:21:414869
[email protected]dea2d372010-09-25 06:41:144870 WebAccessibilityCache::enableAccessibility();
4871
4872 if (webview()) {
4873 // It's possible that the webview has already loaded a webpage without
4874 // accessibility being enabled. Initialize the browser's cached
4875 // accessibility tree by sending it a 'load complete' notification.
4876 postAccessibilityNotification(
4877 webview()->accessibilityObject(),
4878 WebKit::WebAccessibilityNotificationLoadComplete);
4879 }
[email protected]266eb6f2008-09-30 23:56:504880}
4881
[email protected]aef92842010-05-21 16:54:364882void RenderView::OnSetAccessibilityFocus(int acc_obj_id) {
4883 if (!accessibility_.get())
4884 return;
[email protected]02ea2f312010-09-27 17:03:364885
4886 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4887 WebAccessibilityObject root = webview()->accessibilityObject();
4888 if (!obj.isValid() || !root.isValid())
4889 return;
4890
4891 // By convention, calling SetFocus on the root of the tree should clear the
4892 // current focus. Otherwise set the focus to the new node.
4893 if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root))
4894 webview()->clearFocusedNode();
4895 else
4896 obj.setFocused(true);
[email protected]aef92842010-05-21 16:54:364897}
4898
4899void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) {
4900 if (!accessibility_.get())
4901 return;
[email protected]02ea2f312010-09-27 17:03:364902
4903 WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id);
4904 if (!obj.isValid())
4905 return;
4906
4907 obj.performDefaultAction();
[email protected]aef92842010-05-21 16:54:364908}
4909
[email protected]9892b472010-09-16 00:23:424910void RenderView::OnAccessibilityNotificationsAck() {
[email protected]54ec7f82010-10-21 22:32:514911 DCHECK(accessibility_ack_pending_);
4912 accessibility_ack_pending_ = false;
4913 SendPendingAccessibilityNotifications();
[email protected]520cb7d72010-08-31 11:54:314914}
4915
initial.commit09911bf2008-07-26 23:55:294916void RenderView::OnGetAllSavableResourceLinksForCurrentPage(
4917 const GURL& page_url) {
4918 // Prepare list to storage all savable resource links.
4919 std::vector<GURL> resources_list;
4920 std::vector<GURL> referrers_list;
4921 std::vector<GURL> frames_list;
4922 webkit_glue::SavableResourcesResult result(&resources_list,
4923 &referrers_list,
4924 &frames_list);
4925
[email protected]dbeb3952009-10-13 18:01:184926 if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(
4927 webview(),
4928 page_url,
4929 &result,
4930 chrome::kSavableSchemes)) {
initial.commit09911bf2008-07-26 23:55:294931 // If something is wrong when collecting all savable resource links,
4932 // send empty list to embedder(browser) to tell it failed.
4933 referrers_list.clear();
4934 resources_list.clear();
4935 frames_list.clear();
4936 }
4937
4938 // Send result of all savable resource links to embedder.
4939 Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_,
4940 resources_list,
4941 referrers_list,
4942 frames_list));
4943}
4944
4945void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks(
[email protected]f6b48532009-02-12 01:56:324946 const std::vector<GURL>& links,
[email protected]fde6714d12009-02-18 22:39:314947 const std::vector<FilePath>& local_paths,
4948 const FilePath& local_directory_name) {
[email protected]d9ec5c0f2009-12-23 11:55:074949
4950 // Convert std::vector of GURLs to WebVector<WebURL>
4951 WebVector<WebURL> weburl_links(links);
4952
4953 // Convert std::vector of std::strings to WebVector<WebString>
4954 WebVector<WebString> webstring_paths(local_paths.size());
4955 for (size_t i = 0; i < local_paths.size(); i++)
4956 webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]);
4957
4958 WebPageSerializer::serialize(webview()->mainFrame(),
4959 true, this, weburl_links, webstring_paths,
4960 webkit_glue::FilePathToWebString(
4961 local_directory_name));
initial.commit09911bf2008-07-26 23:55:294962}
4963
[email protected]d9ec5c0f2009-12-23 11:55:074964void RenderView::didSerializeDataForFrame(const WebURL& frame_url,
4965 const WebCString& data,
4966 WebPageSerializerClient::PageSerializationStatus status) {
4967 Send(new ViewHostMsg_SendSerializedHtmlData(
4968 routing_id_,
4969 frame_url,
4970 data.data(),
4971 static_cast<int32>(status)));
initial.commit09911bf2008-07-26 23:55:294972}
4973
[email protected]9b18a84f2010-06-10 15:54:044974void RenderView::OnShouldClose() {
[email protected]26aa0482009-09-30 16:55:274975 bool should_close = webview()->dispatchBeforeUnloadEvent();
[email protected]04b4a6c2008-08-02 00:44:474976 Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close));
initial.commit09911bf2008-07-26 23:55:294977}
4978
[email protected]eb6b87a2009-07-24 15:57:394979void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) {
initial.commit09911bf2008-07-26 23:55:294980 // TODO(creis): We'd rather use webview()->Close() here, but that currently
4981 // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs
4982 // in the onunload handler from appearing. For now, we're bypassing that and
4983 // calling the FrameLoader's CloseURL method directly. This should be
4984 // revisited to avoid having two ways to close a page. Having a single way
4985 // to close that can run onunload is also useful for fixing
4986 // http://b/issue?id=753080.
[email protected]a5a65ac2010-11-05 18:14:364987 // TODO(davemoore) This code should be removed once willClose() gets
4988 // called when a page is destroyed. page_load_histograms_.Dump() is safe
4989 // to call multiple times for the same frame, but it will simplify things.
4990 page_load_histograms_.Dump(webview()->mainFrame());
4991 page_load_histograms_.ResetCrossFramePropertyAccess();
[email protected]26aa0482009-09-30 16:55:274992 webview()->dispatchUnloadEvent();
initial.commit09911bf2008-07-26 23:55:294993
[email protected]eb6b87a2009-07-24 15:57:394994 // Just echo back the params in the ACK.
4995 Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params));
initial.commit09911bf2008-07-26 23:55:294996}
4997
4998void RenderView::OnThemeChanged() {
[email protected]6c8afae52009-01-22 02:24:574999#if defined(OS_WIN)
initial.commit09911bf2008-07-26 23:55:295000 gfx::NativeTheme::instance()->CloseHandles();
[email protected]f98d7e3c2010-09-13 22:30:465001 if (webview())
5002 webview()->themeChanged();
[email protected]6c8afae52009-01-22 02:24:575003#else // defined(OS_WIN)
5004 // TODO(port): we don't support theming on non-Windows platforms yet
5005 NOTIMPLEMENTED();
5006#endif
initial.commit09911bf2008-07-26 23:55:295007}
5008
[email protected]9b18a84f2010-06-10 15:54:045009void RenderView::OnHandleMessageFromExternalHost(const std::string& message,
5010 const std::string& origin,
5011 const std::string& target) {
[email protected]3ac14a052008-08-15 21:22:155012 if (message.empty())
5013 return;
[email protected]c091c2c2010-09-17 19:05:465014 GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin,
5015 target);
[email protected]3ac14a052008-08-15 21:22:155016}
5017
[email protected]0aa55312008-10-17 21:53:085018void RenderView::OnDisassociateFromPopupCount() {
5019 if (decrement_shared_popup_at_destruction_)
5020 shared_popup_counter_->data--;
5021 shared_popup_counter_ = new SharedRenderViewCounter(0);
5022 decrement_shared_popup_at_destruction_ = false;
5023}
5024
[email protected]15d79e12009-08-02 19:23:455025bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame,
5026 const WebURLError& error,
5027 bool replace) {
5028 // We only show alternate error pages in the main frame. They are
5029 // intended to assist the user when navigating, so there is not much
5030 // value in showing them for failed subframes. Ideally, we would be
5031 // able to use the TYPED transition type for this, but that flag is
5032 // not preserved across page reloads.
[email protected]dd7daa82009-08-10 05:46:455033 if (frame->parent())
[email protected]15d79e12009-08-02 19:23:455034 return false;
5035
5036 // Use the alternate error page service if this is a DNS failure or
[email protected]c53976d52009-08-07 18:58:375037 // connection failure.
[email protected]15d79e12009-08-02 19:23:455038 int ec = error.reason;
5039 if (ec != net::ERR_NAME_NOT_RESOLVED &&
5040 ec != net::ERR_CONNECTION_FAILED &&
5041 ec != net::ERR_CONNECTION_REFUSED &&
5042 ec != net::ERR_ADDRESS_UNREACHABLE &&
[email protected]c53976d52009-08-07 18:58:375043 ec != net::ERR_CONNECTION_TIMED_OUT)
[email protected]15d79e12009-08-02 19:23:455044 return false;
5045
5046 const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL,
[email protected]7ccddb8c2009-08-04 17:36:555047 ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR);
[email protected]15d79e12009-08-02 19:23:455048 if (!error_page_url.is_valid())
5049 return false;
5050
5051 // Load an empty page first so there is an immediate response to the error,
5052 // and then kick off a request for the alternate error page.
[email protected]dd7daa82009-08-10 05:46:455053 frame->loadHTMLString(std::string(),
[email protected]144143c2010-10-28 08:17:365054 GURL(chrome::kUnreachableWebDataURL),
[email protected]15d79e12009-08-02 19:23:455055 error.unreachableURL,
5056 replace);
5057
5058 // Now, create a fetcher for the error page and associate it with the data
5059 // source we just created via the LoadHTMLString call. That way if another
5060 // navigation occurs, the fetcher will get destroyed.
5061 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455062 NavigationState::FromDataSource(frame->provisionalDataSource());
[email protected]15d79e12009-08-02 19:23:455063 navigation_state->set_alt_error_page_fetcher(
5064 new AltErrorPageResourceFetcher(
5065 error_page_url, frame, error,
5066 NewCallback(this, &RenderView::AltErrorPageFinished)));
5067 return true;
5068}
5069
initial.commit09911bf2008-07-26 23:55:295070std::string RenderView::GetAltHTMLForTemplate(
5071 const DictionaryValue& error_strings, int template_resource_id) const {
[email protected]8a16266e2009-09-10 21:08:395072 const base::StringPiece template_html(
initial.commit09911bf2008-07-26 23:55:295073 ResourceBundle::GetSharedInstance().GetRawDataResource(
5074 template_resource_id));
5075
5076 if (template_html.empty()) {
5077 NOTREACHED() << "unable to load template. ID: " << template_resource_id;
5078 return "";
5079 }
[email protected]7cd22a52009-07-14 00:40:255080
initial.commit09911bf2008-07-26 23:55:295081 // "t" is the id of the templates root node.
[email protected]7cd22a52009-07-14 00:40:255082 return jstemplate_builder::GetTemplatesHtml(
initial.commit09911bf2008-07-26 23:55:295083 template_html, &error_strings, "t");
5084}
[email protected]0e79b9e2009-02-13 04:20:485085
[email protected]15d79e12009-08-02 19:23:455086void RenderView::AltErrorPageFinished(WebFrame* frame,
5087 const WebURLError& original_error,
5088 const std::string& html) {
5089 // Here, we replace the blank page we loaded previously.
[email protected]7ccddb8c2009-08-04 17:36:555090
5091 // If we failed to download the alternate error page, fall back to the
5092 // original error page if present. Otherwise, LoadNavigationErrorPage
5093 // will simply display a default error page.
5094 const std::string* html_to_load = &html;
5095 if (html.empty()) {
5096 NavigationState* navigation_state =
[email protected]dd7daa82009-08-10 05:46:455097 NavigationState::FromDataSource(frame->dataSource());
[email protected]7ccddb8c2009-08-04 17:36:555098 html_to_load = &navigation_state->postponed_data();
5099 }
[email protected]3f853a52010-09-13 19:15:085100 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
5101 true);
[email protected]15d79e12009-08-02 19:23:455102}
5103
[email protected]30f75e62009-02-25 22:01:005104void RenderView::OnMoveOrResizeStarted() {
5105 if (webview())
[email protected]a72a1fa2010-05-03 22:18:475106 webview()->hidePopups();
[email protected]30f75e62009-02-25 22:01:005107}
5108
[email protected]30f75e62009-02-25 22:01:005109void RenderView::OnResize(const gfx::Size& new_size,
5110 const gfx::Rect& resizer_rect) {
[email protected]cda45c02010-02-25 19:28:105111 if (webview()) {
[email protected]a72a1fa2010-05-03 22:18:475112 webview()->hidePopups();
[email protected]cda45c02010-02-25 19:28:105113 if (send_preferred_size_changes_) {
[email protected]7339cd22010-10-27 00:11:205114 webview()->mainFrame()->setCanHaveScrollbars(
5115 should_display_scrollbars(new_size.width(), new_size.height()));
[email protected]cda45c02010-02-25 19:28:105116 }
5117 }
5118
[email protected]30f75e62009-02-25 22:01:005119 RenderWidget::OnResize(new_size, resizer_rect);
5120}
[email protected]0aa477bd2009-03-23 22:21:435121
[email protected]00c39612010-03-06 02:53:285122void RenderView::DidInitiatePaint() {
[email protected]53900d52010-06-16 04:25:015123 // Notify the pepper plugins that we started painting.
5124 pepper_delegate_.ViewInitiatedPaint();
5125
5126 // Notify any "old-style" pepper plugins that we started painting. This is
5127 // used for internal bookkeeping only, so we know that the set can not change
5128 // under us.
[email protected]00c39612010-03-06 02:53:285129 for (std::set<WebPluginDelegatePepper*>::iterator i =
[email protected]53900d52010-06-16 04:25:015130 current_oldstyle_pepper_plugins_.begin();
5131 i != current_oldstyle_pepper_plugins_.end(); ++i)
[email protected]00c39612010-03-06 02:53:285132 (*i)->RenderViewInitiatedPaint();
5133}
5134
5135void RenderView::DidFlushPaint() {
5136 // Notify any pepper plugins that we painted. This will call into the plugin,
5137 // and we it may ask to close itself as a result. This will, in turn, modify
5138 // our set, possibly invalidating the iterator. So we iterate on a copy that
5139 // won't change out from under us.
[email protected]53900d52010-06-16 04:25:015140 pepper_delegate_.ViewFlushedPaint();
5141
5142 // Notify any old-style pepper plugins that we painted. This will call into
5143 // the plugin, and we it may ask to close itself as a result. This will, in
5144 // turn, modify our set, possibly invalidating the iterator. So we iterate on
5145 // a copy that won't change out from under us.
5146 // This should be deleted when we don't support old Pepper anymore.
5147 std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_;
[email protected]00c39612010-03-06 02:53:285148 for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin();
5149 i != plugins.end(); ++i) {
5150 // The copy above makes sure our iterator is never invalid if some plugins
5151 // are destroyed. But some plugin may decide to close all of its views in
5152 // response to a paint in one of them, so we need to make sure each one is
5153 // still "current" before using it.
[email protected]53900d52010-06-16 04:25:015154 if (current_oldstyle_pepper_plugins_.find(*i) !=
5155 current_oldstyle_pepper_plugins_.end())
[email protected]00c39612010-03-06 02:53:285156 (*i)->RenderViewFlushedPaint();
5157 }
5158
5159 WebFrame* main_frame = webview()->mainFrame();
5160
5161 // If we have a provisional frame we are between the start and commit stages
5162 // of loading and we don't want to save stats.
5163 if (!main_frame->provisionalDataSource()) {
5164 WebDataSource* ds = main_frame->dataSource();
5165 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5166 DCHECK(navigation_state);
5167
[email protected]05c8e502010-08-15 15:13:525168 // TODO(jar): The following code should all be inside a method, probably in
5169 // NavigatorState.
[email protected]00c39612010-03-06 02:53:285170 Time now = Time::Now();
5171 if (navigation_state->first_paint_time().is_null()) {
5172 navigation_state->set_first_paint_time(now);
5173 }
5174 if (navigation_state->first_paint_after_load_time().is_null() &&
5175 !navigation_state->finish_load_time().is_null()) {
5176 navigation_state->set_first_paint_after_load_time(now);
5177 }
5178 }
5179}
5180
[email protected]719b36f2010-12-22 20:36:465181webkit::ppapi::PluginInstance* RenderView::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:155182 const gfx::Rect& paint_bounds,
5183 TransportDIB** dib,
5184 gfx::Rect* location,
5185 gfx::Rect* clip) {
5186 return pepper_delegate_.GetBitmapForOptimizedPluginPaint(
5187 paint_bounds, dib, location, clip);
5188}
5189
[email protected]d54169e92011-01-21 09:19:525190gfx::Size RenderView::GetScrollOffset() {
5191 WebKit::WebSize scroll_offset = webview()->mainFrame()->scrollOffset();
5192 return gfx::Size(scroll_offset.width, scroll_offset.height);
5193}
5194
[email protected]05d478752009-04-08 23:38:165195void RenderView::OnClearFocusedNode() {
5196 if (webview())
[email protected]26aa0482009-09-30 16:55:275197 webview()->clearFocusedNode();
[email protected]05d478752009-04-08 23:38:165198}
5199
[email protected]699ab0d2009-04-23 23:19:145200void RenderView::OnSetBackground(const SkBitmap& background) {
5201 if (webview())
[email protected]b4bb2502009-10-01 22:35:275202 webview()->setIsTransparent(!background.empty());
[email protected]699ab0d2009-04-23 23:19:145203
5204 SetBackground(background);
5205}
5206
[email protected]8c66c5a2009-07-22 17:26:345207void RenderView::OnSetActive(bool active) {
5208 if (webview())
[email protected]b4bb2502009-10-01 22:35:275209 webview()->setIsActive(active);
[email protected]d8fd6fa2010-02-01 15:54:265210
5211#if defined(OS_MACOSX)
5212 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5213 for (plugin_it = plugin_delegates_.begin();
5214 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5215 (*plugin_it)->SetWindowFocus(active);
5216 }
5217#endif
[email protected]8c66c5a2009-07-22 17:26:345218}
5219
[email protected]6ce7abc52010-02-02 18:40:145220#if defined(OS_MACOSX)
5221void RenderView::OnSetWindowVisibility(bool visible) {
5222 // Inform plugins that their container has changed visibility.
5223 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5224 for (plugin_it = plugin_delegates_.begin();
5225 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5226 (*plugin_it)->SetContainerVisibility(visible);
5227 }
5228}
[email protected]1e6e3c992010-02-08 15:52:135229
[email protected]4d51d5bf2010-07-26 18:48:265230void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame,
5231 const gfx::Rect& view_frame) {
[email protected]1e6e3c992010-02-08 15:52:135232 // Inform plugins that their window's frame has changed.
5233 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5234 for (plugin_it = plugin_delegates_.begin();
5235 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5236 (*plugin_it)->WindowFrameChanged(window_frame, view_frame);
5237 }
5238}
[email protected]935d63d2010-10-15 23:31:555239
[email protected]b7f75862011-01-21 21:15:135240void RenderView::OnPluginImeCompositionCompleted(const string16& text,
[email protected]935d63d2010-10-15 23:31:555241 int plugin_id) {
[email protected]b7f75862011-01-21 21:15:135242 // WebPluginDelegateProxy is responsible for figuring out if this event
[email protected]935d63d2010-10-15 23:31:555243 // applies to it or not, so inform all the delegates.
5244 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5245 for (plugin_it = plugin_delegates_.begin();
5246 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]b7f75862011-01-21 21:15:135247 (*plugin_it)->ImeCompositionCompleted(text, plugin_id);
[email protected]935d63d2010-10-15 23:31:555248 }
5249}
[email protected]6ce7abc52010-02-02 18:40:145250#endif // OS_MACOSX
5251
[email protected]8b8e7c92010-08-19 18:05:565252void RenderView::SendExtensionRequest(
5253 const ViewHostMsg_DomMessage_Params& params) {
5254 Send(new ViewHostMsg_ExtensionRequest(routing_id_, params));
[email protected]309d7a282009-03-24 09:18:275255}
5256
[email protected]c6619182009-05-12 14:59:325257void RenderView::OnExtensionResponse(int request_id,
5258 bool success,
5259 const std::string& response,
5260 const std::string& error) {
[email protected]0f6053962009-07-09 19:26:355261 ExtensionProcessBindings::HandleResponse(
5262 request_id, success, response, error);
[email protected]309d7a282009-03-24 09:18:275263}
[email protected]c20210e62009-04-03 21:39:265264
[email protected]a7ab1b782010-10-21 23:24:165265void RenderView::OnExtensionMessageInvoke(const std::string& extension_id,
5266 const std::string& function_name,
[email protected]d7259472010-03-24 08:40:495267 const ListValue& args,
[email protected]a807bbe2010-04-14 10:51:195268 const GURL& event_url) {
[email protected]d7259472010-03-24 08:40:495269 RendererExtensionBindings::Invoke(
[email protected]a7ab1b782010-10-21 23:24:165270 extension_id, function_name, args, this, event_url);
[email protected]7120f132009-07-20 21:05:375271}
5272
[email protected]9892b472010-09-16 00:23:425273void RenderView::postAccessibilityNotification(
5274 const WebAccessibilityObject& obj,
5275 WebAccessibilityNotification notification) {
[email protected]dea2d372010-09-25 06:41:145276 if (!accessibility_.get() && webview()) {
5277 // Load complete should be our first notification sent.
5278 // TODO(ctguil): Investigate if a different notification is a WebCore bug.
5279 if (notification != WebKit::WebAccessibilityNotificationLoadComplete)
5280 return;
5281
5282 // Create and initialize our accessibility cache
5283 accessibility_.reset(WebAccessibilityCache::create());
5284 accessibility_->initialize(webview());
5285 }
5286
[email protected]a3fa4f92010-09-30 22:19:335287 if (!accessibility_->isCached(obj)) {
5288 // The browser doesn't know about objects that are not in the cache. Send a
5289 // children change for the first accestor that actually is in the cache.
5290 WebAccessibilityObject parent = obj;
5291 while (parent.isValid() && !accessibility_->isCached(parent))
5292 parent = parent.parentObject();
5293
5294 DCHECK(parent.isValid() && accessibility_->isCached(parent));
5295 if (!parent.isValid())
5296 return;
5297 postAccessibilityNotification(
5298 parent, WebKit::WebAccessibilityNotificationChildrenChanged);
5299
5300 // The parent's children change takes care of the child's children change.
5301 if (notification == WebKit::WebAccessibilityNotificationChildrenChanged)
5302 return;
5303 }
5304
[email protected]dea2d372010-09-25 06:41:145305 // Add the accessibility object to our cache and ensure it's valid.
[email protected]54ec7f82010-10-21 22:32:515306 RendererAccessibilityNotification acc_notification;
5307 acc_notification.id = accessibility_->addOrGetId(obj);
5308 if (acc_notification.id < 0)
[email protected]a3018be2010-03-09 04:28:485309 return;
5310
[email protected]54ec7f82010-10-21 22:32:515311 if (!WebAccessibilityNotificationToViewHostMsg(
5312 notification,
5313 &acc_notification.type)) {
5314 return;
5315 }
5316
5317 // Discard duplicate accessibility notifications.
5318 for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) {
5319 if (pending_accessibility_notifications_[i].id == acc_notification.id &&
5320 pending_accessibility_notifications_[i].type == acc_notification.type) {
[email protected]9892b472010-09-16 00:23:425321 return;
[email protected]54ec7f82010-10-21 22:32:515322 }
[email protected]9892b472010-09-16 00:23:425323 }
[email protected]54ec7f82010-10-21 22:32:515324 pending_accessibility_notifications_.push_back(acc_notification);
[email protected]a3018be2010-03-09 04:28:485325
[email protected]54ec7f82010-10-21 22:32:515326 if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) {
5327 // When no accessibility notifications are in-flight post a task to send
5328 // the notifications to the browser. We use PostTask so that we can queue
5329 // up additional notifications.
5330 MessageLoop::current()->PostTask(
5331 FROM_HERE,
5332 accessibility_method_factory_.NewRunnableMethod(
5333 &RenderView::SendPendingAccessibilityNotifications));
[email protected]520cb7d72010-08-31 11:54:315334 }
[email protected]520cb7d72010-08-31 11:54:315335}
5336
[email protected]c7a827e2011-01-21 00:27:015337void RenderView::OnPrint(bool is_preview) {
5338 DCHECK(webview());
5339 if (webview()) {
5340 // If the user has selected text in the currently focused frame we print
5341 // only that frame (this makes print selection work for multiple frames).
5342 if (webview()->focusedFrame()->hasSelection())
5343 Print(webview()->focusedFrame(), false, is_preview);
5344 else
5345 Print(webview()->mainFrame(), false, is_preview);
5346 }
5347}
5348
[email protected]212a49d2010-10-25 18:23:475349void RenderView::Print(WebFrame* frame,
5350 bool script_initiated,
5351 bool is_preview) {
[email protected]0fda7272009-06-26 15:49:335352 DCHECK(frame);
[email protected]521b2482011-01-15 00:10:105353 GetPrintWebViewHelper()->PrintFrame(frame, script_initiated, is_preview);
5354}
5355
5356PrintWebViewHelper* RenderView::GetPrintWebViewHelper() {
5357 if (print_helper_.get() == NULL)
[email protected]0fda7272009-06-26 15:49:335358 print_helper_.reset(new PrintWebViewHelper(this));
[email protected]521b2482011-01-15 00:10:105359 return print_helper_.get();
[email protected]0fda7272009-06-26 15:49:335360}
[email protected]446705872009-09-10 07:22:485361
5362void RenderView::OnSetEditCommandsForNextKeyEvent(
5363 const EditCommands& edit_commands) {
5364 edit_commands_ = edit_commands;
5365}
5366
[email protected]61f5a7b2009-12-22 22:21:205367void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) {
[email protected]26aa0482009-09-30 16:55:275368 WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL;
[email protected]912256b32009-09-18 09:47:355369 if (!main_frame) {
[email protected]61f5a7b2009-12-22 22:21:205370 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id,
5371 false));
[email protected]912256b32009-09-18 09:47:355372 return;
5373 }
5374
[email protected]fa7b6b542009-11-03 05:02:305375 WebDataSource* ds = main_frame->dataSource();
5376 NavigationState* navigation_state = NavigationState::FromDataSource(ds);
5377 if (!navigation_state->user_script_idle_scheduler()->has_run()) {
[email protected]61f5a7b2009-12-22 22:21:205378 pending_code_execution_queue_.push(
5379 linked_ptr<ViewMsg_ExecuteCode_Params>(
5380 new ViewMsg_ExecuteCode_Params(params)));
[email protected]fa7b6b542009-11-03 05:02:305381 return;
5382 }
5383
[email protected]61f5a7b2009-12-22 22:21:205384 ExecuteCodeImpl(main_frame, params);
[email protected]fa7b6b542009-11-03 05:02:305385}
5386
5387void RenderView::ExecuteCodeImpl(WebFrame* frame,
[email protected]61f5a7b2009-12-22 22:21:205388 const ViewMsg_ExecuteCode_Params& params) {
[email protected]20ad2692009-11-20 18:27:205389 std::vector<WebFrame*> frame_vector;
5390 frame_vector.push_back(frame);
[email protected]61f5a7b2009-12-22 22:21:205391 if (params.all_frames)
[email protected]20ad2692009-11-20 18:27:205392 GetAllChildFrames(frame, &frame_vector);
5393
5394 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5395 frame_it != frame_vector.end(); ++frame_it) {
5396 WebFrame* frame = *frame_it;
[email protected]61f5a7b2009-12-22 22:21:205397 if (params.is_javascript) {
[email protected]be7e5cb2010-10-04 12:53:175398 ExtensionRendererInfo* extension =
5399 ExtensionRendererInfo::GetByID(params.extension_id);
5400
[email protected]1f6228c2010-10-21 03:19:445401 // Since extension info is sent separately from user script info, they can
5402 // be out of sync. We just ignore this situation.
5403 if (!extension)
5404 continue;
5405
[email protected]be7e5cb2010-10-04 12:53:175406 const std::vector<URLPattern> host_permissions =
5407 extension->host_permissions();
5408 if (!Extension::CanExecuteScriptOnPage(
5409 frame->url(),
5410 extension->allowed_to_execute_script_everywhere(),
5411 &host_permissions,
5412 NULL,
5413 NULL)) {
[email protected]61f5a7b2009-12-22 22:21:205414 continue;
[email protected]be7e5cb2010-10-04 12:53:175415 }
[email protected]61f5a7b2009-12-22 22:21:205416
[email protected]20ad2692009-11-20 18:27:205417 std::vector<WebScriptSource> sources;
5418 sources.push_back(
[email protected]61f5a7b2009-12-22 22:21:205419 WebScriptSource(WebString::fromUTF8(params.code)));
5420 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
[email protected]20ad2692009-11-20 18:27:205421 frame->executeScriptInIsolatedWorld(
[email protected]61f5a7b2009-12-22 22:21:205422 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
[email protected]20ad2692009-11-20 18:27:205423 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5424 } else {
[email protected]61f5a7b2009-12-22 22:21:205425 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
[email protected]20ad2692009-11-20 18:27:205426 }
[email protected]912256b32009-09-18 09:47:355427 }
5428
[email protected]61f5a7b2009-12-22 22:21:205429 Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true));
[email protected]912256b32009-09-18 09:47:355430}
5431
[email protected]60c42a8c72009-10-09 04:08:595432void RenderView::Close() {
5433 // We need to grab a pointer to the doomed WebView before we destroy it.
5434 WebView* doomed = webview();
5435 RenderWidget::Close();
[email protected]625332e02010-12-14 07:48:495436 g_view_map.Get().erase(doomed);
[email protected]60c42a8c72009-10-09 04:08:595437}
5438
[email protected]446705872009-09-10 07:22:485439void RenderView::DidHandleKeyEvent() {
5440 edit_commands_.clear();
5441}
5442
[email protected]6a8ddba52010-09-05 04:38:065443void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {
[email protected]676126f72011-01-15 00:03:515444 FOR_EACH_OBSERVER(RenderViewObserver, observers_, DidHandleMouseEvent(event));
[email protected]6a8ddba52010-09-05 04:38:065445}
5446
[email protected]941e4552010-02-01 21:23:435447#if defined(OS_MACOSX)
5448void RenderView::OnWasHidden() {
5449 RenderWidget::OnWasHidden();
5450
5451 // Inform plugins that their container is no longer visible.
5452 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5453 for (plugin_it = plugin_delegates_.begin();
5454 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5455 (*plugin_it)->SetContainerVisibility(false);
5456 }
5457}
5458
5459void RenderView::OnWasRestored(bool needs_repainting) {
5460 RenderWidget::OnWasRestored(needs_repainting);
5461
5462 // Inform plugins that their container is now visible.
5463 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5464 for (plugin_it = plugin_delegates_.begin();
5465 plugin_it != plugin_delegates_.end(); ++plugin_it) {
5466 (*plugin_it)->SetContainerVisibility(true);
5467 }
5468}
[email protected]784ea1ab2010-09-18 00:02:345469#endif // OS_MACOSX
[email protected]1e6e3c992010-02-08 15:52:135470
5471void RenderView::OnSetFocus(bool enable) {
5472 RenderWidget::OnSetFocus(enable);
5473
[email protected]7d3c02c2010-05-05 23:10:315474 if (webview() && webview()->isActive()) {
[email protected]589621b2010-09-23 22:01:075475 // Notify all NPAPI plugins.
[email protected]1e6e3c992010-02-08 15:52:135476 std::set<WebPluginDelegateProxy*>::iterator plugin_it;
5477 for (plugin_it = plugin_delegates_.begin();
5478 plugin_it != plugin_delegates_.end(); ++plugin_it) {
[email protected]784ea1ab2010-09-18 00:02:345479#if defined(OS_MACOSX)
[email protected]7d3c02c2010-05-05 23:10:315480 // RenderWidget's call to setFocus can cause the underlying webview's
5481 // activation state to change just like a call to setIsActive.
5482 if (enable)
5483 (*plugin_it)->SetWindowFocus(true);
[email protected]784ea1ab2010-09-18 00:02:345484#endif
[email protected]7d3c02c2010-05-05 23:10:315485 (*plugin_it)->SetContentAreaFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135486 }
[email protected]589621b2010-09-23 22:01:075487
5488 // Notify all Pepper plugins.
5489 pepper_delegate_.OnSetFocus(enable);
[email protected]1e6e3c992010-02-08 15:52:135490 }
5491}
[email protected]941e4552010-02-01 21:23:435492
[email protected]83dde542009-09-11 20:59:555493void RenderView::EnsureDocumentTag() {
5494 // TODO(darin): There's actually no reason for this to be here. We should
5495 // have the browser side manage the document tag.
5496#if defined(OS_MACOSX)
5497 if (!has_document_tag_) {
5498 // Make the call to get the tag.
5499 Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_));
5500 has_document_tag_ = true;
5501 }
5502#endif
5503}
[email protected]12636df2009-09-28 22:32:215504
[email protected]43f28f832010-02-03 02:28:485505#if defined(OS_MACOSX)
[email protected]b7f75862011-01-21 21:15:135506void RenderView::PluginFocusChanged(bool focused, int plugin_id) {
5507 IPC::Message* msg = new ViewHostMsg_PluginFocusChanged(routing_id(),
5508 focused, plugin_id);
5509 Send(msg);
5510}
5511
5512void RenderView::StartPluginIme() {
5513 IPC::Message* msg = new ViewHostMsg_StartPluginIme(routing_id());
[email protected]935d63d2010-10-15 23:31:555514 // This message can be sent during event-handling, and needs to be delivered
5515 // within that context.
5516 msg->set_unblock(true);
5517 Send(msg);
5518}
5519
[email protected]ea04a4e12010-04-15 00:58:035520gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235521 bool opaque, bool root) {
[email protected]43f28f832010-02-03 02:28:485522 gfx::PluginWindowHandle window = NULL;
5523 Send(new ViewHostMsg_AllocateFakePluginWindowHandle(
[email protected]77e74db2010-08-04 17:46:235524 routing_id(), opaque, root, &window));
[email protected]c36a9b62010-10-14 00:41:115525 if (window) {
5526 fake_plugin_window_handles_.insert(window);
5527 }
[email protected]43f28f832010-02-03 02:28:485528 return window;
5529}
5530
5531void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) {
[email protected]c36a9b62010-10-14 00:41:115532 if (window && fake_plugin_window_handles_.find(window) !=
5533 fake_plugin_window_handles_.end()) {
[email protected]43f28f832010-02-03 02:28:485534 Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window));
[email protected]c36a9b62010-10-14 00:41:115535 fake_plugin_window_handles_.erase(window);
5536 }
[email protected]43f28f832010-02-03 02:28:485537}
5538
[email protected]44ce0b12010-03-12 16:45:335539void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window,
5540 int32 width,
5541 int32 height,
5542 uint64 io_surface_identifier) {
5543 Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface(
[email protected]43f28f832010-02-03 02:28:485544 routing_id(), window, width, height, io_surface_identifier));
5545}
5546
[email protected]44ce0b12010-03-12 16:45:335547void RenderView::AcceleratedSurfaceSetTransportDIB(
5548 gfx::PluginWindowHandle window,
5549 int32 width,
5550 int32 height,
5551 TransportDIB::Handle transport_dib) {
5552 Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB(
[email protected]1aef98132010-02-23 18:00:075553 routing_id(), window, width, height, transport_dib));
5554}
5555
[email protected]44ce0b12010-03-12 16:45:335556TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB(
5557 size_t size) {
[email protected]1aef98132010-02-23 18:00:075558 TransportDIB::Handle dib_handle;
5559 // Assume this is a synchronous RPC.
[email protected]ada848b12010-04-08 22:35:385560 if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle)))
[email protected]1aef98132010-02-23 18:00:075561 return dib_handle;
5562 // Return an invalid handle if Send() fails.
5563 return TransportDIB::DefaultHandleValue();
5564}
5565
[email protected]44ce0b12010-03-12 16:45:335566void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) {
[email protected]1aef98132010-02-23 18:00:075567 Send(new ViewHostMsg_FreeTransportDIB(dib_id));
5568}
5569
[email protected]44ce0b12010-03-12 16:45:335570void RenderView::AcceleratedSurfaceBuffersSwapped(
[email protected]f35d6672010-10-28 21:39:145571 gfx::PluginWindowHandle window, uint64 surface_id) {
5572 Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(
5573 routing_id(), window, surface_id));
[email protected]43f28f832010-02-03 02:28:485574}
5575#endif
[email protected]58c321d2010-02-19 12:11:285576
[email protected]cdaf8d02010-03-30 19:52:475577bool RenderView::ScheduleFileChooser(
5578 const ViewHostMsg_RunFileChooser_Params& params,
5579 WebFileChooserCompletion* completion) {
5580 static const size_t kMaximumPendingFileChooseRequests = 4;
5581 if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) {
5582 // This sanity check prevents too many file choose requests from getting
5583 // queued which could DoS the user. Getting these is most likely a
5584 // programming error (there are many ways to DoS the user so it's not
5585 // considered a "real" security check), either in JS requesting many file
5586 // choosers to pop up, or in a plugin.
5587 //
5588 // TODO(brettw) we might possibly want to require a user gesture to open
5589 // a file picker, which will address this issue in a better way.
5590 return false;
5591 }
5592
5593 file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>(
5594 new PendingFileChooser(params, completion)));
5595 if (file_chooser_completions_.size() == 1) {
5596 // Actually show the browse dialog when this is the first request.
5597 Send(new ViewHostMsg_RunFileChooser(routing_id_, params));
5598 }
5599 return true;
5600}
5601
[email protected]290838a2010-04-27 17:37:015602void RenderView::OnPageTranslated() {
5603 WebFrame* frame = webview()->mainFrame();
5604 if (!frame)
5605 return;
5606
[email protected]676126f72011-01-15 00:03:515607 FOR_EACH_OBSERVER(RenderViewObserver, observers_, FrameTranslated(frame));
[email protected]290838a2010-04-27 17:37:015608}
5609
[email protected]0ff0ff32010-12-21 19:34:425610WebKit::WebGeolocationClient* RenderView::geolocationClient() {
[email protected]676126f72011-01-15 00:03:515611 if (!geolocation_dispatcher_)
5612 geolocation_dispatcher_ = new GeolocationDispatcher(this);
5613 return geolocation_dispatcher_;
[email protected]7e0c4702010-12-31 14:06:255614}
[email protected]61c9f032010-03-31 23:04:195615
[email protected]638694c2010-08-04 22:24:115616WebKit::WebSpeechInputController* RenderView::speechInputController(
5617 WebKit::WebSpeechInputListener* listener) {
[email protected]676126f72011-01-15 00:03:515618 if (!speech_input_dispatcher_)
5619 speech_input_dispatcher_ = new SpeechInputDispatcher(this, listener);
5620 return speech_input_dispatcher_;
[email protected]638694c2010-08-04 22:24:115621}
5622
[email protected]57ead352010-08-11 14:42:535623WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() {
[email protected]676126f72011-01-15 00:03:515624 if (!device_orientation_dispatcher_)
5625 device_orientation_dispatcher_ = new DeviceOrientationDispatcher(this);
5626 return device_orientation_dispatcher_;
[email protected]57ead352010-08-11 14:42:535627}
5628
[email protected]b75b8292010-10-01 07:28:255629void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) {
5630 // For now, don't remember plugin zoom values. We don't want to mix them with
5631 // normal web content (i.e. a fixed layout plugin would usually want them
5632 // different).
5633 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5634
[email protected]b75b8292010-10-01 07:28:255635 int minimum_percent = static_cast<int>(
5636 WebView::zoomLevelToZoomFactor(minimum_level) * 100);
5637 int maximum_percent = static_cast<int>(
5638 WebView::zoomLevelToZoomFactor(maximum_level) * 100);
[email protected]b75b8292010-10-01 07:28:255639
5640 Send(new ViewHostMsg_UpdateZoomLimits(
5641 routing_id_, minimum_percent, maximum_percent, remember));
5642}
5643
5644void RenderView::zoomLevelChanged() {
5645 bool remember = !webview()->mainFrame()->document().isPluginDocument();
5646
[email protected]b75b8292010-10-01 07:28:255647 // Tell the browser which url got zoomed so it can update the menu and the
5648 // saved values if necessary
5649 Send(new ViewHostMsg_DidZoomURL(
[email protected]1cc58eb62010-10-01 22:38:415650 routing_id_, webview()->zoomLevel(), remember,
5651 GURL(webview()->mainFrame()->url())));
[email protected]b75b8292010-10-01 07:28:255652}
5653
[email protected]8079b362010-05-07 18:37:455654bool RenderView::IsNonLocalTopLevelNavigation(
[email protected]61c9f032010-03-31 23:04:195655 const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) {
[email protected]8079b362010-05-07 18:37:455656 // Must be a top level frame.
[email protected]61c9f032010-03-31 23:04:195657 if (frame->parent() != NULL)
5658 return false;
5659
[email protected]f0a3d0b2010-08-06 22:51:535660 // Navigations initiated within Webkit are not sent out to the external host
5661 // in the following cases.
[email protected]900eb2f12010-08-23 22:36:275662 // 1. The url scheme is not http/https
5663 // 2. There is no opener and this is not the first url being opened by this
5664 // RenderView.
5665 // 3. The origin of the url and the opener is the same in which case the
[email protected]f0a3d0b2010-08-06 22:51:535666 // opener relationship is maintained.
[email protected]f0a3d0b2010-08-06 22:51:535667 // 4. Reloads/form submits/back forward navigations
5668 if (!url.SchemeIs("http") && !url.SchemeIs("https"))
5669 return false;
5670
[email protected]2fc22d12010-12-02 23:08:165671 // Not interested in reloads/form submits/resubmits/back forward navigations.
[email protected]d0ed50d2010-06-22 01:01:325672 if (type != WebKit::WebNavigationTypeReload &&
[email protected]070c49c2010-07-13 22:22:015673 type != WebKit::WebNavigationTypeFormSubmitted &&
[email protected]2fc22d12010-12-02 23:08:165674 type != WebKit::WebNavigationTypeFormResubmitted &&
[email protected]070c49c2010-07-13 22:22:015675 type != WebKit::WebNavigationTypeBackForward) {
[email protected]d0ed50d2010-06-22 01:01:325676 // The opener relationship between the new window and the parent allows the
5677 // new window to script the parent and vice versa. This is not allowed if
5678 // the origins of the two domains are different. This can be treated as a
5679 // top level navigation and routed back to the host.
5680 WebKit::WebFrame* opener = frame->opener();
[email protected]900eb2f12010-08-23 22:36:275681 if (!opener) {
[email protected]fe9eb4f92010-08-27 23:16:475682 // Force link click navigations to always be routed to the host as they
5683 // may update session state on the server.
5684 if (type == WebKit::WebNavigationTypeLinkClicked)
5685 return true;
[email protected]900eb2f12010-08-23 22:36:275686 // If this is the first page being loaded by this RenderView instance then
5687 // it should stay here.
5688 if (page_id_ == -1) {
5689 return false;
5690 } else {
[email protected]d0ed50d2010-06-22 01:01:325691 return true;
[email protected]900eb2f12010-08-23 22:36:275692 }
[email protected]d0ed50d2010-06-22 01:01:325693 }
[email protected]900eb2f12010-08-23 22:36:275694
5695 if (url.GetOrigin() != GURL(opener->url()).GetOrigin())
5696 return true;
[email protected]d0ed50d2010-06-22 01:01:325697 }
[email protected]61c9f032010-03-31 23:04:195698 return false;
5699}
[email protected]2b06a992010-08-21 05:48:225700
[email protected]27a9ef32010-09-10 04:06:245701void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code,
5702 IPC::PlatformFileForTransit file_for_transit,
5703 int message_id) {
5704 pepper_delegate_.OnAsyncFileOpened(
5705 error_code,
5706 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
5707 message_id);
5708}
[email protected]caf706f2010-10-26 17:54:085709
5710#if defined(OS_MACOSX)
5711void RenderView::OnSelectPopupMenuItem(int selected_index) {
[email protected]68dc3ba2010-12-06 21:43:155712 if (external_popup_menu_ == NULL) {
5713 // Crash reports from the field indicate that we can be notified with a
5714 // NULL external popup menu (we probably get notified twice).
5715 // If you hit this please file a bug against jcivelli and include the page
5716 // and steps to repro.
5717 NOTREACHED();
5718 return;
5719 }
[email protected]caf706f2010-10-26 17:54:085720 external_popup_menu_->DidSelectItem(selected_index);
5721 external_popup_menu_.reset();
5722}
5723#endif
[email protected]bb461532010-11-26 21:50:235724
5725void RenderView::AddErrorToRootConsole(const string16& message) {
5726 if (webview() && webview()->mainFrame()) {
5727 webview()->mainFrame()->addMessageToConsole(
5728 WebConsoleMessage(WebConsoleMessage::LevelError, message));
5729 }
5730}
[email protected]1b4209f2011-01-07 00:25:405731
5732#if defined(ENABLE_FLAPPER_HACKS)
5733void RenderView::OnConnectTcpACK(
5734 int request_id,
5735 IPC::PlatformFileForTransit socket_for_transit,
5736 const PP_Flash_NetAddress& local_addr,
5737 const PP_Flash_NetAddress& remote_addr) {
5738 pepper_delegate_.OnConnectTcpACK(
5739 request_id,
5740 IPC::PlatformFileForTransitToPlatformFile(socket_for_transit),
5741 local_addr,
5742 remote_addr);
5743}
5744#endif
[email protected]a6097f42011-01-10 08:50:515745
5746void RenderView::OnJavaScriptStressTestControl(int cmd, int param) {
5747 if (cmd == kJavaScriptStressTestSetStressRunType) {
5748 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5749 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5750 v8::Testing::PrepareStressRun(param);
5751 }
5752}
[email protected]521b2482011-01-15 00:10:105753
5754void RenderView::OnContextMenuClosed() {
5755 context_menu_node_.reset();
5756}