[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/renderer/render_view.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | a92b864 | 2009-05-05 23:38:56 | [diff] [blame] | 11 | #include "app/l10n_util.h" |
[email protected] | 3712621 | 2009-05-06 02:23:31 | [diff] [blame] | 12 | #include "app/message_box_flags.h" |
[email protected] | 9929da9 | 2009-05-05 02:05:11 | [diff] [blame] | 13 | #include "app/resource_bundle.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 14 | #include "base/callback.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 16 | #include "base/compiler_specific.h" |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 17 | #include "base/field_trial.h" |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 18 | #include "base/histogram.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 19 | #include "base/process_util.h" |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 20 | #include "base/singleton.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | #include "base/string_piece.h" |
| 22 | #include "base/string_util.h" |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 23 | #include "base/time.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 24 | #include "build/build_config.h" |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 25 | #include "chrome/common/appcache/appcache_dispatcher.h" |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 26 | #include "chrome/common/bindings_policy.h" |
[email protected] | ef91627 | 2009-07-08 21:40:55 | [diff] [blame] | 27 | #include "chrome/common/child_process_logging.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 28 | #include "chrome/common/chrome_switches.h" |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 29 | #include "chrome/common/chrome_constants.h" |
[email protected] | d146b83 | 2009-12-23 02:45:48 | [diff] [blame] | 30 | #include "chrome/common/extensions/extension_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | #include "chrome/common/jstemplate_builder.h" |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 32 | #include "chrome/common/page_zoom.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 33 | #include "chrome/common/render_messages.h" |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 34 | #include "chrome/common/renderer_preferences.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 35 | #include "chrome/common/thumbnail_score.h" |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 36 | #include "chrome/common/url_constants.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 37 | #include "chrome/common/window_container_type.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 38 | #include "chrome/renderer/about_handler.h" |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 39 | #include "chrome/renderer/audio_message_filter.h" |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 40 | #include "chrome/renderer/devtools_agent.h" |
| 41 | #include "chrome/renderer/devtools_client.h" |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 42 | #include "chrome/renderer/extension_groups.h" |
[email protected] | f816c01 | 2009-06-26 21:48:32 | [diff] [blame] | 43 | #include "chrome/renderer/extensions/event_bindings.h" |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 44 | #include "chrome/renderer/extensions/extension_process_bindings.h" |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 45 | #include "chrome/renderer/extensions/renderer_extension_bindings.h" |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 46 | #include "chrome/renderer/geolocation_dispatcher.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 47 | #include "chrome/renderer/localized_error.h" |
[email protected] | 6f56d48 | 2009-02-20 05:02:56 | [diff] [blame] | 48 | #include "chrome/renderer/media/audio_renderer_impl.h" |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 49 | #include "chrome/renderer/media/ipc_video_renderer.h" |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 50 | #include "chrome/renderer/navigation_state.h" |
[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 51 | #include "chrome/renderer/notification_provider.h" |
[email protected] | 8beff076 | 2009-09-29 02:18:30 | [diff] [blame] | 52 | #include "chrome/renderer/plugin_channel_host.h" |
[email protected] | d81c1e5 | 2009-06-03 22:09:50 | [diff] [blame] | 53 | #include "chrome/renderer/print_web_view_helper.h" |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 54 | #include "chrome/renderer/render_process.h" |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 55 | #include "chrome/renderer/render_thread.h" |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 56 | #include "chrome/renderer/renderer_webapplicationcachehost_impl.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 57 | #include "chrome/renderer/renderer_webstoragenamespace_impl.h" |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 58 | #include "chrome/renderer/spellchecker/spellcheck.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 59 | #include "chrome/renderer/user_script_slave.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 60 | #include "chrome/renderer/visitedlink_slave.h" |
[email protected] | d439ba07 | 2009-10-17 22:32:29 | [diff] [blame] | 61 | #include "chrome/renderer/webplugin_delegate_pepper.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 62 | #include "chrome/renderer/webplugin_delegate_proxy.h" |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 63 | #include "chrome/renderer/websharedworker_proxy.h" |
[email protected] | eb47a13 | 2009-03-04 00:39:56 | [diff] [blame] | 64 | #include "chrome/renderer/webworker_proxy.h" |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 65 | #include "gfx/color_utils.h" |
| 66 | #include "gfx/favicon_size.h" |
[email protected] | 5c7293a | 2010-03-17 06:40:57 | [diff] [blame] | 67 | #include "gfx/native_widget_types.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 68 | #include "grit/generated_resources.h" |
| 69 | #include "grit/renderer_resources.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 70 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 71 | #include "net/base/escape.h" |
| 72 | #include "net/base/net_errors.h" |
[email protected] | c399a8a | 2008-11-22 19:38:00 | [diff] [blame] | 73 | #include "skia/ext/bitmap_platform_device.h" |
[email protected] | 83c9e655 | 2008-12-03 16:22:10 | [diff] [blame] | 74 | #include "skia/ext/image_operations.h" |
[email protected] | 65127279 | 2010-02-04 23:16:30 | [diff] [blame] | 75 | #include "third_party/cld/encodings/compact_lang_det/win/cld_unicodetext.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 76 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" |
| 77 | #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 78 | #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 79 | #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" |
| 80 | #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 81 | #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 82 | #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 83 | #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 84 | #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 85 | #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
| 86 | #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 87 | #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 88 | #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 89 | #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 90 | #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 91 | #include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h" |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 92 | #include "third_party/WebKit/WebKit/chromium/public/WebPageSerializer.h" |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 93 | #include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h" |
| 94 | #include "third_party/WebKit/WebKit/chromium/public/WebPluginDocument.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 95 | #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
| 96 | #include "third_party/WebKit/WebKit/chromium/public/WebRange.h" |
| 97 | #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
| 98 | #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" |
| 99 | #include "third_party/WebKit/WebKit/chromium/public/WebSearchableFormData.h" |
| 100 | #include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h" |
| 101 | #include "third_party/WebKit/WebKit/chromium/public/WebSize.h" |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 102 | #include "third_party/WebKit/WebKit/chromium/public/WebStorageNamespace.h" |
[email protected] | 418ed5ab | 2009-11-12 01:14:49 | [diff] [blame] | 103 | #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 104 | #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 105 | #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" |
| 106 | #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 107 | #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
| 108 | #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 109 | #include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h" |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 110 | #include "webkit/appcache/web_application_cache_host_impl.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 111 | #include "webkit/default_plugin/default_plugin_shared.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | #include "webkit/glue/dom_operations.h" |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 113 | #include "webkit/glue/form_data.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 114 | #include "webkit/glue/form_field.h" |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 115 | #include "webkit/glue/glue_serialize.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 116 | #include "webkit/glue/image_decoder.h" |
[email protected] | 8e296bbd | 2009-07-22 21:37:17 | [diff] [blame] | 117 | #include "webkit/glue/media/buffered_data_source.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame] | 118 | #include "webkit/glue/media/simple_data_source.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 119 | #include "webkit/glue/media/video_renderer_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 120 | #include "webkit/glue/password_form.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 121 | #include "webkit/glue/plugins/plugin_list.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 122 | #include "webkit/glue/plugins/webplugin_delegate.h" |
[email protected] | 8a3b796 | 2009-09-04 05:53:23 | [diff] [blame] | 123 | #include "webkit/glue/plugins/webplugin_delegate_impl.h" |
[email protected] | e612d76 | 2010-03-31 04:32:30 | [diff] [blame] | 124 | #include "webkit/glue/plugins/webplugin_impl.h" |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 125 | #include "webkit/glue/site_isolation_metrics.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | #include "webkit/glue/webdropdata.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 127 | #include "webkit/glue/webkit_glue.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 128 | #include "webkit/glue/webmediaplayer_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 130 | #if defined(OS_WIN) |
| 131 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 132 | // * theming |
[email protected] | cd81841 | 2010-03-19 03:23:15 | [diff] [blame] | 133 | #include "gfx/native_theme_win.h" |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 134 | #elif defined(USE_X11) |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 135 | #include "third_party/WebKit/WebKit/chromium/public/linux/WebRenderTheme.h" |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 136 | #elif defined(OS_MACOSX) |
| 137 | #include "skia/ext/skia_utils_mac.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 138 | #endif |
| 139 | |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 140 | using appcache::WebApplicationCacheHostImpl; |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 141 | using base::Time; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 142 | using base::TimeDelta; |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 143 | using webkit_glue::AltErrorPageResourceFetcher; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 144 | using webkit_glue::FormData; |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 145 | using webkit_glue::FormField; |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 146 | using webkit_glue::ImageResourceFetcher; |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 147 | using webkit_glue::PasswordForm; |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 148 | using webkit_glue::PasswordFormDomManager; |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 149 | using webkit_glue::SiteIsolationMetrics; |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 150 | using WebKit::WebAccessibilityCache; |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 151 | using WebKit::WebAccessibilityObject; |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 152 | using WebKit::WebApplicationCacheHost; |
| 153 | using WebKit::WebApplicationCacheHostClient; |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 154 | using WebKit::WebColor; |
| 155 | using WebKit::WebColorName; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 156 | using WebKit::WebConsoleMessage; |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 157 | using WebKit::WebContextMenuData; |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 158 | using WebKit::WebCookieJar; |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 159 | using WebKit::WebCString; |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 160 | using WebKit::WebData; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 161 | using WebKit::WebDataSource; |
[email protected] | 2661b33 | 2009-11-03 18:42:29 | [diff] [blame] | 162 | using WebKit::WebDevToolsAgent; |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 163 | using WebKit::WebDocument; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 164 | using WebKit::WebDragData; |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 165 | using WebKit::WebDragOperation; |
| 166 | using WebKit::WebDragOperationsMask; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 167 | using WebKit::WebEditingAction; |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 168 | using WebKit::WebFileChooserCompletion; |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 169 | using WebKit::WebFindOptions; |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 170 | using WebKit::WebFormControlElement; |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 171 | using WebKit::WebFormElement; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 172 | using WebKit::WebFrame; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 173 | using WebKit::WebHistoryItem; |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 174 | using WebKit::WebImage; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 175 | using WebKit::WebInputElement; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 176 | using WebKit::WebMediaPlayer; |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 177 | using WebKit::WebMediaPlayerAction; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 178 | using WebKit::WebMediaPlayerClient; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 179 | using WebKit::WebNavigationPolicy; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 180 | using WebKit::WebNavigationType; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 181 | using WebKit::WebNode; |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 182 | using WebKit::WebPageSerializer; |
| 183 | using WebKit::WebPageSerializerClient; |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 184 | using WebKit::WebPlugin; |
| 185 | using WebKit::WebPluginParams; |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 186 | using WebKit::WebPluginDocument; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 187 | using WebKit::WebPoint; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 188 | using WebKit::WebPopupMenuInfo; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 189 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 190 | using WebKit::WebRect; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 191 | using WebKit::WebScriptSource; |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 192 | using WebKit::WebSearchableFormData; |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 193 | using WebKit::WebSecurityOrigin; |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 194 | using WebKit::WebSettings; |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 195 | using WebKit::WebSharedWorker; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 196 | using WebKit::WebSize; |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 197 | using WebKit::WebStorageNamespace; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 198 | using WebKit::WebString; |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 199 | using WebKit::WebTextAffinity; |
[email protected] | de570ef | 2009-07-29 18:27:52 | [diff] [blame] | 200 | using WebKit::WebTextDirection; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 201 | using WebKit::WebURL; |
| 202 | using WebKit::WebURLError; |
| 203 | using WebKit::WebURLRequest; |
| 204 | using WebKit::WebURLResponse; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 205 | using WebKit::WebVector; |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 206 | using WebKit::WebView; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 207 | using WebKit::WebWidget; |
[email protected] | 27ba853 | 2009-04-24 20:22:43 | [diff] [blame] | 208 | using WebKit::WebWorker; |
| 209 | using WebKit::WebWorkerClient; |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 210 | using WebKit::WebWindowFeatures; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 211 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 212 | //----------------------------------------------------------------------------- |
| 213 | |
| 214 | // define to write the time necessary for thumbnail/DOM text retrieval, |
| 215 | // respectively, into the system debug log |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 216 | // #define TIME_TEXT_RETRIEVAL |
| 217 | |
| 218 | // maximum number of characters in the document to index, any text beyond this |
| 219 | // point will be clipped |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 220 | static const size_t kMaxIndexChars = 65535; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 221 | |
| 222 | // Size of the thumbnails that we'll generate |
[email protected] | 8b4f489 | 2009-09-04 21:52:37 | [diff] [blame] | 223 | static const int kThumbnailWidth = 212; |
| 224 | static const int kThumbnailHeight = 132; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | |
| 226 | // Delay in milliseconds that we'll wait before capturing the page contents |
| 227 | // and thumbnail. |
| 228 | static const int kDelayForCaptureMs = 500; |
| 229 | |
| 230 | // Typically, we capture the page data once the page is loaded. |
| 231 | // Sometimes, the page never finishes to load, preventing the page capture |
| 232 | // To workaround this problem, we always perform a capture after the following |
| 233 | // delay. |
| 234 | static const int kDelayForForcedCaptureMs = 6000; |
| 235 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 236 | // Time, in seconds, we delay before sending content state changes (such as form |
| 237 | // state and scroll position) to the browser. We delay sending changes to avoid |
| 238 | // spamming the browser. |
| 239 | // To avoid having tab/session restore require sending a message to get the |
| 240 | // current content state during tab closing we use a shorter timeout for the |
| 241 | // foreground renderer. This means there is a small window of time from which |
| 242 | // content state is modified and not sent to session restore, but this is |
| 243 | // better than having to wake up all renderers during shutdown. |
| 244 | static const int kDelaySecondsForContentStateSyncHidden = 5; |
| 245 | static const int kDelaySecondsForContentStateSync = 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 246 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 247 | // The maximum number of popups that can be spawned from one page. |
| 248 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 249 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 250 | static const char* const kUnreachableWebDataURL = |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 251 | "chrome://chromewebdata/"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 252 | |
[email protected] | 50b691c | 2008-10-31 19:08:35 | [diff] [blame] | 253 | static const char* const kBackForwardNavigationScheme = "history"; |
| 254 | |
[email protected] | d64b07b | 2010-04-20 22:14:06 | [diff] [blame] | 255 | // static |
| 256 | const char* const RenderView::kUnknownLanguageCode = "und"; |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 257 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 258 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 259 | WebVector<WebURL> urls; |
| 260 | ds->redirectChain(urls); |
| 261 | result->reserve(urls.size()); |
| 262 | for (size_t i = 0; i < urls.size(); ++i) |
| 263 | result->push_back(urls[i]); |
| 264 | } |
| 265 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 266 | static bool UrlMatchesPermissions( |
| 267 | const GURL& url, const std::vector<URLPattern>& host_permissions) { |
| 268 | for (size_t i = 0; i < host_permissions.size(); ++i) { |
| 269 | if (host_permissions[i].MatchesUrl(url)) |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | return false; |
| 274 | } |
| 275 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 276 | static bool PaintViewIntoCanvas(WebView* view, |
| 277 | skia::PlatformCanvas& canvas) { |
| 278 | view->layout(); |
| 279 | const WebSize& size = view->size(); |
| 280 | |
| 281 | if (!canvas.initialize(size.width, size.height, true)) |
| 282 | return false; |
| 283 | |
| 284 | view->paint(webkit_glue::ToWebCanvas(&canvas), |
| 285 | WebRect(0, 0, size.width, size.height)); |
| 286 | // TODO: Add a way to snapshot the whole page, not just the currently |
| 287 | // visible part. |
| 288 | |
| 289 | return true; |
| 290 | } |
| 291 | |
| 292 | // Calculates how "boring" a thumbnail is. The boring score is the |
| 293 | // 0,1 ranged percentage of pixels that are the most common |
| 294 | // luma. Higher boring scores indicate that a higher percentage of a |
| 295 | // bitmap are all the same brightness. |
| 296 | static double CalculateBoringScore(SkBitmap* bitmap) { |
| 297 | int histogram[256] = {0}; |
| 298 | color_utils::BuildLumaHistogram(bitmap, histogram); |
| 299 | |
| 300 | int color_count = *std::max_element(histogram, histogram + 256); |
| 301 | int pixel_count = bitmap->width() * bitmap->height(); |
| 302 | return static_cast<double>(color_count) / pixel_count; |
| 303 | } |
| 304 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 305 | // True if |frame| contains content that is white-listed for content settings. |
| 306 | static bool IsWhitelistedForContentSettings(WebFrame* frame) { |
| 307 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 308 | if (origin.isEmpty()) |
| 309 | return false; // Uninitialized document? |
| 310 | |
| 311 | if (EqualsASCII(origin.protocol(), chrome::kChromeUIScheme)) |
| 312 | return true; // Browser UI elements should still work. |
| 313 | |
| 314 | // If the scheme is ftp: or file:, an empty file name indicates a directory |
| 315 | // listing, which requires JavaScript to function properly. |
| 316 | GURL frame_url = frame->url(); |
| 317 | const char* kDirProtocols[] = { "ftp", "file" }; |
| 318 | for (size_t i = 0; i < arraysize(kDirProtocols); ++i) { |
| 319 | if (EqualsASCII(origin.protocol(), kDirProtocols[i])) { |
| 320 | return frame_url.SchemeIs(kDirProtocols[i]) && |
| 321 | frame_url.ExtractFileName().empty(); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | return false; |
| 326 | } |
| 327 | |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 328 | // Returns true if the frame is navigating to an URL either into or out of an |
| 329 | // extension app's extent. |
| 330 | static bool CrossesExtensionExtents(WebFrame* frame, const GURL& new_url) { |
| 331 | if (!RenderThread::current()) |
| 332 | return false; |
| 333 | |
| 334 | // If the URL is still empty, this is a window.open navigation. Check the |
| 335 | // opener's URL. |
| 336 | GURL old_url(frame->url()); |
| 337 | if (old_url.is_empty() && frame->opener()) |
| 338 | old_url = frame->opener()->url(); |
| 339 | |
| 340 | std::string old_extension = |
| 341 | RenderThread::current()->GetExtensionIdForURL(old_url); |
| 342 | std::string new_extension = |
| 343 | RenderThread::current()->GetExtensionIdForURL(new_url); |
| 344 | return (old_extension != new_extension); |
| 345 | } |
| 346 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 347 | /////////////////////////////////////////////////////////////////////////////// |
| 348 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 349 | int32 RenderView::next_page_id_ = 1; |
| 350 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 351 | struct RenderView::PendingFileChooser { |
| 352 | PendingFileChooser(const ViewHostMsg_RunFileChooser_Params& p, |
| 353 | WebFileChooserCompletion* c) |
| 354 | : params(p), |
| 355 | completion(c) { |
| 356 | } |
| 357 | ViewHostMsg_RunFileChooser_Params params; |
| 358 | WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 359 | }; |
| 360 | |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 361 | RenderView::RenderView(RenderThreadBase* render_thread, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 362 | const WebPreferences& webkit_preferences, |
| 363 | int64 session_storage_namespace_id) |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 364 | : RenderWidget(render_thread, WebKit::WebPopupTypeNone), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 365 | enabled_bindings_(0), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 366 | target_url_status_(TARGET_NONE), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 367 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 368 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 369 | page_id_(-1), |
| 370 | last_page_id_sent_to_browser_(-1), |
| 371 | last_indexed_page_id_(-1), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 372 | opened_by_user_gesture_(true), |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 373 | opener_suppressed_(false), |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 374 | ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 375 | devtools_agent_(NULL), |
| 376 | devtools_client_(NULL), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 377 | history_list_offset_(-1), |
| 378 | history_list_length_(0), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 379 | has_unload_listener_(false), |
| 380 | decrement_shared_popup_at_destruction_(false), |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 381 | autofill_query_id_(0), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 382 | popup_notification_visible_(false), |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 383 | spelling_panel_visible_(false), |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 384 | send_content_state_immediately_(false), |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 385 | send_preferred_size_changes_(false), |
[email protected] | b6849bda | 2009-10-14 23:59:26 | [diff] [blame] | 386 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 387 | notification_provider_(new NotificationProvider(this))), |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 388 | view_type_(ViewType::INVALID), |
| 389 | browser_window_id_(-1), |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 390 | last_top_level_navigation_page_id_(-1), |
| 391 | #if defined(OS_MACOSX) |
| 392 | has_document_tag_(false), |
| 393 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 394 | document_tag_(0), |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 395 | webkit_preferences_(webkit_preferences), |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 396 | session_storage_namespace_id_(session_storage_namespace_id), |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 397 | ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 398 | ALLOW_THIS_IN_INITIALIZER_LIST(translate_helper_(this)), |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 399 | cross_origin_access_count_(0), |
| 400 | same_origin_access_count_(0) { |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 401 | ClearBlockedContentSettings(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | RenderView::~RenderView() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 405 | if (decrement_shared_popup_at_destruction_) |
| 406 | shared_popup_counter_->data--; |
| 407 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 408 | // Dispose of un-disposed image fetchers. |
| 409 | for (ImageResourceFetcherSet::iterator i = image_fetchers_.begin(); |
| 410 | i != image_fetchers_.end(); ++i) { |
| 411 | delete *i; |
| 412 | } |
| 413 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 414 | // If file chooser is still waiting for answer, dispatch empty answer. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 415 | while (!file_chooser_completions_.empty()) { |
| 416 | if (file_chooser_completions_.front()->completion) { |
| 417 | file_chooser_completions_.front()->completion->didChooseFile( |
| 418 | WebVector<WebString>()); |
| 419 | } |
| 420 | file_chooser_completions_.pop_front(); |
| 421 | } |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 422 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 423 | #if defined(OS_MACOSX) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 424 | // Tell the spellchecker that the document is closed. |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 425 | if (has_document_tag_) |
| 426 | Send(new ViewHostMsg_DocumentWithTagClosed(routing_id_, document_tag_)); |
| 427 | #endif |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 428 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 429 | render_thread_->RemoveFilter(audio_message_filter_); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 430 | |
| 431 | #ifndef NDEBUG |
| 432 | // Make sure we are no longer referenced by the ViewMap. |
| 433 | ViewMap* views = Singleton<ViewMap>::get(); |
| 434 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) |
| 435 | DCHECK_NE(this, it->second) << "Failed to call Close?"; |
| 436 | #endif |
| 437 | } |
| 438 | |
| 439 | /*static*/ |
| 440 | void RenderView::ForEach(RenderViewVisitor* visitor) { |
| 441 | ViewMap* views = Singleton<ViewMap>::get(); |
| 442 | for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { |
| 443 | if (!visitor->Visit(it->second)) |
| 444 | return; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | /*static*/ |
| 449 | RenderView* RenderView::FromWebView(WebView* webview) { |
| 450 | ViewMap* views = Singleton<ViewMap>::get(); |
| 451 | ViewMap::iterator it = views->find(webview); |
| 452 | return it == views->end() ? NULL : it->second; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /*static*/ |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 456 | RenderView* RenderView::Create( |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 457 | RenderThreadBase* render_thread, |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 458 | gfx::NativeViewId parent_hwnd, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 459 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 460 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 461 | const WebPreferences& webkit_prefs, |
| 462 | SharedRenderViewCounter* counter, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 463 | int32 routing_id, |
| 464 | int64 session_storage_namespace_id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 465 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 466 | scoped_refptr<RenderView> view = new RenderView(render_thread, webkit_prefs, |
| 467 | session_storage_namespace_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 468 | view->Init(parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 469 | opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 470 | renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 471 | counter, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 472 | routing_id); // adds reference |
| 473 | return view; |
| 474 | } |
| 475 | |
| 476 | /*static*/ |
| 477 | void RenderView::SetNextPageID(int32 next_page_id) { |
| 478 | // This method should only be called during process startup, and the given |
| 479 | // page id had better not exceed our current next page id! |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 480 | DCHECK_EQ(next_page_id_, 1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 481 | DCHECK(next_page_id >= next_page_id_); |
| 482 | next_page_id_ = next_page_id; |
| 483 | } |
| 484 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 485 | void RenderView::UserMetricsRecordAction(const std::string& action) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 486 | Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); |
| 487 | } |
| 488 | |
[email protected] | a3a8fb6d | 2009-10-22 20:12:51 | [diff] [blame] | 489 | void RenderView::PluginCrashed(const FilePath& plugin_path) { |
| 490 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 493 | #if defined(OS_MACOSX) |
| 494 | void RenderView::RegisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 495 | plugin_delegates_.insert(delegate); |
| 496 | } |
| 497 | |
| 498 | void RenderView::UnregisterPluginDelegate(WebPluginDelegateProxy* delegate) { |
| 499 | plugin_delegates_.erase(delegate); |
| 500 | } |
| 501 | #endif |
| 502 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 503 | void RenderView::Init(gfx::NativeViewId parent_hwnd, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 504 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 505 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 506 | SharedRenderViewCounter* counter, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 507 | int32 routing_id) { |
| 508 | DCHECK(!webview()); |
| 509 | |
| 510 | if (opener_id != MSG_ROUTING_NONE) |
| 511 | opener_id_ = opener_id; |
| 512 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 513 | if (counter) { |
| 514 | shared_popup_counter_ = counter; |
| 515 | shared_popup_counter_->data++; |
| 516 | decrement_shared_popup_at_destruction_ = true; |
| 517 | } else { |
| 518 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 519 | decrement_shared_popup_at_destruction_ = false; |
| 520 | } |
| 521 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 522 | devtools_agent_.reset(new DevToolsAgent(routing_id, this)); |
[email protected] | 9b9d728 | 2009-04-08 14:13:04 | [diff] [blame] | 523 | |
[email protected] | 50ae00ef | 2009-10-19 05:11:03 | [diff] [blame] | 524 | webwidget_ = WebView::create(this); |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 525 | Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 526 | webkit_preferences_.Apply(webview()); |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 527 | webview()->initializeMainFrame(this); |
[email protected] | 2661b33 | 2009-11-03 18:42:29 | [diff] [blame] | 528 | webview()->setDevToolsAgent( |
| 529 | WebDevToolsAgent::create(webview(), devtools_agent_.get())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 530 | |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 531 | OnSetRendererPrefs(renderer_prefs); |
| 532 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 533 | routing_id_ = routing_id; |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 534 | render_thread_->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 535 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 536 | // when we receive ViewMsg_Close. |
| 537 | AddRef(); |
| 538 | |
| 539 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 540 | // completing initialization. Otherwise, we can finish it now. |
| 541 | if (opener_id == MSG_ROUTING_NONE) { |
| 542 | did_show_ = true; |
| 543 | CompleteInit(parent_hwnd); |
| 544 | } |
| 545 | |
| 546 | host_window_ = parent_hwnd; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 547 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 548 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 549 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 550 | enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 551 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 552 | audio_message_filter_ = new AudioMessageFilter(routing_id_); |
| 553 | render_thread_->AddFilter(audio_message_filter_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | void RenderView::OnMessageReceived(const IPC::Message& message) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 557 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 558 | if (main_frame) |
| 559 | child_process_logging::SetActiveURL(main_frame->url()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 560 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 561 | // If this is developer tools renderer intercept tools messages first. |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 562 | if (devtools_client_.get() && devtools_client_->OnMessageReceived(message)) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 563 | return; |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 564 | if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message)) |
| 565 | return; |
[email protected] | b6849bda | 2009-10-14 23:59:26 | [diff] [blame] | 566 | if (notification_provider_->OnMessageReceived(message)) |
| 567 | return; |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 568 | if (geolocation_dispatcher_.get() && |
| 569 | geolocation_dispatcher_->OnMessageReceived(message)) { |
| 570 | return; |
| 571 | } |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 572 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 573 | IPC_BEGIN_MESSAGE_MAP(RenderView, message) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 574 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail) |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 575 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, SendSnapshot) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 576 | IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 577 | IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 578 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 579 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 580 | IPC_MESSAGE_HANDLER(ViewMsg_ReloadFrame, OnReloadFrame) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 581 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 582 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 583 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 584 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 585 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 586 | IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 587 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 588 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
| 589 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 590 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellPanel, OnToggleSpellPanel) |
| 591 | IPC_MESSAGE_HANDLER(ViewMsg_AdvanceToNextMisspelling, |
| 592 | OnAdvanceToNextMisspelling) |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 593 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 594 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 595 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
| 596 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 597 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 598 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 599 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| 600 | IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 601 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 602 | IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL, |
| 603 | OnSetContentSettingsForLoadingURL) |
| 604 | IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, |
| 605 | OnSetZoomLevelForLoadingURL) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 606 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 607 | IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault, |
| 608 | OnResetPageEncodingToDefault) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 609 | IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 610 | IPC_MESSAGE_HANDLER(ViewMsg_DownloadFavIcon, OnDownloadFavIcon) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 611 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 612 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 613 | IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 614 | IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 615 | IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm) |
| 616 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) |
| 617 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) |
| 618 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) |
| 619 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 620 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 621 | IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 622 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved, |
| 623 | OnDragSourceEndedOrMoved) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 624 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, |
| 625 | OnDragSourceSystemDragEnded) |
| 626 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 627 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 628 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 629 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
| 630 | IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) |
| 631 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
| 632 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 633 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 634 | OnGetAllSavableResourceLinksForCurrentPage) |
[email protected] | f09c718 | 2009-03-10 12:54:04 | [diff] [blame] | 635 | IPC_MESSAGE_HANDLER( |
| 636 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 637 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 638 | IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 639 | IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo) |
| 640 | IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo, |
| 641 | OnClearAccessibilityInfo) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 642 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose) |
| 643 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 644 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 645 | IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
| 646 | OnMessageFromExternalHost) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 647 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 648 | OnDisassociateFromPopupCount) |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 649 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillSuggestionsReturned, |
| 650 | OnAutoFillSuggestionsReturned) |
[email protected] | cf28ec5 | 2010-04-09 22:56:34 | [diff] [blame] | 651 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillForms, OnAutoFillForms) |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 652 | IPC_MESSAGE_HANDLER(ViewMsg_AutocompleteSuggestionsReturned, |
| 653 | OnAutocompleteSuggestionsReturned) |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 654 | IPC_MESSAGE_HANDLER(ViewMsg_AutoFillFormDataFilled, |
| 655 | OnAutoFillFormDataFilled) |
[email protected] | 2c4410d | 2009-05-06 23:46:22 | [diff] [blame] | 656 | IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged, |
| 657 | OnPopupNotificationVisibilityChanged) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 658 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 659 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 660 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionMessageInvoke, |
| 661 | OnExtensionMessageInvoke) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 662 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 663 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 664 | IPC_MESSAGE_HANDLER(ViewMsg_EnablePreferredSizeChangedMode, |
| 665 | OnEnablePreferredSizeChangedMode) |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 666 | IPC_MESSAGE_HANDLER(ViewMsg_DisableScrollbarsForSmallWindows, |
| 667 | OnDisableScrollbarsForSmallWindows) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 668 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 669 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateBrowserWindowId, |
| 670 | OnUpdateBrowserWindowId) |
| 671 | IPC_MESSAGE_HANDLER(ViewMsg_NotifyRenderViewType, |
| 672 | OnNotifyRendererViewType) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 673 | IPC_MESSAGE_HANDLER(ViewMsg_MediaPlayerActionAt, OnMediaPlayerActionAt) |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 674 | IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 675 | #if defined(OS_MACOSX) |
| 676 | IPC_MESSAGE_HANDLER(ViewMsg_SetWindowVisibility, OnSetWindowVisibility) |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 677 | IPC_MESSAGE_HANDLER(ViewMsg_WindowFrameChanged, OnWindowFrameChanged) |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 678 | #endif |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 679 | IPC_MESSAGE_HANDLER(ViewMsg_SetEditCommandsForNextKeyEvent, |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 680 | OnSetEditCommandsForNextKeyEvent) |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 681 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteCode, |
| 682 | OnExecuteCode) |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 683 | IPC_MESSAGE_HANDLER(ViewMsg_CustomContextMenuAction, |
| 684 | OnCustomContextMenuAction) |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 685 | IPC_MESSAGE_HANDLER(ViewMsg_TranslatePage, OnTranslatePage) |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 686 | IPC_MESSAGE_HANDLER(ViewMsg_RevertTranslation, OnRevertTranslation) |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 687 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 688 | // Have the super handle all other messages. |
| 689 | IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) |
| 690 | IPC_END_MESSAGE_MAP() |
| 691 | } |
| 692 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 693 | void RenderView::SendThumbnail() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 694 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 695 | if (!main_frame) |
| 696 | return; |
| 697 | |
| 698 | // get the URL for this page |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 699 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 700 | if (url.is_empty()) |
| 701 | return; |
| 702 | |
| 703 | if (size_.IsEmpty()) |
| 704 | return; // Don't create an empty thumbnail! |
| 705 | |
| 706 | ThumbnailScore score; |
| 707 | SkBitmap thumbnail; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 708 | if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight, |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 709 | &thumbnail, &score)) |
| 710 | return; |
| 711 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 712 | // send the thumbnail message to the browser process |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 713 | Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 714 | } |
| 715 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 716 | void RenderView::SendSnapshot() { |
| 717 | SkBitmap snapshot; |
| 718 | bool error = false; |
| 719 | |
| 720 | WebFrame* main_frame = webview()->mainFrame(); |
| 721 | if (!main_frame) |
| 722 | error = true; |
| 723 | |
| 724 | if (!error && !CaptureSnapshot(webview(), &snapshot)) |
| 725 | error = true; |
| 726 | |
| 727 | DCHECK(error == snapshot.empty()) << |
| 728 | "Snapshot should be empty on error, non-empty otherwise."; |
| 729 | |
| 730 | // Send the snapshot to the browser process. |
| 731 | Send(new ViewHostMsg_Snapshot(routing_id_, snapshot)); |
| 732 | } |
| 733 | |
[email protected] | 06863722 | 2009-01-29 16:58:07 | [diff] [blame] | 734 | void RenderView::OnPrintPages() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 735 | DCHECK(webview()); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 736 | if (webview()) { |
| 737 | // If the user has selected text in the currently focused frame we print |
| 738 | // only that frame (this makes print selection work for multiple frames). |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 739 | if (webview()->focusedFrame()->hasSelection()) |
| 740 | Print(webview()->focusedFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 741 | else |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 742 | Print(webview()->mainFrame(), false); |
[email protected] | aa82249f | 2009-07-16 17:23:58 | [diff] [blame] | 743 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 744 | } |
| 745 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 746 | void RenderView::OnPrintingDone(int document_cookie, bool success) { |
| 747 | // Ignoring document cookie here since only one print job can be outstanding |
| 748 | // per renderer and document_cookie is 0 when printing is successful. |
| 749 | DCHECK(print_helper_.get()); |
| 750 | if (print_helper_.get() != NULL) { |
| 751 | print_helper_->DidFinishPrinting(success); |
| 752 | } |
| 753 | } |
| 754 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 755 | void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { |
| 756 | if (load_id != page_id_) |
| 757 | return; // this capture call is no longer relevant due to navigation |
| 758 | if (load_id == last_indexed_page_id_) |
| 759 | return; // we already indexed this page |
| 760 | |
| 761 | if (!webview()) |
| 762 | return; |
| 763 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 764 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 765 | if (!main_frame) |
| 766 | return; |
| 767 | |
| 768 | // Don't index/capture pages that are in view source mode. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 769 | if (main_frame->isViewSourceModeEnabled()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 770 | return; |
| 771 | |
| 772 | // Don't index/capture pages that failed to load. This only checks the top |
| 773 | // level frame so the thumbnail may contain a frame that failed to load. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 774 | WebDataSource* ds = main_frame->dataSource(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 775 | if (ds && ds->hasUnreachableURL()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 776 | return; |
| 777 | |
| 778 | if (!preliminary_capture) |
| 779 | last_indexed_page_id_ = load_id; |
| 780 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 781 | // Get the URL for this page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 782 | GURL url(main_frame->url()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 783 | if (url.is_empty()) |
| 784 | return; |
| 785 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 786 | // Retrieve the frame's full text. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 787 | std::wstring contents; |
| 788 | CaptureText(main_frame, &contents); |
| 789 | if (contents.size()) { |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 790 | base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 791 | std::string language = DetermineTextLanguage(contents); |
| 792 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.LanguageDetection", |
| 793 | base::TimeTicks::Now() - begin_time); |
[email protected] | 7893a98 | 2010-01-07 23:25:52 | [diff] [blame] | 794 | |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 795 | // Send the text to the browser for indexing (the browser might decide not |
| 796 | // to index, if the URL is HTTPS for instance) and language discovery. |
| 797 | Send(new ViewHostMsg_PageContents(routing_id_, url, load_id, contents, |
| 798 | language)); |
[email protected] | 5c426692 | 2009-07-10 16:41:27 | [diff] [blame] | 799 | } |
| 800 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 801 | // thumbnail |
| 802 | SendThumbnail(); |
| 803 | } |
| 804 | |
| 805 | void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) { |
| 806 | contents->clear(); |
| 807 | if (!frame) |
| 808 | return; |
| 809 | |
| 810 | #ifdef TIME_TEXT_RETRIEVAL |
| 811 | double begin = time_util::GetHighResolutionTimeNow(); |
| 812 | #endif |
| 813 | |
| 814 | // get the contents of the frame |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 815 | *contents = UTF16ToWideHack(frame->contentAsText(kMaxIndexChars)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 816 | |
| 817 | #ifdef TIME_TEXT_RETRIEVAL |
| 818 | double end = time_util::GetHighResolutionTimeNow(); |
| 819 | char buf[128]; |
| 820 | sprintf_s(buf, "%d chars retrieved for indexing in %gms\n", |
| 821 | contents.size(), (end - begin)*1000); |
| 822 | OutputDebugStringA(buf); |
| 823 | #endif |
| 824 | |
| 825 | // When the contents are clipped to the maximum, we don't want to have a |
| 826 | // partial word indexed at the end that might have been clipped. Therefore, |
| 827 | // terminate the string at the last space to ensure no words are clipped. |
| 828 | if (contents->size() == kMaxIndexChars) { |
| 829 | size_t last_space_index = contents->find_last_of(kWhitespaceWide); |
| 830 | if (last_space_index == std::wstring::npos) |
| 831 | return; // don't index if we got a huge block of text with no spaces |
| 832 | contents->resize(last_space_index); |
| 833 | } |
| 834 | } |
| 835 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 836 | bool RenderView::CaptureThumbnail(WebView* view, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 837 | int w, |
| 838 | int h, |
| 839 | SkBitmap* thumbnail, |
| 840 | ThumbnailScore* score) { |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 841 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 842 | |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 843 | skia::PlatformCanvas canvas; |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 844 | |
| 845 | // Paint |view| into |canvas|. |
| 846 | if (!PaintViewIntoCanvas(view, canvas)) |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 847 | return false; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 848 | |
| 849 | skia::BitmapPlatformDevice& device = |
| 850 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 851 | |
| 852 | const SkBitmap& src_bmp = device.accessBitmap(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 853 | |
[email protected] | cab34d6a | 2009-09-24 01:14:52 | [diff] [blame] | 854 | SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 855 | float dest_aspect = dest_rect.width() / dest_rect.height(); |
| 856 | |
| 857 | // Get the src rect so that we can preserve the aspect ratio while filling |
| 858 | // the destination. |
| 859 | SkIRect src_rect; |
| 860 | if (src_bmp.width() < dest_rect.width() || |
| 861 | src_bmp.height() < dest_rect.height()) { |
| 862 | // Source image is smaller: we clip the part of source image within the |
| 863 | // dest rect, and then stretch it to fill the dest rect. We don't respect |
| 864 | // the aspect ratio in this case. |
| 865 | src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()), |
| 866 | static_cast<S16CPU>(dest_rect.height())); |
| 867 | score->good_clipping = false; |
| 868 | } else { |
| 869 | float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height(); |
| 870 | if (src_aspect > dest_aspect) { |
| 871 | // Wider than tall, clip horizontally: we center the smaller thumbnail in |
| 872 | // the wider screen. |
| 873 | S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect); |
| 874 | S16CPU x_offset = (src_bmp.width() - new_width) / 2; |
| 875 | src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height()); |
| 876 | score->good_clipping = false; |
| 877 | } else { |
| 878 | src_rect.set(0, 0, src_bmp.width(), |
| 879 | static_cast<S16CPU>(src_bmp.width() / dest_aspect)); |
| 880 | score->good_clipping = true; |
| 881 | } |
| 882 | } |
| 883 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 884 | score->at_top = (view->mainFrame()->scrollOffset().height == 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 885 | |
| 886 | SkBitmap subset; |
[email protected] | 8649fb3 | 2009-06-26 17:51:02 | [diff] [blame] | 887 | device.accessBitmap(false).extractSubset(&subset, src_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 888 | |
| 889 | // Resample the subset that we want to get it the right size. |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 890 | *thumbnail = skia::ImageOperations::Resize( |
| 891 | subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 892 | |
| 893 | score->boring_score = CalculateBoringScore(thumbnail); |
| 894 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 895 | HISTOGRAM_TIMES("Renderer4.Thumbnail", |
| 896 | base::TimeTicks::Now() - beginning_time); |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 897 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 898 | } |
| 899 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 900 | bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) { |
| 901 | base::TimeTicks beginning_time = base::TimeTicks::Now(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 902 | |
[email protected] | 3050792 | 2010-01-15 16:48:23 | [diff] [blame] | 903 | skia::PlatformCanvas canvas; |
| 904 | if (!PaintViewIntoCanvas(view, canvas)) |
| 905 | return false; |
| 906 | |
| 907 | skia::BitmapPlatformDevice& device = |
| 908 | static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| 909 | |
| 910 | const SkBitmap& bitmap = device.accessBitmap(false); |
| 911 | if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
| 912 | return false; |
| 913 | |
| 914 | HISTOGRAM_TIMES("Renderer4.Snapshot", |
| 915 | base::TimeTicks::Now() - beginning_time); |
| 916 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { |
| 920 | if (!webview()) |
| 921 | return; |
| 922 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 923 | history_list_offset_ = params.current_history_list_offset; |
| 924 | history_list_length_ = params.current_history_list_length; |
| 925 | |
[email protected] | 8c785c6 | 2009-07-13 14:20:15 | [diff] [blame] | 926 | if (devtools_agent_.get()) |
| 927 | devtools_agent_->OnNavigate(); |
| 928 | |
[email protected] | 42219753 | 2010-01-25 17:38:23 | [diff] [blame] | 929 | if (notification_provider_.get()) |
| 930 | notification_provider_->OnNavigate(); |
| 931 | |
[email protected] | a9f607e | 2009-10-23 19:59:27 | [diff] [blame] | 932 | child_process_logging::SetActiveURL(params.url); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 933 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 934 | AboutHandler::MaybeHandle(params.url); |
| 935 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 936 | bool is_reload = |
| 937 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD || |
| 938 | params.navigation_type == ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 939 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 940 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 941 | if (is_reload && main_frame->currentHistoryItem().isNull()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 942 | // We cannot reload if we do not have any history state. This happens, for |
| 943 | // example, when recovering from a crash. Our workaround here is a bit of |
| 944 | // a hack since it means that reload after a crashed tab does not cause an |
| 945 | // end-to-end cache validation. |
| 946 | is_reload = false; |
| 947 | } |
| 948 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 949 | // A navigation resulting from loading a javascript URL should not be treated |
| 950 | // as a browser initiated event. Instead, we want it to look as if the page |
| 951 | // initiated any load resulting from JS execution. |
| 952 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 953 | NavigationState* state = NavigationState::CreateBrowserInitiated( |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 954 | params.page_id, |
| 955 | params.pending_history_list_offset, |
| 956 | params.transition, |
| 957 | params.request_time); |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 958 | if (params.navigation_type == ViewMsg_Navigate_Params::RESTORE) { |
| 959 | // We're doing a load of a page that was restored from the last session. |
| 960 | // By default this prefers the cache over loading (LOAD_PREFERRING_CACHE) |
| 961 | // which can result in stale data for pages that are set to expire. We |
| 962 | // explicitly override that by setting the policy here so that as |
| 963 | // necessary we load from the network. |
| 964 | state->set_cache_policy_override(WebURLRequest::UseProtocolCachePolicy); |
| 965 | } |
| 966 | pending_navigation_state_.reset(state); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 967 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 968 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 969 | NavigationState* navigation_state = pending_navigation_state_.get(); |
| 970 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 971 | // If we are reloading, then WebKit will use the history state of the current |
| 972 | // page, so we should just ignore any given history state. Otherwise, if we |
| 973 | // have history state, then we need to navigate to it, which corresponds to a |
| 974 | // back/forward navigation event. |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 975 | if (is_reload) { |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 976 | if (navigation_state) |
| 977 | navigation_state->set_load_type(NavigationState::RELOAD); |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 978 | bool ignore_cache = (params.navigation_type == |
| 979 | ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE); |
| 980 | main_frame->reload(ignore_cache); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 981 | } else if (!params.state.empty()) { |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 982 | // 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] | 983 | DCHECK_NE(params.page_id, -1); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 984 | if (navigation_state) |
| 985 | navigation_state->set_load_type(NavigationState::HISTORY_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 986 | main_frame->loadHistoryItem( |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 987 | webkit_glue::HistoryItemFromString(params.state)); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 988 | } else { |
| 989 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 990 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 991 | |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 992 | // A session history navigation should have been accompanied by state. |
| 993 | DCHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 994 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 995 | if (main_frame->isViewSourceModeEnabled()) |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 996 | request.setCachePolicy(WebURLRequest::ReturnCacheDataElseLoad); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 997 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 998 | if (params.referrer.is_valid()) { |
| 999 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), |
| 1000 | WebString::fromUTF8(params.referrer.spec())); |
| 1001 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 1002 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 1003 | if (navigation_state) |
| 1004 | navigation_state->set_load_type(NavigationState::NORMAL_LOAD); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1005 | main_frame->loadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1006 | } |
| 1007 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1008 | // In case LoadRequest failed before DidCreateDataSource was called. |
| 1009 | pending_navigation_state_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | // Stop loading the current page |
| 1013 | void RenderView::OnStop() { |
| 1014 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 1015 | webview()->mainFrame()->stopLoading(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1016 | } |
| 1017 | |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1018 | // Reload current focused frame. |
| 1019 | // 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] | 1020 | void RenderView::OnReloadFrame() { |
[email protected] | ecbf10d | 2010-02-18 13:03:29 | [diff] [blame] | 1021 | if (webview() && webview()->focusedFrame()) { |
| 1022 | // We always obey the cache (ignore_cache=false) here. |
| 1023 | // TODO(evanm): perhaps we could allow shift-clicking the menu item to do |
| 1024 | // a cache-ignoring reload of the frame. |
| 1025 | webview()->focusedFrame()->reload(false); |
| 1026 | } |
[email protected] | 1dda402 | 2010-01-28 18:24:56 | [diff] [blame] | 1027 | } |
| 1028 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1029 | void RenderView::OnCopyImageAt(int x, int y) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1030 | webview()->copyImageAt(WebPoint(x, y)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1031 | } |
| 1032 | |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1033 | void RenderView::OnExecuteEditCommand(const std::string& name, |
| 1034 | const std::string& value) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1035 | if (!webview() || !webview()->focusedFrame()) |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1036 | return; |
| 1037 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1038 | webview()->focusedFrame()->executeCommand( |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1039 | WebString::fromUTF8(name), WebString::fromUTF8(value)); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 1040 | } |
| 1041 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1042 | void RenderView::OnSetupDevToolsClient() { |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 1043 | DCHECK(!devtools_client_.get()); |
| 1044 | devtools_client_.reset(new DevToolsClient(this)); |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 1045 | } |
| 1046 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1047 | void RenderView::OnUpdateTargetURLAck() { |
| 1048 | // Check if there is a targeturl waiting to be sent. |
| 1049 | if (target_url_status_ == TARGET_PENDING) { |
| 1050 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 1051 | pending_target_url_)); |
| 1052 | } |
| 1053 | |
| 1054 | target_url_status_ = TARGET_NONE; |
| 1055 | } |
| 1056 | |
| 1057 | void RenderView::OnUndo() { |
| 1058 | if (!webview()) |
| 1059 | return; |
| 1060 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1061 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1062 | UserMetricsRecordAction("Undo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | void RenderView::OnRedo() { |
| 1066 | if (!webview()) |
| 1067 | return; |
| 1068 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1069 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1070 | UserMetricsRecordAction("Redo"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | void RenderView::OnCut() { |
| 1074 | if (!webview()) |
| 1075 | return; |
| 1076 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1077 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1078 | UserMetricsRecordAction("Cut"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | void RenderView::OnCopy() { |
| 1082 | if (!webview()) |
| 1083 | return; |
| 1084 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1085 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1086 | UserMetricsRecordAction("Copy"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1087 | } |
| 1088 | |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1089 | #if defined(OS_MACOSX) |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1090 | void RenderView::OnCopyToFindPboard() { |
| 1091 | if (!webview()) |
| 1092 | return; |
| 1093 | |
| 1094 | // Since the find pasteboard supports only plain text, this can be simpler |
| 1095 | // than the |OnCopy()| case. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1096 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1097 | if (frame->hasSelection()) { |
| 1098 | string16 selection = frame->selectionAsText(); |
| 1099 | RenderThread::current()->Send( |
| 1100 | new ViewHostMsg_ClipboardFindPboardWriteStringAsync(selection)); |
| 1101 | } |
| 1102 | |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1103 | UserMetricsRecordAction("CopyToFindPboard"); |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1104 | } |
[email protected] | c0cc309 | 2009-09-12 08:27:27 | [diff] [blame] | 1105 | #endif |
[email protected] | a954bf7 | 2009-09-12 07:30:35 | [diff] [blame] | 1106 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1107 | void RenderView::OnPaste() { |
| 1108 | if (!webview()) |
| 1109 | return; |
| 1110 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1111 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1112 | UserMetricsRecordAction("Paste"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1113 | } |
| 1114 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1115 | void RenderView::OnReplace(const string16& text) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1116 | if (!webview()) |
| 1117 | return; |
| 1118 | |
[email protected] | 1ff7a03 | 2010-02-03 02:46:03 | [diff] [blame] | 1119 | WebFrame* frame = webview()->focusedFrame(); |
| 1120 | if (!frame->hasSelection()) |
| 1121 | frame->selectWordAroundCaret(); |
| 1122 | frame->replaceSelection(text); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1123 | } |
| 1124 | |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1125 | void RenderView::OnAdvanceToNextMisspelling() { |
| 1126 | if (!webview()) |
| 1127 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1128 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1129 | WebString::fromUTF8("AdvanceToNextMisspelling")); |
| 1130 | } |
| 1131 | |
| 1132 | void RenderView::OnToggleSpellPanel(bool is_currently_visible) { |
| 1133 | if (!webview()) |
| 1134 | return; |
| 1135 | // We need to tell the webView whether the spelling panel is visible or not so |
| 1136 | // that it won't need to make ipc calls later. |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1137 | spelling_panel_visible_ = is_currently_visible; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1138 | webview()->focusedFrame()->executeCommand( |
[email protected] | 9832489 | 2009-09-09 21:16:05 | [diff] [blame] | 1139 | WebString::fromUTF8("ToggleSpellPanel")); |
| 1140 | } |
| 1141 | |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1142 | void RenderView::OnToggleSpellCheck() { |
| 1143 | if (!webview()) |
| 1144 | return; |
| 1145 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1146 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1147 | frame->enableContinuousSpellChecking( |
| 1148 | !frame->isContinuousSpellCheckingEnabled()); |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1149 | } |
| 1150 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1151 | void RenderView::OnDelete() { |
| 1152 | if (!webview()) |
| 1153 | return; |
| 1154 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1155 | webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1156 | UserMetricsRecordAction("DeleteSelection"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | void RenderView::OnSelectAll() { |
| 1160 | if (!webview()) |
| 1161 | return; |
| 1162 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1163 | webview()->focusedFrame()->executeCommand( |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 1164 | WebString::fromUTF8("SelectAll")); |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1165 | UserMetricsRecordAction("SelectAll"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | void RenderView::OnSetInitialFocus(bool reverse) { |
| 1169 | if (!webview()) |
| 1170 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1171 | webview()->setInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | /////////////////////////////////////////////////////////////////////////////// |
| 1175 | |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1176 | void RenderView::SetContentSettings(const ContentSettings& settings) { |
| 1177 | current_content_settings_ = settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1178 | } |
| 1179 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1180 | // Tell the embedding application that the URL of the active page has changed |
| 1181 | void RenderView::UpdateURL(WebFrame* frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1182 | WebDataSource* ds = frame->dataSource(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1183 | DCHECK(ds); |
| 1184 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1185 | const WebURLRequest& request = ds->request(); |
| 1186 | const WebURLRequest& original_request = ds->originalRequest(); |
| 1187 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1188 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1189 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 1190 | DCHECK(navigation_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1191 | |
| 1192 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1193 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1194 | params.is_post = false; |
| 1195 | params.page_id = page_id_; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1196 | params.is_content_filtered = response.isContentFiltered(); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1197 | if (!navigation_state->security_info().empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1198 | // SSL state specified in the request takes precedence over the one in the |
| 1199 | // response. |
| 1200 | // So far this is only intended for error pages that are not expected to be |
| 1201 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1202 | DCHECK(response.securityInfo().isEmpty()); |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1203 | params.security_info = navigation_state->security_info(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1204 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1205 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1209 | if (ds->hasUnreachableURL()) { |
| 1210 | params.url = ds->unreachableURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1211 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1212 | params.url = request.url(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1213 | } |
| 1214 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1215 | GetRedirectChain(ds, ¶ms.redirects); |
[email protected] | d94dc1e | 2010-03-04 09:29:24 | [diff] [blame] | 1216 | params.should_update_history = !ds->hasUnreachableURL() && |
| 1217 | !response.isMultipartPayload(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1218 | |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 1219 | params.searchable_form_url = navigation_state->searchable_form_url(); |
| 1220 | params.searchable_form_encoding = |
| 1221 | navigation_state->searchable_form_encoding(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1222 | |
| 1223 | const PasswordForm* password_form_data = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1224 | navigation_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1225 | if (password_form_data) |
| 1226 | params.password_form = *password_form_data; |
| 1227 | |
| 1228 | params.gesture = navigation_gesture_; |
| 1229 | navigation_gesture_ = NavigationGestureUnknown; |
| 1230 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1231 | if (!frame->parent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1232 | // Top-level navigation. |
| 1233 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 1234 | // Clear "block" flags for the new page. This needs to happen before any of |
| 1235 | // allowScripts(), allowImages(), allowPlugins() is called for the new page |
| 1236 | // so that these functions can correctly detect that a piece of content |
| 1237 | // flipped from "not blocked" to "blocked". |
| 1238 | ClearBlockedContentSettings(); |
| 1239 | |
[email protected] | 62d2a11 | 2010-04-07 00:53:02 | [diff] [blame] | 1240 | // Set content settings. Default them from the parent window if one exists. |
| 1241 | // This makes sure about:blank windows work as expected. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1242 | HostContentSettings::iterator host_content_settings = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1243 | host_content_settings_.find(GURL(request.url())); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1244 | if (host_content_settings != host_content_settings_.end()) { |
[email protected] | 433819d | 2010-01-30 20:20:01 | [diff] [blame] | 1245 | SetContentSettings(host_content_settings->second); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1246 | |
| 1247 | // These content settings were merely recorded transiently for this load. |
| 1248 | // We can erase them now. If at some point we reload this page, the |
| 1249 | // browser will send us new, up-to-date content settings. |
| 1250 | host_content_settings_.erase(host_content_settings); |
[email protected] | 3a387ae | 2010-04-08 01:58:40 | [diff] [blame] | 1251 | } else if (frame->opener()) { |
| 1252 | WebView* opener_view = frame->opener()->view(); |
| 1253 | RenderView* opener = FromWebView(opener_view); |
| 1254 | SetContentSettings(opener->current_content_settings_); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1255 | } |
| 1256 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1257 | // Set zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1258 | HostZoomLevels::iterator host_zoom = |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 1259 | host_zoom_levels_.find(GURL(request.url())); |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1260 | if (host_zoom != host_zoom_levels_.end()) { |
| 1261 | webview()->setZoomLevel(false, host_zoom->second); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1262 | // This zoom level was merely recorded transiently for this load. We can |
| 1263 | // erase it now. If at some point we reload this page, the browser will |
| 1264 | // send us a new, up-to-date zoom level. |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 1265 | host_zoom_levels_.erase(host_zoom); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 1266 | } |
| 1267 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1268 | // Update contents MIME type for main frame. |
[email protected] | 9c5645b | 2009-08-11 03:37:55 | [diff] [blame] | 1269 | params.contents_mime_type = ds->response().mimeType().utf8(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1270 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1271 | params.transition = navigation_state->transition_type(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1272 | if (!PageTransition::IsMainFrame(params.transition)) { |
| 1273 | // If the main frame does a load, it should not be reported as a subframe |
| 1274 | // navigation. This can occur in the following case: |
| 1275 | // 1. You're on a site with frames. |
| 1276 | // 2. You do a subframe navigation. This is stored with transition type |
| 1277 | // MANUAL_SUBFRAME. |
| 1278 | // 3. You navigate to some non-frame site, say, google.com. |
| 1279 | // 4. You navigate back to the page from step 2. Since it was initially |
| 1280 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 1281 | // We don't want that, because any navigation that changes the toplevel |
| 1282 | // frame should be tracked as a toplevel navigation (this allows us to |
| 1283 | // update the URL bar, etc). |
| 1284 | params.transition = PageTransition::LINK; |
| 1285 | } |
| 1286 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1287 | // If we have a valid consumed client redirect source, |
| 1288 | // the page contained a client redirect (meta refresh, document.loc...), |
| 1289 | // so we set the referrer and transition to match. |
| 1290 | if (completed_client_redirect_src_.is_valid()) { |
[email protected] | 77e09a9 | 2008-08-01 18:11:04 | [diff] [blame] | 1291 | DCHECK(completed_client_redirect_src_ == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1292 | params.referrer = completed_client_redirect_src_; |
| 1293 | params.transition = static_cast<PageTransition::Type>( |
| 1294 | params.transition | PageTransition::CLIENT_REDIRECT); |
| 1295 | } else { |
| 1296 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 1297 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1298 | params.referrer = GURL( |
| 1299 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1300 | } |
| 1301 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1302 | string16 method = request.httpMethod(); |
| 1303 | if (EqualsASCII(method, "POST")) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1304 | params.is_post = true; |
| 1305 | |
[email protected] | c2a797d | 2009-09-21 16:46:32 | [diff] [blame] | 1306 | // Save some histogram data so we can compute the average memory used per |
| 1307 | // page load of the glyphs. |
| 1308 | UMA_HISTOGRAM_COUNTS_10000("Memory.GlyphPagesPerLoad", |
| 1309 | webkit_glue::GetGlyphPageCount()); |
| 1310 | |
[email protected] | 15cf526b | 2010-02-12 06:33:49 | [diff] [blame] | 1311 | // This message needs to be sent before any of allowScripts(), |
| 1312 | // allowImages(), allowPlugins() is called for the new page, so that when |
| 1313 | // these functions send a ViewHostMsg_ContentBlocked message, it arrives |
| 1314 | // after the ViewHostMsg_FrameNavigate message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1315 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1316 | } else { |
| 1317 | // Subframe navigation: the type depends on whether this navigation |
| 1318 | // generated a new session history entry. When they do generate a session |
| 1319 | // history entry, it means the user initiated the navigation and we should |
| 1320 | // mark it as such. This test checks if this is the first time UpdateURL |
| 1321 | // has been called since WillNavigateToURL was called to initiate the load. |
| 1322 | if (page_id_ > last_page_id_sent_to_browser_) |
| 1323 | params.transition = PageTransition::MANUAL_SUBFRAME; |
| 1324 | else |
| 1325 | params.transition = PageTransition::AUTO_SUBFRAME; |
| 1326 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1327 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 1328 | } |
| 1329 | |
| 1330 | last_page_id_sent_to_browser_ = |
| 1331 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 1332 | |
| 1333 | // 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] | 1334 | // we don't want the transition type to persist. Just clear it. |
| 1335 | navigation_state->set_transition_type(PageTransition::LINK); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1336 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1337 | #if defined(OS_WIN) |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 1338 | if (accessibility_.get()) { |
[email protected] | 1745596 | 2010-02-24 01:39:35 | [diff] [blame] | 1339 | // Remove accessibility info cache. |
| 1340 | accessibility_.reset(); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1341 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1342 | #else |
[email protected] | 7d926f9 | 2009-03-03 14:26:54 | [diff] [blame] | 1343 | // TODO(port): accessibility not yet implemented. See http://crbug.com/8288. |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1344 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | // Tell the embedding application that the title of the active page has changed |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1348 | void RenderView::UpdateTitle(WebFrame* frame, const string16& title) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1349 | // Ignore all but top level navigations... |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1350 | if (!frame->parent()) { |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1351 | Send(new ViewHostMsg_UpdateTitle( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1352 | routing_id_, |
| 1353 | page_id_, |
| 1354 | UTF16ToWideHack(title.length() > chrome::kMaxTitleChars ? |
| 1355 | title.substr(0, chrome::kMaxTitleChars) : title))); |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 1356 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | void RenderView::UpdateEncoding(WebFrame* frame, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1360 | const std::string& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1361 | // Only update main frame's encoding_name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1362 | if (webview()->mainFrame() == frame && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1363 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1364 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1365 | last_encoding_name_ = encoding_name; |
| 1366 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 1367 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | |
[email protected] | f4d34b5 | 2008-11-24 23:05:01 | [diff] [blame] | 1371 | // Sends the previous session history state to the browser so it will be saved |
| 1372 | // before we navigate to a new page. This must be called *before* the page ID |
| 1373 | // has been updated so we know what it was. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1374 | void RenderView::UpdateSessionHistory(WebFrame* frame) { |
| 1375 | // If we have a valid page ID at this point, then it corresponds to the page |
| 1376 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 1377 | // there is no past session history to record. |
| 1378 | if (page_id_ == -1) |
| 1379 | return; |
| 1380 | |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1381 | const WebHistoryItem& item = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1382 | webview()->mainFrame()->previousHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1383 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1384 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 1385 | |
| 1386 | Send(new ViewHostMsg_UpdateState( |
| 1387 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1388 | } |
| 1389 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 1390 | void RenderView::OpenURL( |
| 1391 | const GURL& url, const GURL& referrer, WebNavigationPolicy policy) { |
| 1392 | Send(new ViewHostMsg_OpenURL( |
| 1393 | routing_id_, url, referrer, NavigationPolicyToDisposition(policy))); |
| 1394 | } |
| 1395 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 1396 | // WebViewDelegate ------------------------------------------------------------ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1397 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1398 | void RenderView::LoadNavigationErrorPage(WebFrame* frame, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1399 | const WebURLRequest& failed_request, |
| 1400 | const WebURLError& error, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1401 | const std::string& html, |
| 1402 | bool replace) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1403 | GURL failed_url = error.unreachableURL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1404 | |
| 1405 | std::string alt_html; |
| 1406 | if (html.empty()) { |
| 1407 | // Use a local error page. |
| 1408 | int resource_id; |
| 1409 | DictionaryValue error_strings; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1410 | if (error.reason == net::ERR_CACHE_MISS && |
| 1411 | EqualsASCII(failed_request.httpMethod(), "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1412 | GetFormRepostErrorValues(failed_url, &error_strings); |
| 1413 | resource_id = IDR_ERROR_NO_DETAILS_HTML; |
| 1414 | } else { |
| 1415 | GetLocalizedErrorValues(error, &error_strings); |
| 1416 | resource_id = IDR_NET_ERROR_HTML; |
| 1417 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1418 | |
| 1419 | alt_html = GetAltHTMLForTemplate(error_strings, resource_id); |
| 1420 | } else { |
| 1421 | alt_html = html; |
| 1422 | } |
| 1423 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 1424 | frame->loadHTMLString(alt_html, |
[email protected] | e6f546c3 | 2009-07-01 17:12:55 | [diff] [blame] | 1425 | GURL(kUnreachableWebDataURL), |
| 1426 | failed_url, |
| 1427 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1428 | } |
| 1429 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 1430 | void RenderView::BindDOMAutomationController(WebFrame* frame) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1431 | dom_automation_controller_.set_message_sender(this); |
| 1432 | dom_automation_controller_.set_routing_id(routing_id_); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 1433 | dom_automation_controller_.BindToJavascript(frame, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1434 | L"domAutomationController"); |
| 1435 | } |
| 1436 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1437 | bool RenderView::RunJavaScriptMessage(int type, |
| 1438 | const std::wstring& message, |
| 1439 | const std::wstring& default_value, |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1440 | const GURL& frame_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1441 | std::wstring* result) { |
| 1442 | bool success = false; |
| 1443 | std::wstring result_temp; |
| 1444 | if (!result) |
| 1445 | result = &result_temp; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1446 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1447 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunJavaScriptMessage( |
| 1448 | routing_id_, message, default_value, frame_url, type, &success, result)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1449 | return success; |
| 1450 | } |
| 1451 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 1452 | bool RenderView::SendAndRunNestedMessageLoop(IPC::SyncMessage* message) { |
| 1453 | // Before WebKit asks us to show an alert (etc.), it takes care of doing the |
| 1454 | // equivalent of WebView::willEnterModalLoop. In the case of showModalDialog |
| 1455 | // it is particularly important that we do not call willEnterModalLoop as |
| 1456 | // that would defer resource loads for the dialog itself. |
| 1457 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 1458 | RenderThread::current()->DoNotNotifyWebKitOfModalLoop(); |
| 1459 | |
| 1460 | message->EnableMessagePumping(); // Runs a nested message loop. |
| 1461 | return Send(message); |
| 1462 | } |
| 1463 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1464 | void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) { |
| 1465 | if (!osd_url.is_empty()) |
| 1466 | Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, |
| 1467 | autodetected)); |
| 1468 | } |
| 1469 | |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1470 | void RenderView::OnAutoFillSuggestionsReturned( |
| 1471 | int query_id, |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 1472 | const std::vector<string16>& values, |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1473 | const std::vector<string16>& labels, |
| 1474 | int default_suggestion_index) { |
| 1475 | if (webview() && query_id == autofill_query_id_) { |
| 1476 | webview()->applyAutoFillSuggestions( |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 1477 | autofill_query_node_, values, labels, default_suggestion_index); |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1478 | } |
| 1479 | autofill_query_node_.reset(); |
| 1480 | } |
| 1481 | |
[email protected] | cf28ec5 | 2010-04-09 22:56:34 | [diff] [blame] | 1482 | void RenderView::OnAutoFillForms( |
| 1483 | const std::vector<webkit_glue::FormData>& forms) { |
| 1484 | form_manager_.FillForms(forms); |
| 1485 | } |
| 1486 | |
[email protected] | 95056b58 | 2010-02-18 01:29:24 | [diff] [blame] | 1487 | void RenderView::OnAutocompleteSuggestionsReturned( |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 1488 | int query_id, |
| 1489 | const std::vector<string16>& suggestions, |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1490 | int default_suggestion_index) { |
[email protected] | 7e089f27 | 2009-11-03 17:07:18 | [diff] [blame] | 1491 | if (webview() && query_id == autofill_query_id_) { |
[email protected] | 9e3444c | 2010-02-11 21:30:08 | [diff] [blame] | 1492 | webview()->applyAutocompleteSuggestions( |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 1493 | autofill_query_node_, suggestions, default_suggestion_index); |
| 1494 | } |
| 1495 | autofill_query_node_.reset(); |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1496 | } |
| 1497 | |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 1498 | void RenderView::OnAutoFillFormDataFilled(int query_id, |
| 1499 | const webkit_glue::FormData& form) { |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 1500 | if (query_id != autofill_query_id_) |
| 1501 | return; |
| 1502 | |
| 1503 | form_manager_.FillForm(form); |
| 1504 | } |
| 1505 | |
[email protected] | 2c4410d | 2009-05-06 23:46:22 | [diff] [blame] | 1506 | void RenderView::OnPopupNotificationVisibilityChanged(bool visible) { |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1507 | popup_notification_visible_ = visible; |
| 1508 | } |
| 1509 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1510 | uint32 RenderView::GetCPBrowsingContext() { |
| 1511 | uint32 context = 0; |
| 1512 | Send(new ViewHostMsg_GetCPBrowsingContext(&context)); |
| 1513 | return context; |
| 1514 | } |
| 1515 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1516 | void RenderView::AddSearchProvider(const std::string& url) { |
| 1517 | AddGURLSearchProvider(GURL(url), |
| 1518 | false); // not autodetected |
| 1519 | } |
| 1520 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1521 | void RenderView::OnMissingPluginStatus( |
| 1522 | WebPluginDelegateProxy* delegate, |
| 1523 | int status) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1524 | #if defined(OS_WIN) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1525 | if (!first_default_plugin_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1526 | // Show the InfoBar for the first available plugin. |
| 1527 | if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) { |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1528 | first_default_plugin_ = delegate->AsWeakPtr(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1529 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1530 | } |
| 1531 | } else { |
| 1532 | // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar) |
| 1533 | // to start the download/install. |
| 1534 | if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) { |
| 1535 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1536 | } |
| 1537 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1538 | #else |
| 1539 | // TODO(port): plugins current not supported |
| 1540 | NOTIMPLEMENTED(); |
| 1541 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1542 | } |
| 1543 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1544 | // WebKit::WebViewClient ------------------------------------------------------ |
| 1545 | |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 1546 | // TODO(rafaelw): remove when |
| 1547 | // WebViewClient::createView(WebFrame,WebWindowFeatures) lands. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1548 | WebView* RenderView::createView(WebFrame* creator) { |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 1549 | return createView(creator, WebWindowFeatures()); |
| 1550 | } |
| 1551 | |
| 1552 | WebView* RenderView::createView( |
| 1553 | WebFrame* creator, |
| 1554 | const WebWindowFeatures& features) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1555 | // Check to make sure we aren't overloading on popups. |
| 1556 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1557 | return NULL; |
| 1558 | |
| 1559 | // This window can't be closed from a window.close() call until we receive a |
| 1560 | // message from the Browser process explicitly allowing it. |
| 1561 | popup_notification_visible_ = true; |
| 1562 | |
| 1563 | int32 routing_id = MSG_ROUTING_NONE; |
| 1564 | bool user_gesture = creator->isProcessingUserGesture(); |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1565 | bool opener_suppressed = creator->willSuppressOpenerInNewFrame(); |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1566 | int64 cloned_session_storage_namespace_id; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1567 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1568 | render_thread_->Send( |
[email protected] | 534c66c | 2010-04-28 22:53:11 | [diff] [blame] | 1569 | new ViewHostMsg_CreateWindow( |
| 1570 | routing_id_, |
| 1571 | user_gesture, |
| 1572 | WindowFeaturesToContainerType(features), |
| 1573 | session_storage_namespace_id_, |
| 1574 | &routing_id, |
| 1575 | &cloned_session_storage_namespace_id)); |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1576 | if (routing_id == MSG_ROUTING_NONE) |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1577 | return NULL; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1578 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1579 | RenderView* view = RenderView::Create(render_thread_, |
[email protected] | 659f73fa | 2009-10-13 13:43:42 | [diff] [blame] | 1580 | 0, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1581 | routing_id_, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1582 | renderer_preferences_, |
| 1583 | webkit_preferences_, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1584 | shared_popup_counter_, |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 1585 | routing_id, |
| 1586 | cloned_session_storage_namespace_id); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1587 | view->opened_by_user_gesture_ = user_gesture; |
| 1588 | |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 1589 | // Record whether the creator frame is trying to suppress the opener field. |
| 1590 | view->opener_suppressed_ = opener_suppressed; |
| 1591 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1592 | // Record the security origin of the creator. |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 1593 | GURL creator_url(creator->securityOrigin().toString().utf8()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1594 | if (!creator_url.is_valid() || !creator_url.IsStandard()) |
| 1595 | creator_url = GURL(); |
| 1596 | view->creator_url_ = creator_url; |
| 1597 | |
| 1598 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1599 | // the new render view (we don't need the browser to send the URL back down). |
| 1600 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1601 | |
| 1602 | return view->webview(); |
| 1603 | } |
| 1604 | |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1605 | WebWidget* RenderView::createPopupMenu(WebKit::WebPopupType popup_type) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1606 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1607 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1608 | popup_type); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1609 | return widget->webwidget(); |
| 1610 | } |
| 1611 | |
| 1612 | WebWidget* RenderView::createPopupMenu(const WebPopupMenuInfo& info) { |
| 1613 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
| 1614 | render_thread_, |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 1615 | WebKit::WebPopupTypeSelect); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1616 | widget->ConfigureAsExternalPopupMenu(info); |
| 1617 | return widget->webwidget(); |
| 1618 | } |
| 1619 | |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1620 | WebStorageNamespace* RenderView::createSessionStorageNamespace() { |
| 1621 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) |
| 1622 | return WebStorageNamespace::createSessionStorageNamespace(); |
[email protected] | 59afea1 | 2010-01-20 04:48:29 | [diff] [blame] | 1623 | CHECK(session_storage_namespace_id_ != kInvalidSessionStorageNamespaceId); |
| 1624 | return new RendererWebStorageNamespaceImpl(DOM_STORAGE_SESSION, |
| 1625 | session_storage_namespace_id_); |
[email protected] | bd92c3a | 2010-01-13 05:02:34 | [diff] [blame] | 1626 | } |
| 1627 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1628 | void RenderView::didAddMessageToConsole( |
| 1629 | const WebConsoleMessage& message, const WebString& source_name, |
| 1630 | unsigned source_line) { |
| 1631 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, |
| 1632 | UTF16ToWideHack(message.text), |
| 1633 | static_cast<int32>(source_line), |
| 1634 | UTF16ToWideHack(source_name))); |
| 1635 | } |
| 1636 | |
| 1637 | void RenderView::printPage(WebFrame* frame) { |
[email protected] | 71a1426 | 2009-09-22 20:02:58 | [diff] [blame] | 1638 | DCHECK(frame); |
| 1639 | Print(frame, true); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | void RenderView::didStartLoading() { |
| 1643 | if (is_loading_) { |
| 1644 | DLOG(WARNING) << "didStartLoading called while loading"; |
| 1645 | return; |
| 1646 | } |
| 1647 | |
| 1648 | is_loading_ = true; |
| 1649 | // Clear the pointer so that we can assign it only when there is an unknown |
| 1650 | // plugin on a page. |
| 1651 | first_default_plugin_.reset(); |
| 1652 | |
| 1653 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
| 1654 | } |
| 1655 | |
| 1656 | void RenderView::didStopLoading() { |
| 1657 | if (!is_loading_) { |
| 1658 | DLOG(WARNING) << "DidStopLoading called while not loading"; |
| 1659 | return; |
| 1660 | } |
| 1661 | |
| 1662 | is_loading_ = false; |
| 1663 | |
| 1664 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1665 | // when done loading. This currently isn't an issue as the favicon is only |
| 1666 | // displayed when done loading. Ideally we would send notification when |
| 1667 | // finished parsing the head, but webkit doesn't support that yet. |
| 1668 | // The feed discovery code would also benefit from access to the head. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1669 | GURL favicon_url(webview()->mainFrame()->favIconURL()); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1670 | if (!favicon_url.is_empty()) |
| 1671 | Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url)); |
| 1672 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1673 | AddGURLSearchProvider(webview()->mainFrame()->openSearchDescriptionURL(), |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1674 | true); // autodetected |
| 1675 | |
| 1676 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
| 1677 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 1678 | MessageLoop::current()->PostDelayedTask( |
| 1679 | FROM_HERE, |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1680 | method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_, |
| 1681 | false), |
| 1682 | kDelayForCaptureMs); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1683 | } |
| 1684 | |
[email protected] | f55039a | 2010-02-17 14:12:06 | [diff] [blame] | 1685 | bool RenderView::isSmartInsertDeleteEnabled() { |
| 1686 | #if defined(OS_MACOSX) |
| 1687 | return true; |
| 1688 | #else |
| 1689 | return false; |
| 1690 | #endif |
| 1691 | } |
| 1692 | |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1693 | bool RenderView::isSelectTrailingWhitespaceEnabled() { |
| 1694 | #if defined(OS_WIN) |
| 1695 | return true; |
| 1696 | #else |
| 1697 | return false; |
| 1698 | #endif |
| 1699 | } |
| 1700 | |
| 1701 | void RenderView::setInputMethodEnabled(bool enabled) { |
| 1702 | // Save the updated IME status and mark the input focus has been updated. |
| 1703 | // The IME status is to be sent to a browser process next time when |
| 1704 | // the input caret is rendered. |
| 1705 | if (!ime_control_busy_) { |
| 1706 | ime_control_updated_ = true; |
| 1707 | ime_control_new_state_ = enabled; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | void RenderView::didChangeSelection(bool is_empty_selection) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 1712 | #if defined(USE_X11) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1713 | if (!handling_input_event_) |
| 1714 | return; |
| 1715 | // TODO(estade): investigate incremental updates to the selection so that we |
| 1716 | // don't send the entire selection over IPC every time. |
| 1717 | if (!is_empty_selection) { |
| 1718 | // Sometimes we get repeated didChangeSelection calls from webkit when |
| 1719 | // the selection hasn't actually changed. We don't want to report these |
| 1720 | // because it will cause us to continually claim the X clipboard. |
| 1721 | const std::string& this_selection = |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1722 | webview()->focusedFrame()->selectionAsText().utf8(); |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1723 | if (this_selection == last_selection_) |
| 1724 | return; |
| 1725 | |
| 1726 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
| 1727 | this_selection)); |
| 1728 | last_selection_ = this_selection; |
| 1729 | } else { |
| 1730 | last_selection_.clear(); |
| 1731 | } |
| 1732 | #endif |
| 1733 | } |
| 1734 | |
| 1735 | void RenderView::didExecuteCommand(const WebString& command_name) { |
[email protected] | afe3a167 | 2009-11-17 19:04:12 | [diff] [blame] | 1736 | const std::string& name = UTF16ToUTF8(command_name); |
| 1737 | if (StartsWithASCII(name, "Move", true) || |
| 1738 | StartsWithASCII(name, "Insert", true) || |
| 1739 | StartsWithASCII(name, "Delete", true)) |
[email protected] | 04fc948 | 2009-09-18 22:13:03 | [diff] [blame] | 1740 | return; |
| 1741 | UserMetricsRecordAction(name); |
| 1742 | } |
| 1743 | |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1744 | bool RenderView::handleCurrentKeyboardEvent() { |
| 1745 | if (edit_commands_.empty()) |
| 1746 | return false; |
| 1747 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 1748 | WebFrame* frame = webview()->focusedFrame(); |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1749 | if (!frame) |
| 1750 | return false; |
| 1751 | |
| 1752 | EditCommands::iterator it = edit_commands_.begin(); |
| 1753 | EditCommands::iterator end = edit_commands_.end(); |
| 1754 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1755 | bool did_execute_command = false; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1756 | for (; it != end; ++it) { |
[email protected] | e6e1501 | 2009-09-30 14:59:33 | [diff] [blame] | 1757 | // In gtk and cocoa, it's possible to bind multiple edit commands to one |
| 1758 | // key (but it's the exception). Once one edit command is not executed, it |
| 1759 | // seems safest to not execute the rest. |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1760 | if (!frame->executeCommand(WebString::fromUTF8(it->name), |
| 1761 | WebString::fromUTF8(it->value))) |
| 1762 | break; |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1763 | did_execute_command = true; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1764 | } |
| 1765 | |
[email protected] | 507b33ea | 2009-09-29 03:56:51 | [diff] [blame] | 1766 | return did_execute_command; |
[email protected] | b2528b7 | 2009-09-24 06:57:10 | [diff] [blame] | 1767 | } |
| 1768 | |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1769 | void RenderView::spellCheck(const WebString& text, |
| 1770 | int& misspelled_offset, |
| 1771 | int& misspelled_length) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1772 | EnsureDocumentTag(); |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1773 | |
[email protected] | 85c55dc | 2009-11-06 03:05:46 | [diff] [blame] | 1774 | string16 word(text); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1775 | RenderThread* thread = RenderThread::current(); |
| 1776 | // Will be NULL during unit tests. |
| 1777 | if (thread) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1778 | thread->spellchecker()->SpellCheckWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1779 | word.c_str(), word.size(), document_tag_, |
| 1780 | &misspelled_offset, &misspelled_length, NULL); |
| 1781 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | WebString RenderView::autoCorrectWord(const WebKit::WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1785 | string16 autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1786 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | b86c8c1 | 2009-10-05 22:01:26 | [diff] [blame] | 1787 | if (command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures)) { |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1788 | EnsureDocumentTag(); |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1789 | RenderThread* thread = RenderThread::current(); |
| 1790 | // Will be NULL during unit tests. |
| 1791 | if (thread) { |
| 1792 | autocorrect_word = |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1793 | thread->spellchecker()->GetAutoCorrectionWord( |
[email protected] | cb6037d | 2009-11-16 22:55:17 | [diff] [blame] | 1794 | word, document_tag_); |
| 1795 | } |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1796 | } |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1797 | return autocorrect_word; |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1798 | } |
| 1799 | |
[email protected] | c49085c7 | 2009-10-02 16:28:56 | [diff] [blame] | 1800 | void RenderView::showSpellingUI(bool show) { |
| 1801 | Send(new ViewHostMsg_ShowSpellingPanel(routing_id_, show)); |
| 1802 | } |
| 1803 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1804 | bool RenderView::isShowingSpellingUI() { |
| 1805 | return spelling_panel_visible_; |
| 1806 | } |
| 1807 | |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1808 | void RenderView::updateSpellingUIWithMisspelledWord(const WebString& word) { |
[email protected] | 2a3a776 | 2009-10-19 19:17:32 | [diff] [blame] | 1809 | Send(new ViewHostMsg_UpdateSpellingPanelWithMisspelledWord(routing_id_, |
| 1810 | word)); |
[email protected] | 1dbafaf7 | 2009-09-23 19:43:56 | [diff] [blame] | 1811 | } |
| 1812 | |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1813 | bool RenderView::runFileChooser( |
[email protected] | 01178b5 | 2010-01-15 06:59:35 | [diff] [blame] | 1814 | const WebKit::WebFileChooserParams& params, |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 1815 | WebFileChooserCompletion* chooser_completion) { |
| 1816 | ViewHostMsg_RunFileChooser_Params ipc_params; |
| 1817 | ipc_params.mode = params.multiSelect ? |
| 1818 | ViewHostMsg_RunFileChooser_Params::OpenMultiple : |
| 1819 | ViewHostMsg_RunFileChooser_Params::Open; |
| 1820 | ipc_params.title = params.title; |
| 1821 | ipc_params.default_file_name = |
| 1822 | webkit_glue::WebStringToFilePath(params.initialValue); |
| 1823 | |
| 1824 | return ScheduleFileChooser(ipc_params, chooser_completion); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 1825 | } |
| 1826 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1827 | void RenderView::runModalAlertDialog( |
| 1828 | WebFrame* frame, const WebString& message) { |
| 1829 | RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert, |
| 1830 | UTF16ToWideHack(message), |
| 1831 | std::wstring(), |
| 1832 | frame->url(), |
| 1833 | NULL); |
| 1834 | } |
| 1835 | |
| 1836 | bool RenderView::runModalConfirmDialog( |
| 1837 | WebFrame* frame, const WebString& message) { |
| 1838 | return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm, |
| 1839 | UTF16ToWideHack(message), |
| 1840 | std::wstring(), |
| 1841 | frame->url(), |
| 1842 | NULL); |
| 1843 | } |
| 1844 | |
| 1845 | bool RenderView::runModalPromptDialog( |
| 1846 | WebFrame* frame, const WebString& message, const WebString& default_value, |
| 1847 | WebString* actual_value) { |
| 1848 | std::wstring result; |
| 1849 | bool ok = RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt, |
| 1850 | UTF16ToWideHack(message), |
| 1851 | UTF16ToWideHack(default_value), |
| 1852 | frame->url(), |
| 1853 | &result); |
| 1854 | if (ok) |
| 1855 | actual_value->assign(WideToUTF16Hack(result)); |
| 1856 | return ok; |
| 1857 | } |
| 1858 | |
| 1859 | bool RenderView::runModalBeforeUnloadDialog( |
| 1860 | WebFrame* frame, const WebString& message) { |
| 1861 | bool success = false; |
| 1862 | // This is an ignored return value, but is included so we can accept the same |
| 1863 | // response as RunJavaScriptMessage. |
| 1864 | std::wstring ignored_result; |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1865 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1866 | routing_id_, frame->url(), UTF16ToWideHack(message), &success, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 1867 | &ignored_result)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1868 | return success; |
| 1869 | } |
| 1870 | |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 1871 | void RenderView::showContextMenu( |
| 1872 | WebFrame* frame, const WebContextMenuData& data) { |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1873 | ContextMenuParams params = ContextMenuParams(data); |
| 1874 | if (!params.misspelled_word.empty() && RenderThread::current()) { |
| 1875 | int misspelled_offset, misspelled_length; |
[email protected] | c76a36a | 2010-01-26 22:44:04 | [diff] [blame] | 1876 | bool spelled_right = RenderThread::current()->spellchecker()-> |
| 1877 | SpellCheckWord( |
| 1878 | params.misspelled_word.c_str(), params.misspelled_word.size(), |
| 1879 | document_tag_, |
| 1880 | &misspelled_offset, &misspelled_length, |
| 1881 | ¶ms.dictionary_suggestions); |
| 1882 | if (spelled_right) |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 1883 | params.misspelled_word.clear(); |
| 1884 | } |
| 1885 | |
| 1886 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
[email protected] | 79e3744 | 2009-10-09 18:17:44 | [diff] [blame] | 1887 | } |
| 1888 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1889 | void RenderView::setStatusText(const WebString& text) { |
| 1890 | } |
| 1891 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1892 | void RenderView::UpdateTargetURL(const GURL& url, const GURL& fallback_url) { |
[email protected] | aa6b90b3 | 2010-04-26 15:49:58 | [diff] [blame] | 1893 | GURL latest_url = url.is_empty() ? fallback_url : url; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1894 | if (latest_url == target_url_) |
| 1895 | return; |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1896 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1897 | // Tell the browser to display a destination link. |
| 1898 | if (target_url_status_ == TARGET_INFLIGHT || |
| 1899 | target_url_status_ == TARGET_PENDING) { |
| 1900 | // If we have a request in-flight, save the URL to be sent when we |
| 1901 | // receive an ACK to the in-flight request. We can happily overwrite |
| 1902 | // any existing pending sends. |
| 1903 | pending_target_url_ = latest_url; |
| 1904 | target_url_status_ = TARGET_PENDING; |
| 1905 | } else { |
| 1906 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, latest_url)); |
| 1907 | target_url_ = latest_url; |
| 1908 | target_url_status_ = TARGET_INFLIGHT; |
| 1909 | } |
| 1910 | } |
| 1911 | |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 1912 | void RenderView::StartNavStateSyncTimerIfNecessary() { |
| 1913 | int delay; |
| 1914 | if (send_content_state_immediately_) |
| 1915 | delay = 0; |
| 1916 | else if (is_hidden()) |
| 1917 | delay = kDelaySecondsForContentStateSyncHidden; |
| 1918 | else |
| 1919 | delay = kDelaySecondsForContentStateSync; |
| 1920 | |
| 1921 | if (nav_state_sync_timer_.IsRunning()) { |
| 1922 | // The timer is already running. If the delay of the timer maches the amount |
| 1923 | // we want to delay by, then return. Otherwise stop the timer so that it |
| 1924 | // gets started with the right delay. |
| 1925 | if (nav_state_sync_timer_.GetCurrentDelay().InSeconds() == delay) |
| 1926 | return; |
| 1927 | nav_state_sync_timer_.Stop(); |
| 1928 | } |
| 1929 | |
| 1930 | nav_state_sync_timer_.Start( |
| 1931 | TimeDelta::FromSeconds(delay), this, &RenderView::SyncNavigationState); |
| 1932 | } |
| 1933 | |
[email protected] | 163f824 | 2009-10-30 20:19:55 | [diff] [blame] | 1934 | void RenderView::setMouseOverURL(const WebURL& url) { |
| 1935 | mouse_over_url_ = GURL(url); |
| 1936 | UpdateTargetURL(mouse_over_url_, focus_url_); |
| 1937 | } |
| 1938 | |
| 1939 | void RenderView::setKeyboardFocusURL(const WebURL& url) { |
| 1940 | focus_url_ = GURL(url); |
| 1941 | UpdateTargetURL(focus_url_, mouse_over_url_); |
| 1942 | } |
| 1943 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1944 | void RenderView::setToolTipText(const WebString& text, WebTextDirection hint) { |
| 1945 | Send(new ViewHostMsg_SetTooltipText(routing_id_, UTF16ToWideHack(text), |
| 1946 | hint)); |
| 1947 | } |
| 1948 | |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1949 | void RenderView::startDragging(const WebDragData& data, |
| 1950 | WebDragOperationsMask mask, |
| 1951 | const WebImage& image, |
| 1952 | const WebPoint& imageOffset) { |
| 1953 | #if WEBKIT_USING_SKIA |
| 1954 | SkBitmap bitmap(image.getSkBitmap()); |
| 1955 | #elif WEBKIT_USING_CG |
[email protected] | 78043bdd | 2010-04-05 18:45:33 | [diff] [blame] | 1956 | SkBitmap bitmap = gfx::CGImageToSkBitmap(image.getCGImageRef()); |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1957 | #endif |
| 1958 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1959 | Send(new ViewHostMsg_StartDragging(routing_id_, |
| 1960 | WebDropData(data), |
[email protected] | c27ae59 | 2010-03-18 15:24:41 | [diff] [blame] | 1961 | mask, |
| 1962 | bitmap, |
| 1963 | imageOffset)); |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1964 | } |
| 1965 | |
[email protected] | 28b92df | 2009-09-25 17:35:45 | [diff] [blame] | 1966 | bool RenderView::acceptsLoadDrops() { |
| 1967 | return renderer_preferences_.can_accept_load_drops; |
| 1968 | } |
| 1969 | |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1970 | void RenderView::focusNext() { |
| 1971 | Send(new ViewHostMsg_TakeFocus(routing_id_, false)); |
| 1972 | } |
| 1973 | |
| 1974 | void RenderView::focusPrevious() { |
| 1975 | Send(new ViewHostMsg_TakeFocus(routing_id_, true)); |
| 1976 | } |
| 1977 | |
| 1978 | void RenderView::navigateBackForwardSoon(int offset) { |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1979 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 1980 | } |
| 1981 | |
| 1982 | int RenderView::historyBackListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1983 | return history_list_offset_ < 0 ? 0 : history_list_offset_; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | int RenderView::historyForwardListCount() { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 1987 | return history_list_length_ - historyBackListCount() - 1; |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 1988 | } |
| 1989 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 1990 | void RenderView::didUpdateInspectorSettings() { |
| 1991 | Send(new ViewHostMsg_UpdateInspectorSettings( |
| 1992 | routing_id_, webview()->inspectorSettings().utf8())); |
| 1993 | } |
| 1994 | |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 1995 | void RenderView::queryAutofillSuggestions(const WebNode& node, |
| 1996 | const WebString& name, |
| 1997 | const WebString& value) { |
| 1998 | static int query_counter = 0; |
| 1999 | autofill_query_id_ = query_counter++; |
| 2000 | autofill_query_node_ = node; |
[email protected] | e250e49 | 2010-04-06 21:35:36 | [diff] [blame] | 2001 | |
| 2002 | const WebFormControlElement& element = |
| 2003 | node.toConstElement<WebFormControlElement>(); |
| 2004 | |
[email protected] | dede934 | 2010-04-12 16:51:11 | [diff] [blame] | 2005 | webkit_glue::FormField field; |
| 2006 | FormManager::WebFormControlElementToFormField(element, true, &field); |
[email protected] | e250e49 | 2010-04-06 21:35:36 | [diff] [blame] | 2007 | |
[email protected] | 72eb2da | 2010-04-14 00:31:08 | [diff] [blame] | 2008 | // WebFormControlElementToFormField does not scrape the DOM for the field |
| 2009 | // label, so find the label here. |
| 2010 | // TODO(jhawkins): Add form and field identities so we can use the cached form |
| 2011 | // data in FormManager. |
| 2012 | field.set_label(FormManager::LabelForElement(element)); |
| 2013 | |
[email protected] | dede934 | 2010-04-12 16:51:11 | [diff] [blame] | 2014 | Send(new ViewHostMsg_QueryFormFieldAutofill( |
| 2015 | routing_id_, autofill_query_id_, field)); |
[email protected] | acca2a1f | 2009-10-16 03:53:39 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void RenderView::removeAutofillSuggestions(const WebString& name, |
| 2019 | const WebString& value) { |
| 2020 | Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value)); |
| 2021 | } |
| 2022 | |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2023 | void RenderView::didAcceptAutoFillSuggestion( |
| 2024 | const WebKit::WebNode& node, |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 2025 | const WebKit::WebString& value, |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2026 | const WebKit::WebString& label) { |
| 2027 | static int query_counter = 0; |
| 2028 | autofill_query_id_ = query_counter++; |
| 2029 | |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 2030 | webkit_glue::FormData form; |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 2031 | const WebInputElement element = node.toConstElement<WebInputElement>(); |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2032 | if (!form_manager_.FindFormWithFormControlElement( |
[email protected] | da59227 | 2010-04-14 20:08:49 | [diff] [blame] | 2033 | element, FormManager::REQUIRE_NONE, &form)) |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2034 | return; |
| 2035 | |
| 2036 | Send(new ViewHostMsg_FillAutoFillFormData( |
[email protected] | 8f6e658 | 2010-04-09 02:03:07 | [diff] [blame] | 2037 | routing_id_, autofill_query_id_, form, value, label)); |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2038 | } |
| 2039 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 2040 | // WebKit::WebWidgetClient ---------------------------------------------------- |
| 2041 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2042 | // We are supposed to get a single call to Show for a newly created RenderView |
| 2043 | // that was created via RenderView::CreateWebView. So, we wait until this |
| 2044 | // point to dispatch the ShowView message. |
| 2045 | // |
| 2046 | // This method provides us with the information about how to display the newly |
| 2047 | // created RenderView (i.e., as a constrained popup or as a new tab). |
| 2048 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2049 | void RenderView::show(WebNavigationPolicy policy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2050 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 2051 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 2052 | |
| 2053 | if (did_show_) |
| 2054 | return; |
| 2055 | did_show_ = true; |
| 2056 | |
[email protected] | 28295ec | 2009-10-16 05:34:33 | [diff] [blame] | 2057 | // Force new windows to a popup if they were not opened with a user gesture. |
| 2058 | if (!opened_by_user_gesture_) { |
| 2059 | // We exempt background tabs for compat with older versions of Chrome. |
| 2060 | // TODO(darin): This seems bogus. These should have a user gesture, so |
| 2061 | // we probably don't need this check. |
| 2062 | if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) |
| 2063 | policy = WebKit::WebNavigationPolicyNewPopup; |
| 2064 | } |
| 2065 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2066 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 2067 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 2068 | // browser process will impose a default position otherwise. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2069 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, |
| 2070 | NavigationPolicyToDisposition(policy), initial_pos_, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 2071 | opened_by_user_gesture_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 2072 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2073 | } |
| 2074 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2075 | void RenderView::closeWidgetSoon() { |
[email protected] | 2c4410d | 2009-05-06 23:46:22 | [diff] [blame] | 2076 | if (!popup_notification_visible_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2077 | RenderWidget::closeWidgetSoon(); |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 2078 | } |
| 2079 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 2080 | void RenderView::runModal() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2081 | DCHECK(did_show_) << "should already have shown the view"; |
| 2082 | |
[email protected] | c1f50aa | 2010-02-18 03:46:57 | [diff] [blame] | 2083 | // We must keep WebKit's shared timer running in this case in order to allow |
| 2084 | // showModalDialog to function properly. |
| 2085 | // |
| 2086 | // TODO(darin): WebKit should really be smarter about suppressing events and |
| 2087 | // timers so that we do not need to manage the shared timer in such a heavy |
| 2088 | // handed manner. |
| 2089 | // |
| 2090 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 2091 | RenderThread::current()->DoNotSuspendWebKitSharedTimer(); |
| 2092 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 2093 | SendAndRunNestedMessageLoop(new ViewHostMsg_RunModal(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2094 | } |
| 2095 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2096 | // WebKit::WebFrameClient ----------------------------------------------------- |
| 2097 | |
| 2098 | WebPlugin* RenderView::createPlugin( |
| 2099 | WebFrame* frame, const WebPluginParams& params) { |
| 2100 | return new webkit_glue::WebPluginImpl(frame, params, AsWeakPtr()); |
| 2101 | } |
| 2102 | |
| 2103 | WebWorker* RenderView::createWorker(WebFrame* frame, WebWorkerClient* client) { |
| 2104 | return new WebWorkerProxy(client, RenderThread::current(), routing_id_); |
| 2105 | } |
| 2106 | |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2107 | WebSharedWorker* RenderView::createSharedWorker( |
| 2108 | WebFrame* frame, const WebURL& url, const WebString& name, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2109 | unsigned long long document_id) { |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2110 | |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2111 | int route_id = MSG_ROUTING_NONE; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2112 | bool exists = false; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2113 | bool url_mismatch = false; |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2114 | ViewHostMsg_CreateWorker_Params params; |
| 2115 | params.url = url; |
| 2116 | params.is_shared = true; |
| 2117 | params.name = name; |
| 2118 | params.document_id = document_id; |
| 2119 | params.render_view_route_id = routing_id_; |
| 2120 | params.route_id = MSG_ROUTING_NONE; |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2121 | Send(new ViewHostMsg_LookupSharedWorker( |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2122 | params, &exists, &route_id, &url_mismatch)); |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2123 | if (url_mismatch) { |
| 2124 | return NULL; |
| 2125 | } else { |
| 2126 | return new WebSharedWorkerProxy(RenderThread::current(), |
[email protected] | 0791d3a | 2010-01-28 01:28:49 | [diff] [blame] | 2127 | document_id, |
[email protected] | 6de0bcf | 2010-02-17 22:00:51 | [diff] [blame] | 2128 | exists, |
[email protected] | 30447b6 | 2009-11-13 01:13:37 | [diff] [blame] | 2129 | route_id, |
| 2130 | routing_id_); |
| 2131 | } |
[email protected] | 9c00f00 | 2009-11-05 22:37:42 | [diff] [blame] | 2132 | } |
| 2133 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2134 | WebMediaPlayer* RenderView::createMediaPlayer( |
| 2135 | WebFrame* frame, WebMediaPlayerClient* client) { |
| 2136 | scoped_refptr<media::FilterFactoryCollection> factory = |
| 2137 | new media::FilterFactoryCollection(); |
| 2138 | // Add in any custom filter factories first. |
| 2139 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 2140 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
| 2141 | // Add the chrome specific audio renderer. |
| 2142 | factory->AddFactory( |
| 2143 | AudioRendererImpl::CreateFactory(audio_message_filter())); |
| 2144 | } |
| 2145 | |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2146 | WebApplicationCacheHostImpl* appcache_host = |
| 2147 | WebApplicationCacheHostImpl::FromFrame(frame); |
| 2148 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2149 | // TODO(hclam): obtain the following parameters from |client|. |
| 2150 | webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = |
| 2151 | new webkit_glue::MediaResourceLoaderBridgeFactory( |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 2152 | GURL(), // referrer |
| 2153 | "null", // frame origin |
| 2154 | "null", // main_frame_origin |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2155 | base::GetCurrentProcId(), |
[email protected] | 80f584d9 | 2010-01-21 03:59:04 | [diff] [blame] | 2156 | appcache_host ? appcache_host->host_id() : appcache::kNoHostId, |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2157 | routing_id()); |
| 2158 | |
[email protected] | 0436b9a | 2009-10-23 00:23:05 | [diff] [blame] | 2159 | // A simple data source that keeps all data in memory. |
| 2160 | media::FilterFactory* simple_data_source_factory = |
| 2161 | webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(), |
| 2162 | bridge_factory); |
| 2163 | // A sophisticated data source that does memory caching. |
| 2164 | media::FilterFactory* buffered_data_source_factory = |
| 2165 | webkit_glue::BufferedDataSource::CreateFactory(MessageLoop::current(), |
| 2166 | bridge_factory); |
| 2167 | if (cmd_line->HasSwitch(switches::kSimpleDataSource)) { |
| 2168 | factory->AddFactory(simple_data_source_factory); |
| 2169 | factory->AddFactory(buffered_data_source_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2170 | } else { |
[email protected] | 0436b9a | 2009-10-23 00:23:05 | [diff] [blame] | 2171 | factory->AddFactory(buffered_data_source_factory); |
| 2172 | factory->AddFactory(simple_data_source_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2173 | } |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2174 | |
| 2175 | webkit_glue::WebVideoRendererFactoryFactory* factory_factory = NULL; |
| 2176 | if (cmd_line->HasSwitch(switches::kEnableVideoLayering)) { |
| 2177 | factory_factory = new IPCVideoRenderer::FactoryFactory(routing_id_); |
| 2178 | } else { |
[email protected] | b57509eb | 2010-03-30 01:26:28 | [diff] [blame] | 2179 | bool pts_logging = cmd_line->HasSwitch(switches::kEnableVideoLogging); |
| 2180 | factory_factory = |
| 2181 | new webkit_glue::VideoRendererImpl::FactoryFactory(pts_logging); |
[email protected] | 8400e03 | 2010-02-26 18:50:11 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | return new webkit_glue::WebMediaPlayerImpl(client, factory, factory_factory); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2185 | } |
| 2186 | |
[email protected] | 035545f | 2010-04-09 13:10:21 | [diff] [blame] | 2187 | WebApplicationCacheHost* RenderView::createApplicationCacheHost( |
| 2188 | WebFrame* frame, WebApplicationCacheHostClient* client) { |
| 2189 | return new RendererWebApplicationCacheHostImpl( |
| 2190 | FromWebView(frame->view()), client, |
| 2191 | RenderThread::current()->appcache_dispatcher()->backend_proxy()); |
| 2192 | } |
| 2193 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 2194 | WebCookieJar* RenderView::cookieJar() { |
| 2195 | return &cookie_jar_; |
| 2196 | } |
| 2197 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2198 | void RenderView::willClose(WebFrame* frame) { |
| 2199 | if (!frame->parent()) { |
| 2200 | const GURL& url = frame->url(); |
| 2201 | if (url.SchemeIs("http") || url.SchemeIs("https")) |
| 2202 | DumpLoadHistograms(); |
| 2203 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2204 | |
| 2205 | WebDataSource* ds = frame->dataSource(); |
| 2206 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2207 | navigation_state->user_script_idle_scheduler()->Cancel(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2208 | } |
| 2209 | |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2210 | bool RenderView::allowPlugins(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 2211 | if (!enabled_per_settings) |
| 2212 | return false; |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 2213 | return AllowContentType(CONTENT_SETTINGS_TYPE_PLUGINS); |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | bool RenderView::allowImages(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2217 | if (enabled_per_settings && |
| 2218 | AllowContentType(CONTENT_SETTINGS_TYPE_IMAGES)) |
| 2219 | return true; |
| 2220 | |
| 2221 | if (IsWhitelistedForContentSettings(frame)) |
| 2222 | return true; |
| 2223 | |
| 2224 | DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES); |
| 2225 | return false; // Other protocols fall through here. |
[email protected] | 684e4a4 | 2010-01-30 06:44:11 | [diff] [blame] | 2226 | } |
| 2227 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2228 | void RenderView::loadURLExternally( |
| 2229 | WebFrame* frame, const WebURLRequest& request, |
| 2230 | WebNavigationPolicy policy) { |
[email protected] | efce17b | 2009-09-11 18:04:59 | [diff] [blame] | 2231 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2232 | if (policy == WebKit::WebNavigationPolicyDownload) { |
| 2233 | Send(new ViewHostMsg_DownloadUrl(routing_id_, request.url(), referrer)); |
| 2234 | } else { |
| 2235 | OpenURL(request.url(), referrer, policy); |
| 2236 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | WebNavigationPolicy RenderView::decidePolicyForNavigation( |
| 2240 | WebFrame* frame, const WebURLRequest& request, WebNavigationType type, |
[email protected] | 65b95cd | 2009-10-09 05:10:22 | [diff] [blame] | 2241 | const WebNode&, WebNavigationPolicy default_policy, bool is_redirect) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2242 | // Webkit is asking whether to navigate to a new URL. |
| 2243 | // This is fine normally, except if we're showing UI from one security |
| 2244 | // context and they're trying to navigate to a different context. |
| 2245 | const GURL& url = request.url(); |
| 2246 | |
| 2247 | // 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] | 2248 | // navigations. |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 2249 | if (ShouldRouteNavigationToBrowser(url, frame, type)) { |
| 2250 | last_top_level_navigation_page_id_ = page_id_; |
| 2251 | GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); |
| 2252 | OpenURL(url, referrer, default_policy); |
| 2253 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | // A content initiated navigation may have originated from a link-click, |
| 2257 | // script, drag-n-drop operation, etc. |
| 2258 | bool is_content_initiated = |
| 2259 | NavigationState::FromDataSource(frame->provisionalDataSource())-> |
| 2260 | is_content_initiated(); |
| 2261 | |
| 2262 | // We only care about navigations that are within the current tab (as opposed |
| 2263 | // to, for example, opening a new window). |
| 2264 | // But we sometimes navigate to about:blank to clear a tab, and we want to |
| 2265 | // still allow that. |
| 2266 | if (default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2267 | is_content_initiated && frame->parent() == NULL && |
| 2268 | !url.SchemeIs(chrome::kAboutScheme)) { |
| 2269 | // When we received such unsolicited navigations, we sometimes want to |
| 2270 | // punt them up to the browser to handle. |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 2271 | if (CrossesExtensionExtents(frame, url) || |
| 2272 | BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) || |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2273 | BindingsPolicy::is_extension_enabled(enabled_bindings_) || |
| 2274 | frame->isViewSourceModeEnabled() || |
| 2275 | url.SchemeIs(chrome::kViewSourceScheme) || |
| 2276 | url.SchemeIs(chrome::kPrintScheme)) { |
| 2277 | OpenURL(url, GURL(), default_policy); |
| 2278 | return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. |
| 2279 | } |
| 2280 | } |
| 2281 | |
| 2282 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 2283 | // its own process. This is done by sites like Gmail that try to open links |
| 2284 | // in new windows without script connections back to the original page. We |
| 2285 | // treat such cases as browser navigations (in which we will create a new |
| 2286 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 2287 | // |
| 2288 | // We use the following heuristic to decide whether to fork a new page in its |
| 2289 | // own process: |
| 2290 | // The parent page must open a new tab to about:blank, set the new tab's |
| 2291 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 2292 | // JavaScript. |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2293 | // |
| 2294 | // TODO(creis): Deprecate this logic once we can rely on rel=noreferrer |
| 2295 | // (see below). |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2296 | bool is_fork = |
| 2297 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 2298 | GURL(frame->url()) == GURL(chrome::kAboutBlankURL) && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2299 | // Must be the first real navigation of the tab. |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 2300 | historyBackListCount() < 1 && |
| 2301 | historyForwardListCount() < 1 && |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2302 | // The parent page must have set the child's window.opener to null before |
| 2303 | // redirecting to the desired URL. |
| 2304 | frame->opener() == NULL && |
| 2305 | // Must be a top-level frame. |
| 2306 | frame->parent() == NULL && |
| 2307 | // Must not have issued the request from this page. |
| 2308 | is_content_initiated && |
| 2309 | // Must be targeted at the current tab. |
| 2310 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2311 | // Must be a JavaScript navigation, which appears as "other". |
| 2312 | type == WebKit::WebNavigationTypeOther; |
[email protected] | 007a848b | 2009-10-26 15:55:46 | [diff] [blame] | 2313 | |
| 2314 | // Recognize if this navigation is from a link with rel=noreferrer and |
| 2315 | // target=_blank attributes, in which case the opener will be suppressed. If |
| 2316 | // so, it is safe to load cross-site pages in a separate process, so we |
| 2317 | // should let the browser handle it. |
| 2318 | bool is_noreferrer_and_blank_target = |
| 2319 | // Frame should be top level and not yet navigated. |
| 2320 | frame->parent() == NULL && |
| 2321 | frame->url().isEmpty() && |
| 2322 | historyBackListCount() < 1 && |
| 2323 | historyForwardListCount() < 1 && |
| 2324 | // Links with rel=noreferrer will have no Referer field, and their |
| 2325 | // resulting frame will have its window.opener suppressed. |
| 2326 | // TODO(creis): should add a request.httpReferrer() method to help avoid |
| 2327 | // typos on the unusual spelling of Referer. |
| 2328 | request.httpHeaderField(WebString::fromUTF8("Referer")).isNull() && |
| 2329 | opener_suppressed_ && |
| 2330 | frame->opener() == NULL && |
| 2331 | // Links with target=_blank will have no name. |
| 2332 | frame->name().isNull() && |
| 2333 | // Another frame (with a non-empty creator) should have initiated the |
| 2334 | // request, targeted at this frame. |
| 2335 | !creator_url_.is_empty() && |
| 2336 | is_content_initiated && |
| 2337 | default_policy == WebKit::WebNavigationPolicyCurrentTab && |
| 2338 | type == WebKit::WebNavigationTypeOther; |
| 2339 | |
| 2340 | if (is_fork || is_noreferrer_and_blank_target) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2341 | // Open the URL via the browser, not via WebKit. |
| 2342 | OpenURL(url, GURL(), default_policy); |
| 2343 | return WebKit::WebNavigationPolicyIgnore; |
| 2344 | } |
| 2345 | |
| 2346 | return default_policy; |
| 2347 | } |
| 2348 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2349 | bool RenderView::canHandleRequest( |
| 2350 | WebFrame* frame, const WebURLRequest& request) { |
| 2351 | // We allow WebKit to think that everything can be handled even though |
| 2352 | // browser-side we limit what we load. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2353 | return true; |
| 2354 | } |
| 2355 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2356 | WebURLError RenderView::cannotHandleRequestError( |
| 2357 | WebFrame* frame, const WebURLRequest& request) { |
| 2358 | NOTREACHED(); // Since we said we can handle all requests. |
| 2359 | return WebURLError(); |
| 2360 | } |
| 2361 | |
| 2362 | WebURLError RenderView::cancelledError( |
| 2363 | WebFrame* frame, const WebURLRequest& request) { |
| 2364 | WebURLError error; |
| 2365 | error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 2366 | error.reason = net::ERR_ABORTED; |
| 2367 | error.unreachableURL = request.url(); |
| 2368 | return error; |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | void RenderView::unableToImplementPolicyWithError( |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2372 | WebFrame*, const WebURLError&) { |
| 2373 | NOTREACHED(); // Since we said we can handle all requests. |
[email protected] | 7b7a7dc | 2009-10-19 02:23:34 | [diff] [blame] | 2374 | } |
| 2375 | |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 2376 | void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2377 | NavigationState* navigation_state = |
| 2378 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2379 | |
| 2380 | if (navigation_state->transition_type() == PageTransition::LINK) |
| 2381 | navigation_state->set_transition_type(PageTransition::FORM_SUBMIT); |
| 2382 | |
| 2383 | // Save these to be processed when the ensuing navigation is committed. |
[email protected] | ce0e250d | 2009-10-23 21:00:35 | [diff] [blame] | 2384 | WebSearchableFormData web_searchable_form_data(form); |
| 2385 | navigation_state->set_searchable_form_url(web_searchable_form_data.url()); |
| 2386 | navigation_state->set_searchable_form_encoding( |
[email protected] | b7910b3a | 2010-01-13 18:33:21 | [diff] [blame] | 2387 | web_searchable_form_data.encoding().utf8()); |
[email protected] | 66561e7 | 2010-05-04 22:29:21 | [diff] [blame] | 2388 | navigation_state->set_password_form_data( |
| 2389 | PasswordFormDomManager::CreatePasswordForm(form)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2390 | |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2391 | FormData form_data; |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 2392 | if (FormManager::WebFormElementToFormData( |
[email protected] | 3347bab3 | 2010-04-09 04:11:09 | [diff] [blame] | 2393 | form, FormManager::REQUIRE_AUTOCOMPLETE, true, &form_data)) |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 2394 | Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | void RenderView::willPerformClientRedirect( |
| 2398 | WebFrame* frame, const WebURL& from, const WebURL& to, double interval, |
| 2399 | double fire_time) { |
| 2400 | // Ignore |
| 2401 | } |
| 2402 | |
| 2403 | void RenderView::didCancelClientRedirect(WebFrame* frame) { |
| 2404 | // Ignore |
| 2405 | } |
| 2406 | |
| 2407 | void RenderView::didCompleteClientRedirect( |
| 2408 | WebFrame* frame, const WebURL& from) { |
| 2409 | if (!frame->parent()) |
| 2410 | completed_client_redirect_src_ = from; |
| 2411 | } |
| 2412 | |
| 2413 | void RenderView::didCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
| 2414 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 2415 | // non-null NavigationState. |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 2416 | bool content_initiated = !pending_navigation_state_.get(); |
| 2417 | NavigationState* state = content_initiated ? |
| 2418 | NavigationState::CreateContentInitiated() : |
| 2419 | pending_navigation_state_.release(); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 2420 | if (content_initiated) { |
| 2421 | switch (ds->request().cachePolicy()) { |
| 2422 | case WebURLRequest::UseProtocolCachePolicy: // normal load. |
| 2423 | state->set_load_type(NavigationState::LINK_LOAD_NORMAL); |
| 2424 | break; |
| 2425 | case WebURLRequest::ReloadIgnoringCacheData: // reload. |
| 2426 | state->set_load_type(NavigationState::LINK_LOAD_RELOAD); |
| 2427 | break; |
| 2428 | case WebURLRequest::ReturnCacheDataElseLoad: // allow stale data. |
| 2429 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_STALE_OK); |
| 2430 | break; |
| 2431 | case WebURLRequest::ReturnCacheDataDontLoad: // Don't re-post. |
| 2432 | state->set_load_type(NavigationState::LINK_LOAD_CACHE_ONLY); |
| 2433 | break; |
| 2434 | } |
| 2435 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2436 | |
| 2437 | state->set_user_script_idle_scheduler( |
| 2438 | new UserScriptIdleScheduler(this, frame)); |
| 2439 | ds->setExtraData(state); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | void RenderView::didStartProvisionalLoad(WebFrame* frame) { |
| 2443 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2444 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2445 | |
| 2446 | navigation_state->set_start_load_time(Time::Now()); |
| 2447 | |
| 2448 | // Update the request time if WebKit has better knowledge of it. |
| 2449 | if (navigation_state->request_time().is_null()) { |
| 2450 | double event_time = ds->triggeringEventTime(); |
| 2451 | if (event_time != 0.0) |
| 2452 | navigation_state->set_request_time(Time::FromDoubleT(event_time)); |
| 2453 | } |
| 2454 | |
| 2455 | bool is_top_most = !frame->parent(); |
| 2456 | if (is_top_most) { |
| 2457 | navigation_gesture_ = frame->isProcessingUserGesture() ? |
| 2458 | NavigationGestureUnknown : NavigationGestureAuto; |
| 2459 | |
| 2460 | // Make sure redirect tracking state is clear for the new load. |
| 2461 | completed_client_redirect_src_ = GURL(); |
| 2462 | } else if (frame->parent()->isLoading()) { |
| 2463 | // 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] | 2464 | // load an error page. See didFailProvisionalLoad. |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2465 | navigation_state->set_transition_type(PageTransition::AUTO_SUBFRAME); |
| 2466 | } |
| 2467 | |
| 2468 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
| 2469 | routing_id_, is_top_most, ds->request().url())); |
| 2470 | } |
| 2471 | |
| 2472 | void RenderView::didReceiveServerRedirectForProvisionalLoad(WebFrame* frame) { |
| 2473 | if (frame->parent()) |
| 2474 | return; |
| 2475 | // Received a redirect on the main frame. |
| 2476 | WebDataSource* data_source = frame->provisionalDataSource(); |
| 2477 | if (!data_source) { |
| 2478 | // Should only be invoked when we have a data source. |
| 2479 | NOTREACHED(); |
| 2480 | return; |
| 2481 | } |
| 2482 | std::vector<GURL> redirects; |
| 2483 | GetRedirectChain(data_source, &redirects); |
| 2484 | if (redirects.size() >= 2) { |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2485 | Send(new ViewHostMsg_DidRedirectProvisionalLoad(routing_id_, page_id_, |
| 2486 | redirects[redirects.size() - 2], redirects.back())); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2487 | } |
| 2488 | } |
| 2489 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2490 | void RenderView::didFailProvisionalLoad(WebFrame* frame, |
| 2491 | const WebURLError& error) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2492 | // Notify the browser that we failed a provisional load with an error. |
| 2493 | // |
| 2494 | // Note: It is important this notification occur before DidStopLoading so the |
| 2495 | // SSL manager can react to the provisional load failure before being |
| 2496 | // notified the load stopped. |
| 2497 | // |
| 2498 | WebDataSource* ds = frame->provisionalDataSource(); |
| 2499 | DCHECK(ds); |
| 2500 | |
| 2501 | const WebURLRequest& failed_request = ds->request(); |
| 2502 | |
| 2503 | bool show_repost_interstitial = |
| 2504 | (error.reason == net::ERR_CACHE_MISS && |
| 2505 | EqualsASCII(failed_request.httpMethod(), "POST")); |
| 2506 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
| 2507 | routing_id_, !frame->parent(), error.reason, error.unreachableURL, |
| 2508 | show_repost_interstitial)); |
| 2509 | |
| 2510 | // Don't display an error page if this is simply a cancelled load. Aside |
| 2511 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
| 2512 | if (error.reason == net::ERR_ABORTED) |
| 2513 | return; |
| 2514 | |
| 2515 | // Make sure we never show errors in view source mode. |
| 2516 | frame->enableViewSourceMode(false); |
| 2517 | |
| 2518 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2519 | |
| 2520 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 2521 | // 'replace' load. This is necessary to avoid messing up session history. |
| 2522 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 2523 | // as session history is concerned. |
| 2524 | // |
| 2525 | // AUTO_SUBFRAME loads should always be treated as loads that do not advance |
| 2526 | // the page id. |
| 2527 | // |
| 2528 | bool replace = |
| 2529 | navigation_state->pending_page_id() != -1 || |
| 2530 | navigation_state->transition_type() == PageTransition::AUTO_SUBFRAME; |
| 2531 | |
| 2532 | // If we failed on a browser initiated request, then make sure that our error |
| 2533 | // page load is regarded as the same browser initiated request. |
| 2534 | if (!navigation_state->is_content_initiated()) { |
| 2535 | pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( |
| 2536 | navigation_state->pending_page_id(), |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2537 | navigation_state->pending_history_list_offset(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2538 | navigation_state->transition_type(), |
| 2539 | navigation_state->request_time())); |
| 2540 | } |
| 2541 | |
| 2542 | // Provide the user with a more helpful error page? |
| 2543 | if (MaybeLoadAlternateErrorPage(frame, error, replace)) |
| 2544 | return; |
| 2545 | |
| 2546 | // Fallback to a local error page. |
| 2547 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), |
| 2548 | replace); |
| 2549 | } |
| 2550 | |
| 2551 | void RenderView::didReceiveDocumentData( |
| 2552 | WebFrame* frame, const char* data, size_t data_len, |
| 2553 | bool& prevent_default) { |
| 2554 | NavigationState* navigation_state = |
| 2555 | NavigationState::FromDataSource(frame->dataSource()); |
| 2556 | if (!navigation_state->postpone_loading_data()) |
| 2557 | return; |
| 2558 | |
| 2559 | // We're going to call commitDocumentData ourselves... |
| 2560 | prevent_default = true; |
| 2561 | |
| 2562 | // Continue buffering the response data for the original 404 page. If it |
| 2563 | // grows too large, then we'll just let it through. |
| 2564 | navigation_state->append_postponed_data(data, data_len); |
| 2565 | if (navigation_state->postponed_data().size() >= 512) { |
| 2566 | navigation_state->set_postpone_loading_data(false); |
| 2567 | frame->commitDocumentData(navigation_state->postponed_data().data(), |
| 2568 | navigation_state->postponed_data().size()); |
| 2569 | navigation_state->clear_postponed_data(); |
| 2570 | } |
| 2571 | } |
| 2572 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2573 | void RenderView::didCommitProvisionalLoad(WebFrame* frame, |
| 2574 | bool is_new_navigation) { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2575 | NavigationState* navigation_state = |
| 2576 | NavigationState::FromDataSource(frame->dataSource()); |
| 2577 | |
| 2578 | navigation_state->set_commit_load_time(Time::Now()); |
| 2579 | if (is_new_navigation) { |
| 2580 | // When we perform a new navigation, we need to update the previous session |
| 2581 | // history entry with state for the page we are leaving. |
| 2582 | UpdateSessionHistory(frame); |
| 2583 | |
| 2584 | // We bump our Page ID to correspond with the new session history entry. |
| 2585 | page_id_ = next_page_id_++; |
| 2586 | |
[email protected] | d64b07b | 2010-04-20 22:14:06 | [diff] [blame] | 2587 | // Any pending translation is now obsolete. |
| 2588 | translate_helper_.CancelPendingTranslation(); |
| 2589 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2590 | // Advance our offset in session history, applying the length limit. There |
| 2591 | // is now no forward history. |
| 2592 | history_list_offset_++; |
| 2593 | if (history_list_offset_ >= chrome::kMaxSessionHistoryEntries) |
| 2594 | history_list_offset_ = chrome::kMaxSessionHistoryEntries - 1; |
| 2595 | history_list_length_ = history_list_offset_ + 1; |
| 2596 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 2597 | MessageLoop::current()->PostDelayedTask( |
| 2598 | FROM_HERE, |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2599 | method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, |
| 2600 | page_id_, true), |
| 2601 | kDelayForForcedCaptureMs); |
| 2602 | } else { |
| 2603 | // Inspect the navigation_state on this frame to see if the navigation |
| 2604 | // corresponds to a session history navigation... Note: |frame| may or |
| 2605 | // may not be the toplevel frame, but for the case of capturing session |
| 2606 | // history, the first committed frame suffices. We keep track of whether |
| 2607 | // we've seen this commit before so that only capture session history once |
| 2608 | // per navigation. |
| 2609 | // |
| 2610 | // Note that we need to check if the page ID changed. In the case of a |
| 2611 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 2612 | // previous URL and the current page ID, which would be wrong. |
| 2613 | if (navigation_state->pending_page_id() != -1 && |
| 2614 | navigation_state->pending_page_id() != page_id_ && |
| 2615 | !navigation_state->request_committed()) { |
| 2616 | // This is a successful session history navigation! |
| 2617 | UpdateSessionHistory(frame); |
| 2618 | page_id_ = navigation_state->pending_page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 2619 | |
| 2620 | history_list_offset_ = navigation_state->pending_history_list_offset(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | // Remember that we've already processed this request, so we don't update |
| 2625 | // the session history again. We do this regardless of whether this is |
| 2626 | // a session history navigation, because if we attempted a session history |
| 2627 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 2628 | // new navigation. |
| 2629 | navigation_state->set_request_committed(true); |
| 2630 | |
| 2631 | UpdateURL(frame); |
| 2632 | |
| 2633 | // If this committed load was initiated by a client redirect, we're |
| 2634 | // at the last stop now, so clear it. |
| 2635 | completed_client_redirect_src_ = GURL(); |
| 2636 | |
| 2637 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2638 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2639 | } |
| 2640 | |
| 2641 | void RenderView::didClearWindowObject(WebFrame* frame) { |
| 2642 | if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_)) |
| 2643 | BindDOMAutomationController(frame); |
| 2644 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) { |
| 2645 | dom_ui_bindings_.set_message_sender(this); |
| 2646 | dom_ui_bindings_.set_routing_id(routing_id_); |
| 2647 | dom_ui_bindings_.BindToJavascript(frame, L"chrome"); |
| 2648 | } |
| 2649 | if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) { |
| 2650 | external_host_bindings_.set_message_sender(this); |
| 2651 | external_host_bindings_.set_routing_id(routing_id_); |
| 2652 | external_host_bindings_.BindToJavascript(frame, L"externalHost"); |
| 2653 | } |
| 2654 | } |
| 2655 | |
| 2656 | void RenderView::didCreateDocumentElement(WebFrame* frame) { |
| 2657 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 2658 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 2659 | frame, UserScript::DOCUMENT_START); |
| 2660 | } |
[email protected] | 078b3461 | 2009-09-19 19:31:51 | [diff] [blame] | 2661 | if (view_type_ == ViewType::EXTENSION_TOOLSTRIP || |
| 2662 | view_type_ == ViewType::EXTENSION_MOLE) { |
| 2663 | InjectToolstripCSS(); |
| 2664 | ExtensionProcessBindings::SetViewType(webview(), view_type_); |
| 2665 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2666 | |
| 2667 | // Notify the browser about non-blank documents loading in the top frame. |
| 2668 | GURL url = frame->url(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 2669 | if (url.is_valid() && url.spec() != chrome::kAboutBlankURL) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2670 | if (frame == webview()->mainFrame()) |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2671 | Send(new ViewHostMsg_DocumentAvailableInMainFrame(routing_id_)); |
| 2672 | } |
| 2673 | } |
| 2674 | |
| 2675 | void RenderView::didReceiveTitle(WebFrame* frame, const WebString& title) { |
| 2676 | UpdateTitle(frame, title); |
| 2677 | |
| 2678 | // Also check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2679 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2680 | } |
| 2681 | |
[email protected] | 5019ef1 | 2010-04-27 17:26:58 | [diff] [blame] | 2682 | void RenderView::didChangeIcons(WebFrame* frame) { |
| 2683 | if (!frame->parent()) { |
| 2684 | Send(new ViewHostMsg_UpdateFavIconURL( |
| 2685 | routing_id_, |
| 2686 | page_id_, |
| 2687 | frame->favIconURL())); |
| 2688 | } |
| 2689 | } |
| 2690 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2691 | void RenderView::didFinishDocumentLoad(WebFrame* frame) { |
| 2692 | WebDataSource* ds = frame->dataSource(); |
| 2693 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2694 | DCHECK(navigation_state); |
| 2695 | navigation_state->set_finish_document_load_time(Time::Now()); |
| 2696 | |
| 2697 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_)); |
| 2698 | |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 2699 | // The document has now been fully loaded. Scan for forms to be sent up to |
| 2700 | // the browser. |
| 2701 | // TODO(jhawkins): Make these use the FormManager. |
[email protected] | c8364173 | 2010-02-20 01:04:48 | [diff] [blame] | 2702 | form_manager_.ExtractForms(frame); |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 2703 | SendForms(frame); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 2704 | SendPasswordForms(frame, false); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2705 | |
| 2706 | // Check whether we have new encoding name. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2707 | UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2708 | |
| 2709 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 2710 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 2711 | frame, UserScript::DOCUMENT_END); |
| 2712 | } |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2713 | |
| 2714 | navigation_state->user_script_idle_scheduler()->DidFinishDocumentLoad(); |
| 2715 | } |
| 2716 | |
| 2717 | void RenderView::OnUserScriptIdleTriggered(WebFrame* frame) { |
| 2718 | if (RenderThread::current()) { // Will be NULL during unit tests. |
| 2719 | RenderThread::current()->user_script_slave()->InjectScripts( |
| 2720 | frame, UserScript::DOCUMENT_IDLE); |
| 2721 | } |
| 2722 | |
| 2723 | WebFrame* main_frame = webview()->mainFrame(); |
| 2724 | if (frame == main_frame) { |
| 2725 | while (!pending_code_execution_queue_.empty()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 2726 | linked_ptr<ViewMsg_ExecuteCode_Params>& params = |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2727 | pending_code_execution_queue_.front(); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 2728 | ExecuteCodeImpl(main_frame, *params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2729 | pending_code_execution_queue_.pop(); |
| 2730 | } |
| 2731 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | void RenderView::didHandleOnloadEvents(WebFrame* frame) { |
[email protected] | 7256c504 | 2010-05-01 08:07:50 | [diff] [blame] | 2735 | // Ignore |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | void RenderView::didFailLoad(WebFrame* frame, const WebURLError& error) { |
| 2739 | // Ignore |
| 2740 | } |
| 2741 | |
| 2742 | void RenderView::didFinishLoad(WebFrame* frame) { |
| 2743 | WebDataSource* ds = frame->dataSource(); |
| 2744 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2745 | DCHECK(navigation_state); |
| 2746 | navigation_state->set_finish_load_time(Time::Now()); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 2747 | navigation_state->user_script_idle_scheduler()->DidFinishLoad(); |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 2748 | |
| 2749 | // Let the password manager know which password forms are actually visible. |
| 2750 | SendPasswordForms(frame, true); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2751 | } |
| 2752 | |
[email protected] | ccbe04e | 2010-03-17 17:58:43 | [diff] [blame] | 2753 | void RenderView::didNavigateWithinPage( |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2754 | WebFrame* frame, bool is_new_navigation) { |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 2755 | |
| 2756 | // Determine if the UserScriptIdleScheduler already ran scripts on this page, |
| 2757 | // since a new one gets created by didCreateDataSource. |
| 2758 | NavigationState* state = |
| 2759 | NavigationState::FromDataSource(frame->dataSource()); |
| 2760 | bool idle_scheduler_ran = state->user_script_idle_scheduler()->has_run(); |
| 2761 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2762 | // If this was a reference fragment navigation that we initiated, then we |
| 2763 | // could end up having a non-null pending navigation state. We just need to |
| 2764 | // update the ExtraData on the datasource so that others who read the |
| 2765 | // ExtraData will get the new NavigationState. Similarly, if we did not |
| 2766 | // initiate this navigation, then we need to take care to reset any pre- |
| 2767 | // existing navigation state to a content-initiated navigation state. |
| 2768 | // DidCreateDataSource conveniently takes care of this for us. |
| 2769 | didCreateDataSource(frame, frame->dataSource()); |
| 2770 | |
[email protected] | f6c2459d | 2010-02-24 22:34:06 | [diff] [blame] | 2771 | if (idle_scheduler_ran) { |
| 2772 | // Update the new UserScriptIdleScheduler so we don't re-run scripts. |
| 2773 | NavigationState* new_state = |
| 2774 | NavigationState::FromDataSource(frame->dataSource()); |
| 2775 | new_state->user_script_idle_scheduler()->set_has_run(true); |
| 2776 | } |
| 2777 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2778 | didCommitProvisionalLoad(frame, is_new_navigation); |
| 2779 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 2780 | UpdateTitle(frame, frame->view()->mainFrame()->dataSource()->pageTitle()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2781 | } |
| 2782 | |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 2783 | void RenderView::didUpdateCurrentHistoryItem(WebFrame* frame) { |
[email protected] | 882daa9 | 2009-11-05 16:31:31 | [diff] [blame] | 2784 | StartNavStateSyncTimerIfNecessary(); |
[email protected] | 476b6f8 | 2009-09-10 21:00:59 | [diff] [blame] | 2785 | } |
| 2786 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2787 | void RenderView::assignIdentifierToRequest( |
| 2788 | WebFrame* frame, unsigned identifier, const WebURLRequest& request) { |
| 2789 | // Ignore |
| 2790 | } |
| 2791 | |
| 2792 | void RenderView::willSendRequest( |
| 2793 | WebFrame* frame, unsigned identifier, WebURLRequest& request, |
| 2794 | const WebURLResponse& redirect_response) { |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 2795 | WebFrame* top_frame = frame->top(); |
| 2796 | if (!top_frame) |
| 2797 | top_frame = frame; |
| 2798 | WebDataSource* data_source = top_frame->provisionalDataSource(); |
| 2799 | if (!data_source) |
| 2800 | data_source = top_frame->dataSource(); |
| 2801 | if (data_source) { |
| 2802 | NavigationState* state = NavigationState::FromDataSource(data_source); |
| 2803 | if (state && state->is_cache_policy_override_set()) |
| 2804 | request.setCachePolicy(state->cache_policy_override()); |
| 2805 | } |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2806 | request.setRequestorID(routing_id_); |
[email protected] | c5bbc245 | 2010-03-08 08:33:50 | [diff] [blame] | 2807 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) |
[email protected] | 7deade4 | 2010-03-05 09:33:13 | [diff] [blame] | 2808 | request.clearHTTPHeaderField("Referer"); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 2809 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 2810 | // Temporary metrics, see site_isolation_metrics.h |
| 2811 | SiteIsolationMetrics::AddRequest(identifier, request.targetType()); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | void RenderView::didReceiveResponse( |
| 2815 | WebFrame* frame, unsigned identifier, const WebURLResponse& response) { |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 2816 | |
[email protected] | 85cc78c | 2010-05-04 18:30:09 | [diff] [blame] | 2817 | // Temporary metrics, see site_isolation_metrics.h |
| 2818 | SiteIsolationMetrics::LogMimeTypeForCrossOriginRequest(frame, |
| 2819 | identifier, |
| 2820 | response); |
[email protected] | fa0a343 | 2010-03-30 16:53:49 | [diff] [blame] | 2821 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2822 | // Only do this for responses that correspond to a provisional data source |
| 2823 | // of the top-most frame. If we have a provisional data source, then we |
| 2824 | // can't have any sub-resources yet, so we know that this response must |
| 2825 | // correspond to a frame load. |
| 2826 | if (!frame->provisionalDataSource() || frame->parent()) |
| 2827 | return; |
| 2828 | |
| 2829 | // If we are in view source mode, then just let the user see the source of |
| 2830 | // the server's 404 error page. |
| 2831 | if (frame->isViewSourceModeEnabled()) |
| 2832 | return; |
| 2833 | |
[email protected] | f48013be | 2010-01-14 22:07:45 | [diff] [blame] | 2834 | // Record that this was a page loaded over SPDY. |
| 2835 | if (response.wasFetchedViaSPDY()) { |
| 2836 | NavigationState* navigation_state = |
| 2837 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2838 | navigation_state->set_was_fetched_via_spdy(true); |
| 2839 | } |
| 2840 | |
| 2841 | // Consider loading an alternate error page for 404 responses. |
| 2842 | if (response.httpStatusCode() != 404) |
| 2843 | return; |
| 2844 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2845 | // Can we even load an alternate error page for this URL? |
| 2846 | if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid()) |
| 2847 | return; |
| 2848 | |
| 2849 | NavigationState* navigation_state = |
| 2850 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
| 2851 | navigation_state->set_postpone_loading_data(true); |
| 2852 | navigation_state->clear_postponed_data(); |
| 2853 | } |
| 2854 | |
| 2855 | void RenderView::didFinishResourceLoad( |
| 2856 | WebFrame* frame, unsigned identifier) { |
| 2857 | NavigationState* navigation_state = |
| 2858 | NavigationState::FromDataSource(frame->dataSource()); |
| 2859 | if (!navigation_state->postpone_loading_data()) |
| 2860 | return; |
| 2861 | |
| 2862 | // The server returned a 404 and the content was < 512 bytes (which we |
| 2863 | // suppressed). Go ahead and fetch the alternate page content. |
| 2864 | |
| 2865 | const GURL& frame_url = frame->url(); |
| 2866 | |
| 2867 | const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404); |
| 2868 | DCHECK(error_page_url.is_valid()); |
| 2869 | |
| 2870 | WebURLError original_error; |
| 2871 | original_error.unreachableURL = frame_url; |
| 2872 | |
| 2873 | navigation_state->set_alt_error_page_fetcher( |
| 2874 | new AltErrorPageResourceFetcher( |
| 2875 | error_page_url, frame, original_error, |
| 2876 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 2877 | } |
| 2878 | |
| 2879 | void RenderView::didFailResourceLoad( |
| 2880 | WebFrame* frame, unsigned identifier, const WebURLError& error) { |
| 2881 | // Ignore |
| 2882 | } |
| 2883 | |
| 2884 | void RenderView::didLoadResourceFromMemoryCache( |
| 2885 | WebFrame* frame, const WebURLRequest& request, |
| 2886 | const WebURLResponse& response) { |
| 2887 | // Let the browser know we loaded a resource from the memory cache. This |
| 2888 | // message is needed to display the correct SSL indicators. |
| 2889 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache( |
| 2890 | routing_id_, |
| 2891 | request.url(), |
[email protected] | 91733b6 | 2009-09-18 06:21:09 | [diff] [blame] | 2892 | frame->securityOrigin().toString().utf8(), |
| 2893 | frame->top()->securityOrigin().toString().utf8(), |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2894 | response.securityInfo())); |
| 2895 | } |
| 2896 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 2897 | void RenderView::didDisplayInsecureContent(WebFrame* frame) { |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 2898 | Send(new ViewHostMsg_DidDisplayInsecureContent(routing_id_)); |
| 2899 | } |
| 2900 | |
| 2901 | void RenderView::didRunInsecureContent( |
| 2902 | WebFrame* frame, const WebSecurityOrigin& origin) { |
| 2903 | Send(new ViewHostMsg_DidRunInsecureContent( |
| 2904 | routing_id_, |
| 2905 | origin.toString().utf8())); |
| 2906 | } |
| 2907 | |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 2908 | bool RenderView::allowScript(WebFrame* frame, bool enabled_per_settings) { |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2909 | if (enabled_per_settings && |
| 2910 | AllowContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT)) |
| 2911 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 2912 | |
[email protected] | 12bc847 | 2010-04-15 07:29:40 | [diff] [blame] | 2913 | if (IsWhitelistedForContentSettings(frame)) |
| 2914 | return true; |
[email protected] | 7ea093ba | 2009-11-03 05:54:59 | [diff] [blame] | 2915 | |
| 2916 | return false; // Other protocols fall through here. |
| 2917 | } |
| 2918 | |
[email protected] | 0a1a4543 | 2010-03-31 08:09:45 | [diff] [blame] | 2919 | bool RenderView::allowDatabase( |
| 2920 | WebFrame* frame, const WebString& name, const WebString& display_name, |
| 2921 | unsigned long estimated_size) { |
| 2922 | WebSecurityOrigin origin = frame->securityOrigin(); |
| 2923 | if (origin.isEmpty()) |
| 2924 | return false; // Uninitialized document? |
| 2925 | |
| 2926 | bool result; |
| 2927 | if (!Send(new ViewHostMsg_AllowDatabase(routing_id_, |
| 2928 | origin.toString().utf8(), name, display_name, estimated_size, &result))) |
| 2929 | return false; |
| 2930 | if (!result) |
| 2931 | DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES); |
| 2932 | return result; |
| 2933 | } |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 2934 | void RenderView::didNotAllowScript(WebKit::WebFrame* frame) { |
| 2935 | DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT); |
| 2936 | } |
| 2937 | |
[email protected] | c21f1d5 | 2010-03-04 03:19:43 | [diff] [blame] | 2938 | void RenderView::didNotAllowPlugins(WebKit::WebFrame* frame) { |
| 2939 | DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 2940 | } |
| 2941 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2942 | void RenderView::didExhaustMemoryAvailableForScript(WebFrame* frame) { |
| 2943 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 2944 | } |
| 2945 | |
[email protected] | 0c882b28 | 2009-10-07 17:01:28 | [diff] [blame] | 2946 | void RenderView::didCreateScriptContext(WebFrame* frame) { |
| 2947 | EventBindings::HandleContextCreated(frame, false); |
| 2948 | } |
| 2949 | |
| 2950 | void RenderView::didDestroyScriptContext(WebFrame* frame) { |
| 2951 | EventBindings::HandleContextDestroyed(frame); |
| 2952 | } |
| 2953 | |
| 2954 | void RenderView::didCreateIsolatedScriptContext(WebFrame* frame) { |
| 2955 | EventBindings::HandleContextCreated(frame, true); |
| 2956 | } |
| 2957 | |
[email protected] | fc86daa | 2010-03-30 23:52:53 | [diff] [blame] | 2958 | void RenderView::logCrossFramePropertyAccess(WebFrame* frame, |
| 2959 | WebFrame* target, |
| 2960 | bool cross_origin, |
| 2961 | const WebString& property_name, |
| 2962 | unsigned long long event_id) { |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 2963 | // TODO(johnnyg): track the individual properties and repeat event_ids. |
| 2964 | if (cross_origin) |
| 2965 | cross_origin_access_count_++; |
| 2966 | else |
| 2967 | same_origin_access_count_++; |
| 2968 | } |
| 2969 | |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2970 | void RenderView::didChangeContentsSize(WebFrame* frame, const WebSize& size) { |
[email protected] | d8a179c | 2010-01-31 00:58:14 | [diff] [blame] | 2971 | CheckPreferredSize(); |
| 2972 | } |
| 2973 | |
| 2974 | void RenderView::CheckPreferredSize() { |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2975 | // 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] | 2976 | // be put in that mode by getting a |ViewMsg_EnablePreferredSizeChangedMode| |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2977 | // message. |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame^] | 2978 | if (!send_preferred_size_changes_ || !webview()) |
| 2979 | return; |
[email protected] | dfca5acf | 2010-03-22 03:28:43 | [diff] [blame] | 2980 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame^] | 2981 | // WebCore likes to tell us things have changed even when they haven't, so |
| 2982 | // cache the width and height and only send the IPC message when we're sure |
| 2983 | // they're different. |
| 2984 | gfx::Size size(webview()->mainFrame()->contentsPreferredWidth(), |
| 2985 | webview()->mainFrame()->documentElementScrollHeight()); |
| 2986 | if (size == preferred_size_) |
| 2987 | return; |
[email protected] | c27324b | 2009-11-19 22:44:29 | [diff] [blame] | 2988 | |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame^] | 2989 | preferred_size_ = size; |
| 2990 | Send(new ViewHostMsg_DidContentsPreferredSizeChange(routing_id_, |
| 2991 | preferred_size_)); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 2992 | } |
| 2993 | |
[email protected] | 143dcd59 | 2009-11-06 21:33:49 | [diff] [blame] | 2994 | void RenderView::didChangeScrollOffset(WebFrame* frame) { |
| 2995 | StartNavStateSyncTimerIfNecessary(); |
| 2996 | } |
| 2997 | |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 2998 | void RenderView::reportFindInPageMatchCount(int request_id, int count, |
| 2999 | bool final_update) { |
| 3000 | // If we have a message that has been queued up, then we should just replace |
| 3001 | // it. The ACK from the browser will make sure it gets sent when the browser |
| 3002 | // wants it. |
| 3003 | if (queued_find_reply_message_.get()) { |
| 3004 | IPC::Message* msg = new ViewHostMsg_Find_Reply( |
| 3005 | routing_id_, |
| 3006 | request_id, |
| 3007 | count, |
| 3008 | gfx::Rect(), |
| 3009 | -1, // Don't update active match ordinal. |
| 3010 | final_update); |
| 3011 | queued_find_reply_message_.reset(msg); |
| 3012 | } else { |
| 3013 | // Send the search result over to the browser process. |
| 3014 | Send(new ViewHostMsg_Find_Reply( |
| 3015 | routing_id_, |
| 3016 | request_id, |
| 3017 | count, |
| 3018 | gfx::Rect(), |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame^] | 3019 | -1, // Don't update active match ordinal. |
[email protected] | 8922e1f | 2009-10-03 05:01:26 | [diff] [blame] | 3020 | final_update)); |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | void RenderView::reportFindInPageSelection(int request_id, |
| 3025 | int active_match_ordinal, |
| 3026 | const WebRect& selection_rect) { |
| 3027 | // Send the search result over to the browser process. |
| 3028 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3029 | request_id, |
| 3030 | -1, |
| 3031 | selection_rect, |
| 3032 | active_match_ordinal, |
| 3033 | false)); |
| 3034 | } |
| 3035 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3036 | void RenderView::ReportNoFindInPageResults(int request_id) { |
| 3037 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 3038 | request_id, |
| 3039 | 0, |
| 3040 | gfx::Rect(), |
| 3041 | 0, |
| 3042 | true)); |
| 3043 | } |
| 3044 | |
[email protected] | 79dbc66 | 2009-09-04 05:42:51 | [diff] [blame] | 3045 | // webkit_glue::WebPluginPageDelegate ----------------------------------------- |
| 3046 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3047 | webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate( |
| 3048 | const GURL& url, |
| 3049 | const std::string& mime_type, |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3050 | std::string* actual_mime_type) { |
| 3051 | if (!PluginChannelHost::IsListening()) |
| 3052 | return NULL; |
| 3053 | |
| 3054 | GURL policy_url; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3055 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3056 | if (main_frame) |
| 3057 | policy_url = main_frame->url(); |
| 3058 | |
| 3059 | FilePath path; |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 3060 | render_thread_->Send(new ViewHostMsg_GetPluginPath( |
| 3061 | url, policy_url, mime_type, &path, actual_mime_type)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3062 | if (path.value().empty()) |
| 3063 | return NULL; |
| 3064 | |
| 3065 | const std::string* mime_type_to_use; |
| 3066 | if (!actual_mime_type->empty()) |
| 3067 | mime_type_to_use = actual_mime_type; |
| 3068 | else |
| 3069 | mime_type_to_use = &mime_type; |
| 3070 | |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3071 | bool use_pepper_host = false; |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3072 | bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3073 | // Check for trusted Pepper plugins. |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3074 | const char kPepperPrefix[] = "pepper-"; |
| 3075 | if (StartsWithASCII(*mime_type_to_use, kPepperPrefix, true)) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3076 | if (CommandLine::ForCurrentProcess()-> |
| 3077 | HasSwitch(switches::kInternalPepper)) { |
| 3078 | in_process_plugin = true; |
| 3079 | use_pepper_host = true; |
| 3080 | } else { |
| 3081 | // In process Pepper plugins must be explicitly enabled. |
| 3082 | return NULL; |
| 3083 | } |
[email protected] | d7ce427 | 2010-03-27 01:06:01 | [diff] [blame] | 3084 | } else if (CommandLine::ForCurrentProcess()-> |
| 3085 | HasSwitch(switches::kInternalPDF) && |
| 3086 | StartsWithASCII(*mime_type_to_use, "application/pdf", true)) { |
| 3087 | in_process_plugin = true; |
| 3088 | use_pepper_host = true; |
[email protected] | 26e8d5e | 2009-10-13 02:47:16 | [diff] [blame] | 3089 | } |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3090 | // Check for Native Client modules. |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3091 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) { |
| 3092 | if (mime_type == "application/x-nacl-srpc") { |
| 3093 | in_process_plugin = true; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3094 | use_pepper_host = true; |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 3095 | } |
| 3096 | } |
| 3097 | if (in_process_plugin) { |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3098 | if (use_pepper_host) { |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3099 | WebPluginDelegatePepper* pepper_plugin = |
| 3100 | WebPluginDelegatePepper::Create(path, *mime_type_to_use, |
| 3101 | AsWeakPtr()); |
| 3102 | current_pepper_plugins_.insert(pepper_plugin); |
| 3103 | return pepper_plugin; |
[email protected] | d213966 | 2009-12-10 03:21:14 | [diff] [blame] | 3104 | } else { |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3105 | #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] | 3106 | return WebPluginDelegateImpl::Create( |
| 3107 | path, *mime_type_to_use, gfx::NativeViewFromId(host_window_)); |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3108 | #else |
[email protected] | 596b2c4 | 2010-01-14 20:40:43 | [diff] [blame] | 3109 | NOTIMPLEMENTED(); |
| 3110 | return NULL; |
[email protected] | 7b6616f | 2010-01-14 18:07:55 | [diff] [blame] | 3111 | #endif |
[email protected] | 6876dff | 2010-01-15 19:38:09 | [diff] [blame] | 3112 | } |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3113 | } |
| 3114 | |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 3115 | return new WebPluginDelegateProxy(*mime_type_to_use, AsWeakPtr()); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | void RenderView::CreatedPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3119 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3120 | RenderThread::current()->Send(new ViewHostMsg_CreatePluginContainer( |
| 3121 | routing_id(), window)); |
| 3122 | #endif |
| 3123 | } |
| 3124 | |
| 3125 | void RenderView::WillDestroyPluginWindow(gfx::PluginWindowHandle window) { |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3126 | #if defined(USE_X11) |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3127 | RenderThread::current()->Send(new ViewHostMsg_DestroyPluginContainer( |
| 3128 | routing_id(), window)); |
| 3129 | #endif |
| 3130 | CleanupWindowInPluginMoves(window); |
| 3131 | } |
| 3132 | |
| 3133 | void RenderView::DidMovePlugin(const webkit_glue::WebPluginGeometry& move) { |
| 3134 | SchedulePluginMove(move); |
| 3135 | } |
| 3136 | |
| 3137 | void RenderView::DidStartLoadingForPlugin() { |
| 3138 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3139 | didStartLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | void RenderView::DidStopLoadingForPlugin() { |
| 3143 | // TODO(darin): Make is_loading_ be a counter! |
[email protected] | 48c9cf2d | 2009-09-16 16:47:52 | [diff] [blame] | 3144 | didStopLoading(); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | void RenderView::ShowModalHTMLDialogForPlugin( |
| 3148 | const GURL& url, |
| 3149 | const gfx::Size& size, |
| 3150 | const std::string& json_arguments, |
| 3151 | std::string* json_retval) { |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3152 | SendAndRunNestedMessageLoop(new ViewHostMsg_ShowModalHTMLDialog( |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3153 | routing_id_, url, size.width(), size.height(), json_arguments, |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 3154 | json_retval)); |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3155 | } |
| 3156 | |
[email protected] | b921cfd2 | 2010-02-25 16:57:51 | [diff] [blame] | 3157 | WebCookieJar* RenderView::GetCookieJar() { |
| 3158 | return &cookie_jar_; |
| 3159 | } |
| 3160 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3161 | void RenderView::SyncNavigationState() { |
| 3162 | if (!webview()) |
| 3163 | return; |
| 3164 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3165 | const WebHistoryItem& item = webview()->mainFrame()->currentHistoryItem(); |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3166 | if (item.isNull()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3167 | return; |
[email protected] | ca948a2 | 2009-06-25 19:36:17 | [diff] [blame] | 3168 | |
| 3169 | Send(new ViewHostMsg_UpdateState( |
| 3170 | routing_id_, page_id_, webkit_glue::HistoryItemToString(item))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3171 | } |
| 3172 | |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3173 | bool RenderView::DownloadImage(int id, const GURL& image_url, int image_size) { |
| 3174 | // Make sure webview was not shut down. |
| 3175 | if (!webview()) |
| 3176 | return false; |
| 3177 | // Create an image resource fetcher and assign it with a call back object. |
| 3178 | image_fetchers_.insert(new ImageResourceFetcher( |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3179 | image_url, webview()->mainFrame(), id, image_size, |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3180 | NewCallback(this, &RenderView::DidDownloadImage))); |
| 3181 | return true; |
| 3182 | } |
| 3183 | |
| 3184 | void RenderView::DidDownloadImage(ImageResourceFetcher* fetcher, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3185 | const SkBitmap& image) { |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3186 | // Notify requester of image download status. |
[email protected] | 51bd3661 | 2009-10-20 22:49:47 | [diff] [blame] | 3187 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, |
| 3188 | fetcher->id(), |
| 3189 | fetcher->image_url(), |
| 3190 | image.isNull(), |
| 3191 | image)); |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3192 | // Dispose of the image fetcher. |
| 3193 | DCHECK(image_fetchers_.find(fetcher) != image_fetchers_.end()); |
| 3194 | image_fetchers_.erase(fetcher); |
| 3195 | // We're in the callback from the ImageResourceFetcher, best to delay |
| 3196 | // deletion. |
| 3197 | MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3198 | } |
| 3199 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3200 | void RenderView::OnDownloadFavIcon(int id, |
| 3201 | const GURL& image_url, |
| 3202 | int image_size) { |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3203 | bool data_image_failed = false; |
| 3204 | if (image_url.SchemeIs("data")) { |
| 3205 | SkBitmap data_image = ImageFromDataUrl(image_url); |
| 3206 | data_image_failed = data_image.empty(); |
| 3207 | if (!data_image_failed) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3208 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, false, |
| 3209 | data_image)); |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3213 | if (data_image_failed || |
[email protected] | b0950a7 | 2009-09-29 23:16:17 | [diff] [blame] | 3214 | !DownloadImage(id, image_url, image_size)) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 3215 | Send(new ViewHostMsg_DidDownloadFavIcon(routing_id_, id, image_url, true, |
| 3216 | SkBitmap())); |
| 3217 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3218 | } |
| 3219 | |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 3220 | SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const { |
| 3221 | std::string mime_type, char_set, data; |
| 3222 | if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
| 3223 | // Decode the favicon using WebKit's image decoder. |
| 3224 | webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize)); |
| 3225 | const unsigned char* src_data = |
| 3226 | reinterpret_cast<const unsigned char*>(&data[0]); |
| 3227 | |
| 3228 | return decoder.Decode(src_data, data.size()); |
| 3229 | } |
| 3230 | return SkBitmap(); |
| 3231 | } |
| 3232 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3233 | void RenderView::OnGetApplicationInfo(int page_id) { |
| 3234 | webkit_glue::WebApplicationInfo app_info; |
| 3235 | if (page_id == page_id_) |
| 3236 | webkit_glue::GetApplicationInfo(webview(), &app_info); |
| 3237 | |
| 3238 | // Prune out any data URLs in the set of icons. The browser process expects |
| 3239 | // any icon with a data URL to have originated from a favicon. We don't want |
| 3240 | // to decode arbitrary data URLs in the browser process. See |
| 3241 | // http://b/issue?id=1162972 |
| 3242 | for (size_t i = 0; i < app_info.icons.size(); ++i) { |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 3243 | if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3244 | app_info.icons.erase(app_info.icons.begin() + i); |
| 3245 | --i; |
| 3246 | } |
| 3247 | } |
| 3248 | |
| 3249 | Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info)); |
| 3250 | } |
| 3251 | |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3252 | GURL RenderView::GetAlternateErrorPageURL(const GURL& failed_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3253 | ErrorPageType error_type) { |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3254 | if (failed_url.SchemeIsSecure()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3255 | // If the URL that failed was secure, then the embedding web page was not |
| 3256 | // expecting a network attacker to be able to manipulate its contents. As |
| 3257 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 3258 | // attacker to manipulate the contents of the response if we tried to use |
| 3259 | // the link doctor here. |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3260 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | // Grab the base URL from the browser process. |
| 3264 | if (!alternate_error_page_url_.is_valid()) |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 3265 | return GURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3266 | |
| 3267 | // Strip query params from the failed URL. |
| 3268 | GURL::Replacements remove_params; |
| 3269 | remove_params.ClearUsername(); |
| 3270 | remove_params.ClearPassword(); |
| 3271 | remove_params.ClearQuery(); |
| 3272 | remove_params.ClearRef(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 3273 | const GURL url_to_send = failed_url.ReplaceComponents(remove_params); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3274 | std::string spec_to_send = url_to_send.spec(); |
| 3275 | // Notify link doctor of the url truncation by sending of "?" at the end. |
| 3276 | if (failed_url.has_query()) |
| 3277 | spec_to_send.append("?"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3278 | |
| 3279 | // Construct the query params to send to link doctor. |
| 3280 | std::string params(alternate_error_page_url_.query()); |
| 3281 | params.append("&url="); |
[email protected] | 6fd28f64 | 2010-03-15 17:15:50 | [diff] [blame] | 3282 | params.append(EscapeQueryParamValue(spec_to_send, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3283 | params.append("&sourceid=chrome"); |
| 3284 | params.append("&error="); |
| 3285 | switch (error_type) { |
| 3286 | case DNS_ERROR: |
| 3287 | params.append("dnserror"); |
| 3288 | break; |
| 3289 | |
| 3290 | case HTTP_404: |
| 3291 | params.append("http404"); |
| 3292 | break; |
| 3293 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3294 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 3295 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 3296 | break; |
| 3297 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3298 | default: |
| 3299 | NOTREACHED() << "unknown ErrorPageType"; |
| 3300 | } |
| 3301 | |
| 3302 | // OK, build the final url to return. |
| 3303 | GURL::Replacements link_doctor_params; |
| 3304 | link_doctor_params.SetQueryStr(params); |
| 3305 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 3306 | return url; |
| 3307 | } |
| 3308 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3309 | webkit_glue::WebPluginDelegate* RenderView::GetDelegateForPluginDocument() { |
| 3310 | WebPlugin* plugin = webview()->mainFrame()->document(). |
| 3311 | toElement<WebPluginDocument>().plugin(); |
| 3312 | return static_cast<webkit_glue::WebPluginImpl*>(plugin)->delegate(); |
| 3313 | } |
| 3314 | |
[email protected] | 6069da8c | 2009-10-20 20:33:49 | [diff] [blame] | 3315 | void RenderView::OnFind(int request_id, const string16& search_text, |
| 3316 | const WebFindOptions& options) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3317 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3318 | |
| 3319 | if (main_frame->document().isPluginDocument()) { |
| 3320 | webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument(); |
| 3321 | if (options.findNext) { |
| 3322 | // Just navigate back/forward. |
| 3323 | delegate->SelectFindResult(options.forward); |
| 3324 | } else { |
| 3325 | if (delegate->SupportsFind()) { |
| 3326 | delegate->StartFind(UTF16ToUTF8(search_text), |
| 3327 | options.matchCase, |
| 3328 | request_id); |
| 3329 | } else { |
| 3330 | ReportNoFindInPageResults(request_id); |
| 3331 | } |
| 3332 | } |
| 3333 | return; |
| 3334 | } |
| 3335 | |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3336 | WebFrame* frame_after_main = main_frame->traverseNext(true); |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3337 | WebFrame* focused_frame = webview()->focusedFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3338 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 3339 | |
| 3340 | bool multi_frame = (frame_after_main != main_frame); |
| 3341 | |
| 3342 | // If we have multiple frames, we don't want to wrap the search within the |
| 3343 | // frame, so we check here if we only have main_frame in the chain. |
| 3344 | bool wrap_within_frame = !multi_frame; |
| 3345 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 3346 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3347 | bool result = false; |
| 3348 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3349 | // If something is selected when we start searching it means we cannot just |
| 3350 | // increment the current match ordinal; we need to re-generate it. |
| 3351 | WebRange current_selection = focused_frame->selectionRange(); |
| 3352 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3353 | do { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3354 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3355 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3356 | |
| 3357 | if (!result) { |
| 3358 | // don't leave text selected as you move to the next frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3359 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3360 | |
| 3361 | // Find the next frame, but skip the invisible ones. |
| 3362 | do { |
| 3363 | // What is the next frame to search? (we might be going backwards). Note |
| 3364 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3365 | search_frame = options.forward ? |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3366 | search_frame->traverseNext(true) : |
| 3367 | search_frame->traversePrevious(true); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3368 | } while (!search_frame->hasVisibleContent() && |
| 3369 | search_frame != focused_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3370 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 3371 | // Make sure selection doesn't affect the search operation in new frame. |
[email protected] | a100d76bb | 2009-08-14 17:50:22 | [diff] [blame] | 3372 | search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3373 | |
| 3374 | // If we have multiple frames and we have wrapped back around to the |
| 3375 | // focused frame, we need to search it once more allowing wrap within |
| 3376 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 3377 | // reported matches, but no frames after the focused_frame contain a |
| 3378 | // match for the search word(s). |
| 3379 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3380 | result = search_frame->find( |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3381 | request_id, search_text, options, true, // Force wrapping. |
| 3382 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3383 | } |
| 3384 | } |
| 3385 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3386 | webview()->setFocusedFrame(search_frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3387 | } while (!result && search_frame != focused_frame); |
| 3388 | |
[email protected] | 7830da3e | 2009-11-06 16:27:26 | [diff] [blame] | 3389 | if (options.findNext && current_selection.isNull()) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3390 | // Force the main_frame to report the actual count. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3391 | main_frame->increaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3392 | } else { |
| 3393 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 3394 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 3395 | // yet what is active. |
| 3396 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 3397 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3398 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3399 | // If we find no matches then this will be our last status update. |
| 3400 | // Otherwise the scoping effort will send more results. |
| 3401 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3402 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3403 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 3404 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3405 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 3406 | match_count, |
| 3407 | selection_rect, |
| 3408 | ordinal, |
| 3409 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3410 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3411 | // Scoping effort begins, starting with the mainframe. |
| 3412 | search_frame = main_frame; |
| 3413 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3414 | main_frame->resetMatchCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3415 | |
| 3416 | do { |
| 3417 | // Cancel all old scoping requests before starting a new one. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3418 | search_frame->cancelPendingScopingEffort(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3419 | |
| 3420 | // We don't start another scoping effort unless at least one match has |
| 3421 | // been found. |
| 3422 | if (result) { |
| 3423 | // Start new scoping request. If the scoping function determines that it |
| 3424 | // needs to scope, it will defer until later. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3425 | search_frame->scopeStringMatches(request_id, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3426 | search_text, |
| 3427 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3428 | true); // reset the tickmarks |
| 3429 | } |
| 3430 | |
| 3431 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 3432 | // example if it is not visible. |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 3433 | search_frame = search_frame->traverseNext(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3434 | } while (search_frame != main_frame); |
| 3435 | } |
| 3436 | } |
| 3437 | |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3438 | void RenderView::OnStopFinding(const ViewMsg_StopFinding_Params& params) { |
| 3439 | WebView* view = webview(); |
| 3440 | if (!view) |
| 3441 | return; |
| 3442 | |
| 3443 | WebDocument doc = view->mainFrame()->document(); |
| 3444 | if (doc.isPluginDocument()) { |
| 3445 | GetDelegateForPluginDocument()->StopFind(); |
| 3446 | return; |
| 3447 | } |
| 3448 | |
| 3449 | bool clear_selection = |
| 3450 | params.action == ViewMsg_StopFinding_Params::kClearSelection; |
| 3451 | if (clear_selection) |
| 3452 | view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 3453 | |
| 3454 | WebFrame* frame = view->mainFrame(); |
| 3455 | while (frame) { |
| 3456 | frame->stopFinding(clear_selection); |
| 3457 | frame = frame->traverseNext(false); |
| 3458 | } |
| 3459 | |
| 3460 | if (params.action == ViewMsg_StopFinding_Params::kActivateSelection) { |
| 3461 | WebFrame* focused_frame = view->focusedFrame(); |
| 3462 | if (focused_frame) { |
| 3463 | WebDocument doc = focused_frame->document(); |
| 3464 | if (!doc.isNull()) { |
| 3465 | WebNode node = doc.focusedNode(); |
| 3466 | if (!node.isNull()) |
| 3467 | node.simulateClick(); |
| 3468 | } |
| 3469 | } |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | void RenderView::OnFindReplyAck() { |
| 3474 | // Check if there is any queued up request waiting to be sent. |
| 3475 | if (queued_find_reply_message_.get()) { |
| 3476 | // Send the search result over to the browser process. |
[email protected] | d22d873 | 2010-05-04 19:24:42 | [diff] [blame] | 3477 | Send(queued_find_reply_message_.release()); |
[email protected] | 24a7f3c | 2010-03-25 08:26:49 | [diff] [blame] | 3478 | } |
| 3479 | } |
| 3480 | |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3481 | // static |
| 3482 | std::string RenderView::DetermineTextLanguage(const std::wstring& text) { |
[email protected] | 70082aab | 2010-02-24 01:44:40 | [diff] [blame] | 3483 | // Text with less than 100 bytes will probably not provide good results. |
| 3484 | // Report it as unknown language. |
| 3485 | if (text.length() < 100) |
| 3486 | return kUnknownLanguageCode; |
| 3487 | |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3488 | std::string language = kUnknownLanguageCode; |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3489 | int num_languages = 0; |
| 3490 | bool is_reliable = false; |
[email protected] | 8dc5a205 | 2010-01-19 21:32:42 | [diff] [blame] | 3491 | string16 input = WideToUTF16(text); |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3492 | Language cld_language = |
[email protected] | 8dc5a205 | 2010-01-19 21:32:42 | [diff] [blame] | 3493 | DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable, |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3494 | &num_languages, NULL); |
[email protected] | 70082aab | 2010-02-24 01:44:40 | [diff] [blame] | 3495 | if (is_reliable && cld_language != NUM_LANGUAGES && |
| 3496 | cld_language != UNKNOWN_LANGUAGE && cld_language != TG_UNKNOWN_LANGUAGE) { |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 3497 | // We should not use LanguageCode_ISO_639_1 because it does not cover all |
| 3498 | // the languages CLD can detect. As a result, it'll return the invalid |
[email protected] | 8d022a9 | 2010-02-04 02:49:26 | [diff] [blame] | 3499 | // language code for tradtional Chinese among others. |
| 3500 | // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and |
| 3501 | // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN |
| 3502 | // for Simplified Chinese. |
| 3503 | language = LanguageCodeWithDialects(cld_language); |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3504 | } |
[email protected] | 8c4cdd4 | 2010-01-12 21:31:13 | [diff] [blame] | 3505 | return language; |
[email protected] | 7893a98 | 2010-01-07 23:25:52 | [diff] [blame] | 3506 | } |
| 3507 | |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3508 | bool RenderView::AllowContentType(ContentSettingsType settings_type) { |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 3509 | // CONTENT_SETTING_ASK is only valid for cookies. |
[email protected] | 8934a3b | 2010-02-25 00:34:00 | [diff] [blame] | 3510 | return current_content_settings_.settings[settings_type] != |
| 3511 | CONTENT_SETTING_BLOCK; |
| 3512 | } |
| 3513 | |
| 3514 | void RenderView::DidBlockContentType(ContentSettingsType settings_type) { |
| 3515 | if (!content_blocked_[settings_type]) { |
| 3516 | content_blocked_[settings_type] = true; |
| 3517 | Send(new ViewHostMsg_ContentBlocked(routing_id_, settings_type)); |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 3518 | } |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 3519 | } |
| 3520 | |
[email protected] | 71b0d5d | 2010-02-15 05:43:07 | [diff] [blame] | 3521 | void RenderView::ClearBlockedContentSettings() { |
| 3522 | for (size_t i = 0; i < arraysize(content_blocked_); ++i) |
| 3523 | content_blocked_[i] = false; |
| 3524 | } |
| 3525 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3526 | void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { |
| 3527 | Send(new ViewHostMsg_DnsPrefetch(host_names)); |
| 3528 | } |
| 3529 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3530 | void RenderView::OnZoom(PageZoom::Function function) { |
| 3531 | if (!webview()) // Not sure if this can happen, but no harm in being safe. |
| 3532 | return; |
| 3533 | |
[email protected] | b03794d | 2010-03-26 19:57:52 | [diff] [blame] | 3534 | // Should we be saving zoom levels for plugins? It's not clear, so for now |
| 3535 | // don't. |
| 3536 | if (webview()->mainFrame()->document().isPluginDocument()) { |
| 3537 | webkit_glue::WebPluginDelegate* delegate = GetDelegateForPluginDocument(); |
| 3538 | int zoom; |
| 3539 | if (function == PageZoom::RESET) { |
| 3540 | zoom = 0; |
| 3541 | } else if (function == PageZoom::ZOOM_OUT) { |
| 3542 | zoom = -1; |
| 3543 | } else if (function == PageZoom::ZOOM_IN) { |
| 3544 | zoom = 1; |
| 3545 | } else { |
| 3546 | NOTREACHED(); |
[email protected] | 754bb3b | 2010-03-26 20:12:11 | [diff] [blame] | 3547 | return; |
[email protected] | b03794d | 2010-03-26 19:57:52 | [diff] [blame] | 3548 | } |
| 3549 | delegate->Zoom(zoom); |
| 3550 | return; |
| 3551 | } |
| 3552 | |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3553 | int zoom_level = webview()->zoomLevel(); |
| 3554 | int new_zoom_level = webview()->setZoomLevel(false, |
| 3555 | (function == PageZoom::RESET) ? 0 : (zoom_level + function)); |
| 3556 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3557 | // Tell the browser which url got zoomed so it can update the saved values. |
| 3558 | Send(new ViewHostMsg_DidZoomURL( |
| 3559 | GURL(webview()->mainFrame()->url()), new_zoom_level)); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 3560 | } |
| 3561 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3562 | void RenderView::OnSetContentSettingsForLoadingURL( |
| 3563 | const GURL& url, |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 3564 | const ContentSettings& content_settings) { |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3565 | host_content_settings_[url] = content_settings; |
[email protected] | f85f070 | 2010-01-30 09:31:01 | [diff] [blame] | 3566 | } |
| 3567 | |
[email protected] | 9d797f3 | 2010-04-23 07:17:54 | [diff] [blame] | 3568 | void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url, |
| 3569 | int zoom_level) { |
| 3570 | host_zoom_levels_[url] = zoom_level; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3571 | } |
| 3572 | |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 3573 | void RenderView::OnSetPageEncoding(const std::string& encoding_name) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3574 | webview()->setPageEncoding(WebString::fromUTF8(encoding_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3575 | } |
| 3576 | |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 3577 | void RenderView::OnResetPageEncodingToDefault() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3578 | WebString no_encoding; |
| 3579 | webview()->setPageEncoding(no_encoding); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 3580 | } |
| 3581 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 3582 | bool RenderView::GetAllChildFrames( |
| 3583 | WebFrame* parent_frame, |
| 3584 | std::vector<WebFrame*>* frames_vector) const { |
| 3585 | if (!parent_frame) |
| 3586 | return false; |
| 3587 | for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
| 3588 | child_frame = child_frame->nextSibling()) { |
| 3589 | frames_vector->push_back(child_frame); |
| 3590 | GetAllChildFrames(child_frame, frames_vector); |
| 3591 | } |
| 3592 | return true; |
| 3593 | } |
| 3594 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3595 | WebFrame* RenderView::GetChildFrame(const std::wstring& xpath) const { |
| 3596 | if (xpath.empty()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3597 | return webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3598 | |
| 3599 | // xpath string can represent a frame deep down the tree (across multiple |
| 3600 | // frame DOMs). |
| 3601 | // Example, /html/body/table/tbody/tr/td/iframe\n/frameset/frame[0] |
| 3602 | // should break into 2 xpaths |
| 3603 | // /html/body/table/tbody/tr/td/iframe & /frameset/frame[0] |
| 3604 | |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3605 | WebFrame* frame = webview()->mainFrame(); |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3606 | |
| 3607 | std::wstring xpath_remaining = xpath; |
| 3608 | while (!xpath_remaining.empty()) { |
| 3609 | std::wstring::size_type delim_pos = xpath_remaining.find_first_of(L'\n'); |
| 3610 | std::wstring xpath_child; |
| 3611 | if (delim_pos != std::wstring::npos) { |
| 3612 | xpath_child = xpath_remaining.substr(0, delim_pos); |
| 3613 | xpath_remaining.erase(0, delim_pos + 1); |
| 3614 | } else { |
| 3615 | xpath_remaining.swap(xpath_child); |
| 3616 | } |
| 3617 | frame = frame->findChildByExpression(WideToUTF16Hack(xpath_child)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3618 | } |
| 3619 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3620 | return frame; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3621 | } |
| 3622 | |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 3623 | void RenderView::EvaluateScript(const std::wstring& frame_xpath, |
| 3624 | const std::wstring& script) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3625 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 3626 | if (!web_frame) |
| 3627 | return; |
| 3628 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3629 | web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3630 | } |
| 3631 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3632 | void RenderView::InsertCSS(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 3633 | const std::string& css, |
| 3634 | const std::string& id) { |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3635 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 3636 | if (!web_frame) |
| 3637 | return; |
| 3638 | |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 3639 | web_frame->insertStyleText(WebString::fromUTF8(css), WebString::fromUTF8(id)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3640 | } |
| 3641 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3642 | void RenderView::OnPepperPluginDestroy( |
| 3643 | WebPluginDelegatePepper* pepper_plugin) { |
| 3644 | std::set<WebPluginDelegatePepper*>::iterator found_pepper = |
| 3645 | current_pepper_plugins_.find(pepper_plugin); |
| 3646 | if (found_pepper == current_pepper_plugins_.end()) { |
| 3647 | NOTREACHED(); |
| 3648 | return; |
| 3649 | } |
| 3650 | current_pepper_plugins_.erase(found_pepper); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3651 | |
| 3652 | // The plugin could have been destroyed while it was waiting for a file |
| 3653 | // choose callback, so check all pending completion callbacks and NULL them. |
| 3654 | for (std::deque< linked_ptr<PendingFileChooser> >::iterator i = |
| 3655 | file_chooser_completions_.begin(); |
| 3656 | i != file_chooser_completions_.end(); /* nothing */) { |
| 3657 | if ((*i)->completion == pepper_plugin) { |
| 3658 | // We NULL the first one instead of deleting it because the plugin might |
| 3659 | // be the one waiting for a file choose callback. If the callback later |
| 3660 | // comes, we don't want to send the result to the next callback in line. |
| 3661 | if (i == file_chooser_completions_.begin()) |
| 3662 | (*i)->completion = NULL; |
| 3663 | else |
| 3664 | i = file_chooser_completions_.erase(i); |
| 3665 | } else { |
| 3666 | ++i; |
| 3667 | } |
| 3668 | } |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 3669 | } |
| 3670 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3671 | void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath, |
| 3672 | const std::wstring& jscript) { |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 3673 | EvaluateScript(frame_xpath, jscript); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3674 | } |
| 3675 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3676 | void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, |
[email protected] | ffaef0c | 2009-09-15 17:08:08 | [diff] [blame] | 3677 | const std::string& css, |
| 3678 | const std::string& id) { |
| 3679 | InsertCSS(frame_xpath, css, id); |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 3680 | |
| 3681 | // Notify RenderViewHost that css has been inserted into the frame. |
| 3682 | Send(new ViewHostMsg_OnCSSInserted(routing_id_)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 3683 | } |
| 3684 | |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 3685 | void RenderView::OnAddMessageToConsole( |
| 3686 | const string16& frame_xpath, |
| 3687 | const string16& message, |
| 3688 | const WebConsoleMessage::Level& level) { |
| 3689 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 3690 | if (web_frame) |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3691 | web_frame->addMessageToConsole(WebConsoleMessage(level, message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3692 | } |
| 3693 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 3694 | void RenderView::OnAllowBindings(int enabled_bindings_flags) { |
| 3695 | enabled_bindings_ |= enabled_bindings_flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | void RenderView::OnSetDOMUIProperty(const std::string& name, |
| 3699 | const std::string& value) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 3700 | DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3701 | dom_ui_bindings_.SetProperty(name, value); |
| 3702 | } |
| 3703 | |
| 3704 | void RenderView::OnReservePageIDRange(int size_of_range) { |
| 3705 | next_page_id_ += size_of_range + 1; |
| 3706 | } |
| 3707 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3708 | void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 3709 | const gfx::Point& screen_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3710 | bool ended, |
| 3711 | WebDragOperation op) { |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 3712 | if (ended) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3713 | webview()->dragSourceEndedAt(client_point, screen_point, op); |
[email protected] | 5f9ae6c | 2009-07-08 02:38:03 | [diff] [blame] | 3714 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | void RenderView::OnDragSourceSystemDragEnded() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3718 | webview()->dragSourceSystemDragEnded(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3719 | } |
| 3720 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3721 | void RenderView::OnFillPasswordForm( |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 3722 | const webkit_glue::PasswordFormDomManager::FillData& form_data) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3723 | webkit_glue::FillPasswordForm(this->webview(), form_data); |
| 3724 | } |
| 3725 | |
| 3726 | void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data, |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3727 | const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3728 | const gfx::Point& screen_point, |
| 3729 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3730 | WebDragOperation operation = webview()->dragTargetDragEnter( |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3731 | drop_data.ToDragData(), |
| 3732 | drop_data.identity, |
| 3733 | client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3734 | screen_point, |
| 3735 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3736 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3737 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3738 | } |
| 3739 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3740 | void RenderView::OnDragTargetDragOver(const gfx::Point& client_point, |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3741 | const gfx::Point& screen_point, |
| 3742 | WebDragOperationsMask ops) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3743 | WebDragOperation operation = webview()->dragTargetDragOver( |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3744 | client_point, |
| 3745 | screen_point, |
| 3746 | ops); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3747 | |
[email protected] | 1d9f413 | 2009-09-08 17:29:25 | [diff] [blame] | 3748 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, operation)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | void RenderView::OnDragTargetDragLeave() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3752 | webview()->dragTargetDragLeave(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3753 | } |
| 3754 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 3755 | void RenderView::OnDragTargetDrop(const gfx::Point& client_point, |
| 3756 | const gfx::Point& screen_point) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3757 | webview()->dragTargetDrop(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { |
[email protected] | 2fab253a | 2009-08-17 23:00:59 | [diff] [blame] | 3761 | webkit_preferences_ = prefs; |
| 3762 | webkit_preferences_.Apply(webview()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | void RenderView::OnSetAltErrorPageURL(const GURL& url) { |
| 3766 | alternate_error_page_url_ = url; |
| 3767 | } |
| 3768 | |
[email protected] | a0c7153e | 2009-12-09 14:36:33 | [diff] [blame] | 3769 | void RenderView::OnCustomContextMenuAction(unsigned action) { |
| 3770 | webview()->performCustomContextMenuAction(action); |
| 3771 | } |
| 3772 | |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 3773 | void RenderView::OnTranslatePage(int page_id, |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 3774 | const std::string& translate_script, |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 3775 | const std::string& source_lang, |
| 3776 | const std::string& target_lang) { |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 3777 | translate_helper_.TranslatePage(page_id, source_lang, target_lang, |
| 3778 | translate_script); |
[email protected] | d4a00a7 | 2010-01-29 01:44:42 | [diff] [blame] | 3779 | } |
| 3780 | |
[email protected] | 85d252e | 2010-04-06 22:21:02 | [diff] [blame] | 3781 | void RenderView::OnRevertTranslation(int page_id) { |
| 3782 | translate_helper_.RevertTranslation(page_id); |
[email protected] | 0bedb8a | 2010-01-14 19:36:32 | [diff] [blame] | 3783 | } |
| 3784 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3785 | void RenderView::OnInstallMissingPlugin() { |
| 3786 | // This could happen when the first default plugin is deleted. |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 3787 | if (first_default_plugin_) |
| 3788 | first_default_plugin_->InstallMissingPlugin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3789 | } |
| 3790 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3791 | void RenderView::OnFileChooserResponse(const std::vector<FilePath>& paths) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 3792 | // This could happen if we navigated to a different page before the user |
| 3793 | // closed the chooser. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3794 | if (file_chooser_completions_.empty()) |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 3795 | return; |
| 3796 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3797 | WebVector<WebString> ws_file_names(paths.size()); |
| 3798 | for (size_t i = 0; i < paths.size(); ++i) |
| 3799 | ws_file_names[i] = webkit_glue::FilePathToWebString(paths[i]); |
[email protected] | a112832 | 2009-10-06 18:38:46 | [diff] [blame] | 3800 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 3801 | if (file_chooser_completions_.front()->completion) |
| 3802 | file_chooser_completions_.front()->completion->didChooseFile(ws_file_names); |
| 3803 | file_chooser_completions_.pop_front(); |
| 3804 | |
| 3805 | // If there are more pending file chooser requests, schedule one now. |
| 3806 | if (!file_chooser_completions_.empty()) { |
| 3807 | Send(new ViewHostMsg_RunFileChooser(routing_id_, |
| 3808 | file_chooser_completions_.front()->params)); |
| 3809 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | void RenderView::OnEnableViewSourceMode() { |
| 3813 | if (!webview()) |
| 3814 | return; |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3815 | WebFrame* main_frame = webview()->mainFrame(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3816 | if (!main_frame) |
| 3817 | return; |
| 3818 | |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3819 | main_frame->enableViewSourceMode(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3820 | } |
| 3821 | |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 3822 | void RenderView::OnEnablePreferredSizeChangedMode() { |
[email protected] | 705243f | 2010-05-05 19:58:07 | [diff] [blame^] | 3823 | DCHECK(!send_preferred_size_changes_); |
[email protected] | ab32b16c | 2009-10-16 14:57:25 | [diff] [blame] | 3824 | send_preferred_size_changes_ = true; |
[email protected] | e8014aa5 | 2010-03-03 14:30:06 | [diff] [blame] | 3825 | |
| 3826 | if (ViewType::ShouldAutoResize(view_type_)) |
[email protected] | d8a179c | 2010-01-31 00:58:14 | [diff] [blame] | 3827 | preferred_size_change_timer_.Start(TimeDelta::FromMilliseconds(10), this, |
| 3828 | &RenderView::CheckPreferredSize); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 3829 | } |
| 3830 | |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 3831 | void RenderView::OnDisableScrollbarsForSmallWindows( |
| 3832 | const gfx::Size& disable_scrollbar_size_limit) { |
| 3833 | disable_scrollbars_size_limit_ = disable_scrollbar_size_limit; |
| 3834 | } |
| 3835 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3836 | void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { |
| 3837 | renderer_preferences_ = renderer_prefs; |
[email protected] | 6e282c9 | 2009-07-24 01:19:37 | [diff] [blame] | 3838 | UpdateFontRenderingFromRendererPrefs(); |
[email protected] | 6981f7f | 2010-03-09 00:53:03 | [diff] [blame] | 3839 | #if defined(TOOLKIT_GTK) |
[email protected] | 1c83eb4 | 2009-09-11 21:08:41 | [diff] [blame] | 3840 | WebColorName name = WebKit::WebColorWebkitFocusRingColor; |
| 3841 | WebKit::setNamedColors(&name, &renderer_prefs.focus_ring_color, 1); |
[email protected] | 39cd64ed | 2010-02-05 02:18:46 | [diff] [blame] | 3842 | WebKit::setCaretBlinkInterval(renderer_prefs.caret_blink_interval); |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 3843 | |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3844 | if (webview()) { |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 3845 | webview()->setScrollbarColors( |
| 3846 | renderer_prefs.thumb_inactive_color, |
| 3847 | renderer_prefs.thumb_active_color, |
| 3848 | renderer_prefs.track_color); |
[email protected] | 644d77e | 2010-01-27 01:03:10 | [diff] [blame] | 3849 | webview()->setSelectionColors( |
| 3850 | renderer_prefs.active_selection_bg_color, |
| 3851 | renderer_prefs.active_selection_fg_color, |
| 3852 | renderer_prefs.inactive_selection_bg_color, |
| 3853 | renderer_prefs.inactive_selection_fg_color); |
| 3854 | } |
[email protected] | 7a74e10 | 2009-09-03 00:16:56 | [diff] [blame] | 3855 | #endif |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3856 | } |
| 3857 | |
[email protected] | 952cb70 | 2009-10-07 05:50:28 | [diff] [blame] | 3858 | void RenderView::OnMediaPlayerActionAt(const gfx::Point& location, |
| 3859 | const WebMediaPlayerAction& action) { |
| 3860 | if (webview()) |
| 3861 | webview()->performMediaPlayerAction(action, location); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 3862 | } |
| 3863 | |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 3864 | void RenderView::OnNotifyRendererViewType(ViewType::Type type) { |
[email protected] | 078b3461 | 2009-09-19 19:31:51 | [diff] [blame] | 3865 | // When this is first set, the bindings aren't fully loaded. We only need |
| 3866 | // to call through this API after the page has already been loaded. It's |
| 3867 | // also called in didCreateDocumentElement to bootstrap. |
| 3868 | if (view_type_ != ViewType::INVALID) { |
| 3869 | if (type == ViewType::EXTENSION_MOLE || |
| 3870 | type == ViewType::EXTENSION_TOOLSTRIP) { |
| 3871 | ExtensionProcessBindings::SetViewType(webview(), type); |
| 3872 | } |
| 3873 | } |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 3874 | view_type_ = type; |
| 3875 | } |
| 3876 | |
| 3877 | void RenderView::OnUpdateBrowserWindowId(int window_id) { |
| 3878 | browser_window_id_ = window_id; |
| 3879 | } |
| 3880 | |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 3881 | void RenderView::OnGetAccessibilityInfo( |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 3882 | const webkit_glue::WebAccessibility::InParams& in_params, |
| 3883 | webkit_glue::WebAccessibility::OutParams* out_params) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 3884 | #if defined(OS_WIN) |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 3885 | if (!accessibility_.get()) { |
| 3886 | // TODO(dglazkov): Once implemented for all ports, remove lazy |
| 3887 | // instantiation of accessibility_. |
| 3888 | accessibility_.reset(WebAccessibilityCache::create()); |
| 3889 | accessibility_->initialize(webview()); |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 3890 | } |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 3891 | |
[email protected] | 1745596 | 2010-02-24 01:39:35 | [diff] [blame] | 3892 | out_params->return_code = |
| 3893 | webkit_glue::WebAccessibility::GetAccObjInfo(accessibility_.get(), |
| 3894 | in_params, |
| 3895 | out_params); |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 3896 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 3897 | #else // defined(OS_WIN) |
| 3898 | // TODO(port): accessibility not yet implemented |
| 3899 | NOTIMPLEMENTED(); |
| 3900 | #endif |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 3901 | } |
| 3902 | |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 3903 | void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 3904 | #if defined(OS_WIN) |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 3905 | if (!accessibility_.get()) { |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 3906 | // If accessibility is not activated, ignore clearing message. |
| 3907 | return; |
| 3908 | } |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 3909 | |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 3910 | if (clear_all) { |
| 3911 | accessibility_->clear(); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 3912 | return; |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | accessibility_->remove(acc_obj_id); |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 3916 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 3917 | #else // defined(OS_WIN) |
| 3918 | // TODO(port): accessibility not yet implemented |
| 3919 | NOTIMPLEMENTED(); |
| 3920 | #endif |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 3921 | } |
| 3922 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3923 | void RenderView::OnGetAllSavableResourceLinksForCurrentPage( |
| 3924 | const GURL& page_url) { |
| 3925 | // Prepare list to storage all savable resource links. |
| 3926 | std::vector<GURL> resources_list; |
| 3927 | std::vector<GURL> referrers_list; |
| 3928 | std::vector<GURL> frames_list; |
| 3929 | webkit_glue::SavableResourcesResult result(&resources_list, |
| 3930 | &referrers_list, |
| 3931 | &frames_list); |
| 3932 | |
[email protected] | dbeb395 | 2009-10-13 18:01:18 | [diff] [blame] | 3933 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage( |
| 3934 | webview(), |
| 3935 | page_url, |
| 3936 | &result, |
| 3937 | chrome::kSavableSchemes)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3938 | // If something is wrong when collecting all savable resource links, |
| 3939 | // send empty list to embedder(browser) to tell it failed. |
| 3940 | referrers_list.clear(); |
| 3941 | resources_list.clear(); |
| 3942 | frames_list.clear(); |
| 3943 | } |
| 3944 | |
| 3945 | // Send result of all savable resource links to embedder. |
| 3946 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_, |
| 3947 | resources_list, |
| 3948 | referrers_list, |
| 3949 | frames_list)); |
| 3950 | } |
| 3951 | |
| 3952 | void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | f6b4853 | 2009-02-12 01:56:32 | [diff] [blame] | 3953 | const std::vector<GURL>& links, |
[email protected] | fde6714d1 | 2009-02-18 22:39:31 | [diff] [blame] | 3954 | const std::vector<FilePath>& local_paths, |
| 3955 | const FilePath& local_directory_name) { |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 3956 | |
| 3957 | // Convert std::vector of GURLs to WebVector<WebURL> |
| 3958 | WebVector<WebURL> weburl_links(links); |
| 3959 | |
| 3960 | // Convert std::vector of std::strings to WebVector<WebString> |
| 3961 | WebVector<WebString> webstring_paths(local_paths.size()); |
| 3962 | for (size_t i = 0; i < local_paths.size(); i++) |
| 3963 | webstring_paths[i] = webkit_glue::FilePathToWebString(local_paths[i]); |
| 3964 | |
| 3965 | WebPageSerializer::serialize(webview()->mainFrame(), |
| 3966 | true, this, weburl_links, webstring_paths, |
| 3967 | webkit_glue::FilePathToWebString( |
| 3968 | local_directory_name)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3969 | } |
| 3970 | |
[email protected] | d9ec5c0f | 2009-12-23 11:55:07 | [diff] [blame] | 3971 | void RenderView::didSerializeDataForFrame(const WebURL& frame_url, |
| 3972 | const WebCString& data, |
| 3973 | WebPageSerializerClient::PageSerializationStatus status) { |
| 3974 | Send(new ViewHostMsg_SendSerializedHtmlData( |
| 3975 | routing_id_, |
| 3976 | frame_url, |
| 3977 | data.data(), |
| 3978 | static_cast<int32>(status))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3979 | } |
| 3980 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3981 | void RenderView::OnMsgShouldClose() { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3982 | bool should_close = webview()->dispatchBeforeUnloadEvent(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 3983 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3984 | } |
| 3985 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 3986 | void RenderView::OnClosePage(const ViewMsg_ClosePage_Params& params) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3987 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 3988 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 3989 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 3990 | // calling the FrameLoader's CloseURL method directly. This should be |
| 3991 | // revisited to avoid having two ways to close a page. Having a single way |
| 3992 | // to close that can run onunload is also useful for fixing |
| 3993 | // http://b/issue?id=753080. |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 3994 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 3995 | if (main_frame) { |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 3996 | const GURL& url = main_frame->url(); |
[email protected] | 3d968937 | 2009-09-10 04:29:17 | [diff] [blame] | 3997 | // TODO(davemoore) this code should be removed once willClose() gets |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 3998 | // called when a page is destroyed. DumpLoadHistograms() is safe to call |
| 3999 | // multiple times for the same frame, but it will simplify things. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4000 | if (url.SchemeIs(chrome::kHttpScheme) || |
| 4001 | url.SchemeIs(chrome::kHttpsScheme)) |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4002 | DumpLoadHistograms(); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4003 | } |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4004 | webview()->dispatchUnloadEvent(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4005 | |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 4006 | // Reset stats |
| 4007 | cross_origin_access_count_ = 0; |
| 4008 | same_origin_access_count_ = 0; |
| 4009 | |
[email protected] | eb6b87a | 2009-07-24 15:57:39 | [diff] [blame] | 4010 | // Just echo back the params in the ACK. |
| 4011 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_, params)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | void RenderView::OnThemeChanged() { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4015 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4016 | gfx::NativeTheme::instance()->CloseHandles(); |
| 4017 | gfx::Rect view_rect(0, 0, size_.width(), size_.height()); |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 4018 | didInvalidateRect(view_rect); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 4019 | #else // defined(OS_WIN) |
| 4020 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 4021 | NOTIMPLEMENTED(); |
| 4022 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4023 | } |
| 4024 | |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 4025 | void RenderView::OnMessageFromExternalHost(const std::string& message, |
| 4026 | const std::string& origin, |
| 4027 | const std::string& target) { |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4028 | if (message.empty()) |
| 4029 | return; |
| 4030 | |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 4031 | external_host_bindings_.ForwardMessageFromExternalHost(message, origin, |
| 4032 | target); |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 4033 | } |
| 4034 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 4035 | void RenderView::OnDisassociateFromPopupCount() { |
| 4036 | if (decrement_shared_popup_at_destruction_) |
| 4037 | shared_popup_counter_->data--; |
| 4038 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 4039 | decrement_shared_popup_at_destruction_ = false; |
| 4040 | } |
| 4041 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4042 | bool RenderView::MaybeLoadAlternateErrorPage(WebFrame* frame, |
| 4043 | const WebURLError& error, |
| 4044 | bool replace) { |
| 4045 | // We only show alternate error pages in the main frame. They are |
| 4046 | // intended to assist the user when navigating, so there is not much |
| 4047 | // value in showing them for failed subframes. Ideally, we would be |
| 4048 | // able to use the TYPED transition type for this, but that flag is |
| 4049 | // not preserved across page reloads. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4050 | if (frame->parent()) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4051 | return false; |
| 4052 | |
| 4053 | // Use the alternate error page service if this is a DNS failure or |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4054 | // connection failure. |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4055 | int ec = error.reason; |
| 4056 | if (ec != net::ERR_NAME_NOT_RESOLVED && |
| 4057 | ec != net::ERR_CONNECTION_FAILED && |
| 4058 | ec != net::ERR_CONNECTION_REFUSED && |
| 4059 | ec != net::ERR_ADDRESS_UNREACHABLE && |
[email protected] | c53976d5 | 2009-08-07 18:58:37 | [diff] [blame] | 4060 | ec != net::ERR_CONNECTION_TIMED_OUT) |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4061 | return false; |
| 4062 | |
| 4063 | const GURL& error_page_url = GetAlternateErrorPageURL(error.unreachableURL, |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4064 | ec == net::ERR_NAME_NOT_RESOLVED ? DNS_ERROR : CONNECTION_ERROR); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4065 | if (!error_page_url.is_valid()) |
| 4066 | return false; |
| 4067 | |
| 4068 | // Load an empty page first so there is an immediate response to the error, |
| 4069 | // and then kick off a request for the alternate error page. |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4070 | frame->loadHTMLString(std::string(), |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4071 | GURL(kUnreachableWebDataURL), |
| 4072 | error.unreachableURL, |
| 4073 | replace); |
| 4074 | |
| 4075 | // Now, create a fetcher for the error page and associate it with the data |
| 4076 | // source we just created via the LoadHTMLString call. That way if another |
| 4077 | // navigation occurs, the fetcher will get destroyed. |
| 4078 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4079 | NavigationState::FromDataSource(frame->provisionalDataSource()); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4080 | navigation_state->set_alt_error_page_fetcher( |
| 4081 | new AltErrorPageResourceFetcher( |
| 4082 | error_page_url, frame, error, |
| 4083 | NewCallback(this, &RenderView::AltErrorPageFinished))); |
| 4084 | return true; |
| 4085 | } |
| 4086 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4087 | std::string RenderView::GetAltHTMLForTemplate( |
| 4088 | const DictionaryValue& error_strings, int template_resource_id) const { |
[email protected] | 8a16266e | 2009-09-10 21:08:39 | [diff] [blame] | 4089 | const base::StringPiece template_html( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4090 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 4091 | template_resource_id)); |
| 4092 | |
| 4093 | if (template_html.empty()) { |
| 4094 | NOTREACHED() << "unable to load template. ID: " << template_resource_id; |
| 4095 | return ""; |
| 4096 | } |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4097 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4098 | // "t" is the id of the templates root node. |
[email protected] | 7cd22a5 | 2009-07-14 00:40:25 | [diff] [blame] | 4099 | return jstemplate_builder::GetTemplatesHtml( |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4100 | template_html, &error_strings, "t"); |
| 4101 | } |
[email protected] | 0e79b9e | 2009-02-13 04:20:48 | [diff] [blame] | 4102 | |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4103 | void RenderView::AltErrorPageFinished(WebFrame* frame, |
| 4104 | const WebURLError& original_error, |
| 4105 | const std::string& html) { |
| 4106 | // Here, we replace the blank page we loaded previously. |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4107 | |
| 4108 | // If we failed to download the alternate error page, fall back to the |
| 4109 | // original error page if present. Otherwise, LoadNavigationErrorPage |
| 4110 | // will simply display a default error page. |
| 4111 | const std::string* html_to_load = &html; |
| 4112 | if (html.empty()) { |
| 4113 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4114 | NavigationState::FromDataSource(frame->dataSource()); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 4115 | html_to_load = &navigation_state->postponed_data(); |
| 4116 | } |
| 4117 | LoadNavigationErrorPage( |
| 4118 | frame, WebURLRequest(), original_error, *html_to_load, true); |
[email protected] | 15d79e1 | 2009-08-02 19:23:45 | [diff] [blame] | 4119 | } |
| 4120 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4121 | void RenderView::OnMoveOrResizeStarted() { |
| 4122 | if (webview()) |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4123 | webview()->hidePopups(); |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4124 | } |
| 4125 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4126 | void RenderView::OnResize(const gfx::Size& new_size, |
| 4127 | const gfx::Rect& resizer_rect) { |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4128 | if (webview()) { |
[email protected] | a72a1fa | 2010-05-03 22:18:47 | [diff] [blame] | 4129 | webview()->hidePopups(); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4130 | |
| 4131 | if (send_preferred_size_changes_) { |
| 4132 | // If resizing to a size larger than |disable_scrollbars_size_limit_| in |
| 4133 | // either width or height, allow scroll bars. |
| 4134 | bool allow_scrollbars = ( |
| 4135 | disable_scrollbars_size_limit_.width() <= new_size.width() || |
[email protected] | 45c6e53 | 2010-03-15 23:51:24 | [diff] [blame] | 4136 | disable_scrollbars_size_limit_.height() <= new_size.height()); |
[email protected] | cda45c0 | 2010-02-25 19:28:10 | [diff] [blame] | 4137 | webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars); |
| 4138 | } |
| 4139 | } |
| 4140 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 4141 | RenderWidget::OnResize(new_size, resizer_rect); |
| 4142 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 4143 | |
[email protected] | 00c3961 | 2010-03-06 02:53:28 | [diff] [blame] | 4144 | void RenderView::DidInitiatePaint() { |
| 4145 | // Notify any pepper plugins that we started painting. The plugin "should" |
| 4146 | // never notified that we started painting, this is used for internal |
| 4147 | // bookkeeping only, so we know that the set can not change under us. |
| 4148 | for (std::set<WebPluginDelegatePepper*>::iterator i = |
| 4149 | current_pepper_plugins_.begin(); |
| 4150 | i != current_pepper_plugins_.end(); ++i) |
| 4151 | (*i)->RenderViewInitiatedPaint(); |
| 4152 | } |
| 4153 | |
| 4154 | void RenderView::DidFlushPaint() { |
| 4155 | // Notify any pepper plugins that we painted. This will call into the plugin, |
| 4156 | // and we it may ask to close itself as a result. This will, in turn, modify |
| 4157 | // our set, possibly invalidating the iterator. So we iterate on a copy that |
| 4158 | // won't change out from under us. |
| 4159 | std::set<WebPluginDelegatePepper*> plugins = current_pepper_plugins_; |
| 4160 | for (std::set<WebPluginDelegatePepper*>::iterator i = plugins.begin(); |
| 4161 | i != plugins.end(); ++i) { |
| 4162 | // The copy above makes sure our iterator is never invalid if some plugins |
| 4163 | // are destroyed. But some plugin may decide to close all of its views in |
| 4164 | // response to a paint in one of them, so we need to make sure each one is |
| 4165 | // still "current" before using it. |
| 4166 | if (current_pepper_plugins_.find(*i) != current_pepper_plugins_.end()) |
| 4167 | (*i)->RenderViewFlushedPaint(); |
| 4168 | } |
| 4169 | |
| 4170 | WebFrame* main_frame = webview()->mainFrame(); |
| 4171 | |
| 4172 | // If we have a provisional frame we are between the start and commit stages |
| 4173 | // of loading and we don't want to save stats. |
| 4174 | if (!main_frame->provisionalDataSource()) { |
| 4175 | WebDataSource* ds = main_frame->dataSource(); |
| 4176 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 4177 | DCHECK(navigation_state); |
| 4178 | |
| 4179 | Time now = Time::Now(); |
| 4180 | if (navigation_state->first_paint_time().is_null()) { |
| 4181 | navigation_state->set_first_paint_time(now); |
| 4182 | } |
| 4183 | if (navigation_state->first_paint_after_load_time().is_null() && |
| 4184 | !navigation_state->finish_load_time().is_null()) { |
| 4185 | navigation_state->set_first_paint_after_load_time(now); |
| 4186 | } |
| 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4191 | void RenderView::OnClearFocusedNode() { |
| 4192 | if (webview()) |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4193 | webview()->clearFocusedNode(); |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 4194 | } |
| 4195 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4196 | void RenderView::OnSetBackground(const SkBitmap& background) { |
| 4197 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4198 | webview()->setIsTransparent(!background.empty()); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 4199 | |
| 4200 | SetBackground(background); |
| 4201 | } |
| 4202 | |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4203 | void RenderView::OnSetActive(bool active) { |
| 4204 | if (webview()) |
[email protected] | b4bb250 | 2009-10-01 22:35:27 | [diff] [blame] | 4205 | webview()->setIsActive(active); |
[email protected] | d8fd6fa | 2010-02-01 15:54:26 | [diff] [blame] | 4206 | |
| 4207 | #if defined(OS_MACOSX) |
| 4208 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4209 | for (plugin_it = plugin_delegates_.begin(); |
| 4210 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4211 | (*plugin_it)->SetWindowFocus(active); |
| 4212 | } |
| 4213 | #endif |
[email protected] | 8c66c5a | 2009-07-22 17:26:34 | [diff] [blame] | 4214 | } |
| 4215 | |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4216 | #if defined(OS_MACOSX) |
| 4217 | void RenderView::OnSetWindowVisibility(bool visible) { |
| 4218 | // Inform plugins that their container has changed visibility. |
| 4219 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4220 | for (plugin_it = plugin_delegates_.begin(); |
| 4221 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4222 | (*plugin_it)->SetContainerVisibility(visible); |
| 4223 | } |
| 4224 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4225 | |
| 4226 | void RenderView::OnWindowFrameChanged(gfx::Rect window_frame, |
| 4227 | gfx::Rect view_frame) { |
| 4228 | // Inform plugins that their window's frame has changed. |
| 4229 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4230 | for (plugin_it = plugin_delegates_.begin(); |
| 4231 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4232 | (*plugin_it)->WindowFrameChanged(window_frame, view_frame); |
| 4233 | } |
| 4234 | } |
[email protected] | 6ce7abc5 | 2010-02-02 18:40:14 | [diff] [blame] | 4235 | #endif // OS_MACOSX |
| 4236 | |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4237 | void RenderView::SendExtensionRequest(const std::string& name, |
[email protected] | e4dad9fb | 2009-10-06 18:15:58 | [diff] [blame] | 4238 | const ListValue& args, |
[email protected] | bb64b51 | 2010-04-02 21:01:39 | [diff] [blame] | 4239 | const GURL& source_url, |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 4240 | int request_id, |
[email protected] | 2f25d7b9 | 2009-06-10 00:06:47 | [diff] [blame] | 4241 | bool has_callback) { |
[email protected] | bb64b51 | 2010-04-02 21:01:39 | [diff] [blame] | 4242 | Send(new ViewHostMsg_ExtensionRequest(routing_id_, |
| 4243 | name, |
| 4244 | args, |
| 4245 | source_url, |
| 4246 | request_id, |
[email protected] | 2f25d7b9 | 2009-06-10 00:06:47 | [diff] [blame] | 4247 | has_callback)); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4248 | } |
| 4249 | |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 4250 | void RenderView::OnExtensionResponse(int request_id, |
| 4251 | bool success, |
| 4252 | const std::string& response, |
| 4253 | const std::string& error) { |
[email protected] | 0f605396 | 2009-07-09 19:26:35 | [diff] [blame] | 4254 | ExtensionProcessBindings::HandleResponse( |
| 4255 | request_id, success, response, error); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 4256 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4257 | |
[email protected] | 078b3461 | 2009-09-19 19:31:51 | [diff] [blame] | 4258 | void RenderView::InjectToolstripCSS() { |
| 4259 | if (view_type_ != ViewType::EXTENSION_TOOLSTRIP) |
| 4260 | return; |
| 4261 | |
| 4262 | static const base::StringPiece toolstrip_css( |
| 4263 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 4264 | IDR_EXTENSION_TOOLSTRIP_CSS)); |
| 4265 | std::string css = toolstrip_css.as_string(); |
| 4266 | InsertCSS(L"", css, "ToolstripDefaultCSS"); |
| 4267 | } |
| 4268 | |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 4269 | void RenderView::OnExtensionMessageInvoke(const std::string& function_name, |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4270 | const ListValue& args, |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 4271 | bool requires_incognito_access, |
| 4272 | const GURL& event_url) { |
[email protected] | d725947 | 2010-03-24 08:40:49 | [diff] [blame] | 4273 | RendererExtensionBindings::Invoke( |
[email protected] | a807bbe | 2010-04-14 10:51:19 | [diff] [blame] | 4274 | function_name, args, this, requires_incognito_access, event_url); |
[email protected] | 7120f13 | 2009-07-20 21:05:37 | [diff] [blame] | 4275 | } |
| 4276 | |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4277 | // Dump all load time histograms. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4278 | // |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4279 | // There are 13 histograms measuring various times. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4280 | // The time points we keep are |
| 4281 | // request: time document was requested by user |
| 4282 | // start: time load of document started |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 4283 | // commit: time load of document started |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4284 | // finish_document: main document loaded, before onload() |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4285 | // finish: after onload() and all resources are loaded |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4286 | // first_paint: first paint performed |
| 4287 | // first_paint_after_load: first paint performed after load is finished |
| 4288 | // begin: request if it was user requested, start otherwise |
| 4289 | // |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4290 | // The times that we histogram are |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 4291 | // request->start, |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4292 | // start->commit, |
| 4293 | // commit->finish_document, |
| 4294 | // finish_document->finish, |
| 4295 | // begin->commit, |
| 4296 | // begin->finishDoc, |
| 4297 | // begin->finish, |
| 4298 | // begin->first_paint, |
| 4299 | // begin->first_paint_after_load |
| 4300 | // commit->finishDoc, |
| 4301 | // commit->first_paint, |
| 4302 | // commit->first_paint_after_load, |
| 4303 | // finish->first_paint_after_load, |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4304 | // |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4305 | // It's possible for the request time not to be set, if a client |
| 4306 | // redirect had been done (the user never requested the page) |
| 4307 | // Also, it's possible to load a page without ever laying it out |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4308 | // so first_paint and first_paint_after_load can be 0. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4309 | void RenderView::DumpLoadHistograms() const { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4310 | WebFrame* main_frame = webview()->mainFrame(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4311 | NavigationState* navigation_state = |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4312 | NavigationState::FromDataSource(main_frame->dataSource()); |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4313 | Time finish = navigation_state->finish_load_time(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4314 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4315 | // If we've already dumped, do nothing. |
| 4316 | if (navigation_state->load_histograms_recorded()) |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4317 | return; |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 4318 | |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4319 | // Handle case where user hits "stop" or "back" before loading completely. |
| 4320 | bool abandoned_page = finish.is_null(); |
| 4321 | if (abandoned_page) { |
| 4322 | finish = Time::Now(); |
| 4323 | navigation_state->set_finish_load_time(finish); |
| 4324 | } |
| 4325 | UMA_HISTOGRAM_ENUMERATION("Renderer4.Abandoned", abandoned_page ? 1 : 0, 2); |
| 4326 | |
[email protected] | f899964 | 2009-10-27 21:39:42 | [diff] [blame] | 4327 | LogNavigationState(navigation_state, main_frame->dataSource()); |
| 4328 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4329 | NavigationState::LoadType load_type = navigation_state->load_type(); |
| 4330 | UMA_HISTOGRAM_ENUMERATION("Renderer4.LoadType", load_type, |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4331 | NavigationState::kLoadTypeMax); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4332 | |
[email protected] | ab9eabac | 2010-03-16 16:54:10 | [diff] [blame] | 4333 | // Site isolation metrics. |
| 4334 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithCrossSiteFrameAccess", |
| 4335 | cross_origin_access_count_); |
| 4336 | UMA_HISTOGRAM_COUNTS("SiteIsolation.PageLoadsWithSameSiteFrameAccess", |
| 4337 | same_origin_access_count_); |
| 4338 | |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4339 | Time request = navigation_state->request_time(); |
| 4340 | Time start = navigation_state->start_load_time(); |
| 4341 | Time commit = navigation_state->commit_load_time(); |
| 4342 | Time finish_doc = navigation_state->finish_document_load_time(); |
| 4343 | Time first_paint = navigation_state->first_paint_time(); |
| 4344 | Time first_paint_after_load = |
| 4345 | navigation_state->first_paint_after_load_time(); |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4346 | |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4347 | Time begin; |
| 4348 | // Client side redirects will have no request time. |
| 4349 | if (request.is_null()) { |
| 4350 | begin = start; |
| 4351 | } else { |
| 4352 | begin = request; |
| 4353 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.RequestToStart", start - request); |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 4354 | } |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4355 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.StartToCommit", commit - start); |
| 4356 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4357 | "Renderer4.CommitToFinishDoc", finish_doc - commit); |
| 4358 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4359 | "Renderer4.FinishDocToFinish", finish - finish_doc); |
| 4360 | |
| 4361 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToCommit", commit - begin); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4362 | |
| 4363 | static const TimeDelta kBeginToFinishDocMin(TimeDelta::FromMilliseconds(10)); |
| 4364 | static const TimeDelta kBeginToFinishDocMax(TimeDelta::FromMinutes(10)); |
| 4365 | static const size_t kBeginToFinishDocBucketCount(100); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4366 | TimeDelta begin_to_finish_doc = finish_doc - begin; |
| 4367 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.BeginToFinishDoc", begin_to_finish_doc); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4368 | |
| 4369 | static const TimeDelta kBeginToFinishMin(TimeDelta::FromMilliseconds(10)); |
| 4370 | static const TimeDelta kBeginToFinishMax(TimeDelta::FromMinutes(10)); |
| 4371 | static const size_t kBeginToFinishBucketCount(100); |
| 4372 | TimeDelta begin_to_finish = finish_doc - begin; |
| 4373 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish", begin_to_finish, |
| 4374 | kBeginToFinishMin, kBeginToFinishMax, kBeginToFinishBucketCount); |
| 4375 | |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4376 | switch (load_type) { |
| 4377 | case NavigationState::UNDEFINED_LOAD: |
| 4378 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_UndefLoad", |
| 4379 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4380 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4381 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_UndefLoad", |
| 4382 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4383 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4384 | break; |
| 4385 | case NavigationState::RELOAD: |
| 4386 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_Reload", |
| 4387 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4388 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4389 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_Reload", |
| 4390 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4391 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4392 | break; |
| 4393 | case NavigationState::HISTORY_LOAD: |
| 4394 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_HistoryLoad", |
| 4395 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4396 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4397 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_HistoryLoad", |
| 4398 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4399 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4400 | break; |
| 4401 | case NavigationState::NORMAL_LOAD: |
| 4402 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_NormalLoad", |
| 4403 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4404 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4405 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_NormalLoad", |
| 4406 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4407 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4408 | break; |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4409 | case NavigationState::LINK_LOAD_NORMAL: |
| 4410 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadNormal", |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4411 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4412 | kBeginToFinishDocBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4413 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadNormal", |
| 4414 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4415 | kBeginToFinishBucketCount); |
| 4416 | break; |
| 4417 | case NavigationState::LINK_LOAD_RELOAD: |
| 4418 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadReload", |
| 4419 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4420 | kBeginToFinishDocBucketCount); |
| 4421 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadReload", |
| 4422 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4423 | kBeginToFinishBucketCount); |
| 4424 | break; |
| 4425 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4426 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadStaleOk", |
| 4427 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4428 | kBeginToFinishDocBucketCount); |
| 4429 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadStaleOk", |
| 4430 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4431 | kBeginToFinishBucketCount); |
| 4432 | break; |
| 4433 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 4434 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinishDoc_LinkLoadCacheOnly", |
| 4435 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4436 | kBeginToFinishDocBucketCount); |
| 4437 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.BeginToFinish_LinkLoadCacheOnly", |
| 4438 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4439 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4440 | break; |
| 4441 | default: |
| 4442 | break; |
| 4443 | } |
| 4444 | |
| 4445 | static bool use_dns_histogram(FieldTrialList::Find("DnsImpact") && |
| 4446 | !FieldTrialList::Find("DnsImpact")->group_name().empty()); |
| 4447 | if (use_dns_histogram) { |
[email protected] | f9f4841b | 2010-03-20 05:41:42 | [diff] [blame] | 4448 | UMA_HISTOGRAM_ENUMERATION( |
| 4449 | FieldTrial::MakeName("Renderer4.Abandoned", "DnsImpact"), |
| 4450 | abandoned_page ? 1 : 0, 2); |
| 4451 | UMA_HISTOGRAM_ENUMERATION( |
| 4452 | FieldTrial::MakeName("Renderer4.LoadType", "DnsImpact"), |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4453 | load_type, NavigationState::kLoadTypeMax); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4454 | switch (load_type) { |
| 4455 | case NavigationState::NORMAL_LOAD: |
| 4456 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4457 | "Renderer4.BeginToFinish_NormalLoad", "DnsImpact"), |
| 4458 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4459 | kBeginToFinishBucketCount); |
| 4460 | break; |
| 4461 | case NavigationState::LINK_LOAD_NORMAL: |
| 4462 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4463 | "Renderer4.BeginToFinish_LinkLoadNormal", "DnsImpact"), |
| 4464 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4465 | kBeginToFinishBucketCount); |
| 4466 | break; |
| 4467 | case NavigationState::LINK_LOAD_RELOAD: |
| 4468 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4469 | "Renderer4.BeginToFinish_LinkLoadReload", "DnsImpact"), |
| 4470 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4471 | kBeginToFinishBucketCount); |
| 4472 | break; |
| 4473 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4474 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4475 | "Renderer4.BeginToFinish_LinkLoadStaleOk", "DnsImpact"), |
| 4476 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4477 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4478 | break; |
| 4479 | default: |
| 4480 | break; |
| 4481 | } |
| 4482 | } |
| 4483 | |
| 4484 | static bool use_sdch_histogram(FieldTrialList::Find("GlobalSdch") && |
| 4485 | !FieldTrialList::Find("GlobalSdch")->group_name().empty()); |
| 4486 | if (use_sdch_histogram) { |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4487 | UMA_HISTOGRAM_ENUMERATION( |
| 4488 | FieldTrial::MakeName("Renderer4.LoadType", "GlobalSdch"), |
| 4489 | load_type, NavigationState::kLoadTypeMax); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4490 | switch (load_type) { |
| 4491 | case NavigationState::NORMAL_LOAD: |
| 4492 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4493 | "Renderer4.BeginToFinish_NormalLoad", "GlobalSdch"), |
| 4494 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4495 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4496 | break; |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4497 | case NavigationState::LINK_LOAD_NORMAL: |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4498 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4499 | "Renderer4.BeginToFinish_LinkLoadNormal", "GlobalSdch"), |
| 4500 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4501 | kBeginToFinishBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4502 | break; |
| 4503 | case NavigationState::LINK_LOAD_RELOAD: |
| 4504 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4505 | "Renderer4.BeginToFinish_LinkLoadReload", "GlobalSdch"), |
| 4506 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4507 | kBeginToFinishBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4508 | break; |
| 4509 | case NavigationState::LINK_LOAD_CACHE_STALE_OK: |
| 4510 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4511 | "Renderer4.BeginToFinish_LinkLoadStaleOk", "GlobalSdch"), |
| 4512 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4513 | kBeginToFinishBucketCount); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4514 | break; |
| 4515 | case NavigationState::LINK_LOAD_CACHE_ONLY: |
| 4516 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
[email protected] | fd11f175 | 2010-02-23 22:35:48 | [diff] [blame] | 4517 | "Renderer4.BeginToFinish_LinkLoadCacheOnly", "GlobalSdch"), |
| 4518 | begin_to_finish, kBeginToFinishMin, kBeginToFinishMax, |
| 4519 | kBeginToFinishBucketCount); |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4520 | break; |
| 4521 | default: |
| 4522 | break; |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | static bool use_cache_histogram1(FieldTrialList::Find("CacheSize") && |
| 4527 | !FieldTrialList::Find("CacheSize")->group_name().empty()); |
[email protected] | 4c1b6f0b | 2010-02-07 16:38:18 | [diff] [blame] | 4528 | if (use_cache_histogram1 && NavigationState::LINK_LOAD_NORMAL <= load_type && |
| 4529 | NavigationState::LINK_LOAD_CACHE_ONLY >= load_type) |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4530 | UMA_HISTOGRAM_CUSTOM_TIMES(FieldTrial::MakeName( |
| 4531 | "Renderer4.BeginToFinishDoc_LinkLoad", "CacheSize"), |
| 4532 | begin_to_finish_doc, kBeginToFinishDocMin, kBeginToFinishDocMax, |
| 4533 | kBeginToFinishDocBucketCount); |
[email protected] | e695fbd6 | 2009-06-30 16:31:54 | [diff] [blame] | 4534 | |
[email protected] | 0a32257a | 2009-07-09 18:10:41 | [diff] [blame] | 4535 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.StartToFinish", |
| 4536 | finish - start, kBeginToFinishMin, |
| 4537 | kBeginToFinishMax, kBeginToFinishBucketCount); |
| 4538 | if (!request.is_null()) |
| 4539 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.RequestToFinish", |
| 4540 | finish - request, kBeginToFinishMin, |
| 4541 | kBeginToFinishMax, kBeginToFinishBucketCount); |
[email protected] | e695fbd6 | 2009-06-30 16:31:54 | [diff] [blame] | 4542 | |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4543 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer4.CommitToFinish", finish - commit); |
| 4544 | |
| 4545 | if (!first_paint.is_null()) { |
| 4546 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4547 | "Renderer4.BeginToFirstPaint", first_paint - begin); |
| 4548 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4549 | "Renderer4.CommitToFirstPaint", first_paint - commit); |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4550 | } |
[email protected] | 7a9b51f | 2009-06-29 21:28:29 | [diff] [blame] | 4551 | |
| 4552 | if (!first_paint_after_load.is_null()) { |
| 4553 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4554 | "Renderer4.BeginToFirstPaintAfterLoad", first_paint_after_load - begin); |
| 4555 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4556 | "Renderer4.CommitToFirstPaintAfterLoad", |
| 4557 | first_paint_after_load - commit); |
| 4558 | UMA_HISTOGRAM_MEDIUM_TIMES( |
| 4559 | "Renderer4.FinishToFirstPaintAfterLoad", |
| 4560 | first_paint_after_load - finish); |
| 4561 | } |
| 4562 | |
| 4563 | navigation_state->set_load_histograms_recorded(true); |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 4564 | |
| 4565 | // Since there are currently no guarantees that renderer histograms will be |
| 4566 | // sent to the browser, we initiate a PostTask here to be sure that we send |
| 4567 | // the histograms we generated. Without this call, pages that don't have an |
| 4568 | // on-close-handler might generate data that is lost when the renderer is |
| 4569 | // shutdown abruptly (perchance because the user closed the tab). |
[email protected] | a7ccc4d | 2010-01-27 08:14:48 | [diff] [blame] | 4570 | // TODO(jar) BUG=33233: This needs to be moved to a PostDelayedTask, and it |
| 4571 | // should post when the onload is complete, so that it doesn't interfere with |
| 4572 | // the next load. |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 4573 | if (RenderThread::current()) { |
| 4574 | RenderThread::current()->SendHistograms( |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 4575 | chrome::kHistogramSynchronizerReservedSequenceNumber); |
[email protected] | 1f4fc8e8c | 2010-01-02 00:46:41 | [diff] [blame] | 4576 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 4577 | } |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 4578 | |
[email protected] | f899964 | 2009-10-27 21:39:42 | [diff] [blame] | 4579 | void RenderView::LogNavigationState(const NavigationState* state, |
| 4580 | const WebDataSource* ds) const { |
| 4581 | // Because this function gets called on every page load, |
| 4582 | // take extra care to optimize it away if logging is turned off. |
| 4583 | if (logging::LOG_INFO < logging::GetMinLogLevel()) |
| 4584 | return; |
| 4585 | |
| 4586 | DCHECK(state); |
| 4587 | DCHECK(ds); |
| 4588 | GURL url(ds->request().url()); |
| 4589 | Time start = state->start_load_time(); |
| 4590 | Time finish = state->finish_load_time(); |
| 4591 | // TODO(mbelshe): should we log more stats? |
| 4592 | LOG(INFO) << "PLT: " |
| 4593 | << (finish - start).InMilliseconds() |
| 4594 | << "ms " |
| 4595 | << url.spec(); |
| 4596 | } |
| 4597 | |
[email protected] | cc0445f | 2009-10-13 16:09:08 | [diff] [blame] | 4598 | void RenderView::focusAccessibilityObject( |
| 4599 | const WebAccessibilityObject& acc_obj) { |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 4600 | #if defined(OS_WIN) |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 4601 | // TODO(dglazkov): Current logic implies that focus change can only be made |
| 4602 | // after at least one call to RenderView::OnGetAccessibilityInfo, which is |
| 4603 | // where accessibility is initialized. We should determine whether that's |
| 4604 | // right. |
| 4605 | if (!accessibility_.get()) |
| 4606 | return; |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 4607 | |
| 4608 | // Retrieve the accessibility object id of the AccessibilityObject. |
[email protected] | c7287a9 | 2009-11-04 20:06:15 | [diff] [blame] | 4609 | int acc_obj_id = accessibility_->addOrGetId(acc_obj); |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 4610 | |
| 4611 | // If id is valid, alert the browser side that an accessibility focus change |
| 4612 | // occurred. |
| 4613 | if (acc_obj_id >= 0) |
| 4614 | Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id)); |
| 4615 | |
| 4616 | #else // defined(OS_WIN) |
| 4617 | // TODO(port): accessibility not yet implemented |
| 4618 | NOTIMPLEMENTED(); |
| 4619 | #endif |
| 4620 | } |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4621 | |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 4622 | void RenderView::SendForms(WebFrame* frame) { |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 4623 | // TODO(jhawkins): Use FormManager once we have strict ordering of form |
| 4624 | // control elements in the cache. |
| 4625 | WebVector<WebFormElement> web_forms; |
| 4626 | frame->forms(web_forms); |
| 4627 | |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 4628 | std::vector<FormData> forms; |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 4629 | for (size_t i = 0; i < web_forms.size(); ++i) { |
| 4630 | const WebFormElement& web_form = web_forms[i]; |
| 4631 | |
| 4632 | FormData form; |
| 4633 | FormManager::RequirementsMask requirements = |
[email protected] | b143821 | 2010-04-03 00:30:59 | [diff] [blame] | 4634 | static_cast<FormManager::RequirementsMask>( |
| 4635 | FormManager::REQUIRE_AUTOCOMPLETE | |
| 4636 | FormManager::REQUIRE_ELEMENTS_ENABLED); |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 4637 | if (FormManager::WebFormElementToFormData( |
[email protected] | 3347bab3 | 2010-04-09 04:11:09 | [diff] [blame] | 4638 | web_form, requirements, false, &form)) |
[email protected] | b715f7f | 2010-04-05 22:01:04 | [diff] [blame] | 4639 | forms.push_back(form); |
| 4640 | } |
[email protected] | e6efd02 | 2010-03-31 09:34:50 | [diff] [blame] | 4641 | |
| 4642 | if (!forms.empty()) |
| 4643 | Send(new ViewHostMsg_FormsSeen(routing_id_, forms)); |
[email protected] | e9e0799 | 2010-02-17 21:04:36 | [diff] [blame] | 4644 | } |
| 4645 | |
[email protected] | a3018be | 2010-03-09 04:28:48 | [diff] [blame] | 4646 | void RenderView::didChangeAccessibilityObjectState( |
| 4647 | const WebKit::WebAccessibilityObject& acc_obj) { |
| 4648 | #if defined(OS_WIN) |
| 4649 | // TODO(dglazkov): Current logic implies that a state change can only be made |
| 4650 | // after at least one call to RenderView::OnGetAccessibilityInfo, which is |
| 4651 | // where accessibility is initialized. We should determine whether that's |
| 4652 | // right. |
| 4653 | if (!accessibility_.get()) |
| 4654 | return; |
| 4655 | |
| 4656 | // Retrieve the accessibility object id of the AccessibilityObject. |
| 4657 | int acc_obj_id = accessibility_->addOrGetId(acc_obj); |
| 4658 | |
| 4659 | // If id is valid, alert the browser side that an accessibility object state |
| 4660 | // change occurred. |
| 4661 | if (acc_obj_id >= 0) |
| 4662 | Send(new ViewHostMsg_AccessibilityObjectStateChange(routing_id_, |
| 4663 | acc_obj_id)); |
| 4664 | |
| 4665 | #else // defined(OS_WIN) |
| 4666 | // TODO(port): accessibility not yet implemented |
| 4667 | NOTIMPLEMENTED(); |
| 4668 | #endif |
| 4669 | } |
| 4670 | |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 4671 | void RenderView::SendPasswordForms(WebFrame* frame, bool only_visible) { |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 4672 | WebVector<WebFormElement> forms; |
[email protected] | dd7daa8 | 2009-08-10 05:46:45 | [diff] [blame] | 4673 | frame->forms(forms); |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4674 | |
| 4675 | std::vector<PasswordForm> password_forms; |
| 4676 | for (size_t i = 0; i < forms.size(); ++i) { |
[email protected] | 979c28b | 2009-11-07 01:30:48 | [diff] [blame] | 4677 | const WebFormElement& form = forms[i]; |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4678 | |
| 4679 | // Respect autocomplete=off. |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 4680 | if (!form.autoComplete()) |
| 4681 | continue; |
| 4682 | if (only_visible && !form.hasNonEmptyBoundingBox()) |
| 4683 | continue; |
| 4684 | scoped_ptr<PasswordForm> password_form( |
| 4685 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 4686 | if (password_form.get()) |
| 4687 | password_forms.push_back(*password_form); |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4688 | } |
| 4689 | |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 4690 | if (password_forms.empty()) |
| 4691 | return; |
| 4692 | if (only_visible) |
| 4693 | Send(new ViewHostMsg_PasswordFormsVisible(routing_id_, password_forms)); |
| 4694 | else |
| 4695 | Send(new ViewHostMsg_PasswordFormsFound(routing_id_, password_forms)); |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 4696 | } |
[email protected] | 0fda727 | 2009-06-26 15:49:33 | [diff] [blame] | 4697 | |
| 4698 | void RenderView::Print(WebFrame* frame, bool script_initiated) { |
| 4699 | DCHECK(frame); |
| 4700 | if (print_helper_.get() == NULL) { |
| 4701 | print_helper_.reset(new PrintWebViewHelper(this)); |
| 4702 | } |
| 4703 | print_helper_->Print(frame, script_initiated); |
| 4704 | } |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 4705 | |
| 4706 | void RenderView::OnSetEditCommandsForNextKeyEvent( |
| 4707 | const EditCommands& edit_commands) { |
| 4708 | edit_commands_ = edit_commands; |
| 4709 | } |
| 4710 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4711 | void RenderView::OnExecuteCode(const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | 26aa048 | 2009-09-30 16:55:27 | [diff] [blame] | 4712 | WebFrame* main_frame = webview() ? webview()->mainFrame() : NULL; |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 4713 | if (!main_frame) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4714 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, |
| 4715 | false)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 4716 | return; |
| 4717 | } |
| 4718 | |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 4719 | WebDataSource* ds = main_frame->dataSource(); |
| 4720 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 4721 | if (!navigation_state->user_script_idle_scheduler()->has_run()) { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4722 | pending_code_execution_queue_.push( |
| 4723 | linked_ptr<ViewMsg_ExecuteCode_Params>( |
| 4724 | new ViewMsg_ExecuteCode_Params(params))); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 4725 | return; |
| 4726 | } |
| 4727 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4728 | ExecuteCodeImpl(main_frame, params); |
[email protected] | fa7b6b54 | 2009-11-03 05:02:30 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | void RenderView::ExecuteCodeImpl(WebFrame* frame, |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4732 | const ViewMsg_ExecuteCode_Params& params) { |
[email protected] | d146b83 | 2009-12-23 02:45:48 | [diff] [blame] | 4733 | // Don't execute scripts in gallery pages. |
| 4734 | GURL frame_url = GURL(frame->url()); |
| 4735 | if (frame_url.host() == GURL(extension_urls::kGalleryBrowsePrefix).host()) { |
| 4736 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); |
| 4737 | return; |
| 4738 | } |
| 4739 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4740 | std::vector<WebFrame*> frame_vector; |
| 4741 | frame_vector.push_back(frame); |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4742 | if (params.all_frames) |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4743 | GetAllChildFrames(frame, &frame_vector); |
| 4744 | |
| 4745 | for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin(); |
| 4746 | frame_it != frame_vector.end(); ++frame_it) { |
| 4747 | WebFrame* frame = *frame_it; |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4748 | if (params.is_javascript) { |
| 4749 | if (!UrlMatchesPermissions(frame->url(), params.host_permissions)) |
| 4750 | continue; |
| 4751 | |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4752 | std::vector<WebScriptSource> sources; |
| 4753 | sources.push_back( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4754 | WebScriptSource(WebString::fromUTF8(params.code))); |
| 4755 | UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4756 | frame->executeScriptInIsolatedWorld( |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4757 | UserScriptSlave::GetIsolatedWorldId(params.extension_id), |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4758 | &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); |
| 4759 | } else { |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4760 | frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 4761 | } |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 4762 | } |
| 4763 | |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 4764 | Send(new ViewMsg_ExecuteCodeFinished(routing_id_, params.request_id, true)); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 4765 | } |
| 4766 | |
[email protected] | 60c42a8c7 | 2009-10-09 04:08:59 | [diff] [blame] | 4767 | void RenderView::Close() { |
| 4768 | // We need to grab a pointer to the doomed WebView before we destroy it. |
| 4769 | WebView* doomed = webview(); |
| 4770 | RenderWidget::Close(); |
| 4771 | Singleton<ViewMap>::get()->erase(doomed); |
| 4772 | } |
| 4773 | |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 4774 | void RenderView::DidHandleKeyEvent() { |
| 4775 | edit_commands_.clear(); |
| 4776 | } |
| 4777 | |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4778 | #if defined(OS_MACOSX) |
| 4779 | void RenderView::OnWasHidden() { |
| 4780 | RenderWidget::OnWasHidden(); |
| 4781 | |
| 4782 | // Inform plugins that their container is no longer visible. |
| 4783 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4784 | for (plugin_it = plugin_delegates_.begin(); |
| 4785 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4786 | (*plugin_it)->SetContainerVisibility(false); |
| 4787 | } |
| 4788 | } |
| 4789 | |
| 4790 | void RenderView::OnWasRestored(bool needs_repainting) { |
| 4791 | RenderWidget::OnWasRestored(needs_repainting); |
| 4792 | |
| 4793 | // Inform plugins that their container is now visible. |
| 4794 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4795 | for (plugin_it = plugin_delegates_.begin(); |
| 4796 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4797 | (*plugin_it)->SetContainerVisibility(true); |
| 4798 | } |
| 4799 | } |
[email protected] | 1e6e3c99 | 2010-02-08 15:52:13 | [diff] [blame] | 4800 | |
| 4801 | void RenderView::OnSetFocus(bool enable) { |
| 4802 | RenderWidget::OnSetFocus(enable); |
| 4803 | |
| 4804 | // RenderWidget's call to setFocus can cause the underlying webview's |
| 4805 | // activation state to change just like a call to setIsActive. |
| 4806 | if (enable && webview() && webview()->isActive()) { |
| 4807 | std::set<WebPluginDelegateProxy*>::iterator plugin_it; |
| 4808 | for (plugin_it = plugin_delegates_.begin(); |
| 4809 | plugin_it != plugin_delegates_.end(); ++plugin_it) { |
| 4810 | (*plugin_it)->SetWindowFocus(true); |
| 4811 | } |
| 4812 | } |
| 4813 | } |
[email protected] | 941e455 | 2010-02-01 21:23:43 | [diff] [blame] | 4814 | #endif // OS_MACOSX |
| 4815 | |
[email protected] | 83dde54 | 2009-09-11 20:59:55 | [diff] [blame] | 4816 | void RenderView::EnsureDocumentTag() { |
| 4817 | // TODO(darin): There's actually no reason for this to be here. We should |
| 4818 | // have the browser side manage the document tag. |
| 4819 | #if defined(OS_MACOSX) |
| 4820 | if (!has_document_tag_) { |
| 4821 | // Make the call to get the tag. |
| 4822 | Send(new ViewHostMsg_GetDocumentTag(routing_id_, &document_tag_)); |
| 4823 | has_document_tag_ = true; |
| 4824 | } |
| 4825 | #endif |
| 4826 | } |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 4827 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4828 | #if defined(OS_MACOSX) |
[email protected] | ea04a4e1 | 2010-04-15 00:58:03 | [diff] [blame] | 4829 | gfx::PluginWindowHandle RenderView::AllocateFakePluginWindowHandle( |
| 4830 | bool opaque) { |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4831 | gfx::PluginWindowHandle window = NULL; |
| 4832 | Send(new ViewHostMsg_AllocateFakePluginWindowHandle( |
[email protected] | ea04a4e1 | 2010-04-15 00:58:03 | [diff] [blame] | 4833 | routing_id(), opaque, &window)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4834 | return window; |
| 4835 | } |
| 4836 | |
| 4837 | void RenderView::DestroyFakePluginWindowHandle(gfx::PluginWindowHandle window) { |
| 4838 | if (window) |
| 4839 | Send(new ViewHostMsg_DestroyFakePluginWindowHandle(routing_id(), window)); |
| 4840 | } |
| 4841 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4842 | void RenderView::AcceleratedSurfaceSetIOSurface(gfx::PluginWindowHandle window, |
| 4843 | int32 width, |
| 4844 | int32 height, |
| 4845 | uint64 io_surface_identifier) { |
| 4846 | Send(new ViewHostMsg_AcceleratedSurfaceSetIOSurface( |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4847 | routing_id(), window, width, height, io_surface_identifier)); |
| 4848 | } |
| 4849 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4850 | void RenderView::AcceleratedSurfaceSetTransportDIB( |
| 4851 | gfx::PluginWindowHandle window, |
| 4852 | int32 width, |
| 4853 | int32 height, |
| 4854 | TransportDIB::Handle transport_dib) { |
| 4855 | Send(new ViewHostMsg_AcceleratedSurfaceSetTransportDIB( |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4856 | routing_id(), window, width, height, transport_dib)); |
| 4857 | } |
| 4858 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4859 | TransportDIB::Handle RenderView::AcceleratedSurfaceAllocTransportDIB( |
| 4860 | size_t size) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4861 | TransportDIB::Handle dib_handle; |
| 4862 | // Assume this is a synchronous RPC. |
[email protected] | ada848b1 | 2010-04-08 22:35:38 | [diff] [blame] | 4863 | if (Send(new ViewHostMsg_AllocTransportDIB(size, true, &dib_handle))) |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4864 | return dib_handle; |
| 4865 | // Return an invalid handle if Send() fails. |
| 4866 | return TransportDIB::DefaultHandleValue(); |
| 4867 | } |
| 4868 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4869 | void RenderView::AcceleratedSurfaceFreeTransportDIB(TransportDIB::Id dib_id) { |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 4870 | Send(new ViewHostMsg_FreeTransportDIB(dib_id)); |
| 4871 | } |
| 4872 | |
[email protected] | 44ce0b1 | 2010-03-12 16:45:33 | [diff] [blame] | 4873 | void RenderView::AcceleratedSurfaceBuffersSwapped( |
| 4874 | gfx::PluginWindowHandle window) { |
| 4875 | Send(new ViewHostMsg_AcceleratedSurfaceBuffersSwapped(routing_id(), window)); |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 4876 | } |
| 4877 | #endif |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 4878 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 4879 | bool RenderView::ScheduleFileChooser( |
| 4880 | const ViewHostMsg_RunFileChooser_Params& params, |
| 4881 | WebFileChooserCompletion* completion) { |
| 4882 | static const size_t kMaximumPendingFileChooseRequests = 4; |
| 4883 | if (file_chooser_completions_.size() > kMaximumPendingFileChooseRequests) { |
| 4884 | // This sanity check prevents too many file choose requests from getting |
| 4885 | // queued which could DoS the user. Getting these is most likely a |
| 4886 | // programming error (there are many ways to DoS the user so it's not |
| 4887 | // considered a "real" security check), either in JS requesting many file |
| 4888 | // choosers to pop up, or in a plugin. |
| 4889 | // |
| 4890 | // TODO(brettw) we might possibly want to require a user gesture to open |
| 4891 | // a file picker, which will address this issue in a better way. |
| 4892 | return false; |
| 4893 | } |
| 4894 | |
| 4895 | file_chooser_completions_.push_back(linked_ptr<PendingFileChooser>( |
| 4896 | new PendingFileChooser(params, completion))); |
| 4897 | if (file_chooser_completions_.size() == 1) { |
| 4898 | // Actually show the browse dialog when this is the first request. |
| 4899 | Send(new ViewHostMsg_RunFileChooser(routing_id_, params)); |
| 4900 | } |
| 4901 | return true; |
| 4902 | } |
| 4903 | |
[email protected] | 290838a | 2010-04-27 17:37:01 | [diff] [blame] | 4904 | void RenderView::OnPageTranslated() { |
| 4905 | WebFrame* frame = webview()->mainFrame(); |
| 4906 | if (!frame) |
| 4907 | return; |
| 4908 | |
| 4909 | // The page is translated, so try to extract the form data again. |
| 4910 | form_manager_.ExtractForms(frame); |
| 4911 | SendForms(frame); |
| 4912 | } |
| 4913 | |
[email protected] | 8a5f700 | 2010-03-31 13:47:35 | [diff] [blame] | 4914 | WebKit::WebGeolocationService* RenderView::geolocationService() { |
[email protected] | 58c321d | 2010-02-19 12:11:28 | [diff] [blame] | 4915 | if (!geolocation_dispatcher_.get()) |
| 4916 | geolocation_dispatcher_.reset(new GeolocationDispatcher(this)); |
| 4917 | return geolocation_dispatcher_.get(); |
| 4918 | } |
[email protected] | 61c9f03 | 2010-03-31 23:04:19 | [diff] [blame] | 4919 | |
| 4920 | bool RenderView::ShouldRouteNavigationToBrowser( |
| 4921 | const GURL& url, WebKit::WebFrame* frame, WebKit::WebNavigationType type) { |
| 4922 | // If the browser is interested, then give it a chance to look at top level |
| 4923 | // navigations |
| 4924 | if (!renderer_preferences_.browser_handles_top_level_requests) |
| 4925 | return false; |
| 4926 | |
| 4927 | // Must be a top level frame. |
| 4928 | if (frame->parent() != NULL) |
| 4929 | return false; |
| 4930 | |
| 4931 | // Skip if navigation is on the same page (using '#'). |
| 4932 | GURL frame_origin = GURL(frame->url()).GetOrigin(); |
| 4933 | if (url.GetOrigin() != frame_origin || url.ref().empty()) { |
| 4934 | // The link click could stay on the same page, in cases where it sends some |
| 4935 | // parameters to the same URL. |
| 4936 | if (type == WebKit::WebNavigationTypeLinkClicked) |
| 4937 | return true; |
| 4938 | |
| 4939 | if (last_top_level_navigation_page_id_ != page_id_ && |
| 4940 | // Not interested in reloads. |
| 4941 | type != WebKit::WebNavigationTypeReload && |
| 4942 | type != WebKit::WebNavigationTypeFormSubmitted) { |
| 4943 | return true; |
| 4944 | } |
| 4945 | } |
| 4946 | return false; |
| 4947 | } |