[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] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 18 | #include "base/metrics/field_trial.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 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] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 43 | #include "chrome/common/renderer_preferences.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 44 | #include "chrome/common/thumbnail_score.h" |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 45 | #include "chrome/common/url_constants.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 46 | #include "chrome/common/window_container_type.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 47 | #include "chrome/renderer/about_handler.h" |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 48 | #include "chrome/renderer/audio_message_filter.h" |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 49 | #include "chrome/renderer/autofill_helper.h" |
[email protected] | 2f97917 | 2010-09-16 21:54:03 | [diff] [blame] | 50 | #include "chrome/renderer/automation/dom_automation_controller.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 51 | #include "chrome/renderer/blocked_plugin.h" |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 52 | #include "chrome/renderer/device_orientation_dispatcher.h" |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 53 | #include "chrome/renderer/devtools_agent.h" |
| 54 | #include "chrome/renderer/devtools_client.h" |
[email protected] | 2f97917 | 2010-09-16 21:54:03 | [diff] [blame] | 55 | #include "chrome/renderer/dom_ui_bindings.h" |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 56 | #include "chrome/renderer/extension_groups.h" |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 57 | #include "chrome/renderer/extensions/bindings_utils.h" |
[email protected] | f816c01 | 2009-06-26 21:48:32 | [diff] [blame] | 58 | #include "chrome/renderer/extensions/event_bindings.h" |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 59 | #include "chrome/renderer/extensions/extension_process_bindings.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 60 | #include "chrome/renderer/extensions/extension_renderer_info.h" |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 61 | #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
[email protected] | 2f97917 | 2010-09-16 21:54:03 | [diff] [blame] | 62 | #include "chrome/renderer/external_host_bindings.h" |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 63 | #include "chrome/renderer/external_popup_menu.h" |
[email protected] | ecad776 | 2010-10-22 13:58:48 | [diff] [blame] | 64 | #include "chrome/renderer/geolocation_dispatcher_old.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] | 25e18f8 | 2010-10-27 16:38:43 | [diff] [blame] | 85 | #include "chrome/renderer/user_script_idle_scheduler.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 86 | #include "chrome/renderer/user_script_slave.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 87 | #include "chrome/renderer/visitedlink_slave.h" |
[email protected] | d439ba07 | 2009-10-17 22:32:29 | [diff] [blame] | 88 | #include "chrome/renderer/webplugin_delegate_pepper.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 89 | #include "chrome/renderer/webplugin_delegate_proxy.h" |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 90 | #include "chrome/renderer/websharedworker_proxy.h" |
[email protected] | eb47a13 | 2009-03-04 00:39:56 | [diff] [blame] | 91 | #include "chrome/renderer/webworker_proxy.h" |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 92 | #include "gfx/color_utils.h" |
| 93 | #include "gfx/favicon_size.h" |
[email protected] | 5c7293a | 2010-03-17 06:40:57 | [diff] [blame] | 94 | #include "gfx/native_widget_types.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 95 | #include "gfx/point.h" |
| 96 | #include "gfx/rect.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 97 | #include "grit/generated_resources.h" |
| 98 | #include "grit/renderer_resources.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 99 | #include "media/base/media_switches.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 100 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 101 | #include "net/base/escape.h" |
| 102 | #include "net/base/net_errors.h" |
[email protected] | c399a8a | 2008-11-22 19:38:00 | [diff] [blame] | 103 | #include "skia/ext/bitmap_platform_device.h" |
[email protected] | 83c9e655 | 2008-12-03 16:22:10 | [diff] [blame] | 104 | #include "skia/ext/image_operations.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 105 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 106 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 107 | #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 108 | #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
| 109 | #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 110 | #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 111 | #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 112 | #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 113 | #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 114 | #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" |
| 115 | #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 116 | #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 117 | #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 118 | #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
| 119 | #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 120 | #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 121 | #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 122 | #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 123 | #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 124 | #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 125 | #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 126 | #include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 127 | #include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 128 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 129 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 130 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 131 | #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
| 132 | #include "third_party/WebKit/WebKit/chromium/public/WebRange.h" |
| 133 | #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 134 | #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" |
| 135 | #include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h" |
| 136 | #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 137 | #include "third_party/WebKit/WebKit/chromium/public/WebSettings.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 138 | #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 139 | #include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 140 | #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 141 | #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 142 | #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" |
| 143 | #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 144 | #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
| 145 | #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 146 | #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 147 | #include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 148 | #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h" |
| 149 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 150 | #include "v8/include/v8.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 151 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | 25e18f8 | 2010-10-27 16:38:43 | [diff] [blame] | 152 | #include "webkit/glue/alt_error_page_resource_fetcher.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 153 | #include "webkit/glue/context_menu.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 154 | #include "webkit/glue/dom_operations.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 155 | #include "webkit/glue/form_data.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 156 | #include "webkit/glue/form_field.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 157 | #include "webkit/glue/glue_serialize.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 158 | #include "webkit/glue/image_decoder.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 159 | #include "webkit/glue/image_resource_fetcher.h" |
[email protected] | 8e296bbd | 2009-07-22 21:37:17 | [diff] [blame] | 160 | #include "webkit/glue/media/buffered_data_source.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 161 | #include "webkit/glue/media/simple_data_source.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 162 | #include "webkit/glue/media/video_renderer_impl.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 163 | #include "webkit/glue/password_form_dom_manager.h" |
[email protected] | 0d64bb7 | 2010-07-07 05:36:38 | [diff] [blame] | 164 | #include "webkit/glue/plugins/default_plugin_shared.h" |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 165 | #include "webkit/glue/plugins/pepper_webplugin_impl.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 166 | #include "webkit/glue/plugins/plugin_list.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 167 | #include "webkit/glue/plugins/webplugin_delegate.h" |
[email protected] | 8a3b796 | 2009-09-04 05:53:23 | [diff] [blame] | 168 | #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 169 | #include "webkit/glue/plugins/webplugin_impl.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 170 | #include "webkit/glue/plugins/webview_plugin.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 171 | #include "webkit/glue/site_isolation_metrics.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 172 | #include "webkit/glue/webaccessibility.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 173 | #include "webkit/glue/webdropdata.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 174 | #include "webkit/glue/webkit_glue.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 175 | #include "webkit/glue/webmediaplayer_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 176 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 177 | #if defined(OS_WIN) |
| 178 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 179 | // * theming |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 180 | #include "gfx/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 181 | #elif defined(USE_X11) |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 182 | #include "gfx/native_theme_linux.h" |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 183 | #include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 184 | #elif defined(OS_MACOSX) |
| 185 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 186 | #endif |
| 187 | |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 188 | using WebKit::WebAccessibilityCache; |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 189 | using WebKit::WebAccessibilityNotification; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 190 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 191 | using WebKit::WebApplicationCacheHost; |
| 192 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 193 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 194 | using WebKit::WebColor; |
| 195 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 196 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 197 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 198 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 199 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 200 | using WebKit::WebDataSource; |
[email protected] | 2661b33 | 2009-11-03 18:42:29 | [diff] [blame] | 201 | using WebKit::WebDevToolsAgent; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 202 | using WebKit::WebDocument; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 203 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 204 | using WebKit::WebDragOperation; |
| 205 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 206 | using WebKit::WebEditingAction; |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 207 | using WebKit::WebElement; |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 208 | using WebKit::WebExternalPopupMenu; |
| 209 | using WebKit::WebExternalPopupMenuClient; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 210 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 211 | using WebKit::WebFileSystem; |
| 212 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 213 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 214 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 215 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 216 | using WebKit::WebFrame; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 217 | using WebKit::WebHistoryItem; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 218 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 219 | using WebKit::WebInputElement; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 220 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 221 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 222 | using WebKit::WebMediaPlayerClient; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 223 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 224 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 225 | using WebKit::WebNode; |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 226 | using WebKit::WebPageSerializer; |
| 227 | using WebKit::WebPageSerializerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 228 | using WebKit::WebPlugin; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 229 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 230 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 231 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 232 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 233 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 234 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 235 | using WebKit::WebRect; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 236 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 237 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 238 | using WebKit::WebSecurityOrigin; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 239 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 240 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 241 | using WebKit::WebSize; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 242 | using WebKit::WebStorageNamespace; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 243 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 244 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 245 | using WebKit::WebTextDirection; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 246 | using WebKit::WebURL; |
| 247 | using WebKit::WebURLError; |
| 248 | using WebKit::WebURLRequest; |
| 249 | using WebKit::WebURLResponse; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 250 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 251 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 252 | using WebKit::WebWidget; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 253 | using WebKit::WebWindowFeatures; |
[email protected] | 27ba853 | 2009-04-24 20:22:43 | [diff] [blame] | 254 | using WebKit::WebWorker; |
| 255 | using WebKit::WebWorkerClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 256 | using appcache::WebApplicationCacheHostImpl; |
| 257 | using base::Time; |
| 258 | using base::TimeDelta; |
| 259 | using webkit_glue::AltErrorPageResourceFetcher; |
| 260 | using webkit_glue::FormData; |
| 261 | using webkit_glue::FormField; |
| 262 | using webkit_glue::ImageResourceFetcher; |
| 263 | using webkit_glue::PasswordForm; |
| 264 | using webkit_glue::PasswordFormDomManager; |
| 265 | using webkit_glue::SiteIsolationMetrics; |
| 266 | using webkit_glue::WebAccessibility; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 267 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 268 | //----------------------------------------------------------------------------- |
| 269 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 270 | typedef std::map<WebKit::WebView*, RenderView*> ViewMap; |
| 271 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 272 | // define to write the time necessary for thumbnail/DOM text retrieval, |
| 273 | // respectively, into the system debug log |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 274 | // #define TIME_TEXT_RETRIEVAL |
| 275 | |
| 276 | // maximum number of characters in the document to index, any text beyond this |
| 277 | // point will be clipped |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 278 | static const size_t kMaxIndexChars = 65535; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 279 | |
| 280 | // Size of the thumbnails that we'll generate |
[email protected] | 8b4f489 | 2009-09-04 21:52:37 | [diff] [blame] | 281 | static const int kThumbnailWidth = 212; |
| 282 | static const int kThumbnailHeight = 132; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 283 | |
| 284 | // Delay in milliseconds that we'll wait before capturing the page contents |
| 285 | // and thumbnail. |
| 286 | static const int kDelayForCaptureMs = 500; |
| 287 | |
| 288 | // Typically, we capture the page data once the page is loaded. |
| 289 | // Sometimes, the page never finishes to load, preventing the page capture |
| 290 | // To workaround this problem, we always perform a capture after the following |
| 291 | // delay. |
| 292 | static const int kDelayForForcedCaptureMs = 6000; |
| 293 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 294 | // Time, in seconds, we delay before sending content state changes (such as form |
| 295 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 296 | // spamming the browser. |
| 297 | // To avoid having tab/session restore require sending a message to get the |
| 298 | // current content state during tab closing we use a shorter timeout for the |
| 299 | // foreground renderer. This means there is a small window of time from which |
| 300 | // content state is modified and not sent to session restore, but this is |
| 301 | // better than having to wake up all renderers during shutdown. |
| 302 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 303 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 304 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 305 | // The maximum number of popups that can be spawned from one page. |
| 306 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 307 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 308 | static const char kBackForwardNavigationScheme[] = "history"; |
[email protected] | 50b691c | 2008-10-31 19:08:35 | [diff] [blame] | 309 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 310 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 311 | WebVector<WebURL> urls; |
| 312 | ds->redirectChain(urls); |
| 313 | result->reserve(urls.size()); |
| 314 | for (size_t i = 0; i < urls.size(); ++i) |
| 315 | result->push_back(urls[i]); |
| 316 | } |
| 317 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 318 | static bool PaintViewIntoCanvas(WebView* view, |
| 319 | skia::PlatformCanvas& canvas) { |
| 320 | view->layout(); |
| 321 | const WebSize& size = view->size(); |
| 322 | |
| 323 | if (!canvas.initialize(size.width, size.height, true)) |
| 324 | return false; |
| 325 | |
| 326 | view->paint(webkit_glue::ToWebCanvas(&canvas), |
| 327 | WebRect(0, 0, size.width, size.height)); |
| 328 | // TODO: Add a way to snapshot the whole page, not just the currently |
| 329 | // visible part. |
| 330 | |
| 331 | return true; |
| 332 | } |
| 333 | |
| 334 | // Calculates how "boring" a thumbnail is. The boring score is the |
| 335 | // 0,1 ranged percentage of pixels that are the most common |
| 336 | // luma. Higher boring scores indicate that a higher percentage of a |
| 337 | // bitmap are all the same brightness. |
| 338 | static double CalculateBoringScore(SkBitmap* bitmap) { |
| 339 | int histogram[256] = {0}; |
| 340 | color_utils::BuildLumaHistogram(bitmap, histogram); |
| 341 | |
| 342 | int color_count = *std::max_element(histogram, histogram + 256); |
| 343 | int pixel_count = bitmap->width() * bitmap->height(); |
| 344 | return static_cast<double>(color_count) / pixel_count; |
| 345 | } |
| 346 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 347 | // True if |frame| contains content that is white-listed for content settings. |
| 348 | static bool IsWhitelistedForContentSettings(WebFrame* frame) { |
| 349 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 350 | if (origin.isEmpty()) |
| 351 | return false; // Uninitialized document? |
| 352 | |
| 353 | if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
| 354 | return true; // Browser UI elements should still work. |
| 355 | |
| 356 | // If the scheme is ftp: or file:, an empty file name indicates a directory |
| 357 | // listing, which requires JavaScript to function properly. |
| 358 | GURL frame_url = frame->url(); |
| 359 | const char* kDirProtocols[] = { "ftp", "file" }; |
| 360 | for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { |
| 361 | if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { |
| 362 | return frame_url.SchemeIs(kDirProtocols[i]) && |
| 363 | frame_url.ExtractFileName().empty(); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | return false; |
| 368 | } |
| 369 | |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 370 | // Returns true if the frame is navigating to an URL either into or out of an |
| 371 | // extension app's extent. |
| 372 | static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) { |
| 373 | if (!RenderThread::current()) |
| 374 | return false; |
| 375 | |
| 376 | // If the URL is still empty, this is a window.open navigation. Check the |
| 377 | // opener's URL. |
| 378 | GURL old_url(frame->url()); |
| 379 | if (old_url.is_empty() && frame->opener()) |
| 380 | old_url = frame->opener()->url(); |
| 381 | |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 382 | return !ExtensionRendererInfo::InSameExtent(old_url, new_url); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 383 | } |
| 384 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 385 | // Returns the ISO 639_1 language code of the specified |text|, or 'unknown' |
| 386 | // if it failed. |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 387 | static std::string DetermineTextLanguage(const string16& text) { |
[email protected] | 655f97c3 | 2010-07-22 21:24:17 | [diff] [blame] | 388 | std::string language = chrome::kUnknownLanguageCode; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 389 | int num_languages = 0; |
[email protected] | a9558688 | 2010-08-02 18:40:08 | [diff] [blame] | 390 | int text_bytes = 0; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 391 | bool is_reliable = false; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 392 | Language cld_language = |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 393 | DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable, |
[email protected] | a9558688 | 2010-08-02 18:40:08 | [diff] [blame] | 394 | &num_languages, NULL, &text_bytes); |
| 395 | // We don't trust the result if the CLD reports that the detection is not |
| 396 | // reliable, or if the actual text used to detect the language was less than |
| 397 | // 100 bytes (short texts can often lead to wrong results). |
| 398 | if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES && |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 399 | cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) { |
| 400 | // We should not use LanguageCode_ISO_639_1 because it does not cover all |
| 401 | // the languages CLD can detect. As a result, it'll return the invalid |
| 402 | // language code for tradtional Chinese among others. |
| 403 | // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and |
| 404 | // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN |
| 405 | // for Simplified Chinese. |
| 406 | language = LanguageCodeWithDialects(cld_language); |
| 407 | } |
| 408 | return language; |
| 409 | } |
| 410 | |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 411 | // Returns true if the parameter node is a textfield, text area or a content |
| 412 | // editable div. |
| 413 | static bool IsEditableNode(const WebNode& node) { |
| 414 | bool is_editable_node = false; |
| 415 | if (!node.isNull()) { |
| 416 | if (node.isContentEditable()) { |
| 417 | is_editable_node = true; |
| 418 | } else if (node.isElementNode()) { |
| 419 | is_editable_node = |
| 420 | node.toConst<WebElement>().isTextFormControlElement(); |
| 421 | } |
| 422 | } |
| 423 | return is_editable_node; |
| 424 | } |
| 425 | |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 426 | static bool WebAccessibilityNotificationToViewHostMsg( |
| 427 | WebAccessibilityNotification notification, |
| 428 | ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) { |
| 429 | switch (notification) { |
| 430 | case WebKit::WebAccessibilityNotificationCheckedStateChanged: |
| 431 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 432 | NOTIFICATION_TYPE_CHECK_STATE_CHANGED; |
| 433 | break; |
| 434 | case WebKit::WebAccessibilityNotificationChildrenChanged: |
| 435 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 436 | NOTIFICATION_TYPE_CHILDREN_CHANGED; |
| 437 | break; |
| 438 | case WebKit::WebAccessibilityNotificationFocusedUIElementChanged: |
| 439 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 440 | NOTIFICATION_TYPE_FOCUS_CHANGED; |
| 441 | break; |
| 442 | case WebKit::WebAccessibilityNotificationLoadComplete: |
| 443 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 444 | NOTIFICATION_TYPE_LOAD_COMPLETE; |
| 445 | break; |
| 446 | case WebKit::WebAccessibilityNotificationValueChanged: |
| 447 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 448 | NOTIFICATION_TYPE_VALUE_CHANGED; |
| 449 | break; |
| 450 | case WebKit::WebAccessibilityNotificationSelectedTextChanged: |
| 451 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 452 | NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED; |
| 453 | break; |
| 454 | default: |
| 455 | // TODO(ctguil): Support additional webkit notifications. |
| 456 | return false; |
| 457 | } |
| 458 | return true; |
| 459 | } |
| 460 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 461 | /////////////////////////////////////////////////////////////////////////////// |
| 462 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 463 | int32 RenderView::next_page_id_ = 1; |
| 464 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 465 | struct RenderView::PendingFileChooser { |
| 466 | PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, |
| 467 | WebFileChooserCompletion* c) |
| 468 | : params(p), |
| 469 | completion(c) { |
| 470 | } |
| 471 | ViewHostMsg_RunFileChooser_Params params; |
| 472 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 473 | }; |
| 474 | |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 475 | RenderView::RenderView(RenderThreadBase* render_thread, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 476 | const WebPreferences& webkit_preferences, |
| 477 | int64 session_storage_namespace_id) |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 478 | : RenderWidget(render_thread, WebKit::WebPopupTypeNone), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 479 | webkit_preferences_(webkit_preferences), |
| 480 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 481 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 482 | send_preferred_size_changes_(false), |
| 483 | script_can_close_(true), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 484 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 485 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 486 | opened_by_user_gesture_(true), |
| 487 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 488 | page_id_(-1), |
| 489 | last_page_id_sent_to_browser_(-1), |
| 490 | last_indexed_page_id_(-1), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 491 | history_list_offset_(-1), |
| 492 | history_list_length_(0), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 493 | has_unload_listener_(false), |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 494 | #if defined(OS_MACOSX) |
| 495 | has_document_tag_(false), |
| 496 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 497 | document_tag_(0), |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 498 | cross_origin_access_count_(0), |
| 499 | same_origin_access_count_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 500 | target_url_status_(TARGET_NONE), |
| 501 | spelling_panel_visible_(false), |
| 502 | view_type_(ViewType::INVALID), |
| 503 | browser_window_id_(-1), |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 504 | ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 505 | ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)), |
| 506 | ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)), |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 507 | ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 508 | ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)), |
| 509 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
| 510 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 511 | notification_provider_(new NotificationProvider(this))), |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 512 | accessibility_ack_pending_(false), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 513 | session_storage_namespace_id_(session_storage_namespace_id), |
| 514 | decrement_shared_popup_at_destruction_(false) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 515 | password_autocomplete_manager_.reset(new PasswordAutocompleteManager(this)); |
| 516 | autofill_helper_.reset(new AutoFillHelper(this)); |
| 517 | page_click_tracker_.reset(new PageClickTracker(this)); |
| 518 | // Note that the order of insertion of the listeners is important. |
| 519 | // The password_autocomplete_manager_ takes the first shot at processing the |
| 520 | // notification and can stop the propagation. |
| 521 | page_click_tracker_->AddListener(password_autocomplete_manager_.get()); |
| 522 | page_click_tracker_->AddListener(autofill_helper_.get()); |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 523 | ClearBlockedContentSettings(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | RenderView::~RenderView() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 527 | if (decrement_shared_popup_at_destruction_) |
| 528 | shared_popup_counter_->data--; |
| 529 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 530 | // Dispose of un-disposed image fetchers. |
| 531 | for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin(); |
| 532 | i != image_fetchers_.end(); ++i) { |
| 533 | delete *i; |
| 534 | } |
| 535 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 536 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 537 | while (!file_chooser_completions_.empty()) { |
| 538 | if (file_chooser_completions_.front()->completion) { |
| 539 | file_chooser_completions_.front()->completion->didChooseFile( |
| 540 | WebVector<WebString>()); |
| 541 | } |
| 542 | file_chooser_completions_.pop_front(); |
| 543 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 544 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 545 | #if defined(OS_MACOSX) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 546 | // Tell the spellchecker that the document is closed. |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 547 | if (has_document_tag_) |
| 548 | Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 549 | |
| 550 | // Destroy all fake plugin window handles on the browser side. |
| 551 | while (!fake_plugin_window_handles_.empty()) { |
| 552 | // Make sure no NULL plugin window handles were inserted into this list. |
| 553 | DCHECK(*fake_plugin_window_handles_.begin()); |
| 554 | // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. |
| 555 | DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); |
| 556 | } |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 557 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 558 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 559 | render_thread_->RemoveFilter(audio_message_filter_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 560 | |
| 561 | #ifndef NDEBUG |
| 562 | // Make sure we are no longer referenced by the ViewMap. |
| 563 | ViewMap* views = Singleton<ViewMap>::get(); |
| 564 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 565 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 566 | #endif |
| 567 | } |
| 568 | |
| 569 | /*static*/ |
| 570 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
| 571 | ViewMap* views = Singleton<ViewMap>::get(); |
| 572 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 573 | if (!visitor->Visit(it->second)) |
| 574 | return; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | /*static*/ |
| 579 | RenderView* RenderView::FromWebView(WebView* webview) { |
| 580 | ViewMap* views = Singleton<ViewMap>::get(); |
| 581 | ViewMap::iterator it = views->find(webview); |
| 582 | return it == views->end() ? NULL : it->second; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /*static*/ |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 586 | RenderView* RenderView::Create( |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 587 | RenderThreadBase* render_thread, |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 588 | gfx::NativeViewId parent_hwnd, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 589 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 590 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 591 | const WebPreferences& webkit_prefs, |
| 592 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 593 | int32 routing_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 594 | int64 session_storage_namespace_id, |
| 595 | const string16& frame_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 596 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 597 | scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs, |
| 598 | session_storage_namespace_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 599 | view->Init(parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 600 | opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 601 | renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 602 | counter, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 603 | routing_id, |
| 604 | frame_name); // adds reference |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 605 | return view; |
| 606 | } |
| 607 | |
| 608 | /*static*/ |
| 609 | void RenderView::SetNextPageID(int32 next_page_id) { |
| 610 | // This method should only be called during process startup, and the given |
| 611 | // page id had better not exceed our current next page id! |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 612 | DCHECK_EQ(next_page_id_, 1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 613 | DCHECK(next_page_id >= next_page_id_); |
| 614 | next_page_id_ = next_page_id; |
| 615 | } |
| 616 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 617 | WebKit::WebView* RenderView::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 618 | return static_cast<WebKit::WebView*>(webwidget()); |
| 619 | } |
| 620 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 621 | void RenderView::UserMetricsRecordAction(const std::string& action) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 622 | Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); |
| 623 | } |
| 624 | |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 625 | void RenderView::PluginCrashed(const FilePath& plugin_path) { |
| 626 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 627 | } |
| 628 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 629 | WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame, |
| 630 | const WebPluginParams& params) { |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 631 | WebPluginInfo info; |
| 632 | bool found; |
| 633 | ContentSetting setting; |
| 634 | std::string mime_type; |
| 635 | Send(new ViewHostMsg_GetPluginInfo( |
| 636 | params.url, frame->top()->url(), params.mimeType.utf8(), &found, |
| 637 | &info, &setting, &mime_type)); |
| 638 | if (!found || !info.enabled) |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 639 | return NULL; |
| 640 | scoped_refptr<pepper::PluginModule> pepper_module = |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 641 | PepperPluginRegistry::GetInstance()->GetModule(info.path); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 642 | if (pepper_module) |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 643 | return CreatePepperPlugin(frame, params, info.path, pepper_module.get()); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 644 | else |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 645 | return CreateNPAPIPlugin(frame, params, info.path, mime_type); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 646 | } |
| 647 | |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 648 | void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 649 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 650 | // If the renderer is visible, set initial visibility and focus state. |
| 651 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 652 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 653 | delegate->SetContainerVisibility(true); |
| 654 | if (webview() && webview()->isActive()) |
| 655 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 656 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 657 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 658 | // Plugins start assuming the content has focus (so that they work in |
| 659 | // environments where RenderView isn't hosting them), so we always have to |
| 660 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 661 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 665 | plugin_delegates_.erase(delegate); |
| 666 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 667 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 668 | void RenderView::Init(gfx::NativeViewId parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 669 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 670 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 671 | SharedRenderViewCounter* counter, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 672 | int32 routing_id, |
| 673 | const string16& frame_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 674 | DCHECK(!webview()); |
| 675 | |
| 676 | if (opener_id != MSG_ROUTING_NONE) |
| 677 | opener_id_ = opener_id; |
| 678 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 679 | if (counter) { |
| 680 | shared_popup_counter_ = counter; |
| 681 | shared_popup_counter_->data++; |
| 682 | decrement_shared_popup_at_destruction_ = true; |
| 683 | } else { |
| 684 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 685 | decrement_shared_popup_at_destruction_ = false; |
| 686 | } |
| 687 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 688 | devtools_agent_.reset(new DevToolsAgent(routing_id, this)); |
[email protected] | 9b9d728 | 2009-04-08 14:13:04 | [diff] [blame] | 689 | |
[email protected] | 9a6c623 | 2010-06-25 11:46:49 | [diff] [blame] | 690 | webwidget_ = WebView::create(this, devtools_agent_.get()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 691 | Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 692 | webkit_preferences_.Apply(webview()); |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 693 | webview()->initializeMainFrame(this); |
[email protected] | c1e0696 | 2010-06-17 16:53:23 | [diff] [blame] | 694 | if (!frame_name.empty()) |
| 695 | webview()->mainFrame()->setName(frame_name); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 696 | |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 697 | OnSetRendererPrefs(renderer_prefs); |
| 698 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 699 | routing_id_ = routing_id; |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 700 | render_thread_->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 701 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 702 | // when we receive ViewMsg_Close. |
| 703 | AddRef(); |
| 704 | |
| 705 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 706 | // completing initialization. Otherwise, we can finish it now. |
| 707 | if (opener_id == MSG_ROUTING_NONE) { |
| 708 | did_show_ = true; |
| 709 | CompleteInit(parent_hwnd); |
| 710 | } |
| 711 | |
| 712 | host_window_ = parent_hwnd; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 713 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 714 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 715 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 716 | enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION; |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 717 | if (command_line.HasSwitch(switches::kEnableAccessibility)) |
| 718 | WebAccessibilityCache::enableAccessibility(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 719 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 720 | audio_message_filter_ = new AudioMessageFilter(routing_id_); |
| 721 | render_thread_->AddFilter(audio_message_filter_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | void RenderView::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 725 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 726 | if (main_frame) |
| 727 | child_process_logging::SetActiveURL(main_frame->url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 728 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 729 | // If this is developer tools renderer intercept tools messages first. |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 730 | if (devtools_client_.get() && devtools_client_->OnMessageReceived(message)) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 731 | return; |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 732 | if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message)) |
| 733 | return; |
[email protected] | b6849bda | 2009-10-14 23:59:26 | [diff] [blame] | 734 | if (notification_provider_->OnMessageReceived(message)) |
| 735 | return; |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 736 | if (geolocation_dispatcher_.get() && |
| 737 | geolocation_dispatcher_->OnMessageReceived(message)) { |
| 738 | return; |
| 739 | } |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 740 | if (speech_input_dispatcher_.get() && |
| 741 | speech_input_dispatcher_->OnMessageReceived(message)) { |
| 742 | return; |
| 743 | } |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 744 | if (device_orientation_dispatcher_.get() && |
| 745 | device_orientation_dispatcher_->OnMessageReceived(message)) { |
| 746 | return; |
| 747 | } |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 748 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 749 | IPC_BEGIN_MESSAGE_MAP(RenderView, message) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 750 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail) |
| 751 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 752 | IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 753 | IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 754 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 755 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 756 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 757 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 758 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 759 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 760 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 761 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 762 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 763 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 764 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
| 765 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 766 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 767 | IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, |
| 768 | OnAdvanceToNextMisspelling) |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 769 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 770 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 771 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
| 772 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 773 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 774 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 775 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| 776 | IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 777 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 778 | IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, |
| 779 | OnSetContentSettingsForLoadingURL) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 780 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 781 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 782 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 783 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 784 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 785 | OnResetPageEncodingToDefault) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 786 | IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 787 | IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 788 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 789 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 790 | IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 791 | IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 792 | IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm) |
| 793 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) |
| 794 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) |
| 795 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) |
| 796 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 797 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 798 | IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 799 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved, |
| 800 | OnDragSourceEndedOrMoved) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 801 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, |
| 802 | OnDragSourceSystemDragEnded) |
| 803 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 804 | IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView, |
| 805 | OnScrollFocusedEditableNodeIntoView) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 806 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 807 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 808 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
| 809 | IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 810 | IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 811 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
| 812 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 813 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 814 | OnGetAllSavableResourceLinksForCurrentPage) |
[email protected] | f09c718 | 2009-03-10 12:54:04 | [diff] [blame] | 815 | IPC_MESSAGE_HANDLER( |
| 816 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 817 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 818 | IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 819 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 820 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 821 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 822 | IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 823 | OnHandleMessageFromExternalHost) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 824 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 825 | OnDisassociateFromPopupCount) |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 826 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned, |
| 827 | OnAutoFillSuggestionsReturned) |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 828 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled, |
| 829 | OnAutoFillFormDataFilled) |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 830 | IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose, |
| 831 | OnAllowScriptToClose) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 832 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 833 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 834 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
| 835 | OnExtensionMessageInvoke) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 836 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 837 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 838 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 839 | OnEnablePreferredSizeChangedMode) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 840 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 841 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 842 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 843 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId, |
| 844 | OnUpdateBrowserWindowId) |
| 845 | IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType, |
| 846 | OnNotifyRendererViewType) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 847 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 848 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 849 | #if defined(OS_MACOSX) |
| 850 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 851 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 852 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionConfirmed, |
| 853 | OnPluginImeCompositionConfirmed) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 854 | #endif |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 855 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 856 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 857 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode, |
| 858 | OnExecuteCode) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 859 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 860 | OnCustomContextMenuAction) |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 861 | IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage) |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 862 | IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation) |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 863 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility) |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 864 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus) |
| 865 | IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction, |
| 866 | OnAccessibilityDoDefaultAction) |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 867 | IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK, |
| 868 | OnAccessibilityNotificationsAck) |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 869 | IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 870 | #if defined(OS_MACOSX) |
| 871 | IPC_MESSAGE_HANDLER(ViewMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
| 872 | #endif |
[email protected] | 212a49d | 2010-10-25 18:23:47 | [diff] [blame] | 873 | IPC_MESSAGE_HANDLER(ViewMsg_PrintPreview, OnPrintPreview) |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 874 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 875 | // Have the super handle all other messages. |
| 876 | IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) |
| 877 | IPC_END_MESSAGE_MAP() |
| 878 | } |
| 879 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 880 | void RenderView::OnCaptureThumbnail() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 881 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 882 | if (!main_frame) |
| 883 | return; |
| 884 | |
| 885 | // get the URL for this page |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 886 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 887 | if (url.is_empty()) |
| 888 | return; |
| 889 | |
| 890 | if (size_.IsEmpty()) |
| 891 | return; // Don't create an empty thumbnail! |
| 892 | |
| 893 | ThumbnailScore score; |
| 894 | SkBitmap thumbnail; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 895 | if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight, |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 896 | &thumbnail, &score)) |
| 897 | return; |
| 898 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 899 | // send the thumbnail message to the browser process |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 900 | Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 901 | } |
| 902 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 903 | void RenderView::OnCaptureSnapshot() { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 904 | SkBitmap snapshot; |
| 905 | bool error = false; |
| 906 | |
| 907 | WebFrame* main_frame = webview()->mainFrame(); |
| 908 | if (!main_frame) |
| 909 | error = true; |
| 910 | |
| 911 | if (!error && !CaptureSnapshot(webview(), &snapshot)) |
| 912 | error = true; |
| 913 | |
| 914 | DCHECK(error == snapshot.empty()) << |
| 915 | "Snapshot should be empty on error, non-empty otherwise."; |
| 916 | |
| 917 | // Send the snapshot to the browser process. |
| 918 | Send(new ViewHostMsg_Snapshot(routing_id_, snapshot)); |
| 919 | } |
| 920 | |
[email protected] | 06863722 | 2009-01-29 16:58:07 | [diff] [blame] | 921 | void RenderView::OnPrintPages() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 922 | DCHECK(webview()); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 923 | if (webview()) { |
| 924 | // If the user has selected text in the currently focused frame we print |
| 925 | // only that frame (this makes print selection work for multiple frames). |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 926 | if (webview()->focusedFrame()->hasSelection()) |
[email protected] | 212a49d | 2010-10-25 18:23:47 | [diff] [blame] | 927 | Print(webview()->focusedFrame(), false, false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 928 | else |
[email protected] | 212a49d | 2010-10-25 18:23:47 | [diff] [blame] | 929 | Print(webview()->mainFrame(), false, false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 930 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 931 | } |
| 932 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 933 | void RenderView::OnPrintingDone(int document_cookie, bool success) { |
| 934 | // Ignoring document cookie here since only one print job can be outstanding |
| 935 | // per renderer and document_cookie is 0 when printing is successful. |
| 936 | DCHECK(print_helper_.get()); |
| 937 | if (print_helper_.get() != NULL) { |
| 938 | print_helper_->DidFinishPrinting(success); |
| 939 | } |
| 940 | } |
| 941 | |
[email protected] | 212a49d | 2010-10-25 18:23:47 | [diff] [blame] | 942 | void RenderView::OnPrintPreview() { |
| 943 | DCHECK(webview()); |
| 944 | if (webview()) { |
| 945 | // If the user has selected text in the currently focused frame we print |
| 946 | // only that frame (this makes print selection work for multiple frames). |
| 947 | if (webview()->focusedFrame()->hasSelection()) |
| 948 | Print(webview()->focusedFrame(), false, true); |
| 949 | else |
| 950 | Print(webview()->focusedFrame(), false, true); |
| 951 | } |
| 952 | } |
| 953 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 954 | void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { |
| 955 | if (load_id != page_id_) |
| 956 | return; // this capture call is no longer relevant due to navigation |
| 957 | if (load_id == last_indexed_page_id_) |
| 958 | return; // we already indexed this page |
| 959 | |
| 960 | if (!webview()) |
| 961 | return; |
| 962 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 963 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 964 | if (!main_frame) |
| 965 | return; |
| 966 | |
| 967 | // Don't index/capture pages that are in view source mode. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 968 | if (main_frame->isViewSourceModeEnabled()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 969 | return; |
| 970 | |
| 971 | // Don't index/capture pages that failed to load. This only checks the top |
| 972 | // level frame so the thumbnail may contain a frame that failed to load. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 973 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 974 | if (ds && ds->hasUnreachableURL()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 975 | return; |
| 976 | |
| 977 | if (!preliminary_capture) |
| 978 | last_indexed_page_id_ = load_id; |
| 979 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 980 | // Get the URL for this page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 981 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 982 | if (url.is_empty()) |
| 983 | return; |
| 984 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 985 | // Retrieve the frame's full text. |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 986 | string16 contents; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 987 | CaptureText(main_frame, &contents); |
| 988 | if (contents.size()) { |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 989 | WebKit::WebDocument document = main_frame->document(); |
[email protected] | 5ddfd63e | 2010-09-01 15:48:37 | [diff] [blame] | 990 | // If the page explicitly specifies a language, use it, otherwise we'll |
| 991 | // determine it based on the text content using the CLD. |
| 992 | std::string language = |
| 993 | TranslateHelper::GetPageLanguageFromMetaTag(&document); |
| 994 | if (language.empty()) { |
| 995 | base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 996 | language = DetermineTextLanguage(contents); |
| 997 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection", |
| 998 | base::TimeTicks::Now() - begin_time); |
| 999 | } |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 1000 | // Send the text to the browser for indexing (the browser might decide not |
| 1001 | // to index, if the URL is HTTPS for instance) and language discovery. |
[email protected] | 5ddfd63e | 2010-09-01 15:48:37 | [diff] [blame] | 1002 | Send(new ViewHostMsg_PageContents( |
| 1003 | routing_id_, url, load_id, contents, language, |
| 1004 | TranslateHelper::IsPageTranslatable(&document))); |
[email protected] | 5c426692 | 2009-07-10 16:41:27 | [diff] [blame] | 1005 | } |
| 1006 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 1007 | OnCaptureThumbnail(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1008 | } |
| 1009 | |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 1010 | void RenderView::CaptureText(WebFrame* frame, string16* contents) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1011 | contents->clear(); |
| 1012 | if (!frame) |
| 1013 | return; |
| 1014 | |
| 1015 | #ifdef TIME_TEXT_RETRIEVAL |
| 1016 | double begin = time_util::GetHighResolutionTimeNow(); |
| 1017 | #endif |
| 1018 | |
| 1019 | // get the contents of the frame |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 1020 | *contents = frame->contentAsText(kMaxIndexChars); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1021 | |
| 1022 | #ifdef TIME_TEXT_RETRIEVAL |
| 1023 | double end = time_util::GetHighResolutionTimeNow(); |
| 1024 | char buf[128]; |
| 1025 | sprintf_s(buf, "%d chars retrieved for indexing in %gms\n", |
| 1026 | contents.size(), (end - begin)*1000); |
| 1027 | OutputDebugStringA(buf); |
| 1028 | #endif |
| 1029 | |
| 1030 | // When the contents are clipped to the maximum, we don't want to have a |
| 1031 | // partial word indexed at the end that might have been clipped. Therefore, |
| 1032 | // terminate the string at the last space to ensure no words are clipped. |
| 1033 | if (contents->size() == kMaxIndexChars) { |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 1034 | size_t last_space_index = contents->find_last_of(kWhitespaceUTF16); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1035 | if (last_space_index == std::wstring::npos) |
| 1036 | return; // don't index if we got a huge block of text with no spaces |
| 1037 | contents->resize(last_space_index); |
| 1038 | } |
| 1039 | } |
| 1040 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1041 | bool RenderView::CaptureThumbnail(WebView* view, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1042 | int w, |
| 1043 | int h, |
| 1044 | SkBitmap* thumbnail, |
| 1045 | ThumbnailScore* score) { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1046 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 1047 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1048 | skia::PlatformCanvas canvas; |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1049 | |
| 1050 | // Paint |view| into |canvas|. |
| 1051 | if (!PaintViewIntoCanvas(view, canvas)) |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1052 | return false; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1053 | |
| 1054 | skia::BitmapPlatformDevice& device = |
| 1055 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 1056 | |
| 1057 | const SkBitmap& src_bmp = device.accessBitmap(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1058 | |
[email protected] | cab34d6a | 2009-09-24 01:14:52 | [diff] [blame] | 1059 | SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1060 | float dest_aspect = dest_rect.width() / dest_rect.height(); |
| 1061 | |
| 1062 | // Get the src rect so that we can preserve the aspect ratio while filling |
| 1063 | // the destination. |
| 1064 | SkIRect src_rect; |
| 1065 | if (src_bmp.width() < dest_rect.width() || |
| 1066 | src_bmp.height() < dest_rect.height()) { |
| 1067 | // Source image is smaller: we clip the part of source image within the |
| 1068 | // dest rect, and then stretch it to fill the dest rect. We don't respect |
| 1069 | // the aspect ratio in this case. |
| 1070 | src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()), |
| 1071 | static_cast<S16CPU>(dest_rect.height())); |
| 1072 | score->good_clipping = false; |
| 1073 | } else { |
| 1074 | float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height(); |
| 1075 | if (src_aspect > dest_aspect) { |
| 1076 | // Wider than tall, clip horizontally: we center the smaller thumbnail in |
| 1077 | // the wider screen. |
| 1078 | S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect); |
| 1079 | S16CPU x_offset = (src_bmp.width() - new_width) / 2; |
| 1080 | src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height()); |
| 1081 | score->good_clipping = false; |
| 1082 | } else { |
| 1083 | src_rect.set(0, 0, src_bmp.width(), |
| 1084 | static_cast<S16CPU>(src_bmp.width() / dest_aspect)); |
| 1085 | score->good_clipping = true; |
| 1086 | } |
| 1087 | } |
| 1088 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1089 | score->at_top = (view->mainFrame()->scrollOffset().height == 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1090 | |
| 1091 | SkBitmap subset; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1092 | device.accessBitmap(false).extractSubset(&subset, src_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1093 | |
| 1094 | // Resample the subset that we want to get it the right size. |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 1095 | *thumbnail = skia::ImageOperations::Resize( |
| 1096 | subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1097 | |
| 1098 | score->boring_score = CalculateBoringScore(thumbnail); |
| 1099 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1100 | HISTOGRAM_TIMES("Renderer4.Thumbnail", |
| 1101 | base::TimeTicks::Now() - beginning_time); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 1102 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1103 | } |
| 1104 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1105 | bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) { |
| 1106 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1107 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1108 | skia::PlatformCanvas canvas; |
| 1109 | if (!PaintViewIntoCanvas(view, canvas)) |
| 1110 | return false; |
| 1111 | |
| 1112 | skia::BitmapPlatformDevice& device = |
| 1113 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 1114 | |
| 1115 | const SkBitmap& bitmap = device.accessBitmap(false); |
| 1116 | if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
| 1117 | return false; |
| 1118 | |
| 1119 | HISTOGRAM_TIMES("Renderer4.Snapshot", |
| 1120 | base::TimeTicks::Now() - beginning_time); |
| 1121 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { |
| 1125 | if (!webview()) |
| 1126 | return; |
| 1127 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1128 | history_list_offset_ = params.current_history_list_offset; |
| 1129 | history_list_length_ = params.current_history_list_length; |
| 1130 | |
[email protected] | 8c785c6 | 2009-07-13 14:20:15 | [diff] [blame] | 1131 | if (devtools_agent_.get()) |
| 1132 | devtools_agent_->OnNavigate(); |
| 1133 | |
[email protected] | 42219753 | 2010-01-25 17:38:23 | [diff] [blame] | 1134 | if (notification_provider_.get()) |
| 1135 | notification_provider_->OnNavigate(); |
| 1136 | |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 1137 | child_process_logging::SetActiveURL(params.url); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1138 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1139 | AboutHandler::MaybeHandle(params.url); |
| 1140 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1141 | bool is_reload = |
| 1142 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD || |
| 1143 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1144 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1145 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1146 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1147 | // We cannot reload if we do not have any history state. This happens, for |
| 1148 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1149 | // a hack since it means that reload after a crashed tab does not cause an |
| 1150 | // end-to-end cache validation. |
| 1151 | is_reload = false; |
| 1152 | } |
| 1153 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1154 | // A navigation resulting from loading a javascript URL should not be treated |
| 1155 | // as a browser initiated event. Instead, we want it to look as if the page |
| 1156 | // initiated any load resulting from JS execution. |
| 1157 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1158 | NavigationState* state = NavigationState::CreateBrowserInitiated( |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1159 | params.page_id, |
| 1160 | params.pending_history_list_offset, |
| 1161 | params.transition, |
| 1162 | params.request_time); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1163 | if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) { |
| 1164 | // We're doing a load of a page that was restored from the last session. |
| 1165 | // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE) |
| 1166 | // which can result in stale data for pages that are set to expire. We |
| 1167 | // explicitly override that by setting the policy here so that as |
| 1168 | // necessary we load from the network. |
| 1169 | state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy); |
| 1170 | } |
| 1171 | pending_navigation_state_.reset(state); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1172 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1173 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1174 | NavigationState* navigation_state = pending_navigation_state_.get(); |
| 1175 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1176 | // If we are reloading, then WebKit will use the history state of the current |
| 1177 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1178 | // have history state, then we need to navigate to it, which corresponds to a |
| 1179 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1180 | if (is_reload) { |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1181 | if (navigation_state) |
| 1182 | navigation_state->set_load_type(NavigationState::RELOAD); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1183 | bool ignore_cache = (params.navigation_type == |
| 1184 | ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE); |
| 1185 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1186 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1187 | // 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] | 1188 | DCHECK_NE(params.page_id, -1); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1189 | if (navigation_state) |
| 1190 | navigation_state->set_load_type(NavigationState::HISTORY_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1191 | main_frame->loadHistoryItem( |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1192 | webkit_glue::HistoryItemFromString(params.state)); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1193 | } else { |
| 1194 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1195 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1196 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1197 | // A session history navigation should have been accompanied by state. |
| 1198 | DCHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1199 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1200 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1201 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1202 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1203 | if (params.referrer.is_valid()) { |
| 1204 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), |
| 1205 | WebString::fromUTF8(params.referrer.spec())); |
| 1206 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1207 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1208 | if (navigation_state) |
| 1209 | navigation_state->set_load_type(NavigationState::NORMAL_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1210 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1211 | } |
| 1212 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1213 | // In case LoadRequest failed before DidCreateDataSource was called. |
| 1214 | pending_navigation_state_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | // Stop loading the current page |
| 1218 | void RenderView::OnStop() { |
| 1219 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 1220 | webview()->mainFrame()->stopLoading(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1221 | } |
| 1222 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1223 | // Reload current focused frame. |
| 1224 | // 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] | 1225 | void RenderView::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1226 | if (webview() && webview()->focusedFrame()) { |
| 1227 | // We always obey the cache (ignore_cache=false) here. |
| 1228 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1229 | // a cache-ignoring reload of the frame. |
| 1230 | webview()->focusedFrame()->reload(false); |
| 1231 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1232 | } |
| 1233 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1234 | void RenderView::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1235 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1236 | } |
| 1237 | |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1238 | void RenderView::OnExecuteEditCommand(const std::string& name, |
| 1239 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1240 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1241 | return; |
| 1242 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1243 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1244 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1245 | } |
| 1246 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1247 | void RenderView::OnSetupDevToolsClient() { |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 1248 | DCHECK(!devtools_client_.get()); |
| 1249 | devtools_client_.reset(new DevToolsClient(this)); |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1250 | } |
| 1251 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1252 | void RenderView::OnUpdateTargetURLAck() { |
| 1253 | // Check if there is a targeturl waiting to be sent. |
| 1254 | if (target_url_status_ == TARGET_PENDING) { |
| 1255 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1256 | pending_target_url_)); |
| 1257 | } |
| 1258 | |
| 1259 | target_url_status_ = TARGET_NONE; |
| 1260 | } |
| 1261 | |
| 1262 | void RenderView::OnUndo() { |
| 1263 | if (!webview()) |
| 1264 | return; |
| 1265 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1266 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1267 | UserMetricsRecordAction("Undo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | void RenderView::OnRedo() { |
| 1271 | if (!webview()) |
| 1272 | return; |
| 1273 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1274 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1275 | UserMetricsRecordAction("Redo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | void RenderView::OnCut() { |
| 1279 | if (!webview()) |
| 1280 | return; |
| 1281 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1282 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1283 | UserMetricsRecordAction("Cut"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | void RenderView::OnCopy() { |
| 1287 | if (!webview()) |
| 1288 | return; |
| 1289 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1290 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1291 | UserMetricsRecordAction("Copy"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1292 | } |
| 1293 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1294 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1295 | void RenderView::OnCopyToFindPboard() { |
| 1296 | if (!webview()) |
| 1297 | return; |
| 1298 | |
| 1299 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1300 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1301 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1302 | if (frame->hasSelection()) { |
| 1303 | string16 selection = frame->selectionAsText(); |
| 1304 | RenderThread::current()->Send( |
| 1305 | new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection)); |
| 1306 | } |
| 1307 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1308 | UserMetricsRecordAction("CopyToFindPboard"); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1309 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1310 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1311 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1312 | void RenderView::OnPaste() { |
| 1313 | if (!webview()) |
| 1314 | return; |
| 1315 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1316 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1317 | UserMetricsRecordAction("Paste"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1318 | } |
| 1319 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1320 | void RenderView::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1321 | if (!webview()) |
| 1322 | return; |
| 1323 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1324 | WebFrame* frame = webview()->focusedFrame(); |
| 1325 | if (!frame->hasSelection()) |
| 1326 | frame->selectWordAroundCaret(); |
| 1327 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1328 | } |
| 1329 | |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1330 | void RenderView::OnAdvanceToNextMisspelling() { |
| 1331 | if (!webview()) |
| 1332 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1333 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1334 | WebString::fromUTF8("AdvanceToNextMisspelling")); |
| 1335 | } |
| 1336 | |
| 1337 | void RenderView::OnToggleSpellPanel(bool is_currently_visible) { |
| 1338 | if (!webview()) |
| 1339 | return; |
| 1340 | // We need to tell the webView whether the spelling panel is visible or not so |
| 1341 | // that it won't need to make ipc calls later. |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1342 | spelling_panel_visible_ = is_currently_visible; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1343 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1344 | WebString::fromUTF8("ToggleSpellPanel")); |
| 1345 | } |
| 1346 | |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1347 | void RenderView::OnToggleSpellCheck() { |
| 1348 | if (!webview()) |
| 1349 | return; |
| 1350 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1351 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1352 | frame->enableContinuousSpellChecking( |
| 1353 | !frame->isContinuousSpellCheckingEnabled()); |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1354 | } |
| 1355 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1356 | void RenderView::OnDelete() { |
| 1357 | if (!webview()) |
| 1358 | return; |
| 1359 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1360 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1361 | UserMetricsRecordAction("DeleteSelection"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | void RenderView::OnSelectAll() { |
| 1365 | if (!webview()) |
| 1366 | return; |
| 1367 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1368 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 1369 | WebString::fromUTF8("SelectAll")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1370 | UserMetricsRecordAction("SelectAll"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | void RenderView::OnSetInitialFocus(bool reverse) { |
| 1374 | if (!webview()) |
| 1375 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1376 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1377 | } |
| 1378 | |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 1379 | void RenderView::OnScrollFocusedEditableNodeIntoView() { |
| 1380 | if (!webview()) |
| 1381 | return; |
| 1382 | WebFrame* focused_frame = webview()->focusedFrame(); |
| 1383 | if (focused_frame) { |
| 1384 | WebDocument doc = focused_frame->document(); |
| 1385 | if (!doc.isNull()) { |
| 1386 | WebNode node = doc.focusedNode(); |
| 1387 | if (IsEditableNode(node)) |
| 1388 | // TODO(varunjain): Change webkit API to scroll a particular node into |
| 1389 | // view and use that API here instead. |
| 1390 | webview()->scrollFocusedNodeIntoView(); |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1395 | /////////////////////////////////////////////////////////////////////////////// |
| 1396 | |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1397 | void RenderView::SetContentSettings(const ContentSettings& settings) { |
| 1398 | current_content_settings_ = settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1399 | } |
| 1400 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1401 | // Tell the embedding application that the URL of the active page has changed |
| 1402 | void RenderView::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1403 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1404 | DCHECK(ds); |
| 1405 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1406 | const WebURLRequest& request = ds->request(); |
| 1407 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1408 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1409 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1410 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 1411 | DCHECK(navigation_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1412 | |
| 1413 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1414 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1415 | params.is_post = false; |
| 1416 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1417 | params.frame_id = frame->identifier(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1418 | params.is_content_filtered = response.isContentFiltered(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1419 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1420 | if (!navigation_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1421 | // SSL state specified in the request takes precedence over the one in the |
| 1422 | // response. |
| 1423 | // So far this is only intended for error pages that are not expected to be |
| 1424 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1425 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1426 | params.security_info = navigation_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1427 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1428 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1432 | if (ds->hasUnreachableURL()) { |
| 1433 | params.url = ds->unreachableURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1434 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1435 | params.url = request.url(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1436 | } |
| 1437 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1438 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1439 | params.should_update_history = !ds->hasUnreachableURL() && |
| 1440 | !response.isMultipartPayload(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1441 | |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1442 | params.searchable_form_url = navigation_state->searchable_form_url(); |
| 1443 | params.searchable_form_encoding = |
| 1444 | navigation_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1445 | |
| 1446 | const PasswordForm* password_form_data = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1447 | navigation_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1448 | if (password_form_data) |
| 1449 | params.password_form = *password_form_data; |
| 1450 | |
| 1451 | params.gesture = navigation_gesture_; |
| 1452 | navigation_gesture_ = NavigationGestureUnknown; |
| 1453 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1454 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1455 | // Top-level navigation. |
| 1456 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 1457 | // Clear "block" flags for the new page. This needs to happen before any of |
| 1458 | // allowScripts(), allowImages(), allowPlugins() is called for the new page |
| 1459 | // so that these functions can correctly detect that a piece of content |
| 1460 | // flipped from "not blocked" to "blocked". |
| 1461 | ClearBlockedContentSettings(); |
| 1462 | |
[email protected] | 62d2a11 | 2010-04-07 00:53:02 | [diff] [blame] | 1463 | // Set content settings. Default them from the parent window if one exists. |
| 1464 | // This makes sure about:blank windows work as expected. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1465 | HostContentSettings::iterator host_content_settings = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1466 | host_content_settings_.find(GURL(request.url())); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1467 | if (host_content_settings != host_content_settings_.end()) { |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1468 | SetContentSettings(host_content_settings->second); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1469 | |
| 1470 | // These content settings were merely recorded transiently for this load. |
| 1471 | // We can erase them now. If at some point we reload this page, the |
| 1472 | // browser will send us new, up-to-date content settings. |
| 1473 | host_content_settings_.erase(host_content_settings); |
[email protected] | 3a387ae | 2010-04-08 01:58:40 | [diff] [blame] | 1474 | } else if (frame->opener()) { |
[email protected] | 8128cdd0 | 2010-07-21 20:40:10 | [diff] [blame] | 1475 | // The opener's view is not guaranteed to be non-null (it could be |
| 1476 | // detached from its page but not yet destructed). |
| 1477 | if (WebView* opener_view = frame->opener()->view()) { |
| 1478 | RenderView* opener = FromWebView(opener_view); |
| 1479 | SetContentSettings(opener->current_content_settings_); |
| 1480 | } |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1481 | } |
| 1482 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1483 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1484 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1485 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1486 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1487 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1488 | // Reset the zoom levels for plugins. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1489 | webview()->setZoomLevel(false, 0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1490 | } else { |
| 1491 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1492 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1493 | } |
| 1494 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1495 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1496 | // This zoom level was merely recorded transiently for this load. We can |
| 1497 | // erase it now. If at some point we reload this page, the browser will |
| 1498 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1499 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1500 | } |
| 1501 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1502 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1503 | // will also call us back which will cause us to send a message to |
| 1504 | // update TabContents. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1505 | webview()->zoomLimitsChanged( |
| 1506 | WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier), |
| 1507 | WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1508 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1509 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1510 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1511 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1512 | params.transition = navigation_state->transition_type(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1513 | if (!PageTransition::IsMainFrame(params.transition)) { |
| 1514 | // If the main frame does a load, it should not be reported as a subframe |
| 1515 | // navigation. This can occur in the following case: |
| 1516 | // 1. You're on a site with frames. |
| 1517 | // 2. You do a subframe navigation. This is stored with transition type |
| 1518 | // MANUAL_SUBFRAME. |
| 1519 | // 3. You navigate to some non-frame site, say, google.com. |
| 1520 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1521 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1522 | // We don't want that, because any navigation that changes the toplevel |
| 1523 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1524 | // update the URL bar, etc). |
| 1525 | params.transition = PageTransition::LINK; |
| 1526 | } |
| 1527 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1528 | // If we have a valid consumed client redirect source, |
| 1529 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1530 | // so we set the referrer and transition to match. |
| 1531 | if (completed_client_redirect_src_.is_valid()) { |
[email protected] | 77e09a9 | 2008-08-01 18:11:04 | [diff] [blame] | 1532 | DCHECK(completed_client_redirect_src_ == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1533 | params.referrer = completed_client_redirect_src_; |
| 1534 | params.transition = static_cast<PageTransition::Type>( |
| 1535 | params.transition | PageTransition::CLIENT_REDIRECT); |
| 1536 | } else { |
| 1537 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1538 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1539 | params.referrer = GURL( |
| 1540 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1541 | } |
| 1542 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1543 | string16 method = request.httpMethod(); |
| 1544 | if (EqualsASCII(method, "POST")) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1545 | params.is_post = true; |
| 1546 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1547 | // Save some histogram data so we can compute the average memory used per |
| 1548 | // page load of the glyphs. |
| 1549 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1550 | webkit_glue::GetGlyphPageCount()); |
| 1551 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1552 | // This message needs to be sent before any of allowScripts(), |
| 1553 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1554 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1555 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1556 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1557 | } else { |
| 1558 | // Subframe navigation: the type depends on whether this navigation |
| 1559 | // generated a new session history entry. When they do generate a session |
| 1560 | // history entry, it means the user initiated the navigation and we should |
| 1561 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1562 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1563 | if (page_id_ > last_page_id_sent_to_browser_) |
| 1564 | params.transition = PageTransition::MANUAL_SUBFRAME; |
| 1565 | else |
| 1566 | params.transition = PageTransition::AUTO_SUBFRAME; |
| 1567 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1568 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1569 | } |
| 1570 | |
| 1571 | last_page_id_sent_to_browser_ = |
| 1572 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1573 | |
| 1574 | // 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] | 1575 | // we don't want the transition type to persist. Just clear it. |
| 1576 | navigation_state->set_transition_type(PageTransition::LINK); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1577 | |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1578 | // Check if the navigation was within the same page, in which case we don't |
| 1579 | // want to clear the accessibility cache. |
| 1580 | if (accessibility_.get() && !navigation_state->was_within_same_page()) { |
[email protected] | 1745596 | 2010-02-24 01:39:35 | [diff] [blame] | 1581 | accessibility_.reset(); |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 1582 | pending_accessibility_notifications_.clear(); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1583 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1587 | void RenderView::UpdateTitle(WebFrame* frame, const string16& title) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1588 | // Ignore all but top level navigations... |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1589 | if (!frame->parent()) { |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1590 | Send(new ViewHostMsg_UpdateTitle( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1591 | routing_id_, |
| 1592 | page_id_, |
| 1593 | UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ? |
| 1594 | title.substr(0, chrome::kMaxTitleChars) : title))); |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1595 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | void RenderView::UpdateEncoding(WebFrame* frame, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1599 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1600 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1601 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1602 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1603 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1604 | last_encoding_name_ = encoding_name; |
| 1605 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1606 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1607 | } |
| 1608 | } |
| 1609 | |
[email protected] | f4d34b5 | 2008-11-24 23:05:01 | [diff] [blame] | 1610 | // Sends the previous session history state to the browser so it will be saved |
| 1611 | // before we navigate to a new page. This must be called *before* the page ID |
| 1612 | // has been updated so we know what it was. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1613 | void RenderView::UpdateSessionHistory(WebFrame* frame) { |
| 1614 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1615 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1616 | // there is no past session history to record. |
| 1617 | if (page_id_ == -1) |
| 1618 | return; |
| 1619 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1620 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1621 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1622 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1623 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1624 | |
| 1625 | Send(new ViewHostMsg_UpdateState( |
| 1626 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1627 | } |
| 1628 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1629 | void RenderView::OpenURL( |
| 1630 | const GURL& url, const GURL& referrer, WebNavigationPolicy policy) { |
| 1631 | Send(new ViewHostMsg_OpenURL( |
| 1632 | routing_id_, url, referrer, NavigationPolicyToDisposition(policy))); |
| 1633 | } |
| 1634 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1635 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1636 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1637 | void RenderView::LoadNavigationErrorPage(WebFrame* frame, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1638 | const WebURLRequest& failed_request, |
| 1639 | const WebURLError& error, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1640 | const std::string& html, |
| 1641 | bool replace) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1642 | GURL failed_url = error.unreachableURL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1643 | std::string alt_html; |
[email protected] | 07b49351 | 2010-08-27 15:39:29 | [diff] [blame] | 1644 | ExtensionRendererInfo* extension = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1645 | if (html.empty()) { |
| 1646 | // Use a local error page. |
| 1647 | int resource_id; |
| 1648 | DictionaryValue error_strings; |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1649 | |
[email protected] | 8165428 | 2010-10-04 17:08:06 | [diff] [blame] | 1650 | if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1651 | extension = ExtensionRendererInfo::GetByURL(failed_url); |
| 1652 | if (extension) { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1653 | LocalizedError::GetAppErrorStrings(error, failed_url, extension, |
| 1654 | &error_strings); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1655 | |
| 1656 | // TODO(erikkay): Should we use a different template for different |
| 1657 | // error messages? |
| 1658 | resource_id = IDR_ERROR_APP_HTML; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1659 | } else { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1660 | if (error.domain == WebString::fromUTF8(net::kErrorDomain) && |
| 1661 | error.reason == net::ERR_CACHE_MISS && |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1662 | EqualsASCII(failed_request.httpMethod(), "POST")) { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1663 | LocalizedError::GetFormRepostStrings(failed_url, &error_strings); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1664 | resource_id = IDR_ERROR_NO_DETAILS_HTML; |
| 1665 | } else { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1666 | LocalizedError::GetStrings(error, &error_strings); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1667 | resource_id = IDR_NET_ERROR_HTML; |
| 1668 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1669 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1670 | |
| 1671 | alt_html = GetAltHTMLForTemplate(error_strings, resource_id); |
| 1672 | } else { |
| 1673 | alt_html = html; |
| 1674 | } |
| 1675 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1676 | frame->loadHTMLString(alt_html, |
[email protected] | 144143c | 2010-10-28 08:17:36 | [diff] [blame] | 1677 | GURL(chrome::kUnreachableWebDataURL), |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1678 | failed_url, |
| 1679 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1680 | } |
| 1681 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 1682 | void RenderView::BindDOMAutomationController(WebFrame* frame) { |
[email protected] | 2f97917 | 2010-09-16 21:54:03 | [diff] [blame] | 1683 | if (!dom_automation_controller_.get()) { |
| 1684 | dom_automation_controller_.reset(new DomAutomationController()); |
| 1685 | } |
| 1686 | dom_automation_controller_->set_message_sender(this); |
| 1687 | dom_automation_controller_->set_routing_id(routing_id_); |
| 1688 | dom_automation_controller_->BindToJavascript(frame, |
| 1689 | L"domAutomationController"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1690 | } |
| 1691 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1692 | bool RenderView::RunJavaScriptMessage(int type, |
| 1693 | const std::wstring& message, |
| 1694 | const std::wstring& default_value, |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1695 | const GURL& frame_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1696 | std::wstring* result) { |
| 1697 | bool success = false; |
| 1698 | std::wstring result_temp; |
| 1699 | if (!result) |
| 1700 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1701 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1702 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1703 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1704 | return success; |
| 1705 | } |
| 1706 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1707 | bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
| 1708 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1709 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1710 | // it is particularly important that we do not call willEnterModalLoop as |
| 1711 | // that would defer resource loads for the dialog itself. |
| 1712 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 1713 | RenderThread::current()->DoNotNotifyWebKitOfModalLoop(); |
| 1714 | |
| 1715 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1716 | return Send(message); |
| 1717 | } |
| 1718 | |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1719 | void RenderView::AddGURLSearchProvider( |
| 1720 | const GURL& osd_url, |
| 1721 | const ViewHostMsg_PageHasOSDD_Type& provider_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1722 | if (!osd_url.is_empty()) |
| 1723 | Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1724 | provider_type)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1725 | } |
| 1726 | |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1727 | void RenderView::OnAutoFillSuggestionsReturned( |
| 1728 | int query_id, |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 1729 | const std::vector<string16>& values, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 1730 | const std::vector<string16>& labels, |
[email protected] | a53e0683 | 2010-07-28 22:46:41 | [diff] [blame] | 1731 | const std::vector<string16>& icons, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 1732 | const std::vector<int>& unique_ids) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1733 | autofill_helper_->SuggestionsReceived( |
[email protected] | a53e0683 | 2010-07-28 22:46:41 | [diff] [blame] | 1734 | query_id, values, labels, icons, unique_ids); |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1735 | } |
| 1736 | |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 1737 | void RenderView::OnAutoFillFormDataFilled(int query_id, |
| 1738 | const webkit_glue::FormData& form) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1739 | autofill_helper_->FormDataFilled(query_id, form); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 1740 | } |
| 1741 | |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1742 | void RenderView::OnAllowScriptToClose(bool script_can_close) { |
| 1743 | script_can_close_ = script_can_close; |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1744 | } |
| 1745 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1746 | uint32 RenderView::GetCPBrowsingContext() { |
| 1747 | uint32 context = 0; |
| 1748 | Send(new ViewHostMsg_GetCPBrowsingContext(&context)); |
| 1749 | return context; |
| 1750 | } |
| 1751 | |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1752 | void RenderView::AddSearchProvider( |
| 1753 | const std::string& url, |
| 1754 | const ViewHostMsg_PageHasOSDD_Type& provider_type) { |
| 1755 | if (provider_type.type == |
| 1756 | ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER && |
| 1757 | !webview()->mainFrame()->isProcessingUserGesture()) |
| 1758 | return; |
| 1759 | |
| 1760 | AddGURLSearchProvider(GURL(url), provider_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1761 | } |
| 1762 | |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1763 | ViewHostMsg_GetSearchProviderInstallState_Params |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1764 | RenderView::GetSearchProviderInstallState(WebFrame* frame, |
| 1765 | const std::string& url) { |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1766 | GURL inquiry_url = GURL(url); |
| 1767 | if (inquiry_url.is_empty()) |
| 1768 | return ViewHostMsg_GetSearchProviderInstallState_Params::Denied(); |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1769 | |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1770 | ViewHostMsg_GetSearchProviderInstallState_Params install; |
| 1771 | Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_, |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1772 | frame->url(), |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1773 | inquiry_url, |
| 1774 | &install)); |
| 1775 | return install; |
| 1776 | } |
| 1777 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1778 | void RenderView::OnMissingPluginStatus( |
| 1779 | WebPluginDelegateProxy* delegate, |
| 1780 | int status) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1781 | #if defined(OS_WIN) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1782 | if (!first_default_plugin_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1783 | // Show the InfoBar for the first available plugin. |
| 1784 | if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1785 | first_default_plugin_ = delegate->AsWeakPtr(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1786 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1787 | } |
| 1788 | } else { |
| 1789 | // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar) |
| 1790 | // to start the download/install. |
| 1791 | if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) { |
| 1792 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1793 | } |
| 1794 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1795 | #else |
[email protected] | 76c3b31 | 2010-05-20 21:38:29 | [diff] [blame] | 1796 | // TODO(port): Implement the infobar that accompanies the default plugin. |
| 1797 | // Linux: http://crbug.com/10952 |
| 1798 | // Mac: http://crbug.com/17392 |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1799 | NOTIMPLEMENTED(); |
| 1800 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1801 | } |
| 1802 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1803 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1804 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1805 | WebView* RenderView::createView( |
| 1806 | WebFrame* creator, |
| 1807 | const WebWindowFeatures& features, |
| 1808 | const WebString& frame_name) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1809 | // Check to make sure we aren't overloading on popups. |
| 1810 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1811 | return NULL; |
| 1812 | |
| 1813 | // This window can't be closed from a window.close() call until we receive a |
| 1814 | // message from the Browser process explicitly allowing it. |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1815 | script_can_close_ = false; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1816 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1817 | ViewHostMsg_CreateWindow_Params params; |
| 1818 | params.opener_id = routing_id_; |
| 1819 | params.user_gesture = creator->isProcessingUserGesture(); |
| 1820 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1821 | params.session_storage_namespace_id = session_storage_namespace_id_; |
| 1822 | params.frame_name = frame_name; |
| 1823 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1824 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1825 | int64 cloned_session_storage_namespace_id; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1826 | bool opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1827 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1828 | render_thread_->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1829 | new ViewHostMsg_CreateWindow(params, |
| 1830 | &routing_id, |
| 1831 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1832 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1833 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1834 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1835 | RenderView* view = RenderView::Create(render_thread_, |
[email protected] | 659f73fa | 2009-10-13 13:43:42 | [diff] [blame] | 1836 | 0, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1837 | routing_id_, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1838 | renderer_preferences_, |
| 1839 | webkit_preferences_, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1840 | shared_popup_counter_, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1841 | routing_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1842 | cloned_session_storage_namespace_id, |
| 1843 | frame_name); |
| 1844 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1845 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1846 | // Record whether the creator frame is trying to suppress the opener field. |
| 1847 | view->opener_suppressed_ = opener_suppressed; |
| 1848 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1849 | // Record the security origin of the creator. |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 1850 | GURL creator_url(creator->securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1851 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1852 | creator_url = GURL(); |
| 1853 | view->creator_url_ = creator_url; |
| 1854 | |
| 1855 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1856 | // the new render view (we don't need the browser to send the URL back down). |
| 1857 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1858 | |
| 1859 | return view->webview(); |
| 1860 | } |
| 1861 | |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1862 | WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1863 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1864 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1865 | popup_type); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1866 | return widget->webwidget(); |
| 1867 | } |
| 1868 | |
| 1869 | WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) { |
| 1870 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1871 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1872 | WebKit::WebPopupTypeSelect); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1873 | widget->ConfigureAsExternalPopupMenu(info); |
| 1874 | return widget->webwidget(); |
| 1875 | } |
| 1876 | |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 1877 | WebExternalPopupMenu* RenderView::createExternalPopupMenu( |
| 1878 | const WebPopupMenuInfo& popup_menu_info, |
| 1879 | WebExternalPopupMenuClient* popup_menu_client) { |
| 1880 | DCHECK(!external_popup_menu_.get()); |
| 1881 | external_popup_menu_.reset( |
| 1882 | new ExternalPopupMenu(this, popup_menu_info, popup_menu_client)); |
| 1883 | return external_popup_menu_.get(); |
| 1884 | } |
| 1885 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 1886 | WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) { |
| 1887 | RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_, |
| 1888 | render_thread_, |
| 1889 | popup_type); |
| 1890 | return widget->webwidget(); |
| 1891 | } |
| 1892 | |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1893 | pepper::FullscreenContainer* RenderView::CreatePepperFullscreenContainer( |
| 1894 | pepper::PluginInstance* plugin) { |
| 1895 | RenderWidgetFullscreenPepper* widget = |
| 1896 | RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin); |
| 1897 | widget->show(WebKit::WebNavigationPolicyIgnore); |
| 1898 | return widget->container(); |
| 1899 | } |
| 1900 | |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1901 | WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) { |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1902 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1903 | return WebStorageNamespace::createSessionStorageNamespace(quota); |
[email protected] | 59afea1 | 2010-01-20 04:48:29 | [diff] [blame] | 1904 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
| 1905 | return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION, |
| 1906 | session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1907 | } |
| 1908 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1909 | void RenderView::didAddMessageToConsole( |
| 1910 | const WebConsoleMessage& message, const WebString& source_name, |
| 1911 | unsigned source_line) { |
| 1912 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
| 1913 | UTF16ToWideHack(message.text), |
| 1914 | static_cast<int32>(source_line), |
| 1915 | UTF16ToWideHack(source_name))); |
| 1916 | } |
| 1917 | |
| 1918 | void RenderView::printPage(WebFrame* frame) { |
[email protected] | 71a1426 | 2009-09-22 20:02:58 | [diff] [blame] | 1919 | DCHECK(frame); |
[email protected] | 212a49d | 2010-10-25 18:23:47 | [diff] [blame] | 1920 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1921 | switches::kEnablePrintPreview)) { |
| 1922 | Print(frame, true, true); |
| 1923 | } else { |
| 1924 | Print(frame, true, false); |
| 1925 | } |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1926 | } |
| 1927 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 1928 | WebKit::WebNotificationPresenter* RenderView::notificationPresenter() { |
| 1929 | return notification_provider_.get(); |
| 1930 | } |
| 1931 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1932 | void RenderView::didStartLoading() { |
| 1933 | if (is_loading_) { |
| 1934 | DLOG(WARNING) << "didStartLoading called while loading"; |
| 1935 | return; |
| 1936 | } |
| 1937 | |
| 1938 | is_loading_ = true; |
| 1939 | // Clear the pointer so that we can assign it only when there is an unknown |
| 1940 | // plugin on a page. |
| 1941 | first_default_plugin_.reset(); |
| 1942 | |
| 1943 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
| 1944 | } |
| 1945 | |
| 1946 | void RenderView::didStopLoading() { |
| 1947 | if (!is_loading_) { |
| 1948 | DLOG(WARNING) << "DidStopLoading called while not loading"; |
| 1949 | return; |
| 1950 | } |
| 1951 | |
| 1952 | is_loading_ = false; |
| 1953 | |
| 1954 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1955 | // when done loading. This currently isn't an issue as the favicon is only |
| 1956 | // displayed when done loading. Ideally we would send notification when |
| 1957 | // finished parsing the head, but webkit doesn't support that yet. |
| 1958 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1959 | GURL favicon_url(webview()->mainFrame()->favIconURL()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1960 | if (!favicon_url.is_empty()) |
| 1961 | Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url)); |
| 1962 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1963 | AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(), |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1964 | ViewHostMsg_PageHasOSDD_Type::Autodetected()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1965 | |
| 1966 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1967 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 1968 | MessageLoop::current()->PostDelayedTask( |
| 1969 | FROM_HERE, |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1970 | page_info_method_factory_.NewRunnableMethod( |
| 1971 | &RenderView::CapturePageInfo, page_id_, false), |
[email protected] | 5ddfd63e | 2010-09-01 15:48:37 | [diff] [blame] | 1972 | send_content_state_immediately_ ? 0 : kDelayForCaptureMs); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1973 | } |
| 1974 | |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 1975 | bool RenderView::isSmartInsertDeleteEnabled() { |
| 1976 | #if defined(OS_MACOSX) |
| 1977 | return true; |
| 1978 | #else |
| 1979 | return false; |
| 1980 | #endif |
| 1981 | } |
| 1982 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1983 | bool RenderView::isSelectTrailingWhitespaceEnabled() { |
| 1984 | #if defined(OS_WIN) |
| 1985 | return true; |
| 1986 | #else |
| 1987 | return false; |
| 1988 | #endif |
| 1989 | } |
| 1990 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1991 | void RenderView::didChangeSelection(bool is_empty_selection) { |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 1992 | #if defined(USE_X11) || defined(OS_MACOSX) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1993 | if (!handling_input_event_) |
| 1994 | return; |
| 1995 | // TODO(estade): investigate incremental updates to the selection so that we |
| 1996 | // don't send the entire selection over IPC every time. |
| 1997 | if (!is_empty_selection) { |
| 1998 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 1999 | // the selection hasn't actually changed. We don't want to report these |
| 2000 | // because it will cause us to continually claim the X clipboard. |
| 2001 | const std::string& this_selection = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2002 | webview()->focusedFrame()->selectionAsText().utf8(); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2003 | if (this_selection == last_selection_) |
| 2004 | return; |
| 2005 | |
| 2006 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 2007 | this_selection)); |
| 2008 | last_selection_ = this_selection; |
| 2009 | } else { |
| 2010 | last_selection_.clear(); |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 2011 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 2012 | last_selection_)); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2013 | } |
| 2014 | #endif |
| 2015 | } |
| 2016 | |
| 2017 | void RenderView::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 2018 | const std::string& name = UTF16ToUTF8(command_name); |
| 2019 | if (StartsWithASCII(name, "Move", true) || |
| 2020 | StartsWithASCII(name, "Insert", true) || |
| 2021 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 2022 | return; |
| 2023 | UserMetricsRecordAction(name); |
| 2024 | } |
| 2025 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2026 | void RenderView::textFieldDidEndEditing( |
| 2027 | const WebKit::WebInputElement& element) { |
| 2028 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2029 | password_autocomplete_manager_->TextFieldDidEndEditing(element); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2030 | #endif |
| 2031 | } |
| 2032 | |
| 2033 | void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) { |
| 2034 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2035 | // We post a task for doing the AutoFill as the caret position is not set |
| 2036 | // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and |
| 2037 | // it is needed to trigger autofill. |
| 2038 | autofill_method_factory_.RevokeAll(); |
| 2039 | MessageLoop::current()->PostTask( |
| 2040 | FROM_HERE, |
| 2041 | autofill_method_factory_.NewRunnableMethod( |
| 2042 | &RenderView::TextFieldDidChangeImpl, element)); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2043 | #endif |
| 2044 | } |
| 2045 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2046 | void RenderView::TextFieldDidChangeImpl( |
| 2047 | const WebKit::WebInputElement& element) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2048 | if (password_autocomplete_manager_->TextDidChangeInTextField(element)) |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2049 | return; |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2050 | autofill_helper_->TextDidChangeInTextField(element); |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2051 | } |
| 2052 | |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 2053 | void RenderView::SendPendingAccessibilityNotifications() { |
| 2054 | if (!accessibility_.get()) |
| 2055 | return; |
| 2056 | |
| 2057 | if (pending_accessibility_notifications_.empty()) |
| 2058 | return; |
| 2059 | |
| 2060 | // Send all pending accessibility notifications. |
| 2061 | std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications; |
| 2062 | for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) { |
| 2063 | RendererAccessibilityNotification& notification = |
| 2064 | pending_accessibility_notifications_[i]; |
| 2065 | WebAccessibilityObject obj = accessibility_->getObjectById(notification.id); |
| 2066 | if (!obj.isValid()) |
| 2067 | continue; |
| 2068 | |
| 2069 | ViewHostMsg_AccessibilityNotification_Params param; |
| 2070 | param.notification_type = pending_accessibility_notifications_[i].type; |
| 2071 | param.acc_obj = WebAccessibility(obj, accessibility_.get()); |
| 2072 | notifications.push_back(param); |
| 2073 | } |
| 2074 | pending_accessibility_notifications_.clear(); |
| 2075 | Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications)); |
| 2076 | accessibility_ack_pending_ = true; |
| 2077 | } |
| 2078 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2079 | void RenderView::textFieldDidReceiveKeyDown( |
| 2080 | const WebKit::WebInputElement& element, |
| 2081 | const WebKit::WebKeyboardEvent& event) { |
| 2082 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2083 | password_autocomplete_manager_->TextFieldHandlingKeyDown(element, event); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2084 | #endif |
| 2085 | } |
| 2086 | |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2087 | bool RenderView::handleCurrentKeyboardEvent() { |
| 2088 | if (edit_commands_.empty()) |
| 2089 | return false; |
| 2090 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2091 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2092 | if (!frame) |
| 2093 | return false; |
| 2094 | |
| 2095 | EditCommands::iterator it = edit_commands_.begin(); |
| 2096 | EditCommands::iterator end = edit_commands_.end(); |
| 2097 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2098 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2099 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 2100 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 2101 | // key (but it's the exception). Once one edit command is not executed, it |
| 2102 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2103 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 2104 | WebString::fromUTF8(it->value))) |
| 2105 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2106 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2107 | } |
| 2108 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2109 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2110 | } |
| 2111 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2112 | void RenderView::spellCheck(const WebString& text, |
| 2113 | int& misspelled_offset, |
| 2114 | int& misspelled_length) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2115 | EnsureDocumentTag(); |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 2116 | |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 2117 | string16 word(text); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2118 | RenderThread* thread = RenderThread::current(); |
| 2119 | // Will be NULL during unit tests. |
| 2120 | if (thread) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2121 | thread->spellchecker()->SpellCheckWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2122 | word.c_str(), word.size(), document_tag_, |
| 2123 | &misspelled_offset, &misspelled_length, NULL); |
| 2124 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | WebString RenderView::autoCorrectWord(const WebKit::WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2128 | string16 autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2129 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | b86c8c1 | 2009-10-05 22:01:26 | [diff] [blame] | 2130 | if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2131 | EnsureDocumentTag(); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2132 | RenderThread* thread = RenderThread::current(); |
| 2133 | // Will be NULL during unit tests. |
| 2134 | if (thread) { |
| 2135 | autocorrect_word = |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2136 | thread->spellchecker()->GetAutoCorrectionWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2137 | word, document_tag_); |
| 2138 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2139 | } |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2140 | return autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2141 | } |
| 2142 | |
[email protected] | c49085c7 | 2009-10-02 16:28:56 | [diff] [blame] | 2143 | void RenderView::showSpellingUI(bool show) { |
| 2144 | Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show)); |
| 2145 | } |
| 2146 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2147 | bool RenderView::isShowingSpellingUI() { |
| 2148 | return spelling_panel_visible_; |
| 2149 | } |
| 2150 | |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2151 | void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2152 | Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
| 2153 | word)); |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2154 | } |
| 2155 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2156 | bool RenderView::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 2157 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2158 | WebFileChooserCompletion* chooser_completion) { |
[email protected] | 7ef03e0 | 2010-10-23 11:58:35 | [diff] [blame] | 2159 | // Do not open the file dialog in a hidden RenderView. |
| 2160 | if (is_hidden()) |
| 2161 | return false; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2162 | ViewHostMsg_RunFileChooser_Params ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2163 | if (params.directory) |
| 2164 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; |
| 2165 | else if (params.multiSelect) |
| 2166 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple; |
| 2167 | else |
| 2168 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2169 | ipc_params.title = params.title; |
| 2170 | ipc_params.default_file_name = |
| 2171 | webkit_glue::WebStringToFilePath(params.initialValue); |
[email protected] | 09994913 | 2010-09-08 20:24:59 | [diff] [blame] | 2172 | ipc_params.accept_types = params.acceptTypes; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2173 | |
| 2174 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2175 | } |
| 2176 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2177 | void RenderView::runModalAlertDialog( |
| 2178 | WebFrame* frame, const WebString& message) { |
| 2179 | RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert, |
| 2180 | UTF16ToWideHack(message), |
| 2181 | std::wstring(), |
| 2182 | frame->url(), |
| 2183 | NULL); |
| 2184 | } |
| 2185 | |
| 2186 | bool RenderView::runModalConfirmDialog( |
| 2187 | WebFrame* frame, const WebString& message) { |
| 2188 | return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm, |
| 2189 | UTF16ToWideHack(message), |
| 2190 | std::wstring(), |
| 2191 | frame->url(), |
| 2192 | NULL); |
| 2193 | } |
| 2194 | |
| 2195 | bool RenderView::runModalPromptDialog( |
| 2196 | WebFrame* frame, const WebString& message, const WebString& default_value, |
| 2197 | WebString* actual_value) { |
| 2198 | std::wstring result; |
| 2199 | bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt, |
| 2200 | UTF16ToWideHack(message), |
| 2201 | UTF16ToWideHack(default_value), |
| 2202 | frame->url(), |
| 2203 | &result); |
| 2204 | if (ok) |
| 2205 | actual_value->assign(WideToUTF16Hack(result)); |
| 2206 | return ok; |
| 2207 | } |
| 2208 | |
| 2209 | bool RenderView::runModalBeforeUnloadDialog( |
| 2210 | WebFrame* frame, const WebString& message) { |
| 2211 | bool success = false; |
| 2212 | // This is an ignored return value, but is included so we can accept the same |
| 2213 | // response as RunJavaScriptMessage. |
| 2214 | std::wstring ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2215 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2216 | routing_id_, frame->url(), UTF16ToWideHack(message), &success, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2217 | &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2218 | return success; |
| 2219 | } |
| 2220 | |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2221 | void RenderView::showContextMenu( |
| 2222 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2223 | ContextMenuParams params = ContextMenuParams(data); |
| 2224 | if (!params.misspelled_word.empty() && RenderThread::current()) { |
| 2225 | int misspelled_offset, misspelled_length; |
[email protected] | c76a36a | 2010-01-26 22:44:04 | [diff] [blame] | 2226 | bool spelled_right = RenderThread::current()->spellchecker()-> |
| 2227 | SpellCheckWord( |
| 2228 | params.misspelled_word.c_str(), params.misspelled_word.size(), |
| 2229 | document_tag_, |
| 2230 | &misspelled_offset, &misspelled_length, |
| 2231 | ¶ms.dictionary_suggestions); |
| 2232 | if (spelled_right) |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2233 | params.misspelled_word.clear(); |
| 2234 | } |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2235 | // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do |
| 2236 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2237 | // in the context menu. |
| 2238 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2239 | // data encoded images. We should have a way to save them. |
| 2240 | if (params.src_url.spec().size() > chrome::kMaxURLChars) |
| 2241 | params.src_url = GURL(); |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2242 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2243 | } |
| 2244 | |
[email protected] | 52f139e2c | 2010-06-11 16:56:09 | [diff] [blame] | 2245 | bool RenderView::supportsFullscreen() { |
| 2246 | return CommandLine::ForCurrentProcess()->HasSwitch( |
| 2247 | switches::kEnableVideoFullscreen); |
| 2248 | } |
| 2249 | |
| 2250 | void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) { |
| 2251 | NOTIMPLEMENTED(); |
| 2252 | } |
| 2253 | |
| 2254 | void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) { |
| 2255 | NOTIMPLEMENTED(); |
| 2256 | } |
| 2257 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2258 | void RenderView::setStatusText(const WebString& text) { |
| 2259 | } |
| 2260 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2261 | void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2262 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2263 | if (latest_url == target_url_) |
| 2264 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2265 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2266 | // Tell the browser to display a destination link. |
| 2267 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2268 | target_url_status_ == TARGET_PENDING) { |
| 2269 | // If we have a request in-flight, save the URL to be sent when we |
| 2270 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2271 | // any existing pending sends. |
| 2272 | pending_target_url_ = latest_url; |
| 2273 | target_url_status_ = TARGET_PENDING; |
| 2274 | } else { |
| 2275 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2276 | target_url_ = latest_url; |
| 2277 | target_url_status_ = TARGET_INFLIGHT; |
| 2278 | } |
| 2279 | } |
| 2280 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2281 | void RenderView::StartNavStateSyncTimerIfNecessary() { |
| 2282 | int delay; |
| 2283 | if (send_content_state_immediately_) |
| 2284 | delay = 0; |
| 2285 | else if (is_hidden()) |
| 2286 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2287 | else |
| 2288 | delay = kDelaySecondsForContentStateSync; |
| 2289 | |
| 2290 | if (nav_state_sync_timer_.IsRunning()) { |
| 2291 | // The timer is already running. If the delay of the timer maches the amount |
| 2292 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2293 | // gets started with the right delay. |
| 2294 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2295 | return; |
| 2296 | nav_state_sync_timer_.Stop(); |
| 2297 | } |
| 2298 | |
| 2299 | nav_state_sync_timer_.Start( |
| 2300 | TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState); |
| 2301 | } |
| 2302 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2303 | void RenderView::setMouseOverURL(const WebURL& url) { |
| 2304 | mouse_over_url_ = GURL(url); |
| 2305 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2306 | } |
| 2307 | |
| 2308 | void RenderView::setKeyboardFocusURL(const WebURL& url) { |
| 2309 | focus_url_ = GURL(url); |
| 2310 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2311 | } |
| 2312 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2313 | void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) { |
| 2314 | Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text), |
| 2315 | hint)); |
| 2316 | } |
| 2317 | |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2318 | void RenderView::startDragging(const WebDragData& data, |
| 2319 | WebDragOperationsMask mask, |
| 2320 | const WebImage& image, |
| 2321 | const WebPoint& imageOffset) { |
| 2322 | #if WEBKIT_USING_SKIA |
| 2323 | SkBitmap bitmap(image.getSkBitmap()); |
| 2324 | #elif WEBKIT_USING_CG |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 2325 | SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2326 | #endif |
| 2327 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2328 | Send(new ViewHostMsg_StartDragging(routing_id_, |
| 2329 | WebDropData(data), |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2330 | mask, |
| 2331 | bitmap, |
| 2332 | imageOffset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2333 | } |
| 2334 | |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2335 | bool RenderView::acceptsLoadDrops() { |
| 2336 | return renderer_preferences_.can_accept_load_drops; |
| 2337 | } |
| 2338 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2339 | void RenderView::focusNext() { |
| 2340 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2341 | } |
| 2342 | |
| 2343 | void RenderView::focusPrevious() { |
| 2344 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2345 | } |
| 2346 | |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2347 | void RenderView::focusedNodeChanged(const WebNode& node) { |
[email protected] | 9b66f34bf | 2010-10-27 20:45:51 | [diff] [blame] | 2348 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node))); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 2349 | |
| 2350 | if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { |
| 2351 | // TODO(ctguil): Make WebKit send this notification. |
| 2352 | // When focus is cleared notify accessibility that the document is focused. |
| 2353 | postAccessibilityNotification( |
| 2354 | webview()->accessibilityObject(), |
| 2355 | WebKit::WebAccessibilityNotificationFocusedUIElementChanged); |
| 2356 | } |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2357 | } |
| 2358 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2359 | void RenderView::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2360 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2361 | } |
| 2362 | |
| 2363 | int RenderView::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2364 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | int RenderView::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2368 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2369 | } |
| 2370 | |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2371 | void RenderView::didUpdateInspectorSetting(const WebString& key, |
| 2372 | const WebString& value) { |
| 2373 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2374 | key.utf8(), |
| 2375 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2376 | } |
| 2377 | |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 2378 | void RenderView::queryAutofillSuggestions(const WebNode& node, |
| 2379 | const WebString& name, |
| 2380 | const WebString& value) { |
[email protected] | a5e84bd | 2010-09-14 22:23:36 | [diff] [blame] | 2381 | autofill_helper_->QueryAutoFillSuggestions(node); |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | void RenderView::removeAutofillSuggestions(const WebString& name, |
| 2385 | const WebString& value) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2386 | autofill_helper_->RemoveAutocompleteSuggestion(name, value); |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 2387 | } |
| 2388 | |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2389 | void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node, |
| 2390 | const WebKit::WebString& value, |
[email protected] | 1cf47dd5 | 2010-06-10 22:41:20 | [diff] [blame] | 2391 | const WebKit::WebString& label, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 2392 | int unique_id, |
[email protected] | 1cf47dd5 | 2010-06-10 22:41:20 | [diff] [blame] | 2393 | unsigned index) { |
[email protected] | a5e84bd | 2010-09-14 22:23:36 | [diff] [blame] | 2394 | autofill_helper_->DidAcceptAutoFillSuggestion(node, value, unique_id, index); |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2395 | } |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2396 | |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2397 | void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node, |
| 2398 | const WebKit::WebString& value, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 2399 | const WebKit::WebString& label, |
| 2400 | int unique_id) { |
[email protected] | a5e84bd | 2010-09-14 22:23:36 | [diff] [blame] | 2401 | autofill_helper_->DidSelectAutoFillSuggestion(node, unique_id); |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2405 | autofill_helper_->DidClearAutoFillSelection(node); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2406 | } |
| 2407 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2408 | void RenderView::didAcceptAutocompleteSuggestion( |
| 2409 | const WebKit::WebInputElement& user_element) { |
| 2410 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2411 | bool result = password_autocomplete_manager_->FillPassword(user_element); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2412 | // Since this user name was selected from a suggestion list, we should always |
| 2413 | // have password for it. |
| 2414 | DCHECK(result); |
| 2415 | #endif |
| 2416 | } |
| 2417 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2418 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2419 | |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2420 | void RenderView::didFocus() { |
| 2421 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2422 | // we won't have to test for user gesture anymore and we can |
| 2423 | // move that code back to render_widget.cc |
| 2424 | if (webview() && webview()->mainFrame() && |
| 2425 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2426 | Send(new ViewHostMsg_Focus(routing_id_)); |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | void RenderView::didBlur() { |
| 2431 | // TODO(jcivelli): see TODO above in didFocus(). |
| 2432 | if (webview() && webview()->mainFrame() && |
| 2433 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2434 | Send(new ViewHostMsg_Blur(routing_id_)); |
| 2435 | } |
| 2436 | } |
| 2437 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2438 | // We are supposed to get a single call to Show for a newly created RenderView |
| 2439 | // that was created via RenderView::CreateWebView. So, we wait until this |
| 2440 | // point to dispatch the ShowView message. |
| 2441 | // |
| 2442 | // This method provides us with the information about how to display the newly |
| 2443 | // created RenderView (i.e., as a constrained popup or as a new tab). |
| 2444 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2445 | void RenderView::show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2446 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 2447 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2448 | |
| 2449 | if (did_show_) |
| 2450 | return; |
| 2451 | did_show_ = true; |
| 2452 | |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 2453 | // Extensions and apps always allowed to create unrequested popups. The second |
| 2454 | // check is necessary to include content scripts. |
| 2455 | if (ExtensionRendererInfo::GetByURL(creator_url_) || |
| 2456 | bindings_utils::GetInfoForCurrentContext()) { |
| 2457 | opened_by_user_gesture_ = true; |
| 2458 | } |
| 2459 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2460 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2461 | if (!opened_by_user_gesture_) { |
| 2462 | // We exempt background tabs for compat with older versions of Chrome. |
| 2463 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2464 | // we probably don't need this check. |
| 2465 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2466 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2467 | } |
| 2468 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2469 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2470 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2471 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2472 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2473 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2474 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2475 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2476 | } |
| 2477 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2478 | void RenderView::closeWidgetSoon() { |
[email protected] | 7faa5386 | 2010-06-16 00:09:13 | [diff] [blame] | 2479 | // Cancel pending translations so that the translate_helper_ does not attempt |
| 2480 | // to access the WebView. |
| 2481 | translate_helper_.CancelPendingTranslation(); |
| 2482 | |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 2483 | if (script_can_close_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2484 | RenderWidget::closeWidgetSoon(); |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 2485 | } |
| 2486 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2487 | void RenderView::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2488 | DCHECK(did_show_) << "should already have shown the view"; |
| 2489 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2490 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2491 | // showModalDialog to function properly. |
| 2492 | // |
| 2493 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2494 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2495 | // handed manner. |
| 2496 | // |
| 2497 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 2498 | RenderThread::current()->DoNotSuspendWebKitSharedTimer(); |
| 2499 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2500 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2501 | } |
| 2502 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2503 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2504 | |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 2505 | WebPlugin* RenderView::createPlugin(WebFrame* frame, |
| 2506 | const WebPluginParams& params) { |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2507 | bool found = false; |
| 2508 | ContentSetting setting = CONTENT_SETTING_DEFAULT; |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2509 | CommandLine* cmd = CommandLine::ForCurrentProcess(); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2510 | WebPluginInfo info; |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2511 | GURL url(params.url); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2512 | std::string actual_mime_type; |
| 2513 | Send(new ViewHostMsg_GetPluginInfo(url, |
| 2514 | frame->top()->url(), |
| 2515 | params.mimeType.utf8(), |
| 2516 | &found, |
| 2517 | &info, |
| 2518 | &setting, |
| 2519 | &actual_mime_type)); |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2520 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2521 | if (!found) |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 2522 | return NULL; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2523 | DCHECK(setting != CONTENT_SETTING_DEFAULT); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 2524 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2525 | scoped_ptr<PluginGroup> group(PluginGroup::CopyOrCreatePluginGroup(info)); |
| 2526 | group->AddPlugin(info, 0); |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2527 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2528 | if (!info.enabled) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2529 | if (cmd->HasSwitch(switches::kDisableOutdatedPlugins) && |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2530 | group->IsVulnerable()) { |
| 2531 | Send(new ViewHostMsg_DisabledOutdatedPlugin(routing_id_, |
| 2532 | group->GetGroupName(), |
| 2533 | GURL(group->GetUpdateURL()))); |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 2534 | return CreateOutdatedPluginPlaceholder(frame, params, group.get()); |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2535 | } |
| 2536 | return NULL; |
| 2537 | } |
| 2538 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2539 | if (info.path.value() == kDefaultPluginLibraryName || |
| 2540 | setting == CONTENT_SETTING_ALLOW) { |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2541 | scoped_refptr<pepper::PluginModule> pepper_module = |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2542 | PepperPluginRegistry::GetInstance()->GetModule(info.path); |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2543 | if (pepper_module) { |
| 2544 | return CreatePepperPlugin(frame, |
| 2545 | params, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2546 | info.path, |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2547 | pepper_module.get()); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2548 | } |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2549 | return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type); |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 2550 | } |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2551 | std::string resource; |
| 2552 | if (cmd->HasSwitch(switches::kEnableResourceContentSettings)) |
| 2553 | resource = group->identifier(); |
| 2554 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource); |
| 2555 | int resource_id; |
| 2556 | int message_id; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2557 | if (setting == CONTENT_SETTING_ASK) { |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2558 | resource_id = IDR_BLOCKED_PLUGIN_HTML; |
| 2559 | message_id = IDS_PLUGIN_LOAD; |
| 2560 | } else { |
| 2561 | resource_id = IDR_OUTDATED_PLUGIN_HTML; |
| 2562 | message_id = IDS_PLUGIN_BLOCKED; |
| 2563 | } |
| 2564 | // |blocked_plugin| will delete itself when the WebViewPlugin |
| 2565 | // is destroyed. |
| 2566 | BlockedPlugin* blocked_plugin = |
| 2567 | new BlockedPlugin(this, |
| 2568 | frame, |
| 2569 | params, |
| 2570 | webkit_preferences_, |
| 2571 | resource_id, |
| 2572 | l10n_util::GetStringUTF16(message_id)); |
| 2573 | return blocked_plugin->plugin(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { |
[email protected] | 14396e9 | 2010-05-06 20:40:56 | [diff] [blame] | 2577 | WebApplicationCacheHostImpl* appcache_host = |
| 2578 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2579 | int appcache_host_id = appcache_host ? appcache_host->host_id() : 0; |
| 2580 | return new WebWorkerProxy(client, RenderThread::current(), routing_id_, |
| 2581 | appcache_host_id); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2582 | } |
| 2583 | |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2584 | WebSharedWorker* RenderView::createSharedWorker( |
| 2585 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2586 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2587 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2588 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2589 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2590 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2591 | ViewHostMsg_CreateWorker_Params params; |
| 2592 | params.url = url; |
| 2593 | params.is_shared = true; |
| 2594 | params.name = name; |
| 2595 | params.document_id = document_id; |
| 2596 | params.render_view_route_id = routing_id_; |
| 2597 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 2598 | params.parent_appcache_host_id = 0; |
| 2599 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2600 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2601 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2602 | if (url_mismatch) { |
| 2603 | return NULL; |
| 2604 | } else { |
| 2605 | return new WebSharedWorkerProxy(RenderThread::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2606 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2607 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2608 | route_id, |
| 2609 | routing_id_); |
| 2610 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2611 | } |
| 2612 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2613 | WebMediaPlayer* RenderView::createMediaPlayer( |
| 2614 | WebFrame* frame, WebMediaPlayerClient* client) { |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2615 | media::MediaFilterCollection collection; |
| 2616 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2617 | // Add in any custom filter factories first. |
| 2618 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 2619 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
| 2620 | // Add the chrome specific audio renderer. |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2621 | collection.push_back(new AudioRendererImpl(audio_message_filter())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2622 | } |
| 2623 | |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 2624 | if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) && |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 2625 | !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 2626 | // Add the hardware video decoder factory. |
| 2627 | // TODO(hclam): This assumes that ggl::Context is set to current |
| 2628 | // internally. I need to make it more explicit to get the context. |
| 2629 | bool ret = frame->view()->graphicsContext3D()->makeContextCurrent(); |
| 2630 | CHECK(ret) << "Failed to switch context"; |
| 2631 | |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2632 | collection.push_back(new IpcVideoDecoder( |
[email protected] | 885ff1df | 2010-10-07 21:47:58 | [diff] [blame] | 2633 | MessageLoop::current(), ggl::GetCurrentContext())); |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 2634 | } |
| 2635 | |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2636 | WebApplicationCacheHostImpl* appcache_host = |
| 2637 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2638 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2639 | // TODO(hclam): obtain the following parameters from |client|. |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2640 | // Create two bridge factory for two data sources. |
| 2641 | webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_simple = |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2642 | new webkit_glue::MediaResourceLoaderBridgeFactory( |
[email protected] | 7509760e3 | 2010-10-08 21:54:25 | [diff] [blame] | 2643 | GURL(frame->url()), // referrer |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 2644 | "null", // frame origin |
| 2645 | "null", // main_frame_origin |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2646 | base::GetCurrentProcId(), |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2647 | appcache_host ? appcache_host->host_id() : appcache::kNoHostId, |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2648 | routing_id()); |
| 2649 | |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2650 | webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_buffered = |
| 2651 | new webkit_glue::MediaResourceLoaderBridgeFactory( |
| 2652 | GURL(frame->url()), // referrer |
| 2653 | "null", // frame origin |
| 2654 | "null", // main_frame_origin |
| 2655 | base::GetCurrentProcId(), |
| 2656 | appcache_host ? appcache_host->host_id() : appcache::kNoHostId, |
| 2657 | routing_id()); |
| 2658 | |
| 2659 | scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer; |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2660 | if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) { |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2661 | scoped_refptr<IPCVideoRenderer> renderer = |
| 2662 | new IPCVideoRenderer(routing_id_); |
| 2663 | collection.push_back(renderer); |
| 2664 | video_renderer = renderer; |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2665 | } else { |
[email protected] | b57509eb | 2010-03-30 01:26:28 | [diff] [blame] | 2666 | bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging); |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2667 | scoped_refptr<webkit_glue::VideoRendererImpl> renderer = |
| 2668 | new webkit_glue::VideoRendererImpl(pts_logging); |
| 2669 | collection.push_back(renderer); |
| 2670 | video_renderer = renderer; |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2671 | } |
| 2672 | |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 2673 | return new webkit_glue::WebMediaPlayerImpl( |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame] | 2674 | client, collection, bridge_factory_simple, bridge_factory_buffered, |
| 2675 | cmd_line->HasSwitch(switches::kSimpleDataSource),video_renderer); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2676 | } |
| 2677 | |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2678 | WebApplicationCacheHost* RenderView::createApplicationCacheHost( |
| 2679 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
| 2680 | return new RendererWebApplicationCacheHostImpl( |
| 2681 | FromWebView(frame->view()), client, |
| 2682 | RenderThread::current()->appcache_dispatcher()->backend_proxy()); |
| 2683 | } |
| 2684 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 2685 | WebCookieJar* RenderView::cookieJar() { |
| 2686 | return &cookie_jar_; |
| 2687 | } |
| 2688 | |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2689 | void RenderView::frameDetached(WebFrame* frame) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2690 | autofill_helper_->FrameDetached(frame); |
| 2691 | page_click_tracker_->StopTrackingFrame(frame, true); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2692 | } |
| 2693 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2694 | void RenderView::willClose(WebFrame* frame) { |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2695 | WebDataSource* ds = frame->dataSource(); |
| 2696 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2697 | |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 2698 | if (!frame->parent()) { |
| 2699 | const GURL& url = frame->url(); |
| 2700 | // Ensure state contains scheme. |
| 2701 | if (url.SchemeIs("http")) |
| 2702 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP); |
| 2703 | else if (url.SchemeIs("https")) |
| 2704 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS); |
| 2705 | |
| 2706 | // Dump will only be provided when scheme is http or https. |
| 2707 | DumpLoadHistograms(); |
| 2708 | } |
| 2709 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2710 | navigation_state->user_script_idle_scheduler()->Cancel(); |
[email protected] | 174e60e | 2010-05-06 00:21:16 | [diff] [blame] | 2711 | |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2712 | // TODO(jhawkins): Remove once frameDetached is called by WebKit. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2713 | autofill_helper_->FrameWillClose(frame); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2714 | } |
| 2715 | |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2716 | bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2717 | if (enabled_per_settings && |
| 2718 | AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) |
| 2719 | return true; |
| 2720 | |
| 2721 | if (IsWhitelistedForContentSettings(frame)) |
| 2722 | return true; |
| 2723 | |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2724 | DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2725 | return false; // Other protocols fall through here. |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2726 | } |
| 2727 | |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2728 | bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | a16a421 | 2010-09-01 08:07:46 | [diff] [blame] | 2729 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 2730 | switches::kDisableClickToPlay)) { |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2731 | return WebFrameClient::allowPlugins(frame, enabled_per_settings); |
| 2732 | } |
[email protected] | a16a421 | 2010-09-01 08:07:46 | [diff] [blame] | 2733 | return enabled_per_settings && |
| 2734 | AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS); |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2738 | void RenderView::loadURLExternally( |
| 2739 | WebFrame* frame, const WebURLRequest& request, |
| 2740 | WebNavigationPolicy policy) { |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2741 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2742 | if (policy == WebKit::WebNavigationPolicyDownload) { |
| 2743 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); |
| 2744 | } else { |
| 2745 | OpenURL(request.url(), referrer, policy); |
| 2746 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | WebNavigationPolicy RenderView::decidePolicyForNavigation( |
| 2750 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 2751 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2752 | // Webkit is asking whether to navigate to a new URL. |
| 2753 | // This is fine normally, except if we're showing UI from one security |
| 2754 | // context and they're trying to navigate to a different context. |
| 2755 | const GURL& url = request.url(); |
| 2756 | |
| 2757 | // 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] | 2758 | // navigations. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2759 | if (renderer_preferences_.browser_handles_top_level_requests && |
| 2760 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2761 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
[email protected] | a58db8b | 2010-08-24 01:51:23 | [diff] [blame] | 2762 | // Reset these counters as the RenderView could be reused for the next |
| 2763 | // navigation. |
| 2764 | page_id_ = -1; |
[email protected] | a58db8b | 2010-08-24 01:51:23 | [diff] [blame] | 2765 | last_page_id_sent_to_browser_ = -1; |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2766 | OpenURL(url, referrer, default_policy); |
| 2767 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | // A content initiated navigation may have originated from a link-click, |
| 2771 | // script, drag-n-drop operation, etc. |
| 2772 | bool is_content_initiated = |
| 2773 | NavigationState::FromDataSource(frame->provisionalDataSource())-> |
| 2774 | is_content_initiated(); |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2775 | GURL old_url(frame->url()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2776 | |
| 2777 | // We only care about navigations that are within the current tab (as opposed |
| 2778 | // to, for example, opening a new window). |
| 2779 | // But we sometimes navigate to about:blank to clear a tab, and we want to |
| 2780 | // still allow that. |
| 2781 | if (default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2782 | is_content_initiated && frame->parent() == NULL && |
[email protected] | c240ace | 2010-06-16 18:31:53 | [diff] [blame] | 2783 | type != WebKit::WebNavigationTypeFormSubmitted && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2784 | !url.SchemeIs(chrome::kAboutScheme)) { |
| 2785 | // When we received such unsolicited navigations, we sometimes want to |
| 2786 | // punt them up to the browser to handle. |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2787 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) || |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2788 | frame->isViewSourceModeEnabled() || |
[email protected] | 918059b | 2010-05-25 17:08:42 | [diff] [blame] | 2789 | url.SchemeIs(chrome::kViewSourceScheme)) { |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2790 | // We don't send referrer from these special pages. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2791 | OpenURL(url, GURL(), default_policy); |
| 2792 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2793 | } |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2794 | |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2795 | // We forward non-local navigations from extensions to the browser if they |
| 2796 | // are top-level events, even if the browser hasn't expressed interest. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2797 | // TODO(erikkay) crbug.com/54118 - combine this clause and the next into |
| 2798 | // some shared logic. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2799 | if (BindingsPolicy::is_extension_enabled(enabled_bindings_) && |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2800 | old_url.SchemeIs(chrome::kExtensionScheme) && |
[email protected] | c240ace | 2010-06-16 18:31:53 | [diff] [blame] | 2801 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2802 | // We don't send referrer from extensions. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2803 | OpenURL(url, GURL(), default_policy); |
| 2804 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2805 | } |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2806 | |
| 2807 | // If the navigation would cross an app extent boundary, we also need |
| 2808 | // to defer to the browser to ensure process isolation. |
| 2809 | // TODO(erikkay) This is happening inside of a check to is_content_initiated |
| 2810 | // which means that things like the back button won't trigger it. Is that |
| 2811 | // OK? |
| 2812 | if (CrossesExtensionExtents(frame, url)) { |
| 2813 | // Include the referrer in this case since we're going from a hosted web |
| 2814 | // page. (the packaged case is handled previously by the extension |
| 2815 | // navigation test) |
| 2816 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2817 | OpenURL(url, referrer, default_policy); |
| 2818 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2819 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2823 | // its own process. This is done by sites like Gmail that try to open links |
| 2824 | // in new windows without script connections back to the original page. We |
| 2825 | // treat such cases as browser navigations (in which we will create a new |
| 2826 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2827 | // |
| 2828 | // We use the following heuristic to decide whether to fork a new page in its |
| 2829 | // own process: |
| 2830 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2831 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2832 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2833 | // |
| 2834 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2835 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2836 | bool is_fork = |
| 2837 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2838 | old_url == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2839 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2840 | historyBackListCount() < 1 && |
| 2841 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2842 | // The parent page must have set the child's window.opener to null before |
| 2843 | // redirecting to the desired URL. |
| 2844 | frame->opener() == NULL && |
| 2845 | // Must be a top-level frame. |
| 2846 | frame->parent() == NULL && |
| 2847 | // Must not have issued the request from this page. |
| 2848 | is_content_initiated && |
| 2849 | // Must be targeted at the current tab. |
| 2850 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2851 | // Must be a JavaScript navigation, which appears as "other". |
| 2852 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2853 | |
| 2854 | // Recognize if this navigation is from a link with rel=noreferrer and |
| 2855 | // target=_blank attributes, in which case the opener will be suppressed. If |
| 2856 | // so, it is safe to load cross-site pages in a separate process, so we |
| 2857 | // should let the browser handle it. |
| 2858 | bool is_noreferrer_and_blank_target = |
| 2859 | // Frame should be top level and not yet navigated. |
| 2860 | frame->parent() == NULL && |
| 2861 | frame->url().isEmpty() && |
| 2862 | historyBackListCount() < 1 && |
| 2863 | historyForwardListCount() < 1 && |
| 2864 | // Links with rel=noreferrer will have no Referer field, and their |
| 2865 | // resulting frame will have its window.opener suppressed. |
| 2866 | // TODO(creis): should add a request.httpReferrer() method to help avoid |
| 2867 | // typos on the unusual spelling of Referer. |
| 2868 | request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() && |
| 2869 | opener_suppressed_ && |
| 2870 | frame->opener() == NULL && |
| 2871 | // Links with target=_blank will have no name. |
| 2872 | frame->name().isNull() && |
| 2873 | // Another frame (with a non-empty creator) should have initiated the |
| 2874 | // request, targeted at this frame. |
| 2875 | !creator_url_.is_empty() && |
| 2876 | is_content_initiated && |
| 2877 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2878 | type == WebKit::WebNavigationTypeOther; |
| 2879 | |
| 2880 | if (is_fork || is_noreferrer_and_blank_target) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2881 | // Open the URL via the browser, not via WebKit. |
| 2882 | OpenURL(url, GURL(), default_policy); |
| 2883 | return WebKit::WebNavigationPolicyIgnore; |
| 2884 | } |
| 2885 | |
| 2886 | return default_policy; |
| 2887 | } |
| 2888 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2889 | bool RenderView::canHandleRequest( |
| 2890 | WebFrame* frame, const WebURLRequest& request) { |
| 2891 | // We allow WebKit to think that everything can be handled even though |
| 2892 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2893 | return true; |
| 2894 | } |
| 2895 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2896 | WebURLError RenderView::cannotHandleRequestError( |
| 2897 | WebFrame* frame, const WebURLRequest& request) { |
| 2898 | NOTREACHED(); // Since we said we can handle all requests. |
| 2899 | return WebURLError(); |
| 2900 | } |
| 2901 | |
| 2902 | WebURLError RenderView::cancelledError( |
| 2903 | WebFrame* frame, const WebURLRequest& request) { |
| 2904 | WebURLError error; |
| 2905 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2906 | error.reason = net::ERR_ABORTED; |
| 2907 | error.unreachableURL = request.url(); |
| 2908 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | void RenderView::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2912 | WebFrame*, const WebURLError&) { |
| 2913 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2914 | } |
| 2915 | |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2916 | void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame, |
| 2917 | const WebKit::WebFormElement& form) { |
| 2918 | // Some login forms have onSubmit handlers that put a hash of the password |
| 2919 | // into a hidden field and then clear the password. (Issue 28910.) |
| 2920 | // This method gets called before any of those handlers run, so save away |
| 2921 | // a copy of the password in case it gets lost. |
| 2922 | NavigationState* navigation_state = |
| 2923 | NavigationState::FromDataSource(frame->dataSource()); |
| 2924 | navigation_state->set_password_form_data( |
| 2925 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 2926 | } |
| 2927 | |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 2928 | void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2929 | NavigationState* navigation_state = |
| 2930 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2931 | |
| 2932 | if (navigation_state->transition_type() == PageTransition::LINK) |
| 2933 | navigation_state->set_transition_type(PageTransition::FORM_SUBMIT); |
| 2934 | |
| 2935 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2936 | WebSearchableFormData web_searchable_form_data(form); |
| 2937 | navigation_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2938 | navigation_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2939 | web_searchable_form_data.encoding().utf8()); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2940 | PasswordForm* password_form_data = |
| 2941 | PasswordFormDomManager::CreatePasswordForm(form); |
| 2942 | navigation_state->set_password_form_data(password_form_data); |
| 2943 | |
| 2944 | // If the password has been cleared, recover it from the form contents already |
| 2945 | // stored by willSendSubmitEvent into the dataSource's NavigationState (as |
| 2946 | // opposed to the provisionalDataSource's, which is what we're storing into |
| 2947 | // now.) |
| 2948 | if (password_form_data && password_form_data->password_value.empty()) { |
| 2949 | NavigationState* old_navigation_state = |
| 2950 | NavigationState::FromDataSource(frame->dataSource()); |
| 2951 | if (old_navigation_state) { |
| 2952 | PasswordForm* old_form_data = old_navigation_state->password_form_data(); |
| 2953 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 2954 | password_form_data->password_value = old_form_data->password_value; |
| 2955 | } |
| 2956 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2957 | |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2958 | FormData form_data; |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 2959 | if (FormManager::WebFormElementToFormData( |
[email protected] | 1fa7b48 | 2010-10-01 18:28:58 | [diff] [blame] | 2960 | form, FormManager::REQUIRE_AUTOCOMPLETE, true, false, &form_data)) |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2961 | Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | void RenderView::willPerformClientRedirect( |
| 2965 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2966 | double fire_time) { |
| 2967 | // Ignore |
| 2968 | } |
| 2969 | |
| 2970 | void RenderView::didCancelClientRedirect(WebFrame* frame) { |
| 2971 | // Ignore |
| 2972 | } |
| 2973 | |
| 2974 | void RenderView::didCompleteClientRedirect( |
| 2975 | WebFrame* frame, const WebURL& from) { |
| 2976 | if (!frame->parent()) |
| 2977 | completed_client_redirect_src_ = from; |
| 2978 | } |
| 2979 | |
| 2980 | void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
| 2981 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2982 | // non-null NavigationState. |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 2983 | bool content_initiated = !pending_navigation_state_.get(); |
| 2984 | NavigationState* state = content_initiated ? |
| 2985 | NavigationState::CreateContentInitiated() : |
| 2986 | pending_navigation_state_.release(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2987 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2988 | // NavigationState::referred_by_prefetcher_ is true if we are |
| 2989 | // navigating from a page that used prefetching using a link on that |
| 2990 | // page. We are early enough in the request process here that we |
| 2991 | // can still see the NavigationState of the previous page and set |
| 2992 | // this value appropriately. |
| 2993 | // TODO(gavinp): catch the important case of navigation in a new |
| 2994 | // renderer process. |
| 2995 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2996 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2997 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2998 | const GURL referrer( |
| 2999 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 3000 | if (!referrer.is_empty() && |
| 3001 | NavigationState::FromDataSource( |
| 3002 | old_frame->dataSource())->was_prefetcher()) { |
| 3003 | for (;old_frame;old_frame = old_frame->traverseNext(false)) { |
| 3004 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 3005 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
| 3006 | state->set_was_referred_by_prefetcher(true); |
| 3007 | break; |
| 3008 | } |
| 3009 | } |
| 3010 | } |
| 3011 | } |
| 3012 | } |
| 3013 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3014 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3015 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3016 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 3017 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
| 3018 | state->set_load_type(NavigationState::LINK_LOAD_NORMAL); |
| 3019 | break; |
| 3020 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
| 3021 | state->set_load_type(NavigationState::LINK_LOAD_RELOAD); |
| 3022 | break; |
| 3023 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
| 3024 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK); |
| 3025 | break; |
| 3026 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
| 3027 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY); |
| 3028 | break; |
| 3029 | } |
| 3030 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3031 | |
| 3032 | state->set_user_script_idle_scheduler( |
| 3033 | new UserScriptIdleScheduler(this, frame)); |
| 3034 | ds->setExtraData(state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | void RenderView::didStartProvisionalLoad(WebFrame* frame) { |
| 3038 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3039 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3040 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3041 | // Update the request time if WebKit has better knowledge of it. |
| 3042 | if (navigation_state->request_time().is_null()) { |
| 3043 | double event_time = ds->triggeringEventTime(); |
| 3044 | if (event_time != 0.0) |
| 3045 | navigation_state->set_request_time(Time::FromDoubleT(event_time)); |
| 3046 | } |
| 3047 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 3048 | // Start time is only set after request time. |
| 3049 | navigation_state->set_start_load_time(Time::Now()); |
| 3050 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3051 | bool is_top_most = !frame->parent(); |
| 3052 | if (is_top_most) { |
| 3053 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
| 3054 | NavigationGestureUnknown : NavigationGestureAuto; |
| 3055 | |
| 3056 | // Make sure redirect tracking state is clear for the new load. |
| 3057 | completed_client_redirect_src_ = GURL(); |
| 3058 | } else if (frame->parent()->isLoading()) { |
| 3059 | // 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] | 3060 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3061 | navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME); |
| 3062 | } |
| 3063 | |
| 3064 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 3065 | routing_id_, frame->identifier(), is_top_most, ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) { |
| 3069 | if (frame->parent()) |
| 3070 | return; |
| 3071 | // Received a redirect on the main frame. |
| 3072 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 3073 | if (!data_source) { |
| 3074 | // Should only be invoked when we have a data source. |
| 3075 | NOTREACHED(); |
| 3076 | return; |
| 3077 | } |
| 3078 | std::vector<GURL> redirects; |
| 3079 | GetRedirectChain(data_source, &redirects); |
| 3080 | if (redirects.size() >= 2) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3081 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
| 3082 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3083 | } |
| 3084 | } |
| 3085 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3086 | void RenderView::didFailProvisionalLoad(WebFrame* frame, |
| 3087 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3088 | // Notify the browser that we failed a provisional load with an error. |
| 3089 | // |
| 3090 | // Note: It is important this notification occur before DidStopLoading so the |
| 3091 | // SSL manager can react to the provisional load failure before being |
| 3092 | // notified the load stopped. |
| 3093 | // |
| 3094 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3095 | DCHECK(ds); |
| 3096 | |
| 3097 | const WebURLRequest& failed_request = ds->request(); |
| 3098 | |
| 3099 | bool show_repost_interstitial = |
| 3100 | (error.reason == net::ERR_CACHE_MISS && |
| 3101 | EqualsASCII(failed_request.httpMethod(), "POST")); |
| 3102 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 3103 | routing_id_, frame->identifier(), !frame->parent(), error.reason, |
| 3104 | error.unreachableURL, show_repost_interstitial)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3105 | |
| 3106 | // Don't display an error page if this is simply a cancelled load. Aside |
| 3107 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 3108 | if (error.reason == net::ERR_ABORTED) |
| 3109 | return; |
| 3110 | |
| 3111 | // Make sure we never show errors in view source mode. |
| 3112 | frame->enableViewSourceMode(false); |
| 3113 | |
| 3114 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3115 | |
| 3116 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 3117 | // 'replace' load. This is necessary to avoid messing up session history. |
| 3118 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 3119 | // as session history is concerned. |
| 3120 | // |
| 3121 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 3122 | // the page id. |
| 3123 | // |
| 3124 | bool replace = |
| 3125 | navigation_state->pending_page_id() != -1 || |
| 3126 | navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME; |
| 3127 | |
| 3128 | // If we failed on a browser initiated request, then make sure that our error |
| 3129 | // page load is regarded as the same browser initiated request. |
| 3130 | if (!navigation_state->is_content_initiated()) { |
| 3131 | pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( |
| 3132 | navigation_state->pending_page_id(), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3133 | navigation_state->pending_history_list_offset(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3134 | navigation_state->transition_type(), |
| 3135 | navigation_state->request_time())); |
| 3136 | } |
| 3137 | |
| 3138 | // Provide the user with a more helpful error page? |
| 3139 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 3140 | return; |
| 3141 | |
| 3142 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3143 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | void RenderView::didReceiveDocumentData( |
| 3147 | WebFrame* frame, const char* data, size_t data_len, |
| 3148 | bool& prevent_default) { |
| 3149 | NavigationState* navigation_state = |
| 3150 | NavigationState::FromDataSource(frame->dataSource()); |
| 3151 | if (!navigation_state->postpone_loading_data()) |
| 3152 | return; |
| 3153 | |
| 3154 | // We're going to call commitDocumentData ourselves... |
| 3155 | prevent_default = true; |
| 3156 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3157 | // Continue buffering the response data for the original error page. If it |
| 3158 | // grows too large, then we'll just let it through. For any error other than |
| 3159 | // a 404, "too large" means any data at all. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3160 | navigation_state->append_postponed_data(data, data_len); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3161 | if (navigation_state->postponed_data().size() >= 512 || |
| 3162 | navigation_state->http_status_code() != 404) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3163 | navigation_state->set_postpone_loading_data(false); |
| 3164 | frame->commitDocumentData(navigation_state->postponed_data().data(), |
| 3165 | navigation_state->postponed_data().size()); |
| 3166 | navigation_state->clear_postponed_data(); |
| 3167 | } |
| 3168 | } |
| 3169 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3170 | void RenderView::didCommitProvisionalLoad(WebFrame* frame, |
| 3171 | bool is_new_navigation) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3172 | NavigationState* navigation_state = |
| 3173 | NavigationState::FromDataSource(frame->dataSource()); |
| 3174 | |
| 3175 | navigation_state->set_commit_load_time(Time::Now()); |
| 3176 | if (is_new_navigation) { |
| 3177 | // When we perform a new navigation, we need to update the previous session |
| 3178 | // history entry with state for the page we are leaving. |
| 3179 | UpdateSessionHistory(frame); |
| 3180 | |
| 3181 | // We bump our Page ID to correspond with the new session history entry. |
| 3182 | page_id_ = next_page_id_++; |
| 3183 | |
[email protected] | d64b07b | 2010-04-20 22:14:06 | [diff] [blame] | 3184 | // Any pending translation is now obsolete. |
| 3185 | translate_helper_.CancelPendingTranslation(); |
| 3186 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3187 | // Advance our offset in session history, applying the length limit. There |
| 3188 | // is now no forward history. |
| 3189 | history_list_offset_++; |
| 3190 | if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries) |
| 3191 | history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1; |
| 3192 | history_list_length_ = history_list_offset_ + 1; |
| 3193 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 3194 | MessageLoop::current()->PostDelayedTask( |
| 3195 | FROM_HERE, |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 3196 | page_info_method_factory_.NewRunnableMethod( |
| 3197 | &RenderView::CapturePageInfo, page_id_, true), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3198 | kDelayForForcedCaptureMs); |
| 3199 | } else { |
| 3200 | // Inspect the navigation_state on this frame to see if the navigation |
| 3201 | // corresponds to a session history navigation... Note: |frame| may or |
| 3202 | // may not be the toplevel frame, but for the case of capturing session |
| 3203 | // history, the first committed frame suffices. We keep track of whether |
| 3204 | // we've seen this commit before so that only capture session history once |
| 3205 | // per navigation. |
| 3206 | // |
| 3207 | // Note that we need to check if the page ID changed. In the case of a |
| 3208 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 3209 | // previous URL and the current page ID, which would be wrong. |
| 3210 | if (navigation_state->pending_page_id() != -1 && |
| 3211 | navigation_state->pending_page_id() != page_id_ && |
| 3212 | !navigation_state->request_committed()) { |
| 3213 | // This is a successful session history navigation! |
| 3214 | UpdateSessionHistory(frame); |
| 3215 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3216 | |
| 3217 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | // Remember that we've already processed this request, so we don't update |
| 3222 | // the session history again. We do this regardless of whether this is |
| 3223 | // a session history navigation, because if we attempted a session history |
| 3224 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3225 | // new navigation. |
| 3226 | navigation_state->set_request_committed(true); |
| 3227 | |
| 3228 | UpdateURL(frame); |
| 3229 | |
| 3230 | // If this committed load was initiated by a client redirect, we're |
| 3231 | // at the last stop now, so clear it. |
| 3232 | completed_client_redirect_src_ = GURL(); |
| 3233 | |
| 3234 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3235 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | void RenderView::didClearWindowObject(WebFrame* frame) { |
| 3239 | if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_)) |
| 3240 | BindDOMAutomationController(frame); |
[email protected] | 0d7ae86 | 2010-10-01 13:52:45 | [diff] [blame] | 3241 | GURL frame_url = frame->url(); |
| 3242 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) && |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 3243 | (frame_url.SchemeIs(chrome::kChromeUIScheme) || |
[email protected] | 731ae51 | 2010-10-15 18:20:17 | [diff] [blame] | 3244 | frame_url.SchemeIs(chrome::kGearsScheme) || |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 3245 | frame_url.SchemeIs(chrome::kDataScheme))) { |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3246 | GetDOMUIBindings()->set_message_sender(this); |
| 3247 | GetDOMUIBindings()->set_routing_id(routing_id_); |
| 3248 | GetDOMUIBindings()->BindToJavascript(frame, L"chrome"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3249 | } |
| 3250 | if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) { |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3251 | GetExternalHostBindings()->set_message_sender(this); |
| 3252 | GetExternalHostBindings()->set_routing_id(routing_id_); |
| 3253 | GetExternalHostBindings()->BindToJavascript(frame, L"externalHost"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | void RenderView::didCreateDocumentElement(WebFrame* frame) { |
| 3258 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3259 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3260 | frame, UserScript::DOCUMENT_START); |
| 3261 | } |
| 3262 | |
| 3263 | // Notify the browser about non-blank documents loading in the top frame. |
| 3264 | GURL url = frame->url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 3265 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3266 | if (frame == webview()->mainFrame()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3267 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
| 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { |
| 3272 | UpdateTitle(frame, title); |
| 3273 | |
| 3274 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3275 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3276 | } |
| 3277 | |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3278 | void RenderView::didChangeIcons(WebFrame* frame) { |
| 3279 | if (!frame->parent()) { |
| 3280 | Send(new ViewHostMsg_UpdateFavIconURL( |
| 3281 | routing_id_, |
| 3282 | page_id_, |
| 3283 | frame->favIconURL())); |
| 3284 | } |
| 3285 | } |
| 3286 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3287 | void RenderView::didFinishDocumentLoad(WebFrame* frame) { |
| 3288 | WebDataSource* ds = frame->dataSource(); |
| 3289 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3290 | DCHECK(navigation_state); |
| 3291 | navigation_state->set_finish_document_load_time(Time::Now()); |
| 3292 | |
| 3293 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_)); |
| 3294 | |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3295 | page_click_tracker_->StartTrackingFrame(frame); |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 3296 | // The document has now been fully loaded. Scan for forms to be sent up to |
| 3297 | // the browser. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3298 | autofill_helper_->FrameContentsAvailable(frame); |
| 3299 | password_autocomplete_manager_->SendPasswordForms(frame, false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3300 | |
| 3301 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3302 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3303 | |
| 3304 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3305 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3306 | frame, UserScript::DOCUMENT_END); |
| 3307 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3308 | |
[email protected] | 41f1663 | 2010-10-20 01:21:32 | [diff] [blame] | 3309 | // InjectScripts() can end up creating a new NavigationState if it triggers a |
| 3310 | // fragment navigation, so we need to re-fetch it here. |
| 3311 | navigation_state = NavigationState::FromDataSource(ds); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3312 | navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad(); |
| 3313 | } |
| 3314 | |
| 3315 | void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) { |
| 3316 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3317 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3318 | frame, UserScript::DOCUMENT_IDLE); |
| 3319 | } |
| 3320 | |
| 3321 | WebFrame* main_frame = webview()->mainFrame(); |
| 3322 | if (frame == main_frame) { |
| 3323 | while (!pending_code_execution_queue_.empty()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 3324 | linked_ptr<ViewMsg_ExecuteCode_Params>& params = |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3325 | pending_code_execution_queue_.front(); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 3326 | ExecuteCodeImpl(main_frame, *params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3327 | pending_code_execution_queue_.pop(); |
| 3328 | } |
| 3329 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | void RenderView::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 3333 | if (webview()->mainFrame() == frame) { |
| 3334 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 3335 | page_id_)); |
| 3336 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3337 | } |
| 3338 | |
| 3339 | void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { |
| 3340 | // Ignore |
| 3341 | } |
| 3342 | |
| 3343 | void RenderView::didFinishLoad(WebFrame* frame) { |
| 3344 | WebDataSource* ds = frame->dataSource(); |
| 3345 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3346 | DCHECK(navigation_state); |
| 3347 | navigation_state->set_finish_load_time(Time::Now()); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3348 | navigation_state->user_script_idle_scheduler()->DidFinishLoad(); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3349 | |
| 3350 | // Let the password manager know which password forms are actually visible. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3351 | password_autocomplete_manager_->SendPasswordForms(frame, true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3352 | } |
| 3353 | |
[email protected] | ccbe04e | 2010-03-17 17:58:43 | [diff] [blame] | 3354 | void RenderView::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3355 | WebFrame* frame, bool is_new_navigation) { |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3356 | // Determine if the UserScriptIdleScheduler already ran scripts on this page, |
| 3357 | // since a new one gets created by didCreateDataSource. |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3358 | NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3359 | bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run(); |
| 3360 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3361 | // If this was a reference fragment navigation that we initiated, then we |
| 3362 | // could end up having a non-null pending navigation state. We just need to |
| 3363 | // update the ExtraData on the datasource so that others who read the |
| 3364 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3365 | // initiate this navigation, then we need to take care to reset any pre- |
| 3366 | // existing navigation state to a content-initiated navigation state. |
| 3367 | // DidCreateDataSource conveniently takes care of this for us. |
| 3368 | didCreateDataSource(frame, frame->dataSource()); |
| 3369 | |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3370 | NavigationState* new_state = |
| 3371 | NavigationState::FromDataSource(frame->dataSource()); |
| 3372 | new_state->set_was_within_same_page(true); |
| 3373 | |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3374 | if (idle_scheduler_ran) { |
| 3375 | // Update the new UserScriptIdleScheduler so we don't re-run scripts. |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3376 | new_state->user_script_idle_scheduler()->set_has_run(true); |
| 3377 | } |
| 3378 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3379 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 3380 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3381 | UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3382 | } |
| 3383 | |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3384 | void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3385 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3386 | } |
| 3387 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3388 | void RenderView::assignIdentifierToRequest( |
| 3389 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 3390 | // Ignore |
| 3391 | } |
| 3392 | |
| 3393 | void RenderView::willSendRequest( |
| 3394 | WebFrame* frame, unsigned identifier, WebURLRequest& request, |
| 3395 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3396 | WebFrame* top_frame = frame->top(); |
| 3397 | if (!top_frame) |
| 3398 | top_frame = frame; |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3399 | WebDataSource* provisional_data_source = top_frame->provisionalDataSource(); |
| 3400 | WebDataSource* top_data_source = top_frame->dataSource(); |
| 3401 | WebDataSource* data_source = |
| 3402 | provisional_data_source ? provisional_data_source : top_data_source; |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3403 | if (data_source) { |
| 3404 | NavigationState* state = NavigationState::FromDataSource(data_source); |
| 3405 | if (state && state->is_cache_policy_override_set()) |
| 3406 | request.setCachePolicy(state->cache_policy_override()); |
| 3407 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3408 | |
| 3409 | if (top_data_source) { |
| 3410 | NavigationState* state = NavigationState::FromDataSource(top_data_source); |
| 3411 | if (state && request.targetType() == WebURLRequest::TargetIsPrefetch) |
| 3412 | state->set_was_prefetcher(true); |
| 3413 | } |
| 3414 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3415 | request.setRequestorID(routing_id_); |
[email protected] | c5bbc245 | 2010-03-08 08:33:50 | [diff] [blame] | 3416 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 3417 | request.clearHTTPHeaderField("Referer"); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3418 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 3419 | // Temporary metrics, see site_isolation_metrics.h |
| 3420 | SiteIsolationMetrics::AddRequest(identifier, request.targetType()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | void RenderView::didReceiveResponse( |
| 3424 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3425 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 3426 | // Temporary metrics, see site_isolation_metrics.h |
| 3427 | SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame, |
| 3428 | identifier, |
| 3429 | response); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3430 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3431 | // Only do this for responses that correspond to a provisional data source |
| 3432 | // of the top-most frame. If we have a provisional data source, then we |
| 3433 | // can't have any sub-resources yet, so we know that this response must |
| 3434 | // correspond to a frame load. |
| 3435 | if (!frame->provisionalDataSource() || frame->parent()) |
| 3436 | return; |
| 3437 | |
| 3438 | // 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] | 3439 | // the server's error page. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3440 | if (frame->isViewSourceModeEnabled()) |
| 3441 | return; |
| 3442 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3443 | NavigationState* navigation_state = |
| 3444 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 3445 | CHECK(navigation_state); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3446 | int http_status_code = response.httpStatusCode(); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3447 | |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3448 | // Record page load flags. |
| 3449 | navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); |
| 3450 | navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated()); |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 3451 | navigation_state->set_was_alternate_protocol_available( |
| 3452 | response.wasAlternateProtocolAvailable()); |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3453 | navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3454 | navigation_state->set_http_status_code(http_status_code); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3455 | |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 3456 | // Consider loading an alternate error page for 404 responses. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3457 | if (http_status_code == 404) { |
| 3458 | // Can we even load an alternate error page for this URL? |
| 3459 | if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid()) |
| 3460 | return; |
| 3461 | } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain, |
| 3462 | http_status_code)) { |
| 3463 | // If no corresponding error strings for a particular status code, just |
| 3464 | // render any received data, regardless of whether or not the status code |
| 3465 | // indicates an error. |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 3466 | return; |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3467 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3468 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3469 | navigation_state->set_postpone_loading_data(true); |
| 3470 | navigation_state->clear_postponed_data(); |
| 3471 | } |
| 3472 | |
| 3473 | void RenderView::didFinishResourceLoad( |
| 3474 | WebFrame* frame, unsigned identifier) { |
| 3475 | NavigationState* navigation_state = |
| 3476 | NavigationState::FromDataSource(frame->dataSource()); |
| 3477 | if (!navigation_state->postpone_loading_data()) |
| 3478 | return; |
| 3479 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3480 | // The server returned an error and the content was < 512 bytes (which we |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3481 | // suppressed). Go ahead and fetch the alternate page content. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3482 | int http_status_code = navigation_state->http_status_code(); |
| 3483 | if (http_status_code == 404) { |
| 3484 | // On 404s, try a remote search page as a fallback. |
| 3485 | const GURL& frame_url = frame->url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3486 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3487 | const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404); |
| 3488 | DCHECK(error_page_url.is_valid()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3489 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3490 | WebURLError original_error; |
| 3491 | original_error.unreachableURL = frame_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3492 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3493 | navigation_state->set_alt_error_page_fetcher( |
| 3494 | new AltErrorPageResourceFetcher( |
| 3495 | error_page_url, frame, original_error, |
| 3496 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 3497 | } else { |
| 3498 | // On other errors, use an internal error page. |
| 3499 | WebURLError error; |
| 3500 | error.unreachableURL = frame->url(); |
| 3501 | error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain); |
| 3502 | error.reason = http_status_code; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3503 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3504 | LoadNavigationErrorPage(frame, frame->dataSource()->request(), error, |
| 3505 | std::string(), true); |
| 3506 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | void RenderView::didFailResourceLoad( |
| 3510 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 3511 | // Ignore |
| 3512 | } |
| 3513 | |
| 3514 | void RenderView::didLoadResourceFromMemoryCache( |
| 3515 | WebFrame* frame, const WebURLRequest& request, |
| 3516 | const WebURLResponse& response) { |
| 3517 | // Let the browser know we loaded a resource from the memory cache. This |
| 3518 | // message is needed to display the correct SSL indicators. |
| 3519 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 3520 | routing_id_, |
| 3521 | request.url(), |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 3522 | frame->securityOrigin().toString().utf8(), |
| 3523 | frame->top()->securityOrigin().toString().utf8(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3524 | response.securityInfo())); |
| 3525 | } |
| 3526 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3527 | void RenderView::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3528 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 3529 | } |
| 3530 | |
| 3531 | void RenderView::didRunInsecureContent( |
| 3532 | WebFrame* frame, const WebSecurityOrigin& origin) { |
| 3533 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 3534 | routing_id_, |
| 3535 | origin.toString().utf8())); |
| 3536 | } |
| 3537 | |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3538 | bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 3539 | if (enabled_per_settings && |
| 3540 | AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) |
| 3541 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3542 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 3543 | if (IsWhitelistedForContentSettings(frame)) |
| 3544 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3545 | |
| 3546 | return false; // Other protocols fall through here. |
| 3547 | } |
| 3548 | |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 3549 | bool RenderView::allowDatabase( |
| 3550 | WebFrame* frame, const WebString& name, const WebString& display_name, |
| 3551 | unsigned long estimated_size) { |
| 3552 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 3553 | if (origin.isEmpty()) |
| 3554 | return false; // Uninitialized document? |
| 3555 | |
| 3556 | bool result; |
| 3557 | if (!Send(new ViewHostMsg_AllowDatabase(routing_id_, |
| 3558 | origin.toString().utf8(), name, display_name, estimated_size, &result))) |
| 3559 | return false; |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 3560 | Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_, |
| 3561 | GURL(origin.toString().utf8()), |
| 3562 | name, |
| 3563 | display_name, |
| 3564 | estimated_size, |
| 3565 | !result)); |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 3566 | return result; |
| 3567 | } |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3568 | void RenderView::didNotAllowScript(WebKit::WebFrame* frame) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3569 | DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3570 | } |
| 3571 | |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 3572 | void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3573 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 3574 | } |
| 3575 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3576 | void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
| 3577 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 3578 | } |
| 3579 | |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3580 | void RenderView::didCreateScriptContext(WebFrame* frame) { |
| 3581 | EventBindings::HandleContextCreated(frame, false); |
| 3582 | } |
| 3583 | |
| 3584 | void RenderView::didDestroyScriptContext(WebFrame* frame) { |
| 3585 | EventBindings::HandleContextDestroyed(frame); |
| 3586 | } |
| 3587 | |
| 3588 | void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) { |
| 3589 | EventBindings::HandleContextCreated(frame, true); |
| 3590 | } |
| 3591 | |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 3592 | bool RenderView::allowScriptExtension(WebFrame* frame, |
| 3593 | const WebString& extension_name, |
| 3594 | int extension_group) { |
| 3595 | // NULL in unit tests. |
| 3596 | if (!RenderThread::current()) |
| 3597 | return true; |
| 3598 | |
| 3599 | // Note: we prefer the provisional URL here instead of the document URL |
| 3600 | // because we might be currently loading an URL into a blank page. |
| 3601 | // See http://code.google.com/p/chromium/issues/detail?id=10924 |
| 3602 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3603 | if (!ds) |
| 3604 | ds = frame->dataSource(); |
| 3605 | return RenderThread::current()->AllowScriptExtension( |
| 3606 | extension_name.utf8(), ds->request().url(), extension_group); |
| 3607 | } |
| 3608 | |
[email protected] | fc86daa | 2010-03-30 23:52:53 | [diff] [blame] | 3609 | void RenderView::logCrossFramePropertyAccess(WebFrame* frame, |
| 3610 | WebFrame* target, |
| 3611 | bool cross_origin, |
| 3612 | const WebString& property_name, |
| 3613 | unsigned long long event_id) { |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 3614 | // TODO(johnnyg): track the individual properties and repeat event_ids. |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 3615 | if (cross_origin) |
| 3616 | cross_origin_access_count_++; |
| 3617 | else |
| 3618 | same_origin_access_count_++; |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 3619 | } |
| 3620 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3621 | void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) { |
[email protected] | d8a179c | 2010-01-31 00:58:14 | [diff] [blame] | 3622 | CheckPreferredSize(); |
| 3623 | } |
| 3624 | |
| 3625 | void RenderView::CheckPreferredSize() { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3626 | // 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] | 3627 | // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3628 | // message. |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3629 | if (!send_preferred_size_changes_ || !webview()) |
| 3630 | return; |
[email protected] | dfca5acf | 2010-03-22 03:28:43 | [diff] [blame] | 3631 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3632 | // WebCore likes to tell us things have changed even when they haven't, so |
| 3633 | // cache the width and height and only send the IPC message when we're sure |
| 3634 | // they're different. |
| 3635 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 3636 | webview()->mainFrame()->documentElementScrollHeight()); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 3637 | |
| 3638 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 3639 | // so we need to adjust. |
| 3640 | double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel()); |
| 3641 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 3642 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 3643 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3644 | if (size == preferred_size_) |
| 3645 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 3646 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3647 | preferred_size_ = size; |
| 3648 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 3649 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3650 | } |
| 3651 | |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3652 | void RenderView::didChangeScrollOffset(WebFrame* frame) { |
| 3653 | StartNavStateSyncTimerIfNecessary(); |
| 3654 | } |
| 3655 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3656 | void RenderView::reportFindInPageMatchCount(int request_id, int count, |
| 3657 | bool final_update) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3658 | int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 3659 | if (!count) |
| 3660 | active_match_ordinal = 0; |
| 3661 | |
| 3662 | IPC::Message* msg = new ViewHostMsg_Find_Reply( |
| 3663 | routing_id_, |
| 3664 | request_id, |
| 3665 | count, |
| 3666 | gfx::Rect(), |
| 3667 | active_match_ordinal, |
| 3668 | final_update); |
| 3669 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3670 | // If we have a message that has been queued up, then we should just replace |
| 3671 | // it. The ACK from the browser will make sure it gets sent when the browser |
| 3672 | // wants it. |
| 3673 | if (queued_find_reply_message_.get()) { |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3674 | queued_find_reply_message_.reset(msg); |
| 3675 | } else { |
| 3676 | // Send the search result over to the browser process. |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3677 | Send(msg); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | void RenderView::reportFindInPageSelection(int request_id, |
| 3682 | int active_match_ordinal, |
| 3683 | const WebRect& selection_rect) { |
| 3684 | // Send the search result over to the browser process. |
| 3685 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3686 | request_id, |
| 3687 | -1, |
| 3688 | selection_rect, |
| 3689 | active_match_ordinal, |
| 3690 | false)); |
| 3691 | } |
| 3692 | |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3693 | void RenderView::openFileSystem( |
| 3694 | WebFrame* frame, |
| 3695 | WebFileSystem::Type type, |
| 3696 | long long size, |
| 3697 | WebFileSystemCallbacks* callbacks) { |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3698 | DCHECK(callbacks); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3699 | |
| 3700 | WebSecurityOrigin origin = frame->securityOrigin(); |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3701 | if (origin.isEmpty()) { |
| 3702 | // Uninitialized document? |
| 3703 | callbacks->didFail(WebKit::WebFileErrorAbort); |
| 3704 | return; |
| 3705 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3706 | |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3707 | ChildThread::current()->file_system_dispatcher()->OpenFileSystem( |
| 3708 | GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), |
| 3709 | size, new WebFileSystemCallbackDispatcher(callbacks)); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3710 | } |
| 3711 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 3712 | // webkit_glue::WebPluginPageDelegate ----------------------------------------- |
| 3713 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3714 | webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3715 | const FilePath& file_path, |
| 3716 | const std::string& mime_type) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3717 | if (!PluginChannelHost::IsListening()) |
| 3718 | return NULL; |
| 3719 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3720 | bool use_pepper_host = false; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3721 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3722 | // Check for trusted Pepper plugins. |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3723 | const char kPepperPrefix[] = "pepper-"; |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3724 | if (StartsWithASCII(mime_type, kPepperPrefix, true)) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3725 | if (CommandLine::ForCurrentProcess()-> |
| 3726 | HasSwitch(switches::kInternalPepper)) { |
| 3727 | in_process_plugin = true; |
| 3728 | use_pepper_host = true; |
| 3729 | } else { |
| 3730 | // In process Pepper plugins must be explicitly enabled. |
| 3731 | return NULL; |
| 3732 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3733 | } else { |
| 3734 | FilePath internal_pdf_path; |
| 3735 | PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path); |
| 3736 | if (file_path == internal_pdf_path) { |
| 3737 | in_process_plugin = true; |
| 3738 | use_pepper_host = true; |
| 3739 | } |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3740 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3741 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3742 | // Check for Native Client modules. |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 3743 | if (mime_type == "application/x-nacl-srpc" && |
| 3744 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) { |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3745 | // NaCl is only permitted when we're in an extension/application with the |
| 3746 | // appropriate permission, or when explicitly enabled on the command line. |
| 3747 | |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3748 | GURL main_frame_url(webview()->mainFrame()->url()); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3749 | ExtensionRendererInfo* extension = |
| 3750 | ExtensionRendererInfo::GetByURL(main_frame_url); |
| 3751 | bool in_ext = extension != NULL; |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3752 | bool explicit_enable = |
| 3753 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl); |
| 3754 | |
| 3755 | if (in_ext) { |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 3756 | // TODO(cbiffle): NaCl is back to experimental for M7. |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3757 | if (ExtensionProcessBindings::HasPermission(extension->id(), |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 3758 | Extension::kExperimentalPermission)) { |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3759 | in_process_plugin = true; |
| 3760 | use_pepper_host = true; |
| 3761 | } else { |
| 3762 | // Disable NaCl for apps lacking the permission, even with the flag. |
| 3763 | return NULL; |
| 3764 | } |
| 3765 | } else if (explicit_enable) { |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3766 | in_process_plugin = true; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3767 | use_pepper_host = true; |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3768 | } |
| 3769 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3770 | |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3771 | if (in_process_plugin) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3772 | if (use_pepper_host) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3773 | WebPluginDelegatePepper* pepper_plugin = |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3774 | WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr()); |
[email protected] | b7d7ed5 | 2010-07-20 00:12:33 | [diff] [blame] | 3775 | if (!pepper_plugin) |
| 3776 | return NULL; |
| 3777 | |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 3778 | current_oldstyle_pepper_plugins_.insert(pepper_plugin); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3779 | return pepper_plugin; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3780 | } else { |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3781 | #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] | 3782 | return WebPluginDelegateImpl::Create( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3783 | file_path, mime_type, gfx::NativeViewFromId(host_window_)); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3784 | #else |
[email protected] | 596b2c4 | 2010-01-14 20:40:43 | [diff] [blame] | 3785 | NOTIMPLEMENTED(); |
| 3786 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 3787 | #endif |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3788 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3789 | } |
| 3790 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3791 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3795 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3796 | RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer( |
| 3797 | routing_id(), window)); |
| 3798 | #endif |
| 3799 | } |
| 3800 | |
| 3801 | void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3802 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3803 | RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer( |
| 3804 | routing_id(), window)); |
| 3805 | #endif |
| 3806 | CleanupWindowInPluginMoves(window); |
| 3807 | } |
| 3808 | |
| 3809 | void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) { |
| 3810 | SchedulePluginMove(move); |
| 3811 | } |
| 3812 | |
| 3813 | void RenderView::DidStartLoadingForPlugin() { |
| 3814 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3815 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | void RenderView::DidStopLoadingForPlugin() { |
| 3819 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3820 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3821 | } |
| 3822 | |
| 3823 | void RenderView::ShowModalHTMLDialogForPlugin( |
| 3824 | const GURL& url, |
| 3825 | const gfx::Size& size, |
| 3826 | const std::string& json_arguments, |
| 3827 | std::string* json_retval) { |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3828 | SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog( |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3829 | routing_id_, url, size.width(), size.height(), json_arguments, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3830 | json_retval)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3831 | } |
| 3832 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 3833 | WebCookieJar* RenderView::GetCookieJar() { |
| 3834 | return &cookie_jar_; |
| 3835 | } |
| 3836 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3837 | void RenderView::SyncNavigationState() { |
| 3838 | if (!webview()) |
| 3839 | return; |
| 3840 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3841 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3842 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3843 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3844 | |
| 3845 | Send(new ViewHostMsg_UpdateState( |
| 3846 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3847 | } |
| 3848 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3849 | bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) { |
| 3850 | // Make sure webview was not shut down. |
| 3851 | if (!webview()) |
| 3852 | return false; |
| 3853 | // Create an image resource fetcher and assign it with a call back object. |
| 3854 | image_fetchers_.insert(new ImageResourceFetcher( |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3855 | image_url, webview()->mainFrame(), id, image_size, |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3856 | NewCallback(this, &RenderView::DidDownloadImage))); |
| 3857 | return true; |
| 3858 | } |
| 3859 | |
| 3860 | void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3861 | const SkBitmap& image) { |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3862 | // Notify requester of image download status. |
[email protected] | 51bd3661 | 2009-10-20 22:49:47 | [diff] [blame] | 3863 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, |
| 3864 | fetcher->id(), |
| 3865 | fetcher->image_url(), |
| 3866 | image.isNull(), |
| 3867 | image)); |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3868 | // Dispose of the image fetcher. |
| 3869 | DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end()); |
| 3870 | image_fetchers_.erase(fetcher); |
| 3871 | // We're in the callback from the ImageResourceFetcher, best to delay |
| 3872 | // deletion. |
| 3873 | MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3874 | } |
| 3875 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3876 | void RenderView::OnDownloadFavIcon(int id, |
| 3877 | const GURL& image_url, |
| 3878 | int image_size) { |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3879 | bool data_image_failed = false; |
| 3880 | if (image_url.SchemeIs("data")) { |
| 3881 | SkBitmap data_image = ImageFromDataUrl(image_url); |
| 3882 | data_image_failed = data_image.empty(); |
| 3883 | if (!data_image_failed) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3884 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false, |
| 3885 | data_image)); |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3886 | } |
| 3887 | } |
| 3888 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3889 | if (data_image_failed || |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3890 | !DownloadImage(id, image_url, image_size)) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3891 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true, |
| 3892 | SkBitmap())); |
| 3893 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3894 | } |
| 3895 | |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3896 | SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const { |
| 3897 | std::string mime_type, char_set, data; |
| 3898 | if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
| 3899 | // Decode the favicon using WebKit's image decoder. |
| 3900 | webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize)); |
| 3901 | const unsigned char* src_data = |
| 3902 | reinterpret_cast<const unsigned char*>(&data[0]); |
| 3903 | |
| 3904 | return decoder.Decode(src_data, data.size()); |
| 3905 | } |
| 3906 | return SkBitmap(); |
| 3907 | } |
| 3908 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3909 | void RenderView::OnGetApplicationInfo(int page_id) { |
| 3910 | webkit_glue::WebApplicationInfo app_info; |
| 3911 | if (page_id == page_id_) |
| 3912 | webkit_glue::GetApplicationInfo(webview(), &app_info); |
| 3913 | |
| 3914 | // Prune out any data URLs in the set of icons. The browser process expects |
| 3915 | // any icon with a data URL to have originated from a favicon. We don't want |
| 3916 | // to decode arbitrary data URLs in the browser process. See |
| 3917 | // http://b/issue?id=1162972 |
| 3918 | for (size_t i = 0; i < app_info.icons.size(); ++i) { |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 3919 | if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3920 | app_info.icons.erase(app_info.icons.begin() + i); |
| 3921 | --i; |
| 3922 | } |
| 3923 | } |
| 3924 | |
| 3925 | Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info)); |
| 3926 | } |
| 3927 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3928 | GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3929 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3930 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3931 | // If the URL that failed was secure, then the embedding web page was not |
| 3932 | // expecting a network attacker to be able to manipulate its contents. As |
| 3933 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 3934 | // attacker to manipulate the contents of the response if we tried to use |
| 3935 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3936 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | // Grab the base URL from the browser process. |
| 3940 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3941 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3942 | |
| 3943 | // Strip query params from the failed URL. |
| 3944 | GURL::Replacements remove_params; |
| 3945 | remove_params.ClearUsername(); |
| 3946 | remove_params.ClearPassword(); |
| 3947 | remove_params.ClearQuery(); |
| 3948 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3949 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3950 | std::string spec_to_send = url_to_send.spec(); |
| 3951 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 3952 | if (failed_url.has_query()) |
| 3953 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3954 | |
| 3955 | // Construct the query params to send to link doctor. |
| 3956 | std::string params(alternate_error_page_url_.query()); |
| 3957 | params.append("&url="); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3958 | params.append(EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3959 | params.append("&sourceid=chrome"); |
| 3960 | params.append("&error="); |
| 3961 | switch (error_type) { |
| 3962 | case DNS_ERROR: |
| 3963 | params.append("dnserror"); |
| 3964 | break; |
| 3965 | |
| 3966 | case HTTP_404: |
| 3967 | params.append("http404"); |
| 3968 | break; |
| 3969 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3970 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 3971 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3972 | break; |
| 3973 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3974 | default: |
| 3975 | NOTREACHED() << "unknown ErrorPageType"; |
| 3976 | } |
| 3977 | |
| 3978 | // OK, build the final url to return. |
| 3979 | GURL::Replacements link_doctor_params; |
| 3980 | link_doctor_params.SetQueryStr(params); |
| 3981 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 3982 | return url; |
| 3983 | } |
| 3984 | |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3985 | DOMUIBindings* RenderView::GetDOMUIBindings() { |
| 3986 | if (!dom_ui_bindings_.get()) { |
| 3987 | dom_ui_bindings_.reset(new DOMUIBindings()); |
| 3988 | } |
| 3989 | return dom_ui_bindings_.get(); |
| 3990 | } |
| 3991 | |
| 3992 | ExternalHostBindings* RenderView::GetExternalHostBindings() { |
| 3993 | if (!external_host_bindings_.get()) { |
| 3994 | external_host_bindings_.reset(new ExternalHostBindings()); |
| 3995 | } |
| 3996 | return external_host_bindings_.get(); |
| 3997 | } |
| 3998 | |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3999 | WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() { |
| 4000 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4001 | } |
| 4002 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 4003 | void RenderView::OnFind(int request_id, const string16& search_text, |
| 4004 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4005 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4006 | |
| 4007 | if (main_frame->document().isPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4008 | if (options.findNext) { |
| 4009 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4010 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4011 | } else { |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 4012 | if (GetWebPluginFromPluginDocument()->startFind( |
| 4013 | search_text, options.matchCase, request_id)) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4014 | } else { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 4015 | // Send "no results". |
| 4016 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 4017 | request_id, |
| 4018 | 0, |
| 4019 | gfx::Rect(), |
| 4020 | 0, |
| 4021 | true)); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4022 | } |
| 4023 | } |
| 4024 | return; |
| 4025 | } |
| 4026 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4027 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4028 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4029 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 4030 | |
| 4031 | bool multi_frame = (frame_after_main != main_frame); |
| 4032 | |
| 4033 | // If we have multiple frames, we don't want to wrap the search within the |
| 4034 | // frame, so we check here if we only have main_frame in the chain. |
| 4035 | bool wrap_within_frame = !multi_frame; |
| 4036 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 4037 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4038 | bool result = false; |
| 4039 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4040 | // If something is selected when we start searching it means we cannot just |
| 4041 | // increment the current match ordinal; we need to re-generate it. |
| 4042 | WebRange current_selection = focused_frame->selectionRange(); |
| 4043 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4044 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4045 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4046 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4047 | |
| 4048 | if (!result) { |
| 4049 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 4050 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4051 | |
| 4052 | // Find the next frame, but skip the invisible ones. |
| 4053 | do { |
| 4054 | // What is the next frame to search? (we might be going backwards). Note |
| 4055 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4056 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4057 | search_frame->traverseNext(true) : |
| 4058 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4059 | } while (!search_frame->hasVisibleContent() && |
| 4060 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4061 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 4062 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 4063 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4064 | |
| 4065 | // If we have multiple frames and we have wrapped back around to the |
| 4066 | // focused frame, we need to search it once more allowing wrap within |
| 4067 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 4068 | // reported matches, but no frames after the focused_frame contain a |
| 4069 | // match for the search word(s). |
| 4070 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4071 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4072 | request_id, search_text, options, true, // Force wrapping. |
| 4073 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4074 | } |
| 4075 | } |
| 4076 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4077 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4078 | } while (!result && search_frame != focused_frame); |
| 4079 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4080 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4081 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4082 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4083 | } else { |
| 4084 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 4085 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 4086 | // yet what is active. |
| 4087 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 4088 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4089 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4090 | // If we find no matches then this will be our last status update. |
| 4091 | // Otherwise the scoping effort will send more results. |
| 4092 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4093 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4094 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 4095 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4096 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4097 | match_count, |
| 4098 | selection_rect, |
| 4099 | ordinal, |
| 4100 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4101 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4102 | // Scoping effort begins, starting with the mainframe. |
| 4103 | search_frame = main_frame; |
| 4104 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4105 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4106 | |
| 4107 | do { |
| 4108 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4109 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4110 | |
| 4111 | // We don't start another scoping effort unless at least one match has |
| 4112 | // been found. |
| 4113 | if (result) { |
| 4114 | // Start new scoping request. If the scoping function determines that it |
| 4115 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4116 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4117 | search_text, |
| 4118 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4119 | true); // reset the tickmarks |
| 4120 | } |
| 4121 | |
| 4122 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 4123 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4124 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4125 | } while (search_frame != main_frame); |
| 4126 | } |
| 4127 | } |
| 4128 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4129 | void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) { |
| 4130 | WebView* view = webview(); |
| 4131 | if (!view) |
| 4132 | return; |
| 4133 | |
| 4134 | WebDocument doc = view->mainFrame()->document(); |
| 4135 | if (doc.isPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4136 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4137 | return; |
| 4138 | } |
| 4139 | |
| 4140 | bool clear_selection = |
| 4141 | params.action == ViewMsg_StopFinding_Params::kClearSelection; |
| 4142 | if (clear_selection) |
| 4143 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 4144 | |
| 4145 | WebFrame* frame = view->mainFrame(); |
| 4146 | while (frame) { |
| 4147 | frame->stopFinding(clear_selection); |
| 4148 | frame = frame->traverseNext(false); |
| 4149 | } |
| 4150 | |
| 4151 | if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) { |
| 4152 | WebFrame* focused_frame = view->focusedFrame(); |
| 4153 | if (focused_frame) { |
| 4154 | WebDocument doc = focused_frame->document(); |
| 4155 | if (!doc.isNull()) { |
| 4156 | WebNode node = doc.focusedNode(); |
| 4157 | if (!node.isNull()) |
| 4158 | node.simulateClick(); |
| 4159 | } |
| 4160 | } |
| 4161 | } |
| 4162 | } |
| 4163 | |
| 4164 | void RenderView::OnFindReplyAck() { |
| 4165 | // Check if there is any queued up request waiting to be sent. |
| 4166 | if (queued_find_reply_message_.get()) { |
| 4167 | // Send the search result over to the browser process. |
[email protected] | d22d873 | 2010-05-04 19:24:42 | [diff] [blame] | 4168 | Send(queued_find_reply_message_.release()); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4169 | } |
| 4170 | } |
| 4171 | |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 4172 | bool RenderView::AllowContentType(ContentSettingsType settings_type) { |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 4173 | // CONTENT_SETTING_ASK is only valid for cookies. |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 4174 | return current_content_settings_.settings[settings_type] != |
| 4175 | CONTENT_SETTING_BLOCK; |
| 4176 | } |
| 4177 | |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 4178 | void RenderView::DidBlockContentType(ContentSettingsType settings_type, |
| 4179 | const std::string& resource_identifier) { |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 4180 | if (!content_blocked_[settings_type]) { |
| 4181 | content_blocked_[settings_type] = true; |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 4182 | Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type, |
| 4183 | resource_identifier)); |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 4184 | } |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 4185 | } |
| 4186 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 4187 | void RenderView::ClearBlockedContentSettings() { |
| 4188 | for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 4189 | content_blocked_[i] = false; |
| 4190 | } |
| 4191 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 4192 | WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame, |
| 4193 | const WebPluginParams& params, |
| 4194 | const FilePath& path, |
| 4195 | pepper::PluginModule* pepper_module) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4196 | return new pepper::WebPluginImpl( |
| 4197 | pepper_module, params, pepper_delegate_.AsWeakPtr()); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 4198 | } |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 4199 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 4200 | WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame, |
| 4201 | const WebPluginParams& params, |
| 4202 | const FilePath& path, |
| 4203 | const std::string& mime_type) { |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 4204 | return new webkit_glue::WebPluginImpl( |
| 4205 | frame, params, path, mime_type, AsWeakPtr()); |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 4206 | } |
| 4207 | |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 4208 | WebPlugin* RenderView::CreateOutdatedPluginPlaceholder( |
| 4209 | WebFrame* frame, |
| 4210 | const WebPluginParams& params, |
| 4211 | PluginGroup* group) { |
| 4212 | int resource_id = IDR_OUTDATED_PLUGIN_HTML; |
| 4213 | const base::StringPiece template_html( |
| 4214 | ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| 4215 | |
| 4216 | DCHECK(!template_html.empty()) << "unable to load template. ID: " |
| 4217 | << resource_id; |
| 4218 | |
| 4219 | DictionaryValue values; |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 4220 | values.SetString("message", |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 4221 | l10n_util::GetStringFUTF8(IDS_PLUGIN_OUTDATED, group->GetGroupName())); |
| 4222 | values.Set("pluginGroup", group->GetDataForUI()); |
| 4223 | |
| 4224 | // "t" is the id of the templates root node. |
| 4225 | std::string htmlData = jstemplate_builder::GetTemplatesHtml( |
| 4226 | template_html, &values, "t"); |
| 4227 | |
| 4228 | return WebViewPlugin::Create(NULL, |
| 4229 | webkit_preferences_, |
| 4230 | htmlData, |
| 4231 | GURL("chrome://outdatedplugin/")); |
| 4232 | } |
| 4233 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4234 | void RenderView::OnZoom(PageZoom::Function function) { |
| 4235 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4236 | return; |
| 4237 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 4238 | webview()->hidePopups(); |
[email protected] | b03794d | 2010-03-26 19:57:52 | [diff] [blame] | 4239 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4240 | double old_zoom_level = webview()->zoomLevel(); |
| 4241 | double zoom_level; |
| 4242 | if (function == PageZoom::RESET) { |
| 4243 | zoom_level = 0; |
| 4244 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 4245 | // Previous zoom level is a whole number, so just increment/decrement. |
| 4246 | zoom_level = old_zoom_level + function; |
| 4247 | } else { |
| 4248 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 4249 | // not a whole number, or a plugin changed it to a custom value. We want |
| 4250 | // to go to the next whole number so that the user can always get back to |
| 4251 | // 100% with the keyboard/menu. |
| 4252 | if ((old_zoom_level > 1 && function > 0) || |
| 4253 | (old_zoom_level < 1 && function < 0)) { |
[email protected] | 3209e711 | 2010-10-01 23:53:45 | [diff] [blame] | 4254 | zoom_level = static_cast<int>(old_zoom_level + function); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4255 | } else { |
| 4256 | // We're going towards 100%, so first go to the next whole number. |
| 4257 | zoom_level = static_cast<int>(old_zoom_level); |
| 4258 | } |
| 4259 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4260 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4261 | webview()->setZoomLevel(false, zoom_level); |
| 4262 | zoomLevelChanged(); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4263 | } |
| 4264 | |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 4265 | void RenderView::OnSetZoomLevel(double zoom_level) { |
| 4266 | // Don't set zoom level for full-page plugin since they don't use the same |
| 4267 | // zoom settings. |
| 4268 | if (webview()->mainFrame()->document().isPluginDocument()) |
| 4269 | return; |
| 4270 | |
| 4271 | webview()->hidePopups(); |
| 4272 | webview()->setZoomLevel(false, zoom_level); |
| 4273 | zoomLevelChanged(); |
| 4274 | } |
| 4275 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4276 | void RenderView::OnSetContentSettingsForLoadingURL( |
| 4277 | const GURL& url, |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 4278 | const ContentSettings& content_settings) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4279 | host_content_settings_[url] = content_settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 4280 | } |
| 4281 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4282 | void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url, |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4283 | double zoom_level) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4284 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4285 | } |
| 4286 | |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 4287 | void RenderView::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4288 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4289 | } |
| 4290 | |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4291 | void RenderView::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4292 | WebString no_encoding; |
| 4293 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4294 | } |
| 4295 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4296 | bool RenderView::GetAllChildFrames( |
| 4297 | WebFrame* parent_frame, |
| 4298 | std::vector<WebFrame*>* frames_vector) const { |
| 4299 | if (!parent_frame) |
| 4300 | return false; |
| 4301 | for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
| 4302 | child_frame = child_frame->nextSibling()) { |
| 4303 | frames_vector->push_back(child_frame); |
| 4304 | GetAllChildFrames(child_frame, frames_vector); |
| 4305 | } |
| 4306 | return true; |
| 4307 | } |
| 4308 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4309 | WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { |
| 4310 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4311 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4312 | |
| 4313 | // xpath string can represent a frame deep down the tree (across multiple |
| 4314 | // frame DOMs). |
| 4315 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 4316 | // should break into 2 xpaths |
| 4317 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
| 4318 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4319 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4320 | |
| 4321 | std::wstring xpath_remaining = xpath; |
| 4322 | while (!xpath_remaining.empty()) { |
| 4323 | std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n'); |
| 4324 | std::wstring xpath_child; |
| 4325 | if (delim_pos != std::wstring::npos) { |
| 4326 | xpath_child = xpath_remaining.substr(0, delim_pos); |
| 4327 | xpath_remaining.erase(0, delim_pos + 1); |
| 4328 | } else { |
| 4329 | xpath_remaining.swap(xpath_child); |
| 4330 | } |
| 4331 | frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4332 | } |
| 4333 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4334 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4335 | } |
| 4336 | |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 4337 | void RenderView::SetSuggestResult(const std::string& suggest) { |
[email protected] | 5cbd61f | 2010-10-14 03:49:49 | [diff] [blame] | 4338 | // Explicitly allow empty strings to be sent to the browser. |
| 4339 | Send(new ViewHostMsg_SetSuggestResult(routing_id_, page_id_, suggest)); |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 4340 | } |
| 4341 | |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4342 | void RenderView::EvaluateScript(const string16& frame_xpath, |
| 4343 | const string16& script, |
| 4344 | int id, |
| 4345 | bool notify_result) { |
| 4346 | v8::Handle<v8::Value> result; |
| 4347 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
| 4348 | if (web_frame) |
| 4349 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); |
| 4350 | if (notify_result) { |
| 4351 | bool bool_result = !result.IsEmpty() && result->IsBoolean() ? |
| 4352 | result->BooleanValue() : false; |
| 4353 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, bool_result)); |
| 4354 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4355 | } |
| 4356 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4357 | void RenderView::InsertCSS(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4358 | const std::string& css, |
| 4359 | const std::string& id) { |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4360 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4361 | if (!web_frame) |
| 4362 | return; |
| 4363 | |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4364 | web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4365 | } |
| 4366 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4367 | void RenderView::OnPepperPluginDestroy( |
| 4368 | WebPluginDelegatePepper* pepper_plugin) { |
| 4369 | std::set<WebPluginDelegatePepper*>::iterator found_pepper = |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4370 | current_oldstyle_pepper_plugins_.find(pepper_plugin); |
| 4371 | if (found_pepper == current_oldstyle_pepper_plugins_.end()) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4372 | NOTREACHED(); |
| 4373 | return; |
| 4374 | } |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4375 | current_oldstyle_pepper_plugins_.erase(found_pepper); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4376 | |
| 4377 | // The plugin could have been destroyed while it was waiting for a file |
| 4378 | // choose callback, so check all pending completion callbacks and NULL them. |
| 4379 | for (std::deque< linked_ptr<PendingFileChooser> >::iterator i = |
| 4380 | file_chooser_completions_.begin(); |
| 4381 | i != file_chooser_completions_.end(); /* nothing */) { |
| 4382 | if ((*i)->completion == pepper_plugin) { |
| 4383 | // We NULL the first one instead of deleting it because the plugin might |
| 4384 | // be the one waiting for a file choose callback. If the callback later |
| 4385 | // comes, we don't want to send the result to the next callback in line. |
| 4386 | if (i == file_chooser_completions_.begin()) |
| 4387 | (*i)->completion = NULL; |
| 4388 | else |
| 4389 | i = file_chooser_completions_.erase(i); |
| 4390 | } else { |
| 4391 | ++i; |
| 4392 | } |
| 4393 | } |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4394 | } |
| 4395 | |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4396 | void RenderView::OnScriptEvalRequest(const string16& frame_xpath, |
| 4397 | const string16& jscript, |
| 4398 | int id, |
| 4399 | bool notify_result) { |
| 4400 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4401 | } |
| 4402 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4403 | void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4404 | const std::string& css, |
| 4405 | const std::string& id) { |
| 4406 | InsertCSS(frame_xpath, css, id); |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 4407 | |
| 4408 | // Notify RenderViewHost that css has been inserted into the frame. |
| 4409 | Send(new ViewHostMsg_OnCSSInserted(routing_id_)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4410 | } |
| 4411 | |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4412 | void RenderView::OnAddMessageToConsole( |
| 4413 | const string16& frame_xpath, |
| 4414 | const string16& message, |
| 4415 | const WebConsoleMessage::Level& level) { |
| 4416 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 4417 | if (web_frame) |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4418 | web_frame->addMessageToConsole(WebConsoleMessage(level, message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4419 | } |
| 4420 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4421 | void RenderView::OnAllowBindings(int enabled_bindings_flags) { |
| 4422 | enabled_bindings_ |= enabled_bindings_flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | void RenderView::OnSetDOMUIProperty(const std::string& name, |
| 4426 | const std::string& value) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4427 | DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4428 | GetDOMUIBindings()->SetProperty(name, value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4429 | } |
| 4430 | |
| 4431 | void RenderView::OnReservePageIDRange(int size_of_range) { |
| 4432 | next_page_id_ += size_of_range + 1; |
| 4433 | } |
| 4434 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4435 | void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 4436 | const gfx::Point& screen_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4437 | bool ended, |
| 4438 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4439 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4440 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 4441 | } else { |
| 4442 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4443 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | void RenderView::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4447 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4448 | } |
| 4449 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4450 | void RenderView::OnFillPasswordForm( |
[email protected] | e768baf | 2010-07-16 19:36:16 | [diff] [blame] | 4451 | const webkit_glue::PasswordFormFillData& form_data) { |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4452 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 4453 | password_autocomplete_manager_->ReceivedPasswordFormFillData(webview(), |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4454 | form_data); |
[email protected] | ad24ccb | 2010-07-15 21:38:20 | [diff] [blame] | 4455 | #else |
| 4456 | webkit_glue::FillPasswordForm(this->webview(), form_data); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4457 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data, |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4461 | const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4462 | const gfx::Point& screen_point, |
| 4463 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4464 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4465 | drop_data.ToDragData(), |
| 4466 | drop_data.identity, |
| 4467 | client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4468 | screen_point, |
| 4469 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4470 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4471 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4472 | } |
| 4473 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4474 | void RenderView::OnDragTargetDragOver(const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4475 | const gfx::Point& screen_point, |
| 4476 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4477 | WebDragOperation operation = webview()->dragTargetDragOver( |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4478 | client_point, |
| 4479 | screen_point, |
| 4480 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4481 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4482 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4483 | } |
| 4484 | |
| 4485 | void RenderView::OnDragTargetDragLeave() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4486 | webview()->dragTargetDragLeave(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4487 | } |
| 4488 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4489 | void RenderView::OnDragTargetDrop(const gfx::Point& client_point, |
| 4490 | const gfx::Point& screen_point) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4491 | webview()->dragTargetDrop(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 4495 | webkit_preferences_ = prefs; |
| 4496 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | void RenderView::OnSetAltErrorPageURL(const GURL& url) { |
| 4500 | alternate_error_page_url_ = url; |
| 4501 | } |
| 4502 | |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 4503 | void RenderView::OnCustomContextMenuAction(unsigned action) { |
| 4504 | webview()->performCustomContextMenuAction(action); |
| 4505 | } |
| 4506 | |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4507 | void RenderView::OnTranslatePage(int page_id, |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4508 | const std::string& translate_script, |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4509 | const std::string& source_lang, |
| 4510 | const std::string& target_lang) { |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4511 | translate_helper_.TranslatePage(page_id, source_lang, target_lang, |
| 4512 | translate_script); |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4513 | } |
| 4514 | |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4515 | void RenderView::OnRevertTranslation(int page_id) { |
| 4516 | translate_helper_.RevertTranslation(page_id); |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 4517 | } |
| 4518 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4519 | void RenderView::OnInstallMissingPlugin() { |
| 4520 | // This could happen when the first default plugin is deleted. |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4521 | if (first_default_plugin_) |
| 4522 | first_default_plugin_->InstallMissingPlugin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4523 | } |
| 4524 | |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 4525 | void RenderView::OnLoadBlockedPlugins() { |
| 4526 | NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS, |
| 4527 | Source<RenderView>(this), |
| 4528 | NotificationService::NoDetails()); |
| 4529 | } |
| 4530 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4531 | void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4532 | // This could happen if we navigated to a different page before the user |
| 4533 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4534 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4535 | return; |
| 4536 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4537 | WebVector<WebString> ws_file_names(paths.size()); |
| 4538 | for (size_t i = 0; i < paths.size(); ++i) |
| 4539 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 4540 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4541 | if (file_chooser_completions_.front()->completion) |
| 4542 | file_chooser_completions_.front()->completion->didChooseFile(ws_file_names); |
| 4543 | file_chooser_completions_.pop_front(); |
| 4544 | |
| 4545 | // If there are more pending file chooser requests, schedule one now. |
| 4546 | if (!file_chooser_completions_.empty()) { |
| 4547 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 4548 | file_chooser_completions_.front()->params)); |
| 4549 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | void RenderView::OnEnableViewSourceMode() { |
| 4553 | if (!webview()) |
| 4554 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4555 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4556 | if (!main_frame) |
| 4557 | return; |
| 4558 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4559 | main_frame->enableViewSourceMode(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4560 | } |
| 4561 | |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 4562 | void RenderView::OnEnablePreferredSizeChangedMode(int flags) { |
| 4563 | DCHECK(flags != kPreferredSizeNothing); |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4564 | if (send_preferred_size_changes_) |
| 4565 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4566 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 4567 | |
| 4568 | // WebKit doesn't send a notification of the effective height of the page |
| 4569 | // changes, so poll for it. |
| 4570 | // TODO: Add a notification for this to WebKit, remove polling. After that's |
| 4571 | // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight. |
| 4572 | // http://crbug.com/44850 |
| 4573 | if (flags & kPreferredSizeHeightThisIsSlow) { |
| 4574 | preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this, |
| 4575 | &RenderView::CheckPreferredSize); |
| 4576 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 4577 | } |
| 4578 | |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4579 | void RenderView::OnDisableScrollbarsForSmallWindows( |
| 4580 | const gfx::Size& disable_scrollbar_size_limit) { |
| 4581 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 4582 | } |
| 4583 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4584 | void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { |
| 4585 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 4586 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 0dd6f9b5 | 2010-10-14 16:39:13 | [diff] [blame] | 4587 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 4588 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 4589 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 4590 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 4591 | gfx::NativeThemeLinux::instance()->SetScrollbarColors( |
| 4592 | renderer_prefs.thumb_inactive_color, |
| 4593 | renderer_prefs.thumb_active_color, |
| 4594 | renderer_prefs.track_color); |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4595 | |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4596 | if (webview()) { |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4597 | webview()->setScrollbarColors( |
| 4598 | renderer_prefs.thumb_inactive_color, |
| 4599 | renderer_prefs.thumb_active_color, |
| 4600 | renderer_prefs.track_color); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4601 | webview()->setSelectionColors( |
| 4602 | renderer_prefs.active_selection_bg_color, |
| 4603 | renderer_prefs.active_selection_fg_color, |
| 4604 | renderer_prefs.inactive_selection_bg_color, |
| 4605 | renderer_prefs.inactive_selection_fg_color); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 4606 | webview()->themeChanged(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4607 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 4608 | #endif |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4609 | } |
| 4610 | |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 4611 | void RenderView::OnMediaPlayerActionAt(const gfx::Point& location, |
| 4612 | const WebMediaPlayerAction& action) { |
| 4613 | if (webview()) |
| 4614 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 4615 | } |
| 4616 | |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 4617 | void RenderView::OnNotifyRendererViewType(ViewType::Type type) { |
| 4618 | view_type_ = type; |
| 4619 | } |
| 4620 | |
| 4621 | void RenderView::OnUpdateBrowserWindowId(int window_id) { |
| 4622 | browser_window_id_ = window_id; |
| 4623 | } |
| 4624 | |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 4625 | void RenderView::OnEnableAccessibility() { |
| 4626 | if (WebAccessibilityCache::accessibilityEnabled()) |
| 4627 | return; |
[email protected] | 9f4db51 | 2010-05-10 20:21:41 | [diff] [blame] | 4628 | |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 4629 | WebAccessibilityCache::enableAccessibility(); |
| 4630 | |
| 4631 | if (webview()) { |
| 4632 | // It's possible that the webview has already loaded a webpage without |
| 4633 | // accessibility being enabled. Initialize the browser's cached |
| 4634 | // accessibility tree by sending it a 'load complete' notification. |
| 4635 | postAccessibilityNotification( |
| 4636 | webview()->accessibilityObject(), |
| 4637 | WebKit::WebAccessibilityNotificationLoadComplete); |
| 4638 | } |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 4639 | } |
| 4640 | |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4641 | void RenderView::OnSetAccessibilityFocus(int acc_obj_id) { |
| 4642 | if (!accessibility_.get()) |
| 4643 | return; |
[email protected] | 02ea2f31 | 2010-09-27 17:03:36 | [diff] [blame] | 4644 | |
| 4645 | WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id); |
| 4646 | WebAccessibilityObject root = webview()->accessibilityObject(); |
| 4647 | if (!obj.isValid() || !root.isValid()) |
| 4648 | return; |
| 4649 | |
| 4650 | // By convention, calling SetFocus on the root of the tree should clear the |
| 4651 | // current focus. Otherwise set the focus to the new node. |
| 4652 | if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root)) |
| 4653 | webview()->clearFocusedNode(); |
| 4654 | else |
| 4655 | obj.setFocused(true); |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) { |
| 4659 | if (!accessibility_.get()) |
| 4660 | return; |
[email protected] | 02ea2f31 | 2010-09-27 17:03:36 | [diff] [blame] | 4661 | |
| 4662 | WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id); |
| 4663 | if (!obj.isValid()) |
| 4664 | return; |
| 4665 | |
| 4666 | obj.performDefaultAction(); |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4667 | } |
| 4668 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 4669 | void RenderView::OnAccessibilityNotificationsAck() { |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 4670 | DCHECK(accessibility_ack_pending_); |
| 4671 | accessibility_ack_pending_ = false; |
| 4672 | SendPendingAccessibilityNotifications(); |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 4673 | } |
| 4674 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4675 | void RenderView::OnGetAllSavableResourceLinksForCurrentPage( |
| 4676 | const GURL& page_url) { |
| 4677 | // Prepare list to storage all savable resource links. |
| 4678 | std::vector<GURL> resources_list; |
| 4679 | std::vector<GURL> referrers_list; |
| 4680 | std::vector<GURL> frames_list; |
| 4681 | webkit_glue::SavableResourcesResult result(&resources_list, |
| 4682 | &referrers_list, |
| 4683 | &frames_list); |
| 4684 | |
[email protected] | dbeb395 | 2009-10-13 18:01:18 | [diff] [blame] | 4685 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 4686 | webview(), |
| 4687 | page_url, |
| 4688 | &result, |
| 4689 | chrome::kSavableSchemes)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4690 | // If something is wrong when collecting all savable resource links, |
| 4691 | // send empty list to embedder(browser) to tell it failed. |
| 4692 | referrers_list.clear(); |
| 4693 | resources_list.clear(); |
| 4694 | frames_list.clear(); |
| 4695 | } |
| 4696 | |
| 4697 | // Send result of all savable resource links to embedder. |
| 4698 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_, |
| 4699 | resources_list, |
| 4700 | referrers_list, |
| 4701 | frames_list)); |
| 4702 | } |
| 4703 | |
| 4704 | void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | f6b4853 | 2009-02-12 01:56:32 | [diff] [blame] | 4705 | const std::vector<GURL>& links, |
[email protected] | fde6714d1 | 2009-02-18 22:39:31 | [diff] [blame] | 4706 | const std::vector<FilePath>& local_paths, |
| 4707 | const FilePath& local_directory_name) { |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4708 | |
| 4709 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 4710 | WebVector<WebURL> weburl_links(links); |
| 4711 | |
| 4712 | // Convert std::vector of std::strings to WebVector<WebString> |
| 4713 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 4714 | for (size_t i = 0; i < local_paths.size(); i++) |
| 4715 | webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); |
| 4716 | |
| 4717 | WebPageSerializer::serialize(webview()->mainFrame(), |
| 4718 | true, this, weburl_links, webstring_paths, |
| 4719 | webkit_glue::FilePathToWebString( |
| 4720 | local_directory_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4721 | } |
| 4722 | |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4723 | void RenderView::didSerializeDataForFrame(const WebURL& frame_url, |
| 4724 | const WebCString& data, |
| 4725 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4726 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4727 | routing_id_, |
| 4728 | frame_url, |
| 4729 | data.data(), |
| 4730 | static_cast<int32>(status))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4731 | } |
| 4732 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 4733 | void RenderView::OnShouldClose() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4734 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4735 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4736 | } |
| 4737 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4738 | void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4739 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 4740 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 4741 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 4742 | // calling the FrameLoader's CloseURL method directly. This should be |
| 4743 | // revisited to avoid having two ways to close a page. Having a single way |
| 4744 | // to close that can run onunload is also useful for fixing |
| 4745 | // http://b/issue?id=753080. |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 4746 | WebFrame* main_frame = webview()->mainFrame(); |
| 4747 | if (main_frame) { |
| 4748 | const GURL& url = main_frame->url(); |
| 4749 | // TODO(davemoore) this code should be removed once willClose() gets |
| 4750 | // called when a page is destroyed. DumpLoadHistograms() is safe to call |
| 4751 | // multiple times for the same frame, but it will simplify things. |
| 4752 | |
| 4753 | // Ensure state contains scheme. |
| 4754 | NavigationState* navigation_state = |
| 4755 | NavigationState::FromDataSource(main_frame->dataSource()); |
| 4756 | if (url.SchemeIs("http")) |
| 4757 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP); |
| 4758 | else if (url.SchemeIs("https")) |
| 4759 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS); |
| 4760 | |
| 4761 | // Dump will only be provided when scheme is http or https. |
| 4762 | DumpLoadHistograms(); |
| 4763 | } |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4764 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4765 | |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 4766 | // Reset stats |
| 4767 | cross_origin_access_count_ = 0; |
| 4768 | same_origin_access_count_ = 0; |
| 4769 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4770 | // Just echo back the params in the ACK. |
| 4771 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4772 | } |
| 4773 | |
| 4774 | void RenderView::OnThemeChanged() { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4775 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4776 | gfx::NativeTheme::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 4777 | if (webview()) |
| 4778 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4779 | #else // defined(OS_WIN) |
| 4780 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 4781 | NOTIMPLEMENTED(); |
| 4782 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4783 | } |
| 4784 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 4785 | void RenderView::OnHandleMessageFromExternalHost(const std::string& message, |
| 4786 | const std::string& origin, |
| 4787 | const std::string& target) { |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4788 | if (message.empty()) |
| 4789 | return; |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4790 | GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin, |
| 4791 | target); |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4792 | } |
| 4793 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 4794 | void RenderView::OnDisassociateFromPopupCount() { |
| 4795 | if (decrement_shared_popup_at_destruction_) |
| 4796 | shared_popup_counter_->data--; |
| 4797 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 4798 | decrement_shared_popup_at_destruction_ = false; |
| 4799 | } |
| 4800 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4801 | bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 4802 | const WebURLError& error, |
| 4803 | bool replace) { |
| 4804 | // We only show alternate error pages in the main frame. They are |
| 4805 | // intended to assist the user when navigating, so there is not much |
| 4806 | // value in showing them for failed subframes. Ideally, we would be |
| 4807 | // able to use the TYPED transition type for this, but that flag is |
| 4808 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4809 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4810 | return false; |
| 4811 | |
| 4812 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4813 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4814 | int ec = error.reason; |
| 4815 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 4816 | ec != net::ERR_CONNECTION_FAILED && |
| 4817 | ec != net::ERR_CONNECTION_REFUSED && |
| 4818 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4819 | ec != net::ERR_CONNECTION_TIMED_OUT) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4820 | return false; |
| 4821 | |
| 4822 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4823 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4824 | if (!error_page_url.is_valid()) |
| 4825 | return false; |
| 4826 | |
| 4827 | // Load an empty page first so there is an immediate response to the error, |
| 4828 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4829 | frame->loadHTMLString(std::string(), |
[email protected] | 144143c | 2010-10-28 08:17:36 | [diff] [blame] | 4830 | GURL(chrome::kUnreachableWebDataURL), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4831 | error.unreachableURL, |
| 4832 | replace); |
| 4833 | |
| 4834 | // Now, create a fetcher for the error page and associate it with the data |
| 4835 | // source we just created via the LoadHTMLString call. That way if another |
| 4836 | // navigation occurs, the fetcher will get destroyed. |
| 4837 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4838 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4839 | navigation_state->set_alt_error_page_fetcher( |
| 4840 | new AltErrorPageResourceFetcher( |
| 4841 | error_page_url, frame, error, |
| 4842 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 4843 | return true; |
| 4844 | } |
| 4845 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4846 | std::string RenderView::GetAltHTMLForTemplate( |
| 4847 | const DictionaryValue& error_strings, int template_resource_id) const { |
[email protected] | 8a16266e | 2009-09-10 21:08:39 | [diff] [blame] | 4848 | const base::StringPiece template_html( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4849 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 4850 | template_resource_id)); |
| 4851 | |
| 4852 | if (template_html.empty()) { |
| 4853 | NOTREACHED() << "unable to load template. ID: " << template_resource_id; |
| 4854 | return ""; |
| 4855 | } |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4856 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4857 | // "t" is the id of the templates root node. |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4858 | return jstemplate_builder::GetTemplatesHtml( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4859 | template_html, &error_strings, "t"); |
| 4860 | } |
[email protected] | 0e79b9e | 2009-02-13 04:20:48 | [diff] [blame] | 4861 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4862 | void RenderView::AltErrorPageFinished(WebFrame* frame, |
| 4863 | const WebURLError& original_error, |
| 4864 | const std::string& html) { |
| 4865 | // Here, we replace the blank page we loaded previously. |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4866 | |
| 4867 | // If we failed to download the alternate error page, fall back to the |
| 4868 | // original error page if present. Otherwise, LoadNavigationErrorPage |
| 4869 | // will simply display a default error page. |
| 4870 | const std::string* html_to_load = &html; |
| 4871 | if (html.empty()) { |
| 4872 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4873 | NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4874 | html_to_load = &navigation_state->postponed_data(); |
| 4875 | } |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 4876 | LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load, |
| 4877 | true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4878 | } |
| 4879 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4880 | void RenderView::OnMoveOrResizeStarted() { |
| 4881 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4882 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4883 | } |
| 4884 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4885 | void RenderView::OnResize(const gfx::Size& new_size, |
| 4886 | const gfx::Rect& resizer_rect) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4887 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4888 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4889 | if (send_preferred_size_changes_) { |
[email protected] | 7339cd2 | 2010-10-27 00:11:20 | [diff] [blame] | 4890 | webview()->mainFrame()->setCanHaveScrollbars( |
| 4891 | should_display_scrollbars(new_size.width(), new_size.height())); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4892 | } |
| 4893 | } |
| 4894 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4895 | RenderWidget::OnResize(new_size, resizer_rect); |
| 4896 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 4897 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4898 | void RenderView::DidInitiatePaint() { |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4899 | // Notify the pepper plugins that we started painting. |
| 4900 | pepper_delegate_.ViewInitiatedPaint(); |
| 4901 | |
| 4902 | // Notify any "old-style" pepper plugins that we started painting. This is |
| 4903 | // used for internal bookkeeping only, so we know that the set can not change |
| 4904 | // under us. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4905 | for (std::set<WebPluginDelegatePepper*>::iterator i = |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4906 | current_oldstyle_pepper_plugins_.begin(); |
| 4907 | i != current_oldstyle_pepper_plugins_.end(); ++i) |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4908 | (*i)->RenderViewInitiatedPaint(); |
| 4909 | } |
| 4910 | |
| 4911 | void RenderView::DidFlushPaint() { |
| 4912 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 4913 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 4914 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 4915 | // won't change out from under us. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4916 | pepper_delegate_.ViewFlushedPaint(); |
| 4917 | |
| 4918 | // Notify any old-style pepper plugins that we painted. This will call into |
| 4919 | // the plugin, and we it may ask to close itself as a result. This will, in |
| 4920 | // turn, modify our set, possibly invalidating the iterator. So we iterate on |
| 4921 | // a copy that won't change out from under us. |
| 4922 | // This should be deleted when we don't support old Pepper anymore. |
| 4923 | std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4924 | for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin(); |
| 4925 | i != plugins.end(); ++i) { |
| 4926 | // The copy above makes sure our iterator is never invalid if some plugins |
| 4927 | // are destroyed. But some plugin may decide to close all of its views in |
| 4928 | // response to a paint in one of them, so we need to make sure each one is |
| 4929 | // still "current" before using it. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4930 | if (current_oldstyle_pepper_plugins_.find(*i) != |
| 4931 | current_oldstyle_pepper_plugins_.end()) |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4932 | (*i)->RenderViewFlushedPaint(); |
| 4933 | } |
| 4934 | |
| 4935 | WebFrame* main_frame = webview()->mainFrame(); |
| 4936 | |
| 4937 | // If we have a provisional frame we are between the start and commit stages |
| 4938 | // of loading and we don't want to save stats. |
| 4939 | if (!main_frame->provisionalDataSource()) { |
| 4940 | WebDataSource* ds = main_frame->dataSource(); |
| 4941 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 4942 | DCHECK(navigation_state); |
| 4943 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4944 | // TODO(jar): The following code should all be inside a method, probably in |
| 4945 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4946 | Time now = Time::Now(); |
| 4947 | if (navigation_state->first_paint_time().is_null()) { |
| 4948 | navigation_state->set_first_paint_time(now); |
| 4949 | } |
| 4950 | if (navigation_state->first_paint_after_load_time().is_null() && |
| 4951 | !navigation_state->finish_load_time().is_null()) { |
| 4952 | navigation_state->set_first_paint_after_load_time(now); |
| 4953 | } |
| 4954 | } |
| 4955 | } |
| 4956 | |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 4957 | bool RenderView::GetBitmapForOptimizedPluginPaint( |
| 4958 | const gfx::Rect& paint_bounds, |
| 4959 | TransportDIB** dib, |
| 4960 | gfx::Rect* location, |
| 4961 | gfx::Rect* clip) { |
| 4962 | return pepper_delegate_.GetBitmapForOptimizedPluginPaint( |
| 4963 | paint_bounds, dib, location, clip); |
| 4964 | } |
| 4965 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4966 | void RenderView::OnClearFocusedNode() { |
| 4967 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4968 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4969 | } |
| 4970 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4971 | void RenderView::OnSetBackground(const SkBitmap& background) { |
| 4972 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4973 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4974 | |
| 4975 | SetBackground(background); |
| 4976 | } |
| 4977 | |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4978 | void RenderView::OnSetActive(bool active) { |
| 4979 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4980 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 4981 | |
| 4982 | #if defined(OS_MACOSX) |
| 4983 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4984 | for (plugin_it = plugin_delegates_.begin(); |
| 4985 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4986 | (*plugin_it)->SetWindowFocus(active); |
| 4987 | } |
| 4988 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4989 | } |
| 4990 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4991 | #if defined(OS_MACOSX) |
| 4992 | void RenderView::OnSetWindowVisibility(bool visible) { |
| 4993 | // Inform plugins that their container has changed visibility. |
| 4994 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4995 | for (plugin_it = plugin_delegates_.begin(); |
| 4996 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4997 | (*plugin_it)->SetContainerVisibility(visible); |
| 4998 | } |
| 4999 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5000 | |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 5001 | void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 5002 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5003 | // Inform plugins that their window's frame has changed. |
| 5004 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5005 | for (plugin_it = plugin_delegates_.begin(); |
| 5006 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5007 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 5008 | } |
| 5009 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5010 | |
| 5011 | void RenderView::OnPluginImeCompositionConfirmed(const string16& text, |
| 5012 | int plugin_id) { |
| 5013 | // WebPluginDelegateProxy is responsible for figuring out if this text |
| 5014 | // applies to it or not, so inform all the delegates. |
| 5015 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5016 | for (plugin_it = plugin_delegates_.begin(); |
| 5017 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5018 | (*plugin_it)->ImeCompositionConfirmed(text, plugin_id); |
| 5019 | } |
| 5020 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 5021 | #endif // OS_MACOSX |
| 5022 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 5023 | void RenderView::SendExtensionRequest( |
| 5024 | const ViewHostMsg_DomMessage_Params& params) { |
| 5025 | Send(new ViewHostMsg_ExtensionRequest(routing_id_, params)); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 5026 | } |
| 5027 | |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 5028 | void RenderView::OnExtensionResponse(int request_id, |
| 5029 | bool success, |
| 5030 | const std::string& response, |
| 5031 | const std::string& error) { |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 5032 | ExtensionProcessBindings::HandleResponse( |
| 5033 | request_id, success, response, error); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 5034 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 5035 | |
[email protected] | a7ab1b78 | 2010-10-21 23:24:16 | [diff] [blame] | 5036 | void RenderView::OnExtensionMessageInvoke(const std::string& extension_id, |
| 5037 | const std::string& function_name, |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 5038 | const ListValue& args, |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 5039 | const GURL& event_url) { |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 5040 | RendererExtensionBindings::Invoke( |
[email protected] | a7ab1b78 | 2010-10-21 23:24:16 | [diff] [blame] | 5041 | extension_id, function_name, args, this, event_url); |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 5042 | } |
| 5043 | |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 5044 | // Dump all load time histograms. |
| 5045 | // |
| 5046 | // The time points we keep are |
| 5047 | // request: time document was requested by user |
| 5048 | // start: time load of document started |
| 5049 | // commit: time load of document started |
| 5050 | // finish_document: main document loaded, before onload() |
| 5051 | // finish_all_loads: after onload() and all resources are loaded |
| 5052 | // first_paint: first paint performed |
| 5053 | // first_paint_after_load: first paint performed after load is finished |
| 5054 | // begin: request if it was user requested, start otherwise |
| 5055 | // |
| 5056 | // It's possible for the request time not to be set, if a client |
| 5057 | // redirect had been done (the user never requested the page) |
| 5058 | // Also, it's possible to load a page without ever laying it out |
| 5059 | // so first_paint and first_paint_after_load can be 0. |
| 5060 | void RenderView::DumpLoadHistograms() const { |
| 5061 | // Configuration for PLT related histograms. |
| 5062 | static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10)); |
| 5063 | static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10)); |
| 5064 | static const size_t kPLTCount(100); |
| 5065 | #define PLT_HISTOGRAM(name, sample) \ |
| 5066 | UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount); |
| 5067 | |
| 5068 | WebFrame* main_frame = webview()->mainFrame(); |
| 5069 | NavigationState* navigation_state = |
| 5070 | NavigationState::FromDataSource(main_frame->dataSource()); |
| 5071 | |
| 5072 | URLPattern::SchemeMasks scheme_type = navigation_state->scheme_type(); |
| 5073 | if (scheme_type == 0) |
| 5074 | return; |
| 5075 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP || |
| 5076 | scheme_type == URLPattern::SCHEME_HTTPS); |
| 5077 | |
| 5078 | // If we've already dumped, do nothing. |
| 5079 | if (navigation_state->load_histograms_recorded()) |
| 5080 | return; |
| 5081 | |
| 5082 | // Collect measurement times. |
| 5083 | Time start = navigation_state->start_load_time(); |
| 5084 | if (start.is_null()) |
| 5085 | return; // Probably very premature abandonment of page. |
| 5086 | Time commit = navigation_state->commit_load_time(); |
| 5087 | if (commit.is_null()) |
| 5088 | return; // Probably very premature abandonment of page. |
| 5089 | |
| 5090 | // We properly handle null values for the next 3 variables. |
| 5091 | Time request = navigation_state->request_time(); |
| 5092 | Time first_paint = navigation_state->first_paint_time(); |
| 5093 | Time first_paint_after_load = navigation_state->first_paint_after_load_time(); |
| 5094 | Time finish_doc = navigation_state->finish_document_load_time(); |
| 5095 | Time finish_all_loads = navigation_state->finish_load_time(); |
| 5096 | |
| 5097 | // Handle case where user hits "stop" or "back" before loading completely. |
| 5098 | bool abandoned_page = finish_doc.is_null(); |
| 5099 | if (abandoned_page) { |
| 5100 | finish_doc = Time::Now(); |
| 5101 | navigation_state->set_finish_document_load_time(finish_doc); |
| 5102 | } |
| 5103 | |
| 5104 | // TODO(jar): We should really discriminate the definition of "abandon" more |
| 5105 | // finely. We should have: |
| 5106 | // abandon_before_document_loaded |
| 5107 | // abandon_before_onload_fired |
| 5108 | |
| 5109 | if (finish_all_loads.is_null()) { |
| 5110 | finish_all_loads = Time::Now(); |
| 5111 | navigation_state->set_finish_load_time(finish_all_loads); |
| 5112 | } else { |
| 5113 | DCHECK(!abandoned_page); // How can the doc have finished but not the page? |
| 5114 | if (!abandoned_page) |
| 5115 | return; // Don't try to record a stat which is broken. |
| 5116 | } |
| 5117 | |
| 5118 | // Note: Client side redirects will have no request time. |
| 5119 | Time begin = request.is_null() ? start : request; |
| 5120 | TimeDelta begin_to_finish_doc = finish_doc - begin; |
| 5121 | TimeDelta begin_to_finish_all_loads = finish_all_loads - begin; |
| 5122 | TimeDelta start_to_finish_all_loads = finish_all_loads - start; |
| 5123 | TimeDelta start_to_commit = commit - start; |
| 5124 | |
| 5125 | NavigationState::LoadType load_type = navigation_state->load_type(); |
| 5126 | |
| 5127 | // The above code sanitized all values of times, in preparation for creating |
| 5128 | // actual histograms. The remainder of this code could be run at destructor |
| 5129 | // time for the navigation_state, since all data is intact. |
| 5130 | |
| 5131 | // Aggregate PLT data across all link types. |
| 5132 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2); |
| 5133 | UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type, |
| 5134 | NavigationState::kLoadTypeMax); |
| 5135 | PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit); |
| 5136 | PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit); |
| 5137 | PLT_HISTOGRAM("PLT.FinishDocToFinish", finish_all_loads - finish_doc); |
| 5138 | PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin); |
| 5139 | PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish_all_loads); |
| 5140 | if (!request.is_null()) { |
| 5141 | PLT_HISTOGRAM("PLT.RequestToStart", start - request); |
| 5142 | PLT_HISTOGRAM("PLT.RequestToFinish", finish_all_loads - request); |
| 5143 | } |
| 5144 | PLT_HISTOGRAM("PLT.CommitToFinish", finish_all_loads - commit); |
| 5145 | if (!first_paint.is_null()) { |
| 5146 | DCHECK(begin <= first_paint); |
| 5147 | PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin); |
| 5148 | DCHECK(commit <= first_paint); |
| 5149 | PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit); |
| 5150 | } |
| 5151 | if (!first_paint_after_load.is_null()) { |
| 5152 | DCHECK(begin <= first_paint_after_load); |
| 5153 | PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad", |
| 5154 | first_paint_after_load - begin); |
| 5155 | DCHECK(commit <= first_paint_after_load); |
| 5156 | PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad", |
| 5157 | first_paint_after_load - commit); |
| 5158 | DCHECK(finish_all_loads <= first_paint_after_load); |
| 5159 | PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad", |
| 5160 | first_paint_after_load - finish_all_loads); |
| 5161 | } |
| 5162 | PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc); |
| 5163 | PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish_all_loads); |
| 5164 | |
| 5165 | // Load type related histograms. |
| 5166 | switch (load_type) { |
| 5167 | case NavigationState::UNDEFINED_LOAD: |
| 5168 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc); |
| 5169 | PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish_all_loads); |
| 5170 | break; |
| 5171 | case NavigationState::RELOAD: |
| 5172 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc); |
| 5173 | PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish_all_loads); |
| 5174 | break; |
| 5175 | case NavigationState::HISTORY_LOAD: |
| 5176 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc); |
| 5177 | PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish_all_loads); |
| 5178 | break; |
| 5179 | case NavigationState::NORMAL_LOAD: |
| 5180 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc); |
| 5181 | PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish_all_loads); |
| 5182 | break; |
| 5183 | case NavigationState::LINK_LOAD_NORMAL: |
| 5184 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal", |
| 5185 | begin_to_finish_doc); |
| 5186 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal", |
| 5187 | begin_to_finish_all_loads); |
| 5188 | break; |
| 5189 | case NavigationState::LINK_LOAD_RELOAD: |
| 5190 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload", |
| 5191 | begin_to_finish_doc); |
| 5192 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload", |
| 5193 | begin_to_finish_all_loads); |
| 5194 | break; |
| 5195 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5196 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk", |
| 5197 | begin_to_finish_doc); |
| 5198 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk", |
| 5199 | begin_to_finish_all_loads); |
| 5200 | break; |
| 5201 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 5202 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly", |
| 5203 | begin_to_finish_doc); |
| 5204 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly", |
| 5205 | begin_to_finish_all_loads); |
| 5206 | break; |
| 5207 | default: |
| 5208 | break; |
| 5209 | } |
| 5210 | |
| 5211 | // Histograms to determine if DNS prefetching has an impact on PLT. |
| 5212 | static bool use_dns_histogram(base::FieldTrialList::Find("DnsImpact") && |
| 5213 | !base::FieldTrialList::Find("DnsImpact")->group_name().empty()); |
| 5214 | if (use_dns_histogram) { |
| 5215 | UMA_HISTOGRAM_ENUMERATION( |
| 5216 | base::FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"), |
| 5217 | abandoned_page ? 1 : 0, 2); |
| 5218 | UMA_HISTOGRAM_ENUMERATION( |
| 5219 | base::FieldTrial::MakeName("PLT.LoadType", "DnsImpact"), |
| 5220 | load_type, NavigationState::kLoadTypeMax); |
| 5221 | switch (load_type) { |
| 5222 | case NavigationState::NORMAL_LOAD: |
| 5223 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5224 | "PLT.BeginToFinish_NormalLoad", "DnsImpact"), |
| 5225 | begin_to_finish_all_loads); |
| 5226 | break; |
| 5227 | case NavigationState::LINK_LOAD_NORMAL: |
| 5228 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5229 | "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"), |
| 5230 | begin_to_finish_all_loads); |
| 5231 | break; |
| 5232 | case NavigationState::LINK_LOAD_RELOAD: |
| 5233 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5234 | "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"), |
| 5235 | begin_to_finish_all_loads); |
| 5236 | break; |
| 5237 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5238 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5239 | "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"), |
| 5240 | begin_to_finish_all_loads); |
| 5241 | break; |
| 5242 | default: |
| 5243 | break; |
| 5244 | } |
| 5245 | } |
| 5246 | |
| 5247 | // Histograms to determine if content prefetching has an impact on PLT. |
| 5248 | static const bool prefetching_fieldtrial = |
| 5249 | base::FieldTrialList::Find("Prefetch") && |
| 5250 | !base::FieldTrialList::Find("Prefetch")->group_name().empty(); |
| 5251 | if (prefetching_fieldtrial) { |
| 5252 | if (navigation_state->was_prefetcher()) { |
| 5253 | PLT_HISTOGRAM( |
| 5254 | base::FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcher", |
| 5255 | "Prefetch"), |
| 5256 | begin_to_finish_doc); |
| 5257 | PLT_HISTOGRAM( |
| 5258 | base::FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcher", |
| 5259 | "Prefetch"), |
| 5260 | begin_to_finish_all_loads); |
| 5261 | } |
| 5262 | if (navigation_state->was_referred_by_prefetcher()) { |
| 5263 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5264 | "PLT.BeginToFinishDoc_ContentPrefetcherReferrer", |
| 5265 | "Prefetch"), |
| 5266 | begin_to_finish_doc); |
| 5267 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5268 | "PLT.BeginToFinish_ContentPrefetcherReferrer", |
| 5269 | "Prefetch"), |
| 5270 | begin_to_finish_all_loads); |
| 5271 | } |
| 5272 | UMA_HISTOGRAM_ENUMERATION( |
| 5273 | base::FieldTrial::MakeName("PLT.Abandoned", "Prefetch"), |
| 5274 | abandoned_page ? 1 : 0, 2); |
| 5275 | PLT_HISTOGRAM(base::FieldTrial::MakeName("PLT.BeginToFinishDoc", |
| 5276 | "Prefetch"), |
| 5277 | begin_to_finish_doc); |
| 5278 | PLT_HISTOGRAM(base::FieldTrial::MakeName("PLT.BeginToFinish", "Prefetch"), |
| 5279 | begin_to_finish_all_loads); |
| 5280 | } |
| 5281 | |
| 5282 | // Histograms to determine if backup connection jobs have an impact on PLT. |
| 5283 | static const bool connect_backup_jobs_fieldtrial( |
| 5284 | base::FieldTrialList::Find("ConnnectBackupJobs") && |
| 5285 | !base::FieldTrialList::Find("ConnnectBackupJobs")->group_name().empty()); |
| 5286 | if (connect_backup_jobs_fieldtrial) { |
| 5287 | UMA_HISTOGRAM_ENUMERATION( |
| 5288 | base::FieldTrial::MakeName("PLT.Abandoned", "ConnnectBackupJobs"), |
| 5289 | abandoned_page ? 1 : 0, 2); |
| 5290 | UMA_HISTOGRAM_ENUMERATION( |
| 5291 | base::FieldTrial::MakeName("PLT.LoadType", "ConnnectBackupJobs"), |
| 5292 | load_type, NavigationState::kLoadTypeMax); |
| 5293 | switch (load_type) { |
| 5294 | case NavigationState::NORMAL_LOAD: |
| 5295 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5296 | "PLT.BeginToFinish_NormalLoad", "ConnnectBackupJobs"), |
| 5297 | begin_to_finish_all_loads); |
| 5298 | break; |
| 5299 | case NavigationState::LINK_LOAD_NORMAL: |
| 5300 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5301 | "PLT.BeginToFinish_LinkLoadNormal", "ConnnectBackupJobs"), |
| 5302 | begin_to_finish_all_loads); |
| 5303 | break; |
| 5304 | case NavigationState::LINK_LOAD_RELOAD: |
| 5305 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5306 | "PLT.BeginToFinish_LinkLoadReload", "ConnnectBackupJobs"), |
| 5307 | begin_to_finish_all_loads); |
| 5308 | break; |
| 5309 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5310 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5311 | "PLT.BeginToFinish_LinkLoadStaleOk", "ConnnectBackupJobs"), |
| 5312 | begin_to_finish_all_loads); |
| 5313 | break; |
| 5314 | default: |
| 5315 | break; |
| 5316 | } |
| 5317 | } |
| 5318 | |
| 5319 | // Histograms to determine if the number of connections has an |
| 5320 | // impact on PLT. |
| 5321 | // TODO(jar): Consider removing the per-link-type versions. We |
| 5322 | // really only need LINK_LOAD_NORMAL and NORMAL_LOAD. |
| 5323 | static bool use_connection_impact_histogram( |
| 5324 | base::FieldTrialList::Find("ConnCountImpact") && |
| 5325 | !base::FieldTrialList::Find("ConnCountImpact")->group_name().empty()); |
| 5326 | if (use_connection_impact_histogram) { |
| 5327 | UMA_HISTOGRAM_ENUMERATION( |
| 5328 | base::FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"), |
| 5329 | abandoned_page ? 1 : 0, 2); |
| 5330 | switch (load_type) { |
| 5331 | case NavigationState::NORMAL_LOAD: |
| 5332 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5333 | "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"), |
| 5334 | begin_to_finish_all_loads); |
| 5335 | break; |
| 5336 | case NavigationState::LINK_LOAD_NORMAL: |
| 5337 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5338 | "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"), |
| 5339 | begin_to_finish_all_loads); |
| 5340 | break; |
| 5341 | case NavigationState::LINK_LOAD_RELOAD: |
| 5342 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5343 | "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"), |
| 5344 | begin_to_finish_all_loads); |
| 5345 | break; |
| 5346 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5347 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5348 | "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"), |
| 5349 | begin_to_finish_all_loads); |
| 5350 | break; |
| 5351 | default: |
| 5352 | break; |
| 5353 | } |
| 5354 | } |
| 5355 | |
| 5356 | // Histograms to determine effect of idle socket timeout. |
| 5357 | static bool use_idle_socket_timeout_histogram( |
| 5358 | base::FieldTrialList::Find("IdleSktToImpact") && |
| 5359 | !base::FieldTrialList::Find("IdleSktToImpact")->group_name().empty()); |
| 5360 | if (use_idle_socket_timeout_histogram) { |
| 5361 | UMA_HISTOGRAM_ENUMERATION( |
| 5362 | base::FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"), |
| 5363 | abandoned_page ? 1 : 0, 2); |
| 5364 | switch (load_type) { |
| 5365 | case NavigationState::NORMAL_LOAD: |
| 5366 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5367 | "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"), |
| 5368 | begin_to_finish_all_loads); |
| 5369 | break; |
| 5370 | case NavigationState::LINK_LOAD_NORMAL: |
| 5371 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5372 | "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"), |
| 5373 | begin_to_finish_all_loads); |
| 5374 | break; |
| 5375 | case NavigationState::LINK_LOAD_RELOAD: |
| 5376 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5377 | "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"), |
| 5378 | begin_to_finish_all_loads); |
| 5379 | break; |
| 5380 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5381 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5382 | "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"), |
| 5383 | begin_to_finish_all_loads); |
| 5384 | break; |
| 5385 | default: |
| 5386 | break; |
| 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | // Histograms to determine effect of number of connections per proxy. |
| 5391 | static bool use_proxy_connection_impact_histogram( |
| 5392 | base::FieldTrialList::Find("ProxyConnectionImpact") && |
| 5393 | !base::FieldTrialList::Find("ProxyConnectionImpact")-> |
| 5394 | group_name().empty()); |
| 5395 | if (use_proxy_connection_impact_histogram) { |
| 5396 | UMA_HISTOGRAM_ENUMERATION( |
| 5397 | base::FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"), |
| 5398 | abandoned_page ? 1 : 0, 2); |
| 5399 | switch (load_type) { |
| 5400 | case NavigationState::NORMAL_LOAD: |
| 5401 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5402 | "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"), |
| 5403 | begin_to_finish_all_loads); |
| 5404 | break; |
| 5405 | case NavigationState::LINK_LOAD_NORMAL: |
| 5406 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5407 | "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"), |
| 5408 | begin_to_finish_all_loads); |
| 5409 | break; |
| 5410 | case NavigationState::LINK_LOAD_RELOAD: |
| 5411 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5412 | "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"), |
| 5413 | begin_to_finish_all_loads); |
| 5414 | break; |
| 5415 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5416 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5417 | "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"), |
| 5418 | begin_to_finish_all_loads); |
| 5419 | break; |
| 5420 | default: |
| 5421 | break; |
| 5422 | } |
| 5423 | } |
| 5424 | |
| 5425 | // Histograms to determine if SDCH has an impact. |
| 5426 | // TODO(jar): Consider removing per-link load types and the enumeration. |
| 5427 | static bool use_sdch_histogram(base::FieldTrialList::Find("GlobalSdch") && |
| 5428 | !base::FieldTrialList::Find("GlobalSdch")->group_name().empty()); |
| 5429 | if (use_sdch_histogram) { |
| 5430 | UMA_HISTOGRAM_ENUMERATION( |
| 5431 | base::FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"), |
| 5432 | load_type, NavigationState::kLoadTypeMax); |
| 5433 | switch (load_type) { |
| 5434 | case NavigationState::NORMAL_LOAD: |
| 5435 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5436 | "PLT.BeginToFinish_NormalLoad", "GlobalSdch"), |
| 5437 | begin_to_finish_all_loads); |
| 5438 | break; |
| 5439 | case NavigationState::LINK_LOAD_NORMAL: |
| 5440 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5441 | "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"), |
| 5442 | begin_to_finish_all_loads); |
| 5443 | break; |
| 5444 | case NavigationState::LINK_LOAD_RELOAD: |
| 5445 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5446 | "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"), |
| 5447 | begin_to_finish_all_loads); |
| 5448 | break; |
| 5449 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5450 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5451 | "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"), |
| 5452 | begin_to_finish_all_loads); |
| 5453 | break; |
| 5454 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 5455 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5456 | "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"), |
| 5457 | begin_to_finish_all_loads); |
| 5458 | break; |
| 5459 | default: |
| 5460 | break; |
| 5461 | } |
| 5462 | } |
| 5463 | |
| 5464 | // Histograms to determine if cache size has an impact on PLT. |
| 5465 | static bool use_cache_histogram1(base::FieldTrialList::Find("CacheSize") && |
| 5466 | !base::FieldTrialList::Find("CacheSize")->group_name().empty()); |
| 5467 | if (use_cache_histogram1 && |
| 5468 | NavigationState::LINK_LOAD_NORMAL <= load_type && |
| 5469 | NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) { |
| 5470 | // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like |
| 5471 | // StartToFinish or BeginToFinish would be better. |
| 5472 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5473 | "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc); |
| 5474 | } |
| 5475 | |
| 5476 | // Histograms to determine if cache throttling has an impact on PLT. |
| 5477 | static bool use_cache_histogram2( |
| 5478 | base::FieldTrialList::Find("CacheThrottle") && |
| 5479 | !base::FieldTrialList::Find("CacheThrottle")->group_name().empty()); |
| 5480 | if (use_cache_histogram2) { |
| 5481 | UMA_HISTOGRAM_ENUMERATION( |
| 5482 | base::FieldTrial::MakeName("PLT.Abandoned", "CacheThrottle"), |
| 5483 | abandoned_page ? 1 : 0, 2); |
| 5484 | switch (load_type) { |
| 5485 | case NavigationState::RELOAD: |
| 5486 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5487 | "PLT.BeginToFinish_Reload", "CacheThrottle"), |
| 5488 | begin_to_finish_all_loads); |
| 5489 | break; |
| 5490 | case NavigationState::HISTORY_LOAD: |
| 5491 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5492 | "PLT.BeginToFinish_HistoryLoad", "CacheThrottle"), |
| 5493 | begin_to_finish_all_loads); |
| 5494 | break; |
| 5495 | case NavigationState::NORMAL_LOAD: |
| 5496 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5497 | "PLT.BeginToFinish_NormalLoad", "CacheThrottle"), |
| 5498 | begin_to_finish_all_loads); |
| 5499 | break; |
| 5500 | case NavigationState::LINK_LOAD_NORMAL: |
| 5501 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5502 | "PLT.BeginToFinish_LinkLoadNormal", "CacheThrottle"), |
| 5503 | begin_to_finish_all_loads); |
| 5504 | break; |
| 5505 | case NavigationState::LINK_LOAD_RELOAD: |
| 5506 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5507 | "PLT.BeginToFinish_LinkLoadReload", "CacheThrottle"), |
| 5508 | begin_to_finish_all_loads); |
| 5509 | break; |
| 5510 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5511 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5512 | "PLT.BeginToFinish_LinkLoadStaleOk", "CacheThrottle"), |
| 5513 | begin_to_finish_all_loads); |
| 5514 | break; |
| 5515 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 5516 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5517 | "PLT.BeginToFinish_LinkLoadCacheOnly", "CacheThrottle"), |
| 5518 | begin_to_finish_all_loads); |
| 5519 | break; |
| 5520 | default: |
| 5521 | break; |
| 5522 | } |
| 5523 | if (NavigationState::RELOAD <= load_type && |
| 5524 | NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) { |
| 5525 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5526 | "PLT.BeginToFinish", "CacheThrottle"), |
| 5527 | begin_to_finish_all_loads); |
| 5528 | } |
| 5529 | } |
| 5530 | |
| 5531 | // For the SPDY field trials, we need to verify that the page loaded was |
| 5532 | // the type we requested: |
| 5533 | // if we asked for a SPDY request, we got a SPDY request |
| 5534 | // if we asked for a HTTP request, we got a HTTP request |
| 5535 | // Due to spdy version mismatches, it is possible that we ask for SPDY |
| 5536 | // but didn't get SPDY. |
| 5537 | static bool use_spdy_histogram(base::FieldTrialList::Find("SpdyImpact") && |
| 5538 | !base::FieldTrialList::Find("SpdyImpact")->group_name().empty()); |
| 5539 | if (use_spdy_histogram) { |
| 5540 | // We take extra effort to only compute these once. |
| 5541 | static bool in_spdy_trial = |
| 5542 | base::FieldTrialList::Find("SpdyImpact")->group_name() == |
| 5543 | "npn_with_spdy"; |
| 5544 | static bool in_http_trial = |
| 5545 | base::FieldTrialList::Find("SpdyImpact")->group_name() == |
| 5546 | "npn_with_http"; |
| 5547 | |
| 5548 | bool spdy_trial_success = navigation_state->was_fetched_via_spdy() ? |
| 5549 | in_spdy_trial : in_http_trial; |
| 5550 | if (spdy_trial_success) { |
| 5551 | // Histograms to determine if SPDY has an impact for https traffic. |
| 5552 | // TODO(mbelshe): After we've seen the difference between BeginToFinish |
| 5553 | // and StartToFinish, consider removing one or the other. |
| 5554 | if (scheme_type == URLPattern::SCHEME_HTTPS && |
| 5555 | navigation_state->was_npn_negotiated()) { |
| 5556 | UMA_HISTOGRAM_ENUMERATION( |
| 5557 | base::FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"), |
| 5558 | abandoned_page ? 1 : 0, 2); |
| 5559 | switch (load_type) { |
| 5560 | case NavigationState::LINK_LOAD_NORMAL: |
| 5561 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5562 | "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5563 | begin_to_finish_all_loads); |
| 5564 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5565 | "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5566 | start_to_finish_all_loads); |
| 5567 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5568 | "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5569 | start_to_commit); |
| 5570 | break; |
| 5571 | case NavigationState::NORMAL_LOAD: |
| 5572 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5573 | "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5574 | begin_to_finish_all_loads); |
| 5575 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5576 | "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5577 | start_to_finish_all_loads); |
| 5578 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5579 | "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5580 | start_to_commit); |
| 5581 | break; |
| 5582 | default: |
| 5583 | break; |
| 5584 | } |
| 5585 | } |
| 5586 | |
| 5587 | // Histograms to compare the impact of alternate protocol over http |
| 5588 | // traffic: when spdy is used vs. when http is used. |
| 5589 | if (scheme_type == URLPattern::SCHEME_HTTP && |
| 5590 | navigation_state->was_alternate_protocol_available()) { |
| 5591 | if (!navigation_state->was_npn_negotiated()) { |
| 5592 | // This means that even there is alternate protocols for npn_http or |
| 5593 | // npn_spdy, they are not taken (due to the base::FieldTrial). |
| 5594 | switch (load_type) { |
| 5595 | case NavigationState::LINK_LOAD_NORMAL: |
| 5596 | PLT_HISTOGRAM( |
| 5597 | "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http", |
| 5598 | start_to_finish_all_loads); |
| 5599 | PLT_HISTOGRAM( |
| 5600 | "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http", |
| 5601 | start_to_commit); |
| 5602 | break; |
| 5603 | case NavigationState::NORMAL_LOAD: |
| 5604 | PLT_HISTOGRAM( |
| 5605 | "PLT.StartToFinish_NormalLoad_AlternateProtocol_http", |
| 5606 | start_to_finish_all_loads); |
| 5607 | PLT_HISTOGRAM( |
| 5608 | "PLT.StartToCommit_NormalLoad_AlternateProtocol_http", |
| 5609 | start_to_commit); |
| 5610 | break; |
| 5611 | default: |
| 5612 | break; |
| 5613 | } |
| 5614 | } else if (navigation_state->was_fetched_via_spdy()) { |
| 5615 | switch (load_type) { |
| 5616 | case NavigationState::LINK_LOAD_NORMAL: |
| 5617 | PLT_HISTOGRAM( |
| 5618 | "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy", |
| 5619 | start_to_finish_all_loads); |
| 5620 | PLT_HISTOGRAM( |
| 5621 | "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy", |
| 5622 | start_to_commit); |
| 5623 | break; |
| 5624 | case NavigationState::NORMAL_LOAD: |
| 5625 | PLT_HISTOGRAM( |
| 5626 | "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy", |
| 5627 | start_to_finish_all_loads); |
| 5628 | PLT_HISTOGRAM( |
| 5629 | "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy", |
| 5630 | start_to_commit); |
| 5631 | break; |
| 5632 | default: |
| 5633 | break; |
| 5634 | } |
| 5635 | } |
| 5636 | } |
| 5637 | } |
| 5638 | } |
| 5639 | |
| 5640 | // Record page load time and abandonment rates for proxy cases. |
| 5641 | if (navigation_state->was_fetched_via_proxy()) { |
| 5642 | if (scheme_type == URLPattern::SCHEME_HTTPS) { |
| 5643 | PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish_all_loads); |
| 5644 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https", |
| 5645 | abandoned_page ? 1 : 0, 2); |
| 5646 | } else { |
| 5647 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP); |
| 5648 | PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish_all_loads); |
| 5649 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http", |
| 5650 | abandoned_page ? 1 : 0, 2); |
| 5651 | } |
| 5652 | } else { |
| 5653 | if (scheme_type == URLPattern::SCHEME_HTTPS) { |
| 5654 | PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https", |
| 5655 | start_to_finish_all_loads); |
| 5656 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https", |
| 5657 | abandoned_page ? 1 : 0, 2); |
| 5658 | } else { |
| 5659 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP); |
| 5660 | PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http", |
| 5661 | start_to_finish_all_loads); |
| 5662 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http", |
| 5663 | abandoned_page ? 1 : 0, 2); |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | // Site isolation metrics. |
| 5668 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess", |
| 5669 | cross_origin_access_count_); |
| 5670 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess", |
| 5671 | same_origin_access_count_); |
| 5672 | |
| 5673 | // TODO(jar): This is the ONLY call in this method that needed more than |
| 5674 | // navigation_state. This should be relocated, or changed, so that this |
| 5675 | // body can be made a method on NavigationStates, and run via its destructor. |
| 5676 | // Log some PLT data to the error log. |
| 5677 | LogNavigationState(navigation_state, main_frame->dataSource()); |
| 5678 | |
| 5679 | navigation_state->set_load_histograms_recorded(true); |
| 5680 | |
| 5681 | // Since there are currently no guarantees that renderer histograms will be |
| 5682 | // sent to the browser, we initiate a PostTask here to be sure that we send |
| 5683 | // the histograms we generated. Without this call, pages that don't have an |
| 5684 | // on-close-handler might generate data that is lost when the renderer is |
| 5685 | // shutdown abruptly (perchance because the user closed the tab). |
| 5686 | // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it |
| 5687 | // should post when the onload is complete, so that it doesn't interfere with |
| 5688 | // the next load. |
| 5689 | if (RenderThread::current()) { |
| 5690 | RenderThread::current()->SendHistograms( |
| 5691 | chrome::kHistogramSynchronizerReservedSequenceNumber); |
| 5692 | } |
| 5693 | } |
| 5694 | |
| 5695 | void RenderView::LogNavigationState(const NavigationState* state, |
| 5696 | const WebDataSource* ds) const { |
| 5697 | // Because this function gets called on every page load, |
| 5698 | // take extra care to optimize it away if logging is turned off. |
| 5699 | if (logging::LOG_INFO < logging::GetMinLogLevel()) |
| 5700 | return; |
| 5701 | |
| 5702 | DCHECK(state); |
| 5703 | DCHECK(ds); |
| 5704 | GURL url(ds->request().url()); |
| 5705 | Time start = state->start_load_time(); |
| 5706 | Time finish = state->finish_load_time(); |
| 5707 | // TODO(mbelshe): should we log more stats? |
| 5708 | VLOG(1) << "PLT: " << (finish - start).InMilliseconds() << "ms " |
| 5709 | << url.spec(); |
| 5710 | } |
| 5711 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5712 | void RenderView::postAccessibilityNotification( |
| 5713 | const WebAccessibilityObject& obj, |
| 5714 | WebAccessibilityNotification notification) { |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 5715 | if (!accessibility_.get() && webview()) { |
| 5716 | // Load complete should be our first notification sent. |
| 5717 | // TODO(ctguil): Investigate if a different notification is a WebCore bug. |
| 5718 | if (notification != WebKit::WebAccessibilityNotificationLoadComplete) |
| 5719 | return; |
| 5720 | |
| 5721 | // Create and initialize our accessibility cache |
| 5722 | accessibility_.reset(WebAccessibilityCache::create()); |
| 5723 | accessibility_->initialize(webview()); |
| 5724 | } |
| 5725 | |
[email protected] | a3fa4f9 | 2010-09-30 22:19:33 | [diff] [blame] | 5726 | if (!accessibility_->isCached(obj)) { |
| 5727 | // The browser doesn't know about objects that are not in the cache. Send a |
| 5728 | // children change for the first accestor that actually is in the cache. |
| 5729 | WebAccessibilityObject parent = obj; |
| 5730 | while (parent.isValid() && !accessibility_->isCached(parent)) |
| 5731 | parent = parent.parentObject(); |
| 5732 | |
| 5733 | DCHECK(parent.isValid() && accessibility_->isCached(parent)); |
| 5734 | if (!parent.isValid()) |
| 5735 | return; |
| 5736 | postAccessibilityNotification( |
| 5737 | parent, WebKit::WebAccessibilityNotificationChildrenChanged); |
| 5738 | |
| 5739 | // The parent's children change takes care of the child's children change. |
| 5740 | if (notification == WebKit::WebAccessibilityNotificationChildrenChanged) |
| 5741 | return; |
| 5742 | } |
| 5743 | |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 5744 | // Add the accessibility object to our cache and ensure it's valid. |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5745 | RendererAccessibilityNotification acc_notification; |
| 5746 | acc_notification.id = accessibility_->addOrGetId(obj); |
| 5747 | if (acc_notification.id < 0) |
[email protected] | a3018be | 2010-03-09 04:28:48 | [diff] [blame] | 5748 | return; |
| 5749 | |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5750 | if (!WebAccessibilityNotificationToViewHostMsg( |
| 5751 | notification, |
| 5752 | &acc_notification.type)) { |
| 5753 | return; |
| 5754 | } |
| 5755 | |
| 5756 | // Discard duplicate accessibility notifications. |
| 5757 | for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) { |
| 5758 | if (pending_accessibility_notifications_[i].id == acc_notification.id && |
| 5759 | pending_accessibility_notifications_[i].type == acc_notification.type) { |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5760 | return; |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5761 | } |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5762 | } |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5763 | pending_accessibility_notifications_.push_back(acc_notification); |
[email protected] | a3018be | 2010-03-09 04:28:48 | [diff] [blame] | 5764 | |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5765 | if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) { |
| 5766 | // When no accessibility notifications are in-flight post a task to send |
| 5767 | // the notifications to the browser. We use PostTask so that we can queue |
| 5768 | // up additional notifications. |
| 5769 | MessageLoop::current()->PostTask( |
| 5770 | FROM_HERE, |
| 5771 | accessibility_method_factory_.NewRunnableMethod( |
| 5772 | &RenderView::SendPendingAccessibilityNotifications)); |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 5773 | } |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 5774 | } |
| 5775 | |
[email protected] | 212a49d | 2010-10-25 18:23:47 | [diff] [blame] | 5776 | void RenderView::Print(WebFrame* frame, |
| 5777 | bool script_initiated, |
| 5778 | bool is_preview) { |
[email protected] | 0fda727 | 2009-06-26 15:49:33 | [diff] [blame] | 5779 | DCHECK(frame); |
| 5780 | if (print_helper_.get() == NULL) { |
| 5781 | print_helper_.reset(new PrintWebViewHelper(this)); |
| 5782 | } |
[email protected] | 212a49d | 2010-10-25 18:23:47 | [diff] [blame] | 5783 | print_helper_->Print(frame, script_initiated, is_preview); |
[email protected] | 0fda727 | 2009-06-26 15:49:33 | [diff] [blame] | 5784 | } |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5785 | |
| 5786 | void RenderView::OnSetEditCommandsForNextKeyEvent( |
| 5787 | const EditCommands& edit_commands) { |
| 5788 | edit_commands_ = edit_commands; |
| 5789 | } |
| 5790 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5791 | void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5792 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5793 | if (!main_frame) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5794 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, |
| 5795 | false)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5796 | return; |
| 5797 | } |
| 5798 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5799 | WebDataSource* ds = main_frame->dataSource(); |
| 5800 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 5801 | if (!navigation_state->user_script_idle_scheduler()->has_run()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5802 | pending_code_execution_queue_.push( |
| 5803 | linked_ptr<ViewMsg_ExecuteCode_Params>( |
| 5804 | new ViewMsg_ExecuteCode_Params(params))); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5805 | return; |
| 5806 | } |
| 5807 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5808 | ExecuteCodeImpl(main_frame, params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | void RenderView::ExecuteCodeImpl(WebFrame* frame, |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5812 | const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5813 | std::vector<WebFrame*> frame_vector; |
| 5814 | frame_vector.push_back(frame); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5815 | if (params.all_frames) |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5816 | GetAllChildFrames(frame, &frame_vector); |
| 5817 | |
| 5818 | for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin(); |
| 5819 | frame_it != frame_vector.end(); ++frame_it) { |
| 5820 | WebFrame* frame = *frame_it; |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5821 | if (params.is_javascript) { |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 5822 | ExtensionRendererInfo* extension = |
| 5823 | ExtensionRendererInfo::GetByID(params.extension_id); |
| 5824 | |
[email protected] | 1f6228c | 2010-10-21 03:19:44 | [diff] [blame] | 5825 | // Since extension info is sent separately from user script info, they can |
| 5826 | // be out of sync. We just ignore this situation. |
| 5827 | if (!extension) |
| 5828 | continue; |
| 5829 | |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 5830 | const std::vector<URLPattern> host_permissions = |
| 5831 | extension->host_permissions(); |
| 5832 | if (!Extension::CanExecuteScriptOnPage( |
| 5833 | frame->url(), |
| 5834 | extension->allowed_to_execute_script_everywhere(), |
| 5835 | &host_permissions, |
| 5836 | NULL, |
| 5837 | NULL)) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5838 | continue; |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 5839 | } |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5840 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5841 | std::vector<WebScriptSource> sources; |
| 5842 | sources.push_back( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5843 | WebScriptSource(WebString::fromUTF8(params.code))); |
| 5844 | UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5845 | frame->executeScriptInIsolatedWorld( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5846 | UserScriptSlave::GetIsolatedWorldId(params.extension_id), |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5847 | &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 5848 | } else { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5849 | frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5850 | } |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5851 | } |
| 5852 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5853 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5854 | } |
| 5855 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5856 | void RenderView::Close() { |
| 5857 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5858 | WebView* doomed = webview(); |
| 5859 | RenderWidget::Close(); |
| 5860 | Singleton<ViewMap>::get()->erase(doomed); |
| 5861 | } |
| 5862 | |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5863 | void RenderView::DidHandleKeyEvent() { |
| 5864 | edit_commands_.clear(); |
| 5865 | } |
| 5866 | |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5867 | void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 5868 | page_click_tracker_->DidHandleMouseEvent(event); |
| 5869 | } |
| 5870 | |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5871 | #if defined(OS_MACOSX) |
| 5872 | void RenderView::OnWasHidden() { |
| 5873 | RenderWidget::OnWasHidden(); |
| 5874 | |
| 5875 | // Inform plugins that their container is no longer visible. |
| 5876 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5877 | for (plugin_it = plugin_delegates_.begin(); |
| 5878 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5879 | (*plugin_it)->SetContainerVisibility(false); |
| 5880 | } |
| 5881 | } |
| 5882 | |
| 5883 | void RenderView::OnWasRestored(bool needs_repainting) { |
| 5884 | RenderWidget::OnWasRestored(needs_repainting); |
| 5885 | |
| 5886 | // Inform plugins that their container is now visible. |
| 5887 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5888 | for (plugin_it = plugin_delegates_.begin(); |
| 5889 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5890 | (*plugin_it)->SetContainerVisibility(true); |
| 5891 | } |
| 5892 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5893 | #endif // OS_MACOSX |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5894 | |
| 5895 | void RenderView::OnSetFocus(bool enable) { |
| 5896 | RenderWidget::OnSetFocus(enable); |
| 5897 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5898 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5899 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5900 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5901 | for (plugin_it = plugin_delegates_.begin(); |
| 5902 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5903 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5904 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5905 | // activation state to change just like a call to setIsActive. |
| 5906 | if (enable) |
| 5907 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5908 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5909 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5910 | } |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5911 | |
| 5912 | // Notify all Pepper plugins. |
| 5913 | pepper_delegate_.OnSetFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5914 | } |
| 5915 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5916 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 5917 | void RenderView::EnsureDocumentTag() { |
| 5918 | // TODO(darin): There's actually no reason for this to be here. We should |
| 5919 | // have the browser side manage the document tag. |
| 5920 | #if defined(OS_MACOSX) |
| 5921 | if (!has_document_tag_) { |
| 5922 | // Make the call to get the tag. |
| 5923 | Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); |
| 5924 | has_document_tag_ = true; |
| 5925 | } |
| 5926 | #endif |
| 5927 | } |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 5928 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5929 | #if defined(OS_MACOSX) |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5930 | void RenderView::SetPluginImeEnabled(bool enabled, int plugin_id) { |
| 5931 | IPC::Message* msg = new ViewHostMsg_SetPluginImeEnabled(routing_id(), |
| 5932 | enabled, plugin_id); |
| 5933 | // This message can be sent during event-handling, and needs to be delivered |
| 5934 | // within that context. |
| 5935 | msg->set_unblock(true); |
| 5936 | Send(msg); |
| 5937 | } |
| 5938 | |
[email protected] | ea04a4e1 | 2010-04-15 00:58:03 | [diff] [blame] | 5939 | gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5940 | bool opaque, bool root) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5941 | gfx::PluginWindowHandle window = NULL; |
| 5942 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5943 | routing_id(), opaque, root, &window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5944 | if (window) { |
| 5945 | fake_plugin_window_handles_.insert(window); |
| 5946 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5947 | return window; |
| 5948 | } |
| 5949 | |
| 5950 | void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) { |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5951 | if (window && fake_plugin_window_handles_.find(window) != |
| 5952 | fake_plugin_window_handles_.end()) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5953 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5954 | fake_plugin_window_handles_.erase(window); |
| 5955 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5956 | } |
| 5957 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5958 | void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window, |
| 5959 | int32 width, |
| 5960 | int32 height, |
| 5961 | uint64 io_surface_identifier) { |
| 5962 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5963 | routing_id(), window, width, height, io_surface_identifier)); |
| 5964 | } |
| 5965 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5966 | void RenderView::AcceleratedSurfaceSetTransportDIB( |
| 5967 | gfx::PluginWindowHandle window, |
| 5968 | int32 width, |
| 5969 | int32 height, |
| 5970 | TransportDIB::Handle transport_dib) { |
| 5971 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5972 | routing_id(), window, width, height, transport_dib)); |
| 5973 | } |
| 5974 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5975 | TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB( |
| 5976 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5977 | TransportDIB::Handle dib_handle; |
| 5978 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 5979 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5980 | return dib_handle; |
| 5981 | // Return an invalid handle if Send() fails. |
| 5982 | return TransportDIB::DefaultHandleValue(); |
| 5983 | } |
| 5984 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5985 | void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5986 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 5987 | } |
| 5988 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5989 | void RenderView::AcceleratedSurfaceBuffersSwapped( |
[email protected] | f35d667 | 2010-10-28 21:39:14 | [diff] [blame^] | 5990 | gfx::PluginWindowHandle window, uint64 surface_id) { |
| 5991 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped( |
| 5992 | routing_id(), window, surface_id)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5993 | } |
| 5994 | #endif |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5995 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5996 | bool RenderView::ScheduleFileChooser( |
| 5997 | const ViewHostMsg_RunFileChooser_Params& params, |
| 5998 | WebFileChooserCompletion* completion) { |
| 5999 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 6000 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 6001 | // This sanity check prevents too many file choose requests from getting |
| 6002 | // queued which could DoS the user. Getting these is most likely a |
| 6003 | // programming error (there are many ways to DoS the user so it's not |
| 6004 | // considered a "real" security check), either in JS requesting many file |
| 6005 | // choosers to pop up, or in a plugin. |
| 6006 | // |
| 6007 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 6008 | // a file picker, which will address this issue in a better way. |
| 6009 | return false; |
| 6010 | } |
| 6011 | |
| 6012 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 6013 | new PendingFileChooser(params, completion))); |
| 6014 | if (file_chooser_completions_.size() == 1) { |
| 6015 | // Actually show the browse dialog when this is the first request. |
| 6016 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 6017 | } |
| 6018 | return true; |
| 6019 | } |
| 6020 | |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 6021 | void RenderView::OnPageTranslated() { |
| 6022 | WebFrame* frame = webview()->mainFrame(); |
| 6023 | if (!frame) |
| 6024 | return; |
| 6025 | |
| 6026 | // The page is translated, so try to extract the form data again. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 6027 | autofill_helper_->FrameContentsAvailable(frame); |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 6028 | } |
| 6029 | |
[email protected] | 8a5f700 | 2010-03-31 13:47:35 | [diff] [blame] | 6030 | WebKit::WebGeolocationService* RenderView::geolocationService() { |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 6031 | if (!geolocation_dispatcher_.get()) |
[email protected] | ecad776 | 2010-10-22 13:58:48 | [diff] [blame] | 6032 | geolocation_dispatcher_.reset(new GeolocationDispatcherOld(this)); |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 6033 | return geolocation_dispatcher_.get(); |
| 6034 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6035 | |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 6036 | WebKit::WebSpeechInputController* RenderView::speechInputController( |
| 6037 | WebKit::WebSpeechInputListener* listener) { |
| 6038 | if (!speech_input_dispatcher_.get()) |
| 6039 | speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener)); |
| 6040 | return speech_input_dispatcher_.get(); |
| 6041 | } |
| 6042 | |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 6043 | WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() { |
| 6044 | if (!device_orientation_dispatcher_.get()) |
| 6045 | device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this)); |
| 6046 | return device_orientation_dispatcher_.get(); |
| 6047 | } |
| 6048 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6049 | void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) { |
| 6050 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 6051 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 6052 | // different). |
| 6053 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 6054 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6055 | int minimum_percent = static_cast<int>( |
| 6056 | WebView::zoomLevelToZoomFactor(minimum_level) * 100); |
| 6057 | int maximum_percent = static_cast<int>( |
| 6058 | WebView::zoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6059 | |
| 6060 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 6061 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 6062 | } |
| 6063 | |
| 6064 | void RenderView::zoomLevelChanged() { |
| 6065 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 6066 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6067 | // Tell the browser which url got zoomed so it can update the menu and the |
| 6068 | // saved values if necessary |
| 6069 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | 1cc58eb6 | 2010-10-01 22:38:41 | [diff] [blame] | 6070 | routing_id_, webview()->zoomLevel(), remember, |
| 6071 | GURL(webview()->mainFrame()->url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 6072 | } |
| 6073 | |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 6074 | bool RenderView::IsNonLocalTopLevelNavigation( |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6075 | const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 6076 | // Must be a top level frame. |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6077 | if (frame->parent() != NULL) |
| 6078 | return false; |
| 6079 | |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 6080 | // Navigations initiated within Webkit are not sent out to the external host |
| 6081 | // in the following cases. |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6082 | // 1. The url scheme is not http/https |
| 6083 | // 2. There is no opener and this is not the first url being opened by this |
| 6084 | // RenderView. |
| 6085 | // 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] | 6086 | // opener relationship is maintained. |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 6087 | // 4. Reloads/form submits/back forward navigations |
| 6088 | if (!url.SchemeIs("http") && !url.SchemeIs("https")) |
| 6089 | return false; |
| 6090 | |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6091 | // Not interested in reloads. |
| 6092 | if (type != WebKit::WebNavigationTypeReload && |
[email protected] | 070c49c | 2010-07-13 22:22:01 | [diff] [blame] | 6093 | type != WebKit::WebNavigationTypeFormSubmitted && |
| 6094 | type != WebKit::WebNavigationTypeBackForward) { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6095 | // The opener relationship between the new window and the parent allows the |
| 6096 | // new window to script the parent and vice versa. This is not allowed if |
| 6097 | // the origins of the two domains are different. This can be treated as a |
| 6098 | // top level navigation and routed back to the host. |
| 6099 | WebKit::WebFrame* opener = frame->opener(); |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6100 | if (!opener) { |
[email protected] | fe9eb4f9 | 2010-08-27 23:16:47 | [diff] [blame] | 6101 | // Force link click navigations to always be routed to the host as they |
| 6102 | // may update session state on the server. |
| 6103 | if (type == WebKit::WebNavigationTypeLinkClicked) |
| 6104 | return true; |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6105 | // If this is the first page being loaded by this RenderView instance then |
| 6106 | // it should stay here. |
| 6107 | if (page_id_ == -1) { |
| 6108 | return false; |
| 6109 | } else { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6110 | return true; |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6111 | } |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6112 | } |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6113 | |
| 6114 | if (url.GetOrigin() != GURL(opener->url()).GetOrigin()) |
| 6115 | return true; |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6116 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6117 | return false; |
| 6118 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 6119 | |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 6120 | void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code, |
| 6121 | IPC::PlatformFileForTransit file_for_transit, |
| 6122 | int message_id) { |
| 6123 | pepper_delegate_.OnAsyncFileOpened( |
| 6124 | error_code, |
| 6125 | IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
| 6126 | message_id); |
| 6127 | } |
[email protected] | caf706f | 2010-10-26 17:54:08 | [diff] [blame] | 6128 | |
| 6129 | #if defined(OS_MACOSX) |
| 6130 | void RenderView::OnSelectPopupMenuItem(int selected_index) { |
| 6131 | external_popup_menu_->DidSelectItem(selected_index); |
| 6132 | external_popup_menu_.reset(); |
| 6133 | } |
| 6134 | #endif |