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