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