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