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