[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> |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 8 | #include <cmath> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 12 | #include "app/l10n_util.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 13 | #include "app/message_box_flags.h" |
[email protected] | 9929da9 | 2009-05-05 02:05:11 | [diff] [blame] | 14 | #include "app/resource_bundle.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 15 | #include "base/callback.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 18 | #include "base/metrics/field_trial.h" |
| 19 | #include "base/metrics/histogram.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 20 | #include "base/path_service.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 21 | #include "base/process_util.h" |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 22 | #include "base/singleton.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 23 | #include "base/string_piece.h" |
| 24 | #include "base/string_util.h" |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 25 | #include "base/sys_string_conversions.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 26 | #include "base/time.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 27 | #include "base/utf_string_conversions.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 28 | #include "build/build_config.h" |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 29 | #include "chrome/common/appcache/appcache_dispatcher.h" |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 30 | #include "chrome/common/bindings_policy.h" |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 31 | #include "chrome/common/child_process_logging.h" |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 32 | #include "chrome/common/chrome_constants.h" |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 33 | #include "chrome/common/chrome_paths.h" |
| 34 | #include "chrome/common/chrome_switches.h" |
[email protected] | a0cf04a | 2010-06-23 03:29:55 | [diff] [blame] | 35 | #include "chrome/common/extensions/extension.h" |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 36 | #include "chrome/common/file_system/file_system_dispatcher.h" |
| 37 | #include "chrome/common/file_system/webfilesystem_callback_dispatcher.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 38 | #include "chrome/common/jstemplate_builder.h" |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 39 | #include "chrome/common/notification_service.h" |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 40 | #include "chrome/common/page_zoom.h" |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 41 | #include "chrome/common/pepper_plugin_registry.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 42 | #include "chrome/common/render_messages.h" |
[email protected] | 939856a | 2010-08-24 20:29:02 | [diff] [blame] | 43 | #include "chrome/common/render_messages_params.h" |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 44 | #include "chrome/common/renderer_preferences.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 45 | #include "chrome/common/thumbnail_score.h" |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 46 | #include "chrome/common/url_constants.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 47 | #include "chrome/common/window_container_type.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 48 | #include "chrome/renderer/about_handler.h" |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 49 | #include "chrome/renderer/audio_message_filter.h" |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 50 | #include "chrome/renderer/autofill_helper.h" |
[email protected] | 2f97917 | 2010-09-16 21:54:03 | [diff] [blame] | 51 | #include "chrome/renderer/automation/dom_automation_controller.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 52 | #include "chrome/renderer/blocked_plugin.h" |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 53 | #include "chrome/renderer/device_orientation_dispatcher.h" |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 54 | #include "chrome/renderer/devtools_agent.h" |
| 55 | #include "chrome/renderer/devtools_client.h" |
[email protected] | 2f97917 | 2010-09-16 21:54:03 | [diff] [blame] | 56 | #include "chrome/renderer/dom_ui_bindings.h" |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 57 | #include "chrome/renderer/extension_groups.h" |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 58 | #include "chrome/renderer/extensions/bindings_utils.h" |
[email protected] | f816c01 | 2009-06-26 21:48:32 | [diff] [blame] | 59 | #include "chrome/renderer/extensions/event_bindings.h" |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 60 | #include "chrome/renderer/extensions/extension_process_bindings.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 61 | #include "chrome/renderer/extensions/extension_renderer_info.h" |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 62 | #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
[email protected] | 2f97917 | 2010-09-16 21:54:03 | [diff] [blame] | 63 | #include "chrome/renderer/external_host_bindings.h" |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 64 | #include "chrome/renderer/geolocation_dispatcher.h" |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 65 | #include "chrome/renderer/ggl/ggl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 66 | #include "chrome/renderer/localized_error.h" |
[email protected] | 6f56d48 | 2009-02-20 05:02:56 | [diff] [blame] | 67 | #include "chrome/renderer/media/audio_renderer_impl.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 68 | #include "chrome/renderer/media/ipc_video_decoder.h" |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 69 | #include "chrome/renderer/media/ipc_video_renderer.h" |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 70 | #include "chrome/renderer/navigation_state.h" |
[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 71 | #include "chrome/renderer/notification_provider.h" |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 72 | #include "chrome/renderer/page_click_tracker.h" |
| 73 | #include "chrome/renderer/password_autocomplete_manager.h" |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 74 | #include "chrome/renderer/plugin_channel_host.h" |
[email protected] | d81c1e5 | 2009-06-03 22:09:50 | [diff] [blame] | 75 | #include "chrome/renderer/print_web_view_helper.h" |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 76 | #include "chrome/renderer/render_process.h" |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 77 | #include "chrome/renderer/render_thread.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 78 | #include "chrome/renderer/render_view_visitor.h" |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 79 | #include "chrome/renderer/render_widget_fullscreen.h" |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 80 | #include "chrome/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 81 | #include "chrome/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 82 | #include "chrome/renderer/renderer_webstoragenamespace_impl.h" |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 83 | #include "chrome/renderer/speech_input_dispatcher.h" |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 84 | #include "chrome/renderer/spellchecker/spellcheck.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 85 | #include "chrome/renderer/user_script_slave.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 86 | #include "chrome/renderer/visitedlink_slave.h" |
[email protected] | d439ba07 | 2009-10-17 22:32:29 | [diff] [blame] | 87 | #include "chrome/renderer/webplugin_delegate_pepper.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 88 | #include "chrome/renderer/webplugin_delegate_proxy.h" |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 89 | #include "chrome/renderer/websharedworker_proxy.h" |
[email protected] | eb47a13 | 2009-03-04 00:39:56 | [diff] [blame] | 90 | #include "chrome/renderer/webworker_proxy.h" |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 91 | #include "gfx/color_utils.h" |
| 92 | #include "gfx/favicon_size.h" |
[email protected] | 5c7293a | 2010-03-17 06:40:57 | [diff] [blame] | 93 | #include "gfx/native_widget_types.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 94 | #include "gfx/point.h" |
| 95 | #include "gfx/rect.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 96 | #include "grit/generated_resources.h" |
| 97 | #include "grit/renderer_resources.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 98 | #include "media/base/media_switches.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 99 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 100 | #include "net/base/escape.h" |
| 101 | #include "net/base/net_errors.h" |
[email protected] | c399a8a | 2008-11-22 19:38:00 | [diff] [blame] | 102 | #include "skia/ext/bitmap_platform_device.h" |
[email protected] | 83c9e655 | 2008-12-03 16:22:10 | [diff] [blame] | 103 | #include "skia/ext/image_operations.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 104 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 105 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 106 | #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 107 | #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
| 108 | #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 109 | #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 110 | #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 111 | #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 112 | #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" |
| 113 | #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 114 | #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 115 | #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 116 | #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
| 117 | #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 118 | #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 119 | #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 120 | #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 121 | #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 122 | #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 123 | #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 124 | #include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 125 | #include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 126 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 127 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 128 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 129 | #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
| 130 | #include "third_party/WebKit/WebKit/chromium/public/WebRange.h" |
| 131 | #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 132 | #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" |
| 133 | #include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h" |
| 134 | #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 135 | #include "third_party/WebKit/WebKit/chromium/public/WebSettings.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 136 | #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 137 | #include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 138 | #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 139 | #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 140 | #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" |
| 141 | #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 142 | #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
| 143 | #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 144 | #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 145 | #include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 146 | #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h" |
| 147 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 148 | #include "v8/include/v8.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 149 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 150 | #include "webkit/glue/context_menu.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | #include "webkit/glue/dom_operations.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 152 | #include "webkit/glue/form_data.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 153 | #include "webkit/glue/form_field.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 154 | #include "webkit/glue/glue_serialize.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 155 | #include "webkit/glue/image_decoder.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 156 | #include "webkit/glue/image_resource_fetcher.h" |
[email protected] | 8e296bbd | 2009-07-22 21:37:17 | [diff] [blame] | 157 | #include "webkit/glue/media/buffered_data_source.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 158 | #include "webkit/glue/media/simple_data_source.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 159 | #include "webkit/glue/media/video_renderer_impl.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 160 | #include "webkit/glue/password_form_dom_manager.h" |
[email protected] | 0d64bb7 | 2010-07-07 05:36:38 | [diff] [blame] | 161 | #include "webkit/glue/plugins/default_plugin_shared.h" |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 162 | #include "webkit/glue/plugins/pepper_webplugin_impl.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 163 | #include "webkit/glue/plugins/plugin_list.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 164 | #include "webkit/glue/plugins/webplugin_delegate.h" |
[email protected] | 8a3b796 | 2009-09-04 05:53:23 | [diff] [blame] | 165 | #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 166 | #include "webkit/glue/plugins/webplugin_impl.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 167 | #include "webkit/glue/plugins/webview_plugin.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 168 | #include "webkit/glue/site_isolation_metrics.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 169 | #include "webkit/glue/webaccessibility.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 170 | #include "webkit/glue/webdropdata.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 171 | #include "webkit/glue/webkit_glue.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 172 | #include "webkit/glue/webmediaplayer_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 173 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 174 | #if defined(OS_WIN) |
| 175 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 176 | // * theming |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 177 | #include "gfx/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 178 | #elif defined(USE_X11) |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 179 | #include "gfx/native_theme_linux.h" |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 180 | #include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 181 | #elif defined(OS_MACOSX) |
| 182 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 183 | #endif |
| 184 | |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 185 | using WebKit::WebAccessibilityCache; |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 186 | using WebKit::WebAccessibilityNotification; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 187 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 188 | using WebKit::WebApplicationCacheHost; |
| 189 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 190 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 191 | using WebKit::WebColor; |
| 192 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 193 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 194 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 195 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 196 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 197 | using WebKit::WebDataSource; |
[email protected] | 2661b33 | 2009-11-03 18:42:29 | [diff] [blame] | 198 | using WebKit::WebDevToolsAgent; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 199 | using WebKit::WebDocument; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 200 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 201 | using WebKit::WebDragOperation; |
| 202 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 203 | using WebKit::WebEditingAction; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 204 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 205 | using WebKit::WebFileSystem; |
| 206 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 207 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 208 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 209 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 210 | using WebKit::WebFrame; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 211 | using WebKit::WebHistoryItem; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 212 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 213 | using WebKit::WebInputElement; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 214 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 215 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 216 | using WebKit::WebMediaPlayerClient; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 217 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 218 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 219 | using WebKit::WebNode; |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 220 | using WebKit::WebPageSerializer; |
| 221 | using WebKit::WebPageSerializerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 222 | using WebKit::WebPlugin; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 223 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 224 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 225 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 226 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 227 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 228 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 229 | using WebKit::WebRect; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 230 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 231 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 232 | using WebKit::WebSecurityOrigin; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 233 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 234 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 235 | using WebKit::WebSize; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 236 | using WebKit::WebStorageNamespace; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 237 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 238 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 239 | using WebKit::WebTextDirection; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 240 | using WebKit::WebURL; |
| 241 | using WebKit::WebURLError; |
| 242 | using WebKit::WebURLRequest; |
| 243 | using WebKit::WebURLResponse; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 244 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 245 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 246 | using WebKit::WebWidget; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 247 | using WebKit::WebWindowFeatures; |
[email protected] | 27ba853 | 2009-04-24 20:22:43 | [diff] [blame] | 248 | using WebKit::WebWorker; |
| 249 | using WebKit::WebWorkerClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 250 | using appcache::WebApplicationCacheHostImpl; |
| 251 | using base::Time; |
| 252 | using base::TimeDelta; |
| 253 | using webkit_glue::AltErrorPageResourceFetcher; |
| 254 | using webkit_glue::FormData; |
| 255 | using webkit_glue::FormField; |
| 256 | using webkit_glue::ImageResourceFetcher; |
| 257 | using webkit_glue::PasswordForm; |
| 258 | using webkit_glue::PasswordFormDomManager; |
| 259 | using webkit_glue::SiteIsolationMetrics; |
| 260 | using webkit_glue::WebAccessibility; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 261 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 262 | //----------------------------------------------------------------------------- |
| 263 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 264 | typedef std::map<WebKit::WebView*, RenderView*> ViewMap; |
| 265 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 266 | // define to write the time necessary for thumbnail/DOM text retrieval, |
| 267 | // respectively, into the system debug log |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 268 | // #define TIME_TEXT_RETRIEVAL |
| 269 | |
| 270 | // maximum number of characters in the document to index, any text beyond this |
| 271 | // point will be clipped |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 272 | static const size_t kMaxIndexChars = 65535; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 273 | |
| 274 | // Size of the thumbnails that we'll generate |
[email protected] | 8b4f489 | 2009-09-04 21:52:37 | [diff] [blame] | 275 | static const int kThumbnailWidth = 212; |
| 276 | static const int kThumbnailHeight = 132; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 277 | |
| 278 | // Delay in milliseconds that we'll wait before capturing the page contents |
| 279 | // and thumbnail. |
| 280 | static const int kDelayForCaptureMs = 500; |
| 281 | |
| 282 | // Typically, we capture the page data once the page is loaded. |
| 283 | // Sometimes, the page never finishes to load, preventing the page capture |
| 284 | // To workaround this problem, we always perform a capture after the following |
| 285 | // delay. |
| 286 | static const int kDelayForForcedCaptureMs = 6000; |
| 287 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 288 | // Time, in seconds, we delay before sending content state changes (such as form |
| 289 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 290 | // spamming the browser. |
| 291 | // To avoid having tab/session restore require sending a message to get the |
| 292 | // current content state during tab closing we use a shorter timeout for the |
| 293 | // foreground renderer. This means there is a small window of time from which |
| 294 | // content state is modified and not sent to session restore, but this is |
| 295 | // better than having to wake up all renderers during shutdown. |
| 296 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 297 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 298 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 299 | // The maximum number of popups that can be spawned from one page. |
| 300 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 301 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 302 | static const char kUnreachableWebDataURL[] = "chrome://chromewebdata/"; |
| 303 | static const char kBackForwardNavigationScheme[] = "history"; |
[email protected] | 50b691c | 2008-10-31 19:08:35 | [diff] [blame] | 304 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 305 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 306 | WebVector<WebURL> urls; |
| 307 | ds->redirectChain(urls); |
| 308 | result->reserve(urls.size()); |
| 309 | for (size_t i = 0; i < urls.size(); ++i) |
| 310 | result->push_back(urls[i]); |
| 311 | } |
| 312 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 313 | static bool PaintViewIntoCanvas(WebView* view, |
| 314 | skia::PlatformCanvas& canvas) { |
| 315 | view->layout(); |
| 316 | const WebSize& size = view->size(); |
| 317 | |
| 318 | if (!canvas.initialize(size.width, size.height, true)) |
| 319 | return false; |
| 320 | |
| 321 | view->paint(webkit_glue::ToWebCanvas(&canvas), |
| 322 | WebRect(0, 0, size.width, size.height)); |
| 323 | // TODO: Add a way to snapshot the whole page, not just the currently |
| 324 | // visible part. |
| 325 | |
| 326 | return true; |
| 327 | } |
| 328 | |
| 329 | // Calculates how "boring" a thumbnail is. The boring score is the |
| 330 | // 0,1 ranged percentage of pixels that are the most common |
| 331 | // luma. Higher boring scores indicate that a higher percentage of a |
| 332 | // bitmap are all the same brightness. |
| 333 | static double CalculateBoringScore(SkBitmap* bitmap) { |
| 334 | int histogram[256] = {0}; |
| 335 | color_utils::BuildLumaHistogram(bitmap, histogram); |
| 336 | |
| 337 | int color_count = *std::max_element(histogram, histogram + 256); |
| 338 | int pixel_count = bitmap->width() * bitmap->height(); |
| 339 | return static_cast<double>(color_count) / pixel_count; |
| 340 | } |
| 341 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 342 | // True if |frame| contains content that is white-listed for content settings. |
| 343 | static bool IsWhitelistedForContentSettings(WebFrame* frame) { |
| 344 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 345 | if (origin.isEmpty()) |
| 346 | return false; // Uninitialized document? |
| 347 | |
| 348 | if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
| 349 | return true; // Browser UI elements should still work. |
| 350 | |
| 351 | // If the scheme is ftp: or file:, an empty file name indicates a directory |
| 352 | // listing, which requires JavaScript to function properly. |
| 353 | GURL frame_url = frame->url(); |
| 354 | const char* kDirProtocols[] = { "ftp", "file" }; |
| 355 | for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { |
| 356 | if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { |
| 357 | return frame_url.SchemeIs(kDirProtocols[i]) && |
| 358 | frame_url.ExtractFileName().empty(); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | return false; |
| 363 | } |
| 364 | |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 365 | // Returns true if the frame is navigating to an URL either into or out of an |
| 366 | // extension app's extent. |
| 367 | static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) { |
| 368 | if (!RenderThread::current()) |
| 369 | return false; |
| 370 | |
| 371 | // If the URL is still empty, this is a window.open navigation. Check the |
| 372 | // opener's URL. |
| 373 | GURL old_url(frame->url()); |
| 374 | if (old_url.is_empty() && frame->opener()) |
| 375 | old_url = frame->opener()->url(); |
| 376 | |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 377 | return !ExtensionRendererInfo::InSameExtent(old_url, new_url); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 378 | } |
| 379 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 380 | // Returns the ISO 639_1 language code of the specified |text|, or 'unknown' |
| 381 | // if it failed. |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 382 | static std::string DetermineTextLanguage(const string16& text) { |
[email protected] | 655f97c3 | 2010-07-22 21:24:17 | [diff] [blame] | 383 | std::string language = chrome::kUnknownLanguageCode; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 384 | int num_languages = 0; |
[email protected] | a9558688 | 2010-08-02 18:40:08 | [diff] [blame] | 385 | int text_bytes = 0; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 386 | bool is_reliable = false; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 387 | Language cld_language = |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 388 | DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable, |
[email protected] | a9558688 | 2010-08-02 18:40:08 | [diff] [blame] | 389 | &num_languages, NULL, &text_bytes); |
| 390 | // We don't trust the result if the CLD reports that the detection is not |
| 391 | // reliable, or if the actual text used to detect the language was less than |
| 392 | // 100 bytes (short texts can often lead to wrong results). |
| 393 | if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES && |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 394 | cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) { |
| 395 | // We should not use LanguageCode_ISO_639_1 because it does not cover all |
| 396 | // the languages CLD can detect. As a result, it'll return the invalid |
| 397 | // language code for tradtional Chinese among others. |
| 398 | // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and |
| 399 | // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN |
| 400 | // for Simplified Chinese. |
| 401 | language = LanguageCodeWithDialects(cld_language); |
| 402 | } |
| 403 | return language; |
| 404 | } |
| 405 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 406 | /////////////////////////////////////////////////////////////////////////////// |
| 407 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 408 | int32 RenderView::next_page_id_ = 1; |
| 409 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 410 | struct RenderView::PendingFileChooser { |
| 411 | PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, |
| 412 | WebFileChooserCompletion* c) |
| 413 | : params(p), |
| 414 | completion(c) { |
| 415 | } |
| 416 | ViewHostMsg_RunFileChooser_Params params; |
| 417 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 418 | }; |
| 419 | |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 420 | RenderView::RenderView(RenderThreadBase* render_thread, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 421 | const WebPreferences& webkit_preferences, |
| 422 | int64 session_storage_namespace_id) |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 423 | : RenderWidget(render_thread, WebKit::WebPopupTypeNone), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 424 | webkit_preferences_(webkit_preferences), |
| 425 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 426 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 427 | send_preferred_size_changes_(false), |
| 428 | script_can_close_(true), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 429 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 430 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 431 | opened_by_user_gesture_(true), |
| 432 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 433 | page_id_(-1), |
| 434 | last_page_id_sent_to_browser_(-1), |
| 435 | last_indexed_page_id_(-1), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 436 | history_list_offset_(-1), |
| 437 | history_list_length_(0), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 438 | has_unload_listener_(false), |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 439 | #if defined(OS_MACOSX) |
| 440 | has_document_tag_(false), |
| 441 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 442 | document_tag_(0), |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 443 | cross_origin_access_count_(0), |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 444 | same_origin_access_count_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 445 | target_url_status_(TARGET_NONE), |
| 446 | spelling_panel_visible_(false), |
| 447 | view_type_(ViewType::INVALID), |
| 448 | browser_window_id_(-1), |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 449 | ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 450 | ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)), |
| 451 | ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 452 | ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)), |
| 453 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
| 454 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 455 | notification_provider_(new NotificationProvider(this))), |
| 456 | session_storage_namespace_id_(session_storage_namespace_id), |
| 457 | decrement_shared_popup_at_destruction_(false) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 458 | password_autocomplete_manager_.reset(new PasswordAutocompleteManager(this)); |
| 459 | autofill_helper_.reset(new AutoFillHelper(this)); |
| 460 | page_click_tracker_.reset(new PageClickTracker(this)); |
| 461 | // Note that the order of insertion of the listeners is important. |
| 462 | // The password_autocomplete_manager_ takes the first shot at processing the |
| 463 | // notification and can stop the propagation. |
| 464 | page_click_tracker_->AddListener(password_autocomplete_manager_.get()); |
| 465 | page_click_tracker_->AddListener(autofill_helper_.get()); |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 466 | ClearBlockedContentSettings(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | RenderView::~RenderView() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 470 | if (decrement_shared_popup_at_destruction_) |
| 471 | shared_popup_counter_->data--; |
| 472 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 473 | // Dispose of un-disposed image fetchers. |
| 474 | for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin(); |
| 475 | i != image_fetchers_.end(); ++i) { |
| 476 | delete *i; |
| 477 | } |
| 478 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 479 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 480 | while (!file_chooser_completions_.empty()) { |
| 481 | if (file_chooser_completions_.front()->completion) { |
| 482 | file_chooser_completions_.front()->completion->didChooseFile( |
| 483 | WebVector<WebString>()); |
| 484 | } |
| 485 | file_chooser_completions_.pop_front(); |
| 486 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 487 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 488 | #if defined(OS_MACOSX) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 489 | // Tell the spellchecker that the document is closed. |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 490 | if (has_document_tag_) |
| 491 | Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 492 | |
| 493 | // Destroy all fake plugin window handles on the browser side. |
| 494 | while (!fake_plugin_window_handles_.empty()) { |
| 495 | // Make sure no NULL plugin window handles were inserted into this list. |
| 496 | DCHECK(*fake_plugin_window_handles_.begin()); |
| 497 | // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. |
| 498 | DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); |
| 499 | } |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 500 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 501 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 502 | render_thread_->RemoveFilter(audio_message_filter_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 503 | |
| 504 | #ifndef NDEBUG |
| 505 | // Make sure we are no longer referenced by the ViewMap. |
| 506 | ViewMap* views = Singleton<ViewMap>::get(); |
| 507 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 508 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 509 | #endif |
| 510 | } |
| 511 | |
| 512 | /*static*/ |
| 513 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
| 514 | ViewMap* views = Singleton<ViewMap>::get(); |
| 515 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 516 | if (!visitor->Visit(it->second)) |
| 517 | return; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | /*static*/ |
| 522 | RenderView* RenderView::FromWebView(WebView* webview) { |
| 523 | ViewMap* views = Singleton<ViewMap>::get(); |
| 524 | ViewMap::iterator it = views->find(webview); |
| 525 | return it == views->end() ? NULL : it->second; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | /*static*/ |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 529 | RenderView* RenderView::Create( |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 530 | RenderThreadBase* render_thread, |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 531 | gfx::NativeViewId parent_hwnd, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 532 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 533 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 534 | const WebPreferences& webkit_prefs, |
| 535 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 536 | int32 routing_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 537 | int64 session_storage_namespace_id, |
| 538 | const string16& frame_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 539 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 540 | scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs, |
| 541 | session_storage_namespace_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 542 | view->Init(parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 543 | opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 544 | renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 545 | counter, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 546 | routing_id, |
| 547 | frame_name); // adds reference |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 548 | return view; |
| 549 | } |
| 550 | |
| 551 | /*static*/ |
| 552 | void RenderView::SetNextPageID(int32 next_page_id) { |
| 553 | // This method should only be called during process startup, and the given |
| 554 | // page id had better not exceed our current next page id! |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 555 | DCHECK_EQ(next_page_id_, 1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 556 | DCHECK(next_page_id >= next_page_id_); |
| 557 | next_page_id_ = next_page_id; |
| 558 | } |
| 559 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 560 | WebKit::WebView* RenderView::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 561 | return static_cast<WebKit::WebView*>(webwidget()); |
| 562 | } |
| 563 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 564 | void RenderView::UserMetricsRecordAction(const std::string& action) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 565 | Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); |
| 566 | } |
| 567 | |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 568 | void RenderView::PluginCrashed(const FilePath& plugin_path) { |
| 569 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 572 | WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame, |
| 573 | const WebPluginParams& params) { |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 574 | WebPluginInfo info; |
| 575 | bool found; |
| 576 | ContentSetting setting; |
| 577 | std::string mime_type; |
| 578 | Send(new ViewHostMsg_GetPluginInfo( |
| 579 | params.url, frame->top()->url(), params.mimeType.utf8(), &found, |
| 580 | &info, &setting, &mime_type)); |
| 581 | if (!found || !info.enabled) |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 582 | return NULL; |
| 583 | scoped_refptr<pepper::PluginModule> pepper_module = |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 584 | PepperPluginRegistry::GetInstance()->GetModule(info.path); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 585 | if (pepper_module) |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 586 | return CreatePepperPlugin(frame, params, info.path, pepper_module.get()); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 587 | else |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 588 | return CreateNPAPIPlugin(frame, params, info.path, mime_type); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 589 | } |
| 590 | |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 591 | void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 592 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 593 | // If the renderer is visible, set initial visibility and focus state. |
| 594 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 595 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 596 | delegate->SetContainerVisibility(true); |
| 597 | if (webview() && webview()->isActive()) |
| 598 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 599 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 600 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 601 | // Plugins start assuming the content has focus (so that they work in |
| 602 | // environments where RenderView isn't hosting them), so we always have to |
| 603 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 604 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 608 | plugin_delegates_.erase(delegate); |
| 609 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 610 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 611 | void RenderView::Init(gfx::NativeViewId parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 612 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 613 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 614 | SharedRenderViewCounter* counter, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 615 | int32 routing_id, |
| 616 | const string16& frame_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 617 | DCHECK(!webview()); |
| 618 | |
| 619 | if (opener_id != MSG_ROUTING_NONE) |
| 620 | opener_id_ = opener_id; |
| 621 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 622 | if (counter) { |
| 623 | shared_popup_counter_ = counter; |
| 624 | shared_popup_counter_->data++; |
| 625 | decrement_shared_popup_at_destruction_ = true; |
| 626 | } else { |
| 627 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 628 | decrement_shared_popup_at_destruction_ = false; |
| 629 | } |
| 630 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 631 | devtools_agent_.reset(new DevToolsAgent(routing_id, this)); |
[email protected] | 9b9d728 | 2009-04-08 14:13:04 | [diff] [blame] | 632 | |
[email protected] | 9a6c623 | 2010-06-25 11:46:49 | [diff] [blame] | 633 | webwidget_ = WebView::create(this, devtools_agent_.get()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 634 | Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 635 | webkit_preferences_.Apply(webview()); |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 636 | webview()->initializeMainFrame(this); |
[email protected] | c1e0696 | 2010-06-17 16:53:23 | [diff] [blame] | 637 | if (!frame_name.empty()) |
| 638 | webview()->mainFrame()->setName(frame_name); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 639 | |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 640 | OnSetRendererPrefs(renderer_prefs); |
| 641 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 642 | routing_id_ = routing_id; |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 643 | render_thread_->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 644 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 645 | // when we receive ViewMsg_Close. |
| 646 | AddRef(); |
| 647 | |
| 648 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 649 | // completing initialization. Otherwise, we can finish it now. |
| 650 | if (opener_id == MSG_ROUTING_NONE) { |
| 651 | did_show_ = true; |
| 652 | CompleteInit(parent_hwnd); |
| 653 | } |
| 654 | |
| 655 | host_window_ = parent_hwnd; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 656 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 657 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 658 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 659 | enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION; |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 660 | if (command_line.HasSwitch(switches::kEnableAccessibility)) |
| 661 | WebAccessibilityCache::enableAccessibility(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 662 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 663 | audio_message_filter_ = new AudioMessageFilter(routing_id_); |
| 664 | render_thread_->AddFilter(audio_message_filter_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | void RenderView::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 668 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 669 | if (main_frame) |
| 670 | child_process_logging::SetActiveURL(main_frame->url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 671 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 672 | // If this is developer tools renderer intercept tools messages first. |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 673 | if (devtools_client_.get() && devtools_client_->OnMessageReceived(message)) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 674 | return; |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 675 | if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message)) |
| 676 | return; |
[email protected] | b6849bda | 2009-10-14 23:59:26 | [diff] [blame] | 677 | if (notification_provider_->OnMessageReceived(message)) |
| 678 | return; |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 679 | if (geolocation_dispatcher_.get() && |
| 680 | geolocation_dispatcher_->OnMessageReceived(message)) { |
| 681 | return; |
| 682 | } |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 683 | if (speech_input_dispatcher_.get() && |
| 684 | speech_input_dispatcher_->OnMessageReceived(message)) { |
| 685 | return; |
| 686 | } |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 687 | if (device_orientation_dispatcher_.get() && |
| 688 | device_orientation_dispatcher_->OnMessageReceived(message)) { |
| 689 | return; |
| 690 | } |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 691 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 692 | IPC_BEGIN_MESSAGE_MAP(RenderView, message) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 693 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail) |
| 694 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 695 | IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 696 | IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 697 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 698 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 699 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 700 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 701 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 702 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 703 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 704 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 705 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 706 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 707 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
| 708 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 709 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 710 | IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, |
| 711 | OnAdvanceToNextMisspelling) |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 712 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 713 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 714 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
| 715 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 716 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 717 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 718 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| 719 | IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 720 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 721 | IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, |
| 722 | OnSetContentSettingsForLoadingURL) |
| 723 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 724 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 725 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 726 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 727 | OnResetPageEncodingToDefault) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 728 | IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 729 | IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 730 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 731 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 732 | IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 733 | IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 734 | IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm) |
| 735 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) |
| 736 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) |
| 737 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) |
| 738 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 739 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 740 | IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 741 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved, |
| 742 | OnDragSourceEndedOrMoved) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 743 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, |
| 744 | OnDragSourceSystemDragEnded) |
| 745 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 746 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 747 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 748 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
| 749 | IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 750 | IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 751 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
| 752 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 753 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 754 | OnGetAllSavableResourceLinksForCurrentPage) |
[email protected] | f09c718 | 2009-03-10 12:54:04 | [diff] [blame] | 755 | IPC_MESSAGE_HANDLER( |
| 756 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 757 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 758 | IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 759 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 760 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 761 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 762 | IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 763 | OnHandleMessageFromExternalHost) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 764 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 765 | OnDisassociateFromPopupCount) |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 766 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned, |
| 767 | OnAutoFillSuggestionsReturned) |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 768 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled, |
| 769 | OnAutoFillFormDataFilled) |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 770 | IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose, |
| 771 | OnAllowScriptToClose) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 772 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 773 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 774 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
| 775 | OnExtensionMessageInvoke) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 776 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 777 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 778 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 779 | OnEnablePreferredSizeChangedMode) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 780 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 781 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 782 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 783 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId, |
| 784 | OnUpdateBrowserWindowId) |
| 785 | IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType, |
| 786 | OnNotifyRendererViewType) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 787 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 788 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 789 | #if defined(OS_MACOSX) |
| 790 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 791 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame^] | 792 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionConfirmed, |
| 793 | OnPluginImeCompositionConfirmed) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 794 | #endif |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 795 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 796 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 797 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode, |
| 798 | OnExecuteCode) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 799 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 800 | OnCustomContextMenuAction) |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 801 | IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage) |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 802 | IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation) |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 803 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility) |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 804 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus) |
| 805 | IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction, |
| 806 | OnAccessibilityDoDefaultAction) |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 807 | IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK, |
| 808 | OnAccessibilityNotificationsAck) |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 809 | IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 810 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 811 | // Have the super handle all other messages. |
| 812 | IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) |
| 813 | IPC_END_MESSAGE_MAP() |
| 814 | } |
| 815 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 816 | void RenderView::OnCaptureThumbnail() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 817 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 818 | if (!main_frame) |
| 819 | return; |
| 820 | |
| 821 | // get the URL for this page |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 822 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 823 | if (url.is_empty()) |
| 824 | return; |
| 825 | |
| 826 | if (size_.IsEmpty()) |
| 827 | return; // Don't create an empty thumbnail! |
| 828 | |
| 829 | ThumbnailScore score; |
| 830 | SkBitmap thumbnail; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 831 | if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight, |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 832 | &thumbnail, &score)) |
| 833 | return; |
| 834 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 835 | // send the thumbnail message to the browser process |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 836 | Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 837 | } |
| 838 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 839 | void RenderView::OnCaptureSnapshot() { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 840 | SkBitmap snapshot; |
| 841 | bool error = false; |
| 842 | |
| 843 | WebFrame* main_frame = webview()->mainFrame(); |
| 844 | if (!main_frame) |
| 845 | error = true; |
| 846 | |
| 847 | if (!error && !CaptureSnapshot(webview(), &snapshot)) |
| 848 | error = true; |
| 849 | |
| 850 | DCHECK(error == snapshot.empty()) << |
| 851 | "Snapshot should be empty on error, non-empty otherwise."; |
| 852 | |
| 853 | // Send the snapshot to the browser process. |
| 854 | Send(new ViewHostMsg_Snapshot(routing_id_, snapshot)); |
| 855 | } |
| 856 | |
[email protected] | 06863722 | 2009-01-29 16:58:07 | [diff] [blame] | 857 | void RenderView::OnPrintPages() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 858 | DCHECK(webview()); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 859 | if (webview()) { |
| 860 | // If the user has selected text in the currently focused frame we print |
| 861 | // only that frame (this makes print selection work for multiple frames). |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 862 | if (webview()->focusedFrame()->hasSelection()) |
| 863 | Print(webview()->focusedFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 864 | else |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 865 | Print(webview()->mainFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 866 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 867 | } |
| 868 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 869 | void RenderView::OnPrintingDone(int document_cookie, bool success) { |
| 870 | // Ignoring document cookie here since only one print job can be outstanding |
| 871 | // per renderer and document_cookie is 0 when printing is successful. |
| 872 | DCHECK(print_helper_.get()); |
| 873 | if (print_helper_.get() != NULL) { |
| 874 | print_helper_->DidFinishPrinting(success); |
| 875 | } |
| 876 | } |
| 877 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 878 | void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { |
| 879 | if (load_id != page_id_) |
| 880 | return; // this capture call is no longer relevant due to navigation |
| 881 | if (load_id == last_indexed_page_id_) |
| 882 | return; // we already indexed this page |
| 883 | |
| 884 | if (!webview()) |
| 885 | return; |
| 886 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 887 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 888 | if (!main_frame) |
| 889 | return; |
| 890 | |
| 891 | // Don't index/capture pages that are in view source mode. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 892 | if (main_frame->isViewSourceModeEnabled()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 893 | return; |
| 894 | |
| 895 | // Don't index/capture pages that failed to load. This only checks the top |
| 896 | // level frame so the thumbnail may contain a frame that failed to load. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 897 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 898 | if (ds && ds->hasUnreachableURL()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 899 | return; |
| 900 | |
| 901 | if (!preliminary_capture) |
| 902 | last_indexed_page_id_ = load_id; |
| 903 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 904 | // Get the URL for this page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 905 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 906 | if (url.is_empty()) |
| 907 | return; |
| 908 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 909 | // Retrieve the frame's full text. |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 910 | string16 contents; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 911 | CaptureText(main_frame, &contents); |
| 912 | if (contents.size()) { |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 913 | WebKit::WebDocument document = main_frame->document(); |
[email protected] | 5ddfd63e | 2010-09-01 15:48:37 | [diff] [blame] | 914 | // If the page explicitly specifies a language, use it, otherwise we'll |
| 915 | // determine it based on the text content using the CLD. |
| 916 | std::string language = |
| 917 | TranslateHelper::GetPageLanguageFromMetaTag(&document); |
| 918 | if (language.empty()) { |
| 919 | base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 920 | language = DetermineTextLanguage(contents); |
| 921 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection", |
| 922 | base::TimeTicks::Now() - begin_time); |
| 923 | } |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 924 | // Send the text to the browser for indexing (the browser might decide not |
| 925 | // to index, if the URL is HTTPS for instance) and language discovery. |
[email protected] | 5ddfd63e | 2010-09-01 15:48:37 | [diff] [blame] | 926 | Send(new ViewHostMsg_PageContents( |
| 927 | routing_id_, url, load_id, contents, language, |
| 928 | TranslateHelper::IsPageTranslatable(&document))); |
[email protected] | 5c426692 | 2009-07-10 16:41:27 | [diff] [blame] | 929 | } |
| 930 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 931 | OnCaptureThumbnail(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 932 | } |
| 933 | |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 934 | void RenderView::CaptureText(WebFrame* frame, string16* contents) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 935 | contents->clear(); |
| 936 | if (!frame) |
| 937 | return; |
| 938 | |
| 939 | #ifdef TIME_TEXT_RETRIEVAL |
| 940 | double begin = time_util::GetHighResolutionTimeNow(); |
| 941 | #endif |
| 942 | |
| 943 | // get the contents of the frame |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 944 | *contents = frame->contentAsText(kMaxIndexChars); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 945 | |
| 946 | #ifdef TIME_TEXT_RETRIEVAL |
| 947 | double end = time_util::GetHighResolutionTimeNow(); |
| 948 | char buf[128]; |
| 949 | sprintf_s(buf, "%d chars retrieved for indexing in %gms\n", |
| 950 | contents.size(), (end - begin)*1000); |
| 951 | OutputDebugStringA(buf); |
| 952 | #endif |
| 953 | |
| 954 | // When the contents are clipped to the maximum, we don't want to have a |
| 955 | // partial word indexed at the end that might have been clipped. Therefore, |
| 956 | // terminate the string at the last space to ensure no words are clipped. |
| 957 | if (contents->size() == kMaxIndexChars) { |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 958 | size_t last_space_index = contents->find_last_of(kWhitespaceUTF16); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 959 | if (last_space_index == std::wstring::npos) |
| 960 | return; // don't index if we got a huge block of text with no spaces |
| 961 | contents->resize(last_space_index); |
| 962 | } |
| 963 | } |
| 964 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 965 | bool RenderView::CaptureThumbnail(WebView* view, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 966 | int w, |
| 967 | int h, |
| 968 | SkBitmap* thumbnail, |
| 969 | ThumbnailScore* score) { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 970 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 971 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 972 | skia::PlatformCanvas canvas; |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 973 | |
| 974 | // Paint |view| into |canvas|. |
| 975 | if (!PaintViewIntoCanvas(view, canvas)) |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 976 | return false; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 977 | |
| 978 | skia::BitmapPlatformDevice& device = |
| 979 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 980 | |
| 981 | const SkBitmap& src_bmp = device.accessBitmap(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 982 | |
[email protected] | cab34d6a | 2009-09-24 01:14:52 | [diff] [blame] | 983 | SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 984 | float dest_aspect = dest_rect.width() / dest_rect.height(); |
| 985 | |
| 986 | // Get the src rect so that we can preserve the aspect ratio while filling |
| 987 | // the destination. |
| 988 | SkIRect src_rect; |
| 989 | if (src_bmp.width() < dest_rect.width() || |
| 990 | src_bmp.height() < dest_rect.height()) { |
| 991 | // Source image is smaller: we clip the part of source image within the |
| 992 | // dest rect, and then stretch it to fill the dest rect. We don't respect |
| 993 | // the aspect ratio in this case. |
| 994 | src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()), |
| 995 | static_cast<S16CPU>(dest_rect.height())); |
| 996 | score->good_clipping = false; |
| 997 | } else { |
| 998 | float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height(); |
| 999 | if (src_aspect > dest_aspect) { |
| 1000 | // Wider than tall, clip horizontally: we center the smaller thumbnail in |
| 1001 | // the wider screen. |
| 1002 | S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect); |
| 1003 | S16CPU x_offset = (src_bmp.width() - new_width) / 2; |
| 1004 | src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height()); |
| 1005 | score->good_clipping = false; |
| 1006 | } else { |
| 1007 | src_rect.set(0, 0, src_bmp.width(), |
| 1008 | static_cast<S16CPU>(src_bmp.width() / dest_aspect)); |
| 1009 | score->good_clipping = true; |
| 1010 | } |
| 1011 | } |
| 1012 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1013 | score->at_top = (view->mainFrame()->scrollOffset().height == 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1014 | |
| 1015 | SkBitmap subset; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1016 | device.accessBitmap(false).extractSubset(&subset, src_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1017 | |
| 1018 | // Resample the subset that we want to get it the right size. |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 1019 | *thumbnail = skia::ImageOperations::Resize( |
| 1020 | subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1021 | |
| 1022 | score->boring_score = CalculateBoringScore(thumbnail); |
| 1023 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1024 | HISTOGRAM_TIMES("Renderer4.Thumbnail", |
| 1025 | base::TimeTicks::Now() - beginning_time); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 1026 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1027 | } |
| 1028 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1029 | bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) { |
| 1030 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1031 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1032 | skia::PlatformCanvas canvas; |
| 1033 | if (!PaintViewIntoCanvas(view, canvas)) |
| 1034 | return false; |
| 1035 | |
| 1036 | skia::BitmapPlatformDevice& device = |
| 1037 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 1038 | |
| 1039 | const SkBitmap& bitmap = device.accessBitmap(false); |
| 1040 | if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
| 1041 | return false; |
| 1042 | |
| 1043 | HISTOGRAM_TIMES("Renderer4.Snapshot", |
| 1044 | base::TimeTicks::Now() - beginning_time); |
| 1045 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { |
| 1049 | if (!webview()) |
| 1050 | return; |
| 1051 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1052 | history_list_offset_ = params.current_history_list_offset; |
| 1053 | history_list_length_ = params.current_history_list_length; |
| 1054 | |
[email protected] | 8c785c6 | 2009-07-13 14:20:15 | [diff] [blame] | 1055 | if (devtools_agent_.get()) |
| 1056 | devtools_agent_->OnNavigate(); |
| 1057 | |
[email protected] | 42219753 | 2010-01-25 17:38:23 | [diff] [blame] | 1058 | if (notification_provider_.get()) |
| 1059 | notification_provider_->OnNavigate(); |
| 1060 | |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 1061 | child_process_logging::SetActiveURL(params.url); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1062 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1063 | AboutHandler::MaybeHandle(params.url); |
| 1064 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1065 | bool is_reload = |
| 1066 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD || |
| 1067 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1068 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1069 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1070 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1071 | // We cannot reload if we do not have any history state. This happens, for |
| 1072 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1073 | // a hack since it means that reload after a crashed tab does not cause an |
| 1074 | // end-to-end cache validation. |
| 1075 | is_reload = false; |
| 1076 | } |
| 1077 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1078 | // A navigation resulting from loading a javascript URL should not be treated |
| 1079 | // as a browser initiated event. Instead, we want it to look as if the page |
| 1080 | // initiated any load resulting from JS execution. |
| 1081 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1082 | NavigationState* state = NavigationState::CreateBrowserInitiated( |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1083 | params.page_id, |
| 1084 | params.pending_history_list_offset, |
| 1085 | params.transition, |
| 1086 | params.request_time); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1087 | if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) { |
| 1088 | // We're doing a load of a page that was restored from the last session. |
| 1089 | // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE) |
| 1090 | // which can result in stale data for pages that are set to expire. We |
| 1091 | // explicitly override that by setting the policy here so that as |
| 1092 | // necessary we load from the network. |
| 1093 | state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy); |
| 1094 | } |
| 1095 | pending_navigation_state_.reset(state); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1096 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1097 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1098 | NavigationState* navigation_state = pending_navigation_state_.get(); |
| 1099 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1100 | // If we are reloading, then WebKit will use the history state of the current |
| 1101 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1102 | // have history state, then we need to navigate to it, which corresponds to a |
| 1103 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1104 | if (is_reload) { |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1105 | if (navigation_state) |
| 1106 | navigation_state->set_load_type(NavigationState::RELOAD); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1107 | bool ignore_cache = (params.navigation_type == |
| 1108 | ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE); |
| 1109 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1110 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1111 | // 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] | 1112 | DCHECK_NE(params.page_id, -1); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1113 | if (navigation_state) |
| 1114 | navigation_state->set_load_type(NavigationState::HISTORY_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1115 | main_frame->loadHistoryItem( |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1116 | webkit_glue::HistoryItemFromString(params.state)); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1117 | } else { |
| 1118 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1119 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1120 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1121 | // A session history navigation should have been accompanied by state. |
| 1122 | DCHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1123 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1124 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1125 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1126 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1127 | if (params.referrer.is_valid()) { |
| 1128 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), |
| 1129 | WebString::fromUTF8(params.referrer.spec())); |
| 1130 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1131 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1132 | if (navigation_state) |
| 1133 | navigation_state->set_load_type(NavigationState::NORMAL_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1134 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1135 | } |
| 1136 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1137 | // In case LoadRequest failed before DidCreateDataSource was called. |
| 1138 | pending_navigation_state_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | // Stop loading the current page |
| 1142 | void RenderView::OnStop() { |
| 1143 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 1144 | webview()->mainFrame()->stopLoading(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1145 | } |
| 1146 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1147 | // Reload current focused frame. |
| 1148 | // 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] | 1149 | void RenderView::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1150 | if (webview() && webview()->focusedFrame()) { |
| 1151 | // We always obey the cache (ignore_cache=false) here. |
| 1152 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1153 | // a cache-ignoring reload of the frame. |
| 1154 | webview()->focusedFrame()->reload(false); |
| 1155 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1156 | } |
| 1157 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1158 | void RenderView::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1159 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1160 | } |
| 1161 | |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1162 | void RenderView::OnExecuteEditCommand(const std::string& name, |
| 1163 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1164 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1165 | return; |
| 1166 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1167 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1168 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1169 | } |
| 1170 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1171 | void RenderView::OnSetupDevToolsClient() { |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 1172 | DCHECK(!devtools_client_.get()); |
| 1173 | devtools_client_.reset(new DevToolsClient(this)); |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1174 | } |
| 1175 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1176 | void RenderView::OnUpdateTargetURLAck() { |
| 1177 | // Check if there is a targeturl waiting to be sent. |
| 1178 | if (target_url_status_ == TARGET_PENDING) { |
| 1179 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1180 | pending_target_url_)); |
| 1181 | } |
| 1182 | |
| 1183 | target_url_status_ = TARGET_NONE; |
| 1184 | } |
| 1185 | |
| 1186 | void RenderView::OnUndo() { |
| 1187 | if (!webview()) |
| 1188 | return; |
| 1189 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1190 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1191 | UserMetricsRecordAction("Undo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | void RenderView::OnRedo() { |
| 1195 | if (!webview()) |
| 1196 | return; |
| 1197 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1198 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1199 | UserMetricsRecordAction("Redo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | void RenderView::OnCut() { |
| 1203 | if (!webview()) |
| 1204 | return; |
| 1205 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1206 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1207 | UserMetricsRecordAction("Cut"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | void RenderView::OnCopy() { |
| 1211 | if (!webview()) |
| 1212 | return; |
| 1213 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1214 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1215 | UserMetricsRecordAction("Copy"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1216 | } |
| 1217 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1218 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1219 | void RenderView::OnCopyToFindPboard() { |
| 1220 | if (!webview()) |
| 1221 | return; |
| 1222 | |
| 1223 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1224 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1225 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1226 | if (frame->hasSelection()) { |
| 1227 | string16 selection = frame->selectionAsText(); |
| 1228 | RenderThread::current()->Send( |
| 1229 | new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection)); |
| 1230 | } |
| 1231 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1232 | UserMetricsRecordAction("CopyToFindPboard"); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1233 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1234 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1235 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1236 | void RenderView::OnPaste() { |
| 1237 | if (!webview()) |
| 1238 | return; |
| 1239 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1240 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1241 | UserMetricsRecordAction("Paste"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1242 | } |
| 1243 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1244 | void RenderView::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1245 | if (!webview()) |
| 1246 | return; |
| 1247 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1248 | WebFrame* frame = webview()->focusedFrame(); |
| 1249 | if (!frame->hasSelection()) |
| 1250 | frame->selectWordAroundCaret(); |
| 1251 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1252 | } |
| 1253 | |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1254 | void RenderView::OnAdvanceToNextMisspelling() { |
| 1255 | if (!webview()) |
| 1256 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1257 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1258 | WebString::fromUTF8("AdvanceToNextMisspelling")); |
| 1259 | } |
| 1260 | |
| 1261 | void RenderView::OnToggleSpellPanel(bool is_currently_visible) { |
| 1262 | if (!webview()) |
| 1263 | return; |
| 1264 | // We need to tell the webView whether the spelling panel is visible or not so |
| 1265 | // that it won't need to make ipc calls later. |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1266 | spelling_panel_visible_ = is_currently_visible; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1267 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1268 | WebString::fromUTF8("ToggleSpellPanel")); |
| 1269 | } |
| 1270 | |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1271 | void RenderView::OnToggleSpellCheck() { |
| 1272 | if (!webview()) |
| 1273 | return; |
| 1274 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1275 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1276 | frame->enableContinuousSpellChecking( |
| 1277 | !frame->isContinuousSpellCheckingEnabled()); |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1278 | } |
| 1279 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1280 | void RenderView::OnDelete() { |
| 1281 | if (!webview()) |
| 1282 | return; |
| 1283 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1284 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1285 | UserMetricsRecordAction("DeleteSelection"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | void RenderView::OnSelectAll() { |
| 1289 | if (!webview()) |
| 1290 | return; |
| 1291 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1292 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 1293 | WebString::fromUTF8("SelectAll")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1294 | UserMetricsRecordAction("SelectAll"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | void RenderView::OnSetInitialFocus(bool reverse) { |
| 1298 | if (!webview()) |
| 1299 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1300 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | /////////////////////////////////////////////////////////////////////////////// |
| 1304 | |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1305 | void RenderView::SetContentSettings(const ContentSettings& settings) { |
| 1306 | current_content_settings_ = settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1307 | } |
| 1308 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1309 | // Tell the embedding application that the URL of the active page has changed |
| 1310 | void RenderView::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1311 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1312 | DCHECK(ds); |
| 1313 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1314 | const WebURLRequest& request = ds->request(); |
| 1315 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1316 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1317 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1318 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 1319 | DCHECK(navigation_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1320 | |
| 1321 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1322 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1323 | params.is_post = false; |
| 1324 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1325 | params.frame_id = frame->identifier(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1326 | params.is_content_filtered = response.isContentFiltered(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1327 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1328 | if (!navigation_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1329 | // SSL state specified in the request takes precedence over the one in the |
| 1330 | // response. |
| 1331 | // So far this is only intended for error pages that are not expected to be |
| 1332 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1333 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1334 | params.security_info = navigation_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1335 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1336 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1340 | if (ds->hasUnreachableURL()) { |
| 1341 | params.url = ds->unreachableURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1342 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1343 | params.url = request.url(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1344 | } |
| 1345 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1346 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1347 | params.should_update_history = !ds->hasUnreachableURL() && |
| 1348 | !response.isMultipartPayload(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1349 | |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1350 | params.searchable_form_url = navigation_state->searchable_form_url(); |
| 1351 | params.searchable_form_encoding = |
| 1352 | navigation_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1353 | |
| 1354 | const PasswordForm* password_form_data = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1355 | navigation_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1356 | if (password_form_data) |
| 1357 | params.password_form = *password_form_data; |
| 1358 | |
| 1359 | params.gesture = navigation_gesture_; |
| 1360 | navigation_gesture_ = NavigationGestureUnknown; |
| 1361 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1362 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1363 | // Top-level navigation. |
| 1364 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 1365 | // Clear "block" flags for the new page. This needs to happen before any of |
| 1366 | // allowScripts(), allowImages(), allowPlugins() is called for the new page |
| 1367 | // so that these functions can correctly detect that a piece of content |
| 1368 | // flipped from "not blocked" to "blocked". |
| 1369 | ClearBlockedContentSettings(); |
| 1370 | |
[email protected] | 62d2a11 | 2010-04-07 00:53:02 | [diff] [blame] | 1371 | // Set content settings. Default them from the parent window if one exists. |
| 1372 | // This makes sure about:blank windows work as expected. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1373 | HostContentSettings::iterator host_content_settings = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1374 | host_content_settings_.find(GURL(request.url())); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1375 | if (host_content_settings != host_content_settings_.end()) { |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1376 | SetContentSettings(host_content_settings->second); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1377 | |
| 1378 | // These content settings were merely recorded transiently for this load. |
| 1379 | // We can erase them now. If at some point we reload this page, the |
| 1380 | // browser will send us new, up-to-date content settings. |
| 1381 | host_content_settings_.erase(host_content_settings); |
[email protected] | 3a387ae | 2010-04-08 01:58:40 | [diff] [blame] | 1382 | } else if (frame->opener()) { |
[email protected] | 8128cdd0 | 2010-07-21 20:40:10 | [diff] [blame] | 1383 | // The opener's view is not guaranteed to be non-null (it could be |
| 1384 | // detached from its page but not yet destructed). |
| 1385 | if (WebView* opener_view = frame->opener()->view()) { |
| 1386 | RenderView* opener = FromWebView(opener_view); |
| 1387 | SetContentSettings(opener->current_content_settings_); |
| 1388 | } |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1389 | } |
| 1390 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1391 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1392 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1393 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1394 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1395 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1396 | // Reset the zoom levels for plugins. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1397 | webview()->setZoomLevel(false, 0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1398 | } else { |
| 1399 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1400 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1401 | } |
| 1402 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1403 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1404 | // This zoom level was merely recorded transiently for this load. We can |
| 1405 | // erase it now. If at some point we reload this page, the browser will |
| 1406 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1407 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1408 | } |
| 1409 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1410 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1411 | // will also call us back which will cause us to send a message to |
| 1412 | // update TabContents. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1413 | webview()->zoomLimitsChanged( |
| 1414 | WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier), |
| 1415 | WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1416 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1417 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1418 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1419 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1420 | params.transition = navigation_state->transition_type(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1421 | if (!PageTransition::IsMainFrame(params.transition)) { |
| 1422 | // If the main frame does a load, it should not be reported as a subframe |
| 1423 | // navigation. This can occur in the following case: |
| 1424 | // 1. You're on a site with frames. |
| 1425 | // 2. You do a subframe navigation. This is stored with transition type |
| 1426 | // MANUAL_SUBFRAME. |
| 1427 | // 3. You navigate to some non-frame site, say, google.com. |
| 1428 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1429 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1430 | // We don't want that, because any navigation that changes the toplevel |
| 1431 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1432 | // update the URL bar, etc). |
| 1433 | params.transition = PageTransition::LINK; |
| 1434 | } |
| 1435 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1436 | // If we have a valid consumed client redirect source, |
| 1437 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1438 | // so we set the referrer and transition to match. |
| 1439 | if (completed_client_redirect_src_.is_valid()) { |
[email protected] | 77e09a9 | 2008-08-01 18:11:04 | [diff] [blame] | 1440 | DCHECK(completed_client_redirect_src_ == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1441 | params.referrer = completed_client_redirect_src_; |
| 1442 | params.transition = static_cast<PageTransition::Type>( |
| 1443 | params.transition | PageTransition::CLIENT_REDIRECT); |
| 1444 | } else { |
| 1445 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1446 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1447 | params.referrer = GURL( |
| 1448 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1449 | } |
| 1450 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1451 | string16 method = request.httpMethod(); |
| 1452 | if (EqualsASCII(method, "POST")) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1453 | params.is_post = true; |
| 1454 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1455 | // Save some histogram data so we can compute the average memory used per |
| 1456 | // page load of the glyphs. |
| 1457 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1458 | webkit_glue::GetGlyphPageCount()); |
| 1459 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1460 | // This message needs to be sent before any of allowScripts(), |
| 1461 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1462 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1463 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1464 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1465 | } else { |
| 1466 | // Subframe navigation: the type depends on whether this navigation |
| 1467 | // generated a new session history entry. When they do generate a session |
| 1468 | // history entry, it means the user initiated the navigation and we should |
| 1469 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1470 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1471 | if (page_id_ > last_page_id_sent_to_browser_) |
| 1472 | params.transition = PageTransition::MANUAL_SUBFRAME; |
| 1473 | else |
| 1474 | params.transition = PageTransition::AUTO_SUBFRAME; |
| 1475 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1476 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1477 | } |
| 1478 | |
| 1479 | last_page_id_sent_to_browser_ = |
| 1480 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1481 | |
| 1482 | // 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] | 1483 | // we don't want the transition type to persist. Just clear it. |
| 1484 | navigation_state->set_transition_type(PageTransition::LINK); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1485 | |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1486 | // Check if the navigation was within the same page, in which case we don't |
| 1487 | // want to clear the accessibility cache. |
| 1488 | if (accessibility_.get() && !navigation_state->was_within_same_page()) { |
[email protected] | 1745596 | 2010-02-24 01:39:35 | [diff] [blame] | 1489 | accessibility_.reset(); |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 1490 | pending_accessibility_notifications_.clear(); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1491 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1495 | void RenderView::UpdateTitle(WebFrame* frame, const string16& title) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1496 | // Ignore all but top level navigations... |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1497 | if (!frame->parent()) { |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1498 | Send(new ViewHostMsg_UpdateTitle( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1499 | routing_id_, |
| 1500 | page_id_, |
| 1501 | UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ? |
| 1502 | title.substr(0, chrome::kMaxTitleChars) : title))); |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1503 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | void RenderView::UpdateEncoding(WebFrame* frame, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1507 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1508 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1509 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1510 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1511 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1512 | last_encoding_name_ = encoding_name; |
| 1513 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1514 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | |
[email protected] | f4d34b5 | 2008-11-24 23:05:01 | [diff] [blame] | 1518 | // Sends the previous session history state to the browser so it will be saved |
| 1519 | // before we navigate to a new page. This must be called *before* the page ID |
| 1520 | // has been updated so we know what it was. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1521 | void RenderView::UpdateSessionHistory(WebFrame* frame) { |
| 1522 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1523 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1524 | // there is no past session history to record. |
| 1525 | if (page_id_ == -1) |
| 1526 | return; |
| 1527 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1528 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1529 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1530 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1531 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1532 | |
| 1533 | Send(new ViewHostMsg_UpdateState( |
| 1534 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1535 | } |
| 1536 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1537 | void RenderView::OpenURL( |
| 1538 | const GURL& url, const GURL& referrer, WebNavigationPolicy policy) { |
| 1539 | Send(new ViewHostMsg_OpenURL( |
| 1540 | routing_id_, url, referrer, NavigationPolicyToDisposition(policy))); |
| 1541 | } |
| 1542 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1543 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1544 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1545 | void RenderView::LoadNavigationErrorPage(WebFrame* frame, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1546 | const WebURLRequest& failed_request, |
| 1547 | const WebURLError& error, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1548 | const std::string& html, |
| 1549 | bool replace) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1550 | GURL failed_url = error.unreachableURL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1551 | std::string alt_html; |
[email protected] | 07b49351 | 2010-08-27 15:39:29 | [diff] [blame] | 1552 | ExtensionRendererInfo* extension = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1553 | if (html.empty()) { |
| 1554 | // Use a local error page. |
| 1555 | int resource_id; |
| 1556 | DictionaryValue error_strings; |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1557 | |
[email protected] | 8165428 | 2010-10-04 17:08:06 | [diff] [blame] | 1558 | if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1559 | extension = ExtensionRendererInfo::GetByURL(failed_url); |
| 1560 | if (extension) { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1561 | LocalizedError::GetAppErrorStrings(error, failed_url, extension, |
| 1562 | &error_strings); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1563 | |
| 1564 | // TODO(erikkay): Should we use a different template for different |
| 1565 | // error messages? |
| 1566 | resource_id = IDR_ERROR_APP_HTML; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1567 | } else { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1568 | if (error.domain == WebString::fromUTF8(net::kErrorDomain) && |
| 1569 | error.reason == net::ERR_CACHE_MISS && |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1570 | EqualsASCII(failed_request.httpMethod(), "POST")) { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1571 | LocalizedError::GetFormRepostStrings(failed_url, &error_strings); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1572 | resource_id = IDR_ERROR_NO_DETAILS_HTML; |
| 1573 | } else { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1574 | LocalizedError::GetStrings(error, &error_strings); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1575 | resource_id = IDR_NET_ERROR_HTML; |
| 1576 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1577 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1578 | |
| 1579 | alt_html = GetAltHTMLForTemplate(error_strings, resource_id); |
| 1580 | } else { |
| 1581 | alt_html = html; |
| 1582 | } |
| 1583 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1584 | frame->loadHTMLString(alt_html, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1585 | GURL(kUnreachableWebDataURL), |
| 1586 | failed_url, |
| 1587 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1588 | } |
| 1589 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 1590 | void RenderView::BindDOMAutomationController(WebFrame* frame) { |
[email protected] | 2f97917 | 2010-09-16 21:54:03 | [diff] [blame] | 1591 | if (!dom_automation_controller_.get()) { |
| 1592 | dom_automation_controller_.reset(new DomAutomationController()); |
| 1593 | } |
| 1594 | dom_automation_controller_->set_message_sender(this); |
| 1595 | dom_automation_controller_->set_routing_id(routing_id_); |
| 1596 | dom_automation_controller_->BindToJavascript(frame, |
| 1597 | L"domAutomationController"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1598 | } |
| 1599 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1600 | bool RenderView::RunJavaScriptMessage(int type, |
| 1601 | const std::wstring& message, |
| 1602 | const std::wstring& default_value, |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1603 | const GURL& frame_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1604 | std::wstring* result) { |
| 1605 | bool success = false; |
| 1606 | std::wstring result_temp; |
| 1607 | if (!result) |
| 1608 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1609 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1610 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1611 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1612 | return success; |
| 1613 | } |
| 1614 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1615 | bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
| 1616 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1617 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1618 | // it is particularly important that we do not call willEnterModalLoop as |
| 1619 | // that would defer resource loads for the dialog itself. |
| 1620 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 1621 | RenderThread::current()->DoNotNotifyWebKitOfModalLoop(); |
| 1622 | |
| 1623 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1624 | return Send(message); |
| 1625 | } |
| 1626 | |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1627 | void RenderView::AddGURLSearchProvider( |
| 1628 | const GURL& osd_url, |
| 1629 | const ViewHostMsg_PageHasOSDD_Type& provider_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1630 | if (!osd_url.is_empty()) |
| 1631 | Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1632 | provider_type)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1633 | } |
| 1634 | |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1635 | void RenderView::OnAutoFillSuggestionsReturned( |
| 1636 | int query_id, |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 1637 | const std::vector<string16>& values, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 1638 | const std::vector<string16>& labels, |
[email protected] | a53e0683 | 2010-07-28 22:46:41 | [diff] [blame] | 1639 | const std::vector<string16>& icons, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 1640 | const std::vector<int>& unique_ids) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1641 | autofill_helper_->SuggestionsReceived( |
[email protected] | a53e0683 | 2010-07-28 22:46:41 | [diff] [blame] | 1642 | query_id, values, labels, icons, unique_ids); |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1643 | } |
| 1644 | |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 1645 | void RenderView::OnAutoFillFormDataFilled(int query_id, |
| 1646 | const webkit_glue::FormData& form) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1647 | autofill_helper_->FormDataFilled(query_id, form); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 1648 | } |
| 1649 | |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1650 | void RenderView::OnAllowScriptToClose(bool script_can_close) { |
| 1651 | script_can_close_ = script_can_close; |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1652 | } |
| 1653 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1654 | uint32 RenderView::GetCPBrowsingContext() { |
| 1655 | uint32 context = 0; |
| 1656 | Send(new ViewHostMsg_GetCPBrowsingContext(&context)); |
| 1657 | return context; |
| 1658 | } |
| 1659 | |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1660 | void RenderView::AddSearchProvider( |
| 1661 | const std::string& url, |
| 1662 | const ViewHostMsg_PageHasOSDD_Type& provider_type) { |
| 1663 | if (provider_type.type == |
| 1664 | ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER && |
| 1665 | !webview()->mainFrame()->isProcessingUserGesture()) |
| 1666 | return; |
| 1667 | |
| 1668 | AddGURLSearchProvider(GURL(url), provider_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1669 | } |
| 1670 | |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1671 | ViewHostMsg_GetSearchProviderInstallState_Params |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1672 | RenderView::GetSearchProviderInstallState(WebFrame* frame, |
| 1673 | const std::string& url) { |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1674 | GURL inquiry_url = GURL(url); |
| 1675 | if (inquiry_url.is_empty()) |
| 1676 | return ViewHostMsg_GetSearchProviderInstallState_Params::Denied(); |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1677 | |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1678 | ViewHostMsg_GetSearchProviderInstallState_Params install; |
| 1679 | Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_, |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1680 | frame->url(), |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1681 | inquiry_url, |
| 1682 | &install)); |
| 1683 | return install; |
| 1684 | } |
| 1685 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1686 | void RenderView::OnMissingPluginStatus( |
| 1687 | WebPluginDelegateProxy* delegate, |
| 1688 | int status) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1689 | #if defined(OS_WIN) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1690 | if (!first_default_plugin_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1691 | // Show the InfoBar for the first available plugin. |
| 1692 | if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1693 | first_default_plugin_ = delegate->AsWeakPtr(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1694 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1695 | } |
| 1696 | } else { |
| 1697 | // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar) |
| 1698 | // to start the download/install. |
| 1699 | if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) { |
| 1700 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1701 | } |
| 1702 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1703 | #else |
[email protected] | 76c3b31 | 2010-05-20 21:38:29 | [diff] [blame] | 1704 | // TODO(port): Implement the infobar that accompanies the default plugin. |
| 1705 | // Linux: http://crbug.com/10952 |
| 1706 | // Mac: http://crbug.com/17392 |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1707 | NOTIMPLEMENTED(); |
| 1708 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1709 | } |
| 1710 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1711 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1712 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1713 | WebView* RenderView::createView( |
| 1714 | WebFrame* creator, |
| 1715 | const WebWindowFeatures& features, |
| 1716 | const WebString& frame_name) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1717 | // Check to make sure we aren't overloading on popups. |
| 1718 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1719 | return NULL; |
| 1720 | |
| 1721 | // This window can't be closed from a window.close() call until we receive a |
| 1722 | // message from the Browser process explicitly allowing it. |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1723 | script_can_close_ = false; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1724 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1725 | ViewHostMsg_CreateWindow_Params params; |
| 1726 | params.opener_id = routing_id_; |
| 1727 | params.user_gesture = creator->isProcessingUserGesture(); |
| 1728 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1729 | params.session_storage_namespace_id = session_storage_namespace_id_; |
| 1730 | params.frame_name = frame_name; |
| 1731 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1732 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1733 | int64 cloned_session_storage_namespace_id; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1734 | bool opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1735 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1736 | render_thread_->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1737 | new ViewHostMsg_CreateWindow(params, |
| 1738 | &routing_id, |
| 1739 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1740 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1741 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1742 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1743 | RenderView* view = RenderView::Create(render_thread_, |
[email protected] | 659f73fa | 2009-10-13 13:43:42 | [diff] [blame] | 1744 | 0, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1745 | routing_id_, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1746 | renderer_preferences_, |
| 1747 | webkit_preferences_, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1748 | shared_popup_counter_, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1749 | routing_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1750 | cloned_session_storage_namespace_id, |
| 1751 | frame_name); |
| 1752 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1753 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1754 | // Record whether the creator frame is trying to suppress the opener field. |
| 1755 | view->opener_suppressed_ = opener_suppressed; |
| 1756 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1757 | // Record the security origin of the creator. |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 1758 | GURL creator_url(creator->securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1759 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1760 | creator_url = GURL(); |
| 1761 | view->creator_url_ = creator_url; |
| 1762 | |
| 1763 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1764 | // the new render view (we don't need the browser to send the URL back down). |
| 1765 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1766 | |
| 1767 | return view->webview(); |
| 1768 | } |
| 1769 | |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1770 | WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1771 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1772 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1773 | popup_type); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1774 | return widget->webwidget(); |
| 1775 | } |
| 1776 | |
| 1777 | WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) { |
| 1778 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1779 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1780 | WebKit::WebPopupTypeSelect); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1781 | widget->ConfigureAsExternalPopupMenu(info); |
| 1782 | return widget->webwidget(); |
| 1783 | } |
| 1784 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 1785 | WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) { |
| 1786 | RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_, |
| 1787 | render_thread_, |
| 1788 | popup_type); |
| 1789 | return widget->webwidget(); |
| 1790 | } |
| 1791 | |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1792 | pepper::FullscreenContainer* RenderView::CreatePepperFullscreenContainer( |
| 1793 | pepper::PluginInstance* plugin) { |
| 1794 | RenderWidgetFullscreenPepper* widget = |
| 1795 | RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin); |
| 1796 | widget->show(WebKit::WebNavigationPolicyIgnore); |
| 1797 | return widget->container(); |
| 1798 | } |
| 1799 | |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1800 | WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) { |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1801 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1802 | return WebStorageNamespace::createSessionStorageNamespace(quota); |
[email protected] | 59afea1 | 2010-01-20 04:48:29 | [diff] [blame] | 1803 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
| 1804 | return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION, |
| 1805 | session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1806 | } |
| 1807 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1808 | void RenderView::didAddMessageToConsole( |
| 1809 | const WebConsoleMessage& message, const WebString& source_name, |
| 1810 | unsigned source_line) { |
| 1811 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
| 1812 | UTF16ToWideHack(message.text), |
| 1813 | static_cast<int32>(source_line), |
| 1814 | UTF16ToWideHack(source_name))); |
| 1815 | } |
| 1816 | |
| 1817 | void RenderView::printPage(WebFrame* frame) { |
[email protected] | 71a1426 | 2009-09-22 20:02:58 | [diff] [blame] | 1818 | DCHECK(frame); |
| 1819 | Print(frame, true); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1820 | } |
| 1821 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 1822 | WebKit::WebNotificationPresenter* RenderView::notificationPresenter() { |
| 1823 | return notification_provider_.get(); |
| 1824 | } |
| 1825 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1826 | void RenderView::didStartLoading() { |
| 1827 | if (is_loading_) { |
| 1828 | DLOG(WARNING) << "didStartLoading called while loading"; |
| 1829 | return; |
| 1830 | } |
| 1831 | |
| 1832 | is_loading_ = true; |
| 1833 | // Clear the pointer so that we can assign it only when there is an unknown |
| 1834 | // plugin on a page. |
| 1835 | first_default_plugin_.reset(); |
| 1836 | |
| 1837 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
| 1838 | } |
| 1839 | |
| 1840 | void RenderView::didStopLoading() { |
| 1841 | if (!is_loading_) { |
| 1842 | DLOG(WARNING) << "DidStopLoading called while not loading"; |
| 1843 | return; |
| 1844 | } |
| 1845 | |
| 1846 | is_loading_ = false; |
| 1847 | |
| 1848 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1849 | // when done loading. This currently isn't an issue as the favicon is only |
| 1850 | // displayed when done loading. Ideally we would send notification when |
| 1851 | // finished parsing the head, but webkit doesn't support that yet. |
| 1852 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1853 | GURL favicon_url(webview()->mainFrame()->favIconURL()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1854 | if (!favicon_url.is_empty()) |
| 1855 | Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url)); |
| 1856 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1857 | AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(), |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1858 | ViewHostMsg_PageHasOSDD_Type::Autodetected()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1859 | |
| 1860 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1861 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 1862 | MessageLoop::current()->PostDelayedTask( |
| 1863 | FROM_HERE, |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1864 | page_info_method_factory_.NewRunnableMethod( |
| 1865 | &RenderView::CapturePageInfo, page_id_, false), |
[email protected] | 5ddfd63e | 2010-09-01 15:48:37 | [diff] [blame] | 1866 | send_content_state_immediately_ ? 0 : kDelayForCaptureMs); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1867 | } |
| 1868 | |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 1869 | bool RenderView::isSmartInsertDeleteEnabled() { |
| 1870 | #if defined(OS_MACOSX) |
| 1871 | return true; |
| 1872 | #else |
| 1873 | return false; |
| 1874 | #endif |
| 1875 | } |
| 1876 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1877 | bool RenderView::isSelectTrailingWhitespaceEnabled() { |
| 1878 | #if defined(OS_WIN) |
| 1879 | return true; |
| 1880 | #else |
| 1881 | return false; |
| 1882 | #endif |
| 1883 | } |
| 1884 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1885 | void RenderView::didChangeSelection(bool is_empty_selection) { |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 1886 | #if defined(USE_X11) || defined(OS_MACOSX) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1887 | if (!handling_input_event_) |
| 1888 | return; |
| 1889 | // TODO(estade): investigate incremental updates to the selection so that we |
| 1890 | // don't send the entire selection over IPC every time. |
| 1891 | if (!is_empty_selection) { |
| 1892 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 1893 | // the selection hasn't actually changed. We don't want to report these |
| 1894 | // because it will cause us to continually claim the X clipboard. |
| 1895 | const std::string& this_selection = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1896 | webview()->focusedFrame()->selectionAsText().utf8(); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1897 | if (this_selection == last_selection_) |
| 1898 | return; |
| 1899 | |
| 1900 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 1901 | this_selection)); |
| 1902 | last_selection_ = this_selection; |
| 1903 | } else { |
| 1904 | last_selection_.clear(); |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 1905 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 1906 | last_selection_)); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1907 | } |
| 1908 | #endif |
| 1909 | } |
| 1910 | |
| 1911 | void RenderView::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1912 | const std::string& name = UTF16ToUTF8(command_name); |
| 1913 | if (StartsWithASCII(name, "Move", true) || |
| 1914 | StartsWithASCII(name, "Insert", true) || |
| 1915 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1916 | return; |
| 1917 | UserMetricsRecordAction(name); |
| 1918 | } |
| 1919 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1920 | void RenderView::textFieldDidEndEditing( |
| 1921 | const WebKit::WebInputElement& element) { |
| 1922 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1923 | password_autocomplete_manager_->TextFieldDidEndEditing(element); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1924 | #endif |
| 1925 | } |
| 1926 | |
| 1927 | void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) { |
| 1928 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1929 | // We post a task for doing the AutoFill as the caret position is not set |
| 1930 | // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and |
| 1931 | // it is needed to trigger autofill. |
| 1932 | autofill_method_factory_.RevokeAll(); |
| 1933 | MessageLoop::current()->PostTask( |
| 1934 | FROM_HERE, |
| 1935 | autofill_method_factory_.NewRunnableMethod( |
| 1936 | &RenderView::TextFieldDidChangeImpl, element)); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1937 | #endif |
| 1938 | } |
| 1939 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1940 | void RenderView::TextFieldDidChangeImpl( |
| 1941 | const WebKit::WebInputElement& element) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1942 | if (password_autocomplete_manager_->TextDidChangeInTextField(element)) |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1943 | return; |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1944 | autofill_helper_->TextDidChangeInTextField(element); |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1945 | } |
| 1946 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1947 | void RenderView::textFieldDidReceiveKeyDown( |
| 1948 | const WebKit::WebInputElement& element, |
| 1949 | const WebKit::WebKeyboardEvent& event) { |
| 1950 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1951 | password_autocomplete_manager_->TextFieldHandlingKeyDown(element, event); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1952 | #endif |
| 1953 | } |
| 1954 | |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1955 | bool RenderView::handleCurrentKeyboardEvent() { |
| 1956 | if (edit_commands_.empty()) |
| 1957 | return false; |
| 1958 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1959 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1960 | if (!frame) |
| 1961 | return false; |
| 1962 | |
| 1963 | EditCommands::iterator it = edit_commands_.begin(); |
| 1964 | EditCommands::iterator end = edit_commands_.end(); |
| 1965 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1966 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1967 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 1968 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 1969 | // key (but it's the exception). Once one edit command is not executed, it |
| 1970 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1971 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 1972 | WebString::fromUTF8(it->value))) |
| 1973 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1974 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1975 | } |
| 1976 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1977 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1978 | } |
| 1979 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1980 | void RenderView::inputElementClicked(const WebKit::WebInputElement& element, |
| 1981 | bool already_focused) { |
| 1982 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1983 | if (password_autocomplete_manager_->InputElementClicked(element, |
| 1984 | already_focused)) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1985 | return; |
| 1986 | } |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1987 | autofill_helper_->InputElementClicked(element, already_focused); |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1988 | #endif |
| 1989 | } |
| 1990 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1991 | void RenderView::spellCheck(const WebString& text, |
| 1992 | int& misspelled_offset, |
| 1993 | int& misspelled_length) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1994 | EnsureDocumentTag(); |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1995 | |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1996 | string16 word(text); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1997 | RenderThread* thread = RenderThread::current(); |
| 1998 | // Will be NULL during unit tests. |
| 1999 | if (thread) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2000 | thread->spellchecker()->SpellCheckWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2001 | word.c_str(), word.size(), document_tag_, |
| 2002 | &misspelled_offset, &misspelled_length, NULL); |
| 2003 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | WebString RenderView::autoCorrectWord(const WebKit::WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2007 | string16 autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2008 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | b86c8c1 | 2009-10-05 22:01:26 | [diff] [blame] | 2009 | if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2010 | EnsureDocumentTag(); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2011 | RenderThread* thread = RenderThread::current(); |
| 2012 | // Will be NULL during unit tests. |
| 2013 | if (thread) { |
| 2014 | autocorrect_word = |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2015 | thread->spellchecker()->GetAutoCorrectionWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2016 | word, document_tag_); |
| 2017 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2018 | } |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2019 | return autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2020 | } |
| 2021 | |
[email protected] | c49085c7 | 2009-10-02 16:28:56 | [diff] [blame] | 2022 | void RenderView::showSpellingUI(bool show) { |
| 2023 | Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show)); |
| 2024 | } |
| 2025 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2026 | bool RenderView::isShowingSpellingUI() { |
| 2027 | return spelling_panel_visible_; |
| 2028 | } |
| 2029 | |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2030 | void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2031 | Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
| 2032 | word)); |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2033 | } |
| 2034 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2035 | bool RenderView::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 2036 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2037 | WebFileChooserCompletion* chooser_completion) { |
| 2038 | ViewHostMsg_RunFileChooser_Params ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2039 | if (params.directory) |
| 2040 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; |
| 2041 | else if (params.multiSelect) |
| 2042 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple; |
| 2043 | else |
| 2044 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2045 | ipc_params.title = params.title; |
| 2046 | ipc_params.default_file_name = |
| 2047 | webkit_glue::WebStringToFilePath(params.initialValue); |
[email protected] | 09994913 | 2010-09-08 20:24:59 | [diff] [blame] | 2048 | ipc_params.accept_types = params.acceptTypes; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2049 | |
| 2050 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2051 | } |
| 2052 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2053 | void RenderView::runModalAlertDialog( |
| 2054 | WebFrame* frame, const WebString& message) { |
| 2055 | RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert, |
| 2056 | UTF16ToWideHack(message), |
| 2057 | std::wstring(), |
| 2058 | frame->url(), |
| 2059 | NULL); |
| 2060 | } |
| 2061 | |
| 2062 | bool RenderView::runModalConfirmDialog( |
| 2063 | WebFrame* frame, const WebString& message) { |
| 2064 | return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm, |
| 2065 | UTF16ToWideHack(message), |
| 2066 | std::wstring(), |
| 2067 | frame->url(), |
| 2068 | NULL); |
| 2069 | } |
| 2070 | |
| 2071 | bool RenderView::runModalPromptDialog( |
| 2072 | WebFrame* frame, const WebString& message, const WebString& default_value, |
| 2073 | WebString* actual_value) { |
| 2074 | std::wstring result; |
| 2075 | bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt, |
| 2076 | UTF16ToWideHack(message), |
| 2077 | UTF16ToWideHack(default_value), |
| 2078 | frame->url(), |
| 2079 | &result); |
| 2080 | if (ok) |
| 2081 | actual_value->assign(WideToUTF16Hack(result)); |
| 2082 | return ok; |
| 2083 | } |
| 2084 | |
| 2085 | bool RenderView::runModalBeforeUnloadDialog( |
| 2086 | WebFrame* frame, const WebString& message) { |
| 2087 | bool success = false; |
| 2088 | // This is an ignored return value, but is included so we can accept the same |
| 2089 | // response as RunJavaScriptMessage. |
| 2090 | std::wstring ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2091 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2092 | routing_id_, frame->url(), UTF16ToWideHack(message), &success, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2093 | &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2094 | return success; |
| 2095 | } |
| 2096 | |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2097 | void RenderView::showContextMenu( |
| 2098 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2099 | ContextMenuParams params = ContextMenuParams(data); |
| 2100 | if (!params.misspelled_word.empty() && RenderThread::current()) { |
| 2101 | int misspelled_offset, misspelled_length; |
[email protected] | c76a36a | 2010-01-26 22:44:04 | [diff] [blame] | 2102 | bool spelled_right = RenderThread::current()->spellchecker()-> |
| 2103 | SpellCheckWord( |
| 2104 | params.misspelled_word.c_str(), params.misspelled_word.size(), |
| 2105 | document_tag_, |
| 2106 | &misspelled_offset, &misspelled_length, |
| 2107 | ¶ms.dictionary_suggestions); |
| 2108 | if (spelled_right) |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2109 | params.misspelled_word.clear(); |
| 2110 | } |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2111 | // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do |
| 2112 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2113 | // in the context menu. |
| 2114 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2115 | // data encoded images. We should have a way to save them. |
| 2116 | if (params.src_url.spec().size() > chrome::kMaxURLChars) |
| 2117 | params.src_url = GURL(); |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2118 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2119 | } |
| 2120 | |
[email protected] | 52f139e2c | 2010-06-11 16:56:09 | [diff] [blame] | 2121 | bool RenderView::supportsFullscreen() { |
| 2122 | return CommandLine::ForCurrentProcess()->HasSwitch( |
| 2123 | switches::kEnableVideoFullscreen); |
| 2124 | } |
| 2125 | |
| 2126 | void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) { |
| 2127 | NOTIMPLEMENTED(); |
| 2128 | } |
| 2129 | |
| 2130 | void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) { |
| 2131 | NOTIMPLEMENTED(); |
| 2132 | } |
| 2133 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2134 | void RenderView::setStatusText(const WebString& text) { |
| 2135 | } |
| 2136 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2137 | void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2138 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2139 | if (latest_url == target_url_) |
| 2140 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2141 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2142 | // Tell the browser to display a destination link. |
| 2143 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2144 | target_url_status_ == TARGET_PENDING) { |
| 2145 | // If we have a request in-flight, save the URL to be sent when we |
| 2146 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2147 | // any existing pending sends. |
| 2148 | pending_target_url_ = latest_url; |
| 2149 | target_url_status_ = TARGET_PENDING; |
| 2150 | } else { |
| 2151 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2152 | target_url_ = latest_url; |
| 2153 | target_url_status_ = TARGET_INFLIGHT; |
| 2154 | } |
| 2155 | } |
| 2156 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2157 | void RenderView::StartNavStateSyncTimerIfNecessary() { |
| 2158 | int delay; |
| 2159 | if (send_content_state_immediately_) |
| 2160 | delay = 0; |
| 2161 | else if (is_hidden()) |
| 2162 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2163 | else |
| 2164 | delay = kDelaySecondsForContentStateSync; |
| 2165 | |
| 2166 | if (nav_state_sync_timer_.IsRunning()) { |
| 2167 | // The timer is already running. If the delay of the timer maches the amount |
| 2168 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2169 | // gets started with the right delay. |
| 2170 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2171 | return; |
| 2172 | nav_state_sync_timer_.Stop(); |
| 2173 | } |
| 2174 | |
| 2175 | nav_state_sync_timer_.Start( |
| 2176 | TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState); |
| 2177 | } |
| 2178 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2179 | void RenderView::setMouseOverURL(const WebURL& url) { |
| 2180 | mouse_over_url_ = GURL(url); |
| 2181 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2182 | } |
| 2183 | |
| 2184 | void RenderView::setKeyboardFocusURL(const WebURL& url) { |
| 2185 | focus_url_ = GURL(url); |
| 2186 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2187 | } |
| 2188 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2189 | void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) { |
| 2190 | Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text), |
| 2191 | hint)); |
| 2192 | } |
| 2193 | |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2194 | void RenderView::startDragging(const WebDragData& data, |
| 2195 | WebDragOperationsMask mask, |
| 2196 | const WebImage& image, |
| 2197 | const WebPoint& imageOffset) { |
| 2198 | #if WEBKIT_USING_SKIA |
| 2199 | SkBitmap bitmap(image.getSkBitmap()); |
| 2200 | #elif WEBKIT_USING_CG |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 2201 | SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2202 | #endif |
| 2203 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2204 | Send(new ViewHostMsg_StartDragging(routing_id_, |
| 2205 | WebDropData(data), |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2206 | mask, |
| 2207 | bitmap, |
| 2208 | imageOffset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2209 | } |
| 2210 | |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2211 | bool RenderView::acceptsLoadDrops() { |
| 2212 | return renderer_preferences_.can_accept_load_drops; |
| 2213 | } |
| 2214 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2215 | void RenderView::focusNext() { |
| 2216 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2217 | } |
| 2218 | |
| 2219 | void RenderView::focusPrevious() { |
| 2220 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2221 | } |
| 2222 | |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2223 | void RenderView::focusedNodeChanged(const WebNode& node) { |
| 2224 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_)); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 2225 | |
| 2226 | if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { |
| 2227 | // TODO(ctguil): Make WebKit send this notification. |
| 2228 | // When focus is cleared notify accessibility that the document is focused. |
| 2229 | postAccessibilityNotification( |
| 2230 | webview()->accessibilityObject(), |
| 2231 | WebKit::WebAccessibilityNotificationFocusedUIElementChanged); |
| 2232 | } |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2233 | } |
| 2234 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2235 | void RenderView::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2236 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2237 | } |
| 2238 | |
| 2239 | int RenderView::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2240 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | int RenderView::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2244 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2245 | } |
| 2246 | |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2247 | void RenderView::didUpdateInspectorSetting(const WebString& key, |
| 2248 | const WebString& value) { |
| 2249 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2250 | key.utf8(), |
| 2251 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2252 | } |
| 2253 | |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 2254 | void RenderView::queryAutofillSuggestions(const WebNode& node, |
| 2255 | const WebString& name, |
| 2256 | const WebString& value) { |
[email protected] | a5e84bd | 2010-09-14 22:23:36 | [diff] [blame] | 2257 | autofill_helper_->QueryAutoFillSuggestions(node); |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | void RenderView::removeAutofillSuggestions(const WebString& name, |
| 2261 | const WebString& value) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2262 | autofill_helper_->RemoveAutocompleteSuggestion(name, value); |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 2263 | } |
| 2264 | |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2265 | void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node, |
| 2266 | const WebKit::WebString& value, |
[email protected] | 1cf47dd5 | 2010-06-10 22:41:20 | [diff] [blame] | 2267 | const WebKit::WebString& label, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 2268 | int unique_id, |
[email protected] | 1cf47dd5 | 2010-06-10 22:41:20 | [diff] [blame] | 2269 | unsigned index) { |
[email protected] | a5e84bd | 2010-09-14 22:23:36 | [diff] [blame] | 2270 | autofill_helper_->DidAcceptAutoFillSuggestion(node, value, unique_id, index); |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2271 | } |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2272 | |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2273 | void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node, |
| 2274 | const WebKit::WebString& value, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 2275 | const WebKit::WebString& label, |
| 2276 | int unique_id) { |
[email protected] | a5e84bd | 2010-09-14 22:23:36 | [diff] [blame] | 2277 | autofill_helper_->DidSelectAutoFillSuggestion(node, unique_id); |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2281 | autofill_helper_->DidClearAutoFillSelection(node); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2282 | } |
| 2283 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2284 | void RenderView::didAcceptAutocompleteSuggestion( |
| 2285 | const WebKit::WebInputElement& user_element) { |
| 2286 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2287 | bool result = password_autocomplete_manager_->FillPassword(user_element); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2288 | // Since this user name was selected from a suggestion list, we should always |
| 2289 | // have password for it. |
| 2290 | DCHECK(result); |
| 2291 | #endif |
| 2292 | } |
| 2293 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2294 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2295 | |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2296 | void RenderView::didFocus() { |
| 2297 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2298 | // we won't have to test for user gesture anymore and we can |
| 2299 | // move that code back to render_widget.cc |
| 2300 | if (webview() && webview()->mainFrame() && |
| 2301 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2302 | Send(new ViewHostMsg_Focus(routing_id_)); |
| 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | void RenderView::didBlur() { |
| 2307 | // TODO(jcivelli): see TODO above in didFocus(). |
| 2308 | if (webview() && webview()->mainFrame() && |
| 2309 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2310 | Send(new ViewHostMsg_Blur(routing_id_)); |
| 2311 | } |
| 2312 | } |
| 2313 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2314 | // We are supposed to get a single call to Show for a newly created RenderView |
| 2315 | // that was created via RenderView::CreateWebView. So, we wait until this |
| 2316 | // point to dispatch the ShowView message. |
| 2317 | // |
| 2318 | // This method provides us with the information about how to display the newly |
| 2319 | // created RenderView (i.e., as a constrained popup or as a new tab). |
| 2320 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2321 | void RenderView::show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2322 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 2323 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2324 | |
| 2325 | if (did_show_) |
| 2326 | return; |
| 2327 | did_show_ = true; |
| 2328 | |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 2329 | // Extensions and apps always allowed to create unrequested popups. The second |
| 2330 | // check is necessary to include content scripts. |
| 2331 | if (ExtensionRendererInfo::GetByURL(creator_url_) || |
| 2332 | bindings_utils::GetInfoForCurrentContext()) { |
| 2333 | opened_by_user_gesture_ = true; |
| 2334 | } |
| 2335 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2336 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2337 | if (!opened_by_user_gesture_) { |
| 2338 | // We exempt background tabs for compat with older versions of Chrome. |
| 2339 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2340 | // we probably don't need this check. |
| 2341 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2342 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2343 | } |
| 2344 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2345 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2346 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2347 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2348 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2349 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2350 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2351 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2352 | } |
| 2353 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2354 | void RenderView::closeWidgetSoon() { |
[email protected] | 7faa5386 | 2010-06-16 00:09:13 | [diff] [blame] | 2355 | // Cancel pending translations so that the translate_helper_ does not attempt |
| 2356 | // to access the WebView. |
| 2357 | translate_helper_.CancelPendingTranslation(); |
| 2358 | |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 2359 | if (script_can_close_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2360 | RenderWidget::closeWidgetSoon(); |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 2361 | } |
| 2362 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2363 | void RenderView::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2364 | DCHECK(did_show_) << "should already have shown the view"; |
| 2365 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2366 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2367 | // showModalDialog to function properly. |
| 2368 | // |
| 2369 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2370 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2371 | // handed manner. |
| 2372 | // |
| 2373 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 2374 | RenderThread::current()->DoNotSuspendWebKitSharedTimer(); |
| 2375 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2376 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2377 | } |
| 2378 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2379 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2380 | |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 2381 | WebPlugin* RenderView::createPlugin(WebFrame* frame, |
| 2382 | const WebPluginParams& params) { |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2383 | bool found = false; |
| 2384 | ContentSetting setting = CONTENT_SETTING_DEFAULT; |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2385 | CommandLine* cmd = CommandLine::ForCurrentProcess(); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2386 | WebPluginInfo info; |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2387 | GURL url(params.url); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2388 | std::string actual_mime_type; |
| 2389 | Send(new ViewHostMsg_GetPluginInfo(url, |
| 2390 | frame->top()->url(), |
| 2391 | params.mimeType.utf8(), |
| 2392 | &found, |
| 2393 | &info, |
| 2394 | &setting, |
| 2395 | &actual_mime_type)); |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2396 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2397 | if (!found) |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 2398 | return NULL; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2399 | DCHECK(setting != CONTENT_SETTING_DEFAULT); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 2400 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2401 | scoped_ptr<PluginGroup> group(PluginGroup::CopyOrCreatePluginGroup(info)); |
| 2402 | group->AddPlugin(info, 0); |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2403 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2404 | if (!info.enabled) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2405 | if (cmd->HasSwitch(switches::kDisableOutdatedPlugins) && |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2406 | group->IsVulnerable()) { |
| 2407 | Send(new ViewHostMsg_DisabledOutdatedPlugin(routing_id_, |
| 2408 | group->GetGroupName(), |
| 2409 | GURL(group->GetUpdateURL()))); |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 2410 | return CreateOutdatedPluginPlaceholder(frame, params, group.get()); |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2411 | } |
| 2412 | return NULL; |
| 2413 | } |
| 2414 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2415 | if (info.path.value() == kDefaultPluginLibraryName || |
| 2416 | setting == CONTENT_SETTING_ALLOW) { |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2417 | scoped_refptr<pepper::PluginModule> pepper_module = |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2418 | PepperPluginRegistry::GetInstance()->GetModule(info.path); |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2419 | if (pepper_module) { |
| 2420 | return CreatePepperPlugin(frame, |
| 2421 | params, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2422 | info.path, |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2423 | pepper_module.get()); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2424 | } |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2425 | return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type); |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 2426 | } |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2427 | std::string resource; |
| 2428 | if (cmd->HasSwitch(switches::kEnableResourceContentSettings)) |
| 2429 | resource = group->identifier(); |
| 2430 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource); |
| 2431 | int resource_id; |
| 2432 | int message_id; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2433 | if (setting == CONTENT_SETTING_ASK) { |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2434 | resource_id = IDR_BLOCKED_PLUGIN_HTML; |
| 2435 | message_id = IDS_PLUGIN_LOAD; |
| 2436 | } else { |
| 2437 | resource_id = IDR_OUTDATED_PLUGIN_HTML; |
| 2438 | message_id = IDS_PLUGIN_BLOCKED; |
| 2439 | } |
| 2440 | // |blocked_plugin| will delete itself when the WebViewPlugin |
| 2441 | // is destroyed. |
| 2442 | BlockedPlugin* blocked_plugin = |
| 2443 | new BlockedPlugin(this, |
| 2444 | frame, |
| 2445 | params, |
| 2446 | webkit_preferences_, |
| 2447 | resource_id, |
| 2448 | l10n_util::GetStringUTF16(message_id)); |
| 2449 | return blocked_plugin->plugin(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { |
[email protected] | 14396e9 | 2010-05-06 20:40:56 | [diff] [blame] | 2453 | WebApplicationCacheHostImpl* appcache_host = |
| 2454 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2455 | int appcache_host_id = appcache_host ? appcache_host->host_id() : 0; |
| 2456 | return new WebWorkerProxy(client, RenderThread::current(), routing_id_, |
| 2457 | appcache_host_id); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2458 | } |
| 2459 | |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2460 | WebSharedWorker* RenderView::createSharedWorker( |
| 2461 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2462 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2463 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2464 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2465 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2466 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2467 | ViewHostMsg_CreateWorker_Params params; |
| 2468 | params.url = url; |
| 2469 | params.is_shared = true; |
| 2470 | params.name = name; |
| 2471 | params.document_id = document_id; |
| 2472 | params.render_view_route_id = routing_id_; |
| 2473 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 2474 | params.parent_appcache_host_id = 0; |
| 2475 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2476 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2477 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2478 | if (url_mismatch) { |
| 2479 | return NULL; |
| 2480 | } else { |
| 2481 | return new WebSharedWorkerProxy(RenderThread::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2482 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2483 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2484 | route_id, |
| 2485 | routing_id_); |
| 2486 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2487 | } |
| 2488 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2489 | WebMediaPlayer* RenderView::createMediaPlayer( |
| 2490 | WebFrame* frame, WebMediaPlayerClient* client) { |
| 2491 | scoped_refptr<media::FilterFactoryCollection> factory = |
| 2492 | new media::FilterFactoryCollection(); |
| 2493 | // Add in any custom filter factories first. |
| 2494 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 2495 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
| 2496 | // Add the chrome specific audio renderer. |
| 2497 | factory->AddFactory( |
| 2498 | AudioRendererImpl::CreateFactory(audio_message_filter())); |
| 2499 | } |
| 2500 | |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 2501 | if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) && |
| 2502 | !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { |
| 2503 | // Add the hardware video decoder factory. |
| 2504 | // TODO(hclam): This assumes that ggl::Context is set to current |
| 2505 | // internally. I need to make it more explicit to get the context. |
| 2506 | bool ret = frame->view()->graphicsContext3D()->makeContextCurrent(); |
| 2507 | CHECK(ret) << "Failed to switch context"; |
| 2508 | |
| 2509 | factory->AddFactory(IpcVideoDecoder::CreateFactory( |
[email protected] | 885ff1df | 2010-10-07 21:47:58 | [diff] [blame] | 2510 | MessageLoop::current(), ggl::GetCurrentContext())); |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 2511 | } |
| 2512 | |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2513 | WebApplicationCacheHostImpl* appcache_host = |
| 2514 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2515 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2516 | // TODO(hclam): obtain the following parameters from |client|. |
| 2517 | webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = |
| 2518 | new webkit_glue::MediaResourceLoaderBridgeFactory( |
[email protected] | 7509760e3 | 2010-10-08 21:54:25 | [diff] [blame] | 2519 | GURL(frame->url()), // referrer |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 2520 | "null", // frame origin |
| 2521 | "null", // main_frame_origin |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2522 | base::GetCurrentProcId(), |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2523 | appcache_host ? appcache_host->host_id() : appcache::kNoHostId, |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2524 | routing_id()); |
| 2525 | |
[email protected] | 0436b9a | 2009-10-23 00:23:05 | [diff] [blame] | 2526 | // A simple data source that keeps all data in memory. |
| 2527 | media::FilterFactory* simple_data_source_factory = |
| 2528 | webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(), |
| 2529 | bridge_factory); |
| 2530 | // A sophisticated data source that does memory caching. |
| 2531 | media::FilterFactory* buffered_data_source_factory = |
| 2532 | webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(), |
| 2533 | bridge_factory); |
| 2534 | if (cmd_line->HasSwitch(switches::kSimpleDataSource)) { |
| 2535 | factory->AddFactory(simple_data_source_factory); |
| 2536 | factory->AddFactory(buffered_data_source_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2537 | } else { |
[email protected] | 0436b9a | 2009-10-23 00:23:05 | [diff] [blame] | 2538 | factory->AddFactory(buffered_data_source_factory); |
| 2539 | factory->AddFactory(simple_data_source_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2540 | } |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2541 | |
| 2542 | webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL; |
| 2543 | if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) { |
| 2544 | factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_); |
| 2545 | } else { |
[email protected] | b57509eb | 2010-03-30 01:26:28 | [diff] [blame] | 2546 | bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging); |
| 2547 | factory_factory = |
| 2548 | new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging); |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2552 | } |
| 2553 | |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2554 | WebApplicationCacheHost* RenderView::createApplicationCacheHost( |
| 2555 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
| 2556 | return new RendererWebApplicationCacheHostImpl( |
| 2557 | FromWebView(frame->view()), client, |
| 2558 | RenderThread::current()->appcache_dispatcher()->backend_proxy()); |
| 2559 | } |
| 2560 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 2561 | WebCookieJar* RenderView::cookieJar() { |
| 2562 | return &cookie_jar_; |
| 2563 | } |
| 2564 | |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2565 | void RenderView::frameDetached(WebFrame* frame) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2566 | autofill_helper_->FrameDetached(frame); |
| 2567 | page_click_tracker_->StopTrackingFrame(frame, true); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2568 | } |
| 2569 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2570 | void RenderView::willClose(WebFrame* frame) { |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2571 | WebDataSource* ds = frame->dataSource(); |
| 2572 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2573 | |
| 2574 | if (!frame->parent()) { |
| 2575 | const GURL& url = frame->url(); |
| 2576 | // Ensure state contains scheme. |
| 2577 | if (url.SchemeIs("http")) |
| 2578 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP); |
| 2579 | else if (url.SchemeIs("https")) |
| 2580 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS); |
| 2581 | |
| 2582 | // Dump will only be provided when scheme is http or https. |
| 2583 | DumpLoadHistograms(); |
| 2584 | } |
| 2585 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2586 | navigation_state->user_script_idle_scheduler()->Cancel(); |
[email protected] | 174e60e | 2010-05-06 00:21:16 | [diff] [blame] | 2587 | |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2588 | // TODO(jhawkins): Remove once frameDetached is called by WebKit. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2589 | autofill_helper_->FrameWillClose(frame); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2590 | } |
| 2591 | |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2592 | bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2593 | if (enabled_per_settings && |
| 2594 | AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) |
| 2595 | return true; |
| 2596 | |
| 2597 | if (IsWhitelistedForContentSettings(frame)) |
| 2598 | return true; |
| 2599 | |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2600 | DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2601 | return false; // Other protocols fall through here. |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2602 | } |
| 2603 | |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2604 | bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | a16a421 | 2010-09-01 08:07:46 | [diff] [blame] | 2605 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 2606 | switches::kDisableClickToPlay)) { |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2607 | return WebFrameClient::allowPlugins(frame, enabled_per_settings); |
| 2608 | } |
[email protected] | a16a421 | 2010-09-01 08:07:46 | [diff] [blame] | 2609 | return enabled_per_settings && |
| 2610 | AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS); |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2614 | void RenderView::loadURLExternally( |
| 2615 | WebFrame* frame, const WebURLRequest& request, |
| 2616 | WebNavigationPolicy policy) { |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2617 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2618 | if (policy == WebKit::WebNavigationPolicyDownload) { |
| 2619 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); |
| 2620 | } else { |
| 2621 | OpenURL(request.url(), referrer, policy); |
| 2622 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | WebNavigationPolicy RenderView::decidePolicyForNavigation( |
| 2626 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 2627 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2628 | // Webkit is asking whether to navigate to a new URL. |
| 2629 | // This is fine normally, except if we're showing UI from one security |
| 2630 | // context and they're trying to navigate to a different context. |
| 2631 | const GURL& url = request.url(); |
| 2632 | |
| 2633 | // 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] | 2634 | // navigations. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2635 | if (renderer_preferences_.browser_handles_top_level_requests && |
| 2636 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2637 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
[email protected] | a58db8b | 2010-08-24 01:51:23 | [diff] [blame] | 2638 | // Reset these counters as the RenderView could be reused for the next |
| 2639 | // navigation. |
| 2640 | page_id_ = -1; |
[email protected] | a58db8b | 2010-08-24 01:51:23 | [diff] [blame] | 2641 | last_page_id_sent_to_browser_ = -1; |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2642 | OpenURL(url, referrer, default_policy); |
| 2643 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | // A content initiated navigation may have originated from a link-click, |
| 2647 | // script, drag-n-drop operation, etc. |
| 2648 | bool is_content_initiated = |
| 2649 | NavigationState::FromDataSource(frame->provisionalDataSource())-> |
| 2650 | is_content_initiated(); |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2651 | GURL old_url(frame->url()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2652 | |
| 2653 | // We only care about navigations that are within the current tab (as opposed |
| 2654 | // to, for example, opening a new window). |
| 2655 | // But we sometimes navigate to about:blank to clear a tab, and we want to |
| 2656 | // still allow that. |
| 2657 | if (default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2658 | is_content_initiated && frame->parent() == NULL && |
[email protected] | c240ace | 2010-06-16 18:31:53 | [diff] [blame] | 2659 | type != WebKit::WebNavigationTypeFormSubmitted && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2660 | !url.SchemeIs(chrome::kAboutScheme)) { |
| 2661 | // When we received such unsolicited navigations, we sometimes want to |
| 2662 | // punt them up to the browser to handle. |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2663 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) || |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2664 | frame->isViewSourceModeEnabled() || |
[email protected] | 918059b | 2010-05-25 17:08:42 | [diff] [blame] | 2665 | url.SchemeIs(chrome::kViewSourceScheme)) { |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2666 | // We don't send referrer from these special pages. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2667 | OpenURL(url, GURL(), default_policy); |
| 2668 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2669 | } |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2670 | |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2671 | // We forward non-local navigations from extensions to the browser if they |
| 2672 | // are top-level events, even if the browser hasn't expressed interest. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2673 | // TODO(erikkay) crbug.com/54118 - combine this clause and the next into |
| 2674 | // some shared logic. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2675 | if (BindingsPolicy::is_extension_enabled(enabled_bindings_) && |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2676 | old_url.SchemeIs(chrome::kExtensionScheme) && |
[email protected] | c240ace | 2010-06-16 18:31:53 | [diff] [blame] | 2677 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2678 | // We don't send referrer from extensions. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2679 | OpenURL(url, GURL(), default_policy); |
| 2680 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2681 | } |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2682 | |
| 2683 | // If the navigation would cross an app extent boundary, we also need |
| 2684 | // to defer to the browser to ensure process isolation. |
| 2685 | // TODO(erikkay) This is happening inside of a check to is_content_initiated |
| 2686 | // which means that things like the back button won't trigger it. Is that |
| 2687 | // OK? |
| 2688 | if (CrossesExtensionExtents(frame, url)) { |
| 2689 | // Include the referrer in this case since we're going from a hosted web |
| 2690 | // page. (the packaged case is handled previously by the extension |
| 2691 | // navigation test) |
| 2692 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2693 | OpenURL(url, referrer, default_policy); |
| 2694 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2695 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2699 | // its own process. This is done by sites like Gmail that try to open links |
| 2700 | // in new windows without script connections back to the original page. We |
| 2701 | // treat such cases as browser navigations (in which we will create a new |
| 2702 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2703 | // |
| 2704 | // We use the following heuristic to decide whether to fork a new page in its |
| 2705 | // own process: |
| 2706 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2707 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2708 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2709 | // |
| 2710 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2711 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2712 | bool is_fork = |
| 2713 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2714 | old_url == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2715 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2716 | historyBackListCount() < 1 && |
| 2717 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2718 | // The parent page must have set the child's window.opener to null before |
| 2719 | // redirecting to the desired URL. |
| 2720 | frame->opener() == NULL && |
| 2721 | // Must be a top-level frame. |
| 2722 | frame->parent() == NULL && |
| 2723 | // Must not have issued the request from this page. |
| 2724 | is_content_initiated && |
| 2725 | // Must be targeted at the current tab. |
| 2726 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2727 | // Must be a JavaScript navigation, which appears as "other". |
| 2728 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2729 | |
| 2730 | // Recognize if this navigation is from a link with rel=noreferrer and |
| 2731 | // target=_blank attributes, in which case the opener will be suppressed. If |
| 2732 | // so, it is safe to load cross-site pages in a separate process, so we |
| 2733 | // should let the browser handle it. |
| 2734 | bool is_noreferrer_and_blank_target = |
| 2735 | // Frame should be top level and not yet navigated. |
| 2736 | frame->parent() == NULL && |
| 2737 | frame->url().isEmpty() && |
| 2738 | historyBackListCount() < 1 && |
| 2739 | historyForwardListCount() < 1 && |
| 2740 | // Links with rel=noreferrer will have no Referer field, and their |
| 2741 | // resulting frame will have its window.opener suppressed. |
| 2742 | // TODO(creis): should add a request.httpReferrer() method to help avoid |
| 2743 | // typos on the unusual spelling of Referer. |
| 2744 | request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() && |
| 2745 | opener_suppressed_ && |
| 2746 | frame->opener() == NULL && |
| 2747 | // Links with target=_blank will have no name. |
| 2748 | frame->name().isNull() && |
| 2749 | // Another frame (with a non-empty creator) should have initiated the |
| 2750 | // request, targeted at this frame. |
| 2751 | !creator_url_.is_empty() && |
| 2752 | is_content_initiated && |
| 2753 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2754 | type == WebKit::WebNavigationTypeOther; |
| 2755 | |
| 2756 | if (is_fork || is_noreferrer_and_blank_target) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2757 | // Open the URL via the browser, not via WebKit. |
| 2758 | OpenURL(url, GURL(), default_policy); |
| 2759 | return WebKit::WebNavigationPolicyIgnore; |
| 2760 | } |
| 2761 | |
| 2762 | return default_policy; |
| 2763 | } |
| 2764 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2765 | bool RenderView::canHandleRequest( |
| 2766 | WebFrame* frame, const WebURLRequest& request) { |
| 2767 | // We allow WebKit to think that everything can be handled even though |
| 2768 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2769 | return true; |
| 2770 | } |
| 2771 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2772 | WebURLError RenderView::cannotHandleRequestError( |
| 2773 | WebFrame* frame, const WebURLRequest& request) { |
| 2774 | NOTREACHED(); // Since we said we can handle all requests. |
| 2775 | return WebURLError(); |
| 2776 | } |
| 2777 | |
| 2778 | WebURLError RenderView::cancelledError( |
| 2779 | WebFrame* frame, const WebURLRequest& request) { |
| 2780 | WebURLError error; |
| 2781 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2782 | error.reason = net::ERR_ABORTED; |
| 2783 | error.unreachableURL = request.url(); |
| 2784 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | void RenderView::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2788 | WebFrame*, const WebURLError&) { |
| 2789 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2790 | } |
| 2791 | |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2792 | void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame, |
| 2793 | const WebKit::WebFormElement& form) { |
| 2794 | // Some login forms have onSubmit handlers that put a hash of the password |
| 2795 | // into a hidden field and then clear the password. (Issue 28910.) |
| 2796 | // This method gets called before any of those handlers run, so save away |
| 2797 | // a copy of the password in case it gets lost. |
| 2798 | NavigationState* navigation_state = |
| 2799 | NavigationState::FromDataSource(frame->dataSource()); |
| 2800 | navigation_state->set_password_form_data( |
| 2801 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 2802 | } |
| 2803 | |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 2804 | void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2805 | NavigationState* navigation_state = |
| 2806 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2807 | |
| 2808 | if (navigation_state->transition_type() == PageTransition::LINK) |
| 2809 | navigation_state->set_transition_type(PageTransition::FORM_SUBMIT); |
| 2810 | |
| 2811 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2812 | WebSearchableFormData web_searchable_form_data(form); |
| 2813 | navigation_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2814 | navigation_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2815 | web_searchable_form_data.encoding().utf8()); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2816 | PasswordForm* password_form_data = |
| 2817 | PasswordFormDomManager::CreatePasswordForm(form); |
| 2818 | navigation_state->set_password_form_data(password_form_data); |
| 2819 | |
| 2820 | // If the password has been cleared, recover it from the form contents already |
| 2821 | // stored by willSendSubmitEvent into the dataSource's NavigationState (as |
| 2822 | // opposed to the provisionalDataSource's, which is what we're storing into |
| 2823 | // now.) |
| 2824 | if (password_form_data && password_form_data->password_value.empty()) { |
| 2825 | NavigationState* old_navigation_state = |
| 2826 | NavigationState::FromDataSource(frame->dataSource()); |
| 2827 | if (old_navigation_state) { |
| 2828 | PasswordForm* old_form_data = old_navigation_state->password_form_data(); |
| 2829 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 2830 | password_form_data->password_value = old_form_data->password_value; |
| 2831 | } |
| 2832 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2833 | |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2834 | FormData form_data; |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 2835 | if (FormManager::WebFormElementToFormData( |
[email protected] | 1fa7b48 | 2010-10-01 18:28:58 | [diff] [blame] | 2836 | form, FormManager::REQUIRE_AUTOCOMPLETE, true, false, &form_data)) |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2837 | Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | void RenderView::willPerformClientRedirect( |
| 2841 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2842 | double fire_time) { |
| 2843 | // Ignore |
| 2844 | } |
| 2845 | |
| 2846 | void RenderView::didCancelClientRedirect(WebFrame* frame) { |
| 2847 | // Ignore |
| 2848 | } |
| 2849 | |
| 2850 | void RenderView::didCompleteClientRedirect( |
| 2851 | WebFrame* frame, const WebURL& from) { |
| 2852 | if (!frame->parent()) |
| 2853 | completed_client_redirect_src_ = from; |
| 2854 | } |
| 2855 | |
| 2856 | void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
| 2857 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2858 | // non-null NavigationState. |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 2859 | bool content_initiated = !pending_navigation_state_.get(); |
| 2860 | NavigationState* state = content_initiated ? |
| 2861 | NavigationState::CreateContentInitiated() : |
| 2862 | pending_navigation_state_.release(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2863 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2864 | // NavigationState::referred_by_prefetcher_ is true if we are |
| 2865 | // navigating from a page that used prefetching using a link on that |
| 2866 | // page. We are early enough in the request process here that we |
| 2867 | // can still see the NavigationState of the previous page and set |
| 2868 | // this value appropriately. |
| 2869 | // TODO(gavinp): catch the important case of navigation in a new |
| 2870 | // renderer process. |
| 2871 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2872 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2873 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2874 | const GURL referrer( |
| 2875 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2876 | if (!referrer.is_empty() && |
| 2877 | NavigationState::FromDataSource( |
| 2878 | old_frame->dataSource())->was_prefetcher()) { |
| 2879 | for (;old_frame;old_frame = old_frame->traverseNext(false)) { |
| 2880 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 2881 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
| 2882 | state->set_was_referred_by_prefetcher(true); |
| 2883 | break; |
| 2884 | } |
| 2885 | } |
| 2886 | } |
| 2887 | } |
| 2888 | } |
| 2889 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2890 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2891 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2892 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2893 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
| 2894 | state->set_load_type(NavigationState::LINK_LOAD_NORMAL); |
| 2895 | break; |
| 2896 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
| 2897 | state->set_load_type(NavigationState::LINK_LOAD_RELOAD); |
| 2898 | break; |
| 2899 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
| 2900 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK); |
| 2901 | break; |
| 2902 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
| 2903 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY); |
| 2904 | break; |
| 2905 | } |
| 2906 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2907 | |
| 2908 | state->set_user_script_idle_scheduler( |
| 2909 | new UserScriptIdleScheduler(this, frame)); |
| 2910 | ds->setExtraData(state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | void RenderView::didStartProvisionalLoad(WebFrame* frame) { |
| 2914 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2915 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2916 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2917 | // Update the request time if WebKit has better knowledge of it. |
| 2918 | if (navigation_state->request_time().is_null()) { |
| 2919 | double event_time = ds->triggeringEventTime(); |
| 2920 | if (event_time != 0.0) |
| 2921 | navigation_state->set_request_time(Time::FromDoubleT(event_time)); |
| 2922 | } |
| 2923 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2924 | // Start time is only set after request time. |
| 2925 | navigation_state->set_start_load_time(Time::Now()); |
| 2926 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2927 | bool is_top_most = !frame->parent(); |
| 2928 | if (is_top_most) { |
| 2929 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
| 2930 | NavigationGestureUnknown : NavigationGestureAuto; |
| 2931 | |
| 2932 | // Make sure redirect tracking state is clear for the new load. |
| 2933 | completed_client_redirect_src_ = GURL(); |
| 2934 | } else if (frame->parent()->isLoading()) { |
| 2935 | // 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] | 2936 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2937 | navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME); |
| 2938 | } |
| 2939 | |
| 2940 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 2941 | routing_id_, frame->identifier(), is_top_most, ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) { |
| 2945 | if (frame->parent()) |
| 2946 | return; |
| 2947 | // Received a redirect on the main frame. |
| 2948 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 2949 | if (!data_source) { |
| 2950 | // Should only be invoked when we have a data source. |
| 2951 | NOTREACHED(); |
| 2952 | return; |
| 2953 | } |
| 2954 | std::vector<GURL> redirects; |
| 2955 | GetRedirectChain(data_source, &redirects); |
| 2956 | if (redirects.size() >= 2) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2957 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
| 2958 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2959 | } |
| 2960 | } |
| 2961 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2962 | void RenderView::didFailProvisionalLoad(WebFrame* frame, |
| 2963 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2964 | // Notify the browser that we failed a provisional load with an error. |
| 2965 | // |
| 2966 | // Note: It is important this notification occur before DidStopLoading so the |
| 2967 | // SSL manager can react to the provisional load failure before being |
| 2968 | // notified the load stopped. |
| 2969 | // |
| 2970 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2971 | DCHECK(ds); |
| 2972 | |
| 2973 | const WebURLRequest& failed_request = ds->request(); |
| 2974 | |
| 2975 | bool show_repost_interstitial = |
| 2976 | (error.reason == net::ERR_CACHE_MISS && |
| 2977 | EqualsASCII(failed_request.httpMethod(), "POST")); |
| 2978 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 2979 | routing_id_, frame->identifier(), !frame->parent(), error.reason, |
| 2980 | error.unreachableURL, show_repost_interstitial)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2981 | |
| 2982 | // Don't display an error page if this is simply a cancelled load. Aside |
| 2983 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 2984 | if (error.reason == net::ERR_ABORTED) |
| 2985 | return; |
| 2986 | |
| 2987 | // Make sure we never show errors in view source mode. |
| 2988 | frame->enableViewSourceMode(false); |
| 2989 | |
| 2990 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2991 | |
| 2992 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 2993 | // 'replace' load. This is necessary to avoid messing up session history. |
| 2994 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 2995 | // as session history is concerned. |
| 2996 | // |
| 2997 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 2998 | // the page id. |
| 2999 | // |
| 3000 | bool replace = |
| 3001 | navigation_state->pending_page_id() != -1 || |
| 3002 | navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME; |
| 3003 | |
| 3004 | // If we failed on a browser initiated request, then make sure that our error |
| 3005 | // page load is regarded as the same browser initiated request. |
| 3006 | if (!navigation_state->is_content_initiated()) { |
| 3007 | pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( |
| 3008 | navigation_state->pending_page_id(), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3009 | navigation_state->pending_history_list_offset(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3010 | navigation_state->transition_type(), |
| 3011 | navigation_state->request_time())); |
| 3012 | } |
| 3013 | |
| 3014 | // Provide the user with a more helpful error page? |
| 3015 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 3016 | return; |
| 3017 | |
| 3018 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3019 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | void RenderView::didReceiveDocumentData( |
| 3023 | WebFrame* frame, const char* data, size_t data_len, |
| 3024 | bool& prevent_default) { |
| 3025 | NavigationState* navigation_state = |
| 3026 | NavigationState::FromDataSource(frame->dataSource()); |
| 3027 | if (!navigation_state->postpone_loading_data()) |
| 3028 | return; |
| 3029 | |
| 3030 | // We're going to call commitDocumentData ourselves... |
| 3031 | prevent_default = true; |
| 3032 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3033 | // Continue buffering the response data for the original error page. If it |
| 3034 | // grows too large, then we'll just let it through. For any error other than |
| 3035 | // a 404, "too large" means any data at all. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3036 | navigation_state->append_postponed_data(data, data_len); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3037 | if (navigation_state->postponed_data().size() >= 512 || |
| 3038 | navigation_state->http_status_code() != 404) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3039 | navigation_state->set_postpone_loading_data(false); |
| 3040 | frame->commitDocumentData(navigation_state->postponed_data().data(), |
| 3041 | navigation_state->postponed_data().size()); |
| 3042 | navigation_state->clear_postponed_data(); |
| 3043 | } |
| 3044 | } |
| 3045 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3046 | void RenderView::didCommitProvisionalLoad(WebFrame* frame, |
| 3047 | bool is_new_navigation) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3048 | NavigationState* navigation_state = |
| 3049 | NavigationState::FromDataSource(frame->dataSource()); |
| 3050 | |
| 3051 | navigation_state->set_commit_load_time(Time::Now()); |
| 3052 | if (is_new_navigation) { |
| 3053 | // When we perform a new navigation, we need to update the previous session |
| 3054 | // history entry with state for the page we are leaving. |
| 3055 | UpdateSessionHistory(frame); |
| 3056 | |
| 3057 | // We bump our Page ID to correspond with the new session history entry. |
| 3058 | page_id_ = next_page_id_++; |
| 3059 | |
[email protected] | d64b07b | 2010-04-20 22:14:06 | [diff] [blame] | 3060 | // Any pending translation is now obsolete. |
| 3061 | translate_helper_.CancelPendingTranslation(); |
| 3062 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3063 | // Advance our offset in session history, applying the length limit. There |
| 3064 | // is now no forward history. |
| 3065 | history_list_offset_++; |
| 3066 | if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries) |
| 3067 | history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1; |
| 3068 | history_list_length_ = history_list_offset_ + 1; |
| 3069 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 3070 | MessageLoop::current()->PostDelayedTask( |
| 3071 | FROM_HERE, |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 3072 | page_info_method_factory_.NewRunnableMethod( |
| 3073 | &RenderView::CapturePageInfo, page_id_, true), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3074 | kDelayForForcedCaptureMs); |
| 3075 | } else { |
| 3076 | // Inspect the navigation_state on this frame to see if the navigation |
| 3077 | // corresponds to a session history navigation... Note: |frame| may or |
| 3078 | // may not be the toplevel frame, but for the case of capturing session |
| 3079 | // history, the first committed frame suffices. We keep track of whether |
| 3080 | // we've seen this commit before so that only capture session history once |
| 3081 | // per navigation. |
| 3082 | // |
| 3083 | // Note that we need to check if the page ID changed. In the case of a |
| 3084 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 3085 | // previous URL and the current page ID, which would be wrong. |
| 3086 | if (navigation_state->pending_page_id() != -1 && |
| 3087 | navigation_state->pending_page_id() != page_id_ && |
| 3088 | !navigation_state->request_committed()) { |
| 3089 | // This is a successful session history navigation! |
| 3090 | UpdateSessionHistory(frame); |
| 3091 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3092 | |
| 3093 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | // Remember that we've already processed this request, so we don't update |
| 3098 | // the session history again. We do this regardless of whether this is |
| 3099 | // a session history navigation, because if we attempted a session history |
| 3100 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3101 | // new navigation. |
| 3102 | navigation_state->set_request_committed(true); |
| 3103 | |
| 3104 | UpdateURL(frame); |
| 3105 | |
| 3106 | // If this committed load was initiated by a client redirect, we're |
| 3107 | // at the last stop now, so clear it. |
| 3108 | completed_client_redirect_src_ = GURL(); |
| 3109 | |
| 3110 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3111 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | void RenderView::didClearWindowObject(WebFrame* frame) { |
| 3115 | if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_)) |
| 3116 | BindDOMAutomationController(frame); |
[email protected] | 0d7ae86 | 2010-10-01 13:52:45 | [diff] [blame] | 3117 | GURL frame_url = frame->url(); |
| 3118 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) && |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 3119 | (frame_url.SchemeIs(chrome::kChromeUIScheme) || |
[email protected] | 731ae51 | 2010-10-15 18:20:17 | [diff] [blame] | 3120 | frame_url.SchemeIs(chrome::kGearsScheme) || |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 3121 | frame_url.SchemeIs(chrome::kDataScheme))) { |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3122 | GetDOMUIBindings()->set_message_sender(this); |
| 3123 | GetDOMUIBindings()->set_routing_id(routing_id_); |
| 3124 | GetDOMUIBindings()->BindToJavascript(frame, L"chrome"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3125 | } |
| 3126 | if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) { |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3127 | GetExternalHostBindings()->set_message_sender(this); |
| 3128 | GetExternalHostBindings()->set_routing_id(routing_id_); |
| 3129 | GetExternalHostBindings()->BindToJavascript(frame, L"externalHost"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3130 | } |
| 3131 | } |
| 3132 | |
| 3133 | void RenderView::didCreateDocumentElement(WebFrame* frame) { |
| 3134 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3135 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3136 | frame, UserScript::DOCUMENT_START); |
| 3137 | } |
| 3138 | |
| 3139 | // Notify the browser about non-blank documents loading in the top frame. |
| 3140 | GURL url = frame->url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 3141 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3142 | if (frame == webview()->mainFrame()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3143 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { |
| 3148 | UpdateTitle(frame, title); |
| 3149 | |
| 3150 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3151 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3152 | } |
| 3153 | |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3154 | void RenderView::didChangeIcons(WebFrame* frame) { |
| 3155 | if (!frame->parent()) { |
| 3156 | Send(new ViewHostMsg_UpdateFavIconURL( |
| 3157 | routing_id_, |
| 3158 | page_id_, |
| 3159 | frame->favIconURL())); |
| 3160 | } |
| 3161 | } |
| 3162 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3163 | void RenderView::didFinishDocumentLoad(WebFrame* frame) { |
| 3164 | WebDataSource* ds = frame->dataSource(); |
| 3165 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3166 | DCHECK(navigation_state); |
| 3167 | navigation_state->set_finish_document_load_time(Time::Now()); |
| 3168 | |
| 3169 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_)); |
| 3170 | |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3171 | page_click_tracker_->StartTrackingFrame(frame); |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 3172 | // The document has now been fully loaded. Scan for forms to be sent up to |
| 3173 | // the browser. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3174 | autofill_helper_->FrameContentsAvailable(frame); |
| 3175 | password_autocomplete_manager_->SendPasswordForms(frame, false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3176 | |
| 3177 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3178 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3179 | |
| 3180 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3181 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3182 | frame, UserScript::DOCUMENT_END); |
| 3183 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3184 | |
| 3185 | navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad(); |
| 3186 | } |
| 3187 | |
| 3188 | void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) { |
| 3189 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3190 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3191 | frame, UserScript::DOCUMENT_IDLE); |
| 3192 | } |
| 3193 | |
| 3194 | WebFrame* main_frame = webview()->mainFrame(); |
| 3195 | if (frame == main_frame) { |
| 3196 | while (!pending_code_execution_queue_.empty()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 3197 | linked_ptr<ViewMsg_ExecuteCode_Params>& params = |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3198 | pending_code_execution_queue_.front(); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 3199 | ExecuteCodeImpl(main_frame, *params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3200 | pending_code_execution_queue_.pop(); |
| 3201 | } |
| 3202 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | void RenderView::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 3206 | if (webview()->mainFrame() == frame) { |
| 3207 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 3208 | page_id_)); |
| 3209 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { |
| 3213 | // Ignore |
| 3214 | } |
| 3215 | |
| 3216 | void RenderView::didFinishLoad(WebFrame* frame) { |
| 3217 | WebDataSource* ds = frame->dataSource(); |
| 3218 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3219 | DCHECK(navigation_state); |
| 3220 | navigation_state->set_finish_load_time(Time::Now()); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3221 | navigation_state->user_script_idle_scheduler()->DidFinishLoad(); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3222 | |
| 3223 | // Let the password manager know which password forms are actually visible. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3224 | password_autocomplete_manager_->SendPasswordForms(frame, true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3225 | } |
| 3226 | |
[email protected] | ccbe04e | 2010-03-17 17:58:43 | [diff] [blame] | 3227 | void RenderView::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3228 | WebFrame* frame, bool is_new_navigation) { |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3229 | // Determine if the UserScriptIdleScheduler already ran scripts on this page, |
| 3230 | // since a new one gets created by didCreateDataSource. |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3231 | NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3232 | bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run(); |
| 3233 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3234 | // If this was a reference fragment navigation that we initiated, then we |
| 3235 | // could end up having a non-null pending navigation state. We just need to |
| 3236 | // update the ExtraData on the datasource so that others who read the |
| 3237 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3238 | // initiate this navigation, then we need to take care to reset any pre- |
| 3239 | // existing navigation state to a content-initiated navigation state. |
| 3240 | // DidCreateDataSource conveniently takes care of this for us. |
| 3241 | didCreateDataSource(frame, frame->dataSource()); |
| 3242 | |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3243 | NavigationState* new_state = |
| 3244 | NavigationState::FromDataSource(frame->dataSource()); |
| 3245 | new_state->set_was_within_same_page(true); |
| 3246 | |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3247 | if (idle_scheduler_ran) { |
| 3248 | // Update the new UserScriptIdleScheduler so we don't re-run scripts. |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3249 | new_state->user_script_idle_scheduler()->set_has_run(true); |
| 3250 | } |
| 3251 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3252 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 3253 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3254 | UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3255 | } |
| 3256 | |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3257 | void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3258 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3259 | } |
| 3260 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3261 | void RenderView::assignIdentifierToRequest( |
| 3262 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 3263 | // Ignore |
| 3264 | } |
| 3265 | |
| 3266 | void RenderView::willSendRequest( |
| 3267 | WebFrame* frame, unsigned identifier, WebURLRequest& request, |
| 3268 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3269 | WebFrame* top_frame = frame->top(); |
| 3270 | if (!top_frame) |
| 3271 | top_frame = frame; |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3272 | WebDataSource* provisional_data_source = top_frame->provisionalDataSource(); |
| 3273 | WebDataSource* top_data_source = top_frame->dataSource(); |
| 3274 | WebDataSource* data_source = |
| 3275 | provisional_data_source ? provisional_data_source : top_data_source; |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3276 | if (data_source) { |
| 3277 | NavigationState* state = NavigationState::FromDataSource(data_source); |
| 3278 | if (state && state->is_cache_policy_override_set()) |
| 3279 | request.setCachePolicy(state->cache_policy_override()); |
| 3280 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3281 | |
| 3282 | if (top_data_source) { |
| 3283 | NavigationState* state = NavigationState::FromDataSource(top_data_source); |
| 3284 | if (state && request.targetType() == WebURLRequest::TargetIsPrefetch) |
| 3285 | state->set_was_prefetcher(true); |
| 3286 | } |
| 3287 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3288 | request.setRequestorID(routing_id_); |
[email protected] | c5bbc245 | 2010-03-08 08:33:50 | [diff] [blame] | 3289 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 3290 | request.clearHTTPHeaderField("Referer"); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3291 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 3292 | // Temporary metrics, see site_isolation_metrics.h |
| 3293 | SiteIsolationMetrics::AddRequest(identifier, request.targetType()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | void RenderView::didReceiveResponse( |
| 3297 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3298 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 3299 | // Temporary metrics, see site_isolation_metrics.h |
| 3300 | SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame, |
| 3301 | identifier, |
| 3302 | response); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3303 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3304 | // Only do this for responses that correspond to a provisional data source |
| 3305 | // of the top-most frame. If we have a provisional data source, then we |
| 3306 | // can't have any sub-resources yet, so we know that this response must |
| 3307 | // correspond to a frame load. |
| 3308 | if (!frame->provisionalDataSource() || frame->parent()) |
| 3309 | return; |
| 3310 | |
| 3311 | // If we are in view source mode, then just let the user see the source of |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3312 | // the server's error page. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3313 | if (frame->isViewSourceModeEnabled()) |
| 3314 | return; |
| 3315 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3316 | NavigationState* navigation_state = |
| 3317 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 3318 | CHECK(navigation_state); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3319 | int http_status_code = response.httpStatusCode(); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3320 | |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3321 | // Record page load flags. |
| 3322 | navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); |
| 3323 | navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated()); |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 3324 | navigation_state->set_was_alternate_protocol_available( |
| 3325 | response.wasAlternateProtocolAvailable()); |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3326 | navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3327 | navigation_state->set_http_status_code(http_status_code); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3328 | |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 3329 | // Consider loading an alternate error page for 404 responses. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3330 | if (http_status_code == 404) { |
| 3331 | // Can we even load an alternate error page for this URL? |
| 3332 | if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid()) |
| 3333 | return; |
| 3334 | } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain, |
| 3335 | http_status_code)) { |
| 3336 | // If no corresponding error strings for a particular status code, just |
| 3337 | // render any received data, regardless of whether or not the status code |
| 3338 | // indicates an error. |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 3339 | return; |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3340 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3341 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3342 | navigation_state->set_postpone_loading_data(true); |
| 3343 | navigation_state->clear_postponed_data(); |
| 3344 | } |
| 3345 | |
| 3346 | void RenderView::didFinishResourceLoad( |
| 3347 | WebFrame* frame, unsigned identifier) { |
| 3348 | NavigationState* navigation_state = |
| 3349 | NavigationState::FromDataSource(frame->dataSource()); |
| 3350 | if (!navigation_state->postpone_loading_data()) |
| 3351 | return; |
| 3352 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3353 | // The server returned an error and the content was < 512 bytes (which we |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3354 | // suppressed). Go ahead and fetch the alternate page content. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3355 | int http_status_code = navigation_state->http_status_code(); |
| 3356 | if (http_status_code == 404) { |
| 3357 | // On 404s, try a remote search page as a fallback. |
| 3358 | const GURL& frame_url = frame->url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3359 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3360 | const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404); |
| 3361 | DCHECK(error_page_url.is_valid()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3362 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3363 | WebURLError original_error; |
| 3364 | original_error.unreachableURL = frame_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3365 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3366 | navigation_state->set_alt_error_page_fetcher( |
| 3367 | new AltErrorPageResourceFetcher( |
| 3368 | error_page_url, frame, original_error, |
| 3369 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 3370 | } else { |
| 3371 | // On other errors, use an internal error page. |
| 3372 | WebURLError error; |
| 3373 | error.unreachableURL = frame->url(); |
| 3374 | error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain); |
| 3375 | error.reason = http_status_code; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3376 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3377 | LoadNavigationErrorPage(frame, frame->dataSource()->request(), error, |
| 3378 | std::string(), true); |
| 3379 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3380 | } |
| 3381 | |
| 3382 | void RenderView::didFailResourceLoad( |
| 3383 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 3384 | // Ignore |
| 3385 | } |
| 3386 | |
| 3387 | void RenderView::didLoadResourceFromMemoryCache( |
| 3388 | WebFrame* frame, const WebURLRequest& request, |
| 3389 | const WebURLResponse& response) { |
| 3390 | // Let the browser know we loaded a resource from the memory cache. This |
| 3391 | // message is needed to display the correct SSL indicators. |
| 3392 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 3393 | routing_id_, |
| 3394 | request.url(), |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 3395 | frame->securityOrigin().toString().utf8(), |
| 3396 | frame->top()->securityOrigin().toString().utf8(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3397 | response.securityInfo())); |
| 3398 | } |
| 3399 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3400 | void RenderView::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3401 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 3402 | } |
| 3403 | |
| 3404 | void RenderView::didRunInsecureContent( |
| 3405 | WebFrame* frame, const WebSecurityOrigin& origin) { |
| 3406 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 3407 | routing_id_, |
| 3408 | origin.toString().utf8())); |
| 3409 | } |
| 3410 | |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3411 | bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 3412 | if (enabled_per_settings && |
| 3413 | AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) |
| 3414 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3415 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 3416 | if (IsWhitelistedForContentSettings(frame)) |
| 3417 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3418 | |
| 3419 | return false; // Other protocols fall through here. |
| 3420 | } |
| 3421 | |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 3422 | bool RenderView::allowDatabase( |
| 3423 | WebFrame* frame, const WebString& name, const WebString& display_name, |
| 3424 | unsigned long estimated_size) { |
| 3425 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 3426 | if (origin.isEmpty()) |
| 3427 | return false; // Uninitialized document? |
| 3428 | |
| 3429 | bool result; |
| 3430 | if (!Send(new ViewHostMsg_AllowDatabase(routing_id_, |
| 3431 | origin.toString().utf8(), name, display_name, estimated_size, &result))) |
| 3432 | return false; |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 3433 | Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_, |
| 3434 | GURL(origin.toString().utf8()), |
| 3435 | name, |
| 3436 | display_name, |
| 3437 | estimated_size, |
| 3438 | !result)); |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 3439 | return result; |
| 3440 | } |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3441 | void RenderView::didNotAllowScript(WebKit::WebFrame* frame) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3442 | DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3443 | } |
| 3444 | |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 3445 | void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3446 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 3447 | } |
| 3448 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3449 | void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
| 3450 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 3451 | } |
| 3452 | |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3453 | void RenderView::didCreateScriptContext(WebFrame* frame) { |
| 3454 | EventBindings::HandleContextCreated(frame, false); |
| 3455 | } |
| 3456 | |
| 3457 | void RenderView::didDestroyScriptContext(WebFrame* frame) { |
| 3458 | EventBindings::HandleContextDestroyed(frame); |
| 3459 | } |
| 3460 | |
| 3461 | void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) { |
| 3462 | EventBindings::HandleContextCreated(frame, true); |
| 3463 | } |
| 3464 | |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 3465 | bool RenderView::allowScriptExtension(WebFrame* frame, |
| 3466 | const WebString& extension_name, |
| 3467 | int extension_group) { |
| 3468 | // NULL in unit tests. |
| 3469 | if (!RenderThread::current()) |
| 3470 | return true; |
| 3471 | |
| 3472 | // Note: we prefer the provisional URL here instead of the document URL |
| 3473 | // because we might be currently loading an URL into a blank page. |
| 3474 | // See http://code.google.com/p/chromium/issues/detail?id=10924 |
| 3475 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3476 | if (!ds) |
| 3477 | ds = frame->dataSource(); |
| 3478 | return RenderThread::current()->AllowScriptExtension( |
| 3479 | extension_name.utf8(), ds->request().url(), extension_group); |
| 3480 | } |
| 3481 | |
[email protected] | fc86daa | 2010-03-30 23:52:53 | [diff] [blame] | 3482 | void RenderView::logCrossFramePropertyAccess(WebFrame* frame, |
| 3483 | WebFrame* target, |
| 3484 | bool cross_origin, |
| 3485 | const WebString& property_name, |
| 3486 | unsigned long long event_id) { |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 3487 | // TODO(johnnyg): track the individual properties and repeat event_ids. |
| 3488 | if (cross_origin) |
| 3489 | cross_origin_access_count_++; |
| 3490 | else |
| 3491 | same_origin_access_count_++; |
| 3492 | } |
| 3493 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3494 | void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) { |
[email protected] | d8a179c | 2010-01-31 00:58:14 | [diff] [blame] | 3495 | CheckPreferredSize(); |
| 3496 | } |
| 3497 | |
| 3498 | void RenderView::CheckPreferredSize() { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3499 | // 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] | 3500 | // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3501 | // message. |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3502 | if (!send_preferred_size_changes_ || !webview()) |
| 3503 | return; |
[email protected] | dfca5acf | 2010-03-22 03:28:43 | [diff] [blame] | 3504 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3505 | // WebCore likes to tell us things have changed even when they haven't, so |
| 3506 | // cache the width and height and only send the IPC message when we're sure |
| 3507 | // they're different. |
| 3508 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 3509 | webview()->mainFrame()->documentElementScrollHeight()); |
| 3510 | if (size == preferred_size_) |
| 3511 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 3512 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3513 | preferred_size_ = size; |
| 3514 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 3515 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3516 | } |
| 3517 | |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3518 | void RenderView::didChangeScrollOffset(WebFrame* frame) { |
| 3519 | StartNavStateSyncTimerIfNecessary(); |
| 3520 | } |
| 3521 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3522 | void RenderView::reportFindInPageMatchCount(int request_id, int count, |
| 3523 | bool final_update) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3524 | int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 3525 | if (!count) |
| 3526 | active_match_ordinal = 0; |
| 3527 | |
| 3528 | IPC::Message* msg = new ViewHostMsg_Find_Reply( |
| 3529 | routing_id_, |
| 3530 | request_id, |
| 3531 | count, |
| 3532 | gfx::Rect(), |
| 3533 | active_match_ordinal, |
| 3534 | final_update); |
| 3535 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3536 | // If we have a message that has been queued up, then we should just replace |
| 3537 | // it. The ACK from the browser will make sure it gets sent when the browser |
| 3538 | // wants it. |
| 3539 | if (queued_find_reply_message_.get()) { |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3540 | queued_find_reply_message_.reset(msg); |
| 3541 | } else { |
| 3542 | // Send the search result over to the browser process. |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3543 | Send(msg); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3544 | } |
| 3545 | } |
| 3546 | |
| 3547 | void RenderView::reportFindInPageSelection(int request_id, |
| 3548 | int active_match_ordinal, |
| 3549 | const WebRect& selection_rect) { |
| 3550 | // Send the search result over to the browser process. |
| 3551 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3552 | request_id, |
| 3553 | -1, |
| 3554 | selection_rect, |
| 3555 | active_match_ordinal, |
| 3556 | false)); |
| 3557 | } |
| 3558 | |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3559 | void RenderView::openFileSystem( |
| 3560 | WebFrame* frame, |
| 3561 | WebFileSystem::Type type, |
| 3562 | long long size, |
| 3563 | WebFileSystemCallbacks* callbacks) { |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3564 | DCHECK(callbacks); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3565 | |
| 3566 | WebSecurityOrigin origin = frame->securityOrigin(); |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3567 | if (origin.isEmpty()) { |
| 3568 | // Uninitialized document? |
| 3569 | callbacks->didFail(WebKit::WebFileErrorAbort); |
| 3570 | return; |
| 3571 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3572 | |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3573 | ChildThread::current()->file_system_dispatcher()->OpenFileSystem( |
| 3574 | GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), |
| 3575 | size, new WebFileSystemCallbackDispatcher(callbacks)); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3576 | } |
| 3577 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 3578 | // webkit_glue::WebPluginPageDelegate ----------------------------------------- |
| 3579 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3580 | webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3581 | const FilePath& file_path, |
| 3582 | const std::string& mime_type) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3583 | if (!PluginChannelHost::IsListening()) |
| 3584 | return NULL; |
| 3585 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3586 | bool use_pepper_host = false; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3587 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3588 | // Check for trusted Pepper plugins. |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3589 | const char kPepperPrefix[] = "pepper-"; |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3590 | if (StartsWithASCII(mime_type, kPepperPrefix, true)) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3591 | if (CommandLine::ForCurrentProcess()-> |
| 3592 | HasSwitch(switches::kInternalPepper)) { |
| 3593 | in_process_plugin = true; |
| 3594 | use_pepper_host = true; |
| 3595 | } else { |
| 3596 | // In process Pepper plugins must be explicitly enabled. |
| 3597 | return NULL; |
| 3598 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3599 | } else { |
| 3600 | FilePath internal_pdf_path; |
| 3601 | PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path); |
| 3602 | if (file_path == internal_pdf_path) { |
| 3603 | in_process_plugin = true; |
| 3604 | use_pepper_host = true; |
| 3605 | } |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3606 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3607 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3608 | // Check for Native Client modules. |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 3609 | if (mime_type == "application/x-nacl-srpc" && |
| 3610 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) { |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3611 | // NaCl is only permitted when we're in an extension/application with the |
| 3612 | // appropriate permission, or when explicitly enabled on the command line. |
| 3613 | |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3614 | GURL main_frame_url(webview()->mainFrame()->url()); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3615 | ExtensionRendererInfo* extension = |
| 3616 | ExtensionRendererInfo::GetByURL(main_frame_url); |
| 3617 | bool in_ext = extension != NULL; |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3618 | bool explicit_enable = |
| 3619 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl); |
| 3620 | |
| 3621 | if (in_ext) { |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 3622 | // TODO(cbiffle): NaCl is back to experimental for M7. |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3623 | if (ExtensionProcessBindings::HasPermission(extension->id(), |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 3624 | Extension::kExperimentalPermission)) { |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3625 | in_process_plugin = true; |
| 3626 | use_pepper_host = true; |
| 3627 | } else { |
| 3628 | // Disable NaCl for apps lacking the permission, even with the flag. |
| 3629 | return NULL; |
| 3630 | } |
| 3631 | } else if (explicit_enable) { |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3632 | in_process_plugin = true; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3633 | use_pepper_host = true; |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3634 | } |
| 3635 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3636 | |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3637 | if (in_process_plugin) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3638 | if (use_pepper_host) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3639 | WebPluginDelegatePepper* pepper_plugin = |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3640 | WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr()); |
[email protected] | b7d7ed5 | 2010-07-20 00:12:33 | [diff] [blame] | 3641 | if (!pepper_plugin) |
| 3642 | return NULL; |
| 3643 | |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 3644 | current_oldstyle_pepper_plugins_.insert(pepper_plugin); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3645 | return pepper_plugin; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3646 | } else { |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3647 | #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] | 3648 | return WebPluginDelegateImpl::Create( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3649 | file_path, mime_type, gfx::NativeViewFromId(host_window_)); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3650 | #else |
[email protected] | 596b2c4 | 2010-01-14 20:40:43 | [diff] [blame] | 3651 | NOTIMPLEMENTED(); |
| 3652 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 3653 | #endif |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3654 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3655 | } |
| 3656 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3657 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3661 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3662 | RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer( |
| 3663 | routing_id(), window)); |
| 3664 | #endif |
| 3665 | } |
| 3666 | |
| 3667 | void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3668 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3669 | RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer( |
| 3670 | routing_id(), window)); |
| 3671 | #endif |
| 3672 | CleanupWindowInPluginMoves(window); |
| 3673 | } |
| 3674 | |
| 3675 | void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) { |
| 3676 | SchedulePluginMove(move); |
| 3677 | } |
| 3678 | |
| 3679 | void RenderView::DidStartLoadingForPlugin() { |
| 3680 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3681 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | void RenderView::DidStopLoadingForPlugin() { |
| 3685 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3686 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | void RenderView::ShowModalHTMLDialogForPlugin( |
| 3690 | const GURL& url, |
| 3691 | const gfx::Size& size, |
| 3692 | const std::string& json_arguments, |
| 3693 | std::string* json_retval) { |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3694 | SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog( |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3695 | routing_id_, url, size.width(), size.height(), json_arguments, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3696 | json_retval)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3697 | } |
| 3698 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 3699 | WebCookieJar* RenderView::GetCookieJar() { |
| 3700 | return &cookie_jar_; |
| 3701 | } |
| 3702 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3703 | void RenderView::SyncNavigationState() { |
| 3704 | if (!webview()) |
| 3705 | return; |
| 3706 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3707 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3708 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3709 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3710 | |
| 3711 | Send(new ViewHostMsg_UpdateState( |
| 3712 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3713 | } |
| 3714 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3715 | bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) { |
| 3716 | // Make sure webview was not shut down. |
| 3717 | if (!webview()) |
| 3718 | return false; |
| 3719 | // Create an image resource fetcher and assign it with a call back object. |
| 3720 | image_fetchers_.insert(new ImageResourceFetcher( |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3721 | image_url, webview()->mainFrame(), id, image_size, |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3722 | NewCallback(this, &RenderView::DidDownloadImage))); |
| 3723 | return true; |
| 3724 | } |
| 3725 | |
| 3726 | void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3727 | const SkBitmap& image) { |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3728 | // Notify requester of image download status. |
[email protected] | 51bd3661 | 2009-10-20 22:49:47 | [diff] [blame] | 3729 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, |
| 3730 | fetcher->id(), |
| 3731 | fetcher->image_url(), |
| 3732 | image.isNull(), |
| 3733 | image)); |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3734 | // Dispose of the image fetcher. |
| 3735 | DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end()); |
| 3736 | image_fetchers_.erase(fetcher); |
| 3737 | // We're in the callback from the ImageResourceFetcher, best to delay |
| 3738 | // deletion. |
| 3739 | MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3740 | } |
| 3741 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3742 | void RenderView::OnDownloadFavIcon(int id, |
| 3743 | const GURL& image_url, |
| 3744 | int image_size) { |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3745 | bool data_image_failed = false; |
| 3746 | if (image_url.SchemeIs("data")) { |
| 3747 | SkBitmap data_image = ImageFromDataUrl(image_url); |
| 3748 | data_image_failed = data_image.empty(); |
| 3749 | if (!data_image_failed) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3750 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false, |
| 3751 | data_image)); |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3752 | } |
| 3753 | } |
| 3754 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3755 | if (data_image_failed || |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3756 | !DownloadImage(id, image_url, image_size)) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3757 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true, |
| 3758 | SkBitmap())); |
| 3759 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3760 | } |
| 3761 | |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3762 | SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const { |
| 3763 | std::string mime_type, char_set, data; |
| 3764 | if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
| 3765 | // Decode the favicon using WebKit's image decoder. |
| 3766 | webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize)); |
| 3767 | const unsigned char* src_data = |
| 3768 | reinterpret_cast<const unsigned char*>(&data[0]); |
| 3769 | |
| 3770 | return decoder.Decode(src_data, data.size()); |
| 3771 | } |
| 3772 | return SkBitmap(); |
| 3773 | } |
| 3774 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3775 | void RenderView::OnGetApplicationInfo(int page_id) { |
| 3776 | webkit_glue::WebApplicationInfo app_info; |
| 3777 | if (page_id == page_id_) |
| 3778 | webkit_glue::GetApplicationInfo(webview(), &app_info); |
| 3779 | |
| 3780 | // Prune out any data URLs in the set of icons. The browser process expects |
| 3781 | // any icon with a data URL to have originated from a favicon. We don't want |
| 3782 | // to decode arbitrary data URLs in the browser process. See |
| 3783 | // http://b/issue?id=1162972 |
| 3784 | for (size_t i = 0; i < app_info.icons.size(); ++i) { |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 3785 | if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3786 | app_info.icons.erase(app_info.icons.begin() + i); |
| 3787 | --i; |
| 3788 | } |
| 3789 | } |
| 3790 | |
| 3791 | Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info)); |
| 3792 | } |
| 3793 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3794 | GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3795 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3796 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3797 | // If the URL that failed was secure, then the embedding web page was not |
| 3798 | // expecting a network attacker to be able to manipulate its contents. As |
| 3799 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 3800 | // attacker to manipulate the contents of the response if we tried to use |
| 3801 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3802 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | // Grab the base URL from the browser process. |
| 3806 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3807 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3808 | |
| 3809 | // Strip query params from the failed URL. |
| 3810 | GURL::Replacements remove_params; |
| 3811 | remove_params.ClearUsername(); |
| 3812 | remove_params.ClearPassword(); |
| 3813 | remove_params.ClearQuery(); |
| 3814 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3815 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3816 | std::string spec_to_send = url_to_send.spec(); |
| 3817 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 3818 | if (failed_url.has_query()) |
| 3819 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3820 | |
| 3821 | // Construct the query params to send to link doctor. |
| 3822 | std::string params(alternate_error_page_url_.query()); |
| 3823 | params.append("&url="); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3824 | params.append(EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3825 | params.append("&sourceid=chrome"); |
| 3826 | params.append("&error="); |
| 3827 | switch (error_type) { |
| 3828 | case DNS_ERROR: |
| 3829 | params.append("dnserror"); |
| 3830 | break; |
| 3831 | |
| 3832 | case HTTP_404: |
| 3833 | params.append("http404"); |
| 3834 | break; |
| 3835 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3836 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 3837 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3838 | break; |
| 3839 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3840 | default: |
| 3841 | NOTREACHED() << "unknown ErrorPageType"; |
| 3842 | } |
| 3843 | |
| 3844 | // OK, build the final url to return. |
| 3845 | GURL::Replacements link_doctor_params; |
| 3846 | link_doctor_params.SetQueryStr(params); |
| 3847 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 3848 | return url; |
| 3849 | } |
| 3850 | |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3851 | DOMUIBindings* RenderView::GetDOMUIBindings() { |
| 3852 | if (!dom_ui_bindings_.get()) { |
| 3853 | dom_ui_bindings_.reset(new DOMUIBindings()); |
| 3854 | } |
| 3855 | return dom_ui_bindings_.get(); |
| 3856 | } |
| 3857 | |
| 3858 | ExternalHostBindings* RenderView::GetExternalHostBindings() { |
| 3859 | if (!external_host_bindings_.get()) { |
| 3860 | external_host_bindings_.reset(new ExternalHostBindings()); |
| 3861 | } |
| 3862 | return external_host_bindings_.get(); |
| 3863 | } |
| 3864 | |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3865 | WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() { |
| 3866 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3867 | } |
| 3868 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3869 | void RenderView::OnFind(int request_id, const string16& search_text, |
| 3870 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3871 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3872 | |
| 3873 | if (main_frame->document().isPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3874 | if (options.findNext) { |
| 3875 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3876 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3877 | } else { |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 3878 | if (GetWebPluginFromPluginDocument()->startFind( |
| 3879 | search_text, options.matchCase, request_id)) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3880 | } else { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3881 | // Send "no results". |
| 3882 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3883 | request_id, |
| 3884 | 0, |
| 3885 | gfx::Rect(), |
| 3886 | 0, |
| 3887 | true)); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3888 | } |
| 3889 | } |
| 3890 | return; |
| 3891 | } |
| 3892 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3893 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3894 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3895 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 3896 | |
| 3897 | bool multi_frame = (frame_after_main != main_frame); |
| 3898 | |
| 3899 | // If we have multiple frames, we don't want to wrap the search within the |
| 3900 | // frame, so we check here if we only have main_frame in the chain. |
| 3901 | bool wrap_within_frame = !multi_frame; |
| 3902 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 3903 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3904 | bool result = false; |
| 3905 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3906 | // If something is selected when we start searching it means we cannot just |
| 3907 | // increment the current match ordinal; we need to re-generate it. |
| 3908 | WebRange current_selection = focused_frame->selectionRange(); |
| 3909 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3910 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3911 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3912 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3913 | |
| 3914 | if (!result) { |
| 3915 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3916 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3917 | |
| 3918 | // Find the next frame, but skip the invisible ones. |
| 3919 | do { |
| 3920 | // What is the next frame to search? (we might be going backwards). Note |
| 3921 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3922 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3923 | search_frame->traverseNext(true) : |
| 3924 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3925 | } while (!search_frame->hasVisibleContent() && |
| 3926 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3927 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 3928 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3929 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3930 | |
| 3931 | // If we have multiple frames and we have wrapped back around to the |
| 3932 | // focused frame, we need to search it once more allowing wrap within |
| 3933 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 3934 | // reported matches, but no frames after the focused_frame contain a |
| 3935 | // match for the search word(s). |
| 3936 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3937 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3938 | request_id, search_text, options, true, // Force wrapping. |
| 3939 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3940 | } |
| 3941 | } |
| 3942 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3943 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3944 | } while (!result && search_frame != focused_frame); |
| 3945 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3946 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3947 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3948 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3949 | } else { |
| 3950 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 3951 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 3952 | // yet what is active. |
| 3953 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 3954 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3955 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3956 | // If we find no matches then this will be our last status update. |
| 3957 | // Otherwise the scoping effort will send more results. |
| 3958 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3959 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3960 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 3961 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3962 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3963 | match_count, |
| 3964 | selection_rect, |
| 3965 | ordinal, |
| 3966 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3967 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3968 | // Scoping effort begins, starting with the mainframe. |
| 3969 | search_frame = main_frame; |
| 3970 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3971 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3972 | |
| 3973 | do { |
| 3974 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3975 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3976 | |
| 3977 | // We don't start another scoping effort unless at least one match has |
| 3978 | // been found. |
| 3979 | if (result) { |
| 3980 | // Start new scoping request. If the scoping function determines that it |
| 3981 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3982 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3983 | search_text, |
| 3984 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3985 | true); // reset the tickmarks |
| 3986 | } |
| 3987 | |
| 3988 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 3989 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3990 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3991 | } while (search_frame != main_frame); |
| 3992 | } |
| 3993 | } |
| 3994 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3995 | void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) { |
| 3996 | WebView* view = webview(); |
| 3997 | if (!view) |
| 3998 | return; |
| 3999 | |
| 4000 | WebDocument doc = view->mainFrame()->document(); |
| 4001 | if (doc.isPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4002 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4003 | return; |
| 4004 | } |
| 4005 | |
| 4006 | bool clear_selection = |
| 4007 | params.action == ViewMsg_StopFinding_Params::kClearSelection; |
| 4008 | if (clear_selection) |
| 4009 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 4010 | |
| 4011 | WebFrame* frame = view->mainFrame(); |
| 4012 | while (frame) { |
| 4013 | frame->stopFinding(clear_selection); |
| 4014 | frame = frame->traverseNext(false); |
| 4015 | } |
| 4016 | |
| 4017 | if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) { |
| 4018 | WebFrame* focused_frame = view->focusedFrame(); |
| 4019 | if (focused_frame) { |
| 4020 | WebDocument doc = focused_frame->document(); |
| 4021 | if (!doc.isNull()) { |
| 4022 | WebNode node = doc.focusedNode(); |
| 4023 | if (!node.isNull()) |
| 4024 | node.simulateClick(); |
| 4025 | } |
| 4026 | } |
| 4027 | } |
| 4028 | } |
| 4029 | |
| 4030 | void RenderView::OnFindReplyAck() { |
| 4031 | // Check if there is any queued up request waiting to be sent. |
| 4032 | if (queued_find_reply_message_.get()) { |
| 4033 | // Send the search result over to the browser process. |
[email protected] | d22d873 | 2010-05-04 19:24:42 | [diff] [blame] | 4034 | Send(queued_find_reply_message_.release()); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4035 | } |
| 4036 | } |
| 4037 | |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 4038 | bool RenderView::AllowContentType(ContentSettingsType settings_type) { |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 4039 | // CONTENT_SETTING_ASK is only valid for cookies. |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 4040 | return current_content_settings_.settings[settings_type] != |
| 4041 | CONTENT_SETTING_BLOCK; |
| 4042 | } |
| 4043 | |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 4044 | void RenderView::DidBlockContentType(ContentSettingsType settings_type, |
| 4045 | const std::string& resource_identifier) { |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 4046 | if (!content_blocked_[settings_type]) { |
| 4047 | content_blocked_[settings_type] = true; |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 4048 | Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type, |
| 4049 | resource_identifier)); |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 4050 | } |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 4051 | } |
| 4052 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 4053 | void RenderView::ClearBlockedContentSettings() { |
| 4054 | for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 4055 | content_blocked_[i] = false; |
| 4056 | } |
| 4057 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 4058 | WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame, |
| 4059 | const WebPluginParams& params, |
| 4060 | const FilePath& path, |
| 4061 | pepper::PluginModule* pepper_module) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4062 | return new pepper::WebPluginImpl( |
| 4063 | pepper_module, params, pepper_delegate_.AsWeakPtr()); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 4064 | } |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 4065 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 4066 | WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame, |
| 4067 | const WebPluginParams& params, |
| 4068 | const FilePath& path, |
| 4069 | const std::string& mime_type) { |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 4070 | return new webkit_glue::WebPluginImpl( |
| 4071 | frame, params, path, mime_type, AsWeakPtr()); |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 4072 | } |
| 4073 | |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 4074 | WebPlugin* RenderView::CreateOutdatedPluginPlaceholder( |
| 4075 | WebFrame* frame, |
| 4076 | const WebPluginParams& params, |
| 4077 | PluginGroup* group) { |
| 4078 | int resource_id = IDR_OUTDATED_PLUGIN_HTML; |
| 4079 | const base::StringPiece template_html( |
| 4080 | ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| 4081 | |
| 4082 | DCHECK(!template_html.empty()) << "unable to load template. ID: " |
| 4083 | << resource_id; |
| 4084 | |
| 4085 | DictionaryValue values; |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 4086 | values.SetString("message", |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 4087 | l10n_util::GetStringFUTF8(IDS_PLUGIN_OUTDATED, group->GetGroupName())); |
| 4088 | values.Set("pluginGroup", group->GetDataForUI()); |
| 4089 | |
| 4090 | // "t" is the id of the templates root node. |
| 4091 | std::string htmlData = jstemplate_builder::GetTemplatesHtml( |
| 4092 | template_html, &values, "t"); |
| 4093 | |
| 4094 | return WebViewPlugin::Create(NULL, |
| 4095 | webkit_preferences_, |
| 4096 | htmlData, |
| 4097 | GURL("chrome://outdatedplugin/")); |
| 4098 | } |
| 4099 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4100 | void RenderView::OnZoom(PageZoom::Function function) { |
| 4101 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4102 | return; |
| 4103 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 4104 | webview()->hidePopups(); |
[email protected] | b03794d | 2010-03-26 19:57:52 | [diff] [blame] | 4105 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4106 | double old_zoom_level = webview()->zoomLevel(); |
| 4107 | double zoom_level; |
| 4108 | if (function == PageZoom::RESET) { |
| 4109 | zoom_level = 0; |
| 4110 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 4111 | // Previous zoom level is a whole number, so just increment/decrement. |
| 4112 | zoom_level = old_zoom_level + function; |
| 4113 | } else { |
| 4114 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 4115 | // not a whole number, or a plugin changed it to a custom value. We want |
| 4116 | // to go to the next whole number so that the user can always get back to |
| 4117 | // 100% with the keyboard/menu. |
| 4118 | if ((old_zoom_level > 1 && function > 0) || |
| 4119 | (old_zoom_level < 1 && function < 0)) { |
[email protected] | 3209e711 | 2010-10-01 23:53:45 | [diff] [blame] | 4120 | zoom_level = static_cast<int>(old_zoom_level + function); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4121 | } else { |
| 4122 | // We're going towards 100%, so first go to the next whole number. |
| 4123 | zoom_level = static_cast<int>(old_zoom_level); |
| 4124 | } |
| 4125 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4126 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4127 | webview()->setZoomLevel(false, zoom_level); |
| 4128 | zoomLevelChanged(); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4129 | } |
| 4130 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4131 | void RenderView::OnSetContentSettingsForLoadingURL( |
| 4132 | const GURL& url, |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 4133 | const ContentSettings& content_settings) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4134 | host_content_settings_[url] = content_settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 4135 | } |
| 4136 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4137 | void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url, |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4138 | double zoom_level) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4139 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4140 | } |
| 4141 | |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 4142 | void RenderView::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4143 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4144 | } |
| 4145 | |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4146 | void RenderView::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4147 | WebString no_encoding; |
| 4148 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4149 | } |
| 4150 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4151 | bool RenderView::GetAllChildFrames( |
| 4152 | WebFrame* parent_frame, |
| 4153 | std::vector<WebFrame*>* frames_vector) const { |
| 4154 | if (!parent_frame) |
| 4155 | return false; |
| 4156 | for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
| 4157 | child_frame = child_frame->nextSibling()) { |
| 4158 | frames_vector->push_back(child_frame); |
| 4159 | GetAllChildFrames(child_frame, frames_vector); |
| 4160 | } |
| 4161 | return true; |
| 4162 | } |
| 4163 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4164 | WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { |
| 4165 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4166 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4167 | |
| 4168 | // xpath string can represent a frame deep down the tree (across multiple |
| 4169 | // frame DOMs). |
| 4170 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 4171 | // should break into 2 xpaths |
| 4172 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
| 4173 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4174 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4175 | |
| 4176 | std::wstring xpath_remaining = xpath; |
| 4177 | while (!xpath_remaining.empty()) { |
| 4178 | std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n'); |
| 4179 | std::wstring xpath_child; |
| 4180 | if (delim_pos != std::wstring::npos) { |
| 4181 | xpath_child = xpath_remaining.substr(0, delim_pos); |
| 4182 | xpath_remaining.erase(0, delim_pos + 1); |
| 4183 | } else { |
| 4184 | xpath_remaining.swap(xpath_child); |
| 4185 | } |
| 4186 | frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4187 | } |
| 4188 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4189 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4190 | } |
| 4191 | |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 4192 | void RenderView::SetSuggestResult(const std::string& suggest) { |
[email protected] | 5cbd61f | 2010-10-14 03:49:49 | [diff] [blame] | 4193 | // Explicitly allow empty strings to be sent to the browser. |
| 4194 | Send(new ViewHostMsg_SetSuggestResult(routing_id_, page_id_, suggest)); |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 4195 | } |
| 4196 | |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4197 | void RenderView::EvaluateScript(const string16& frame_xpath, |
| 4198 | const string16& script, |
| 4199 | int id, |
| 4200 | bool notify_result) { |
| 4201 | v8::Handle<v8::Value> result; |
| 4202 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
| 4203 | if (web_frame) |
| 4204 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); |
| 4205 | if (notify_result) { |
| 4206 | bool bool_result = !result.IsEmpty() && result->IsBoolean() ? |
| 4207 | result->BooleanValue() : false; |
| 4208 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, bool_result)); |
| 4209 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4210 | } |
| 4211 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4212 | void RenderView::InsertCSS(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4213 | const std::string& css, |
| 4214 | const std::string& id) { |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4215 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4216 | if (!web_frame) |
| 4217 | return; |
| 4218 | |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4219 | web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4220 | } |
| 4221 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4222 | void RenderView::OnPepperPluginDestroy( |
| 4223 | WebPluginDelegatePepper* pepper_plugin) { |
| 4224 | std::set<WebPluginDelegatePepper*>::iterator found_pepper = |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4225 | current_oldstyle_pepper_plugins_.find(pepper_plugin); |
| 4226 | if (found_pepper == current_oldstyle_pepper_plugins_.end()) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4227 | NOTREACHED(); |
| 4228 | return; |
| 4229 | } |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4230 | current_oldstyle_pepper_plugins_.erase(found_pepper); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4231 | |
| 4232 | // The plugin could have been destroyed while it was waiting for a file |
| 4233 | // choose callback, so check all pending completion callbacks and NULL them. |
| 4234 | for (std::deque< linked_ptr<PendingFileChooser> >::iterator i = |
| 4235 | file_chooser_completions_.begin(); |
| 4236 | i != file_chooser_completions_.end(); /* nothing */) { |
| 4237 | if ((*i)->completion == pepper_plugin) { |
| 4238 | // We NULL the first one instead of deleting it because the plugin might |
| 4239 | // be the one waiting for a file choose callback. If the callback later |
| 4240 | // comes, we don't want to send the result to the next callback in line. |
| 4241 | if (i == file_chooser_completions_.begin()) |
| 4242 | (*i)->completion = NULL; |
| 4243 | else |
| 4244 | i = file_chooser_completions_.erase(i); |
| 4245 | } else { |
| 4246 | ++i; |
| 4247 | } |
| 4248 | } |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4249 | } |
| 4250 | |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4251 | void RenderView::OnScriptEvalRequest(const string16& frame_xpath, |
| 4252 | const string16& jscript, |
| 4253 | int id, |
| 4254 | bool notify_result) { |
| 4255 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4256 | } |
| 4257 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4258 | void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4259 | const std::string& css, |
| 4260 | const std::string& id) { |
| 4261 | InsertCSS(frame_xpath, css, id); |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 4262 | |
| 4263 | // Notify RenderViewHost that css has been inserted into the frame. |
| 4264 | Send(new ViewHostMsg_OnCSSInserted(routing_id_)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4265 | } |
| 4266 | |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4267 | void RenderView::OnAddMessageToConsole( |
| 4268 | const string16& frame_xpath, |
| 4269 | const string16& message, |
| 4270 | const WebConsoleMessage::Level& level) { |
| 4271 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 4272 | if (web_frame) |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4273 | web_frame->addMessageToConsole(WebConsoleMessage(level, message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4274 | } |
| 4275 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4276 | void RenderView::OnAllowBindings(int enabled_bindings_flags) { |
| 4277 | enabled_bindings_ |= enabled_bindings_flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | void RenderView::OnSetDOMUIProperty(const std::string& name, |
| 4281 | const std::string& value) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4282 | DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4283 | GetDOMUIBindings()->SetProperty(name, value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4284 | } |
| 4285 | |
| 4286 | void RenderView::OnReservePageIDRange(int size_of_range) { |
| 4287 | next_page_id_ += size_of_range + 1; |
| 4288 | } |
| 4289 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4290 | void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 4291 | const gfx::Point& screen_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4292 | bool ended, |
| 4293 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4294 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4295 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 4296 | } else { |
| 4297 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4298 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | void RenderView::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4302 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4303 | } |
| 4304 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4305 | void RenderView::OnFillPasswordForm( |
[email protected] | e768baf | 2010-07-16 19:36:16 | [diff] [blame] | 4306 | const webkit_glue::PasswordFormFillData& form_data) { |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4307 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 4308 | password_autocomplete_manager_->ReceivedPasswordFormFillData(webview(), |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4309 | form_data); |
[email protected] | ad24ccb | 2010-07-15 21:38:20 | [diff] [blame] | 4310 | #else |
| 4311 | webkit_glue::FillPasswordForm(this->webview(), form_data); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4312 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data, |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4316 | const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4317 | const gfx::Point& screen_point, |
| 4318 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4319 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4320 | drop_data.ToDragData(), |
| 4321 | drop_data.identity, |
| 4322 | client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4323 | screen_point, |
| 4324 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4325 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4326 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4327 | } |
| 4328 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4329 | void RenderView::OnDragTargetDragOver(const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4330 | const gfx::Point& screen_point, |
| 4331 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4332 | WebDragOperation operation = webview()->dragTargetDragOver( |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4333 | client_point, |
| 4334 | screen_point, |
| 4335 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4336 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4337 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | void RenderView::OnDragTargetDragLeave() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4341 | webview()->dragTargetDragLeave(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4342 | } |
| 4343 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4344 | void RenderView::OnDragTargetDrop(const gfx::Point& client_point, |
| 4345 | const gfx::Point& screen_point) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4346 | webview()->dragTargetDrop(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4347 | } |
| 4348 | |
| 4349 | void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 4350 | webkit_preferences_ = prefs; |
| 4351 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | void RenderView::OnSetAltErrorPageURL(const GURL& url) { |
| 4355 | alternate_error_page_url_ = url; |
| 4356 | } |
| 4357 | |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 4358 | void RenderView::OnCustomContextMenuAction(unsigned action) { |
| 4359 | webview()->performCustomContextMenuAction(action); |
| 4360 | } |
| 4361 | |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4362 | void RenderView::OnTranslatePage(int page_id, |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4363 | const std::string& translate_script, |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4364 | const std::string& source_lang, |
| 4365 | const std::string& target_lang) { |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4366 | translate_helper_.TranslatePage(page_id, source_lang, target_lang, |
| 4367 | translate_script); |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4368 | } |
| 4369 | |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4370 | void RenderView::OnRevertTranslation(int page_id) { |
| 4371 | translate_helper_.RevertTranslation(page_id); |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 4372 | } |
| 4373 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4374 | void RenderView::OnInstallMissingPlugin() { |
| 4375 | // This could happen when the first default plugin is deleted. |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4376 | if (first_default_plugin_) |
| 4377 | first_default_plugin_->InstallMissingPlugin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4378 | } |
| 4379 | |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 4380 | void RenderView::OnLoadBlockedPlugins() { |
| 4381 | NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS, |
| 4382 | Source<RenderView>(this), |
| 4383 | NotificationService::NoDetails()); |
| 4384 | } |
| 4385 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4386 | void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4387 | // This could happen if we navigated to a different page before the user |
| 4388 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4389 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4390 | return; |
| 4391 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4392 | WebVector<WebString> ws_file_names(paths.size()); |
| 4393 | for (size_t i = 0; i < paths.size(); ++i) |
| 4394 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 4395 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4396 | if (file_chooser_completions_.front()->completion) |
| 4397 | file_chooser_completions_.front()->completion->didChooseFile(ws_file_names); |
| 4398 | file_chooser_completions_.pop_front(); |
| 4399 | |
| 4400 | // If there are more pending file chooser requests, schedule one now. |
| 4401 | if (!file_chooser_completions_.empty()) { |
| 4402 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 4403 | file_chooser_completions_.front()->params)); |
| 4404 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | void RenderView::OnEnableViewSourceMode() { |
| 4408 | if (!webview()) |
| 4409 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4410 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4411 | if (!main_frame) |
| 4412 | return; |
| 4413 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4414 | main_frame->enableViewSourceMode(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4415 | } |
| 4416 | |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 4417 | void RenderView::OnEnablePreferredSizeChangedMode(int flags) { |
| 4418 | DCHECK(flags != kPreferredSizeNothing); |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4419 | if (send_preferred_size_changes_) |
| 4420 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4421 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 4422 | |
| 4423 | // WebKit doesn't send a notification of the effective height of the page |
| 4424 | // changes, so poll for it. |
| 4425 | // TODO: Add a notification for this to WebKit, remove polling. After that's |
| 4426 | // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight. |
| 4427 | // http://crbug.com/44850 |
| 4428 | if (flags & kPreferredSizeHeightThisIsSlow) { |
| 4429 | preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this, |
| 4430 | &RenderView::CheckPreferredSize); |
| 4431 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 4432 | } |
| 4433 | |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4434 | void RenderView::OnDisableScrollbarsForSmallWindows( |
| 4435 | const gfx::Size& disable_scrollbar_size_limit) { |
| 4436 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 4437 | } |
| 4438 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4439 | void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { |
| 4440 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 4441 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 0dd6f9b5 | 2010-10-14 16:39:13 | [diff] [blame] | 4442 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 4443 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 4444 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 4445 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 4446 | gfx::NativeThemeLinux::instance()->SetScrollbarColors( |
| 4447 | renderer_prefs.thumb_inactive_color, |
| 4448 | renderer_prefs.thumb_active_color, |
| 4449 | renderer_prefs.track_color); |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4450 | |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4451 | if (webview()) { |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4452 | webview()->setScrollbarColors( |
| 4453 | renderer_prefs.thumb_inactive_color, |
| 4454 | renderer_prefs.thumb_active_color, |
| 4455 | renderer_prefs.track_color); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4456 | webview()->setSelectionColors( |
| 4457 | renderer_prefs.active_selection_bg_color, |
| 4458 | renderer_prefs.active_selection_fg_color, |
| 4459 | renderer_prefs.inactive_selection_bg_color, |
| 4460 | renderer_prefs.inactive_selection_fg_color); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 4461 | webview()->themeChanged(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4462 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 4463 | #endif |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4464 | } |
| 4465 | |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 4466 | void RenderView::OnMediaPlayerActionAt(const gfx::Point& location, |
| 4467 | const WebMediaPlayerAction& action) { |
| 4468 | if (webview()) |
| 4469 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 4470 | } |
| 4471 | |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 4472 | void RenderView::OnNotifyRendererViewType(ViewType::Type type) { |
| 4473 | view_type_ = type; |
| 4474 | } |
| 4475 | |
| 4476 | void RenderView::OnUpdateBrowserWindowId(int window_id) { |
| 4477 | browser_window_id_ = window_id; |
| 4478 | } |
| 4479 | |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 4480 | void RenderView::OnEnableAccessibility() { |
| 4481 | if (WebAccessibilityCache::accessibilityEnabled()) |
| 4482 | return; |
[email protected] | 9f4db51 | 2010-05-10 20:21:41 | [diff] [blame] | 4483 | |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 4484 | WebAccessibilityCache::enableAccessibility(); |
| 4485 | |
| 4486 | if (webview()) { |
| 4487 | // It's possible that the webview has already loaded a webpage without |
| 4488 | // accessibility being enabled. Initialize the browser's cached |
| 4489 | // accessibility tree by sending it a 'load complete' notification. |
| 4490 | postAccessibilityNotification( |
| 4491 | webview()->accessibilityObject(), |
| 4492 | WebKit::WebAccessibilityNotificationLoadComplete); |
| 4493 | } |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 4494 | } |
| 4495 | |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4496 | void RenderView::OnSetAccessibilityFocus(int acc_obj_id) { |
| 4497 | if (!accessibility_.get()) |
| 4498 | return; |
[email protected] | 02ea2f31 | 2010-09-27 17:03:36 | [diff] [blame] | 4499 | |
| 4500 | WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id); |
| 4501 | WebAccessibilityObject root = webview()->accessibilityObject(); |
| 4502 | if (!obj.isValid() || !root.isValid()) |
| 4503 | return; |
| 4504 | |
| 4505 | // By convention, calling SetFocus on the root of the tree should clear the |
| 4506 | // current focus. Otherwise set the focus to the new node. |
| 4507 | if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root)) |
| 4508 | webview()->clearFocusedNode(); |
| 4509 | else |
| 4510 | obj.setFocused(true); |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4511 | } |
| 4512 | |
| 4513 | void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) { |
| 4514 | if (!accessibility_.get()) |
| 4515 | return; |
[email protected] | 02ea2f31 | 2010-09-27 17:03:36 | [diff] [blame] | 4516 | |
| 4517 | WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id); |
| 4518 | if (!obj.isValid()) |
| 4519 | return; |
| 4520 | |
| 4521 | obj.performDefaultAction(); |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4522 | } |
| 4523 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 4524 | void RenderView::OnAccessibilityNotificationsAck() { |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 4525 | if (!accessibility_.get()) |
| 4526 | return; |
| 4527 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 4528 | if (!pending_accessibility_notifications_.empty()) { |
| 4529 | Send(new ViewHostMsg_AccessibilityNotifications( |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 4530 | routing_id_, |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 4531 | pending_accessibility_notifications_)); |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 4532 | } |
| 4533 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 4534 | pending_accessibility_notifications_.clear(); |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 4535 | } |
| 4536 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4537 | void RenderView::OnGetAllSavableResourceLinksForCurrentPage( |
| 4538 | const GURL& page_url) { |
| 4539 | // Prepare list to storage all savable resource links. |
| 4540 | std::vector<GURL> resources_list; |
| 4541 | std::vector<GURL> referrers_list; |
| 4542 | std::vector<GURL> frames_list; |
| 4543 | webkit_glue::SavableResourcesResult result(&resources_list, |
| 4544 | &referrers_list, |
| 4545 | &frames_list); |
| 4546 | |
[email protected] | dbeb395 | 2009-10-13 18:01:18 | [diff] [blame] | 4547 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 4548 | webview(), |
| 4549 | page_url, |
| 4550 | &result, |
| 4551 | chrome::kSavableSchemes)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4552 | // If something is wrong when collecting all savable resource links, |
| 4553 | // send empty list to embedder(browser) to tell it failed. |
| 4554 | referrers_list.clear(); |
| 4555 | resources_list.clear(); |
| 4556 | frames_list.clear(); |
| 4557 | } |
| 4558 | |
| 4559 | // Send result of all savable resource links to embedder. |
| 4560 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_, |
| 4561 | resources_list, |
| 4562 | referrers_list, |
| 4563 | frames_list)); |
| 4564 | } |
| 4565 | |
| 4566 | void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | f6b4853 | 2009-02-12 01:56:32 | [diff] [blame] | 4567 | const std::vector<GURL>& links, |
[email protected] | fde6714d1 | 2009-02-18 22:39:31 | [diff] [blame] | 4568 | const std::vector<FilePath>& local_paths, |
| 4569 | const FilePath& local_directory_name) { |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4570 | |
| 4571 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 4572 | WebVector<WebURL> weburl_links(links); |
| 4573 | |
| 4574 | // Convert std::vector of std::strings to WebVector<WebString> |
| 4575 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 4576 | for (size_t i = 0; i < local_paths.size(); i++) |
| 4577 | webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); |
| 4578 | |
| 4579 | WebPageSerializer::serialize(webview()->mainFrame(), |
| 4580 | true, this, weburl_links, webstring_paths, |
| 4581 | webkit_glue::FilePathToWebString( |
| 4582 | local_directory_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4583 | } |
| 4584 | |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4585 | void RenderView::didSerializeDataForFrame(const WebURL& frame_url, |
| 4586 | const WebCString& data, |
| 4587 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4588 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4589 | routing_id_, |
| 4590 | frame_url, |
| 4591 | data.data(), |
| 4592 | static_cast<int32>(status))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4593 | } |
| 4594 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 4595 | void RenderView::OnShouldClose() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4596 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4597 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4598 | } |
| 4599 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4600 | void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4601 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 4602 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 4603 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 4604 | // calling the FrameLoader's CloseURL method directly. This should be |
| 4605 | // revisited to avoid having two ways to close a page. Having a single way |
| 4606 | // to close that can run onunload is also useful for fixing |
| 4607 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4608 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4609 | if (main_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4610 | const GURL& url = main_frame->url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 4611 | // TODO(davemoore) this code should be removed once willClose() gets |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4612 | // called when a page is destroyed. DumpLoadHistograms() is safe to call |
| 4613 | // multiple times for the same frame, but it will simplify things. |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4614 | |
| 4615 | // Ensure state contains scheme. |
| 4616 | NavigationState* navigation_state = |
| 4617 | NavigationState::FromDataSource(main_frame->dataSource()); |
| 4618 | if (url.SchemeIs("http")) |
| 4619 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP); |
| 4620 | else if (url.SchemeIs("https")) |
| 4621 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS); |
| 4622 | |
| 4623 | // Dump will only be provided when scheme is http or https. |
| 4624 | DumpLoadHistograms(); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4625 | } |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4626 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4627 | |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 4628 | // Reset stats |
| 4629 | cross_origin_access_count_ = 0; |
| 4630 | same_origin_access_count_ = 0; |
| 4631 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4632 | // Just echo back the params in the ACK. |
| 4633 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4634 | } |
| 4635 | |
| 4636 | void RenderView::OnThemeChanged() { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4637 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4638 | gfx::NativeTheme::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 4639 | if (webview()) |
| 4640 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4641 | #else // defined(OS_WIN) |
| 4642 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 4643 | NOTIMPLEMENTED(); |
| 4644 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4645 | } |
| 4646 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 4647 | void RenderView::OnHandleMessageFromExternalHost(const std::string& message, |
| 4648 | const std::string& origin, |
| 4649 | const std::string& target) { |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4650 | if (message.empty()) |
| 4651 | return; |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4652 | GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin, |
| 4653 | target); |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4654 | } |
| 4655 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 4656 | void RenderView::OnDisassociateFromPopupCount() { |
| 4657 | if (decrement_shared_popup_at_destruction_) |
| 4658 | shared_popup_counter_->data--; |
| 4659 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 4660 | decrement_shared_popup_at_destruction_ = false; |
| 4661 | } |
| 4662 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4663 | bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 4664 | const WebURLError& error, |
| 4665 | bool replace) { |
| 4666 | // We only show alternate error pages in the main frame. They are |
| 4667 | // intended to assist the user when navigating, so there is not much |
| 4668 | // value in showing them for failed subframes. Ideally, we would be |
| 4669 | // able to use the TYPED transition type for this, but that flag is |
| 4670 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4671 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4672 | return false; |
| 4673 | |
| 4674 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4675 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4676 | int ec = error.reason; |
| 4677 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 4678 | ec != net::ERR_CONNECTION_FAILED && |
| 4679 | ec != net::ERR_CONNECTION_REFUSED && |
| 4680 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4681 | ec != net::ERR_CONNECTION_TIMED_OUT) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4682 | return false; |
| 4683 | |
| 4684 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4685 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4686 | if (!error_page_url.is_valid()) |
| 4687 | return false; |
| 4688 | |
| 4689 | // Load an empty page first so there is an immediate response to the error, |
| 4690 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4691 | frame->loadHTMLString(std::string(), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4692 | GURL(kUnreachableWebDataURL), |
| 4693 | error.unreachableURL, |
| 4694 | replace); |
| 4695 | |
| 4696 | // Now, create a fetcher for the error page and associate it with the data |
| 4697 | // source we just created via the LoadHTMLString call. That way if another |
| 4698 | // navigation occurs, the fetcher will get destroyed. |
| 4699 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4700 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4701 | navigation_state->set_alt_error_page_fetcher( |
| 4702 | new AltErrorPageResourceFetcher( |
| 4703 | error_page_url, frame, error, |
| 4704 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 4705 | return true; |
| 4706 | } |
| 4707 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4708 | std::string RenderView::GetAltHTMLForTemplate( |
| 4709 | const DictionaryValue& error_strings, int template_resource_id) const { |
[email protected] | 8a16266e | 2009-09-10 21:08:39 | [diff] [blame] | 4710 | const base::StringPiece template_html( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4711 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 4712 | template_resource_id)); |
| 4713 | |
| 4714 | if (template_html.empty()) { |
| 4715 | NOTREACHED() << "unable to load template. ID: " << template_resource_id; |
| 4716 | return ""; |
| 4717 | } |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4718 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4719 | // "t" is the id of the templates root node. |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4720 | return jstemplate_builder::GetTemplatesHtml( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4721 | template_html, &error_strings, "t"); |
| 4722 | } |
[email protected] | 0e79b9e | 2009-02-13 04:20:48 | [diff] [blame] | 4723 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4724 | void RenderView::AltErrorPageFinished(WebFrame* frame, |
| 4725 | const WebURLError& original_error, |
| 4726 | const std::string& html) { |
| 4727 | // Here, we replace the blank page we loaded previously. |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4728 | |
| 4729 | // If we failed to download the alternate error page, fall back to the |
| 4730 | // original error page if present. Otherwise, LoadNavigationErrorPage |
| 4731 | // will simply display a default error page. |
| 4732 | const std::string* html_to_load = &html; |
| 4733 | if (html.empty()) { |
| 4734 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4735 | NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4736 | html_to_load = &navigation_state->postponed_data(); |
| 4737 | } |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 4738 | LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load, |
| 4739 | true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4740 | } |
| 4741 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4742 | void RenderView::OnMoveOrResizeStarted() { |
| 4743 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4744 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4745 | } |
| 4746 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4747 | void RenderView::OnResize(const gfx::Size& new_size, |
| 4748 | const gfx::Rect& resizer_rect) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4749 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4750 | webview()->hidePopups(); |
[email protected] | 98e92fe2 | 2010-09-24 22:15:13 | [diff] [blame] | 4751 | |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4752 | if (send_preferred_size_changes_) { |
[email protected] | 98e92fe2 | 2010-09-24 22:15:13 | [diff] [blame] | 4753 | // If resizing to a size larger than |disable_scrollbars_size_limit_| in |
| 4754 | // either width or height, allow scroll bars. |
| 4755 | bool allow_scrollbars = ( |
| 4756 | disable_scrollbars_size_limit_.width() <= new_size.width() || |
| 4757 | disable_scrollbars_size_limit_.height() <= new_size.height()); |
| 4758 | webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4759 | } |
| 4760 | } |
| 4761 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4762 | RenderWidget::OnResize(new_size, resizer_rect); |
| 4763 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 4764 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4765 | void RenderView::DidInitiatePaint() { |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4766 | // Notify the pepper plugins that we started painting. |
| 4767 | pepper_delegate_.ViewInitiatedPaint(); |
| 4768 | |
| 4769 | // Notify any "old-style" pepper plugins that we started painting. This is |
| 4770 | // used for internal bookkeeping only, so we know that the set can not change |
| 4771 | // under us. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4772 | for (std::set<WebPluginDelegatePepper*>::iterator i = |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4773 | current_oldstyle_pepper_plugins_.begin(); |
| 4774 | i != current_oldstyle_pepper_plugins_.end(); ++i) |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4775 | (*i)->RenderViewInitiatedPaint(); |
| 4776 | } |
| 4777 | |
| 4778 | void RenderView::DidFlushPaint() { |
| 4779 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 4780 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 4781 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 4782 | // won't change out from under us. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4783 | pepper_delegate_.ViewFlushedPaint(); |
| 4784 | |
| 4785 | // Notify any old-style pepper plugins that we painted. This will call into |
| 4786 | // the plugin, and we it may ask to close itself as a result. This will, in |
| 4787 | // turn, modify our set, possibly invalidating the iterator. So we iterate on |
| 4788 | // a copy that won't change out from under us. |
| 4789 | // This should be deleted when we don't support old Pepper anymore. |
| 4790 | std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4791 | for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin(); |
| 4792 | i != plugins.end(); ++i) { |
| 4793 | // The copy above makes sure our iterator is never invalid if some plugins |
| 4794 | // are destroyed. But some plugin may decide to close all of its views in |
| 4795 | // response to a paint in one of them, so we need to make sure each one is |
| 4796 | // still "current" before using it. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4797 | if (current_oldstyle_pepper_plugins_.find(*i) != |
| 4798 | current_oldstyle_pepper_plugins_.end()) |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4799 | (*i)->RenderViewFlushedPaint(); |
| 4800 | } |
| 4801 | |
| 4802 | WebFrame* main_frame = webview()->mainFrame(); |
| 4803 | |
| 4804 | // If we have a provisional frame we are between the start and commit stages |
| 4805 | // of loading and we don't want to save stats. |
| 4806 | if (!main_frame->provisionalDataSource()) { |
| 4807 | WebDataSource* ds = main_frame->dataSource(); |
| 4808 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 4809 | DCHECK(navigation_state); |
| 4810 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4811 | // TODO(jar): The following code should all be inside a method, probably in |
| 4812 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4813 | Time now = Time::Now(); |
| 4814 | if (navigation_state->first_paint_time().is_null()) { |
| 4815 | navigation_state->set_first_paint_time(now); |
| 4816 | } |
| 4817 | if (navigation_state->first_paint_after_load_time().is_null() && |
| 4818 | !navigation_state->finish_load_time().is_null()) { |
| 4819 | navigation_state->set_first_paint_after_load_time(now); |
| 4820 | } |
| 4821 | } |
| 4822 | } |
| 4823 | |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 4824 | bool RenderView::GetBitmapForOptimizedPluginPaint( |
| 4825 | const gfx::Rect& paint_bounds, |
| 4826 | TransportDIB** dib, |
| 4827 | gfx::Rect* location, |
| 4828 | gfx::Rect* clip) { |
| 4829 | return pepper_delegate_.GetBitmapForOptimizedPluginPaint( |
| 4830 | paint_bounds, dib, location, clip); |
| 4831 | } |
| 4832 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4833 | void RenderView::OnClearFocusedNode() { |
| 4834 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4835 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4836 | } |
| 4837 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4838 | void RenderView::OnSetBackground(const SkBitmap& background) { |
| 4839 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4840 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4841 | |
| 4842 | SetBackground(background); |
| 4843 | } |
| 4844 | |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4845 | void RenderView::OnSetActive(bool active) { |
| 4846 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4847 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 4848 | |
| 4849 | #if defined(OS_MACOSX) |
| 4850 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4851 | for (plugin_it = plugin_delegates_.begin(); |
| 4852 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4853 | (*plugin_it)->SetWindowFocus(active); |
| 4854 | } |
| 4855 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4856 | } |
| 4857 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4858 | #if defined(OS_MACOSX) |
| 4859 | void RenderView::OnSetWindowVisibility(bool visible) { |
| 4860 | // Inform plugins that their container has changed visibility. |
| 4861 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4862 | for (plugin_it = plugin_delegates_.begin(); |
| 4863 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4864 | (*plugin_it)->SetContainerVisibility(visible); |
| 4865 | } |
| 4866 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4867 | |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 4868 | void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 4869 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4870 | // Inform plugins that their window's frame has changed. |
| 4871 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4872 | for (plugin_it = plugin_delegates_.begin(); |
| 4873 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4874 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 4875 | } |
| 4876 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame^] | 4877 | |
| 4878 | void RenderView::OnPluginImeCompositionConfirmed(const string16& text, |
| 4879 | int plugin_id) { |
| 4880 | // WebPluginDelegateProxy is responsible for figuring out if this text |
| 4881 | // applies to it or not, so inform all the delegates. |
| 4882 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4883 | for (plugin_it = plugin_delegates_.begin(); |
| 4884 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4885 | (*plugin_it)->ImeCompositionConfirmed(text, plugin_id); |
| 4886 | } |
| 4887 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4888 | #endif // OS_MACOSX |
| 4889 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 4890 | void RenderView::SendExtensionRequest( |
| 4891 | const ViewHostMsg_DomMessage_Params& params) { |
| 4892 | Send(new ViewHostMsg_ExtensionRequest(routing_id_, params)); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4893 | } |
| 4894 | |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 4895 | void RenderView::OnExtensionResponse(int request_id, |
| 4896 | bool success, |
| 4897 | const std::string& response, |
| 4898 | const std::string& error) { |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 4899 | ExtensionProcessBindings::HandleResponse( |
| 4900 | request_id, success, response, error); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4901 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4902 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 4903 | void RenderView::OnExtensionMessageInvoke(const std::string& function_name, |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4904 | const ListValue& args, |
[email protected] | 414785a | 2010-10-08 21:32:34 | [diff] [blame] | 4905 | bool cross_incognito, |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 4906 | const GURL& event_url) { |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4907 | RendererExtensionBindings::Invoke( |
[email protected] | 414785a | 2010-10-08 21:32:34 | [diff] [blame] | 4908 | function_name, args, this, cross_incognito, event_url); |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 4909 | } |
| 4910 | |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4911 | // Dump all load time histograms. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4912 | // |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4913 | // The time points we keep are |
| 4914 | // request: time document was requested by user |
| 4915 | // start: time load of document started |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 4916 | // commit: time load of document started |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4917 | // finish_document: main document loaded, before onload() |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4918 | // finish_all_loads: after onload() and all resources are loaded |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4919 | // first_paint: first paint performed |
| 4920 | // first_paint_after_load: first paint performed after load is finished |
| 4921 | // begin: request if it was user requested, start otherwise |
| 4922 | // |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4923 | // It's possible for the request time not to be set, if a client |
| 4924 | // redirect had been done (the user never requested the page) |
| 4925 | // Also, it's possible to load a page without ever laying it out |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4926 | // so first_paint and first_paint_after_load can be 0. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4927 | void RenderView::DumpLoadHistograms() const { |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4928 | // Configuration for PLT related histograms. |
| 4929 | static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10)); |
| 4930 | static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10)); |
| 4931 | static const size_t kPLTCount(100); |
| 4932 | #define PLT_HISTOGRAM(name, sample) \ |
| 4933 | UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount); |
| 4934 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4935 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4936 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4937 | NavigationState::FromDataSource(main_frame->dataSource()); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4938 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4939 | URLPattern::SchemeMasks scheme_type = navigation_state->scheme_type(); |
| 4940 | if (scheme_type == 0) |
| 4941 | return; |
| 4942 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP || |
| 4943 | scheme_type == URLPattern::SCHEME_HTTPS); |
| 4944 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4945 | // If we've already dumped, do nothing. |
| 4946 | if (navigation_state->load_histograms_recorded()) |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4947 | return; |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4948 | |
| 4949 | // Collect measurement times. |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4950 | Time start = navigation_state->start_load_time(); |
| 4951 | if (start.is_null()) |
| 4952 | return; // Probably very premature abandonment of page. |
| 4953 | Time commit = navigation_state->commit_load_time(); |
| 4954 | if (commit.is_null()) |
| 4955 | return; // Probably very premature abandonment of page. |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4956 | |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4957 | // We properly handle null values for the next 3 variables. |
| 4958 | Time request = navigation_state->request_time(); |
| 4959 | Time first_paint = navigation_state->first_paint_time(); |
| 4960 | Time first_paint_after_load = navigation_state->first_paint_after_load_time(); |
[email protected] | b855ebe6 | 2010-05-12 23:01:45 | [diff] [blame] | 4961 | Time finish_doc = navigation_state->finish_document_load_time(); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4962 | Time finish_all_loads = navigation_state->finish_load_time(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4963 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4964 | // Handle case where user hits "stop" or "back" before loading completely. |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4965 | bool abandoned_page = finish_doc.is_null(); |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4966 | if (abandoned_page) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4967 | finish_doc = Time::Now(); |
| 4968 | navigation_state->set_finish_document_load_time(finish_doc); |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4969 | } |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4970 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4971 | // TODO(jar): We should really discriminate the definition of "abandon" more |
| 4972 | // finely. We should have: |
| 4973 | // abandon_before_document_loaded |
| 4974 | // abandon_before_onload_fired |
| 4975 | |
| 4976 | if (finish_all_loads.is_null()) { |
| 4977 | finish_all_loads = Time::Now(); |
| 4978 | navigation_state->set_finish_load_time(finish_all_loads); |
| 4979 | } else { |
| 4980 | DCHECK(!abandoned_page); // How can the doc have finished but not the page? |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4981 | if (!abandoned_page) |
| 4982 | return; // Don't try to record a stat which is broken. |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | // Note: Client side redirects will have no request time. |
| 4986 | Time begin = request.is_null() ? start : request; |
| 4987 | TimeDelta begin_to_finish_doc = finish_doc - begin; |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4988 | TimeDelta begin_to_finish_all_loads = finish_all_loads - begin; |
| 4989 | TimeDelta start_to_finish_all_loads = finish_all_loads - start; |
[email protected] | ef1d8d32 | 2010-06-13 18:31:25 | [diff] [blame] | 4990 | TimeDelta start_to_commit = commit - start; |
[email protected] | f899964 | 2009-10-27 21:39:42 | [diff] [blame] | 4991 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4992 | NavigationState::LoadType load_type = navigation_state->load_type(); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4993 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4994 | // The above code sanitized all values of times, in preparation for creating |
| 4995 | // actual histograms. The remainder of this code could be run at destructor |
| 4996 | // time for the navigation_state, since all data is intact. |
| 4997 | |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 4998 | // Aggregate PLT data across all link types. |
| 4999 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2); |
| 5000 | UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type, |
| 5001 | NavigationState::kLoadTypeMax); |
[email protected] | ef1d8d32 | 2010-06-13 18:31:25 | [diff] [blame] | 5002 | PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5003 | PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5004 | PLT_HISTOGRAM("PLT.FinishDocToFinish", finish_all_loads - finish_doc); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5005 | PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5006 | PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5007 | if (!request.is_null()) { |
| 5008 | PLT_HISTOGRAM("PLT.RequestToStart", start - request); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5009 | PLT_HISTOGRAM("PLT.RequestToFinish", finish_all_loads - request); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5010 | } |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5011 | PLT_HISTOGRAM("PLT.CommitToFinish", finish_all_loads - commit); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5012 | if (!first_paint.is_null()) { |
| 5013 | DCHECK(begin <= first_paint); |
| 5014 | PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin); |
| 5015 | DCHECK(commit <= first_paint); |
| 5016 | PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit); |
| 5017 | } |
| 5018 | if (!first_paint_after_load.is_null()) { |
| 5019 | DCHECK(begin <= first_paint_after_load); |
| 5020 | PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad", |
| 5021 | first_paint_after_load - begin); |
| 5022 | DCHECK(commit <= first_paint_after_load); |
| 5023 | PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad", |
| 5024 | first_paint_after_load - commit); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5025 | DCHECK(finish_all_loads <= first_paint_after_load); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5026 | PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5027 | first_paint_after_load - finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5028 | } |
| 5029 | PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5030 | PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5031 | |
| 5032 | // Load type related histograms. |
| 5033 | switch (load_type) { |
| 5034 | case NavigationState::UNDEFINED_LOAD: |
| 5035 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5036 | PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5037 | break; |
| 5038 | case NavigationState::RELOAD: |
| 5039 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5040 | PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5041 | break; |
| 5042 | case NavigationState::HISTORY_LOAD: |
| 5043 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5044 | PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5045 | break; |
| 5046 | case NavigationState::NORMAL_LOAD: |
| 5047 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5048 | PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5049 | break; |
| 5050 | case NavigationState::LINK_LOAD_NORMAL: |
| 5051 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal", |
| 5052 | begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5053 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal", |
| 5054 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5055 | break; |
| 5056 | case NavigationState::LINK_LOAD_RELOAD: |
| 5057 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload", |
| 5058 | begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5059 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload", |
| 5060 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5061 | break; |
| 5062 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5063 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk", |
| 5064 | begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5065 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk", |
| 5066 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5067 | break; |
| 5068 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 5069 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly", |
| 5070 | begin_to_finish_doc); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5071 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly", |
| 5072 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5073 | break; |
| 5074 | default: |
| 5075 | break; |
| 5076 | } |
| 5077 | |
| 5078 | // Histograms to determine if DNS prefetching has an impact on PLT. |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5079 | static bool use_dns_histogram(base::FieldTrialList::Find("DnsImpact") && |
| 5080 | !base::FieldTrialList::Find("DnsImpact")->group_name().empty()); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5081 | if (use_dns_histogram) { |
| 5082 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5083 | base::FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"), |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5084 | abandoned_page ? 1 : 0, 2); |
| 5085 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5086 | base::FieldTrial::MakeName("PLT.LoadType", "DnsImpact"), |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5087 | load_type, NavigationState::kLoadTypeMax); |
| 5088 | switch (load_type) { |
| 5089 | case NavigationState::NORMAL_LOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5090 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5091 | "PLT.BeginToFinish_NormalLoad", "DnsImpact"), |
| 5092 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5093 | break; |
| 5094 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5095 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5096 | "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"), |
[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 | case NavigationState::LINK_LOAD_RELOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5100 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5101 | "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5102 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5103 | break; |
| 5104 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5105 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5106 | "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5107 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5108 | break; |
| 5109 | default: |
| 5110 | break; |
| 5111 | } |
| 5112 | } |
| 5113 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 5114 | // Histograms to determine if content prefetching has an impact on PLT. |
| 5115 | static const bool prefetching_fieldtrial = |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5116 | base::FieldTrialList::Find("Prefetch") && |
| 5117 | !base::FieldTrialList::Find("Prefetch")->group_name().empty(); |
[email protected] | 13ae2df9 | 2010-08-19 20:05:10 | [diff] [blame] | 5118 | if (prefetching_fieldtrial) { |
| 5119 | if (navigation_state->was_prefetcher()) { |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 5120 | PLT_HISTOGRAM( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5121 | base::FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcher", |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 5122 | "Prefetch"), |
| 5123 | begin_to_finish_doc); |
| 5124 | PLT_HISTOGRAM( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5125 | base::FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcher", |
| 5126 | "Prefetch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5127 | begin_to_finish_all_loads); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 5128 | } |
[email protected] | 13ae2df9 | 2010-08-19 20:05:10 | [diff] [blame] | 5129 | if (navigation_state->was_referred_by_prefetcher()) { |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5130 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5131 | "PLT.BeginToFinishDoc_ContentPrefetcherReferrer", |
| 5132 | "Prefetch"), |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 5133 | begin_to_finish_doc); |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5134 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5135 | "PLT.BeginToFinish_ContentPrefetcherReferrer", |
| 5136 | "Prefetch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5137 | begin_to_finish_all_loads); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 5138 | } |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5139 | UMA_HISTOGRAM_ENUMERATION( |
| 5140 | base::FieldTrial::MakeName("PLT.Abandoned", "Prefetch"), |
| 5141 | abandoned_page ? 1 : 0, 2); |
| 5142 | PLT_HISTOGRAM(base::FieldTrial::MakeName("PLT.BeginToFinishDoc", |
| 5143 | "Prefetch"), |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 5144 | begin_to_finish_doc); |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5145 | PLT_HISTOGRAM(base::FieldTrial::MakeName("PLT.BeginToFinish", "Prefetch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5146 | begin_to_finish_all_loads); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 5147 | } |
| 5148 | |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 5149 | // Histograms to determine if backup connection jobs have an impact on PLT. |
| 5150 | static const bool connect_backup_jobs_fieldtrial( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5151 | base::FieldTrialList::Find("ConnnectBackupJobs") && |
| 5152 | !base::FieldTrialList::Find("ConnnectBackupJobs")->group_name().empty()); |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 5153 | if (connect_backup_jobs_fieldtrial) { |
| 5154 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5155 | base::FieldTrial::MakeName("PLT.Abandoned", "ConnnectBackupJobs"), |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 5156 | abandoned_page ? 1 : 0, 2); |
| 5157 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5158 | base::FieldTrial::MakeName("PLT.LoadType", "ConnnectBackupJobs"), |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 5159 | load_type, NavigationState::kLoadTypeMax); |
| 5160 | switch (load_type) { |
| 5161 | case NavigationState::NORMAL_LOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5162 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 5163 | "PLT.BeginToFinish_NormalLoad", "ConnnectBackupJobs"), |
| 5164 | begin_to_finish_all_loads); |
| 5165 | break; |
| 5166 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5167 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 5168 | "PLT.BeginToFinish_LinkLoadNormal", "ConnnectBackupJobs"), |
| 5169 | begin_to_finish_all_loads); |
| 5170 | break; |
| 5171 | case NavigationState::LINK_LOAD_RELOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5172 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 5173 | "PLT.BeginToFinish_LinkLoadReload", "ConnnectBackupJobs"), |
| 5174 | begin_to_finish_all_loads); |
| 5175 | break; |
| 5176 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5177 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 06d9404 | 2010-08-25 01:45:22 | [diff] [blame] | 5178 | "PLT.BeginToFinish_LinkLoadStaleOk", "ConnnectBackupJobs"), |
| 5179 | begin_to_finish_all_loads); |
| 5180 | break; |
| 5181 | default: |
| 5182 | break; |
| 5183 | } |
| 5184 | } |
| 5185 | |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5186 | // Histograms to determine if the number of connections has an |
| 5187 | // impact on PLT. |
| 5188 | // TODO(jar): Consider removing the per-link-type versions. We |
| 5189 | // really only need LINK_LOAD_NORMAL and NORMAL_LOAD. |
[email protected] | 9754649 | 2010-08-09 05:14:49 | [diff] [blame] | 5190 | static bool use_connection_impact_histogram( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5191 | base::FieldTrialList::Find("ConnCountImpact") && |
| 5192 | !base::FieldTrialList::Find("ConnCountImpact")->group_name().empty()); |
[email protected] | 9754649 | 2010-08-09 05:14:49 | [diff] [blame] | 5193 | if (use_connection_impact_histogram) { |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5194 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5195 | base::FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"), |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5196 | abandoned_page ? 1 : 0, 2); |
| 5197 | switch (load_type) { |
| 5198 | case NavigationState::NORMAL_LOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5199 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5200 | "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5201 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5202 | break; |
| 5203 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5204 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5205 | "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5206 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5207 | break; |
| 5208 | case NavigationState::LINK_LOAD_RELOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5209 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5210 | "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5211 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5212 | break; |
| 5213 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5214 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5215 | "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5216 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5217 | break; |
| 5218 | default: |
| 5219 | break; |
| 5220 | } |
| 5221 | } |
| 5222 | |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5223 | // Histograms to determine effect of idle socket timeout. |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5224 | static bool use_idle_socket_timeout_histogram( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5225 | base::FieldTrialList::Find("IdleSktToImpact") && |
| 5226 | !base::FieldTrialList::Find("IdleSktToImpact")->group_name().empty()); |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5227 | if (use_idle_socket_timeout_histogram) { |
| 5228 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5229 | base::FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"), |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5230 | abandoned_page ? 1 : 0, 2); |
| 5231 | switch (load_type) { |
| 5232 | case NavigationState::NORMAL_LOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5233 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5234 | "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5235 | begin_to_finish_all_loads); |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5236 | break; |
| 5237 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5238 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5239 | "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5240 | begin_to_finish_all_loads); |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5241 | break; |
| 5242 | case NavigationState::LINK_LOAD_RELOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5243 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5244 | "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5245 | begin_to_finish_all_loads); |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5246 | break; |
| 5247 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5248 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5249 | "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5250 | begin_to_finish_all_loads); |
[email protected] | 241c5c2c | 2010-06-21 18:46:00 | [diff] [blame] | 5251 | break; |
| 5252 | default: |
| 5253 | break; |
| 5254 | } |
| 5255 | } |
| 5256 | |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5257 | // Histograms to determine effect of number of connections per proxy. |
| 5258 | static bool use_proxy_connection_impact_histogram( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5259 | base::FieldTrialList::Find("ProxyConnectionImpact") && |
| 5260 | !base::FieldTrialList::Find("ProxyConnectionImpact")-> |
| 5261 | group_name().empty()); |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5262 | if (use_proxy_connection_impact_histogram) { |
| 5263 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5264 | base::FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"), |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5265 | abandoned_page ? 1 : 0, 2); |
| 5266 | switch (load_type) { |
| 5267 | case NavigationState::NORMAL_LOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5268 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5269 | "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5270 | begin_to_finish_all_loads); |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5271 | break; |
| 5272 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5273 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5274 | "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5275 | begin_to_finish_all_loads); |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5276 | break; |
| 5277 | case NavigationState::LINK_LOAD_RELOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5278 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5279 | "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5280 | begin_to_finish_all_loads); |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5281 | break; |
| 5282 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5283 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5284 | "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5285 | begin_to_finish_all_loads); |
[email protected] | 78a258a | 2010-08-02 16:34:26 | [diff] [blame] | 5286 | break; |
| 5287 | default: |
| 5288 | break; |
| 5289 | } |
| 5290 | } |
| 5291 | |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5292 | // Histograms to determine if SDCH has an impact. |
| 5293 | // TODO(jar): Consider removing per-link load types and the enumeration. |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5294 | static bool use_sdch_histogram(base::FieldTrialList::Find("GlobalSdch") && |
| 5295 | !base::FieldTrialList::Find("GlobalSdch")->group_name().empty()); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5296 | if (use_sdch_histogram) { |
| 5297 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5298 | base::FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"), |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5299 | load_type, NavigationState::kLoadTypeMax); |
| 5300 | switch (load_type) { |
| 5301 | case NavigationState::NORMAL_LOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5302 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5303 | "PLT.BeginToFinish_NormalLoad", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5304 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5305 | break; |
| 5306 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5307 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5308 | "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5309 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5310 | break; |
| 5311 | case NavigationState::LINK_LOAD_RELOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5312 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5313 | "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5314 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5315 | break; |
| 5316 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5317 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5318 | "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5319 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5320 | break; |
| 5321 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5322 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5323 | "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"), |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5324 | begin_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5325 | break; |
| 5326 | default: |
| 5327 | break; |
| 5328 | } |
| 5329 | } |
| 5330 | |
| 5331 | // Histograms to determine if cache size has an impact on PLT. |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5332 | static bool use_cache_histogram1(base::FieldTrialList::Find("CacheSize") && |
| 5333 | !base::FieldTrialList::Find("CacheSize")->group_name().empty()); |
| 5334 | if (use_cache_histogram1 && |
| 5335 | NavigationState::LINK_LOAD_NORMAL <= load_type && |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5336 | NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) { |
| 5337 | // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like |
| 5338 | // StartToFinish or BeginToFinish would be better. |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5339 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5340 | "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc); |
| 5341 | } |
| 5342 | |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5343 | // Histograms to determine if cache throttling has an impact on PLT. |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 5344 | static bool use_cache_histogram2( |
| 5345 | base::FieldTrialList::Find("CacheThrottle") && |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5346 | !base::FieldTrialList::Find("CacheThrottle")->group_name().empty()); |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5347 | if (use_cache_histogram2) { |
| 5348 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5349 | base::FieldTrial::MakeName("PLT.Abandoned", "CacheThrottle"), |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5350 | abandoned_page ? 1 : 0, 2); |
| 5351 | switch (load_type) { |
| 5352 | case NavigationState::RELOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5353 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5354 | "PLT.BeginToFinish_Reload", "CacheThrottle"), |
| 5355 | begin_to_finish_all_loads); |
| 5356 | break; |
| 5357 | case NavigationState::HISTORY_LOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5358 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5359 | "PLT.BeginToFinish_HistoryLoad", "CacheThrottle"), |
| 5360 | begin_to_finish_all_loads); |
| 5361 | break; |
| 5362 | case NavigationState::NORMAL_LOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5363 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5364 | "PLT.BeginToFinish_NormalLoad", "CacheThrottle"), |
| 5365 | begin_to_finish_all_loads); |
| 5366 | break; |
| 5367 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5368 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5369 | "PLT.BeginToFinish_LinkLoadNormal", "CacheThrottle"), |
| 5370 | begin_to_finish_all_loads); |
| 5371 | break; |
| 5372 | case NavigationState::LINK_LOAD_RELOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5373 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5374 | "PLT.BeginToFinish_LinkLoadReload", "CacheThrottle"), |
| 5375 | begin_to_finish_all_loads); |
| 5376 | break; |
| 5377 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5378 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5379 | "PLT.BeginToFinish_LinkLoadStaleOk", "CacheThrottle"), |
| 5380 | begin_to_finish_all_loads); |
| 5381 | break; |
| 5382 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5383 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5384 | "PLT.BeginToFinish_LinkLoadCacheOnly", "CacheThrottle"), |
| 5385 | begin_to_finish_all_loads); |
| 5386 | break; |
| 5387 | default: |
| 5388 | break; |
| 5389 | } |
| 5390 | if (NavigationState::RELOAD <= load_type && |
| 5391 | NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) { |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5392 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 1a20f10 | 2010-09-16 21:50:39 | [diff] [blame] | 5393 | "PLT.BeginToFinish", "CacheThrottle"), |
| 5394 | begin_to_finish_all_loads); |
| 5395 | } |
| 5396 | } |
| 5397 | |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5398 | // For the SPDY field trials, we need to verify that the page loaded was |
| 5399 | // the type we requested: |
| 5400 | // if we asked for a SPDY request, we got a SPDY request |
| 5401 | // if we asked for a HTTP request, we got a HTTP request |
| 5402 | // Due to spdy version mismatches, it is possible that we ask for SPDY |
| 5403 | // but didn't get SPDY. |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5404 | static bool use_spdy_histogram(base::FieldTrialList::Find("SpdyImpact") && |
| 5405 | !base::FieldTrialList::Find("SpdyImpact")->group_name().empty()); |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5406 | if (use_spdy_histogram) { |
| 5407 | // We take extra effort to only compute these once. |
| 5408 | static bool in_spdy_trial = |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5409 | base::FieldTrialList::Find("SpdyImpact")->group_name() == |
| 5410 | "npn_with_spdy"; |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5411 | static bool in_http_trial = |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5412 | base::FieldTrialList::Find("SpdyImpact")->group_name() == |
| 5413 | "npn_with_http"; |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5414 | |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5415 | bool spdy_trial_success = navigation_state->was_fetched_via_spdy() ? |
| 5416 | in_spdy_trial : in_http_trial; |
| 5417 | if (spdy_trial_success) { |
| 5418 | // Histograms to determine if SPDY has an impact for https traffic. |
| 5419 | // TODO(mbelshe): After we've seen the difference between BeginToFinish |
| 5420 | // and StartToFinish, consider removing one or the other. |
| 5421 | if (scheme_type == URLPattern::SCHEME_HTTPS && |
| 5422 | navigation_state->was_npn_negotiated()) { |
| 5423 | UMA_HISTOGRAM_ENUMERATION( |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5424 | base::FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"), |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5425 | abandoned_page ? 1 : 0, 2); |
| 5426 | switch (load_type) { |
| 5427 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5428 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5429 | "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5430 | begin_to_finish_all_loads); |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5431 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5432 | "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5433 | start_to_finish_all_loads); |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5434 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5435 | "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5436 | start_to_commit); |
| 5437 | break; |
| 5438 | case NavigationState::NORMAL_LOAD: |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5439 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5440 | "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5441 | begin_to_finish_all_loads); |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5442 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5443 | "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5444 | start_to_finish_all_loads); |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5445 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5446 | "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5447 | start_to_commit); |
| 5448 | break; |
| 5449 | default: |
| 5450 | break; |
| 5451 | } |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 5452 | } |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5453 | |
| 5454 | // Histograms to compare the impact of alternate protocol over http |
| 5455 | // traffic: when spdy is used vs. when http is used. |
| 5456 | if (scheme_type == URLPattern::SCHEME_HTTP && |
| 5457 | navigation_state->was_alternate_protocol_available()) { |
| 5458 | if (!navigation_state->was_npn_negotiated()) { |
| 5459 | // This means that even there is alternate protocols for npn_http or |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 5460 | // npn_spdy, they are not taken (due to the base::FieldTrial). |
[email protected] | 8cfe6bb | 2010-08-27 02:35:00 | [diff] [blame] | 5461 | switch (load_type) { |
| 5462 | case NavigationState::LINK_LOAD_NORMAL: |
| 5463 | PLT_HISTOGRAM( |
| 5464 | "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http", |
| 5465 | start_to_finish_all_loads); |
| 5466 | PLT_HISTOGRAM( |
| 5467 | "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http", |
| 5468 | start_to_commit); |
| 5469 | break; |
| 5470 | case NavigationState::NORMAL_LOAD: |
| 5471 | PLT_HISTOGRAM( |
| 5472 | "PLT.StartToFinish_NormalLoad_AlternateProtocol_http", |
| 5473 | start_to_finish_all_loads); |
| 5474 | PLT_HISTOGRAM( |
| 5475 | "PLT.StartToCommit_NormalLoad_AlternateProtocol_http", |
| 5476 | start_to_commit); |
| 5477 | break; |
| 5478 | default: |
| 5479 | break; |
| 5480 | } |
| 5481 | } else if (navigation_state->was_fetched_via_spdy()) { |
| 5482 | switch (load_type) { |
| 5483 | case NavigationState::LINK_LOAD_NORMAL: |
| 5484 | PLT_HISTOGRAM( |
| 5485 | "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy", |
| 5486 | start_to_finish_all_loads); |
| 5487 | PLT_HISTOGRAM( |
| 5488 | "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy", |
| 5489 | start_to_commit); |
| 5490 | break; |
| 5491 | case NavigationState::NORMAL_LOAD: |
| 5492 | PLT_HISTOGRAM( |
| 5493 | "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy", |
| 5494 | start_to_finish_all_loads); |
| 5495 | PLT_HISTOGRAM( |
| 5496 | "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy", |
| 5497 | start_to_commit); |
| 5498 | break; |
| 5499 | default: |
| 5500 | break; |
| 5501 | } |
| 5502 | } |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 5503 | } |
| 5504 | } |
| 5505 | } |
| 5506 | |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5507 | // Record page load time and abandonment rates for proxy cases. |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5508 | if (navigation_state->was_fetched_via_proxy()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5509 | if (scheme_type == URLPattern::SCHEME_HTTPS) { |
| 5510 | PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5511 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5512 | abandoned_page ? 1 : 0, 2); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5513 | } else { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5514 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP); |
| 5515 | PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5516 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5517 | abandoned_page ? 1 : 0, 2); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5518 | } |
| 5519 | } else { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5520 | if (scheme_type == URLPattern::SCHEME_HTTPS) { |
| 5521 | PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https", |
| 5522 | start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5523 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5524 | abandoned_page ? 1 : 0, 2); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5525 | } else { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5526 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP); |
| 5527 | PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http", |
| 5528 | start_to_finish_all_loads); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5529 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http", |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5530 | abandoned_page ? 1 : 0, 2); |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5531 | } |
| 5532 | } |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 5533 | |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 5534 | // Site isolation metrics. |
| 5535 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess", |
| 5536 | cross_origin_access_count_); |
| 5537 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess", |
| 5538 | same_origin_access_count_); |
| 5539 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 5540 | // TODO(jar): This is the ONLY call in this method that needed more than |
| 5541 | // navigation_state. This should be relocated, or changed, so that this |
| 5542 | // body can be made a method on NavigationStates, and run via its destructor. |
[email protected] | cf9a7bc | 2010-06-11 18:54:50 | [diff] [blame] | 5543 | // Log some PLT data to the error log. |
| 5544 | LogNavigationState(navigation_state, main_frame->dataSource()); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 5545 | |
| 5546 | navigation_state->set_load_histograms_recorded(true); |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 5547 | |
| 5548 | // Since there are currently no guarantees that renderer histograms will be |
| 5549 | // sent to the browser, we initiate a PostTask here to be sure that we send |
| 5550 | // the histograms we generated. Without this call, pages that don't have an |
| 5551 | // on-close-handler might generate data that is lost when the renderer is |
| 5552 | // shutdown abruptly (perchance because the user closed the tab). |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 5553 | // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it |
| 5554 | // should post when the onload is complete, so that it doesn't interfere with |
| 5555 | // the next load. |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 5556 | if (RenderThread::current()) { |
| 5557 | RenderThread::current()->SendHistograms( |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 5558 | chrome::kHistogramSynchronizerReservedSequenceNumber); |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 5559 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 5560 | } |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 5561 | |
[email protected] | f899964 | 2009-10-27 21:39:42 | [diff] [blame] | 5562 | void RenderView::LogNavigationState(const NavigationState* state, |
| 5563 | const WebDataSource* ds) const { |
| 5564 | // Because this function gets called on every page load, |
| 5565 | // take extra care to optimize it away if logging is turned off. |
| 5566 | if (logging::LOG_INFO < logging::GetMinLogLevel()) |
| 5567 | return; |
| 5568 | |
| 5569 | DCHECK(state); |
| 5570 | DCHECK(ds); |
| 5571 | GURL url(ds->request().url()); |
| 5572 | Time start = state->start_load_time(); |
| 5573 | Time finish = state->finish_load_time(); |
| 5574 | // TODO(mbelshe): should we log more stats? |
| 5575 | LOG(INFO) << "PLT: " |
| 5576 | << (finish - start).InMilliseconds() |
| 5577 | << "ms " |
| 5578 | << url.spec(); |
| 5579 | } |
| 5580 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5581 | void RenderView::postAccessibilityNotification( |
| 5582 | const WebAccessibilityObject& obj, |
| 5583 | WebAccessibilityNotification notification) { |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 5584 | if (!accessibility_.get() && webview()) { |
| 5585 | // Load complete should be our first notification sent. |
| 5586 | // TODO(ctguil): Investigate if a different notification is a WebCore bug. |
| 5587 | if (notification != WebKit::WebAccessibilityNotificationLoadComplete) |
| 5588 | return; |
| 5589 | |
| 5590 | // Create and initialize our accessibility cache |
| 5591 | accessibility_.reset(WebAccessibilityCache::create()); |
| 5592 | accessibility_->initialize(webview()); |
| 5593 | } |
| 5594 | |
[email protected] | a3fa4f9 | 2010-09-30 22:19:33 | [diff] [blame] | 5595 | if (!accessibility_->isCached(obj)) { |
| 5596 | // The browser doesn't know about objects that are not in the cache. Send a |
| 5597 | // children change for the first accestor that actually is in the cache. |
| 5598 | WebAccessibilityObject parent = obj; |
| 5599 | while (parent.isValid() && !accessibility_->isCached(parent)) |
| 5600 | parent = parent.parentObject(); |
| 5601 | |
| 5602 | DCHECK(parent.isValid() && accessibility_->isCached(parent)); |
| 5603 | if (!parent.isValid()) |
| 5604 | return; |
| 5605 | postAccessibilityNotification( |
| 5606 | parent, WebKit::WebAccessibilityNotificationChildrenChanged); |
| 5607 | |
| 5608 | // The parent's children change takes care of the child's children change. |
| 5609 | if (notification == WebKit::WebAccessibilityNotificationChildrenChanged) |
| 5610 | return; |
| 5611 | } |
| 5612 | |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 5613 | // Add the accessibility object to our cache and ensure it's valid. |
| 5614 | if (accessibility_->addOrGetId(obj) < 0) |
[email protected] | a3018be | 2010-03-09 04:28:48 | [diff] [blame] | 5615 | return; |
| 5616 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5617 | ViewHostMsg_AccessibilityNotification_Params param; |
| 5618 | switch (notification) { |
| 5619 | case WebKit::WebAccessibilityNotificationCheckedStateChanged: |
| 5620 | param.notification_type = |
| 5621 | ViewHostMsg_AccessibilityNotification_Params:: |
| 5622 | NOTIFICATION_TYPE_CHECK_STATE_CHANGED; |
| 5623 | break; |
| 5624 | case WebKit::WebAccessibilityNotificationChildrenChanged: |
| 5625 | param.notification_type = |
| 5626 | ViewHostMsg_AccessibilityNotification_Params:: |
| 5627 | NOTIFICATION_TYPE_CHILDREN_CHANGED; |
| 5628 | break; |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 5629 | case WebKit::WebAccessibilityNotificationFocusedUIElementChanged: |
| 5630 | param.notification_type = |
| 5631 | ViewHostMsg_AccessibilityNotification_Params:: |
| 5632 | NOTIFICATION_TYPE_FOCUS_CHANGED; |
| 5633 | break; |
| 5634 | case WebKit::WebAccessibilityNotificationLoadComplete: |
| 5635 | param.notification_type = |
| 5636 | ViewHostMsg_AccessibilityNotification_Params:: |
| 5637 | NOTIFICATION_TYPE_LOAD_COMPLETE; |
| 5638 | break; |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5639 | case WebKit::WebAccessibilityNotificationValueChanged: |
| 5640 | param.notification_type = |
| 5641 | ViewHostMsg_AccessibilityNotification_Params:: |
| 5642 | NOTIFICATION_TYPE_VALUE_CHANGED; |
| 5643 | break; |
[email protected] | bd554c64 | 2010-10-01 19:52:04 | [diff] [blame] | 5644 | case WebKit::WebAccessibilityNotificationSelectedTextChanged: |
| 5645 | param.notification_type = |
| 5646 | ViewHostMsg_AccessibilityNotification_Params:: |
| 5647 | NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED; |
| 5648 | break; |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5649 | default: |
| 5650 | return; |
| 5651 | } |
| 5652 | param.acc_obj = WebAccessibility(obj, accessibility_.get()); |
[email protected] | a3018be | 2010-03-09 04:28:48 | [diff] [blame] | 5653 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5654 | if (pending_accessibility_notifications_.empty()) { |
| 5655 | Send(new ViewHostMsg_AccessibilityNotifications( |
| 5656 | routing_id_, |
| 5657 | pending_accessibility_notifications_)); |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 5658 | } |
| 5659 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5660 | pending_accessibility_notifications_.push_back(param); |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 5661 | } |
| 5662 | |
[email protected] | 0fda727 | 2009-06-26 15:49:33 | [diff] [blame] | 5663 | void RenderView::Print(WebFrame* frame, bool script_initiated) { |
| 5664 | DCHECK(frame); |
| 5665 | if (print_helper_.get() == NULL) { |
| 5666 | print_helper_.reset(new PrintWebViewHelper(this)); |
| 5667 | } |
| 5668 | print_helper_->Print(frame, script_initiated); |
| 5669 | } |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5670 | |
| 5671 | void RenderView::OnSetEditCommandsForNextKeyEvent( |
| 5672 | const EditCommands& edit_commands) { |
| 5673 | edit_commands_ = edit_commands; |
| 5674 | } |
| 5675 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5676 | void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5677 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5678 | if (!main_frame) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5679 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, |
| 5680 | false)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5681 | return; |
| 5682 | } |
| 5683 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5684 | WebDataSource* ds = main_frame->dataSource(); |
| 5685 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 5686 | if (!navigation_state->user_script_idle_scheduler()->has_run()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5687 | pending_code_execution_queue_.push( |
| 5688 | linked_ptr<ViewMsg_ExecuteCode_Params>( |
| 5689 | new ViewMsg_ExecuteCode_Params(params))); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5690 | return; |
| 5691 | } |
| 5692 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5693 | ExecuteCodeImpl(main_frame, params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | void RenderView::ExecuteCodeImpl(WebFrame* frame, |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5697 | const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5698 | std::vector<WebFrame*> frame_vector; |
| 5699 | frame_vector.push_back(frame); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5700 | if (params.all_frames) |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5701 | GetAllChildFrames(frame, &frame_vector); |
| 5702 | |
| 5703 | for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin(); |
| 5704 | frame_it != frame_vector.end(); ++frame_it) { |
| 5705 | WebFrame* frame = *frame_it; |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5706 | if (params.is_javascript) { |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 5707 | ExtensionRendererInfo* extension = |
| 5708 | ExtensionRendererInfo::GetByID(params.extension_id); |
| 5709 | |
| 5710 | const std::vector<URLPattern> host_permissions = |
| 5711 | extension->host_permissions(); |
| 5712 | if (!Extension::CanExecuteScriptOnPage( |
| 5713 | frame->url(), |
| 5714 | extension->allowed_to_execute_script_everywhere(), |
| 5715 | &host_permissions, |
| 5716 | NULL, |
| 5717 | NULL)) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5718 | continue; |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 5719 | } |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5720 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5721 | std::vector<WebScriptSource> sources; |
| 5722 | sources.push_back( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5723 | WebScriptSource(WebString::fromUTF8(params.code))); |
| 5724 | UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5725 | frame->executeScriptInIsolatedWorld( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5726 | UserScriptSlave::GetIsolatedWorldId(params.extension_id), |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5727 | &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 5728 | } else { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5729 | frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5730 | } |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5731 | } |
| 5732 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5733 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5734 | } |
| 5735 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5736 | void RenderView::Close() { |
| 5737 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5738 | WebView* doomed = webview(); |
| 5739 | RenderWidget::Close(); |
| 5740 | Singleton<ViewMap>::get()->erase(doomed); |
| 5741 | } |
| 5742 | |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5743 | void RenderView::DidHandleKeyEvent() { |
| 5744 | edit_commands_.clear(); |
| 5745 | } |
| 5746 | |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5747 | void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 5748 | page_click_tracker_->DidHandleMouseEvent(event); |
| 5749 | } |
| 5750 | |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5751 | #if defined(OS_MACOSX) |
| 5752 | void RenderView::OnWasHidden() { |
| 5753 | RenderWidget::OnWasHidden(); |
| 5754 | |
| 5755 | // Inform plugins that their container is no longer visible. |
| 5756 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5757 | for (plugin_it = plugin_delegates_.begin(); |
| 5758 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5759 | (*plugin_it)->SetContainerVisibility(false); |
| 5760 | } |
| 5761 | } |
| 5762 | |
| 5763 | void RenderView::OnWasRestored(bool needs_repainting) { |
| 5764 | RenderWidget::OnWasRestored(needs_repainting); |
| 5765 | |
| 5766 | // Inform plugins that their container is now visible. |
| 5767 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5768 | for (plugin_it = plugin_delegates_.begin(); |
| 5769 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5770 | (*plugin_it)->SetContainerVisibility(true); |
| 5771 | } |
| 5772 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5773 | #endif // OS_MACOSX |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5774 | |
| 5775 | void RenderView::OnSetFocus(bool enable) { |
| 5776 | RenderWidget::OnSetFocus(enable); |
| 5777 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5778 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5779 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5780 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5781 | for (plugin_it = plugin_delegates_.begin(); |
| 5782 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5783 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5784 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5785 | // activation state to change just like a call to setIsActive. |
| 5786 | if (enable) |
| 5787 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5788 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5789 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5790 | } |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5791 | |
| 5792 | // Notify all Pepper plugins. |
| 5793 | pepper_delegate_.OnSetFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5794 | } |
| 5795 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5796 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 5797 | void RenderView::EnsureDocumentTag() { |
| 5798 | // TODO(darin): There's actually no reason for this to be here. We should |
| 5799 | // have the browser side manage the document tag. |
| 5800 | #if defined(OS_MACOSX) |
| 5801 | if (!has_document_tag_) { |
| 5802 | // Make the call to get the tag. |
| 5803 | Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); |
| 5804 | has_document_tag_ = true; |
| 5805 | } |
| 5806 | #endif |
| 5807 | } |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 5808 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5809 | #if defined(OS_MACOSX) |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame^] | 5810 | void RenderView::SetPluginImeEnabled(bool enabled, int plugin_id) { |
| 5811 | IPC::Message* msg = new ViewHostMsg_SetPluginImeEnabled(routing_id(), |
| 5812 | enabled, plugin_id); |
| 5813 | // This message can be sent during event-handling, and needs to be delivered |
| 5814 | // within that context. |
| 5815 | msg->set_unblock(true); |
| 5816 | Send(msg); |
| 5817 | } |
| 5818 | |
[email protected] | ea04a4e1 | 2010-04-15 00:58:03 | [diff] [blame] | 5819 | gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5820 | bool opaque, bool root) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5821 | gfx::PluginWindowHandle window = NULL; |
| 5822 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5823 | routing_id(), opaque, root, &window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5824 | if (window) { |
| 5825 | fake_plugin_window_handles_.insert(window); |
| 5826 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5827 | return window; |
| 5828 | } |
| 5829 | |
| 5830 | void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) { |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5831 | if (window && fake_plugin_window_handles_.find(window) != |
| 5832 | fake_plugin_window_handles_.end()) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5833 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5834 | fake_plugin_window_handles_.erase(window); |
| 5835 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5836 | } |
| 5837 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5838 | void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window, |
| 5839 | int32 width, |
| 5840 | int32 height, |
| 5841 | uint64 io_surface_identifier) { |
| 5842 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5843 | routing_id(), window, width, height, io_surface_identifier)); |
| 5844 | } |
| 5845 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5846 | void RenderView::AcceleratedSurfaceSetTransportDIB( |
| 5847 | gfx::PluginWindowHandle window, |
| 5848 | int32 width, |
| 5849 | int32 height, |
| 5850 | TransportDIB::Handle transport_dib) { |
| 5851 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5852 | routing_id(), window, width, height, transport_dib)); |
| 5853 | } |
| 5854 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5855 | TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB( |
| 5856 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5857 | TransportDIB::Handle dib_handle; |
| 5858 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 5859 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5860 | return dib_handle; |
| 5861 | // Return an invalid handle if Send() fails. |
| 5862 | return TransportDIB::DefaultHandleValue(); |
| 5863 | } |
| 5864 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5865 | void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5866 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 5867 | } |
| 5868 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5869 | void RenderView::AcceleratedSurfaceBuffersSwapped( |
| 5870 | gfx::PluginWindowHandle window) { |
| 5871 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5872 | } |
| 5873 | #endif |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5874 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5875 | bool RenderView::ScheduleFileChooser( |
| 5876 | const ViewHostMsg_RunFileChooser_Params& params, |
| 5877 | WebFileChooserCompletion* completion) { |
| 5878 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 5879 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 5880 | // This sanity check prevents too many file choose requests from getting |
| 5881 | // queued which could DoS the user. Getting these is most likely a |
| 5882 | // programming error (there are many ways to DoS the user so it's not |
| 5883 | // considered a "real" security check), either in JS requesting many file |
| 5884 | // choosers to pop up, or in a plugin. |
| 5885 | // |
| 5886 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 5887 | // a file picker, which will address this issue in a better way. |
| 5888 | return false; |
| 5889 | } |
| 5890 | |
| 5891 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 5892 | new PendingFileChooser(params, completion))); |
| 5893 | if (file_chooser_completions_.size() == 1) { |
| 5894 | // Actually show the browse dialog when this is the first request. |
| 5895 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 5896 | } |
| 5897 | return true; |
| 5898 | } |
| 5899 | |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 5900 | void RenderView::OnPageTranslated() { |
| 5901 | WebFrame* frame = webview()->mainFrame(); |
| 5902 | if (!frame) |
| 5903 | return; |
| 5904 | |
| 5905 | // The page is translated, so try to extract the form data again. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5906 | autofill_helper_->FrameContentsAvailable(frame); |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 5907 | } |
| 5908 | |
[email protected] | 8a5f700 | 2010-03-31 13:47:35 | [diff] [blame] | 5909 | WebKit::WebGeolocationService* RenderView::geolocationService() { |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5910 | if (!geolocation_dispatcher_.get()) |
| 5911 | geolocation_dispatcher_.reset(new GeolocationDispatcher(this)); |
| 5912 | return geolocation_dispatcher_.get(); |
| 5913 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5914 | |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 5915 | WebKit::WebSpeechInputController* RenderView::speechInputController( |
| 5916 | WebKit::WebSpeechInputListener* listener) { |
| 5917 | if (!speech_input_dispatcher_.get()) |
| 5918 | speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener)); |
| 5919 | return speech_input_dispatcher_.get(); |
| 5920 | } |
| 5921 | |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 5922 | WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() { |
| 5923 | if (!device_orientation_dispatcher_.get()) |
| 5924 | device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this)); |
| 5925 | return device_orientation_dispatcher_.get(); |
| 5926 | } |
| 5927 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5928 | void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) { |
| 5929 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 5930 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 5931 | // different). |
| 5932 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 5933 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5934 | int minimum_percent = static_cast<int>( |
| 5935 | WebView::zoomLevelToZoomFactor(minimum_level) * 100); |
| 5936 | int maximum_percent = static_cast<int>( |
| 5937 | WebView::zoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5938 | |
| 5939 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 5940 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 5941 | } |
| 5942 | |
| 5943 | void RenderView::zoomLevelChanged() { |
| 5944 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 5945 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5946 | // Tell the browser which url got zoomed so it can update the menu and the |
| 5947 | // saved values if necessary |
| 5948 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | 1cc58eb6 | 2010-10-01 22:38:41 | [diff] [blame] | 5949 | routing_id_, webview()->zoomLevel(), remember, |
| 5950 | GURL(webview()->mainFrame()->url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5951 | } |
| 5952 | |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 5953 | bool RenderView::IsNonLocalTopLevelNavigation( |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5954 | const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 5955 | // Must be a top level frame. |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5956 | if (frame->parent() != NULL) |
| 5957 | return false; |
| 5958 | |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 5959 | // Navigations initiated within Webkit are not sent out to the external host |
| 5960 | // in the following cases. |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 5961 | // 1. The url scheme is not http/https |
| 5962 | // 2. There is no opener and this is not the first url being opened by this |
| 5963 | // RenderView. |
| 5964 | // 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] | 5965 | // opener relationship is maintained. |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 5966 | // 4. Reloads/form submits/back forward navigations |
| 5967 | if (!url.SchemeIs("http") && !url.SchemeIs("https")) |
| 5968 | return false; |
| 5969 | |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5970 | // Not interested in reloads. |
| 5971 | if (type != WebKit::WebNavigationTypeReload && |
[email protected] | 070c49c | 2010-07-13 22:22:01 | [diff] [blame] | 5972 | type != WebKit::WebNavigationTypeFormSubmitted && |
| 5973 | type != WebKit::WebNavigationTypeBackForward) { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5974 | // The opener relationship between the new window and the parent allows the |
| 5975 | // new window to script the parent and vice versa. This is not allowed if |
| 5976 | // the origins of the two domains are different. This can be treated as a |
| 5977 | // top level navigation and routed back to the host. |
| 5978 | WebKit::WebFrame* opener = frame->opener(); |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 5979 | if (!opener) { |
[email protected] | fe9eb4f9 | 2010-08-27 23:16:47 | [diff] [blame] | 5980 | // Force link click navigations to always be routed to the host as they |
| 5981 | // may update session state on the server. |
| 5982 | if (type == WebKit::WebNavigationTypeLinkClicked) |
| 5983 | return true; |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 5984 | // If this is the first page being loaded by this RenderView instance then |
| 5985 | // it should stay here. |
| 5986 | if (page_id_ == -1) { |
| 5987 | return false; |
| 5988 | } else { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5989 | return true; |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 5990 | } |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5991 | } |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 5992 | |
| 5993 | if (url.GetOrigin() != GURL(opener->url()).GetOrigin()) |
| 5994 | return true; |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 5995 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5996 | return false; |
| 5997 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 5998 | |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 5999 | void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code, |
| 6000 | IPC::PlatformFileForTransit file_for_transit, |
| 6001 | int message_id) { |
| 6002 | pepper_delegate_.OnAsyncFileOpened( |
| 6003 | error_code, |
| 6004 | IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
| 6005 | message_id); |
| 6006 | } |