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