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