[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] | ecad776 | 2010-10-22 13:58:48 | [diff] [blame] | 63 | #include "chrome/renderer/geolocation_dispatcher_old.h" |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 64 | #include "chrome/renderer/ggl/ggl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 65 | #include "chrome/renderer/localized_error.h" |
[email protected] | 6f56d48 | 2009-02-20 05:02:56 | [diff] [blame] | 66 | #include "chrome/renderer/media/audio_renderer_impl.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 67 | #include "chrome/renderer/media/ipc_video_decoder.h" |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 68 | #include "chrome/renderer/media/ipc_video_renderer.h" |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 69 | #include "chrome/renderer/navigation_state.h" |
[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 70 | #include "chrome/renderer/notification_provider.h" |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 71 | #include "chrome/renderer/page_click_tracker.h" |
| 72 | #include "chrome/renderer/password_autocomplete_manager.h" |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 73 | #include "chrome/renderer/plugin_channel_host.h" |
[email protected] | d81c1e5 | 2009-06-03 22:09:50 | [diff] [blame] | 74 | #include "chrome/renderer/print_web_view_helper.h" |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 75 | #include "chrome/renderer/render_process.h" |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 76 | #include "chrome/renderer/render_thread.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 77 | #include "chrome/renderer/render_view_visitor.h" |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 78 | #include "chrome/renderer/render_widget_fullscreen.h" |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 79 | #include "chrome/renderer/render_widget_fullscreen_pepper.h" |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 80 | #include "chrome/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 81 | #include "chrome/renderer/renderer_webstoragenamespace_impl.h" |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 82 | #include "chrome/renderer/speech_input_dispatcher.h" |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 83 | #include "chrome/renderer/spellchecker/spellcheck.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 84 | #include "chrome/renderer/user_script_slave.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 85 | #include "chrome/renderer/visitedlink_slave.h" |
[email protected] | d439ba07 | 2009-10-17 22:32:29 | [diff] [blame] | 86 | #include "chrome/renderer/webplugin_delegate_pepper.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 87 | #include "chrome/renderer/webplugin_delegate_proxy.h" |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 88 | #include "chrome/renderer/websharedworker_proxy.h" |
[email protected] | eb47a13 | 2009-03-04 00:39:56 | [diff] [blame] | 89 | #include "chrome/renderer/webworker_proxy.h" |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 90 | #include "gfx/color_utils.h" |
| 91 | #include "gfx/favicon_size.h" |
[email protected] | 5c7293a | 2010-03-17 06:40:57 | [diff] [blame] | 92 | #include "gfx/native_widget_types.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 93 | #include "gfx/point.h" |
| 94 | #include "gfx/rect.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 95 | #include "grit/generated_resources.h" |
| 96 | #include "grit/renderer_resources.h" |
[email protected] | ee68378a | 2010-08-10 01:05:41 | [diff] [blame] | 97 | #include "media/base/media_switches.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 98 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 99 | #include "net/base/escape.h" |
| 100 | #include "net/base/net_errors.h" |
[email protected] | c399a8a | 2008-11-22 19:38:00 | [diff] [blame] | 101 | #include "skia/ext/bitmap_platform_device.h" |
[email protected] | 83c9e655 | 2008-12-03 16:22:10 | [diff] [blame] | 102 | #include "skia/ext/image_operations.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 103 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 104 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 105 | #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 106 | #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
| 107 | #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 108 | #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 109 | #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 110 | #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 111 | #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" |
| 112 | #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 113 | #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 114 | #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 115 | #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
| 116 | #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 117 | #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 118 | #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 119 | #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 120 | #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 121 | #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 122 | #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 123 | #include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 124 | #include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 125 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 126 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 127 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 128 | #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
| 129 | #include "third_party/WebKit/WebKit/chromium/public/WebRange.h" |
| 130 | #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 131 | #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" |
| 132 | #include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h" |
| 133 | #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 134 | #include "third_party/WebKit/WebKit/chromium/public/WebSettings.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 135 | #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 136 | #include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 137 | #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 138 | #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 139 | #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" |
| 140 | #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 141 | #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
| 142 | #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 143 | #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 144 | #include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h" |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 145 | #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h" |
| 146 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 147 | #include "v8/include/v8.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 148 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 149 | #include "webkit/glue/context_menu.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 150 | #include "webkit/glue/dom_operations.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 151 | #include "webkit/glue/form_data.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 152 | #include "webkit/glue/form_field.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 153 | #include "webkit/glue/glue_serialize.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 154 | #include "webkit/glue/image_decoder.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 155 | #include "webkit/glue/image_resource_fetcher.h" |
[email protected] | 8e296bbd | 2009-07-22 21:37:17 | [diff] [blame] | 156 | #include "webkit/glue/media/buffered_data_source.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 157 | #include "webkit/glue/media/simple_data_source.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 158 | #include "webkit/glue/media/video_renderer_impl.h" |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 159 | #include "webkit/glue/password_form_dom_manager.h" |
[email protected] | 0d64bb7 | 2010-07-07 05:36:38 | [diff] [blame] | 160 | #include "webkit/glue/plugins/default_plugin_shared.h" |
[email protected] | b4f68dea | 2010-05-13 06:03:17 | [diff] [blame] | 161 | #include "webkit/glue/plugins/pepper_webplugin_impl.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 162 | #include "webkit/glue/plugins/plugin_list.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 163 | #include "webkit/glue/plugins/webplugin_delegate.h" |
[email protected] | 8a3b796 | 2009-09-04 05:53:23 | [diff] [blame] | 164 | #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 165 | #include "webkit/glue/plugins/webplugin_impl.h" |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 166 | #include "webkit/glue/plugins/webview_plugin.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 167 | #include "webkit/glue/site_isolation_metrics.h" |
[email protected] | 7a4de7a6 | 2010-08-17 18:38:24 | [diff] [blame] | 168 | #include "webkit/glue/webaccessibility.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 169 | #include "webkit/glue/webdropdata.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 170 | #include "webkit/glue/webkit_glue.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 171 | #include "webkit/glue/webmediaplayer_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 172 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 173 | #if defined(OS_WIN) |
| 174 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 175 | // * theming |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 176 | #include "gfx/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 177 | #elif defined(USE_X11) |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 178 | #include "gfx/native_theme_linux.h" |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 179 | #include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 180 | #elif defined(OS_MACOSX) |
| 181 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 182 | #endif |
| 183 | |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 184 | using WebKit::WebAccessibilityCache; |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 185 | using WebKit::WebAccessibilityNotification; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 186 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 187 | using WebKit::WebApplicationCacheHost; |
| 188 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 189 | using WebKit::WebCString; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 190 | using WebKit::WebColor; |
| 191 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 192 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 193 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 194 | using WebKit::WebCookieJar; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 195 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 196 | using WebKit::WebDataSource; |
[email protected] | 2661b33 | 2009-11-03 18:42:29 | [diff] [blame] | 197 | using WebKit::WebDevToolsAgent; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 198 | using WebKit::WebDocument; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 199 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 200 | using WebKit::WebDragOperation; |
| 201 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 202 | using WebKit::WebEditingAction; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 203 | using WebKit::WebFileChooserCompletion; |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 204 | using WebKit::WebFileSystem; |
| 205 | using WebKit::WebFileSystemCallbacks; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 206 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 207 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 208 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 209 | using WebKit::WebFrame; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 210 | using WebKit::WebHistoryItem; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 211 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 212 | using WebKit::WebInputElement; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 213 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 214 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 215 | using WebKit::WebMediaPlayerClient; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 216 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 217 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 218 | using WebKit::WebNode; |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 219 | using WebKit::WebPageSerializer; |
| 220 | using WebKit::WebPageSerializerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 221 | using WebKit::WebPlugin; |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 222 | using WebKit::WebPluginContainer; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 223 | using WebKit::WebPluginDocument; |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 224 | using WebKit::WebPluginParams; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 225 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 226 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 227 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 228 | using WebKit::WebRect; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 229 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 230 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 231 | using WebKit::WebSecurityOrigin; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 232 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 233 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 234 | using WebKit::WebSize; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 235 | using WebKit::WebStorageNamespace; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 236 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 237 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 238 | using WebKit::WebTextDirection; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 239 | using WebKit::WebURL; |
| 240 | using WebKit::WebURLError; |
| 241 | using WebKit::WebURLRequest; |
| 242 | using WebKit::WebURLResponse; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 243 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 244 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 245 | using WebKit::WebWidget; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 246 | using WebKit::WebWindowFeatures; |
[email protected] | 27ba853 | 2009-04-24 20:22:43 | [diff] [blame] | 247 | using WebKit::WebWorker; |
| 248 | using WebKit::WebWorkerClient; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 249 | using appcache::WebApplicationCacheHostImpl; |
| 250 | using base::Time; |
| 251 | using base::TimeDelta; |
| 252 | using webkit_glue::AltErrorPageResourceFetcher; |
| 253 | using webkit_glue::FormData; |
| 254 | using webkit_glue::FormField; |
| 255 | using webkit_glue::ImageResourceFetcher; |
| 256 | using webkit_glue::PasswordForm; |
| 257 | using webkit_glue::PasswordFormDomManager; |
| 258 | using webkit_glue::SiteIsolationMetrics; |
| 259 | using webkit_glue::WebAccessibility; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 260 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 261 | //----------------------------------------------------------------------------- |
| 262 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 263 | typedef std::map<WebKit::WebView*, RenderView*> ViewMap; |
| 264 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | // define to write the time necessary for thumbnail/DOM text retrieval, |
| 266 | // respectively, into the system debug log |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 267 | // #define TIME_TEXT_RETRIEVAL |
| 268 | |
| 269 | // maximum number of characters in the document to index, any text beyond this |
| 270 | // point will be clipped |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 271 | static const size_t kMaxIndexChars = 65535; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 272 | |
| 273 | // Size of the thumbnails that we'll generate |
[email protected] | 8b4f489 | 2009-09-04 21:52:37 | [diff] [blame] | 274 | static const int kThumbnailWidth = 212; |
| 275 | static const int kThumbnailHeight = 132; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 276 | |
| 277 | // Delay in milliseconds that we'll wait before capturing the page contents |
| 278 | // and thumbnail. |
| 279 | static const int kDelayForCaptureMs = 500; |
| 280 | |
| 281 | // Typically, we capture the page data once the page is loaded. |
| 282 | // Sometimes, the page never finishes to load, preventing the page capture |
| 283 | // To workaround this problem, we always perform a capture after the following |
| 284 | // delay. |
| 285 | static const int kDelayForForcedCaptureMs = 6000; |
| 286 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 287 | // Time, in seconds, we delay before sending content state changes (such as form |
| 288 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 289 | // spamming the browser. |
| 290 | // To avoid having tab/session restore require sending a message to get the |
| 291 | // current content state during tab closing we use a shorter timeout for the |
| 292 | // foreground renderer. This means there is a small window of time from which |
| 293 | // content state is modified and not sent to session restore, but this is |
| 294 | // better than having to wake up all renderers during shutdown. |
| 295 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 296 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 297 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 298 | // The maximum number of popups that can be spawned from one page. |
| 299 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 300 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 301 | static const char kUnreachableWebDataURL[] = "chrome://chromewebdata/"; |
| 302 | static const char kBackForwardNavigationScheme[] = "history"; |
[email protected] | 50b691c | 2008-10-31 19:08:35 | [diff] [blame] | 303 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 304 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 305 | WebVector<WebURL> urls; |
| 306 | ds->redirectChain(urls); |
| 307 | result->reserve(urls.size()); |
| 308 | for (size_t i = 0; i < urls.size(); ++i) |
| 309 | result->push_back(urls[i]); |
| 310 | } |
| 311 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 312 | static bool PaintViewIntoCanvas(WebView* view, |
| 313 | skia::PlatformCanvas& canvas) { |
| 314 | view->layout(); |
| 315 | const WebSize& size = view->size(); |
| 316 | |
| 317 | if (!canvas.initialize(size.width, size.height, true)) |
| 318 | return false; |
| 319 | |
| 320 | view->paint(webkit_glue::ToWebCanvas(&canvas), |
| 321 | WebRect(0, 0, size.width, size.height)); |
| 322 | // TODO: Add a way to snapshot the whole page, not just the currently |
| 323 | // visible part. |
| 324 | |
| 325 | return true; |
| 326 | } |
| 327 | |
| 328 | // Calculates how "boring" a thumbnail is. The boring score is the |
| 329 | // 0,1 ranged percentage of pixels that are the most common |
| 330 | // luma. Higher boring scores indicate that a higher percentage of a |
| 331 | // bitmap are all the same brightness. |
| 332 | static double CalculateBoringScore(SkBitmap* bitmap) { |
| 333 | int histogram[256] = {0}; |
| 334 | color_utils::BuildLumaHistogram(bitmap, histogram); |
| 335 | |
| 336 | int color_count = *std::max_element(histogram, histogram + 256); |
| 337 | int pixel_count = bitmap->width() * bitmap->height(); |
| 338 | return static_cast<double>(color_count) / pixel_count; |
| 339 | } |
| 340 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 341 | // True if |frame| contains content that is white-listed for content settings. |
| 342 | static bool IsWhitelistedForContentSettings(WebFrame* frame) { |
| 343 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 344 | if (origin.isEmpty()) |
| 345 | return false; // Uninitialized document? |
| 346 | |
| 347 | if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
| 348 | return true; // Browser UI elements should still work. |
| 349 | |
| 350 | // If the scheme is ftp: or file:, an empty file name indicates a directory |
| 351 | // listing, which requires JavaScript to function properly. |
| 352 | GURL frame_url = frame->url(); |
| 353 | const char* kDirProtocols[] = { "ftp", "file" }; |
| 354 | for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { |
| 355 | if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { |
| 356 | return frame_url.SchemeIs(kDirProtocols[i]) && |
| 357 | frame_url.ExtractFileName().empty(); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return false; |
| 362 | } |
| 363 | |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 364 | // Returns true if the frame is navigating to an URL either into or out of an |
| 365 | // extension app's extent. |
| 366 | static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) { |
| 367 | if (!RenderThread::current()) |
| 368 | return false; |
| 369 | |
| 370 | // If the URL is still empty, this is a window.open navigation. Check the |
| 371 | // opener's URL. |
| 372 | GURL old_url(frame->url()); |
| 373 | if (old_url.is_empty() && frame->opener()) |
| 374 | old_url = frame->opener()->url(); |
| 375 | |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 376 | return !ExtensionRendererInfo::InSameExtent(old_url, new_url); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 377 | } |
| 378 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 379 | // Returns the ISO 639_1 language code of the specified |text|, or 'unknown' |
| 380 | // if it failed. |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 381 | static std::string DetermineTextLanguage(const string16& text) { |
[email protected] | 655f97c3 | 2010-07-22 21:24:17 | [diff] [blame] | 382 | std::string language = chrome::kUnknownLanguageCode; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 383 | int num_languages = 0; |
[email protected] | a9558688 | 2010-08-02 18:40:08 | [diff] [blame] | 384 | int text_bytes = 0; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 385 | bool is_reliable = false; |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 386 | Language cld_language = |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 387 | DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable, |
[email protected] | a9558688 | 2010-08-02 18:40:08 | [diff] [blame] | 388 | &num_languages, NULL, &text_bytes); |
| 389 | // We don't trust the result if the CLD reports that the detection is not |
| 390 | // reliable, or if the actual text used to detect the language was less than |
| 391 | // 100 bytes (short texts can often lead to wrong results). |
| 392 | if (is_reliable && text_bytes >= 100 && cld_language != NUM_LANGUAGES && |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 393 | cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) { |
| 394 | // We should not use LanguageCode_ISO_639_1 because it does not cover all |
| 395 | // the languages CLD can detect. As a result, it'll return the invalid |
| 396 | // language code for tradtional Chinese among others. |
| 397 | // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and |
| 398 | // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN |
| 399 | // for Simplified Chinese. |
| 400 | language = LanguageCodeWithDialects(cld_language); |
| 401 | } |
| 402 | return language; |
| 403 | } |
| 404 | |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 405 | static bool WebAccessibilityNotificationToViewHostMsg( |
| 406 | WebAccessibilityNotification notification, |
| 407 | ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) { |
| 408 | switch (notification) { |
| 409 | case WebKit::WebAccessibilityNotificationCheckedStateChanged: |
| 410 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 411 | NOTIFICATION_TYPE_CHECK_STATE_CHANGED; |
| 412 | break; |
| 413 | case WebKit::WebAccessibilityNotificationChildrenChanged: |
| 414 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 415 | NOTIFICATION_TYPE_CHILDREN_CHANGED; |
| 416 | break; |
| 417 | case WebKit::WebAccessibilityNotificationFocusedUIElementChanged: |
| 418 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 419 | NOTIFICATION_TYPE_FOCUS_CHANGED; |
| 420 | break; |
| 421 | case WebKit::WebAccessibilityNotificationLoadComplete: |
| 422 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 423 | NOTIFICATION_TYPE_LOAD_COMPLETE; |
| 424 | break; |
| 425 | case WebKit::WebAccessibilityNotificationValueChanged: |
| 426 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 427 | NOTIFICATION_TYPE_VALUE_CHANGED; |
| 428 | break; |
| 429 | case WebKit::WebAccessibilityNotificationSelectedTextChanged: |
| 430 | *type = ViewHostMsg_AccessibilityNotification_Params:: |
| 431 | NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED; |
| 432 | break; |
| 433 | default: |
| 434 | // TODO(ctguil): Support additional webkit notifications. |
| 435 | return false; |
| 436 | } |
| 437 | return true; |
| 438 | } |
| 439 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 440 | /////////////////////////////////////////////////////////////////////////////// |
| 441 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 442 | int32 RenderView::next_page_id_ = 1; |
| 443 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 444 | struct RenderView::PendingFileChooser { |
| 445 | PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, |
| 446 | WebFileChooserCompletion* c) |
| 447 | : params(p), |
| 448 | completion(c) { |
| 449 | } |
| 450 | ViewHostMsg_RunFileChooser_Params params; |
| 451 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 452 | }; |
| 453 | |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 454 | RenderView::RenderView(RenderThreadBase* render_thread, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 455 | const WebPreferences& webkit_preferences, |
| 456 | int64 session_storage_namespace_id) |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 457 | : RenderWidget(render_thread, WebKit::WebPopupTypeNone), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 458 | webkit_preferences_(webkit_preferences), |
| 459 | send_content_state_immediately_(false), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 460 | enabled_bindings_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 461 | send_preferred_size_changes_(false), |
| 462 | script_can_close_(true), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 463 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 464 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 465 | opened_by_user_gesture_(true), |
| 466 | opener_suppressed_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 467 | page_id_(-1), |
| 468 | last_page_id_sent_to_browser_(-1), |
| 469 | last_indexed_page_id_(-1), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 470 | history_list_offset_(-1), |
| 471 | history_list_length_(0), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 472 | has_unload_listener_(false), |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 473 | #if defined(OS_MACOSX) |
| 474 | has_document_tag_(false), |
| 475 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 476 | document_tag_(0), |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 477 | cross_origin_access_count_(0), |
| 478 | same_origin_access_count_(0), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 479 | target_url_status_(TARGET_NONE), |
| 480 | spelling_panel_visible_(false), |
| 481 | view_type_(ViewType::INVALID), |
| 482 | browser_window_id_(-1), |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 483 | ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 484 | ALLOW_THIS_IN_INITIALIZER_LIST(page_info_method_factory_(this)), |
| 485 | ALLOW_THIS_IN_INITIALIZER_LIST(autofill_method_factory_(this)), |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 486 | ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 487 | ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)), |
| 488 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
| 489 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 490 | notification_provider_(new NotificationProvider(this))), |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 491 | accessibility_ack_pending_(false), |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 492 | session_storage_namespace_id_(session_storage_namespace_id), |
| 493 | decrement_shared_popup_at_destruction_(false) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 494 | password_autocomplete_manager_.reset(new PasswordAutocompleteManager(this)); |
| 495 | autofill_helper_.reset(new AutoFillHelper(this)); |
| 496 | page_click_tracker_.reset(new PageClickTracker(this)); |
| 497 | // Note that the order of insertion of the listeners is important. |
| 498 | // The password_autocomplete_manager_ takes the first shot at processing the |
| 499 | // notification and can stop the propagation. |
| 500 | page_click_tracker_->AddListener(password_autocomplete_manager_.get()); |
| 501 | page_click_tracker_->AddListener(autofill_helper_.get()); |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 502 | ClearBlockedContentSettings(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | RenderView::~RenderView() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 506 | if (decrement_shared_popup_at_destruction_) |
| 507 | shared_popup_counter_->data--; |
| 508 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 509 | // Dispose of un-disposed image fetchers. |
| 510 | for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin(); |
| 511 | i != image_fetchers_.end(); ++i) { |
| 512 | delete *i; |
| 513 | } |
| 514 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 515 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 516 | while (!file_chooser_completions_.empty()) { |
| 517 | if (file_chooser_completions_.front()->completion) { |
| 518 | file_chooser_completions_.front()->completion->didChooseFile( |
| 519 | WebVector<WebString>()); |
| 520 | } |
| 521 | file_chooser_completions_.pop_front(); |
| 522 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 523 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 524 | #if defined(OS_MACOSX) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 525 | // Tell the spellchecker that the document is closed. |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 526 | if (has_document_tag_) |
| 527 | Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 528 | |
| 529 | // Destroy all fake plugin window handles on the browser side. |
| 530 | while (!fake_plugin_window_handles_.empty()) { |
| 531 | // Make sure no NULL plugin window handles were inserted into this list. |
| 532 | DCHECK(*fake_plugin_window_handles_.begin()); |
| 533 | // DestroyFakePluginWindowHandle modifies fake_plugin_window_handles_. |
| 534 | DestroyFakePluginWindowHandle(*fake_plugin_window_handles_.begin()); |
| 535 | } |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 536 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 537 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 538 | render_thread_->RemoveFilter(audio_message_filter_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 539 | |
| 540 | #ifndef NDEBUG |
| 541 | // Make sure we are no longer referenced by the ViewMap. |
| 542 | ViewMap* views = Singleton<ViewMap>::get(); |
| 543 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 544 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 545 | #endif |
| 546 | } |
| 547 | |
| 548 | /*static*/ |
| 549 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
| 550 | ViewMap* views = Singleton<ViewMap>::get(); |
| 551 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 552 | if (!visitor->Visit(it->second)) |
| 553 | return; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | /*static*/ |
| 558 | RenderView* RenderView::FromWebView(WebView* webview) { |
| 559 | ViewMap* views = Singleton<ViewMap>::get(); |
| 560 | ViewMap::iterator it = views->find(webview); |
| 561 | return it == views->end() ? NULL : it->second; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /*static*/ |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 565 | RenderView* RenderView::Create( |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 566 | RenderThreadBase* render_thread, |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 567 | gfx::NativeViewId parent_hwnd, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 568 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 569 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 570 | const WebPreferences& webkit_prefs, |
| 571 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 572 | int32 routing_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 573 | int64 session_storage_namespace_id, |
| 574 | const string16& frame_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 575 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 576 | scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs, |
| 577 | session_storage_namespace_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 578 | view->Init(parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 579 | opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 580 | renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 581 | counter, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 582 | routing_id, |
| 583 | frame_name); // adds reference |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 584 | return view; |
| 585 | } |
| 586 | |
| 587 | /*static*/ |
| 588 | void RenderView::SetNextPageID(int32 next_page_id) { |
| 589 | // This method should only be called during process startup, and the given |
| 590 | // page id had better not exceed our current next page id! |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 591 | DCHECK_EQ(next_page_id_, 1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 592 | DCHECK(next_page_id >= next_page_id_); |
| 593 | next_page_id_ = next_page_id; |
| 594 | } |
| 595 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 596 | WebKit::WebView* RenderView::webview() const { |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 597 | return static_cast<WebKit::WebView*>(webwidget()); |
| 598 | } |
| 599 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 600 | void RenderView::UserMetricsRecordAction(const std::string& action) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 601 | Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); |
| 602 | } |
| 603 | |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 604 | void RenderView::PluginCrashed(const FilePath& plugin_path) { |
| 605 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 606 | } |
| 607 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 608 | WebPlugin* RenderView::CreatePluginNoCheck(WebFrame* frame, |
| 609 | const WebPluginParams& params) { |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 610 | WebPluginInfo info; |
| 611 | bool found; |
| 612 | ContentSetting setting; |
| 613 | std::string mime_type; |
| 614 | Send(new ViewHostMsg_GetPluginInfo( |
| 615 | params.url, frame->top()->url(), params.mimeType.utf8(), &found, |
| 616 | &info, &setting, &mime_type)); |
| 617 | if (!found || !info.enabled) |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 618 | return NULL; |
| 619 | scoped_refptr<pepper::PluginModule> pepper_module = |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 620 | PepperPluginRegistry::GetInstance()->GetModule(info.path); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 621 | if (pepper_module) |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 622 | return CreatePepperPlugin(frame, params, info.path, pepper_module.get()); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 623 | else |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 624 | return CreateNPAPIPlugin(frame, params, info.path, mime_type); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 625 | } |
| 626 | |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 627 | void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 628 | plugin_delegates_.insert(delegate); |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 629 | // If the renderer is visible, set initial visibility and focus state. |
| 630 | if (!is_hidden()) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 631 | #if defined(OS_MACOSX) |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 632 | delegate->SetContainerVisibility(true); |
| 633 | if (webview() && webview()->isActive()) |
| 634 | delegate->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 635 | #endif |
[email protected] | 4923229 | 2010-09-03 19:07:30 | [diff] [blame] | 636 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 637 | // Plugins start assuming the content has focus (so that they work in |
| 638 | // environments where RenderView isn't hosting them), so we always have to |
| 639 | // set the initial state. See webplugin_delegate_impl.h for details. |
| 640 | delegate->SetContentAreaFocus(has_focus()); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 644 | plugin_delegates_.erase(delegate); |
| 645 | } |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 646 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 647 | void RenderView::Init(gfx::NativeViewId parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 648 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 649 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 650 | SharedRenderViewCounter* counter, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 651 | int32 routing_id, |
| 652 | const string16& frame_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 653 | DCHECK(!webview()); |
| 654 | |
| 655 | if (opener_id != MSG_ROUTING_NONE) |
| 656 | opener_id_ = opener_id; |
| 657 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 658 | if (counter) { |
| 659 | shared_popup_counter_ = counter; |
| 660 | shared_popup_counter_->data++; |
| 661 | decrement_shared_popup_at_destruction_ = true; |
| 662 | } else { |
| 663 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 664 | decrement_shared_popup_at_destruction_ = false; |
| 665 | } |
| 666 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 667 | devtools_agent_.reset(new DevToolsAgent(routing_id, this)); |
[email protected] | 9b9d728 | 2009-04-08 14:13:04 | [diff] [blame] | 668 | |
[email protected] | 9a6c623 | 2010-06-25 11:46:49 | [diff] [blame] | 669 | webwidget_ = WebView::create(this, devtools_agent_.get()); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 670 | Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 671 | webkit_preferences_.Apply(webview()); |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 672 | webview()->initializeMainFrame(this); |
[email protected] | c1e0696 | 2010-06-17 16:53:23 | [diff] [blame] | 673 | if (!frame_name.empty()) |
| 674 | webview()->mainFrame()->setName(frame_name); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 675 | |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 676 | OnSetRendererPrefs(renderer_prefs); |
| 677 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 678 | routing_id_ = routing_id; |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 679 | render_thread_->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 680 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 681 | // when we receive ViewMsg_Close. |
| 682 | AddRef(); |
| 683 | |
| 684 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 685 | // completing initialization. Otherwise, we can finish it now. |
| 686 | if (opener_id == MSG_ROUTING_NONE) { |
| 687 | did_show_ = true; |
| 688 | CompleteInit(parent_hwnd); |
| 689 | } |
| 690 | |
| 691 | host_window_ = parent_hwnd; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 692 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 693 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 694 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 695 | enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION; |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 696 | if (command_line.HasSwitch(switches::kEnableAccessibility)) |
| 697 | WebAccessibilityCache::enableAccessibility(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 698 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 699 | audio_message_filter_ = new AudioMessageFilter(routing_id_); |
| 700 | render_thread_->AddFilter(audio_message_filter_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | void RenderView::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 704 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 705 | if (main_frame) |
| 706 | child_process_logging::SetActiveURL(main_frame->url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 707 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 708 | // If this is developer tools renderer intercept tools messages first. |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 709 | if (devtools_client_.get() && devtools_client_->OnMessageReceived(message)) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 710 | return; |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 711 | if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message)) |
| 712 | return; |
[email protected] | b6849bda | 2009-10-14 23:59:26 | [diff] [blame] | 713 | if (notification_provider_->OnMessageReceived(message)) |
| 714 | return; |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 715 | if (geolocation_dispatcher_.get() && |
| 716 | geolocation_dispatcher_->OnMessageReceived(message)) { |
| 717 | return; |
| 718 | } |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 719 | if (speech_input_dispatcher_.get() && |
| 720 | speech_input_dispatcher_->OnMessageReceived(message)) { |
| 721 | return; |
| 722 | } |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 723 | if (device_orientation_dispatcher_.get() && |
| 724 | device_orientation_dispatcher_->OnMessageReceived(message)) { |
| 725 | return; |
| 726 | } |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 727 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 728 | IPC_BEGIN_MESSAGE_MAP(RenderView, message) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 729 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail) |
| 730 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 731 | IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 732 | IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 733 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 734 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 735 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 736 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 737 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 738 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 739 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 740 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 741 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 742 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 743 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
| 744 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 745 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 746 | IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, |
| 747 | OnAdvanceToNextMisspelling) |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 748 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 749 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 750 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
| 751 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 752 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 753 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 754 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| 755 | IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 756 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 757 | IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, |
| 758 | OnSetContentSettingsForLoadingURL) |
| 759 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 760 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 761 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 762 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 763 | OnResetPageEncodingToDefault) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 764 | IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 765 | IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 766 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 767 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 768 | IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 769 | IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 770 | IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm) |
| 771 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) |
| 772 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) |
| 773 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) |
| 774 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 775 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 776 | IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 777 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved, |
| 778 | OnDragSourceEndedOrMoved) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 779 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, |
| 780 | OnDragSourceSystemDragEnded) |
| 781 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 782 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 783 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 784 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
| 785 | IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 786 | IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 787 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
| 788 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 789 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 790 | OnGetAllSavableResourceLinksForCurrentPage) |
[email protected] | f09c718 | 2009-03-10 12:54:04 | [diff] [blame] | 791 | IPC_MESSAGE_HANDLER( |
| 792 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 793 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 794 | IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 795 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnShouldClose) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 796 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 797 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 798 | IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 799 | OnHandleMessageFromExternalHost) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 800 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 801 | OnDisassociateFromPopupCount) |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 802 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned, |
| 803 | OnAutoFillSuggestionsReturned) |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 804 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled, |
| 805 | OnAutoFillFormDataFilled) |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 806 | IPC_MESSAGE_HANDLER(ViewMsg_AllowScriptToClose, |
| 807 | OnAllowScriptToClose) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 808 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 809 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 810 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
| 811 | OnExtensionMessageInvoke) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 812 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 813 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 814 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 815 | OnEnablePreferredSizeChangedMode) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 816 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 817 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 818 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 819 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId, |
| 820 | OnUpdateBrowserWindowId) |
| 821 | IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType, |
| 822 | OnNotifyRendererViewType) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 823 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 824 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 825 | #if defined(OS_MACOSX) |
| 826 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 827 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 828 | IPC_MESSAGE_HANDLER(ViewMsg_PluginImeCompositionConfirmed, |
| 829 | OnPluginImeCompositionConfirmed) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 830 | #endif |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 831 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 832 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 833 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode, |
| 834 | OnExecuteCode) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 835 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 836 | OnCustomContextMenuAction) |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 837 | IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage) |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 838 | IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation) |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 839 | IPC_MESSAGE_HANDLER(ViewMsg_EnableAccessibility, OnEnableAccessibility) |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 840 | IPC_MESSAGE_HANDLER(ViewMsg_SetAccessibilityFocus, OnSetAccessibilityFocus) |
| 841 | IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityDoDefaultAction, |
| 842 | OnAccessibilityDoDefaultAction) |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 843 | IPC_MESSAGE_HANDLER(ViewMsg_AccessibilityNotifications_ACK, |
| 844 | OnAccessibilityNotificationsAck) |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 845 | IPC_MESSAGE_HANDLER(ViewMsg_AsyncOpenFile_ACK, OnAsyncFileOpened) |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 846 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 847 | // Have the super handle all other messages. |
| 848 | IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) |
| 849 | IPC_END_MESSAGE_MAP() |
| 850 | } |
| 851 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 852 | void RenderView::OnCaptureThumbnail() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 853 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 854 | if (!main_frame) |
| 855 | return; |
| 856 | |
| 857 | // get the URL for this page |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 858 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 859 | if (url.is_empty()) |
| 860 | return; |
| 861 | |
| 862 | if (size_.IsEmpty()) |
| 863 | return; // Don't create an empty thumbnail! |
| 864 | |
| 865 | ThumbnailScore score; |
| 866 | SkBitmap thumbnail; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 867 | if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight, |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 868 | &thumbnail, &score)) |
| 869 | return; |
| 870 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 871 | // send the thumbnail message to the browser process |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 872 | Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 873 | } |
| 874 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 875 | void RenderView::OnCaptureSnapshot() { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 876 | SkBitmap snapshot; |
| 877 | bool error = false; |
| 878 | |
| 879 | WebFrame* main_frame = webview()->mainFrame(); |
| 880 | if (!main_frame) |
| 881 | error = true; |
| 882 | |
| 883 | if (!error && !CaptureSnapshot(webview(), &snapshot)) |
| 884 | error = true; |
| 885 | |
| 886 | DCHECK(error == snapshot.empty()) << |
| 887 | "Snapshot should be empty on error, non-empty otherwise."; |
| 888 | |
| 889 | // Send the snapshot to the browser process. |
| 890 | Send(new ViewHostMsg_Snapshot(routing_id_, snapshot)); |
| 891 | } |
| 892 | |
[email protected] | 06863722 | 2009-01-29 16:58:07 | [diff] [blame] | 893 | void RenderView::OnPrintPages() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 894 | DCHECK(webview()); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 895 | if (webview()) { |
| 896 | // If the user has selected text in the currently focused frame we print |
| 897 | // only that frame (this makes print selection work for multiple frames). |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 898 | if (webview()->focusedFrame()->hasSelection()) |
| 899 | Print(webview()->focusedFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 900 | else |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 901 | Print(webview()->mainFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 902 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 903 | } |
| 904 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 905 | void RenderView::OnPrintingDone(int document_cookie, bool success) { |
| 906 | // Ignoring document cookie here since only one print job can be outstanding |
| 907 | // per renderer and document_cookie is 0 when printing is successful. |
| 908 | DCHECK(print_helper_.get()); |
| 909 | if (print_helper_.get() != NULL) { |
| 910 | print_helper_->DidFinishPrinting(success); |
| 911 | } |
| 912 | } |
| 913 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 914 | void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { |
| 915 | if (load_id != page_id_) |
| 916 | return; // this capture call is no longer relevant due to navigation |
| 917 | if (load_id == last_indexed_page_id_) |
| 918 | return; // we already indexed this page |
| 919 | |
| 920 | if (!webview()) |
| 921 | return; |
| 922 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 923 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 924 | if (!main_frame) |
| 925 | return; |
| 926 | |
| 927 | // Don't index/capture pages that are in view source mode. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 928 | if (main_frame->isViewSourceModeEnabled()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 929 | return; |
| 930 | |
| 931 | // Don't index/capture pages that failed to load. This only checks the top |
| 932 | // level frame so the thumbnail may contain a frame that failed to load. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 933 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 934 | if (ds && ds->hasUnreachableURL()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 935 | return; |
| 936 | |
| 937 | if (!preliminary_capture) |
| 938 | last_indexed_page_id_ = load_id; |
| 939 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 940 | // Get the URL for this page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 941 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 942 | if (url.is_empty()) |
| 943 | return; |
| 944 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 945 | // Retrieve the frame's full text. |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 946 | string16 contents; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 947 | CaptureText(main_frame, &contents); |
| 948 | if (contents.size()) { |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 949 | WebKit::WebDocument document = main_frame->document(); |
[email protected] | 5ddfd63e | 2010-09-01 15:48:37 | [diff] [blame] | 950 | // If the page explicitly specifies a language, use it, otherwise we'll |
| 951 | // determine it based on the text content using the CLD. |
| 952 | std::string language = |
| 953 | TranslateHelper::GetPageLanguageFromMetaTag(&document); |
| 954 | if (language.empty()) { |
| 955 | base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 956 | language = DetermineTextLanguage(contents); |
| 957 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection", |
| 958 | base::TimeTicks::Now() - begin_time); |
| 959 | } |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 960 | // Send the text to the browser for indexing (the browser might decide not |
| 961 | // to index, if the URL is HTTPS for instance) and language discovery. |
[email protected] | 5ddfd63e | 2010-09-01 15:48:37 | [diff] [blame] | 962 | Send(new ViewHostMsg_PageContents( |
| 963 | routing_id_, url, load_id, contents, language, |
| 964 | TranslateHelper::IsPageTranslatable(&document))); |
[email protected] | 5c426692 | 2009-07-10 16:41:27 | [diff] [blame] | 965 | } |
| 966 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 967 | OnCaptureThumbnail(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 968 | } |
| 969 | |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 970 | void RenderView::CaptureText(WebFrame* frame, string16* contents) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 971 | contents->clear(); |
| 972 | if (!frame) |
| 973 | return; |
| 974 | |
| 975 | #ifdef TIME_TEXT_RETRIEVAL |
| 976 | double begin = time_util::GetHighResolutionTimeNow(); |
| 977 | #endif |
| 978 | |
| 979 | // get the contents of the frame |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 980 | *contents = frame->contentAsText(kMaxIndexChars); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 981 | |
| 982 | #ifdef TIME_TEXT_RETRIEVAL |
| 983 | double end = time_util::GetHighResolutionTimeNow(); |
| 984 | char buf[128]; |
| 985 | sprintf_s(buf, "%d chars retrieved for indexing in %gms\n", |
| 986 | contents.size(), (end - begin)*1000); |
| 987 | OutputDebugStringA(buf); |
| 988 | #endif |
| 989 | |
| 990 | // When the contents are clipped to the maximum, we don't want to have a |
| 991 | // partial word indexed at the end that might have been clipped. Therefore, |
| 992 | // terminate the string at the last space to ensure no words are clipped. |
| 993 | if (contents->size() == kMaxIndexChars) { |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 994 | size_t last_space_index = contents->find_last_of(kWhitespaceUTF16); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 995 | if (last_space_index == std::wstring::npos) |
| 996 | return; // don't index if we got a huge block of text with no spaces |
| 997 | contents->resize(last_space_index); |
| 998 | } |
| 999 | } |
| 1000 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1001 | bool RenderView::CaptureThumbnail(WebView* view, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1002 | int w, |
| 1003 | int h, |
| 1004 | SkBitmap* thumbnail, |
| 1005 | ThumbnailScore* score) { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1006 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 1007 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1008 | skia::PlatformCanvas canvas; |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1009 | |
| 1010 | // Paint |view| into |canvas|. |
| 1011 | if (!PaintViewIntoCanvas(view, canvas)) |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1012 | return false; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1013 | |
| 1014 | skia::BitmapPlatformDevice& device = |
| 1015 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 1016 | |
| 1017 | const SkBitmap& src_bmp = device.accessBitmap(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1018 | |
[email protected] | cab34d6a | 2009-09-24 01:14:52 | [diff] [blame] | 1019 | SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1020 | float dest_aspect = dest_rect.width() / dest_rect.height(); |
| 1021 | |
| 1022 | // Get the src rect so that we can preserve the aspect ratio while filling |
| 1023 | // the destination. |
| 1024 | SkIRect src_rect; |
| 1025 | if (src_bmp.width() < dest_rect.width() || |
| 1026 | src_bmp.height() < dest_rect.height()) { |
| 1027 | // Source image is smaller: we clip the part of source image within the |
| 1028 | // dest rect, and then stretch it to fill the dest rect. We don't respect |
| 1029 | // the aspect ratio in this case. |
| 1030 | src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()), |
| 1031 | static_cast<S16CPU>(dest_rect.height())); |
| 1032 | score->good_clipping = false; |
| 1033 | } else { |
| 1034 | float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height(); |
| 1035 | if (src_aspect > dest_aspect) { |
| 1036 | // Wider than tall, clip horizontally: we center the smaller thumbnail in |
| 1037 | // the wider screen. |
| 1038 | S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect); |
| 1039 | S16CPU x_offset = (src_bmp.width() - new_width) / 2; |
| 1040 | src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height()); |
| 1041 | score->good_clipping = false; |
| 1042 | } else { |
| 1043 | src_rect.set(0, 0, src_bmp.width(), |
| 1044 | static_cast<S16CPU>(src_bmp.width() / dest_aspect)); |
| 1045 | score->good_clipping = true; |
| 1046 | } |
| 1047 | } |
| 1048 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1049 | score->at_top = (view->mainFrame()->scrollOffset().height == 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1050 | |
| 1051 | SkBitmap subset; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 1052 | device.accessBitmap(false).extractSubset(&subset, src_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1053 | |
| 1054 | // Resample the subset that we want to get it the right size. |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 1055 | *thumbnail = skia::ImageOperations::Resize( |
| 1056 | subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1057 | |
| 1058 | score->boring_score = CalculateBoringScore(thumbnail); |
| 1059 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1060 | HISTOGRAM_TIMES("Renderer4.Thumbnail", |
| 1061 | base::TimeTicks::Now() - beginning_time); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 1062 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1063 | } |
| 1064 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1065 | bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) { |
| 1066 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1067 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 1068 | skia::PlatformCanvas canvas; |
| 1069 | if (!PaintViewIntoCanvas(view, canvas)) |
| 1070 | return false; |
| 1071 | |
| 1072 | skia::BitmapPlatformDevice& device = |
| 1073 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 1074 | |
| 1075 | const SkBitmap& bitmap = device.accessBitmap(false); |
| 1076 | if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
| 1077 | return false; |
| 1078 | |
| 1079 | HISTOGRAM_TIMES("Renderer4.Snapshot", |
| 1080 | base::TimeTicks::Now() - beginning_time); |
| 1081 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { |
| 1085 | if (!webview()) |
| 1086 | return; |
| 1087 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1088 | history_list_offset_ = params.current_history_list_offset; |
| 1089 | history_list_length_ = params.current_history_list_length; |
| 1090 | |
[email protected] | 8c785c6 | 2009-07-13 14:20:15 | [diff] [blame] | 1091 | if (devtools_agent_.get()) |
| 1092 | devtools_agent_->OnNavigate(); |
| 1093 | |
[email protected] | 42219753 | 2010-01-25 17:38:23 | [diff] [blame] | 1094 | if (notification_provider_.get()) |
| 1095 | notification_provider_->OnNavigate(); |
| 1096 | |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 1097 | child_process_logging::SetActiveURL(params.url); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 1098 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1099 | AboutHandler::MaybeHandle(params.url); |
| 1100 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1101 | bool is_reload = |
| 1102 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD || |
| 1103 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1104 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1105 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1106 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1107 | // We cannot reload if we do not have any history state. This happens, for |
| 1108 | // example, when recovering from a crash. Our workaround here is a bit of |
| 1109 | // a hack since it means that reload after a crashed tab does not cause an |
| 1110 | // end-to-end cache validation. |
| 1111 | is_reload = false; |
| 1112 | } |
| 1113 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1114 | // A navigation resulting from loading a javascript URL should not be treated |
| 1115 | // as a browser initiated event. Instead, we want it to look as if the page |
| 1116 | // initiated any load resulting from JS execution. |
| 1117 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1118 | NavigationState* state = NavigationState::CreateBrowserInitiated( |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1119 | params.page_id, |
| 1120 | params.pending_history_list_offset, |
| 1121 | params.transition, |
| 1122 | params.request_time); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 1123 | if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) { |
| 1124 | // We're doing a load of a page that was restored from the last session. |
| 1125 | // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE) |
| 1126 | // which can result in stale data for pages that are set to expire. We |
| 1127 | // explicitly override that by setting the policy here so that as |
| 1128 | // necessary we load from the network. |
| 1129 | state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy); |
| 1130 | } |
| 1131 | pending_navigation_state_.reset(state); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1132 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1133 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1134 | NavigationState* navigation_state = pending_navigation_state_.get(); |
| 1135 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1136 | // If we are reloading, then WebKit will use the history state of the current |
| 1137 | // page, so we should just ignore any given history state. Otherwise, if we |
| 1138 | // have history state, then we need to navigate to it, which corresponds to a |
| 1139 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1140 | if (is_reload) { |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1141 | if (navigation_state) |
| 1142 | navigation_state->set_load_type(NavigationState::RELOAD); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1143 | bool ignore_cache = (params.navigation_type == |
| 1144 | ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE); |
| 1145 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1146 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1147 | // 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] | 1148 | DCHECK_NE(params.page_id, -1); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1149 | if (navigation_state) |
| 1150 | navigation_state->set_load_type(NavigationState::HISTORY_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1151 | main_frame->loadHistoryItem( |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1152 | webkit_glue::HistoryItemFromString(params.state)); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1153 | } else { |
| 1154 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1155 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1156 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1157 | // A session history navigation should have been accompanied by state. |
| 1158 | DCHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1159 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1160 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1161 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1162 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1163 | if (params.referrer.is_valid()) { |
| 1164 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), |
| 1165 | WebString::fromUTF8(params.referrer.spec())); |
| 1166 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1167 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1168 | if (navigation_state) |
| 1169 | navigation_state->set_load_type(NavigationState::NORMAL_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1170 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1171 | } |
| 1172 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1173 | // In case LoadRequest failed before DidCreateDataSource was called. |
| 1174 | pending_navigation_state_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | // Stop loading the current page |
| 1178 | void RenderView::OnStop() { |
| 1179 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 1180 | webview()->mainFrame()->stopLoading(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1181 | } |
| 1182 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1183 | // Reload current focused frame. |
| 1184 | // 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] | 1185 | void RenderView::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1186 | if (webview() && webview()->focusedFrame()) { |
| 1187 | // We always obey the cache (ignore_cache=false) here. |
| 1188 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1189 | // a cache-ignoring reload of the frame. |
| 1190 | webview()->focusedFrame()->reload(false); |
| 1191 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1192 | } |
| 1193 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1194 | void RenderView::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1195 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1196 | } |
| 1197 | |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1198 | void RenderView::OnExecuteEditCommand(const std::string& name, |
| 1199 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1200 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1201 | return; |
| 1202 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1203 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1204 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1205 | } |
| 1206 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1207 | void RenderView::OnSetupDevToolsClient() { |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 1208 | DCHECK(!devtools_client_.get()); |
| 1209 | devtools_client_.reset(new DevToolsClient(this)); |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1210 | } |
| 1211 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1212 | void RenderView::OnUpdateTargetURLAck() { |
| 1213 | // Check if there is a targeturl waiting to be sent. |
| 1214 | if (target_url_status_ == TARGET_PENDING) { |
| 1215 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1216 | pending_target_url_)); |
| 1217 | } |
| 1218 | |
| 1219 | target_url_status_ = TARGET_NONE; |
| 1220 | } |
| 1221 | |
| 1222 | void RenderView::OnUndo() { |
| 1223 | if (!webview()) |
| 1224 | return; |
| 1225 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1226 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1227 | UserMetricsRecordAction("Undo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | void RenderView::OnRedo() { |
| 1231 | if (!webview()) |
| 1232 | return; |
| 1233 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1234 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1235 | UserMetricsRecordAction("Redo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | void RenderView::OnCut() { |
| 1239 | if (!webview()) |
| 1240 | return; |
| 1241 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1242 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1243 | UserMetricsRecordAction("Cut"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | void RenderView::OnCopy() { |
| 1247 | if (!webview()) |
| 1248 | return; |
| 1249 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1250 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1251 | UserMetricsRecordAction("Copy"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1252 | } |
| 1253 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1254 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1255 | void RenderView::OnCopyToFindPboard() { |
| 1256 | if (!webview()) |
| 1257 | return; |
| 1258 | |
| 1259 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1260 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1261 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1262 | if (frame->hasSelection()) { |
| 1263 | string16 selection = frame->selectionAsText(); |
| 1264 | RenderThread::current()->Send( |
| 1265 | new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection)); |
| 1266 | } |
| 1267 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1268 | UserMetricsRecordAction("CopyToFindPboard"); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1269 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1270 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1271 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1272 | void RenderView::OnPaste() { |
| 1273 | if (!webview()) |
| 1274 | return; |
| 1275 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1276 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1277 | UserMetricsRecordAction("Paste"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1278 | } |
| 1279 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1280 | void RenderView::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1281 | if (!webview()) |
| 1282 | return; |
| 1283 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1284 | WebFrame* frame = webview()->focusedFrame(); |
| 1285 | if (!frame->hasSelection()) |
| 1286 | frame->selectWordAroundCaret(); |
| 1287 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1288 | } |
| 1289 | |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1290 | void RenderView::OnAdvanceToNextMisspelling() { |
| 1291 | if (!webview()) |
| 1292 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1293 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1294 | WebString::fromUTF8("AdvanceToNextMisspelling")); |
| 1295 | } |
| 1296 | |
| 1297 | void RenderView::OnToggleSpellPanel(bool is_currently_visible) { |
| 1298 | if (!webview()) |
| 1299 | return; |
| 1300 | // We need to tell the webView whether the spelling panel is visible or not so |
| 1301 | // that it won't need to make ipc calls later. |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1302 | spelling_panel_visible_ = is_currently_visible; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1303 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1304 | WebString::fromUTF8("ToggleSpellPanel")); |
| 1305 | } |
| 1306 | |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1307 | void RenderView::OnToggleSpellCheck() { |
| 1308 | if (!webview()) |
| 1309 | return; |
| 1310 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1311 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1312 | frame->enableContinuousSpellChecking( |
| 1313 | !frame->isContinuousSpellCheckingEnabled()); |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1314 | } |
| 1315 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1316 | void RenderView::OnDelete() { |
| 1317 | if (!webview()) |
| 1318 | return; |
| 1319 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1320 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1321 | UserMetricsRecordAction("DeleteSelection"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | void RenderView::OnSelectAll() { |
| 1325 | if (!webview()) |
| 1326 | return; |
| 1327 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1328 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 1329 | WebString::fromUTF8("SelectAll")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1330 | UserMetricsRecordAction("SelectAll"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | void RenderView::OnSetInitialFocus(bool reverse) { |
| 1334 | if (!webview()) |
| 1335 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1336 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | /////////////////////////////////////////////////////////////////////////////// |
| 1340 | |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1341 | void RenderView::SetContentSettings(const ContentSettings& settings) { |
| 1342 | current_content_settings_ = settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1343 | } |
| 1344 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1345 | // Tell the embedding application that the URL of the active page has changed |
| 1346 | void RenderView::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1347 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1348 | DCHECK(ds); |
| 1349 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1350 | const WebURLRequest& request = ds->request(); |
| 1351 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1352 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1353 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1354 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 1355 | DCHECK(navigation_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1356 | |
| 1357 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1358 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1359 | params.is_post = false; |
| 1360 | params.page_id = page_id_; |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1361 | params.frame_id = frame->identifier(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1362 | params.is_content_filtered = response.isContentFiltered(); |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1363 | params.was_within_same_page = navigation_state->was_within_same_page(); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1364 | if (!navigation_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1365 | // SSL state specified in the request takes precedence over the one in the |
| 1366 | // response. |
| 1367 | // So far this is only intended for error pages that are not expected to be |
| 1368 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1369 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1370 | params.security_info = navigation_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1371 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1372 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1376 | if (ds->hasUnreachableURL()) { |
| 1377 | params.url = ds->unreachableURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1378 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1379 | params.url = request.url(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1380 | } |
| 1381 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1382 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1383 | params.should_update_history = !ds->hasUnreachableURL() && |
| 1384 | !response.isMultipartPayload(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1385 | |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1386 | params.searchable_form_url = navigation_state->searchable_form_url(); |
| 1387 | params.searchable_form_encoding = |
| 1388 | navigation_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1389 | |
| 1390 | const PasswordForm* password_form_data = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1391 | navigation_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1392 | if (password_form_data) |
| 1393 | params.password_form = *password_form_data; |
| 1394 | |
| 1395 | params.gesture = navigation_gesture_; |
| 1396 | navigation_gesture_ = NavigationGestureUnknown; |
| 1397 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1398 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1399 | // Top-level navigation. |
| 1400 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 1401 | // Clear "block" flags for the new page. This needs to happen before any of |
| 1402 | // allowScripts(), allowImages(), allowPlugins() is called for the new page |
| 1403 | // so that these functions can correctly detect that a piece of content |
| 1404 | // flipped from "not blocked" to "blocked". |
| 1405 | ClearBlockedContentSettings(); |
| 1406 | |
[email protected] | 62d2a11 | 2010-04-07 00:53:02 | [diff] [blame] | 1407 | // Set content settings. Default them from the parent window if one exists. |
| 1408 | // This makes sure about:blank windows work as expected. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1409 | HostContentSettings::iterator host_content_settings = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1410 | host_content_settings_.find(GURL(request.url())); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1411 | if (host_content_settings != host_content_settings_.end()) { |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1412 | SetContentSettings(host_content_settings->second); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1413 | |
| 1414 | // These content settings were merely recorded transiently for this load. |
| 1415 | // We can erase them now. If at some point we reload this page, the |
| 1416 | // browser will send us new, up-to-date content settings. |
| 1417 | host_content_settings_.erase(host_content_settings); |
[email protected] | 3a387ae | 2010-04-08 01:58:40 | [diff] [blame] | 1418 | } else if (frame->opener()) { |
[email protected] | 8128cdd0 | 2010-07-21 20:40:10 | [diff] [blame] | 1419 | // The opener's view is not guaranteed to be non-null (it could be |
| 1420 | // detached from its page but not yet destructed). |
| 1421 | if (WebView* opener_view = frame->opener()->view()) { |
| 1422 | RenderView* opener = FromWebView(opener_view); |
| 1423 | SetContentSettings(opener->current_content_settings_); |
| 1424 | } |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1425 | } |
| 1426 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1427 | // Set zoom level, but don't do it for full-page plugin since they don't use |
| 1428 | // the same zoom settings. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1429 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1430 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1431 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 1432 | // Reset the zoom levels for plugins. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1433 | webview()->setZoomLevel(false, 0); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1434 | } else { |
| 1435 | if (host_zoom != host_zoom_levels_.end()) |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1436 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1437 | } |
| 1438 | |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1439 | if (host_zoom != host_zoom_levels_.end()) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1440 | // This zoom level was merely recorded transiently for this load. We can |
| 1441 | // erase it now. If at some point we reload this page, the browser will |
| 1442 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1443 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1444 | } |
| 1445 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1446 | // Reset the zoom limits in case a plugin had changed them previously. This |
| 1447 | // will also call us back which will cause us to send a message to |
| 1448 | // update TabContents. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1449 | webview()->zoomLimitsChanged( |
| 1450 | WebView::zoomFactorToZoomLevel(WebView::minTextSizeMultiplier), |
| 1451 | WebView::zoomFactorToZoomLevel(WebView::maxTextSizeMultiplier)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1452 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1453 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1454 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1455 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1456 | params.transition = navigation_state->transition_type(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1457 | if (!PageTransition::IsMainFrame(params.transition)) { |
| 1458 | // If the main frame does a load, it should not be reported as a subframe |
| 1459 | // navigation. This can occur in the following case: |
| 1460 | // 1. You're on a site with frames. |
| 1461 | // 2. You do a subframe navigation. This is stored with transition type |
| 1462 | // MANUAL_SUBFRAME. |
| 1463 | // 3. You navigate to some non-frame site, say, google.com. |
| 1464 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1465 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1466 | // We don't want that, because any navigation that changes the toplevel |
| 1467 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1468 | // update the URL bar, etc). |
| 1469 | params.transition = PageTransition::LINK; |
| 1470 | } |
| 1471 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1472 | // If we have a valid consumed client redirect source, |
| 1473 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1474 | // so we set the referrer and transition to match. |
| 1475 | if (completed_client_redirect_src_.is_valid()) { |
[email protected] | 77e09a9 | 2008-08-01 18:11:04 | [diff] [blame] | 1476 | DCHECK(completed_client_redirect_src_ == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1477 | params.referrer = completed_client_redirect_src_; |
| 1478 | params.transition = static_cast<PageTransition::Type>( |
| 1479 | params.transition | PageTransition::CLIENT_REDIRECT); |
| 1480 | } else { |
| 1481 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1482 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1483 | params.referrer = GURL( |
| 1484 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1485 | } |
| 1486 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1487 | string16 method = request.httpMethod(); |
| 1488 | if (EqualsASCII(method, "POST")) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1489 | params.is_post = true; |
| 1490 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1491 | // Save some histogram data so we can compute the average memory used per |
| 1492 | // page load of the glyphs. |
| 1493 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1494 | webkit_glue::GetGlyphPageCount()); |
| 1495 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1496 | // This message needs to be sent before any of allowScripts(), |
| 1497 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1498 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1499 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1500 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1501 | } else { |
| 1502 | // Subframe navigation: the type depends on whether this navigation |
| 1503 | // generated a new session history entry. When they do generate a session |
| 1504 | // history entry, it means the user initiated the navigation and we should |
| 1505 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1506 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1507 | if (page_id_ > last_page_id_sent_to_browser_) |
| 1508 | params.transition = PageTransition::MANUAL_SUBFRAME; |
| 1509 | else |
| 1510 | params.transition = PageTransition::AUTO_SUBFRAME; |
| 1511 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1512 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1513 | } |
| 1514 | |
| 1515 | last_page_id_sent_to_browser_ = |
| 1516 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1517 | |
| 1518 | // 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] | 1519 | // we don't want the transition type to persist. Just clear it. |
| 1520 | navigation_state->set_transition_type(PageTransition::LINK); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1521 | |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 1522 | // Check if the navigation was within the same page, in which case we don't |
| 1523 | // want to clear the accessibility cache. |
| 1524 | if (accessibility_.get() && !navigation_state->was_within_same_page()) { |
[email protected] | 1745596 | 2010-02-24 01:39:35 | [diff] [blame] | 1525 | accessibility_.reset(); |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 1526 | pending_accessibility_notifications_.clear(); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1527 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1531 | void RenderView::UpdateTitle(WebFrame* frame, const string16& title) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1532 | // Ignore all but top level navigations... |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1533 | if (!frame->parent()) { |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1534 | Send(new ViewHostMsg_UpdateTitle( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1535 | routing_id_, |
| 1536 | page_id_, |
| 1537 | UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ? |
| 1538 | title.substr(0, chrome::kMaxTitleChars) : title))); |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1539 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | void RenderView::UpdateEncoding(WebFrame* frame, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1543 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1544 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1545 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1546 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1547 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1548 | last_encoding_name_ = encoding_name; |
| 1549 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1550 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | |
[email protected] | f4d34b5 | 2008-11-24 23:05:01 | [diff] [blame] | 1554 | // Sends the previous session history state to the browser so it will be saved |
| 1555 | // before we navigate to a new page. This must be called *before* the page ID |
| 1556 | // has been updated so we know what it was. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1557 | void RenderView::UpdateSessionHistory(WebFrame* frame) { |
| 1558 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1559 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1560 | // there is no past session history to record. |
| 1561 | if (page_id_ == -1) |
| 1562 | return; |
| 1563 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1564 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1565 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1566 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1567 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1568 | |
| 1569 | Send(new ViewHostMsg_UpdateState( |
| 1570 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1571 | } |
| 1572 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1573 | void RenderView::OpenURL( |
| 1574 | const GURL& url, const GURL& referrer, WebNavigationPolicy policy) { |
| 1575 | Send(new ViewHostMsg_OpenURL( |
| 1576 | routing_id_, url, referrer, NavigationPolicyToDisposition(policy))); |
| 1577 | } |
| 1578 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1579 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1580 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1581 | void RenderView::LoadNavigationErrorPage(WebFrame* frame, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1582 | const WebURLRequest& failed_request, |
| 1583 | const WebURLError& error, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1584 | const std::string& html, |
| 1585 | bool replace) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1586 | GURL failed_url = error.unreachableURL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1587 | std::string alt_html; |
[email protected] | 07b49351 | 2010-08-27 15:39:29 | [diff] [blame] | 1588 | ExtensionRendererInfo* extension = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1589 | if (html.empty()) { |
| 1590 | // Use a local error page. |
| 1591 | int resource_id; |
| 1592 | DictionaryValue error_strings; |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1593 | |
[email protected] | 8165428 | 2010-10-04 17:08:06 | [diff] [blame] | 1594 | if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1595 | extension = ExtensionRendererInfo::GetByURL(failed_url); |
| 1596 | if (extension) { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1597 | LocalizedError::GetAppErrorStrings(error, failed_url, extension, |
| 1598 | &error_strings); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1599 | |
| 1600 | // TODO(erikkay): Should we use a different template for different |
| 1601 | // error messages? |
| 1602 | resource_id = IDR_ERROR_APP_HTML; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1603 | } else { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1604 | if (error.domain == WebString::fromUTF8(net::kErrorDomain) && |
| 1605 | error.reason == net::ERR_CACHE_MISS && |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1606 | EqualsASCII(failed_request.httpMethod(), "POST")) { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1607 | LocalizedError::GetFormRepostStrings(failed_url, &error_strings); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1608 | resource_id = IDR_ERROR_NO_DETAILS_HTML; |
| 1609 | } else { |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 1610 | LocalizedError::GetStrings(error, &error_strings); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 1611 | resource_id = IDR_NET_ERROR_HTML; |
| 1612 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1613 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1614 | |
| 1615 | alt_html = GetAltHTMLForTemplate(error_strings, resource_id); |
| 1616 | } else { |
| 1617 | alt_html = html; |
| 1618 | } |
| 1619 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1620 | frame->loadHTMLString(alt_html, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1621 | GURL(kUnreachableWebDataURL), |
| 1622 | failed_url, |
| 1623 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1624 | } |
| 1625 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 1626 | void RenderView::BindDOMAutomationController(WebFrame* frame) { |
[email protected] | 2f97917 | 2010-09-16 21:54:03 | [diff] [blame] | 1627 | if (!dom_automation_controller_.get()) { |
| 1628 | dom_automation_controller_.reset(new DomAutomationController()); |
| 1629 | } |
| 1630 | dom_automation_controller_->set_message_sender(this); |
| 1631 | dom_automation_controller_->set_routing_id(routing_id_); |
| 1632 | dom_automation_controller_->BindToJavascript(frame, |
| 1633 | L"domAutomationController"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1634 | } |
| 1635 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1636 | bool RenderView::RunJavaScriptMessage(int type, |
| 1637 | const std::wstring& message, |
| 1638 | const std::wstring& default_value, |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1639 | const GURL& frame_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1640 | std::wstring* result) { |
| 1641 | bool success = false; |
| 1642 | std::wstring result_temp; |
| 1643 | if (!result) |
| 1644 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1645 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1646 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1647 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1648 | return success; |
| 1649 | } |
| 1650 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1651 | bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
| 1652 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1653 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1654 | // it is particularly important that we do not call willEnterModalLoop as |
| 1655 | // that would defer resource loads for the dialog itself. |
| 1656 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 1657 | RenderThread::current()->DoNotNotifyWebKitOfModalLoop(); |
| 1658 | |
| 1659 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1660 | return Send(message); |
| 1661 | } |
| 1662 | |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1663 | void RenderView::AddGURLSearchProvider( |
| 1664 | const GURL& osd_url, |
| 1665 | const ViewHostMsg_PageHasOSDD_Type& provider_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1666 | if (!osd_url.is_empty()) |
| 1667 | Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1668 | provider_type)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1669 | } |
| 1670 | |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1671 | void RenderView::OnAutoFillSuggestionsReturned( |
| 1672 | int query_id, |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 1673 | const std::vector<string16>& values, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 1674 | const std::vector<string16>& labels, |
[email protected] | a53e0683 | 2010-07-28 22:46:41 | [diff] [blame] | 1675 | const std::vector<string16>& icons, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 1676 | const std::vector<int>& unique_ids) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1677 | autofill_helper_->SuggestionsReceived( |
[email protected] | a53e0683 | 2010-07-28 22:46:41 | [diff] [blame] | 1678 | query_id, values, labels, icons, unique_ids); |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1679 | } |
| 1680 | |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 1681 | void RenderView::OnAutoFillFormDataFilled(int query_id, |
| 1682 | const webkit_glue::FormData& form) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1683 | autofill_helper_->FormDataFilled(query_id, form); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 1684 | } |
| 1685 | |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1686 | void RenderView::OnAllowScriptToClose(bool script_can_close) { |
| 1687 | script_can_close_ = script_can_close; |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1688 | } |
| 1689 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1690 | uint32 RenderView::GetCPBrowsingContext() { |
| 1691 | uint32 context = 0; |
| 1692 | Send(new ViewHostMsg_GetCPBrowsingContext(&context)); |
| 1693 | return context; |
| 1694 | } |
| 1695 | |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1696 | void RenderView::AddSearchProvider( |
| 1697 | const std::string& url, |
| 1698 | const ViewHostMsg_PageHasOSDD_Type& provider_type) { |
| 1699 | if (provider_type.type == |
| 1700 | ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER && |
| 1701 | !webview()->mainFrame()->isProcessingUserGesture()) |
| 1702 | return; |
| 1703 | |
| 1704 | AddGURLSearchProvider(GURL(url), provider_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1705 | } |
| 1706 | |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1707 | ViewHostMsg_GetSearchProviderInstallState_Params |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1708 | RenderView::GetSearchProviderInstallState(WebFrame* frame, |
| 1709 | const std::string& url) { |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1710 | GURL inquiry_url = GURL(url); |
| 1711 | if (inquiry_url.is_empty()) |
| 1712 | return ViewHostMsg_GetSearchProviderInstallState_Params::Denied(); |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1713 | |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1714 | ViewHostMsg_GetSearchProviderInstallState_Params install; |
| 1715 | Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_, |
[email protected] | 52ded45 | 2010-08-23 22:01:25 | [diff] [blame] | 1716 | frame->url(), |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame] | 1717 | inquiry_url, |
| 1718 | &install)); |
| 1719 | return install; |
| 1720 | } |
| 1721 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1722 | void RenderView::OnMissingPluginStatus( |
| 1723 | WebPluginDelegateProxy* delegate, |
| 1724 | int status) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1725 | #if defined(OS_WIN) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1726 | if (!first_default_plugin_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1727 | // Show the InfoBar for the first available plugin. |
| 1728 | if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1729 | first_default_plugin_ = delegate->AsWeakPtr(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1730 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1731 | } |
| 1732 | } else { |
| 1733 | // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar) |
| 1734 | // to start the download/install. |
| 1735 | if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) { |
| 1736 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1737 | } |
| 1738 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1739 | #else |
[email protected] | 76c3b31 | 2010-05-20 21:38:29 | [diff] [blame] | 1740 | // TODO(port): Implement the infobar that accompanies the default plugin. |
| 1741 | // Linux: http://crbug.com/10952 |
| 1742 | // Mac: http://crbug.com/17392 |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1743 | NOTIMPLEMENTED(); |
| 1744 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1745 | } |
| 1746 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1747 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1748 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1749 | WebView* RenderView::createView( |
| 1750 | WebFrame* creator, |
| 1751 | const WebWindowFeatures& features, |
| 1752 | const WebString& frame_name) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1753 | // Check to make sure we aren't overloading on popups. |
| 1754 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1755 | return NULL; |
| 1756 | |
| 1757 | // This window can't be closed from a window.close() call until we receive a |
| 1758 | // message from the Browser process explicitly allowing it. |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 1759 | script_can_close_ = false; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1760 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1761 | ViewHostMsg_CreateWindow_Params params; |
| 1762 | params.opener_id = routing_id_; |
| 1763 | params.user_gesture = creator->isProcessingUserGesture(); |
| 1764 | params.window_container_type = WindowFeaturesToContainerType(features); |
| 1765 | params.session_storage_namespace_id = session_storage_namespace_id_; |
| 1766 | params.frame_name = frame_name; |
| 1767 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1768 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1769 | int64 cloned_session_storage_namespace_id; |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1770 | bool opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1771 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1772 | render_thread_->Send( |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1773 | new ViewHostMsg_CreateWindow(params, |
| 1774 | &routing_id, |
| 1775 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1776 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1777 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1778 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1779 | RenderView* view = RenderView::Create(render_thread_, |
[email protected] | 659f73fa | 2009-10-13 13:43:42 | [diff] [blame] | 1780 | 0, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1781 | routing_id_, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1782 | renderer_preferences_, |
| 1783 | webkit_preferences_, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1784 | shared_popup_counter_, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1785 | routing_id, |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 1786 | cloned_session_storage_namespace_id, |
| 1787 | frame_name); |
| 1788 | view->opened_by_user_gesture_ = params.user_gesture; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1789 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1790 | // Record whether the creator frame is trying to suppress the opener field. |
| 1791 | view->opener_suppressed_ = opener_suppressed; |
| 1792 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1793 | // Record the security origin of the creator. |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 1794 | GURL creator_url(creator->securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1795 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1796 | creator_url = GURL(); |
| 1797 | view->creator_url_ = creator_url; |
| 1798 | |
| 1799 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1800 | // the new render view (we don't need the browser to send the URL back down). |
| 1801 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1802 | |
| 1803 | return view->webview(); |
| 1804 | } |
| 1805 | |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1806 | WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1807 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1808 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1809 | popup_type); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1810 | return widget->webwidget(); |
| 1811 | } |
| 1812 | |
| 1813 | WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) { |
| 1814 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1815 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1816 | WebKit::WebPopupTypeSelect); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1817 | widget->ConfigureAsExternalPopupMenu(info); |
| 1818 | return widget->webwidget(); |
| 1819 | } |
| 1820 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 1821 | WebWidget* RenderView::createFullscreenWindow(WebKit::WebPopupType popup_type) { |
| 1822 | RenderWidget* widget = RenderWidgetFullscreen::Create(routing_id_, |
| 1823 | render_thread_, |
| 1824 | popup_type); |
| 1825 | return widget->webwidget(); |
| 1826 | } |
| 1827 | |
[email protected] | 79c7bed | 2010-09-14 22:28:39 | [diff] [blame] | 1828 | pepper::FullscreenContainer* RenderView::CreatePepperFullscreenContainer( |
| 1829 | pepper::PluginInstance* plugin) { |
| 1830 | RenderWidgetFullscreenPepper* widget = |
| 1831 | RenderWidgetFullscreenPepper::Create(routing_id_, render_thread_, plugin); |
| 1832 | widget->show(WebKit::WebNavigationPolicyIgnore); |
| 1833 | return widget->container(); |
| 1834 | } |
| 1835 | |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1836 | WebStorageNamespace* RenderView::createSessionStorageNamespace(unsigned quota) { |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1837 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
[email protected] | 68c50e5 | 2010-05-12 11:14:39 | [diff] [blame] | 1838 | return WebStorageNamespace::createSessionStorageNamespace(quota); |
[email protected] | 59afea1 | 2010-01-20 04:48:29 | [diff] [blame] | 1839 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
| 1840 | return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION, |
| 1841 | session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1842 | } |
| 1843 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1844 | void RenderView::didAddMessageToConsole( |
| 1845 | const WebConsoleMessage& message, const WebString& source_name, |
| 1846 | unsigned source_line) { |
| 1847 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
| 1848 | UTF16ToWideHack(message.text), |
| 1849 | static_cast<int32>(source_line), |
| 1850 | UTF16ToWideHack(source_name))); |
| 1851 | } |
| 1852 | |
| 1853 | void RenderView::printPage(WebFrame* frame) { |
[email protected] | 71a1426 | 2009-09-22 20:02:58 | [diff] [blame] | 1854 | DCHECK(frame); |
| 1855 | Print(frame, true); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1856 | } |
| 1857 | |
[email protected] | 3354d3e | 2010-06-10 19:53:02 | [diff] [blame] | 1858 | WebKit::WebNotificationPresenter* RenderView::notificationPresenter() { |
| 1859 | return notification_provider_.get(); |
| 1860 | } |
| 1861 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1862 | void RenderView::didStartLoading() { |
| 1863 | if (is_loading_) { |
| 1864 | DLOG(WARNING) << "didStartLoading called while loading"; |
| 1865 | return; |
| 1866 | } |
| 1867 | |
| 1868 | is_loading_ = true; |
| 1869 | // Clear the pointer so that we can assign it only when there is an unknown |
| 1870 | // plugin on a page. |
| 1871 | first_default_plugin_.reset(); |
| 1872 | |
| 1873 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
| 1874 | } |
| 1875 | |
| 1876 | void RenderView::didStopLoading() { |
| 1877 | if (!is_loading_) { |
| 1878 | DLOG(WARNING) << "DidStopLoading called while not loading"; |
| 1879 | return; |
| 1880 | } |
| 1881 | |
| 1882 | is_loading_ = false; |
| 1883 | |
| 1884 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1885 | // when done loading. This currently isn't an issue as the favicon is only |
| 1886 | // displayed when done loading. Ideally we would send notification when |
| 1887 | // finished parsing the head, but webkit doesn't support that yet. |
| 1888 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1889 | GURL favicon_url(webview()->mainFrame()->favIconURL()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1890 | if (!favicon_url.is_empty()) |
| 1891 | Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url)); |
| 1892 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1893 | AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(), |
[email protected] | 2de7e00 | 2010-10-11 22:58:20 | [diff] [blame] | 1894 | ViewHostMsg_PageHasOSDD_Type::Autodetected()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1895 | |
| 1896 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1897 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 1898 | MessageLoop::current()->PostDelayedTask( |
| 1899 | FROM_HERE, |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1900 | page_info_method_factory_.NewRunnableMethod( |
| 1901 | &RenderView::CapturePageInfo, page_id_, false), |
[email protected] | 5ddfd63e | 2010-09-01 15:48:37 | [diff] [blame] | 1902 | send_content_state_immediately_ ? 0 : kDelayForCaptureMs); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1903 | } |
| 1904 | |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 1905 | bool RenderView::isSmartInsertDeleteEnabled() { |
| 1906 | #if defined(OS_MACOSX) |
| 1907 | return true; |
| 1908 | #else |
| 1909 | return false; |
| 1910 | #endif |
| 1911 | } |
| 1912 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1913 | bool RenderView::isSelectTrailingWhitespaceEnabled() { |
| 1914 | #if defined(OS_WIN) |
| 1915 | return true; |
| 1916 | #else |
| 1917 | return false; |
| 1918 | #endif |
| 1919 | } |
| 1920 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1921 | void RenderView::didChangeSelection(bool is_empty_selection) { |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 1922 | #if defined(USE_X11) || defined(OS_MACOSX) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1923 | if (!handling_input_event_) |
| 1924 | return; |
| 1925 | // TODO(estade): investigate incremental updates to the selection so that we |
| 1926 | // don't send the entire selection over IPC every time. |
| 1927 | if (!is_empty_selection) { |
| 1928 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 1929 | // the selection hasn't actually changed. We don't want to report these |
| 1930 | // because it will cause us to continually claim the X clipboard. |
| 1931 | const std::string& this_selection = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1932 | webview()->focusedFrame()->selectionAsText().utf8(); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1933 | if (this_selection == last_selection_) |
| 1934 | return; |
| 1935 | |
| 1936 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 1937 | this_selection)); |
| 1938 | last_selection_ = this_selection; |
| 1939 | } else { |
| 1940 | last_selection_.clear(); |
[email protected] | eef99c2 | 2010-08-17 05:55:16 | [diff] [blame] | 1941 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 1942 | last_selection_)); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1943 | } |
| 1944 | #endif |
| 1945 | } |
| 1946 | |
| 1947 | void RenderView::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1948 | const std::string& name = UTF16ToUTF8(command_name); |
| 1949 | if (StartsWithASCII(name, "Move", true) || |
| 1950 | StartsWithASCII(name, "Insert", true) || |
| 1951 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1952 | return; |
| 1953 | UserMetricsRecordAction(name); |
| 1954 | } |
| 1955 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1956 | void RenderView::textFieldDidEndEditing( |
| 1957 | const WebKit::WebInputElement& element) { |
| 1958 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1959 | password_autocomplete_manager_->TextFieldDidEndEditing(element); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1960 | #endif |
| 1961 | } |
| 1962 | |
| 1963 | void RenderView::textFieldDidChange(const WebKit::WebInputElement& element) { |
| 1964 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1965 | // We post a task for doing the AutoFill as the caret position is not set |
| 1966 | // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and |
| 1967 | // it is needed to trigger autofill. |
| 1968 | autofill_method_factory_.RevokeAll(); |
| 1969 | MessageLoop::current()->PostTask( |
| 1970 | FROM_HERE, |
| 1971 | autofill_method_factory_.NewRunnableMethod( |
| 1972 | &RenderView::TextFieldDidChangeImpl, element)); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 1973 | #endif |
| 1974 | } |
| 1975 | |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1976 | void RenderView::TextFieldDidChangeImpl( |
| 1977 | const WebKit::WebInputElement& element) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1978 | if (password_autocomplete_manager_->TextDidChangeInTextField(element)) |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1979 | return; |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 1980 | autofill_helper_->TextDidChangeInTextField(element); |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 1981 | } |
| 1982 | |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 1983 | void RenderView::SendPendingAccessibilityNotifications() { |
| 1984 | if (!accessibility_.get()) |
| 1985 | return; |
| 1986 | |
| 1987 | if (pending_accessibility_notifications_.empty()) |
| 1988 | return; |
| 1989 | |
| 1990 | // Send all pending accessibility notifications. |
| 1991 | std::vector<ViewHostMsg_AccessibilityNotification_Params> notifications; |
| 1992 | for (size_t i = 0; i < pending_accessibility_notifications_.size(); i++) { |
| 1993 | RendererAccessibilityNotification& notification = |
| 1994 | pending_accessibility_notifications_[i]; |
| 1995 | WebAccessibilityObject obj = accessibility_->getObjectById(notification.id); |
| 1996 | if (!obj.isValid()) |
| 1997 | continue; |
| 1998 | |
| 1999 | ViewHostMsg_AccessibilityNotification_Params param; |
| 2000 | param.notification_type = pending_accessibility_notifications_[i].type; |
| 2001 | param.acc_obj = WebAccessibility(obj, accessibility_.get()); |
| 2002 | notifications.push_back(param); |
| 2003 | } |
| 2004 | pending_accessibility_notifications_.clear(); |
| 2005 | Send(new ViewHostMsg_AccessibilityNotifications(routing_id_, notifications)); |
| 2006 | accessibility_ack_pending_ = true; |
| 2007 | } |
| 2008 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2009 | void RenderView::textFieldDidReceiveKeyDown( |
| 2010 | const WebKit::WebInputElement& element, |
| 2011 | const WebKit::WebKeyboardEvent& event) { |
| 2012 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2013 | password_autocomplete_manager_->TextFieldHandlingKeyDown(element, event); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2014 | #endif |
| 2015 | } |
| 2016 | |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2017 | bool RenderView::handleCurrentKeyboardEvent() { |
| 2018 | if (edit_commands_.empty()) |
| 2019 | return false; |
| 2020 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2021 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2022 | if (!frame) |
| 2023 | return false; |
| 2024 | |
| 2025 | EditCommands::iterator it = edit_commands_.begin(); |
| 2026 | EditCommands::iterator end = edit_commands_.end(); |
| 2027 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2028 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2029 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 2030 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 2031 | // key (but it's the exception). Once one edit command is not executed, it |
| 2032 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2033 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 2034 | WebString::fromUTF8(it->value))) |
| 2035 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2036 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2037 | } |
| 2038 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 2039 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 2040 | } |
| 2041 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2042 | void RenderView::spellCheck(const WebString& text, |
| 2043 | int& misspelled_offset, |
| 2044 | int& misspelled_length) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2045 | EnsureDocumentTag(); |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 2046 | |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 2047 | string16 word(text); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2048 | RenderThread* thread = RenderThread::current(); |
| 2049 | // Will be NULL during unit tests. |
| 2050 | if (thread) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2051 | thread->spellchecker()->SpellCheckWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2052 | word.c_str(), word.size(), document_tag_, |
| 2053 | &misspelled_offset, &misspelled_length, NULL); |
| 2054 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | WebString RenderView::autoCorrectWord(const WebKit::WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2058 | string16 autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2059 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | b86c8c1 | 2009-10-05 22:01:26 | [diff] [blame] | 2060 | if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2061 | EnsureDocumentTag(); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2062 | RenderThread* thread = RenderThread::current(); |
| 2063 | // Will be NULL during unit tests. |
| 2064 | if (thread) { |
| 2065 | autocorrect_word = |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2066 | thread->spellchecker()->GetAutoCorrectionWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 2067 | word, document_tag_); |
| 2068 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2069 | } |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2070 | return autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2071 | } |
| 2072 | |
[email protected] | c49085c7 | 2009-10-02 16:28:56 | [diff] [blame] | 2073 | void RenderView::showSpellingUI(bool show) { |
| 2074 | Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show)); |
| 2075 | } |
| 2076 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2077 | bool RenderView::isShowingSpellingUI() { |
| 2078 | return spelling_panel_visible_; |
| 2079 | } |
| 2080 | |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2081 | void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 2082 | Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
| 2083 | word)); |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 2084 | } |
| 2085 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2086 | bool RenderView::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 2087 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2088 | WebFileChooserCompletion* chooser_completion) { |
| 2089 | ViewHostMsg_RunFileChooser_Params ipc_params; |
[email protected] | b5977a0c | 2010-08-24 19:46:26 | [diff] [blame] | 2090 | if (params.directory) |
| 2091 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenFolder; |
| 2092 | else if (params.multiSelect) |
| 2093 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::OpenMultiple; |
| 2094 | else |
| 2095 | ipc_params.mode = ViewHostMsg_RunFileChooser_Params::Open; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2096 | ipc_params.title = params.title; |
| 2097 | ipc_params.default_file_name = |
| 2098 | webkit_glue::WebStringToFilePath(params.initialValue); |
[email protected] | 09994913 | 2010-09-08 20:24:59 | [diff] [blame] | 2099 | ipc_params.accept_types = params.acceptTypes; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2100 | |
| 2101 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 2102 | } |
| 2103 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2104 | void RenderView::runModalAlertDialog( |
| 2105 | WebFrame* frame, const WebString& message) { |
| 2106 | RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert, |
| 2107 | UTF16ToWideHack(message), |
| 2108 | std::wstring(), |
| 2109 | frame->url(), |
| 2110 | NULL); |
| 2111 | } |
| 2112 | |
| 2113 | bool RenderView::runModalConfirmDialog( |
| 2114 | WebFrame* frame, const WebString& message) { |
| 2115 | return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm, |
| 2116 | UTF16ToWideHack(message), |
| 2117 | std::wstring(), |
| 2118 | frame->url(), |
| 2119 | NULL); |
| 2120 | } |
| 2121 | |
| 2122 | bool RenderView::runModalPromptDialog( |
| 2123 | WebFrame* frame, const WebString& message, const WebString& default_value, |
| 2124 | WebString* actual_value) { |
| 2125 | std::wstring result; |
| 2126 | bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt, |
| 2127 | UTF16ToWideHack(message), |
| 2128 | UTF16ToWideHack(default_value), |
| 2129 | frame->url(), |
| 2130 | &result); |
| 2131 | if (ok) |
| 2132 | actual_value->assign(WideToUTF16Hack(result)); |
| 2133 | return ok; |
| 2134 | } |
| 2135 | |
| 2136 | bool RenderView::runModalBeforeUnloadDialog( |
| 2137 | WebFrame* frame, const WebString& message) { |
| 2138 | bool success = false; |
| 2139 | // This is an ignored return value, but is included so we can accept the same |
| 2140 | // response as RunJavaScriptMessage. |
| 2141 | std::wstring ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2142 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2143 | routing_id_, frame->url(), UTF16ToWideHack(message), &success, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2144 | &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2145 | return success; |
| 2146 | } |
| 2147 | |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2148 | void RenderView::showContextMenu( |
| 2149 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2150 | ContextMenuParams params = ContextMenuParams(data); |
| 2151 | if (!params.misspelled_word.empty() && RenderThread::current()) { |
| 2152 | int misspelled_offset, misspelled_length; |
[email protected] | c76a36a | 2010-01-26 22:44:04 | [diff] [blame] | 2153 | bool spelled_right = RenderThread::current()->spellchecker()-> |
| 2154 | SpellCheckWord( |
| 2155 | params.misspelled_word.c_str(), params.misspelled_word.size(), |
| 2156 | document_tag_, |
| 2157 | &misspelled_offset, &misspelled_length, |
| 2158 | ¶ms.dictionary_suggestions); |
| 2159 | if (spelled_right) |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2160 | params.misspelled_word.clear(); |
| 2161 | } |
[email protected] | 216932c | 2010-08-26 21:44:27 | [diff] [blame] | 2162 | // Serializing a GURL longer than chrome::kMaxURLChars will fail, so don't do |
| 2163 | // it. We replace it with an empty GURL so the appropriate items are disabled |
| 2164 | // in the context menu. |
| 2165 | // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large |
| 2166 | // data encoded images. We should have a way to save them. |
| 2167 | if (params.src_url.spec().size() > chrome::kMaxURLChars) |
| 2168 | params.src_url = GURL(); |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2169 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 2170 | } |
| 2171 | |
[email protected] | 52f139e2c | 2010-06-11 16:56:09 | [diff] [blame] | 2172 | bool RenderView::supportsFullscreen() { |
| 2173 | return CommandLine::ForCurrentProcess()->HasSwitch( |
| 2174 | switches::kEnableVideoFullscreen); |
| 2175 | } |
| 2176 | |
| 2177 | void RenderView::enterFullscreenForNode(const WebKit::WebNode& node) { |
| 2178 | NOTIMPLEMENTED(); |
| 2179 | } |
| 2180 | |
| 2181 | void RenderView::exitFullscreenForNode(const WebKit::WebNode& node) { |
| 2182 | NOTIMPLEMENTED(); |
| 2183 | } |
| 2184 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2185 | void RenderView::setStatusText(const WebString& text) { |
| 2186 | } |
| 2187 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2188 | void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 2189 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2190 | if (latest_url == target_url_) |
| 2191 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2192 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2193 | // Tell the browser to display a destination link. |
| 2194 | if (target_url_status_ == TARGET_INFLIGHT || |
| 2195 | target_url_status_ == TARGET_PENDING) { |
| 2196 | // If we have a request in-flight, save the URL to be sent when we |
| 2197 | // receive an ACK to the in-flight request. We can happily overwrite |
| 2198 | // any existing pending sends. |
| 2199 | pending_target_url_ = latest_url; |
| 2200 | target_url_status_ = TARGET_PENDING; |
| 2201 | } else { |
| 2202 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 2203 | target_url_ = latest_url; |
| 2204 | target_url_status_ = TARGET_INFLIGHT; |
| 2205 | } |
| 2206 | } |
| 2207 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2208 | void RenderView::StartNavStateSyncTimerIfNecessary() { |
| 2209 | int delay; |
| 2210 | if (send_content_state_immediately_) |
| 2211 | delay = 0; |
| 2212 | else if (is_hidden()) |
| 2213 | delay = kDelaySecondsForContentStateSyncHidden; |
| 2214 | else |
| 2215 | delay = kDelaySecondsForContentStateSync; |
| 2216 | |
| 2217 | if (nav_state_sync_timer_.IsRunning()) { |
| 2218 | // The timer is already running. If the delay of the timer maches the amount |
| 2219 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 2220 | // gets started with the right delay. |
| 2221 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 2222 | return; |
| 2223 | nav_state_sync_timer_.Stop(); |
| 2224 | } |
| 2225 | |
| 2226 | nav_state_sync_timer_.Start( |
| 2227 | TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState); |
| 2228 | } |
| 2229 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 2230 | void RenderView::setMouseOverURL(const WebURL& url) { |
| 2231 | mouse_over_url_ = GURL(url); |
| 2232 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 2233 | } |
| 2234 | |
| 2235 | void RenderView::setKeyboardFocusURL(const WebURL& url) { |
| 2236 | focus_url_ = GURL(url); |
| 2237 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 2238 | } |
| 2239 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2240 | void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) { |
| 2241 | Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text), |
| 2242 | hint)); |
| 2243 | } |
| 2244 | |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2245 | void RenderView::startDragging(const WebDragData& data, |
| 2246 | WebDragOperationsMask mask, |
| 2247 | const WebImage& image, |
| 2248 | const WebPoint& imageOffset) { |
| 2249 | #if WEBKIT_USING_SKIA |
| 2250 | SkBitmap bitmap(image.getSkBitmap()); |
| 2251 | #elif WEBKIT_USING_CG |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 2252 | SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2253 | #endif |
| 2254 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2255 | Send(new ViewHostMsg_StartDragging(routing_id_, |
| 2256 | WebDropData(data), |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 2257 | mask, |
| 2258 | bitmap, |
| 2259 | imageOffset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2260 | } |
| 2261 | |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 2262 | bool RenderView::acceptsLoadDrops() { |
| 2263 | return renderer_preferences_.can_accept_load_drops; |
| 2264 | } |
| 2265 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2266 | void RenderView::focusNext() { |
| 2267 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 2268 | } |
| 2269 | |
| 2270 | void RenderView::focusPrevious() { |
| 2271 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 2272 | } |
| 2273 | |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2274 | void RenderView::focusedNodeChanged(const WebNode& node) { |
| 2275 | Send(new ViewHostMsg_FocusedNodeChanged(routing_id_)); |
[email protected] | a4b103b | 2010-10-05 18:46:07 | [diff] [blame] | 2276 | |
| 2277 | if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { |
| 2278 | // TODO(ctguil): Make WebKit send this notification. |
| 2279 | // When focus is cleared notify accessibility that the document is focused. |
| 2280 | postAccessibilityNotification( |
| 2281 | webview()->accessibilityObject(), |
| 2282 | WebKit::WebAccessibilityNotificationFocusedUIElementChanged); |
| 2283 | } |
[email protected] | 08e9e13 | 2010-06-01 16:58:49 | [diff] [blame] | 2284 | } |
| 2285 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2286 | void RenderView::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2287 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2288 | } |
| 2289 | |
| 2290 | int RenderView::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2291 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | int RenderView::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2295 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2296 | } |
| 2297 | |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2298 | void RenderView::didUpdateInspectorSetting(const WebString& key, |
| 2299 | const WebString& value) { |
| 2300 | Send(new ViewHostMsg_UpdateInspectorSetting(routing_id_, |
| 2301 | key.utf8(), |
| 2302 | value.utf8())); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2303 | } |
| 2304 | |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 2305 | void RenderView::queryAutofillSuggestions(const WebNode& node, |
| 2306 | const WebString& name, |
| 2307 | const WebString& value) { |
[email protected] | a5e84bd | 2010-09-14 22:23:36 | [diff] [blame] | 2308 | autofill_helper_->QueryAutoFillSuggestions(node); |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | void RenderView::removeAutofillSuggestions(const WebString& name, |
| 2312 | const WebString& value) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2313 | autofill_helper_->RemoveAutocompleteSuggestion(name, value); |
[email protected] | acca2a1 | 2009-10-16 03:53:39 | [diff] [blame] | 2314 | } |
| 2315 | |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2316 | void RenderView::didAcceptAutoFillSuggestion(const WebKit::WebNode& node, |
| 2317 | const WebKit::WebString& value, |
[email protected] | 1cf47dd5 | 2010-06-10 22:41:20 | [diff] [blame] | 2318 | const WebKit::WebString& label, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 2319 | int unique_id, |
[email protected] | 1cf47dd5 | 2010-06-10 22:41:20 | [diff] [blame] | 2320 | unsigned index) { |
[email protected] | a5e84bd | 2010-09-14 22:23:36 | [diff] [blame] | 2321 | autofill_helper_->DidAcceptAutoFillSuggestion(node, value, unique_id, index); |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2322 | } |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2323 | |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2324 | void RenderView::didSelectAutoFillSuggestion(const WebKit::WebNode& node, |
| 2325 | const WebKit::WebString& value, |
[email protected] | 0a05545 | 2010-07-16 17:34:39 | [diff] [blame] | 2326 | const WebKit::WebString& label, |
| 2327 | int unique_id) { |
[email protected] | a5e84bd | 2010-09-14 22:23:36 | [diff] [blame] | 2328 | autofill_helper_->DidSelectAutoFillSuggestion(node, unique_id); |
[email protected] | 18ca9a6b | 2010-06-02 19:05:18 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | void RenderView::didClearAutoFillSelection(const WebKit::WebNode& node) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2332 | autofill_helper_->DidClearAutoFillSelection(node); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2333 | } |
| 2334 | |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2335 | void RenderView::didAcceptAutocompleteSuggestion( |
| 2336 | const WebKit::WebInputElement& user_element) { |
| 2337 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2338 | bool result = password_autocomplete_manager_->FillPassword(user_element); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 2339 | // Since this user name was selected from a suggestion list, we should always |
| 2340 | // have password for it. |
| 2341 | DCHECK(result); |
| 2342 | #endif |
| 2343 | } |
| 2344 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2345 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2346 | |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 2347 | void RenderView::didFocus() { |
| 2348 | // TODO(jcivelli): when https://bugs.webkit.org/show_bug.cgi?id=33389 is fixed |
| 2349 | // we won't have to test for user gesture anymore and we can |
| 2350 | // move that code back to render_widget.cc |
| 2351 | if (webview() && webview()->mainFrame() && |
| 2352 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2353 | Send(new ViewHostMsg_Focus(routing_id_)); |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | void RenderView::didBlur() { |
| 2358 | // TODO(jcivelli): see TODO above in didFocus(). |
| 2359 | if (webview() && webview()->mainFrame() && |
| 2360 | webview()->mainFrame()->isProcessingUserGesture()) { |
| 2361 | Send(new ViewHostMsg_Blur(routing_id_)); |
| 2362 | } |
| 2363 | } |
| 2364 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2365 | // We are supposed to get a single call to Show for a newly created RenderView |
| 2366 | // that was created via RenderView::CreateWebView. So, we wait until this |
| 2367 | // point to dispatch the ShowView message. |
| 2368 | // |
| 2369 | // This method provides us with the information about how to display the newly |
| 2370 | // created RenderView (i.e., as a constrained popup or as a new tab). |
| 2371 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2372 | void RenderView::show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2373 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 2374 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2375 | |
| 2376 | if (did_show_) |
| 2377 | return; |
| 2378 | did_show_ = true; |
| 2379 | |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 2380 | // Extensions and apps always allowed to create unrequested popups. The second |
| 2381 | // check is necessary to include content scripts. |
| 2382 | if (ExtensionRendererInfo::GetByURL(creator_url_) || |
| 2383 | bindings_utils::GetInfoForCurrentContext()) { |
| 2384 | opened_by_user_gesture_ = true; |
| 2385 | } |
| 2386 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2387 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2388 | if (!opened_by_user_gesture_) { |
| 2389 | // We exempt background tabs for compat with older versions of Chrome. |
| 2390 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2391 | // we probably don't need this check. |
| 2392 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2393 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2394 | } |
| 2395 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2396 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2397 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2398 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2399 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2400 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2401 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2402 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2403 | } |
| 2404 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2405 | void RenderView::closeWidgetSoon() { |
[email protected] | 7faa5386 | 2010-06-16 00:09:13 | [diff] [blame] | 2406 | // Cancel pending translations so that the translate_helper_ does not attempt |
| 2407 | // to access the WebView. |
| 2408 | translate_helper_.CancelPendingTranslation(); |
| 2409 | |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 2410 | if (script_can_close_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2411 | RenderWidget::closeWidgetSoon(); |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 2412 | } |
| 2413 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2414 | void RenderView::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2415 | DCHECK(did_show_) << "should already have shown the view"; |
| 2416 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2417 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2418 | // showModalDialog to function properly. |
| 2419 | // |
| 2420 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2421 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2422 | // handed manner. |
| 2423 | // |
| 2424 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 2425 | RenderThread::current()->DoNotSuspendWebKitSharedTimer(); |
| 2426 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2427 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2428 | } |
| 2429 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2430 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2431 | |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 2432 | WebPlugin* RenderView::createPlugin(WebFrame* frame, |
| 2433 | const WebPluginParams& params) { |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2434 | bool found = false; |
| 2435 | ContentSetting setting = CONTENT_SETTING_DEFAULT; |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2436 | CommandLine* cmd = CommandLine::ForCurrentProcess(); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2437 | WebPluginInfo info; |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2438 | GURL url(params.url); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2439 | std::string actual_mime_type; |
| 2440 | Send(new ViewHostMsg_GetPluginInfo(url, |
| 2441 | frame->top()->url(), |
| 2442 | params.mimeType.utf8(), |
| 2443 | &found, |
| 2444 | &info, |
| 2445 | &setting, |
| 2446 | &actual_mime_type)); |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 2447 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2448 | if (!found) |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 2449 | return NULL; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2450 | DCHECK(setting != CONTENT_SETTING_DEFAULT); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 2451 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2452 | scoped_ptr<PluginGroup> group(PluginGroup::CopyOrCreatePluginGroup(info)); |
| 2453 | group->AddPlugin(info, 0); |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2454 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2455 | if (!info.enabled) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2456 | if (cmd->HasSwitch(switches::kDisableOutdatedPlugins) && |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2457 | group->IsVulnerable()) { |
| 2458 | Send(new ViewHostMsg_DisabledOutdatedPlugin(routing_id_, |
| 2459 | group->GetGroupName(), |
| 2460 | GURL(group->GetUpdateURL()))); |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 2461 | return CreateOutdatedPluginPlaceholder(frame, params, group.get()); |
[email protected] | 851b1eb | 2010-08-09 13:32:29 | [diff] [blame] | 2462 | } |
| 2463 | return NULL; |
| 2464 | } |
| 2465 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2466 | if (info.path.value() == kDefaultPluginLibraryName || |
| 2467 | setting == CONTENT_SETTING_ALLOW) { |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2468 | scoped_refptr<pepper::PluginModule> pepper_module = |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2469 | PepperPluginRegistry::GetInstance()->GetModule(info.path); |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2470 | if (pepper_module) { |
| 2471 | return CreatePepperPlugin(frame, |
| 2472 | params, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2473 | info.path, |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2474 | pepper_module.get()); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 2475 | } |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2476 | return CreateNPAPIPlugin(frame, params, info.path, actual_mime_type); |
[email protected] | 0cdafff | 2010-07-26 09:54:37 | [diff] [blame] | 2477 | } |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2478 | std::string resource; |
| 2479 | if (cmd->HasSwitch(switches::kEnableResourceContentSettings)) |
| 2480 | resource = group->identifier(); |
| 2481 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, resource); |
| 2482 | int resource_id; |
| 2483 | int message_id; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 2484 | if (setting == CONTENT_SETTING_ASK) { |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 2485 | resource_id = IDR_BLOCKED_PLUGIN_HTML; |
| 2486 | message_id = IDS_PLUGIN_LOAD; |
| 2487 | } else { |
| 2488 | resource_id = IDR_OUTDATED_PLUGIN_HTML; |
| 2489 | message_id = IDS_PLUGIN_BLOCKED; |
| 2490 | } |
| 2491 | // |blocked_plugin| will delete itself when the WebViewPlugin |
| 2492 | // is destroyed. |
| 2493 | BlockedPlugin* blocked_plugin = |
| 2494 | new BlockedPlugin(this, |
| 2495 | frame, |
| 2496 | params, |
| 2497 | webkit_preferences_, |
| 2498 | resource_id, |
| 2499 | l10n_util::GetStringUTF16(message_id)); |
| 2500 | return blocked_plugin->plugin(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { |
[email protected] | 14396e9 | 2010-05-06 20:40:56 | [diff] [blame] | 2504 | WebApplicationCacheHostImpl* appcache_host = |
| 2505 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2506 | int appcache_host_id = appcache_host ? appcache_host->host_id() : 0; |
| 2507 | return new WebWorkerProxy(client, RenderThread::current(), routing_id_, |
| 2508 | appcache_host_id); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2509 | } |
| 2510 | |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2511 | WebSharedWorker* RenderView::createSharedWorker( |
| 2512 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2513 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2514 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2515 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2516 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2517 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2518 | ViewHostMsg_CreateWorker_Params params; |
| 2519 | params.url = url; |
| 2520 | params.is_shared = true; |
| 2521 | params.name = name; |
| 2522 | params.document_id = document_id; |
| 2523 | params.render_view_route_id = routing_id_; |
| 2524 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | f9bc9c0 | 2010-05-24 19:19:23 | [diff] [blame] | 2525 | params.parent_appcache_host_id = 0; |
| 2526 | params.script_resource_appcache_id = 0; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2527 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2528 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2529 | if (url_mismatch) { |
| 2530 | return NULL; |
| 2531 | } else { |
| 2532 | return new WebSharedWorkerProxy(RenderThread::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2533 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2534 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2535 | route_id, |
| 2536 | routing_id_); |
| 2537 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2538 | } |
| 2539 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2540 | WebMediaPlayer* RenderView::createMediaPlayer( |
| 2541 | WebFrame* frame, WebMediaPlayerClient* client) { |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame^] | 2542 | media::MediaFilterCollection collection; |
| 2543 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2544 | // Add in any custom filter factories first. |
| 2545 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 2546 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
| 2547 | // Add the chrome specific audio renderer. |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame^] | 2548 | collection.push_back(new AudioRendererImpl(audio_message_filter())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2549 | } |
| 2550 | |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 2551 | if (cmd_line->HasSwitch(switches::kEnableAcceleratedDecoding) && |
[email protected] | 11c4c81 | 2010-10-22 19:50:12 | [diff] [blame] | 2552 | !cmd_line->HasSwitch(switches::kDisableAcceleratedCompositing)) { |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 2553 | // Add the hardware video decoder factory. |
| 2554 | // TODO(hclam): This assumes that ggl::Context is set to current |
| 2555 | // internally. I need to make it more explicit to get the context. |
| 2556 | bool ret = frame->view()->graphicsContext3D()->makeContextCurrent(); |
| 2557 | CHECK(ret) << "Failed to switch context"; |
| 2558 | |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame^] | 2559 | collection.push_back(new IpcVideoDecoder( |
[email protected] | 885ff1df | 2010-10-07 21:47:58 | [diff] [blame] | 2560 | MessageLoop::current(), ggl::GetCurrentContext())); |
[email protected] | 3bb0860 | 2010-10-07 21:47:17 | [diff] [blame] | 2561 | } |
| 2562 | |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2563 | WebApplicationCacheHostImpl* appcache_host = |
| 2564 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2565 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2566 | // TODO(hclam): obtain the following parameters from |client|. |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame^] | 2567 | // Create two bridge factory for two data sources. |
| 2568 | webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_simple = |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2569 | new webkit_glue::MediaResourceLoaderBridgeFactory( |
[email protected] | 7509760e3 | 2010-10-08 21:54:25 | [diff] [blame] | 2570 | GURL(frame->url()), // referrer |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 2571 | "null", // frame origin |
| 2572 | "null", // main_frame_origin |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2573 | base::GetCurrentProcId(), |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2574 | appcache_host ? appcache_host->host_id() : appcache::kNoHostId, |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2575 | routing_id()); |
| 2576 | |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame^] | 2577 | webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_buffered = |
| 2578 | new webkit_glue::MediaResourceLoaderBridgeFactory( |
| 2579 | GURL(frame->url()), // referrer |
| 2580 | "null", // frame origin |
| 2581 | "null", // main_frame_origin |
| 2582 | base::GetCurrentProcId(), |
| 2583 | appcache_host ? appcache_host->host_id() : appcache::kNoHostId, |
| 2584 | routing_id()); |
| 2585 | |
| 2586 | scoped_refptr<webkit_glue::WebVideoRenderer> video_renderer; |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2587 | if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) { |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame^] | 2588 | scoped_refptr<IPCVideoRenderer> renderer = |
| 2589 | new IPCVideoRenderer(routing_id_); |
| 2590 | collection.push_back(renderer); |
| 2591 | video_renderer = renderer; |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2592 | } else { |
[email protected] | b57509eb | 2010-03-30 01:26:28 | [diff] [blame] | 2593 | bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging); |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame^] | 2594 | scoped_refptr<webkit_glue::VideoRendererImpl> renderer = |
| 2595 | new webkit_glue::VideoRendererImpl(pts_logging); |
| 2596 | collection.push_back(renderer); |
| 2597 | video_renderer = renderer; |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2598 | } |
| 2599 | |
[email protected] | 5b5bb9d | 2010-10-22 19:57:36 | [diff] [blame] | 2600 | return new webkit_glue::WebMediaPlayerImpl( |
[email protected] | 457d834 | 2010-10-23 01:20:37 | [diff] [blame^] | 2601 | client, collection, bridge_factory_simple, bridge_factory_buffered, |
| 2602 | cmd_line->HasSwitch(switches::kSimpleDataSource),video_renderer); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2603 | } |
| 2604 | |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2605 | WebApplicationCacheHost* RenderView::createApplicationCacheHost( |
| 2606 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
| 2607 | return new RendererWebApplicationCacheHostImpl( |
| 2608 | FromWebView(frame->view()), client, |
| 2609 | RenderThread::current()->appcache_dispatcher()->backend_proxy()); |
| 2610 | } |
| 2611 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 2612 | WebCookieJar* RenderView::cookieJar() { |
| 2613 | return &cookie_jar_; |
| 2614 | } |
| 2615 | |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2616 | void RenderView::frameDetached(WebFrame* frame) { |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2617 | autofill_helper_->FrameDetached(frame); |
| 2618 | page_click_tracker_->StopTrackingFrame(frame, true); |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2619 | } |
| 2620 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2621 | void RenderView::willClose(WebFrame* frame) { |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2622 | WebDataSource* ds = frame->dataSource(); |
| 2623 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2624 | |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 2625 | if (!frame->parent()) { |
| 2626 | const GURL& url = frame->url(); |
| 2627 | // Ensure state contains scheme. |
| 2628 | if (url.SchemeIs("http")) |
| 2629 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP); |
| 2630 | else if (url.SchemeIs("https")) |
| 2631 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS); |
| 2632 | |
| 2633 | // Dump will only be provided when scheme is http or https. |
| 2634 | DumpLoadHistograms(); |
| 2635 | } |
| 2636 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2637 | navigation_state->user_script_idle_scheduler()->Cancel(); |
[email protected] | 174e60e | 2010-05-06 00:21:16 | [diff] [blame] | 2638 | |
[email protected] | 5041f98 | 2010-08-11 21:40:45 | [diff] [blame] | 2639 | // TODO(jhawkins): Remove once frameDetached is called by WebKit. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 2640 | autofill_helper_->FrameWillClose(frame); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2641 | } |
| 2642 | |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2643 | bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2644 | if (enabled_per_settings && |
| 2645 | AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) |
| 2646 | return true; |
| 2647 | |
| 2648 | if (IsWhitelistedForContentSettings(frame)) |
| 2649 | return true; |
| 2650 | |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 2651 | DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES, std::string()); |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2652 | return false; // Other protocols fall through here. |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2653 | } |
| 2654 | |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2655 | bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | a16a421 | 2010-09-01 08:07:46 | [diff] [blame] | 2656 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 2657 | switches::kDisableClickToPlay)) { |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2658 | return WebFrameClient::allowPlugins(frame, enabled_per_settings); |
| 2659 | } |
[email protected] | a16a421 | 2010-09-01 08:07:46 | [diff] [blame] | 2660 | return enabled_per_settings && |
| 2661 | AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS); |
[email protected] | d5f9e4f | 2010-07-28 08:31:30 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2665 | void RenderView::loadURLExternally( |
| 2666 | WebFrame* frame, const WebURLRequest& request, |
| 2667 | WebNavigationPolicy policy) { |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2668 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2669 | if (policy == WebKit::WebNavigationPolicyDownload) { |
| 2670 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); |
| 2671 | } else { |
| 2672 | OpenURL(request.url(), referrer, policy); |
| 2673 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | WebNavigationPolicy RenderView::decidePolicyForNavigation( |
| 2677 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 2678 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2679 | // Webkit is asking whether to navigate to a new URL. |
| 2680 | // This is fine normally, except if we're showing UI from one security |
| 2681 | // context and they're trying to navigate to a different context. |
| 2682 | const GURL& url = request.url(); |
| 2683 | |
| 2684 | // 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] | 2685 | // navigations. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2686 | if (renderer_preferences_.browser_handles_top_level_requests && |
| 2687 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2688 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
[email protected] | a58db8b | 2010-08-24 01:51:23 | [diff] [blame] | 2689 | // Reset these counters as the RenderView could be reused for the next |
| 2690 | // navigation. |
| 2691 | page_id_ = -1; |
[email protected] | a58db8b | 2010-08-24 01:51:23 | [diff] [blame] | 2692 | last_page_id_sent_to_browser_ = -1; |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2693 | OpenURL(url, referrer, default_policy); |
| 2694 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | // A content initiated navigation may have originated from a link-click, |
| 2698 | // script, drag-n-drop operation, etc. |
| 2699 | bool is_content_initiated = |
| 2700 | NavigationState::FromDataSource(frame->provisionalDataSource())-> |
| 2701 | is_content_initiated(); |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2702 | GURL old_url(frame->url()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2703 | |
| 2704 | // We only care about navigations that are within the current tab (as opposed |
| 2705 | // to, for example, opening a new window). |
| 2706 | // But we sometimes navigate to about:blank to clear a tab, and we want to |
| 2707 | // still allow that. |
| 2708 | if (default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2709 | is_content_initiated && frame->parent() == NULL && |
[email protected] | c240ace | 2010-06-16 18:31:53 | [diff] [blame] | 2710 | type != WebKit::WebNavigationTypeFormSubmitted && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2711 | !url.SchemeIs(chrome::kAboutScheme)) { |
| 2712 | // When we received such unsolicited navigations, we sometimes want to |
| 2713 | // punt them up to the browser to handle. |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2714 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) || |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2715 | frame->isViewSourceModeEnabled() || |
[email protected] | 918059b | 2010-05-25 17:08:42 | [diff] [blame] | 2716 | url.SchemeIs(chrome::kViewSourceScheme)) { |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2717 | // We don't send referrer from these special pages. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2718 | OpenURL(url, GURL(), default_policy); |
| 2719 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2720 | } |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2721 | |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2722 | // We forward non-local navigations from extensions to the browser if they |
| 2723 | // are top-level events, even if the browser hasn't expressed interest. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2724 | // TODO(erikkay) crbug.com/54118 - combine this clause and the next into |
| 2725 | // some shared logic. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2726 | if (BindingsPolicy::is_extension_enabled(enabled_bindings_) && |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2727 | old_url.SchemeIs(chrome::kExtensionScheme) && |
[email protected] | c240ace | 2010-06-16 18:31:53 | [diff] [blame] | 2728 | IsNonLocalTopLevelNavigation(url, frame, type)) { |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2729 | // We don't send referrer from extensions. |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 2730 | OpenURL(url, GURL(), default_policy); |
| 2731 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2732 | } |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 2733 | |
| 2734 | // If the navigation would cross an app extent boundary, we also need |
| 2735 | // to defer to the browser to ensure process isolation. |
| 2736 | // TODO(erikkay) This is happening inside of a check to is_content_initiated |
| 2737 | // which means that things like the back button won't trigger it. Is that |
| 2738 | // OK? |
| 2739 | if (CrossesExtensionExtents(frame, url)) { |
| 2740 | // Include the referrer in this case since we're going from a hosted web |
| 2741 | // page. (the packaged case is handled previously by the extension |
| 2742 | // navigation test) |
| 2743 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2744 | OpenURL(url, referrer, default_policy); |
| 2745 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2746 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2750 | // its own process. This is done by sites like Gmail that try to open links |
| 2751 | // in new windows without script connections back to the original page. We |
| 2752 | // treat such cases as browser navigations (in which we will create a new |
| 2753 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2754 | // |
| 2755 | // We use the following heuristic to decide whether to fork a new page in its |
| 2756 | // own process: |
| 2757 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2758 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2759 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2760 | // |
| 2761 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2762 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2763 | bool is_fork = |
| 2764 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | a6b960ad97 | 2010-09-01 19:53:58 | [diff] [blame] | 2765 | old_url == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2766 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2767 | historyBackListCount() < 1 && |
| 2768 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2769 | // The parent page must have set the child's window.opener to null before |
| 2770 | // redirecting to the desired URL. |
| 2771 | frame->opener() == NULL && |
| 2772 | // Must be a top-level frame. |
| 2773 | frame->parent() == NULL && |
| 2774 | // Must not have issued the request from this page. |
| 2775 | is_content_initiated && |
| 2776 | // Must be targeted at the current tab. |
| 2777 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2778 | // Must be a JavaScript navigation, which appears as "other". |
| 2779 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2780 | |
| 2781 | // Recognize if this navigation is from a link with rel=noreferrer and |
| 2782 | // target=_blank attributes, in which case the opener will be suppressed. If |
| 2783 | // so, it is safe to load cross-site pages in a separate process, so we |
| 2784 | // should let the browser handle it. |
| 2785 | bool is_noreferrer_and_blank_target = |
| 2786 | // Frame should be top level and not yet navigated. |
| 2787 | frame->parent() == NULL && |
| 2788 | frame->url().isEmpty() && |
| 2789 | historyBackListCount() < 1 && |
| 2790 | historyForwardListCount() < 1 && |
| 2791 | // Links with rel=noreferrer will have no Referer field, and their |
| 2792 | // resulting frame will have its window.opener suppressed. |
| 2793 | // TODO(creis): should add a request.httpReferrer() method to help avoid |
| 2794 | // typos on the unusual spelling of Referer. |
| 2795 | request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() && |
| 2796 | opener_suppressed_ && |
| 2797 | frame->opener() == NULL && |
| 2798 | // Links with target=_blank will have no name. |
| 2799 | frame->name().isNull() && |
| 2800 | // Another frame (with a non-empty creator) should have initiated the |
| 2801 | // request, targeted at this frame. |
| 2802 | !creator_url_.is_empty() && |
| 2803 | is_content_initiated && |
| 2804 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2805 | type == WebKit::WebNavigationTypeOther; |
| 2806 | |
| 2807 | if (is_fork || is_noreferrer_and_blank_target) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2808 | // Open the URL via the browser, not via WebKit. |
| 2809 | OpenURL(url, GURL(), default_policy); |
| 2810 | return WebKit::WebNavigationPolicyIgnore; |
| 2811 | } |
| 2812 | |
| 2813 | return default_policy; |
| 2814 | } |
| 2815 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2816 | bool RenderView::canHandleRequest( |
| 2817 | WebFrame* frame, const WebURLRequest& request) { |
| 2818 | // We allow WebKit to think that everything can be handled even though |
| 2819 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2820 | return true; |
| 2821 | } |
| 2822 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2823 | WebURLError RenderView::cannotHandleRequestError( |
| 2824 | WebFrame* frame, const WebURLRequest& request) { |
| 2825 | NOTREACHED(); // Since we said we can handle all requests. |
| 2826 | return WebURLError(); |
| 2827 | } |
| 2828 | |
| 2829 | WebURLError RenderView::cancelledError( |
| 2830 | WebFrame* frame, const WebURLRequest& request) { |
| 2831 | WebURLError error; |
| 2832 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2833 | error.reason = net::ERR_ABORTED; |
| 2834 | error.unreachableURL = request.url(); |
| 2835 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | void RenderView::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2839 | WebFrame*, const WebURLError&) { |
| 2840 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2841 | } |
| 2842 | |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2843 | void RenderView::willSendSubmitEvent(WebKit::WebFrame* frame, |
| 2844 | const WebKit::WebFormElement& form) { |
| 2845 | // Some login forms have onSubmit handlers that put a hash of the password |
| 2846 | // into a hidden field and then clear the password. (Issue 28910.) |
| 2847 | // This method gets called before any of those handlers run, so save away |
| 2848 | // a copy of the password in case it gets lost. |
| 2849 | NavigationState* navigation_state = |
| 2850 | NavigationState::FromDataSource(frame->dataSource()); |
| 2851 | navigation_state->set_password_form_data( |
| 2852 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 2853 | } |
| 2854 | |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 2855 | void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2856 | NavigationState* navigation_state = |
| 2857 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2858 | |
| 2859 | if (navigation_state->transition_type() == PageTransition::LINK) |
| 2860 | navigation_state->set_transition_type(PageTransition::FORM_SUBMIT); |
| 2861 | |
| 2862 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2863 | WebSearchableFormData web_searchable_form_data(form); |
| 2864 | navigation_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2865 | navigation_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2866 | web_searchable_form_data.encoding().utf8()); |
[email protected] | 90eeddb | 2010-05-06 21:06:43 | [diff] [blame] | 2867 | PasswordForm* password_form_data = |
| 2868 | PasswordFormDomManager::CreatePasswordForm(form); |
| 2869 | navigation_state->set_password_form_data(password_form_data); |
| 2870 | |
| 2871 | // If the password has been cleared, recover it from the form contents already |
| 2872 | // stored by willSendSubmitEvent into the dataSource's NavigationState (as |
| 2873 | // opposed to the provisionalDataSource's, which is what we're storing into |
| 2874 | // now.) |
| 2875 | if (password_form_data && password_form_data->password_value.empty()) { |
| 2876 | NavigationState* old_navigation_state = |
| 2877 | NavigationState::FromDataSource(frame->dataSource()); |
| 2878 | if (old_navigation_state) { |
| 2879 | PasswordForm* old_form_data = old_navigation_state->password_form_data(); |
| 2880 | if (old_form_data && old_form_data->action == password_form_data->action) |
| 2881 | password_form_data->password_value = old_form_data->password_value; |
| 2882 | } |
| 2883 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2884 | |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2885 | FormData form_data; |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 2886 | if (FormManager::WebFormElementToFormData( |
[email protected] | 1fa7b48 | 2010-10-01 18:28:58 | [diff] [blame] | 2887 | form, FormManager::REQUIRE_AUTOCOMPLETE, true, false, &form_data)) |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2888 | Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | void RenderView::willPerformClientRedirect( |
| 2892 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2893 | double fire_time) { |
| 2894 | // Ignore |
| 2895 | } |
| 2896 | |
| 2897 | void RenderView::didCancelClientRedirect(WebFrame* frame) { |
| 2898 | // Ignore |
| 2899 | } |
| 2900 | |
| 2901 | void RenderView::didCompleteClientRedirect( |
| 2902 | WebFrame* frame, const WebURL& from) { |
| 2903 | if (!frame->parent()) |
| 2904 | completed_client_redirect_src_ = from; |
| 2905 | } |
| 2906 | |
| 2907 | void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
| 2908 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2909 | // non-null NavigationState. |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 2910 | bool content_initiated = !pending_navigation_state_.get(); |
| 2911 | NavigationState* state = content_initiated ? |
| 2912 | NavigationState::CreateContentInitiated() : |
| 2913 | pending_navigation_state_.release(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2914 | |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2915 | // NavigationState::referred_by_prefetcher_ is true if we are |
| 2916 | // navigating from a page that used prefetching using a link on that |
| 2917 | // page. We are early enough in the request process here that we |
| 2918 | // can still see the NavigationState of the previous page and set |
| 2919 | // this value appropriately. |
| 2920 | // TODO(gavinp): catch the important case of navigation in a new |
| 2921 | // renderer process. |
| 2922 | if (webview()) { |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 2923 | if (WebFrame* old_frame = webview()->mainFrame()) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2924 | const WebURLRequest& original_request = ds->originalRequest(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2925 | const GURL referrer( |
| 2926 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2927 | if (!referrer.is_empty() && |
| 2928 | NavigationState::FromDataSource( |
| 2929 | old_frame->dataSource())->was_prefetcher()) { |
| 2930 | for (;old_frame;old_frame = old_frame->traverseNext(false)) { |
| 2931 | WebDataSource* old_frame_ds = old_frame->dataSource(); |
| 2932 | if (old_frame_ds && referrer == GURL(old_frame_ds->request().url())) { |
| 2933 | state->set_was_referred_by_prefetcher(true); |
| 2934 | break; |
| 2935 | } |
| 2936 | } |
| 2937 | } |
| 2938 | } |
| 2939 | } |
| 2940 | |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2941 | if (content_initiated) { |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2942 | const WebURLRequest& request = ds->request(); |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 2943 | switch (request.cachePolicy()) { |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2944 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
| 2945 | state->set_load_type(NavigationState::LINK_LOAD_NORMAL); |
| 2946 | break; |
| 2947 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
| 2948 | state->set_load_type(NavigationState::LINK_LOAD_RELOAD); |
| 2949 | break; |
| 2950 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
| 2951 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK); |
| 2952 | break; |
| 2953 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
| 2954 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY); |
| 2955 | break; |
| 2956 | } |
| 2957 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2958 | |
| 2959 | state->set_user_script_idle_scheduler( |
| 2960 | new UserScriptIdleScheduler(this, frame)); |
| 2961 | ds->setExtraData(state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | void RenderView::didStartProvisionalLoad(WebFrame* frame) { |
| 2965 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2966 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2967 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2968 | // Update the request time if WebKit has better knowledge of it. |
| 2969 | if (navigation_state->request_time().is_null()) { |
| 2970 | double event_time = ds->triggeringEventTime(); |
| 2971 | if (event_time != 0.0) |
| 2972 | navigation_state->set_request_time(Time::FromDoubleT(event_time)); |
| 2973 | } |
| 2974 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 2975 | // Start time is only set after request time. |
| 2976 | navigation_state->set_start_load_time(Time::Now()); |
| 2977 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2978 | bool is_top_most = !frame->parent(); |
| 2979 | if (is_top_most) { |
| 2980 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
| 2981 | NavigationGestureUnknown : NavigationGestureAuto; |
| 2982 | |
| 2983 | // Make sure redirect tracking state is clear for the new load. |
| 2984 | completed_client_redirect_src_ = GURL(); |
| 2985 | } else if (frame->parent()->isLoading()) { |
| 2986 | // 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] | 2987 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2988 | navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME); |
| 2989 | } |
| 2990 | |
| 2991 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 2992 | routing_id_, frame->identifier(), is_top_most, ds->request().url())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) { |
| 2996 | if (frame->parent()) |
| 2997 | return; |
| 2998 | // Received a redirect on the main frame. |
| 2999 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 3000 | if (!data_source) { |
| 3001 | // Should only be invoked when we have a data source. |
| 3002 | NOTREACHED(); |
| 3003 | return; |
| 3004 | } |
| 3005 | std::vector<GURL> redirects; |
| 3006 | GetRedirectChain(data_source, &redirects); |
| 3007 | if (redirects.size() >= 2) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3008 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
| 3009 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3010 | } |
| 3011 | } |
| 3012 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3013 | void RenderView::didFailProvisionalLoad(WebFrame* frame, |
| 3014 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3015 | // Notify the browser that we failed a provisional load with an error. |
| 3016 | // |
| 3017 | // Note: It is important this notification occur before DidStopLoading so the |
| 3018 | // SSL manager can react to the provisional load failure before being |
| 3019 | // notified the load stopped. |
| 3020 | // |
| 3021 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3022 | DCHECK(ds); |
| 3023 | |
| 3024 | const WebURLRequest& failed_request = ds->request(); |
| 3025 | |
| 3026 | bool show_repost_interstitial = |
| 3027 | (error.reason == net::ERR_CACHE_MISS && |
| 3028 | EqualsASCII(failed_request.httpMethod(), "POST")); |
| 3029 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 3030 | routing_id_, frame->identifier(), !frame->parent(), error.reason, |
| 3031 | error.unreachableURL, show_repost_interstitial)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3032 | |
| 3033 | // Don't display an error page if this is simply a cancelled load. Aside |
| 3034 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 3035 | if (error.reason == net::ERR_ABORTED) |
| 3036 | return; |
| 3037 | |
| 3038 | // Make sure we never show errors in view source mode. |
| 3039 | frame->enableViewSourceMode(false); |
| 3040 | |
| 3041 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3042 | |
| 3043 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 3044 | // 'replace' load. This is necessary to avoid messing up session history. |
| 3045 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 3046 | // as session history is concerned. |
| 3047 | // |
| 3048 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 3049 | // the page id. |
| 3050 | // |
| 3051 | bool replace = |
| 3052 | navigation_state->pending_page_id() != -1 || |
| 3053 | navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME; |
| 3054 | |
| 3055 | // If we failed on a browser initiated request, then make sure that our error |
| 3056 | // page load is regarded as the same browser initiated request. |
| 3057 | if (!navigation_state->is_content_initiated()) { |
| 3058 | pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( |
| 3059 | navigation_state->pending_page_id(), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3060 | navigation_state->pending_history_list_offset(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3061 | navigation_state->transition_type(), |
| 3062 | navigation_state->request_time())); |
| 3063 | } |
| 3064 | |
| 3065 | // Provide the user with a more helpful error page? |
| 3066 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 3067 | return; |
| 3068 | |
| 3069 | // Fallback to a local error page. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3070 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | void RenderView::didReceiveDocumentData( |
| 3074 | WebFrame* frame, const char* data, size_t data_len, |
| 3075 | bool& prevent_default) { |
| 3076 | NavigationState* navigation_state = |
| 3077 | NavigationState::FromDataSource(frame->dataSource()); |
| 3078 | if (!navigation_state->postpone_loading_data()) |
| 3079 | return; |
| 3080 | |
| 3081 | // We're going to call commitDocumentData ourselves... |
| 3082 | prevent_default = true; |
| 3083 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3084 | // Continue buffering the response data for the original error page. If it |
| 3085 | // grows too large, then we'll just let it through. For any error other than |
| 3086 | // a 404, "too large" means any data at all. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3087 | navigation_state->append_postponed_data(data, data_len); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3088 | if (navigation_state->postponed_data().size() >= 512 || |
| 3089 | navigation_state->http_status_code() != 404) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3090 | navigation_state->set_postpone_loading_data(false); |
| 3091 | frame->commitDocumentData(navigation_state->postponed_data().data(), |
| 3092 | navigation_state->postponed_data().size()); |
| 3093 | navigation_state->clear_postponed_data(); |
| 3094 | } |
| 3095 | } |
| 3096 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3097 | void RenderView::didCommitProvisionalLoad(WebFrame* frame, |
| 3098 | bool is_new_navigation) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3099 | NavigationState* navigation_state = |
| 3100 | NavigationState::FromDataSource(frame->dataSource()); |
| 3101 | |
| 3102 | navigation_state->set_commit_load_time(Time::Now()); |
| 3103 | if (is_new_navigation) { |
| 3104 | // When we perform a new navigation, we need to update the previous session |
| 3105 | // history entry with state for the page we are leaving. |
| 3106 | UpdateSessionHistory(frame); |
| 3107 | |
| 3108 | // We bump our Page ID to correspond with the new session history entry. |
| 3109 | page_id_ = next_page_id_++; |
| 3110 | |
[email protected] | d64b07b | 2010-04-20 22:14:06 | [diff] [blame] | 3111 | // Any pending translation is now obsolete. |
| 3112 | translate_helper_.CancelPendingTranslation(); |
| 3113 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3114 | // Advance our offset in session history, applying the length limit. There |
| 3115 | // is now no forward history. |
| 3116 | history_list_offset_++; |
| 3117 | if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries) |
| 3118 | history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1; |
| 3119 | history_list_length_ = history_list_offset_ + 1; |
| 3120 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 3121 | MessageLoop::current()->PostDelayedTask( |
| 3122 | FROM_HERE, |
[email protected] | e47aec5 | 2010-08-12 00:50:30 | [diff] [blame] | 3123 | page_info_method_factory_.NewRunnableMethod( |
| 3124 | &RenderView::CapturePageInfo, page_id_, true), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3125 | kDelayForForcedCaptureMs); |
| 3126 | } else { |
| 3127 | // Inspect the navigation_state on this frame to see if the navigation |
| 3128 | // corresponds to a session history navigation... Note: |frame| may or |
| 3129 | // may not be the toplevel frame, but for the case of capturing session |
| 3130 | // history, the first committed frame suffices. We keep track of whether |
| 3131 | // we've seen this commit before so that only capture session history once |
| 3132 | // per navigation. |
| 3133 | // |
| 3134 | // Note that we need to check if the page ID changed. In the case of a |
| 3135 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 3136 | // previous URL and the current page ID, which would be wrong. |
| 3137 | if (navigation_state->pending_page_id() != -1 && |
| 3138 | navigation_state->pending_page_id() != page_id_ && |
| 3139 | !navigation_state->request_committed()) { |
| 3140 | // This is a successful session history navigation! |
| 3141 | UpdateSessionHistory(frame); |
| 3142 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 3143 | |
| 3144 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3145 | } |
| 3146 | } |
| 3147 | |
| 3148 | // Remember that we've already processed this request, so we don't update |
| 3149 | // the session history again. We do this regardless of whether this is |
| 3150 | // a session history navigation, because if we attempted a session history |
| 3151 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 3152 | // new navigation. |
| 3153 | navigation_state->set_request_committed(true); |
| 3154 | |
| 3155 | UpdateURL(frame); |
| 3156 | |
| 3157 | // If this committed load was initiated by a client redirect, we're |
| 3158 | // at the last stop now, so clear it. |
| 3159 | completed_client_redirect_src_ = GURL(); |
| 3160 | |
| 3161 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3162 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | void RenderView::didClearWindowObject(WebFrame* frame) { |
| 3166 | if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_)) |
| 3167 | BindDOMAutomationController(frame); |
[email protected] | 0d7ae86 | 2010-10-01 13:52:45 | [diff] [blame] | 3168 | GURL frame_url = frame->url(); |
| 3169 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) && |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 3170 | (frame_url.SchemeIs(chrome::kChromeUIScheme) || |
[email protected] | 731ae51 | 2010-10-15 18:20:17 | [diff] [blame] | 3171 | frame_url.SchemeIs(chrome::kGearsScheme) || |
[email protected] | bfa83eb8 | 2010-10-06 08:41:25 | [diff] [blame] | 3172 | frame_url.SchemeIs(chrome::kDataScheme))) { |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3173 | GetDOMUIBindings()->set_message_sender(this); |
| 3174 | GetDOMUIBindings()->set_routing_id(routing_id_); |
| 3175 | GetDOMUIBindings()->BindToJavascript(frame, L"chrome"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3176 | } |
| 3177 | if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) { |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3178 | GetExternalHostBindings()->set_message_sender(this); |
| 3179 | GetExternalHostBindings()->set_routing_id(routing_id_); |
| 3180 | GetExternalHostBindings()->BindToJavascript(frame, L"externalHost"); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | void RenderView::didCreateDocumentElement(WebFrame* frame) { |
| 3185 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3186 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3187 | frame, UserScript::DOCUMENT_START); |
| 3188 | } |
| 3189 | |
| 3190 | // Notify the browser about non-blank documents loading in the top frame. |
| 3191 | GURL url = frame->url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 3192 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3193 | if (frame == webview()->mainFrame()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3194 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
| 3195 | } |
| 3196 | } |
| 3197 | |
| 3198 | void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { |
| 3199 | UpdateTitle(frame, title); |
| 3200 | |
| 3201 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3202 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3203 | } |
| 3204 | |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 3205 | void RenderView::didChangeIcons(WebFrame* frame) { |
| 3206 | if (!frame->parent()) { |
| 3207 | Send(new ViewHostMsg_UpdateFavIconURL( |
| 3208 | routing_id_, |
| 3209 | page_id_, |
| 3210 | frame->favIconURL())); |
| 3211 | } |
| 3212 | } |
| 3213 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3214 | void RenderView::didFinishDocumentLoad(WebFrame* frame) { |
| 3215 | WebDataSource* ds = frame->dataSource(); |
| 3216 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3217 | DCHECK(navigation_state); |
| 3218 | navigation_state->set_finish_document_load_time(Time::Now()); |
| 3219 | |
| 3220 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_)); |
| 3221 | |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3222 | page_click_tracker_->StartTrackingFrame(frame); |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 3223 | // The document has now been fully loaded. Scan for forms to be sent up to |
| 3224 | // the browser. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3225 | autofill_helper_->FrameContentsAvailable(frame); |
| 3226 | password_autocomplete_manager_->SendPasswordForms(frame, false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3227 | |
| 3228 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3229 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3230 | |
| 3231 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3232 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3233 | frame, UserScript::DOCUMENT_END); |
| 3234 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3235 | |
[email protected] | 41f1663 | 2010-10-20 01:21:32 | [diff] [blame] | 3236 | // InjectScripts() can end up creating a new NavigationState if it triggers a |
| 3237 | // fragment navigation, so we need to re-fetch it here. |
| 3238 | navigation_state = NavigationState::FromDataSource(ds); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3239 | navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad(); |
| 3240 | } |
| 3241 | |
| 3242 | void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) { |
| 3243 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 3244 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 3245 | frame, UserScript::DOCUMENT_IDLE); |
| 3246 | } |
| 3247 | |
| 3248 | WebFrame* main_frame = webview()->mainFrame(); |
| 3249 | if (frame == main_frame) { |
| 3250 | while (!pending_code_execution_queue_.empty()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 3251 | linked_ptr<ViewMsg_ExecuteCode_Params>& params = |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3252 | pending_code_execution_queue_.front(); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 3253 | ExecuteCodeImpl(main_frame, *params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3254 | pending_code_execution_queue_.pop(); |
| 3255 | } |
| 3256 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | void RenderView::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 3260 | if (webview()->mainFrame() == frame) { |
| 3261 | Send(new ViewHostMsg_DocumentOnLoadCompletedInMainFrame(routing_id_, |
| 3262 | page_id_)); |
| 3263 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { |
| 3267 | // Ignore |
| 3268 | } |
| 3269 | |
| 3270 | void RenderView::didFinishLoad(WebFrame* frame) { |
| 3271 | WebDataSource* ds = frame->dataSource(); |
| 3272 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 3273 | DCHECK(navigation_state); |
| 3274 | navigation_state->set_finish_load_time(Time::Now()); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 3275 | navigation_state->user_script_idle_scheduler()->DidFinishLoad(); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 3276 | |
| 3277 | // Let the password manager know which password forms are actually visible. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 3278 | password_autocomplete_manager_->SendPasswordForms(frame, true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3279 | } |
| 3280 | |
[email protected] | ccbe04e | 2010-03-17 17:58:43 | [diff] [blame] | 3281 | void RenderView::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3282 | WebFrame* frame, bool is_new_navigation) { |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3283 | // Determine if the UserScriptIdleScheduler already ran scripts on this page, |
| 3284 | // since a new one gets created by didCreateDataSource. |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3285 | NavigationState* state = NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3286 | bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run(); |
| 3287 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3288 | // If this was a reference fragment navigation that we initiated, then we |
| 3289 | // could end up having a non-null pending navigation state. We just need to |
| 3290 | // update the ExtraData on the datasource so that others who read the |
| 3291 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 3292 | // initiate this navigation, then we need to take care to reset any pre- |
| 3293 | // existing navigation state to a content-initiated navigation state. |
| 3294 | // DidCreateDataSource conveniently takes care of this for us. |
| 3295 | didCreateDataSource(frame, frame->dataSource()); |
| 3296 | |
[email protected] | af15bed | 2010-08-25 21:12:09 | [diff] [blame] | 3297 | NavigationState* new_state = |
| 3298 | NavigationState::FromDataSource(frame->dataSource()); |
| 3299 | new_state->set_was_within_same_page(true); |
| 3300 | |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3301 | if (idle_scheduler_ran) { |
| 3302 | // Update the new UserScriptIdleScheduler so we don't re-run scripts. |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 3303 | new_state->user_script_idle_scheduler()->set_has_run(true); |
| 3304 | } |
| 3305 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3306 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 3307 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3308 | UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3309 | } |
| 3310 | |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3311 | void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 3312 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 3313 | } |
| 3314 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3315 | void RenderView::assignIdentifierToRequest( |
| 3316 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 3317 | // Ignore |
| 3318 | } |
| 3319 | |
| 3320 | void RenderView::willSendRequest( |
| 3321 | WebFrame* frame, unsigned identifier, WebURLRequest& request, |
| 3322 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3323 | WebFrame* top_frame = frame->top(); |
| 3324 | if (!top_frame) |
| 3325 | top_frame = frame; |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3326 | WebDataSource* provisional_data_source = top_frame->provisionalDataSource(); |
| 3327 | WebDataSource* top_data_source = top_frame->dataSource(); |
| 3328 | WebDataSource* data_source = |
| 3329 | provisional_data_source ? provisional_data_source : top_data_source; |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 3330 | if (data_source) { |
| 3331 | NavigationState* state = NavigationState::FromDataSource(data_source); |
| 3332 | if (state && state->is_cache_policy_override_set()) |
| 3333 | request.setCachePolicy(state->cache_policy_override()); |
| 3334 | } |
[email protected] | 8a3125a71 | 2010-08-09 18:58:51 | [diff] [blame] | 3335 | |
| 3336 | if (top_data_source) { |
| 3337 | NavigationState* state = NavigationState::FromDataSource(top_data_source); |
| 3338 | if (state && request.targetType() == WebURLRequest::TargetIsPrefetch) |
| 3339 | state->set_was_prefetcher(true); |
| 3340 | } |
| 3341 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3342 | request.setRequestorID(routing_id_); |
[email protected] | c5bbc245 | 2010-03-08 08:33:50 | [diff] [blame] | 3343 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 3344 | request.clearHTTPHeaderField("Referer"); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3345 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 3346 | // Temporary metrics, see site_isolation_metrics.h |
| 3347 | SiteIsolationMetrics::AddRequest(identifier, request.targetType()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | void RenderView::didReceiveResponse( |
| 3351 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3352 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 3353 | // Temporary metrics, see site_isolation_metrics.h |
| 3354 | SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame, |
| 3355 | identifier, |
| 3356 | response); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 3357 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3358 | // Only do this for responses that correspond to a provisional data source |
| 3359 | // of the top-most frame. If we have a provisional data source, then we |
| 3360 | // can't have any sub-resources yet, so we know that this response must |
| 3361 | // correspond to a frame load. |
| 3362 | if (!frame->provisionalDataSource() || frame->parent()) |
| 3363 | return; |
| 3364 | |
| 3365 | // 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] | 3366 | // the server's error page. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3367 | if (frame->isViewSourceModeEnabled()) |
| 3368 | return; |
| 3369 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3370 | NavigationState* navigation_state = |
| 3371 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 3372 | CHECK(navigation_state); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3373 | int http_status_code = response.httpStatusCode(); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3374 | |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3375 | // Record page load flags. |
| 3376 | navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); |
| 3377 | navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated()); |
[email protected] | 193b0b89 | 2010-06-26 03:57:57 | [diff] [blame] | 3378 | navigation_state->set_was_alternate_protocol_available( |
| 3379 | response.wasAlternateProtocolAvailable()); |
[email protected] | 972ebdff | 2010-06-10 22:59:07 | [diff] [blame] | 3380 | navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3381 | navigation_state->set_http_status_code(http_status_code); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 3382 | |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 3383 | // Consider loading an alternate error page for 404 responses. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3384 | if (http_status_code == 404) { |
| 3385 | // Can we even load an alternate error page for this URL? |
| 3386 | if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid()) |
| 3387 | return; |
| 3388 | } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain, |
| 3389 | http_status_code)) { |
| 3390 | // If no corresponding error strings for a particular status code, just |
| 3391 | // render any received data, regardless of whether or not the status code |
| 3392 | // indicates an error. |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 3393 | return; |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3394 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3395 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3396 | navigation_state->set_postpone_loading_data(true); |
| 3397 | navigation_state->clear_postponed_data(); |
| 3398 | } |
| 3399 | |
| 3400 | void RenderView::didFinishResourceLoad( |
| 3401 | WebFrame* frame, unsigned identifier) { |
| 3402 | NavigationState* navigation_state = |
| 3403 | NavigationState::FromDataSource(frame->dataSource()); |
| 3404 | if (!navigation_state->postpone_loading_data()) |
| 3405 | return; |
| 3406 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3407 | // The server returned an error and the content was < 512 bytes (which we |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3408 | // suppressed). Go ahead and fetch the alternate page content. |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3409 | int http_status_code = navigation_state->http_status_code(); |
| 3410 | if (http_status_code == 404) { |
| 3411 | // On 404s, try a remote search page as a fallback. |
| 3412 | const GURL& frame_url = frame->url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3413 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3414 | const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404); |
| 3415 | DCHECK(error_page_url.is_valid()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3416 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3417 | WebURLError original_error; |
| 3418 | original_error.unreachableURL = frame_url; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3419 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3420 | navigation_state->set_alt_error_page_fetcher( |
| 3421 | new AltErrorPageResourceFetcher( |
| 3422 | error_page_url, frame, original_error, |
| 3423 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 3424 | } else { |
| 3425 | // On other errors, use an internal error page. |
| 3426 | WebURLError error; |
| 3427 | error.unreachableURL = frame->url(); |
| 3428 | error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain); |
| 3429 | error.reason = http_status_code; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3430 | |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 3431 | LoadNavigationErrorPage(frame, frame->dataSource()->request(), error, |
| 3432 | std::string(), true); |
| 3433 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3434 | } |
| 3435 | |
| 3436 | void RenderView::didFailResourceLoad( |
| 3437 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 3438 | // Ignore |
| 3439 | } |
| 3440 | |
| 3441 | void RenderView::didLoadResourceFromMemoryCache( |
| 3442 | WebFrame* frame, const WebURLRequest& request, |
| 3443 | const WebURLResponse& response) { |
| 3444 | // Let the browser know we loaded a resource from the memory cache. This |
| 3445 | // message is needed to display the correct SSL indicators. |
| 3446 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 3447 | routing_id_, |
| 3448 | request.url(), |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 3449 | frame->securityOrigin().toString().utf8(), |
| 3450 | frame->top()->securityOrigin().toString().utf8(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3451 | response.securityInfo())); |
| 3452 | } |
| 3453 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3454 | void RenderView::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 3455 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 3456 | } |
| 3457 | |
| 3458 | void RenderView::didRunInsecureContent( |
| 3459 | WebFrame* frame, const WebSecurityOrigin& origin) { |
| 3460 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 3461 | routing_id_, |
| 3462 | origin.toString().utf8())); |
| 3463 | } |
| 3464 | |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3465 | bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 3466 | if (enabled_per_settings && |
| 3467 | AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) |
| 3468 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3469 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 3470 | if (IsWhitelistedForContentSettings(frame)) |
| 3471 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 3472 | |
| 3473 | return false; // Other protocols fall through here. |
| 3474 | } |
| 3475 | |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 3476 | bool RenderView::allowDatabase( |
| 3477 | WebFrame* frame, const WebString& name, const WebString& display_name, |
| 3478 | unsigned long estimated_size) { |
| 3479 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 3480 | if (origin.isEmpty()) |
| 3481 | return false; // Uninitialized document? |
| 3482 | |
| 3483 | bool result; |
| 3484 | if (!Send(new ViewHostMsg_AllowDatabase(routing_id_, |
| 3485 | origin.toString().utf8(), name, display_name, estimated_size, &result))) |
| 3486 | return false; |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 3487 | Send(new ViewHostMsg_WebDatabaseAccessed(routing_id_, |
| 3488 | GURL(origin.toString().utf8()), |
| 3489 | name, |
| 3490 | display_name, |
| 3491 | estimated_size, |
| 3492 | !result)); |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 3493 | return result; |
| 3494 | } |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3495 | void RenderView::didNotAllowScript(WebKit::WebFrame* frame) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3496 | DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()); |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3497 | } |
| 3498 | |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 3499 | void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) { |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 3500 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS, std::string()); |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 3501 | } |
| 3502 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3503 | void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
| 3504 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 3505 | } |
| 3506 | |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 3507 | void RenderView::didCreateScriptContext(WebFrame* frame) { |
| 3508 | EventBindings::HandleContextCreated(frame, false); |
| 3509 | } |
| 3510 | |
| 3511 | void RenderView::didDestroyScriptContext(WebFrame* frame) { |
| 3512 | EventBindings::HandleContextDestroyed(frame); |
| 3513 | } |
| 3514 | |
| 3515 | void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) { |
| 3516 | EventBindings::HandleContextCreated(frame, true); |
| 3517 | } |
| 3518 | |
[email protected] | af7eb3fb | 2010-09-23 21:31:06 | [diff] [blame] | 3519 | bool RenderView::allowScriptExtension(WebFrame* frame, |
| 3520 | const WebString& extension_name, |
| 3521 | int extension_group) { |
| 3522 | // NULL in unit tests. |
| 3523 | if (!RenderThread::current()) |
| 3524 | return true; |
| 3525 | |
| 3526 | // Note: we prefer the provisional URL here instead of the document URL |
| 3527 | // because we might be currently loading an URL into a blank page. |
| 3528 | // See http://code.google.com/p/chromium/issues/detail?id=10924 |
| 3529 | WebDataSource* ds = frame->provisionalDataSource(); |
| 3530 | if (!ds) |
| 3531 | ds = frame->dataSource(); |
| 3532 | return RenderThread::current()->AllowScriptExtension( |
| 3533 | extension_name.utf8(), ds->request().url(), extension_group); |
| 3534 | } |
| 3535 | |
[email protected] | fc86daa | 2010-03-30 23:52:53 | [diff] [blame] | 3536 | void RenderView::logCrossFramePropertyAccess(WebFrame* frame, |
| 3537 | WebFrame* target, |
| 3538 | bool cross_origin, |
| 3539 | const WebString& property_name, |
| 3540 | unsigned long long event_id) { |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 3541 | // TODO(johnnyg): track the individual properties and repeat event_ids. |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 3542 | if (cross_origin) |
| 3543 | cross_origin_access_count_++; |
| 3544 | else |
| 3545 | same_origin_access_count_++; |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 3546 | } |
| 3547 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3548 | void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) { |
[email protected] | d8a179c | 2010-01-31 00:58:14 | [diff] [blame] | 3549 | CheckPreferredSize(); |
| 3550 | } |
| 3551 | |
| 3552 | void RenderView::CheckPreferredSize() { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3553 | // 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] | 3554 | // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3555 | // message. |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3556 | if (!send_preferred_size_changes_ || !webview()) |
| 3557 | return; |
[email protected] | dfca5acf | 2010-03-22 03:28:43 | [diff] [blame] | 3558 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3559 | // WebCore likes to tell us things have changed even when they haven't, so |
| 3560 | // cache the width and height and only send the IPC message when we're sure |
| 3561 | // they're different. |
| 3562 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 3563 | webview()->mainFrame()->documentElementScrollHeight()); |
[email protected] | 8205d74 | 2010-10-22 23:51:53 | [diff] [blame] | 3564 | |
| 3565 | // In the presence of zoom, these sizes are still reported as if unzoomed, |
| 3566 | // so we need to adjust. |
| 3567 | double zoom_factor = WebView::zoomLevelToZoomFactor(webview()->zoomLevel()); |
| 3568 | size.set_width(static_cast<int>(size.width() * zoom_factor)); |
| 3569 | size.set_height(static_cast<int>(size.height() * zoom_factor)); |
| 3570 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3571 | if (size == preferred_size_) |
| 3572 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 3573 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame] | 3574 | preferred_size_ = size; |
| 3575 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 3576 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3577 | } |
| 3578 | |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 3579 | void RenderView::didChangeScrollOffset(WebFrame* frame) { |
| 3580 | StartNavStateSyncTimerIfNecessary(); |
| 3581 | } |
| 3582 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3583 | void RenderView::reportFindInPageMatchCount(int request_id, int count, |
| 3584 | bool final_update) { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3585 | int active_match_ordinal = -1; // -1 = don't update active match ordinal |
| 3586 | if (!count) |
| 3587 | active_match_ordinal = 0; |
| 3588 | |
| 3589 | IPC::Message* msg = new ViewHostMsg_Find_Reply( |
| 3590 | routing_id_, |
| 3591 | request_id, |
| 3592 | count, |
| 3593 | gfx::Rect(), |
| 3594 | active_match_ordinal, |
| 3595 | final_update); |
| 3596 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3597 | // If we have a message that has been queued up, then we should just replace |
| 3598 | // it. The ACK from the browser will make sure it gets sent when the browser |
| 3599 | // wants it. |
| 3600 | if (queued_find_reply_message_.get()) { |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3601 | queued_find_reply_message_.reset(msg); |
| 3602 | } else { |
| 3603 | // Send the search result over to the browser process. |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3604 | Send(msg); |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3605 | } |
| 3606 | } |
| 3607 | |
| 3608 | void RenderView::reportFindInPageSelection(int request_id, |
| 3609 | int active_match_ordinal, |
| 3610 | const WebRect& selection_rect) { |
| 3611 | // Send the search result over to the browser process. |
| 3612 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3613 | request_id, |
| 3614 | -1, |
| 3615 | selection_rect, |
| 3616 | active_match_ordinal, |
| 3617 | false)); |
| 3618 | } |
| 3619 | |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3620 | void RenderView::openFileSystem( |
| 3621 | WebFrame* frame, |
| 3622 | WebFileSystem::Type type, |
| 3623 | long long size, |
| 3624 | WebFileSystemCallbacks* callbacks) { |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3625 | DCHECK(callbacks); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3626 | |
| 3627 | WebSecurityOrigin origin = frame->securityOrigin(); |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3628 | if (origin.isEmpty()) { |
| 3629 | // Uninitialized document? |
| 3630 | callbacks->didFail(WebKit::WebFileErrorAbort); |
| 3631 | return; |
| 3632 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3633 | |
[email protected] | c5a272d | 2010-09-27 18:37:08 | [diff] [blame] | 3634 | ChildThread::current()->file_system_dispatcher()->OpenFileSystem( |
| 3635 | GURL(origin.toString()), static_cast<fileapi::FileSystemType>(type), |
| 3636 | size, new WebFileSystemCallbackDispatcher(callbacks)); |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 3637 | } |
| 3638 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 3639 | // webkit_glue::WebPluginPageDelegate ----------------------------------------- |
| 3640 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3641 | webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3642 | const FilePath& file_path, |
| 3643 | const std::string& mime_type) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3644 | if (!PluginChannelHost::IsListening()) |
| 3645 | return NULL; |
| 3646 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3647 | bool use_pepper_host = false; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3648 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3649 | // Check for trusted Pepper plugins. |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3650 | const char kPepperPrefix[] = "pepper-"; |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3651 | if (StartsWithASCII(mime_type, kPepperPrefix, true)) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3652 | if (CommandLine::ForCurrentProcess()-> |
| 3653 | HasSwitch(switches::kInternalPepper)) { |
| 3654 | in_process_plugin = true; |
| 3655 | use_pepper_host = true; |
| 3656 | } else { |
| 3657 | // In process Pepper plugins must be explicitly enabled. |
| 3658 | return NULL; |
| 3659 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3660 | } else { |
| 3661 | FilePath internal_pdf_path; |
| 3662 | PathService::Get(chrome::FILE_PDF_PLUGIN, &internal_pdf_path); |
| 3663 | if (file_path == internal_pdf_path) { |
| 3664 | in_process_plugin = true; |
| 3665 | use_pepper_host = true; |
| 3666 | } |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3667 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3668 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3669 | // Check for Native Client modules. |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 3670 | if (mime_type == "application/x-nacl-srpc" && |
| 3671 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) { |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3672 | // NaCl is only permitted when we're in an extension/application with the |
| 3673 | // appropriate permission, or when explicitly enabled on the command line. |
| 3674 | |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3675 | GURL main_frame_url(webview()->mainFrame()->url()); |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3676 | ExtensionRendererInfo* extension = |
| 3677 | ExtensionRendererInfo::GetByURL(main_frame_url); |
| 3678 | bool in_ext = extension != NULL; |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3679 | bool explicit_enable = |
| 3680 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl); |
| 3681 | |
| 3682 | if (in_ext) { |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 3683 | // TODO(cbiffle): NaCl is back to experimental for M7. |
[email protected] | 5351dbc | 2010-08-27 15:22:11 | [diff] [blame] | 3684 | if (ExtensionProcessBindings::HasPermission(extension->id(), |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 3685 | Extension::kExperimentalPermission)) { |
[email protected] | 8f05f7f | 2010-07-30 23:12:43 | [diff] [blame] | 3686 | in_process_plugin = true; |
| 3687 | use_pepper_host = true; |
| 3688 | } else { |
| 3689 | // Disable NaCl for apps lacking the permission, even with the flag. |
| 3690 | return NULL; |
| 3691 | } |
| 3692 | } else if (explicit_enable) { |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3693 | in_process_plugin = true; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3694 | use_pepper_host = true; |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3695 | } |
| 3696 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3697 | |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3698 | if (in_process_plugin) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3699 | if (use_pepper_host) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3700 | WebPluginDelegatePepper* pepper_plugin = |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3701 | WebPluginDelegatePepper::Create(file_path, mime_type, AsWeakPtr()); |
[email protected] | b7d7ed5 | 2010-07-20 00:12:33 | [diff] [blame] | 3702 | if (!pepper_plugin) |
| 3703 | return NULL; |
| 3704 | |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 3705 | current_oldstyle_pepper_plugins_.insert(pepper_plugin); |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3706 | return pepper_plugin; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3707 | } else { |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3708 | #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] | 3709 | return WebPluginDelegateImpl::Create( |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3710 | file_path, mime_type, gfx::NativeViewFromId(host_window_)); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3711 | #else |
[email protected] | 596b2c4 | 2010-01-14 20:40:43 | [diff] [blame] | 3712 | NOTIMPLEMENTED(); |
| 3713 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 3714 | #endif |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3715 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3716 | } |
| 3717 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 3718 | return new WebPluginDelegateProxy(mime_type, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3722 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3723 | RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer( |
| 3724 | routing_id(), window)); |
| 3725 | #endif |
| 3726 | } |
| 3727 | |
| 3728 | void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3729 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3730 | RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer( |
| 3731 | routing_id(), window)); |
| 3732 | #endif |
| 3733 | CleanupWindowInPluginMoves(window); |
| 3734 | } |
| 3735 | |
| 3736 | void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) { |
| 3737 | SchedulePluginMove(move); |
| 3738 | } |
| 3739 | |
| 3740 | void RenderView::DidStartLoadingForPlugin() { |
| 3741 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3742 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | void RenderView::DidStopLoadingForPlugin() { |
| 3746 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3747 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | void RenderView::ShowModalHTMLDialogForPlugin( |
| 3751 | const GURL& url, |
| 3752 | const gfx::Size& size, |
| 3753 | const std::string& json_arguments, |
| 3754 | std::string* json_retval) { |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3755 | SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog( |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3756 | routing_id_, url, size.width(), size.height(), json_arguments, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3757 | json_retval)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3758 | } |
| 3759 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 3760 | WebCookieJar* RenderView::GetCookieJar() { |
| 3761 | return &cookie_jar_; |
| 3762 | } |
| 3763 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3764 | void RenderView::SyncNavigationState() { |
| 3765 | if (!webview()) |
| 3766 | return; |
| 3767 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3768 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3769 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3770 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3771 | |
| 3772 | Send(new ViewHostMsg_UpdateState( |
| 3773 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3774 | } |
| 3775 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3776 | bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) { |
| 3777 | // Make sure webview was not shut down. |
| 3778 | if (!webview()) |
| 3779 | return false; |
| 3780 | // Create an image resource fetcher and assign it with a call back object. |
| 3781 | image_fetchers_.insert(new ImageResourceFetcher( |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3782 | image_url, webview()->mainFrame(), id, image_size, |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3783 | NewCallback(this, &RenderView::DidDownloadImage))); |
| 3784 | return true; |
| 3785 | } |
| 3786 | |
| 3787 | void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3788 | const SkBitmap& image) { |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3789 | // Notify requester of image download status. |
[email protected] | 51bd3661 | 2009-10-20 22:49:47 | [diff] [blame] | 3790 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, |
| 3791 | fetcher->id(), |
| 3792 | fetcher->image_url(), |
| 3793 | image.isNull(), |
| 3794 | image)); |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3795 | // Dispose of the image fetcher. |
| 3796 | DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end()); |
| 3797 | image_fetchers_.erase(fetcher); |
| 3798 | // We're in the callback from the ImageResourceFetcher, best to delay |
| 3799 | // deletion. |
| 3800 | MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3801 | } |
| 3802 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3803 | void RenderView::OnDownloadFavIcon(int id, |
| 3804 | const GURL& image_url, |
| 3805 | int image_size) { |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3806 | bool data_image_failed = false; |
| 3807 | if (image_url.SchemeIs("data")) { |
| 3808 | SkBitmap data_image = ImageFromDataUrl(image_url); |
| 3809 | data_image_failed = data_image.empty(); |
| 3810 | if (!data_image_failed) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3811 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false, |
| 3812 | data_image)); |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3813 | } |
| 3814 | } |
| 3815 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3816 | if (data_image_failed || |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3817 | !DownloadImage(id, image_url, image_size)) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3818 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true, |
| 3819 | SkBitmap())); |
| 3820 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3821 | } |
| 3822 | |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3823 | SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const { |
| 3824 | std::string mime_type, char_set, data; |
| 3825 | if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
| 3826 | // Decode the favicon using WebKit's image decoder. |
| 3827 | webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize)); |
| 3828 | const unsigned char* src_data = |
| 3829 | reinterpret_cast<const unsigned char*>(&data[0]); |
| 3830 | |
| 3831 | return decoder.Decode(src_data, data.size()); |
| 3832 | } |
| 3833 | return SkBitmap(); |
| 3834 | } |
| 3835 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3836 | void RenderView::OnGetApplicationInfo(int page_id) { |
| 3837 | webkit_glue::WebApplicationInfo app_info; |
| 3838 | if (page_id == page_id_) |
| 3839 | webkit_glue::GetApplicationInfo(webview(), &app_info); |
| 3840 | |
| 3841 | // Prune out any data URLs in the set of icons. The browser process expects |
| 3842 | // any icon with a data URL to have originated from a favicon. We don't want |
| 3843 | // to decode arbitrary data URLs in the browser process. See |
| 3844 | // http://b/issue?id=1162972 |
| 3845 | for (size_t i = 0; i < app_info.icons.size(); ++i) { |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 3846 | if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3847 | app_info.icons.erase(app_info.icons.begin() + i); |
| 3848 | --i; |
| 3849 | } |
| 3850 | } |
| 3851 | |
| 3852 | Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info)); |
| 3853 | } |
| 3854 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3855 | GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3856 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3857 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3858 | // If the URL that failed was secure, then the embedding web page was not |
| 3859 | // expecting a network attacker to be able to manipulate its contents. As |
| 3860 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 3861 | // attacker to manipulate the contents of the response if we tried to use |
| 3862 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3863 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3864 | } |
| 3865 | |
| 3866 | // Grab the base URL from the browser process. |
| 3867 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3868 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3869 | |
| 3870 | // Strip query params from the failed URL. |
| 3871 | GURL::Replacements remove_params; |
| 3872 | remove_params.ClearUsername(); |
| 3873 | remove_params.ClearPassword(); |
| 3874 | remove_params.ClearQuery(); |
| 3875 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3876 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3877 | std::string spec_to_send = url_to_send.spec(); |
| 3878 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 3879 | if (failed_url.has_query()) |
| 3880 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3881 | |
| 3882 | // Construct the query params to send to link doctor. |
| 3883 | std::string params(alternate_error_page_url_.query()); |
| 3884 | params.append("&url="); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3885 | params.append(EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3886 | params.append("&sourceid=chrome"); |
| 3887 | params.append("&error="); |
| 3888 | switch (error_type) { |
| 3889 | case DNS_ERROR: |
| 3890 | params.append("dnserror"); |
| 3891 | break; |
| 3892 | |
| 3893 | case HTTP_404: |
| 3894 | params.append("http404"); |
| 3895 | break; |
| 3896 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3897 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 3898 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3899 | break; |
| 3900 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3901 | default: |
| 3902 | NOTREACHED() << "unknown ErrorPageType"; |
| 3903 | } |
| 3904 | |
| 3905 | // OK, build the final url to return. |
| 3906 | GURL::Replacements link_doctor_params; |
| 3907 | link_doctor_params.SetQueryStr(params); |
| 3908 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 3909 | return url; |
| 3910 | } |
| 3911 | |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 3912 | DOMUIBindings* RenderView::GetDOMUIBindings() { |
| 3913 | if (!dom_ui_bindings_.get()) { |
| 3914 | dom_ui_bindings_.reset(new DOMUIBindings()); |
| 3915 | } |
| 3916 | return dom_ui_bindings_.get(); |
| 3917 | } |
| 3918 | |
| 3919 | ExternalHostBindings* RenderView::GetExternalHostBindings() { |
| 3920 | if (!external_host_bindings_.get()) { |
| 3921 | external_host_bindings_.reset(new ExternalHostBindings()); |
| 3922 | } |
| 3923 | return external_host_bindings_.get(); |
| 3924 | } |
| 3925 | |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3926 | WebKit::WebPlugin* RenderView::GetWebPluginFromPluginDocument() { |
| 3927 | return webview()->mainFrame()->document().to<WebPluginDocument>().plugin(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3928 | } |
| 3929 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3930 | void RenderView::OnFind(int request_id, const string16& search_text, |
| 3931 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3932 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3933 | |
| 3934 | if (main_frame->document().isPluginDocument()) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3935 | if (options.findNext) { |
| 3936 | // Just navigate back/forward. |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 3937 | GetWebPluginFromPluginDocument()->selectFindResult(options.forward); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3938 | } else { |
[email protected] | afdbd14 | 2010-07-10 08:01:23 | [diff] [blame] | 3939 | if (GetWebPluginFromPluginDocument()->startFind( |
| 3940 | search_text, options.matchCase, request_id)) { |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3941 | } else { |
[email protected] | e7c58a3 | 2010-08-13 19:47:11 | [diff] [blame] | 3942 | // Send "no results". |
| 3943 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3944 | request_id, |
| 3945 | 0, |
| 3946 | gfx::Rect(), |
| 3947 | 0, |
| 3948 | true)); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3949 | } |
| 3950 | } |
| 3951 | return; |
| 3952 | } |
| 3953 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3954 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3955 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3956 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 3957 | |
| 3958 | bool multi_frame = (frame_after_main != main_frame); |
| 3959 | |
| 3960 | // If we have multiple frames, we don't want to wrap the search within the |
| 3961 | // frame, so we check here if we only have main_frame in the chain. |
| 3962 | bool wrap_within_frame = !multi_frame; |
| 3963 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 3964 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3965 | bool result = false; |
| 3966 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3967 | // If something is selected when we start searching it means we cannot just |
| 3968 | // increment the current match ordinal; we need to re-generate it. |
| 3969 | WebRange current_selection = focused_frame->selectionRange(); |
| 3970 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3971 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3972 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3973 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3974 | |
| 3975 | if (!result) { |
| 3976 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3977 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3978 | |
| 3979 | // Find the next frame, but skip the invisible ones. |
| 3980 | do { |
| 3981 | // What is the next frame to search? (we might be going backwards). Note |
| 3982 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3983 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3984 | search_frame->traverseNext(true) : |
| 3985 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3986 | } while (!search_frame->hasVisibleContent() && |
| 3987 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3988 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 3989 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3990 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3991 | |
| 3992 | // If we have multiple frames and we have wrapped back around to the |
| 3993 | // focused frame, we need to search it once more allowing wrap within |
| 3994 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 3995 | // reported matches, but no frames after the focused_frame contain a |
| 3996 | // match for the search word(s). |
| 3997 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3998 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3999 | request_id, search_text, options, true, // Force wrapping. |
| 4000 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4001 | } |
| 4002 | } |
| 4003 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4004 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4005 | } while (!result && search_frame != focused_frame); |
| 4006 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 4007 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4008 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4009 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4010 | } else { |
| 4011 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 4012 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 4013 | // yet what is active. |
| 4014 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 4015 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4016 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4017 | // If we find no matches then this will be our last status update. |
| 4018 | // Otherwise the scoping effort will send more results. |
| 4019 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4020 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4021 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 4022 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4023 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 4024 | match_count, |
| 4025 | selection_rect, |
| 4026 | ordinal, |
| 4027 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4028 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4029 | // Scoping effort begins, starting with the mainframe. |
| 4030 | search_frame = main_frame; |
| 4031 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4032 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4033 | |
| 4034 | do { |
| 4035 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4036 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4037 | |
| 4038 | // We don't start another scoping effort unless at least one match has |
| 4039 | // been found. |
| 4040 | if (result) { |
| 4041 | // Start new scoping request. If the scoping function determines that it |
| 4042 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4043 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4044 | search_text, |
| 4045 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4046 | true); // reset the tickmarks |
| 4047 | } |
| 4048 | |
| 4049 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 4050 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4051 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4052 | } while (search_frame != main_frame); |
| 4053 | } |
| 4054 | } |
| 4055 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4056 | void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) { |
| 4057 | WebView* view = webview(); |
| 4058 | if (!view) |
| 4059 | return; |
| 4060 | |
| 4061 | WebDocument doc = view->mainFrame()->document(); |
| 4062 | if (doc.isPluginDocument()) { |
[email protected] | 0fdbf8c | 2010-07-08 20:33:01 | [diff] [blame] | 4063 | GetWebPluginFromPluginDocument()->stopFind(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4064 | return; |
| 4065 | } |
| 4066 | |
| 4067 | bool clear_selection = |
| 4068 | params.action == ViewMsg_StopFinding_Params::kClearSelection; |
| 4069 | if (clear_selection) |
| 4070 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 4071 | |
| 4072 | WebFrame* frame = view->mainFrame(); |
| 4073 | while (frame) { |
| 4074 | frame->stopFinding(clear_selection); |
| 4075 | frame = frame->traverseNext(false); |
| 4076 | } |
| 4077 | |
| 4078 | if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) { |
| 4079 | WebFrame* focused_frame = view->focusedFrame(); |
| 4080 | if (focused_frame) { |
| 4081 | WebDocument doc = focused_frame->document(); |
| 4082 | if (!doc.isNull()) { |
| 4083 | WebNode node = doc.focusedNode(); |
| 4084 | if (!node.isNull()) |
| 4085 | node.simulateClick(); |
| 4086 | } |
| 4087 | } |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | void RenderView::OnFindReplyAck() { |
| 4092 | // Check if there is any queued up request waiting to be sent. |
| 4093 | if (queued_find_reply_message_.get()) { |
| 4094 | // Send the search result over to the browser process. |
[email protected] | d22d873 | 2010-05-04 19:24:42 | [diff] [blame] | 4095 | Send(queued_find_reply_message_.release()); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 4096 | } |
| 4097 | } |
| 4098 | |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 4099 | bool RenderView::AllowContentType(ContentSettingsType settings_type) { |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 4100 | // CONTENT_SETTING_ASK is only valid for cookies. |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 4101 | return current_content_settings_.settings[settings_type] != |
| 4102 | CONTENT_SETTING_BLOCK; |
| 4103 | } |
| 4104 | |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 4105 | void RenderView::DidBlockContentType(ContentSettingsType settings_type, |
| 4106 | const std::string& resource_identifier) { |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 4107 | if (!content_blocked_[settings_type]) { |
| 4108 | content_blocked_[settings_type] = true; |
[email protected] | 5512613 | 2010-08-19 14:53:28 | [diff] [blame] | 4109 | Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type, |
| 4110 | resource_identifier)); |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 4111 | } |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 4112 | } |
| 4113 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 4114 | void RenderView::ClearBlockedContentSettings() { |
| 4115 | for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 4116 | content_blocked_[i] = false; |
| 4117 | } |
| 4118 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 4119 | WebPlugin* RenderView::CreatePepperPlugin(WebFrame* frame, |
| 4120 | const WebPluginParams& params, |
| 4121 | const FilePath& path, |
| 4122 | pepper::PluginModule* pepper_module) { |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4123 | return new pepper::WebPluginImpl( |
| 4124 | pepper_module, params, pepper_delegate_.AsWeakPtr()); |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 4125 | } |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 4126 | |
[email protected] | aad51d1c | 2010-08-05 08:38:09 | [diff] [blame] | 4127 | WebPlugin* RenderView::CreateNPAPIPlugin(WebFrame* frame, |
| 4128 | const WebPluginParams& params, |
| 4129 | const FilePath& path, |
| 4130 | const std::string& mime_type) { |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 4131 | return new webkit_glue::WebPluginImpl( |
| 4132 | frame, params, path, mime_type, AsWeakPtr()); |
[email protected] | 00152e9 | 2010-07-19 11:47:40 | [diff] [blame] | 4133 | } |
| 4134 | |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 4135 | WebPlugin* RenderView::CreateOutdatedPluginPlaceholder( |
| 4136 | WebFrame* frame, |
| 4137 | const WebPluginParams& params, |
| 4138 | PluginGroup* group) { |
| 4139 | int resource_id = IDR_OUTDATED_PLUGIN_HTML; |
| 4140 | const base::StringPiece template_html( |
| 4141 | ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| 4142 | |
| 4143 | DCHECK(!template_html.empty()) << "unable to load template. ID: " |
| 4144 | << resource_id; |
| 4145 | |
| 4146 | DictionaryValue values; |
[email protected] | fc61e22 | 2010-10-11 15:42:14 | [diff] [blame] | 4147 | values.SetString("message", |
[email protected] | 57b66d0 | 2010-09-30 11:24:51 | [diff] [blame] | 4148 | l10n_util::GetStringFUTF8(IDS_PLUGIN_OUTDATED, group->GetGroupName())); |
| 4149 | values.Set("pluginGroup", group->GetDataForUI()); |
| 4150 | |
| 4151 | // "t" is the id of the templates root node. |
| 4152 | std::string htmlData = jstemplate_builder::GetTemplatesHtml( |
| 4153 | template_html, &values, "t"); |
| 4154 | |
| 4155 | return WebViewPlugin::Create(NULL, |
| 4156 | webkit_preferences_, |
| 4157 | htmlData, |
| 4158 | GURL("chrome://outdatedplugin/")); |
| 4159 | } |
| 4160 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4161 | void RenderView::OnZoom(PageZoom::Function function) { |
| 4162 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 4163 | return; |
| 4164 | |
[email protected] | 258d3112 | 2010-05-09 10:59:41 | [diff] [blame] | 4165 | webview()->hidePopups(); |
[email protected] | b03794d | 2010-03-26 19:57:52 | [diff] [blame] | 4166 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4167 | double old_zoom_level = webview()->zoomLevel(); |
| 4168 | double zoom_level; |
| 4169 | if (function == PageZoom::RESET) { |
| 4170 | zoom_level = 0; |
| 4171 | } else if (static_cast<int>(old_zoom_level) == old_zoom_level) { |
| 4172 | // Previous zoom level is a whole number, so just increment/decrement. |
| 4173 | zoom_level = old_zoom_level + function; |
| 4174 | } else { |
| 4175 | // Either the user hit the zoom factor limit and thus the zoom level is now |
| 4176 | // not a whole number, or a plugin changed it to a custom value. We want |
| 4177 | // to go to the next whole number so that the user can always get back to |
| 4178 | // 100% with the keyboard/menu. |
| 4179 | if ((old_zoom_level > 1 && function > 0) || |
| 4180 | (old_zoom_level < 1 && function < 0)) { |
[email protected] | 3209e711 | 2010-10-01 23:53:45 | [diff] [blame] | 4181 | zoom_level = static_cast<int>(old_zoom_level + function); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4182 | } else { |
| 4183 | // We're going towards 100%, so first go to the next whole number. |
| 4184 | zoom_level = static_cast<int>(old_zoom_level); |
| 4185 | } |
| 4186 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4187 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4188 | webview()->setZoomLevel(false, zoom_level); |
| 4189 | zoomLevelChanged(); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 4190 | } |
| 4191 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4192 | void RenderView::OnSetContentSettingsForLoadingURL( |
| 4193 | const GURL& url, |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 4194 | const ContentSettings& content_settings) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4195 | host_content_settings_[url] = content_settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 4196 | } |
| 4197 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4198 | void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url, |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 4199 | double zoom_level) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 4200 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4201 | } |
| 4202 | |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 4203 | void RenderView::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4204 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4205 | } |
| 4206 | |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4207 | void RenderView::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4208 | WebString no_encoding; |
| 4209 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 4210 | } |
| 4211 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4212 | bool RenderView::GetAllChildFrames( |
| 4213 | WebFrame* parent_frame, |
| 4214 | std::vector<WebFrame*>* frames_vector) const { |
| 4215 | if (!parent_frame) |
| 4216 | return false; |
| 4217 | for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
| 4218 | child_frame = child_frame->nextSibling()) { |
| 4219 | frames_vector->push_back(child_frame); |
| 4220 | GetAllChildFrames(child_frame, frames_vector); |
| 4221 | } |
| 4222 | return true; |
| 4223 | } |
| 4224 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4225 | WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { |
| 4226 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4227 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4228 | |
| 4229 | // xpath string can represent a frame deep down the tree (across multiple |
| 4230 | // frame DOMs). |
| 4231 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 4232 | // should break into 2 xpaths |
| 4233 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
| 4234 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4235 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4236 | |
| 4237 | std::wstring xpath_remaining = xpath; |
| 4238 | while (!xpath_remaining.empty()) { |
| 4239 | std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n'); |
| 4240 | std::wstring xpath_child; |
| 4241 | if (delim_pos != std::wstring::npos) { |
| 4242 | xpath_child = xpath_remaining.substr(0, delim_pos); |
| 4243 | xpath_remaining.erase(0, delim_pos + 1); |
| 4244 | } else { |
| 4245 | xpath_remaining.swap(xpath_child); |
| 4246 | } |
| 4247 | frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4248 | } |
| 4249 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4250 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4251 | } |
| 4252 | |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 4253 | void RenderView::SetSuggestResult(const std::string& suggest) { |
[email protected] | 5cbd61f | 2010-10-14 03:49:49 | [diff] [blame] | 4254 | // Explicitly allow empty strings to be sent to the browser. |
| 4255 | Send(new ViewHostMsg_SetSuggestResult(routing_id_, page_id_, suggest)); |
[email protected] | 15d9c0c | 2010-09-10 22:36:26 | [diff] [blame] | 4256 | } |
| 4257 | |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4258 | void RenderView::EvaluateScript(const string16& frame_xpath, |
| 4259 | const string16& script, |
| 4260 | int id, |
| 4261 | bool notify_result) { |
| 4262 | v8::Handle<v8::Value> result; |
| 4263 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
| 4264 | if (web_frame) |
| 4265 | result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); |
| 4266 | if (notify_result) { |
| 4267 | bool bool_result = !result.IsEmpty() && result->IsBoolean() ? |
| 4268 | result->BooleanValue() : false; |
| 4269 | Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, bool_result)); |
| 4270 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4271 | } |
| 4272 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4273 | void RenderView::InsertCSS(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4274 | const std::string& css, |
| 4275 | const std::string& id) { |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4276 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 4277 | if (!web_frame) |
| 4278 | return; |
| 4279 | |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4280 | web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4281 | } |
| 4282 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4283 | void RenderView::OnPepperPluginDestroy( |
| 4284 | WebPluginDelegatePepper* pepper_plugin) { |
| 4285 | std::set<WebPluginDelegatePepper*>::iterator found_pepper = |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4286 | current_oldstyle_pepper_plugins_.find(pepper_plugin); |
| 4287 | if (found_pepper == current_oldstyle_pepper_plugins_.end()) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4288 | NOTREACHED(); |
| 4289 | return; |
| 4290 | } |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4291 | current_oldstyle_pepper_plugins_.erase(found_pepper); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4292 | |
| 4293 | // The plugin could have been destroyed while it was waiting for a file |
| 4294 | // choose callback, so check all pending completion callbacks and NULL them. |
| 4295 | for (std::deque< linked_ptr<PendingFileChooser> >::iterator i = |
| 4296 | file_chooser_completions_.begin(); |
| 4297 | i != file_chooser_completions_.end(); /* nothing */) { |
| 4298 | if ((*i)->completion == pepper_plugin) { |
| 4299 | // We NULL the first one instead of deleting it because the plugin might |
| 4300 | // be the one waiting for a file choose callback. If the callback later |
| 4301 | // comes, we don't want to send the result to the next callback in line. |
| 4302 | if (i == file_chooser_completions_.begin()) |
| 4303 | (*i)->completion = NULL; |
| 4304 | else |
| 4305 | i = file_chooser_completions_.erase(i); |
| 4306 | } else { |
| 4307 | ++i; |
| 4308 | } |
| 4309 | } |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4310 | } |
| 4311 | |
[email protected] | 882b7b2 | 2010-10-05 03:34:53 | [diff] [blame] | 4312 | void RenderView::OnScriptEvalRequest(const string16& frame_xpath, |
| 4313 | const string16& jscript, |
| 4314 | int id, |
| 4315 | bool notify_result) { |
| 4316 | EvaluateScript(frame_xpath, jscript, id, notify_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4317 | } |
| 4318 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4319 | void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 4320 | const std::string& css, |
| 4321 | const std::string& id) { |
| 4322 | InsertCSS(frame_xpath, css, id); |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 4323 | |
| 4324 | // Notify RenderViewHost that css has been inserted into the frame. |
| 4325 | Send(new ViewHostMsg_OnCSSInserted(routing_id_)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 4326 | } |
| 4327 | |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 4328 | void RenderView::OnAddMessageToConsole( |
| 4329 | const string16& frame_xpath, |
| 4330 | const string16& message, |
| 4331 | const WebConsoleMessage::Level& level) { |
| 4332 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 4333 | if (web_frame) |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4334 | web_frame->addMessageToConsole(WebConsoleMessage(level, message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4335 | } |
| 4336 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4337 | void RenderView::OnAllowBindings(int enabled_bindings_flags) { |
| 4338 | enabled_bindings_ |= enabled_bindings_flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | void RenderView::OnSetDOMUIProperty(const std::string& name, |
| 4342 | const std::string& value) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 4343 | DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)); |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4344 | GetDOMUIBindings()->SetProperty(name, value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4345 | } |
| 4346 | |
| 4347 | void RenderView::OnReservePageIDRange(int size_of_range) { |
| 4348 | next_page_id_ += size_of_range + 1; |
| 4349 | } |
| 4350 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4351 | void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 4352 | const gfx::Point& screen_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4353 | bool ended, |
| 4354 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4355 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4356 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | daec5d6 | 2010-06-04 09:14:20 | [diff] [blame] | 4357 | } else { |
| 4358 | webview()->dragSourceMovedTo(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 4359 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | void RenderView::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4363 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4364 | } |
| 4365 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4366 | void RenderView::OnFillPasswordForm( |
[email protected] | e768baf | 2010-07-16 19:36:16 | [diff] [blame] | 4367 | const webkit_glue::PasswordFormFillData& form_data) { |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4368 | #if defined(WEBKIT_BUG_41283_IS_FIXED) |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 4369 | password_autocomplete_manager_->ReceivedPasswordFormFillData(webview(), |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4370 | form_data); |
[email protected] | ad24ccb | 2010-07-15 21:38:20 | [diff] [blame] | 4371 | #else |
| 4372 | webkit_glue::FillPasswordForm(this->webview(), form_data); |
[email protected] | 03f5707 | 2010-07-14 17:36:08 | [diff] [blame] | 4373 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4374 | } |
| 4375 | |
| 4376 | void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data, |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4377 | const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4378 | const gfx::Point& screen_point, |
| 4379 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4380 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4381 | drop_data.ToDragData(), |
| 4382 | drop_data.identity, |
| 4383 | client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4384 | screen_point, |
| 4385 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4386 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4387 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4388 | } |
| 4389 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4390 | void RenderView::OnDragTargetDragOver(const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4391 | const gfx::Point& screen_point, |
| 4392 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4393 | WebDragOperation operation = webview()->dragTargetDragOver( |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4394 | client_point, |
| 4395 | screen_point, |
| 4396 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4397 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 4398 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4399 | } |
| 4400 | |
| 4401 | void RenderView::OnDragTargetDragLeave() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4402 | webview()->dragTargetDragLeave(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4403 | } |
| 4404 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 4405 | void RenderView::OnDragTargetDrop(const gfx::Point& client_point, |
| 4406 | const gfx::Point& screen_point) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4407 | webview()->dragTargetDrop(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 4411 | webkit_preferences_ = prefs; |
| 4412 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4413 | } |
| 4414 | |
| 4415 | void RenderView::OnSetAltErrorPageURL(const GURL& url) { |
| 4416 | alternate_error_page_url_ = url; |
| 4417 | } |
| 4418 | |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 4419 | void RenderView::OnCustomContextMenuAction(unsigned action) { |
| 4420 | webview()->performCustomContextMenuAction(action); |
| 4421 | } |
| 4422 | |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4423 | void RenderView::OnTranslatePage(int page_id, |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4424 | const std::string& translate_script, |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4425 | const std::string& source_lang, |
| 4426 | const std::string& target_lang) { |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4427 | translate_helper_.TranslatePage(page_id, source_lang, target_lang, |
| 4428 | translate_script); |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 4429 | } |
| 4430 | |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 4431 | void RenderView::OnRevertTranslation(int page_id) { |
| 4432 | translate_helper_.RevertTranslation(page_id); |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 4433 | } |
| 4434 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4435 | void RenderView::OnInstallMissingPlugin() { |
| 4436 | // This could happen when the first default plugin is deleted. |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 4437 | if (first_default_plugin_) |
| 4438 | first_default_plugin_->InstallMissingPlugin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4439 | } |
| 4440 | |
[email protected] | 97c5c59 | 2010-08-03 08:22:21 | [diff] [blame] | 4441 | void RenderView::OnLoadBlockedPlugins() { |
| 4442 | NotificationService::current()->Notify(NotificationType::SHOULD_LOAD_PLUGINS, |
| 4443 | Source<RenderView>(this), |
| 4444 | NotificationService::NoDetails()); |
| 4445 | } |
| 4446 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4447 | void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4448 | // This could happen if we navigated to a different page before the user |
| 4449 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4450 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 4451 | return; |
| 4452 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4453 | WebVector<WebString> ws_file_names(paths.size()); |
| 4454 | for (size_t i = 0; i < paths.size(); ++i) |
| 4455 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 4456 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4457 | if (file_chooser_completions_.front()->completion) |
| 4458 | file_chooser_completions_.front()->completion->didChooseFile(ws_file_names); |
| 4459 | file_chooser_completions_.pop_front(); |
| 4460 | |
| 4461 | // If there are more pending file chooser requests, schedule one now. |
| 4462 | if (!file_chooser_completions_.empty()) { |
| 4463 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 4464 | file_chooser_completions_.front()->params)); |
| 4465 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | void RenderView::OnEnableViewSourceMode() { |
| 4469 | if (!webview()) |
| 4470 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4471 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4472 | if (!main_frame) |
| 4473 | return; |
| 4474 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4475 | main_frame->enableViewSourceMode(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4476 | } |
| 4477 | |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 4478 | void RenderView::OnEnablePreferredSizeChangedMode(int flags) { |
| 4479 | DCHECK(flags != kPreferredSizeNothing); |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4480 | if (send_preferred_size_changes_) |
| 4481 | return; |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 4482 | send_preferred_size_changes_ = true; |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 4483 | |
| 4484 | // WebKit doesn't send a notification of the effective height of the page |
| 4485 | // changes, so poll for it. |
| 4486 | // TODO: Add a notification for this to WebKit, remove polling. After that's |
| 4487 | // done, rename kPreferredSizeHeightThisIsSlow to kPreferredSizeHeight. |
| 4488 | // http://crbug.com/44850 |
| 4489 | if (flags & kPreferredSizeHeightThisIsSlow) { |
| 4490 | preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this, |
| 4491 | &RenderView::CheckPreferredSize); |
| 4492 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 4493 | } |
| 4494 | |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4495 | void RenderView::OnDisableScrollbarsForSmallWindows( |
| 4496 | const gfx::Size& disable_scrollbar_size_limit) { |
| 4497 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 4498 | } |
| 4499 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4500 | void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { |
| 4501 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 4502 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 0dd6f9b5 | 2010-10-14 16:39:13 | [diff] [blame] | 4503 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 4504 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 4505 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 4506 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 8d1b864d1 | 2010-10-10 00:04:34 | [diff] [blame] | 4507 | gfx::NativeThemeLinux::instance()->SetScrollbarColors( |
| 4508 | renderer_prefs.thumb_inactive_color, |
| 4509 | renderer_prefs.thumb_active_color, |
| 4510 | renderer_prefs.track_color); |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4511 | |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4512 | if (webview()) { |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 4513 | webview()->setScrollbarColors( |
| 4514 | renderer_prefs.thumb_inactive_color, |
| 4515 | renderer_prefs.thumb_active_color, |
| 4516 | renderer_prefs.track_color); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4517 | webview()->setSelectionColors( |
| 4518 | renderer_prefs.active_selection_bg_color, |
| 4519 | renderer_prefs.active_selection_fg_color, |
| 4520 | renderer_prefs.inactive_selection_bg_color, |
| 4521 | renderer_prefs.inactive_selection_fg_color); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 4522 | webview()->themeChanged(); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 4523 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 4524 | #endif |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4525 | } |
| 4526 | |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 4527 | void RenderView::OnMediaPlayerActionAt(const gfx::Point& location, |
| 4528 | const WebMediaPlayerAction& action) { |
| 4529 | if (webview()) |
| 4530 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 4531 | } |
| 4532 | |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 4533 | void RenderView::OnNotifyRendererViewType(ViewType::Type type) { |
| 4534 | view_type_ = type; |
| 4535 | } |
| 4536 | |
| 4537 | void RenderView::OnUpdateBrowserWindowId(int window_id) { |
| 4538 | browser_window_id_ = window_id; |
| 4539 | } |
| 4540 | |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 4541 | void RenderView::OnEnableAccessibility() { |
| 4542 | if (WebAccessibilityCache::accessibilityEnabled()) |
| 4543 | return; |
[email protected] | 9f4db51 | 2010-05-10 20:21:41 | [diff] [blame] | 4544 | |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 4545 | WebAccessibilityCache::enableAccessibility(); |
| 4546 | |
| 4547 | if (webview()) { |
| 4548 | // It's possible that the webview has already loaded a webpage without |
| 4549 | // accessibility being enabled. Initialize the browser's cached |
| 4550 | // accessibility tree by sending it a 'load complete' notification. |
| 4551 | postAccessibilityNotification( |
| 4552 | webview()->accessibilityObject(), |
| 4553 | WebKit::WebAccessibilityNotificationLoadComplete); |
| 4554 | } |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 4555 | } |
| 4556 | |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4557 | void RenderView::OnSetAccessibilityFocus(int acc_obj_id) { |
| 4558 | if (!accessibility_.get()) |
| 4559 | return; |
[email protected] | 02ea2f31 | 2010-09-27 17:03:36 | [diff] [blame] | 4560 | |
| 4561 | WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id); |
| 4562 | WebAccessibilityObject root = webview()->accessibilityObject(); |
| 4563 | if (!obj.isValid() || !root.isValid()) |
| 4564 | return; |
| 4565 | |
| 4566 | // By convention, calling SetFocus on the root of the tree should clear the |
| 4567 | // current focus. Otherwise set the focus to the new node. |
| 4568 | if (accessibility_->addOrGetId(obj) == accessibility_->addOrGetId(root)) |
| 4569 | webview()->clearFocusedNode(); |
| 4570 | else |
| 4571 | obj.setFocused(true); |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4572 | } |
| 4573 | |
| 4574 | void RenderView::OnAccessibilityDoDefaultAction(int acc_obj_id) { |
| 4575 | if (!accessibility_.get()) |
| 4576 | return; |
[email protected] | 02ea2f31 | 2010-09-27 17:03:36 | [diff] [blame] | 4577 | |
| 4578 | WebAccessibilityObject obj = accessibility_->getObjectById(acc_obj_id); |
| 4579 | if (!obj.isValid()) |
| 4580 | return; |
| 4581 | |
| 4582 | obj.performDefaultAction(); |
[email protected] | aef9284 | 2010-05-21 16:54:36 | [diff] [blame] | 4583 | } |
| 4584 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 4585 | void RenderView::OnAccessibilityNotificationsAck() { |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 4586 | DCHECK(accessibility_ack_pending_); |
| 4587 | accessibility_ack_pending_ = false; |
| 4588 | SendPendingAccessibilityNotifications(); |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 4589 | } |
| 4590 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4591 | void RenderView::OnGetAllSavableResourceLinksForCurrentPage( |
| 4592 | const GURL& page_url) { |
| 4593 | // Prepare list to storage all savable resource links. |
| 4594 | std::vector<GURL> resources_list; |
| 4595 | std::vector<GURL> referrers_list; |
| 4596 | std::vector<GURL> frames_list; |
| 4597 | webkit_glue::SavableResourcesResult result(&resources_list, |
| 4598 | &referrers_list, |
| 4599 | &frames_list); |
| 4600 | |
[email protected] | dbeb395 | 2009-10-13 18:01:18 | [diff] [blame] | 4601 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 4602 | webview(), |
| 4603 | page_url, |
| 4604 | &result, |
| 4605 | chrome::kSavableSchemes)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4606 | // If something is wrong when collecting all savable resource links, |
| 4607 | // send empty list to embedder(browser) to tell it failed. |
| 4608 | referrers_list.clear(); |
| 4609 | resources_list.clear(); |
| 4610 | frames_list.clear(); |
| 4611 | } |
| 4612 | |
| 4613 | // Send result of all savable resource links to embedder. |
| 4614 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_, |
| 4615 | resources_list, |
| 4616 | referrers_list, |
| 4617 | frames_list)); |
| 4618 | } |
| 4619 | |
| 4620 | void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | f6b4853 | 2009-02-12 01:56:32 | [diff] [blame] | 4621 | const std::vector<GURL>& links, |
[email protected] | fde6714d1 | 2009-02-18 22:39:31 | [diff] [blame] | 4622 | const std::vector<FilePath>& local_paths, |
| 4623 | const FilePath& local_directory_name) { |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4624 | |
| 4625 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 4626 | WebVector<WebURL> weburl_links(links); |
| 4627 | |
| 4628 | // Convert std::vector of std::strings to WebVector<WebString> |
| 4629 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 4630 | for (size_t i = 0; i < local_paths.size(); i++) |
| 4631 | webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); |
| 4632 | |
| 4633 | WebPageSerializer::serialize(webview()->mainFrame(), |
| 4634 | true, this, weburl_links, webstring_paths, |
| 4635 | webkit_glue::FilePathToWebString( |
| 4636 | local_directory_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4637 | } |
| 4638 | |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 4639 | void RenderView::didSerializeDataForFrame(const WebURL& frame_url, |
| 4640 | const WebCString& data, |
| 4641 | WebPageSerializerClient::PageSerializationStatus status) { |
| 4642 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 4643 | routing_id_, |
| 4644 | frame_url, |
| 4645 | data.data(), |
| 4646 | static_cast<int32>(status))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4647 | } |
| 4648 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 4649 | void RenderView::OnShouldClose() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4650 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 4651 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4652 | } |
| 4653 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4654 | void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4655 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 4656 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 4657 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 4658 | // calling the FrameLoader's CloseURL method directly. This should be |
| 4659 | // revisited to avoid having two ways to close a page. Having a single way |
| 4660 | // to close that can run onunload is also useful for fixing |
| 4661 | // http://b/issue?id=753080. |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 4662 | WebFrame* main_frame = webview()->mainFrame(); |
| 4663 | if (main_frame) { |
| 4664 | const GURL& url = main_frame->url(); |
| 4665 | // TODO(davemoore) this code should be removed once willClose() gets |
| 4666 | // called when a page is destroyed. DumpLoadHistograms() is safe to call |
| 4667 | // multiple times for the same frame, but it will simplify things. |
| 4668 | |
| 4669 | // Ensure state contains scheme. |
| 4670 | NavigationState* navigation_state = |
| 4671 | NavigationState::FromDataSource(main_frame->dataSource()); |
| 4672 | if (url.SchemeIs("http")) |
| 4673 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTP); |
| 4674 | else if (url.SchemeIs("https")) |
| 4675 | navigation_state->set_scheme_type(URLPattern::SCHEME_HTTPS); |
| 4676 | |
| 4677 | // Dump will only be provided when scheme is http or https. |
| 4678 | DumpLoadHistograms(); |
| 4679 | } |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4680 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4681 | |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 4682 | // Reset stats |
| 4683 | cross_origin_access_count_ = 0; |
| 4684 | same_origin_access_count_ = 0; |
| 4685 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4686 | // Just echo back the params in the ACK. |
| 4687 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4688 | } |
| 4689 | |
| 4690 | void RenderView::OnThemeChanged() { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4691 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4692 | gfx::NativeTheme::instance()->CloseHandles(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 4693 | if (webview()) |
| 4694 | webview()->themeChanged(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4695 | #else // defined(OS_WIN) |
| 4696 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 4697 | NOTIMPLEMENTED(); |
| 4698 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4699 | } |
| 4700 | |
[email protected] | 9b18a84f | 2010-06-10 15:54:04 | [diff] [blame] | 4701 | void RenderView::OnHandleMessageFromExternalHost(const std::string& message, |
| 4702 | const std::string& origin, |
| 4703 | const std::string& target) { |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4704 | if (message.empty()) |
| 4705 | return; |
[email protected] | c091c2c | 2010-09-17 19:05:46 | [diff] [blame] | 4706 | GetExternalHostBindings()->ForwardMessageFromExternalHost(message, origin, |
| 4707 | target); |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4708 | } |
| 4709 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 4710 | void RenderView::OnDisassociateFromPopupCount() { |
| 4711 | if (decrement_shared_popup_at_destruction_) |
| 4712 | shared_popup_counter_->data--; |
| 4713 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 4714 | decrement_shared_popup_at_destruction_ = false; |
| 4715 | } |
| 4716 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4717 | bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 4718 | const WebURLError& error, |
| 4719 | bool replace) { |
| 4720 | // We only show alternate error pages in the main frame. They are |
| 4721 | // intended to assist the user when navigating, so there is not much |
| 4722 | // value in showing them for failed subframes. Ideally, we would be |
| 4723 | // able to use the TYPED transition type for this, but that flag is |
| 4724 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4725 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4726 | return false; |
| 4727 | |
| 4728 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4729 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4730 | int ec = error.reason; |
| 4731 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 4732 | ec != net::ERR_CONNECTION_FAILED && |
| 4733 | ec != net::ERR_CONNECTION_REFUSED && |
| 4734 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4735 | ec != net::ERR_CONNECTION_TIMED_OUT) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4736 | return false; |
| 4737 | |
| 4738 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4739 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4740 | if (!error_page_url.is_valid()) |
| 4741 | return false; |
| 4742 | |
| 4743 | // Load an empty page first so there is an immediate response to the error, |
| 4744 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4745 | frame->loadHTMLString(std::string(), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4746 | GURL(kUnreachableWebDataURL), |
| 4747 | error.unreachableURL, |
| 4748 | replace); |
| 4749 | |
| 4750 | // Now, create a fetcher for the error page and associate it with the data |
| 4751 | // source we just created via the LoadHTMLString call. That way if another |
| 4752 | // navigation occurs, the fetcher will get destroyed. |
| 4753 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4754 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4755 | navigation_state->set_alt_error_page_fetcher( |
| 4756 | new AltErrorPageResourceFetcher( |
| 4757 | error_page_url, frame, error, |
| 4758 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 4759 | return true; |
| 4760 | } |
| 4761 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4762 | std::string RenderView::GetAltHTMLForTemplate( |
| 4763 | const DictionaryValue& error_strings, int template_resource_id) const { |
[email protected] | 8a16266e | 2009-09-10 21:08:39 | [diff] [blame] | 4764 | const base::StringPiece template_html( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4765 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 4766 | template_resource_id)); |
| 4767 | |
| 4768 | if (template_html.empty()) { |
| 4769 | NOTREACHED() << "unable to load template. ID: " << template_resource_id; |
| 4770 | return ""; |
| 4771 | } |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4772 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4773 | // "t" is the id of the templates root node. |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4774 | return jstemplate_builder::GetTemplatesHtml( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4775 | template_html, &error_strings, "t"); |
| 4776 | } |
[email protected] | 0e79b9e | 2009-02-13 04:20:48 | [diff] [blame] | 4777 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4778 | void RenderView::AltErrorPageFinished(WebFrame* frame, |
| 4779 | const WebURLError& original_error, |
| 4780 | const std::string& html) { |
| 4781 | // Here, we replace the blank page we loaded previously. |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4782 | |
| 4783 | // If we failed to download the alternate error page, fall back to the |
| 4784 | // original error page if present. Otherwise, LoadNavigationErrorPage |
| 4785 | // will simply display a default error page. |
| 4786 | const std::string* html_to_load = &html; |
| 4787 | if (html.empty()) { |
| 4788 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4789 | NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4790 | html_to_load = &navigation_state->postponed_data(); |
| 4791 | } |
[email protected] | 3f853a5 | 2010-09-13 19:15:08 | [diff] [blame] | 4792 | LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load, |
| 4793 | true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4794 | } |
| 4795 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4796 | void RenderView::OnMoveOrResizeStarted() { |
| 4797 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4798 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4799 | } |
| 4800 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4801 | void RenderView::OnResize(const gfx::Size& new_size, |
| 4802 | const gfx::Rect& resizer_rect) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4803 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4804 | webview()->hidePopups(); |
[email protected] | 98e92fe2 | 2010-09-24 22:15:13 | [diff] [blame] | 4805 | |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4806 | if (send_preferred_size_changes_) { |
[email protected] | 98e92fe2 | 2010-09-24 22:15:13 | [diff] [blame] | 4807 | // If resizing to a size larger than |disable_scrollbars_size_limit_| in |
| 4808 | // either width or height, allow scroll bars. |
| 4809 | bool allow_scrollbars = ( |
| 4810 | disable_scrollbars_size_limit_.width() <= new_size.width() || |
| 4811 | disable_scrollbars_size_limit_.height() <= new_size.height()); |
| 4812 | webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4813 | } |
| 4814 | } |
| 4815 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4816 | RenderWidget::OnResize(new_size, resizer_rect); |
| 4817 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 4818 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4819 | void RenderView::DidInitiatePaint() { |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4820 | // Notify the pepper plugins that we started painting. |
| 4821 | pepper_delegate_.ViewInitiatedPaint(); |
| 4822 | |
| 4823 | // Notify any "old-style" pepper plugins that we started painting. This is |
| 4824 | // used for internal bookkeeping only, so we know that the set can not change |
| 4825 | // under us. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4826 | for (std::set<WebPluginDelegatePepper*>::iterator i = |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4827 | current_oldstyle_pepper_plugins_.begin(); |
| 4828 | i != current_oldstyle_pepper_plugins_.end(); ++i) |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4829 | (*i)->RenderViewInitiatedPaint(); |
| 4830 | } |
| 4831 | |
| 4832 | void RenderView::DidFlushPaint() { |
| 4833 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 4834 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 4835 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 4836 | // won't change out from under us. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4837 | pepper_delegate_.ViewFlushedPaint(); |
| 4838 | |
| 4839 | // Notify any old-style pepper plugins that we painted. This will call into |
| 4840 | // the plugin, and we it may ask to close itself as a result. This will, in |
| 4841 | // turn, modify our set, possibly invalidating the iterator. So we iterate on |
| 4842 | // a copy that won't change out from under us. |
| 4843 | // This should be deleted when we don't support old Pepper anymore. |
| 4844 | std::set<WebPluginDelegatePepper*> plugins = current_oldstyle_pepper_plugins_; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4845 | for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin(); |
| 4846 | i != plugins.end(); ++i) { |
| 4847 | // The copy above makes sure our iterator is never invalid if some plugins |
| 4848 | // are destroyed. But some plugin may decide to close all of its views in |
| 4849 | // response to a paint in one of them, so we need to make sure each one is |
| 4850 | // still "current" before using it. |
[email protected] | 53900d5 | 2010-06-16 04:25:01 | [diff] [blame] | 4851 | if (current_oldstyle_pepper_plugins_.find(*i) != |
| 4852 | current_oldstyle_pepper_plugins_.end()) |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4853 | (*i)->RenderViewFlushedPaint(); |
| 4854 | } |
| 4855 | |
| 4856 | WebFrame* main_frame = webview()->mainFrame(); |
| 4857 | |
| 4858 | // If we have a provisional frame we are between the start and commit stages |
| 4859 | // of loading and we don't want to save stats. |
| 4860 | if (!main_frame->provisionalDataSource()) { |
| 4861 | WebDataSource* ds = main_frame->dataSource(); |
| 4862 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 4863 | DCHECK(navigation_state); |
| 4864 | |
[email protected] | 05c8e50 | 2010-08-15 15:13:52 | [diff] [blame] | 4865 | // TODO(jar): The following code should all be inside a method, probably in |
| 4866 | // NavigatorState. |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4867 | Time now = Time::Now(); |
| 4868 | if (navigation_state->first_paint_time().is_null()) { |
| 4869 | navigation_state->set_first_paint_time(now); |
| 4870 | } |
| 4871 | if (navigation_state->first_paint_after_load_time().is_null() && |
| 4872 | !navigation_state->finish_load_time().is_null()) { |
| 4873 | navigation_state->set_first_paint_after_load_time(now); |
| 4874 | } |
| 4875 | } |
| 4876 | } |
| 4877 | |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 4878 | bool RenderView::GetBitmapForOptimizedPluginPaint( |
| 4879 | const gfx::Rect& paint_bounds, |
| 4880 | TransportDIB** dib, |
| 4881 | gfx::Rect* location, |
| 4882 | gfx::Rect* clip) { |
| 4883 | return pepper_delegate_.GetBitmapForOptimizedPluginPaint( |
| 4884 | paint_bounds, dib, location, clip); |
| 4885 | } |
| 4886 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4887 | void RenderView::OnClearFocusedNode() { |
| 4888 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4889 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4890 | } |
| 4891 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4892 | void RenderView::OnSetBackground(const SkBitmap& background) { |
| 4893 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4894 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4895 | |
| 4896 | SetBackground(background); |
| 4897 | } |
| 4898 | |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4899 | void RenderView::OnSetActive(bool active) { |
| 4900 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4901 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 4902 | |
| 4903 | #if defined(OS_MACOSX) |
| 4904 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4905 | for (plugin_it = plugin_delegates_.begin(); |
| 4906 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4907 | (*plugin_it)->SetWindowFocus(active); |
| 4908 | } |
| 4909 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4910 | } |
| 4911 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4912 | #if defined(OS_MACOSX) |
| 4913 | void RenderView::OnSetWindowVisibility(bool visible) { |
| 4914 | // Inform plugins that their container has changed visibility. |
| 4915 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4916 | for (plugin_it = plugin_delegates_.begin(); |
| 4917 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4918 | (*plugin_it)->SetContainerVisibility(visible); |
| 4919 | } |
| 4920 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4921 | |
[email protected] | 4d51d5bf | 2010-07-26 18:48:26 | [diff] [blame] | 4922 | void RenderView::OnWindowFrameChanged(const gfx::Rect& window_frame, |
| 4923 | const gfx::Rect& view_frame) { |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4924 | // Inform plugins that their window's frame has changed. |
| 4925 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4926 | for (plugin_it = plugin_delegates_.begin(); |
| 4927 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4928 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 4929 | } |
| 4930 | } |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 4931 | |
| 4932 | void RenderView::OnPluginImeCompositionConfirmed(const string16& text, |
| 4933 | int plugin_id) { |
| 4934 | // WebPluginDelegateProxy is responsible for figuring out if this text |
| 4935 | // applies to it or not, so inform all the delegates. |
| 4936 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4937 | for (plugin_it = plugin_delegates_.begin(); |
| 4938 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4939 | (*plugin_it)->ImeCompositionConfirmed(text, plugin_id); |
| 4940 | } |
| 4941 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4942 | #endif // OS_MACOSX |
| 4943 | |
[email protected] | 8b8e7c9 | 2010-08-19 18:05:56 | [diff] [blame] | 4944 | void RenderView::SendExtensionRequest( |
| 4945 | const ViewHostMsg_DomMessage_Params& params) { |
| 4946 | Send(new ViewHostMsg_ExtensionRequest(routing_id_, params)); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4947 | } |
| 4948 | |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 4949 | void RenderView::OnExtensionResponse(int request_id, |
| 4950 | bool success, |
| 4951 | const std::string& response, |
| 4952 | const std::string& error) { |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 4953 | ExtensionProcessBindings::HandleResponse( |
| 4954 | request_id, success, response, error); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4955 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4956 | |
[email protected] | a7ab1b78 | 2010-10-21 23:24:16 | [diff] [blame] | 4957 | void RenderView::OnExtensionMessageInvoke(const std::string& extension_id, |
| 4958 | const std::string& function_name, |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4959 | const ListValue& args, |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 4960 | const GURL& event_url) { |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4961 | RendererExtensionBindings::Invoke( |
[email protected] | a7ab1b78 | 2010-10-21 23:24:16 | [diff] [blame] | 4962 | extension_id, function_name, args, this, event_url); |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 4963 | } |
| 4964 | |
[email protected] | d03088ee7 | 2010-10-22 21:27:10 | [diff] [blame] | 4965 | // Dump all load time histograms. |
| 4966 | // |
| 4967 | // The time points we keep are |
| 4968 | // request: time document was requested by user |
| 4969 | // start: time load of document started |
| 4970 | // commit: time load of document started |
| 4971 | // finish_document: main document loaded, before onload() |
| 4972 | // finish_all_loads: after onload() and all resources are loaded |
| 4973 | // first_paint: first paint performed |
| 4974 | // first_paint_after_load: first paint performed after load is finished |
| 4975 | // begin: request if it was user requested, start otherwise |
| 4976 | // |
| 4977 | // It's possible for the request time not to be set, if a client |
| 4978 | // redirect had been done (the user never requested the page) |
| 4979 | // Also, it's possible to load a page without ever laying it out |
| 4980 | // so first_paint and first_paint_after_load can be 0. |
| 4981 | void RenderView::DumpLoadHistograms() const { |
| 4982 | // Configuration for PLT related histograms. |
| 4983 | static const TimeDelta kPLTMin(TimeDelta::FromMilliseconds(10)); |
| 4984 | static const TimeDelta kPLTMax(TimeDelta::FromMinutes(10)); |
| 4985 | static const size_t kPLTCount(100); |
| 4986 | #define PLT_HISTOGRAM(name, sample) \ |
| 4987 | UMA_HISTOGRAM_CUSTOM_TIMES(name, sample, kPLTMin, kPLTMax, kPLTCount); |
| 4988 | |
| 4989 | WebFrame* main_frame = webview()->mainFrame(); |
| 4990 | NavigationState* navigation_state = |
| 4991 | NavigationState::FromDataSource(main_frame->dataSource()); |
| 4992 | |
| 4993 | URLPattern::SchemeMasks scheme_type = navigation_state->scheme_type(); |
| 4994 | if (scheme_type == 0) |
| 4995 | return; |
| 4996 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP || |
| 4997 | scheme_type == URLPattern::SCHEME_HTTPS); |
| 4998 | |
| 4999 | // If we've already dumped, do nothing. |
| 5000 | if (navigation_state->load_histograms_recorded()) |
| 5001 | return; |
| 5002 | |
| 5003 | // Collect measurement times. |
| 5004 | Time start = navigation_state->start_load_time(); |
| 5005 | if (start.is_null()) |
| 5006 | return; // Probably very premature abandonment of page. |
| 5007 | Time commit = navigation_state->commit_load_time(); |
| 5008 | if (commit.is_null()) |
| 5009 | return; // Probably very premature abandonment of page. |
| 5010 | |
| 5011 | // We properly handle null values for the next 3 variables. |
| 5012 | Time request = navigation_state->request_time(); |
| 5013 | Time first_paint = navigation_state->first_paint_time(); |
| 5014 | Time first_paint_after_load = navigation_state->first_paint_after_load_time(); |
| 5015 | Time finish_doc = navigation_state->finish_document_load_time(); |
| 5016 | Time finish_all_loads = navigation_state->finish_load_time(); |
| 5017 | |
| 5018 | // Handle case where user hits "stop" or "back" before loading completely. |
| 5019 | bool abandoned_page = finish_doc.is_null(); |
| 5020 | if (abandoned_page) { |
| 5021 | finish_doc = Time::Now(); |
| 5022 | navigation_state->set_finish_document_load_time(finish_doc); |
| 5023 | } |
| 5024 | |
| 5025 | // TODO(jar): We should really discriminate the definition of "abandon" more |
| 5026 | // finely. We should have: |
| 5027 | // abandon_before_document_loaded |
| 5028 | // abandon_before_onload_fired |
| 5029 | |
| 5030 | if (finish_all_loads.is_null()) { |
| 5031 | finish_all_loads = Time::Now(); |
| 5032 | navigation_state->set_finish_load_time(finish_all_loads); |
| 5033 | } else { |
| 5034 | DCHECK(!abandoned_page); // How can the doc have finished but not the page? |
| 5035 | if (!abandoned_page) |
| 5036 | return; // Don't try to record a stat which is broken. |
| 5037 | } |
| 5038 | |
| 5039 | // Note: Client side redirects will have no request time. |
| 5040 | Time begin = request.is_null() ? start : request; |
| 5041 | TimeDelta begin_to_finish_doc = finish_doc - begin; |
| 5042 | TimeDelta begin_to_finish_all_loads = finish_all_loads - begin; |
| 5043 | TimeDelta start_to_finish_all_loads = finish_all_loads - start; |
| 5044 | TimeDelta start_to_commit = commit - start; |
| 5045 | |
| 5046 | NavigationState::LoadType load_type = navigation_state->load_type(); |
| 5047 | |
| 5048 | // The above code sanitized all values of times, in preparation for creating |
| 5049 | // actual histograms. The remainder of this code could be run at destructor |
| 5050 | // time for the navigation_state, since all data is intact. |
| 5051 | |
| 5052 | // Aggregate PLT data across all link types. |
| 5053 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned", abandoned_page ? 1 : 0, 2); |
| 5054 | UMA_HISTOGRAM_ENUMERATION("PLT.LoadType", load_type, |
| 5055 | NavigationState::kLoadTypeMax); |
| 5056 | PLT_HISTOGRAM("PLT.StartToCommit", start_to_commit); |
| 5057 | PLT_HISTOGRAM("PLT.CommitToFinishDoc", finish_doc - commit); |
| 5058 | PLT_HISTOGRAM("PLT.FinishDocToFinish", finish_all_loads - finish_doc); |
| 5059 | PLT_HISTOGRAM("PLT.BeginToCommit", commit - begin); |
| 5060 | PLT_HISTOGRAM("PLT.StartToFinish", start_to_finish_all_loads); |
| 5061 | if (!request.is_null()) { |
| 5062 | PLT_HISTOGRAM("PLT.RequestToStart", start - request); |
| 5063 | PLT_HISTOGRAM("PLT.RequestToFinish", finish_all_loads - request); |
| 5064 | } |
| 5065 | PLT_HISTOGRAM("PLT.CommitToFinish", finish_all_loads - commit); |
| 5066 | if (!first_paint.is_null()) { |
| 5067 | DCHECK(begin <= first_paint); |
| 5068 | PLT_HISTOGRAM("PLT.BeginToFirstPaint", first_paint - begin); |
| 5069 | DCHECK(commit <= first_paint); |
| 5070 | PLT_HISTOGRAM("PLT.CommitToFirstPaint", first_paint - commit); |
| 5071 | } |
| 5072 | if (!first_paint_after_load.is_null()) { |
| 5073 | DCHECK(begin <= first_paint_after_load); |
| 5074 | PLT_HISTOGRAM("PLT.BeginToFirstPaintAfterLoad", |
| 5075 | first_paint_after_load - begin); |
| 5076 | DCHECK(commit <= first_paint_after_load); |
| 5077 | PLT_HISTOGRAM("PLT.CommitToFirstPaintAfterLoad", |
| 5078 | first_paint_after_load - commit); |
| 5079 | DCHECK(finish_all_loads <= first_paint_after_load); |
| 5080 | PLT_HISTOGRAM("PLT.FinishToFirstPaintAfterLoad", |
| 5081 | first_paint_after_load - finish_all_loads); |
| 5082 | } |
| 5083 | PLT_HISTOGRAM("PLT.BeginToFinishDoc", begin_to_finish_doc); |
| 5084 | PLT_HISTOGRAM("PLT.BeginToFinish", begin_to_finish_all_loads); |
| 5085 | |
| 5086 | // Load type related histograms. |
| 5087 | switch (load_type) { |
| 5088 | case NavigationState::UNDEFINED_LOAD: |
| 5089 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_UndefLoad", begin_to_finish_doc); |
| 5090 | PLT_HISTOGRAM("PLT.BeginToFinish_UndefLoad", begin_to_finish_all_loads); |
| 5091 | break; |
| 5092 | case NavigationState::RELOAD: |
| 5093 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_Reload", begin_to_finish_doc); |
| 5094 | PLT_HISTOGRAM("PLT.BeginToFinish_Reload", begin_to_finish_all_loads); |
| 5095 | break; |
| 5096 | case NavigationState::HISTORY_LOAD: |
| 5097 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_HistoryLoad", begin_to_finish_doc); |
| 5098 | PLT_HISTOGRAM("PLT.BeginToFinish_HistoryLoad", begin_to_finish_all_loads); |
| 5099 | break; |
| 5100 | case NavigationState::NORMAL_LOAD: |
| 5101 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_NormalLoad", begin_to_finish_doc); |
| 5102 | PLT_HISTOGRAM("PLT.BeginToFinish_NormalLoad", begin_to_finish_all_loads); |
| 5103 | break; |
| 5104 | case NavigationState::LINK_LOAD_NORMAL: |
| 5105 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadNormal", |
| 5106 | begin_to_finish_doc); |
| 5107 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadNormal", |
| 5108 | begin_to_finish_all_loads); |
| 5109 | break; |
| 5110 | case NavigationState::LINK_LOAD_RELOAD: |
| 5111 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadReload", |
| 5112 | begin_to_finish_doc); |
| 5113 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadReload", |
| 5114 | begin_to_finish_all_loads); |
| 5115 | break; |
| 5116 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5117 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadStaleOk", |
| 5118 | begin_to_finish_doc); |
| 5119 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadStaleOk", |
| 5120 | begin_to_finish_all_loads); |
| 5121 | break; |
| 5122 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 5123 | PLT_HISTOGRAM("PLT.BeginToFinishDoc_LinkLoadCacheOnly", |
| 5124 | begin_to_finish_doc); |
| 5125 | PLT_HISTOGRAM("PLT.BeginToFinish_LinkLoadCacheOnly", |
| 5126 | begin_to_finish_all_loads); |
| 5127 | break; |
| 5128 | default: |
| 5129 | break; |
| 5130 | } |
| 5131 | |
| 5132 | // Histograms to determine if DNS prefetching has an impact on PLT. |
| 5133 | static bool use_dns_histogram(base::FieldTrialList::Find("DnsImpact") && |
| 5134 | !base::FieldTrialList::Find("DnsImpact")->group_name().empty()); |
| 5135 | if (use_dns_histogram) { |
| 5136 | UMA_HISTOGRAM_ENUMERATION( |
| 5137 | base::FieldTrial::MakeName("PLT.Abandoned", "DnsImpact"), |
| 5138 | abandoned_page ? 1 : 0, 2); |
| 5139 | UMA_HISTOGRAM_ENUMERATION( |
| 5140 | base::FieldTrial::MakeName("PLT.LoadType", "DnsImpact"), |
| 5141 | load_type, NavigationState::kLoadTypeMax); |
| 5142 | switch (load_type) { |
| 5143 | case NavigationState::NORMAL_LOAD: |
| 5144 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5145 | "PLT.BeginToFinish_NormalLoad", "DnsImpact"), |
| 5146 | begin_to_finish_all_loads); |
| 5147 | break; |
| 5148 | case NavigationState::LINK_LOAD_NORMAL: |
| 5149 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5150 | "PLT.BeginToFinish_LinkLoadNormal", "DnsImpact"), |
| 5151 | begin_to_finish_all_loads); |
| 5152 | break; |
| 5153 | case NavigationState::LINK_LOAD_RELOAD: |
| 5154 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5155 | "PLT.BeginToFinish_LinkLoadReload", "DnsImpact"), |
| 5156 | begin_to_finish_all_loads); |
| 5157 | break; |
| 5158 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5159 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5160 | "PLT.BeginToFinish_LinkLoadStaleOk", "DnsImpact"), |
| 5161 | begin_to_finish_all_loads); |
| 5162 | break; |
| 5163 | default: |
| 5164 | break; |
| 5165 | } |
| 5166 | } |
| 5167 | |
| 5168 | // Histograms to determine if content prefetching has an impact on PLT. |
| 5169 | static const bool prefetching_fieldtrial = |
| 5170 | base::FieldTrialList::Find("Prefetch") && |
| 5171 | !base::FieldTrialList::Find("Prefetch")->group_name().empty(); |
| 5172 | if (prefetching_fieldtrial) { |
| 5173 | if (navigation_state->was_prefetcher()) { |
| 5174 | PLT_HISTOGRAM( |
| 5175 | base::FieldTrial::MakeName("PLT.BeginToFinishDoc_ContentPrefetcher", |
| 5176 | "Prefetch"), |
| 5177 | begin_to_finish_doc); |
| 5178 | PLT_HISTOGRAM( |
| 5179 | base::FieldTrial::MakeName("PLT.BeginToFinish_ContentPrefetcher", |
| 5180 | "Prefetch"), |
| 5181 | begin_to_finish_all_loads); |
| 5182 | } |
| 5183 | if (navigation_state->was_referred_by_prefetcher()) { |
| 5184 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5185 | "PLT.BeginToFinishDoc_ContentPrefetcherReferrer", |
| 5186 | "Prefetch"), |
| 5187 | begin_to_finish_doc); |
| 5188 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5189 | "PLT.BeginToFinish_ContentPrefetcherReferrer", |
| 5190 | "Prefetch"), |
| 5191 | begin_to_finish_all_loads); |
| 5192 | } |
| 5193 | UMA_HISTOGRAM_ENUMERATION( |
| 5194 | base::FieldTrial::MakeName("PLT.Abandoned", "Prefetch"), |
| 5195 | abandoned_page ? 1 : 0, 2); |
| 5196 | PLT_HISTOGRAM(base::FieldTrial::MakeName("PLT.BeginToFinishDoc", |
| 5197 | "Prefetch"), |
| 5198 | begin_to_finish_doc); |
| 5199 | PLT_HISTOGRAM(base::FieldTrial::MakeName("PLT.BeginToFinish", "Prefetch"), |
| 5200 | begin_to_finish_all_loads); |
| 5201 | } |
| 5202 | |
| 5203 | // Histograms to determine if backup connection jobs have an impact on PLT. |
| 5204 | static const bool connect_backup_jobs_fieldtrial( |
| 5205 | base::FieldTrialList::Find("ConnnectBackupJobs") && |
| 5206 | !base::FieldTrialList::Find("ConnnectBackupJobs")->group_name().empty()); |
| 5207 | if (connect_backup_jobs_fieldtrial) { |
| 5208 | UMA_HISTOGRAM_ENUMERATION( |
| 5209 | base::FieldTrial::MakeName("PLT.Abandoned", "ConnnectBackupJobs"), |
| 5210 | abandoned_page ? 1 : 0, 2); |
| 5211 | UMA_HISTOGRAM_ENUMERATION( |
| 5212 | base::FieldTrial::MakeName("PLT.LoadType", "ConnnectBackupJobs"), |
| 5213 | load_type, NavigationState::kLoadTypeMax); |
| 5214 | switch (load_type) { |
| 5215 | case NavigationState::NORMAL_LOAD: |
| 5216 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5217 | "PLT.BeginToFinish_NormalLoad", "ConnnectBackupJobs"), |
| 5218 | begin_to_finish_all_loads); |
| 5219 | break; |
| 5220 | case NavigationState::LINK_LOAD_NORMAL: |
| 5221 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5222 | "PLT.BeginToFinish_LinkLoadNormal", "ConnnectBackupJobs"), |
| 5223 | begin_to_finish_all_loads); |
| 5224 | break; |
| 5225 | case NavigationState::LINK_LOAD_RELOAD: |
| 5226 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5227 | "PLT.BeginToFinish_LinkLoadReload", "ConnnectBackupJobs"), |
| 5228 | begin_to_finish_all_loads); |
| 5229 | break; |
| 5230 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5231 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5232 | "PLT.BeginToFinish_LinkLoadStaleOk", "ConnnectBackupJobs"), |
| 5233 | begin_to_finish_all_loads); |
| 5234 | break; |
| 5235 | default: |
| 5236 | break; |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | // Histograms to determine if the number of connections has an |
| 5241 | // impact on PLT. |
| 5242 | // TODO(jar): Consider removing the per-link-type versions. We |
| 5243 | // really only need LINK_LOAD_NORMAL and NORMAL_LOAD. |
| 5244 | static bool use_connection_impact_histogram( |
| 5245 | base::FieldTrialList::Find("ConnCountImpact") && |
| 5246 | !base::FieldTrialList::Find("ConnCountImpact")->group_name().empty()); |
| 5247 | if (use_connection_impact_histogram) { |
| 5248 | UMA_HISTOGRAM_ENUMERATION( |
| 5249 | base::FieldTrial::MakeName("PLT.Abandoned", "ConnCountImpact"), |
| 5250 | abandoned_page ? 1 : 0, 2); |
| 5251 | switch (load_type) { |
| 5252 | case NavigationState::NORMAL_LOAD: |
| 5253 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5254 | "PLT.BeginToFinish_NormalLoad", "ConnCountImpact"), |
| 5255 | begin_to_finish_all_loads); |
| 5256 | break; |
| 5257 | case NavigationState::LINK_LOAD_NORMAL: |
| 5258 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5259 | "PLT.BeginToFinish_LinkLoadNormal", "ConnCountImpact"), |
| 5260 | begin_to_finish_all_loads); |
| 5261 | break; |
| 5262 | case NavigationState::LINK_LOAD_RELOAD: |
| 5263 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5264 | "PLT.BeginToFinish_LinkLoadReload", "ConnCountImpact"), |
| 5265 | begin_to_finish_all_loads); |
| 5266 | break; |
| 5267 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5268 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5269 | "PLT.BeginToFinish_LinkLoadStaleOk", "ConnCountImpact"), |
| 5270 | begin_to_finish_all_loads); |
| 5271 | break; |
| 5272 | default: |
| 5273 | break; |
| 5274 | } |
| 5275 | } |
| 5276 | |
| 5277 | // Histograms to determine effect of idle socket timeout. |
| 5278 | static bool use_idle_socket_timeout_histogram( |
| 5279 | base::FieldTrialList::Find("IdleSktToImpact") && |
| 5280 | !base::FieldTrialList::Find("IdleSktToImpact")->group_name().empty()); |
| 5281 | if (use_idle_socket_timeout_histogram) { |
| 5282 | UMA_HISTOGRAM_ENUMERATION( |
| 5283 | base::FieldTrial::MakeName("PLT.Abandoned", "IdleSktToImpact"), |
| 5284 | abandoned_page ? 1 : 0, 2); |
| 5285 | switch (load_type) { |
| 5286 | case NavigationState::NORMAL_LOAD: |
| 5287 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5288 | "PLT.BeginToFinish_NormalLoad", "IdleSktToImpact"), |
| 5289 | begin_to_finish_all_loads); |
| 5290 | break; |
| 5291 | case NavigationState::LINK_LOAD_NORMAL: |
| 5292 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5293 | "PLT.BeginToFinish_LinkLoadNormal", "IdleSktToImpact"), |
| 5294 | begin_to_finish_all_loads); |
| 5295 | break; |
| 5296 | case NavigationState::LINK_LOAD_RELOAD: |
| 5297 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5298 | "PLT.BeginToFinish_LinkLoadReload", "IdleSktToImpact"), |
| 5299 | begin_to_finish_all_loads); |
| 5300 | break; |
| 5301 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5302 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5303 | "PLT.BeginToFinish_LinkLoadStaleOk", "IdleSktToImpact"), |
| 5304 | begin_to_finish_all_loads); |
| 5305 | break; |
| 5306 | default: |
| 5307 | break; |
| 5308 | } |
| 5309 | } |
| 5310 | |
| 5311 | // Histograms to determine effect of number of connections per proxy. |
| 5312 | static bool use_proxy_connection_impact_histogram( |
| 5313 | base::FieldTrialList::Find("ProxyConnectionImpact") && |
| 5314 | !base::FieldTrialList::Find("ProxyConnectionImpact")-> |
| 5315 | group_name().empty()); |
| 5316 | if (use_proxy_connection_impact_histogram) { |
| 5317 | UMA_HISTOGRAM_ENUMERATION( |
| 5318 | base::FieldTrial::MakeName("PLT.Abandoned", "ProxyConnectionImpact"), |
| 5319 | abandoned_page ? 1 : 0, 2); |
| 5320 | switch (load_type) { |
| 5321 | case NavigationState::NORMAL_LOAD: |
| 5322 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5323 | "PLT.BeginToFinish_NormalLoad", "ProxyConnectionImpact"), |
| 5324 | begin_to_finish_all_loads); |
| 5325 | break; |
| 5326 | case NavigationState::LINK_LOAD_NORMAL: |
| 5327 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5328 | "PLT.BeginToFinish_LinkLoadNormal", "ProxyConnectionImpact"), |
| 5329 | begin_to_finish_all_loads); |
| 5330 | break; |
| 5331 | case NavigationState::LINK_LOAD_RELOAD: |
| 5332 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5333 | "PLT.BeginToFinish_LinkLoadReload", "ProxyConnectionImpact"), |
| 5334 | begin_to_finish_all_loads); |
| 5335 | break; |
| 5336 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5337 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5338 | "PLT.BeginToFinish_LinkLoadStaleOk", "ProxyConnectionImpact"), |
| 5339 | begin_to_finish_all_loads); |
| 5340 | break; |
| 5341 | default: |
| 5342 | break; |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | // Histograms to determine if SDCH has an impact. |
| 5347 | // TODO(jar): Consider removing per-link load types and the enumeration. |
| 5348 | static bool use_sdch_histogram(base::FieldTrialList::Find("GlobalSdch") && |
| 5349 | !base::FieldTrialList::Find("GlobalSdch")->group_name().empty()); |
| 5350 | if (use_sdch_histogram) { |
| 5351 | UMA_HISTOGRAM_ENUMERATION( |
| 5352 | base::FieldTrial::MakeName("PLT.LoadType", "GlobalSdch"), |
| 5353 | load_type, NavigationState::kLoadTypeMax); |
| 5354 | switch (load_type) { |
| 5355 | case NavigationState::NORMAL_LOAD: |
| 5356 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5357 | "PLT.BeginToFinish_NormalLoad", "GlobalSdch"), |
| 5358 | begin_to_finish_all_loads); |
| 5359 | break; |
| 5360 | case NavigationState::LINK_LOAD_NORMAL: |
| 5361 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5362 | "PLT.BeginToFinish_LinkLoadNormal", "GlobalSdch"), |
| 5363 | begin_to_finish_all_loads); |
| 5364 | break; |
| 5365 | case NavigationState::LINK_LOAD_RELOAD: |
| 5366 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5367 | "PLT.BeginToFinish_LinkLoadReload", "GlobalSdch"), |
| 5368 | begin_to_finish_all_loads); |
| 5369 | break; |
| 5370 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5371 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5372 | "PLT.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"), |
| 5373 | begin_to_finish_all_loads); |
| 5374 | break; |
| 5375 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 5376 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5377 | "PLT.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"), |
| 5378 | begin_to_finish_all_loads); |
| 5379 | break; |
| 5380 | default: |
| 5381 | break; |
| 5382 | } |
| 5383 | } |
| 5384 | |
| 5385 | // Histograms to determine if cache size has an impact on PLT. |
| 5386 | static bool use_cache_histogram1(base::FieldTrialList::Find("CacheSize") && |
| 5387 | !base::FieldTrialList::Find("CacheSize")->group_name().empty()); |
| 5388 | if (use_cache_histogram1 && |
| 5389 | NavigationState::LINK_LOAD_NORMAL <= load_type && |
| 5390 | NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) { |
| 5391 | // TODO(mbelshe): Do we really want BeginToFinishDoc here? It seems like |
| 5392 | // StartToFinish or BeginToFinish would be better. |
| 5393 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5394 | "PLT.BeginToFinishDoc_LinkLoad", "CacheSize"), begin_to_finish_doc); |
| 5395 | } |
| 5396 | |
| 5397 | // Histograms to determine if cache throttling has an impact on PLT. |
| 5398 | static bool use_cache_histogram2( |
| 5399 | base::FieldTrialList::Find("CacheThrottle") && |
| 5400 | !base::FieldTrialList::Find("CacheThrottle")->group_name().empty()); |
| 5401 | if (use_cache_histogram2) { |
| 5402 | UMA_HISTOGRAM_ENUMERATION( |
| 5403 | base::FieldTrial::MakeName("PLT.Abandoned", "CacheThrottle"), |
| 5404 | abandoned_page ? 1 : 0, 2); |
| 5405 | switch (load_type) { |
| 5406 | case NavigationState::RELOAD: |
| 5407 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5408 | "PLT.BeginToFinish_Reload", "CacheThrottle"), |
| 5409 | begin_to_finish_all_loads); |
| 5410 | break; |
| 5411 | case NavigationState::HISTORY_LOAD: |
| 5412 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5413 | "PLT.BeginToFinish_HistoryLoad", "CacheThrottle"), |
| 5414 | begin_to_finish_all_loads); |
| 5415 | break; |
| 5416 | case NavigationState::NORMAL_LOAD: |
| 5417 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5418 | "PLT.BeginToFinish_NormalLoad", "CacheThrottle"), |
| 5419 | begin_to_finish_all_loads); |
| 5420 | break; |
| 5421 | case NavigationState::LINK_LOAD_NORMAL: |
| 5422 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5423 | "PLT.BeginToFinish_LinkLoadNormal", "CacheThrottle"), |
| 5424 | begin_to_finish_all_loads); |
| 5425 | break; |
| 5426 | case NavigationState::LINK_LOAD_RELOAD: |
| 5427 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5428 | "PLT.BeginToFinish_LinkLoadReload", "CacheThrottle"), |
| 5429 | begin_to_finish_all_loads); |
| 5430 | break; |
| 5431 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 5432 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5433 | "PLT.BeginToFinish_LinkLoadStaleOk", "CacheThrottle"), |
| 5434 | begin_to_finish_all_loads); |
| 5435 | break; |
| 5436 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 5437 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5438 | "PLT.BeginToFinish_LinkLoadCacheOnly", "CacheThrottle"), |
| 5439 | begin_to_finish_all_loads); |
| 5440 | break; |
| 5441 | default: |
| 5442 | break; |
| 5443 | } |
| 5444 | if (NavigationState::RELOAD <= load_type && |
| 5445 | NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) { |
| 5446 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5447 | "PLT.BeginToFinish", "CacheThrottle"), |
| 5448 | begin_to_finish_all_loads); |
| 5449 | } |
| 5450 | } |
| 5451 | |
| 5452 | // For the SPDY field trials, we need to verify that the page loaded was |
| 5453 | // the type we requested: |
| 5454 | // if we asked for a SPDY request, we got a SPDY request |
| 5455 | // if we asked for a HTTP request, we got a HTTP request |
| 5456 | // Due to spdy version mismatches, it is possible that we ask for SPDY |
| 5457 | // but didn't get SPDY. |
| 5458 | static bool use_spdy_histogram(base::FieldTrialList::Find("SpdyImpact") && |
| 5459 | !base::FieldTrialList::Find("SpdyImpact")->group_name().empty()); |
| 5460 | if (use_spdy_histogram) { |
| 5461 | // We take extra effort to only compute these once. |
| 5462 | static bool in_spdy_trial = |
| 5463 | base::FieldTrialList::Find("SpdyImpact")->group_name() == |
| 5464 | "npn_with_spdy"; |
| 5465 | static bool in_http_trial = |
| 5466 | base::FieldTrialList::Find("SpdyImpact")->group_name() == |
| 5467 | "npn_with_http"; |
| 5468 | |
| 5469 | bool spdy_trial_success = navigation_state->was_fetched_via_spdy() ? |
| 5470 | in_spdy_trial : in_http_trial; |
| 5471 | if (spdy_trial_success) { |
| 5472 | // Histograms to determine if SPDY has an impact for https traffic. |
| 5473 | // TODO(mbelshe): After we've seen the difference between BeginToFinish |
| 5474 | // and StartToFinish, consider removing one or the other. |
| 5475 | if (scheme_type == URLPattern::SCHEME_HTTPS && |
| 5476 | navigation_state->was_npn_negotiated()) { |
| 5477 | UMA_HISTOGRAM_ENUMERATION( |
| 5478 | base::FieldTrial::MakeName("PLT.Abandoned", "SpdyImpact"), |
| 5479 | abandoned_page ? 1 : 0, 2); |
| 5480 | switch (load_type) { |
| 5481 | case NavigationState::LINK_LOAD_NORMAL: |
| 5482 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5483 | "PLT.BeginToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5484 | begin_to_finish_all_loads); |
| 5485 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5486 | "PLT.StartToFinish_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5487 | start_to_finish_all_loads); |
| 5488 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5489 | "PLT.StartToCommit_LinkLoadNormal_SpdyTrial", "SpdyImpact"), |
| 5490 | start_to_commit); |
| 5491 | break; |
| 5492 | case NavigationState::NORMAL_LOAD: |
| 5493 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5494 | "PLT.BeginToFinish_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5495 | begin_to_finish_all_loads); |
| 5496 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5497 | "PLT.StartToFinish_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5498 | start_to_finish_all_loads); |
| 5499 | PLT_HISTOGRAM(base::FieldTrial::MakeName( |
| 5500 | "PLT.StartToCommit_NormalLoad_SpdyTrial", "SpdyImpact"), |
| 5501 | start_to_commit); |
| 5502 | break; |
| 5503 | default: |
| 5504 | break; |
| 5505 | } |
| 5506 | } |
| 5507 | |
| 5508 | // Histograms to compare the impact of alternate protocol over http |
| 5509 | // traffic: when spdy is used vs. when http is used. |
| 5510 | if (scheme_type == URLPattern::SCHEME_HTTP && |
| 5511 | navigation_state->was_alternate_protocol_available()) { |
| 5512 | if (!navigation_state->was_npn_negotiated()) { |
| 5513 | // This means that even there is alternate protocols for npn_http or |
| 5514 | // npn_spdy, they are not taken (due to the base::FieldTrial). |
| 5515 | switch (load_type) { |
| 5516 | case NavigationState::LINK_LOAD_NORMAL: |
| 5517 | PLT_HISTOGRAM( |
| 5518 | "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_http", |
| 5519 | start_to_finish_all_loads); |
| 5520 | PLT_HISTOGRAM( |
| 5521 | "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_http", |
| 5522 | start_to_commit); |
| 5523 | break; |
| 5524 | case NavigationState::NORMAL_LOAD: |
| 5525 | PLT_HISTOGRAM( |
| 5526 | "PLT.StartToFinish_NormalLoad_AlternateProtocol_http", |
| 5527 | start_to_finish_all_loads); |
| 5528 | PLT_HISTOGRAM( |
| 5529 | "PLT.StartToCommit_NormalLoad_AlternateProtocol_http", |
| 5530 | start_to_commit); |
| 5531 | break; |
| 5532 | default: |
| 5533 | break; |
| 5534 | } |
| 5535 | } else if (navigation_state->was_fetched_via_spdy()) { |
| 5536 | switch (load_type) { |
| 5537 | case NavigationState::LINK_LOAD_NORMAL: |
| 5538 | PLT_HISTOGRAM( |
| 5539 | "PLT.StartToFinish_LinkLoadNormal_AlternateProtocol_spdy", |
| 5540 | start_to_finish_all_loads); |
| 5541 | PLT_HISTOGRAM( |
| 5542 | "PLT.StartToCommit_LinkLoadNormal_AlternateProtocol_spdy", |
| 5543 | start_to_commit); |
| 5544 | break; |
| 5545 | case NavigationState::NORMAL_LOAD: |
| 5546 | PLT_HISTOGRAM( |
| 5547 | "PLT.StartToFinish_NormalLoad_AlternateProtocol_spdy", |
| 5548 | start_to_finish_all_loads); |
| 5549 | PLT_HISTOGRAM( |
| 5550 | "PLT.StartToCommit_NormalLoad_AlternateProtocol_spdy", |
| 5551 | start_to_commit); |
| 5552 | break; |
| 5553 | default: |
| 5554 | break; |
| 5555 | } |
| 5556 | } |
| 5557 | } |
| 5558 | } |
| 5559 | } |
| 5560 | |
| 5561 | // Record page load time and abandonment rates for proxy cases. |
| 5562 | if (navigation_state->was_fetched_via_proxy()) { |
| 5563 | if (scheme_type == URLPattern::SCHEME_HTTPS) { |
| 5564 | PLT_HISTOGRAM("PLT.StartToFinish.Proxy.https", start_to_finish_all_loads); |
| 5565 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.https", |
| 5566 | abandoned_page ? 1 : 0, 2); |
| 5567 | } else { |
| 5568 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP); |
| 5569 | PLT_HISTOGRAM("PLT.StartToFinish.Proxy.http", start_to_finish_all_loads); |
| 5570 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.Proxy.http", |
| 5571 | abandoned_page ? 1 : 0, 2); |
| 5572 | } |
| 5573 | } else { |
| 5574 | if (scheme_type == URLPattern::SCHEME_HTTPS) { |
| 5575 | PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.https", |
| 5576 | start_to_finish_all_loads); |
| 5577 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.https", |
| 5578 | abandoned_page ? 1 : 0, 2); |
| 5579 | } else { |
| 5580 | DCHECK(scheme_type == URLPattern::SCHEME_HTTP); |
| 5581 | PLT_HISTOGRAM("PLT.StartToFinish.NoProxy.http", |
| 5582 | start_to_finish_all_loads); |
| 5583 | UMA_HISTOGRAM_ENUMERATION("PLT.Abandoned.NoProxy.http", |
| 5584 | abandoned_page ? 1 : 0, 2); |
| 5585 | } |
| 5586 | } |
| 5587 | |
| 5588 | // Site isolation metrics. |
| 5589 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess", |
| 5590 | cross_origin_access_count_); |
| 5591 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess", |
| 5592 | same_origin_access_count_); |
| 5593 | |
| 5594 | // TODO(jar): This is the ONLY call in this method that needed more than |
| 5595 | // navigation_state. This should be relocated, or changed, so that this |
| 5596 | // body can be made a method on NavigationStates, and run via its destructor. |
| 5597 | // Log some PLT data to the error log. |
| 5598 | LogNavigationState(navigation_state, main_frame->dataSource()); |
| 5599 | |
| 5600 | navigation_state->set_load_histograms_recorded(true); |
| 5601 | |
| 5602 | // Since there are currently no guarantees that renderer histograms will be |
| 5603 | // sent to the browser, we initiate a PostTask here to be sure that we send |
| 5604 | // the histograms we generated. Without this call, pages that don't have an |
| 5605 | // on-close-handler might generate data that is lost when the renderer is |
| 5606 | // shutdown abruptly (perchance because the user closed the tab). |
| 5607 | // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it |
| 5608 | // should post when the onload is complete, so that it doesn't interfere with |
| 5609 | // the next load. |
| 5610 | if (RenderThread::current()) { |
| 5611 | RenderThread::current()->SendHistograms( |
| 5612 | chrome::kHistogramSynchronizerReservedSequenceNumber); |
| 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | void RenderView::LogNavigationState(const NavigationState* state, |
| 5617 | const WebDataSource* ds) const { |
| 5618 | // Because this function gets called on every page load, |
| 5619 | // take extra care to optimize it away if logging is turned off. |
| 5620 | if (logging::LOG_INFO < logging::GetMinLogLevel()) |
| 5621 | return; |
| 5622 | |
| 5623 | DCHECK(state); |
| 5624 | DCHECK(ds); |
| 5625 | GURL url(ds->request().url()); |
| 5626 | Time start = state->start_load_time(); |
| 5627 | Time finish = state->finish_load_time(); |
| 5628 | // TODO(mbelshe): should we log more stats? |
| 5629 | VLOG(1) << "PLT: " << (finish - start).InMilliseconds() << "ms " |
| 5630 | << url.spec(); |
| 5631 | } |
| 5632 | |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5633 | void RenderView::postAccessibilityNotification( |
| 5634 | const WebAccessibilityObject& obj, |
| 5635 | WebAccessibilityNotification notification) { |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 5636 | if (!accessibility_.get() && webview()) { |
| 5637 | // Load complete should be our first notification sent. |
| 5638 | // TODO(ctguil): Investigate if a different notification is a WebCore bug. |
| 5639 | if (notification != WebKit::WebAccessibilityNotificationLoadComplete) |
| 5640 | return; |
| 5641 | |
| 5642 | // Create and initialize our accessibility cache |
| 5643 | accessibility_.reset(WebAccessibilityCache::create()); |
| 5644 | accessibility_->initialize(webview()); |
| 5645 | } |
| 5646 | |
[email protected] | a3fa4f9 | 2010-09-30 22:19:33 | [diff] [blame] | 5647 | if (!accessibility_->isCached(obj)) { |
| 5648 | // The browser doesn't know about objects that are not in the cache. Send a |
| 5649 | // children change for the first accestor that actually is in the cache. |
| 5650 | WebAccessibilityObject parent = obj; |
| 5651 | while (parent.isValid() && !accessibility_->isCached(parent)) |
| 5652 | parent = parent.parentObject(); |
| 5653 | |
| 5654 | DCHECK(parent.isValid() && accessibility_->isCached(parent)); |
| 5655 | if (!parent.isValid()) |
| 5656 | return; |
| 5657 | postAccessibilityNotification( |
| 5658 | parent, WebKit::WebAccessibilityNotificationChildrenChanged); |
| 5659 | |
| 5660 | // The parent's children change takes care of the child's children change. |
| 5661 | if (notification == WebKit::WebAccessibilityNotificationChildrenChanged) |
| 5662 | return; |
| 5663 | } |
| 5664 | |
[email protected] | dea2d37 | 2010-09-25 06:41:14 | [diff] [blame] | 5665 | // Add the accessibility object to our cache and ensure it's valid. |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5666 | RendererAccessibilityNotification acc_notification; |
| 5667 | acc_notification.id = accessibility_->addOrGetId(obj); |
| 5668 | if (acc_notification.id < 0) |
[email protected] | a3018be | 2010-03-09 04:28:48 | [diff] [blame] | 5669 | return; |
| 5670 | |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5671 | if (!WebAccessibilityNotificationToViewHostMsg( |
| 5672 | notification, |
| 5673 | &acc_notification.type)) { |
| 5674 | return; |
| 5675 | } |
| 5676 | |
| 5677 | // Discard duplicate accessibility notifications. |
| 5678 | for (uint32 i = 0; i < pending_accessibility_notifications_.size(); i++) { |
| 5679 | if (pending_accessibility_notifications_[i].id == acc_notification.id && |
| 5680 | pending_accessibility_notifications_[i].type == acc_notification.type) { |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5681 | return; |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5682 | } |
[email protected] | 9892b47 | 2010-09-16 00:23:42 | [diff] [blame] | 5683 | } |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5684 | pending_accessibility_notifications_.push_back(acc_notification); |
[email protected] | a3018be | 2010-03-09 04:28:48 | [diff] [blame] | 5685 | |
[email protected] | 54ec7f8 | 2010-10-21 22:32:51 | [diff] [blame] | 5686 | if (!accessibility_ack_pending_ && accessibility_method_factory_.empty()) { |
| 5687 | // When no accessibility notifications are in-flight post a task to send |
| 5688 | // the notifications to the browser. We use PostTask so that we can queue |
| 5689 | // up additional notifications. |
| 5690 | MessageLoop::current()->PostTask( |
| 5691 | FROM_HERE, |
| 5692 | accessibility_method_factory_.NewRunnableMethod( |
| 5693 | &RenderView::SendPendingAccessibilityNotifications)); |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 5694 | } |
[email protected] | 520cb7d7 | 2010-08-31 11:54:31 | [diff] [blame] | 5695 | } |
| 5696 | |
[email protected] | 0fda727 | 2009-06-26 15:49:33 | [diff] [blame] | 5697 | void RenderView::Print(WebFrame* frame, bool script_initiated) { |
| 5698 | DCHECK(frame); |
| 5699 | if (print_helper_.get() == NULL) { |
| 5700 | print_helper_.reset(new PrintWebViewHelper(this)); |
| 5701 | } |
| 5702 | print_helper_->Print(frame, script_initiated); |
| 5703 | } |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5704 | |
| 5705 | void RenderView::OnSetEditCommandsForNextKeyEvent( |
| 5706 | const EditCommands& edit_commands) { |
| 5707 | edit_commands_ = edit_commands; |
| 5708 | } |
| 5709 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5710 | void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 5711 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5712 | if (!main_frame) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5713 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, |
| 5714 | false)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5715 | return; |
| 5716 | } |
| 5717 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5718 | WebDataSource* ds = main_frame->dataSource(); |
| 5719 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 5720 | if (!navigation_state->user_script_idle_scheduler()->has_run()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5721 | pending_code_execution_queue_.push( |
| 5722 | linked_ptr<ViewMsg_ExecuteCode_Params>( |
| 5723 | new ViewMsg_ExecuteCode_Params(params))); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5724 | return; |
| 5725 | } |
| 5726 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5727 | ExecuteCodeImpl(main_frame, params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | void RenderView::ExecuteCodeImpl(WebFrame* frame, |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5731 | const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5732 | std::vector<WebFrame*> frame_vector; |
| 5733 | frame_vector.push_back(frame); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5734 | if (params.all_frames) |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5735 | GetAllChildFrames(frame, &frame_vector); |
| 5736 | |
| 5737 | for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin(); |
| 5738 | frame_it != frame_vector.end(); ++frame_it) { |
| 5739 | WebFrame* frame = *frame_it; |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5740 | if (params.is_javascript) { |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 5741 | ExtensionRendererInfo* extension = |
| 5742 | ExtensionRendererInfo::GetByID(params.extension_id); |
| 5743 | |
[email protected] | 1f6228c | 2010-10-21 03:19:44 | [diff] [blame] | 5744 | // Since extension info is sent separately from user script info, they can |
| 5745 | // be out of sync. We just ignore this situation. |
| 5746 | if (!extension) |
| 5747 | continue; |
| 5748 | |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 5749 | const std::vector<URLPattern> host_permissions = |
| 5750 | extension->host_permissions(); |
| 5751 | if (!Extension::CanExecuteScriptOnPage( |
| 5752 | frame->url(), |
| 5753 | extension->allowed_to_execute_script_everywhere(), |
| 5754 | &host_permissions, |
| 5755 | NULL, |
| 5756 | NULL)) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5757 | continue; |
[email protected] | be7e5cb | 2010-10-04 12:53:17 | [diff] [blame] | 5758 | } |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5759 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5760 | std::vector<WebScriptSource> sources; |
| 5761 | sources.push_back( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5762 | WebScriptSource(WebString::fromUTF8(params.code))); |
| 5763 | UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5764 | frame->executeScriptInIsolatedWorld( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5765 | UserScriptSlave::GetIsolatedWorldId(params.extension_id), |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5766 | &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 5767 | } else { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5768 | frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 5769 | } |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5770 | } |
| 5771 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 5772 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 5773 | } |
| 5774 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 5775 | void RenderView::Close() { |
| 5776 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 5777 | WebView* doomed = webview(); |
| 5778 | RenderWidget::Close(); |
| 5779 | Singleton<ViewMap>::get()->erase(doomed); |
| 5780 | } |
| 5781 | |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 5782 | void RenderView::DidHandleKeyEvent() { |
| 5783 | edit_commands_.clear(); |
| 5784 | } |
| 5785 | |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5786 | void RenderView::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 5787 | page_click_tracker_->DidHandleMouseEvent(event); |
| 5788 | } |
| 5789 | |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5790 | #if defined(OS_MACOSX) |
| 5791 | void RenderView::OnWasHidden() { |
| 5792 | RenderWidget::OnWasHidden(); |
| 5793 | |
| 5794 | // Inform plugins that their container is no longer visible. |
| 5795 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5796 | for (plugin_it = plugin_delegates_.begin(); |
| 5797 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5798 | (*plugin_it)->SetContainerVisibility(false); |
| 5799 | } |
| 5800 | } |
| 5801 | |
| 5802 | void RenderView::OnWasRestored(bool needs_repainting) { |
| 5803 | RenderWidget::OnWasRestored(needs_repainting); |
| 5804 | |
| 5805 | // Inform plugins that their container is now visible. |
| 5806 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5807 | for (plugin_it = plugin_delegates_.begin(); |
| 5808 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 5809 | (*plugin_it)->SetContainerVisibility(true); |
| 5810 | } |
| 5811 | } |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5812 | #endif // OS_MACOSX |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5813 | |
| 5814 | void RenderView::OnSetFocus(bool enable) { |
| 5815 | RenderWidget::OnSetFocus(enable); |
| 5816 | |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5817 | if (webview() && webview()->isActive()) { |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5818 | // Notify all NPAPI plugins. |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5819 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 5820 | for (plugin_it = plugin_delegates_.begin(); |
| 5821 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5822 | #if defined(OS_MACOSX) |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5823 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 5824 | // activation state to change just like a call to setIsActive. |
| 5825 | if (enable) |
| 5826 | (*plugin_it)->SetWindowFocus(true); |
[email protected] | 784ea1ab | 2010-09-18 00:02:34 | [diff] [blame] | 5827 | #endif |
[email protected] | 7d3c02c | 2010-05-05 23:10:31 | [diff] [blame] | 5828 | (*plugin_it)->SetContentAreaFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5829 | } |
[email protected] | 589621b | 2010-09-23 22:01:07 | [diff] [blame] | 5830 | |
| 5831 | // Notify all Pepper plugins. |
| 5832 | pepper_delegate_.OnSetFocus(enable); |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 5833 | } |
| 5834 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 5835 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 5836 | void RenderView::EnsureDocumentTag() { |
| 5837 | // TODO(darin): There's actually no reason for this to be here. We should |
| 5838 | // have the browser side manage the document tag. |
| 5839 | #if defined(OS_MACOSX) |
| 5840 | if (!has_document_tag_) { |
| 5841 | // Make the call to get the tag. |
| 5842 | Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); |
| 5843 | has_document_tag_ = true; |
| 5844 | } |
| 5845 | #endif |
| 5846 | } |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 5847 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5848 | #if defined(OS_MACOSX) |
[email protected] | 935d63d | 2010-10-15 23:31:55 | [diff] [blame] | 5849 | void RenderView::SetPluginImeEnabled(bool enabled, int plugin_id) { |
| 5850 | IPC::Message* msg = new ViewHostMsg_SetPluginImeEnabled(routing_id(), |
| 5851 | enabled, plugin_id); |
| 5852 | // This message can be sent during event-handling, and needs to be delivered |
| 5853 | // within that context. |
| 5854 | msg->set_unblock(true); |
| 5855 | Send(msg); |
| 5856 | } |
| 5857 | |
[email protected] | ea04a4e1 | 2010-04-15 00:58:03 | [diff] [blame] | 5858 | gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5859 | bool opaque, bool root) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5860 | gfx::PluginWindowHandle window = NULL; |
| 5861 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | 77e74db | 2010-08-04 17:46:23 | [diff] [blame] | 5862 | routing_id(), opaque, root, &window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5863 | if (window) { |
| 5864 | fake_plugin_window_handles_.insert(window); |
| 5865 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5866 | return window; |
| 5867 | } |
| 5868 | |
| 5869 | void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) { |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5870 | if (window && fake_plugin_window_handles_.find(window) != |
| 5871 | fake_plugin_window_handles_.end()) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5872 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
[email protected] | c36a9b6 | 2010-10-14 00:41:11 | [diff] [blame] | 5873 | fake_plugin_window_handles_.erase(window); |
| 5874 | } |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5875 | } |
| 5876 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5877 | void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window, |
| 5878 | int32 width, |
| 5879 | int32 height, |
| 5880 | uint64 io_surface_identifier) { |
| 5881 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5882 | routing_id(), window, width, height, io_surface_identifier)); |
| 5883 | } |
| 5884 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5885 | void RenderView::AcceleratedSurfaceSetTransportDIB( |
| 5886 | gfx::PluginWindowHandle window, |
| 5887 | int32 width, |
| 5888 | int32 height, |
| 5889 | TransportDIB::Handle transport_dib) { |
| 5890 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5891 | routing_id(), window, width, height, transport_dib)); |
| 5892 | } |
| 5893 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5894 | TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB( |
| 5895 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5896 | TransportDIB::Handle dib_handle; |
| 5897 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 5898 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5899 | return dib_handle; |
| 5900 | // Return an invalid handle if Send() fails. |
| 5901 | return TransportDIB::DefaultHandleValue(); |
| 5902 | } |
| 5903 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5904 | void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 5905 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 5906 | } |
| 5907 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 5908 | void RenderView::AcceleratedSurfaceBuffersSwapped( |
| 5909 | gfx::PluginWindowHandle window) { |
| 5910 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 5911 | } |
| 5912 | #endif |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5913 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 5914 | bool RenderView::ScheduleFileChooser( |
| 5915 | const ViewHostMsg_RunFileChooser_Params& params, |
| 5916 | WebFileChooserCompletion* completion) { |
| 5917 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 5918 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 5919 | // This sanity check prevents too many file choose requests from getting |
| 5920 | // queued which could DoS the user. Getting these is most likely a |
| 5921 | // programming error (there are many ways to DoS the user so it's not |
| 5922 | // considered a "real" security check), either in JS requesting many file |
| 5923 | // choosers to pop up, or in a plugin. |
| 5924 | // |
| 5925 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 5926 | // a file picker, which will address this issue in a better way. |
| 5927 | return false; |
| 5928 | } |
| 5929 | |
| 5930 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 5931 | new PendingFileChooser(params, completion))); |
| 5932 | if (file_chooser_completions_.size() == 1) { |
| 5933 | // Actually show the browse dialog when this is the first request. |
| 5934 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 5935 | } |
| 5936 | return true; |
| 5937 | } |
| 5938 | |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 5939 | void RenderView::OnPageTranslated() { |
| 5940 | WebFrame* frame = webview()->mainFrame(); |
| 5941 | if (!frame) |
| 5942 | return; |
| 5943 | |
| 5944 | // The page is translated, so try to extract the form data again. |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 5945 | autofill_helper_->FrameContentsAvailable(frame); |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 5946 | } |
| 5947 | |
[email protected] | 8a5f700 | 2010-03-31 13:47:35 | [diff] [blame] | 5948 | WebKit::WebGeolocationService* RenderView::geolocationService() { |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5949 | if (!geolocation_dispatcher_.get()) |
[email protected] | ecad776 | 2010-10-22 13:58:48 | [diff] [blame] | 5950 | geolocation_dispatcher_.reset(new GeolocationDispatcherOld(this)); |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 5951 | return geolocation_dispatcher_.get(); |
| 5952 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5953 | |
[email protected] | 638694c | 2010-08-04 22:24:11 | [diff] [blame] | 5954 | WebKit::WebSpeechInputController* RenderView::speechInputController( |
| 5955 | WebKit::WebSpeechInputListener* listener) { |
| 5956 | if (!speech_input_dispatcher_.get()) |
| 5957 | speech_input_dispatcher_.reset(new SpeechInputDispatcher(this, listener)); |
| 5958 | return speech_input_dispatcher_.get(); |
| 5959 | } |
| 5960 | |
[email protected] | 57ead35 | 2010-08-11 14:42:53 | [diff] [blame] | 5961 | WebKit::WebDeviceOrientationClient* RenderView::deviceOrientationClient() { |
| 5962 | if (!device_orientation_dispatcher_.get()) |
| 5963 | device_orientation_dispatcher_.reset(new DeviceOrientationDispatcher(this)); |
| 5964 | return device_orientation_dispatcher_.get(); |
| 5965 | } |
| 5966 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5967 | void RenderView::zoomLimitsChanged(double minimum_level, double maximum_level) { |
| 5968 | // For now, don't remember plugin zoom values. We don't want to mix them with |
| 5969 | // normal web content (i.e. a fixed layout plugin would usually want them |
| 5970 | // different). |
| 5971 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 5972 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5973 | int minimum_percent = static_cast<int>( |
| 5974 | WebView::zoomLevelToZoomFactor(minimum_level) * 100); |
| 5975 | int maximum_percent = static_cast<int>( |
| 5976 | WebView::zoomLevelToZoomFactor(maximum_level) * 100); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5977 | |
| 5978 | Send(new ViewHostMsg_UpdateZoomLimits( |
| 5979 | routing_id_, minimum_percent, maximum_percent, remember)); |
| 5980 | } |
| 5981 | |
| 5982 | void RenderView::zoomLevelChanged() { |
| 5983 | bool remember = !webview()->mainFrame()->document().isPluginDocument(); |
| 5984 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5985 | // Tell the browser which url got zoomed so it can update the menu and the |
| 5986 | // saved values if necessary |
| 5987 | Send(new ViewHostMsg_DidZoomURL( |
[email protected] | 1cc58eb6 | 2010-10-01 22:38:41 | [diff] [blame] | 5988 | routing_id_, webview()->zoomLevel(), remember, |
| 5989 | GURL(webview()->mainFrame()->url()))); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 5990 | } |
| 5991 | |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 5992 | bool RenderView::IsNonLocalTopLevelNavigation( |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5993 | const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { |
[email protected] | 8079b36 | 2010-05-07 18:37:45 | [diff] [blame] | 5994 | // Must be a top level frame. |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 5995 | if (frame->parent() != NULL) |
| 5996 | return false; |
| 5997 | |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 5998 | // Navigations initiated within Webkit are not sent out to the external host |
| 5999 | // in the following cases. |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6000 | // 1. The url scheme is not http/https |
| 6001 | // 2. There is no opener and this is not the first url being opened by this |
| 6002 | // RenderView. |
| 6003 | // 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] | 6004 | // opener relationship is maintained. |
[email protected] | f0a3d0b | 2010-08-06 22:51:53 | [diff] [blame] | 6005 | // 4. Reloads/form submits/back forward navigations |
| 6006 | if (!url.SchemeIs("http") && !url.SchemeIs("https")) |
| 6007 | return false; |
| 6008 | |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6009 | // Not interested in reloads. |
| 6010 | if (type != WebKit::WebNavigationTypeReload && |
[email protected] | 070c49c | 2010-07-13 22:22:01 | [diff] [blame] | 6011 | type != WebKit::WebNavigationTypeFormSubmitted && |
| 6012 | type != WebKit::WebNavigationTypeBackForward) { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6013 | // The opener relationship between the new window and the parent allows the |
| 6014 | // new window to script the parent and vice versa. This is not allowed if |
| 6015 | // the origins of the two domains are different. This can be treated as a |
| 6016 | // top level navigation and routed back to the host. |
| 6017 | WebKit::WebFrame* opener = frame->opener(); |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6018 | if (!opener) { |
[email protected] | fe9eb4f9 | 2010-08-27 23:16:47 | [diff] [blame] | 6019 | // Force link click navigations to always be routed to the host as they |
| 6020 | // may update session state on the server. |
| 6021 | if (type == WebKit::WebNavigationTypeLinkClicked) |
| 6022 | return true; |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6023 | // If this is the first page being loaded by this RenderView instance then |
| 6024 | // it should stay here. |
| 6025 | if (page_id_ == -1) { |
| 6026 | return false; |
| 6027 | } else { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6028 | return true; |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6029 | } |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6030 | } |
[email protected] | 900eb2f1 | 2010-08-23 22:36:27 | [diff] [blame] | 6031 | |
| 6032 | if (url.GetOrigin() != GURL(opener->url()).GetOrigin()) |
| 6033 | return true; |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 6034 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 6035 | return false; |
| 6036 | } |
[email protected] | 2b06a99 | 2010-08-21 05:48:22 | [diff] [blame] | 6037 | |
[email protected] | 27a9ef3 | 2010-09-10 04:06:24 | [diff] [blame] | 6038 | void RenderView::OnAsyncFileOpened(base::PlatformFileError error_code, |
| 6039 | IPC::PlatformFileForTransit file_for_transit, |
| 6040 | int message_id) { |
| 6041 | pepper_delegate_.OnAsyncFileOpened( |
| 6042 | error_code, |
| 6043 | IPC::PlatformFileForTransitToPlatformFile(file_for_transit), |
| 6044 | message_id); |
| 6045 | } |