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