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