[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/renderer/render_view.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | 3712621 | 2009-05-06 02:23:31 | [diff] [blame] | 11 | #include "app/message_box_flags.h" |
[email protected] | 9929da9 | 2009-05-05 02:05:11 | [diff] [blame] | 12 | #include "app/resource_bundle.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 13 | #include "base/callback.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 16 | #include "base/field_trial.h" |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 17 | #include "base/histogram.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 18 | #include "base/path_service.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 19 | #include "base/process_util.h" |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 20 | #include "base/singleton.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | #include "base/string_piece.h" |
| 22 | #include "base/string_util.h" |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 23 | #include "base/time.h" |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 24 | #include "base/sys_string_conversions.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 25 | #include "base/utf_string_conversions.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 26 | #include "build/build_config.h" |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 27 | #include "chrome/common/appcache/appcache_dispatcher.h" |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 28 | #include "chrome/common/bindings_policy.h" |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 29 | #include "chrome/common/child_process_logging.h" |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 30 | #include "chrome/common/chrome_constants.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 31 | #include "chrome/common/chrome_paths.h" |
| 32 | #include "chrome/common/chrome_switches.h" |
[email protected] | a0cf04a | 2010-06-23 03:29:55 | [diff] [blame] | 33 | #include "chrome/common/extensions/extension.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | #include "chrome/common/jstemplate_builder.h" |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 35 | #include "chrome/common/notification_service.h" |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 36 | #include "chrome/common/page_zoom.h" |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 37 | #include "chrome/common/pepper_plugin_registry.h" |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 38 | #include "chrome/common/plugin_group.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 39 | #include "chrome/common/render_messages.h" |
[email protected] | 939856a | 2010-08-24 20:29:02 | [diff] [blame] | 40 | #include "chrome/common/render_messages_params.h" |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 41 | #include "chrome/common/renderer_preferences.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 42 | #include "chrome/common/thumbnail_score.h" |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 43 | #include "chrome/common/url_constants.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 44 | #include "chrome/common/window_container_type.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 45 | #include "chrome/renderer/about_handler.h" |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 46 | #include "chrome/renderer/audio_message_filter.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 47 | #include "chrome/renderer/blocked_plugin.h" |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 48 | #include "chrome/renderer/device_orientation_dispatcher.h" |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 49 | #include "chrome/renderer/devtools_agent.h" |
| 50 | #include "chrome/renderer/devtools_client.h" |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 51 | #include "chrome/renderer/extension_groups.h" |
[email protected] | f816c01 | 2009-06-26 21:48:32 | [diff] [blame] | 52 | #include "chrome/renderer/extensions/event_bindings.h" |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 53 | #include "chrome/renderer/extensions/extension_process_bindings.h" |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 54 | #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 55 | #include "chrome/renderer/geolocation_dispatcher.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | #include "chrome/renderer/localized_error.h" |
[email protected] | 6f56d48 | 2009-02-20 05:02:56 | [diff] [blame] | 57 | #include "chrome/renderer/media/audio_renderer_impl.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 58 | #include "chrome/renderer/media/ipc_video_decoder.h" |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 59 | #include "chrome/renderer/media/ipc_video_renderer.h" |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 60 | #include "chrome/renderer/navigation_state.h" |
[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 61 | #include "chrome/renderer/notification_provider.h" |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 62 | #include "chrome/renderer/plugin_channel_host.h" |
[email protected] | d81c1e5 | 2009-06-03 22:09:50 | [diff] [blame] | 63 | #include "chrome/renderer/print_web_view_helper.h" |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 64 | #include "chrome/renderer/render_process.h" |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 65 | #include "chrome/renderer/render_thread.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 66 | #include "chrome/renderer/render_view_visitor.h" |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 67 | #include "chrome/renderer/render_widget_fullscreen.h" |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 68 | #include "chrome/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 69 | #include "chrome/renderer/renderer_webstoragenamespace_impl.h" |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 70 | #include "chrome/renderer/speech_input_dispatcher.h" |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 71 | #include "chrome/renderer/spellchecker/spellcheck.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 72 | #include "chrome/renderer/user_script_slave.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 73 | #include "chrome/renderer/visitedlink_slave.h" |
[email protected] | d439ba07 | 2009-10-17 22:32:29 | [diff] [blame] | 74 | #include "chrome/renderer/webplugin_delegate_pepper.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 75 | #include "chrome/renderer/webplugin_delegate_proxy.h" |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 76 | #include "chrome/renderer/websharedworker_proxy.h" |
[email protected] | eb47a13 | 2009-03-04 00:39:56 | [diff] [blame] | 77 | #include "chrome/renderer/webworker_proxy.h" |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 78 | #include "gfx/color_utils.h" |
| 79 | #include "gfx/favicon_size.h" |
[email protected] | 5c7293a | 2010-03-17 06:40:57 | [diff] [blame] | 80 | #include "gfx/native_widget_types.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 81 | #include "gfx/point.h" |
| 82 | #include "gfx/rect.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 83 | #include "grit/generated_resources.h" |
| 84 | #include "grit/renderer_resources.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 85 | #include "media/base/media_switches.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 86 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 87 | #include "net/base/escape.h" |
| 88 | #include "net/base/net_errors.h" |
[email protected] | c399a8a | 2008-11-22 19:38:00 | [diff] [blame] | 89 | #include "skia/ext/bitmap_platform_device.h" |
[email protected] | 83c9e655 | 2008-12-03 16:22:10 | [diff] [blame] | 90 | #include "skia/ext/image_operations.h" |
[email protected] | 65127279 | 2010-02-04 23:16:30 | [diff] [blame] | 91 | #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h" |
[email protected] | b5558cf2 | 2010-07-12 17:30:06 | [diff] [blame] | 92 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 93 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 94 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 95 | #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 96 | #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
| 97 | #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 98 | #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 99 | #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 100 | #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 101 | #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 102 | #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" |
| 103 | #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 104 | #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 105 | #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
| 106 | #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 107 | #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 108 | #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 109 | #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 110 | #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 111 | #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 112 | #include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 113 | #include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 114 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 115 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 116 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 117 | #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
| 118 | #include "third_party/WebKit/WebKit/chromium/public/WebRange.h" |
| 119 | #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 120 | #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" |
| 121 | #include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h" |
| 122 | #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 123 | #include "third_party/WebKit/WebKit/chromium/public/WebSettings.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 124 | #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 125 | #include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 126 | #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 127 | #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 128 | #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" |
| 129 | #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 130 | #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
| 131 | #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 132 | #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 133 | #include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 134 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 135 | #include "webkit/glue/context_menu.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 136 | #include "webkit/glue/dom_operations.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 137 | #include "webkit/glue/form_data.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 138 | #include "webkit/glue/form_field.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 139 | #include "webkit/glue/glue_serialize.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 140 | #include "webkit/glue/image_decoder.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 141 | #include "webkit/glue/image_resource_fetcher.h" |
[email protected] | 8e296bbd | 2009-07-22 21:37:17 | [diff] [blame] | 142 | #include "webkit/glue/media/buffered_data_source.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 143 | #include "webkit/glue/media/simple_data_source.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 144 | #include "webkit/glue/media/video_renderer_impl.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 145 | #include "webkit/glue/password_form_dom_manager.h" |
[email protected] | 0d64bb7 | 2010-07-07 05:36:38 | [diff] [blame] | 146 | #include "webkit/glue/plugins/default_plugin_shared.h" |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 147 | #include "webkit/glue/plugins/pepper_webplugin_impl.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 148 | #include "webkit/glue/plugins/plugin_list.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 149 | #include "webkit/glue/plugins/webplugin_delegate.h" |
[email protected] | 8a3b796 | 2009-09-04 05:53:23 | [diff] [blame] | 150 | #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 151 | #include "webkit/glue/plugins/webplugin_impl.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 152 | #include "webkit/glue/plugins/webview_plugin.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 153 | #include "webkit/glue/site_isolation_metrics.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 154 | #include "webkit/glue/webaccessibility.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 155 | #include "webkit/glue/webdropdata.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 156 | #include "webkit/glue/webkit_glue.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 157 | #include "webkit/glue/webmediaplayer_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 159 | #if defined(OS_WIN) |
| 160 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 161 | // * theming |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 162 | #include "gfx/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 163 | #elif defined(USE_X11) |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 164 | #include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 165 | #elif defined(OS_MACOSX) |
| 166 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 167 | #endif |
| 168 | |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 169 | using appcache::WebApplicationCacheHostImpl; |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 170 | using base::Time; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 171 | using base::TimeDelta; |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 172 | using webkit_glue::AltErrorPageResourceFetcher; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 173 | using webkit_glue::FormData; |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 174 | using webkit_glue::FormField; |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 175 | using webkit_glue::ImageResourceFetcher; |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 176 | using webkit_glue::PasswordForm; |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 177 | using webkit_glue::PasswordFormDomManager; |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 178 | using webkit_glue::SiteIsolationMetrics; |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 179 | using WebKit::WebAccessibilityCache; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 180 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 181 | using WebKit::WebApplicationCacheHost; |
| 182 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 183 | using WebKit::WebColor; |
| 184 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 185 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 186 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 187 | using WebKit::WebCookieJar; |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 188 | using WebKit::WebCString; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 189 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 190 | using WebKit::WebDataSource; |
[email protected] | 2661b33 | 2009-11-03 18:42:29 | [diff] [blame] | 191 | using WebKit::WebDevToolsAgent; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 192 | using WebKit::WebDocument; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 193 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 194 | using WebKit::WebDragOperation; |
| 195 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 196 | using WebKit::WebEditingAction; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 197 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 198 | using WebKit::WebFileSystem; |
| 199 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 200 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 201 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 202 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 203 | using WebKit::WebFrame; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 204 | using WebKit::WebHistoryItem; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 205 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 206 | using WebKit::WebInputElement; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 207 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 208 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 209 | using WebKit::WebMediaPlayerClient; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 210 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 211 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 212 | using WebKit::WebNode; |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 213 | using WebKit::WebPageSerializer; |
| 214 | using WebKit::WebPageSerializerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 215 | using WebKit::WebPlugin; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 216 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 217 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 218 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 219 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 220 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 221 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 222 | using WebKit::WebRect; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 223 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 224 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 225 | using WebKit::WebSecurityOrigin; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 226 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 227 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 228 | using WebKit::WebSize; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 229 | using WebKit::WebStorageNamespace; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 230 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 231 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 232 | using WebKit::WebTextDirection; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 233 | using WebKit::WebURL; |
| 234 | using WebKit::WebURLError; |
| 235 | using WebKit::WebURLRequest; |
| 236 | using WebKit::WebURLResponse; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 237 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 238 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 239 | using WebKit::WebWidget; |
[email protected] | 27ba853 | 2009-04-24 20:22:43 | [diff] [blame] | 240 | using WebKit::WebWorker; |
| 241 | using WebKit::WebWorkerClient; |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 242 | using WebKit::WebWindowFeatures; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 243 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 244 | //----------------------------------------------------------------------------- |
| 245 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 246 | typedef std::map<WebKit::WebView*, RenderView*> ViewMap; |
| 247 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 248 | // define to write the time necessary for thumbnail/DOM text retrieval, |
| 249 | // respectively, into the system debug log |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 250 | // #define TIME_TEXT_RETRIEVAL |
| 251 | |
| 252 | // maximum number of characters in the document to index, any text beyond this |
| 253 | // point will be clipped |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 254 | static const size_t kMaxIndexChars = 65535; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 255 | |
| 256 | // Size of the thumbnails that we'll generate |
[email protected] | 8b4f489 | 2009-09-04 21:52:37 | [diff] [blame] | 257 | static const int kThumbnailWidth = 212; |
| 258 | static const int kThumbnailHeight = 132; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 259 | |
| 260 | // Delay in milliseconds that we'll wait before capturing the page contents |
| 261 | // and thumbnail. |
| 262 | static const int kDelayForCaptureMs = 500; |
| 263 | |
| 264 | // Typically, we capture the page data once the page is loaded. |
| 265 | // Sometimes, the page never finishes to load, preventing the page capture |
| 266 | // To workaround this problem, we always perform a capture after the following |
| 267 | // delay. |
| 268 | static const int kDelayForForcedCaptureMs = 6000; |
| 269 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 270 | // Time, in seconds, we delay before sending content state changes (such as form |
| 271 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 272 | // spamming the browser. |
| 273 | // To avoid having tab/session restore require sending a message to get the |
| 274 | // current content state during tab closing we use a shorter timeout for the |
| 275 | // foreground renderer. This means there is a small window of time from which |
| 276 | // content state is modified and not sent to session restore, but this is |
| 277 | // better than having to wake up all renderers during shutdown. |
| 278 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 279 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 280 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 281 | // The maximum number of popups that can be spawned from one page. |
| 282 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 283 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 284 | static const char* const kUnreachableWebDataURL = |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 285 | "chrome://chromewebdata/"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 286 | |
[email protected] | 50b691c | 2008-10-31 19:08:35 | [diff] [blame] | 287 | static const char* const kBackForwardNavigationScheme = "history"; |
| 288 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 289 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 290 | WebVector<WebURL> urls; |
| 291 | ds->redirectChain(urls); |
| 292 | result->reserve(urls.size()); |
| 293 | for (size_t i = 0; i < urls.size(); ++i) |
| 294 | result->push_back(urls[i]); |
| 295 | } |
| 296 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 297 | static bool UrlMatchesPermissions( |
| 298 | const GURL& url, const std::vector<URLPattern>& host_permissions) { |
| 299 | for (size_t i = 0; i < host_permissions.size(); ++i) { |
| 300 | if (host_permissions[i].MatchesUrl(url)) |
| 301 | return true; |
| 302 | } |
| 303 | |
| 304 | return false; |
| 305 | } |
| 306 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 307 | static bool PaintViewIntoCanvas(WebView* view, |
| 308 | skia::PlatformCanvas& canvas) { |
| 309 | view->layout(); |
| 310 | const WebSize& size = view->size(); |
| 311 | |
| 312 | if (!canvas.initialize(size.width, size.height, true)) |
| 313 | return false; |
| 314 | |
| 315 | view->paint(webkit_glue::ToWebCanvas(&canvas), |
| 316 | WebRect(0, 0, size.width, size.height)); |
| 317 | // TODO: Add a way to snapshot the whole page, not just the currently |
| 318 | // visible part. |
| 319 | |
| 320 | return true; |
| 321 | } |
| 322 | |
| 323 | // Calculates how "boring" a thumbnail is. The boring score is the |
| 324 | // 0,1 ranged percentage of pixels that are the most common |
| 325 | // luma. Higher boring scores indicate that a higher percentage of a |
| 326 | // bitmap are all the same brightness. |
| 327 | static double CalculateBoringScore(SkBitmap* bitmap) { |
| 328 | int histogram[256] = {0}; |
| 329 | color_utils::BuildLumaHistogram(bitmap, histogram); |
| 330 | |
| 331 | int color_count = *std::max_element(histogram, histogram + 256); |
| 332 | int pixel_count = bitmap->width() * bitmap->height(); |
| 333 | return static_cast<double>(color_count) / pixel_count; |
| 334 | } |
| 335 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 336 | // True if |frame| contains content that is white-listed for content settings. |
| 337 | static bool IsWhitelistedForContentSettings(WebFrame* frame) { |
| 338 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 339 | if (origin.isEmpty()) |
| 340 | return false; // Uninitialized document? |
| 341 | |
| 342 | if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
| 343 | return true; // Browser UI elements should still work. |
| 344 | |
| 345 | // If the scheme is ftp: or file:, an empty file name indicates a directory |
| 346 | // listing, which requires JavaScript to function properly. |
| 347 | GURL frame_url = frame->url(); |
| 348 | const char* kDirProtocols[] = { "ftp", "file" }; |
| 349 | for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { |
| 350 | if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { |
| 351 | return frame_url.SchemeIs(kDirProtocols[i]) && |
| 352 | frame_url.ExtractFileName().empty(); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | return false; |
| 357 | } |
| 358 | |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 359 | // Returns true if the frame is navigating to an URL either into or out of an |
| 360 | // extension app's extent. |
| 361 | static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) { |
| 362 | if (!RenderThread::current()) |
| 363 | return false; |
| 364 | |
| 365 | // If the URL is still empty, this is a window.open navigation. Check the |
| 366 | // opener's URL. |
| 367 | GURL old_url(frame->url()); |
| 368 | if (old_url.is_empty() && frame->opener()) |
| 369 | old_url = frame->opener()->url(); |
| 370 | |
| 371 | std::string old_extension = |
[email protected] | 4fdbc149 | 2010-07-01 01:20:59 | [diff] [blame] | 372 | RenderThread::current()->GetExtensionIdByURL(old_url); |
| 373 | if (!old_extension.empty()) { |
| 374 | if (RenderThread::current()->GetExtensionIdByBrowseExtent(new_url) == |
| 375 | old_extension) { |
| 376 | return false; |
| 377 | } |
| 378 | } |
| 379 | |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 380 | std::string new_extension = |
[email protected] | 4fdbc149 | 2010-07-01 01:20:59 | [diff] [blame] | 381 | RenderThread::current()->GetExtensionIdByURL(new_url); |
| 382 | return old_extension != new_extension; |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 383 | } |
| 384 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 385 | // Returns the ISO 639_1 language code of the specified |text|, or 'unknown' |
| 386 | // if it failed. |
| 387 | // |
| 388 | // Note this only works on Windows at this time. It always returns 'unknown' |
| 389 | // on other platforms. |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 390 | static std::string DetermineTextLanguage(const string16& text) { |
[email protected] | 655f97c3 | 2010-07-22 21:24:17 | [diff] [blame] | 391 | std::string language = chrome::kUnknownLanguageCode; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 392 | int num_languages = 0; |
[email protected] | a9558688 | 2010-08-02 18:40:08 | [diff] [blame] | 393 | int text_bytes = 0; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 394 | bool is_reliable = false; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 395 | Language cld_language = |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 396 | DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable, |
[email protected] | a9558688 | 2010-08-02 18:40:08 | [diff] [blame] | 397 | &num_languages, NULL, &text_bytes); |
| 398 | // We don't trust the result if the CLD reports that the detection is not |
| 399 | // reliable, or if the actual text used to detect the language was less than |
| 400 | // 100 bytes (short texts can often lead to wrong results). |
| 401 | if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES && |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 402 | cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) { |
| 403 | // We should not use LanguageCode_ISO_639_1 because it does not cover all |
| 404 | // the languages CLD can detect. As a result, it'll return the invalid |
| 405 | // language code for tradtional Chinese among others. |
| 406 | // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and |
| 407 | // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN |
| 408 | // for Simplified Chinese. |
| 409 | language = LanguageCodeWithDialects(cld_language); |
| 410 | } |
| 411 | return language; |
| 412 | } |
| 413 | |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 414 | // Holds pending openFileSystem callbacks. |
| 415 | struct RenderView::PendingOpenFileSystem { |
| 416 | explicit PendingOpenFileSystem(WebFileSystemCallbacks* c) : callbacks(c) { |
| 417 | } |
| 418 | ~PendingOpenFileSystem() { |
| 419 | if (callbacks) |
| 420 | callbacks->didFail(WebKit::WebFileErrorAbort); |
| 421 | } |
| 422 | WebFileSystemCallbacks* callbacks; |
| 423 | }; |
| 424 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 425 | /////////////////////////////////////////////////////////////////////////////// |
| 426 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 427 | int32 RenderView::next_page_id_ = 1; |
| 428 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 429 | struct RenderView::PendingFileChooser { |
| 430 | PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, |
| 431 | WebFileChooserCompletion* c) |
| 432 | : params(p), |
| 433 | completion(c) { |
| 434 | } |
| 435 | ViewHostMsg_RunFileChooser_Params params; |
| 436 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 437 | }; |
| 438 | |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 439 | RenderView::RenderView(RenderThreadBase* render_thread, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 440 | const WebPreferences& webkit_preferences, |
| 441 | int64 session_storage_namespace_id) |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 442 | : RenderWidget(render_thread, WebKit::WebPopupTypeNone), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 443 | webkit_preferences_(webkit_preferences), |
| 444 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 445 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 446 | send_preferred_size_changes_(false), |
| 447 | script_can_close_(true), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 448 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 449 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 450 | opened_by_user_gesture_(true), |
| 451 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 452 | page_id_(-1), |
| 453 | last_page_id_sent_to_browser_(-1), |
| 454 | last_indexed_page_id_(-1), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 455 | history_list_offset_(-1), |
| 456 | history_list_length_(0), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 457 | has_unload_listener_(false), |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 458 | #if defined(OS_MACOSX) |
| 459 | has_document_tag_(false), |
| 460 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 461 | document_tag_(0), |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 462 | cross_origin_access_count_(0), |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 463 | same_origin_access_count_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 464 | target_url_status_(TARGET_NONE), |
| 465 | spelling_panel_visible_(false), |
| 466 | view_type_(ViewType::INVALID), |
| 467 | browser_window_id_(-1), |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 468 | ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 469 | ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)), |
| 470 | ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 471 | ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)), |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 472 | ALLOW_THIS_IN_INITIALIZER_LIST(password_autocomplete_manager_(this)), |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 473 | ALLOW_THIS_IN_INITIALIZER_LIST(autofill_helper_(this)), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 474 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
| 475 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 476 | notification_provider_(new NotificationProvider(this))), |
| 477 | session_storage_namespace_id_(session_storage_namespace_id), |
| 478 | decrement_shared_popup_at_destruction_(false) { |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 479 | ClearBlockedContentSettings(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | RenderView::~RenderView() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 483 | if (decrement_shared_popup_at_destruction_) |
| 484 | shared_popup_counter_->data--; |
| 485 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 486 | // Dispose of un-disposed image fetchers. |
| 487 | for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin(); |
| 488 | i != image_fetchers_.end(); ++i) { |
| 489 | delete *i; |
| 490 | } |
| 491 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 492 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 493 | while (!file_chooser_completions_.empty()) { |
| 494 | if (file_chooser_completions_.front()->completion) { |
| 495 | file_chooser_completions_.front()->completion->didChooseFile( |
| 496 | WebVector<WebString>()); |
| 497 | } |
| 498 | file_chooser_completions_.pop_front(); |
| 499 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 500 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 501 | #if defined(OS_MACOSX) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 502 | // Tell the spellchecker that the document is closed. |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 503 | if (has_document_tag_) |
| 504 | Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_)); |
| 505 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 506 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 507 | render_thread_->RemoveFilter(audio_message_filter_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 508 | |
| 509 | #ifndef NDEBUG |
| 510 | // Make sure we are no longer referenced by the ViewMap. |
| 511 | ViewMap* views = Singleton<ViewMap>::get(); |
| 512 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 513 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 514 | #endif |
| 515 | } |
| 516 | |
| 517 | /*static*/ |
| 518 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
| 519 | ViewMap* views = Singleton<ViewMap>::get(); |
| 520 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 521 | if (!visitor->Visit(it->second)) |
| 522 | return; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | /*static*/ |
| 527 | RenderView* RenderView::FromWebView(WebView* webview) { |
| 528 | ViewMap* views = Singleton<ViewMap>::get(); |
| 529 | ViewMap::iterator it = views->find(webview); |
| 530 | return it == views->end() ? NULL : it->second; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /*static*/ |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 534 | RenderView* RenderView::Create( |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 535 | RenderThreadBase* render_thread, |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 536 | gfx::NativeViewId parent_hwnd, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 537 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 538 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 539 | const WebPreferences& webkit_prefs, |
| 540 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 541 | int32 routing_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 542 | int64 session_storage_namespace_id, |
| 543 | const string16& frame_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 544 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 545 | scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs, |
| 546 | session_storage_namespace_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 547 | view->Init(parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 548 | opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 549 | renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 550 | counter, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 551 | routing_id, |
| 552 | frame_name); // adds reference |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 553 | return view; |
| 554 | } |
| 555 | |
| 556 | /*static*/ |
| 557 | void RenderView::SetNextPageID(int32 next_page_id) { |
| 558 | // This method should only be called during process startup, and the given |
| 559 | // page id had better not exceed our current next page id! |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 560 | DCHECK_EQ(next_page_id_, 1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 561 | DCHECK(next_page_id >= next_page_id_); |
| 562 | next_page_id_ = next_page_id; |
| 563 | } |
| 564 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 565 | WebKit::WebView* RenderView::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 566 | return static_cast<WebKit::WebView*>(webwidget()); |
| 567 | } |
| 568 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 569 | void RenderView::UserMetricsRecordAction(const std::string& action) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 570 | Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); |
| 571 | } |
| 572 | |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 573 | void RenderView::PluginCrashed(const FilePath& plugin_path) { |
| 574 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 575 | } |
| 576 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 577 | WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame, |
| 578 | const WebPluginParams& params) { |
| 579 | WebPluginInfo info; |
| 580 | bool found; |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 581 | ContentSetting setting; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 582 | std::string mime_type; |
| 583 | Send(new ViewHostMsg_GetPluginInfo( |
| 584 | params.url, frame->top()->url(), params.mimeType.utf8(), &found, |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 585 | &info, &setting, &mime_type)); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 586 | if (!found || !info.enabled) |
| 587 | return NULL; |
| 588 | scoped_refptr<pepper::PluginModule> pepper_module = |
| 589 | PepperPluginRegistry::GetInstance()->GetModule(info.path); |
| 590 | if (pepper_module) |
| 591 | return CreatePepperPlugin(frame, params, info.path, pepper_module.get()); |
| 592 | else |
| 593 | return CreateNPAPIPlugin(frame, params, info.path, mime_type); |
| 594 | } |
| 595 | |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 596 | #if defined(OS_MACOSX) |
| 597 | void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 598 | plugin_delegates_.insert(delegate); |
| 599 | } |
| 600 | |
| 601 | void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 602 | plugin_delegates_.erase(delegate); |
| 603 | } |
| 604 | #endif |
| 605 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 606 | void RenderView::Init(gfx::NativeViewId parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 607 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 608 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 609 | SharedRenderViewCounter* counter, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 610 | int32 routing_id, |
| 611 | const string16& frame_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 612 | DCHECK(!webview()); |
| 613 | |
| 614 | if (opener_id != MSG_ROUTING_NONE) |
| 615 | opener_id_ = opener_id; |
| 616 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 617 | if (counter) { |
| 618 | shared_popup_counter_ = counter; |
| 619 | shared_popup_counter_->data++; |
| 620 | decrement_shared_popup_at_destruction_ = true; |
| 621 | } else { |
| 622 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 623 | decrement_shared_popup_at_destruction_ = false; |
| 624 | } |
| 625 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 626 | devtools_agent_.reset(new DevToolsAgent(routing_id, this)); |
[email protected] | 9b9d728 | 2009-04-08 14:13:04 | [diff] [blame] | 627 | |
[email protected] | 9a6c623 | 2010-06-25 11:46:49 | [diff] [blame] | 628 | webwidget_ = WebView::create(this, devtools_agent_.get()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 629 | Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 630 | webkit_preferences_.Apply(webview()); |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 631 | webview()->initializeMainFrame(this); |
[email protected] | c1e0696 | 2010-06-17 16:53:23 | [diff] [blame] | 632 | if (!frame_name.empty()) |
| 633 | webview()->mainFrame()->setName(frame_name); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 634 | |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 635 | OnSetRendererPrefs(renderer_prefs); |
| 636 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 637 | routing_id_ = routing_id; |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 638 | render_thread_->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 639 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 640 | // when we receive ViewMsg_Close. |
| 641 | AddRef(); |
| 642 | |
| 643 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 644 | // completing initialization. Otherwise, we can finish it now. |
| 645 | if (opener_id == MSG_ROUTING_NONE) { |
| 646 | did_show_ = true; |
| 647 | CompleteInit(parent_hwnd); |
| 648 | } |
| 649 | |
| 650 | host_window_ = parent_hwnd; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 651 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 652 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 653 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 654 | enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 655 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 656 | audio_message_filter_ = new AudioMessageFilter(routing_id_); |
| 657 | render_thread_->AddFilter(audio_message_filter_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | void RenderView::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 661 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 662 | if (main_frame) |
| 663 | child_process_logging::SetActiveURL(main_frame->url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 664 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 665 | // If this is developer tools renderer intercept tools messages first. |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 666 | if (devtools_client_.get() && devtools_client_->OnMessageReceived(message)) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 667 | return; |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 668 | if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message)) |
| 669 | return; |
[email protected] | b6849bda | 2009-10-14 23:59:26 | [diff] [blame] | 670 | if (notification_provider_->OnMessageReceived(message)) |
| 671 | return; |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 672 | if (geolocation_dispatcher_.get() && |
| 673 | geolocation_dispatcher_->OnMessageReceived(message)) { |
| 674 | return; |
| 675 | } |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 676 | if (speech_input_dispatcher_.get() && |
| 677 | speech_input_dispatcher_->OnMessageReceived(message)) { |
| 678 | return; |
| 679 | } |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 680 | if (device_orientation_dispatcher_.get() && |
| 681 | device_orientation_dispatcher_->OnMessageReceived(message)) { |
| 682 | return; |
| 683 | } |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 684 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 685 | IPC_BEGIN_MESSAGE_MAP(RenderView, message) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 686 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail) |
| 687 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 688 | IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 689 | IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 690 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 691 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 692 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 693 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 694 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 695 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 696 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 697 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 698 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 699 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 700 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
| 701 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 702 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 703 | IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, |
| 704 | OnAdvanceToNextMisspelling) |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 705 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 706 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 707 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
| 708 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 709 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 710 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 711 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| 712 | IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 713 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 714 | IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, |
| 715 | OnSetContentSettingsForLoadingURL) |
| 716 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 717 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 718 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 719 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 720 | OnResetPageEncodingToDefault) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 721 | IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 722 | IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 723 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 724 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 725 | IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 726 | IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 727 | IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm) |
| 728 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) |
| 729 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) |
| 730 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) |
| 731 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 732 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 733 | IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 734 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved, |
| 735 | OnDragSourceEndedOrMoved) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 736 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, |
| 737 | OnDragSourceSystemDragEnded) |
| 738 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 739 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 740 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 741 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
| 742 | IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 743 | IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 744 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
| 745 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 746 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 747 | OnGetAllSavableResourceLinksForCurrentPage) |
[email protected] | f09c718 | 2009-03-10 12:54:04 | [diff] [blame] | 748 | IPC_MESSAGE_HANDLER( |
| 749 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 750 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 751 | IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 752 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 753 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 754 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 755 | IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 756 | OnHandleMessageFromExternalHost) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 757 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 758 | OnDisassociateFromPopupCount) |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 759 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned, |
| 760 | OnAutoFillSuggestionsReturned) |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 761 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled, |
| 762 | OnAutoFillFormDataFilled) |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 763 | IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose, |
| 764 | OnAllowScriptToClose) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 765 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 766 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 767 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
| 768 | OnExtensionMessageInvoke) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 769 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 770 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 771 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 772 | OnEnablePreferredSizeChangedMode) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 773 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 774 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 775 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 776 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId, |
| 777 | OnUpdateBrowserWindowId) |
| 778 | IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType, |
| 779 | OnNotifyRendererViewType) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 780 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 781 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 782 | #if defined(OS_MACOSX) |
| 783 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 784 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 785 | #endif |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 786 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 787 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 788 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode, |
| 789 | OnExecuteCode) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 790 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 791 | OnCustomContextMenuAction) |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 792 | IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage) |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 793 | IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation) |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 794 | IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityTree, OnGetAccessibilityTree) |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 795 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus) |
| 796 | IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction, |
| 797 | OnAccessibilityDoDefaultAction) |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 798 | IPC_MESSAGE_HANDLER(ViewMsg_OpenFileSystemRequest_Complete, |
| 799 | OnOpenFileSystemRequestComplete) |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 800 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 801 | // Have the super handle all other messages. |
| 802 | IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) |
| 803 | IPC_END_MESSAGE_MAP() |
| 804 | } |
| 805 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 806 | void RenderView::OnCaptureThumbnail() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 807 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 808 | if (!main_frame) |
| 809 | return; |
| 810 | |
| 811 | // get the URL for this page |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 812 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 813 | if (url.is_empty()) |
| 814 | return; |
| 815 | |
| 816 | if (size_.IsEmpty()) |
| 817 | return; // Don't create an empty thumbnail! |
| 818 | |
| 819 | ThumbnailScore score; |
| 820 | SkBitmap thumbnail; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 821 | if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight, |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 822 | &thumbnail, &score)) |
| 823 | return; |
| 824 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 825 | // send the thumbnail message to the browser process |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 826 | Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 827 | } |
| 828 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 829 | void RenderView::OnCaptureSnapshot() { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 830 | SkBitmap snapshot; |
| 831 | bool error = false; |
| 832 | |
| 833 | WebFrame* main_frame = webview()->mainFrame(); |
| 834 | if (!main_frame) |
| 835 | error = true; |
| 836 | |
| 837 | if (!error && !CaptureSnapshot(webview(), &snapshot)) |
| 838 | error = true; |
| 839 | |
| 840 | DCHECK(error == snapshot.empty()) << |
| 841 | "Snapshot should be empty on error, non-empty otherwise."; |
| 842 | |
| 843 | // Send the snapshot to the browser process. |
| 844 | Send(new ViewHostMsg_Snapshot(routing_id_, snapshot)); |
| 845 | } |
| 846 | |
[email protected] | 06863722 | 2009-01-29 16:58:07 | [diff] [blame] | 847 | void RenderView::OnPrintPages() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 848 | DCHECK(webview()); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 849 | if (webview()) { |
| 850 | // If the user has selected text in the currently focused frame we print |
| 851 | // only that frame (this makes print selection work for multiple frames). |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 852 | if (webview()->focusedFrame()->hasSelection()) |
| 853 | Print(webview()->focusedFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 854 | else |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 855 | Print(webview()->mainFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 856 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 857 | } |
| 858 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 859 | void RenderView::OnPrintingDone(int document_cookie, bool success) { |
| 860 | // Ignoring document cookie here since only one print job can be outstanding |
| 861 | // per renderer and document_cookie is 0 when printing is successful. |
| 862 | DCHECK(print_helper_.get()); |
| 863 | if (print_helper_.get() != NULL) { |
| 864 | print_helper_->DidFinishPrinting(success); |
| 865 | } |
| 866 | } |
| 867 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 868 | void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { |
| 869 | if (load_id != page_id_) |
| 870 | return; // this capture call is no longer relevant due to navigation |
| 871 | if (load_id == last_indexed_page_id_) |
| 872 | return; // we already indexed this page |
| 873 | |
| 874 | if (!webview()) |
| 875 | return; |
| 876 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 877 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 878 | if (!main_frame) |
| 879 | return; |
| 880 | |
| 881 | // Don't index/capture pages that are in view source mode. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 882 | if (main_frame->isViewSourceModeEnabled()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 883 | return; |
| 884 | |
| 885 | // Don't index/capture pages that failed to load. This only checks the top |
| 886 | // level frame so the thumbnail may contain a frame that failed to load. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 887 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 888 | if (ds && ds->hasUnreachableURL()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 889 | return; |
| 890 | |
| 891 | if (!preliminary_capture) |
| 892 | last_indexed_page_id_ = load_id; |
| 893 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 894 | // Get the URL for this page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 895 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 896 | if (url.is_empty()) |
| 897 | return; |
| 898 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 899 | // Retrieve the frame's full text. |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 900 | string16 contents; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 901 | CaptureText(main_frame, &contents); |
| 902 | if (contents.size()) { |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 903 | base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 904 | std::string language = DetermineTextLanguage(contents); |
| 905 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection", |
| 906 | base::TimeTicks::Now() - begin_time); |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 907 | WebKit::WebDocument document = main_frame->document(); |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 908 | // Send the text to the browser for indexing (the browser might decide not |
| 909 | // to index, if the URL is HTTPS for instance) and language discovery. |
| 910 | Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents, |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 911 | language, IsPageTranslatable(&document))); |
[email protected] | 5c426692 | 2009-07-10 16:41:27 | [diff] [blame] | 912 | } |
| 913 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 914 | OnCaptureThumbnail(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 915 | } |
| 916 | |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 917 | void RenderView::CaptureText(WebFrame* frame, string16* contents) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 918 | contents->clear(); |
| 919 | if (!frame) |
| 920 | return; |
| 921 | |
| 922 | #ifdef TIME_TEXT_RETRIEVAL |
| 923 | double begin = time_util::GetHighResolutionTimeNow(); |
| 924 | #endif |
| 925 | |
| 926 | // get the contents of the frame |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 927 | *contents = frame->contentAsText(kMaxIndexChars); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 928 | |
| 929 | #ifdef TIME_TEXT_RETRIEVAL |
| 930 | double end = time_util::GetHighResolutionTimeNow(); |
| 931 | char buf[128]; |
| 932 | sprintf_s(buf, "%d chars retrieved for indexing in %gms\n", |
| 933 | contents.size(), (end - begin)*1000); |
| 934 | OutputDebugStringA(buf); |
| 935 | #endif |
| 936 | |
| 937 | // When the contents are clipped to the maximum, we don't want to have a |
| 938 | // partial word indexed at the end that might have been clipped. Therefore, |
| 939 | // terminate the string at the last space to ensure no words are clipped. |
| 940 | if (contents->size() == kMaxIndexChars) { |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 941 | size_t last_space_index = contents->find_last_of(kWhitespaceUTF16); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 942 | if (last_space_index == std::wstring::npos) |
| 943 | return; // don't index if we got a huge block of text with no spaces |
| 944 | contents->resize(last_space_index); |
| 945 | } |
| 946 | } |
| 947 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 948 | bool RenderView::CaptureThumbnail(WebView* view, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 949 | int w, |
| 950 | int h, |
| 951 | SkBitmap* thumbnail, |
| 952 | ThumbnailScore* score) { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 953 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 954 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 955 | skia::PlatformCanvas canvas; |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 956 | |
| 957 | // Paint |view| into |canvas|. |
| 958 | if (!PaintViewIntoCanvas(view, canvas)) |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 959 | return false; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 960 | |
| 961 | skia::BitmapPlatformDevice& device = |
| 962 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 963 | |
| 964 | const SkBitmap& src_bmp = device.accessBitmap(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 965 | |
[email protected] | cab34d6a | 2009-09-24 01:14:52 | [diff] [blame] | 966 | SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 967 | float dest_aspect = dest_rect.width() / dest_rect.height(); |
| 968 | |
| 969 | // Get the src rect so that we can preserve the aspect ratio while filling |
| 970 | // the destination. |
| 971 | SkIRect src_rect; |
| 972 | if (src_bmp.width() < dest_rect.width() || |
| 973 | src_bmp.height() < dest_rect.height()) { |
| 974 | // Source image is smaller: we clip the part of source image within the |
| 975 | // dest rect, and then stretch it to fill the dest rect. We don't respect |
| 976 | // the aspect ratio in this case. |
| 977 | src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()), |
| 978 | static_cast<S16CPU>(dest_rect.height())); |
| 979 | score->good_clipping = false; |
| 980 | } else { |
| 981 | float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height(); |
| 982 | if (src_aspect > dest_aspect) { |
| 983 | // Wider than tall, clip horizontally: we center the smaller thumbnail in |
| 984 | // the wider screen. |
| 985 | S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect); |
| 986 | S16CPU x_offset = (src_bmp.width() - new_width) / 2; |
| 987 | src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height()); |
| 988 | score->good_clipping = false; |
| 989 | } else { |
| 990 | src_rect.set(0, 0, src_bmp.width(), |
| 991 | static_cast<S16CPU>(src_bmp.width() / dest_aspect)); |
| 992 | score->good_clipping = true; |
| 993 | } |
| 994 | } |
| 995 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 996 | score->at_top = (view->mainFrame()->scrollOffset().height == 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 997 | |
| 998 | SkBitmap subset; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 999 | device.accessBitmap(false).extractSubset(&subset, src_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1000 | |
| 1001 | // Resample the subset that we want to get it the right size. |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 1002 | *thumbnail = skia::ImageOperations::Resize( |
| 1003 | subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1004 | |
| 1005 | score->boring_score = CalculateBoringScore(thumbnail); |
| 1006 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1007 | HISTOGRAM_TIMES("Renderer4.Thumbnail", |
| 1008 | base::TimeTicks::Now() - beginning_time); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 1009 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1010 | } |
| 1011 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1012 | bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) { |
| 1013 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1014 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1015 | skia::PlatformCanvas canvas; |
| 1016 | if (!PaintViewIntoCanvas(view, canvas)) |
| 1017 | return false; |
| 1018 | |
| 1019 | skia::BitmapPlatformDevice& device = |
| 1020 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 1021 | |
| 1022 | const SkBitmap& bitmap = device.accessBitmap(false); |
| 1023 | if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
| 1024 | return false; |
| 1025 | |
| 1026 | HISTOGRAM_TIMES("Renderer4.Snapshot", |
| 1027 | base::TimeTicks::Now() - beginning_time); |
| 1028 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { |
| 1032 | if (!webview()) |
| 1033 | return; |
| 1034 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1035 | history_list_offset_ = params.current_history_list_offset; |
| 1036 | history_list_length_ = params.current_history_list_length; |
| 1037 | |
[email protected] | 8c785c6 | 2009-07-13 14:20:15 | [diff] [blame] | 1038 | if (devtools_agent_.get()) |
| 1039 | devtools_agent_->OnNavigate(); |
| 1040 | |
[email protected] | 42219753 | 2010-01-25 17:38:23 | [diff] [blame] | 1041 | if (notification_provider_.get()) |
| 1042 | notification_provider_->OnNavigate(); |
| 1043 | |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 1044 | child_process_logging::SetActiveURL(params.url); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1045 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1046 | AboutHandler::MaybeHandle(params.url); |
| 1047 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1048 | bool is_reload = |
| 1049 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD || |
| 1050 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1051 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1052 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1053 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1054 | // We cannot reload if we do not have any history state. This happens, for |
| 1055 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1056 | // a hack since it means that reload after a crashed tab does not cause an |
| 1057 | // end-to-end cache validation. |
| 1058 | is_reload = false; |
| 1059 | } |
| 1060 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1061 | // A navigation resulting from loading a javascript URL should not be treated |
| 1062 | // as a browser initiated event. Instead, we want it to look as if the page |
| 1063 | // initiated any load resulting from JS execution. |
| 1064 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1065 | NavigationState* state = NavigationState::CreateBrowserInitiated( |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1066 | params.page_id, |
| 1067 | params.pending_history_list_offset, |
| 1068 | params.transition, |
| 1069 | params.request_time); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1070 | if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) { |
| 1071 | // We're doing a load of a page that was restored from the last session. |
| 1072 | // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE) |
| 1073 | // which can result in stale data for pages that are set to expire. We |
| 1074 | // explicitly override that by setting the policy here so that as |
| 1075 | // necessary we load from the network. |
| 1076 | state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy); |
| 1077 | } |
| 1078 | pending_navigation_state_.reset(state); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1079 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1080 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1081 | NavigationState* navigation_state = pending_navigation_state_.get(); |
| 1082 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1083 | // If we are reloading, then WebKit will use the history state of the current |
| 1084 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1085 | // have history state, then we need to navigate to it, which corresponds to a |
| 1086 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1087 | if (is_reload) { |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1088 | if (navigation_state) |
| 1089 | navigation_state->set_load_type(NavigationState::RELOAD); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1090 | bool ignore_cache = (params.navigation_type == |
| 1091 | ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE); |
| 1092 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1093 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1094 | // We must know the page ID of the page we are navigating back to. |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 1095 | DCHECK_NE(params.page_id, -1); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1096 | if (navigation_state) |
| 1097 | navigation_state->set_load_type(NavigationState::HISTORY_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1098 | main_frame->loadHistoryItem( |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1099 | webkit_glue::HistoryItemFromString(params.state)); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1100 | } else { |
| 1101 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1102 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1103 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1104 | // A session history navigation should have been accompanied by state. |
| 1105 | DCHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1106 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1107 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1108 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1109 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1110 | if (params.referrer.is_valid()) { |
| 1111 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), |
| 1112 | WebString::fromUTF8(params.referrer.spec())); |
| 1113 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1114 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1115 | if (navigation_state) |
| 1116 | navigation_state->set_load_type(NavigationState::NORMAL_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1117 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1118 | } |
| 1119 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1120 | // In case LoadRequest failed before DidCreateDataSource was called. |
| 1121 | pending_navigation_state_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | // Stop loading the current page |
| 1125 | void RenderView::OnStop() { |
| 1126 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 1127 | webview()->mainFrame()->stopLoading(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1128 | } |
| 1129 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1130 | // Reload current focused frame. |
| 1131 | // E.g. called by right-clicking on the frame and picking "reload this frame". |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1132 | void RenderView::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1133 | if (webview() && webview()->focusedFrame()) { |
| 1134 | // We always obey the cache (ignore_cache=false) here. |
| 1135 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1136 | // a cache-ignoring reload of the frame. |
| 1137 | webview()->focusedFrame()->reload(false); |
| 1138 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1139 | } |
| 1140 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1141 | void RenderView::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1142 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1143 | } |
| 1144 | |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1145 | void RenderView::OnExecuteEditCommand(const std::string& name, |
| 1146 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1147 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1148 | return; |
| 1149 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1150 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1151 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1152 | } |
| 1153 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1154 | void RenderView::OnSetupDevToolsClient() { |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 1155 | DCHECK(!devtools_client_.get()); |
| 1156 | devtools_client_.reset(new DevToolsClient(this)); |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1157 | } |
| 1158 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1159 | void RenderView::OnUpdateTargetURLAck() { |
| 1160 | // Check if there is a targeturl waiting to be sent. |
| 1161 | if (target_url_status_ == TARGET_PENDING) { |
| 1162 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1163 | pending_target_url_)); |
| 1164 | } |
| 1165 | |
| 1166 | target_url_status_ = TARGET_NONE; |
| 1167 | } |
| 1168 | |
| 1169 | void RenderView::OnUndo() { |
| 1170 | if (!webview()) |
| 1171 | return; |
| 1172 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1173 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1174 | UserMetricsRecordAction("Undo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | void RenderView::OnRedo() { |
| 1178 | if (!webview()) |
| 1179 | return; |
| 1180 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1181 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1182 | UserMetricsRecordAction("Redo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | void RenderView::OnCut() { |
| 1186 | if (!webview()) |
| 1187 | return; |
| 1188 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1189 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1190 | UserMetricsRecordAction("Cut"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | void RenderView::OnCopy() { |
| 1194 | if (!webview()) |
| 1195 | return; |
| 1196 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1197 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1198 | UserMetricsRecordAction("Copy"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1199 | } |
| 1200 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1201 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1202 | void RenderView::OnCopyToFindPboard() { |
| 1203 | if (!webview()) |
| 1204 | return; |
| 1205 | |
| 1206 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1207 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1208 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1209 | if (frame->hasSelection()) { |
| 1210 | string16 selection = frame->selectionAsText(); |
| 1211 | RenderThread::current()->Send( |
| 1212 | new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection)); |
| 1213 | } |
| 1214 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1215 | UserMetricsRecordAction("CopyToFindPboard"); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1216 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1217 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1218 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1219 | void RenderView::OnPaste() { |
| 1220 | if (!webview()) |
| 1221 | return; |
| 1222 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1223 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1224 | UserMetricsRecordAction("Paste"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1225 | } |
| 1226 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1227 | void RenderView::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1228 | if (!webview()) |
| 1229 | return; |
| 1230 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1231 | WebFrame* frame = webview()->focusedFrame(); |
| 1232 | if (!frame->hasSelection()) |
| 1233 | frame->selectWordAroundCaret(); |
| 1234 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1235 | } |
| 1236 | |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1237 | void RenderView::OnAdvanceToNextMisspelling() { |
| 1238 | if (!webview()) |
| 1239 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1240 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1241 | WebString::fromUTF8("AdvanceToNextMisspelling")); |
| 1242 | } |
| 1243 | |
| 1244 | void RenderView::OnToggleSpellPanel(bool is_currently_visible) { |
| 1245 | if (!webview()) |
| 1246 | return; |
| 1247 | // We need to tell the webView whether the spelling panel is visible or not so |
| 1248 | // that it won't need to make ipc calls later. |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1249 | spelling_panel_visible_ = is_currently_visible; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1250 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1251 | WebString::fromUTF8("ToggleSpellPanel")); |
| 1252 | } |
| 1253 | |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1254 | void RenderView::OnToggleSpellCheck() { |
| 1255 | if (!webview()) |
| 1256 | return; |
| 1257 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1258 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1259 | frame->enableContinuousSpellChecking( |
| 1260 | !frame->isContinuousSpellCheckingEnabled()); |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1261 | } |
| 1262 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1263 | void RenderView::OnDelete() { |
| 1264 | if (!webview()) |
| 1265 | return; |
| 1266 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1267 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1268 | UserMetricsRecordAction("DeleteSelection"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | void RenderView::OnSelectAll() { |
| 1272 | if (!webview()) |
| 1273 | return; |
| 1274 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1275 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 1276 | WebString::fromUTF8("SelectAll")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1277 | UserMetricsRecordAction("SelectAll"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | void RenderView::OnSetInitialFocus(bool reverse) { |
| 1281 | if (!webview()) |
| 1282 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1283 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /////////////////////////////////////////////////////////////////////////////// |
| 1287 | |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1288 | void RenderView::SetContentSettings(const ContentSettings& settings) { |
| 1289 | current_content_settings_ = settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1290 | } |
| 1291 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1292 | // Tell the embedding application that the URL of the active page has changed |
| 1293 | void RenderView::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1294 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1295 | DCHECK(ds); |
| 1296 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1297 | const WebURLRequest& request = ds->request(); |
| 1298 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1299 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1300 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1301 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 1302 | DCHECK(navigation_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1303 | |
| 1304 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1305 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1306 | params.is_post = false; |
| 1307 | params.page_id = page_id_; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1308 | params.is_content_filtered = response.isContentFiltered(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1309 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1310 | if (!navigation_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1311 | // SSL state specified in the request takes precedence over the one in the |
| 1312 | // response. |
| 1313 | // So far this is only intended for error pages that are not expected to be |
| 1314 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1315 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1316 | params.security_info = navigation_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1317 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1318 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1322 | if (ds->hasUnreachableURL()) { |
| 1323 | params.url = ds->unreachableURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1324 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1325 | params.url = request.url(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1326 | } |
| 1327 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1328 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1329 | params.should_update_history = !ds->hasUnreachableURL() && |
| 1330 | !response.isMultipartPayload(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1331 | |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1332 | params.searchable_form_url = navigation_state->searchable_form_url(); |
| 1333 | params.searchable_form_encoding = |
| 1334 | navigation_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1335 | |
| 1336 | const PasswordForm* password_form_data = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1337 | navigation_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1338 | if (password_form_data) |
| 1339 | params.password_form = *password_form_data; |
| 1340 | |
| 1341 | params.gesture = navigation_gesture_; |
| 1342 | navigation_gesture_ = NavigationGestureUnknown; |
| 1343 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1344 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1345 | // Top-level navigation. |
| 1346 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 1347 | // Clear "block" flags for the new page. This needs to happen before any of |
| 1348 | // allowScripts(), allowImages(), allowPlugins() is called for the new page |
| 1349 | // so that these functions can correctly detect that a piece of content |
| 1350 | // flipped from "not blocked" to "blocked". |
| 1351 | ClearBlockedContentSettings(); |
| 1352 | |
[email protected] | 62d2a11 | 2010-04-07 00:53:02 | [diff] [blame] | 1353 | // Set content settings. Default them from the parent window if one exists. |
| 1354 | // This makes sure about:blank windows work as expected. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1355 | HostContentSettings::iterator host_content_settings = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1356 | host_content_settings_.find(GURL(request.url())); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1357 | if (host_content_settings != host_content_settings_.end()) { |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1358 | SetContentSettings(host_content_settings->second); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1359 | |
| 1360 | // These content settings were merely recorded transiently for this load. |
| 1361 | // We can erase them now. If at some point we reload this page, the |
| 1362 | // browser will send us new, up-to-date content settings. |
| 1363 | host_content_settings_.erase(host_content_settings); |
[email protected] | 3a387ae | 2010-04-08 01:58:40 | [diff] [blame] | 1364 | } else if (frame->opener()) { |
[email protected] | 8128cdd0 | 2010-07-21 20:40:10 | [diff] [blame] | 1365 | // The opener's view is not guaranteed to be non-null (it could be |
| 1366 | // detached from its page but not yet destructed). |
| 1367 | if (WebView* opener_view = frame->opener()->view()) { |
| 1368 | RenderView* opener = FromWebView(opener_view); |
| 1369 | SetContentSettings(opener->current_content_settings_); |
| 1370 | } |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1371 | } |
| 1372 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1373 | // Set zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1374 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1375 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1376 | if (host_zoom != host_zoom_levels_.end()) { |
| 1377 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1378 | // This zoom level was merely recorded transiently for this load. We can |
| 1379 | // erase it now. If at some point we reload this page, the browser will |
| 1380 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1381 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1382 | } |
| 1383 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1384 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1385 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1386 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1387 | params.transition = navigation_state->transition_type(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1388 | if (!PageTransition::IsMainFrame(params.transition)) { |
| 1389 | // If the main frame does a load, it should not be reported as a subframe |
| 1390 | // navigation. This can occur in the following case: |
| 1391 | // 1. You're on a site with frames. |
| 1392 | // 2. You do a subframe navigation. This is stored with transition type |
| 1393 | // MANUAL_SUBFRAME. |
| 1394 | // 3. You navigate to some non-frame site, say, google.com. |
| 1395 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1396 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1397 | // We don't want that, because any navigation that changes the toplevel |
| 1398 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1399 | // update the URL bar, etc). |
| 1400 | params.transition = PageTransition::LINK; |
| 1401 | } |
| 1402 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1403 | // If we have a valid consumed client redirect source, |
| 1404 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1405 | // so we set the referrer and transition to match. |
| 1406 | if (completed_client_redirect_src_.is_valid()) { |
[email protected] | 77e09a9 | 2008-08-01 18:11:04 | [diff] [blame] | 1407 | DCHECK(completed_client_redirect_src_ == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1408 | params.referrer = completed_client_redirect_src_; |
| 1409 | params.transition = static_cast<PageTransition::Type>( |
| 1410 | params.transition | PageTransition::CLIENT_REDIRECT); |
| 1411 | } else { |
| 1412 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1413 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1414 | params.referrer = GURL( |
| 1415 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1416 | } |
| 1417 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1418 | string16 method = request.httpMethod(); |
| 1419 | if (EqualsASCII(method, "POST")) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1420 | params.is_post = true; |
| 1421 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1422 | // Save some histogram data so we can compute the average memory used per |
| 1423 | // page load of the glyphs. |
| 1424 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1425 | webkit_glue::GetGlyphPageCount()); |
| 1426 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1427 | // This message needs to be sent before any of allowScripts(), |
| 1428 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1429 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1430 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1431 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1432 | } else { |
| 1433 | // Subframe navigation: the type depends on whether this navigation |
| 1434 | // generated a new session history entry. When they do generate a session |
| 1435 | // history entry, it means the user initiated the navigation and we should |
| 1436 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1437 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1438 | if (page_id_ > last_page_id_sent_to_browser_) |
| 1439 | params.transition = PageTransition::MANUAL_SUBFRAME; |
| 1440 | else |
| 1441 | params.transition = PageTransition::AUTO_SUBFRAME; |
| 1442 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1443 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1444 | } |
| 1445 | |
| 1446 | last_page_id_sent_to_browser_ = |
| 1447 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1448 | |
| 1449 | // If we end up reusing this WebRequest (for example, due to a #ref click), |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1450 | // we don't want the transition type to persist. Just clear it. |
| 1451 | navigation_state->set_transition_type(PageTransition::LINK); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1452 | |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1453 | // Check if the navigation was within the same page, in which case we don't |
| 1454 | // want to clear the accessibility cache. |
| 1455 | if (accessibility_.get() && !navigation_state->was_within_same_page()) { |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 1456 | accessibility_->clear(); |
[email protected] | 1745596 | 2010-02-24 01:39:35 | [diff] [blame] | 1457 | accessibility_.reset(); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1458 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1462 | void RenderView::UpdateTitle(WebFrame* frame, const string16& title) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1463 | // Ignore all but top level navigations... |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1464 | if (!frame->parent()) { |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1465 | Send(new ViewHostMsg_UpdateTitle( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1466 | routing_id_, |
| 1467 | page_id_, |
| 1468 | UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ? |
| 1469 | title.substr(0, chrome::kMaxTitleChars) : title))); |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1470 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | void RenderView::UpdateEncoding(WebFrame* frame, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1474 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1475 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1476 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1477 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1478 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1479 | last_encoding_name_ = encoding_name; |
| 1480 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1481 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
[email protected] | f4d34b5 | 2008-11-24 23:05:01 | [diff] [blame] | 1485 | // Sends the previous session history state to the browser so it will be saved |
| 1486 | // before we navigate to a new page. This must be called *before* the page ID |
| 1487 | // has been updated so we know what it was. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1488 | void RenderView::UpdateSessionHistory(WebFrame* frame) { |
| 1489 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1490 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1491 | // there is no past session history to record. |
| 1492 | if (page_id_ == -1) |
| 1493 | return; |
| 1494 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1495 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1496 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1497 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1498 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1499 | |
| 1500 | Send(new ViewHostMsg_UpdateState( |
| 1501 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1502 | } |
| 1503 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1504 | void RenderView::OpenURL( |
| 1505 | const GURL& url, const GURL& referrer, WebNavigationPolicy policy) { |
| 1506 | Send(new ViewHostMsg_OpenURL( |
| 1507 | routing_id_, url, referrer, NavigationPolicyToDisposition(policy))); |
| 1508 | } |
| 1509 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1510 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1511 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1512 | void RenderView::LoadNavigationErrorPage(WebFrame* frame, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1513 | const WebURLRequest& failed_request, |
| 1514 | const WebURLError& error, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1515 | const std::string& html, |
| 1516 | bool replace) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1517 | GURL failed_url = error.unreachableURL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1518 | |
| 1519 | std::string alt_html; |
| 1520 | if (html.empty()) { |
| 1521 | // Use a local error page. |
| 1522 | int resource_id; |
| 1523 | DictionaryValue error_strings; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1524 | if (error.reason == net::ERR_CACHE_MISS && |
| 1525 | EqualsASCII(failed_request.httpMethod(), "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1526 | GetFormRepostErrorValues(failed_url, &error_strings); |
| 1527 | resource_id = IDR_ERROR_NO_DETAILS_HTML; |
| 1528 | } else { |
| 1529 | GetLocalizedErrorValues(error, &error_strings); |
| 1530 | resource_id = IDR_NET_ERROR_HTML; |
| 1531 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1532 | |
| 1533 | alt_html = GetAltHTMLForTemplate(error_strings, resource_id); |
| 1534 | } else { |
| 1535 | alt_html = html; |
| 1536 | } |
| 1537 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1538 | frame->loadHTMLString(alt_html, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1539 | GURL(kUnreachableWebDataURL), |
| 1540 | failed_url, |
| 1541 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1542 | } |
| 1543 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 1544 | void RenderView::BindDOMAutomationController(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1545 | dom_automation_controller_.set_message_sender(this); |
| 1546 | dom_automation_controller_.set_routing_id(routing_id_); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 1547 | dom_automation_controller_.BindToJavascript(frame, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1548 | L"domAutomationController"); |
| 1549 | } |
| 1550 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1551 | bool RenderView::RunJavaScriptMessage(int type, |
| 1552 | const std::wstring& message, |
| 1553 | const std::wstring& default_value, |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1554 | const GURL& frame_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1555 | std::wstring* result) { |
| 1556 | bool success = false; |
| 1557 | std::wstring result_temp; |
| 1558 | if (!result) |
| 1559 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1560 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1561 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1562 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1563 | return success; |
| 1564 | } |
| 1565 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1566 | bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
| 1567 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1568 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1569 | // it is particularly important that we do not call willEnterModalLoop as |
| 1570 | // that would defer resource loads for the dialog itself. |
| 1571 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 1572 | RenderThread::current()->DoNotNotifyWebKitOfModalLoop(); |
| 1573 | |
| 1574 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1575 | return Send(message); |
| 1576 | } |
| 1577 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1578 | void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) { |
| 1579 | if (!osd_url.is_empty()) |
| 1580 | Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, |
| 1581 | autodetected)); |
| 1582 | } |
| 1583 | |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1584 | void RenderView::OnAutoFillSuggestionsReturned( |
| 1585 | int query_id, |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 1586 | const std::vector<string16>& values, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 1587 | const std::vector<string16>& labels, |
[email protected] | a53e0683 | 2010-07-28 22:46:41 | [diff] [blame] | 1588 | const std::vector<string16>& icons, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 1589 | const std::vector<int>& unique_ids) { |
[email protected] | a53e0683 | 2010-07-28 22:46:41 | [diff] [blame] | 1590 | autofill_helper_.SuggestionsReceived( |
| 1591 | query_id, values, labels, icons, unique_ids); |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1592 | } |
| 1593 | |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 1594 | void RenderView::OnAutoFillFormDataFilled(int query_id, |
| 1595 | const webkit_glue::FormData& form) { |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 1596 | autofill_helper_.FormDataFilled(query_id, form); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 1597 | } |
| 1598 | |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1599 | void RenderView::OnAllowScriptToClose(bool script_can_close) { |
| 1600 | script_can_close_ = script_can_close; |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1601 | } |
| 1602 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1603 | uint32 RenderView::GetCPBrowsingContext() { |
| 1604 | uint32 context = 0; |
| 1605 | Send(new ViewHostMsg_GetCPBrowsingContext(&context)); |
| 1606 | return context; |
| 1607 | } |
| 1608 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1609 | void RenderView::AddSearchProvider(const std::string& url) { |
| 1610 | AddGURLSearchProvider(GURL(url), |
| 1611 | false); // not autodetected |
| 1612 | } |
| 1613 | |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1614 | ViewHostMsg_GetSearchProviderInstallState_Params |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1615 | RenderView::GetSearchProviderInstallState(WebFrame* frame, |
| 1616 | const std::string& url) { |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1617 | GURL inquiry_url = GURL(url); |
| 1618 | if (inquiry_url.is_empty()) |
| 1619 | return ViewHostMsg_GetSearchProviderInstallState_Params::Denied(); |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1620 | |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1621 | ViewHostMsg_GetSearchProviderInstallState_Params install; |
| 1622 | Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_, |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1623 | frame->url(), |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1624 | inquiry_url, |
| 1625 | &install)); |
| 1626 | return install; |
| 1627 | } |
| 1628 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1629 | void RenderView::OnMissingPluginStatus( |
| 1630 | WebPluginDelegateProxy* delegate, |
| 1631 | int status) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1632 | #if defined(OS_WIN) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1633 | if (!first_default_plugin_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1634 | // Show the InfoBar for the first available plugin. |
| 1635 | if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1636 | first_default_plugin_ = delegate->AsWeakPtr(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1637 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1638 | } |
| 1639 | } else { |
| 1640 | // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar) |
| 1641 | // to start the download/install. |
| 1642 | if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) { |
| 1643 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1644 | } |
| 1645 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1646 | #else |
[email protected] | 76c3b31 | 2010-05-20 21:38:29 | [diff] [blame] | 1647 | // TODO(port): Implement the infobar that accompanies the default plugin. |
| 1648 | // Linux: http://crbug.com/10952 |
| 1649 | // Mac: http://crbug.com/17392 |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1650 | NOTIMPLEMENTED(); |
| 1651 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1652 | } |
| 1653 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1654 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1655 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1656 | WebView* RenderView::createView( |
| 1657 | WebFrame* creator, |
| 1658 | const WebWindowFeatures& features, |
| 1659 | const WebString& frame_name) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1660 | // Check to make sure we aren't overloading on popups. |
| 1661 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1662 | return NULL; |
| 1663 | |
| 1664 | // This window can't be closed from a window.close() call until we receive a |
| 1665 | // message from the Browser process explicitly allowing it. |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1666 | script_can_close_ = false; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1667 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1668 | ViewHostMsg_CreateWindow_Params params; |
| 1669 | params.opener_id = routing_id_; |
| 1670 | params.user_gesture = creator->isProcessingUserGesture(); |
| 1671 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1672 | params.session_storage_namespace_id = session_storage_namespace_id_; |
| 1673 | params.frame_name = frame_name; |
| 1674 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1675 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1676 | int64 cloned_session_storage_namespace_id; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1677 | bool opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1678 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1679 | render_thread_->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1680 | new ViewHostMsg_CreateWindow(params, |
| 1681 | &routing_id, |
| 1682 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1683 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1684 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1685 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1686 | RenderView* view = RenderView::Create(render_thread_, |
[email protected] | 659f73fa | 2009-10-13 13:43:42 | [diff] [blame] | 1687 | 0, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1688 | routing_id_, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1689 | renderer_preferences_, |
| 1690 | webkit_preferences_, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1691 | shared_popup_counter_, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1692 | routing_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1693 | cloned_session_storage_namespace_id, |
| 1694 | frame_name); |
| 1695 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1696 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1697 | // Record whether the creator frame is trying to suppress the opener field. |
| 1698 | view->opener_suppressed_ = opener_suppressed; |
| 1699 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1700 | // Record the security origin of the creator. |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 1701 | GURL creator_url(creator->securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1702 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1703 | creator_url = GURL(); |
| 1704 | view->creator_url_ = creator_url; |
| 1705 | |
| 1706 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1707 | // the new render view (we don't need the browser to send the URL back down). |
| 1708 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1709 | |
| 1710 | return view->webview(); |
| 1711 | } |
| 1712 | |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1713 | WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1714 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1715 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1716 | popup_type); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1717 | return widget->webwidget(); |
| 1718 | } |
| 1719 | |
| 1720 | WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) { |
| 1721 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1722 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1723 | WebKit::WebPopupTypeSelect); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1724 | widget->ConfigureAsExternalPopupMenu(info); |
| 1725 | return widget->webwidget(); |
| 1726 | } |
| 1727 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 1728 | WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) { |
| 1729 | RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_, |
| 1730 | render_thread_, |
| 1731 | popup_type); |
| 1732 | return widget->webwidget(); |
| 1733 | } |
| 1734 | |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1735 | WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) { |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1736 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1737 | return WebStorageNamespace::createSessionStorageNamespace(quota); |
[email protected] | 59afea1 | 2010-01-20 04:48:29 | [diff] [blame] | 1738 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
| 1739 | return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION, |
| 1740 | session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1741 | } |
| 1742 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1743 | void RenderView::didAddMessageToConsole( |
| 1744 | const WebConsoleMessage& message, const WebString& source_name, |
| 1745 | unsigned source_line) { |
| 1746 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
| 1747 | UTF16ToWideHack(message.text), |
| 1748 | static_cast<int32>(source_line), |
| 1749 | UTF16ToWideHack(source_name))); |
| 1750 | } |
| 1751 | |
| 1752 | void RenderView::printPage(WebFrame* frame) { |
[email protected] | 71a1426 | 2009-09-22 20:02:58 | [diff] [blame] | 1753 | DCHECK(frame); |
| 1754 | Print(frame, true); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1755 | } |
| 1756 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 1757 | WebKit::WebNotificationPresenter* RenderView::notificationPresenter() { |
| 1758 | return notification_provider_.get(); |
| 1759 | } |
| 1760 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1761 | void RenderView::didStartLoading() { |
| 1762 | if (is_loading_) { |
| 1763 | DLOG(WARNING) << "didStartLoading called while loading"; |
| 1764 | return; |
| 1765 | } |
| 1766 | |
| 1767 | is_loading_ = true; |
| 1768 | // Clear the pointer so that we can assign it only when there is an unknown |
| 1769 | // plugin on a page. |
| 1770 | first_default_plugin_.reset(); |
| 1771 | |
| 1772 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
| 1773 | } |
| 1774 | |
| 1775 | void RenderView::didStopLoading() { |
| 1776 | if (!is_loading_) { |
| 1777 | DLOG(WARNING) << "DidStopLoading called while not loading"; |
| 1778 | return; |
| 1779 | } |
| 1780 | |
| 1781 | is_loading_ = false; |
| 1782 | |
| 1783 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1784 | // when done loading. This currently isn't an issue as the favicon is only |
| 1785 | // displayed when done loading. Ideally we would send notification when |
| 1786 | // finished parsing the head, but webkit doesn't support that yet. |
| 1787 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1788 | GURL favicon_url(webview()->mainFrame()->favIconURL()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1789 | if (!favicon_url.is_empty()) |
| 1790 | Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url)); |
| 1791 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1792 | AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1793 | true); // autodetected |
| 1794 | |
| 1795 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1796 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 1797 | MessageLoop::current()->PostDelayedTask( |
| 1798 | FROM_HERE, |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1799 | page_info_method_factory_.NewRunnableMethod( |
| 1800 | &RenderView::CapturePageInfo, page_id_, false), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1801 | kDelayForCaptureMs); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1802 | } |
| 1803 | |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 1804 | bool RenderView::isSmartInsertDeleteEnabled() { |
| 1805 | #if defined(OS_MACOSX) |
| 1806 | return true; |
| 1807 | #else |
| 1808 | return false; |
| 1809 | #endif |
| 1810 | } |
| 1811 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1812 | bool RenderView::isSelectTrailingWhitespaceEnabled() { |
| 1813 | #if defined(OS_WIN) |
| 1814 | return true; |
| 1815 | #else |
| 1816 | return false; |
| 1817 | #endif |
| 1818 | } |
| 1819 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1820 | void RenderView::didChangeSelection(bool is_empty_selection) { |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 1821 | #if defined(USE_X11) || defined(OS_MACOSX) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1822 | if (!handling_input_event_) |
| 1823 | return; |
| 1824 | // TODO(estade): investigate incremental updates to the selection so that we |
| 1825 | // don't send the entire selection over IPC every time. |
| 1826 | if (!is_empty_selection) { |
| 1827 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 1828 | // the selection hasn't actually changed. We don't want to report these |
| 1829 | // because it will cause us to continually claim the X clipboard. |
| 1830 | const std::string& this_selection = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1831 | webview()->focusedFrame()->selectionAsText().utf8(); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1832 | if (this_selection == last_selection_) |
| 1833 | return; |
| 1834 | |
| 1835 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 1836 | this_selection)); |
| 1837 | last_selection_ = this_selection; |
| 1838 | } else { |
| 1839 | last_selection_.clear(); |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 1840 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 1841 | last_selection_)); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1842 | } |
| 1843 | #endif |
| 1844 | } |
| 1845 | |
| 1846 | void RenderView::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1847 | const std::string& name = UTF16ToUTF8(command_name); |
| 1848 | if (StartsWithASCII(name, "Move", true) || |
| 1849 | StartsWithASCII(name, "Insert", true) || |
| 1850 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1851 | return; |
| 1852 | UserMetricsRecordAction(name); |
| 1853 | } |
| 1854 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1855 | void RenderView::textFieldDidEndEditing( |
| 1856 | const WebKit::WebInputElement& element) { |
| 1857 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
| 1858 | password_autocomplete_manager_.TextFieldDidEndEditing(element); |
| 1859 | #endif |
| 1860 | } |
| 1861 | |
| 1862 | void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) { |
| 1863 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1864 | // We post a task for doing the AutoFill as the caret position is not set |
| 1865 | // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and |
| 1866 | // it is needed to trigger autofill. |
| 1867 | autofill_method_factory_.RevokeAll(); |
| 1868 | MessageLoop::current()->PostTask( |
| 1869 | FROM_HERE, |
| 1870 | autofill_method_factory_.NewRunnableMethod( |
| 1871 | &RenderView::TextFieldDidChangeImpl, element)); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1872 | #endif |
| 1873 | } |
| 1874 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1875 | void RenderView::TextFieldDidChangeImpl( |
| 1876 | const WebKit::WebInputElement& element) { |
| 1877 | if (password_autocomplete_manager_.TextDidChangeInTextField(element)) |
| 1878 | return; |
| 1879 | autofill_helper_.TextDidChangeInTextField(element); |
| 1880 | } |
| 1881 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1882 | void RenderView::textFieldDidReceiveKeyDown( |
| 1883 | const WebKit::WebInputElement& element, |
| 1884 | const WebKit::WebKeyboardEvent& event) { |
| 1885 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
| 1886 | password_autocomplete_manager_.TextFieldHandlingKeyDown(element, event); |
| 1887 | #endif |
| 1888 | } |
| 1889 | |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1890 | bool RenderView::handleCurrentKeyboardEvent() { |
| 1891 | if (edit_commands_.empty()) |
| 1892 | return false; |
| 1893 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1894 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1895 | if (!frame) |
| 1896 | return false; |
| 1897 | |
| 1898 | EditCommands::iterator it = edit_commands_.begin(); |
| 1899 | EditCommands::iterator end = edit_commands_.end(); |
| 1900 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1901 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1902 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 1903 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 1904 | // key (but it's the exception). Once one edit command is not executed, it |
| 1905 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1906 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 1907 | WebString::fromUTF8(it->value))) |
| 1908 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1909 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1910 | } |
| 1911 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1912 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1913 | } |
| 1914 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1915 | void RenderView::inputElementClicked(const WebKit::WebInputElement& element, |
| 1916 | bool already_focused) { |
| 1917 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
| 1918 | if (password_autocomplete_manager_.InputElementClicked(element, |
| 1919 | already_focused)) { |
| 1920 | return; |
| 1921 | } |
| 1922 | autofill_helper_.InputElementClicked(element, already_focused); |
| 1923 | #endif |
| 1924 | } |
| 1925 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1926 | void RenderView::spellCheck(const WebString& text, |
| 1927 | int& misspelled_offset, |
| 1928 | int& misspelled_length) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1929 | EnsureDocumentTag(); |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1930 | |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1931 | string16 word(text); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1932 | RenderThread* thread = RenderThread::current(); |
| 1933 | // Will be NULL during unit tests. |
| 1934 | if (thread) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1935 | thread->spellchecker()->SpellCheckWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1936 | word.c_str(), word.size(), document_tag_, |
| 1937 | &misspelled_offset, &misspelled_length, NULL); |
| 1938 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | WebString RenderView::autoCorrectWord(const WebKit::WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1942 | string16 autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1943 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | b86c8c1 | 2009-10-05 22:01:26 | [diff] [blame] | 1944 | if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1945 | EnsureDocumentTag(); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1946 | RenderThread* thread = RenderThread::current(); |
| 1947 | // Will be NULL during unit tests. |
| 1948 | if (thread) { |
| 1949 | autocorrect_word = |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1950 | thread->spellchecker()->GetAutoCorrectionWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1951 | word, document_tag_); |
| 1952 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1953 | } |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1954 | return autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1955 | } |
| 1956 | |
[email protected] | c49085c7 | 2009-10-02 16:28:56 | [diff] [blame] | 1957 | void RenderView::showSpellingUI(bool show) { |
| 1958 | Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show)); |
| 1959 | } |
| 1960 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1961 | bool RenderView::isShowingSpellingUI() { |
| 1962 | return spelling_panel_visible_; |
| 1963 | } |
| 1964 | |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1965 | void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1966 | Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
| 1967 | word)); |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1968 | } |
| 1969 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1970 | bool RenderView::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 1971 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1972 | WebFileChooserCompletion* chooser_completion) { |
| 1973 | ViewHostMsg_RunFileChooser_Params ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 1974 | if (params.directory) |
| 1975 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; |
| 1976 | else if (params.multiSelect) |
| 1977 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple; |
| 1978 | else |
| 1979 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1980 | ipc_params.title = params.title; |
| 1981 | ipc_params.default_file_name = |
| 1982 | webkit_glue::WebStringToFilePath(params.initialValue); |
| 1983 | |
| 1984 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1985 | } |
| 1986 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1987 | void RenderView::runModalAlertDialog( |
| 1988 | WebFrame* frame, const WebString& message) { |
| 1989 | RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert, |
| 1990 | UTF16ToWideHack(message), |
| 1991 | std::wstring(), |
| 1992 | frame->url(), |
| 1993 | NULL); |
| 1994 | } |
| 1995 | |
| 1996 | bool RenderView::runModalConfirmDialog( |
| 1997 | WebFrame* frame, const WebString& message) { |
| 1998 | return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm, |
| 1999 | UTF16ToWideHack(message), |
| 2000 | std::wstring(), |
| 2001 | frame->url(), |
| 2002 | NULL); |
| 2003 | } |
| 2004 | |
| 2005 | bool RenderView::runModalPromptDialog( |
| 2006 | WebFrame* frame, const WebString& message, const WebString& default_value, |
| 2007 | WebString* actual_value) { |
| 2008 | std::wstring result; |
| 2009 | bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt, |
| 2010 | UTF16ToWideHack(message), |
| 2011 | UTF16ToWideHack(default_value), |
| 2012 | frame->url(), |
| 2013 | &result); |
| 2014 | if (ok) |
| 2015 | actual_value->assign(WideToUTF16Hack(result)); |
| 2016 | return ok; |
| 2017 | } |
| 2018 | |
| 2019 | bool RenderView::runModalBeforeUnloadDialog( |
| 2020 | WebFrame* frame, const WebString& message) { |
| 2021 | bool success = false; |
| 2022 | // This is an ignored return value, but is included so we can accept the same |
| 2023 | // response as RunJavaScriptMessage. |
| 2024 | std::wstring ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2025 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2026 | routing_id_, frame->url(), UTF16ToWideHack(message), &success, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2027 | &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2028 | return success; |
| 2029 | } |
| 2030 | |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2031 | void RenderView::showContextMenu( |
| 2032 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2033 | ContextMenuParams params = ContextMenuParams(data); |
| 2034 | if (!params.misspelled_word.empty() && RenderThread::current()) { |
| 2035 | int misspelled_offset, misspelled_length; |
[email protected] | c76a36a | 2010-01-26 22:44:04 | [diff] [blame] | 2036 | bool spelled_right = RenderThread::current()->spellchecker()-> |
| 2037 | SpellCheckWord( |
| 2038 | params.misspelled_word.c_str(), params.misspelled_word.size(), |
| 2039 | document_tag_, |
| 2040 | &misspelled_offset, &misspelled_length, |
| 2041 | ¶ms.dictionary_suggestions); |
| 2042 | if (spelled_right) |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2043 | params.misspelled_word.clear(); |
| 2044 | } |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame^] | 2045 | // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do |
| 2046 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2047 | // in the context menu. |
| 2048 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2049 | // data encoded images. We should have a way to save them. |
| 2050 | if (params.src_url.spec().size() > chrome::kMaxURLChars) |
| 2051 | params.src_url = GURL(); |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2052 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2053 | } |
| 2054 | |
[email protected] | 52f139e2c | 2010-06-11 16:56:09 | [diff] [blame] | 2055 | bool RenderView::supportsFullscreen() { |
| 2056 | return CommandLine::ForCurrentProcess()->HasSwitch( |
| 2057 | switches::kEnableVideoFullscreen); |
| 2058 | } |
| 2059 | |
| 2060 | void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) { |
| 2061 | NOTIMPLEMENTED(); |
| 2062 | } |
| 2063 | |
| 2064 | void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) { |
| 2065 | NOTIMPLEMENTED(); |
| 2066 | } |
| 2067 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2068 | void RenderView::setStatusText(const WebString& text) { |
| 2069 | } |
| 2070 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2071 | void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2072 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2073 | if (latest_url == target_url_) |
| 2074 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2075 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2076 | // Tell the browser to display a destination link. |
| 2077 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2078 | target_url_status_ == TARGET_PENDING) { |
| 2079 | // If we have a request in-flight, save the URL to be sent when we |
| 2080 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2081 | // any existing pending sends. |
| 2082 | pending_target_url_ = latest_url; |
| 2083 | target_url_status_ = TARGET_PENDING; |
| 2084 | } else { |
| 2085 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2086 | target_url_ = latest_url; |
| 2087 | target_url_status_ = TARGET_INFLIGHT; |
| 2088 | } |
| 2089 | } |
| 2090 | |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 2091 | bool RenderView::IsPageTranslatable(WebKit::WebDocument* document) { |
| 2092 | std::vector<WebKit::WebElement> meta_elements; |
| 2093 | webkit_glue::GetMetaElementsWithName(document, ASCIIToUTF16("google"), |
| 2094 | &meta_elements); |
| 2095 | std::vector<WebKit::WebElement>::const_iterator iter; |
| 2096 | for (iter = meta_elements.begin(); iter != meta_elements.end(); ++iter) { |
| 2097 | WebString attribute = iter->getAttribute("value"); |
| 2098 | if (attribute.isNull()) // We support both 'value' and 'content'. |
| 2099 | attribute = iter->getAttribute("content"); |
| 2100 | if (attribute.isNull()) |
| 2101 | continue; |
| 2102 | if (LowerCaseEqualsASCII(attribute, "notranslate")) |
| 2103 | return false; |
| 2104 | } |
| 2105 | return true; |
| 2106 | } |
| 2107 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2108 | void RenderView::StartNavStateSyncTimerIfNecessary() { |
| 2109 | int delay; |
| 2110 | if (send_content_state_immediately_) |
| 2111 | delay = 0; |
| 2112 | else if (is_hidden()) |
| 2113 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2114 | else |
| 2115 | delay = kDelaySecondsForContentStateSync; |
| 2116 | |
| 2117 | if (nav_state_sync_timer_.IsRunning()) { |
| 2118 | // The timer is already running. If the delay of the timer maches the amount |
| 2119 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2120 | // gets started with the right delay. |
| 2121 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2122 | return; |
| 2123 | nav_state_sync_timer_.Stop(); |
| 2124 | } |
| 2125 | |
| 2126 | nav_state_sync_timer_.Start( |
| 2127 | TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState); |
| 2128 | } |
| 2129 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2130 | void RenderView::setMouseOverURL(const WebURL& url) { |
| 2131 | mouse_over_url_ = GURL(url); |
| 2132 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2133 | } |
| 2134 | |
| 2135 | void RenderView::setKeyboardFocusURL(const WebURL& url) { |
| 2136 | focus_url_ = GURL(url); |
| 2137 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2138 | } |
| 2139 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2140 | void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) { |
| 2141 | Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text), |
| 2142 | hint)); |
| 2143 | } |
| 2144 | |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2145 | void RenderView::startDragging(const WebDragData& data, |
| 2146 | WebDragOperationsMask mask, |
| 2147 | const WebImage& image, |
| 2148 | const WebPoint& imageOffset) { |
| 2149 | #if WEBKIT_USING_SKIA |
| 2150 | SkBitmap bitmap(image.getSkBitmap()); |
| 2151 | #elif WEBKIT_USING_CG |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 2152 | SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2153 | #endif |
| 2154 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2155 | Send(new ViewHostMsg_StartDragging(routing_id_, |
| 2156 | WebDropData(data), |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2157 | mask, |
| 2158 | bitmap, |
| 2159 | imageOffset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2160 | } |
| 2161 | |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2162 | bool RenderView::acceptsLoadDrops() { |
| 2163 | return renderer_preferences_.can_accept_load_drops; |
| 2164 | } |
| 2165 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2166 | void RenderView::focusNext() { |
| 2167 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2168 | } |
| 2169 | |
| 2170 | void RenderView::focusPrevious() { |
| 2171 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2172 | } |
| 2173 | |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2174 | void RenderView::focusedNodeChanged(const WebNode& node) { |
| 2175 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_)); |
| 2176 | } |
| 2177 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2178 | void RenderView::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2179 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2180 | } |
| 2181 | |
| 2182 | int RenderView::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2183 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | int RenderView::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2187 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2188 | } |
| 2189 | |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2190 | void RenderView::didUpdateInspectorSetting(const WebString& key, |
| 2191 | const WebString& value) { |
| 2192 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2193 | key.utf8(), |
| 2194 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2195 | } |
| 2196 | |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 2197 | void RenderView::queryAutofillSuggestions(const WebNode& node, |
| 2198 | const WebString& name, |
| 2199 | const WebString& value) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2200 | autofill_helper_.QueryAutoFillSuggestions(node, name, value); |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | void RenderView::removeAutofillSuggestions(const WebString& name, |
| 2204 | const WebString& value) { |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 2205 | autofill_helper_.RemoveAutocompleteSuggestion(name, value); |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 2206 | } |
| 2207 | |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2208 | void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node, |
| 2209 | const WebKit::WebString& value, |
[email protected] | 1cf47dd5 | 2010-06-10 22:41:20 | [diff] [blame] | 2210 | const WebKit::WebString& label, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 2211 | int unique_id, |
[email protected] | 1cf47dd5 | 2010-06-10 22:41:20 | [diff] [blame] | 2212 | unsigned index) { |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 2213 | autofill_helper_.DidAcceptAutoFillSuggestion(node, value, label, unique_id, |
| 2214 | index); |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2215 | } |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2216 | |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2217 | void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node, |
| 2218 | const WebKit::WebString& value, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 2219 | const WebKit::WebString& label, |
| 2220 | int unique_id) { |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 2221 | autofill_helper_.DidSelectAutoFillSuggestion(node, value, label, unique_id); |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) { |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 2225 | autofill_helper_.DidClearAutoFillSelection(node); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2226 | } |
| 2227 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2228 | void RenderView::didAcceptAutocompleteSuggestion( |
| 2229 | const WebKit::WebInputElement& user_element) { |
| 2230 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
| 2231 | bool result = password_autocomplete_manager_.FillPassword(user_element); |
| 2232 | // Since this user name was selected from a suggestion list, we should always |
| 2233 | // have password for it. |
| 2234 | DCHECK(result); |
| 2235 | #endif |
| 2236 | } |
| 2237 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2238 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2239 | |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2240 | void RenderView::didFocus() { |
| 2241 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2242 | // we won't have to test for user gesture anymore and we can |
| 2243 | // move that code back to render_widget.cc |
| 2244 | if (webview() && webview()->mainFrame() && |
| 2245 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2246 | Send(new ViewHostMsg_Focus(routing_id_)); |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | void RenderView::didBlur() { |
| 2251 | // TODO(jcivelli): see TODO above in didFocus(). |
| 2252 | if (webview() && webview()->mainFrame() && |
| 2253 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2254 | Send(new ViewHostMsg_Blur(routing_id_)); |
| 2255 | } |
| 2256 | } |
| 2257 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2258 | // We are supposed to get a single call to Show for a newly created RenderView |
| 2259 | // that was created via RenderView::CreateWebView. So, we wait until this |
| 2260 | // point to dispatch the ShowView message. |
| 2261 | // |
| 2262 | // This method provides us with the information about how to display the newly |
| 2263 | // created RenderView (i.e., as a constrained popup or as a new tab). |
| 2264 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2265 | void RenderView::show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2266 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 2267 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2268 | |
| 2269 | if (did_show_) |
| 2270 | return; |
| 2271 | did_show_ = true; |
| 2272 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2273 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2274 | if (!opened_by_user_gesture_) { |
| 2275 | // We exempt background tabs for compat with older versions of Chrome. |
| 2276 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2277 | // we probably don't need this check. |
| 2278 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2279 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2280 | } |
| 2281 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2282 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2283 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2284 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2285 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2286 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2287 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2288 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2289 | } |
| 2290 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2291 | void RenderView::closeWidgetSoon() { |
[email protected] | 7faa5386 | 2010-06-16 00:09:13 | [diff] [blame] | 2292 | // Cancel pending translations so that the translate_helper_ does not attempt |
| 2293 | // to access the WebView. |
| 2294 | translate_helper_.CancelPendingTranslation(); |
| 2295 | |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 2296 | if (script_can_close_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2297 | RenderWidget::closeWidgetSoon(); |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 2298 | } |
| 2299 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2300 | void RenderView::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2301 | DCHECK(did_show_) << "should already have shown the view"; |
| 2302 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2303 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2304 | // showModalDialog to function properly. |
| 2305 | // |
| 2306 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2307 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2308 | // handed manner. |
| 2309 | // |
| 2310 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 2311 | RenderThread::current()->DoNotSuspendWebKitSharedTimer(); |
| 2312 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2313 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2314 | } |
| 2315 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2316 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2317 | |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 2318 | WebPlugin* RenderView::createPlugin(WebFrame* frame, |
| 2319 | const WebPluginParams& params) { |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2320 | bool found = false; |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2321 | ContentSetting setting = CONTENT_SETTING_DEFAULT; |
| 2322 | CommandLine* cmd = CommandLine::ForCurrentProcess(); |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2323 | WebPluginInfo info; |
| 2324 | GURL url(params.url); |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 2325 | std::string actual_mime_type; |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2326 | Send(new ViewHostMsg_GetPluginInfo(url, |
| 2327 | frame->top()->url(), |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2328 | params.mimeType.utf8(), |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2329 | &found, |
| 2330 | &info, |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2331 | &setting, |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2332 | &actual_mime_type)); |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2333 | |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2334 | if (!found) |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 2335 | return NULL; |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 2336 | |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2337 | scoped_ptr<PluginGroup> group(PluginGroup::FindHardcodedPluginGroup(info)); |
| 2338 | group->AddPlugin(info, 0); |
| 2339 | |
| 2340 | if (!info.enabled) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2341 | if (cmd->HasSwitch(switches::kDisableOutdatedPlugins) && |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2342 | group->IsVulnerable()) { |
| 2343 | Send(new ViewHostMsg_DisabledOutdatedPlugin(routing_id_, |
| 2344 | group->GetGroupName(), |
| 2345 | GURL(group->GetUpdateURL()))); |
| 2346 | return CreatePluginPlaceholder(frame, params, group.get()); |
| 2347 | } |
| 2348 | return NULL; |
| 2349 | } |
| 2350 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2351 | if (info.path.value() != kDefaultPluginLibraryName) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2352 | std::string resource; |
| 2353 | if (cmd->HasSwitch(switches::kEnableResourceContentSettings)) { |
| 2354 | #if defined(OS_POSIX) |
| 2355 | resource = info.path.value(); |
| 2356 | #elif defined(OS_WIN) |
| 2357 | resource = base::SysWideToUTF8(info.path.value()); |
| 2358 | #endif |
| 2359 | } |
| 2360 | if (setting == CONTENT_SETTING_BLOCK) { |
| 2361 | DCHECK(cmd->HasSwitch(switches::kEnableClickToPlay)); |
| 2362 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource); |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2363 | return CreatePluginPlaceholder(frame, params, NULL); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2364 | } |
| 2365 | scoped_refptr<pepper::PluginModule> pepper_module = |
| 2366 | PepperPluginRegistry::GetInstance()->GetModule(info.path); |
| 2367 | if (pepper_module) |
| 2368 | return CreatePepperPlugin(frame, params, info.path, pepper_module.get()); |
| 2369 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2370 | switches::kBlockNonSandboxedPlugins) && |
| 2371 | setting != CONTENT_SETTING_ALLOW) { |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2372 | Send(new ViewHostMsg_NonSandboxedPluginBlocked(routing_id_, |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2373 | resource, |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2374 | group->GetGroupName())); |
| 2375 | return CreatePluginPlaceholder(frame, params, NULL); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2376 | } |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 2377 | } |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2378 | return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { |
[email protected] | 14396e9 | 2010-05-06 20:40:56 | [diff] [blame] | 2382 | WebApplicationCacheHostImpl* appcache_host = |
| 2383 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2384 | int appcache_host_id = appcache_host ? appcache_host->host_id() : 0; |
| 2385 | return new WebWorkerProxy(client, RenderThread::current(), routing_id_, |
| 2386 | appcache_host_id); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2387 | } |
| 2388 | |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2389 | WebSharedWorker* RenderView::createSharedWorker( |
| 2390 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2391 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2392 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2393 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2394 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2395 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2396 | ViewHostMsg_CreateWorker_Params params; |
| 2397 | params.url = url; |
| 2398 | params.is_shared = true; |
| 2399 | params.name = name; |
| 2400 | params.document_id = document_id; |
| 2401 | params.render_view_route_id = routing_id_; |
| 2402 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 2403 | params.parent_appcache_host_id = 0; |
| 2404 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2405 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2406 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2407 | if (url_mismatch) { |
| 2408 | return NULL; |
| 2409 | } else { |
| 2410 | return new WebSharedWorkerProxy(RenderThread::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2411 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2412 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2413 | route_id, |
| 2414 | routing_id_); |
| 2415 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2416 | } |
| 2417 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2418 | WebMediaPlayer* RenderView::createMediaPlayer( |
| 2419 | WebFrame* frame, WebMediaPlayerClient* client) { |
| 2420 | scoped_refptr<media::FilterFactoryCollection> factory = |
| 2421 | new media::FilterFactoryCollection(); |
| 2422 | // Add in any custom filter factories first. |
| 2423 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 2424 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
| 2425 | // Add the chrome specific audio renderer. |
| 2426 | factory->AddFactory( |
| 2427 | AudioRendererImpl::CreateFactory(audio_message_filter())); |
| 2428 | } |
| 2429 | |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 2430 | if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) && |
| 2431 | cmd_line->HasSwitch(switches::kEnableAcceleratedCompositing)) { |
| 2432 | // Add the hardware video decoder factory. |
| 2433 | factory->AddFactory( |
| 2434 | media::IpcVideoDecoder::CreateFactory(MessageLoop::current())); |
| 2435 | } |
| 2436 | |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2437 | WebApplicationCacheHostImpl* appcache_host = |
| 2438 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2439 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2440 | // TODO(hclam): obtain the following parameters from |client|. |
| 2441 | webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = |
| 2442 | new webkit_glue::MediaResourceLoaderBridgeFactory( |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 2443 | GURL(), // referrer |
| 2444 | "null", // frame origin |
| 2445 | "null", // main_frame_origin |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2446 | base::GetCurrentProcId(), |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2447 | appcache_host ? appcache_host->host_id() : appcache::kNoHostId, |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2448 | routing_id()); |
| 2449 | |
[email protected] | 0436b9a | 2009-10-23 00:23:05 | [diff] [blame] | 2450 | // A simple data source that keeps all data in memory. |
| 2451 | media::FilterFactory* simple_data_source_factory = |
| 2452 | webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(), |
| 2453 | bridge_factory); |
| 2454 | // A sophisticated data source that does memory caching. |
| 2455 | media::FilterFactory* buffered_data_source_factory = |
| 2456 | webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(), |
| 2457 | bridge_factory); |
| 2458 | if (cmd_line->HasSwitch(switches::kSimpleDataSource)) { |
| 2459 | factory->AddFactory(simple_data_source_factory); |
| 2460 | factory->AddFactory(buffered_data_source_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2461 | } else { |
[email protected] | 0436b9a | 2009-10-23 00:23:05 | [diff] [blame] | 2462 | factory->AddFactory(buffered_data_source_factory); |
| 2463 | factory->AddFactory(simple_data_source_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2464 | } |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2465 | |
| 2466 | webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL; |
| 2467 | if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) { |
| 2468 | factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_); |
| 2469 | } else { |
[email protected] | b57509eb | 2010-03-30 01:26:28 | [diff] [blame] | 2470 | bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging); |
| 2471 | factory_factory = |
| 2472 | new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging); |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2476 | } |
| 2477 | |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2478 | WebApplicationCacheHost* RenderView::createApplicationCacheHost( |
| 2479 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
| 2480 | return new RendererWebApplicationCacheHostImpl( |
| 2481 | FromWebView(frame->view()), client, |
| 2482 | RenderThread::current()->appcache_dispatcher()->backend_proxy()); |
| 2483 | } |
| 2484 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 2485 | WebCookieJar* RenderView::cookieJar() { |
| 2486 | return &cookie_jar_; |
| 2487 | } |
| 2488 | |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2489 | void RenderView::frameDetached(WebFrame* frame) { |
| 2490 | autofill_helper_.FrameDetached(frame); |
| 2491 | } |
| 2492 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2493 | void RenderView::willClose(WebFrame* frame) { |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2494 | WebDataSource* ds = frame->dataSource(); |
| 2495 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2496 | |
| 2497 | if (!frame->parent()) { |
| 2498 | const GURL& url = frame->url(); |
| 2499 | // Ensure state contains scheme. |
| 2500 | if (url.SchemeIs("http")) |
| 2501 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP); |
| 2502 | else if (url.SchemeIs("https")) |
| 2503 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS); |
| 2504 | |
| 2505 | // Dump will only be provided when scheme is http or https. |
| 2506 | DumpLoadHistograms(); |
| 2507 | } |
| 2508 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2509 | navigation_state->user_script_idle_scheduler()->Cancel(); |
[email protected] | 174e60e | 2010-05-06 00:21:16 | [diff] [blame] | 2510 | |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2511 | // TODO(jhawkins): Remove once frameDetached is called by WebKit. |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 2512 | autofill_helper_.FrameWillClose(frame); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2513 | } |
| 2514 | |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2515 | bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2516 | if (enabled_per_settings && |
| 2517 | AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) |
| 2518 | return true; |
| 2519 | |
| 2520 | if (IsWhitelistedForContentSettings(frame)) |
| 2521 | return true; |
| 2522 | |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2523 | DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2524 | return false; // Other protocols fall through here. |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2525 | } |
| 2526 | |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2527 | bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) { |
| 2528 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2529 | switches::kEnableClickToPlay)) { |
| 2530 | return WebFrameClient::allowPlugins(frame, enabled_per_settings); |
| 2531 | } |
| 2532 | return (enabled_per_settings && |
| 2533 | AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 2534 | } |
| 2535 | |
| 2536 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2537 | void RenderView::loadURLExternally( |
| 2538 | WebFrame* frame, const WebURLRequest& request, |
| 2539 | WebNavigationPolicy policy) { |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2540 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2541 | if (policy == WebKit::WebNavigationPolicyDownload) { |
| 2542 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); |
| 2543 | } else { |
| 2544 | OpenURL(request.url(), referrer, policy); |
| 2545 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | WebNavigationPolicy RenderView::decidePolicyForNavigation( |
| 2549 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 2550 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2551 | // Webkit is asking whether to navigate to a new URL. |
| 2552 | // This is fine normally, except if we're showing UI from one security |
| 2553 | // context and they're trying to navigate to a different context. |
| 2554 | const GURL& url = request.url(); |
| 2555 | |
| 2556 | // If the browser is interested, then give it a chance to look at top level |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 2557 | // navigations. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2558 | if (renderer_preferences_.browser_handles_top_level_requests && |
| 2559 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2560 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
[email protected] | a58db8b | 2010-08-24 01:51:23 | [diff] [blame] | 2561 | // Reset these counters as the RenderView could be reused for the next |
| 2562 | // navigation. |
| 2563 | page_id_ = -1; |
| 2564 | next_page_id_ = 1; |
| 2565 | last_page_id_sent_to_browser_ = -1; |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2566 | OpenURL(url, referrer, default_policy); |
| 2567 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | // A content initiated navigation may have originated from a link-click, |
| 2571 | // script, drag-n-drop operation, etc. |
| 2572 | bool is_content_initiated = |
| 2573 | NavigationState::FromDataSource(frame->provisionalDataSource())-> |
| 2574 | is_content_initiated(); |
| 2575 | |
| 2576 | // We only care about navigations that are within the current tab (as opposed |
| 2577 | // to, for example, opening a new window). |
| 2578 | // But we sometimes navigate to about:blank to clear a tab, and we want to |
| 2579 | // still allow that. |
| 2580 | if (default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2581 | is_content_initiated && frame->parent() == NULL && |
[email protected] | c240ace | 2010-06-16 18:31:53 | [diff] [blame] | 2582 | type != WebKit::WebNavigationTypeFormSubmitted && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2583 | !url.SchemeIs(chrome::kAboutScheme)) { |
| 2584 | // When we received such unsolicited navigations, we sometimes want to |
| 2585 | // punt them up to the browser to handle. |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 2586 | if (CrossesExtensionExtents(frame, url) || |
| 2587 | BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) || |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2588 | frame->isViewSourceModeEnabled() || |
[email protected] | 918059b | 2010-05-25 17:08:42 | [diff] [blame] | 2589 | url.SchemeIs(chrome::kViewSourceScheme)) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2590 | OpenURL(url, GURL(), default_policy); |
| 2591 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2592 | } |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2593 | |
| 2594 | // We forward navigations from extensions to the browser if they are |
| 2595 | // top-level events, even if the browser hasn't expressed interest. |
| 2596 | // |
| 2597 | // Note that we've already forwarded cross-extension extents navigations |
| 2598 | // above. |
| 2599 | if (BindingsPolicy::is_extension_enabled(enabled_bindings_) && |
[email protected] | c240ace | 2010-06-16 18:31:53 | [diff] [blame] | 2600 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2601 | OpenURL(url, GURL(), default_policy); |
| 2602 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2603 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2607 | // its own process. This is done by sites like Gmail that try to open links |
| 2608 | // in new windows without script connections back to the original page. We |
| 2609 | // treat such cases as browser navigations (in which we will create a new |
| 2610 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2611 | // |
| 2612 | // We use the following heuristic to decide whether to fork a new page in its |
| 2613 | // own process: |
| 2614 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2615 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2616 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2617 | // |
| 2618 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2619 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2620 | bool is_fork = |
| 2621 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 2622 | GURL(frame->url()) == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2623 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2624 | historyBackListCount() < 1 && |
| 2625 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2626 | // The parent page must have set the child's window.opener to null before |
| 2627 | // redirecting to the desired URL. |
| 2628 | frame->opener() == NULL && |
| 2629 | // Must be a top-level frame. |
| 2630 | frame->parent() == NULL && |
| 2631 | // Must not have issued the request from this page. |
| 2632 | is_content_initiated && |
| 2633 | // Must be targeted at the current tab. |
| 2634 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2635 | // Must be a JavaScript navigation, which appears as "other". |
| 2636 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2637 | |
| 2638 | // Recognize if this navigation is from a link with rel=noreferrer and |
| 2639 | // target=_blank attributes, in which case the opener will be suppressed. If |
| 2640 | // so, it is safe to load cross-site pages in a separate process, so we |
| 2641 | // should let the browser handle it. |
| 2642 | bool is_noreferrer_and_blank_target = |
| 2643 | // Frame should be top level and not yet navigated. |
| 2644 | frame->parent() == NULL && |
| 2645 | frame->url().isEmpty() && |
| 2646 | historyBackListCount() < 1 && |
| 2647 | historyForwardListCount() < 1 && |
| 2648 | // Links with rel=noreferrer will have no Referer field, and their |
| 2649 | // resulting frame will have its window.opener suppressed. |
| 2650 | // TODO(creis): should add a request.httpReferrer() method to help avoid |
| 2651 | // typos on the unusual spelling of Referer. |
| 2652 | request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() && |
| 2653 | opener_suppressed_ && |
| 2654 | frame->opener() == NULL && |
| 2655 | // Links with target=_blank will have no name. |
| 2656 | frame->name().isNull() && |
| 2657 | // Another frame (with a non-empty creator) should have initiated the |
| 2658 | // request, targeted at this frame. |
| 2659 | !creator_url_.is_empty() && |
| 2660 | is_content_initiated && |
| 2661 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2662 | type == WebKit::WebNavigationTypeOther; |
| 2663 | |
| 2664 | if (is_fork || is_noreferrer_and_blank_target) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2665 | // Open the URL via the browser, not via WebKit. |
| 2666 | OpenURL(url, GURL(), default_policy); |
| 2667 | return WebKit::WebNavigationPolicyIgnore; |
| 2668 | } |
| 2669 | |
| 2670 | return default_policy; |
| 2671 | } |
| 2672 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2673 | bool RenderView::canHandleRequest( |
| 2674 | WebFrame* frame, const WebURLRequest& request) { |
| 2675 | // We allow WebKit to think that everything can be handled even though |
| 2676 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2677 | return true; |
| 2678 | } |
| 2679 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2680 | WebURLError RenderView::cannotHandleRequestError( |
| 2681 | WebFrame* frame, const WebURLRequest& request) { |
| 2682 | NOTREACHED(); // Since we said we can handle all requests. |
| 2683 | return WebURLError(); |
| 2684 | } |
| 2685 | |
| 2686 | WebURLError RenderView::cancelledError( |
| 2687 | WebFrame* frame, const WebURLRequest& request) { |
| 2688 | WebURLError error; |
| 2689 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2690 | error.reason = net::ERR_ABORTED; |
| 2691 | error.unreachableURL = request.url(); |
| 2692 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | void RenderView::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2696 | WebFrame*, const WebURLError&) { |
| 2697 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2698 | } |
| 2699 | |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2700 | void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame, |
| 2701 | const WebKit::WebFormElement& form) { |
| 2702 | // Some login forms have onSubmit handlers that put a hash of the password |
| 2703 | // into a hidden field and then clear the password. (Issue 28910.) |
| 2704 | // This method gets called before any of those handlers run, so save away |
| 2705 | // a copy of the password in case it gets lost. |
| 2706 | NavigationState* navigation_state = |
| 2707 | NavigationState::FromDataSource(frame->dataSource()); |
| 2708 | navigation_state->set_password_form_data( |
| 2709 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 2710 | } |
| 2711 | |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 2712 | void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2713 | NavigationState* navigation_state = |
| 2714 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2715 | |
| 2716 | if (navigation_state->transition_type() == PageTransition::LINK) |
| 2717 | navigation_state->set_transition_type(PageTransition::FORM_SUBMIT); |
| 2718 | |
| 2719 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2720 | WebSearchableFormData web_searchable_form_data(form); |
| 2721 | navigation_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2722 | navigation_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2723 | web_searchable_form_data.encoding().utf8()); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2724 | PasswordForm* password_form_data = |
| 2725 | PasswordFormDomManager::CreatePasswordForm(form); |
| 2726 | navigation_state->set_password_form_data(password_form_data); |
| 2727 | |
| 2728 | // If the password has been cleared, recover it from the form contents already |
| 2729 | // stored by willSendSubmitEvent into the dataSource's NavigationState (as |
| 2730 | // opposed to the provisionalDataSource's, which is what we're storing into |
| 2731 | // now.) |
| 2732 | if (password_form_data && password_form_data->password_value.empty()) { |
| 2733 | NavigationState* old_navigation_state = |
| 2734 | NavigationState::FromDataSource(frame->dataSource()); |
| 2735 | if (old_navigation_state) { |
| 2736 | PasswordForm* old_form_data = old_navigation_state->password_form_data(); |
| 2737 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 2738 | password_form_data->password_value = old_form_data->password_value; |
| 2739 | } |
| 2740 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2741 | |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2742 | FormData form_data; |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 2743 | if (FormManager::WebFormElementToFormData( |
[email protected] | 3347bab3 | 2010-04-09 04:11:09 | [diff] [blame] | 2744 | form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data)) |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2745 | Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | void RenderView::willPerformClientRedirect( |
| 2749 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2750 | double fire_time) { |
| 2751 | // Ignore |
| 2752 | } |
| 2753 | |
| 2754 | void RenderView::didCancelClientRedirect(WebFrame* frame) { |
| 2755 | // Ignore |
| 2756 | } |
| 2757 | |
| 2758 | void RenderView::didCompleteClientRedirect( |
| 2759 | WebFrame* frame, const WebURL& from) { |
| 2760 | if (!frame->parent()) |
| 2761 | completed_client_redirect_src_ = from; |
| 2762 | } |
| 2763 | |
| 2764 | void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
| 2765 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2766 | // non-null NavigationState. |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 2767 | bool content_initiated = !pending_navigation_state_.get(); |
| 2768 | NavigationState* state = content_initiated ? |
| 2769 | NavigationState::CreateContentInitiated() : |
| 2770 | pending_navigation_state_.release(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2771 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2772 | // NavigationState::referred_by_prefetcher_ is true if we are |
| 2773 | // navigating from a page that used prefetching using a link on that |
| 2774 | // page. We are early enough in the request process here that we |
| 2775 | // can still see the NavigationState of the previous page and set |
| 2776 | // this value appropriately. |
| 2777 | // TODO(gavinp): catch the important case of navigation in a new |
| 2778 | // renderer process. |
| 2779 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2780 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2781 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2782 | const GURL referrer( |
| 2783 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2784 | if (!referrer.is_empty() && |
| 2785 | NavigationState::FromDataSource( |
| 2786 | old_frame->dataSource())->was_prefetcher()) { |
| 2787 | for (;old_frame;old_frame = old_frame->traverseNext(false)) { |
| 2788 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 2789 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
| 2790 | state->set_was_referred_by_prefetcher(true); |
| 2791 | break; |
| 2792 | } |
| 2793 | } |
| 2794 | } |
| 2795 | } |
| 2796 | } |
| 2797 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2798 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2799 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2800 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2801 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
| 2802 | state->set_load_type(NavigationState::LINK_LOAD_NORMAL); |
| 2803 | break; |
| 2804 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
| 2805 | state->set_load_type(NavigationState::LINK_LOAD_RELOAD); |
| 2806 | break; |
| 2807 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
| 2808 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK); |
| 2809 | break; |
| 2810 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
| 2811 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY); |
| 2812 | break; |
| 2813 | } |
| 2814 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2815 | |
| 2816 | state->set_user_script_idle_scheduler( |
| 2817 | new UserScriptIdleScheduler(this, frame)); |
| 2818 | ds->setExtraData(state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | void RenderView::didStartProvisionalLoad(WebFrame* frame) { |
| 2822 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2823 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2824 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2825 | // Update the request time if WebKit has better knowledge of it. |
| 2826 | if (navigation_state->request_time().is_null()) { |
| 2827 | double event_time = ds->triggeringEventTime(); |
| 2828 | if (event_time != 0.0) |
| 2829 | navigation_state->set_request_time(Time::FromDoubleT(event_time)); |
| 2830 | } |
| 2831 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2832 | // Start time is only set after request time. |
| 2833 | navigation_state->set_start_load_time(Time::Now()); |
| 2834 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2835 | bool is_top_most = !frame->parent(); |
| 2836 | if (is_top_most) { |
| 2837 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
| 2838 | NavigationGestureUnknown : NavigationGestureAuto; |
| 2839 | |
| 2840 | // Make sure redirect tracking state is clear for the new load. |
| 2841 | completed_client_redirect_src_ = GURL(); |
| 2842 | } else if (frame->parent()->isLoading()) { |
| 2843 | // Take note of AUTO_SUBFRAME loads here, so that we can know how to |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 2844 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2845 | navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME); |
| 2846 | } |
| 2847 | |
| 2848 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
| 2849 | routing_id_, is_top_most, ds->request().url())); |
| 2850 | } |
| 2851 | |
| 2852 | void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) { |
| 2853 | if (frame->parent()) |
| 2854 | return; |
| 2855 | // Received a redirect on the main frame. |
| 2856 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 2857 | if (!data_source) { |
| 2858 | // Should only be invoked when we have a data source. |
| 2859 | NOTREACHED(); |
| 2860 | return; |
| 2861 | } |
| 2862 | std::vector<GURL> redirects; |
| 2863 | GetRedirectChain(data_source, &redirects); |
| 2864 | if (redirects.size() >= 2) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2865 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
| 2866 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2870 | void RenderView::didFailProvisionalLoad(WebFrame* frame, |
| 2871 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2872 | // Notify the browser that we failed a provisional load with an error. |
| 2873 | // |
| 2874 | // Note: It is important this notification occur before DidStopLoading so the |
| 2875 | // SSL manager can react to the provisional load failure before being |
| 2876 | // notified the load stopped. |
| 2877 | // |
| 2878 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2879 | DCHECK(ds); |
| 2880 | |
| 2881 | const WebURLRequest& failed_request = ds->request(); |
| 2882 | |
| 2883 | bool show_repost_interstitial = |
| 2884 | (error.reason == net::ERR_CACHE_MISS && |
| 2885 | EqualsASCII(failed_request.httpMethod(), "POST")); |
| 2886 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
| 2887 | routing_id_, !frame->parent(), error.reason, error.unreachableURL, |
| 2888 | show_repost_interstitial)); |
| 2889 | |
| 2890 | // Don't display an error page if this is simply a cancelled load. Aside |
| 2891 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 2892 | if (error.reason == net::ERR_ABORTED) |
| 2893 | return; |
| 2894 | |
| 2895 | // Make sure we never show errors in view source mode. |
| 2896 | frame->enableViewSourceMode(false); |
| 2897 | |
| 2898 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2899 | |
| 2900 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 2901 | // 'replace' load. This is necessary to avoid messing up session history. |
| 2902 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 2903 | // as session history is concerned. |
| 2904 | // |
| 2905 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 2906 | // the page id. |
| 2907 | // |
| 2908 | bool replace = |
| 2909 | navigation_state->pending_page_id() != -1 || |
| 2910 | navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME; |
| 2911 | |
| 2912 | // If we failed on a browser initiated request, then make sure that our error |
| 2913 | // page load is regarded as the same browser initiated request. |
| 2914 | if (!navigation_state->is_content_initiated()) { |
| 2915 | pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( |
| 2916 | navigation_state->pending_page_id(), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2917 | navigation_state->pending_history_list_offset(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2918 | navigation_state->transition_type(), |
| 2919 | navigation_state->request_time())); |
| 2920 | } |
| 2921 | |
| 2922 | // Provide the user with a more helpful error page? |
| 2923 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 2924 | return; |
| 2925 | |
| 2926 | // Fallback to a local error page. |
| 2927 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), |
| 2928 | replace); |
| 2929 | } |
| 2930 | |
| 2931 | void RenderView::didReceiveDocumentData( |
| 2932 | WebFrame* frame, const char* data, size_t data_len, |
| 2933 | bool& prevent_default) { |
| 2934 | NavigationState* navigation_state = |
| 2935 | NavigationState::FromDataSource(frame->dataSource()); |
| 2936 | if (!navigation_state->postpone_loading_data()) |
| 2937 | return; |
| 2938 | |
| 2939 | // We're going to call commitDocumentData ourselves... |
| 2940 | prevent_default = true; |
| 2941 | |
| 2942 | // Continue buffering the response data for the original 404 page. If it |
| 2943 | // grows too large, then we'll just let it through. |
| 2944 | navigation_state->append_postponed_data(data, data_len); |
| 2945 | if (navigation_state->postponed_data().size() >= 512) { |
| 2946 | navigation_state->set_postpone_loading_data(false); |
| 2947 | frame->commitDocumentData(navigation_state->postponed_data().data(), |
| 2948 | navigation_state->postponed_data().size()); |
| 2949 | navigation_state->clear_postponed_data(); |
| 2950 | } |
| 2951 | } |
| 2952 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2953 | void RenderView::didCommitProvisionalLoad(WebFrame* frame, |
| 2954 | bool is_new_navigation) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2955 | NavigationState* navigation_state = |
| 2956 | NavigationState::FromDataSource(frame->dataSource()); |
| 2957 | |
| 2958 | navigation_state->set_commit_load_time(Time::Now()); |
| 2959 | if (is_new_navigation) { |
| 2960 | // When we perform a new navigation, we need to update the previous session |
| 2961 | // history entry with state for the page we are leaving. |
| 2962 | UpdateSessionHistory(frame); |
| 2963 | |
| 2964 | // We bump our Page ID to correspond with the new session history entry. |
| 2965 | page_id_ = next_page_id_++; |
| 2966 | |
[email protected] | d64b07b | 2010-04-20 22:14:06 | [diff] [blame] | 2967 | // Any pending translation is now obsolete. |
| 2968 | translate_helper_.CancelPendingTranslation(); |
| 2969 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2970 | // Advance our offset in session history, applying the length limit. There |
| 2971 | // is now no forward history. |
| 2972 | history_list_offset_++; |
| 2973 | if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries) |
| 2974 | history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1; |
| 2975 | history_list_length_ = history_list_offset_ + 1; |
| 2976 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 2977 | MessageLoop::current()->PostDelayedTask( |
| 2978 | FROM_HERE, |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2979 | page_info_method_factory_.NewRunnableMethod( |
| 2980 | &RenderView::CapturePageInfo, page_id_, true), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2981 | kDelayForForcedCaptureMs); |
| 2982 | } else { |
| 2983 | // Inspect the navigation_state on this frame to see if the navigation |
| 2984 | // corresponds to a session history navigation... Note: |frame| may or |
| 2985 | // may not be the toplevel frame, but for the case of capturing session |
| 2986 | // history, the first committed frame suffices. We keep track of whether |
| 2987 | // we've seen this commit before so that only capture session history once |
| 2988 | // per navigation. |
| 2989 | // |
| 2990 | // Note that we need to check if the page ID changed. In the case of a |
| 2991 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 2992 | // previous URL and the current page ID, which would be wrong. |
| 2993 | if (navigation_state->pending_page_id() != -1 && |
| 2994 | navigation_state->pending_page_id() != page_id_ && |
| 2995 | !navigation_state->request_committed()) { |
| 2996 | // This is a successful session history navigation! |
| 2997 | UpdateSessionHistory(frame); |
| 2998 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2999 | |
| 3000 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | // Remember that we've already processed this request, so we don't update |
| 3005 | // the session history again. We do this regardless of whether this is |
| 3006 | // a session history navigation, because if we attempted a session history |
| 3007 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3008 | // new navigation. |
| 3009 | navigation_state->set_request_committed(true); |
| 3010 | |
| 3011 | UpdateURL(frame); |
| 3012 | |
| 3013 | // If this committed load was initiated by a client redirect, we're |
| 3014 | // at the last stop now, so clear it. |
| 3015 | completed_client_redirect_src_ = GURL(); |
| 3016 | |
| 3017 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3018 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | void RenderView::didClearWindowObject(WebFrame* frame) { |
| 3022 | if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_)) |
| 3023 | BindDOMAutomationController(frame); |
| 3024 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) { |
| 3025 | dom_ui_bindings_.set_message_sender(this); |
| 3026 | dom_ui_bindings_.set_routing_id(routing_id_); |
| 3027 | dom_ui_bindings_.BindToJavascript(frame, L"chrome"); |
| 3028 | } |
| 3029 | if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) { |
| 3030 | external_host_bindings_.set_message_sender(this); |
| 3031 | external_host_bindings_.set_routing_id(routing_id_); |
| 3032 | external_host_bindings_.BindToJavascript(frame, L"externalHost"); |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | void RenderView::didCreateDocumentElement(WebFrame* frame) { |
| 3037 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3038 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3039 | frame, UserScript::DOCUMENT_START); |
| 3040 | } |
| 3041 | |
| 3042 | // Notify the browser about non-blank documents loading in the top frame. |
| 3043 | GURL url = frame->url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 3044 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3045 | if (frame == webview()->mainFrame()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3046 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
| 3047 | } |
| 3048 | } |
| 3049 | |
| 3050 | void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { |
| 3051 | UpdateTitle(frame, title); |
| 3052 | |
| 3053 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3054 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3055 | } |
| 3056 | |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3057 | void RenderView::didChangeIcons(WebFrame* frame) { |
| 3058 | if (!frame->parent()) { |
| 3059 | Send(new ViewHostMsg_UpdateFavIconURL( |
| 3060 | routing_id_, |
| 3061 | page_id_, |
| 3062 | frame->favIconURL())); |
| 3063 | } |
| 3064 | } |
| 3065 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3066 | void RenderView::didFinishDocumentLoad(WebFrame* frame) { |
| 3067 | WebDataSource* ds = frame->dataSource(); |
| 3068 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3069 | DCHECK(navigation_state); |
| 3070 | navigation_state->set_finish_document_load_time(Time::Now()); |
| 3071 | |
| 3072 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_)); |
| 3073 | |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 3074 | // The document has now been fully loaded. Scan for forms to be sent up to |
| 3075 | // the browser. |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 3076 | autofill_helper_.FrameContentsAvailable(frame); |
| 3077 | password_autocomplete_manager_.SendPasswordForms(frame, false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3078 | |
| 3079 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3080 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3081 | |
| 3082 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3083 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3084 | frame, UserScript::DOCUMENT_END); |
| 3085 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3086 | |
| 3087 | navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad(); |
| 3088 | } |
| 3089 | |
| 3090 | void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) { |
| 3091 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3092 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3093 | frame, UserScript::DOCUMENT_IDLE); |
| 3094 | } |
| 3095 | |
| 3096 | WebFrame* main_frame = webview()->mainFrame(); |
| 3097 | if (frame == main_frame) { |
| 3098 | while (!pending_code_execution_queue_.empty()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 3099 | linked_ptr<ViewMsg_ExecuteCode_Params>& params = |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3100 | pending_code_execution_queue_.front(); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 3101 | ExecuteCodeImpl(main_frame, *params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3102 | pending_code_execution_queue_.pop(); |
| 3103 | } |
| 3104 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | void RenderView::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | dd3c3e68 | 2010-05-12 18:51:26 | [diff] [blame] | 3108 | if (webview()->mainFrame() == frame) |
| 3109 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { |
| 3113 | // Ignore |
| 3114 | } |
| 3115 | |
| 3116 | void RenderView::didFinishLoad(WebFrame* frame) { |
| 3117 | WebDataSource* ds = frame->dataSource(); |
| 3118 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3119 | DCHECK(navigation_state); |
| 3120 | navigation_state->set_finish_load_time(Time::Now()); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3121 | navigation_state->user_script_idle_scheduler()->DidFinishLoad(); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3122 | |
| 3123 | // Let the password manager know which password forms are actually visible. |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 3124 | password_autocomplete_manager_.SendPasswordForms(frame, true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3125 | } |
| 3126 | |
[email protected] | ccbe04e | 2010-03-17 17:58:43 | [diff] [blame] | 3127 | void RenderView::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3128 | WebFrame* frame, bool is_new_navigation) { |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3129 | // Determine if the UserScriptIdleScheduler already ran scripts on this page, |
| 3130 | // since a new one gets created by didCreateDataSource. |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3131 | NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3132 | bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run(); |
| 3133 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3134 | // If this was a reference fragment navigation that we initiated, then we |
| 3135 | // could end up having a non-null pending navigation state. We just need to |
| 3136 | // update the ExtraData on the datasource so that others who read the |
| 3137 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3138 | // initiate this navigation, then we need to take care to reset any pre- |
| 3139 | // existing navigation state to a content-initiated navigation state. |
| 3140 | // DidCreateDataSource conveniently takes care of this for us. |
| 3141 | didCreateDataSource(frame, frame->dataSource()); |
| 3142 | |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3143 | NavigationState* new_state = |
| 3144 | NavigationState::FromDataSource(frame->dataSource()); |
| 3145 | new_state->set_was_within_same_page(true); |
| 3146 | |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3147 | if (idle_scheduler_ran) { |
| 3148 | // Update the new UserScriptIdleScheduler so we don't re-run scripts. |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3149 | new_state->user_script_idle_scheduler()->set_has_run(true); |
| 3150 | } |
| 3151 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3152 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 3153 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3154 | UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3155 | } |
| 3156 | |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3157 | void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3158 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3159 | } |
| 3160 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3161 | void RenderView::assignIdentifierToRequest( |
| 3162 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 3163 | // Ignore |
| 3164 | } |
| 3165 | |
| 3166 | void RenderView::willSendRequest( |
| 3167 | WebFrame* frame, unsigned identifier, WebURLRequest& request, |
| 3168 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3169 | WebFrame* top_frame = frame->top(); |
| 3170 | if (!top_frame) |
| 3171 | top_frame = frame; |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3172 | WebDataSource* provisional_data_source = top_frame->provisionalDataSource(); |
| 3173 | WebDataSource* top_data_source = top_frame->dataSource(); |
| 3174 | WebDataSource* data_source = |
| 3175 | provisional_data_source ? provisional_data_source : top_data_source; |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3176 | if (data_source) { |
| 3177 | NavigationState* state = NavigationState::FromDataSource(data_source); |
| 3178 | if (state && state->is_cache_policy_override_set()) |
| 3179 | request.setCachePolicy(state->cache_policy_override()); |
| 3180 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3181 | |
| 3182 | if (top_data_source) { |
| 3183 | NavigationState* state = NavigationState::FromDataSource(top_data_source); |
| 3184 | if (state && request.targetType() == WebURLRequest::TargetIsPrefetch) |
| 3185 | state->set_was_prefetcher(true); |
| 3186 | } |
| 3187 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3188 | request.setRequestorID(routing_id_); |
[email protected] | c5bbc245 | 2010-03-08 08:33:50 | [diff] [blame] | 3189 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 3190 | request.clearHTTPHeaderField("Referer"); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3191 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 3192 | // Temporary metrics, see site_isolation_metrics.h |
| 3193 | SiteIsolationMetrics::AddRequest(identifier, request.targetType()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | void RenderView::didReceiveResponse( |
| 3197 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3198 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 3199 | // Temporary metrics, see site_isolation_metrics.h |
| 3200 | SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame, |
| 3201 | identifier, |
| 3202 | response); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3203 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3204 | // Only do this for responses that correspond to a provisional data source |
| 3205 | // of the top-most frame. If we have a provisional data source, then we |
| 3206 | // can't have any sub-resources yet, so we know that this response must |
| 3207 | // correspond to a frame load. |
| 3208 | if (!frame->provisionalDataSource() || frame->parent()) |
| 3209 | return; |
| 3210 | |
| 3211 | // If we are in view source mode, then just let the user see the source of |
| 3212 | // the server's 404 error page. |
| 3213 | if (frame->isViewSourceModeEnabled()) |
| 3214 | return; |
| 3215 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3216 | NavigationState* navigation_state = |
| 3217 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 3218 | CHECK(navigation_state); |
| 3219 | |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3220 | // Record page load flags. |
| 3221 | navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); |
| 3222 | navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated()); |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 3223 | navigation_state->set_was_alternate_protocol_available( |
| 3224 | response.wasAlternateProtocolAvailable()); |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3225 | navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3226 | |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 3227 | // Consider loading an alternate error page for 404 responses. |
| 3228 | if (response.httpStatusCode() != 404) |
| 3229 | return; |
| 3230 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3231 | // Can we even load an alternate error page for this URL? |
| 3232 | if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid()) |
| 3233 | return; |
| 3234 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3235 | navigation_state->set_postpone_loading_data(true); |
| 3236 | navigation_state->clear_postponed_data(); |
| 3237 | } |
| 3238 | |
| 3239 | void RenderView::didFinishResourceLoad( |
| 3240 | WebFrame* frame, unsigned identifier) { |
| 3241 | NavigationState* navigation_state = |
| 3242 | NavigationState::FromDataSource(frame->dataSource()); |
| 3243 | if (!navigation_state->postpone_loading_data()) |
| 3244 | return; |
| 3245 | |
| 3246 | // The server returned a 404 and the content was < 512 bytes (which we |
| 3247 | // suppressed). Go ahead and fetch the alternate page content. |
| 3248 | |
| 3249 | const GURL& frame_url = frame->url(); |
| 3250 | |
| 3251 | const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404); |
| 3252 | DCHECK(error_page_url.is_valid()); |
| 3253 | |
| 3254 | WebURLError original_error; |
| 3255 | original_error.unreachableURL = frame_url; |
| 3256 | |
| 3257 | navigation_state->set_alt_error_page_fetcher( |
| 3258 | new AltErrorPageResourceFetcher( |
| 3259 | error_page_url, frame, original_error, |
| 3260 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 3261 | } |
| 3262 | |
| 3263 | void RenderView::didFailResourceLoad( |
| 3264 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 3265 | // Ignore |
| 3266 | } |
| 3267 | |
| 3268 | void RenderView::didLoadResourceFromMemoryCache( |
| 3269 | WebFrame* frame, const WebURLRequest& request, |
| 3270 | const WebURLResponse& response) { |
| 3271 | // Let the browser know we loaded a resource from the memory cache. This |
| 3272 | // message is needed to display the correct SSL indicators. |
| 3273 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 3274 | routing_id_, |
| 3275 | request.url(), |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 3276 | frame->securityOrigin().toString().utf8(), |
| 3277 | frame->top()->securityOrigin().toString().utf8(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3278 | response.securityInfo())); |
| 3279 | } |
| 3280 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3281 | void RenderView::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3282 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 3283 | } |
| 3284 | |
| 3285 | void RenderView::didRunInsecureContent( |
| 3286 | WebFrame* frame, const WebSecurityOrigin& origin) { |
| 3287 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 3288 | routing_id_, |
| 3289 | origin.toString().utf8())); |
| 3290 | } |
| 3291 | |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3292 | bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 3293 | if (enabled_per_settings && |
| 3294 | AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) |
| 3295 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3296 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 3297 | if (IsWhitelistedForContentSettings(frame)) |
| 3298 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3299 | |
| 3300 | return false; // Other protocols fall through here. |
| 3301 | } |
| 3302 | |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 3303 | bool RenderView::allowDatabase( |
| 3304 | WebFrame* frame, const WebString& name, const WebString& display_name, |
| 3305 | unsigned long estimated_size) { |
| 3306 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 3307 | if (origin.isEmpty()) |
| 3308 | return false; // Uninitialized document? |
| 3309 | |
| 3310 | bool result; |
| 3311 | if (!Send(new ViewHostMsg_AllowDatabase(routing_id_, |
| 3312 | origin.toString().utf8(), name, display_name, estimated_size, &result))) |
| 3313 | return false; |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 3314 | Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_, |
| 3315 | GURL(origin.toString().utf8()), |
| 3316 | name, |
| 3317 | display_name, |
| 3318 | estimated_size, |
| 3319 | !result)); |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 3320 | return result; |
| 3321 | } |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3322 | void RenderView::didNotAllowScript(WebKit::WebFrame* frame) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3323 | DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3324 | } |
| 3325 | |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 3326 | void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3327 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 3328 | } |
| 3329 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3330 | void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
| 3331 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 3332 | } |
| 3333 | |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3334 | void RenderView::didCreateScriptContext(WebFrame* frame) { |
| 3335 | EventBindings::HandleContextCreated(frame, false); |
| 3336 | } |
| 3337 | |
| 3338 | void RenderView::didDestroyScriptContext(WebFrame* frame) { |
| 3339 | EventBindings::HandleContextDestroyed(frame); |
| 3340 | } |
| 3341 | |
| 3342 | void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) { |
| 3343 | EventBindings::HandleContextCreated(frame, true); |
| 3344 | } |
| 3345 | |
[email protected] | fc86daa | 2010-03-30 23:52:53 | [diff] [blame] | 3346 | void RenderView::logCrossFramePropertyAccess(WebFrame* frame, |
| 3347 | WebFrame* target, |
| 3348 | bool cross_origin, |
| 3349 | const WebString& property_name, |
| 3350 | unsigned long long event_id) { |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 3351 | // TODO(johnnyg): track the individual properties and repeat event_ids. |
| 3352 | if (cross_origin) |
| 3353 | cross_origin_access_count_++; |
| 3354 | else |
| 3355 | same_origin_access_count_++; |
| 3356 | } |
| 3357 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3358 | void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) { |
[email protected] | d8a179c | 2010-01-31 00:58:14 | [diff] [blame] | 3359 | CheckPreferredSize(); |
| 3360 | } |
| 3361 | |
| 3362 | void RenderView::CheckPreferredSize() { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3363 | // We don't always want to send the change messages over IPC, only if we've |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 3364 | // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3365 | // message. |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3366 | if (!send_preferred_size_changes_ || !webview()) |
| 3367 | return; |
[email protected] | dfca5acf | 2010-03-22 03:28:43 | [diff] [blame] | 3368 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3369 | // WebCore likes to tell us things have changed even when they haven't, so |
| 3370 | // cache the width and height and only send the IPC message when we're sure |
| 3371 | // they're different. |
| 3372 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 3373 | webview()->mainFrame()->documentElementScrollHeight()); |
| 3374 | if (size == preferred_size_) |
| 3375 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 3376 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3377 | preferred_size_ = size; |
| 3378 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 3379 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3380 | } |
| 3381 | |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3382 | void RenderView::didChangeScrollOffset(WebFrame* frame) { |
| 3383 | StartNavStateSyncTimerIfNecessary(); |
| 3384 | } |
| 3385 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3386 | void RenderView::reportFindInPageMatchCount(int request_id, int count, |
| 3387 | bool final_update) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3388 | int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 3389 | if (!count) |
| 3390 | active_match_ordinal = 0; |
| 3391 | |
| 3392 | IPC::Message* msg = new ViewHostMsg_Find_Reply( |
| 3393 | routing_id_, |
| 3394 | request_id, |
| 3395 | count, |
| 3396 | gfx::Rect(), |
| 3397 | active_match_ordinal, |
| 3398 | final_update); |
| 3399 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3400 | // If we have a message that has been queued up, then we should just replace |
| 3401 | // it. The ACK from the browser will make sure it gets sent when the browser |
| 3402 | // wants it. |
| 3403 | if (queued_find_reply_message_.get()) { |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3404 | queued_find_reply_message_.reset(msg); |
| 3405 | } else { |
| 3406 | // Send the search result over to the browser process. |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3407 | Send(msg); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3408 | } |
| 3409 | } |
| 3410 | |
| 3411 | void RenderView::reportFindInPageSelection(int request_id, |
| 3412 | int active_match_ordinal, |
| 3413 | const WebRect& selection_rect) { |
| 3414 | // Send the search result over to the browser process. |
| 3415 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3416 | request_id, |
| 3417 | -1, |
| 3418 | selection_rect, |
| 3419 | active_match_ordinal, |
| 3420 | false)); |
| 3421 | } |
| 3422 | |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3423 | void RenderView::openFileSystem( |
| 3424 | WebFrame* frame, |
| 3425 | WebFileSystem::Type type, |
| 3426 | long long size, |
| 3427 | WebFileSystemCallbacks* callbacks) { |
| 3428 | scoped_ptr<PendingOpenFileSystem> request( |
| 3429 | new PendingOpenFileSystem(callbacks)); |
| 3430 | |
| 3431 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 3432 | if (origin.isEmpty()) |
| 3433 | return; // Uninitialized document? |
| 3434 | |
| 3435 | ViewHostMsg_OpenFileSystemRequest_Params params; |
| 3436 | params.routing_id = routing_id_; |
| 3437 | params.request_id = pending_file_system_requests_.Add(request.release()); |
| 3438 | params.origin_url = GURL(origin.toString()); |
| 3439 | params.type = type; |
| 3440 | params.requested_size = size; |
| 3441 | |
| 3442 | Send(new ViewHostMsg_OpenFileSystemRequest(params)); |
| 3443 | } |
| 3444 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 3445 | // webkit_glue::WebPluginPageDelegate ----------------------------------------- |
| 3446 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3447 | webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3448 | const FilePath& file_path, |
| 3449 | const std::string& mime_type) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3450 | if (!PluginChannelHost::IsListening()) |
| 3451 | return NULL; |
| 3452 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3453 | bool use_pepper_host = false; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3454 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3455 | // Check for trusted Pepper plugins. |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3456 | const char kPepperPrefix[] = "pepper-"; |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3457 | if (StartsWithASCII(mime_type, kPepperPrefix, true)) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3458 | if (CommandLine::ForCurrentProcess()-> |
| 3459 | HasSwitch(switches::kInternalPepper)) { |
| 3460 | in_process_plugin = true; |
| 3461 | use_pepper_host = true; |
| 3462 | } else { |
| 3463 | // In process Pepper plugins must be explicitly enabled. |
| 3464 | return NULL; |
| 3465 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3466 | } else { |
| 3467 | FilePath internal_pdf_path; |
| 3468 | PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path); |
| 3469 | if (file_path == internal_pdf_path) { |
| 3470 | in_process_plugin = true; |
| 3471 | use_pepper_host = true; |
| 3472 | } |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3473 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3474 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3475 | // Check for Native Client modules. |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3476 | if (mime_type == "application/x-nacl-srpc") { |
| 3477 | // NaCl is only permitted when we're in an extension/application with the |
| 3478 | // appropriate permission, or when explicitly enabled on the command line. |
| 3479 | |
| 3480 | // TODO(cbiffle): need browser test for this before M7 (bug 45881) |
| 3481 | GURL main_frame_url(webview()->mainFrame()->url()); |
| 3482 | const std::string &extension_id = |
| 3483 | RenderThread::current()->GetExtensionIdByURL(main_frame_url); |
| 3484 | bool in_ext = extension_id != ""; |
| 3485 | bool explicit_enable = |
| 3486 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl); |
| 3487 | |
| 3488 | if (in_ext) { |
| 3489 | if (ExtensionProcessBindings::HasPermission(extension_id, |
| 3490 | Extension::kNativeClientPermission)) { |
| 3491 | in_process_plugin = true; |
| 3492 | use_pepper_host = true; |
| 3493 | } else { |
| 3494 | // Disable NaCl for apps lacking the permission, even with the flag. |
| 3495 | return NULL; |
| 3496 | } |
| 3497 | } else if (explicit_enable) { |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3498 | in_process_plugin = true; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3499 | use_pepper_host = true; |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3500 | } |
| 3501 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3502 | |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3503 | if (in_process_plugin) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3504 | if (use_pepper_host) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3505 | WebPluginDelegatePepper* pepper_plugin = |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3506 | WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr()); |
[email protected] | b7d7ed5 | 2010-07-20 00:12:33 | [diff] [blame] | 3507 | if (!pepper_plugin) |
| 3508 | return NULL; |
| 3509 | |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 3510 | current_oldstyle_pepper_plugins_.insert(pepper_plugin); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3511 | return pepper_plugin; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3512 | } else { |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3513 | #if defined(OS_WIN) // In-proc plugins aren't supported on Linux or Mac. |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3514 | return WebPluginDelegateImpl::Create( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3515 | file_path, mime_type, gfx::NativeViewFromId(host_window_)); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3516 | #else |
[email protected] | 596b2c4 | 2010-01-14 20:40:43 | [diff] [blame] | 3517 | NOTIMPLEMENTED(); |
| 3518 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 3519 | #endif |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3520 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3521 | } |
| 3522 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3523 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3527 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3528 | RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer( |
| 3529 | routing_id(), window)); |
| 3530 | #endif |
| 3531 | } |
| 3532 | |
| 3533 | void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3534 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3535 | RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer( |
| 3536 | routing_id(), window)); |
| 3537 | #endif |
| 3538 | CleanupWindowInPluginMoves(window); |
| 3539 | } |
| 3540 | |
| 3541 | void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) { |
| 3542 | SchedulePluginMove(move); |
| 3543 | } |
| 3544 | |
| 3545 | void RenderView::DidStartLoadingForPlugin() { |
| 3546 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3547 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | void RenderView::DidStopLoadingForPlugin() { |
| 3551 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3552 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3553 | } |
| 3554 | |
| 3555 | void RenderView::ShowModalHTMLDialogForPlugin( |
| 3556 | const GURL& url, |
| 3557 | const gfx::Size& size, |
| 3558 | const std::string& json_arguments, |
| 3559 | std::string* json_retval) { |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3560 | SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog( |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3561 | routing_id_, url, size.width(), size.height(), json_arguments, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3562 | json_retval)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3563 | } |
| 3564 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 3565 | WebCookieJar* RenderView::GetCookieJar() { |
| 3566 | return &cookie_jar_; |
| 3567 | } |
| 3568 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3569 | void RenderView::SyncNavigationState() { |
| 3570 | if (!webview()) |
| 3571 | return; |
| 3572 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3573 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3574 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3575 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3576 | |
| 3577 | Send(new ViewHostMsg_UpdateState( |
| 3578 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3579 | } |
| 3580 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3581 | bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) { |
| 3582 | // Make sure webview was not shut down. |
| 3583 | if (!webview()) |
| 3584 | return false; |
| 3585 | // Create an image resource fetcher and assign it with a call back object. |
| 3586 | image_fetchers_.insert(new ImageResourceFetcher( |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3587 | image_url, webview()->mainFrame(), id, image_size, |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3588 | NewCallback(this, &RenderView::DidDownloadImage))); |
| 3589 | return true; |
| 3590 | } |
| 3591 | |
| 3592 | void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3593 | const SkBitmap& image) { |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3594 | // Notify requester of image download status. |
[email protected] | 51bd3661 | 2009-10-20 22:49:47 | [diff] [blame] | 3595 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, |
| 3596 | fetcher->id(), |
| 3597 | fetcher->image_url(), |
| 3598 | image.isNull(), |
| 3599 | image)); |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3600 | // Dispose of the image fetcher. |
| 3601 | DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end()); |
| 3602 | image_fetchers_.erase(fetcher); |
| 3603 | // We're in the callback from the ImageResourceFetcher, best to delay |
| 3604 | // deletion. |
| 3605 | MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3606 | } |
| 3607 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3608 | void RenderView::OnDownloadFavIcon(int id, |
| 3609 | const GURL& image_url, |
| 3610 | int image_size) { |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3611 | bool data_image_failed = false; |
| 3612 | if (image_url.SchemeIs("data")) { |
| 3613 | SkBitmap data_image = ImageFromDataUrl(image_url); |
| 3614 | data_image_failed = data_image.empty(); |
| 3615 | if (!data_image_failed) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3616 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false, |
| 3617 | data_image)); |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3618 | } |
| 3619 | } |
| 3620 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3621 | if (data_image_failed || |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3622 | !DownloadImage(id, image_url, image_size)) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3623 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true, |
| 3624 | SkBitmap())); |
| 3625 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3626 | } |
| 3627 | |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3628 | SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const { |
| 3629 | std::string mime_type, char_set, data; |
| 3630 | if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
| 3631 | // Decode the favicon using WebKit's image decoder. |
| 3632 | webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize)); |
| 3633 | const unsigned char* src_data = |
| 3634 | reinterpret_cast<const unsigned char*>(&data[0]); |
| 3635 | |
| 3636 | return decoder.Decode(src_data, data.size()); |
| 3637 | } |
| 3638 | return SkBitmap(); |
| 3639 | } |
| 3640 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3641 | void RenderView::OnGetApplicationInfo(int page_id) { |
| 3642 | webkit_glue::WebApplicationInfo app_info; |
| 3643 | if (page_id == page_id_) |
| 3644 | webkit_glue::GetApplicationInfo(webview(), &app_info); |
| 3645 | |
| 3646 | // Prune out any data URLs in the set of icons. The browser process expects |
| 3647 | // any icon with a data URL to have originated from a favicon. We don't want |
| 3648 | // to decode arbitrary data URLs in the browser process. See |
| 3649 | // http://b/issue?id=1162972 |
| 3650 | for (size_t i = 0; i < app_info.icons.size(); ++i) { |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 3651 | if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3652 | app_info.icons.erase(app_info.icons.begin() + i); |
| 3653 | --i; |
| 3654 | } |
| 3655 | } |
| 3656 | |
| 3657 | Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info)); |
| 3658 | } |
| 3659 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3660 | GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3661 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3662 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3663 | // If the URL that failed was secure, then the embedding web page was not |
| 3664 | // expecting a network attacker to be able to manipulate its contents. As |
| 3665 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 3666 | // attacker to manipulate the contents of the response if we tried to use |
| 3667 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3668 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | // Grab the base URL from the browser process. |
| 3672 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3673 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3674 | |
| 3675 | // Strip query params from the failed URL. |
| 3676 | GURL::Replacements remove_params; |
| 3677 | remove_params.ClearUsername(); |
| 3678 | remove_params.ClearPassword(); |
| 3679 | remove_params.ClearQuery(); |
| 3680 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3681 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3682 | std::string spec_to_send = url_to_send.spec(); |
| 3683 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 3684 | if (failed_url.has_query()) |
| 3685 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3686 | |
| 3687 | // Construct the query params to send to link doctor. |
| 3688 | std::string params(alternate_error_page_url_.query()); |
| 3689 | params.append("&url="); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3690 | params.append(EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3691 | params.append("&sourceid=chrome"); |
| 3692 | params.append("&error="); |
| 3693 | switch (error_type) { |
| 3694 | case DNS_ERROR: |
| 3695 | params.append("dnserror"); |
| 3696 | break; |
| 3697 | |
| 3698 | case HTTP_404: |
| 3699 | params.append("http404"); |
| 3700 | break; |
| 3701 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3702 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 3703 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3704 | break; |
| 3705 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3706 | default: |
| 3707 | NOTREACHED() << "unknown ErrorPageType"; |
| 3708 | } |
| 3709 | |
| 3710 | // OK, build the final url to return. |
| 3711 | GURL::Replacements link_doctor_params; |
| 3712 | link_doctor_params.SetQueryStr(params); |
| 3713 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 3714 | return url; |
| 3715 | } |
| 3716 | |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3717 | WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() { |
| 3718 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3719 | } |
| 3720 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3721 | void RenderView::OnFind(int request_id, const string16& search_text, |
| 3722 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3723 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3724 | |
| 3725 | if (main_frame->document().isPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3726 | if (options.findNext) { |
| 3727 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3728 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3729 | } else { |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 3730 | if (GetWebPluginFromPluginDocument()->startFind( |
| 3731 | search_text, options.matchCase, request_id)) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3732 | } else { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3733 | // Send "no results". |
| 3734 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3735 | request_id, |
| 3736 | 0, |
| 3737 | gfx::Rect(), |
| 3738 | 0, |
| 3739 | true)); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | return; |
| 3743 | } |
| 3744 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3745 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3746 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3747 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 3748 | |
| 3749 | bool multi_frame = (frame_after_main != main_frame); |
| 3750 | |
| 3751 | // If we have multiple frames, we don't want to wrap the search within the |
| 3752 | // frame, so we check here if we only have main_frame in the chain. |
| 3753 | bool wrap_within_frame = !multi_frame; |
| 3754 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 3755 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3756 | bool result = false; |
| 3757 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3758 | // If something is selected when we start searching it means we cannot just |
| 3759 | // increment the current match ordinal; we need to re-generate it. |
| 3760 | WebRange current_selection = focused_frame->selectionRange(); |
| 3761 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3762 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3763 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3764 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3765 | |
| 3766 | if (!result) { |
| 3767 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3768 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3769 | |
| 3770 | // Find the next frame, but skip the invisible ones. |
| 3771 | do { |
| 3772 | // What is the next frame to search? (we might be going backwards). Note |
| 3773 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3774 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3775 | search_frame->traverseNext(true) : |
| 3776 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3777 | } while (!search_frame->hasVisibleContent() && |
| 3778 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3779 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 3780 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3781 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3782 | |
| 3783 | // If we have multiple frames and we have wrapped back around to the |
| 3784 | // focused frame, we need to search it once more allowing wrap within |
| 3785 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 3786 | // reported matches, but no frames after the focused_frame contain a |
| 3787 | // match for the search word(s). |
| 3788 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3789 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3790 | request_id, search_text, options, true, // Force wrapping. |
| 3791 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3792 | } |
| 3793 | } |
| 3794 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3795 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3796 | } while (!result && search_frame != focused_frame); |
| 3797 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3798 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3799 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3800 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3801 | } else { |
| 3802 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 3803 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 3804 | // yet what is active. |
| 3805 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 3806 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3807 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3808 | // If we find no matches then this will be our last status update. |
| 3809 | // Otherwise the scoping effort will send more results. |
| 3810 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3811 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3812 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 3813 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3814 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3815 | match_count, |
| 3816 | selection_rect, |
| 3817 | ordinal, |
| 3818 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3819 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3820 | // Scoping effort begins, starting with the mainframe. |
| 3821 | search_frame = main_frame; |
| 3822 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3823 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3824 | |
| 3825 | do { |
| 3826 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3827 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3828 | |
| 3829 | // We don't start another scoping effort unless at least one match has |
| 3830 | // been found. |
| 3831 | if (result) { |
| 3832 | // Start new scoping request. If the scoping function determines that it |
| 3833 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3834 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3835 | search_text, |
| 3836 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3837 | true); // reset the tickmarks |
| 3838 | } |
| 3839 | |
| 3840 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 3841 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3842 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3843 | } while (search_frame != main_frame); |
| 3844 | } |
| 3845 | } |
| 3846 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3847 | void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) { |
| 3848 | WebView* view = webview(); |
| 3849 | if (!view) |
| 3850 | return; |
| 3851 | |
| 3852 | WebDocument doc = view->mainFrame()->document(); |
| 3853 | if (doc.isPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3854 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3855 | return; |
| 3856 | } |
| 3857 | |
| 3858 | bool clear_selection = |
| 3859 | params.action == ViewMsg_StopFinding_Params::kClearSelection; |
| 3860 | if (clear_selection) |
| 3861 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 3862 | |
| 3863 | WebFrame* frame = view->mainFrame(); |
| 3864 | while (frame) { |
| 3865 | frame->stopFinding(clear_selection); |
| 3866 | frame = frame->traverseNext(false); |
| 3867 | } |
| 3868 | |
| 3869 | if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) { |
| 3870 | WebFrame* focused_frame = view->focusedFrame(); |
| 3871 | if (focused_frame) { |
| 3872 | WebDocument doc = focused_frame->document(); |
| 3873 | if (!doc.isNull()) { |
| 3874 | WebNode node = doc.focusedNode(); |
| 3875 | if (!node.isNull()) |
| 3876 | node.simulateClick(); |
| 3877 | } |
| 3878 | } |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | void RenderView::OnFindReplyAck() { |
| 3883 | // Check if there is any queued up request waiting to be sent. |
| 3884 | if (queued_find_reply_message_.get()) { |
| 3885 | // Send the search result over to the browser process. |
[email protected] | d22d873 | 2010-05-04 19:24:42 | [diff] [blame] | 3886 | Send(queued_find_reply_message_.release()); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3887 | } |
| 3888 | } |
| 3889 | |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3890 | bool RenderView::AllowContentType(ContentSettingsType settings_type) { |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 3891 | // CONTENT_SETTING_ASK is only valid for cookies. |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3892 | return current_content_settings_.settings[settings_type] != |
| 3893 | CONTENT_SETTING_BLOCK; |
| 3894 | } |
| 3895 | |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3896 | void RenderView::DidBlockContentType(ContentSettingsType settings_type, |
| 3897 | const std::string& resource_identifier) { |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3898 | if (!content_blocked_[settings_type]) { |
| 3899 | content_blocked_[settings_type] = true; |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3900 | Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type, |
| 3901 | resource_identifier)); |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 3902 | } |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 3903 | } |
| 3904 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 3905 | void RenderView::ClearBlockedContentSettings() { |
| 3906 | for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 3907 | content_blocked_[i] = false; |
| 3908 | } |
| 3909 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 3910 | WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame, |
| 3911 | const WebPluginParams& params, |
| 3912 | const FilePath& path, |
| 3913 | pepper::PluginModule* pepper_module) { |
| 3914 | WebPlugin* plugin = new pepper::WebPluginImpl(pepper_module, params, |
| 3915 | pepper_delegate_.AsWeakPtr()); |
| 3916 | if (plugin && !frame->parent() && frame->document().isPluginDocument()) { |
| 3917 | // If this is a full-page plugin hosting the internal PDF plugin, we want |
| 3918 | // to notify the browser so that it can treat things like zooming |
| 3919 | // differently. |
| 3920 | // TODO(sanjeevr): Use a Pepper interface to determine this rather than |
| 3921 | // hardcode this for the PDF plugin path. |
| 3922 | FilePath pdf_path; |
| 3923 | PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
| 3924 | if (path == pdf_path) |
| 3925 | Send(new ViewHostMsg_SetDisplayingPDFContent(routing_id_)); |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 3926 | } |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 3927 | return plugin; |
| 3928 | } |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 3929 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 3930 | WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame, |
| 3931 | const WebPluginParams& params, |
| 3932 | const FilePath& path, |
| 3933 | const std::string& mime_type) { |
| 3934 | std::string actual_mime_type(mime_type); |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 3935 | if (actual_mime_type.empty()) |
| 3936 | actual_mime_type = params.mimeType.utf8(); |
| 3937 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 3938 | return new webkit_glue::WebPluginImpl(frame, params, path, |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 3939 | actual_mime_type, AsWeakPtr()); |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | WebPlugin* RenderView::CreatePluginPlaceholder(WebFrame* frame, |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 3943 | const WebPluginParams& params, |
| 3944 | PluginGroup* group) { |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 3945 | // |blocked_plugin| will delete itself when the WebViewPlugin is destroyed. |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 3946 | BlockedPlugin* blocked_plugin = new BlockedPlugin(this, frame, params, group); |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 3947 | WebViewPlugin* plugin = blocked_plugin->plugin(); |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 3948 | WebView* web_view = plugin->web_view(); |
| 3949 | webkit_preferences_.Apply(web_view); |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 3950 | return plugin; |
| 3951 | } |
| 3952 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3953 | void RenderView::OnZoom(PageZoom::Function function) { |
| 3954 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 3955 | return; |
| 3956 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 3957 | webview()->hidePopups(); |
[email protected] | b03794d | 2010-03-26 19:57:52 | [diff] [blame] | 3958 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3959 | int zoom_level = webview()->zoomLevel(); |
| 3960 | int new_zoom_level = webview()->setZoomLevel(false, |
| 3961 | (function == PageZoom::RESET) ? 0 : (zoom_level + function)); |
| 3962 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3963 | // Tell the browser which url got zoomed so it can update the saved values. |
| 3964 | Send(new ViewHostMsg_DidZoomURL( |
| 3965 | GURL(webview()->mainFrame()->url()), new_zoom_level)); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3966 | } |
| 3967 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3968 | void RenderView::OnSetContentSettingsForLoadingURL( |
| 3969 | const GURL& url, |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 3970 | const ContentSettings& content_settings) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3971 | host_content_settings_[url] = content_settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 3972 | } |
| 3973 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3974 | void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 3975 | int zoom_level) { |
| 3976 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3977 | } |
| 3978 | |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 3979 | void RenderView::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3980 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3981 | } |
| 3982 | |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 3983 | void RenderView::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3984 | WebString no_encoding; |
| 3985 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 3986 | } |
| 3987 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 3988 | bool RenderView::GetAllChildFrames( |
| 3989 | WebFrame* parent_frame, |
| 3990 | std::vector<WebFrame*>* frames_vector) const { |
| 3991 | if (!parent_frame) |
| 3992 | return false; |
| 3993 | for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
| 3994 | child_frame = child_frame->nextSibling()) { |
| 3995 | frames_vector->push_back(child_frame); |
| 3996 | GetAllChildFrames(child_frame, frames_vector); |
| 3997 | } |
| 3998 | return true; |
| 3999 | } |
| 4000 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4001 | WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { |
| 4002 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4003 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4004 | |
| 4005 | // xpath string can represent a frame deep down the tree (across multiple |
| 4006 | // frame DOMs). |
| 4007 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 4008 | // should break into 2 xpaths |
| 4009 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
| 4010 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4011 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4012 | |
| 4013 | std::wstring xpath_remaining = xpath; |
| 4014 | while (!xpath_remaining.empty()) { |
| 4015 | std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n'); |
| 4016 | std::wstring xpath_child; |
| 4017 | if (delim_pos != std::wstring::npos) { |
| 4018 | xpath_child = xpath_remaining.substr(0, delim_pos); |
| 4019 | xpath_remaining.erase(0, delim_pos + 1); |
| 4020 | } else { |
| 4021 | xpath_remaining.swap(xpath_child); |
| 4022 | } |
| 4023 | frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4024 | } |
| 4025 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4026 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4027 | } |
| 4028 | |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 4029 | void RenderView::EvaluateScript(const std::wstring& frame_xpath, |
| 4030 | const std::wstring& script) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4031 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4032 | if (!web_frame) |
| 4033 | return; |
| 4034 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4035 | web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4036 | } |
| 4037 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4038 | void RenderView::InsertCSS(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4039 | const std::string& css, |
| 4040 | const std::string& id) { |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4041 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4042 | if (!web_frame) |
| 4043 | return; |
| 4044 | |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4045 | web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4046 | } |
| 4047 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4048 | void RenderView::OnPepperPluginDestroy( |
| 4049 | WebPluginDelegatePepper* pepper_plugin) { |
| 4050 | std::set<WebPluginDelegatePepper*>::iterator found_pepper = |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4051 | current_oldstyle_pepper_plugins_.find(pepper_plugin); |
| 4052 | if (found_pepper == current_oldstyle_pepper_plugins_.end()) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4053 | NOTREACHED(); |
| 4054 | return; |
| 4055 | } |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4056 | current_oldstyle_pepper_plugins_.erase(found_pepper); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4057 | |
| 4058 | // The plugin could have been destroyed while it was waiting for a file |
| 4059 | // choose callback, so check all pending completion callbacks and NULL them. |
| 4060 | for (std::deque< linked_ptr<PendingFileChooser> >::iterator i = |
| 4061 | file_chooser_completions_.begin(); |
| 4062 | i != file_chooser_completions_.end(); /* nothing */) { |
| 4063 | if ((*i)->completion == pepper_plugin) { |
| 4064 | // We NULL the first one instead of deleting it because the plugin might |
| 4065 | // be the one waiting for a file choose callback. If the callback later |
| 4066 | // comes, we don't want to send the result to the next callback in line. |
| 4067 | if (i == file_chooser_completions_.begin()) |
| 4068 | (*i)->completion = NULL; |
| 4069 | else |
| 4070 | i = file_chooser_completions_.erase(i); |
| 4071 | } else { |
| 4072 | ++i; |
| 4073 | } |
| 4074 | } |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4075 | } |
| 4076 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4077 | void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath, |
| 4078 | const std::wstring& jscript) { |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 4079 | EvaluateScript(frame_xpath, jscript); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4080 | } |
| 4081 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4082 | void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4083 | const std::string& css, |
| 4084 | const std::string& id) { |
| 4085 | InsertCSS(frame_xpath, css, id); |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 4086 | |
| 4087 | // Notify RenderViewHost that css has been inserted into the frame. |
| 4088 | Send(new ViewHostMsg_OnCSSInserted(routing_id_)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4089 | } |
| 4090 | |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4091 | void RenderView::OnAddMessageToConsole( |
| 4092 | const string16& frame_xpath, |
| 4093 | const string16& message, |
| 4094 | const WebConsoleMessage::Level& level) { |
| 4095 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 4096 | if (web_frame) |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4097 | web_frame->addMessageToConsole(WebConsoleMessage(level, message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4098 | } |
| 4099 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4100 | void RenderView::OnAllowBindings(int enabled_bindings_flags) { |
| 4101 | enabled_bindings_ |= enabled_bindings_flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | void RenderView::OnSetDOMUIProperty(const std::string& name, |
| 4105 | const std::string& value) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4106 | DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4107 | dom_ui_bindings_.SetProperty(name, value); |
| 4108 | } |
| 4109 | |
| 4110 | void RenderView::OnReservePageIDRange(int size_of_range) { |
| 4111 | next_page_id_ += size_of_range + 1; |
| 4112 | } |
| 4113 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4114 | void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 4115 | const gfx::Point& screen_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4116 | bool ended, |
| 4117 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4118 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4119 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 4120 | } else { |
| 4121 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4122 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | void RenderView::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4126 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4127 | } |
| 4128 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4129 | void RenderView::OnFillPasswordForm( |
[email protected] | e768baf | 2010-07-16 19:36:16 | [diff] [blame] | 4130 | const webkit_glue::PasswordFormFillData& form_data) { |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4131 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
| 4132 | password_autocomplete_manager_.ReceivedPasswordFormFillData(webview(), |
| 4133 | form_data); |
[email protected] | ad24ccb | 2010-07-15 21:38:20 | [diff] [blame] | 4134 | #else |
| 4135 | webkit_glue::FillPasswordForm(this->webview(), form_data); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4136 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data, |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4140 | const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4141 | const gfx::Point& screen_point, |
| 4142 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4143 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4144 | drop_data.ToDragData(), |
| 4145 | drop_data.identity, |
| 4146 | client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4147 | screen_point, |
| 4148 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4149 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4150 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4151 | } |
| 4152 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4153 | void RenderView::OnDragTargetDragOver(const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4154 | const gfx::Point& screen_point, |
| 4155 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4156 | WebDragOperation operation = webview()->dragTargetDragOver( |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4157 | client_point, |
| 4158 | screen_point, |
| 4159 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4160 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4161 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | void RenderView::OnDragTargetDragLeave() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4165 | webview()->dragTargetDragLeave(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4166 | } |
| 4167 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4168 | void RenderView::OnDragTargetDrop(const gfx::Point& client_point, |
| 4169 | const gfx::Point& screen_point) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4170 | webview()->dragTargetDrop(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 4174 | webkit_preferences_ = prefs; |
| 4175 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | void RenderView::OnSetAltErrorPageURL(const GURL& url) { |
| 4179 | alternate_error_page_url_ = url; |
| 4180 | } |
| 4181 | |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 4182 | void RenderView::OnCustomContextMenuAction(unsigned action) { |
| 4183 | webview()->performCustomContextMenuAction(action); |
| 4184 | } |
| 4185 | |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4186 | void RenderView::OnTranslatePage(int page_id, |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4187 | const std::string& translate_script, |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4188 | const std::string& source_lang, |
| 4189 | const std::string& target_lang) { |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4190 | translate_helper_.TranslatePage(page_id, source_lang, target_lang, |
| 4191 | translate_script); |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4192 | } |
| 4193 | |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4194 | void RenderView::OnRevertTranslation(int page_id) { |
| 4195 | translate_helper_.RevertTranslation(page_id); |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 4196 | } |
| 4197 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4198 | void RenderView::OnInstallMissingPlugin() { |
| 4199 | // This could happen when the first default plugin is deleted. |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4200 | if (first_default_plugin_) |
| 4201 | first_default_plugin_->InstallMissingPlugin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4202 | } |
| 4203 | |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 4204 | void RenderView::OnLoadBlockedPlugins() { |
| 4205 | NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS, |
| 4206 | Source<RenderView>(this), |
| 4207 | NotificationService::NoDetails()); |
| 4208 | } |
| 4209 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4210 | void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4211 | // This could happen if we navigated to a different page before the user |
| 4212 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4213 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4214 | return; |
| 4215 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4216 | WebVector<WebString> ws_file_names(paths.size()); |
| 4217 | for (size_t i = 0; i < paths.size(); ++i) |
| 4218 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 4219 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4220 | if (file_chooser_completions_.front()->completion) |
| 4221 | file_chooser_completions_.front()->completion->didChooseFile(ws_file_names); |
| 4222 | file_chooser_completions_.pop_front(); |
| 4223 | |
| 4224 | // If there are more pending file chooser requests, schedule one now. |
| 4225 | if (!file_chooser_completions_.empty()) { |
| 4226 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 4227 | file_chooser_completions_.front()->params)); |
| 4228 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | void RenderView::OnEnableViewSourceMode() { |
| 4232 | if (!webview()) |
| 4233 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4234 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4235 | if (!main_frame) |
| 4236 | return; |
| 4237 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4238 | main_frame->enableViewSourceMode(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4239 | } |
| 4240 | |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 4241 | void RenderView::OnEnablePreferredSizeChangedMode(int flags) { |
| 4242 | DCHECK(flags != kPreferredSizeNothing); |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4243 | if (send_preferred_size_changes_) |
| 4244 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4245 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 4246 | |
| 4247 | // WebKit doesn't send a notification of the effective height of the page |
| 4248 | // changes, so poll for it. |
| 4249 | // TODO: Add a notification for this to WebKit, remove polling. After that's |
| 4250 | // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight. |
| 4251 | // http://crbug.com/44850 |
| 4252 | if (flags & kPreferredSizeHeightThisIsSlow) { |
| 4253 | preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this, |
| 4254 | &RenderView::CheckPreferredSize); |
| 4255 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 4256 | } |
| 4257 | |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4258 | void RenderView::OnDisableScrollbarsForSmallWindows( |
| 4259 | const gfx::Size& disable_scrollbar_size_limit) { |
| 4260 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 4261 | } |
| 4262 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4263 | void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { |
| 4264 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 4265 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 4266 | #if defined(TOOLKIT_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 4267 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 4268 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 4269 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4270 | |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4271 | if (webview()) { |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4272 | webview()->setScrollbarColors( |
| 4273 | renderer_prefs.thumb_inactive_color, |
| 4274 | renderer_prefs.thumb_active_color, |
| 4275 | renderer_prefs.track_color); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4276 | webview()->setSelectionColors( |
| 4277 | renderer_prefs.active_selection_bg_color, |
| 4278 | renderer_prefs.active_selection_fg_color, |
| 4279 | renderer_prefs.inactive_selection_bg_color, |
| 4280 | renderer_prefs.inactive_selection_fg_color); |
[email protected] | 61c6440 | 2010-05-25 22:05:01 | [diff] [blame] | 4281 | didInvalidateRect(gfx::Rect(size_)); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4282 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 4283 | #endif |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4284 | } |
| 4285 | |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 4286 | void RenderView::OnMediaPlayerActionAt(const gfx::Point& location, |
| 4287 | const WebMediaPlayerAction& action) { |
| 4288 | if (webview()) |
| 4289 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 4290 | } |
| 4291 | |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 4292 | void RenderView::OnNotifyRendererViewType(ViewType::Type type) { |
| 4293 | view_type_ = type; |
| 4294 | } |
| 4295 | |
| 4296 | void RenderView::OnUpdateBrowserWindowId(int window_id) { |
| 4297 | browser_window_id_ = window_id; |
| 4298 | } |
| 4299 | |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 4300 | void RenderView::OnGetAccessibilityTree() { |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4301 | if (accessibility_.get()) |
[email protected] | 9f4db51 | 2010-05-10 20:21:41 | [diff] [blame] | 4302 | accessibility_->clear(); |
[email protected] | 039a1da | 2010-05-12 02:08:11 | [diff] [blame] | 4303 | accessibility_.reset(WebAccessibilityCache::create()); |
| 4304 | accessibility_->initialize(webview()); |
[email protected] | 9f4db51 | 2010-05-10 20:21:41 | [diff] [blame] | 4305 | |
[email protected] | b3df5a4 | 2010-05-11 14:31:09 | [diff] [blame] | 4306 | WebAccessibilityObject src_tree = webview()->accessibilityObject(); |
| 4307 | webkit_glue::WebAccessibility dst_tree(src_tree, accessibility_.get()); |
| 4308 | Send(new ViewHostMsg_AccessibilityTree(routing_id_, dst_tree)); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 4309 | } |
| 4310 | |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4311 | void RenderView::OnSetAccessibilityFocus(int acc_obj_id) { |
| 4312 | if (!accessibility_.get()) |
| 4313 | return; |
| 4314 | if (accessibility_->isValidId(acc_obj_id)) { |
| 4315 | // TODO(dmazzoni) fix the cache so that id=1000 is not a magic number. |
| 4316 | // By convention, calling SetFocus on the root of the tree (id = 1000) |
| 4317 | // should clear the current focus. Otherwise set the focus to the new |
| 4318 | // node. |
| 4319 | if (acc_obj_id == 1000) |
| 4320 | webview()->clearFocusedNode(); |
| 4321 | else |
| 4322 | accessibility_->getObjectById(acc_obj_id).setFocused(true); |
| 4323 | } |
| 4324 | } |
| 4325 | |
| 4326 | void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) { |
| 4327 | if (!accessibility_.get()) |
| 4328 | return; |
| 4329 | if (accessibility_->isValidId(acc_obj_id)) { |
| 4330 | accessibility_->getObjectById(acc_obj_id).performDefaultAction(); |
| 4331 | } |
| 4332 | } |
| 4333 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4334 | void RenderView::OnGetAllSavableResourceLinksForCurrentPage( |
| 4335 | const GURL& page_url) { |
| 4336 | // Prepare list to storage all savable resource links. |
| 4337 | std::vector<GURL> resources_list; |
| 4338 | std::vector<GURL> referrers_list; |
| 4339 | std::vector<GURL> frames_list; |
| 4340 | webkit_glue::SavableResourcesResult result(&resources_list, |
| 4341 | &referrers_list, |
| 4342 | &frames_list); |
| 4343 | |
[email protected] | dbeb395 | 2009-10-13 18:01:18 | [diff] [blame] | 4344 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 4345 | webview(), |
| 4346 | page_url, |
| 4347 | &result, |
| 4348 | chrome::kSavableSchemes)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4349 | // If something is wrong when collecting all savable resource links, |
| 4350 | // send empty list to embedder(browser) to tell it failed. |
| 4351 | referrers_list.clear(); |
| 4352 | resources_list.clear(); |
| 4353 | frames_list.clear(); |
| 4354 | } |
| 4355 | |
| 4356 | // Send result of all savable resource links to embedder. |
| 4357 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_, |
| 4358 | resources_list, |
| 4359 | referrers_list, |
| 4360 | frames_list)); |
| 4361 | } |
| 4362 | |
| 4363 | void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | f6b4853 | 2009-02-12 01:56:32 | [diff] [blame] | 4364 | const std::vector<GURL>& links, |
[email protected] | fde6714d1 | 2009-02-18 22:39:31 | [diff] [blame] | 4365 | const std::vector<FilePath>& local_paths, |
| 4366 | const FilePath& local_directory_name) { |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4367 | |
| 4368 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 4369 | WebVector<WebURL> weburl_links(links); |
| 4370 | |
| 4371 | // Convert std::vector of std::strings to WebVector<WebString> |
| 4372 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 4373 | for (size_t i = 0; i < local_paths.size(); i++) |
| 4374 | webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); |
| 4375 | |
| 4376 | WebPageSerializer::serialize(webview()->mainFrame(), |
| 4377 | true, this, weburl_links, webstring_paths, |
| 4378 | webkit_glue::FilePathToWebString( |
| 4379 | local_directory_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4380 | } |
| 4381 | |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4382 | void RenderView::didSerializeDataForFrame(const WebURL& frame_url, |
| 4383 | const WebCString& data, |
| 4384 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4385 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4386 | routing_id_, |
| 4387 | frame_url, |
| 4388 | data.data(), |
| 4389 | static_cast<int32>(status))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4390 | } |
| 4391 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 4392 | void RenderView::OnShouldClose() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4393 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4394 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4395 | } |
| 4396 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4397 | void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4398 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 4399 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 4400 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 4401 | // calling the FrameLoader's CloseURL method directly. This should be |
| 4402 | // revisited to avoid having two ways to close a page. Having a single way |
| 4403 | // to close that can run onunload is also useful for fixing |
| 4404 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4405 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4406 | if (main_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4407 | const GURL& url = main_frame->url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4408 | // TODO(davemoore) this code should be removed once willClose() gets |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4409 | // called when a page is destroyed. DumpLoadHistograms() is safe to call |
| 4410 | // multiple times for the same frame, but it will simplify things. |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4411 | |
| 4412 | // Ensure state contains scheme. |
| 4413 | NavigationState* navigation_state = |
| 4414 | NavigationState::FromDataSource(main_frame->dataSource()); |
| 4415 | if (url.SchemeIs("http")) |
| 4416 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP); |
| 4417 | else if (url.SchemeIs("https")) |
| 4418 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS); |
| 4419 | |
| 4420 | // Dump will only be provided when scheme is http or https. |
| 4421 | DumpLoadHistograms(); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4422 | } |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4423 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4424 | |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 4425 | // Reset stats |
| 4426 | cross_origin_access_count_ = 0; |
| 4427 | same_origin_access_count_ = 0; |
| 4428 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4429 | // Just echo back the params in the ACK. |
| 4430 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4431 | } |
| 4432 | |
| 4433 | void RenderView::OnThemeChanged() { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4434 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4435 | gfx::NativeTheme::instance()->CloseHandles(); |
[email protected] | 61c6440 | 2010-05-25 22:05:01 | [diff] [blame] | 4436 | didInvalidateRect(gfx::Rect(size_)); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4437 | #else // defined(OS_WIN) |
| 4438 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 4439 | NOTIMPLEMENTED(); |
| 4440 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4441 | } |
| 4442 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 4443 | void RenderView::OnHandleMessageFromExternalHost(const std::string& message, |
| 4444 | const std::string& origin, |
| 4445 | const std::string& target) { |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4446 | if (message.empty()) |
| 4447 | return; |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 4448 | external_host_bindings_.ForwardMessageFromExternalHost(message, origin, |
| 4449 | target); |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4450 | } |
| 4451 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 4452 | void RenderView::OnDisassociateFromPopupCount() { |
| 4453 | if (decrement_shared_popup_at_destruction_) |
| 4454 | shared_popup_counter_->data--; |
| 4455 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 4456 | decrement_shared_popup_at_destruction_ = false; |
| 4457 | } |
| 4458 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4459 | bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 4460 | const WebURLError& error, |
| 4461 | bool replace) { |
| 4462 | // We only show alternate error pages in the main frame. They are |
| 4463 | // intended to assist the user when navigating, so there is not much |
| 4464 | // value in showing them for failed subframes. Ideally, we would be |
| 4465 | // able to use the TYPED transition type for this, but that flag is |
| 4466 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4467 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4468 | return false; |
| 4469 | |
| 4470 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4471 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4472 | int ec = error.reason; |
| 4473 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 4474 | ec != net::ERR_CONNECTION_FAILED && |
| 4475 | ec != net::ERR_CONNECTION_REFUSED && |
| 4476 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4477 | ec != net::ERR_CONNECTION_TIMED_OUT) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4478 | return false; |
| 4479 | |
| 4480 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4481 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4482 | if (!error_page_url.is_valid()) |
| 4483 | return false; |
| 4484 | |
| 4485 | // Load an empty page first so there is an immediate response to the error, |
| 4486 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4487 | frame->loadHTMLString(std::string(), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4488 | GURL(kUnreachableWebDataURL), |
| 4489 | error.unreachableURL, |
| 4490 | replace); |
| 4491 | |
| 4492 | // Now, create a fetcher for the error page and associate it with the data |
| 4493 | // source we just created via the LoadHTMLString call. That way if another |
| 4494 | // navigation occurs, the fetcher will get destroyed. |
| 4495 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4496 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4497 | navigation_state->set_alt_error_page_fetcher( |
| 4498 | new AltErrorPageResourceFetcher( |
| 4499 | error_page_url, frame, error, |
| 4500 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 4501 | return true; |
| 4502 | } |
| 4503 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4504 | std::string RenderView::GetAltHTMLForTemplate( |
| 4505 | const DictionaryValue& error_strings, int template_resource_id) const { |
[email protected] | 8a16266e | 2009-09-10 21:08:39 | [diff] [blame] | 4506 | const base::StringPiece template_html( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4507 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 4508 | template_resource_id)); |
| 4509 | |
| 4510 | if (template_html.empty()) { |
| 4511 | NOTREACHED() << "unable to load template. ID: " << template_resource_id; |
| 4512 | return ""; |
| 4513 | } |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4514 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4515 | // "t" is the id of the templates root node. |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4516 | return jstemplate_builder::GetTemplatesHtml( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4517 | template_html, &error_strings, "t"); |
| 4518 | } |
[email protected] | 0e79b9e | 2009-02-13 04:20:48 | [diff] [blame] | 4519 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4520 | void RenderView::AltErrorPageFinished(WebFrame* frame, |
| 4521 | const WebURLError& original_error, |
| 4522 | const std::string& html) { |
| 4523 | // Here, we replace the blank page we loaded previously. |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4524 | |
| 4525 | // If we failed to download the alternate error page, fall back to the |
| 4526 | // original error page if present. Otherwise, LoadNavigationErrorPage |
| 4527 | // will simply display a default error page. |
| 4528 | const std::string* html_to_load = &html; |
| 4529 | if (html.empty()) { |
| 4530 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4531 | NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4532 | html_to_load = &navigation_state->postponed_data(); |
| 4533 | } |
| 4534 | LoadNavigationErrorPage( |
| 4535 | frame, WebURLRequest(), original_error, *html_to_load, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4536 | } |
| 4537 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4538 | void RenderView::OnMoveOrResizeStarted() { |
| 4539 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4540 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4541 | } |
| 4542 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4543 | void RenderView::OnResize(const gfx::Size& new_size, |
| 4544 | const gfx::Rect& resizer_rect) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4545 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4546 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4547 | |
| 4548 | if (send_preferred_size_changes_) { |
| 4549 | // If resizing to a size larger than |disable_scrollbars_size_limit_| in |
| 4550 | // either width or height, allow scroll bars. |
| 4551 | bool allow_scrollbars = ( |
| 4552 | disable_scrollbars_size_limit_.width() <= new_size.width() || |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 4553 | disable_scrollbars_size_limit_.height() <= new_size.height()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4554 | webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars); |
| 4555 | } |
| 4556 | } |
| 4557 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4558 | RenderWidget::OnResize(new_size, resizer_rect); |
| 4559 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 4560 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4561 | void RenderView::DidInitiatePaint() { |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4562 | // Notify the pepper plugins that we started painting. |
| 4563 | pepper_delegate_.ViewInitiatedPaint(); |
| 4564 | |
| 4565 | // Notify any "old-style" pepper plugins that we started painting. This is |
| 4566 | // used for internal bookkeeping only, so we know that the set can not change |
| 4567 | // under us. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4568 | for (std::set<WebPluginDelegatePepper*>::iterator i = |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4569 | current_oldstyle_pepper_plugins_.begin(); |
| 4570 | i != current_oldstyle_pepper_plugins_.end(); ++i) |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4571 | (*i)->RenderViewInitiatedPaint(); |
| 4572 | } |
| 4573 | |
| 4574 | void RenderView::DidFlushPaint() { |
| 4575 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 4576 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 4577 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 4578 | // won't change out from under us. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4579 | pepper_delegate_.ViewFlushedPaint(); |
| 4580 | |
| 4581 | // Notify any old-style pepper plugins that we painted. This will call into |
| 4582 | // the plugin, and we it may ask to close itself as a result. This will, in |
| 4583 | // turn, modify our set, possibly invalidating the iterator. So we iterate on |
| 4584 | // a copy that won't change out from under us. |
| 4585 | // This should be deleted when we don't support old Pepper anymore. |
| 4586 | std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4587 | for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin(); |
| 4588 | i != plugins.end(); ++i) { |
| 4589 | // The copy above makes sure our iterator is never invalid if some plugins |
| 4590 | // are destroyed. But some plugin may decide to close all of its views in |
| 4591 | // response to a paint in one of them, so we need to make sure each one is |
| 4592 | // still "current" before using it. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4593 | if (current_oldstyle_pepper_plugins_.find(*i) != |
| 4594 | current_oldstyle_pepper_plugins_.end()) |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4595 | (*i)->RenderViewFlushedPaint(); |
| 4596 | } |
| 4597 | |
| 4598 | WebFrame* main_frame = webview()->mainFrame(); |
| 4599 | |
| 4600 | // If we have a provisional frame we are between the start and commit stages |
| 4601 | // of loading and we don't want to save stats. |
| 4602 | if (!main_frame->provisionalDataSource()) { |
| 4603 | WebDataSource* ds = main_frame->dataSource(); |
| 4604 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 4605 | DCHECK(navigation_state); |
| 4606 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4607 | // TODO(jar): The following code should all be inside a method, probably in |
| 4608 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4609 | Time now = Time::Now(); |
| 4610 | if (navigation_state->first_paint_time().is_null()) { |
| 4611 | navigation_state->set_first_paint_time(now); |
| 4612 | } |
| 4613 | if (navigation_state->first_paint_after_load_time().is_null() && |
| 4614 | !navigation_state->finish_load_time().is_null()) { |
| 4615 | navigation_state->set_first_paint_after_load_time(now); |
| 4616 | } |
| 4617 | } |
| 4618 | } |
| 4619 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4620 | void RenderView::OnClearFocusedNode() { |
| 4621 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4622 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4623 | } |
| 4624 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4625 | void RenderView::OnSetBackground(const SkBitmap& background) { |
| 4626 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4627 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4628 | |
| 4629 | SetBackground(background); |
| 4630 | } |
| 4631 | |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4632 | void RenderView::OnSetActive(bool active) { |
| 4633 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4634 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 4635 | |
| 4636 | #if defined(OS_MACOSX) |
| 4637 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4638 | for (plugin_it = plugin_delegates_.begin(); |
| 4639 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4640 | (*plugin_it)->SetWindowFocus(active); |
| 4641 | } |
| 4642 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4643 | } |
| 4644 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4645 | #if defined(OS_MACOSX) |
| 4646 | void RenderView::OnSetWindowVisibility(bool visible) { |
| 4647 | // Inform plugins that their container has changed visibility. |
| 4648 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4649 | for (plugin_it = plugin_delegates_.begin(); |
| 4650 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4651 | (*plugin_it)->SetContainerVisibility(visible); |
| 4652 | } |
| 4653 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4654 | |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 4655 | void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 4656 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4657 | // Inform plugins that their window's frame has changed. |
| 4658 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4659 | for (plugin_it = plugin_delegates_.begin(); |
| 4660 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4661 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 4662 | } |
| 4663 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4664 | #endif // OS_MACOSX |
| 4665 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 4666 | void RenderView::SendExtensionRequest( |
| 4667 | const ViewHostMsg_DomMessage_Params& params) { |
| 4668 | Send(new ViewHostMsg_ExtensionRequest(routing_id_, params)); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4669 | } |
| 4670 | |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 4671 | void RenderView::OnExtensionResponse(int request_id, |
| 4672 | bool success, |
| 4673 | const std::string& response, |
| 4674 | const std::string& error) { |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 4675 | ExtensionProcessBindings::HandleResponse( |
| 4676 | request_id, success, response, error); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4677 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4678 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 4679 | void RenderView::OnExtensionMessageInvoke(const std::string& function_name, |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4680 | const ListValue& args, |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 4681 | bool requires_incognito_access, |
| 4682 | const GURL& event_url) { |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4683 | RendererExtensionBindings::Invoke( |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 4684 | function_name, args, this, requires_incognito_access, event_url); |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 4685 | } |
| 4686 | |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4687 | // Dump all load time histograms. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4688 | // |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4689 | // The time points we keep are |
| 4690 | // request: time document was requested by user |
| 4691 | // start: time load of document started |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 4692 | // commit: time load of document started |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4693 | // finish_document: main document loaded, before onload() |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4694 | // finish_all_loads: after onload() and all resources are loaded |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4695 | // first_paint: first paint performed |
| 4696 | // first_paint_after_load: first paint performed after load is finished |
| 4697 | // begin: request if it was user requested, start otherwise |
| 4698 | // |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4699 | // It's possible for the request time not to be set, if a client |
| 4700 | // redirect had been done (the user never requested the page) |
| 4701 | // Also, it's possible to load a page without ever laying it out |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4702 | // so first_paint and first_paint_after_load can be 0. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4703 | void RenderView::DumpLoadHistograms() const { |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4704 | // Configuration for PLT related histograms. |
| 4705 | static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10)); |
| 4706 | static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10)); |
| 4707 | static const size_t kPLTCount(100); |
| 4708 | #define PLT_HISTOGRAM(name, sample) \ |
| 4709 | UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount); |
| 4710 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4711 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4712 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4713 | NavigationState::FromDataSource(main_frame->dataSource()); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4714 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4715 | URLPattern::SchemeMasks scheme_type = navigation_state->scheme_type(); |
| 4716 | if (scheme_type == 0) |
| 4717 | return; |
| 4718 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP || |
| 4719 | scheme_type == URLPattern::SCHEME_HTTPS); |
| 4720 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4721 | // If we've already dumped, do nothing. |
| 4722 | if (navigation_state->load_histograms_recorded()) |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4723 | return; |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4724 | |
| 4725 | // Collect measurement times. |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4726 | Time start = navigation_state->start_load_time(); |
| 4727 | if (start.is_null()) |
| 4728 | return; // Probably very premature abandonment of page. |
| 4729 | Time commit = navigation_state->commit_load_time(); |
| 4730 | if (commit.is_null()) |
| 4731 | return; // Probably very premature abandonment of page. |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4732 | |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4733 | // We properly handle null values for the next 3 variables. |
| 4734 | Time request = navigation_state->request_time(); |
| 4735 | Time first_paint = navigation_state->first_paint_time(); |
| 4736 | Time first_paint_after_load = navigation_state->first_paint_after_load_time(); |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4737 | Time finish_doc = navigation_state->finish_document_load_time(); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4738 | Time finish_all_loads = navigation_state->finish_load_time(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4739 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4740 | // Handle case where user hits "stop" or "back" before loading completely. |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4741 | bool abandoned_page = finish_doc.is_null(); |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4742 | if (abandoned_page) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4743 | finish_doc = Time::Now(); |
| 4744 | navigation_state->set_finish_document_load_time(finish_doc); |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4745 | } |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4746 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4747 | // TODO(jar): We should really discriminate the definition of "abandon" more |
| 4748 | // finely. We should have: |
| 4749 | // abandon_before_document_loaded |
| 4750 | // abandon_before_onload_fired |
| 4751 | |
| 4752 | if (finish_all_loads.is_null()) { |
| 4753 | finish_all_loads = Time::Now(); |
| 4754 | navigation_state->set_finish_load_time(finish_all_loads); |
| 4755 | } else { |
| 4756 | DCHECK(!abandoned_page); // How can the doc have finished but not the page? |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4757 | if (!abandoned_page) |
| 4758 | return; // Don't try to record a stat which is broken. |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | // Note: Client side redirects will have no request time. |
| 4762 | Time begin = request.is_null() ? start : request; |
| 4763 | TimeDelta begin_to_finish_doc = finish_doc - begin; |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4764 | TimeDelta begin_to_finish_all_loads = finish_all_loads - begin; |
| 4765 | TimeDelta start_to_finish_all_loads = finish_all_loads - start; |
[email protected] | ef1d8d32 | 2010-06-13 18:31:25 | [diff] [blame] | 4766 | TimeDelta start_to_commit = commit - start; |
[email protected] | f899964 | 2009-10-27 21:39:42 | [diff] [blame] | 4767 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4768 | NavigationState::LoadType load_type = navigation_state->load_type(); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4769 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4770 | // The above code sanitized all values of times, in preparation for creating |
| 4771 | // actual histograms. The remainder of this code could be run at destructor |
| 4772 | // time for the navigation_state, since all data is intact. |
| 4773 | |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4774 | // Aggregate PLT data across all link types. |
| 4775 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2); |
| 4776 | UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type, |
| 4777 | NavigationState::kLoadTypeMax); |
[email protected] | ef1d8d32 | 2010-06-13 18:31:25 | [diff] [blame] | 4778 | PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4779 | PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4780 | PLT_HISTOGRAM("PLT.FinishDocToFinish", finish_all_loads - finish_doc); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4781 | PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4782 | PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4783 | if (!request.is_null()) { |
| 4784 | PLT_HISTOGRAM("PLT.RequestToStart", start - request); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4785 | PLT_HISTOGRAM("PLT.RequestToFinish", finish_all_loads - request); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4786 | } |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4787 | PLT_HISTOGRAM("PLT.CommitToFinish", finish_all_loads - commit); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4788 | if (!first_paint.is_null()) { |
| 4789 | DCHECK(begin <= first_paint); |
| 4790 | PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin); |
| 4791 | DCHECK(commit <= first_paint); |
| 4792 | PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit); |
| 4793 | } |
| 4794 | if (!first_paint_after_load.is_null()) { |
| 4795 | DCHECK(begin <= first_paint_after_load); |
| 4796 | PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad", |
| 4797 | first_paint_after_load - begin); |
| 4798 | DCHECK(commit <= first_paint_after_load); |
| 4799 | PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad", |
| 4800 | first_paint_after_load - commit); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4801 | DCHECK(finish_all_loads <= first_paint_after_load); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4802 | PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4803 | first_paint_after_load - finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4804 | } |
| 4805 | PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4806 | PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4807 | |
| 4808 | // Load type related histograms. |
| 4809 | switch (load_type) { |
| 4810 | case NavigationState::UNDEFINED_LOAD: |
| 4811 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4812 | PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4813 | break; |
| 4814 | case NavigationState::RELOAD: |
| 4815 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4816 | PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4817 | break; |
| 4818 | case NavigationState::HISTORY_LOAD: |
| 4819 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4820 | PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4821 | break; |
| 4822 | case NavigationState::NORMAL_LOAD: |
| 4823 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4824 | PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4825 | break; |
| 4826 | case NavigationState::LINK_LOAD_NORMAL: |
| 4827 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal", |
| 4828 | begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4829 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal", |
| 4830 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4831 | break; |
| 4832 | case NavigationState::LINK_LOAD_RELOAD: |
| 4833 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload", |
| 4834 | begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4835 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload", |
| 4836 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4837 | break; |
| 4838 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4839 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk", |
| 4840 | begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4841 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk", |
| 4842 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4843 | break; |
| 4844 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 4845 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly", |
| 4846 | begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4847 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly", |
| 4848 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4849 | break; |
| 4850 | default: |
| 4851 | break; |
| 4852 | } |
| 4853 | |
| 4854 | // Histograms to determine if DNS prefetching has an impact on PLT. |
| 4855 | static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") && |
| 4856 | !FieldTrialList::Find("DnsImpact")->group_name().empty()); |
| 4857 | if (use_dns_histogram) { |
| 4858 | UMA_HISTOGRAM_ENUMERATION( |
| 4859 | FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"), |
| 4860 | abandoned_page ? 1 : 0, 2); |
| 4861 | UMA_HISTOGRAM_ENUMERATION( |
| 4862 | FieldTrial::MakeName("PLT.LoadType", "DnsImpact"), |
| 4863 | load_type, NavigationState::kLoadTypeMax); |
| 4864 | switch (load_type) { |
| 4865 | case NavigationState::NORMAL_LOAD: |
| 4866 | PLT_HISTOGRAM(FieldTrial::MakeName( |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4867 | "PLT.BeginToFinish_NormalLoad", "DnsImpact"), |
| 4868 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4869 | break; |
| 4870 | case NavigationState::LINK_LOAD_NORMAL: |
| 4871 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4872 | "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4873 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4874 | break; |
| 4875 | case NavigationState::LINK_LOAD_RELOAD: |
| 4876 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4877 | "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4878 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4879 | break; |
| 4880 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4881 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4882 | "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4883 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4884 | break; |
| 4885 | default: |
| 4886 | break; |
| 4887 | } |
| 4888 | } |
| 4889 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 4890 | // Histograms to determine if content prefetching has an impact on PLT. |
| 4891 | static const bool prefetching_fieldtrial = |
| 4892 | FieldTrialList::Find("Prefetch") && |
| 4893 | !FieldTrialList::Find("Prefetch")->group_name().empty(); |
[email protected] | 13ae2df9 | 2010-08-19 20:05:10 | [diff] [blame] | 4894 | if (prefetching_fieldtrial) { |
| 4895 | if (navigation_state->was_prefetcher()) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 4896 | PLT_HISTOGRAM( |
| 4897 | FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcher", |
| 4898 | "Prefetch"), |
| 4899 | begin_to_finish_doc); |
| 4900 | PLT_HISTOGRAM( |
| 4901 | FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcher", |
| 4902 | "Prefetch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4903 | begin_to_finish_all_loads); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 4904 | } |
[email protected] | 13ae2df9 | 2010-08-19 20:05:10 | [diff] [blame] | 4905 | if (navigation_state->was_referred_by_prefetcher()) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 4906 | PLT_HISTOGRAM( |
| 4907 | FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcherReferrer", |
| 4908 | "Prefetch"), |
| 4909 | begin_to_finish_doc); |
| 4910 | PLT_HISTOGRAM( |
| 4911 | FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcherReferrer", |
| 4912 | "Prefetch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4913 | begin_to_finish_all_loads); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 4914 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 4915 | UMA_HISTOGRAM_ENUMERATION(FieldTrial::MakeName("PLT.Abandoned", "Prefetch"), |
| 4916 | abandoned_page ? 1 : 0, 2); |
| 4917 | PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinishDoc", "Prefetch"), |
| 4918 | begin_to_finish_doc); |
| 4919 | PLT_HISTOGRAM(FieldTrial::MakeName("PLT.BeginToFinish", "Prefetch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4920 | begin_to_finish_all_loads); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 4921 | } |
| 4922 | |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 4923 | // Histograms to determine if backup connection jobs have an impact on PLT. |
| 4924 | static const bool connect_backup_jobs_fieldtrial( |
| 4925 | FieldTrialList::Find("ConnnectBackupJobs") && |
| 4926 | !FieldTrialList::Find("ConnnectBackupJobs")->group_name().empty()); |
| 4927 | if (connect_backup_jobs_fieldtrial) { |
| 4928 | UMA_HISTOGRAM_ENUMERATION( |
| 4929 | FieldTrial::MakeName("PLT.Abandoned", "ConnnectBackupJobs"), |
| 4930 | abandoned_page ? 1 : 0, 2); |
| 4931 | UMA_HISTOGRAM_ENUMERATION( |
| 4932 | FieldTrial::MakeName("PLT.LoadType", "ConnnectBackupJobs"), |
| 4933 | load_type, NavigationState::kLoadTypeMax); |
| 4934 | switch (load_type) { |
| 4935 | case NavigationState::NORMAL_LOAD: |
| 4936 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4937 | "PLT.BeginToFinish_NormalLoad", "ConnnectBackupJobs"), |
| 4938 | begin_to_finish_all_loads); |
| 4939 | break; |
| 4940 | case NavigationState::LINK_LOAD_NORMAL: |
| 4941 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4942 | "PLT.BeginToFinish_LinkLoadNormal", "ConnnectBackupJobs"), |
| 4943 | begin_to_finish_all_loads); |
| 4944 | break; |
| 4945 | case NavigationState::LINK_LOAD_RELOAD: |
| 4946 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4947 | "PLT.BeginToFinish_LinkLoadReload", "ConnnectBackupJobs"), |
| 4948 | begin_to_finish_all_loads); |
| 4949 | break; |
| 4950 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4951 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4952 | "PLT.BeginToFinish_LinkLoadStaleOk", "ConnnectBackupJobs"), |
| 4953 | begin_to_finish_all_loads); |
| 4954 | break; |
| 4955 | default: |
| 4956 | break; |
| 4957 | } |
| 4958 | } |
| 4959 | |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4960 | // Histograms to determine if the number of connections has an |
| 4961 | // impact on PLT. |
| 4962 | // TODO(jar): Consider removing the per-link-type versions. We |
| 4963 | // really only need LINK_LOAD_NORMAL and NORMAL_LOAD. |
[email protected] | 9754649 | 2010-08-09 05:14:49 | [diff] [blame] | 4964 | static bool use_connection_impact_histogram( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4965 | FieldTrialList::Find("ConnCountImpact") && |
| 4966 | !FieldTrialList::Find("ConnCountImpact")->group_name().empty()); |
[email protected] | 9754649 | 2010-08-09 05:14:49 | [diff] [blame] | 4967 | if (use_connection_impact_histogram) { |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4968 | UMA_HISTOGRAM_ENUMERATION( |
| 4969 | FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"), |
| 4970 | abandoned_page ? 1 : 0, 2); |
| 4971 | switch (load_type) { |
| 4972 | case NavigationState::NORMAL_LOAD: |
| 4973 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4974 | "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4975 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4976 | break; |
| 4977 | case NavigationState::LINK_LOAD_NORMAL: |
| 4978 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4979 | "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4980 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4981 | break; |
| 4982 | case NavigationState::LINK_LOAD_RELOAD: |
| 4983 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4984 | "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4985 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4986 | break; |
| 4987 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4988 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 4989 | "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4990 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4991 | break; |
| 4992 | default: |
| 4993 | break; |
| 4994 | } |
| 4995 | } |
| 4996 | |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 4997 | // Histograms to determine effect of idle socket timeout. |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 4998 | static bool use_idle_socket_timeout_histogram( |
| 4999 | FieldTrialList::Find("IdleSktToImpact") && |
| 5000 | !FieldTrialList::Find("IdleSktToImpact")->group_name().empty()); |
| 5001 | if (use_idle_socket_timeout_histogram) { |
| 5002 | UMA_HISTOGRAM_ENUMERATION( |
| 5003 | FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"), |
| 5004 | abandoned_page ? 1 : 0, 2); |
| 5005 | switch (load_type) { |
| 5006 | case NavigationState::NORMAL_LOAD: |
| 5007 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5008 | "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5009 | begin_to_finish_all_loads); |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5010 | break; |
| 5011 | case NavigationState::LINK_LOAD_NORMAL: |
| 5012 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5013 | "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5014 | begin_to_finish_all_loads); |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5015 | break; |
| 5016 | case NavigationState::LINK_LOAD_RELOAD: |
| 5017 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5018 | "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5019 | begin_to_finish_all_loads); |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5020 | break; |
| 5021 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5022 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5023 | "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5024 | begin_to_finish_all_loads); |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5025 | break; |
| 5026 | default: |
| 5027 | break; |
| 5028 | } |
| 5029 | } |
| 5030 | |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5031 | // Histograms to determine effect of number of connections per proxy. |
| 5032 | static bool use_proxy_connection_impact_histogram( |
| 5033 | FieldTrialList::Find("ProxyConnectionImpact") && |
| 5034 | !FieldTrialList::Find("ProxyConnectionImpact")->group_name().empty()); |
| 5035 | if (use_proxy_connection_impact_histogram) { |
| 5036 | UMA_HISTOGRAM_ENUMERATION( |
| 5037 | FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"), |
| 5038 | abandoned_page ? 1 : 0, 2); |
| 5039 | switch (load_type) { |
| 5040 | case NavigationState::NORMAL_LOAD: |
| 5041 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5042 | "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5043 | begin_to_finish_all_loads); |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5044 | break; |
| 5045 | case NavigationState::LINK_LOAD_NORMAL: |
| 5046 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5047 | "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5048 | begin_to_finish_all_loads); |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5049 | break; |
| 5050 | case NavigationState::LINK_LOAD_RELOAD: |
| 5051 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5052 | "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5053 | begin_to_finish_all_loads); |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5054 | break; |
| 5055 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5056 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5057 | "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5058 | begin_to_finish_all_loads); |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5059 | break; |
| 5060 | default: |
| 5061 | break; |
| 5062 | } |
| 5063 | } |
| 5064 | |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5065 | // Histograms to determine if SDCH has an impact. |
| 5066 | // TODO(jar): Consider removing per-link load types and the enumeration. |
| 5067 | static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") && |
| 5068 | !FieldTrialList::Find("GlobalSdch")->group_name().empty()); |
| 5069 | if (use_sdch_histogram) { |
| 5070 | UMA_HISTOGRAM_ENUMERATION( |
| 5071 | FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"), |
| 5072 | load_type, NavigationState::kLoadTypeMax); |
| 5073 | switch (load_type) { |
| 5074 | case NavigationState::NORMAL_LOAD: |
| 5075 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5076 | "PLT.BeginToFinish_NormalLoad", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5077 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5078 | break; |
| 5079 | case NavigationState::LINK_LOAD_NORMAL: |
| 5080 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5081 | "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5082 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5083 | break; |
| 5084 | case NavigationState::LINK_LOAD_RELOAD: |
| 5085 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5086 | "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5087 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5088 | break; |
| 5089 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5090 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5091 | "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5092 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5093 | break; |
| 5094 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 5095 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5096 | "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5097 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5098 | break; |
| 5099 | default: |
| 5100 | break; |
| 5101 | } |
| 5102 | } |
| 5103 | |
| 5104 | // Histograms to determine if cache size has an impact on PLT. |
| 5105 | static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") && |
| 5106 | !FieldTrialList::Find("CacheSize")->group_name().empty()); |
| 5107 | if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type && |
| 5108 | NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) { |
| 5109 | // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like |
| 5110 | // StartToFinish or BeginToFinish would be better. |
| 5111 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5112 | "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc); |
| 5113 | } |
| 5114 | |
[email protected] | 115f554 | 2010-07-28 06:48:21 | [diff] [blame] | 5115 | |
[email protected] | 115f554 | 2010-07-28 06:48:21 | [diff] [blame] | 5116 | // Histograms to determine if SPDY has an impact for https traffic. |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5117 | // TODO(mbelshe): After we've seen the difference between BeginToFinish |
| 5118 | // and StartToFinish, consider removing one or the other. |
| 5119 | static bool use_spdy_histogram(FieldTrialList::Find("SpdyImpact") && |
| 5120 | !FieldTrialList::Find("SpdyImpact")->group_name().empty()); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5121 | if (use_spdy_histogram && |
| 5122 | scheme_type == URLPattern::SCHEME_HTTPS && |
[email protected] | 115f554 | 2010-07-28 06:48:21 | [diff] [blame] | 5123 | navigation_state->was_npn_negotiated()) { |
[email protected] | 30b3588 | 2010-06-14 21:21:01 | [diff] [blame] | 5124 | UMA_HISTOGRAM_ENUMERATION( |
| 5125 | FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"), |
| 5126 | abandoned_page ? 1 : 0, 2); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5127 | switch (load_type) { |
| 5128 | case NavigationState::LINK_LOAD_NORMAL: |
| 5129 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5130 | "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5131 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5132 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5133 | "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5134 | start_to_finish_all_loads); |
[email protected] | ef1d8d32 | 2010-06-13 18:31:25 | [diff] [blame] | 5135 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5136 | "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5137 | start_to_commit); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5138 | break; |
| 5139 | case NavigationState::NORMAL_LOAD: |
| 5140 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5141 | "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5142 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5143 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5144 | "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5145 | start_to_finish_all_loads); |
[email protected] | ef1d8d32 | 2010-06-13 18:31:25 | [diff] [blame] | 5146 | PLT_HISTOGRAM(FieldTrial::MakeName( |
| 5147 | "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5148 | start_to_commit); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5149 | break; |
| 5150 | default: |
| 5151 | break; |
| 5152 | } |
| 5153 | } |
| 5154 | |
[email protected] | 115f554 | 2010-07-28 06:48:21 | [diff] [blame] | 5155 | // Histograms to compare the impact of alternate protocol over http traffic: |
| 5156 | // when spdy is used vs. when http is used. |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5157 | if (scheme_type == URLPattern::SCHEME_HTTP && |
[email protected] | 115f554 | 2010-07-28 06:48:21 | [diff] [blame] | 5158 | navigation_state->was_alternate_protocol_available()) { |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 5159 | if (!navigation_state->was_npn_negotiated()) { |
| 5160 | // This means that even there is alternate protocols for npn_http or |
| 5161 | // npn_spdy, they are not taken (due to the fieldtrial). |
| 5162 | switch (load_type) { |
| 5163 | case NavigationState::LINK_LOAD_NORMAL: |
| 5164 | PLT_HISTOGRAM( |
| 5165 | "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5166 | start_to_finish_all_loads); |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 5167 | PLT_HISTOGRAM( |
| 5168 | "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http", |
| 5169 | start_to_commit); |
| 5170 | break; |
| 5171 | case NavigationState::NORMAL_LOAD: |
| 5172 | PLT_HISTOGRAM( |
| 5173 | "PLT.StartToFinish_NormalLoad_AlternateProtocol_http", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5174 | start_to_finish_all_loads); |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 5175 | PLT_HISTOGRAM( |
| 5176 | "PLT.StartToCommit_NormalLoad_AlternateProtocol_http", |
| 5177 | start_to_commit); |
| 5178 | break; |
| 5179 | default: |
| 5180 | break; |
| 5181 | } |
| 5182 | } else if (navigation_state->was_fetched_via_spdy()) { |
| 5183 | switch (load_type) { |
| 5184 | case NavigationState::LINK_LOAD_NORMAL: |
| 5185 | PLT_HISTOGRAM( |
| 5186 | "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5187 | start_to_finish_all_loads); |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 5188 | PLT_HISTOGRAM( |
| 5189 | "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy", |
| 5190 | start_to_commit); |
| 5191 | break; |
| 5192 | case NavigationState::NORMAL_LOAD: |
| 5193 | PLT_HISTOGRAM( |
| 5194 | "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5195 | start_to_finish_all_loads); |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 5196 | PLT_HISTOGRAM( |
| 5197 | "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy", |
| 5198 | start_to_commit); |
| 5199 | break; |
| 5200 | default: |
| 5201 | break; |
| 5202 | } |
| 5203 | } |
| 5204 | } |
| 5205 | |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5206 | // Record page load time and abandonment rates for proxy cases. |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5207 | if (navigation_state->was_fetched_via_proxy()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5208 | if (scheme_type == URLPattern::SCHEME_HTTPS) { |
| 5209 | PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5210 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5211 | abandoned_page ? 1 : 0, 2); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5212 | } else { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5213 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP); |
| 5214 | PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5215 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5216 | abandoned_page ? 1 : 0, 2); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5217 | } |
| 5218 | } else { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5219 | if (scheme_type == URLPattern::SCHEME_HTTPS) { |
| 5220 | PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https", |
| 5221 | start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5222 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5223 | abandoned_page ? 1 : 0, 2); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5224 | } else { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5225 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP); |
| 5226 | PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http", |
| 5227 | start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5228 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5229 | abandoned_page ? 1 : 0, 2); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5230 | } |
| 5231 | } |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 5232 | |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 5233 | // Site isolation metrics. |
| 5234 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess", |
| 5235 | cross_origin_access_count_); |
| 5236 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess", |
| 5237 | same_origin_access_count_); |
| 5238 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5239 | // TODO(jar): This is the ONLY call in this method that needed more than |
| 5240 | // navigation_state. This should be relocated, or changed, so that this |
| 5241 | // body can be made a method on NavigationStates, and run via its destructor. |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5242 | // Log some PLT data to the error log. |
| 5243 | LogNavigationState(navigation_state, main_frame->dataSource()); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 5244 | |
| 5245 | navigation_state->set_load_histograms_recorded(true); |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 5246 | |
| 5247 | // Since there are currently no guarantees that renderer histograms will be |
| 5248 | // sent to the browser, we initiate a PostTask here to be sure that we send |
| 5249 | // the histograms we generated. Without this call, pages that don't have an |
| 5250 | // on-close-handler might generate data that is lost when the renderer is |
| 5251 | // shutdown abruptly (perchance because the user closed the tab). |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 5252 | // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it |
| 5253 | // should post when the onload is complete, so that it doesn't interfere with |
| 5254 | // the next load. |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 5255 | if (RenderThread::current()) { |
| 5256 | RenderThread::current()->SendHistograms( |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 5257 | chrome::kHistogramSynchronizerReservedSequenceNumber); |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 5258 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 5259 | } |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 5260 | |
[email protected] | f899964 | 2009-10-27 21:39:42 | [diff] [blame] | 5261 | void RenderView::LogNavigationState(const NavigationState* state, |
| 5262 | const WebDataSource* ds) const { |
| 5263 | // Because this function gets called on every page load, |
| 5264 | // take extra care to optimize it away if logging is turned off. |
| 5265 | if (logging::LOG_INFO < logging::GetMinLogLevel()) |
| 5266 | return; |
| 5267 | |
| 5268 | DCHECK(state); |
| 5269 | DCHECK(ds); |
| 5270 | GURL url(ds->request().url()); |
| 5271 | Time start = state->start_load_time(); |
| 5272 | Time finish = state->finish_load_time(); |
| 5273 | // TODO(mbelshe): should we log more stats? |
| 5274 | LOG(INFO) << "PLT: " |
| 5275 | << (finish - start).InMilliseconds() |
| 5276 | << "ms " |
| 5277 | << url.spec(); |
| 5278 | } |
| 5279 | |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 5280 | void RenderView::focusAccessibilityObject( |
| 5281 | const WebAccessibilityObject& acc_obj) { |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 5282 | #if defined(OS_WIN) |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 5283 | // TODO(dglazkov): Current logic implies that focus change can only be made |
| 5284 | // after at least one call to RenderView::OnGetAccessibilityInfo, which is |
| 5285 | // where accessibility is initialized. We should determine whether that's |
| 5286 | // right. |
| 5287 | if (!accessibility_.get()) |
| 5288 | return; |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 5289 | |
| 5290 | // Retrieve the accessibility object id of the AccessibilityObject. |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 5291 | int acc_obj_id = accessibility_->addOrGetId(acc_obj); |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 5292 | |
| 5293 | // If id is valid, alert the browser side that an accessibility focus change |
| 5294 | // occurred. |
| 5295 | if (acc_obj_id >= 0) |
| 5296 | Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id)); |
| 5297 | |
| 5298 | #else // defined(OS_WIN) |
| 5299 | // TODO(port): accessibility not yet implemented |
| 5300 | NOTIMPLEMENTED(); |
| 5301 | #endif |
| 5302 | } |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 5303 | |
[email protected] | a3018be | 2010-03-09 04:28:48 | [diff] [blame] | 5304 | void RenderView::didChangeAccessibilityObjectState( |
| 5305 | const WebKit::WebAccessibilityObject& acc_obj) { |
| 5306 | #if defined(OS_WIN) |
| 5307 | // TODO(dglazkov): Current logic implies that a state change can only be made |
| 5308 | // after at least one call to RenderView::OnGetAccessibilityInfo, which is |
| 5309 | // where accessibility is initialized. We should determine whether that's |
| 5310 | // right. |
| 5311 | if (!accessibility_.get()) |
| 5312 | return; |
| 5313 | |
| 5314 | // Retrieve the accessibility object id of the AccessibilityObject. |
| 5315 | int acc_obj_id = accessibility_->addOrGetId(acc_obj); |
| 5316 | |
| 5317 | // If id is valid, alert the browser side that an accessibility object state |
| 5318 | // change occurred. |
| 5319 | if (acc_obj_id >= 0) |
| 5320 | Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_, |
| 5321 | acc_obj_id)); |
| 5322 | |
| 5323 | #else // defined(OS_WIN) |
| 5324 | // TODO(port): accessibility not yet implemented |
| 5325 | NOTIMPLEMENTED(); |
| 5326 | #endif |
| 5327 | } |
| 5328 | |
[email protected] | 0fda727 | 2009-06-26 15:49:33 | [diff] [blame] | 5329 | void RenderView::Print(WebFrame* frame, bool script_initiated) { |
| 5330 | DCHECK(frame); |
| 5331 | if (print_helper_.get() == NULL) { |
| 5332 | print_helper_.reset(new PrintWebViewHelper(this)); |
| 5333 | } |
| 5334 | print_helper_->Print(frame, script_initiated); |
| 5335 | } |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5336 | |
| 5337 | void RenderView::OnSetEditCommandsForNextKeyEvent( |
| 5338 | const EditCommands& edit_commands) { |
| 5339 | edit_commands_ = edit_commands; |
| 5340 | } |
| 5341 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5342 | void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5343 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5344 | if (!main_frame) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5345 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, |
| 5346 | false)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5347 | return; |
| 5348 | } |
| 5349 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5350 | WebDataSource* ds = main_frame->dataSource(); |
| 5351 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 5352 | if (!navigation_state->user_script_idle_scheduler()->has_run()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5353 | pending_code_execution_queue_.push( |
| 5354 | linked_ptr<ViewMsg_ExecuteCode_Params>( |
| 5355 | new ViewMsg_ExecuteCode_Params(params))); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5356 | return; |
| 5357 | } |
| 5358 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5359 | ExecuteCodeImpl(main_frame, params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | void RenderView::ExecuteCodeImpl(WebFrame* frame, |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5363 | const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | d146b83 | 2009-12-23 02:45:48 | [diff] [blame] | 5364 | // Don't execute scripts in gallery pages. |
| 5365 | GURL frame_url = GURL(frame->url()); |
[email protected] | 638d45d | 2010-07-09 17:35:08 | [diff] [blame] | 5366 | if (frame_url.host() == GURL(Extension::ChromeStoreURL()).host() |
| 5367 | && !CommandLine::ForCurrentProcess()->HasSwitch( |
| 5368 | switches::kAllowScriptingGallery)) { |
[email protected] | d146b83 | 2009-12-23 02:45:48 | [diff] [blame] | 5369 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); |
| 5370 | return; |
| 5371 | } |
| 5372 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5373 | std::vector<WebFrame*> frame_vector; |
| 5374 | frame_vector.push_back(frame); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5375 | if (params.all_frames) |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5376 | GetAllChildFrames(frame, &frame_vector); |
| 5377 | |
| 5378 | for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin(); |
| 5379 | frame_it != frame_vector.end(); ++frame_it) { |
| 5380 | WebFrame* frame = *frame_it; |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5381 | if (params.is_javascript) { |
| 5382 | if (!UrlMatchesPermissions(frame->url(), params.host_permissions)) |
| 5383 | continue; |
| 5384 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5385 | std::vector<WebScriptSource> sources; |
| 5386 | sources.push_back( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5387 | WebScriptSource(WebString::fromUTF8(params.code))); |
| 5388 | UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5389 | frame->executeScriptInIsolatedWorld( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5390 | UserScriptSlave::GetIsolatedWorldId(params.extension_id), |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5391 | &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 5392 | } else { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5393 | frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5394 | } |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5395 | } |
| 5396 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5397 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5398 | } |
| 5399 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5400 | void RenderView::Close() { |
| 5401 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5402 | WebView* doomed = webview(); |
| 5403 | RenderWidget::Close(); |
| 5404 | Singleton<ViewMap>::get()->erase(doomed); |
| 5405 | } |
| 5406 | |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5407 | void RenderView::DidHandleKeyEvent() { |
| 5408 | edit_commands_.clear(); |
| 5409 | } |
| 5410 | |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5411 | #if defined(OS_MACOSX) |
| 5412 | void RenderView::OnWasHidden() { |
| 5413 | RenderWidget::OnWasHidden(); |
| 5414 | |
| 5415 | // Inform plugins that their container is no longer visible. |
| 5416 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5417 | for (plugin_it = plugin_delegates_.begin(); |
| 5418 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5419 | (*plugin_it)->SetContainerVisibility(false); |
| 5420 | } |
| 5421 | } |
| 5422 | |
| 5423 | void RenderView::OnWasRestored(bool needs_repainting) { |
| 5424 | RenderWidget::OnWasRestored(needs_repainting); |
| 5425 | |
| 5426 | // Inform plugins that their container is now visible. |
| 5427 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5428 | for (plugin_it = plugin_delegates_.begin(); |
| 5429 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5430 | (*plugin_it)->SetContainerVisibility(true); |
| 5431 | } |
| 5432 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5433 | |
| 5434 | void RenderView::OnSetFocus(bool enable) { |
| 5435 | RenderWidget::OnSetFocus(enable); |
| 5436 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5437 | if (webview() && webview()->isActive()) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5438 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5439 | for (plugin_it = plugin_delegates_.begin(); |
| 5440 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5441 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5442 | // activation state to change just like a call to setIsActive. |
| 5443 | if (enable) |
| 5444 | (*plugin_it)->SetWindowFocus(true); |
| 5445 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5446 | } |
| 5447 | } |
| 5448 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5449 | #endif // OS_MACOSX |
| 5450 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 5451 | void RenderView::EnsureDocumentTag() { |
| 5452 | // TODO(darin): There's actually no reason for this to be here. We should |
| 5453 | // have the browser side manage the document tag. |
| 5454 | #if defined(OS_MACOSX) |
| 5455 | if (!has_document_tag_) { |
| 5456 | // Make the call to get the tag. |
| 5457 | Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); |
| 5458 | has_document_tag_ = true; |
| 5459 | } |
| 5460 | #endif |
| 5461 | } |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 5462 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5463 | #if defined(OS_MACOSX) |
[email protected] | ea04a4e1 | 2010-04-15 00:58:03 | [diff] [blame] | 5464 | gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5465 | bool opaque, bool root) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5466 | gfx::PluginWindowHandle window = NULL; |
| 5467 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5468 | routing_id(), opaque, root, &window)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5469 | return window; |
| 5470 | } |
| 5471 | |
| 5472 | void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) { |
| 5473 | if (window) |
| 5474 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
| 5475 | } |
| 5476 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5477 | void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window, |
| 5478 | int32 width, |
| 5479 | int32 height, |
| 5480 | uint64 io_surface_identifier) { |
| 5481 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5482 | routing_id(), window, width, height, io_surface_identifier)); |
| 5483 | } |
| 5484 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5485 | void RenderView::AcceleratedSurfaceSetTransportDIB( |
| 5486 | gfx::PluginWindowHandle window, |
| 5487 | int32 width, |
| 5488 | int32 height, |
| 5489 | TransportDIB::Handle transport_dib) { |
| 5490 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5491 | routing_id(), window, width, height, transport_dib)); |
| 5492 | } |
| 5493 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5494 | TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB( |
| 5495 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5496 | TransportDIB::Handle dib_handle; |
| 5497 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 5498 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5499 | return dib_handle; |
| 5500 | // Return an invalid handle if Send() fails. |
| 5501 | return TransportDIB::DefaultHandleValue(); |
| 5502 | } |
| 5503 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5504 | void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5505 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 5506 | } |
| 5507 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5508 | void RenderView::AcceleratedSurfaceBuffersSwapped( |
| 5509 | gfx::PluginWindowHandle window) { |
| 5510 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5511 | } |
| 5512 | #endif |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5513 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5514 | bool RenderView::ScheduleFileChooser( |
| 5515 | const ViewHostMsg_RunFileChooser_Params& params, |
| 5516 | WebFileChooserCompletion* completion) { |
| 5517 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 5518 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 5519 | // This sanity check prevents too many file choose requests from getting |
| 5520 | // queued which could DoS the user. Getting these is most likely a |
| 5521 | // programming error (there are many ways to DoS the user so it's not |
| 5522 | // considered a "real" security check), either in JS requesting many file |
| 5523 | // choosers to pop up, or in a plugin. |
| 5524 | // |
| 5525 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 5526 | // a file picker, which will address this issue in a better way. |
| 5527 | return false; |
| 5528 | } |
| 5529 | |
| 5530 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 5531 | new PendingFileChooser(params, completion))); |
| 5532 | if (file_chooser_completions_.size() == 1) { |
| 5533 | // Actually show the browse dialog when this is the first request. |
| 5534 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 5535 | } |
| 5536 | return true; |
| 5537 | } |
| 5538 | |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 5539 | void RenderView::OnPageTranslated() { |
| 5540 | WebFrame* frame = webview()->mainFrame(); |
| 5541 | if (!frame) |
| 5542 | return; |
| 5543 | |
| 5544 | // The page is translated, so try to extract the form data again. |
[email protected] | 679f128f | 2010-07-22 22:57:44 | [diff] [blame] | 5545 | autofill_helper_.FrameContentsAvailable(frame); |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 5546 | } |
| 5547 | |
[email protected] | 8a5f700 | 2010-03-31 13:47:35 | [diff] [blame] | 5548 | WebKit::WebGeolocationService* RenderView::geolocationService() { |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5549 | if (!geolocation_dispatcher_.get()) |
| 5550 | geolocation_dispatcher_.reset(new GeolocationDispatcher(this)); |
| 5551 | return geolocation_dispatcher_.get(); |
| 5552 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5553 | |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 5554 | WebKit::WebSpeechInputController* RenderView::speechInputController( |
| 5555 | WebKit::WebSpeechInputListener* listener) { |
| 5556 | if (!speech_input_dispatcher_.get()) |
| 5557 | speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener)); |
| 5558 | return speech_input_dispatcher_.get(); |
| 5559 | } |
| 5560 | |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 5561 | WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() { |
| 5562 | if (!device_orientation_dispatcher_.get()) |
| 5563 | device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this)); |
| 5564 | return device_orientation_dispatcher_.get(); |
| 5565 | } |
| 5566 | |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 5567 | bool RenderView::IsNonLocalTopLevelNavigation( |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5568 | const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 5569 | // Must be a top level frame. |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5570 | if (frame->parent() != NULL) |
| 5571 | return false; |
| 5572 | |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 5573 | // Navigations initiated within Webkit are not sent out to the external host |
| 5574 | // in the following cases. |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 5575 | // 1. The url scheme is not http/https |
| 5576 | // 2. There is no opener and this is not the first url being opened by this |
| 5577 | // RenderView. |
| 5578 | // 3. The origin of the url and the opener is the same in which case the |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 5579 | // opener relationship is maintained. |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 5580 | // 4. Reloads/form submits/back forward navigations |
| 5581 | if (!url.SchemeIs("http") && !url.SchemeIs("https")) |
| 5582 | return false; |
| 5583 | |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5584 | // Not interested in reloads. |
| 5585 | if (type != WebKit::WebNavigationTypeReload && |
[email protected] | 070c49c | 2010-07-13 22:22:01 | [diff] [blame] | 5586 | type != WebKit::WebNavigationTypeFormSubmitted && |
| 5587 | type != WebKit::WebNavigationTypeBackForward) { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5588 | // The opener relationship between the new window and the parent allows the |
| 5589 | // new window to script the parent and vice versa. This is not allowed if |
| 5590 | // the origins of the two domains are different. This can be treated as a |
| 5591 | // top level navigation and routed back to the host. |
| 5592 | WebKit::WebFrame* opener = frame->opener(); |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 5593 | if (!opener) { |
| 5594 | // If this is the first page being loaded by this RenderView instance then |
| 5595 | // it should stay here. |
| 5596 | if (page_id_ == -1) { |
| 5597 | return false; |
| 5598 | } else { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5599 | return true; |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 5600 | } |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5601 | } |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 5602 | |
| 5603 | if (url.GetOrigin() != GURL(opener->url()).GetOrigin()) |
| 5604 | return true; |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5605 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5606 | return false; |
| 5607 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 5608 | |
| 5609 | void RenderView::OnOpenFileSystemRequestComplete( |
| 5610 | int request_id, bool accepted, const string16& name, |
| 5611 | const string16& root_path) { |
| 5612 | PendingOpenFileSystem* request = pending_file_system_requests_.Lookup( |
| 5613 | request_id); |
| 5614 | DCHECK(request); |
| 5615 | if (accepted) |
| 5616 | request->callbacks->didOpenFileSystem(name, root_path); |
| 5617 | else |
| 5618 | request->callbacks->didFail(WebKit::WebFileErrorSecurity); |
| 5619 | request->callbacks = NULL; |
| 5620 | pending_file_system_requests_.Remove(request_id); |
| 5621 | } |