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