[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/renderer/render_view.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | 91e81ae | 2009-05-08 22:14:38 | [diff] [blame] | 11 | #include "app/gfx/color_utils.h" |
[email protected] | 3712621 | 2009-05-06 02:23:31 | [diff] [blame] | 12 | #include "app/gfx/favicon_size.h" |
[email protected] | a92b864 | 2009-05-05 23:38:56 | [diff] [blame] | 13 | #include "app/l10n_util.h" |
[email protected] | 3712621 | 2009-05-06 02:23:31 | [diff] [blame] | 14 | #include "app/message_box_flags.h" |
[email protected] | 9929da9 | 2009-05-05 02:05:11 | [diff] [blame] | 15 | #include "app/resource_bundle.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "base/command_line.h" |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 18 | #include "base/field_trial.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | #include "base/gfx/png_encoder.h" |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 20 | #include "base/gfx/native_widget_types.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame^] | 21 | #include "base/process_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | #include "base/string_piece.h" |
| 23 | #include "base/string_util.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 24 | #include "build/build_config.h" |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 25 | #include "chrome/common/bindings_policy.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 26 | #include "chrome/common/chrome_switches.h" |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 27 | #include "chrome/common/chrome_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 28 | #include "chrome/common/jstemplate_builder.h" |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 29 | #include "chrome/common/page_zoom.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 30 | #include "chrome/common/render_messages.h" |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 31 | #include "chrome/common/renderer_preferences.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | #include "chrome/common/thumbnail_score.h" |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 33 | #include "chrome/common/url_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | #include "chrome/renderer/about_handler.h" |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 35 | #include "chrome/renderer/audio_message_filter.h" |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 36 | #include "chrome/renderer/devtools_agent.h" |
| 37 | #include "chrome/renderer/devtools_client.h" |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 38 | #include "chrome/renderer/extensions/extension_process_bindings.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | #include "chrome/renderer/localized_error.h" |
[email protected] | 6f56d48 | 2009-02-20 05:02:56 | [diff] [blame] | 40 | #include "chrome/renderer/media/audio_renderer_impl.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 41 | #include "chrome/renderer/media/buffered_data_source.h" |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 42 | #include "chrome/renderer/navigation_state.h" |
[email protected] | d81c1e5 | 2009-06-03 22:09:50 | [diff] [blame] | 43 | #include "chrome/renderer/print_web_view_helper.h" |
[email protected] | 39008c0 | 2009-02-11 23:59:25 | [diff] [blame] | 44 | #include "chrome/renderer/render_process.h" |
[email protected] | fcf1954 | 2009-03-30 21:24:07 | [diff] [blame] | 45 | #include "chrome/renderer/renderer_logging.h" |
[email protected] | 0938d3c | 2009-01-09 20:37:35 | [diff] [blame] | 46 | #include "chrome/renderer/user_script_slave.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 47 | #include "chrome/renderer/visitedlink_slave.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 48 | #include "chrome/renderer/webplugin_delegate_proxy.h" |
[email protected] | eb47a13 | 2009-03-04 00:39:56 | [diff] [blame] | 49 | #include "chrome/renderer/webworker_proxy.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 50 | #include "grit/generated_resources.h" |
| 51 | #include "grit/renderer_resources.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 52 | #include "net/base/data_url.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 53 | #include "net/base/escape.h" |
| 54 | #include "net/base/net_errors.h" |
[email protected] | c399a8a | 2008-11-22 19:38:00 | [diff] [blame] | 55 | #include "skia/ext/bitmap_platform_device.h" |
[email protected] | 83c9e655 | 2008-12-03 16:22:10 | [diff] [blame] | 56 | #include "skia/ext/image_operations.h" |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 57 | #include "webkit/api/public/WebDataSource.h" |
[email protected] | afdcf5c | 2009-05-10 20:30:41 | [diff] [blame] | 58 | #include "webkit/api/public/WebDragData.h" |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 59 | #include "webkit/api/public/WebForm.h" |
[email protected] | afdcf5c | 2009-05-10 20:30:41 | [diff] [blame] | 60 | #include "webkit/api/public/WebPoint.h" |
| 61 | #include "webkit/api/public/WebRect.h" |
| 62 | #include "webkit/api/public/WebScriptSource.h" |
| 63 | #include "webkit/api/public/WebSize.h" |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 64 | #include "webkit/api/public/WebURL.h" |
| 65 | #include "webkit/api/public/WebURLError.h" |
| 66 | #include "webkit/api/public/WebURLRequest.h" |
| 67 | #include "webkit/api/public/WebURLResponse.h" |
| 68 | #include "webkit/api/public/WebVector.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 69 | #include "webkit/default_plugin/default_plugin_shared.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 70 | #include "webkit/glue/dom_operations.h" |
| 71 | #include "webkit/glue/dom_serializer.h" |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 72 | #include "webkit/glue/image_decoder.h" |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame^] | 73 | #include "webkit/glue/media/simple_data_source.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 74 | #include "webkit/glue/password_form.h" |
[email protected] | ba4b17f | 2009-02-11 21:32:29 | [diff] [blame] | 75 | #include "webkit/glue/plugins/plugin_list.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 76 | #include "webkit/glue/searchable_form_data.h" |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 77 | #include "webkit/glue/webaccessibilitymanager_impl.h" |
[email protected] | 611cad4 | 2009-03-16 18:51:34 | [diff] [blame] | 78 | #include "webkit/glue/webdevtoolsagent_delegate.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 79 | #include "webkit/glue/webdropdata.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 80 | #include "webkit/glue/webframe.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 81 | #include "webkit/glue/webkit_glue.h" |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 82 | #include "webkit/glue/webmediaplayer_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 83 | #include "webkit/glue/webpreferences.h" |
[email protected] | b94d332 | 2009-02-12 19:49:04 | [diff] [blame] | 84 | #include "webkit/glue/webplugin_delegate.h" |
[email protected] | 00d7e62 | 2009-04-21 23:06:05 | [diff] [blame] | 85 | #include "webkit/glue/webtextinput.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 86 | #include "webkit/glue/webview.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 87 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 88 | #if defined(OS_WIN) |
| 89 | // TODO(port): these files are currently Windows only because they concern: |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 90 | // * theming |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 91 | #include "base/gfx/native_theme.h" |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 92 | #endif |
| 93 | |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 94 | using base::Time; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 95 | using base::TimeDelta; |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 96 | using webkit_glue::AutofillForm; |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 97 | using webkit_glue::PasswordForm; |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 98 | using webkit_glue::PasswordFormDomManager; |
| 99 | using webkit_glue::SearchableFormData; |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 100 | using WebKit::WebConsoleMessage; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 101 | using WebKit::WebDataSource; |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 102 | using WebKit::WebDragData; |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 103 | using WebKit::WebForm; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 104 | using WebKit::WebNavigationType; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 105 | using WebKit::WebRect; |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 106 | using WebKit::WebScriptSource; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 107 | using WebKit::WebString; |
| 108 | using WebKit::WebURL; |
| 109 | using WebKit::WebURLError; |
| 110 | using WebKit::WebURLRequest; |
| 111 | using WebKit::WebURLResponse; |
[email protected] | 27ba853 | 2009-04-24 20:22:43 | [diff] [blame] | 112 | using WebKit::WebWorker; |
| 113 | using WebKit::WebWorkerClient; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 114 | using WebKit::WebVector; |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 115 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 116 | //----------------------------------------------------------------------------- |
| 117 | |
| 118 | // define to write the time necessary for thumbnail/DOM text retrieval, |
| 119 | // respectively, into the system debug log |
| 120 | // #define TIME_BITMAP_RETRIEVAL |
| 121 | // #define TIME_TEXT_RETRIEVAL |
| 122 | |
| 123 | // maximum number of characters in the document to index, any text beyond this |
| 124 | // point will be clipped |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 125 | static const size_t kMaxIndexChars = 65535; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | |
| 127 | // Size of the thumbnails that we'll generate |
| 128 | static const int kThumbnailWidth = 196; |
| 129 | static const int kThumbnailHeight = 136; |
| 130 | |
| 131 | // Delay in milliseconds that we'll wait before capturing the page contents |
| 132 | // and thumbnail. |
| 133 | static const int kDelayForCaptureMs = 500; |
| 134 | |
| 135 | // Typically, we capture the page data once the page is loaded. |
| 136 | // Sometimes, the page never finishes to load, preventing the page capture |
| 137 | // To workaround this problem, we always perform a capture after the following |
| 138 | // delay. |
| 139 | static const int kDelayForForcedCaptureMs = 6000; |
| 140 | |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 141 | // The default value for RenderView.delay_seconds_for_form_state_sync_, see |
| 142 | // that variable for more. |
| 143 | const int kDefaultDelaySecondsForFormStateSync = 5; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 144 | |
| 145 | // The next available page ID to use. This ensures that the page IDs are |
| 146 | // globally unique in the renderer. |
| 147 | static int32 next_page_id_ = 1; |
| 148 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 149 | // The maximum number of popups that can be spawned from one page. |
| 150 | static const int kMaximumNumberOfUnacknowledgedPopups = 25; |
| 151 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 152 | static const char* const kUnreachableWebDataURL = |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 153 | "chrome://chromewebdata/"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 154 | |
[email protected] | 50b691c | 2008-10-31 19:08:35 | [diff] [blame] | 155 | static const char* const kBackForwardNavigationScheme = "history"; |
| 156 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 157 | static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) { |
| 158 | WebVector<WebURL> urls; |
| 159 | ds->redirectChain(urls); |
| 160 | result->reserve(urls.size()); |
| 161 | for (size_t i = 0; i < urls.size(); ++i) |
| 162 | result->push_back(urls[i]); |
| 163 | } |
| 164 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 165 | /////////////////////////////////////////////////////////////////////////////// |
| 166 | |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 167 | RenderView::RenderView(RenderThreadBase* render_thread) |
| 168 | : RenderWidget(render_thread, true), |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 169 | enabled_bindings_(0), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 170 | target_url_status_(TARGET_NONE), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 171 | is_loading_(false), |
[email protected] | e75cb49e | 2009-01-05 23:13:21 | [diff] [blame] | 172 | navigation_gesture_(NavigationGestureUnknown), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 173 | page_id_(-1), |
| 174 | last_page_id_sent_to_browser_(-1), |
| 175 | last_indexed_page_id_(-1), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 176 | opened_by_user_gesture_(true), |
[email protected] | bb063b7 | 2009-03-27 23:18:50 | [diff] [blame] | 177 | ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 178 | first_default_plugin_(NULL), |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 179 | devtools_agent_(NULL), |
| 180 | devtools_client_(NULL), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 181 | history_back_list_count_(0), |
| 182 | history_forward_list_count_(0), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 183 | has_unload_listener_(false), |
| 184 | decrement_shared_popup_at_destruction_(false), |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 185 | form_field_autofill_request_id_(0), |
| 186 | popup_notification_visible_(false), |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 187 | delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync), |
| 188 | preferred_width_(0), |
[email protected] | 9b6f40e | 2009-06-11 15:54:26 | [diff] [blame] | 189 | send_preferred_width_changes_(false) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | RenderView::~RenderView() { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 193 | if (decrement_shared_popup_at_destruction_) |
| 194 | shared_popup_counter_->data--; |
| 195 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 196 | // Clear any back-pointers that might still be held by plugins. |
| 197 | PluginDelegateList::iterator it = plugin_delegates_.begin(); |
| 198 | while (it != plugin_delegates_.end()) { |
| 199 | (*it)->DropRenderView(); |
| 200 | it = plugin_delegates_.erase(it); |
| 201 | } |
| 202 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 203 | render_thread_->RemoveFilter(audio_message_filter_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /*static*/ |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 207 | RenderView* RenderView::Create( |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 208 | RenderThreadBase* render_thread, |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 209 | gfx::NativeViewId parent_hwnd, |
[email protected] | 1c4947f | 2009-01-15 22:25:11 | [diff] [blame] | 210 | base::WaitableEvent* modal_dialog_event, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 211 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 212 | const RendererPreferences& renderer_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 213 | const WebPreferences& webkit_prefs, |
| 214 | SharedRenderViewCounter* counter, |
| 215 | int32 routing_id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 216 | DCHECK(routing_id != MSG_ROUTING_NONE); |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 217 | scoped_refptr<RenderView> view = new RenderView(render_thread); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 218 | view->Init(parent_hwnd, |
| 219 | modal_dialog_event, |
| 220 | opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 221 | renderer_prefs, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 222 | webkit_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 223 | counter, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 224 | routing_id); // adds reference |
| 225 | return view; |
| 226 | } |
| 227 | |
| 228 | /*static*/ |
| 229 | void RenderView::SetNextPageID(int32 next_page_id) { |
| 230 | // This method should only be called during process startup, and the given |
| 231 | // page id had better not exceed our current next page id! |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 232 | DCHECK_EQ(next_page_id_, 1); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 233 | DCHECK(next_page_id >= next_page_id_); |
| 234 | next_page_id_ = next_page_id; |
| 235 | } |
| 236 | |
| 237 | void RenderView::PluginDestroyed(WebPluginDelegateProxy* proxy) { |
| 238 | PluginDelegateList::iterator it = |
| 239 | std::find(plugin_delegates_.begin(), plugin_delegates_.end(), proxy); |
| 240 | DCHECK(it != plugin_delegates_.end()); |
| 241 | plugin_delegates_.erase(it); |
| 242 | // If the plugin is deleted, we need to clear our reference in case user |
| 243 | // clicks the info bar to install. Unfortunately we are getting |
| 244 | // PluginDestroyed in single process mode. However, that is not a huge |
| 245 | // concern. |
| 246 | if (proxy == first_default_plugin_) |
| 247 | first_default_plugin_ = NULL; |
| 248 | } |
| 249 | |
[email protected] | 690a99c | 2009-01-06 16:48:45 | [diff] [blame] | 250 | void RenderView::PluginCrashed(const FilePath& plugin_path) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 251 | Send(new ViewHostMsg_CrashedPlugin(routing_id_, plugin_path)); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | void RenderView::JSOutOfMemory() { |
| 256 | Send(new ViewHostMsg_JSOutOfMemory(routing_id_)); |
| 257 | } |
| 258 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 259 | void RenderView::Init(gfx::NativeViewId parent_hwnd, |
[email protected] | 1c4947f | 2009-01-15 22:25:11 | [diff] [blame] | 260 | base::WaitableEvent* modal_dialog_event, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 261 | int32 opener_id, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 262 | const RendererPreferences& renderer_prefs, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 263 | const WebPreferences& webkit_prefs, |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 264 | SharedRenderViewCounter* counter, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | int32 routing_id) { |
| 266 | DCHECK(!webview()); |
| 267 | |
| 268 | if (opener_id != MSG_ROUTING_NONE) |
| 269 | opener_id_ = opener_id; |
| 270 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 271 | if (counter) { |
| 272 | shared_popup_counter_ = counter; |
| 273 | shared_popup_counter_->data++; |
| 274 | decrement_shared_popup_at_destruction_ = true; |
| 275 | } else { |
| 276 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 277 | decrement_shared_popup_at_destruction_ = false; |
| 278 | } |
| 279 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 280 | OnSetRendererPrefs(renderer_prefs); |
| 281 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 282 | devtools_agent_.reset(new DevToolsAgent(routing_id, this)); |
[email protected] | 9b9d728 | 2009-04-08 14:13:04 | [diff] [blame] | 283 | |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 284 | webwidget_ = WebView::Create(this, webkit_prefs); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 285 | |
[email protected] | 2e417c8 | 2009-04-02 22:30:26 | [diff] [blame] | 286 | #if defined(OS_LINUX) |
| 287 | // We have to enable ourselves as the editor delegate on linux so we can copy |
| 288 | // text selections to the X clipboard. |
| 289 | webview()->SetUseEditorDelegate(true); |
| 290 | #endif |
| 291 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 292 | // Don't let WebCore keep a B/F list - we have our own. |
| 293 | // We let it keep 1 entry because FrameLoader::goToItem expects an item in the |
| 294 | // backForwardList, which is used only in ASSERTs. |
| 295 | webview()->SetBackForwardListSize(1); |
| 296 | |
| 297 | routing_id_ = routing_id; |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 298 | render_thread_->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 299 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 300 | // when we receive ViewMsg_Close. |
| 301 | AddRef(); |
| 302 | |
| 303 | // If this is a popup, we must wait for the CreatingNew_ACK message before |
| 304 | // completing initialization. Otherwise, we can finish it now. |
| 305 | if (opener_id == MSG_ROUTING_NONE) { |
| 306 | did_show_ = true; |
| 307 | CompleteInit(parent_hwnd); |
| 308 | } |
| 309 | |
| 310 | host_window_ = parent_hwnd; |
[email protected] | 1c4947f | 2009-01-15 22:25:11 | [diff] [blame] | 311 | modal_dialog_event_.reset(modal_dialog_event); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 312 | |
[email protected] | 58bfc6b | 2009-06-24 09:45:02 | [diff] [blame] | 313 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 314 | if (command_line.HasSwitch(switches::kDomAutomationController)) |
| 315 | enabled_bindings_ |= BindingsPolicy::DOM_AUTOMATION; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 316 | |
[email protected] | 5fb8896 | 2009-04-16 19:03:25 | [diff] [blame] | 317 | audio_message_filter_ = new AudioMessageFilter(routing_id_); |
| 318 | render_thread_->AddFilter(audio_message_filter_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | void RenderView::OnMessageReceived(const IPC::Message& message) { |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 322 | WebFrame* main_frame = webview() ? webview()->GetMainFrame() : NULL; |
| 323 | renderer_logging::ScopedActiveRenderingURLSetter url_setter( |
| 324 | main_frame ? main_frame->GetURL() : GURL()); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 325 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 326 | // If this is developer tools renderer intercept tools messages first. |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 327 | if (devtools_client_.get() && devtools_client_->OnMessageReceived(message)) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 328 | return; |
[email protected] | b4b967e | 2009-04-22 11:33:05 | [diff] [blame] | 329 | if (devtools_agent_.get() && devtools_agent_->OnMessageReceived(message)) |
| 330 | return; |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 331 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 332 | IPC_BEGIN_MESSAGE_MAP(RenderView, message) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 333 | IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, SendThumbnail) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 334 | IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 335 | IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 336 | IPC_MESSAGE_HANDLER(ViewMsg_Navigate, OnNavigate) |
| 337 | IPC_MESSAGE_HANDLER(ViewMsg_Stop, OnStop) |
| 338 | IPC_MESSAGE_HANDLER(ViewMsg_LoadAlternateHTMLText, OnLoadAlternateHTMLText) |
| 339 | IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) |
| 340 | IPC_MESSAGE_HANDLER(ViewMsg_Undo, OnUndo) |
| 341 | IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) |
| 342 | IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) |
| 343 | IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) |
| 344 | IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) |
| 345 | IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 346 | IPC_MESSAGE_HANDLER(ViewMsg_ToggleSpellCheck, OnToggleSpellCheck) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 347 | IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) |
| 348 | IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) |
| 349 | IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 350 | IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 351 | IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 352 | IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
[email protected] | ea8c745 | 2009-04-02 20:47:06 | [diff] [blame] | 353 | IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 354 | IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 355 | IPC_MESSAGE_HANDLER(ViewMsg_SetupDevToolsClient, OnSetupDevToolsClient) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 356 | IPC_MESSAGE_HANDLER(ViewMsg_DownloadImage, OnDownloadImage) |
| 357 | IPC_MESSAGE_HANDLER(ViewMsg_ScriptEvalRequest, OnScriptEvalRequest) |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 358 | IPC_MESSAGE_HANDLER(ViewMsg_CSSInsertRequest, OnCSSInsertRequest) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 359 | IPC_MESSAGE_HANDLER(ViewMsg_AddMessageToConsole, OnAddMessageToConsole) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 360 | IPC_MESSAGE_HANDLER(ViewMsg_ReservePageIDRange, OnReservePageIDRange) |
| 361 | IPC_MESSAGE_HANDLER(ViewMsg_UploadFile, OnUploadFileRequest) |
| 362 | IPC_MESSAGE_HANDLER(ViewMsg_FormFill, OnFormFill) |
| 363 | IPC_MESSAGE_HANDLER(ViewMsg_FillPasswordForm, OnFillPasswordForm) |
| 364 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragEnter, OnDragTargetDragEnter) |
| 365 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) |
| 366 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) |
| 367 | IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 368 | IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 369 | IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 370 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved, |
| 371 | OnDragSourceEndedOrMoved) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 372 | IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, |
| 373 | OnDragSourceSystemDragEnded) |
| 374 | IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
| 375 | IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) |
| 376 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 377 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 378 | IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) |
| 379 | IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) |
| 380 | IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) |
| 381 | IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) |
| 382 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateBackForwardListCount, |
| 383 | OnUpdateBackForwardListCount) |
| 384 | IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, |
| 385 | OnGetAllSavableResourceLinksForCurrentPage) |
[email protected] | f09c718 | 2009-03-10 12:54:04 | [diff] [blame] | 386 | IPC_MESSAGE_HANDLER( |
| 387 | ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks, |
| 388 | OnGetSerializedHtmlDataForCurrentPageWithLocalLinks) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 389 | IPC_MESSAGE_HANDLER(ViewMsg_GetApplicationInfo, OnGetApplicationInfo) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 390 | IPC_MESSAGE_HANDLER(ViewMsg_GetAccessibilityInfo, OnGetAccessibilityInfo) |
| 391 | IPC_MESSAGE_HANDLER(ViewMsg_ClearAccessibilityInfo, |
| 392 | OnClearAccessibilityInfo) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 393 | IPC_MESSAGE_HANDLER(ViewMsg_ShouldClose, OnMsgShouldClose) |
| 394 | IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| 395 | IPC_MESSAGE_HANDLER(ViewMsg_ThemeChanged, OnThemeChanged) |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 396 | IPC_MESSAGE_HANDLER(ViewMsg_HandleMessageFromExternalHost, |
| 397 | OnMessageFromExternalHost) |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 398 | IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount, |
| 399 | OnDisassociateFromPopupCount) |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 400 | IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions, |
| 401 | OnReceivedAutofillSuggestions) |
[email protected] | 2c4410d | 2009-05-06 23:46:22 | [diff] [blame] | 402 | IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged, |
| 403 | OnPopupNotificationVisibilityChanged) |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 404 | IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted) |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 405 | IPC_MESSAGE_HANDLER(ViewMsg_ExtensionResponse, OnExtensionResponse) |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 406 | IPC_MESSAGE_HANDLER(ViewMsg_ClearFocusedNode, OnClearFocusedNode) |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 407 | IPC_MESSAGE_HANDLER(ViewMsg_SetBackground, OnSetBackground) |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 408 | IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode, |
| 409 | OnEnableIntrinsicWidthChangedMode) |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 410 | IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs) |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 411 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 412 | // Have the super handle all other messages. |
| 413 | IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message)) |
| 414 | IPC_END_MESSAGE_MAP() |
| 415 | } |
| 416 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 417 | void RenderView::SendThumbnail() { |
| 418 | WebFrame* main_frame = webview()->GetMainFrame(); |
| 419 | if (!main_frame) |
| 420 | return; |
| 421 | |
| 422 | // get the URL for this page |
| 423 | GURL url(main_frame->GetURL()); |
| 424 | if (url.is_empty()) |
| 425 | return; |
| 426 | |
| 427 | if (size_.IsEmpty()) |
| 428 | return; // Don't create an empty thumbnail! |
| 429 | |
| 430 | ThumbnailScore score; |
| 431 | SkBitmap thumbnail; |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 432 | if (!CaptureThumbnail(main_frame, kThumbnailWidth, kThumbnailHeight, |
| 433 | &thumbnail, &score)) |
| 434 | return; |
| 435 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 436 | // send the thumbnail message to the browser process |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 437 | Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 438 | } |
| 439 | |
[email protected] | 06863722 | 2009-01-29 16:58:07 | [diff] [blame] | 440 | void RenderView::OnPrintPages() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 441 | DCHECK(webview()); |
[email protected] | 06863722 | 2009-01-29 16:58:07 | [diff] [blame] | 442 | if (webview()) { |
| 443 | // The renderer own the control flow as if it was a window.print() call. |
| 444 | ScriptedPrint(webview()->GetMainFrame()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 445 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 446 | } |
| 447 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 448 | void RenderView::OnPrintingDone(int document_cookie, bool success) { |
| 449 | // Ignoring document cookie here since only one print job can be outstanding |
| 450 | // per renderer and document_cookie is 0 when printing is successful. |
| 451 | DCHECK(print_helper_.get()); |
| 452 | if (print_helper_.get() != NULL) { |
| 453 | print_helper_->DidFinishPrinting(success); |
| 454 | } |
| 455 | } |
| 456 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 457 | void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { |
| 458 | if (load_id != page_id_) |
| 459 | return; // this capture call is no longer relevant due to navigation |
| 460 | if (load_id == last_indexed_page_id_) |
| 461 | return; // we already indexed this page |
| 462 | |
| 463 | if (!webview()) |
| 464 | return; |
| 465 | |
| 466 | WebFrame* main_frame = webview()->GetMainFrame(); |
| 467 | if (!main_frame) |
| 468 | return; |
| 469 | |
| 470 | // Don't index/capture pages that are in view source mode. |
| 471 | if (main_frame->GetInViewSourceMode()) |
| 472 | return; |
| 473 | |
| 474 | // Don't index/capture pages that failed to load. This only checks the top |
| 475 | // level frame so the thumbnail may contain a frame that failed to load. |
| 476 | WebDataSource* ds = main_frame->GetDataSource(); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 477 | if (ds && ds->hasUnreachableURL()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 478 | return; |
| 479 | |
| 480 | if (!preliminary_capture) |
| 481 | last_indexed_page_id_ = load_id; |
| 482 | |
| 483 | // get the URL for this page |
| 484 | GURL url(main_frame->GetURL()); |
| 485 | if (url.is_empty()) |
| 486 | return; |
| 487 | |
| 488 | // full text |
| 489 | std::wstring contents; |
| 490 | CaptureText(main_frame, &contents); |
| 491 | if (contents.size()) { |
| 492 | // Send the text to the browser for indexing. |
| 493 | Send(new ViewHostMsg_PageContents(url, load_id, contents)); |
| 494 | } |
| 495 | |
| 496 | // thumbnail |
| 497 | SendThumbnail(); |
| 498 | } |
| 499 | |
| 500 | void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) { |
| 501 | contents->clear(); |
| 502 | if (!frame) |
| 503 | return; |
| 504 | |
[email protected] | 0faf0bd9 | 2008-09-09 20:53:27 | [diff] [blame] | 505 | // Don't index any https pages. People generally don't want their bank |
| 506 | // accounts, etc. indexed on their computer, especially since some of these |
| 507 | // things are not marked cachable. |
| 508 | // TODO(brettw) we may want to consider more elaborate heuristics such as |
| 509 | // the cachability of the page. We may also want to consider subframes (this |
| 510 | // test will still index subframes if the subframe is SSL). |
| 511 | if (frame->GetURL().SchemeIsSecure()) |
| 512 | return; |
| 513 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 514 | #ifdef TIME_TEXT_RETRIEVAL |
| 515 | double begin = time_util::GetHighResolutionTimeNow(); |
| 516 | #endif |
| 517 | |
| 518 | // get the contents of the frame |
| 519 | frame->GetContentAsPlainText(kMaxIndexChars, contents); |
| 520 | |
| 521 | #ifdef TIME_TEXT_RETRIEVAL |
| 522 | double end = time_util::GetHighResolutionTimeNow(); |
| 523 | char buf[128]; |
| 524 | sprintf_s(buf, "%d chars retrieved for indexing in %gms\n", |
| 525 | contents.size(), (end - begin)*1000); |
| 526 | OutputDebugStringA(buf); |
| 527 | #endif |
| 528 | |
| 529 | // When the contents are clipped to the maximum, we don't want to have a |
| 530 | // partial word indexed at the end that might have been clipped. Therefore, |
| 531 | // terminate the string at the last space to ensure no words are clipped. |
| 532 | if (contents->size() == kMaxIndexChars) { |
| 533 | size_t last_space_index = contents->find_last_of(kWhitespaceWide); |
| 534 | if (last_space_index == std::wstring::npos) |
| 535 | return; // don't index if we got a huge block of text with no spaces |
| 536 | contents->resize(last_space_index); |
| 537 | } |
| 538 | } |
| 539 | |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 540 | bool RenderView::CaptureThumbnail(WebFrame* frame, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 541 | int w, |
| 542 | int h, |
| 543 | SkBitmap* thumbnail, |
| 544 | ThumbnailScore* score) { |
| 545 | #ifdef TIME_BITMAP_RETRIEVAL |
| 546 | double begin = time_util::GetHighResolutionTimeNow(); |
| 547 | #endif |
| 548 | |
[email protected] | 21f527e | 2008-12-17 23:29:40 | [diff] [blame] | 549 | scoped_ptr<skia::BitmapPlatformDevice> device; |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 550 | if (!frame->CaptureImage(&device, true)) |
| 551 | return false; |
| 552 | |
| 553 | const SkBitmap& src_bmp = device->accessBitmap(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 554 | |
| 555 | SkRect dest_rect; |
| 556 | dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h)); |
| 557 | float dest_aspect = dest_rect.width() / dest_rect.height(); |
| 558 | |
| 559 | // Get the src rect so that we can preserve the aspect ratio while filling |
| 560 | // the destination. |
| 561 | SkIRect src_rect; |
| 562 | if (src_bmp.width() < dest_rect.width() || |
| 563 | src_bmp.height() < dest_rect.height()) { |
| 564 | // Source image is smaller: we clip the part of source image within the |
| 565 | // dest rect, and then stretch it to fill the dest rect. We don't respect |
| 566 | // the aspect ratio in this case. |
| 567 | src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()), |
| 568 | static_cast<S16CPU>(dest_rect.height())); |
| 569 | score->good_clipping = false; |
| 570 | } else { |
| 571 | float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height(); |
| 572 | if (src_aspect > dest_aspect) { |
| 573 | // Wider than tall, clip horizontally: we center the smaller thumbnail in |
| 574 | // the wider screen. |
| 575 | S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect); |
| 576 | S16CPU x_offset = (src_bmp.width() - new_width) / 2; |
| 577 | src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height()); |
| 578 | score->good_clipping = false; |
| 579 | } else { |
| 580 | src_rect.set(0, 0, src_bmp.width(), |
| 581 | static_cast<S16CPU>(src_bmp.width() / dest_aspect)); |
| 582 | score->good_clipping = true; |
| 583 | } |
| 584 | } |
| 585 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 586 | score->at_top = (frame->ScrollOffset().height == 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 587 | |
| 588 | SkBitmap subset; |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 589 | device->accessBitmap(false).extractSubset(&subset, src_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 590 | |
| 591 | // Resample the subset that we want to get it the right size. |
[email protected] | 465b34b7 | 2008-12-12 20:19:14 | [diff] [blame] | 592 | *thumbnail = skia::ImageOperations::Resize( |
| 593 | subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 594 | |
| 595 | score->boring_score = CalculateBoringScore(thumbnail); |
| 596 | |
| 597 | #ifdef TIME_BITMAP_RETRIEVAL |
| 598 | double end = time_util::GetHighResolutionTimeNow(); |
| 599 | char buf[128]; |
| 600 | sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000); |
| 601 | OutputDebugStringA(buf); |
| 602 | #endif |
[email protected] | b6e4bec | 2008-11-12 01:17:15 | [diff] [blame] | 603 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | double RenderView::CalculateBoringScore(SkBitmap* bitmap) { |
| 607 | int histogram[256] = {0}; |
| 608 | color_utils::BuildLumaHistogram(bitmap, histogram); |
| 609 | |
| 610 | int color_count = *std::max_element(histogram, histogram + 256); |
| 611 | int pixel_count = bitmap->width() * bitmap->height(); |
| 612 | return static_cast<double>(color_count) / pixel_count; |
| 613 | } |
| 614 | |
| 615 | void RenderView::OnNavigate(const ViewMsg_Navigate_Params& params) { |
| 616 | if (!webview()) |
| 617 | return; |
| 618 | |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 619 | renderer_logging::ScopedActiveRenderingURLSetter url_setter(params.url); |
[email protected] | f8b6b6f | 2009-03-10 16:48:26 | [diff] [blame] | 620 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 621 | AboutHandler::MaybeHandle(params.url); |
| 622 | |
| 623 | bool is_reload = params.reload; |
| 624 | |
| 625 | WebFrame* main_frame = webview()->GetMainFrame(); |
[email protected] | 606843fa | 2008-12-02 19:08:56 | [diff] [blame] | 626 | if (is_reload && !main_frame->HasCurrentHistoryState()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 627 | // We cannot reload if we do not have any history state. This happens, for |
| 628 | // example, when recovering from a crash. Our workaround here is a bit of |
| 629 | // a hack since it means that reload after a crashed tab does not cause an |
| 630 | // end-to-end cache validation. |
| 631 | is_reload = false; |
| 632 | } |
| 633 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 634 | // A navigation resulting from loading a javascript URL should not be treated |
| 635 | // as a browser initiated event. Instead, we want it to look as if the page |
| 636 | // initiated any load resulting from JS execution. |
| 637 | if (!params.url.SchemeIs(chrome::kJavaScriptScheme)) { |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 638 | pending_navigation_state_.reset(NavigationState::CreateBrowserInitiated( |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 639 | params.page_id, params.transition, params.request_time)); |
| 640 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 641 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 642 | // If we are reloading, then WebKit will use the history state of the current |
| 643 | // page, so we should just ignore any given history state. Otherwise, if we |
| 644 | // have history state, then we need to navigate to it, which corresponds to a |
| 645 | // back/forward navigation event. |
| 646 | if (!is_reload && !params.state.empty()) { |
| 647 | // 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] | 648 | DCHECK_NE(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 649 | main_frame->LoadHistoryState(params.state); |
| 650 | } else { |
| 651 | // Navigate to the given URL. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 652 | WebURLRequest request(params.url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 653 | |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 654 | // TODO(darin): WebFrame should just have a Reload method. |
| 655 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 656 | WebURLRequest::CachePolicy cache_policy; |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 657 | if (is_reload) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 658 | cache_policy = WebURLRequest::ReloadIgnoringCacheData; |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 659 | } else { |
| 660 | // A session history navigation should have been accompanied by state. |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 661 | DCHECK_EQ(params.page_id, -1); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 662 | if (main_frame->GetInViewSourceMode()) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 663 | cache_policy = WebURLRequest::ReturnCacheDataElseLoad; |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 664 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 665 | cache_policy = WebURLRequest::UseProtocolCachePolicy; |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 666 | } |
| 667 | } |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 668 | request.setCachePolicy(cache_policy); |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 669 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 670 | if (params.referrer.is_valid()) { |
| 671 | request.setHTTPHeaderField(WebString::fromUTF8("Referer"), |
| 672 | WebString::fromUTF8(params.referrer.spec())); |
| 673 | } |
[email protected] | 04d3c6e | 2009-05-22 17:00:13 | [diff] [blame] | 674 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 675 | main_frame->LoadRequest(request); |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 676 | } |
| 677 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 678 | // In case LoadRequest failed before DidCreateDataSource was called. |
| 679 | pending_navigation_state_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | // Stop loading the current page |
| 683 | void RenderView::OnStop() { |
| 684 | if (webview()) |
| 685 | webview()->StopLoading(); |
| 686 | } |
| 687 | |
| 688 | void RenderView::OnLoadAlternateHTMLText(const std::string& html_contents, |
| 689 | bool new_navigation, |
| 690 | const GURL& display_url, |
| 691 | const std::string& security_info) { |
| 692 | if (!webview()) |
| 693 | return; |
| 694 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 695 | WebURLRequest request; |
| 696 | request.initialize(); |
| 697 | request.setURL(GURL(kUnreachableWebDataURL)); |
| 698 | request.setSecurityInfo(security_info); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 699 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 700 | webview()->GetMainFrame()->LoadAlternateHTMLString(request, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 701 | html_contents, |
| 702 | display_url, |
| 703 | !new_navigation); |
| 704 | } |
| 705 | |
| 706 | void RenderView::OnCopyImageAt(int x, int y) { |
| 707 | webview()->CopyImageAt(x, y); |
| 708 | } |
| 709 | |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 710 | void RenderView::OnExecuteEditCommand(const std::string& name, |
| 711 | const std::string& value) { |
| 712 | if (!webview() || !webview()->GetFocusedFrame()) |
| 713 | return; |
| 714 | |
[email protected] | 4b59ae60 | 2009-06-23 20:58:15 | [diff] [blame] | 715 | webview()->GetFocusedFrame()->ExecuteEditCommandByName(name, value); |
[email protected] | 68b1e92 | 2009-06-23 16:00:25 | [diff] [blame] | 716 | } |
| 717 | |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 718 | void RenderView::OnSetupDevToolsClient() { |
[email protected] | e4ac5df | 2009-03-17 15:33:11 | [diff] [blame] | 719 | DCHECK(!devtools_client_.get()); |
| 720 | devtools_client_.reset(new DevToolsClient(this)); |
[email protected] | b2abac7 | 2009-02-26 12:39:28 | [diff] [blame] | 721 | } |
| 722 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 723 | void RenderView::OnStopFinding(bool clear_selection) { |
| 724 | WebView* view = webview(); |
| 725 | if (!view) |
| 726 | return; |
| 727 | |
| 728 | if (clear_selection) |
| 729 | view->GetFocusedFrame()->ClearSelection(); |
| 730 | |
| 731 | WebFrame* frame = view->GetMainFrame(); |
| 732 | while (frame) { |
[email protected] | 65134c43 | 2008-09-26 21:47:20 | [diff] [blame] | 733 | frame->StopFinding(clear_selection); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 734 | frame = view->GetNextFrameAfter(frame, false); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | void RenderView::OnFindReplyAck() { |
| 739 | // Check if there is any queued up request waiting to be sent. |
| 740 | if (queued_find_reply_message_.get()) { |
| 741 | // Send the search result over to the browser process. |
| 742 | Send(queued_find_reply_message_.get()); |
| 743 | queued_find_reply_message_.release(); |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | void RenderView::OnUpdateTargetURLAck() { |
| 748 | // Check if there is a targeturl waiting to be sent. |
| 749 | if (target_url_status_ == TARGET_PENDING) { |
| 750 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, |
| 751 | pending_target_url_)); |
| 752 | } |
| 753 | |
| 754 | target_url_status_ = TARGET_NONE; |
| 755 | } |
| 756 | |
| 757 | void RenderView::OnUndo() { |
| 758 | if (!webview()) |
| 759 | return; |
| 760 | |
| 761 | webview()->GetFocusedFrame()->Undo(); |
| 762 | } |
| 763 | |
| 764 | void RenderView::OnRedo() { |
| 765 | if (!webview()) |
| 766 | return; |
| 767 | |
| 768 | webview()->GetFocusedFrame()->Redo(); |
| 769 | } |
| 770 | |
| 771 | void RenderView::OnCut() { |
| 772 | if (!webview()) |
| 773 | return; |
| 774 | |
| 775 | webview()->GetFocusedFrame()->Cut(); |
| 776 | } |
| 777 | |
| 778 | void RenderView::OnCopy() { |
| 779 | if (!webview()) |
| 780 | return; |
| 781 | |
| 782 | webview()->GetFocusedFrame()->Copy(); |
| 783 | } |
| 784 | |
| 785 | void RenderView::OnPaste() { |
| 786 | if (!webview()) |
| 787 | return; |
| 788 | |
| 789 | webview()->GetFocusedFrame()->Paste(); |
| 790 | } |
| 791 | |
| 792 | void RenderView::OnReplace(const std::wstring& text) { |
| 793 | if (!webview()) |
| 794 | return; |
| 795 | |
| 796 | webview()->GetFocusedFrame()->Replace(text); |
| 797 | } |
| 798 | |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 799 | void RenderView::OnToggleSpellCheck() { |
| 800 | if (!webview()) |
| 801 | return; |
| 802 | |
| 803 | webview()->GetFocusedFrame()->ToggleSpellCheck(); |
| 804 | } |
| 805 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 806 | void RenderView::OnDelete() { |
| 807 | if (!webview()) |
| 808 | return; |
| 809 | |
| 810 | webview()->GetFocusedFrame()->Delete(); |
| 811 | } |
| 812 | |
| 813 | void RenderView::OnSelectAll() { |
| 814 | if (!webview()) |
| 815 | return; |
| 816 | |
| 817 | webview()->GetFocusedFrame()->SelectAll(); |
| 818 | } |
| 819 | |
| 820 | void RenderView::OnSetInitialFocus(bool reverse) { |
| 821 | if (!webview()) |
| 822 | return; |
| 823 | webview()->SetInitialFocus(reverse); |
| 824 | } |
| 825 | |
| 826 | /////////////////////////////////////////////////////////////////////////////// |
| 827 | |
| 828 | // Tell the embedding application that the URL of the active page has changed |
| 829 | void RenderView::UpdateURL(WebFrame* frame) { |
| 830 | WebDataSource* ds = frame->GetDataSource(); |
| 831 | DCHECK(ds); |
| 832 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 833 | const WebURLRequest& request = ds->request(); |
| 834 | const WebURLRequest& original_request = ds->originalRequest(); |
| 835 | const WebURLResponse& response = ds->response(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 836 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 837 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 838 | DCHECK(navigation_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 839 | |
| 840 | ViewHostMsg_FrameNavigate_Params params; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 841 | params.http_status_code = response.httpStatusCode(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 842 | params.is_post = false; |
| 843 | params.page_id = page_id_; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 844 | params.is_content_filtered = response.isContentFiltered(); |
| 845 | if (!request.securityInfo().isEmpty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 846 | // SSL state specified in the request takes precedence over the one in the |
| 847 | // response. |
| 848 | // So far this is only intended for error pages that are not expected to be |
| 849 | // over ssl, so we should not get any clash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 850 | DCHECK(response.securityInfo().isEmpty()); |
| 851 | params.security_info = request.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 852 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 853 | params.security_info = response.securityInfo(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | // Set the URL to be displayed in the browser UI to the user. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 857 | if (ds->hasUnreachableURL()) { |
| 858 | params.url = ds->unreachableURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 859 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 860 | params.url = request.url(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 861 | } |
| 862 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 863 | GetRedirectChain(ds, ¶ms.redirects); |
| 864 | params.should_update_history = !ds->hasUnreachableURL(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 865 | |
| 866 | const SearchableFormData* searchable_form_data = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 867 | navigation_state->searchable_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 868 | if (searchable_form_data) { |
| 869 | params.searchable_form_url = searchable_form_data->url(); |
| 870 | params.searchable_form_element_name = searchable_form_data->element_name(); |
| 871 | params.searchable_form_encoding = searchable_form_data->encoding(); |
| 872 | } |
| 873 | |
| 874 | const PasswordForm* password_form_data = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 875 | navigation_state->password_form_data(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 876 | if (password_form_data) |
| 877 | params.password_form = *password_form_data; |
| 878 | |
| 879 | params.gesture = navigation_gesture_; |
| 880 | navigation_gesture_ = NavigationGestureUnknown; |
| 881 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 882 | if (!frame->GetParent()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 883 | // Top-level navigation. |
| 884 | |
| 885 | // Update contents MIME type for main frame. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 886 | params.contents_mime_type = UTF16ToUTF8(ds->response().mimeType()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 887 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 888 | params.transition = navigation_state->transition_type(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 889 | if (!PageTransition::IsMainFrame(params.transition)) { |
| 890 | // If the main frame does a load, it should not be reported as a subframe |
| 891 | // navigation. This can occur in the following case: |
| 892 | // 1. You're on a site with frames. |
| 893 | // 2. You do a subframe navigation. This is stored with transition type |
| 894 | // MANUAL_SUBFRAME. |
| 895 | // 3. You navigate to some non-frame site, say, google.com. |
| 896 | // 4. You navigate back to the page from step 2. Since it was initially |
| 897 | // MANUAL_SUBFRAME, it will be that same transition type here. |
| 898 | // We don't want that, because any navigation that changes the toplevel |
| 899 | // frame should be tracked as a toplevel navigation (this allows us to |
| 900 | // update the URL bar, etc). |
| 901 | params.transition = PageTransition::LINK; |
| 902 | } |
| 903 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 904 | // If we have a valid consumed client redirect source, |
| 905 | // the page contained a client redirect (meta refresh, document.loc...), |
| 906 | // so we set the referrer and transition to match. |
| 907 | if (completed_client_redirect_src_.is_valid()) { |
[email protected] | 77e09a9 | 2008-08-01 18:11:04 | [diff] [blame] | 908 | DCHECK(completed_client_redirect_src_ == params.redirects[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 909 | params.referrer = completed_client_redirect_src_; |
| 910 | params.transition = static_cast<PageTransition::Type>( |
| 911 | params.transition | PageTransition::CLIENT_REDIRECT); |
| 912 | } else { |
| 913 | // Bug 654101: the referrer will be empty on https->http transitions. It |
| 914 | // would be nice if we could get the real referrer from somewhere. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 915 | params.referrer = GURL( |
| 916 | original_request.httpHeaderField(WebString::fromUTF8("Referer"))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 917 | } |
| 918 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 919 | string16 method = request.httpMethod(); |
| 920 | if (EqualsASCII(method, "POST")) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 921 | params.is_post = true; |
| 922 | |
| 923 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 924 | } else { |
| 925 | // Subframe navigation: the type depends on whether this navigation |
| 926 | // generated a new session history entry. When they do generate a session |
| 927 | // history entry, it means the user initiated the navigation and we should |
| 928 | // mark it as such. This test checks if this is the first time UpdateURL |
| 929 | // has been called since WillNavigateToURL was called to initiate the load. |
| 930 | if (page_id_ > last_page_id_sent_to_browser_) |
| 931 | params.transition = PageTransition::MANUAL_SUBFRAME; |
| 932 | else |
| 933 | params.transition = PageTransition::AUTO_SUBFRAME; |
| 934 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 935 | Send(new ViewHostMsg_FrameNavigate(routing_id_, params)); |
| 936 | } |
| 937 | |
| 938 | last_page_id_sent_to_browser_ = |
| 939 | std::max(last_page_id_sent_to_browser_, page_id_); |
| 940 | |
| 941 | // 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] | 942 | // we don't want the transition type to persist. Just clear it. |
| 943 | navigation_state->set_transition_type(PageTransition::LINK); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 944 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 945 | #if defined(OS_WIN) |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 946 | if (web_accessibility_manager_.get()) { |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 947 | // Clear accessibility info cache. |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 948 | web_accessibility_manager_->ClearAccObjMap(-1, true); |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 949 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 950 | #else |
[email protected] | 7d926f9 | 2009-03-03 14:26:54 | [diff] [blame] | 951 | // TODO(port): accessibility not yet implemented. See http://crbug.com/8288. |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 952 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | // Tell the embedding application that the title of the active page has changed |
| 956 | void RenderView::UpdateTitle(WebFrame* frame, const std::wstring& title) { |
| 957 | // Ignore all but top level navigations... |
[email protected] | f0af6a7 | 2009-05-30 05:25:17 | [diff] [blame] | 958 | if (webview()->GetMainFrame() == frame) { |
| 959 | Send(new ViewHostMsg_UpdateTitle( |
| 960 | routing_id_, |
| 961 | page_id_, |
| 962 | title.length() > chrome::kMaxTitleChars ? |
| 963 | title.substr(0, chrome::kMaxTitleChars) : title)); |
| 964 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | void RenderView::UpdateEncoding(WebFrame* frame, |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 968 | const std::wstring& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 969 | // Only update main frame's encoding_name. |
| 970 | if (webview()->GetMainFrame() == frame && |
| 971 | last_encoding_name_ != encoding_name) { |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 972 | // Save the encoding name for later comparing. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 973 | last_encoding_name_ = encoding_name; |
| 974 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 975 | Send(new ViewHostMsg_UpdateEncoding(routing_id_, last_encoding_name_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | |
[email protected] | f4d34b5 | 2008-11-24 23:05:01 | [diff] [blame] | 979 | // Sends the previous session history state to the browser so it will be saved |
| 980 | // before we navigate to a new page. This must be called *before* the page ID |
| 981 | // has been updated so we know what it was. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 982 | void RenderView::UpdateSessionHistory(WebFrame* frame) { |
| 983 | // If we have a valid page ID at this point, then it corresponds to the page |
| 984 | // we are navigating away from. Otherwise, this is the first navigation, so |
| 985 | // there is no past session history to record. |
| 986 | if (page_id_ == -1) |
| 987 | return; |
| 988 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 989 | std::string state; |
[email protected] | 606843fa | 2008-12-02 19:08:56 | [diff] [blame] | 990 | if (!webview()->GetMainFrame()->GetPreviousHistoryState(&state)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 991 | return; |
[email protected] | 606843fa | 2008-12-02 19:08:56 | [diff] [blame] | 992 | Send(new ViewHostMsg_UpdateState(routing_id_, page_id_, state)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | /////////////////////////////////////////////////////////////////////////////// |
| 996 | // WebViewDelegate |
| 997 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 998 | bool RenderView::CanAcceptLoadDrops() const { |
| 999 | return renderer_preferences_.can_accept_load_drops; |
| 1000 | } |
| 1001 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1002 | void RenderView::DidStartLoading(WebView* webview) { |
| 1003 | if (is_loading_) { |
| 1004 | DLOG(WARNING) << "DidStartLoading called while loading"; |
| 1005 | return; |
| 1006 | } |
| 1007 | |
| 1008 | is_loading_ = true; |
| 1009 | // Clear the pointer so that we can assign it only when there is an unknown |
| 1010 | // plugin on a page. |
| 1011 | first_default_plugin_ = NULL; |
| 1012 | |
[email protected] | 329581b | 2009-04-28 06:52:35 | [diff] [blame] | 1013 | Send(new ViewHostMsg_DidStartLoading(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | void RenderView::DidStopLoading(WebView* webview) { |
| 1017 | if (!is_loading_) { |
| 1018 | DLOG(WARNING) << "DidStopLoading called while not loading"; |
| 1019 | return; |
| 1020 | } |
| 1021 | |
| 1022 | is_loading_ = false; |
| 1023 | |
| 1024 | // NOTE: For now we're doing the safest thing, and sending out notification |
| 1025 | // when done loading. This currently isn't an issue as the favicon is only |
| 1026 | // displayed when done loading. Ideally we would send notification when |
| 1027 | // finished parsing the head, but webkit doesn't support that yet. |
| 1028 | // The feed discovery code would also benefit from access to the head. |
| 1029 | GURL favicon_url(webview->GetMainFrame()->GetFavIconURL()); |
| 1030 | if (!favicon_url.is_empty()) |
| 1031 | Send(new ViewHostMsg_UpdateFavIconURL(routing_id_, page_id_, favicon_url)); |
| 1032 | |
| 1033 | AddGURLSearchProvider(webview->GetMainFrame()->GetOSDDURL(), |
| 1034 | true); // autodetected |
| 1035 | |
[email protected] | 329581b | 2009-04-28 06:52:35 | [diff] [blame] | 1036 | Send(new ViewHostMsg_DidStopLoading(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1037 | |
| 1038 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 1039 | method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, page_id_, |
| 1040 | false), |
| 1041 | kDelayForCaptureMs); |
| 1042 | |
| 1043 | // The page is loaded. Try to process the file we need to upload if any. |
| 1044 | ProcessPendingUpload(); |
| 1045 | |
| 1046 | // Since the page is done loading, we are sure we don't need to try |
| 1047 | // again. |
| 1048 | ResetPendingUpload(); |
| 1049 | } |
| 1050 | |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1051 | void RenderView::DidCreateDataSource(WebFrame* frame, WebDataSource* ds) { |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1052 | // The rest of RenderView assumes that a WebDataSource will always have a |
| 1053 | // non-null NavigationState. |
| 1054 | if (pending_navigation_state_.get()) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1055 | ds->setExtraData(pending_navigation_state_.release()); |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1056 | } else { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1057 | ds->setExtraData(NavigationState::CreateContentInitiated()); |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1058 | } |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1059 | } |
| 1060 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1061 | void RenderView::DidStartProvisionalLoadForFrame( |
| 1062 | WebView* webview, |
| 1063 | WebFrame* frame, |
| 1064 | NavigationGesture gesture) { |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 1065 | WebDataSource* ds = frame->GetProvisionalDataSource(); |
| 1066 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 1067 | |
| 1068 | navigation_state->set_start_load_time(Time::Now()); |
| 1069 | |
| 1070 | // Update the request time if WebKit has better knowledge of it. |
| 1071 | if (navigation_state->request_time().is_null()) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1072 | double event_time = ds->triggeringEventTime(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 1073 | if (event_time != 0.0) |
| 1074 | navigation_state->set_request_time(Time::FromDoubleT(event_time)); |
| 1075 | } |
| 1076 | |
| 1077 | bool is_top_most = !frame->GetParent(); |
| 1078 | if (is_top_most) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1079 | navigation_gesture_ = gesture; |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 1080 | |
[email protected] | 77e09a9 | 2008-08-01 18:11:04 | [diff] [blame] | 1081 | // Make sure redirect tracking state is clear for the new load. |
| 1082 | completed_client_redirect_src_ = GURL(); |
| 1083 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1084 | |
| 1085 | Send(new ViewHostMsg_DidStartProvisionalLoadForFrame( |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1086 | routing_id_, is_top_most, ds->request().url())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | bool RenderView::DidLoadResourceFromMemoryCache(WebView* webview, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1090 | const WebURLRequest& request, |
| 1091 | const WebURLResponse& response, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1092 | WebFrame* frame) { |
| 1093 | // Let the browser know we loaded a resource from the memory cache. This |
| 1094 | // message is needed to display the correct SSL indicators. |
| 1095 | Send(new ViewHostMsg_DidLoadResourceFromMemoryCache(routing_id_, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1096 | request.url(), frame->GetSecurityOrigin(), |
[email protected] | ffc4586 | 2009-03-17 06:11:08 | [diff] [blame] | 1097 | frame->GetTop()->GetSecurityOrigin(), |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1098 | response.securityInfo())); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1099 | |
| 1100 | return false; |
| 1101 | } |
| 1102 | |
| 1103 | void RenderView::DidReceiveProvisionalLoadServerRedirect(WebView* webview, |
| 1104 | WebFrame* frame) { |
| 1105 | if (frame == webview->GetMainFrame()) { |
| 1106 | // Received a redirect on the main frame. |
| 1107 | WebDataSource* data_source = |
| 1108 | webview->GetMainFrame()->GetProvisionalDataSource(); |
| 1109 | if (!data_source) { |
| 1110 | // Should only be invoked when we have a data source. |
| 1111 | NOTREACHED(); |
| 1112 | return; |
| 1113 | } |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1114 | std::vector<GURL> redirects; |
| 1115 | GetRedirectChain(data_source, &redirects); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1116 | if (redirects.size() >= 2) { |
| 1117 | Send(new ViewHostMsg_DidRedirectProvisionalLoad( |
| 1118 | routing_id_, page_id_, redirects[redirects.size() - 2], |
| 1119 | redirects[redirects.size() - 1])); |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | void RenderView::DidFailProvisionalLoadWithError(WebView* webview, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1125 | const WebURLError& error, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1126 | WebFrame* frame) { |
| 1127 | // Notify the browser that we failed a provisional load with an error. |
| 1128 | // |
| 1129 | // Note: It is important this notification occur before DidStopLoading so the |
| 1130 | // SSL manager can react to the provisional load failure before being |
| 1131 | // notified the load stopped. |
| 1132 | // |
| 1133 | WebDataSource* ds = frame->GetProvisionalDataSource(); |
| 1134 | DCHECK(ds); |
| 1135 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1136 | const WebURLRequest& failed_request = ds->request(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1137 | |
| 1138 | bool show_repost_interstitial = |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1139 | (error.reason == net::ERR_CACHE_MISS && |
| 1140 | EqualsASCII(failed_request.httpMethod(), "POST")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1141 | Send(new ViewHostMsg_DidFailProvisionalLoadWithError( |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1142 | routing_id_, !frame->GetParent(), |
| 1143 | error.reason, error.unreachableURL, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1144 | show_repost_interstitial)); |
| 1145 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1146 | // Don't display an error page if this is simply a cancelled load. Aside |
| 1147 | // from being dumb, WebCore doesn't expect it and it will cause a crash. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1148 | if (error.reason == net::ERR_ABORTED) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1149 | return; |
| 1150 | |
[email protected] | 546ddd17 | 2009-06-25 00:25:01 | [diff] [blame] | 1151 | // Make sure we never show errors in view source mode. |
| 1152 | frame->SetInViewSourceMode(false); |
| 1153 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1154 | // If this is a failed back/forward/reload navigation, then we need to do a |
| 1155 | // 'replace' load. This is necessary to avoid messing up session history. |
| 1156 | // Otherwise, we do a normal load, which simulates a 'go' navigation as far |
| 1157 | // as session history is concerned. |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1158 | bool replace = !NavigationState::FromDataSource(ds)->is_new_navigation(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1159 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 1160 | // Use the alternate error page service if this is a DNS failure or |
| 1161 | // connection failure. ERR_CONNECTION_FAILED can be dropped once we no longer |
| 1162 | // use winhttp. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1163 | int ec = error.reason; |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 1164 | if (ec == net::ERR_NAME_NOT_RESOLVED || |
| 1165 | ec == net::ERR_CONNECTION_FAILED || |
| 1166 | ec == net::ERR_CONNECTION_REFUSED || |
| 1167 | ec == net::ERR_ADDRESS_UNREACHABLE || |
| 1168 | ec == net::ERR_TIMED_OUT) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1169 | const GURL& failed_url = error.unreachableURL; |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 1170 | const GURL& error_page_url = GetAlternateErrorPageURL(failed_url, |
| 1171 | ec == net::ERR_NAME_NOT_RESOLVED ? WebViewDelegate::DNS_ERROR |
| 1172 | : WebViewDelegate::CONNECTION_ERROR); |
| 1173 | if (error_page_url.is_valid()) { |
| 1174 | // Ask the WebFrame to fetch the alternate error page for us. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1175 | frame->LoadAlternateHTMLErrorPage(failed_request, error, error_page_url, |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 1176 | replace, GURL(kUnreachableWebDataURL)); |
| 1177 | return; |
| 1178 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1179 | } |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 1180 | |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 1181 | // Fallback to a local error page. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1182 | LoadNavigationErrorPage(frame, failed_request, error, std::string(), |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 1183 | replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | void RenderView::LoadNavigationErrorPage(WebFrame* frame, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1187 | const WebURLRequest& failed_request, |
| 1188 | const WebURLError& error, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1189 | const std::string& html, |
| 1190 | bool replace) { |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1191 | GURL failed_url = error.unreachableURL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1192 | |
| 1193 | std::string alt_html; |
| 1194 | if (html.empty()) { |
| 1195 | // Use a local error page. |
| 1196 | int resource_id; |
| 1197 | DictionaryValue error_strings; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1198 | if (error.reason == net::ERR_CACHE_MISS && |
| 1199 | EqualsASCII(failed_request.httpMethod(), "POST")) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1200 | GetFormRepostErrorValues(failed_url, &error_strings); |
| 1201 | resource_id = IDR_ERROR_NO_DETAILS_HTML; |
| 1202 | } else { |
| 1203 | GetLocalizedErrorValues(error, &error_strings); |
| 1204 | resource_id = IDR_NET_ERROR_HTML; |
| 1205 | } |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 1206 | error_strings.SetString(L"textdirection", |
| 1207 | (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? |
| 1208 | L"rtl" : L"ltr"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1209 | |
| 1210 | alt_html = GetAltHTMLForTemplate(error_strings, resource_id); |
| 1211 | } else { |
| 1212 | alt_html = html; |
| 1213 | } |
| 1214 | |
| 1215 | // Use a data: URL as the site URL to prevent against XSS attacks. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1216 | WebURLRequest request(failed_request); |
| 1217 | request.setURL(GURL(kUnreachableWebDataURL)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1218 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1219 | frame->LoadAlternateHTMLString(request, alt_html, failed_url, replace); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | void RenderView::DidCommitLoadForFrame(WebView *webview, WebFrame* frame, |
| 1223 | bool is_new_navigation) { |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1224 | NavigationState* navigation_state = |
| 1225 | NavigationState::FromDataSource(frame->GetDataSource()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1226 | |
| 1227 | if (is_new_navigation) { |
| 1228 | // When we perform a new navigation, we need to update the previous session |
| 1229 | // history entry with state for the page we are leaving. |
| 1230 | UpdateSessionHistory(frame); |
| 1231 | |
| 1232 | // We bump our Page ID to correspond with the new session history entry. |
| 1233 | page_id_ = next_page_id_++; |
| 1234 | |
| 1235 | MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 1236 | method_factory_.NewRunnableMethod(&RenderView::CapturePageInfo, |
| 1237 | page_id_, true), |
| 1238 | kDelayForForcedCaptureMs); |
| 1239 | } else { |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1240 | // Inspect the navigation_state on the main frame (set in our Navigate |
| 1241 | // method) to see if the navigation corresponds to a session history |
| 1242 | // navigation... Note: |frame| may or may not be the toplevel frame, but |
| 1243 | // for the case of capturing session history, the first committed frame |
| 1244 | // suffices. We keep track of whether we've seen this commit before so |
| 1245 | // that only capture session history once per navigation. |
[email protected] | f4d34b5 | 2008-11-24 23:05:01 | [diff] [blame] | 1246 | // |
| 1247 | // Note that we need to check if the page ID changed. In the case of a |
| 1248 | // reload, the page ID doesn't change, and UpdateSessionHistory gets the |
| 1249 | // previous URL and the current page ID, which would be wrong. |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1250 | if (!navigation_state->is_new_navigation() && |
| 1251 | !navigation_state->request_committed() && |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1252 | page_id_ != navigation_state->pending_page_id()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1253 | // This is a successful session history navigation! |
| 1254 | UpdateSessionHistory(frame); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1255 | page_id_ = navigation_state->pending_page_id(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | // Remember that we've already processed this request, so we don't update |
| 1260 | // the session history again. We do this regardless of whether this is |
| 1261 | // a session history navigation, because if we attempted a session history |
| 1262 | // navigation without valid HistoryItem state, WebCore will think it is a |
| 1263 | // new navigation. |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1264 | navigation_state->set_request_committed(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1265 | |
| 1266 | UpdateURL(frame); |
| 1267 | |
| 1268 | // If this committed load was initiated by a client redirect, we're |
| 1269 | // at the last stop now, so clear it. |
| 1270 | completed_client_redirect_src_ = GURL(); |
| 1271 | |
| 1272 | // Check whether we have new encoding name. |
| 1273 | UpdateEncoding(frame, webview->GetMainFrameEncodingName()); |
| 1274 | } |
| 1275 | |
| 1276 | void RenderView::DidReceiveTitle(WebView* webview, |
| 1277 | const std::wstring& title, |
| 1278 | WebFrame* frame) { |
| 1279 | UpdateTitle(frame, title); |
| 1280 | |
| 1281 | // Also check whether we have new encoding name. |
| 1282 | UpdateEncoding(frame, webview->GetMainFrameEncodingName()); |
| 1283 | } |
| 1284 | |
| 1285 | void RenderView::DidFinishLoadForFrame(WebView* webview, WebFrame* frame) { |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 1286 | if (webview->GetMainFrame() == frame) { |
| 1287 | const GURL& url = frame->GetURL(); |
| 1288 | if (url.SchemeIs("http") || url.SchemeIs("https")) |
| 1289 | DumpLoadHistograms(); |
| 1290 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | void RenderView::DidFailLoadWithError(WebView* webview, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1294 | const WebURLError& error, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1295 | WebFrame* frame) { |
[email protected] | 546ddd17 | 2009-06-25 00:25:01 | [diff] [blame] | 1296 | // Currently this function is empty. When you implement something here and it |
| 1297 | // will display any error messages in HTML, please make sure to call |
| 1298 | // frame->SetInViewSourceMode(false) not to show them in view source mode. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | void RenderView::DidFinishDocumentLoadForFrame(WebView* webview, |
| 1302 | WebFrame* frame) { |
[email protected] | 09b8f82f | 2009-06-16 20:22:11 | [diff] [blame] | 1303 | Send(new ViewHostMsg_DocumentLoadedInFrame(routing_id_)); |
| 1304 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1305 | // The document has now been fully loaded. Scan for password forms to be |
| 1306 | // sent up to the browser. |
| 1307 | SendPasswordForms(frame); |
| 1308 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1309 | // Check whether we have new encoding name. |
| 1310 | UpdateEncoding(frame, webview->GetMainFrameEncodingName()); |
[email protected] | 1e0f7040 | 2008-10-16 23:57:47 | [diff] [blame] | 1311 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 1312 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 1313 | RenderThread::current()->user_script_slave()->InjectScripts( |
[email protected] | 0afe827 | 2009-02-14 04:15:16 | [diff] [blame] | 1314 | frame, UserScript::DOCUMENT_END); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | void RenderView::DidHandleOnloadEventsForFrame(WebView* webview, |
| 1318 | WebFrame* frame) { |
| 1319 | } |
| 1320 | |
| 1321 | void RenderView::DidChangeLocationWithinPageForFrame(WebView* webview, |
| 1322 | WebFrame* frame, |
| 1323 | bool is_new_navigation) { |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1324 | // If this was a reference fragment navigation that we initiated, then we |
| 1325 | // could end up having a non-null pending navigation state. We just need to |
| 1326 | // update the ExtraData on the datasource so that others who read the |
| 1327 | // ExtraData will get the new NavigationState. Similarly, if we did not |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1328 | // initiate this navigation, then we need to take care to reset any pre- |
| 1329 | // existing navigation state to a content-initiated navigation state. |
| 1330 | // DidCreateDataSource conveniently takes care of this for us. |
| 1331 | DidCreateDataSource(frame, frame->GetDataSource()); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1332 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1333 | DidCommitLoadForFrame(webview, frame, is_new_navigation); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1334 | |
[email protected] | 9d806f5 | 2009-03-12 22:50:54 | [diff] [blame] | 1335 | const string16& title = |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1336 | webview->GetMainFrame()->GetDataSource()->pageTitle(); |
[email protected] | 9d806f5 | 2009-03-12 22:50:54 | [diff] [blame] | 1337 | UpdateTitle(frame, UTF16ToWideHack(title)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1338 | } |
| 1339 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1340 | void RenderView::DidCompleteClientRedirect(WebView* webview, |
| 1341 | WebFrame* frame, |
| 1342 | const GURL& source) { |
| 1343 | if (webview->GetMainFrame() == frame) |
| 1344 | completed_client_redirect_src_ = source; |
| 1345 | } |
| 1346 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1347 | void RenderView::WillSubmitForm(WebView* webview, WebFrame* frame, |
| 1348 | const WebForm& form) { |
| 1349 | NavigationState* navigation_state = |
| 1350 | NavigationState::FromDataSource(frame->GetProvisionalDataSource()); |
| 1351 | |
| 1352 | if (navigation_state->transition_type() == PageTransition::LINK) |
| 1353 | navigation_state->set_transition_type(PageTransition::FORM_SUBMIT); |
| 1354 | |
| 1355 | // Save these to be processed when the ensuing navigation is committed. |
| 1356 | navigation_state->set_searchable_form_data( |
| 1357 | SearchableFormData::Create(form)); |
| 1358 | navigation_state->set_password_form_data( |
| 1359 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 1360 | |
| 1361 | if (form.isAutoCompleteEnabled()) { |
| 1362 | scoped_ptr<AutofillForm> autofill_form(AutofillForm::Create(form)); |
| 1363 | if (autofill_form.get()) |
| 1364 | Send(new ViewHostMsg_AutofillFormSubmitted(routing_id_, *autofill_form)); |
| 1365 | } |
| 1366 | } |
| 1367 | |
[email protected] | 5b35a6b | 2009-03-16 19:58:08 | [diff] [blame] | 1368 | void RenderView::WillSendRequest(WebView* webview, |
| 1369 | uint32 identifier, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1370 | WebURLRequest* request) { |
| 1371 | request->setRequestorID(routing_id_); |
[email protected] | 5b35a6b | 2009-03-16 19:58:08 | [diff] [blame] | 1372 | } |
| 1373 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1374 | void RenderView::BindDOMAutomationController(WebFrame* webframe) { |
| 1375 | dom_automation_controller_.set_message_sender(this); |
| 1376 | dom_automation_controller_.set_routing_id(routing_id_); |
| 1377 | dom_automation_controller_.BindToJavascript(webframe, |
| 1378 | L"domAutomationController"); |
| 1379 | } |
| 1380 | |
| 1381 | void RenderView::WindowObjectCleared(WebFrame* webframe) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 1382 | if (BindingsPolicy::is_dom_automation_enabled(enabled_bindings_)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1383 | BindDOMAutomationController(webframe); |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 1384 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1385 | dom_ui_bindings_.set_message_sender(this); |
| 1386 | dom_ui_bindings_.set_routing_id(routing_id_); |
| 1387 | dom_ui_bindings_.BindToJavascript(webframe, L"chrome"); |
| 1388 | } |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 1389 | if (BindingsPolicy::is_external_host_enabled(enabled_bindings_)) { |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 1390 | external_host_bindings_.set_message_sender(this); |
| 1391 | external_host_bindings_.set_routing_id(routing_id_); |
| 1392 | external_host_bindings_.BindToJavascript(webframe, L"externalHost"); |
| 1393 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1394 | } |
| 1395 | |
[email protected] | 0afe827 | 2009-02-14 04:15:16 | [diff] [blame] | 1396 | void RenderView::DocumentElementAvailable(WebFrame* frame) { |
[email protected] | 4b8323b | 2009-04-17 18:45:44 | [diff] [blame] | 1397 | // TODO(mpcomplete): remove this before Chrome extensions ship. |
| 1398 | // HACK. This is a temporary workaround to allow cross-origin XHR for Chrome |
| 1399 | // extensions. It grants full access to every origin, when we really want |
| 1400 | // to be able to restrict them more specifically. |
[email protected] | d959ce2 | 2009-04-15 21:03:42 | [diff] [blame] | 1401 | if (frame->GetURL().SchemeIs(chrome::kExtensionScheme)) |
[email protected] | 4b8323b | 2009-04-17 18:45:44 | [diff] [blame] | 1402 | frame->GrantUniversalAccess(); |
[email protected] | d959ce2 | 2009-04-15 21:03:42 | [diff] [blame] | 1403 | |
[email protected] | d0298224 | 2009-06-19 02:51:42 | [diff] [blame] | 1404 | // Tell extensions to self-register their js contexts. |
| 1405 | // TODO(rafaelw): This is kind of gross. We need a way to call through |
| 1406 | // the glue layer to retrieve the current v8::Context. |
| 1407 | if (frame->GetURL().SchemeIs(chrome::kExtensionScheme)) |
| 1408 | ExtensionProcessBindings::RegisterExtensionContext(frame); |
[email protected] | 85b9984 | 2009-05-16 02:01:25 | [diff] [blame] | 1409 | |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 1410 | if (RenderThread::current()) // Will be NULL during unit tests. |
| 1411 | RenderThread::current()->user_script_slave()->InjectScripts( |
[email protected] | 0afe827 | 2009-02-14 04:15:16 | [diff] [blame] | 1412 | frame, UserScript::DOCUMENT_START); |
| 1413 | } |
| 1414 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1415 | WindowOpenDisposition RenderView::DispositionForNavigationAction( |
| 1416 | WebView* webview, |
| 1417 | WebFrame* frame, |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1418 | const WebURLRequest& request, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1419 | WebNavigationType type, |
| 1420 | WindowOpenDisposition disposition, |
| 1421 | bool is_redirect) { |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1422 | // A content initiated navigation may have originated from a link-click, |
| 1423 | // script, drag-n-drop operation, etc. |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1424 | bool is_content_initiated = |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 1425 | NavigationState::FromDataSource(frame->GetProvisionalDataSource())-> |
| 1426 | is_content_initiated(); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1427 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1428 | // Webkit is asking whether to navigate to a new URL. |
| 1429 | // This is fine normally, except if we're showing UI from one security |
| 1430 | // context and they're trying to navigate to a different context. |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1431 | const GURL& url = request.url(); |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1432 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1433 | // We only care about navigations that are within the current tab (as opposed |
| 1434 | // to, for example, opening a new window). |
| 1435 | // But we sometimes navigate to about:blank to clear a tab, and we want to |
| 1436 | // still allow that. |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1437 | if (disposition == CURRENT_TAB && is_content_initiated && |
| 1438 | frame->GetParent() == NULL && !url.SchemeIs(chrome::kAboutScheme)) { |
| 1439 | // When we received such unsolicited navigations, we sometimes want to |
| 1440 | // punt them up to the browser to handle. |
| 1441 | if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) || |
[email protected] | 1e5f53a | 2009-06-15 23:48:04 | [diff] [blame] | 1442 | BindingsPolicy::is_extension_enabled(enabled_bindings_) || |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1443 | frame->GetInViewSourceMode() || |
| 1444 | url.SchemeIs(chrome::kViewSourceScheme)) { |
| 1445 | OpenURL(webview, url, GURL(), disposition); |
| 1446 | return IGNORE_ACTION; // Suppress the load here. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | // Detect when a page is "forking" a new tab that can be safely rendered in |
| 1451 | // its own process. This is done by sites like Gmail that try to open links |
| 1452 | // in new windows without script connections back to the original page. We |
| 1453 | // treat such cases as browser navigations (in which we will create a new |
| 1454 | // renderer for a cross-site navigation), rather than WebKit navigations. |
| 1455 | // |
| 1456 | // We use the following heuristic to decide whether to fork a new page in its |
| 1457 | // own process: |
| 1458 | // The parent page must open a new tab to about:blank, set the new tab's |
| 1459 | // window.opener to null, and then redirect the tab to a cross-site URL using |
| 1460 | // JavaScript. |
| 1461 | bool is_fork = |
| 1462 | // Must start from a tab showing about:blank, which is later redirected. |
[email protected] | 6aad4bd | 2009-02-26 22:55:17 | [diff] [blame] | 1463 | frame->GetURL() == GURL("about:blank") && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1464 | // Must be the first real navigation of the tab. |
| 1465 | GetHistoryBackListCount() < 1 && |
| 1466 | GetHistoryForwardListCount() < 1 && |
| 1467 | // The parent page must have set the child's window.opener to null before |
| 1468 | // redirecting to the desired URL. |
| 1469 | frame->GetOpener() == NULL && |
| 1470 | // Must be a top-level frame. |
| 1471 | frame->GetParent() == NULL && |
[email protected] | 77f17a8 | 2009-05-21 04:42:54 | [diff] [blame] | 1472 | // Must not have issued the request from this page. |
| 1473 | is_content_initiated && |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1474 | // Must be targeted at the current tab. |
| 1475 | disposition == CURRENT_TAB && |
| 1476 | // Must be a JavaScript navigation, which appears as "other". |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 1477 | type == WebKit::WebNavigationTypeOther; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1478 | if (is_fork) { |
| 1479 | // Open the URL via the browser, not via WebKit. |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1480 | OpenURL(webview, url, GURL(), disposition); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1481 | return IGNORE_ACTION; |
| 1482 | } |
| 1483 | |
| 1484 | return disposition; |
| 1485 | } |
| 1486 | |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1487 | void RenderView::RunJavaScriptAlert(WebFrame* webframe, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1488 | const std::wstring& message) { |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 1489 | RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptAlert, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1490 | message, |
| 1491 | std::wstring(), |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1492 | webframe->GetURL(), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1493 | NULL); |
| 1494 | } |
| 1495 | |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1496 | bool RenderView::RunJavaScriptConfirm(WebFrame* webframe, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1497 | const std::wstring& message) { |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 1498 | return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptConfirm, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1499 | message, |
| 1500 | std::wstring(), |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1501 | webframe->GetURL(), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1502 | NULL); |
| 1503 | } |
| 1504 | |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1505 | bool RenderView::RunJavaScriptPrompt(WebFrame* webframe, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1506 | const std::wstring& message, |
| 1507 | const std::wstring& default_value, |
| 1508 | std::wstring* result) { |
[email protected] | 478ff2ed | 2009-04-21 23:49:18 | [diff] [blame] | 1509 | return RunJavaScriptMessage(MessageBoxFlags::kIsJavascriptPrompt, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1510 | message, |
| 1511 | default_value, |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1512 | webframe->GetURL(), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1513 | result); |
| 1514 | } |
| 1515 | |
| 1516 | bool RenderView::RunJavaScriptMessage(int type, |
| 1517 | const std::wstring& message, |
| 1518 | const std::wstring& default_value, |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1519 | const GURL& frame_url, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1520 | std::wstring* result) { |
| 1521 | bool success = false; |
| 1522 | std::wstring result_temp; |
| 1523 | if (!result) |
| 1524 | result = &result_temp; |
| 1525 | IPC::SyncMessage* msg = new ViewHostMsg_RunJavaScriptMessage( |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1526 | routing_id_, message, default_value, frame_url, type, &success, result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1527 | |
[email protected] | 1c4947f | 2009-01-15 22:25:11 | [diff] [blame] | 1528 | msg->set_pump_messages_event(modal_dialog_event_.get()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1529 | Send(msg); |
| 1530 | |
| 1531 | return success; |
| 1532 | } |
| 1533 | |
| 1534 | void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) { |
| 1535 | if (!osd_url.is_empty()) |
| 1536 | Send(new ViewHostMsg_PageHasOSDD(routing_id_, page_id_, osd_url, |
| 1537 | autodetected)); |
| 1538 | } |
| 1539 | |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1540 | bool RenderView::RunBeforeUnloadConfirm(WebFrame* webframe, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1541 | const std::wstring& message) { |
| 1542 | bool success = false; |
| 1543 | // This is an ignored return value, but is included so we can accept the same |
| 1544 | // response as RunJavaScriptMessage. |
| 1545 | std::wstring ignored_result; |
| 1546 | IPC::SyncMessage* msg = new ViewHostMsg_RunBeforeUnloadConfirm( |
[email protected] | a455d381 | 2009-03-05 20:18:07 | [diff] [blame] | 1547 | routing_id_, webframe->GetURL(), message, &success, &ignored_result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1548 | |
[email protected] | 1c4947f | 2009-01-15 22:25:11 | [diff] [blame] | 1549 | msg->set_pump_messages_event(modal_dialog_event_.get()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1550 | Send(msg); |
| 1551 | |
| 1552 | return success; |
| 1553 | } |
| 1554 | |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1555 | void RenderView::QueryFormFieldAutofill(const std::wstring& field_name, |
| 1556 | const std::wstring& text, |
| 1557 | int64 node_id) { |
| 1558 | static int message_id_counter = 0; |
| 1559 | form_field_autofill_request_id_ = message_id_counter++; |
| 1560 | Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_, |
| 1561 | field_name, text, |
| 1562 | node_id, |
| 1563 | form_field_autofill_request_id_)); |
| 1564 | } |
| 1565 | |
[email protected] | 4d2b6fb | 2009-03-20 22:28:17 | [diff] [blame] | 1566 | void RenderView::RemoveStoredAutofillEntry(const std::wstring& name, |
| 1567 | const std::wstring& value) { |
| 1568 | Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value)); |
| 1569 | } |
| 1570 | |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1571 | void RenderView::OnReceivedAutofillSuggestions( |
| 1572 | int64 node_id, |
| 1573 | int request_id, |
[email protected] | 8d0f15c | 2008-11-11 01:01:09 | [diff] [blame] | 1574 | const std::vector<std::wstring>& suggestions, |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1575 | int default_suggestion_index) { |
| 1576 | if (!webview() || request_id != form_field_autofill_request_id_) |
| 1577 | return; |
| 1578 | |
| 1579 | webview()->AutofillSuggestionsForNode(node_id, suggestions, |
| 1580 | default_suggestion_index); |
| 1581 | } |
| 1582 | |
[email protected] | 2c4410d | 2009-05-06 23:46:22 | [diff] [blame] | 1583 | void RenderView::OnPopupNotificationVisibilityChanged(bool visible) { |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1584 | popup_notification_visible_ = visible; |
| 1585 | } |
| 1586 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1587 | void RenderView::ShowModalHTMLDialog(const GURL& url, int width, int height, |
| 1588 | const std::string& json_arguments, |
| 1589 | std::string* json_retval) { |
| 1590 | IPC::SyncMessage* msg = new ViewHostMsg_ShowModalHTMLDialog( |
| 1591 | routing_id_, url, width, height, json_arguments, json_retval); |
| 1592 | |
[email protected] | 1c4947f | 2009-01-15 22:25:11 | [diff] [blame] | 1593 | msg->set_pump_messages_event(modal_dialog_event_.get()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1594 | Send(msg); |
| 1595 | } |
| 1596 | |
| 1597 | uint32 RenderView::GetCPBrowsingContext() { |
| 1598 | uint32 context = 0; |
| 1599 | Send(new ViewHostMsg_GetCPBrowsingContext(&context)); |
| 1600 | return context; |
| 1601 | } |
| 1602 | |
| 1603 | // Tell the browser to display a destination link. |
| 1604 | void RenderView::UpdateTargetURL(WebView* webview, const GURL& url) { |
| 1605 | if (url != target_url_) { |
| 1606 | if (target_url_status_ == TARGET_INFLIGHT || |
| 1607 | target_url_status_ == TARGET_PENDING) { |
| 1608 | // If we have a request in-flight, save the URL to be sent when we |
| 1609 | // receive an ACK to the in-flight request. We can happily overwrite |
| 1610 | // any existing pending sends. |
| 1611 | pending_target_url_ = url; |
| 1612 | target_url_status_ = TARGET_PENDING; |
| 1613 | } else { |
| 1614 | Send(new ViewHostMsg_UpdateTargetURL(routing_id_, page_id_, url)); |
| 1615 | target_url_ = url; |
| 1616 | target_url_status_ = TARGET_INFLIGHT; |
| 1617 | } |
| 1618 | } |
| 1619 | } |
| 1620 | |
[email protected] | b62d1a8c | 2009-01-13 23:54:57 | [diff] [blame] | 1621 | void RenderView::RunFileChooser(bool multi_select, |
[email protected] | b949f111 | 2009-04-12 20:03:08 | [diff] [blame] | 1622 | const string16& title, |
| 1623 | const FilePath& default_filename, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1624 | WebFileChooserCallback* file_chooser) { |
| 1625 | if (file_chooser_.get()) { |
| 1626 | // TODO(brettw): bug 1235154: This should be a synchronous message to deal |
| 1627 | // with the fact that web pages can programatically trigger this. With the |
| 1628 | // asnychronous messages, we can get an additional call when one is pending, |
| 1629 | // which this test is for. For now, we just ignore the additional file |
| 1630 | // chooser request. WebKit doesn't do anything to expect the callback, so |
| 1631 | // we can just ignore calling it. |
| 1632 | delete file_chooser; |
| 1633 | return; |
| 1634 | } |
| 1635 | file_chooser_.reset(file_chooser); |
[email protected] | b62d1a8c | 2009-01-13 23:54:57 | [diff] [blame] | 1636 | Send(new ViewHostMsg_RunFileChooser(routing_id_, multi_select, title, |
[email protected] | b949f111 | 2009-04-12 20:03:08 | [diff] [blame] | 1637 | default_filename)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | void RenderView::AddMessageToConsole(WebView* webview, |
| 1641 | const std::wstring& message, |
| 1642 | unsigned int line_no, |
| 1643 | const std::wstring& source_id) { |
| 1644 | Send(new ViewHostMsg_AddMessageToConsole(routing_id_, message, |
| 1645 | static_cast<int32>(line_no), |
| 1646 | source_id)); |
| 1647 | } |
| 1648 | |
| 1649 | void RenderView::AddSearchProvider(const std::string& url) { |
| 1650 | AddGURLSearchProvider(GURL(url), |
| 1651 | false); // not autodetected |
| 1652 | } |
| 1653 | |
[email protected] | c88a70fe | 2009-05-05 20:00:22 | [diff] [blame] | 1654 | WebView* RenderView::CreateWebView(WebView* webview, |
| 1655 | bool user_gesture, |
| 1656 | const GURL& creator_url) { |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 1657 | // Check to make sure we aren't overloading on popups. |
| 1658 | if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups) |
| 1659 | return NULL; |
| 1660 | |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1661 | // This window can't be closed from a window.close() call until we receive a |
| 1662 | // message from the Browser process explicitly allowing it. |
| 1663 | popup_notification_visible_ = true; |
| 1664 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1665 | int32 routing_id = MSG_ROUTING_NONE; |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1666 | |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 1667 | ModalDialogEvent modal_dialog_event; |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1668 | render_thread_->Send( |
[email protected] | 15787f8f | 2008-10-17 15:29:03 | [diff] [blame] | 1669 | new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id, |
| 1670 | &modal_dialog_event)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1671 | if (routing_id == MSG_ROUTING_NONE) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1672 | return NULL; |
| 1673 | } |
| 1674 | |
| 1675 | // The WebView holds a reference to this new RenderView |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1676 | const WebPreferences& web_prefs = webview->GetPreferences(); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1677 | base::WaitableEvent* waitable_event = new base::WaitableEvent |
| 1678 | #if defined(OS_WIN) |
[email protected] | 18bcc3c | 2009-01-27 21:39:15 | [diff] [blame] | 1679 | (modal_dialog_event.event); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1680 | #else |
| 1681 | (true, false); |
| 1682 | #endif |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 1683 | RenderView* view = RenderView::Create(render_thread_, |
[email protected] | 1c4947f | 2009-01-15 22:25:11 | [diff] [blame] | 1684 | NULL, waitable_event, routing_id_, |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1685 | renderer_preferences_, web_prefs, |
| 1686 | shared_popup_counter_, routing_id); |
[email protected] | ed4bf2d | 2009-05-05 00:10:06 | [diff] [blame] | 1687 | view->opened_by_user_gesture_ = user_gesture; |
[email protected] | c88a70fe | 2009-05-05 20:00:22 | [diff] [blame] | 1688 | view->creator_url_ = creator_url; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1689 | |
| 1690 | // Copy over the alternate error page URL so we can have alt error pages in |
| 1691 | // the new render view (we don't need the browser to send the URL back down). |
| 1692 | view->alternate_error_page_url_ = alternate_error_page_url_; |
| 1693 | |
| 1694 | return view->webview(); |
| 1695 | } |
| 1696 | |
[email protected] | 0ebf387 | 2008-11-07 21:35:03 | [diff] [blame] | 1697 | WebWidget* RenderView::CreatePopupWidget(WebView* webview, |
[email protected] | cfd727f | 2009-01-09 20:21:11 | [diff] [blame] | 1698 | bool activatable) { |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 1699 | RenderWidget* widget = RenderWidget::Create(routing_id_, |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 1700 | render_thread_, |
[email protected] | cfd727f | 2009-01-09 20:21:11 | [diff] [blame] | 1701 | activatable); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1702 | return widget->webwidget(); |
| 1703 | } |
| 1704 | |
| 1705 | WebPluginDelegate* RenderView::CreatePluginDelegate( |
| 1706 | WebView* webview, |
| 1707 | const GURL& url, |
| 1708 | const std::string& mime_type, |
| 1709 | const std::string& clsid, |
| 1710 | std::string* actual_mime_type) { |
[email protected] | ffeba6d | 2009-04-27 20:43:26 | [diff] [blame] | 1711 | #if defined(OS_WIN) || defined(OS_LINUX) |
[email protected] | 6273e2e7 | 2009-04-17 00:13:55 | [diff] [blame] | 1712 | if (!PluginChannelHost::IsListening()) |
| 1713 | return NULL; |
| 1714 | |
[email protected] | 9dd9e838 | 2009-06-05 18:23:21 | [diff] [blame] | 1715 | GURL policy_url; |
| 1716 | if (webview->GetMainFrame()) |
| 1717 | policy_url = webview->GetMainFrame()->GetURL(); |
| 1718 | |
[email protected] | f5cdaff | 2009-05-19 21:01:47 | [diff] [blame] | 1719 | FilePath path; |
| 1720 | render_thread_->Send( |
[email protected] | 9dd9e838 | 2009-06-05 18:23:21 | [diff] [blame] | 1721 | new ViewHostMsg_GetPluginPath(url, policy_url, mime_type, clsid, &path, |
[email protected] | f5cdaff | 2009-05-19 21:01:47 | [diff] [blame] | 1722 | actual_mime_type)); |
| 1723 | if (path.value().empty()) |
| 1724 | return NULL; |
| 1725 | |
| 1726 | std::string mime_type_to_use; |
| 1727 | if (!actual_mime_type->empty()) |
| 1728 | mime_type_to_use = *actual_mime_type; |
| 1729 | else |
| 1730 | mime_type_to_use = mime_type; |
| 1731 | |
[email protected] | ffeba6d | 2009-04-27 20:43:26 | [diff] [blame] | 1732 | #if !defined(OS_LINUX) // In-proc plugins aren't supported on Linux. |
[email protected] | 88a1fb47a | 2009-03-13 00:18:06 | [diff] [blame] | 1733 | if (RenderProcess::current()->in_process_plugins()) { |
[email protected] | b94d332 | 2009-02-12 19:49:04 | [diff] [blame] | 1734 | return WebPluginDelegate::Create(path, |
| 1735 | mime_type_to_use, |
| 1736 | gfx::NativeViewFromId(host_window_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1737 | } |
[email protected] | ffeba6d | 2009-04-27 20:43:26 | [diff] [blame] | 1738 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1739 | |
| 1740 | WebPluginDelegateProxy* proxy = |
[email protected] | f5cdaff | 2009-05-19 21:01:47 | [diff] [blame] | 1741 | WebPluginDelegateProxy::Create(url, mime_type_to_use, clsid, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1742 | if (!proxy) |
| 1743 | return NULL; |
| 1744 | |
| 1745 | // We hold onto the proxy so we can poke it when we are painting. See our |
| 1746 | // DidPaint implementation below. |
| 1747 | plugin_delegates_.push_back(proxy); |
| 1748 | |
| 1749 | return proxy; |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1750 | #else |
[email protected] | 157e5d2 | 2009-04-23 18:43:35 | [diff] [blame] | 1751 | // TODO(port): Plugins currently not supported |
| 1752 | NOTIMPLEMENTED(); |
| 1753 | return NULL; |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1754 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1755 | } |
| 1756 | |
[email protected] | 4e6be3f | 2009-05-07 02:24:44 | [diff] [blame] | 1757 | WebKit::WebMediaPlayer* RenderView::CreateWebMediaPlayer( |
| 1758 | WebKit::WebMediaPlayerClient* client) { |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 1759 | scoped_refptr<media::FilterFactoryCollection> factory = |
| 1760 | new media::FilterFactoryCollection(); |
| 1761 | // Add in any custom filter factories first. |
| 1762 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 1763 | if (!cmd_line->HasSwitch(switches::kDisableAudio)) { |
| 1764 | // Add the chrome specific audio renderer. |
| 1765 | factory->AddFactory( |
| 1766 | AudioRendererImpl::CreateFactory(audio_message_filter())); |
| 1767 | } |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame^] | 1768 | |
| 1769 | // TODO(hclam): obtain the following parameters from |client|. |
| 1770 | webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory = |
| 1771 | new webkit_glue::MediaResourceLoaderBridgeFactory( |
| 1772 | GURL::EmptyGURL(), // referrer |
| 1773 | "null", // frame origin |
| 1774 | "null", // main_frame_origin |
| 1775 | base::GetCurrentProcId(), |
| 1776 | WebAppCacheContext::kNoAppCacheContextId, |
| 1777 | routing_id()); |
| 1778 | |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 1779 | if (!cmd_line->HasSwitch(switches::kSimpleDataSource)) { |
| 1780 | // Add the chrome specific media data source. |
[email protected] | 70ab61c9 | 2009-06-16 19:29:39 | [diff] [blame] | 1781 | factory->AddFactory( |
| 1782 | BufferedDataSource::CreateFactory(MessageLoop::current(), |
[email protected] | 8380c09 | 2009-06-25 17:45:51 | [diff] [blame^] | 1783 | bridge_factory)); |
| 1784 | } else { |
| 1785 | factory->AddFactory( |
| 1786 | webkit_glue::SimpleDataSource::CreateFactory(MessageLoop::current(), |
| 1787 | bridge_factory)); |
[email protected] | add5177 | 2009-06-11 18:25:17 | [diff] [blame] | 1788 | } |
| 1789 | return new webkit_glue::WebMediaPlayerImpl(client, factory); |
[email protected] | ec9212f | 2008-12-18 21:40:36 | [diff] [blame] | 1790 | } |
| 1791 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1792 | void RenderView::OnMissingPluginStatus(WebPluginDelegate* delegate, |
| 1793 | int status) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1794 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1795 | if (first_default_plugin_ == NULL) { |
| 1796 | // Show the InfoBar for the first available plugin. |
| 1797 | if (status == default_plugin::MISSING_PLUGIN_AVAILABLE) { |
| 1798 | first_default_plugin_ = delegate; |
| 1799 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1800 | } |
| 1801 | } else { |
| 1802 | // Closes the InfoBar if user clicks on the plugin (instead of the InfoBar) |
| 1803 | // to start the download/install. |
| 1804 | if (status == default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD) { |
| 1805 | Send(new ViewHostMsg_MissingPluginStatus(routing_id_, status)); |
| 1806 | } |
| 1807 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 1808 | #else |
| 1809 | // TODO(port): plugins current not supported |
| 1810 | NOTIMPLEMENTED(); |
| 1811 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1812 | } |
| 1813 | |
[email protected] | eb47a13 | 2009-03-04 00:39:56 | [diff] [blame] | 1814 | WebWorker* RenderView::CreateWebWorker(WebWorkerClient* client) { |
| 1815 | #if defined(OS_WIN) |
[email protected] | ec775ef | 2009-05-01 21:20:47 | [diff] [blame] | 1816 | return new WebWorkerProxy(client, RenderThread::current(), routing_id_); |
[email protected] | eb47a13 | 2009-03-04 00:39:56 | [diff] [blame] | 1817 | #else |
| 1818 | // TODO(port): out of process workers |
| 1819 | NOTIMPLEMENTED(); |
| 1820 | return NULL; |
| 1821 | #endif |
| 1822 | } |
| 1823 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1824 | void RenderView::OpenURL(WebView* webview, const GURL& url, |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1825 | const GURL& referrer, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1826 | WindowOpenDisposition disposition) { |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 1827 | Send(new ViewHostMsg_OpenURL(routing_id_, url, referrer, disposition)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1828 | } |
| 1829 | |
[email protected] | 1d52220 | 2009-04-04 01:56:42 | [diff] [blame] | 1830 | void RenderView::DidContentsSizeChange(WebWidget* webwidget, |
| 1831 | int new_width, |
| 1832 | int new_height) { |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 1833 | // We don't always want to send the change messages over IPC, only if we've |
| 1834 | // be put in that mode by getting a |ViewMsg_EnableIntrinsicWidthChangedMode| |
| 1835 | // message. |
| 1836 | // TODO(rafaelw): Figure out where the best place to set this for extensions |
| 1837 | // is. It isn't clean to test for ExtensionView by examining the |
| 1838 | // enabled_bindings. This needs to be generalized as it becomes clear what |
| 1839 | // extension toolbars need. |
| 1840 | if (BindingsPolicy::is_extension_enabled(enabled_bindings_) || |
| 1841 | send_preferred_width_changes_) { |
| 1842 | // WebCore likes to tell us things have changed even when they haven't, so |
| 1843 | // cache the width and only send the IPC message when we're sure the |
| 1844 | // width is different. |
[email protected] | 1d52220 | 2009-04-04 01:56:42 | [diff] [blame] | 1845 | int width = webview()->GetMainFrame()->GetContentsPreferredWidth(); |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 1846 | if (width != preferred_width_) { |
| 1847 | Send(new ViewHostMsg_DidContentsPreferredWidthChange(routing_id_, width)); |
| 1848 | preferred_width_ = width; |
| 1849 | } |
[email protected] | 1d52220 | 2009-04-04 01:56:42 | [diff] [blame] | 1850 | } |
| 1851 | } |
| 1852 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1853 | // We are supposed to get a single call to Show for a newly created RenderView |
| 1854 | // that was created via RenderView::CreateWebView. So, we wait until this |
| 1855 | // point to dispatch the ShowView message. |
| 1856 | // |
| 1857 | // This method provides us with the information about how to display the newly |
| 1858 | // created RenderView (i.e., as a constrained popup or as a new tab). |
| 1859 | // |
| 1860 | void RenderView::Show(WebWidget* webwidget, WindowOpenDisposition disposition) { |
| 1861 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 1862 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 1863 | |
| 1864 | if (did_show_) |
| 1865 | return; |
| 1866 | did_show_ = true; |
| 1867 | |
| 1868 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 1869 | // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the |
| 1870 | // browser process will impose a default position otherwise. |
[email protected] | 35f7d21 | 2009-04-29 21:19:27 | [diff] [blame] | 1871 | Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, disposition, |
[email protected] | c88a70fe | 2009-05-05 20:00:22 | [diff] [blame] | 1872 | initial_pos_, opened_by_user_gesture_, creator_url_)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1873 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1874 | } |
| 1875 | |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1876 | void RenderView::CloseWidgetSoon(WebWidget* webwidget) { |
[email protected] | 2c4410d | 2009-05-06 23:46:22 | [diff] [blame] | 1877 | if (!popup_notification_visible_) |
[email protected] | 634a6f9 | 2008-12-01 21:39:31 | [diff] [blame] | 1878 | RenderWidget::CloseWidgetSoon(webwidget); |
| 1879 | } |
| 1880 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1881 | void RenderView::RunModal(WebWidget* webwidget) { |
| 1882 | DCHECK(did_show_) << "should already have shown the view"; |
| 1883 | |
| 1884 | IPC::SyncMessage* msg = new ViewHostMsg_RunModal(routing_id_); |
| 1885 | |
[email protected] | 1c4947f | 2009-01-15 22:25:11 | [diff] [blame] | 1886 | msg->set_pump_messages_event(modal_dialog_event_.get()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1887 | Send(msg); |
| 1888 | } |
| 1889 | |
| 1890 | void RenderView::SyncNavigationState() { |
| 1891 | if (!webview()) |
| 1892 | return; |
| 1893 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1894 | std::string state; |
[email protected] | 606843fa | 2008-12-02 19:08:56 | [diff] [blame] | 1895 | if (!webview()->GetMainFrame()->GetCurrentHistoryState(&state)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1896 | return; |
[email protected] | 606843fa | 2008-12-02 19:08:56 | [diff] [blame] | 1897 | Send(new ViewHostMsg_UpdateState(routing_id_, page_id_, state)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | void RenderView::ShowContextMenu(WebView* webview, |
[email protected] | 12464693 | 2009-01-28 18:39:02 | [diff] [blame] | 1901 | ContextNode node, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1902 | int x, |
| 1903 | int y, |
| 1904 | const GURL& link_url, |
| 1905 | const GURL& image_url, |
| 1906 | const GURL& page_url, |
| 1907 | const GURL& frame_url, |
| 1908 | const std::wstring& selection_text, |
| 1909 | const std::wstring& misspelled_word, |
[email protected] | 6aa376b | 2008-09-23 18:49:52 | [diff] [blame] | 1910 | int edit_flags, |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 1911 | const std::string& security_info, |
| 1912 | const std::string& frame_charset) { |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 1913 | ContextMenuParams params; |
[email protected] | 12464693 | 2009-01-28 18:39:02 | [diff] [blame] | 1914 | params.node = node; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1915 | params.x = x; |
| 1916 | params.y = y; |
| 1917 | params.image_url = image_url; |
| 1918 | params.link_url = link_url; |
[email protected] | e6c7981 | 2009-04-22 22:31:42 | [diff] [blame] | 1919 | params.unfiltered_link_url = link_url; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1920 | params.page_url = page_url; |
| 1921 | params.frame_url = frame_url; |
| 1922 | params.selection_text = selection_text; |
| 1923 | params.misspelled_word = misspelled_word; |
[email protected] | be645db | 2009-02-06 20:36:33 | [diff] [blame] | 1924 | params.spellcheck_enabled = |
[email protected] | bbbd545c | 2008-12-15 20:18:04 | [diff] [blame] | 1925 | webview->GetFocusedFrame()->SpellCheckEnabled(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1926 | params.edit_flags = edit_flags; |
[email protected] | 6aa376b | 2008-09-23 18:49:52 | [diff] [blame] | 1927 | params.security_info = security_info; |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 1928 | params.frame_charset = frame_charset; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1929 | Send(new ViewHostMsg_ContextMenu(routing_id_, params)); |
| 1930 | } |
| 1931 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 1932 | void RenderView::StartDragging(WebView* webview, |
| 1933 | const WebDragData& drag_data) { |
| 1934 | Send(new ViewHostMsg_StartDragging(routing_id_, WebDropData(drag_data))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | void RenderView::TakeFocus(WebView* webview, bool reverse) { |
| 1938 | Send(new ViewHostMsg_TakeFocus(routing_id_, reverse)); |
| 1939 | } |
| 1940 | |
| 1941 | void RenderView::DidDownloadImage(int id, |
| 1942 | const GURL& image_url, |
| 1943 | bool errored, |
| 1944 | const SkBitmap& image) { |
| 1945 | Send(new ViewHostMsg_DidDownloadImage(routing_id_, id, image_url, errored, |
| 1946 | image)); |
| 1947 | } |
| 1948 | |
| 1949 | |
| 1950 | void RenderView::OnDownloadImage(int id, |
| 1951 | const GURL& image_url, |
| 1952 | int image_size) { |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 1953 | bool data_image_failed = false; |
| 1954 | if (image_url.SchemeIs("data")) { |
| 1955 | SkBitmap data_image = ImageFromDataUrl(image_url); |
| 1956 | data_image_failed = data_image.empty(); |
| 1957 | if (!data_image_failed) { |
| 1958 | Send(new ViewHostMsg_DidDownloadImage(routing_id_, id, image_url, false, |
| 1959 | data_image)); |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | if (data_image_failed || !webview()->DownloadImage(id, image_url, image_size)) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1964 | Send(new ViewHostMsg_DidDownloadImage(routing_id_, id, image_url, true, |
| 1965 | SkBitmap())); |
| 1966 | } |
| 1967 | |
[email protected] | f11ca073 | 2009-04-11 00:09:34 | [diff] [blame] | 1968 | SkBitmap RenderView::ImageFromDataUrl(const GURL& url) const { |
| 1969 | std::string mime_type, char_set, data; |
| 1970 | if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { |
| 1971 | // Decode the favicon using WebKit's image decoder. |
| 1972 | webkit_glue::ImageDecoder decoder(gfx::Size(kFavIconSize, kFavIconSize)); |
| 1973 | const unsigned char* src_data = |
| 1974 | reinterpret_cast<const unsigned char*>(&data[0]); |
| 1975 | |
| 1976 | return decoder.Decode(src_data, data.size()); |
| 1977 | } |
| 1978 | return SkBitmap(); |
| 1979 | } |
| 1980 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1981 | void RenderView::OnGetApplicationInfo(int page_id) { |
| 1982 | webkit_glue::WebApplicationInfo app_info; |
| 1983 | if (page_id == page_id_) |
| 1984 | webkit_glue::GetApplicationInfo(webview(), &app_info); |
| 1985 | |
| 1986 | // Prune out any data URLs in the set of icons. The browser process expects |
| 1987 | // any icon with a data URL to have originated from a favicon. We don't want |
| 1988 | // to decode arbitrary data URLs in the browser process. See |
| 1989 | // http://b/issue?id=1162972 |
| 1990 | for (size_t i = 0; i < app_info.icons.size(); ++i) { |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 1991 | if (app_info.icons[i].url.SchemeIs(chrome::kDataScheme)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1992 | app_info.icons.erase(app_info.icons.begin() + i); |
| 1993 | --i; |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | Send(new ViewHostMsg_DidGetApplicationInfo(routing_id_, page_id, app_info)); |
| 1998 | } |
| 1999 | |
| 2000 | GURL RenderView::GetAlternateErrorPageURL(const GURL& failedURL, |
| 2001 | ErrorPageType error_type) { |
| 2002 | if (failedURL.SchemeIsSecure()) { |
| 2003 | // If the URL that failed was secure, then the embedding web page was not |
| 2004 | // expecting a network attacker to be able to manipulate its contents. As |
| 2005 | // we fetch alternate error pages over HTTP, we would be allowing a network |
| 2006 | // attacker to manipulate the contents of the response if we tried to use |
| 2007 | // the link doctor here. |
| 2008 | return GURL::EmptyGURL(); |
| 2009 | } |
| 2010 | |
| 2011 | // Grab the base URL from the browser process. |
| 2012 | if (!alternate_error_page_url_.is_valid()) |
| 2013 | return GURL::EmptyGURL(); |
| 2014 | |
| 2015 | // Strip query params from the failed URL. |
| 2016 | GURL::Replacements remove_params; |
| 2017 | remove_params.ClearUsername(); |
| 2018 | remove_params.ClearPassword(); |
| 2019 | remove_params.ClearQuery(); |
| 2020 | remove_params.ClearRef(); |
| 2021 | const GURL url_to_send = failedURL.ReplaceComponents(remove_params); |
| 2022 | |
| 2023 | // Construct the query params to send to link doctor. |
| 2024 | std::string params(alternate_error_page_url_.query()); |
| 2025 | params.append("&url="); |
| 2026 | params.append(EscapeQueryParamValue(url_to_send.spec())); |
| 2027 | params.append("&sourceid=chrome"); |
| 2028 | params.append("&error="); |
| 2029 | switch (error_type) { |
| 2030 | case DNS_ERROR: |
| 2031 | params.append("dnserror"); |
| 2032 | break; |
| 2033 | |
| 2034 | case HTTP_404: |
| 2035 | params.append("http404"); |
| 2036 | break; |
| 2037 | |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 2038 | case CONNECTION_ERROR: |
[email protected] | e1f934b | 2009-01-26 20:41:33 | [diff] [blame] | 2039 | params.append("connectionfailure"); |
[email protected] | 5df266ac | 2008-10-15 19:50:13 | [diff] [blame] | 2040 | break; |
| 2041 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2042 | default: |
| 2043 | NOTREACHED() << "unknown ErrorPageType"; |
| 2044 | } |
| 2045 | |
| 2046 | // OK, build the final url to return. |
| 2047 | GURL::Replacements link_doctor_params; |
| 2048 | link_doctor_params.SetQueryStr(params); |
| 2049 | GURL url = alternate_error_page_url_.ReplaceComponents(link_doctor_params); |
| 2050 | return url; |
| 2051 | } |
| 2052 | |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2053 | void RenderView::OnFind(int request_id, |
| 2054 | const string16& search_text, |
| 2055 | const WebKit::WebFindOptions& options) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2056 | WebFrame* main_frame = webview()->GetMainFrame(); |
| 2057 | WebFrame* frame_after_main = webview()->GetNextFrameAfter(main_frame, true); |
| 2058 | WebFrame* focused_frame = webview()->GetFocusedFrame(); |
| 2059 | WebFrame* search_frame = focused_frame; // start searching focused frame. |
| 2060 | |
| 2061 | bool multi_frame = (frame_after_main != main_frame); |
| 2062 | |
| 2063 | // If we have multiple frames, we don't want to wrap the search within the |
| 2064 | // frame, so we check here if we only have main_frame in the chain. |
| 2065 | bool wrap_within_frame = !multi_frame; |
| 2066 | |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 2067 | WebRect selection_rect; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2068 | bool result = false; |
| 2069 | |
| 2070 | do { |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2071 | result = search_frame->Find( |
| 2072 | request_id, search_text, options, wrap_within_frame, &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2073 | |
| 2074 | if (!result) { |
| 2075 | // don't leave text selected as you move to the next frame. |
| 2076 | search_frame->ClearSelection(); |
| 2077 | |
| 2078 | // Find the next frame, but skip the invisible ones. |
| 2079 | do { |
| 2080 | // What is the next frame to search? (we might be going backwards). Note |
| 2081 | // that we specify wrap=true so that search_frame never becomes NULL. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2082 | search_frame = options.forward ? |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2083 | webview()->GetNextFrameAfter(search_frame, true) : |
| 2084 | webview()->GetPreviousFrameBefore(search_frame, true); |
| 2085 | } while (!search_frame->Visible() && search_frame != focused_frame); |
| 2086 | |
[email protected] | 884db41 | 2008-11-24 23:46:50 | [diff] [blame] | 2087 | // Make sure selection doesn't affect the search operation in new frame. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2088 | search_frame->ClearSelection(); |
| 2089 | |
| 2090 | // If we have multiple frames and we have wrapped back around to the |
| 2091 | // focused frame, we need to search it once more allowing wrap within |
| 2092 | // the frame, otherwise it will report 'no match' if the focused frame has |
| 2093 | // reported matches, but no frames after the focused_frame contain a |
| 2094 | // match for the search word(s). |
| 2095 | if (multi_frame && search_frame == focused_frame) { |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2096 | result = search_frame->Find( |
| 2097 | request_id, search_text, options, true, // Force wrapping. |
| 2098 | &selection_rect); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | |
| 2102 | // TODO(jcampan): http://b/issue?id=1157486 Remove StoreForFocus call once |
| 2103 | // we have the fix for 792423. |
| 2104 | search_frame->GetView()->StoreFocusForFrame(search_frame); |
| 2105 | webview()->SetFocusedFrame(search_frame); |
| 2106 | } while (!result && search_frame != focused_frame); |
| 2107 | |
| 2108 | // Make sure we don't leave any frame focused or the focus won't be restored |
| 2109 | // properly in WebViewImpl::SetFocus(). Note that we are talking here about |
| 2110 | // focused on the SelectionController, not FocusController. |
| 2111 | // webview()->GetFocusedFrame() will still return the last focused frame (as |
| 2112 | // it queries the FocusController). |
| 2113 | // TODO(jcampan): http://b/issue?id=1157486 Remove next line once we have the |
| 2114 | // fix for 792423. |
| 2115 | webview()->SetFocusedFrame(NULL); |
| 2116 | |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2117 | if (options.findNext) { |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2118 | // Force the main_frame to report the actual count. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2119 | main_frame->IncreaseMatchCount(0, request_id); |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2120 | } else { |
| 2121 | // If nothing is found, set result to "0 of 0", otherwise, set it to |
| 2122 | // "-1 of 1" to indicate that we found at least one item, but we don't know |
| 2123 | // yet what is active. |
| 2124 | int ordinal = result ? -1 : 0; // -1 here means, we might know more later. |
| 2125 | int match_count = result ? 1 : 0; // 1 here means possibly more coming. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2126 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2127 | // If we find no matches then this will be our last status update. |
| 2128 | // Otherwise the scoping effort will send more results. |
| 2129 | bool final_status_update = !result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2130 | |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2131 | // Send the search result over to the browser process. |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 2132 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2133 | request_id, |
[email protected] | 4f3dc37 | 2009-02-24 00:10:29 | [diff] [blame] | 2134 | match_count, |
| 2135 | selection_rect, |
| 2136 | ordinal, |
| 2137 | final_status_update)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2138 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2139 | // Scoping effort begins, starting with the mainframe. |
| 2140 | search_frame = main_frame; |
| 2141 | |
| 2142 | main_frame->ResetMatchCount(); |
| 2143 | |
| 2144 | do { |
| 2145 | // Cancel all old scoping requests before starting a new one. |
| 2146 | search_frame->CancelPendingScopingEffort(); |
| 2147 | |
| 2148 | // We don't start another scoping effort unless at least one match has |
| 2149 | // been found. |
| 2150 | if (result) { |
| 2151 | // Start new scoping request. If the scoping function determines that it |
| 2152 | // needs to scope, it will defer until later. |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2153 | search_frame->ScopeStringMatches(request_id, |
| 2154 | search_text, |
| 2155 | options, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2156 | true); // reset the tickmarks |
| 2157 | } |
| 2158 | |
| 2159 | // Iterate to the next frame. The frame will not necessarily scope, for |
| 2160 | // example if it is not visible. |
| 2161 | search_frame = webview()->GetNextFrameAfter(search_frame, true); |
| 2162 | } while (search_frame != main_frame); |
| 2163 | } |
| 2164 | } |
| 2165 | |
| 2166 | void RenderView::ReportFindInPageMatchCount(int count, int request_id, |
| 2167 | bool final_update) { |
| 2168 | // If we have a message that has been queued up, then we should just replace |
| 2169 | // it. The ACK from the browser will make sure it gets sent when the browser |
| 2170 | // wants it. |
| 2171 | if (queued_find_reply_message_.get()) { |
| 2172 | IPC::Message* msg = new ViewHostMsg_Find_Reply( |
| 2173 | routing_id_, |
| 2174 | request_id, |
| 2175 | count, |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 2176 | gfx::Rect(), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2177 | -1, // Don't update active match ordinal. |
| 2178 | final_update); |
| 2179 | queued_find_reply_message_.reset(msg); |
| 2180 | } else { |
| 2181 | // Send the search result over to the browser process. |
| 2182 | Send(new ViewHostMsg_Find_Reply( |
| 2183 | routing_id_, |
| 2184 | request_id, |
| 2185 | count, |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 2186 | gfx::Rect(), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2187 | -1, // // Don't update active match ordinal. |
| 2188 | final_update)); |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | void RenderView::ReportFindInPageSelection(int request_id, |
| 2193 | int active_match_ordinal, |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 2194 | const WebRect& selection_rect) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2195 | // Send the search result over to the browser process. |
| 2196 | Send(new ViewHostMsg_Find_Reply(routing_id_, |
| 2197 | request_id, |
| 2198 | -1, |
| 2199 | selection_rect, |
| 2200 | active_match_ordinal, |
| 2201 | false)); |
| 2202 | } |
| 2203 | |
[email protected] | ed4bf2d | 2009-05-05 00:10:06 | [diff] [blame] | 2204 | bool RenderView::WasOpenedByUserGesture() const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2205 | return opened_by_user_gesture_; |
| 2206 | } |
| 2207 | |
[email protected] | 7f40fc5b | 2009-06-12 19:23:08 | [diff] [blame] | 2208 | void RenderView::SpellCheck(const std::wstring& word, int* misspell_location, |
| 2209 | int* misspell_length) { |
| 2210 | Send(new ViewHostMsg_SpellCheck(routing_id_, word, misspell_location, |
| 2211 | misspell_length)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2212 | } |
| 2213 | |
[email protected] | 26ea6c4 | 2009-06-10 22:32:21 | [diff] [blame] | 2214 | std::wstring RenderView::GetAutoCorrectWord( |
| 2215 | const std::wstring& misspelled_word) { |
| 2216 | std::wstring autocorrect_word; |
[email protected] | eda2b5a | 2009-05-12 19:30:21 | [diff] [blame] | 2217 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 2218 | if (command_line.HasSwitch(switches::kAutoSpellCorrect)) { |
| 2219 | Send(new ViewHostMsg_GetAutoCorrectWord(routing_id_, misspelled_word, |
| 2220 | &autocorrect_word)); |
| 2221 | } |
[email protected] | 26ea6c4 | 2009-06-10 22:32:21 | [diff] [blame] | 2222 | |
| 2223 | return autocorrect_word; |
[email protected] | eda2b5a | 2009-05-12 19:30:21 | [diff] [blame] | 2224 | } |
| 2225 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2226 | void RenderView::SetInputMethodState(bool enabled) { |
| 2227 | // Save the updated IME status and mark the input focus has been updated. |
| 2228 | // The IME status is to be sent to a browser process next time when |
| 2229 | // the input caret is rendered. |
[email protected] | 9f23f59 | 2008-11-17 08:36:34 | [diff] [blame] | 2230 | if (!ime_control_busy_) { |
| 2231 | ime_control_updated_ = true; |
| 2232 | ime_control_new_state_ = enabled; |
| 2233 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | void RenderView::ScriptedPrint(WebFrame* frame) { |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 2237 | if (print_helper_.get() == NULL) { |
| 2238 | print_helper_.reset(new PrintWebViewHelper(this)); |
| 2239 | } |
| 2240 | print_helper_->SyncPrint(frame); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2241 | } |
| 2242 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2243 | void RenderView::UserMetricsRecordAction(const std::wstring& action) { |
| 2244 | Send(new ViewHostMsg_UserMetricsRecordAction(routing_id_, action)); |
| 2245 | } |
| 2246 | |
| 2247 | void RenderView::DnsPrefetch(const std::vector<std::string>& host_names) { |
| 2248 | Send(new ViewHostMsg_DnsPrefetch(host_names)); |
| 2249 | } |
| 2250 | |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 2251 | void RenderView::OnZoom(int function) { |
| 2252 | static const bool kZoomIsTextOnly = false; |
| 2253 | switch (function) { |
| 2254 | case PageZoom::SMALLER: |
| 2255 | webview()->ZoomOut(kZoomIsTextOnly); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2256 | break; |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 2257 | case PageZoom::STANDARD: |
| 2258 | webview()->ResetZoom(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2259 | break; |
[email protected] | 630e26b | 2008-10-14 22:55:17 | [diff] [blame] | 2260 | case PageZoom::LARGER: |
| 2261 | webview()->ZoomIn(kZoomIsTextOnly); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2262 | break; |
| 2263 | default: |
| 2264 | NOTREACHED(); |
| 2265 | } |
| 2266 | } |
| 2267 | |
[email protected] | ea8c745 | 2009-04-02 20:47:06 | [diff] [blame] | 2268 | void RenderView::OnInsertText(const string16& text) { |
[email protected] | 5f9e0b8 | 2009-05-08 22:13:39 | [diff] [blame] | 2269 | WebFrame* frame = webview()->GetFocusedFrame(); |
| 2270 | if (!frame) |
| 2271 | return; |
| 2272 | WebTextInput* text_input = frame->GetTextInput(); |
[email protected] | 00d7e62 | 2009-04-21 23:06:05 | [diff] [blame] | 2273 | if (text_input) |
[email protected] | 7be0e17 | 2009-05-14 01:05:27 | [diff] [blame] | 2274 | text_input->InsertText(text); |
[email protected] | ea8c745 | 2009-04-02 20:47:06 | [diff] [blame] | 2275 | } |
| 2276 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 2277 | void RenderView::OnSetPageEncoding(const std::wstring& encoding_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2278 | webview()->SetPageEncoding(encoding_name); |
| 2279 | } |
| 2280 | |
[email protected] | f6e59a6 | 2009-05-13 21:12:03 | [diff] [blame] | 2281 | void RenderView::NavigateBackForwardSoon(int offset) { |
[email protected] | f46aff6 | 2008-10-16 07:58:05 | [diff] [blame] | 2282 | history_back_list_count_ += offset; |
| 2283 | history_forward_list_count_ -= offset; |
| 2284 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2285 | Send(new ViewHostMsg_GoToEntryAtOffset(routing_id_, offset)); |
| 2286 | } |
| 2287 | |
| 2288 | int RenderView::GetHistoryBackListCount() { |
| 2289 | return history_back_list_count_; |
| 2290 | } |
| 2291 | |
| 2292 | int RenderView::GetHistoryForwardListCount() { |
| 2293 | return history_forward_list_count_; |
| 2294 | } |
| 2295 | |
| 2296 | void RenderView::OnNavStateChanged(WebView* webview) { |
[email protected] | 81a3441 | 2009-01-05 19:17:24 | [diff] [blame] | 2297 | if (!nav_state_sync_timer_.IsRunning()) { |
| 2298 | nav_state_sync_timer_.Start( |
| 2299 | TimeDelta::FromSeconds(delay_seconds_for_form_state_sync_), this, |
| 2300 | &RenderView::SyncNavigationState); |
| 2301 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | void RenderView::SetTooltipText(WebView* webview, |
| 2305 | const std::wstring& tooltip_text) { |
| 2306 | Send(new ViewHostMsg_SetTooltipText(routing_id_, tooltip_text)); |
| 2307 | } |
| 2308 | |
[email protected] | 2e417c8 | 2009-04-02 22:30:26 | [diff] [blame] | 2309 | void RenderView::DidChangeSelection(bool is_empty_selection) { |
| 2310 | #if defined(OS_LINUX) |
[email protected] | d5d7b800 | 2009-05-18 21:20:54 | [diff] [blame] | 2311 | // TODO(estade): investigate incremental updates to the selection so that we |
| 2312 | // don't send the entire selection over IPC every time. |
[email protected] | 2e417c8 | 2009-04-02 22:30:26 | [diff] [blame] | 2313 | if (!is_empty_selection) { |
[email protected] | d5d7b800 | 2009-05-18 21:20:54 | [diff] [blame] | 2314 | // Sometimes we get repeated DidChangeSelection calls from webkit when |
| 2315 | // the selection hasn't actually changed. We don't want to report these |
| 2316 | // because it will cause us to continually claim the X clipboard. |
| 2317 | const std::string& this_selection = |
| 2318 | webview()->GetFocusedFrame()->GetSelection(false); |
| 2319 | if (this_selection == last_selection_) |
| 2320 | return; |
| 2321 | |
[email protected] | dbadbcc | 2009-04-09 00:57:10 | [diff] [blame] | 2322 | Send(new ViewHostMsg_SelectionChanged(routing_id_, |
[email protected] | d5d7b800 | 2009-05-18 21:20:54 | [diff] [blame] | 2323 | this_selection)); |
| 2324 | last_selection_ = this_selection; |
[email protected] | 2e417c8 | 2009-04-02 22:30:26 | [diff] [blame] | 2325 | } |
| 2326 | #endif |
| 2327 | } |
| 2328 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2329 | void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) { |
| 2330 | Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer)); |
| 2331 | } |
| 2332 | |
[email protected] | 0df3012 | 2009-06-03 12:13:08 | [diff] [blame] | 2333 | void RenderView::UpdateInspectorSettings(const std::wstring& raw_settings) { |
| 2334 | Send(new ViewHostMsg_UpdateInspectorSettings(routing_id_, raw_settings)); |
| 2335 | } |
| 2336 | |
[email protected] | 611cad4 | 2009-03-16 18:51:34 | [diff] [blame] | 2337 | WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() { |
[email protected] | b75b7d07 | 2009-04-06 13:47:00 | [diff] [blame] | 2338 | return devtools_agent_.get(); |
[email protected] | 611cad4 | 2009-03-16 18:51:34 | [diff] [blame] | 2339 | } |
| 2340 | |
[email protected] | ea8c745 | 2009-04-02 20:47:06 | [diff] [blame] | 2341 | void RenderView::PasteFromSelectionClipboard() { |
| 2342 | Send(new ViewHostMsg_PasteFromSelectionClipboard(routing_id_)); |
| 2343 | } |
| 2344 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2345 | WebFrame* RenderView::GetChildFrame(const std::wstring& frame_xpath) const { |
| 2346 | WebFrame* web_frame; |
| 2347 | if (frame_xpath.empty()) { |
| 2348 | web_frame = webview()->GetMainFrame(); |
| 2349 | } else { |
| 2350 | web_frame = webview()->GetMainFrame()->GetChildFrame(frame_xpath); |
| 2351 | } |
| 2352 | |
| 2353 | return web_frame; |
| 2354 | } |
| 2355 | |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 2356 | void RenderView::EvaluateScript(const std::wstring& frame_xpath, |
| 2357 | const std::wstring& script) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2358 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 2359 | if (!web_frame) |
| 2360 | return; |
| 2361 | |
[email protected] | 4f99913 | 2009-03-31 18:08:40 | [diff] [blame] | 2362 | web_frame->ExecuteScript(WebScriptSource(WideToUTF16Hack(script))); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2363 | } |
| 2364 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 2365 | void RenderView::InsertCSS(const std::wstring& frame_xpath, |
| 2366 | const std::string& css) { |
| 2367 | WebFrame* web_frame = GetChildFrame(frame_xpath); |
| 2368 | if (!web_frame) |
| 2369 | return; |
| 2370 | |
| 2371 | web_frame->InsertCSSStyles(css); |
| 2372 | } |
| 2373 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2374 | void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath, |
| 2375 | const std::wstring& jscript) { |
[email protected] | f29acf5 | 2008-11-03 20:08:33 | [diff] [blame] | 2376 | EvaluateScript(frame_xpath, jscript); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2377 | } |
| 2378 | |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 2379 | void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, |
| 2380 | const std::string& css) { |
| 2381 | InsertCSS(frame_xpath, css); |
[email protected] | ae46154 | 2009-06-19 19:03:41 | [diff] [blame] | 2382 | |
| 2383 | // Notify RenderViewHost that css has been inserted into the frame. |
| 2384 | Send(new ViewHostMsg_OnCSSInserted(routing_id_)); |
[email protected] | 1810e13 | 2009-03-24 23:35:48 | [diff] [blame] | 2385 | } |
| 2386 | |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2387 | void RenderView::OnAddMessageToConsole( |
| 2388 | const string16& frame_xpath, |
| 2389 | const string16& message, |
| 2390 | const WebConsoleMessage::Level& level) { |
| 2391 | WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); |
[email protected] | 0dea3ea | 2009-03-31 23:30:59 | [diff] [blame] | 2392 | if (web_frame) |
[email protected] | 7ea066a | 2009-04-06 20:21:59 | [diff] [blame] | 2393 | web_frame->AddMessageToConsole(WebConsoleMessage(level, message)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2394 | } |
| 2395 | |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 2396 | void RenderView::OnAllowBindings(int enabled_bindings_flags) { |
| 2397 | enabled_bindings_ |= enabled_bindings_flags; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | void RenderView::OnSetDOMUIProperty(const std::string& name, |
| 2401 | const std::string& value) { |
[email protected] | 81e6378 | 2009-02-27 19:35:09 | [diff] [blame] | 2402 | DCHECK(BindingsPolicy::is_dom_ui_enabled(enabled_bindings_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2403 | dom_ui_bindings_.SetProperty(name, value); |
| 2404 | } |
| 2405 | |
| 2406 | void RenderView::OnReservePageIDRange(int size_of_range) { |
| 2407 | next_page_id_ += size_of_range + 1; |
| 2408 | } |
| 2409 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 2410 | void RenderView::OnDragSourceEndedOrMoved(const gfx::Point& client_point, |
| 2411 | const gfx::Point& screen_point, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2412 | bool ended) { |
| 2413 | if (ended) |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 2414 | webview()->DragSourceEndedAt(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2415 | else |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 2416 | webview()->DragSourceMovedTo(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | void RenderView::OnDragSourceSystemDragEnded() { |
| 2420 | webview()->DragSourceSystemDragEnded(); |
| 2421 | } |
| 2422 | |
| 2423 | void RenderView::OnUploadFileRequest(const ViewMsg_UploadFile_Params& p) { |
| 2424 | webkit_glue::FileUploadData* f = new webkit_glue::FileUploadData; |
| 2425 | f->file_path = p.file_path; |
| 2426 | f->form_name = p.form; |
| 2427 | f->file_name = p.file; |
| 2428 | f->submit_name = p.submit; |
| 2429 | |
| 2430 | // Build the other form values map. |
| 2431 | if (!p.other_values.empty()) { |
| 2432 | std::vector<std::wstring> e; |
| 2433 | std::vector<std::wstring> kvp; |
| 2434 | std::vector<std::wstring>::iterator i; |
| 2435 | |
| 2436 | SplitString(p.other_values, L'\n', &e); |
| 2437 | for (i = e.begin(); i != e.end(); ++i) { |
| 2438 | SplitString(*i, L'=', &kvp); |
| 2439 | if (kvp.size() == 2) |
| 2440 | f->other_form_values[kvp[0]] = kvp[1]; |
| 2441 | kvp.clear(); |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | pending_upload_data_.reset(f); |
| 2446 | ProcessPendingUpload(); |
| 2447 | } |
| 2448 | |
| 2449 | void RenderView::ProcessPendingUpload() { |
| 2450 | webkit_glue::FileUploadData* f = pending_upload_data_.get(); |
| 2451 | if (f && webview() && webkit_glue::FillFormToUploadFile(webview(), *f)) |
| 2452 | ResetPendingUpload(); |
| 2453 | } |
| 2454 | |
| 2455 | void RenderView::ResetPendingUpload() { |
| 2456 | pending_upload_data_.reset(); |
| 2457 | } |
| 2458 | |
| 2459 | void RenderView::OnFormFill(const FormData& form) { |
| 2460 | webkit_glue::FillForm(this->webview(), form); |
| 2461 | } |
| 2462 | |
| 2463 | void RenderView::OnFillPasswordForm( |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 2464 | const webkit_glue::PasswordFormDomManager::FillData& form_data) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2465 | webkit_glue::FillPasswordForm(this->webview(), form_data); |
| 2466 | } |
| 2467 | |
| 2468 | void RenderView::OnDragTargetDragEnter(const WebDropData& drop_data, |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 2469 | const gfx::Point& client_point, |
| 2470 | const gfx::Point& screen_point) { |
| 2471 | bool is_drop_target = webview()->DragTargetDragEnter( |
| 2472 | drop_data.ToDragData(), |
| 2473 | drop_data.identity, |
| 2474 | client_point, |
| 2475 | screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2476 | |
| 2477 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target)); |
| 2478 | } |
| 2479 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 2480 | void RenderView::OnDragTargetDragOver(const gfx::Point& client_point, |
| 2481 | const gfx::Point& screen_point) { |
| 2482 | bool is_drop_target = |
| 2483 | webview()->DragTargetDragOver(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2484 | |
| 2485 | Send(new ViewHostMsg_UpdateDragCursor(routing_id_, is_drop_target)); |
| 2486 | } |
| 2487 | |
| 2488 | void RenderView::OnDragTargetDragLeave() { |
| 2489 | webview()->DragTargetDragLeave(); |
| 2490 | } |
| 2491 | |
[email protected] | e80c73b | 2009-04-07 23:24:58 | [diff] [blame] | 2492 | void RenderView::OnDragTargetDrop(const gfx::Point& client_point, |
| 2493 | const gfx::Point& screen_point) { |
| 2494 | webview()->DragTargetDrop(client_point, screen_point); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2495 | } |
| 2496 | |
| 2497 | void RenderView::OnUpdateWebPreferences(const WebPreferences& prefs) { |
| 2498 | webview()->SetPreferences(prefs); |
| 2499 | } |
| 2500 | |
| 2501 | void RenderView::OnSetAltErrorPageURL(const GURL& url) { |
| 2502 | alternate_error_page_url_ = url; |
| 2503 | } |
| 2504 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2505 | void RenderView::OnInstallMissingPlugin() { |
| 2506 | // This could happen when the first default plugin is deleted. |
| 2507 | if (first_default_plugin_ == NULL) |
| 2508 | return; |
| 2509 | first_default_plugin_->InstallMissingPlugin(); |
| 2510 | } |
| 2511 | |
[email protected] | b62d1a8c | 2009-01-13 23:54:57 | [diff] [blame] | 2512 | void RenderView::OnFileChooserResponse( |
[email protected] | 561abe6 | 2009-04-06 18:08:34 | [diff] [blame] | 2513 | const std::vector<FilePath>& file_names) { |
[email protected] | 8029f567 | 2009-03-20 22:33:36 | [diff] [blame] | 2514 | // This could happen if we navigated to a different page before the user |
| 2515 | // closed the chooser. |
| 2516 | if (!file_chooser_.get()) |
| 2517 | return; |
| 2518 | |
[email protected] | b62d1a8c | 2009-01-13 23:54:57 | [diff] [blame] | 2519 | file_chooser_->OnFileChoose(file_names); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2520 | file_chooser_.reset(); |
| 2521 | } |
| 2522 | |
| 2523 | void RenderView::OnEnableViewSourceMode() { |
| 2524 | if (!webview()) |
| 2525 | return; |
| 2526 | WebFrame* main_frame = webview()->GetMainFrame(); |
| 2527 | if (!main_frame) |
| 2528 | return; |
| 2529 | |
| 2530 | main_frame->SetInViewSourceMode(true); |
| 2531 | } |
| 2532 | |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 2533 | void RenderView::OnEnableIntrinsicWidthChangedMode() { |
| 2534 | send_preferred_width_changes_ = true; |
| 2535 | } |
| 2536 | |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 2537 | void RenderView::OnSetRendererPrefs(const RendererPreferences& renderer_prefs) { |
| 2538 | renderer_preferences_ = renderer_prefs; |
| 2539 | } |
| 2540 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2541 | void RenderView::OnUpdateBackForwardListCount(int back_list_count, |
| 2542 | int forward_list_count) { |
| 2543 | history_back_list_count_ = back_list_count; |
| 2544 | history_forward_list_count_ = forward_list_count; |
| 2545 | } |
| 2546 | |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 2547 | void RenderView::OnGetAccessibilityInfo( |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 2548 | const webkit_glue::WebAccessibility::InParams& in_params, |
| 2549 | webkit_glue::WebAccessibility::OutParams* out_params) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 2550 | #if defined(OS_WIN) |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 2551 | if (!web_accessibility_manager_.get()) { |
| 2552 | web_accessibility_manager_.reset( |
| 2553 | webkit_glue::WebAccessibilityManager::Create()); |
| 2554 | } |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 2555 | |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 2556 | if (!web_accessibility_manager_->GetAccObjInfo(webview(), in_params, |
| 2557 | out_params)) { |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 2558 | return; |
| 2559 | } |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 2560 | #else // defined(OS_WIN) |
| 2561 | // TODO(port): accessibility not yet implemented |
| 2562 | NOTIMPLEMENTED(); |
| 2563 | #endif |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 2564 | } |
| 2565 | |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 2566 | void RenderView::OnClearAccessibilityInfo(int acc_obj_id, bool clear_all) { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 2567 | #if defined(OS_WIN) |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 2568 | if (!web_accessibility_manager_.get()) { |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 2569 | // If accessibility is not activated, ignore clearing message. |
| 2570 | return; |
| 2571 | } |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 2572 | |
[email protected] | 6a983b4 | 2009-03-20 20:12:25 | [diff] [blame] | 2573 | if (!web_accessibility_manager_->ClearAccObjMap(acc_obj_id, clear_all)) |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 2574 | return; |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 2575 | |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 2576 | #else // defined(OS_WIN) |
| 2577 | // TODO(port): accessibility not yet implemented |
| 2578 | NOTIMPLEMENTED(); |
| 2579 | #endif |
[email protected] | 266eb6f | 2008-09-30 23:56:50 | [diff] [blame] | 2580 | } |
| 2581 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2582 | void RenderView::OnGetAllSavableResourceLinksForCurrentPage( |
| 2583 | const GURL& page_url) { |
| 2584 | // Prepare list to storage all savable resource links. |
| 2585 | std::vector<GURL> resources_list; |
| 2586 | std::vector<GURL> referrers_list; |
| 2587 | std::vector<GURL> frames_list; |
| 2588 | webkit_glue::SavableResourcesResult result(&resources_list, |
| 2589 | &referrers_list, |
| 2590 | &frames_list); |
| 2591 | |
| 2592 | if (!webkit_glue::GetAllSavableResourceLinksForCurrentPage(webview(), |
| 2593 | page_url, |
| 2594 | &result)) { |
| 2595 | // If something is wrong when collecting all savable resource links, |
| 2596 | // send empty list to embedder(browser) to tell it failed. |
| 2597 | referrers_list.clear(); |
| 2598 | resources_list.clear(); |
| 2599 | frames_list.clear(); |
| 2600 | } |
| 2601 | |
| 2602 | // Send result of all savable resource links to embedder. |
| 2603 | Send(new ViewHostMsg_SendCurrentPageAllSavableResourceLinks(routing_id_, |
| 2604 | resources_list, |
| 2605 | referrers_list, |
| 2606 | frames_list)); |
| 2607 | } |
| 2608 | |
| 2609 | void RenderView::OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |
[email protected] | f6b4853 | 2009-02-12 01:56:32 | [diff] [blame] | 2610 | const std::vector<GURL>& links, |
[email protected] | fde6714d1 | 2009-02-18 22:39:31 | [diff] [blame] | 2611 | const std::vector<FilePath>& local_paths, |
| 2612 | const FilePath& local_directory_name) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2613 | webkit_glue::DomSerializer dom_serializer(webview()->GetMainFrame(), |
| 2614 | true, |
| 2615 | this, |
| 2616 | links, |
| 2617 | local_paths, |
| 2618 | local_directory_name); |
| 2619 | dom_serializer.SerializeDom(); |
| 2620 | } |
| 2621 | |
| 2622 | void RenderView::DidSerializeDataForFrame(const GURL& frame_url, |
| 2623 | const std::string& data, PageSavingSerializationStatus status) { |
| 2624 | Send(new ViewHostMsg_SendSerializedHtmlData(routing_id_, |
| 2625 | frame_url, data, static_cast<int32>(status))); |
| 2626 | } |
| 2627 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2628 | void RenderView::OnMsgShouldClose() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2629 | bool should_close = webview()->ShouldClose(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2630 | Send(new ViewHostMsg_ShouldClose_ACK(routing_id_, should_close)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | void RenderView::OnClosePage(int new_render_process_host_id, |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2634 | int new_request_id) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2635 | // TODO(creis): We'd rather use webview()->Close() here, but that currently |
| 2636 | // sets the WebView's delegate_ to NULL, preventing any JavaScript dialogs |
| 2637 | // in the onunload handler from appearing. For now, we're bypassing that and |
| 2638 | // calling the FrameLoader's CloseURL method directly. This should be |
| 2639 | // revisited to avoid having two ways to close a page. Having a single way |
| 2640 | // to close that can run onunload is also useful for fixing |
| 2641 | // http://b/issue?id=753080. |
| 2642 | WebFrame* main_frame = webview()->GetMainFrame(); |
| 2643 | if (main_frame) |
| 2644 | main_frame->ClosePage(); |
| 2645 | |
| 2646 | Send(new ViewHostMsg_ClosePage_ACK(routing_id_, |
| 2647 | new_render_process_host_id, |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2648 | new_request_id)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | void RenderView::OnThemeChanged() { |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 2652 | #if defined(OS_WIN) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2653 | gfx::NativeTheme::instance()->CloseHandles(); |
| 2654 | gfx::Rect view_rect(0, 0, size_.width(), size_.height()); |
| 2655 | DidInvalidateRect(webwidget_, view_rect); |
[email protected] | 6c8afae5 | 2009-01-22 02:24:57 | [diff] [blame] | 2656 | #else // defined(OS_WIN) |
| 2657 | // TODO(port): we don't support theming on non-Windows platforms yet |
| 2658 | NOTIMPLEMENTED(); |
| 2659 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2660 | } |
| 2661 | |
[email protected] | f46aff6 | 2008-10-16 07:58:05 | [diff] [blame] | 2662 | void RenderView::DidAddHistoryItem() { |
[email protected] | f890108 | 2008-10-31 23:34:03 | [diff] [blame] | 2663 | // We don't want to update the history length for the start page |
| 2664 | // navigation. |
| 2665 | WebFrame* main_frame = webview()->GetMainFrame(); |
| 2666 | DCHECK(main_frame != NULL); |
| 2667 | |
| 2668 | WebDataSource* ds = main_frame->GetDataSource(); |
| 2669 | DCHECK(ds != NULL); |
| 2670 | |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 2671 | NavigationState* navigation_state = NavigationState::FromDataSource(ds); |
| 2672 | if (navigation_state->transition_type() == PageTransition::START_PAGE) |
[email protected] | f890108 | 2008-10-31 23:34:03 | [diff] [blame] | 2673 | return; |
| 2674 | |
[email protected] | f46aff6 | 2008-10-16 07:58:05 | [diff] [blame] | 2675 | history_back_list_count_++; |
| 2676 | history_forward_list_count_ = 0; |
| 2677 | } |
| 2678 | |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 2679 | void RenderView::OnMessageFromExternalHost(const std::string& message, |
| 2680 | const std::string& origin, |
| 2681 | const std::string& target) { |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 2682 | if (message.empty()) |
| 2683 | return; |
| 2684 | |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 2685 | external_host_bindings_.ForwardMessageFromExternalHost(message, origin, |
| 2686 | target); |
[email protected] | 3ac14a05 | 2008-08-15 21:22:15 | [diff] [blame] | 2687 | } |
| 2688 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 2689 | void RenderView::OnDisassociateFromPopupCount() { |
| 2690 | if (decrement_shared_popup_at_destruction_) |
| 2691 | shared_popup_counter_->data--; |
| 2692 | shared_popup_counter_ = new SharedRenderViewCounter(0); |
| 2693 | decrement_shared_popup_at_destruction_ = false; |
| 2694 | } |
| 2695 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2696 | std::string RenderView::GetAltHTMLForTemplate( |
| 2697 | const DictionaryValue& error_strings, int template_resource_id) const { |
| 2698 | const StringPiece template_html( |
| 2699 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 2700 | template_resource_id)); |
| 2701 | |
| 2702 | if (template_html.empty()) { |
| 2703 | NOTREACHED() << "unable to load template. ID: " << template_resource_id; |
| 2704 | return ""; |
| 2705 | } |
| 2706 | // "t" is the id of the templates root node. |
| 2707 | return jstemplate_builder::GetTemplateHtml( |
| 2708 | template_html, &error_strings, "t"); |
| 2709 | } |
[email protected] | 0e79b9e | 2009-02-13 04:20:48 | [diff] [blame] | 2710 | |
| 2711 | MessageLoop* RenderView::GetMessageLoopForIO() { |
| 2712 | // Assume that we have only one RenderThread in the process and the owner loop |
| 2713 | // of RenderThread is an IO message loop. |
[email protected] | 8930d47 | 2009-02-21 08:05:28 | [diff] [blame] | 2714 | if (RenderThread::current()) |
| 2715 | return RenderThread::current()->owner_loop(); |
[email protected] | 0e79b9e | 2009-02-13 04:20:48 | [diff] [blame] | 2716 | return NULL; |
| 2717 | } |
[email protected] | 6f56d48 | 2009-02-20 05:02:56 | [diff] [blame] | 2718 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 2719 | void RenderView::OnMoveOrResizeStarted() { |
| 2720 | if (webview()) |
| 2721 | webview()->HideAutofillPopup(); |
| 2722 | } |
| 2723 | |
[email protected] | 30f75e6 | 2009-02-25 22:01:00 | [diff] [blame] | 2724 | void RenderView::OnResize(const gfx::Size& new_size, |
| 2725 | const gfx::Rect& resizer_rect) { |
| 2726 | if (webview()) |
| 2727 | webview()->HideAutofillPopup(); |
| 2728 | RenderWidget::OnResize(new_size, resizer_rect); |
| 2729 | } |
[email protected] | 0aa477bd | 2009-03-23 22:21:43 | [diff] [blame] | 2730 | |
[email protected] | 05d47875 | 2009-04-08 23:38:16 | [diff] [blame] | 2731 | void RenderView::OnClearFocusedNode() { |
| 2732 | if (webview()) |
| 2733 | webview()->ClearFocusedNode(); |
| 2734 | } |
| 2735 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 2736 | void RenderView::OnSetBackground(const SkBitmap& background) { |
| 2737 | if (webview()) |
| 2738 | webview()->SetIsTransparent(!background.empty()); |
| 2739 | |
| 2740 | SetBackground(background); |
| 2741 | } |
| 2742 | |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 2743 | void RenderView::SendExtensionRequest(const std::string& name, |
| 2744 | const std::string& args, |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 2745 | int request_id, |
[email protected] | 2f25d7b9 | 2009-06-10 00:06:47 | [diff] [blame] | 2746 | bool has_callback) { |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 2747 | Send(new ViewHostMsg_ExtensionRequest(routing_id_, name, args, request_id, |
[email protected] | 2f25d7b9 | 2009-06-10 00:06:47 | [diff] [blame] | 2748 | has_callback)); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 2749 | } |
| 2750 | |
[email protected] | c661918 | 2009-05-12 14:59:32 | [diff] [blame] | 2751 | void RenderView::OnExtensionResponse(int request_id, |
| 2752 | bool success, |
| 2753 | const std::string& response, |
| 2754 | const std::string& error) { |
[email protected] | 2f25d7b9 | 2009-06-10 00:06:47 | [diff] [blame] | 2755 | ExtensionProcessBindings::HandleResponse(request_id, success, response, |
| 2756 | error); |
[email protected] | 309d7a28 | 2009-03-24 09:18:27 | [diff] [blame] | 2757 | } |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2758 | |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2759 | // Dump all load time histograms. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2760 | // |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2761 | // There are 7 histograms measuring various times. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2762 | // The time points we keep are |
| 2763 | // request: time document was requested by user |
| 2764 | // start: time load of document started |
| 2765 | // finishDoc: main document loaded, before onload() |
| 2766 | // finish: after onload() and all resources are loaded |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2767 | // firstLayout: first layout performed |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2768 | // The times that we histogram are |
| 2769 | // requestToStart, |
| 2770 | // startToFinishDoc, |
| 2771 | // finishDocToFinish, |
| 2772 | // startToFinish, |
| 2773 | // requestToFinish, |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2774 | // requestToFirstLayout |
| 2775 | // startToFirstLayout |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2776 | // |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2777 | // It's possible for the request time not to be set, if a client |
| 2778 | // redirect had been done (the user never requested the page) |
| 2779 | // Also, it's possible to load a page without ever laying it out |
| 2780 | // so firstLayout can be 0. |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2781 | void RenderView::DumpLoadHistograms() const { |
| 2782 | WebFrame* main_frame = webview()->GetMainFrame(); |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 2783 | NavigationState* navigation_state = |
| 2784 | NavigationState::FromDataSource(main_frame->GetDataSource()); |
| 2785 | |
| 2786 | Time request_time = navigation_state->request_time(); |
| 2787 | Time start_load_time = navigation_state->start_load_time(); |
| 2788 | Time finish_document_load_time = |
| 2789 | navigation_state->finish_document_load_time(); |
| 2790 | Time finish_load_time = navigation_state->finish_load_time(); |
| 2791 | Time first_layout_time = navigation_state->first_layout_time(); |
| 2792 | |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2793 | TimeDelta request_to_start = start_load_time - request_time; |
| 2794 | TimeDelta start_to_finish_doc = finish_document_load_time - start_load_time; |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2795 | TimeDelta finish_doc_to_finish = |
| 2796 | finish_load_time - finish_document_load_time; |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2797 | TimeDelta start_to_finish = finish_load_time - start_load_time; |
[email protected] | 978077e | 2009-06-20 22:32:51 | [diff] [blame] | 2798 | TimeDelta request_to_finish = finish_load_time - request_time; |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2799 | TimeDelta request_to_first_layout = first_layout_time - request_time; |
| 2800 | TimeDelta start_to_first_layout = first_layout_time - start_load_time; |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2801 | |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2802 | // Client side redirects will have no request time |
| 2803 | if (request_time.ToInternalValue() != 0) { |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 2804 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer2.RequestToStart", request_to_start); |
[email protected] | 978077e | 2009-06-20 22:32:51 | [diff] [blame] | 2805 | UMA_HISTOGRAM_CUSTOM_TIMES( |
| 2806 | FieldTrial::MakeName("Renderer2.RequestToFinish_2", "DnsImpact").data(), |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 2807 | request_to_finish, TimeDelta::FromMilliseconds(10), |
| 2808 | TimeDelta::FromMinutes(10), 100); |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2809 | if (request_to_first_layout.ToInternalValue() >= 0) { |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 2810 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer2.RequestToFirstLayout", |
[email protected] | 4646f29 | 2009-05-20 03:49:05 | [diff] [blame] | 2811 | request_to_first_layout); |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2812 | } |
| 2813 | } |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 2814 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer2.StartToFinishDoc", start_to_finish_doc); |
| 2815 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer2.FinishDocToFinish", |
| 2816 | finish_doc_to_finish); |
| 2817 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer2.StartToFinish", start_to_finish); |
[email protected] | e7e4f3c | 2009-04-21 15:24:08 | [diff] [blame] | 2818 | if (start_to_first_layout.ToInternalValue() >= 0) { |
[email protected] | f929f2f2 | 2009-06-12 16:56:58 | [diff] [blame] | 2819 | UMA_HISTOGRAM_MEDIUM_TIMES("Renderer2.StartToFirstLayout", |
| 2820 | start_to_first_layout); |
[email protected] | c20210e6 | 2009-04-03 21:39:26 | [diff] [blame] | 2821 | } |
| 2822 | } |
[email protected] | e846d0d | 2009-05-20 00:53:06 | [diff] [blame] | 2823 | |
| 2824 | void RenderView::FocusAccessibilityObject( |
| 2825 | WebCore::AccessibilityObject* acc_obj) { |
| 2826 | #if defined(OS_WIN) |
| 2827 | if (!web_accessibility_manager_.get()) { |
| 2828 | web_accessibility_manager_.reset( |
| 2829 | webkit_glue::WebAccessibilityManager::Create()); |
| 2830 | } |
| 2831 | |
| 2832 | // Retrieve the accessibility object id of the AccessibilityObject. |
| 2833 | int acc_obj_id = web_accessibility_manager_->FocusAccObj(acc_obj); |
| 2834 | |
| 2835 | // If id is valid, alert the browser side that an accessibility focus change |
| 2836 | // occurred. |
| 2837 | if (acc_obj_id >= 0) |
| 2838 | Send(new ViewHostMsg_AccessibilityFocusChange(routing_id_, acc_obj_id)); |
| 2839 | |
| 2840 | #else // defined(OS_WIN) |
| 2841 | // TODO(port): accessibility not yet implemented |
| 2842 | NOTIMPLEMENTED(); |
| 2843 | #endif |
| 2844 | } |
[email protected] | daa8c58e | 2009-06-15 17:21:10 | [diff] [blame] | 2845 | |
| 2846 | void RenderView::SendPasswordForms(WebFrame* frame) { |
| 2847 | std::vector<WebForm> forms; |
| 2848 | frame->GetForms(&forms); |
| 2849 | |
| 2850 | std::vector<PasswordForm> password_forms; |
| 2851 | for (size_t i = 0; i < forms.size(); ++i) { |
| 2852 | const WebForm& form = forms[i]; |
| 2853 | |
| 2854 | // Respect autocomplete=off. |
| 2855 | if (form.isAutoCompleteEnabled()) { |
| 2856 | scoped_ptr<PasswordForm> password_form( |
| 2857 | PasswordFormDomManager::CreatePasswordForm(form)); |
| 2858 | if (password_form.get()) |
| 2859 | password_forms.push_back(*password_form); |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | if (!password_forms.empty()) |
| 2864 | Send(new ViewHostMsg_PasswordFormsSeen(routing_id_, password_forms)); |
| 2865 | } |